How to Prevent Linux from Initializing a Usb Hid Device

How can I prevent linux from initializing a USB HID device

you have right, you have to play with the udev rules.

First of all you have to identify your device. Find the idProduct and the idVendor of your device. You can use:

lsusb

Then in the rules.d folder (/etc/udev/rules.d) create a new file with the name:

10-my-usb.rules

In this file add this line

SUBSYSTEM=="usb",ATTRS{idVendor}=="XXXX", ATTRS{idProduct}=="XXXX", MODE="666", GROUP+="plugdev"

Replace the XXXX with the value you get before

Then restart your udev rules:

sudo udevadm trigger

Then unplug and replug normally you can use it

Prevent usbhid from autoloading when USB HID device is plugged in

udev is the best and easiest way doing that, add a new rule in e.g.:
/etc/udev/rules.d/99-disable-usb-hid.rules:

SUBSYSTEMS=="usb", DRIVERS=="usbhid", ACTION=="add", ATTR{authorized}="0"

and restart udev.
I've just tested it in Debian Jessie ARM 4.4.16.

How could be notified once USB device is attached/detached in linux system and read the file from USB

I'd add udev rule first with running your custom script. Something like:

ACTION=="add", KERNEL=="sd?1", SUBSYSTEMS=="usb", RUN+="/path/to/your/script %k"

%k is kernel parameter that is passed to your script.

From udev man:

$kernel, %k
The kernel name for this device.

In the script I'd use curl. If you don't need some tricky logic. If so, I'd use python.

Anyway I think udev is perfect for this problem.



Related Topics



Leave a reply



Submit