How to load a module (not a driver) when a USB device is plugged in

Jatinshravan
#include<linux/init.h>
#include<linux/module.h>
#include <linux/usb/input.h>
#include <linux/hid.h>

/*
 * Version information
*/
#define DRIVER_VERSION ""
#define DRIVER_DESC "Hello World module"
#define DRIVER_LICENSE "GPL"

MODULE_LICENSE(DRIVER_LICENSE);
MODULE_AUTHOR(DRIVER_AUTHOR);

static void __exit hello_world_exit(void)
{
    pr_debug("Bye!\n");
}

static int __init hello_world_init(void)
{
pr_debug("Hello, USB!");
return 0;
}

static struct usb_device_id usb_kbd_id_table[] = {
{ USB_INTERFACE_INFO(USB_INTERFACE_CLASS_HID,
        USB_INTERFACE_SUBCLASS_BOOT,
        USB_INTERFACE_PROTOCOL_KEYBOARD) },
{}
};

MODULE_DEVICE_TABLE(usb, usb_kbd_id_table);

module_init(hello_world_init);
module_exit(hello_world_exit);

How do I make the kernel load this module load when a USB mouse is plugged in (using the userspace hotplug tools) ? Right now, I have put the hello_world.ko file in /lib/modules/$(uname -r) and run depmod -a.

Eugene Sh.

In modern Linux the functionality for loading drivers/modules (or invoking any other commands) whenever new hardware is detected is handled by udev. You will have to write a udev rule for your device that will instruct the kernel to load your module when your device has been detected and the corresponding event has occurred. Read more about it here.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to be notified when a USB device was plugged in?

From Dev

How to load my custom driver module on USB device connected?

From Dev

How can I determine the version of a device driver when the device is not plugged in?

From Dev

How to know when Android device is plugged into USB port?

From Dev

How can I start a systemd service when a given USB device (ethernet dongle) is plugged in?

From Dev

How to get udev to identify a USB device regardless of the USB port it is plugged in?

From Dev

How to create a job with WorkManager when device is plugged in?

From Java

Prevent usbhid from autoloading when USB HID device is plugged in

From Dev

Which code is running when device is off and USB is plugged in?

From Dev

Wi-fi turns off when USB device is plugged in

From Dev

Change tkinter menu when a USB device is plugged in or taken out

From Dev

How to redirect sound to USB headset when plugged in?

From Dev

How to assign USB driver to device

From Dev

How to auto-sync with a plugged-in USB mass storage device?

From Dev

udev rule to auto load keyboard layout when usb keyboard plugged in

From Java

How can I bind a driver with a USB device?

From Dev

How can I remotely determine if a USB3.0 device is plugged into a USB3.0 port?

From Dev

How to make my application run automatically when USB drive is plugged in?

From Dev

How can I automatically switch to USB headset when plugged in?

From Dev

How to run a python script with imports when usb plugged into Linux machine?

From Dev

Detect if a USB device is plugged in Javascript from browser

From Dev

Identify what USB port is a device plugged into

From Dev

Windows 10 usb 3.1 port stops working when device is plugged in another

From Dev

Disable one component of USB composite device that causes bluescreen when plugged in or booted

From Dev

How to find the driver (module) associated with a device on Linux?

From Dev

Automatically sync a folder to a USB when USB is plugged in?

From Dev

How can I be sure that I've plugged a device into a USB 3 port?

From Dev

How can I run code whenever a USB device is (un)plugged, without requiring root permissions?

From Dev

How can I run a Bash script every time is plugged an USB device?

Related Related

  1. 1

    How to be notified when a USB device was plugged in?

  2. 2

    How to load my custom driver module on USB device connected?

  3. 3

    How can I determine the version of a device driver when the device is not plugged in?

  4. 4

    How to know when Android device is plugged into USB port?

  5. 5

    How can I start a systemd service when a given USB device (ethernet dongle) is plugged in?

  6. 6

    How to get udev to identify a USB device regardless of the USB port it is plugged in?

  7. 7

    How to create a job with WorkManager when device is plugged in?

  8. 8

    Prevent usbhid from autoloading when USB HID device is plugged in

  9. 9

    Which code is running when device is off and USB is plugged in?

  10. 10

    Wi-fi turns off when USB device is plugged in

  11. 11

    Change tkinter menu when a USB device is plugged in or taken out

  12. 12

    How to redirect sound to USB headset when plugged in?

  13. 13

    How to assign USB driver to device

  14. 14

    How to auto-sync with a plugged-in USB mass storage device?

  15. 15

    udev rule to auto load keyboard layout when usb keyboard plugged in

  16. 16

    How can I bind a driver with a USB device?

  17. 17

    How can I remotely determine if a USB3.0 device is plugged into a USB3.0 port?

  18. 18

    How to make my application run automatically when USB drive is plugged in?

  19. 19

    How can I automatically switch to USB headset when plugged in?

  20. 20

    How to run a python script with imports when usb plugged into Linux machine?

  21. 21

    Detect if a USB device is plugged in Javascript from browser

  22. 22

    Identify what USB port is a device plugged into

  23. 23

    Windows 10 usb 3.1 port stops working when device is plugged in another

  24. 24

    Disable one component of USB composite device that causes bluescreen when plugged in or booted

  25. 25

    How to find the driver (module) associated with a device on Linux?

  26. 26

    Automatically sync a folder to a USB when USB is plugged in?

  27. 27

    How can I be sure that I've plugged a device into a USB 3 port?

  28. 28

    How can I run code whenever a USB device is (un)plugged, without requiring root permissions?

  29. 29

    How can I run a Bash script every time is plugged an USB device?

HotTag

Archive