24

I would like to bind/unbind my usb device - a wireless adapter.

echo -n "1-1:1.0" > /sys/bus/usb/drivers/ub/unbind

So to able to do that, I need the bus ID. lsusb prints out the following:

Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp. 
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. 
Bus 001 Device 004: ID 148f:2573 Ralink Technology, Corp. RT2501/RT2573 Wireless Adapter

And lsusb -t:

/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=dwc_otg/1p, 480M
    |__ Port 1: Dev 2, If 0, Class=hub, Driver=hub/3p, 480M
        |__ Port 1: Dev 3, If 0, Class=vend., Driver=smsc95xx, 480M
        |__ Port 2: Dev 4, If 0, Class=vend., Driver=rt73usb, 480

So where can I find this bus ID? Thanks!
Update: here is the detailed info about the wireless devide: (lsusb -v | grep -E '\<(Bus|iProduct|bDeviceClass|bDeviceProtocol)' 2>/dev/null)

Bus 001 Device 004: ID 148f:2573 Ralink Technology, Corp. RT2501/RT2573 Wireless Adapter
  bDeviceClass            0 (Defined at Interface level)
  bDeviceProtocol         0 
  iProduct                2
3
  • maybe this will help you: lsusb -v | grep -E '\<(Bus|iProduct|bDeviceClass|bDeviceProtocol)' 2>/dev/null
    – LilloX
    Nov 12, 2015 at 11:27
  • @LilloX updated the question, can you please help to find that id?
    – laplasz
    Nov 12, 2015 at 11:34
  • 2
    In you situation: Bus=1, Port=2 so: echo -n "1-2" > /sys/bus/usb/drivers/usb/unbind You don't need the device number
    – LilloX
    Nov 12, 2015 at 12:58

5 Answers 5

18

You can read off the sequence from the device tree you get with lsusb -t. The number before the hyphen is the bus, the numbers after the hyphen are the port sequence. Your device is on bus 01, on port 1 of the root hub for this bus is another hub, and on port 3 of this hub is your device: So you get 1-1.3.

If you know the vendor id from lsusb (like 148f for Ralink), you can also grep for it with

