Prevent usbhid from claiming USB device

15,950

Solution 1

I've solved this part of the problem:

  • OPTIONS=="ignore_device" was removed from the kernel (commit)
  • blacklist usbhid didn't do anything, not even blocked my keyboard
  • A configuration file in /etc/modprobe.d with options usbhid quirks=0xdead:0xbeef:0x0004 did not work because usbhid was not compiled as module

So, I added usbhid.quirks=0xdead:0xbeef:0x4 to the boot command line (on Raspbian, that's in /boot/cmdline.txt) and usbhid does not bind the device anymore.


My original problem, however, still remains. I always get a read/timeout error when accessing the RFID reader the first time.

Solution 2

I had the same problem and I solved modifying the udev rules file like this:

SUBSYSTEM=="input", GROUP="input", MODE="0666"
SUBSYSTEM=="usb", ATTRS{idVendor}=="4242", ATTRS{idProduct}=="e131", MODE:="666", GROUP="users"

And now I can read the RFID logger by using libusb functions.

Share:
15,950
AndiDog
Author by

AndiDog

Principal Engineer, improving engineering by means of knowledge and practice sharing, automation, tooling. Developing with C++/Python/TypeScript/Rust/Go/Kubernetes... choice doesn't matter much, as long as you stick with it.

Updated on September 18, 2022

Comments

  • AndiDog
    AndiDog over 1 year

    Directly related: Prevent claiming of novelty usb device by usbhid so I can control it with libusb?

    I want to access an RFID reader (works as HID device) from a program that uses libusb-0.1. In the code, the kernel driver is correctly detached with usb_detach_kernel_driver_np (no errors), but is seems that whenever my program tries to access the USB device, the usbhid module reclaims it. The following error always appears in dmesg:

    usb 1-1.3: usbfs: interface 0 claimed by usbhid while 'MyProgram' sets config #1

    I've added the following udev rule, restarted udevd and replugged the device, but without effect. It is supposed to blacklist the device from being used by usbhid.

    # I anonymized the vendor/product IDs here
    ATTRS{idVendor}=="dead", ATTRS{idProduct}=="beef", OPTIONS=="ignore_device"
    

    Apart from dmesg output, I can see in /sys/bus/usb/drivers/usbhid/ that the device 1-1.3:1.0 is recreated every time, so the blacklisting doesn't seem to work.

    Anything else I could try? The operating system is Raspbian (on a Raspberry Pi) with kernel 3.2.27.