LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Ubuntu (http://www.linuxquestions.org/questions/ubuntu-63/)
-   -   Load module on usb dongle insert... (http://www.linuxquestions.org/questions/ubuntu-63/load-module-on-usb-dongle-insert-843842/)

wilku 11-12-2010 03:47 AM

Load module on usb dongle insert...
 
Hi,

I have a problem with a wireless mouse on my laptop running Ubuntu 10.10. If thw receiver is plugged during boot, it works out of the box. But if I plug it in afterwards, I have to manually do
Code:

sudo modprobe usbhid
for it to start workin.

My question is how to automatically load a module when a usb device with a given id is inserted?

Cheers
Tomek

wilku 11-12-2010 05:17 AM

I've learned that the correct word is "hotplug" ;)

I have added new file usbhid.conf to /etc/modprobe.d/ with the following content
Code:

#Labtec usb wireless mouse
#alias usb:v1020p0206d*dc*dsc*dp*ic*isc*ip* usbhid
alias usb:v1020p0206d0104dc00dsc00dp00ic03isc01ip02 usbhid

Still no candy. Neither version of alias works. I got the modalias string somewhere from /sys. This is the correct modalias, as the vendor and product id match with lsusb output:
Code:

Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 003: ID 1020:0206 Labtec
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 002: ID 0846:4260 NetGear, Inc. WG111v3 54 Mbps Wireless [realtek RTL8187B]
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Any ideas?

GrapefruiTgirl 11-12-2010 05:26 AM

Quote:

Originally Posted by wilku (Post 4156583)
.

My question is how to automatically load a module when a usb device with a given id is inserted?

Cheers
Tomek

I suggest that "UDEV Rules" would be a good way to accomplish what you're doing. You *may* be able to do (some or all of) it by the way you're doing, but I believe that using UDEV Rules would be more appropriate.

The location of your rules directory may be different depending on your distro, but /etc/udev/rules.d or /lib/udev/rules.d are two common locations.

There are loads of LQ threads dealing with udev rules, and also some pretty good tutotials on the 'net about this topic as well. See Google.

In a udev rule, you can use that 'modalias' value, provided it is unique from all modaliases of your other devices, as part of the matching criteria, and tell udev to insert the usbhid driver when it finds this device, as well as any other things you wish to perform when the device is connected (run a script, issue some commands, etc..).

Best of luck, whichever way you go.

wilku 11-12-2010 05:42 AM

Thank you very much!

I have added this file to /etc/udev/rules.d:
Code:

#Labtec wireless mouse
ACTION=="add", SUBSYSTEM=="usb", MODALIAS=="v1020p0206*", RUN+="/sbin/modprobe usbhid"

It started working. I wonder why it didn't the other way though...
Well, nevermind, it works this way.
Thank you once more.

GrapefruiTgirl 11-12-2010 05:45 AM

I don't know all the ins and outs of this stuff and how everything ties together, but I figure that both modprobe.d/* and the udev rules, play a role, depending precisely when the device is detected; i.e.: is it found during boot, and/or is it found when it is inserted later.

For example, the UDEV rule probably plays a role first, and then, modprobe.d/* are consulted to look for any options or whatever, that are associated with the module being inserted by udev.

If someone has anything to add on this subject, I would be interested in hearing more.

Meanwhile, it's good to hear that you've got some success here!

Cheers.


All times are GMT -5. The time now is 02:26 AM.