Linux: How to assign USB driver to device

12,684

This question sounds a lot like a USB device containing a small flash disk which contains the Windows driver, but actually it's a sort of network access device (UMTS modem comes to my mind). If this is the case, try to use USB_ModeSwitch, which contains a database of USB devices and the commands and data which must be used to move the device from "storage mode" to "network access mode". If the device is not configured in the database, Usb Sniffer for Windows can be used on Windows to trace the USB traffic and extract the necessary command/data combo.

Automation of usb_modeswitch, so that it performs it's magic when you plug in your device can be done using udev rules. If you're using a Fedora or Ubuntu based distribution, this is handled for you when you install the packages providing usb_modeswitch (sorry I've no info about SUSE but i think it's similar).In Fedora it's the package use_modeswitch_data, which provides a wrapper for the usb_modeswitch cmd and the necessary rule files.

If you really want bind/unbind USB devices to drivers, see this LWN article. As root, echo $usbid > /sys/bus/usb/drivers/usb-storage/unbind will unbind the USB device with $usbid from the "usb-storage" driver. Using the same command, but using bind instead of unbind, will try to bind the device to the driver. But be aware that it makes no sense (and will not work) to bind a device which acts like a storage device to a usbnet driver.

Share:
12,684
linsek
Author by

linsek

Updated on June 04, 2022

Comments

  • linsek
    linsek almost 2 years

    This question is two-fold:

    1- How do you manually detach a driver from a USB device and attach a different one? For example, I have a device that when connected automatically uses the usb-storage driver.

    // usbview output

    Vendor Id: xxxx
    Product Id: xxxx
    ...
        Number of Interfaces: 2
        Interface Number: 0
            Name: usb-storage
            Number of Endpoints: 2
            ...
        Interface Number: 1
            Name: (none)
            Number of Endpoints: 2
            ...
    

    I do not want to use the usb-storage driver, so I have an application running on the host in which I use the libusb library to detach the usb-storage driver and then I claim the interface. I then can send data to and from the applications running on my USB device and on my host Linux system.

    How do you detach a driver manually outside of an application?

    2- How do I automatically assign the driver to attach on device plugin. I currently have a udev rule setup to set the device permissions automatically.

    SUBSYSTEM=="usb", ATTR{idVendor}=="xxxx", MODE="0666"
    

    Can I use udev rules to assign drivers to specific interfaces on the USB device? For example, if I wanted the usbnet module to be used on automatically on interface 0 instead of usb-storage, is that possible in udev?

    Thanks,

    (I'm a little confused about how StackExchange works with it's different sites or if they are all the same. This is a Linux question so it was also posted on Unix & Linux. Forgive me if it shouldn't be posted here too, but StackOverflow also handles Linux, so...)

  • bofh.at
    bofh.at over 12 years
    If you really want bind/unbind USB devices to drivers, see this LWN article. # echo $usbid > /sys/bus/usb/drivers/usb-storage/unbind will unbdind the usb device with $usbid from the "usb-storage" driver. The same cmdline, but using "bind" instead of unbind, will try to bind the device to the driver. But be aware that it makes no sense (and will not work) to bind a device which acts like a storage device to a usbnet driver.