I found a solution:
First of all, I am still using udev rules, but I changed it the following way:
Code:
ln1 # Rule to disable all devices (Should not be active in the same time as the rule here below)
ln2 ACTION=="add", SUBSYSTEM=="usb", RUN+="/bin/sh -c 'for host in /sys/bus/usb/devices/usb*; do echo 0 > $host/authorized_default; done'"
ln3
ln4 # Rule to enable all devices (Should not be active in the same time as the rule here above)
ln5 #ACTION=="add", SUBSYSTEM=="usb", RUN+="/bin/sh -c 'for host in /sys/bus/usb/devices/usb*; do echo 1 > $host/authorized_default; done'"
ln6
ln7 # Rule to authorize the keyboard/mouse dongle
ln8 ACTION=="add", ATTR{idVendor}=="046d", ATTR{idProduct}=="c529", RUN+="/bin/sh -c 'echo 1 > /sys$DEVPATH/authorized'"
ln9 ACTION=="add", ATTR{idVendor}=="046d", ATTR{idProduct}=="c529", RUN+="/bin/sh -c 'echo 1 > /sys$DEVPATH/authorized_default'"
So, to follow my application execution process: (1) on start-up of my machine, only the keyboard/mouse is active. If any other usb devices are connected, they are not 'active' (but they are detected if the lsusb command is executed --> this is the reason why I changed the content of my rule).
(2) when I click on a button to enable the usb ports, through the execution of a script, I change my rule the following way: I comment line 2 and I uncomment line 5. At this point, we need to load and make the rules active. Once the file is updated, I apply through my script the two following command:
Code:
sudo udevadm control --reload
sudo udevadm trigger --action=add
When I plug in a usb device, it is available !
(3) To go back, I re-update my rule file in its initial state, reload and trigger.
There is one pitfall in my solution, but I can live with it because it is not critical for me: Once the rule to disable all usb has been reapplied after step 3, if the usb device has not been removed (i.e. plugged out), it is still active - until it is plugged out and then plugged in : because the effect is on "trigger action add".
To be complete, this link helped me along the way.
Bookmarks