libusb: fix using LIBUSB_DT_REPORT for HID Report Descriptor #438
Labels
No labels
3rdparty
Android
API
Author does not respond
bsd
bug
build system/CI
ci-virtual-device
CMake
Contributions Welcome
Core
dependencies
device-specific
documentation
don't_merge
duplicate
enhancement
Example
Haiku
hidraw
hotplug
info required
invalid
libusb
macOS
Misc
Not an issue
question
Release
Test
Test GUI
Windows
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-libusb/hidapi#438
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Sometime it is required to get/parse the HID Report Descriptor, e.g.:
Unfortunately not all devices haveLIBUSB_DT_REPORTrequest implemented, even though raw USB descriptors contain the HID Report Descriptor.UPD: probably the way HIDAPI uses
LIBUSB_DT_REPORTis not correct.Instead of using
LIBUSB_DT_REPORTthere are several possible alternatives:UPD: it only contains HID descriptor, and not the HID Report descriptor;
descriptorsfrom sysfs - linux-specific solution;UPD: same limitation as with libusb descriptors - HID Report descriptor is not part of the USB
descriptors.From HID USB specification:
It shall not return ... HID Report descriptor ... .
Tried this with libusb: true - with my devices the interface descriptor contains the HID descriptor, but it doesn't include the HID Report descriptor.
Looks like it is not an option(
I wonder, what
means. What type of error do you get, if you try to gather the Report Descriptor?
Do you know, how operating system drivers of Windows or hidraw request the Report Descriptor from these devices?
I guess that usbutils (lsusb & usbhid-dump) fails for these devices too?
libusb_control_transfer() for getting the HID report descriptor failed with -1: LIBUSB_ERROR_IOMaybe my assumption about
LIBUSB_DT_REPORTnot being supported by the device is not correct - that was my itinial thought.That's what I intent to find out. Not the first time I'll be going thru hidraw sources.
sudo lsusb -vgives me a similar thing I got with libusb:Interestingly,
sudo usbhid-dumpactually gives me what I need:Maybe I just need to poke around its sources.
Both are based on libusb. I noticed, that usbhid-dump determines the size of the Report-Descriptor before reading it.
Hm, that information is available from Interface descriptor. Maybe that's what is missing to make it wokr.
I'll try it (passing the actual Report descriptors size) later today.
Found this in kernel/hidusb driver.
Looks like it uses the
LIBUSB_DT_REPORTbut it specifically requests the size as per HID descriptor.I saw this code of usbhid-dump: https://github.com/gregkh/usbutils/blame/master/usbhid-dump/src/iface_list.c#L94
Yeah, that's basically the same thing.
I made an attempt to fix it here: https://github.com/libusb/hidapi/tree/libusb_report_descriptor_read
But it still doesn't wokr as expected.
I'll be able to check it some time later.
@Youw
libusb xusb may not handle atill the situations but it works to list the HID report descriptors (only for interface 0).
https://github.com/libusb/libusb/blob/master/examples/xusb.c#L609
Example run against teensy 2.0 RawHID device.
Ah, sorry I didn't explicitly mention it here regarding:
#444 completely resolves the issue now.
The problem was about not sending the correct libusb request to get the HID Report descriptor.
BTW: in the xusb example here - there is a bug:
wIndexparameter is set to0, which means the request will work only if the USB Interface №0 is a HID Interface.wIndexhas to be set to the HID Interface index.Yes that example is only meant for the particular HID device in reality :
// Microsoft Sidewinder Precision Pro Joystick - 1 HID interface(
github.com/libusb/libusb@b88f144185/examples/xusb.c (L1054))Explicitly naming the parameter value as a variable would make a better sample. Just a thought.
Thanks. Yes I think this issue is sorted. You can also close #443 as there is a working work-around now.