2

I am new to kernel programming and I have dev_t value of a USB device.

I want to get the details of the device like vendor ID, product ID, or some other attribute which will vary from device to device. I want to do this in kernel space, and without loading my program as an external module.

I have came across a libusb library, however, as far as I know, it is used in user space. Is it possible to use libusb in kernel space also, like my requirement? If possible, how to import and set-up libusb so that I can compile kernel?

Daniel Hedberg
  • 5,677
  • 4
  • 36
  • 61
upInCloud
  • 979
  • 2
  • 10
  • 29
  • How do you plan to write code that runs in kernel space, if not by writing a kernel module? –  Feb 16 '13 at 17:58
  • by adding the code in kernel source, and compiling as a custom kernel... – upInCloud Feb 16 '13 at 18:08
  • 2
    http://stackoverflow.com/questions/14722392/programmatically-obtaining-the-vendor-id-product-id-of-a-usb-device-on-linux-pl/14722513#14722513 – Jeyaram Feb 19 '13 at 08:35
  • 1
    I highly recommend using loadable kernel moduules so you won't haave to recompile the entire kernel every time you edit your code. By doing that, your code goes right into the linux kernel like it's an add-on. – Varda Elentári Feb 23 '13 at 22:05

1 Answers1

1

It is better to write a loadable kernel module for this task. Every time you find a bug you just have to compile your module against your kernel and load it. There is a defined framework in kernel for USB, use APIs that are provided by kernel to do things you are looking for. Except That libusb is a user space library and there is no point of using it inside kernel. In user space you can access USB related information using procfs/sysfs also.

flying-high
  • 219
  • 2
  • 7