Linux – How to disable USB devices based on their vendor ID on GNU/Linux

deviceslinuxnxtudevusb

In that question someone wanted a blacklist for all USB devices, and then only allow specific devices.

In this question, we want to accept all USB devices, but prevent the driver (e.g. cdc_acm) from taking one specific device type – for example, an LEGO® NXT brick in flash mode should not be taken (because fwflash needs raw access to the device), but an Arduino board should still be accessed by the driver to produce /dev/ttyACM0, in an educative environment accessing both NXT and Arduino hardware.

Best Answer

I’ve been able to do this with an udev rule, after some trickery (and using lsusb to find out the vendor and product ID of the device in flash mode):

$ cat /etc/udev/rules.d/nxt.rules
# disable NXT in flash mode
ACTION=="add", ATTR{idVendor}=="03eb", ATTR{idProduct}=="6124", RUN="/bin/sh -c '/bin/echo -n $kernel:1.0 | /usr/bin/tee /sys/bus/usb/drivers/cdc_acm/unbind | /usr/bin/logger -t nxt-flashmode'"

This rule is triggered when an NXT brick is plugged in while in flash mode, or put into flash mode while plugged in. It does not prevent cdc_acm from grabbing it, but immediately after tells it to release the device, so fwflash can access it.

I have not found out what the :1.0 is, and why use that and not :1.1 which also shows up in sysfs. However, I wanted to share a working (for me) solution. Environment: Debian unstable as of end of October, 2014 (i.e. pretty much Debian jessie).