xref: /reactos/sdk/include/psdk/usb.h (revision c2c66aff)
1*c2c66affSColin Finck /*
2*c2c66affSColin Finck  * usb.h
3*c2c66affSColin Finck  *
4*c2c66affSColin Finck  * This file is part of the ReactOS PSDK package.
5*c2c66affSColin Finck  *
6*c2c66affSColin Finck  * Contributors:
7*c2c66affSColin Finck  *   Created by Casper S. Hornstrup <chorns@users.sourceforge.net>
8*c2c66affSColin Finck  *
9*c2c66affSColin Finck  * THIS SOFTWARE IS NOT COPYRIGHTED
10*c2c66affSColin Finck  *
11*c2c66affSColin Finck  * This source code is offered for use in the public domain. You may
12*c2c66affSColin Finck  * use, modify or distribute it freely.
13*c2c66affSColin Finck  *
14*c2c66affSColin Finck  * This code is distributed in the hope that it will be useful but
15*c2c66affSColin Finck  * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
16*c2c66affSColin Finck  * DISCLAIMED. This includes but is not limited to warranties of
17*c2c66affSColin Finck  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18*c2c66affSColin Finck  *
19*c2c66affSColin Finck  */
20*c2c66affSColin Finck 
21*c2c66affSColin Finck #pragma once
22*c2c66affSColin Finck 
23*c2c66affSColin Finck /* Helper macro to enable gcc's extension. */
24*c2c66affSColin Finck #ifndef __GNU_EXTENSION
25*c2c66affSColin Finck #ifdef __GNUC__
26*c2c66affSColin Finck #define __GNU_EXTENSION __extension__
27*c2c66affSColin Finck #else
28*c2c66affSColin Finck #define __GNU_EXTENSION
29*c2c66affSColin Finck #endif
30*c2c66affSColin Finck #endif
31*c2c66affSColin Finck 
32*c2c66affSColin Finck #ifdef OSR21_COMPAT
33*c2c66affSColin Finck #pragma message("WARNING: OSR21_COMPAT SWITCH NOT SUPPORTED")
34*c2c66affSColin Finck #endif
35*c2c66affSColin Finck 
36*c2c66affSColin Finck #ifndef _NTDDK_
37*c2c66affSColin Finck #ifndef _WDMDDK_
38*c2c66affSColin Finck typedef PVOID PIRP;
39*c2c66affSColin Finck typedef PVOID PMDL;
40*c2c66affSColin Finck #endif
41*c2c66affSColin Finck #endif
42*c2c66affSColin Finck 
43*c2c66affSColin Finck #define USBDI_VERSION    0x00000500
44*c2c66affSColin Finck 
45*c2c66affSColin Finck #include "usb200.h"
46*c2c66affSColin Finck 
47*c2c66affSColin Finck #define USB_PORTATTR_NO_CONNECTOR                       0x00000001
48*c2c66affSColin Finck #define USB_PORTATTR_SHARED_USB2                        0x00000002
49*c2c66affSColin Finck #define USB_PORTATTR_MINI_CONNECTOR                     0x00000004
50*c2c66affSColin Finck #define USB_PORTATTR_OEM_CONNECTOR                      0x00000008
51*c2c66affSColin Finck #define USB_PORTATTR_OWNED_BY_CC                        0x01000000
52*c2c66affSColin Finck #define USB_PORTATTR_NO_OVERCURRENT_UI                  0x02000000
53*c2c66affSColin Finck 
54*c2c66affSColin Finck typedef enum _USB_CONTROLLER_FLAVOR {
55*c2c66affSColin Finck   USB_HcGeneric = 0,
56*c2c66affSColin Finck   OHCI_Generic = 100,
57*c2c66affSColin Finck   OHCI_Hydra,
58*c2c66affSColin Finck   OHCI_NEC,
59*c2c66affSColin Finck   UHCI_Generic = 200,
60*c2c66affSColin Finck   UHCI_Piix4 = 201,
61*c2c66affSColin Finck   UHCI_Piix3 = 202,
62*c2c66affSColin Finck   UHCI_Ich2 = 203,
63*c2c66affSColin Finck   UHCI_Reserved204 = 204,
64*c2c66affSColin Finck   UHCI_Ich1 = 205,
65*c2c66affSColin Finck   UHCI_Ich3m = 206,
66*c2c66affSColin Finck   UHCI_Ich4 = 207,
67*c2c66affSColin Finck   UHCI_Ich5 = 208,
68*c2c66affSColin Finck   UHCI_Ich6 = 209,
69*c2c66affSColin Finck   UHCI_Intel = 249,
70*c2c66affSColin Finck   UHCI_VIA = 250,
71*c2c66affSColin Finck   UHCI_VIA_x01 = 251,
72*c2c66affSColin Finck   UHCI_VIA_x02 = 252,
73*c2c66affSColin Finck   UHCI_VIA_x03 = 253,
74*c2c66affSColin Finck   UHCI_VIA_x04 = 254,
75*c2c66affSColin Finck   UHCI_VIA_x0E_FIFO = 264,
76*c2c66affSColin Finck   EHCI_Generic = 1000,
77*c2c66affSColin Finck   EHCI_NEC = 2000,
78*c2c66affSColin Finck   EHCI_Lucent = 3000
79*c2c66affSColin Finck } USB_CONTROLLER_FLAVOR;
80*c2c66affSColin Finck 
81*c2c66affSColin Finck 
82*c2c66affSColin Finck #define USB_DEFAULT_DEVICE_ADDRESS                      0
83*c2c66affSColin Finck #define USB_DEFAULT_ENDPOINT_ADDRESS                    0
84*c2c66affSColin Finck #define USB_DEFAULT_MAX_PACKET                          64
85*c2c66affSColin Finck #define URB_FROM_IRP(Irp)                               ((IoGetCurrentIrpStackLocation(Irp))->Parameters.Others.Argument1)
86*c2c66affSColin Finck #define URB_FUNCTION_SELECT_CONFIGURATION               0x0000
87*c2c66affSColin Finck #define URB_FUNCTION_SELECT_INTERFACE                   0x0001
88*c2c66affSColin Finck #define URB_FUNCTION_ABORT_PIPE                         0x0002
89*c2c66affSColin Finck #define URB_FUNCTION_TAKE_FRAME_LENGTH_CONTROL          0x0003
90*c2c66affSColin Finck #define URB_FUNCTION_RELEASE_FRAME_LENGTH_CONTROL       0x0004
91*c2c66affSColin Finck #define URB_FUNCTION_GET_FRAME_LENGTH                   0x0005
92*c2c66affSColin Finck #define URB_FUNCTION_SET_FRAME_LENGTH                   0x0006
93*c2c66affSColin Finck #define URB_FUNCTION_GET_CURRENT_FRAME_NUMBER           0x0007
94*c2c66affSColin Finck #define URB_FUNCTION_CONTROL_TRANSFER                   0x0008
95*c2c66affSColin Finck #define URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER         0x0009
96*c2c66affSColin Finck #define URB_FUNCTION_ISOCH_TRANSFER                     0x000A
97*c2c66affSColin Finck #define URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE         0x000B
98*c2c66affSColin Finck #define URB_FUNCTION_SET_DESCRIPTOR_TO_DEVICE           0x000C
99*c2c66affSColin Finck #define URB_FUNCTION_SET_FEATURE_TO_DEVICE              0x000D
100*c2c66affSColin Finck #define URB_FUNCTION_SET_FEATURE_TO_INTERFACE           0x000E
101*c2c66affSColin Finck #define URB_FUNCTION_SET_FEATURE_TO_ENDPOINT            0x000F
102*c2c66affSColin Finck #define URB_FUNCTION_CLEAR_FEATURE_TO_DEVICE            0x0010
103*c2c66affSColin Finck #define URB_FUNCTION_CLEAR_FEATURE_TO_INTERFACE         0x0011
104*c2c66affSColin Finck #define URB_FUNCTION_CLEAR_FEATURE_TO_ENDPOINT          0x0012
105*c2c66affSColin Finck #define URB_FUNCTION_GET_STATUS_FROM_DEVICE             0x0013
106*c2c66affSColin Finck #define URB_FUNCTION_GET_STATUS_FROM_INTERFACE          0x0014
107*c2c66affSColin Finck #define URB_FUNCTION_GET_STATUS_FROM_ENDPOINT           0x0015
108*c2c66affSColin Finck #define URB_FUNCTION_RESERVED_0X0016                    0x0016
109*c2c66affSColin Finck #define URB_FUNCTION_VENDOR_DEVICE                      0x0017
110*c2c66affSColin Finck #define URB_FUNCTION_VENDOR_INTERFACE                   0x0018
111*c2c66affSColin Finck #define URB_FUNCTION_VENDOR_ENDPOINT                    0x0019
112*c2c66affSColin Finck #define URB_FUNCTION_CLASS_DEVICE                       0x001A
113*c2c66affSColin Finck #define URB_FUNCTION_CLASS_INTERFACE                    0x001B
114*c2c66affSColin Finck #define URB_FUNCTION_CLASS_ENDPOINT                     0x001C
115*c2c66affSColin Finck #define URB_FUNCTION_RESERVE_0X001D                     0x001D
116*c2c66affSColin Finck #define URB_FUNCTION_SYNC_RESET_PIPE_AND_CLEAR_STALL    0x001E
117*c2c66affSColin Finck #define URB_FUNCTION_CLASS_OTHER                        0x001F
118*c2c66affSColin Finck #define URB_FUNCTION_VENDOR_OTHER                       0x0020
119*c2c66affSColin Finck #define URB_FUNCTION_GET_STATUS_FROM_OTHER              0x0021
120*c2c66affSColin Finck #define URB_FUNCTION_CLEAR_FEATURE_TO_OTHER             0x0022
121*c2c66affSColin Finck #define URB_FUNCTION_SET_FEATURE_TO_OTHER               0x0023
122*c2c66affSColin Finck #define URB_FUNCTION_GET_DESCRIPTOR_FROM_ENDPOINT       0x0024
123*c2c66affSColin Finck #define URB_FUNCTION_SET_DESCRIPTOR_TO_ENDPOINT         0x0025
124*c2c66affSColin Finck #define URB_FUNCTION_GET_CONFIGURATION                  0x0026
125*c2c66affSColin Finck #define URB_FUNCTION_GET_INTERFACE                      0x0027
126*c2c66affSColin Finck #define URB_FUNCTION_GET_DESCRIPTOR_FROM_INTERFACE      0x0028
127*c2c66affSColin Finck #define URB_FUNCTION_SET_DESCRIPTOR_TO_INTERFACE        0x0029
128*c2c66affSColin Finck 
129*c2c66affSColin Finck #if (_WIN32_WINNT >= 0x0501)
130*c2c66affSColin Finck 
131*c2c66affSColin Finck #define URB_FUNCTION_GET_MS_FEATURE_DESCRIPTOR          0x002A
132*c2c66affSColin Finck #define URB_FUNCTION_SYNC_RESET_PIPE                    0x0030
133*c2c66affSColin Finck #define URB_FUNCTION_SYNC_CLEAR_STALL                   0x0031
134*c2c66affSColin Finck 
135*c2c66affSColin Finck #endif
136*c2c66affSColin Finck 
137*c2c66affSColin Finck #if (_WIN32_WINNT >= 0x0600)
138*c2c66affSColin Finck 
139*c2c66affSColin Finck #define URB_FUNCTION_CONTROL_TRANSFER_EX             0x0032
140*c2c66affSColin Finck #define URB_FUNCTION_RESERVE_0X0033                  0x0033
141*c2c66affSColin Finck #define URB_FUNCTION_RESERVE_0X0034                  0x0034
142*c2c66affSColin Finck 
143*c2c66affSColin Finck #endif
144*c2c66affSColin Finck 
145*c2c66affSColin Finck #define URB_FUNCTION_RESERVE_0X002B                     0x002B
146*c2c66affSColin Finck #define URB_FUNCTION_RESERVE_0X002C                     0x002C
147*c2c66affSColin Finck #define URB_FUNCTION_RESERVE_0X002D                     0x002D
148*c2c66affSColin Finck #define URB_FUNCTION_RESERVE_0X002E                     0x002E
149*c2c66affSColin Finck #define URB_FUNCTION_RESERVE_0X002F                     0x002F
150*c2c66affSColin Finck 
151*c2c66affSColin Finck #define URB_FUNCTION_RESET_PIPE                         URB_FUNCTION_SYNC_RESET_PIPE_AND_CLEAR_STALL
152*c2c66affSColin Finck 
153*c2c66affSColin Finck #define USBD_TRANSFER_DIRECTION                         0x00000001
154*c2c66affSColin Finck #define USBD_SHORT_TRANSFER_OK                          0x00000002
155*c2c66affSColin Finck #define USBD_START_ISO_TRANSFER_ASAP                    0x00000004
156*c2c66affSColin Finck #define USBD_DEFAULT_PIPE_TRANSFER                      0x00000008
157*c2c66affSColin Finck #define USBD_TRANSFER_DIRECTION_FLAG(flags)             ((flags) & USBD_TRANSFER_DIRECTION)
158*c2c66affSColin Finck 
159*c2c66affSColin Finck #define USBD_TRANSFER_DIRECTION_OUT                     0
160*c2c66affSColin Finck #define USBD_TRANSFER_DIRECTION_IN                      1
161*c2c66affSColin Finck #define VALID_TRANSFER_FLAGS_MASK                       (USBD_SHORT_TRANSFER_OK | USBD_TRANSFER_DIRECTION | \
162*c2c66affSColin Finck                                                          USBD_START_ISO_TRANSFER_ASAP | USBD_DEFAULT_PIPE_TRANSFER)
163*c2c66affSColin Finck #define USBD_ISO_START_FRAME_RANGE                      1024
164*c2c66affSColin Finck 
165*c2c66affSColin Finck typedef LONG USBD_STATUS;
166*c2c66affSColin Finck 
167*c2c66affSColin Finck #define USBD_SUCCESS(Status)                            ((USBD_STATUS)(Status) >= 0)
168*c2c66affSColin Finck #define USBD_PENDING(Status)                            ((ULONG)(Status) >> 30 == 1)
169*c2c66affSColin Finck #define USBD_ERROR(Status)                              ((USBD_STATUS)(Status) < 0)
170*c2c66affSColin Finck #define USBD_STATUS_SUCCESS                             ((USBD_STATUS)0x00000000L)
171*c2c66affSColin Finck #define USBD_STATUS_PENDING                             ((USBD_STATUS)0x40000000L)
172*c2c66affSColin Finck #define USBD_STATUS_CRC                                 ((USBD_STATUS)0xC0000001L)
173*c2c66affSColin Finck #define USBD_STATUS_BTSTUFF                             ((USBD_STATUS)0xC0000002L)
174*c2c66affSColin Finck #define USBD_STATUS_DATA_TOGGLE_MISMATCH                ((USBD_STATUS)0xC0000003L)
175*c2c66affSColin Finck #define USBD_STATUS_STALL_PID                           ((USBD_STATUS)0xC0000004L)
176*c2c66affSColin Finck #define USBD_STATUS_DEV_NOT_RESPONDING                  ((USBD_STATUS)0xC0000005L)
177*c2c66affSColin Finck #define USBD_STATUS_PID_CHECK_FAILURE                   ((USBD_STATUS)0xC0000006L)
178*c2c66affSColin Finck #define USBD_STATUS_UNEXPECTED_PID                      ((USBD_STATUS)0xC0000007L)
179*c2c66affSColin Finck #define USBD_STATUS_DATA_OVERRUN                        ((USBD_STATUS)0xC0000008L)
180*c2c66affSColin Finck #define USBD_STATUS_DATA_UNDERRUN                       ((USBD_STATUS)0xC0000009L)
181*c2c66affSColin Finck #define USBD_STATUS_RESERVED1                           ((USBD_STATUS)0xC000000AL)
182*c2c66affSColin Finck #define USBD_STATUS_RESERVED2                           ((USBD_STATUS)0xC000000BL)
183*c2c66affSColin Finck #define USBD_STATUS_BUFFER_OVERRUN                      ((USBD_STATUS)0xC000000CL)
184*c2c66affSColin Finck #define USBD_STATUS_BUFFER_UNDERRUN                     ((USBD_STATUS)0xC000000DL)
185*c2c66affSColin Finck #define USBD_STATUS_NOT_ACCESSED                        ((USBD_STATUS)0xC000000FL)
186*c2c66affSColin Finck #define USBD_STATUS_FIFO                                ((USBD_STATUS)0xC0000010L)
187*c2c66affSColin Finck #define USBD_STATUS_XACT_ERROR                          ((USBD_STATUS)0xC0000011L)
188*c2c66affSColin Finck #define USBD_STATUS_BABBLE_DETECTED                     ((USBD_STATUS)0xC0000012L)
189*c2c66affSColin Finck #define USBD_STATUS_DATA_BUFFER_ERROR                   ((USBD_STATUS)0xC0000013L)
190*c2c66affSColin Finck #define USBD_STATUS_ENDPOINT_HALTED                     ((USBD_STATUS)0xC0000030L)
191*c2c66affSColin Finck #define USBD_STATUS_INVALID_URB_FUNCTION                ((USBD_STATUS)0x80000200L)
192*c2c66affSColin Finck #define USBD_STATUS_INVALID_PARAMETER                   ((USBD_STATUS)0x80000300L)
193*c2c66affSColin Finck #define USBD_STATUS_ERROR_BUSY                          ((USBD_STATUS)0x80000400L)
194*c2c66affSColin Finck #define USBD_STATUS_INVALID_PIPE_HANDLE                 ((USBD_STATUS)0x80000600L)
195*c2c66affSColin Finck #define USBD_STATUS_NO_BANDWIDTH                        ((USBD_STATUS)0x80000700L)
196*c2c66affSColin Finck #define USBD_STATUS_INTERNAL_HC_ERROR                   ((USBD_STATUS)0x80000800L)
197*c2c66affSColin Finck #define USBD_STATUS_ERROR_SHORT_TRANSFER                ((USBD_STATUS)0x80000900L)
198*c2c66affSColin Finck #define USBD_STATUS_BAD_START_FRAME                     ((USBD_STATUS)0xC0000A00L)
199*c2c66affSColin Finck #define USBD_STATUS_ISOCH_REQUEST_FAILED                ((USBD_STATUS)0xC0000B00L)
200*c2c66affSColin Finck #define USBD_STATUS_FRAME_CONTROL_OWNED                 ((USBD_STATUS)0xC0000C00L)
201*c2c66affSColin Finck #define USBD_STATUS_FRAME_CONTROL_NOT_OWNED             ((USBD_STATUS)0xC0000D00L)
202*c2c66affSColin Finck #define USBD_STATUS_NOT_SUPPORTED                       ((USBD_STATUS)0xC0000E00L)
203*c2c66affSColin Finck #define USBD_STATUS_INVALID_CONFIGURATION_DESCRIPTOR    ((USBD_STATUS)0xC0000F00L)
204*c2c66affSColin Finck #define USBD_STATUS_INSUFFICIENT_RESOURCES              ((USBD_STATUS)0xC0001000L)
205*c2c66affSColin Finck #define USBD_STATUS_SET_CONFIG_FAILED                   ((USBD_STATUS)0xC0002000L)
206*c2c66affSColin Finck #define USBD_STATUS_BUFFER_TOO_SMALL                    ((USBD_STATUS)0xC0003000L)
207*c2c66affSColin Finck #define USBD_STATUS_INTERFACE_NOT_FOUND                 ((USBD_STATUS)0xC0004000L)
208*c2c66affSColin Finck #define USBD_STATUS_INVALID_PIPE_FLAGS                  ((USBD_STATUS)0xC0005000L)
209*c2c66affSColin Finck #define USBD_STATUS_TIMEOUT                             ((USBD_STATUS)0xC0006000L)
210*c2c66affSColin Finck #define USBD_STATUS_DEVICE_GONE                         ((USBD_STATUS)0xC0007000L)
211*c2c66affSColin Finck #define USBD_STATUS_STATUS_NOT_MAPPED                   ((USBD_STATUS)0xC0008000L)
212*c2c66affSColin Finck #define USBD_STATUS_HUB_INTERNAL_ERROR                  ((USBD_STATUS)0xC0009000L)
213*c2c66affSColin Finck #define USBD_STATUS_CANCELED                            ((USBD_STATUS)0xC0010000L)
214*c2c66affSColin Finck #define USBD_STATUS_ISO_NOT_ACCESSED_BY_HW              ((USBD_STATUS)0xC0020000L)
215*c2c66affSColin Finck #define USBD_STATUS_ISO_TD_ERROR                        ((USBD_STATUS)0xC0030000L)
216*c2c66affSColin Finck #define USBD_STATUS_ISO_NA_LATE_USBPORT                 ((USBD_STATUS)0xC0040000L)
217*c2c66affSColin Finck #define USBD_STATUS_ISO_NOT_ACCESSED_LATE               ((USBD_STATUS)0xC0050000L)
218*c2c66affSColin Finck #define USBD_STATUS_BAD_DESCRIPTOR                      ((USBD_STATUS)0xC0100000L)
219*c2c66affSColin Finck #define USBD_STATUS_BAD_DESCRIPTOR_BLEN                 ((USBD_STATUS)0xC0100001L)
220*c2c66affSColin Finck #define USBD_STATUS_BAD_DESCRIPTOR_TYPE                 ((USBD_STATUS)0xC0100002L)
221*c2c66affSColin Finck #define USBD_STATUS_BAD_INTERFACE_DESCRIPTOR            ((USBD_STATUS)0xC0100003L)
222*c2c66affSColin Finck #define USBD_STATUS_BAD_ENDPOINT_DESCRIPTOR             ((USBD_STATUS)0xC0100004L)
223*c2c66affSColin Finck #define USBD_STATUS_BAD_INTERFACE_ASSOC_DESCRIPTOR      ((USBD_STATUS)0xC0100005L)
224*c2c66affSColin Finck #define USBD_STATUS_BAD_CONFIG_DESC_LENGTH              ((USBD_STATUS)0xC0100006L)
225*c2c66affSColin Finck #define USBD_STATUS_BAD_NUMBER_OF_INTERFACES            ((USBD_STATUS)0xC0100007L)
226*c2c66affSColin Finck #define USBD_STATUS_BAD_NUMBER_OF_ENDPOINTS             ((USBD_STATUS)0xC0100008L)
227*c2c66affSColin Finck #define USBD_STATUS_BAD_ENDPOINT_ADDRESS                ((USBD_STATUS)0xC0100009L)
228*c2c66affSColin Finck 
229*c2c66affSColin Finck typedef PVOID USBD_PIPE_HANDLE;
230*c2c66affSColin Finck typedef PVOID USBD_CONFIGURATION_HANDLE;
231*c2c66affSColin Finck typedef PVOID USBD_INTERFACE_HANDLE;
232*c2c66affSColin Finck 
233*c2c66affSColin Finck #if (_WIN32_WINNT >= 0x0501)
234*c2c66affSColin Finck #define USBD_DEFAULT_MAXIMUM_TRANSFER_SIZE              0xFFFFFFFF
235*c2c66affSColin Finck #else
236*c2c66affSColin Finck #define USBD_DEFAULT_MAXIMUM_TRANSFER_SIZE  PAGE_SIZE
237*c2c66affSColin Finck #endif
238*c2c66affSColin Finck 
239*c2c66affSColin Finck typedef struct _USBD_VERSION_INFORMATION {
240*c2c66affSColin Finck   ULONG USBDI_Version;
241*c2c66affSColin Finck   ULONG Supported_USB_Version;
242*c2c66affSColin Finck } USBD_VERSION_INFORMATION, *PUSBD_VERSION_INFORMATION;
243*c2c66affSColin Finck 
244*c2c66affSColin Finck typedef enum _USBD_PIPE_TYPE {
245*c2c66affSColin Finck   UsbdPipeTypeControl,
246*c2c66affSColin Finck   UsbdPipeTypeIsochronous,
247*c2c66affSColin Finck   UsbdPipeTypeBulk,
248*c2c66affSColin Finck   UsbdPipeTypeInterrupt
249*c2c66affSColin Finck } USBD_PIPE_TYPE;
250*c2c66affSColin Finck 
251*c2c66affSColin Finck #define USBD_PIPE_DIRECTION_IN(pipeInformation)         ((pipeInformation)->EndpointAddress & USB_ENDPOINT_DIRECTION_MASK)
252*c2c66affSColin Finck 
253*c2c66affSColin Finck typedef struct _USBD_DEVICE_INFORMATION {
254*c2c66affSColin Finck   ULONG OffsetNext;
255*c2c66affSColin Finck   PVOID UsbdDeviceHandle;
256*c2c66affSColin Finck   USB_DEVICE_DESCRIPTOR DeviceDescriptor;
257*c2c66affSColin Finck } USBD_DEVICE_INFORMATION, *PUSBD_DEVICE_INFORMATION;
258*c2c66affSColin Finck 
259*c2c66affSColin Finck typedef struct _USBD_PIPE_INFORMATION {
260*c2c66affSColin Finck   USHORT MaximumPacketSize;
261*c2c66affSColin Finck   UCHAR EndpointAddress;
262*c2c66affSColin Finck   UCHAR Interval;
263*c2c66affSColin Finck   USBD_PIPE_TYPE PipeType;
264*c2c66affSColin Finck   USBD_PIPE_HANDLE PipeHandle;
265*c2c66affSColin Finck   ULONG MaximumTransferSize;
266*c2c66affSColin Finck   ULONG PipeFlags;
267*c2c66affSColin Finck } USBD_PIPE_INFORMATION, *PUSBD_PIPE_INFORMATION;
268*c2c66affSColin Finck 
269*c2c66affSColin Finck #define USBD_PF_CHANGE_MAX_PACKET                       0x00000001
270*c2c66affSColin Finck #define USBD_PF_SHORT_PACKET_OPT                        0x00000002
271*c2c66affSColin Finck #define USBD_PF_ENABLE_RT_THREAD_ACCESS                 0x00000004
272*c2c66affSColin Finck #define USBD_PF_MAP_ADD_TRANSFERS                       0x00000008
273*c2c66affSColin Finck #define USBD_PF_VALID_MASK                              (USBD_PF_CHANGE_MAX_PACKET | USBD_PF_SHORT_PACKET_OPT | \
274*c2c66affSColin Finck                                                          USBD_PF_ENABLE_RT_THREAD_ACCESS | USBD_PF_MAP_ADD_TRANSFERS)
275*c2c66affSColin Finck 
276*c2c66affSColin Finck typedef struct _USBD_INTERFACE_INFORMATION {
277*c2c66affSColin Finck   USHORT Length;
278*c2c66affSColin Finck   UCHAR InterfaceNumber;
279*c2c66affSColin Finck   UCHAR AlternateSetting;
280*c2c66affSColin Finck   UCHAR Class;
281*c2c66affSColin Finck   UCHAR SubClass;
282*c2c66affSColin Finck   UCHAR Protocol;
283*c2c66affSColin Finck   UCHAR Reserved;
284*c2c66affSColin Finck   USBD_INTERFACE_HANDLE InterfaceHandle;
285*c2c66affSColin Finck   ULONG NumberOfPipes;
286*c2c66affSColin Finck   USBD_PIPE_INFORMATION Pipes[1];
287*c2c66affSColin Finck } USBD_INTERFACE_INFORMATION, *PUSBD_INTERFACE_INFORMATION;
288*c2c66affSColin Finck 
289*c2c66affSColin Finck struct _URB_HCD_AREA {
290*c2c66affSColin Finck   PVOID Reserved8[8];
291*c2c66affSColin Finck };
292*c2c66affSColin Finck 
293*c2c66affSColin Finck struct _URB_HEADER {
294*c2c66affSColin Finck   USHORT Length;
295*c2c66affSColin Finck   USHORT Function;
296*c2c66affSColin Finck   USBD_STATUS Status;
297*c2c66affSColin Finck   PVOID UsbdDeviceHandle;
298*c2c66affSColin Finck   ULONG UsbdFlags;
299*c2c66affSColin Finck };
300*c2c66affSColin Finck 
301*c2c66affSColin Finck struct _URB_SELECT_INTERFACE {
302*c2c66affSColin Finck   struct _URB_HEADER Hdr;
303*c2c66affSColin Finck   USBD_CONFIGURATION_HANDLE ConfigurationHandle;
304*c2c66affSColin Finck   USBD_INTERFACE_INFORMATION Interface;
305*c2c66affSColin Finck };
306*c2c66affSColin Finck 
307*c2c66affSColin Finck struct _URB_SELECT_CONFIGURATION {
308*c2c66affSColin Finck   struct _URB_HEADER Hdr;
309*c2c66affSColin Finck   PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor;
310*c2c66affSColin Finck   USBD_CONFIGURATION_HANDLE ConfigurationHandle;
311*c2c66affSColin Finck   USBD_INTERFACE_INFORMATION Interface;
312*c2c66affSColin Finck };
313*c2c66affSColin Finck 
314*c2c66affSColin Finck struct _URB_PIPE_REQUEST {
315*c2c66affSColin Finck   struct _URB_HEADER Hdr;
316*c2c66affSColin Finck   USBD_PIPE_HANDLE PipeHandle;
317*c2c66affSColin Finck   ULONG Reserved;
318*c2c66affSColin Finck };
319*c2c66affSColin Finck 
320*c2c66affSColin Finck struct _URB_FRAME_LENGTH_CONTROL {
321*c2c66affSColin Finck   struct _URB_HEADER Hdr;
322*c2c66affSColin Finck };
323*c2c66affSColin Finck 
324*c2c66affSColin Finck struct _URB_GET_FRAME_LENGTH {
325*c2c66affSColin Finck   struct _URB_HEADER Hdr;
326*c2c66affSColin Finck   ULONG FrameLength;
327*c2c66affSColin Finck   ULONG FrameNumber;
328*c2c66affSColin Finck };
329*c2c66affSColin Finck 
330*c2c66affSColin Finck struct _URB_SET_FRAME_LENGTH {
331*c2c66affSColin Finck   struct _URB_HEADER Hdr;
332*c2c66affSColin Finck   LONG FrameLengthDelta;
333*c2c66affSColin Finck };
334*c2c66affSColin Finck 
335*c2c66affSColin Finck struct _URB_GET_CURRENT_FRAME_NUMBER {
336*c2c66affSColin Finck   struct _URB_HEADER Hdr;
337*c2c66affSColin Finck   ULONG FrameNumber;
338*c2c66affSColin Finck };
339*c2c66affSColin Finck 
340*c2c66affSColin Finck struct _URB_CONTROL_DESCRIPTOR_REQUEST {
341*c2c66affSColin Finck   struct _URB_HEADER Hdr;
342*c2c66affSColin Finck   PVOID Reserved;
343*c2c66affSColin Finck   ULONG Reserved0;
344*c2c66affSColin Finck   ULONG TransferBufferLength;
345*c2c66affSColin Finck   PVOID TransferBuffer;
346*c2c66affSColin Finck   PMDL TransferBufferMDL;
347*c2c66affSColin Finck   struct _URB *UrbLink;
348*c2c66affSColin Finck   struct _URB_HCD_AREA hca;
349*c2c66affSColin Finck   USHORT Reserved1;
350*c2c66affSColin Finck   UCHAR Index;
351*c2c66affSColin Finck   UCHAR DescriptorType;
352*c2c66affSColin Finck   USHORT LanguageId;
353*c2c66affSColin Finck   USHORT Reserved2;
354*c2c66affSColin Finck };
355*c2c66affSColin Finck 
356*c2c66affSColin Finck struct _URB_CONTROL_GET_STATUS_REQUEST {
357*c2c66affSColin Finck   struct _URB_HEADER Hdr;
358*c2c66affSColin Finck   PVOID Reserved;
359*c2c66affSColin Finck   ULONG Reserved0;
360*c2c66affSColin Finck   ULONG TransferBufferLength;
361*c2c66affSColin Finck   PVOID TransferBuffer;
362*c2c66affSColin Finck   PMDL TransferBufferMDL;
363*c2c66affSColin Finck   struct _URB *UrbLink;
364*c2c66affSColin Finck   struct _URB_HCD_AREA hca;
365*c2c66affSColin Finck   UCHAR Reserved1[4];
366*c2c66affSColin Finck   USHORT Index;
367*c2c66affSColin Finck   USHORT Reserved2;
368*c2c66affSColin Finck };
369*c2c66affSColin Finck 
370*c2c66affSColin Finck struct _URB_CONTROL_FEATURE_REQUEST {
371*c2c66affSColin Finck   struct _URB_HEADER Hdr;
372*c2c66affSColin Finck   PVOID Reserved;
373*c2c66affSColin Finck   ULONG Reserved2;
374*c2c66affSColin Finck   ULONG Reserved3;
375*c2c66affSColin Finck   PVOID Reserved4;
376*c2c66affSColin Finck   PMDL Reserved5;
377*c2c66affSColin Finck   struct _URB *UrbLink;
378*c2c66affSColin Finck   struct _URB_HCD_AREA hca;
379*c2c66affSColin Finck   USHORT Reserved0;
380*c2c66affSColin Finck   USHORT FeatureSelector;
381*c2c66affSColin Finck   USHORT Index;
382*c2c66affSColin Finck   USHORT Reserved1;
383*c2c66affSColin Finck };
384*c2c66affSColin Finck 
385*c2c66affSColin Finck struct _URB_CONTROL_VENDOR_OR_CLASS_REQUEST {
386*c2c66affSColin Finck   struct _URB_HEADER Hdr;
387*c2c66affSColin Finck   PVOID Reserved;
388*c2c66affSColin Finck   ULONG TransferFlags;
389*c2c66affSColin Finck   ULONG TransferBufferLength;
390*c2c66affSColin Finck   PVOID TransferBuffer;
391*c2c66affSColin Finck   PMDL TransferBufferMDL;
392*c2c66affSColin Finck   struct _URB *UrbLink;
393*c2c66affSColin Finck   struct _URB_HCD_AREA hca;
394*c2c66affSColin Finck   UCHAR RequestTypeReservedBits;
395*c2c66affSColin Finck   UCHAR Request;
396*c2c66affSColin Finck   USHORT Value;
397*c2c66affSColin Finck   USHORT Index;
398*c2c66affSColin Finck   USHORT Reserved1;
399*c2c66affSColin Finck };
400*c2c66affSColin Finck 
401*c2c66affSColin Finck struct _URB_CONTROL_GET_INTERFACE_REQUEST {
402*c2c66affSColin Finck   struct _URB_HEADER Hdr;
403*c2c66affSColin Finck   PVOID Reserved;
404*c2c66affSColin Finck   ULONG Reserved0;
405*c2c66affSColin Finck   ULONG TransferBufferLength;
406*c2c66affSColin Finck   PVOID TransferBuffer;
407*c2c66affSColin Finck   PMDL TransferBufferMDL;
408*c2c66affSColin Finck   struct _URB *UrbLink;
409*c2c66affSColin Finck   struct _URB_HCD_AREA hca;
410*c2c66affSColin Finck   UCHAR Reserved1[4];
411*c2c66affSColin Finck   USHORT Interface;
412*c2c66affSColin Finck   USHORT Reserved2;
413*c2c66affSColin Finck };
414*c2c66affSColin Finck 
415*c2c66affSColin Finck struct _URB_CONTROL_GET_CONFIGURATION_REQUEST {
416*c2c66affSColin Finck   struct _URB_HEADER Hdr;
417*c2c66affSColin Finck   PVOID Reserved;
418*c2c66affSColin Finck   ULONG Reserved0;
419*c2c66affSColin Finck   ULONG TransferBufferLength;
420*c2c66affSColin Finck   PVOID TransferBuffer;
421*c2c66affSColin Finck   PMDL TransferBufferMDL;
422*c2c66affSColin Finck   struct _URB *UrbLink;
423*c2c66affSColin Finck   struct _URB_HCD_AREA hca;
424*c2c66affSColin Finck   UCHAR Reserved1[8];
425*c2c66affSColin Finck };
426*c2c66affSColin Finck 
427*c2c66affSColin Finck #if (_WIN32_WINNT >= 0x0501)
428*c2c66affSColin Finck 
429*c2c66affSColin Finck #define OS_STRING_DESCRIPTOR_INDEX                      0xEE
430*c2c66affSColin Finck #define MS_GENRE_DESCRIPTOR_INDEX                       0x0001
431*c2c66affSColin Finck #define MS_POWER_DESCRIPTOR_INDEX                       0x0002
432*c2c66affSColin Finck #define MS_OS_STRING_SIGNATURE                          L"MSFT100"
433*c2c66affSColin Finck #define MS_OS_FLAGS_CONTAINERID                         0x02
434*c2c66affSColin Finck 
435*c2c66affSColin Finck typedef struct _OS_STRING {
436*c2c66affSColin Finck   UCHAR bLength;
437*c2c66affSColin Finck   UCHAR bDescriptorType;
438*c2c66affSColin Finck   WCHAR MicrosoftString[7];
439*c2c66affSColin Finck   UCHAR bVendorCode;
440*c2c66affSColin Finck   union {
441*c2c66affSColin Finck     UCHAR bPad;
442*c2c66affSColin Finck     UCHAR bFlags;
443*c2c66affSColin Finck   };
444*c2c66affSColin Finck } OS_STRING, *POS_STRING;
445*c2c66affSColin Finck 
446*c2c66affSColin Finck struct _URB_OS_FEATURE_DESCRIPTOR_REQUEST {
447*c2c66affSColin Finck   struct _URB_HEADER Hdr;
448*c2c66affSColin Finck   PVOID Reserved;
449*c2c66affSColin Finck   ULONG Reserved0;
450*c2c66affSColin Finck   ULONG TransferBufferLength;
451*c2c66affSColin Finck   PVOID TransferBuffer;
452*c2c66affSColin Finck   PMDL TransferBufferMDL;
453*c2c66affSColin Finck   struct _URB *UrbLink;
454*c2c66affSColin Finck   struct _URB_HCD_AREA hca;
455*c2c66affSColin Finck   UCHAR Recipient:5;
456*c2c66affSColin Finck   UCHAR Reserved1:3;
457*c2c66affSColin Finck   UCHAR Reserved2;
458*c2c66affSColin Finck   UCHAR InterfaceNumber;
459*c2c66affSColin Finck   UCHAR MS_PageIndex;
460*c2c66affSColin Finck   USHORT MS_FeatureDescriptorIndex;
461*c2c66affSColin Finck   USHORT Reserved3;
462*c2c66affSColin Finck };
463*c2c66affSColin Finck 
464*c2c66affSColin Finck #endif
465*c2c66affSColin Finck 
466*c2c66affSColin Finck struct _URB_CONTROL_TRANSFER {
467*c2c66affSColin Finck   struct _URB_HEADER Hdr;
468*c2c66affSColin Finck   USBD_PIPE_HANDLE PipeHandle;
469*c2c66affSColin Finck   ULONG TransferFlags;
470*c2c66affSColin Finck   ULONG TransferBufferLength;
471*c2c66affSColin Finck   PVOID TransferBuffer;
472*c2c66affSColin Finck   PMDL TransferBufferMDL;
473*c2c66affSColin Finck   struct _URB *UrbLink;
474*c2c66affSColin Finck   struct _URB_HCD_AREA hca;
475*c2c66affSColin Finck   UCHAR SetupPacket[8];
476*c2c66affSColin Finck };
477*c2c66affSColin Finck 
478*c2c66affSColin Finck #if (_WIN32_WINNT >= 0x0600)
479*c2c66affSColin Finck 
480*c2c66affSColin Finck struct _URB_CONTROL_TRANSFER_EX {
481*c2c66affSColin Finck   struct _URB_HEADER Hdr;
482*c2c66affSColin Finck   USBD_PIPE_HANDLE PipeHandle;
483*c2c66affSColin Finck   ULONG TransferFlags;
484*c2c66affSColin Finck   ULONG TransferBufferLength;
485*c2c66affSColin Finck   PVOID TransferBuffer;
486*c2c66affSColin Finck   PMDL TransferBufferMDL;
487*c2c66affSColin Finck   ULONG Timeout;
488*c2c66affSColin Finck #ifdef WIN64
489*c2c66affSColin Finck   ULONG Pad;
490*c2c66affSColin Finck #endif
491*c2c66affSColin Finck   struct _URB_HCD_AREA hca;
492*c2c66affSColin Finck   UCHAR SetupPacket[8];
493*c2c66affSColin Finck };
494*c2c66affSColin Finck 
495*c2c66affSColin Finck #endif
496*c2c66affSColin Finck 
497*c2c66affSColin Finck struct _URB_BULK_OR_INTERRUPT_TRANSFER {
498*c2c66affSColin Finck   struct _URB_HEADER Hdr;
499*c2c66affSColin Finck   USBD_PIPE_HANDLE PipeHandle;
500*c2c66affSColin Finck   ULONG TransferFlags;
501*c2c66affSColin Finck   ULONG TransferBufferLength;
502*c2c66affSColin Finck   PVOID TransferBuffer;
503*c2c66affSColin Finck   PMDL TransferBufferMDL;
504*c2c66affSColin Finck   struct _URB *UrbLink;
505*c2c66affSColin Finck   struct _URB_HCD_AREA hca;
506*c2c66affSColin Finck };
507*c2c66affSColin Finck 
508*c2c66affSColin Finck typedef struct _USBD_ISO_PACKET_DESCRIPTOR {
509*c2c66affSColin Finck   ULONG Offset;
510*c2c66affSColin Finck   ULONG Length;
511*c2c66affSColin Finck   USBD_STATUS Status;
512*c2c66affSColin Finck } USBD_ISO_PACKET_DESCRIPTOR, *PUSBD_ISO_PACKET_DESCRIPTOR;
513*c2c66affSColin Finck 
514*c2c66affSColin Finck struct _URB_ISOCH_TRANSFER {
515*c2c66affSColin Finck   struct _URB_HEADER Hdr;
516*c2c66affSColin Finck   USBD_PIPE_HANDLE PipeHandle;
517*c2c66affSColin Finck   ULONG TransferFlags;
518*c2c66affSColin Finck   ULONG TransferBufferLength;
519*c2c66affSColin Finck   PVOID TransferBuffer;
520*c2c66affSColin Finck   PMDL TransferBufferMDL;
521*c2c66affSColin Finck   struct _URB *UrbLink;
522*c2c66affSColin Finck   struct _URB_HCD_AREA hca;
523*c2c66affSColin Finck   ULONG StartFrame;
524*c2c66affSColin Finck   ULONG NumberOfPackets;
525*c2c66affSColin Finck   ULONG ErrorCount;
526*c2c66affSColin Finck   USBD_ISO_PACKET_DESCRIPTOR IsoPacket[1];
527*c2c66affSColin Finck };
528*c2c66affSColin Finck 
529*c2c66affSColin Finck typedef struct _URB {
530*c2c66affSColin Finck   __GNU_EXTENSION union {
531*c2c66affSColin Finck     struct _URB_HEADER UrbHeader;
532*c2c66affSColin Finck     struct _URB_SELECT_INTERFACE UrbSelectInterface;
533*c2c66affSColin Finck     struct _URB_SELECT_CONFIGURATION UrbSelectConfiguration;
534*c2c66affSColin Finck     struct _URB_PIPE_REQUEST UrbPipeRequest;
535*c2c66affSColin Finck     struct _URB_FRAME_LENGTH_CONTROL UrbFrameLengthControl;
536*c2c66affSColin Finck     struct _URB_GET_FRAME_LENGTH UrbGetFrameLength;
537*c2c66affSColin Finck     struct _URB_SET_FRAME_LENGTH UrbSetFrameLength;
538*c2c66affSColin Finck     struct _URB_GET_CURRENT_FRAME_NUMBER UrbGetCurrentFrameNumber;
539*c2c66affSColin Finck     struct _URB_CONTROL_TRANSFER UrbControlTransfer;
540*c2c66affSColin Finck #if (_WIN32_WINNT >= 0x0600)
541*c2c66affSColin Finck     struct _URB_CONTROL_TRANSFER_EX UrbControlTransferEx;
542*c2c66affSColin Finck #endif
543*c2c66affSColin Finck     struct _URB_BULK_OR_INTERRUPT_TRANSFER UrbBulkOrInterruptTransfer;
544*c2c66affSColin Finck     struct _URB_ISOCH_TRANSFER UrbIsochronousTransfer;
545*c2c66affSColin Finck     struct _URB_CONTROL_DESCRIPTOR_REQUEST UrbControlDescriptorRequest;
546*c2c66affSColin Finck     struct _URB_CONTROL_GET_STATUS_REQUEST UrbControlGetStatusRequest;
547*c2c66affSColin Finck     struct _URB_CONTROL_FEATURE_REQUEST UrbControlFeatureRequest;
548*c2c66affSColin Finck     struct _URB_CONTROL_VENDOR_OR_CLASS_REQUEST UrbControlVendorClassRequest;
549*c2c66affSColin Finck     struct _URB_CONTROL_GET_INTERFACE_REQUEST UrbControlGetInterfaceRequest;
550*c2c66affSColin Finck     struct _URB_CONTROL_GET_CONFIGURATION_REQUEST UrbControlGetConfigurationRequest;
551*c2c66affSColin Finck #if (_WIN32_WINNT >= 0x0501)
552*c2c66affSColin Finck     struct _URB_OS_FEATURE_DESCRIPTOR_REQUEST UrbOSFeatureDescriptorRequest;
553*c2c66affSColin Finck #endif
554*c2c66affSColin Finck   };
555*c2c66affSColin Finck } URB, *PURB;
556