Stop usbhid from claiming usb device on hotplug
Hi all, I'm writing a kernel module, but probe() is never called since usbhid claims the usb device as soon as the device is plugged in. Tried/potential solutions: #1: I have tried to write the usb hid id to /sys/bus/usb/drivers/usbhid/unbind (e.g. echo "1-1.1:1.4" > /sys/bus/usb/drivers/usbhid/unbind) and that properly unbinds the device from usbhid, but I want my module to claim the device when it's plugged in. Adding the above command to udev didn't do much as I couldn't find a way to tell my module to claim it as it was plugged in. It seems to me that usbhid claims the device, then udev rule unbinds it, but since usbhid already claimed it at plugin, my module's probe() wasn't called regardless. #2: I also tried unloading usbhid and loading my module and *then* usbhid. When the device was plugged in, usbhid still took over and my module's probe() still wasn't called. Even if that worked, it wouldn't feel like a proper solution. #3: I could potentially blacklist the device in drivers sources, but that doesn't seem a good option because I may want to have usbhid manage the device at some point At this point, I have no idea what else I could try! Any help or direction would be appreciated. Thanks.
On Fri, May 29, 2015 at 04:58:17PM -0400, Armin Moradi wrote:
Hi all,
I'm writing a kernel module, but probe() is never called since usbhid claims the usb device as soon as the device is plugged in.
What type of module for what type of device? And why do you want to override the hid driver from binding to it? thanks, greg k-h
I'm writing a kernel module, but probe() is never called since usbhid claims the usb device as soon as the device is plugged in.
What type of module for what type of device? And why do you want to override the hid driver from binding to it?
thanks,
greg k-h
I'm just learning about device drivers, so I'm writing a dummy usb device driver. I've pasted the code here (I hope the formatting is correct): #include <linux/init.h> #include <linux/kernel.h> #include <linux/module.h> #include <linux/usb.h> static int mmod_probe(struct usb_interface *intf, const struct usb_device_id *id) { pr_debug("mmod: probe is called"); /* return -ENODEV if we don't want to claim the device */ return 0; } static void mmod_disc(struct usb_interface *intf) { pr_debug("mmod: disconnected"); } static const struct usb_device_id mmod_id[] = { {.match_flags = USB_DEVICE_ID_MATCH_INT_PROTOCOL, .bInterfaceClass = 0x01 }, {} }; /* export the id to userspace */ MODULE_DEVICE_TABLE(usb, mmod_id); static struct usb_driver mmod_driver = { .name = "mmod_driver", .id_table = mmod_id, .probe = mmod_probe, .disconnect = mmod_disc }; static int __init init_task05(void) { pr_debug("mmod loaded"); usb_register(&mmod_driver); return 0; } static void __exit exit_mymod(void) { pr_debug("mmod unloaded"); usb_deregister(&mmod_driver); } module_init(init_mmod); module_exit(exit_mmod); MODULE_LICENSE("GPL"); I can load and unload the module and I can see the messages being printed. I can also see usbcore registering the new driver in dmesg, but when I plug any usb keyboard (which I have registered in id table), the probe never gets called. Instead, I see usbhid taking over and initializing the device in dmesg. And as far as intention goes, this is just for fun. I have thought about editing hid-core.c and adding usb quirks there and recompile the kernel, but that seems a bit drastic. I thought maybe there's a better way to do it. Thanks a lot, -- Armin Moradi
On Sat, May 30, 2015 at 01:43:20AM -0400, Armin Moradi wrote:
I'm writing a kernel module, but probe() is never called since usbhid claims the usb device as soon as the device is plugged in.
What type of module for what type of device? And why do you want to override the hid driver from binding to it?
thanks,
greg k-h
I'm just learning about device drivers, so I'm writing a dummy usb device driver. I've pasted the code here (I hope the formatting is correct):
This was for a challenge that doesn't want you to ask in public, sorry, I'm not going to answer it. best of luck, greg k-h
I think it is a part of eudyptula challenge and if it is so, just make sure that is it asking for probing or just for dynamic loading. On 30 May 2015 at 13:09, Greg KH <greg@kroah.com> wrote:
On Sat, May 30, 2015 at 01:43:20AM -0400, Armin Moradi wrote:
I'm writing a kernel module, but probe() is never called since usbhid claims the usb device as soon as the device is plugged in.
What type of module for what type of device? And why do you want to override the hid driver from binding to it?
thanks,
greg k-h
I'm just learning about device drivers, so I'm writing a dummy usb device driver. I've pasted the code here (I hope the formatting is correct):
This was for a challenge that doesn't want you to ask in public, sorry, I'm not going to answer it.
best of luck,
greg k-h
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
On 30 May 2015 at 13:09, Greg KH <greg@kroah.com> wrote:
On Sat, May 30, 2015 at 01:43:20AM -0400, Armin Moradi wrote:
I'm writing a kernel module, but probe() is never called since usbhid claims the usb device as soon as the device is plugged in.
What type of module for what type of device? And why do you want to override the hid driver from binding to it?
thanks,
greg k-h
I'm just learning about device drivers, so I'm writing a dummy usb device driver. I've pasted the code here (I hope the formatting is correct):
This was for a challenge that doesn't want you to ask in public, sorry, I'm not going to answer it.
best of luck,
greg k-h
Right. I'm already kicked from the challenge (my bad :( ), but I still wanted to know how this may be possible. Though, it's probably not a good idea to talk about this as others may be doing the challenge. Anyway, thanks for your help.
I think it is a part of eudyptula challenge and if it is so, just make sure that is it asking for probing or just for dynamic loading.
The challenge asked for userspace dynamic *loading* on hotplug which I had done, but while I was reading LDD 3rd ed., I also wanted to get probing to work which is done after the driver is already loaded. That's when I found out only one driver can claim a device and wanted to see if it were possible to change which driver binds which device at runtime without reloading usbhid or changing the order which modules are loaded. Thanks, -- Armin Moradi
On Sat, May 30, 2015 at 9:28 PM, <Valdis.Kletnieks@vt.edu> wrote:
On Sat, 30 May 2015 04:07:08 -0400, Armin Moradi said:
had done, but while I was reading LDD 3rd ed., I also wanted to get probing to work which is done after the driver is already loaded.
If it's a dummy driver, what device is it going to probe?
I have tried specifying a vendorID and productID in the id_table for one of the keyboards I have lying around. My expectation would be that the probe would get called when that device is connected, but I see usbhid initializing the keyboard and probe() not getting called at all.
participants (4)
-
Abhishek bist -
Armin Moradi -
Greg KH -
Valdis.Kletnieks@vt.edu