source: Daodan/MinGW/include/ddk/usb.h@ 1122

Last change on this file since 1122 was 1046, checked in by alloc, 8 years ago

Daodan: Added Windows MinGW and build batch file

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