-
Notifications
You must be signed in to change notification settings - Fork 400
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Report ID get overwritten when using hid_get_input_report on Linux #514
Comments
Update on this - it also affects the kernel I have managed to fix the issue by using this patch on the kernel:
I'm wondering if this could be a breaking change for some people. It'd be great to get some feedback, before I got ahead a submit if upstream. Also, looking at core implementation (used by |
Unfortunately I'm not familiar with I can't find the uhid documentation to support that statement, but my reasoning is simple - there is not even a mention of a special handling of the |
Thanks for your reply @Youw According to this doc, I should mention that I have only implemented that dummy UHID device to prove the bug and help anyone with an easy way to reproduce the problem locally, without needing to mess up with a real HID ready device; that bug happens with an actual HID device. (Which I'm waiting to get my hands on again to test if that module patch solves the issue, hopefully in a few hours) IMHO, the bug seems to be quite clear, looking at that function and docstring, the first byte shouldn't be overwritten. |
If you have a real HID device - it is even easier to test: try the same HIDAPI code you have, but link agains That should tell you if the problem is the kernel/hidraw or the aproach you take. We consider libusb backend of HIDAPI is one of the most tested implementation of client-side USB/HID protocol.
You're missing one point: "the first byte of the report is the report ID" - that is not only a driver/function description; that is also part of the HID specification. And the device, as an implementation of HID protocol, is responsible to make sure that the first byte is set to report ID for "GET Report" request - not the driver. So, technicall, the first byte does gets overwritten in the driver implementation by the data returned by the device, but normally it matches the Report ID from the request, as the device has to copy it. |
Also, if you have a real device, I suggest trying to compare the behavior on Windows and macOS - those are independent backend implementations. |
Apologies, it looks like I got carried away. This is not a bug at all. It looks like there was a genuine decision to obfuscate the Report ID in the project I'm working on, nothing wrong on |
Interesting that @acolombier proposed a patch to linux-input subsystem here. But the patch is not accepted for backwards compatability reason. |
When using
hid_get_input_report
on Linux, the first byte of the buffer containing the report ID gets overwritten by the report first byte of data while it should not (spec)Here is a simple way to reproduce the bug with a
uhid
virtual devicetest_dev.c
test_get_report.c
With the two previous files in the current directory, run the following commands
Expected output
Actual output
Version
libhidapi-hidraw: 0.11.2
Linux Kernel: 6.1.11
I'd be happy to help addressing the bug once I get confirmation on it. At first glance, it feels like the fix may have to go in the kernel driver (
drivers/hid/hid-core.c
ordrivers/hid/hidraw.c
) as I cannot see any ways that would allow to make a bug fix without amemmove
on the library side. But since the name of Alan Ott is mentioned at a few places on the kernel sources/docs, I thought I would raise the bug first before escalating it :)The text was updated successfully, but these errors were encountered: