"Fossies" - the Fresh Open Source Software Archive

Member "usbutils-015/usb-devices" (20 Jan 2022, 4498 Bytes) of package /linux/misc/usbutils-015.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "usb-devices": 014_vs_015.

    1 #!/bin/sh
    2 # SPDX-License-Identifier: GPL-2.0-or-later
    3 #
    4 # Copyright (c) 2009 Greg Kroah-Hartman <greg@kroah.com>
    5 # Copyright (c) 2009 Randy Dunlap <rdunlap@xenotime.net>
    6 # Copyright (c) 2009 Frans Pop <elendil@planet.nl>
    7 
    8 print_string() {
    9     file=$1
   10     name=$2
   11     if [ -f $file ]; then
   12         echo "S:  $name=`cat $file`"
   13     fi
   14 }
   15 
   16 class_decode() {
   17     class=$1        # v4: in hex
   18 
   19     case $class in
   20     "00") echo ">ifc " ;;
   21     "01") echo "audio" ;;
   22     "02") echo "commc" ;;
   23     "03") echo "HID  " ;;
   24     "05") echo "PID  " ;;
   25     "06") echo "still" ;;
   26     "07") echo "print" ;;
   27     "08") echo "stor." ;;
   28     "09") echo "hub  " ;;
   29     "0a") echo "data " ;;
   30     "0b") echo "scard" ;;
   31     "0d") echo "c-sec" ;;
   32     "0e") echo "video" ;;
   33     "0f") echo "perhc" ;;
   34     "10") echo "av   " ;;
   35     "11") echo "blbrd" ;;
   36     "12") echo "bridg" ;;
   37     "dc") echo "diagd" ;;
   38     "e0") echo "wlcon" ;;
   39     "ef") echo "misc " ;;
   40     "fe") echo "app. " ;;
   41     "ff") echo "vend." ;;
   42     "*")  echo "unk. " ;;
   43     esac
   44 }
   45 
   46 print_endpoint() {
   47     eppath=$1
   48 
   49     addr=`cat $eppath/bEndpointAddress`
   50     attr=`cat $eppath/bmAttributes`
   51     dir=`cat $eppath/direction`
   52     if [ "$dir" = in ]; then
   53         dir=I
   54     elif [ "$dir" = out ]; then
   55         dir=O
   56     elif [ "$dir" = both ]; then
   57         dir=B
   58     fi
   59     eptype=`cat $eppath/type`
   60     if [ "$eptype" = Control ]; then
   61         eptype="Ctrl"
   62     elif [ "$eptype" = Interrupt ]; then
   63         eptype="Int."
   64     fi
   65     maxps_hex="0x`cat $eppath/wMaxPacketSize`"
   66     # Extract MaxPS size (bits 0-10) and multiplicity values (bits 11-12)
   67     maxps=$((`printf "%4i*%s\n" $(($maxps_hex & 0x7ff)) \
   68                 $((1 + (($maxps_hex >> 11) & 0x3)))`))
   69     interval=`cat $eppath/interval`
   70 
   71     printf "E:  Ad=%s(%s) Atr=%s(%s) MxPS=%4s Ivl=%s\n" \
   72         $addr $dir $attr $eptype "$maxps" $interval
   73 }
   74 
   75 print_interface() {
   76     ifpath=$1
   77 
   78     ifnum=`cat $ifpath/bInterfaceNumber`
   79     altset=`cat $ifpath/bAlternateSetting`
   80     numeps=`cat $ifpath/bNumEndpoints`
   81     class=`cat $ifpath/bInterfaceClass`
   82     subclass=`cat $ifpath/bInterfaceSubClass`
   83     protocol=`cat $ifpath/bInterfaceProtocol`
   84     if [ -L $ifpath/driver ]; then      # v4: allow for no driver
   85         driver=`readlink $ifpath/driver`
   86         driver=`basename "$driver"`
   87     else
   88         driver="(none)"
   89     fi
   90     classname=`class_decode $class`
   91     printf "I:  If#=%2i Alt=%2i #EPs=%2i Cls=%s(%s) Sub=%s Prot=%s Driver=%s\n" \
   92         0x${ifnum#0} ${altset#0} 0x${numeps#0} $class "$classname" $subclass \
   93         $protocol $driver
   94 
   95     for endpoint in $ifpath/ep_??
   96     do
   97         if [ -L $endpoint ] || [ -d $endpoint ]; then   # v4: verify endpoint exists
   98             print_endpoint $endpoint
   99         fi
  100     done
  101 }
  102 
  103 print_device() {
  104     local devpath=$1
  105     local parent=$2
  106     local level=$3
  107     local count=$4
  108 
  109     [ -d $devpath ] || return
  110     cd $devpath
  111 
  112     busnum=`cat busnum`
  113     devnum=`cat devnum`
  114 
  115     if [ $level -gt 0 ]; then
  116         port=$((${devpath##*[-.]} - 1))
  117     else
  118         port=0
  119     fi
  120     speed=`cat speed`
  121     maxchild=`cat maxchild`
  122     printf "\nT:  Bus=%02i Lev=%02i Prnt=%02i Port=%02i Cnt=%02i Dev#=%3i Spd=%-4s MxCh=%2i\n" \
  123         $busnum $level $parent $port $count $devnum $speed $maxchild
  124 
  125     ver=`cat version`
  126     devclass=`cat bDeviceClass`
  127     devsubclass=`cat bDeviceSubClass`
  128     devprotocol=`cat bDeviceProtocol`
  129     maxps0=`cat bMaxPacketSize0`
  130     numconfigs=`cat bNumConfigurations`
  131     classname=`class_decode $devclass`
  132     printf "D:  Ver=%5s Cls=%s(%s) Sub=%s Prot=%s MxPS=%2i #Cfgs=%3i\n" \
  133         $ver $devclass "$classname" $devsubclass $devprotocol \
  134         $maxps0 $numconfigs
  135 
  136     vendid=`cat idVendor`
  137     prodid=`cat idProduct`
  138     revmajor=`cat bcdDevice | cut -c 1-2`
  139     revminor=`cat bcdDevice | cut -c 3-4`
  140     printf "P:  Vendor=%s ProdID=%s Rev=%s.%s\n" \
  141         $vendid $prodid $revmajor $revminor
  142 
  143     print_string manufacturer "Manufacturer"
  144     print_string product Product
  145     print_string serial SerialNumber
  146 
  147     numifs=`cat bNumInterfaces`
  148     cfgnum=`cat bConfigurationValue`
  149     attr=`cat bmAttributes`
  150     maxpower=`cat bMaxPower`
  151     printf "C:  #Ifs=%2i Cfg#=%2i Atr=%s MxPwr=%s\n" \
  152         $numifs $cfgnum $attr $maxpower
  153 
  154     # There's not really any useful info in endpoint 00
  155     #print_endpoint $devpath/ep_00
  156 
  157     for interface in $busnum-*:?.*
  158     do
  159         print_interface $devpath/$interface
  160     done
  161 
  162     devcount=0
  163     for subdev in $busnum-*
  164     do
  165         echo "$subdev" | grep -Eq "^$busnum-[0-9]+(\.[0-9]+)*$" \
  166             || continue
  167 
  168         devcount=$(($devcount + 1))
  169         if [ -d $devpath/$subdev ]; then
  170             print_device $devpath/$subdev \
  171                 $devnum $(($level +1)) $devcount
  172         fi
  173     done
  174 }
  175 
  176 if [ ! -d /sys/bus ]; then
  177     echo "Error: directory /sys/bus does not exist; is sysfs mounted?" >&2
  178     exit 1
  179 fi
  180 
  181 for device in $(ls /sys/bus/usb/devices/ | grep ^usb | sort -V)
  182 do
  183     print_device /sys/bus/usb/devices/$device 0 0 0
  184 done