2

I am trying to write a kernel module which loads upon detection of USB Mouse. I am new to this stuff, I googled for this issue but couldn't find any appropriate solution.

can anyone please explain flow of this?

  • Presumably initially the kernel will do exactly the same for a USB mouse as for a USB sound card, since until it's gone some way through its procedures, it can't *know* whether the newly-connected device is a mouse or a sound card. So I'm interested, because what ***I*** want to know is whether it's possible to change ***the name of the device*** as reported elsewhere in the system. I have several different audio devices with similar names, and it's tiresome selecting the right one when I want to switch between output devices. – FumbleFingers May 10 '20 at 13:16
  • You should look at the Linux USB API documentation https://www.kernel.org/doc/html/v4.13/driver-api/usb/index.html and more precisely the writing drivers and hotplugging parts : https://www.kernel.org/doc/html/v4.13/driver-api/usb/writing_usb_driver.html https://www.kernel.org/doc/html/v4.13/driver-api/usb/hotplug.html – Mali May 11 '20 at 11:29
  • And maybe this one too, https://kernel.readthedocs.io/en/sphinx-samples/writing_usb_driver.html – Mali May 11 '20 at 14:47

1 Answers1

0

Very generic question, so very superficial answer:

The USB events bubble up to the part of the kernel that deals with new USB devices. This talks to the part of the kernel that can load modules on demand. This in turn looks for modules with an alias that fit the USB vendor and product id (or other USB fields). It may also make the decision by USB class.

Many USB mice are HID (human interface device) standard USB devices. In that case, the HID layer kicks in, the kernel will read the HID descriptor for the mouse, and interpret the HID events accordingly.

So if you could include information in your question about what kind of USB mouse it is (via lsusb -v), and why it doesn't work with the available drivers, that would be helpful...

dirkt
  • 31,679
  • 3
  • 40
  • 73