binding/unbinding usb drivers a.k.a. who stole my hidraw1 device file

Hi!
Recently I was playing with using my HID device differently then usual: I used the libusb library. Instead opening a raw file /dev/hidraw1, I used libusb_open_device_with_vid_pid().
Everything was working properly, then it was a time to go back using the hidraw file… but wait: where is my hidraw1 device?

It seems it was gone since I opened it with libusb:

# ll /dev/hidraw*
crw-------    1 root     0         247,   0 Oct 19 18:49 /dev/hidraw0
crw-------    1 root     0         247,   2 Jan  1  1970 /dev/hidraw2
crw-------    1 root     0         247,   3 Jan  1  1970 /dev/hidraw3

As you can see – hidraw1 is missing.

Fortunately I found a solution to this issue which I am now sharing here (also for me).
When I typed lsusb -t to list all my devices I’ve got:

# 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=Vendor Specific Class, Driver=smsc95xx, 480M
        |__ Port 3: Dev 4, If 0, Class=Hub, Driver=hub/4p, 480M
            |__ Port 2: Dev 5, If 0, Class=Hub, Driver=hub/4p, 480M
                |__ Port 4: Dev 7, If 0, Class=Hub, Driver=hub/4p, 480M
                    |__ Port 4: Dev 9, If 0, Class=Human Interface Device, Driver=usbhid, 1.5M
                    |__ Port 4: Dev 9, If 1, Class=Human Interface Device, Driver=usbhid, 1.5M
            |__ Port 3: Dev 123, If 1, Class=CDC Data, Driver=cdc_acm, 12M
            |__ Port 3: Dev 123, If 2, Class=Human Interface Device, Driver=usbhid, 12M
            |__ Port 3: Dev 123, If 0, Class=Communications, Driver=cdc_acm, 12M
            |__ Port 4: Dev 8, If 0, Class=Human Interface Device, Driver=usbfs, 1.5M

The device which I want back is in the last line. Note the Driver=usbfs. This is the key part – the device is bound to usbfs driver instead of usbhid.
I had to unbind the device from usbfs driver and bind back to usbhid.
To do it I entered /sys/bus/usb/drivers/usbfs and typed:

/sys/bus/usb/drivers/usbfs # ls -la
total 0
drwxr-xr-x    2 root     0                0 Oct 23 18:35 .
drwxr-xr-x    9 root     0                0 Oct 23 18:35 ..
lrwxrwxrwx    1 root     0                0 Oct 23 18:42 1-1.3.4:1.0 -> ../../../../devices/platform/soc/20980000.usb/usb1/1-1/1-1.3/1-1.3.4/1-1.3.4:1.0
--w-------    1 root     0             4096 Oct 23 18:42 bind
lrwxrwxrwx    1 root     0                0 Oct 23 18:42 module -> ../../../../module/usbcore
-rw-r--r--    1 root     0             4096 Oct 23 18:42 new_id
-rw-r--r--    1 root     0             4096 Oct 23 18:42 remove_id
--w-------    1 root     0             4096 Oct 23 18:42 uevent
--w-------    1 root     0             4096 Oct 23 18:42 unbind

As you can see the device “1-1.3.4:1.0” (you can correlate this path with lsusb -t) is listed here (bound).
I typed:

/sys/bus/usb/drivers/usbfs # echo -n "1-1.3.4:1.0" > unbind
sh: write error: No such device

Despite this error when I looked again the device is not bind there anymore:

/sys/bus/usb/drivers/usbfs # ls -la
total 0
drwxr-xr-x    2 root     0                0 Oct 23 18:35 .
drwxr-xr-x    9 root     0                0 Oct 23 18:35 ..
--w-------    1 root     0             4096 Oct 23 18:42 bind
lrwxrwxrwx    1 root     0                0 Oct 23 18:42 module -> ../../../../module/usbcore
-rw-r--r--    1 root     0             4096 Oct 23 18:42 new_id
-rw-r--r--    1 root     0             4096 Oct 23 18:42 remove_id
--w-------    1 root     0             4096 Oct 23 18:42 uevent
--w-------    1 root     0             4096 Oct 23 18:44 unbind

Now it was a time to bound it to usbhid (first typing cd ../usbhid):

