6 * This file is part of the w32api package.
9 * Created by Casper S. Hornstrup <chorns@users.sourceforge.net>
11 * THIS SOFTWARE IS NOT COPYRIGHTED
13 * This source code is offered for use in the public domain. You may
14 * use, modify or distribute it freely.
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.
27 #pragma GCC system_header
31 #error usbdi.h cannot be included with usb.h
41 typedef LONG USBD_STATUS
;
42 typedef PVOID USBD_PIPE_HANDLE
;
43 typedef PVOID USBD_CONFIGURATION_HANDLE
;
44 typedef PVOID USBD_INTERFACE_HANDLE
;
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)
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)
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)
114 #define USBD_TRANSFER_DIRECTION_FLAG(flags) ((flags) & USBD_TRANSFER_DIRECTION)
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)
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
128 typedef enum _USB_CONTROLLER_FLAVOR
{
143 } USB_CONTROLLER_FLAVOR
;
149 PVOID UsbdDeviceHandle
;
153 typedef struct _USBD_VERSION_INFORMATION
{
155 ULONG Supported_USB_Version
;
156 } USBD_VERSION_INFORMATION
, *PUSBD_VERSION_INFORMATION
;
158 struct _URB_HCD_AREA
{
162 struct _URB_BULK_OR_INTERRUPT_TRANSFER
{
163 struct _URB_HEADER Hdr
;
164 USBD_PIPE_HANDLE PipeHandle
;
166 ULONG TransferBufferLength
;
167 PVOID TransferBuffer
;
168 PMDL TransferBufferMDL
;
169 struct _URB
*UrbLink
;
170 struct _URB_HCD_AREA hca
;
173 struct _URB_CONTROL_DESCRIPTOR_REQUEST
{
174 struct _URB_HEADER Hdr
;
177 ULONG TransferBufferLength
;
178 PVOID TransferBuffer
;
179 PMDL TransferBufferMDL
;
180 struct _URB
*UrbLink
;
181 struct _URB_HCD_AREA hca
;
184 UCHAR DescriptorType
;
189 struct _URB_CONTROL_FEATURE_REQUEST
{
190 struct _URB_HEADER Hdr
;
196 struct _URB
*UrbLink
;
197 struct _URB_HCD_AREA hca
;
199 USHORT FeatureSelector
;
204 struct _URB_CONTROL_GET_CONFIGURATION_REQUEST
{
205 struct _URB_HEADER Hdr
;
208 ULONG TransferBufferLength
;
209 PVOID TransferBuffer
;
210 PMDL TransferBufferMDL
;
211 struct _URB
*UrbLink
;
212 struct _URB_HCD_AREA hca
;
216 struct _URB_CONTROL_GET_INTERFACE_REQUEST
{
217 struct _URB_HEADER Hdr
;
220 ULONG TransferBufferLength
;
221 PVOID TransferBuffer
;
222 PMDL TransferBufferMDL
;
223 struct _URB
*UrbLink
;
224 struct _URB_HCD_AREA hca
;
230 struct _URB_CONTROL_GET_STATUS_REQUEST
{
231 struct _URB_HEADER Hdr
;
234 ULONG TransferBufferLength
;
235 PVOID TransferBuffer
;
236 PMDL TransferBufferMDL
;
237 struct _URB
*UrbLink
;
238 struct _URB_HCD_AREA hca
;
244 struct _URB_CONTROL_TRANSFER
{
245 struct _URB_HEADER Hdr
;
246 USBD_PIPE_HANDLE PipeHandle
;
248 ULONG TransferBufferLength
;
249 PVOID TransferBuffer
;
250 PMDL TransferBufferMDL
;
251 struct _URB
*UrbLink
;
252 struct _URB_HCD_AREA hca
;
253 UCHAR SetupPacket
[8];
256 struct _URB_CONTROL_VENDOR_OR_CLASS_REQUEST
{
257 struct _URB_HEADER Hdr
;
260 ULONG TransferBufferLength
;
261 PVOID TransferBuffer
;
262 PMDL TransferBufferMDL
;
263 struct _URB
*UrbLink
;
264 struct _URB_HCD_AREA hca
;
265 UCHAR RequestTypeReservedBits
;
272 struct _URB_FRAME_LENGTH_CONTROL
{
273 struct _URB_HEADER Hdr
;
276 struct _URB_GET_CURRENT_FRAME_NUMBER
{
277 struct _URB_HEADER Hdr
;
281 struct _URB_GET_FRAME_LENGTH
{
282 struct _URB_HEADER Hdr
;
287 typedef struct _USBD_ISO_PACKET_DESCRIPTOR
{
291 } USBD_ISO_PACKET_DESCRIPTOR
, *PUSBD_ISO_PACKET_DESCRIPTOR
;
293 struct _URB_ISOCH_TRANSFER
{
294 struct _URB_HEADER Hdr
;
295 USBD_PIPE_HANDLE PipeHandle
;
297 ULONG TransferBufferLength
;
298 PVOID TransferBuffer
;
299 PMDL TransferBufferMDL
;
300 struct _URB
*UrbLink
;
301 struct _URB_HCD_AREA hca
;
303 ULONG NumberOfPackets
;
305 USBD_ISO_PACKET_DESCRIPTOR IsoPacket
[1];
308 typedef enum _USBD_PIPE_TYPE
{
310 UsbdPipeTypeIsochronous
,
312 UsbdPipeTypeInterrupt
315 typedef struct _USBD_PIPE_INFORMATION
{
316 USHORT MaximumPacketSize
;
317 UCHAR EndpointAddress
;
319 USBD_PIPE_TYPE PipeType
;
320 USBD_PIPE_HANDLE PipeHandle
;
321 ULONG MaximumTransferSize
;
323 } USBD_PIPE_INFORMATION
, *PUSBD_PIPE_INFORMATION
;
325 #define USBD_PIPE_DIRECTION_IN(pipeInformation) \
326 ((pipeInformation)->EndpointAddress & USB_ENDPOINT_DIRECTION_MASK)
328 typedef struct _USBD_INTERFACE_INFORMATION
{
330 UCHAR InterfaceNumber
;
331 UCHAR AlternateSetting
;
336 USBD_INTERFACE_HANDLE InterfaceHandle
;
338 USBD_PIPE_INFORMATION Pipes
[1];
339 } USBD_INTERFACE_INFORMATION
, *PUSBD_INTERFACE_INFORMATION
;
341 struct _URB_SELECT_INTERFACE
{
342 struct _URB_HEADER Hdr
;
343 USBD_CONFIGURATION_HANDLE ConfigurationHandle
;
344 USBD_INTERFACE_INFORMATION Interface
;
347 struct _URB_SELECT_CONFIGURATION
{
348 struct _URB_HEADER Hdr
;
349 PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor
;
350 USBD_CONFIGURATION_HANDLE ConfigurationHandle
;
351 USBD_INTERFACE_INFORMATION Interface
;
354 struct _URB_PIPE_REQUEST
{
355 struct _URB_HEADER Hdr
;
356 USBD_PIPE_HANDLE PipeHandle
;
360 struct _URB_SET_FRAME_LENGTH
{
361 struct _URB_HEADER Hdr
;
362 LONG FrameLengthDelta
;
365 typedef 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
;
387 #define URB_FROM_IRP(Irp) ((IoGetCurrentIrpStackLocation(Irp))->Parameters.Others.Argument1)
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
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
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)
450 #define OS_STRING_DESCRIPTOR_INDEX 0xEE
452 #define MS_GENRE_DESCRIPTOR_INDEX 0x0001
453 #define MS_POWER_DESCRIPTOR_INDEX 0x0002
455 #define MS_OS_STRING_SIGNATURE L"MSFT100"
457 typedef struct _OS_STRING
{
459 UCHAR bDescriptorType
;
460 WCHAR MicrosoftString
[7];
463 } OS_STRING
, *POS_STRING
;
469 #endif /* defined __USBDI_H */