hid_get_input_report: Correct number of bytes_returned #232
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!232
Loading…
Reference in a new issue
No description provided.
Delete branch "patch-1"
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?
This fixes https://github.com/libusb/hidapi/issues/229
And definitely breaks something else
What does it break? Do you have an example of an HID device where the old code returned the correct number of bytes? Can you share the HID Report Descriptor of this device and the number of read bytes returned?
So I guess
hid_get_feature_reporthas to be updated as well?@todbot any chance you could take a look at this? I don't have any device that uses all of: feature, input and interrupt reports.
ping @todbot
While unable to verify it myself, I tried to check MS documentation for details on
HidD_GetInputReport/IOCTL_HID_GET_INPUT_REPORTand it seems that the patch is correct, as per documentation.Note,
hid_get_input_reporthas been implemented based onhid_get_feature_reports current implementation.What bothers me here, is that same applies for
IOCTL_HID_GET_FEATURE/HidD_GetFeatureand it seems, that similar update is required forhid_get_feature_report.But:
bytes_returned++;has been added explicitly by Alan, as a bugfix. Is it mean that Alan and Petr Stehlík been both wrong at that time?@JoergAtGithub, any chance you can verify the behavior of
hid_get_feature_report?I tried hid_get_feature_report with my device, which has the following Feature Reports:

For ReportID 241 it reads 3 bytes
For ReportID 243 it reads 4 bytes
I expected 3 bytes (including the byte for the ReportID) in both cases.
Why do you expect reading 3 bytes, if report size for both of the reports is 8 as per descriptor?
1 byte ReportID + ReportSize (8Bit) * ReportCount(2)
In such case we're at square 1 again, as without this patch you'd get 2 and 3 byts.
What about the content of the buffer? Is it updated as expected?
What happens if you pass a larger buffer (e.g. of 5 bytes) ?
I patched hid_get_input_report, and tested as requested hid_get_feature_report. The later is not related to my patch.
I understad that. I'm just trying to get the full picture, as I'd expect an idential usage from two almost identical functions with pretty much identical API.
One more thing.
Has it been tested on Win10?
Win7
http://janaxelson.com/hidpage.htm
The above website has Windows host software and device side FW, which may be useful for tests.
I will try to dig out my device with my test FW last time I used to test libusb Windows HID backend. It is a simple mod of Jan's Generic HID FW.
https://github.com/mcuee/picusb/tree/master/lvr_genhid_mod
https://github.com/mcuee/picusb/blob/master/lvr_genhid_mod/libusb1_lvrhid8.c
So I just got my example up and running with libusb HID backend. I need to update my test code (INTERFACE to MYINTERFACE to avoid conflict) a bit.
First pair (char) is report ID (Out report ID and Input report ID), the results seems to be okay
Second pair and third pair (char) are the real data, OUT and IN data should be the same, so the results seem to be okay as well.
Last pair (char) is kind of my coding mistake (should be for (i=1;i<=PACKET_INT_LEN-1; i++) question[i]=0x30+i;) but it is also a good test. There should be no extra data on the IN data so the results (0) are still correct.
I will see if I can translate the code to hidapi and then test again.
I think I can use hidapitester.
From my test, it seems to me the input report is correct with hidapi.
From my test, it seems to me there is an issue with feature report readback with hidapi. It says reading 4 bytes.
Report Descriptor of the device.
https://github.com/libusb/hidapi/issues/229
Unfortunately hidapitester does not test the correctness of hid_get_input_report().
I believe the changes is correct based on my testing and analysis in #229. Similar changes need to be implemented for feature report as well.
The change is also confirmed by Tim Roberts' answer to my query in libusb-devel mailing list. Similar changes need to be implemented for feature report as well.
@JoergAtGithub or @Youw Is it possible for you to create another pull request for feature report? I am poor at git myself and I do not want to touch the code for hidapi (or libusb as well).
Yes, I will.