I guess, the above is the full code for your kernel module. Anyway you are using correct structs and vendor ID, Device ID will be available in device descriptor. Refer for more details about descriptors.
I suggest you to refer kernel code here.
Update 1:
The following program will give you information about HUBs available in system. usb_hub_for_each_child macro is not supported in 3.2.0 kernel version, but supported in latest 3.7.x versions.
usb_bus_list
is declared in #include <linux/usb/hcd.h>
.
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/usb.h>
#include <linux/usb/hcd.h>
#include <linux/list.h>
MODULE_LICENSE("GPL");
int ourinitmodule(void)
{
int chix = 0;
struct usb_device *dev, *childdev = NULL;
struct usb_bus *bus = NULL;
list_for_each_entry(bus, &usb_bus_list, bus_list)
{
printk("
USB Bus : %d", bus->busnum);
dev = bus->root_hub;
printk("
Vendor Id:%x, Product Id:%x
", dev->descriptor.idVendor, dev->descriptor.idProduct);
#if 0 //usb_hub_for_each_child macro not supported in 3.2.0, so trying with 3.7.6.
usb_hub_for_each_child(dev, chix, childdev)
{
if(childdev)
{
printk("
Vendor Id:%x, Product Id:%x
", childdev->descriptor.idVendor, childdev->descriptor.idProduct);
}
}
#endif
}
printk(KERN_ALERT "
Hello Jay, Welcome to sample application....
");
return 0;
}
void ourcleanupmodule(void)
{
printk(KERN_ALERT "
Hello Jay, Thanks....Exiting Application.
");
return;
}
module_init(ourinitmodule);
module_exit(ourcleanupmodule);
Output is
USB Bus :4
Vendor Id:1d6B, Product Id:3
USB Bus :3
Vendor Id:1d6B, Product Id:2
USB Bus :2
Vendor Id:1d6B, Product Id:2
USB Bus :1
Vendor Id:1d6B, Product Id:2
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…