Consolidate HID report descriptor parsing across backends #833
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#833
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?
Problem
HIDAPI currently has several private implementations that decode or walk HID report descriptors:
libusb/hid.chas its own item walker for Usage Page/Usage extraction.libusb/hidapi_libusb_report_descriptor.hto calculate maximum Input/Output/Feature report sizes.linux/hid.cindependently implements report-item decoding and Usage Page/Usage extraction.netbsd/hid.ccontains another closely related implementation.These routines duplicate short/long item decoding, bounds checks, global-item state, Usage handling, and malformed-descriptor behavior. Keeping the new libusb parser under the backend directory also makes reuse by the hidraw and NetBSD backends unnecessarily difficult.
Windows'
hidapi_descriptor_reconstruct.cperforms the inverse operation—reconstructing a descriptor from preparsed data—so it may remain separate, but shared item definitions or test data could still be evaluated.Proposal
Introduce a private common report-descriptor module, for example under
src/or another backend-neutral internal directory, and migrate reusable decoding logic into it.The common layer should:
HIDAPI_BUILD_AS_CXX.Acceptance criteria
hidapi_libusb_report_descriptor.hno longer imply that generic parsing belongs exclusively to libusb.Related to #728.
Related to #796.
Generated by Codex (GPT-5.6 Sol).
I don't know what are your feelings/policies about C++, but this library could be helpful here: https://github.com/IntergatedCircuits/hid-rp
It has various levels of facilities for parsing HID report descriptors, from the simplest iteration from item to item, to more structured parsing with global state stack tracking. It also generates full usage tables and can print report descriptors with usage information.
I don't mind anything regarding C++ (I'm a C++ developer myself), specially where it makes sense.
As for the scope of this particular task - using
hid-rpwould mean make all of HIDAPI implementation a C++ source, or introduce C++ modules with "C bindings", which I don't thinkg neither should happen. What is used by HIDAPI internally is partial and isolated, let it stay that way.