-
Notifications
You must be signed in to change notification settings - Fork 20
/
usbhelper.h
155 lines (135 loc) · 3.97 KB
/
usbhelper.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
USB descriptor structs
Copyright (C) 2015,2016 Peter Lawrence
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
#ifndef __USB_MAGIC_H
#define __USB_MAGIC_H
#include <stdint.h>
/*
IMPORTANT note to self:
all of these helper structs must *solely* use uint8_t-derived members
GCC doesn't seem to support packed structs any more, so to only way to avoid padding is to be uint8_t-only
*/
struct usb_uint16
{
uint8_t lo;
uint8_t hi;
};
#define USB_UINT16(x) { .lo = LOBYTE(x), .hi = HIBYTE(x) }
struct device_descriptor
{
uint8_t bLength;
uint8_t bDescriptorType;
struct usb_uint16 bcdUSB;
uint8_t bDeviceClass;
uint8_t bDeviceSubclass;
uint8_t bDeviceProtocol;
uint8_t bMaxPacketSize0;
struct usb_uint16 idVendor;
struct usb_uint16 idProduct;
struct usb_uint16 bcdDevice;
uint8_t iManufacturer;
uint8_t iProduct;
uint8_t iSerialNumber;
uint8_t bNumConfigurations;
};
struct configuration_descriptor
{
uint8_t bLength;
uint8_t bDescriptorType;
struct usb_uint16 wTotalLength;
uint8_t bNumInterfaces;
uint8_t bConfigurationValue;
uint8_t iConfiguration;
uint8_t bmAttributes;
uint8_t bMaxPower;
};
struct interface_descriptor
{
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 endpoint_descriptor
{
uint8_t bLength;
uint8_t bDescriptorType;
uint8_t bEndpointAddress;
uint8_t bmAttributes;
struct usb_uint16 wMaxPacketSize;
uint8_t bInterval;
};
struct cdc_functional_descriptor_header
{
uint8_t bFunctionLength;
uint8_t bDescriptorType;
uint8_t bDescriptorSubtype;
struct usb_uint16 bcdCDC;
};
struct cdc_acm_functional_descriptor
{
uint8_t bFunctionLength;
uint8_t bDescriptorType;
uint8_t bDescriptorSubtype;
uint8_t bmCapabilities;
};
struct cdc_cm_functional_descriptor
{
uint8_t bFunctionLength;
uint8_t bDescriptorType;
uint8_t bDescriptorSubtype;
uint8_t bmCapabilities;
uint8_t bDataInterface;
};
struct cdc_union_functional_descriptor
{
uint8_t bFunctionLength;
uint8_t bDescriptorType;
uint8_t bDescriptorSubtype;
uint8_t bMasterInterface;
uint8_t bSlaveInterface0;
};
struct cdc_enet_functional_descriptor
{
uint8_t bFunctionLength;
uint8_t bDescriptorType;
uint8_t bDescriptorSubtype;
uint8_t iMACAddress;
uint8_t bmEthernetStatistics[4];
struct usb_uint16 wMaxSegmentSize;
struct usb_uint16 wMCFilters;
uint8_t bNumberPowerFilters;
};
struct interface_association_descriptor
{
uint8_t bLength;
uint8_t bDescriptorType;
uint8_t bFirstInterface;
uint8_t bInterfaceCount;
uint8_t bFunctionClass;
uint8_t bFunctionSubClass;
uint8_t bFunctionProtocol;
uint8_t iFunction;
};
#endif /* __USB_MAGIC_H */