Linux(CentOS) - USB device driver - MODULE_DEVICE_TABLE - probe function July 18, 2018 12:04AM |
#include <linux/init.h> // Macros used to mark up functions e.g., __init __exit #include <linux/module.h> // Core header for loading LKMs into the kernel #include <linux/kernel.h> // Contains types, macros, functions for the kernel // Includes for Major/Minor #include <linux/types.h> #include <linux/kdev_t.h> #include <linux/fs.h> // For registering devices, blocking/non-blocking #include <asm/uaccess.h> #include <linux/slab.h> //Used when kmalloc or kzalloc is called #include <linux/usb.h> #define SUCCESS 0 #define DEVICE_NAME "hello_world" #define BUF_LEN 80 MODULE_LICENSE("GPL" ///The license type -- this affects runtime behavior MODULE_AUTHOR("Mohit Gupta"
; ///The author -- visible when you use modinfo MODULE_DESCRIPTION("A simple Hello World USB driver"
; ///The description -- see modinfo MODULE_VERSION("0.1"
; ///< The version of the module static int usb_probe(struct usb_interface* interface, const struct usb_device_id* id) { printk(KERN_INFO "USBHelloWorld: (%04X:%04X) plugged\n", id->idVendor, id->idProduct); return 0; } static void usb_disconnect(struct usb_interface* interface) { printk(KERN_INFO "USBHelloWorld: USB device removed\n"
; } /* Table of devices that work with this driver */ static struct usb_device_id usb_table[] = { //{ USB_DEVICE(USB_SKEL_VENDOR_ID, USB_SKEL_PRODUCT_ID) }, { USB_DEVICE(0x058F, 0x6387) }, { USB_DEVICE(0x80ee, 0x0021) }, /*VirtualBox USB Tablet*/ { USB_DEVICE(0x1d6b, 0x0001) }, /*Linux Foundation 1.1 root hub*/ { 0 } /* Terminating Entry*/ }; MODULE_DEVICE_TABLE(usb, usb_table); static struct usb_driver skel_driver = { .name = "custom_usb_driver", .probe = usb_probe, .disconnect = usb_disconnect, //.fops = &usb_fops, // .minor = USB_MINOR_BASE, .id_table = usb_table }; /* __init = After loading this function will be removed as it is not needed any more. */ static int __init __usb_init(void) { int result = 0; printk(KERN_ALERT "USBHelloWorld: __usb_init\n"
; result = usb_register(&skel_driver); if(result < 0) { printk(KERN_ALERT "USBHelloWorld: register failed for the driver. Error No\n"
; return -1; } printk(KERN_ALERT "USBHelloWorld: __usb_init done\n"
; return 0; } /* __exit = If module is built directly into kernel or kernel is configured to disallow unloading of modules, functions marked with __exit are simply discarded. */ static void __exit __usb_exit(void) { printk(KERN_ALERT "USBHelloWorld: Exiting\n"
; /* deregister this driver with the USB subsystem */ usb_deregister(&skel_driver); } module_init(__usb_init); module_exit(__usb_exit);
How to watch online movies December 18, 2018 12:42AM |
Re: Linux(CentOS) - USB device driver - MODULE_DEVICE_TABLE - probe function March 02, 2019 02:55PM |
Best Streaming Services September 29, 2019 01:28AM |
70-778 Exam Dumps October 17, 2019 02:28PM |