1

I need to use lsusb to determine the type of USB connection my USB has to know if dd is working at full speed. I read that to do this I need to use lsusb -t, but the output doesn't tell me which device node each entry corresponds to. How do I figure that out?

Melab
  • 1,219

4 Answers4

1

lsusb -t seems to provide a tree which lists "Dev X" - this corresponds to device "00X" in a standard "lsusb" listing.

Another alternative would be to use lsusb -v which "includes configuration descriptors for the devices current speed".

davidgo
  • 73,366
1

I've been fiddling with this for a while, here's a script I came up with to map the lsusb output to /sys. It seems to work for me but I haven't tested it extensively yet.

(Note: I'm not having much luck formatting this, so you might have to add some newlines or whatever)

#!/bin/bash
#
# usb2sys - find lsusb device in /sys file system
#

die()
{
    echo "$@"
    exit 1
}

[[ $# -lt 1 ]] && die "need vendor and product ids (from lsusb) as dddd:dddd"

vendor=${1%:*}
product=${1##*:}

sys=/sys/bus/usb/devices/
cd $sys

for d in *; do
    path=$sys/$d
    if [ -f $path/idProduct ]; then
      prod=$( cat $path/idProduct )
      vend=$( cat $path/idVendor )

      if [ $prod = $product -a $vend = $vendor ]; then
        echo prod = $prod
        echo vend = $vend
        echo /sys device is $path
        cat $path/power/wakeup
        echo ""
      fi
    fi
done
Joe
  • 19
0

As far as I know there is no single command or utility that will give you the information. You have to rummage for the information under /sys. See https://stackoverflow.com/questions/3493858/linux-how-to-map-a-blockdevice-to-a-usb-device for more information.

fpmurphy
  • 1,661
0

This is the output of lsusb -t for my system:

    # lsusb -t
    /:  Bus 04.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/2p, 480M
        |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/6p, 480M
    /:  Bus 03.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/2p, 480M
        |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/6p, 480M
            |__ Port 3: Dev 3, If 0, Class=Wireless, Driver=btusb, 12M
            |__ Port 3: Dev 3, If 1, Class=Wireless, Driver=btusb, 12M
    /:  Bus 02.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/4p, 5000M
        |__ Port 3: Dev 2, If 0, Class=Mass Storage, Driver=usb-storage, 5000M
    /:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/4p, 480M
        |__ Port 1: Dev 2, If 0, Class=Human Interface Device, Driver=usbhid, 12M
        |__ Port 1: Dev 2, If 1, Class=Human Interface Device, Driver=usbhid, 12M
        |__ Port 1: Dev 2, If 2, Class=Human Interface Device, Driver=usbhid, 12M
        |__ Port 2: Dev 3, If 0, Class=Vendor Specific Class, Driver=asix, 480M

The only mass storage device is located at Bus 02, Port 03, and it is served by the driver xhci_hcd, which is the proper Linux driver for USB3.0 devices. To the best of my knowledge, this si the only reference you will find to speed, here.

The above can be double-checked as follows. Since you are searching for a block device, go to /sys/class/block, where you can find:

# cd /sys/class/block/
root@debS:/sys/class/block# ls
loop0  loop2  loop4  loop6  sda   sda2  sda6  sdb
loop1  loop3  loop5  loop7  sda1  sda5  sda7  sdb1

Assuming you are interested in block device sdb, now you determine the bus address as follows:

# cd sdb; cd $(realpath $PWD); echo $PWD
/sys/devices/pci0000:00/0000:00:14.0/usb2/2-3/2-3:1.0/host6/target6:0:0/6:0:0:0/block/sdb

This (bus2, port 3) jibes with the above.

MariusMatutiae
  • 48,517
  • 12
  • 86
  • 136