xref: /reactos/sdk/include/psdk/usb200.h (revision d4ff198c)
1 /*
2  * usb200.h
3  *
4  * This file is part of the ReactOS PSDK package.
5  *
6  * Contributors:
7  *   Magnus Olsen.
8  *
9  * THIS SOFTWARE IS NOT COPYRIGHTED
10  *
11  * This source code is offered for use in the public domain. You may
12  * use, modify or distribute it freely.
13  *
14  * This code is distributed in the hope that it will be useful but
15  * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
16  * DISCLAIMED. This includes but is not limited to warranties of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18  *
19  */
20 
21 #pragma once
22 
23 /* Helper macro to enable gcc's extension. */
24 #ifndef __GNU_EXTENSION
25 #ifdef __GNUC__
26 #define __GNU_EXTENSION __extension__
27 #else
28 #define __GNU_EXTENSION
29 #endif
30 #endif
31 
32 #include "usb100.h"
33 
34 #include <pshpack1.h>
35 
36 typedef enum _USB_DEVICE_TYPE {
37   Usb11Device = 0,
38   Usb20Device
39 } USB_DEVICE_TYPE;
40 
41 typedef enum _USB_DEVICE_SPEED {
42   UsbLowSpeed = 0,
43   UsbFullSpeed,
44   UsbHighSpeed
45 } USB_DEVICE_SPEED;
46 
47 #define USB_PORT_STATUS_CONNECT                       0x0001
48 #define USB_PORT_STATUS_ENABLE                        0x0002
49 #define USB_PORT_STATUS_SUSPEND                       0x0004
50 #define USB_PORT_STATUS_OVER_CURRENT                  0x0008
51 #define USB_PORT_STATUS_RESET                         0x0010
52 #define USB_PORT_STATUS_POWER                         0x0100
53 #define USB_PORT_STATUS_LOW_SPEED                     0x0200
54 #define USB_PORT_STATUS_HIGH_SPEED                    0x0400
55 
56 
57 typedef union _BM_REQUEST_TYPE {
58 #ifdef __cplusplus
59   struct {
60 #else
61   struct _BM {
62 #endif
63     UCHAR Recipient:2;
64     UCHAR Reserved:3;
65     UCHAR Type:2;
66     UCHAR Dir:1;
67   };
68   UCHAR B;
69 } BM_REQUEST_TYPE, *PBM_REQUEST_TYPE;
70 
71 typedef struct _USB_DEFAULT_PIPE_SETUP_PACKET {
72   BM_REQUEST_TYPE bmRequestType;
73   UCHAR bRequest;
74   union _wValue {
75     __GNU_EXTENSION struct {
76       UCHAR LowByte;
77       UCHAR HiByte;
78     };
79     USHORT W;
80   } wValue;
81   union _wIndex {
82     __GNU_EXTENSION struct {
83       UCHAR LowByte;
84       UCHAR HiByte;
85     };
86     USHORT W;
87   } wIndex;
88   USHORT wLength;
89 } USB_DEFAULT_PIPE_SETUP_PACKET, *PUSB_DEFAULT_PIPE_SETUP_PACKET;
90 
91 C_ASSERT(sizeof(USB_DEFAULT_PIPE_SETUP_PACKET) == 8);
92 
93 #define USB_DEVICE_QUALIFIER_DESCRIPTOR_TYPE          0x06
94 #define USB_OTHER_SPEED_CONFIGURATION_DESCRIPTOR_TYPE 0x07
95 
96 typedef struct _USB_DEVICE_QUALIFIER_DESCRIPTOR {
97   UCHAR bLength;
98   UCHAR bDescriptorType;
99   USHORT bcdUSB;
100   UCHAR bDeviceClass;
101   UCHAR bDeviceSubClass;
102   UCHAR bDeviceProtocol;
103   UCHAR bMaxPacketSize0;
104   UCHAR bNumConfigurations;
105   UCHAR bReserved;
106 } USB_DEVICE_QUALIFIER_DESCRIPTOR, *PUSB_DEVICE_QUALIFIER_DESCRIPTOR;
107 
108 typedef union _USB_HIGH_SPEED_MAXPACKET {
109   struct _MP {
110     USHORT MaxPacket:11;
111     USHORT HSmux:2;
112     USHORT Reserved:3;
113   } _MP;
114   USHORT us;
115 } USB_HIGH_SPEED_MAXPACKET, *PUSB_HIGH_SPEED_MAXPACKET;
116 
117 #define USB_INTERFACE_ASSOCIATION_DESCRIPTOR_TYPE     0x0B
118 
119 typedef struct _USB_INTERFACE_ASSOCIATION_DESCRIPTOR {
120   UCHAR bLength;
121   UCHAR bDescriptorType;
122   UCHAR bFirstInterface;
123   UCHAR bInterfaceCount;
124   UCHAR bFunctionClass;
125   UCHAR bFunctionSubClass;
126   UCHAR bFunctionProtocol;
127   UCHAR iFunction;
128 } USB_INTERFACE_ASSOCIATION_DESCRIPTOR, *PUSB_INTERFACE_ASSOCIATION_DESCRIPTOR;
129 
130 typedef union _USB_20_PORT_STATUS {
131   USHORT AsUshort16;
132   struct {
133     USHORT CurrentConnectStatus:1;
134     USHORT PortEnabledDisabled:1;
135     USHORT Suspend:1;
136     USHORT OverCurrent:1;
137     USHORT Reset:1;
138     USHORT L1:1;
139     USHORT Reserved0:2;
140     USHORT PortPower:1;
141     USHORT LowSpeedDeviceAttached:1;
142     USHORT HighSpeedDeviceAttached:1;
143     USHORT PortTestMode:1;
144     USHORT PortIndicatorControl:1;
145     USHORT Reserved1:3;
146   };
147 } USB_20_PORT_STATUS, *PUSB_20_PORT_STATUS;
148 
149 C_ASSERT(sizeof(USB_20_PORT_STATUS) == sizeof(USHORT));
150 
151 #define USB_PORT_STATUS_CONNECT       0x0001
152 #define USB_PORT_STATUS_ENABLE        0x0002
153 #define USB_PORT_STATUS_SUSPEND       0x0004
154 #define USB_PORT_STATUS_OVER_CURRENT  0x0008
155 #define USB_PORT_STATUS_RESET         0x0010
156 #define USB_PORT_STATUS_POWER         0x0100
157 #define USB_PORT_STATUS_LOW_SPEED     0x0200
158 #define USB_PORT_STATUS_HIGH_SPEED    0x0400
159 
160 typedef union _USB_20_PORT_CHANGE {
161   USHORT AsUshort16;
162   struct {
163     USHORT ConnectStatusChange:1;
164     USHORT PortEnableDisableChange:1;
165     USHORT SuspendChange:1;
166     USHORT OverCurrentIndicatorChange:1;
167     USHORT ResetChange:1;
168     USHORT Reserved2:11;
169   };
170 } USB_20_PORT_CHANGE, *PUSB_20_PORT_CHANGE;
171 
172 C_ASSERT(sizeof(USB_20_PORT_CHANGE) == sizeof(USHORT));
173 
174 typedef union _USB_30_PORT_STATUS {
175   USHORT AsUshort16;
176   struct {
177     USHORT CurrentConnectStatus:1;
178     USHORT PortEnabledDisabled:1;
179     USHORT Reserved0:1;
180     USHORT OverCurrent:1;
181     USHORT Reset:1;
182     USHORT PortLinkState:4;
183     USHORT PortPower:1;
184     USHORT NegotiatedDeviceSpeed:3;
185     USHORT Reserved1:3;
186   };
187 } USB_30_PORT_STATUS, *PUSB_30_PORT_STATUS;
188 
189 C_ASSERT(sizeof(USB_30_PORT_STATUS) == sizeof(USHORT));
190 
191 #define PORT_LINK_STATE_U0               0
192 #define PORT_LINK_STATE_U1               1
193 #define PORT_LINK_STATE_U2               2
194 #define PORT_LINK_STATE_U3               3
195 #define PORT_LINK_STATE_DISABLED         4
196 #define PORT_LINK_STATE_RX_DETECT        5
197 #define PORT_LINK_STATE_INACTIVE         6
198 #define PORT_LINK_STATE_POLLING          7
199 #define PORT_LINK_STATE_RECOVERY         8
200 #define PORT_LINK_STATE_HOT_RESET        9
201 #define PORT_LINK_STATE_COMPLIANCE_MODE  10
202 #define PORT_LINK_STATE_LOOPBACK         11
203 #define PORT_LINK_STATE_TEST_MODE        11 // xHCI-specific, replacing LOOPBACK
204 
205 typedef union _USB_30_PORT_CHANGE {
206   USHORT AsUshort16;
207   struct {
208     USHORT ConnectStatusChange :1;
209     USHORT Reserved2 :2;
210     USHORT OverCurrentIndicatorChange :1;
211     USHORT ResetChange :1;
212     USHORT BHResetChange :1;
213     USHORT PortLinkStateChange :1;
214     USHORT PortConfigErrorChange :1;
215     USHORT Reserved3 :8;
216   };
217 } USB_30_PORT_CHANGE, *PUSB_30_PORT_CHANGE;
218 
219 C_ASSERT(sizeof(USB_30_PORT_CHANGE) == sizeof(USHORT));
220 
221 typedef union _USB_PORT_STATUS {
222   USHORT AsUshort16;
223   USB_20_PORT_STATUS Usb20PortStatus;
224   USB_30_PORT_STATUS Usb30PortStatus;
225 } USB_PORT_STATUS, *PUSB_PORT_STATUS;
226 
227 C_ASSERT(sizeof(USB_PORT_STATUS) == sizeof(USHORT));
228 
229 typedef union _USB_PORT_CHANGE {
230   USHORT AsUshort16;
231   USB_20_PORT_CHANGE Usb20PortChange;
232   USB_30_PORT_CHANGE Usb30PortChange;
233 } USB_PORT_CHANGE, *PUSB_PORT_CHANGE;
234 
235 C_ASSERT(sizeof(USB_PORT_CHANGE) == sizeof(USHORT));
236 
237 typedef union _USB_PORT_STATUS_AND_CHANGE {
238   ULONG AsUlong32;
239   struct {
240     USB_PORT_STATUS PortStatus;
241     USB_PORT_CHANGE PortChange;
242   };
243 } USB_PORT_STATUS_AND_CHANGE, *PUSB_PORT_STATUS_AND_CHANGE;
244 
245 C_ASSERT(sizeof(USB_PORT_STATUS_AND_CHANGE) == sizeof(ULONG));
246 
247 typedef union _USB_HUB_STATUS {
248   USHORT AsUshort16;
249   struct {
250     USHORT LocalPowerLost:1;
251     USHORT OverCurrent:1;
252     USHORT Reserved:14;
253   };
254 } USB_HUB_STATUS, *PUSB_HUB_STATUS;
255 
256 C_ASSERT(sizeof(USB_HUB_STATUS) == sizeof(USHORT));
257 
258 typedef union _USB_HUB_CHANGE {
259   USHORT AsUshort16;
260   struct {
261     USHORT LocalPowerChange:1;
262     USHORT OverCurrentChange:1;
263     USHORT Reserved:14;
264   };
265 } USB_HUB_CHANGE, *PUSB_HUB_CHANGE;
266 
267 C_ASSERT(sizeof(USB_HUB_CHANGE) == sizeof(USHORT));
268 
269 typedef union _USB_HUB_STATUS_AND_CHANGE {
270   ULONG AsUlong32;
271   struct {
272     USB_HUB_STATUS HubStatus;
273     USB_HUB_CHANGE HubChange;
274   };
275 } USB_HUB_STATUS_AND_CHANGE, *PUSB_HUB_STATUS_AND_CHANGE;
276 
277 C_ASSERT(sizeof(USB_HUB_STATUS_AND_CHANGE) == sizeof(ULONG));
278 
279 #define USB_20_HUB_DESCRIPTOR_TYPE  0x29
280 #define USB_30_HUB_DESCRIPTOR_TYPE  0x2A
281 
282 #define USB_REQUEST_CLEAR_TT_BUFFER     0x08
283 #define USB_REQUEST_RESET_TT            0x09
284 #define USB_REQUEST_GET_TT_STATE        0x0A
285 #define USB_REQUEST_STOP_TT             0x0B
286 
287 #define USB_REQUEST_SET_HUB_DEPTH       0x0C
288 #define USB_REQUEST_GET_PORT_ERR_COUNT  0x0D
289 
290 #define USB_DEVICE_CLASS_RESERVED             0x00
291 #define USB_DEVICE_CLASS_AUDIO                0x01
292 #define USB_DEVICE_CLASS_COMMUNICATIONS       0x02
293 #define USB_DEVICE_CLASS_HUMAN_INTERFACE      0x03
294 #define USB_DEVICE_CLASS_MONITOR              0x04
295 #define USB_DEVICE_CLASS_PHYSICAL_INTERFACE   0x05
296 #define USB_DEVICE_CLASS_POWER                0x06
297 #define USB_DEVICE_CLASS_IMAGE                0x06
298 #define USB_DEVICE_CLASS_PRINTER              0x07
299 #define USB_DEVICE_CLASS_STORAGE              0x08
300 #define USB_DEVICE_CLASS_HUB                  0x09
301 #define USB_DEVICE_CLASS_CDC_DATA             0x0A
302 #define USB_DEVICE_CLASS_SMART_CARD           0x0B
303 #define USB_DEVICE_CLASS_CONTENT_SECURITY     0x0D
304 #define USB_DEVICE_CLASS_VIDEO                0x0E
305 #define USB_DEVICE_CLASS_PERSONAL_HEALTHCARE  0x0F
306 #define USB_DEVICE_CLASS_AUDIO_VIDEO          0x10
307 #define USB_DEVICE_CLASS_BILLBOARD            0x11
308 #define USB_DEVICE_CLASS_DIAGNOSTIC_DEVICE    0xDC
309 #define USB_DEVICE_CLASS_WIRELESS_CONTROLLER  0xE0
310 #define USB_DEVICE_CLASS_MISCELLANEOUS        0xEF
311 #define USB_DEVICE_CLASS_APPLICATION_SPECIFIC 0xFE
312 #define USB_DEVICE_CLASS_VENDOR_SPECIFIC      0xFF
313 
314 #include <poppack.h>
315