I am currently trying to list all usb devices that are connected to a Linux system, the code will be running in the kernel, as an LSM. The lsm code is known good.
I have looked at this question but it was asked six years ago.
The answer to the question suggested using the following code:
struct usb_device udev; struct usb_bus *bus; ssize_t ret; static int __init usb_fun_init (void) { int result; __le16 idVendor = 0; __le16 idProduct = 0; __u8 iManufacturer = 0; __u8 iSerialNumber = 0; printk(KERN_INFO "\n************************************ in init\n"); list_for_each_entry(bus, &usb_bus_list, bus_list) { printk(KERN_INFO "***************** Begins ****************"); printk(KERN_INFO "Vendor ID = %x", bus->root_hub->descriptor.idVendor); printk(KERN_INFO "Product ID = %x", bus->root_hub->descriptor.idProduct); printk(KERN_INFO "Serial Number = %x", bus->root_hub->descriptor.iSerialNumber); //printk(KERN_INFO "Manu = %s", bus->root_hub->descriptor.iManufacturer); printk(KERN_INFO "Manu = %s", bus->root_hub->manufacturer); printk(KERN_INFO "Product = %s", bus->root_hub->product); printk(KERN_INFO "Serial Number = %s", bus->root_hub->serial); printk(KERN_INFO "\nManufacturer = %s", udev.bus.iManufacturer); } return 0; } static void __exit usb_fun_exit (void) { printk(KERN_INFO "\n************************************ in exit\n"); } module_init(usb_fun_init); module_exit(usb_fun_exit); MODULE_LICENSE("GPL");
However, the compilation errors out. From what i can see, the kernel structures have changed, i have poked about the header files, and the only likely candidate i can see is usb_bus_id
as it has the same method signature, and return type. However this does not work either. Could someone please point me in the right direction?