Reputation: 489
I am new to Linux kernel and I am presently learning USB device drivers. I wrote a simple USB driver with probe callback and disconnect callback functions.
In the probe callback I try to display values of the struct usb_device_id argument passed to it. The problem is that structure variable shows product id and vendor id as 0.
What is the reason for this? Am I doing all right?
The code snippets from the driver are
#include<linux/init.h>
#include<linux/kernel.h>
#include<linux/module.h>
#include<linux/usb.h>
int probe_callback(struct usb_interface *intf, const struct usb_device_id *id);
void disconnect_callback(struct usb_interface *intf);
struct usb_device_id usb_ids[]={
{.driver_info=42},
{}
};
struct usb_driver USB_DRIVER={
.name="NEW USB",
.id_table=usb_ids,
.probe=probe_callback,
.disconnect=disconnect_callback
};
//PROBLEM IS IN THE FUNCTION BELOW .....................
int probe_callback(struct usb_interface *intf, const struct usb_device_id *id)
{
printk(KERN_ALERT "probe callback\n");
__u16 vendor_id=id->idVendor;
__u16 product_id=id->idProduct;
printk("product id : %x vendor id : %x\n", product_id, vendor_id);
return 0;
}
//..........................
void disconnect_callback(struct usb_interface *intf)
{
printk(KERN_ALERT "disconnect callback\n");
}
static int start(void)
{
printk(KERN_ALERT "module registered\n");
int result;
result=usb_register(&USB_DRIVER);
if(result)
{
printk("error in registering usb driver...Error code = %d\n", result);
}
return result;
}
static void stop(void)
{
printk(KERN_ALERT "module unregistered\n");
usb_deregister(&USB_DRIVER);
}
module_init(start);
module_exit(stop);
The logs I get when I execute dmesg are
[ 1539.714265] probe callback
[ 1539.714277] product id : 0 vendor id : 0
Thanks in advance for any help
Upvotes: 1
Views: 847
Reputation: 17403
Your usb_id
table does not contain vendor and product IDs. The id
pointer passed to your probe_callback
points to the element of usb_id
that matched the device being probed.
You need to fill in the elements of your usb_id
table properly to match the devices you are interested in, for example using the USB_DEVICE(vend, prod)
macro.
Upvotes: 4