使用USB鼠标HID报告描述符分析HID_REPORT及成员HID_REPORT_ITEM关系
2022-05-19
1703
0
HID 报告描述分过程比较麻烦,对于MAIN ITEM,相对来说比较简单,就是一个简单的树形结构。但对于GLOBAL ITEM和LOCAL ITEM组织的数据结构定义,还是相对比较麻烦的。 每一个HID 报告描述符 都会有很多集合,这是由MAIN ITEM的Collection关键字定义的,无论它是Application类型的还是Physical类型的,反正其形成的树形关系只要报告描述符 不变,其树形关系就不变。 对于每个COLLECTION,可能会有HID 的报告信息,每个报告使用HID_REPORT结构体定义,而每个报告的数据结构组成是由HID_REPORT_ITEM定义的。
typedef struct __HID_COLLECTION__
{
UCHAR Type;
ULONG Usage;
UCHAR StringID;
UCHAR PhysicalID;
ULONG ReportCount;
ULONG NodeCount;
struct __HID_COLLECTION__ ** Nodes;//ChildeCount
struct __HID_COLLECTION__ * Root;
struct _HID_REPORT ** Reports; //ReportCount
ULONG Offsets[1];
}HID_COLLECTION, *PHID_COLLECTION;
typedef struct _HID_REPORT
{
UCHAR Type;
UCHAR ReportID;
ULONG ReportSize;
ULONG ItemCount;
ULONG ItemAllocated;
HID_REPORT_ITEM Items[1];
}HID_REPORT, *PHID_REPORT;
typedef struct
{
ULONG ByteOffset;
UCHAR Shift;
ULONG Mask;
UCHAR BitCount;
UCHAR HasData;
UCHAR Array;
UCHAR Relative;
ULONG Minimum;
ULONG Maximum;
ULONG UsageMinimum;
ULONG UsageMaximum;
ULONG Data;
UCHAR Valid;
}HID_REPORT_ITEM, *PHID_REPORT_ITEM;
这里我们以USB鼠标的报告描述符 来分析这些数据结构的关系:
0x05, 0x01, // Usage Page (Generic Desktop Ctrls)
0x09, 0x02, // Usage (Mouse)
0xA1, 0x01, // Collection (Application)
0x09, 0x01, // Usage (Pointer)
0xA1, 0x00, // Collection (Physical)
0x95, 0x03, // Report Count (3)
0x75, 0x01, // Report Size (1)
0x05, 0x09, // Usage Page (Button)
0x19, 0x01, // Usage Minimum (0x01)
0x29, 0x03, // Usage Maximum (0x03)
0x15, 0x00, // Logical Minimum (0)
0x25, 0x01, // Logical Maximum (1)
0x81, 0x02, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
0x95, 0x01, // Report Count (1)
0x75, 0x05, // Report Size (5)
0x81, 0x03, // Input (Const,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
0x95, 0x03, // Report Count (3)
0x75, 0x08, // Report Size (8)
0x05, 0x01, // Usage Page (Generic Desktop Ctrls)
0x09, 0x30, // Usage (X)
0x09, 0x31, // Usage (Y)
0x09, 0x38, // Usage (Wheel)
0x15, 0x81, // Logical Minimum (-127)
0x25, 0x7F, // Logical Maximum (127)
0x81, 0x06, // Input (Data,Var,Rel,No Wrap,Linear,Preferred State,No Null Position)
0xC0, // End Collection
以上的数据结构经过分析后的数据结构如下: 可以看到,其总共会有7个HID_REPORT_ITEM。我们分别来看一下看个的内容:
CurrentCollection->Reports[0]->Items[0]
类型
成员
值
unsigned long
ByteOffset
0x00000000
unsigned char
Shift
0x00 ‘\0’
unsigned long
Mask
0x00000001
unsigned char
BitCount
0x01 ‘\x1’
unsigned char
HasData
0x01 ‘\x1’
unsigned char
Array
0x00 ‘\0’
unsigned char
Relative
0x00 ‘\0’
unsigned long
Minimum
0x00000000
unsigned long
Maximum
0x00000001
unsigned long
UsageMinimum
0x00090001
unsigned long
UsageMaximum
0x00090001
unsigned long
Data
0x00000000
unsigned char
Valid
0x00 ‘\0’
CurrentCollection->Reports[0]->Items[1]
类型
成员
值
unsigned long
ByteOffset
0x00000000
unsigned char
Shift
0x01 ‘\x1’
unsigned long
Mask
0x00000001
unsigned char
BitCount
0x01 ‘\x1’
unsigned char
HasData
0x01 ‘\x1’
unsigned char
Array
0x00 ‘\0’
unsigned char
Relative
0x00 ‘\0’
unsigned long
Minimum
0x00000000
unsigned long
Maximum
0x00000001
unsigned long
UsageMinimum
0x00090002
unsigned long
UsageMaximum
0x00090002
unsigned long
Data
0x00000000
unsigned char
Valid
0x00 ‘\0’
CurrentCollection->Reports[0]->Items[2]
类型
成员
值
unsigned long
ByteOffset
0x00000000
unsigned char
Shift
0x02 ‘\x2’
unsigned long
Mask
0x00000001
unsigned char
BitCount
0x01 ‘\x1’
unsigned char
HasData
0x01 ‘\x1’
unsigned char
Array
0x00 ‘\0’
unsigned char
Relative
0x00 ‘\0’
unsigned long
Minimum
0x00000000
unsigned long
Maximum
0x00000001
unsigned long
UsageMinimum
0x00090003
unsigned long
UsageMaximum
0x00090003
unsigned long
Data
0x00000000
unsigned char
Valid
0x00 ‘\0’
CurrentCollection->Reports[0]->Items[3]
类型
成员
值
unsigned long
ByteOffset
0x00000000
unsigned char
Shift
0x03 ‘\x3’
unsigned long
Mask
0x0000001f
unsigned char
BitCount
0x05 ‘\x5’
unsigned char
HasData
0x00 ‘\0’
unsigned char
Array
0x00 ‘\0’
unsigned char
Relative
0x00 ‘\0’
unsigned long
Minimum
0x00000000
unsigned long
Maximum
0x00000001
unsigned long
UsageMinimum
0x00090000
unsigned long
UsageMaximum
0x00090000
unsigned long
Data
0x00000000
unsigned char
Valid
0x00 ‘\0’
CurrentCollection->Reports[0]->Items[4]
类型
成员
值
unsigned long
ByteOffset
0x00000001
unsigned char
Shift
0x00 ‘\0’
unsigned long
Mask
0x000000ff
unsigned char
BitCount
0x08 ‘\b’
unsigned char
HasData
0x01 ‘\x1’
unsigned char
Array
0x00 ‘\0’
unsigned char
Relative
0x01 ‘\x1’
unsigned long
Minimum
0x00000081
unsigned long
Maximum
0x0000007f
unsigned long
UsageMinimum
0x00010030
unsigned long
UsageMaximum
0x00010030
unsigned long
Data
0x00000000
unsigned char
Valid
0x00 ‘\0’
CurrentCollection->Reports[0]->Items[5]
类型
成员
值
unsigned long
ByteOffset
0x00000002
unsigned char
Shift
0x00 ‘\0’
unsigned long
Mask
0x000000ff
unsigned char
BitCount
0x08 ‘\b’
unsigned char
HasData
0x01 ‘\x1’
unsigned char
Array
0x00 ‘\0’
unsigned char
Relative
0x01 ‘\x1’
unsigned long
Minimum
0x00000081
unsigned long
Maximum
0x0000007f
unsigned long
UsageMinimum
0x00010031
unsigned long
UsageMaximum
0x00010031
unsigned long
Data
0x00000000
unsigned char
Valid
0x00 ‘\0’
CurrentCollection->Reports[0]->Items[6]
类型
成员
值
unsigned long
ByteOffset
0x00000003
unsigned char
Shift
0x00 ‘\0’
unsigned long
Mask
0x000000ff
unsigned char
BitCount
0x08 ‘\b’
unsigned char
HasData
0x01 ‘\x1’
unsigned char
Array
0x00 ‘\0’
unsigned char
Relative
0x01 ‘\x1’
unsigned long
Minimum
0x00000081
unsigned long
Maximum
0x0000007f
unsigned long
UsageMinimum
0x00010038
unsigned long
UsageMaximum
0x00010038
unsigned long
Data
0x00000000
unsigned char
Valid
0x00 ‘\0’
¥打赏
随手分享,手有余香
HID人机交互QQ群:564808376
UAC音频QQ群:218581009
UVC相机QQ群:331552032
BOT&UASP大容量存储QQ群:258159197
STC-USB单片机QQ群:315457461
USB技术交流QQ群2:580684376
USB技术交流QQ群:952873936