1/*++
2
3Copyright (c) Microsoft Corporation. All rights reserved.
4
5Module Name:
6
7        USBDI.H
8
9Abstract:
10
11   structures common to the USBD and USB device drivers.
12
13Environment:
14
15    Kernel & user mode
16
17Revision History:
18
19    09-29-95 : created
20
21--*/
22
23#ifndef   __USBDI_H__
24#define   __USBDI_H__
25
26/*
27Anonymous structures have been removed, if your driver relies on these then
28you must build with the following macro defined.
29
30#define OSR21_COMPAT
31*/
32
33#ifndef _NTDDK_
34#ifndef _WDMDDK_
35typedef void * PIRP;
36typedef void * PMDL;
37#endif
38#endif
39
40#define USBDI_VERSION    0x300
41
42#include "usbioctl.h"
43//
44// USB defined structures and constants
45// (see chapter 9 of USB specification)
46//
47
48#define USB_DEFAULT_DEVICE_ADDRESS     0
49#define USB_DEFAULT_ENDPOINT_ADDRESS   0
50
51//
52// max packet size (bytes) for default endpoint
53// until SET_ADDRESS command is received.
54//
55
56#define USB_DEFAULT_MAX_PACKET         64
57
58//
59// USBD interface structures and constants
60//
61
62
63#define URB_FROM_IRP(Irp) ((IoGetCurrentIrpStackLocation(Irp))->Parameters.Others.Argument1)
64
65//
66//  URB request codes
67//
68
69#define URB_FUNCTION_SELECT_CONFIGURATION            0x0000
70#define URB_FUNCTION_SELECT_INTERFACE                0x0001
71#define URB_FUNCTION_ABORT_PIPE                      0x0002
72#define URB_FUNCTION_TAKE_FRAME_LENGTH_CONTROL       0x0003
73#define URB_FUNCTION_RELEASE_FRAME_LENGTH_CONTROL    0x0004
74#define URB_FUNCTION_GET_FRAME_LENGTH                0x0005
75#define URB_FUNCTION_SET_FRAME_LENGTH                0x0006
76#define URB_FUNCTION_GET_CURRENT_FRAME_NUMBER        0x0007
77#define URB_FUNCTION_CONTROL_TRANSFER                0x0008
78#define URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER      0x0009
79#define URB_FUNCTION_ISOCH_TRANSFER                  0x000A
80#define URB_FUNCTION_RESET_PIPE                      0x001E
81
82//
83// These functions correspond
84// to the standard commands on the default pipe
85//
86// direction is implied
87//
88
89#define URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE     0x000B
90#define URB_FUNCTION_GET_DESCRIPTOR_FROM_ENDPOINT   0x0024
91#define URB_FUNCTION_GET_DESCRIPTOR_FROM_INTERFACE  0x0028
92
93#define URB_FUNCTION_SET_DESCRIPTOR_TO_DEVICE       0x000C
94#define URB_FUNCTION_SET_DESCRIPTOR_TO_ENDPOINT     0x0025
95#define URB_FUNCTION_SET_DESCRIPTOR_TO_INTERFACE    0x0029
96
97#define URB_FUNCTION_SET_FEATURE_TO_DEVICE          0x000D
98#define URB_FUNCTION_SET_FEATURE_TO_INTERFACE       0x000E
99#define URB_FUNCTION_SET_FEATURE_TO_ENDPOINT        0x000F
100#define URB_FUNCTION_SET_FEATURE_TO_OTHER           0x0023
101
102#define URB_FUNCTION_CLEAR_FEATURE_TO_DEVICE        0x0010
103#define URB_FUNCTION_CLEAR_FEATURE_TO_INTERFACE     0x0011
104#define URB_FUNCTION_CLEAR_FEATURE_TO_ENDPOINT      0x0012
105#define URB_FUNCTION_CLEAR_FEATURE_TO_OTHER         0x0022
106
107#define URB_FUNCTION_GET_STATUS_FROM_DEVICE         0x0013
108#define URB_FUNCTION_GET_STATUS_FROM_INTERFACE      0x0014
109#define URB_FUNCTION_GET_STATUS_FROM_ENDPOINT       0x0015
110#define URB_FUNCTION_GET_STATUS_FROM_OTHER          0x0021
111
112// direction is specified in TransferFlags
113
114#define URB_FUNCTION_RESERVED0                      0x0016
115
116//
117// These are for sending vendor and class commands
118// on the default pipe
119//
120// direction is specified in TransferFlags
121//
122
123#define URB_FUNCTION_VENDOR_DEVICE                   0x0017
124#define URB_FUNCTION_VENDOR_INTERFACE                0x0018
125#define URB_FUNCTION_VENDOR_ENDPOINT                 0x0019
126#define URB_FUNCTION_VENDOR_OTHER                    0x0020
127
128#define URB_FUNCTION_CLASS_DEVICE                    0x001A
129#define URB_FUNCTION_CLASS_INTERFACE                 0x001B
130#define URB_FUNCTION_CLASS_ENDPOINT                  0x001C
131#define URB_FUNCTION_CLASS_OTHER                     0x001F
132
133//
134// Reserved function codes
135//
136#define URB_FUNCTION_RESERVED                        0x001D
137
138#define URB_FUNCTION_GET_CONFIGURATION               0x0026
139#define URB_FUNCTION_GET_INTERFACE                   0x0027
140
141#define URB_FUNCTION_LAST                            0x0029
142
143//
144// Values for URB TransferFlags Field
145//
146#define USBD_TRANSFER_DIRECTION(x)            ((x) & USBD_TRANSFER_DIRECTION_IN)
147
148#define USBD_TRANSFER_DIRECTION_OUT           0
149
150#define USBD_TRANSFER_DIRECTION_BIT           0
151#define USBD_TRANSFER_DIRECTION_IN            (1<<USBD_TRANSFER_DIRECTION_BIT)
152
153#define USBD_SHORT_TRANSFER_OK_BIT            1
154#define USBD_SHORT_TRANSFER_OK                (1<<USBD_SHORT_TRANSFER_OK_BIT)
155
156#define USBD_START_ISO_TRANSFER_ASAP_BIT      2
157#define USBD_START_ISO_TRANSFER_ASAP          (1<<USBD_START_ISO_TRANSFER_ASAP_BIT)
158
159
160#define USBD_ISO_START_FRAME_RANGE            1024
161
162typedef LONG USBD_STATUS;
163
164//
165// USBD status codes
166//
167//  Status values are 32 bit values layed out as follows:
168//
169//   3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
170//   1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
171//  +---+---------------------------+-------------------------------+
172//  | S |               Status Code                                 |
173//  +---+---------------------------+-------------------------------+
174//
175//  where
176//
177//      S - is the state code
178//
179//          00 - completed with success
180//          01 - request is pending
181//          10 - completed with error, endpoint not stalled
182//          11 - completed with error, endpoint stalled
183//
184//
185//      Code - is the status code
186//
187
188//
189// Generic test for success on any status value (non-negative numbers
190// indicate success).
191//
192
193#define USBD_SUCCESS(Status) ((USBD_STATUS)(Status) >= 0)
194
195//
196// Generic test for pending status value.
197//
198
199#define USBD_PENDING(Status) ((ULONG)(Status) >> 30 == 1)
200
201//
202// Generic test for error on any status value.
203//
204
205#define USBD_ERROR(Status) ((USBD_STATUS)(Status) < 0)
206
207//
208// Generic test for stall on any status value.
209//
210
211#define USBD_HALTED(Status) ((ULONG)(Status) >> 30 == 3)
212
213//
214// Macro to check the status code only
215//
216
217#define USBD_STATUS(Status) ((ULONG)(Status) & 0x0FFFFFFFL)
218
219
220#define USBD_STATUS_SUCCESS                  ((USBD_STATUS)0x00000000L)
221#define USBD_STATUS_PENDING                  ((USBD_STATUS)0x40000000L)
222#define USBD_STATUS_HALTED                   ((USBD_STATUS)0xC0000000L)
223#define USBD_STATUS_ERROR                    ((USBD_STATUS)0x80000000L)
224
225//
226// HC status codes
227// Note: these status codes have both the error and the stall bit set.
228//
229#define USBD_STATUS_CRC                      ((USBD_STATUS)0xC0000001L)
230#define USBD_STATUS_BTSTUFF                  ((USBD_STATUS)0xC0000002L)
231#define USBD_STATUS_DATA_TOGGLE_MISMATCH     ((USBD_STATUS)0xC0000003L)
232#define USBD_STATUS_STALL_PID                ((USBD_STATUS)0xC0000004L)
233#define USBD_STATUS_DEV_NOT_RESPONDING       ((USBD_STATUS)0xC0000005L)
234#define USBD_STATUS_PID_CHECK_FAILURE        ((USBD_STATUS)0xC0000006L)
235#define USBD_STATUS_UNEXPECTED_PID           ((USBD_STATUS)0xC0000007L)
236#define USBD_STATUS_DATA_OVERRUN             ((USBD_STATUS)0xC0000008L)
237#define USBD_STATUS_DATA_UNDERRUN            ((USBD_STATUS)0xC0000009L)
238#define USBD_STATUS_RESERVED1                ((USBD_STATUS)0xC000000AL)
239#define USBD_STATUS_RESERVED2                ((USBD_STATUS)0xC000000BL)
240#define USBD_STATUS_BUFFER_OVERRUN           ((USBD_STATUS)0xC000000CL)
241#define USBD_STATUS_BUFFER_UNDERRUN          ((USBD_STATUS)0xC000000DL)
242#define USBD_STATUS_NOT_ACCESSED             ((USBD_STATUS)0xC000000FL)
243#define USBD_STATUS_FIFO                     ((USBD_STATUS)0xC0000010L)
244
245//
246// returned by HCD if a transfer is submitted to an endpoint that is
247// stalled
248//
249#define USBD_STATUS_ENDPOINT_HALTED         ((USBD_STATUS)0xC0000030L)
250
251//
252// Software status codes
253// Note: the following status codes have only the error bit set
254//
255#define USBD_STATUS_NO_MEMORY                ((USBD_STATUS)0x80000100L)
256#define USBD_STATUS_INVALID_URB_FUNCTION     ((USBD_STATUS)0x80000200L)
257#define USBD_STATUS_INVALID_PARAMETER        ((USBD_STATUS)0x80000300L)
258
259//
260// returned if client driver attempts to close an endpoint/interface
261// or configuration with outstanding transfers.
262//
263#define USBD_STATUS_ERROR_BUSY               ((USBD_STATUS)0x80000400L)
264//
265// returned by USBD if it cannot complete a URB request, typically this
266// will be returned in the URB status field when the Irp is completed
267// with a more specific NT error code in the irp.status field.
268//
269#define USBD_STATUS_REQUEST_FAILED           ((USBD_STATUS)0x80000500L)
270
271#define USBD_STATUS_INVALID_PIPE_HANDLE      ((USBD_STATUS)0x80000600L)
272
273// returned when there is not enough bandwidth avialable
274// to open a requested endpoint
275#define USBD_STATUS_NO_BANDWIDTH             ((USBD_STATUS)0x80000700L)
276//
277// generic HC error
278//
279#define USBD_STATUS_INTERNAL_HC_ERROR        ((USBD_STATUS)0x80000800L)
280//
281// returned when a short packet terminates the transfer
282// ie USBD_SHORT_TRANSFER_OK bit not set
283//
284#define USBD_STATUS_ERROR_SHORT_TRANSFER     ((USBD_STATUS)0x80000900L)
285//
286// returned if the requested start frame is not within
287// USBD_ISO_START_FRAME_RANGE of the current USB frame,
288// note that the stall bit is set
289//
290#define USBD_STATUS_BAD_START_FRAME          ((USBD_STATUS)0xC0000A00L)
291//
292// returned by HCD if all packets in an iso transfer complete with an error
293//
294#define USBD_STATUS_ISOCH_REQUEST_FAILED     ((USBD_STATUS)0xC0000B00L)
295//
296// returned by USBD if the frame length control for a given
297// HC is already taken by anothe driver
298//
299#define USBD_STATUS_FRAME_CONTROL_OWNED      ((USBD_STATUS)0xC0000C00L)
300//
301// returned by USBD if the caller does not own frame length control and
302// attempts to release or modify the HC frame length
303//
304#define USBD_STATUS_FRAME_CONTROL_NOT_OWNED  ((USBD_STATUS)0xC0000D00L)
305
306//
307// set when a transfers is completed due to an AbortPipe request from
308// the client driver
309//
310// Note: no error or stall bit is set for these status codes
311//
312#define USBD_STATUS_CANCELED                 ((USBD_STATUS)0x00010000L)
313
314#define USBD_STATUS_CANCELING                ((USBD_STATUS)0x00020000L)
315
316//
317// taken from usb.h
318#define USBD_STATUS_INAVLID_CONFIGURATION_DESCRIPTOR \
319                                             ((USBD_STATUS)0xC0000F00L)
320
321
322typedef PVOID USBD_PIPE_HANDLE;
323typedef PVOID USBD_CONFIGURATION_HANDLE;
324typedef PVOID USBD_INTERFACE_HANDLE;
325
326//
327// Value used to indicate the default max transfer size
328//
329
330#define USBD_DEFAULT_MAXIMUM_TRANSFER_SIZE  PAGE_SIZE
331
332
333//
334// structure returned from USBD_GetVersion function
335//
336
337typedef struct _USBD_VERSION_INFORMATION {
338    ULONG USBDI_Version;          //BCD usb interface version number
339    ULONG Supported_USB_Version;  //BCD USB spec version number
340}__attribute__((packed)) USBD_VERSION_INFORMATION, *PUSBD_VERSION_INFORMATION;
341
342typedef enum _USBD_PIPE_TYPE {
343    UsbdPipeTypeControl,
344    UsbdPipeTypeIsochronous,
345    UsbdPipeTypeBulk,
346    UsbdPipeTypeInterrupt
347}__attribute__((packed)) USBD_PIPE_TYPE;
348
349#define USBD_PIPE_DIRECTION_IN(pipeInformation) ((pipeInformation)->EndpointAddress & \
350                                                  USB_ENDPOINT_DIRECTION_MASK)
351
352typedef struct _USBD_DEVICE_INFORMATION {
353    ULONG OffsetNext;
354    PVOID UsbdDeviceHandle;
355    USB_DEVICE_DESCRIPTOR DeviceDescriptor;
356}__attribute__((packed)) USBD_DEVICE_INFORMATION, *PUSBD_DEVICE_INFORMATION;
357
358//
359//      URB request structures
360//
361
362//
363// USBD pipe information structure, this structure
364// is returned for each pipe opened thru an
365// SELECT_CONFIGURATION or SELECT_INTERFACE request.
366//
367
368typedef struct _USBD_PIPE_INFORMATION {
369    //
370    // OUTPUT
371    // These fields are filled in by USBD
372    //
373    USHORT MaximumPacketSize;  // Maximum packet size for this pipe
374    UCHAR EndpointAddress;     // 8 bit USB endpoint address (includes direction)
375                               // taken from endpoint descriptor
376    UCHAR Interval;            // Polling interval in ms if interrupt pipe
377
378    USBD_PIPE_TYPE PipeType;   // PipeType identifies type of transfer valid for this pipe
379    UCHAR empty[3];
380    USBD_PIPE_HANDLE PipeHandle;
381
382    //
383    // INPUT
384    // These fields are filled in by the client driver
385    //
386    ULONG MaximumTransferSize; // Maximum size for a single request
387                               // in bytes.
388    ULONG PipeFlags;
389}__attribute__((packed)) USBD_PIPE_INFORMATION, *PUSBD_PIPE_INFORMATION;
390
391//
392// values for PipeFlags field in USBD_PIPE_INFORMATION field
393//
394
395#define USBD_PF_CHANGE_MAX_PACKET       0x00000001
396#define USBD_PF_DOUBLE_BUFFER           0x00000002
397#define USBD_PF_ENABLE_RT_THREAD_ACCESS 0x00000004
398#define USBD_PF_MAP_ADD_TRANSFERS       0x00000008
399
400#define USBD_PF_VALID_MASK    (USBD_PF_CHANGE_MAX_PACKET | \
401                               USBD_PF_DOUBLE_BUFFER | \
402                               USBD_PF_ENABLE_RT_THREAD_ACCESS | \
403                               USBD_PF_MAP_ADD_TRANSFERS)
404//
405// USBD interface information structure, this structure
406// is returned for each interface opened thru an
407// SELECT_CONFIGURATION or SELECT_INTERFACE request.
408//
409
410typedef struct _USBD_INTERFACE_INFORMATION {
411    USHORT Length;       // Length of this structure, including
412                         // all pipe information structures that
413                         // follow.
414    //
415    // INPUT
416    //
417    // Interface number and Alternate setting this
418    // structure is associated with
419    //
420    UCHAR InterfaceNumber;
421    UCHAR AlternateSetting;
422
423    //
424    // OUTPUT
425    // These fields are filled in by USBD
426    //
427    UCHAR Class;
428    UCHAR SubClass;
429    UCHAR Protocol;
430    UCHAR Reserved;
431
432    USBD_INTERFACE_HANDLE InterfaceHandle;
433    ULONG NumberOfPipes;
434
435    //
436    // INPUT/OUPUT
437    // see PIPE_INFORMATION
438#ifdef OSR21_COMPAT
439    USBD_PIPE_INFORMATION Pipes[0];
440#else
441    USBD_PIPE_INFORMATION Pipes[1];
442#endif
443}__attribute__((packed)) USBD_INTERFACE_INFORMATION, *PUSBD_INTERFACE_INFORMATION;
444
445//
446// work space in transfer request provided
447// for HCDs
448//
449
450struct _URB_HCD_AREA {
451    PVOID HcdEndpoint;
452    PIRP HcdIrp;
453    LIST_ENTRY HcdListEntry;
454    LIST_ENTRY HcdListEntry2;
455    PVOID HcdCurrentIoFlushPointer;
456    PVOID HcdExtension;
457}__attribute__((packed));
458
459
460struct _URB_HEADER {
461    //
462    // Fields filled in by client driver
463    //
464    USHORT Length;
465    USHORT Function;
466    USBD_STATUS Status;
467    //
468    // Fields used only by USBD
469    //
470    PVOID UsbdDeviceHandle; // device handle assigned to this device
471                            // by USBD
472    ULONG UsbdFlags;        // flags field reserved for USBD use.
473}__attribute__((packed));
474
475struct _URB_SELECT_INTERFACE {
476#ifdef OSR21_COMPAT
477    struct _URB_HEADER;
478#else
479    struct _URB_HEADER Hdr;                 // function code indicates get or set.
480#endif
481    USBD_CONFIGURATION_HANDLE ConfigurationHandle;
482
483    // client must input AlternateSetting & Interface Number
484    // class driver returns interface and handle
485    // for new alternate setting
486    USBD_INTERFACE_INFORMATION Interface;
487}__attribute__((packed));
488
489struct _URB_SELECT_CONFIGURATION {
490#ifdef OSR21_COMPAT
491    struct _URB_HEADER;
492#else
493    struct _URB_HEADER Hdr;                 // function code indicates get or set.
494#endif
495    // NULL indicates to set the device
496    // to the 'unconfigured' state
497    // ie set to configuration 0
498    PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor;
499    USBD_CONFIGURATION_HANDLE ConfigurationHandle;
500    USBD_INTERFACE_INFORMATION Interface;
501}__attribute__((packed));
502
503//
504// This structure used for ABORT_PIPE & RESET_PIPE
505//
506
507struct _URB_PIPE_REQUEST {
508#ifdef OSR21_COMPAT
509    struct _URB_HEADER;
510#else
511    struct _URB_HEADER Hdr;                 // function code indicates get or set.
512#endif
513    USBD_PIPE_HANDLE PipeHandle;
514    ULONG Reserved;
515}__attribute__((packed));
516
517//
518// This structure used for
519// TAKE_FRAME_LENGTH_CONTROL &
520//        RELEASE_FRAME_LENGTH_CONTROL
521//
522
523struct _URB_FRAME_LENGTH_CONTROL {
524#ifdef OSR21_COMPAT
525    struct _URB_HEADER;
526#else
527    struct _URB_HEADER Hdr;                 // function code indicates get or set.
528#endif
529};
530
531struct _URB_GET_FRAME_LENGTH {
532#ifdef OSR21_COMPAT
533    struct _URB_HEADER;
534#else
535    struct _URB_HEADER Hdr;                 // function code indicates get or set.
536#endif
537    ULONG FrameLength;
538    ULONG FrameNumber;
539}__attribute__((packed));
540
541struct _URB_SET_FRAME_LENGTH {
542#ifdef OSR21_COMPAT
543    struct _URB_HEADER;
544#else
545    struct _URB_HEADER Hdr;                 // function code indicates get or set.
546#endif
547    LONG FrameLengthDelta;
548}__attribute__((packed));
549
550struct _URB_GET_CURRENT_FRAME_NUMBER {
551#ifdef OSR21_COMPAT
552    struct _URB_HEADER;
553#else
554    struct _URB_HEADER Hdr;                 // function code indicates get or set.
555#endif
556    ULONG FrameNumber;
557}__attribute__((packed));
558
559//
560// Structures for specific control transfers
561// on the default pipe.
562//
563
564// GET_DESCRIPTOR
565// SET_DESCRIPTOR
566
567struct _URB_CONTROL_DESCRIPTOR_REQUEST {
568#ifdef OSR21_COMPAT
569    struct _URB_HEADER;
570#else
571    struct _URB_HEADER Hdr;                 // function code indicates get or set.
572#endif
573    PVOID Reserved;
574    ULONG Reserved0;
575    ULONG TransferBufferLength;
576    PVOID TransferBuffer;
577    PMDL TransferBufferMDL;             // *optional*
578    struct _URB *UrbLink;               // *optional* link to next urb request
579                                        // if this is a chain of commands
580    struct _URB_HCD_AREA hca;               // fields for HCD use
581    USHORT Reserved1;
582    UCHAR Index;
583    UCHAR DescriptorType;
584    USHORT LanguageId;
585    USHORT Reserved2;
586}__attribute__((packed));
587
588// GET_STATUS
589
590struct _URB_CONTROL_GET_STATUS_REQUEST {
591#ifdef OSR21_COMPAT
592    struct _URB_HEADER;
593#else
594    struct _URB_HEADER Hdr;                 // function code indicates get or set.
595#endif
596    PVOID Reserved;
597    ULONG Reserved0;
598    ULONG TransferBufferLength;
599    PVOID TransferBuffer;
600    PMDL TransferBufferMDL;             // *optional*
601    struct _URB *UrbLink;               // *optional* link to next urb request
602                                        // if this is a chain of commands
603    struct _URB_HCD_AREA hca;           // fields for HCD use
604    UCHAR Reserved1[4];
605    USHORT Index;                       // zero, interface or endpoint
606    USHORT Reserved2;
607}__attribute__((packed));
608
609// SET_FEATURE
610// CLEAR_FEATURE
611
612struct _URB_CONTROL_FEATURE_REQUEST {
613#ifdef OSR21_COMPAT
614    struct _URB_HEADER;
615#else
616    struct _URB_HEADER Hdr;                 // function code indicates get or set.
617#endif
618    PVOID Reserved;
619    ULONG Reserved2;
620    ULONG Reserved3;
621    PVOID Reserved4;
622    PMDL Reserved5;
623    struct _URB *UrbLink;               // *optional* link to next urb request
624                                        // if this is a chain of commands
625    struct _URB_HCD_AREA hca;           // fields for HCD use
626    USHORT Reserved0;
627    USHORT FeatureSelector;
628    USHORT Index;                       // zero, interface or endpoint
629    USHORT Reserved1;
630}__attribute__((packed));
631
632// VENDOR & CLASS
633
634struct _URB_CONTROL_VENDOR_OR_CLASS_REQUEST {
635#ifdef OSR21_COMPAT
636    struct _URB_HEADER;
637#else
638    struct _URB_HEADER Hdr;                 // function code indicates get or set.
639#endif
640    PVOID Reserved;
641    ULONG TransferFlags;
642    ULONG TransferBufferLength;
643    PVOID TransferBuffer;
644    PMDL TransferBufferMDL;             // *optional*
645    struct _URB *UrbLink;               // *optional* link to next urb request
646                                        // if this is a chain of commands
647    struct _URB_HCD_AREA hca;           // fields for HCD use
648    UCHAR RequestTypeReservedBits;
649    UCHAR Request;
650    USHORT Value;
651    USHORT Index;
652    USHORT Reserved1;
653}__attribute__((packed));
654
655
656struct _URB_CONTROL_GET_INTERFACE_REQUEST {
657#ifdef OSR21_COMPAT
658    struct _URB_HEADER;
659#else
660    struct _URB_HEADER Hdr;                 // function code indicates get or set.
661#endif
662    PVOID Reserved;
663    ULONG Reserved0;
664    ULONG TransferBufferLength;
665    PVOID TransferBuffer;
666    PMDL TransferBufferMDL;             // *optional*
667    struct _URB *UrbLink;               // *optional* link to next urb request
668                                        // if this is a chain of commands
669    struct _URB_HCD_AREA hca;           // fields for HCD use
670    UCHAR Reserved1[4];
671    USHORT Interface;
672    USHORT Reserved2;
673}__attribute__((packed));
674
675
676struct _URB_CONTROL_GET_CONFIGURATION_REQUEST {
677#ifdef OSR21_COMPAT
678    struct _URB_HEADER Hdr;
679#else
680    struct _URB_HEADER Hdr;                 // function code indicates get or set.
681#endif
682    PVOID Reserved;
683    ULONG Reserved0;
684    ULONG TransferBufferLength;
685    PVOID TransferBuffer;
686    PMDL TransferBufferMDL;             // *optional*
687    struct _URB *UrbLink;               // *optional* link to next urb request
688                                        // if this is a chain of commands
689    struct _URB_HCD_AREA hca;           // fields for HCD use
690    UCHAR Reserved1[8];
691}__attribute__((packed));
692
693
694//
695// request format for a control transfer on
696// the non-default pipe.
697//
698
699struct _URB_CONTROL_TRANSFER {
700#ifdef OSR21_COMPAT
701    struct _URB_HEADER;
702#else
703    struct _URB_HEADER Hdr;                 // function code indicates get or set.
704#endif
705    USBD_PIPE_HANDLE PipeHandle;
706    ULONG TransferFlags;
707    ULONG TransferBufferLength;
708    PVOID TransferBuffer;
709    PMDL TransferBufferMDL;             // *optional*
710    struct _URB *UrbLink;               // *optional* link to next urb request
711                                        // if this is a chain of commands
712    struct _URB_HCD_AREA hca;           // fields for HCD use
713    UCHAR SetupPacket[8];
714}__attribute__((packed));
715
716
717struct _URB_BULK_OR_INTERRUPT_TRANSFER {
718#ifdef OSR21_COMPAT
719    struct _URB_HEADER;
720#else
721    struct _URB_HEADER Hdr;                 // function code indicates get or set.
722#endif
723    USBD_PIPE_HANDLE PipeHandle;
724    ULONG TransferFlags;                // note: the direction bit will be set by USBD
725    ULONG TransferBufferLength;
726    PVOID TransferBuffer;
727    PMDL TransferBufferMDL;             // *optional*
728    struct _URB *UrbLink;               // *optional* link to next urb request
729                                        // if this is a chain of commands
730    struct _URB_HCD_AREA hca;           // fields for HCD use
731}__attribute__((packed));
732
733
734//
735// ISO Transfer request
736//
737// TransferBufferMDL must point to a single virtually
738// contiguous buffer.
739//
740// StartFrame - the frame to send/receive the first packet of
741// the request.
742//
743// NumberOfPackets - number of packets to send in this request
744//
745//
746// IsoPacket Array
747//
748//      Input:  Offset - offset of the packet from the beginig
749//                 of the client buffer.
750//      Output: Length -  is set to the actual length of the packet
751//                (For IN transfers).
752//      Status: error that occurred during transmission or
753//              reception of the packet.
754//
755
756typedef struct _USBD_ISO_PACKET_DESCRIPTOR {
757    ULONG Offset;       // INPUT Offset of the packet from the begining of the
758                        // buffer.
759
760    ULONG Length;       // OUTPUT length of data received (for in).
761                        // OUTPUT 0 for OUT.
762    USBD_STATUS Status; // status code for this packet.
763}__attribute__((packed)) USBD_ISO_PACKET_DESCRIPTOR, *PUSBD_ISO_PACKET_DESCRIPTOR;
764
765struct _URB_ISOCH_TRANSFER {
766    //
767    // This block is the same as CommonTransfer
768    //
769#ifdef OSR21_COMPAT
770    struct _URB_HEADER;
771#else
772    struct _URB_HEADER Hdr;                 // function code indicates get or set.
773#endif
774    USBD_PIPE_HANDLE PipeHandle;
775    ULONG TransferFlags;
776    ULONG TransferBufferLength;
777    PVOID TransferBuffer;
778    PMDL TransferBufferMDL;             // *optional*
779    struct _URB *UrbLink;               // *optional* link to next urb request
780                                        // if this is a chain of commands
781    struct _URB_HCD_AREA hca;           // fields for HCD use
782
783    //
784    // this block contains transfer fields
785    // specific to isochronous transfers
786    //
787
788    // 32 bit frame number to begin this transfer on, must be within 1000
789    // frames of the current USB frame or an error is returned.
790
791    // START_ISO_TRANSFER_ASAP flag in transferFlags:
792    // If this flag is set and no transfers have been submitted
793    // for the pipe then the transfer will begin on the next frame
794    // and StartFrame will be updated with the frame number the transfer
795    // was started on.
796    // If this flag is set and the pipe has active transfers then
797    // the transfer will be queued to begin on the frame after the
798    // last transfer queued is completed.
799    //
800    ULONG StartFrame;
801    // number of packets that make up this request
802    ULONG NumberOfPackets;
803    // number of packets that completed with errors
804    ULONG ErrorCount;
805#ifdef OSR21_COMPAT
806    USBD_ISO_PACKET_DESCRIPTOR IsoPacket[0];
807#else
808    USBD_ISO_PACKET_DESCRIPTOR IsoPacket[1];
809#endif
810}__attribute__((packed));
811
812
813typedef struct _URB {
814    union {
815            struct _URB_HEADER                           UrbHeader;
816            struct _URB_SELECT_INTERFACE                 UrbSelectInterface;
817            struct _URB_SELECT_CONFIGURATION             UrbSelectConfiguration;
818            struct _URB_PIPE_REQUEST                     UrbPipeRequest;
819            struct _URB_FRAME_LENGTH_CONTROL             UrbFrameLengthControl;
820            struct _URB_GET_FRAME_LENGTH                 UrbGetFrameLength;
821            struct _URB_SET_FRAME_LENGTH                 UrbSetFrameLength;
822            struct _URB_GET_CURRENT_FRAME_NUMBER         UrbGetCurrentFrameNumber;
823            struct _URB_CONTROL_TRANSFER                 UrbControlTransfer;
824            struct _URB_BULK_OR_INTERRUPT_TRANSFER       UrbBulkOrInterruptTransfer;
825            struct _URB_ISOCH_TRANSFER                   UrbIsochronousTransfer;
826
827            // for standard control transfers on the default pipe
828            struct _URB_CONTROL_DESCRIPTOR_REQUEST       UrbControlDescriptorRequest;
829            struct _URB_CONTROL_GET_STATUS_REQUEST       UrbControlGetStatusRequest;
830            struct _URB_CONTROL_FEATURE_REQUEST          UrbControlFeatureRequest;
831            struct _URB_CONTROL_VENDOR_OR_CLASS_REQUEST  UrbControlVendorClassRequest;
832            struct _URB_CONTROL_GET_INTERFACE_REQUEST    UrbControlGetInterfaceRequest;
833            struct _URB_CONTROL_GET_CONFIGURATION_REQUEST UrbControlGetConfigurationRequest;
834    };
835}__attribute__((packed))  URB, *PURB;
836
837
838#endif /*  __USBDI_H__ */
839
840