Quoting from ther USB spec for HID Descriptors: http://www.usb.org/developers/hidpage/HID1_11.pdf “the value bNumDescriptors identifies the number of additional class specific descriptors present. This number must be at least one (1) as a Report
descriptor will always be present.”
The format of the HID descriptor defined in hidport.h is:
typedef struct _HID_DESCRIPTOR
{
UCHAR bLength;
UCHAR bDescriptorType;
USHORT bcdHID;
UCHAR bCountry;
UCHAR bNumDescriptors;
/*
* This is an array of one OR MORE descriptors.
*/
struct _HID_DESCRIPTOR_DESC_LIST {
UCHAR bReportType;
USHORT wReportLength;
} DescriptorList [1];
} HID_DESCRIPTOR, * PHID_DESCRIPTOR;
Which in renaming the members of the embdedded structure from those in the spec, to include the word ‘report’, backs this statement up, and actual data says there is one: 09 21 00 01 00 01 22 34 <– the 0x22 is the type and 0x34 the length of tyher report derscriptor.
The problem is, what does ‘present’ mean? It isn’t in the config descriptor which is where the HID descriptor is, so in the complete absence of documentation in the MDSN for this descriptor type, I had a dig around in some Linux code for a host and discovered the report descriptor is obtained not from the device, like the other descriptors, but from an interface.
Microsoft include a define for this, URB_FUNCTION_GET_DESCRIPTOR_FROM_INTERFACE, but not a macro (UsbBuildGetDescriptorRequest being the macro to get a descriptor from a devcice).
What is also odd is that the report descriptor doesnt follow the format of the other descriptors in having a USB_COMMON_DESCRIPTOR type header at its start. (In fact it is just an array of chars).
What is also inconsistent is that when using this define you don’t need to specify an interface index like you do when using URB_FUNCTION_VENDOR_INTERFACE.
So why the oversight? Why the missing macro and why is the descriptor structure different from the others, including the HID descriptor? And why no interface index?
Something else, the HID descriptor documented here: https://msdn.microsoft.com/en-us/windows/hardware/commercialize/design/component-guidelines/windows-precision-touchpad-required-hid-descriptors has member variables that match the spec, and not the ones in hidport.h
Not a big problem, provided you know where to look in linux to see how a USB host works, but it would be nice to have better consistency and documentaion in the MSDN.