grep 148f /sys/bus/usb/devices/*/idVendor

and you'll get something like

/sys/bus/usb/devices/1-1.3/idVendor:148f

as answer. If there are several devices from the same vendor, you can narrow it down with idProduct.

2
  • 1
    Why is it not 1-1.1.3 as those are the port numbers walking down the tree?
    – AndreKR
    Jul 23, 2019 at 22:44
  • I agree that the recent suggested edit wasn’t very good, but it did highlight the fact that this answer could be improved by expanding on the last sentence. Sep 11, 2020 at 19:17
7

As I was grepping for the productVendor 😭 I kept thinking this can't be so hard (though inventive)... Might as well RTFM. man lsusb:

-t, --tree
              Tells lsusb to dump the physical USB device hierarchy as a tree. Verbosity can be increased twice with the v option.

...twice. TWICE. lsusb -tvv:

/:  Bus 06.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M
    ID 1d6b:0001 Linux Foundation 1.1 root hub
    /sys/bus/usb/devices/usb6  /dev/bus/usb/006/001
    |__ Port 2: Dev 2, If 0, Class=Wireless, Driver=btusb, 12M
        ID 0bda:8771 Realtek Semiconductor Corp.
        /sys/bus/usb/devices/6-2  /dev/bus/usb/006/002 <--these guys right here
    |__ Port 2: Dev 2, If 1, Class=Wireless, Driver=btusb, 12M
        ID 0bda:8771 Realtek Semiconductor Corp.
        /sys/bus/usb/devices/6-2  /dev/bus/usb/006/002
1
  • Thanks for that! Here is a oneliner with awk to get the deviceId given you know the vendor/product: lsusb -tvv | awk '/046d:c52b/ { getline; print gensub(/.*devices\/([0-9\-\.]*)/, "\\1", "g", $1); exit; }'
    – Amir
    Mar 19 at 0:45
3

finally I found the right bus ID of the usb device. There is a file listing all the IDs - /sys/bus/usb/devices/ and the content is the following:

root@raspberrypi:/home/pi# ls /sys/bus/usb/devices
1-0:1.0  1-1  1-1.1  1-1:1.0  1-1.1:1.0  1-1.3  1-1.3:1.0  usb1

and the corresponding lsusb:

root@raspberrypi:/home/pi# lsusb -t
/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=dwc_otg/1p, 480M
    |__ Port 1: Dev 2, If 0, Class=hub, Driver=hub/3p, 480M
        |__ Port 1: Dev 3, If 0, Class=vend., Driver=smsc95xx, 480M
        |__ Port 3: Dev 17, If 0, Class=vend., Driver=rt73usb, 480M

root@raspberrypi:/home/pi# lsusb
Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp. 
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. 
Bus 001 Device 017: ID 148f:2573 Ralink Technology, Corp. RT2501/RT2573 Wireless Adapter

so I tried 1-1.3 as an ID and it worked. But 1-3 did not.

root@raspberrypi:/home/pi# echo -n "1-3" > /sys/bus/usb/drivers/usb/unbind
bash: echo: write error: No such device
1

Here is an example where I was trying to do the same thing on Ubuntu 16.04 for USB-Ethernet device:

anurag@anurag-ThinkPad-E470:~$ lsusb
Bus 002 Device 003: ID 0b95:1790 ASIX Electronics Corp. AX88179 Gigabit Ethernet
Bus 002 Device 002: ID 0424:5744 Standard Microsystems Corp.
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 007: ID 138a:0011 Validity Sensors, Inc. VFS5011 Fingerprint Reader

We want to unbind the first device. You can see the driver instance created in sysfs and within the driver, an instance of the USB bus address of the Ethernet Dongle:

anurag@anurag-ThinkPad-E470:/sys/bus/usb/drivers$ ls
ax88179_178a  btusb  hub  r8188eu  usb  usbfs  usbhid  uvcvideo
anurag@anurag-ThinkPad-E470:/sys/bus/usb/drivers/ax88179_178a$ ls
2-2.2:1.0  bind  module  new_id  remove_id  uevent  unbind

If you plug in another dongle of same type, you can now see two devices:

anurag@anurag-ThinkPad-E470:/sys/bus/usb/drivers/ax88179_178a$ ls
2-2.1:1.0  2-2.2:1.0  bind  module  new_id  remove_id  uevent  unbind

At this point you can see two net devices:

anurag@anurag-ThinkPad-E470:~$ ip link show
....
6: enx000ec6cd8d75: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN mode DEFAULT group default qlen 1000
    link/ether 00:0e:c6:cd:8d:75 brd ff:ff:ff:ff:ff:ff
7: enx000ec6cd8d90: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN mode DEFAULT group default qlen 1000
    link/ether 00:0e:c6:cd:8d:90 brd ff:ff:ff:ff:ff:ff

You can unbind like so:

anurag@anurag-ThinkPad-E470:/sys/bus/usb/drivers/ax88179_178a$ sudo sh -c "echo 2-2.2:1.0 > unbind"
[sudo] password for anurag:
anurag@anurag-ThinkPad-E470:/sys/bus/usb/drivers/ax88179_178a$ ls
2-2.1:1.0  bind  module  new_id  remove_id  uevent  unbind

And the device will no longer show up in the interface list:

anurag@anurag-ThinkPad-E470:~$ ip link show
....
6: enx000ec6cd8d75: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN mode DEFAULT group default qlen 1000
    link/ether 00:0e:c6:cd:8d:75 brd ff:ff:ff:ff:ff:ff

Note that just issuing sudo echo 2-2.2:1.0 > unbind doesn’t work because that only elevates permission for the echo command and not for the redirection. Hence we use temporarily elevated shell. The unbind is writable only by root user.

1

For me the easiest way to find Bus ID:device ID (nnn:mmm) is with:

watch -n 0.5 -d lsusb

This wil run lsusb every half a second and highlight the differences between runs. Just plug and replug the device and the related device will be highlighted.

Bus 001 Device 006 # → Bus ID: 001, Device: ID 006

Reference.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .