简体   繁体   中英

How can I retrieve wLength of a hid device in linux?

I want to retrieve wLength (that can be specified by a hid device). The clear answer maybe is to send a ctrl signal to device. But I tried it by the following code:

struct usbfs_ctrltransfer ctrl = {
    .bmRequestType = LIBUSB_ENDPOINT_IN,
    .bRequest = LIBUSB_REQUEST_GET_CONFIGURATION,
    .wValue = 0,
    .wIndex = 0,
    .wLength = 1,
    ...
}
....
r = ioctl(fd, 0, &ctrl);
....

The result of this code was just an error value (I think that was -1!). I reloaded the hid module (kernel module) in debug mode(modprobe hid debug=100 --> don't panic for this large debug level!). In this case the hid print out the true value of the wLength.

/build/buildd/linux-3.13.0/drivers/hid/usbhid/hid-core.c: submitting ctrl urb: Get_Report wValue=0x0100 wIndex=0x0001 wLength=64

I track it in Linux kernel source code and I found that this information are printed in usb_get_intfdata. In summary I wonder to know if there is an equal function in userland or not?

The answer to this question is using udev. ‌By reading special attribute, called bmAttributes, you can find the I/O's actual length. Using below code to read it:

 ....
 udev_device_get_sysattr_value(dev, "bmAttributes")
 ....

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM