Date: Thu, 30 Dec 1999 12:39:19 -0800 From: Randy Dunlap <randy.dunlap@intel.com> To: linux-usb@suse.com Subject: [linux-usb] USB /proc tree viewer --------------C927279C5C28292061897DDF Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Hi, Here are updated procusb and usbtree (perl) scripts. These work with virtual root hubs as in 2.3.35. usbtree sample output for root hub, external hub with mouse, keyboard, and cpia-based camera: /: Bus 00.Port 00: Dev 1, Class=root_hub, Driver=hub/2p, 12M |__ Bus 00.Port 00: Dev 2, If 0, Class=hub, Driver=hub/4p, 12M |__ Bus 00.Port 00: Dev 3, If 0, Class=HID, Driver=mouse, 1.5M |__ Bus 00.Port 01: Dev 4, If 0, Class=HID, Driver=keyboard, 1.5M |__ Bus 00.Port 01: Dev 4, If 1, Class=HID, Driver=mouse, 1.5M |__ Bus 00.Port 03: Dev 5, If 1, Class=vend., Driver=cpia, 12M |__ Bus 00.Port 03: Dev 5, If 1, Class=vend., Driver=cpia, 12M |__ Bus 00.Port 03: Dev 5, If 1, Class=vend., Driver=cpia, 12M |__ Bus 00.Port 03: Dev 5, If 1, Class=vend., Driver=cpia, 12M ~Randy --------------C927279C5C28292061897DDF Content-Type: text/plain; charset=us-ascii; name="procusb" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="procusb" #!/usr/bin/perl # Reads /proc/bus/usb/devices and selectively lists and/or # interprets it. $DEVFILENAME = "/proc/bus/usb/devices"; $PROGNAME = $0; print "\n"; $TAGS = $ARGV[0]; # save user TAGS if (length ($TAGS) == 0) { print "usage: $PROGNAME tags\n"; print " where 'tags' can be any number of 'TBDPSCIE' or 'A(LL)'\n"; exit 1; } $ALL = ($TAGS =~ /all/i) || ($TAGS =~ /a/i); # TBD: Check that $TAGS is valid. if (! $ALL) { } if (! open (DEVNUM, "<$DEVFILENAME")) { print "$PROGNAME: cannot open '$DEVFILENAME'\n"; exit 1; } while ($line = <DEVNUM>) # read a text line from DEVNUM { if (($ALL) || ($line =~ /^[$TAGS]:/i)) # any of TAGS at beg. of line? { print "$line"; # still has newline char on it # TBD: add more/paging functionality. } } # end while DEVNUM close (DEVNUM); print "\n"; # END. --------------C927279C5C28292061897DDF Content-Type: text/plain; charset=us-ascii; name="usbtree" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="usbtree" #!/usr/bin/perl # Reads /proc/bus/usb/devices and selectively lists and/or # interprets it. $DEVFILENAME = "/proc/bus/usb/devices"; $PROGNAME = $0; print "\n"; $TAGS = $ARGV[0]; # save user TAGS if (length ($TAGS) == 0) { } if (! open (DEVNUM, "<$DEVFILENAME")) { print "$PROGNAME: cannot open '$DEVFILENAME'\n"; exit 1; } while ($line = <DEVNUM>) # read a text line from DEVNUM { # skip all lines except those that begin with "T:" or "D:" or "I:". if (($line !~ "^T:") && ($line !~ "^I:") && ($line !~ "^D:")) { next; # to the next line } chomp $line; # remove line endings # First convert '=' signs to spaces. $line =~ tr/=/ /; # and convert all '(' and ')' to spaces. $line =~ tr/(/ /; $line =~ tr/)/ /; # split the line at spaces. @fields = split / +/, $line; if ($line =~ "^T:") { # split yields: $bus, $level, $port, $devnum, $speed, $maxchild. $bus = @fields [2]; $level = @fields [4]; $port = @fields [8]; $devnum = @fields [12]; $speed = @fields [14]; $maxchild = @fields [16]; $devclass = "?"; $intclass = "?"; $driver = "?"; $ifnum = "?"; $showclass = "?"; # derived from $devclass or $intclass next; } # end T: line elsif ($line =~ "^D:") { # for D: line $devclass = @fields [5]; next; } else { # for I: line $intclass = @fields [9]; $ifnum = @fields [2]; $driver = @fields [15]; } # end I: line if ($level > 1) { $temp = $level; while ($temp > 1) { print " "; $temp--; } } if (($devclass eq ">ifc") || ($devclass eq "unk.")) { # then use InterfaceClass, not DeviceClass $showclass = $intclass; } else { # use DeviceClass $showclass = $devclass; } if ($level == 0) { print sprintf ("/: Bus $bus.Port $port: Dev $devnum, Class=root_hub, Driver=hub/%sp, %sM\n", $maxchild, $speed); } else { print sprintf ("|__ Bus $bus.Port $port: Dev $devnum, If $ifnum, Class=$showclass, Driver=$driver%s, %sM\n", ($maxchild == 0) ? "" : ("/" . $maxchild . "p"), $speed); } } # end while DEVNUM close (DEVNUM); print "\n"; # END. --------------C927279C5C28292061897DDF Content-Type: text/plain; charset=us-ascii -- To unsubscribe, e-mail: linux-usb-unsubscribe@suse.com For additional commands, e-mail: linux-usb-help@suse.com --------------C927279C5C28292061897DDF--