Welcome! Log In Create A New Profile

Advanced

Linux(CentOS) - USB device driver - MODULE_DEVICE_TABLE - probe function

Posted by Mohit Gupta 
I am new to writing USB driver. My current goal is to create usb driver for which probe function is called. I am running linux on windows using VirtualBox. probe function to not called after module is installed.

lsusb
Bus 001 Device 002: ID 80ee:0021 VirtualBox USB Tablet
Bus 001 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub

#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"winking smiley;              ///The license type -- this affects runtime behavior
MODULE_AUTHOR("Mohit Gupta"winking smiley;      ///The author -- visible when you use modinfo
MODULE_DESCRIPTION("A simple Hello World USB driver"winking smiley;  ///The description -- see modinfo
MODULE_VERSION("0.1"winking smiley;              ///< 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"winking smiley;
}

/* 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"winking smiley;

   result = usb_register(&skel_driver);
   if(result < 0)
   {
     printk(KERN_ALERT "USBHelloWorld: register failed for the driver. Error No\n"winking smiley;
     return -1;
   }


   printk(KERN_ALERT "USBHelloWorld: __usb_init done\n"winking smiley;

   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"winking smiley;

   /* 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
Hotstar App let you watch free online TV shows and sports programs. This is India’s largest live streaming app with more than 400 million followers offering live coverages of global events on a paid subscription.
It could an issue with your table, try to catch all USB devices first. This way you'll be sure problem isn't here
Author:

Your Email:


Subject:


Spam prevention:
Please, solve the mathematical question and enter the answer in the input field below. This is for blocking bots that try to post this form automatically.
Question: how much is 2 plus 17?
Message: