-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdescriptor_parser.h
97 lines (81 loc) · 2.16 KB
/
descriptor_parser.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#ifndef __DESCRIPTOR_PARSER___
#define __DESCRIPTOR_PARSER___
#include <stdint.h>
#include <stdbool.h>
#include "./usb_transfer.h"
#define DEVICE_CLASS_DEVICE 0x00
#define DEVICE_CLASS_HID 0x03
#define HID_SUBCLASS_BOOT 0x01
#define HID_PROTOCOL_KEYBOARD 0x01
#define HID_PROTOCOL_MOUSE 0x02
#define DESC_TYPE_DEVICE 0x01
#define DESC_TYPE_CONFIGURATION 0x02
#define DESC_TYPE_INTERFACE 0x04
#define DESC_TYPE_ENDPOINT 0x05
#define DESC_TYPE_HID 0x21
#define DESC_TYPE_REPORT 0x22
#define DESC_TYPE_PHYSICAL 0x23
struct DeviceDescriptor {
uint8_t bLength;
uint8_t bDescriptorType;
uint16_t bcdUSB;
uint8_t bDeviceClass;
uint8_t bDeviceSubClass;
uint8_t bDeviceProtocol;
uint8_t bMaxPacketSize0;
uint16_t idVendor;
uint16_t idProduct;
uint16_t bcdDevice;
uint8_t iManufacturer;
uint8_t iProduct;
uint8_t iSerialNumber;
uint8_t bNumConfigurations;
};
struct ConfigurationDescriptor {
uint8_t bLength;
uint8_t bDescriptorType;
uint16_t wTotalLength;
uint8_t bNumInterfacs;
uint8_t bConfigurationValue;
uint8_t iConfiguration;
uint8_t bmAttributes;
uint8_t bMaxPower;
};
struct InterfaceDescriptor {
uint8_t bLength;
uint8_t bDescriptorType;
uint8_t bInterfaceNumber;
uint8_t bAlternateSetting;
uint8_t bNumEndpoints;
uint8_t bInterfaceClass;
uint8_t bInterfaceSubClass;
uint8_t bInterfaceProtocol;
uint8_t iInterface;
};
struct EndpointDescriptor {
uint8_t bLength;
uint8_t bDescriptorType;
uint8_t bEndpointAddress;
uint8_t bmAttributes;
uint16_t wMaxPacketSize;
uint8_t bInterval;
};
struct HidDescriptorElement {
uint8_t bDescriptorType;
uint16_t wDescriptorLength;
};
struct HidDescriptor {
uint8_t bLength;
uint8_t bDescriptorType;
uint16_t bcdHID;
uint8_t bCountryCode;
uint8_t bNumDescriptors;
struct HidDescriptorElement descriptors[];
};
struct HidInfo {
uint8_t bootMouseConfiguration;
uint8_t bootMouseInterface;
uint8_t bootMouseEndpoint;
};
bool getHIDInfo(struct HidInfo* result);
#endif