source: Daodan/MinGW/include/ddk/usbdi.h@ 1163

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

Daodan: Added Windows MinGW and build batch file

File size: 13.0 KB
Line 
1/*
2 * usbdi.h
3 *
4 * USBD and USB device driver definitions
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 __USBDI_H
24#define __USBDI_H
25
26#if __GNUC__ >=3
27#pragma GCC system_header
28#endif
29
30#ifdef __USB_H
31#error usb.h cannot be included with usbdi.h
32#else
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
38#include "ntddk.h"
39#include "usbioctl.h"
40
41#define USBDI_VERSION 0x300
42
43#define USB_DEFAULT_DEVICE_ADDRESS 0
44#define USB_DEFAULT_ENDPOINT_ADDRESS 0
45#define USB_DEFAULT_MAX_PACKET 64
46
47#define URB_FROM_IRP(Irp) ((IoGetCurrentIrpStackLocation(Irp))->Parameters.Others.Argument1)
48
49#define URB_FUNCTION_SELECT_CONFIGURATION 0x0000
50#define URB_FUNCTION_SELECT_INTERFACE 0x0001
51#define URB_FUNCTION_ABORT_PIPE 0x0002
52#define URB_FUNCTION_TAKE_FRAME_LENGTH_CONTROL 0x0003
53#define URB_FUNCTION_RELEASE_FRAME_LENGTH_CONTROL 0x0004
54#define URB_FUNCTION_GET_FRAME_LENGTH 0x0005
55#define URB_FUNCTION_SET_FRAME_LENGTH 0x0006
56#define URB_FUNCTION_GET_CURRENT_FRAME_NUMBER 0x0007
57#define URB_FUNCTION_CONTROL_TRANSFER 0x0008
58#define URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER 0x0009
59#define URB_FUNCTION_ISOCH_TRANSFER 0x000A
60#define URB_FUNCTION_RESET_PIPE 0x001E
61#define URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE 0x000B
62#define URB_FUNCTION_GET_DESCRIPTOR_FROM_ENDPOINT 0x0024
63#define URB_FUNCTION_GET_DESCRIPTOR_FROM_INTERFACE 0x0028
64#define URB_FUNCTION_SET_DESCRIPTOR_TO_DEVICE 0x000C
65#define URB_FUNCTION_SET_DESCRIPTOR_TO_ENDPOINT 0x0025
66#define URB_FUNCTION_SET_DESCRIPTOR_TO_INTERFACE 0x0029
67#define URB_FUNCTION_SET_FEATURE_TO_DEVICE 0x000D
68#define URB_FUNCTION_SET_FEATURE_TO_INTERFACE 0x000E
69#define URB_FUNCTION_SET_FEATURE_TO_ENDPOINT 0x000F
70#define URB_FUNCTION_SET_FEATURE_TO_OTHER 0x0023
71#define URB_FUNCTION_CLEAR_FEATURE_TO_DEVICE 0x0010
72#define URB_FUNCTION_CLEAR_FEATURE_TO_INTERFACE 0x0011
73#define URB_FUNCTION_CLEAR_FEATURE_TO_ENDPOINT 0x0012
74#define URB_FUNCTION_CLEAR_FEATURE_TO_OTHER 0x0022
75#define URB_FUNCTION_GET_STATUS_FROM_DEVICE 0x0013
76#define URB_FUNCTION_GET_STATUS_FROM_INTERFACE 0x0014
77#define URB_FUNCTION_GET_STATUS_FROM_ENDPOINT 0x0015
78#define URB_FUNCTION_GET_STATUS_FROM_OTHER 0x0021
79#define URB_FUNCTION_RESERVED0 0x0016
80#define URB_FUNCTION_VENDOR_DEVICE 0x0017
81#define URB_FUNCTION_VENDOR_INTERFACE 0x0018
82#define URB_FUNCTION_VENDOR_ENDPOINT 0x0019
83#define URB_FUNCTION_VENDOR_OTHER 0x0020
84#define URB_FUNCTION_CLASS_DEVICE 0x001A
85#define URB_FUNCTION_CLASS_INTERFACE 0x001B
86#define URB_FUNCTION_CLASS_ENDPOINT 0x001C
87#define URB_FUNCTION_CLASS_OTHER 0x001F
88#define URB_FUNCTION_RESERVED 0x001D
89#define URB_FUNCTION_GET_CONFIGURATION 0x0026
90#define URB_FUNCTION_GET_INTERFACE 0x0027
91#define URB_FUNCTION_LAST 0x0029
92
93typedef LONG USBD_STATUS;
94typedef PVOID USBD_PIPE_HANDLE;
95typedef PVOID USBD_CONFIGURATION_HANDLE;
96typedef PVOID USBD_INTERFACE_HANDLE;
97
98#define USBD_ERROR(Status) ((USBD_STATUS)(Status) < 0)
99#define USBD_HALTED(Status) ((ULONG)(Status) >> 30 == 3)
100#define USBD_PENDING(Status) ((ULONG)(Status) >> 30 == 1)
101#define USBD_STATUS(Status) ((ULONG)(Status) & 0x0FFFFFFFL)
102#define USBD_SUCCESS(Status) ((USBD_STATUS)(Status) >= 0)
103
104#define USBD_STATUS_SUCCESS ((USBD_STATUS)0x00000000L)
105#define USBD_STATUS_PENDING ((USBD_STATUS)0x40000000L)
106#define USBD_STATUS_HALTED ((USBD_STATUS)0xC0000000L)
107#define USBD_STATUS_ERROR ((USBD_STATUS)0x80000000L)
108#define USBD_STATUS_NO_MEMORY ((USBD_STATUS)0x80000100L)
109#define USBD_STATUS_INVALID_URB_FUNCTION ((USBD_STATUS)0x80000200L)
110#define USBD_STATUS_INVALID_PARAMETER ((USBD_STATUS)0x80000300L)
111#define USBD_STATUS_ERROR_BUSY ((USBD_STATUS)0x80000400L)
112#define USBD_STATUS_REQUEST_FAILED ((USBD_STATUS)0x80000500L)
113#define USBD_STATUS_INVALID_PIPE_HANDLE ((USBD_STATUS)0x80000600L)
114#define USBD_STATUS_NO_BANDWIDTH ((USBD_STATUS)0x80000700L)
115#define USBD_STATUS_INTERNAL_HC_ERROR ((USBD_STATUS)0x80000800L)
116#define USBD_STATUS_ERROR_SHORT_TRANSFER ((USBD_STATUS)0x80000900L)
117#define USBD_STATUS_CRC ((USBD_STATUS)0xC0000001L)
118#define USBD_STATUS_BTSTUFF ((USBD_STATUS)0xC0000002L)
119#define USBD_STATUS_DATA_TOGGLE_MISMATCH ((USBD_STATUS)0xC0000003L)
120#define USBD_STATUS_STALL_PID ((USBD_STATUS)0xC0000004L)
121#define USBD_STATUS_DEV_NOT_RESPONDING ((USBD_STATUS)0xC0000005L)
122#define USBD_STATUS_PID_CHECK_FAILURE ((USBD_STATUS)0xC0000006L)
123#define USBD_STATUS_UNEXPECTED_PID ((USBD_STATUS)0xC0000007L)
124#define USBD_STATUS_DATA_OVERRUN ((USBD_STATUS)0xC0000008L)
125#define USBD_STATUS_DATA_UNDERRUN ((USBD_STATUS)0xC0000009L)
126#define USBD_STATUS_RESERVED1 ((USBD_STATUS)0xC000000AL)
127#define USBD_STATUS_RESERVED2 ((USBD_STATUS)0xC000000BL)
128#define USBD_STATUS_BUFFER_OVERRUN ((USBD_STATUS)0xC000000CL)
129#define USBD_STATUS_BUFFER_UNDERRUN ((USBD_STATUS)0xC000000DL)
130#define USBD_STATUS_NOT_ACCESSED ((USBD_STATUS)0xC000000FL)
131#define USBD_STATUS_FIFO ((USBD_STATUS)0xC0000010L)
132#define USBD_STATUS_ENDPOINT_HALTED ((USBD_STATUS)0xC0000030L)
133#define USBD_STATUS_BAD_START_FRAME ((USBD_STATUS)0xC0000A00L)
134#define USBD_STATUS_ISOCH_REQUEST_FAILED ((USBD_STATUS)0xC0000B00L)
135#define USBD_STATUS_FRAME_CONTROL_OWNED ((USBD_STATUS)0xC0000C00L)
136#define USBD_STATUS_FRAME_CONTROL_NOT_OWNED \
137 ((USBD_STATUS)0xC0000D00L)
138#define USBD_STATUS_INAVLID_CONFIGURATION_DESCRIPTOR \
139 ((USBD_STATUS)0xC0000F00L)
140#define USBD_STATUS_CANCELING ((USBD_STATUS)0x00020000L)
141
142#define USBD_PIPE_DIRECTION_IN(pipeInformation) \
143 ((pipeInformation)->EndpointAddress & USB_ENDPOINT_DIRECTION_MASK)
144
145struct _URB_HEADER {
146 USHORT Length;
147 USHORT Function;
148 USBD_STATUS Status;
149 PVOID UsbdDeviceHandle;
150 ULONG UsbdFlags;
151};
152
153struct _URB_HCD_AREA {
154 PVOID HcdEndpoint;
155 PIRP HcdIrp;
156 LIST_ENTRY HcdListEntry;
157 LIST_ENTRY HcdListEntry2;
158 PVOID HcdCurrentIoFlushPointer;
159 PVOID HcdExtension;
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
308struct _URB_PIPE_REQUEST {
309 struct _URB_HEADER Hdr;
310 USBD_PIPE_HANDLE PipeHandle;
311 ULONG Reserved;
312};
313
314struct _URB_SET_FRAME_LENGTH {
315 struct _URB_HEADER Hdr;
316 LONG FrameLengthDelta;
317};
318
319typedef struct _USBD_DEVICE_INFORMATION {
320 ULONG OffsetNext;
321 PVOID UsbdDeviceHandle;
322 USB_DEVICE_DESCRIPTOR DeviceDescriptor;
323} USBD_DEVICE_INFORMATION, *PUSBD_DEVICE_INFORMATION;
324
325typedef enum _USBD_PIPE_TYPE {
326 UsbdPipeTypeControl,
327 UsbdPipeTypeIsochronous,
328 UsbdPipeTypeBulk,
329 UsbdPipeTypeInterrupt
330} USBD_PIPE_TYPE;
331
332/* USBD_PIPE_INFORMATION.PipeFlags constants */
333#define USBD_PF_CHANGE_MAX_PACKET 0x00000001
334#define USBD_PF_DOUBLE_BUFFER 0x00000002
335#define USBD_PF_ENABLE_RT_THREAD_ACCESS 0x00000004
336#define USBD_PF_MAP_ADD_TRANSFERS 0x00000008
337
338typedef struct _USBD_PIPE_INFORMATION {
339 USHORT MaximumPacketSize;
340 UCHAR EndpointAddress;
341 UCHAR Interval;
342 USBD_PIPE_TYPE PipeType;
343 USBD_PIPE_HANDLE PipeHandle;
344 ULONG MaximumTransferSize;
345 ULONG PipeFlags;
346} USBD_PIPE_INFORMATION, *PUSBD_PIPE_INFORMATION;
347
348typedef struct _USBD_INTERFACE_INFORMATION {
349 USHORT Length;
350 UCHAR InterfaceNumber;
351 UCHAR AlternateSetting;
352 UCHAR Class;
353 UCHAR SubClass;
354 UCHAR Protocol;
355 UCHAR Reserved;
356 USBD_INTERFACE_HANDLE InterfaceHandle;
357 ULONG NumberOfPipes;
358 USBD_PIPE_INFORMATION Pipes[1];
359} USBD_INTERFACE_INFORMATION, *PUSBD_INTERFACE_INFORMATION;
360
361struct _URB_SELECT_CONFIGURATION {
362 struct _URB_HEADER Hdr;
363 PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor;
364 USBD_CONFIGURATION_HANDLE ConfigurationHandle;
365 USBD_INTERFACE_INFORMATION Interface;
366};
367
368struct _URB_SELECT_INTERFACE {
369 struct _URB_HEADER Hdr;
370 USBD_CONFIGURATION_HANDLE ConfigurationHandle;
371 USBD_INTERFACE_INFORMATION Interface;
372};
373
374typedef struct _USBD_VERSION_INFORMATION {
375 ULONG USBDI_Version;
376 ULONG Supported_USB_Version;
377} USBD_VERSION_INFORMATION, *PUSBD_VERSION_INFORMATION;
378
379typedef struct _URB {
380 union {
381 struct _URB_HEADER UrbHeader;
382 struct _URB_SELECT_INTERFACE UrbSelectInterface;
383 struct _URB_SELECT_CONFIGURATION UrbSelectConfiguration;
384 struct _URB_PIPE_REQUEST UrbPipeRequest;
385 struct _URB_FRAME_LENGTH_CONTROL UrbFrameLengthControl;
386 struct _URB_GET_FRAME_LENGTH UrbGetFrameLength;
387 struct _URB_SET_FRAME_LENGTH UrbSetFrameLength;
388 struct _URB_GET_CURRENT_FRAME_NUMBER UrbGetCurrentFrameNumber;
389 struct _URB_CONTROL_TRANSFER UrbControlTransfer;
390 struct _URB_BULK_OR_INTERRUPT_TRANSFER UrbBulkOrInterruptTransfer;
391 struct _URB_ISOCH_TRANSFER UrbIsochronousTransfer;
392 struct _URB_CONTROL_DESCRIPTOR_REQUEST UrbControlDescriptorRequest;
393 struct _URB_CONTROL_GET_STATUS_REQUEST UrbControlGetStatusRequest;
394 struct _URB_CONTROL_FEATURE_REQUEST UrbControlFeatureRequest;
395 struct _URB_CONTROL_VENDOR_OR_CLASS_REQUEST UrbControlVendorClassRequest;
396 struct _URB_CONTROL_GET_INTERFACE_REQUEST UrbControlGetInterfaceRequest;
397 struct _URB_CONTROL_GET_CONFIGURATION_REQUEST UrbControlGetConfigurationRequest;
398 };
399} URB, *PURB;
400
401#ifdef __cplusplus
402}
403#endif
404
405#endif /* defined __USB_H */
406
407#endif /* __USBDI_H */
Note: See TracBrowser for help on using the repository browser.