Skip to content
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

RFC: add hid_get_report_descriptor API function #451

Merged
merged 24 commits into from Mar 12, 2023
Merged

RFC: add hid_get_report_descriptor API function #451

merged 24 commits into from Mar 12, 2023

Conversation

Youw
Copy link
Member

@Youw Youw commented Sep 10, 2022

  • Add ASAN checks for utest/MSVC build;

Resolves: #249

Youw and others added 6 commits February 6, 2022 03:33
- macOS implementation;
- libusb: based on LIBUSB_REQUEST_GET_DESCRIPTOR/LIBUSB_DT_REPORT;
- hidraw: based on HIDIOCGRDESC;
- windows: based on HIDP_PREPARSED_DATA reverse-engineer/reconstruction;

Author: JoergAtGithub <64457745+JoergAtGithub@users.noreply.github.com>
Author: Ihor Dutchak <ihor.youw@gmail.com>
…escriptor

Merge 0.12.0 master into get-descriptor branch
@Youw Youw marked this pull request as draft September 10, 2022 16:27
- first step is to use HID_API_MAX_REPORT_DESCRIPTOR_SIZE internally;
- port a few improvements from get-descriptor branch early;
# Conflicts:
#	hidapi/hidapi.h
#	hidtest/test.c
#	libusb/hid.c
#	linux/hid.c
@Youw Youw changed the base branch from master to report-descriptor-upd September 10, 2022 17:48
@mcuee mcuee added enhancement New feature or request macOS Related to macOS backend Windows Related to Windows backend hidraw Related to Linux/hidraw backend libusb Related to libusb backend Core Related to common codes like hidapi.h labels Sep 11, 2022
Base automatically changed from report-descriptor-upd to master September 15, 2022 10:05
@DJm00n
Copy link
Contributor

DJm00n commented Oct 16, 2022

Hey @Youw! Nice PR!
Can you please give some information about limitations of this approach?

I wanted to test it with a bunch of game controllers that I have and prepare tests for them. How to generate those *_expected.rpt_desc files?

@Youw
Copy link
Member Author

Youw commented Oct 16, 2022

The main discussion is under #249.
And @JoergAtGithub did most of the job. I believe he has a tool to generate rpt files in one of his branches.

@JoergAtGithub
Copy link
Contributor

JoergAtGithub commented Oct 16, 2022

@DJm00n I just opened PR #467 for the pp_data_dump.exe tool, that others can find it.

There are basically 3 restrictions with this approach:

  1. It depends on the undocumented preparsed data struct (if Microsoft once decide to change the declaration of this struct, it would stop working - we tested it on Win7, Win10 and Win11 and between these versions, there are no changes)
  2. The reconstructed descriptor is logical identical to the orginal, but not byte-wise
    for example
0x75, 0x08,        //   Report Size (8)
0x95, 0x06,        //   Report Count (6)
0x81, 0x00,        //   Input (Data,Array,Abs,No Wrap,Linear,Preferred State,No Null Position)
0x75, 0x08,        //   Report Size (8)
0x95, 0x06,        //   Report Count (6)
0x81, 0x00,        //   Input (Data,Array,Abs,No Wrap,Linear,Preferred State,No Null Position)

is logically the same as:

0x75, 0x08,        //   Report Size (8)
0x95, 0x06,        //   Report Count (6)
0x81, 0x00,        //   Input (Data,Array,Abs,No Wrap,Linear,Preferred State,No Null Position)
0x81, 0x00,        //   Input (Data,Array,Abs,No Wrap,Linear,Preferred State,No Null Position)

because the preparsed data contain only the logical relevant information, we can only assume, how it looked byte-wise

  1. The preparsed data do not contain information about the padding bits, which:
  • fill the gaps between the used bits (the number of these constant bits is determined, but not the type - but it doesn't matter logically)
  • are appended at the end of the report. The HID test spec says only, that you shoul fill the remaining bits of the last byte with constant bit padding. But it doesn't prohibit to add more constant bytes at the end - the reconstrctor can only assume, that there are no unused constant bytes add the end of a report.

--
But there are also some specified syntax cases (#343 (comment)), which I implemented, but couldn't test, due to lack on real-world devices.
BTW: https://github.com/abend0c1/hidrdd/tree/master/examples contains all report descriptor examples published by the HID group in encoded form. If someone could program these into an HID device and than run pp_data_dump.exe, we would have several edge cases covered in the test case.

hidtest/test.c Outdated Show resolved Hide resolved
Youw and others added 2 commits October 18, 2022 01:53
Co-authored-by: JoergAtGithub <64457745+JoergAtGithub@users.noreply.github.com>
Co-authored-by: JoergAtGithub <64457745+JoergAtGithub@users.noreply.github.com>
JoergAtGithub and others added 3 commits January 2, 2023 15:19
Add a small command line tool for Windows, which dumps the content of the `Preparsed Data` structure, provided by the Windows HID subsystem, into a file.

The generated file is in a text format, which is readable for human, as by the `hid_report_reconstructor_test.exe` unit test executable of the HIDAPI project. This unit test allows it to test the HIDAPI's report descriptor reconstructor - offline, without the hardware device connected.
and solve the merge conflicts
@mcuee
Copy link
Member

mcuee commented Jan 26, 2023

Just FYI of others that #343 and #467 have been integrated in the following feature branch.
https://github.com/libusb/hidapi/tree/get-descriptor

More test results here:

JoergAtGithub and others added 5 commits February 11, 2023 21:51
- effectively used to run (unit)tests on Windows with ASAN checks;
- fix for incorrect collection sorting and final bit padding;
Add a Testcase, using the data of the "Xbox One For Windows" controller provided: #501 (comment)
@Youw Youw marked this pull request as ready for review February 22, 2023 11:09
Copy link
Member Author

@Youw Youw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has been a long way to get at this point.
Thanks everyone.

I'll keep this PR for a couple of days. If no objections/issues found - I'll merge it to master after that.

@Youw Youw merged commit 26b5bb0 into master Mar 12, 2023
@Youw Youw deleted the get-descriptor branch March 12, 2023 12:45
@mcuee
Copy link
Member

mcuee commented Mar 12, 2023

@Youw

This is a major improvement for HIDAPI. Just wondering if you want to start the process to release version 0.14. Thanks.

@Youw
Copy link
Member Author

Youw commented Mar 12, 2023

Release - not right now.
Bump a version - right away.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Core Related to common codes like hidapi.h enhancement New feature or request hidraw Related to Linux/hidraw backend libusb Related to libusb backend macOS Related to macOS backend Windows Related to Windows backend
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Need API to get the HID Report Descriptor or a similar data structure
5 participants