Alan Ott
2011-01-15 07:02:32 UTC
Hi,
I'm trying to read the HID report descriptor for a device. Really, I'm
just trying to get the Usage Page and Usage out of the HID report
descriptor. Best I've been able to tell, this is done using a
libusb_control_transfer() [1].
The problem is, to do this type of control transfer (one that contains
LIBUSB_RECIPIENT_INTERFACE), you have to call libusb_claim_interface()
first. In order to call libusb_claim_interface(), you have to call
libusb_detach_kernel_driver().
The code[1] works. But what happens is that every time someone calls my
hid_enumerate() function, the kernel driver for every HID device gets
detached and re-attached (because I have to detach and re-attach to get
the HID report descriptor). This seems less than desirable. Further, the
detach and re-attach sequence will re-shuffle the device numbers for the
kernel device files for these devices in some cases. (For example,
hidraw1 and hidraw2 will become hidraw0 and hidraw1 in some cases).
Clearly my hid_enumerate() function should be as less invasive as
possible. The detach/claim/release/attach sequence seems invasive. Is
there a better way that I'm missing?
Alan.
[1] https://github.com/signal11/hidapi/blob/master/linux/hid-libusb.c#L469
I'm trying to read the HID report descriptor for a device. Really, I'm
just trying to get the Usage Page and Usage out of the HID report
descriptor. Best I've been able to tell, this is done using a
libusb_control_transfer() [1].
The problem is, to do this type of control transfer (one that contains
LIBUSB_RECIPIENT_INTERFACE), you have to call libusb_claim_interface()
first. In order to call libusb_claim_interface(), you have to call
libusb_detach_kernel_driver().
The code[1] works. But what happens is that every time someone calls my
hid_enumerate() function, the kernel driver for every HID device gets
detached and re-attached (because I have to detach and re-attach to get
the HID report descriptor). This seems less than desirable. Further, the
detach and re-attach sequence will re-shuffle the device numbers for the
kernel device files for these devices in some cases. (For example,
hidraw1 and hidraw2 will become hidraw0 and hidraw1 in some cases).
Clearly my hid_enumerate() function should be as less invasive as
possible. The detach/claim/release/attach sequence seems invasive. Is
there a better way that I'm missing?
Alan.
[1] https://github.com/signal11/hidapi/blob/master/linux/hid-libusb.c#L469