You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
linux/hid.c independently implements report-item decoding and Usage Page/Usage extraction.
netbsd/hid.c contains 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.c performs 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:
Decode HID short and long items safely.
Expose enough parser state or callbacks to derive Usage Page/Usage and per-report-ID sizes.
Keep transport-specific descriptor retrieval in each backend.
Remain an internal implementation detail with no public ABI additions.
Compile as both C and C++ under HIDAPI_BUILD_AS_CXX.
Preserve each backend's existing fallback and malformed-descriptor behavior.
Acceptance criteria
libusb, Linux hidraw, and NetBSD reuse the common descriptor walker where practical.
Duplicated byte/item decoding helpers are removed.
Existing backend behavior remains covered by tests.
The Windows fixture corpus and focused malformed/boundary cases provide shared parser coverage.
The eventual location and naming of hidapi_libusb_report_descriptor.h no longer imply that generic parsing belongs exclusively to libusb.
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).