Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

836 lines
26 KiB

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