/sys/bus/usb/drivers/usbhid # ll
total 0
drwxr-xr-x    2 root     0                0 Oct 23 18:35 .
drwxr-xr-x    9 root     0                0 Oct 23 18:35 ..
lrwxrwxrwx    1 root     0                0 Oct 23 18:35 1-1.3.2.4.4:1.0 -> ../../../../devices/platform/soc/20980000.usb/usb1/1-1/1-1.3/1-1.3.2/1-1.3.2.4/1-1.3.2.4.4/1-1.3.2.4.4:1.0
lrwxrwxrwx    1 root     0                0 Oct 23 18:35 1-1.3.2.4.4:1.1 -> ../../../../devices/platform/soc/20980000.usb/usb1/1-1/1-1.3/1-1.3.2/1-1.3.2.4/1-1.3.2.4.4/1-1.3.2.4.4:1.1
lrwxrwxrwx    1 root     0                0 Oct 23 18:35 1-1.3.3:1.2 -> ../../../../devices/platform/soc/20980000.usb/usb1/1-1/1-1.3/1-1.3.3/1-1.3.3:1.2
--w-------    1 root     0             4096 Oct 23 18:35 bind
lrwxrwxrwx    1 root     0                0 Oct 23 18:35 module -> ../../../../module/usbhid
-rw-r--r--    1 root     0             4096 Oct 23 18:35 new_id
-rw-r--r--    1 root     0             4096 Oct 23 18:35 remove_id
--w-------    1 root     0             4096 Oct 23 18:35 uevent
--w-------    1 root     0             4096 Oct 23 18:35 unbind
/sys/bus/usb/drivers/usbhid # echo -n "1-1.3.4:1.0" > bind
/sys/bus/usb/drivers/usbhid # ll
total 0
drwxr-xr-x    2 root     0                0 Oct 23 18:35 .
drwxr-xr-x    9 root     0                0 Oct 23 18:35 ..
lrwxrwxrwx    1 root     0                0 Oct 23 18:35 1-1.3.2.4.4:1.0 -> ../../../../devices/platform/soc/20980000.usb/usb1/1-1/1-1.3/1-1.3.2/1-1.3.2.4/1-1.3.2.4.4/1-1.3.2.4.4:1.0
lrwxrwxrwx    1 root     0                0 Oct 23 18:35 1-1.3.2.4.4:1.1 -> ../../../../devices/platform/soc/20980000.usb/usb1/1-1/1-1.3/1-1.3.2/1-1.3.2.4/1-1.3.2.4.4/1-1.3.2.4.4:1.1
lrwxrwxrwx    1 root     0                0 Oct 23 18:35 1-1.3.3:1.2 -> ../../../../devices/platform/soc/20980000.usb/usb1/1-1/1-1.3/1-1.3.3/1-1.3.3:1.2
lrwxrwxrwx    1 root     0                0 Oct 23 18:45 1-1.3.4:1.0 -> ../../../../devices/platform/soc/20980000.usb/usb1/1-1/1-1.3/1-1.3.4/1-1.3.4:1.0
--w-------    1 root     0             4096 Oct 23 18:45 bind
lrwxrwxrwx    1 root     0                0 Oct 23 18:35 module -> ../../../../module/usbhid
-rw-r--r--    1 root     0             4096 Oct 23 18:35 new_id
-rw-r--r--    1 root     0             4096 Oct 23 18:35 remove_id
--w-------    1 root     0             4096 Oct 23 18:35 uevent
--w-------    1 root     0             4096 Oct 23 18:35 unbind

And I’ve got back my missing hidraw1 device:

~ # ll /dev/hidraw*
crw-------    1 root     0         247,   0 Oct 19 18:49 /dev/hidraw0
crw-------    1 root     0         247,   1 Oct 23 18:45 /dev/hidraw1
crw-------    1 root     0         247,   2 Jan  1  1970 /dev/hidraw2
crw-------    1 root     0         247,   3 Jan  1  1970 /dev/hidraw3

The driver change is also confirmed in ‘lsusb -t‘:

# 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=Vendor Specific Class, Driver=smsc95xx, 480M
        |__ Port 3: Dev 4, If 0, Class=Hub, Driver=hub/4p, 480M
            |__ Port 2: Dev 5, If 0, Class=Hub, Driver=hub/4p, 480M
                |__ Port 4: Dev 7, If 0, Class=Hub, Driver=hub/4p, 480M
                    |__ Port 4: Dev 9, If 0, Class=Human Interface Device, Driver=usbhid, 1.5M
                    |__ Port 4: Dev 9, If 1, Class=Human Interface Device, Driver=usbhid, 1.5M
            |__ Port 3: Dev 123, If 1, Class=CDC Data, Driver=cdc_acm, 12M
            |__ Port 3: Dev 123, If 2, Class=Human Interface Device, Driver=usbhid, 12M
            |__ Port 3: Dev 123, If 0, Class=Communications, Driver=cdc_acm, 12M
            |__ Port 4: Dev 8, If 0, Class=Human Interface Device, Driver=usbhid, 1.5M

Leave a Reply

Your email address will not be published. Required fields are marked *