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.

1050 lines
34 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. USB.H
  5. Abstract:
  6. structures and APIs for USB drivers.
  7. Environment:
  8. Kernel & user mode
  9. Revision History:
  10. 09-29-95 : created
  11. --*/
  12. #ifndef __USB_H__
  13. #define __USB_H__
  14. /*
  15. This file is equivalent to USBDI.H with extensions supported by
  16. usbport.sys for eUSB.
  17. This file replaces usbdi.h and is compatible with older versions
  18. of the USB stack.
  19. */
  20. #ifdef __USBDI_H__
  21. error
  22. #endif
  23. #ifdef OSR21_COMPAT
  24. #pragma message("WARNING: OSR21_COMPAT SWITCH NOT SUPPORTED")
  25. #endif
  26. #ifndef _NTDDK_
  27. #ifndef _WDMDDK_
  28. typedef PVOID PIRP;
  29. typedef PVOID PMDL;
  30. #endif
  31. #endif
  32. #define USBDI_VERSION 0x00000500
  33. #include "usb200.h"
  34. #ifdef _WDMDDK_
  35. #endif
  36. /*
  37. Microsoft Extended Port Attribute Flags
  38. */
  39. #define USB_PORTATTR_NO_CONNECTOR 0x00000001
  40. #define USB_PORTATTR_SHARED_USB2 0x00000002
  41. #define USB_PORTATTR_MINI_CONNECTOR 0x00000004
  42. #define USB_PORTATTR_OEM_CONNECTOR 0x00000008
  43. /* dynamic attributes */
  44. #define USB_PORTATTR_OWNED_BY_CC 0x01000000
  45. #define USB_PORTATTR_NO_OVERCURRENT_UI 0x02000000
  46. /* define USB controller flavors:
  47. These are all known HW implementations that require special
  48. hacks.
  49. */
  50. typedef enum _USB_CONTROLLER_FLAVOR {
  51. USB_HcGeneric = 0,
  52. OHCI_Generic = 100,
  53. OHCI_Hydra,
  54. OHCI_NEC,
  55. UHCI_Generic = 200,
  56. UHCI_Piix4,
  57. UHCI_Piix3,
  58. UHCI_Ich2_1,
  59. UHCI_Ich2_2,
  60. UHCI_Ich1,
  61. UHCI_VIA = 250,
  62. EHCI_Generic = 1000,
  63. EHCI_NEC = 2000,
  64. EHCI_Lucent = 3000
  65. } USB_CONTROLLER_FLAVOR;
  66. //
  67. // USB defined structures and constants
  68. // (see chapter 9 of USB specification)
  69. //
  70. #define USB_DEFAULT_DEVICE_ADDRESS 0
  71. #define USB_DEFAULT_ENDPOINT_ADDRESS 0
  72. //
  73. // max packet size (bytes) for default endpoint
  74. // until SET_ADDRESS command is received.
  75. //
  76. #define USB_DEFAULT_MAX_PACKET 64
  77. //
  78. // USBD interface structures and constants
  79. //
  80. #define URB_FROM_IRP(Irp) ((IoGetCurrentIrpStackLocation(Irp))->Parameters.Others.Argument1)
  81. //
  82. // URB request codes
  83. //
  84. #define URB_FUNCTION_SELECT_CONFIGURATION 0x0000
  85. #define URB_FUNCTION_SELECT_INTERFACE 0x0001
  86. #define URB_FUNCTION_ABORT_PIPE 0x0002
  87. #define URB_FUNCTION_TAKE_FRAME_LENGTH_CONTROL 0x0003
  88. #define URB_FUNCTION_RELEASE_FRAME_LENGTH_CONTROL 0x0004
  89. #define URB_FUNCTION_GET_FRAME_LENGTH 0x0005
  90. #define URB_FUNCTION_SET_FRAME_LENGTH 0x0006
  91. #define URB_FUNCTION_GET_CURRENT_FRAME_NUMBER 0x0007
  92. #define URB_FUNCTION_CONTROL_TRANSFER 0x0008
  93. #define URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER 0x0009
  94. #define URB_FUNCTION_ISOCH_TRANSFER 0x000A
  95. #define URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE 0x000B
  96. #define URB_FUNCTION_SET_DESCRIPTOR_TO_DEVICE 0x000C
  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_CLEAR_FEATURE_TO_DEVICE 0x0010
  101. #define URB_FUNCTION_CLEAR_FEATURE_TO_INTERFACE 0x0011
  102. #define URB_FUNCTION_CLEAR_FEATURE_TO_ENDPOINT 0x0012
  103. #define URB_FUNCTION_GET_STATUS_FROM_DEVICE 0x0013
  104. #define URB_FUNCTION_GET_STATUS_FROM_INTERFACE 0x0014
  105. #define URB_FUNCTION_GET_STATUS_FROM_ENDPOINT 0x0015
  106. #define URB_FUNCTION_RESERVED_0X0016 0x0016
  107. #define URB_FUNCTION_VENDOR_DEVICE 0x0017
  108. #define URB_FUNCTION_VENDOR_INTERFACE 0x0018
  109. #define URB_FUNCTION_VENDOR_ENDPOINT 0x0019
  110. #define URB_FUNCTION_CLASS_DEVICE 0x001A
  111. #define URB_FUNCTION_CLASS_INTERFACE 0x001B
  112. #define URB_FUNCTION_CLASS_ENDPOINT 0x001C
  113. #define URB_FUNCTION_RESERVE_0X001D 0x001D
  114. // previously URB_FUNCTION_RESET_PIPE
  115. #define URB_FUNCTION_SYNC_RESET_PIPE_AND_CLEAR_STALL 0x001E
  116. #define URB_FUNCTION_CLASS_OTHER 0x001F
  117. #define URB_FUNCTION_VENDOR_OTHER 0x0020
  118. #define URB_FUNCTION_GET_STATUS_FROM_OTHER 0x0021
  119. #define URB_FUNCTION_CLEAR_FEATURE_TO_OTHER 0x0022
  120. #define URB_FUNCTION_SET_FEATURE_TO_OTHER 0x0023
  121. #define URB_FUNCTION_GET_DESCRIPTOR_FROM_ENDPOINT 0x0024
  122. #define URB_FUNCTION_SET_DESCRIPTOR_TO_ENDPOINT 0x0025
  123. #define URB_FUNCTION_GET_CONFIGURATION 0x0026
  124. #define URB_FUNCTION_GET_INTERFACE 0x0027
  125. #define URB_FUNCTION_GET_DESCRIPTOR_FROM_INTERFACE 0x0028
  126. #define URB_FUNCTION_SET_DESCRIPTOR_TO_INTERFACE 0x0029
  127. // Rserveve 0x002B-0x002F
  128. #define URB_FUNCTION_GET_MS_FEATURE_DESCRIPTOR 0x002A
  129. #define URB_FUNCTION_RESERVE_0X002B 0x002B
  130. #define URB_FUNCTION_RESERVE_0X002C 0x002C
  131. #define URB_FUNCTION_RESERVE_0X002D 0x002D
  132. #define URB_FUNCTION_RESERVE_0X002E 0x002E
  133. #define URB_FUNCTION_RESERVE_0X002F 0x002F
  134. // USB 2.0 calls start at 0x0030
  135. #define URB_FUNCTION_SYNC_RESET_PIPE 0x0030
  136. #define URB_FUNCTION_SYNC_CLEAR_STALL 0x0031
  137. // for backward drivers
  138. #define URB_FUNCTION_RESET_PIPE \
  139. URB_FUNCTION_SYNC_RESET_PIPE_AND_CLEAR_STALL
  140. /* Control Pipe Function Groupings
  141. These functions correspond to the standard commands
  142. on the default pipe, direction is implied
  143. URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE
  144. URB_FUNCTION_GET_DESCRIPTOR_FROM_ENDPOINT
  145. URB_FUNCTION_GET_DESCRIPTOR_FROM_INTERFACE
  146. URB_FUNCTION_SET_DESCRIPTOR_TO_DEVICE
  147. URB_FUNCTION_SET_DESCRIPTOR_TO_ENDPOINT
  148. URB_FUNCTION_SET_DESCRIPTOR_TO_INTERFACE
  149. URB_FUNCTION_SET_FEATURE_TO_DEVICE
  150. URB_FUNCTION_SET_FEATURE_TO_INTERFACE
  151. URB_FUNCTION_SET_FEATURE_TO_ENDPOINT
  152. URB_FUNCTION_SET_FEATURE_TO_OTHER
  153. URB_FUNCTION_CLEAR_FEATURE_TO_DEVICE
  154. URB_FUNCTION_CLEAR_FEATURE_TO_INTERFACE
  155. URB_FUNCTION_CLEAR_FEATURE_TO_ENDPOINT
  156. URB_FUNCTION_CLEAR_FEATURE_TO_OTHER
  157. URB_FUNCTION_GET_STATUS_FROM_DEVICE
  158. URB_FUNCTION_GET_STATUS_FROM_INTERFACE
  159. URB_FUNCTION_GET_STATUS_FROM_ENDPOINT
  160. URB_FUNCTION_GET_STATUS_FROM_OTHER
  161. URB_FUNCTION_VENDOR_DEVICE
  162. URB_FUNCTION_VENDOR_INTERFACE
  163. URB_FUNCTION_VENDOR_ENDPOINT
  164. URB_FUNCTION_VENDOR_OTHER
  165. URB_FUNCTION_CLASS_DEVICE
  166. URB_FUNCTION_CLASS_INTERFACE
  167. URB_FUNCTION_CLASS_ENDPOINT
  168. URB_FUNCTION_CLASS_OTHER
  169. */
  170. //
  171. // Values for URB TransferFlags Field
  172. //
  173. /*
  174. Set if data moves device->host
  175. */
  176. #define USBD_TRANSFER_DIRECTION 0x00000001
  177. /*
  178. This bit if not set indicates that a short packet, and hence,
  179. a short transfer is an error condition
  180. */
  181. #define USBD_SHORT_TRANSFER_OK 0x00000002
  182. /*
  183. Subit the iso transfer on the next frame
  184. */
  185. #define USBD_START_ISO_TRANSFER_ASAP 0x00000004
  186. #define USBD_DEFAULT_PIPE_TRANSFER 0x00000008
  187. #define USBD_TRANSFER_DIRECTION_FLAG(flags) ((flags) & USBD_TRANSFER_DIRECTION)
  188. #define USBD_TRANSFER_DIRECTION_OUT 0
  189. #define USBD_TRANSFER_DIRECTION_IN 1
  190. #define VALID_TRANSFER_FLAGS_MASK (USBD_SHORT_TRANSFER_OK | \
  191. USBD_TRANSFER_DIRECTION | \
  192. USBD_START_ISO_TRANSFER_ASAP | \
  193. USBD_DEFAULT_PIPE_TRANSFER)
  194. #define USBD_ISO_START_FRAME_RANGE 1024
  195. typedef LONG USBD_STATUS;
  196. //
  197. // USBD status codes
  198. //
  199. // Status values are 32 bit values layed out as follows:
  200. //
  201. // 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
  202. // 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
  203. // +---+---------------------------+-------------------------------+
  204. // | S | Status Code |
  205. // +---+---------------------------+-------------------------------+
  206. //
  207. // where
  208. //
  209. // S - is the state code
  210. //
  211. // 00 - completed with success
  212. // 01 - request is pending
  213. // 11, 10 - completed with error
  214. //
  215. //
  216. // Code - is the status code
  217. //
  218. //
  219. // Generic test for success on any status value (non-negative numbers
  220. // indicate success).
  221. //
  222. #define USBD_SUCCESS(Status) ((USBD_STATUS)(Status) >= 0)
  223. //
  224. // Generic test for pending status value.
  225. //
  226. #define USBD_PENDING(Status) ((ULONG)(Status) >> 30 == 1)
  227. //
  228. // Generic test for error on any status value.
  229. //
  230. #define USBD_ERROR(Status) ((USBD_STATUS)(Status) < 0)
  231. //
  232. // Macro to check the status code only
  233. //
  234. //
  235. //define USBD_STATUS(Status) ((ULONG)(Status) & 0x0FFFFFFFL)
  236. // the high order bits (0xC) will always be set on an error
  237. #define USBD_STATUS_SUCCESS ((USBD_STATUS)0x00000000L)
  238. #define USBD_STATUS_PENDING ((USBD_STATUS)0x40000000L)
  239. //
  240. //#define USBD_STATUS_ERROR ((USBD_STATUS)0xC0000000L)
  241. // The following are defined for backward compatibility with the usb 1.0 stack
  242. //
  243. // HC (Hardware) status codes range 0x00000001 - 0x000000FF
  244. //
  245. #define USBD_STATUS_CRC ((USBD_STATUS)0xC0000001L)
  246. #define USBD_STATUS_BTSTUFF ((USBD_STATUS)0xC0000002L)
  247. #define USBD_STATUS_DATA_TOGGLE_MISMATCH ((USBD_STATUS)0xC0000003L)
  248. #define USBD_STATUS_STALL_PID ((USBD_STATUS)0xC0000004L)
  249. #define USBD_STATUS_DEV_NOT_RESPONDING ((USBD_STATUS)0xC0000005L)
  250. #define USBD_STATUS_PID_CHECK_FAILURE ((USBD_STATUS)0xC0000006L)
  251. #define USBD_STATUS_UNEXPECTED_PID ((USBD_STATUS)0xC0000007L)
  252. #define USBD_STATUS_DATA_OVERRUN ((USBD_STATUS)0xC0000008L)
  253. #define USBD_STATUS_DATA_UNDERRUN ((USBD_STATUS)0xC0000009L)
  254. #define USBD_STATUS_RESERVED1 ((USBD_STATUS)0xC000000AL)
  255. #define USBD_STATUS_RESERVED2 ((USBD_STATUS)0xC000000BL)
  256. #define USBD_STATUS_BUFFER_OVERRUN ((USBD_STATUS)0xC000000CL)
  257. #define USBD_STATUS_BUFFER_UNDERRUN ((USBD_STATUS)0xC000000DL)
  258. #define USBD_STATUS_NOT_ACCESSED ((USBD_STATUS)0xC000000FL)
  259. #define USBD_STATUS_FIFO ((USBD_STATUS)0xC0000010L)
  260. #define USBD_STATUS_XACT_ERROR ((USBD_STATUS)0xC0000011L)
  261. #define USBD_STATUS_BABBLE_DETECTED ((USBD_STATUS)0xC0000012L)
  262. #define USBD_STATUS_DATA_BUFFER_ERROR ((USBD_STATUS)0xC0000013L)
  263. //
  264. // returned by HCD if a transfer is submitted to an endpoint that is
  265. // stalled
  266. //
  267. #define USBD_STATUS_ENDPOINT_HALTED ((USBD_STATUS)0xC0000030L)
  268. //
  269. // Software status codes
  270. //
  271. #define USBD_STATUS_INVALID_URB_FUNCTION ((USBD_STATUS)0x80000200L)
  272. #define USBD_STATUS_INVALID_PARAMETER ((USBD_STATUS)0x80000300L)
  273. //
  274. // returned if client driver attempts to close an endpoint/interface
  275. // or configuration with outstanding transfers.
  276. //
  277. #define USBD_STATUS_ERROR_BUSY ((USBD_STATUS)0x80000400L)
  278. //
  279. // returned by USBD if it cannot complete a URB request, typically this
  280. // will be returned in the URB status field when the Irp is completed
  281. // with a more specific NT error code in the irp.status field.
  282. //
  283. //#define USBD_STATUS_REQUEST_FAILED ((USBD_STATUS)0x80000500L)
  284. #define USBD_STATUS_INVALID_PIPE_HANDLE ((USBD_STATUS)0x80000600L)
  285. // returned when there is not enough bandwidth avialable
  286. // to open a requested endpoint
  287. #define USBD_STATUS_NO_BANDWIDTH ((USBD_STATUS)0x80000700L)
  288. //
  289. // generic HC error
  290. //
  291. #define USBD_STATUS_INTERNAL_HC_ERROR ((USBD_STATUS)0x80000800L)
  292. //
  293. // returned when a short packet terminates the transfer
  294. // ie USBD_SHORT_TRANSFER_OK bit not set
  295. //
  296. #define USBD_STATUS_ERROR_SHORT_TRANSFER ((USBD_STATUS)0x80000900L)
  297. //
  298. // returned if the requested start frame is not within
  299. // USBD_ISO_START_FRAME_RANGE of the current USB frame,
  300. // note that the stall bit is set
  301. //
  302. #define USBD_STATUS_BAD_START_FRAME ((USBD_STATUS)0xC0000A00L)
  303. //
  304. // returned by HCD if all packets in an iso transfer complete with an error
  305. //
  306. #define USBD_STATUS_ISOCH_REQUEST_FAILED ((USBD_STATUS)0xC0000B00L)
  307. //
  308. // returned by USBD if the frame length control for a given
  309. // HC is already taken by anothe driver
  310. //
  311. #define USBD_STATUS_FRAME_CONTROL_OWNED ((USBD_STATUS)0xC0000C00L)
  312. //
  313. // returned by USBD if the caller does not own frame length control and
  314. // attempts to release or modify the HC frame length
  315. //
  316. #define USBD_STATUS_FRAME_CONTROL_NOT_OWNED ((USBD_STATUS)0xC0000D00L)
  317. //
  318. // additonal software error codes added for usb 2.0
  319. //
  320. //
  321. // returned for APIS not supported/implemented
  322. //
  323. #define USBD_STATUS_NOT_SUPPORTED ((USBD_STATUS)0xC0000E00L)
  324. #define USBD_STATUS_INAVLID_CONFIGURATION_DESCRIPTOR \
  325. ((USBD_STATUS)0xC0000F00L)
  326. #define USBD_STATUS_INSUFFICIENT_RESOURCES ((USBD_STATUS)0xC0001000L)
  327. #define USBD_STATUS_SET_CONFIG_FAILED ((USBD_STATUS)0xC0002000L)
  328. #define USBD_STATUS_BUFFER_TOO_SMALL ((USBD_STATUS)0xC0003000L)
  329. #define USBD_STATUS_INTERFACE_NOT_FOUND ((USBD_STATUS)0xC0004000L)
  330. #define USBD_STATUS_INAVLID_PIPE_FLAGS ((USBD_STATUS)0xC0005000L)
  331. #define USBD_STATUS_TIMEOUT ((USBD_STATUS)0xC0006000L)
  332. #define USBD_STATUS_DEVICE_GONE ((USBD_STATUS)0xC0007000L)
  333. #define USBD_STATUS_STATUS_NOT_MAPPED ((USBD_STATUS)0xC0008000L)
  334. //
  335. // set when a transfers is completed due to an AbortPipe request from
  336. // the client driver
  337. //
  338. //
  339. #define USBD_STATUS_CANCELED ((USBD_STATUS)0xC0010000L)
  340. //
  341. // extended isochronous error codes, these errors appear in the
  342. // packet status field of an isochronous transfer
  343. //
  344. // for some reason the controller did not access the TD asocated with this
  345. // packet
  346. #define USBD_STATUS_ISO_NOT_ACCESSED_BY_HW ((USBD_STATUS)0xC0020000L)
  347. // controller reported an error in the TD
  348. // since TD errors are controoler specific they are reorted
  349. // generically with this error code
  350. #define USBD_STATUS_ISO_TD_ERROR ((USBD_STATUS)0xC0030000L)
  351. // the packet was submitted in time by the client but
  352. // failed to reach the miniport in time
  353. #define USBD_STATUS_ISO_NA_LATE_USBPORT ((USBD_STATUS)0xC0040000L)
  354. // the packet was not sent because the client submitted it too late
  355. // to transmit
  356. #define USBD_STATUS_ISO_NOT_ACCESSED_LATE ((USBD_STATUS)0xC0050000L)
  357. typedef PVOID USBD_PIPE_HANDLE;
  358. typedef PVOID USBD_CONFIGURATION_HANDLE;
  359. typedef PVOID USBD_INTERFACE_HANDLE;
  360. //
  361. // Value used to indicate the default max transfer size
  362. //
  363. /*
  364. MAX TRANSFER SIZE
  365. Specified during select_configuration or
  366. selec_interface. This is the largest
  367. transfer a client driver will do to an
  368. endpoint.
  369. This value may be from 0x00000001 to
  370. 0xFFFFFFFF (1 to 4GB)
  371. */
  372. //
  373. #define USBD_DEFAULT_MAXIMUM_TRANSFER_SIZE 0xFFFFFFFF
  374. //
  375. // structure returned from USBD_GetVersion function
  376. //
  377. typedef struct _USBD_VERSION_INFORMATION {
  378. ULONG USBDI_Version; //BCD usb interface version number
  379. ULONG Supported_USB_Version; //BCD USB spec version number
  380. } USBD_VERSION_INFORMATION, *PUSBD_VERSION_INFORMATION;
  381. typedef enum _USBD_PIPE_TYPE {
  382. UsbdPipeTypeControl,
  383. UsbdPipeTypeIsochronous,
  384. UsbdPipeTypeBulk,
  385. UsbdPipeTypeInterrupt
  386. } USBD_PIPE_TYPE;
  387. #define USBD_PIPE_DIRECTION_IN(pipeInformation) ((pipeInformation)->EndpointAddress & \
  388. USB_ENDPOINT_DIRECTION_MASK)
  389. typedef struct _USBD_DEVICE_INFORMATION {
  390. ULONG OffsetNext;
  391. PVOID UsbdDeviceHandle;
  392. USB_DEVICE_DESCRIPTOR DeviceDescriptor;
  393. } USBD_DEVICE_INFORMATION, *PUSBD_DEVICE_INFORMATION;
  394. //
  395. // URB request structures
  396. //
  397. //
  398. // USBD pipe information structure, this structure
  399. // is returned for each pipe opened thru an
  400. // SELECT_CONFIGURATION or SELECT_INTERFACE request.
  401. //
  402. typedef struct _USBD_PIPE_INFORMATION {
  403. //
  404. // OUTPUT
  405. // These fields are filled in by USBD
  406. //
  407. USHORT MaximumPacketSize; // Maximum packet size for this pipe
  408. UCHAR EndpointAddress; // 8 bit USB endpoint address (includes direction)
  409. // taken from endpoint descriptor
  410. UCHAR Interval; // Polling interval in ms if interrupt pipe
  411. USBD_PIPE_TYPE PipeType; // PipeType identifies type of transfer valid for this pipe
  412. USBD_PIPE_HANDLE PipeHandle;
  413. //
  414. // INPUT
  415. // These fields are filled in by the client driver
  416. //
  417. ULONG MaximumTransferSize; // Maximum size for a single request
  418. // in bytes.
  419. ULONG PipeFlags;
  420. } USBD_PIPE_INFORMATION, *PUSBD_PIPE_INFORMATION;
  421. //
  422. // values for PipeFlags field in USBD_PIPE_INFORMATION field
  423. //
  424. // override the enpoint max_packet size
  425. // with the value in pipe_information
  426. // field
  427. #define USBD_PF_CHANGE_MAX_PACKET 0x00000001
  428. // optimize for short packets
  429. // 'bulk optimization #1'
  430. #define USBD_PF_SHORT_PACKET_OPT 0x00000002
  431. // optimize transfers for use
  432. // with 'real time threads
  433. #define USBD_PF_ENABLE_RT_THREAD_ACCESS 0x00000004
  434. // causes the driver to allocate map
  435. // map more transfers in the queue.
  436. #define USBD_PF_MAP_ADD_TRANSFERS 0x00000008
  437. #define USBD_PF_VALID_MASK (USBD_PF_CHANGE_MAX_PACKET | \
  438. USBD_PF_SHORT_PACKET_OPT | \
  439. USBD_PF_ENABLE_RT_THREAD_ACCESS | \
  440. USBD_PF_MAP_ADD_TRANSFERS)
  441. //
  442. // USBD interface information structure, this structure
  443. // is returned for each interface opened thru an
  444. // SELECT_CONFIGURATION or SELECT_INTERFACE request.
  445. //
  446. typedef struct _USBD_INTERFACE_INFORMATION {
  447. USHORT Length; // Length of this structure, including
  448. // all pipe information structures that
  449. // follow.
  450. //
  451. // INPUT
  452. //
  453. // Interface number and Alternate setting this
  454. // structure is associated with
  455. //
  456. UCHAR InterfaceNumber;
  457. UCHAR AlternateSetting;
  458. //
  459. // OUTPUT
  460. // These fields are filled in by USBD
  461. //
  462. UCHAR Class;
  463. UCHAR SubClass;
  464. UCHAR Protocol;
  465. UCHAR Reserved;
  466. USBD_INTERFACE_HANDLE InterfaceHandle;
  467. ULONG NumberOfPipes;
  468. //
  469. // INPUT/OUPUT
  470. // see PIPE_INFORMATION
  471. USBD_PIPE_INFORMATION Pipes[1];
  472. } USBD_INTERFACE_INFORMATION, *PUSBD_INTERFACE_INFORMATION;
  473. //
  474. // work space provided for HCDs
  475. //
  476. struct _URB_HCD_AREA {
  477. PVOID Reserved8[8];
  478. };
  479. struct _URB_HEADER {
  480. //
  481. // Fields filled in by client driver
  482. //
  483. USHORT Length;
  484. USHORT Function;
  485. USBD_STATUS Status;
  486. //
  487. // Fields used only by USBD
  488. //
  489. PVOID UsbdDeviceHandle; // device handle assigned to this device
  490. // by USBD
  491. ULONG UsbdFlags; // flags field reserved for USBD use.
  492. };
  493. struct _URB_SELECT_INTERFACE {
  494. struct _URB_HEADER Hdr; // function code indicates get or set.
  495. USBD_CONFIGURATION_HANDLE ConfigurationHandle;
  496. // client must input AlternateSetting & Interface Number
  497. // class driver returns interface and handle
  498. // for new alternate setting
  499. USBD_INTERFACE_INFORMATION Interface;
  500. };
  501. struct _URB_SELECT_CONFIGURATION {
  502. struct _URB_HEADER Hdr; // function code indicates get or set.
  503. // NULL indicates to set the device
  504. // to the 'unconfigured' state
  505. // ie set to configuration 0
  506. PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor;
  507. USBD_CONFIGURATION_HANDLE ConfigurationHandle;
  508. USBD_INTERFACE_INFORMATION Interface;
  509. };
  510. //
  511. // This structure used for ABORT_PIPE & RESET_PIPE
  512. //
  513. struct _URB_PIPE_REQUEST {
  514. struct _URB_HEADER Hdr; // function code indicates get or set.
  515. USBD_PIPE_HANDLE PipeHandle;
  516. ULONG Reserved;
  517. };
  518. //
  519. // This structure used for
  520. // TAKE_FRAME_LENGTH_CONTROL &
  521. // RELEASE_FRAME_LENGTH_CONTROL
  522. //
  523. struct _URB_FRAME_LENGTH_CONTROL {
  524. struct _URB_HEADER Hdr; // function code indicates get or set.
  525. };
  526. struct _URB_GET_FRAME_LENGTH {
  527. struct _URB_HEADER Hdr; // function code indicates get or set.
  528. ULONG FrameLength;
  529. ULONG FrameNumber;
  530. };
  531. struct _URB_SET_FRAME_LENGTH {
  532. struct _URB_HEADER Hdr; // function code indicates get or set.
  533. LONG FrameLengthDelta;
  534. };
  535. struct _URB_GET_CURRENT_FRAME_NUMBER {
  536. struct _URB_HEADER Hdr; // function code indicates get or set.
  537. ULONG FrameNumber;
  538. };
  539. //
  540. // Structures for specific control transfers
  541. // on the default pipe.
  542. //
  543. // GET_DESCRIPTOR
  544. // SET_DESCRIPTOR
  545. struct _URB_CONTROL_DESCRIPTOR_REQUEST {
  546. struct _URB_HEADER Hdr; // function code indicates get or set.
  547. PVOID Reserved;
  548. ULONG Reserved0;
  549. ULONG TransferBufferLength;
  550. PVOID TransferBuffer;
  551. PMDL TransferBufferMDL; // *optional*
  552. struct _URB *UrbLink; // *optional* link to next urb request
  553. // if this is a chain of commands
  554. struct _URB_HCD_AREA hca; // fields for HCD use
  555. USHORT Reserved1;
  556. UCHAR Index;
  557. UCHAR DescriptorType;
  558. USHORT LanguageId;
  559. USHORT Reserved2;
  560. };
  561. // GET_STATUS
  562. struct _URB_CONTROL_GET_STATUS_REQUEST {
  563. struct _URB_HEADER Hdr; // function code indicates get or set.
  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[4];
  573. USHORT Index; // zero, interface or endpoint
  574. USHORT Reserved2;
  575. };
  576. // SET_FEATURE
  577. // CLEAR_FEATURE
  578. struct _URB_CONTROL_FEATURE_REQUEST {
  579. struct _URB_HEADER Hdr; // function code indicates get or set.
  580. PVOID Reserved;
  581. ULONG Reserved2;
  582. ULONG Reserved3;
  583. PVOID Reserved4;
  584. PMDL Reserved5;
  585. struct _URB *UrbLink; // *optional* link to next urb request
  586. // if this is a chain of commands
  587. struct _URB_HCD_AREA hca; // fields for HCD use
  588. USHORT Reserved0;
  589. USHORT FeatureSelector;
  590. USHORT Index; // zero, interface or endpoint
  591. USHORT Reserved1;
  592. };
  593. // VENDOR & CLASS
  594. struct _URB_CONTROL_VENDOR_OR_CLASS_REQUEST {
  595. struct _URB_HEADER Hdr; // function code indicates get or set.
  596. PVOID Reserved;
  597. ULONG TransferFlags;
  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 RequestTypeReservedBits;
  605. UCHAR Request;
  606. USHORT Value;
  607. USHORT Index;
  608. USHORT Reserved1;
  609. };
  610. struct _URB_CONTROL_GET_INTERFACE_REQUEST {
  611. struct _URB_HEADER Hdr; // function code indicates get or set.
  612. PVOID Reserved;
  613. ULONG Reserved0;
  614. ULONG TransferBufferLength;
  615. PVOID TransferBuffer;
  616. PMDL TransferBufferMDL; // *optional*
  617. struct _URB *UrbLink; // *optional* link to next urb request
  618. // if this is a chain of commands
  619. struct _URB_HCD_AREA hca; // fields for HCD use
  620. UCHAR Reserved1[4];
  621. USHORT Interface;
  622. USHORT Reserved2;
  623. };
  624. struct _URB_CONTROL_GET_CONFIGURATION_REQUEST {
  625. struct _URB_HEADER Hdr; // function code indicates get or set.
  626. PVOID Reserved;
  627. ULONG Reserved0;
  628. ULONG TransferBufferLength;
  629. PVOID TransferBuffer;
  630. PMDL TransferBufferMDL; // *optional*
  631. struct _URB *UrbLink; // *optional* link to next urb request
  632. // if this is a chain of commands
  633. struct _URB_HCD_AREA hca; // fields for HCD use
  634. UCHAR Reserved1[8];
  635. };
  636. // Microsoft OS Descriptor APIs
  637. #define OS_STRING_DESCRIPTOR_INDEX 0xEE
  638. #define MS_GENRE_DESCRIPTOR_INDEX 0x0001
  639. #define MS_POWER_DESCRIPTOR_INDEX 0x0002
  640. #define MS_OS_STRING_SIGNATURE L"MSFT100"
  641. typedef struct _OS_STRING {
  642. UCHAR bLength;
  643. UCHAR bDescriptorType;
  644. WCHAR MicrosoftString[7];
  645. UCHAR bVendorCode;
  646. UCHAR bPad;
  647. } OS_STRING, *POS_STRING;
  648. struct _URB_OS_FEATURE_DESCRIPTOR_REQUEST {
  649. struct _URB_HEADER Hdr; // function code indicates get or set.
  650. PVOID Reserved;
  651. ULONG Reserved0;
  652. ULONG TransferBufferLength;
  653. PVOID TransferBuffer;
  654. PMDL TransferBufferMDL; // *optional*
  655. struct _URB *UrbLink; // *optional* link to next urb request
  656. // if this is a chain of commands
  657. struct _URB_HCD_AREA hca; // fields for HCD use
  658. UCHAR Recipient:5; // Recipient {Device,Interface,Endpoint}
  659. UCHAR Reserved1:3;
  660. UCHAR Reserved2;
  661. UCHAR InterfaceNumber; // wValue - high byte
  662. UCHAR MS_PageIndex; // wValue - low byte
  663. USHORT MS_FeatureDescriptorIndex; // wIndex field
  664. USHORT Reserved3;
  665. };
  666. //
  667. // request format for a control transfer on
  668. // the non-default pipe.
  669. //
  670. struct _URB_CONTROL_TRANSFER {
  671. struct _URB_HEADER Hdr; // function code indicates get or set.
  672. USBD_PIPE_HANDLE PipeHandle;
  673. ULONG TransferFlags;
  674. ULONG TransferBufferLength;
  675. PVOID TransferBuffer;
  676. PMDL TransferBufferMDL; // *optional*
  677. struct _URB *UrbLink; // *optional* link to next urb request
  678. // if this is a chain of commands
  679. struct _URB_HCD_AREA hca; // fields for HCD use
  680. UCHAR SetupPacket[8];
  681. };
  682. struct _URB_BULK_OR_INTERRUPT_TRANSFER {
  683. struct _URB_HEADER Hdr; // function code indicates get or set.
  684. USBD_PIPE_HANDLE PipeHandle;
  685. ULONG TransferFlags; // note: the direction bit will be set by USBD
  686. ULONG TransferBufferLength;
  687. PVOID TransferBuffer;
  688. PMDL TransferBufferMDL; // *optional*
  689. struct _URB *UrbLink; // *optional* link to next urb request
  690. // if this is a chain of commands
  691. struct _URB_HCD_AREA hca; // fields for HCD use
  692. };
  693. //
  694. // ISO Transfer request
  695. //
  696. // TransferBufferMDL must point to a single virtually
  697. // contiguous buffer.
  698. //
  699. // StartFrame - the frame to send/receive the first packet of
  700. // the request.
  701. //
  702. // NumberOfPackets - number of packets to send in this request
  703. //
  704. //
  705. // IsoPacket Array
  706. //
  707. // Input: Offset - offset of the packet from the beginig
  708. // of the client buffer.
  709. // Output: Length - is set to the actual length of the packet
  710. // (For IN transfers).
  711. // Status: error that occurred during transmission or
  712. // reception of the packet.
  713. //
  714. typedef struct _USBD_ISO_PACKET_DESCRIPTOR {
  715. ULONG Offset; // INPUT Offset of the packet from the begining of the
  716. // buffer.
  717. ULONG Length; // OUTPUT length of data received (for in).
  718. // OUTPUT 0 for OUT.
  719. USBD_STATUS Status; // status code for this packet.
  720. } USBD_ISO_PACKET_DESCRIPTOR, *PUSBD_ISO_PACKET_DESCRIPTOR;
  721. struct _URB_ISOCH_TRANSFER {
  722. //
  723. // This block is the same as CommonTransfer
  724. //
  725. struct _URB_HEADER Hdr; // function code indicates get or set.
  726. USBD_PIPE_HANDLE PipeHandle;
  727. ULONG TransferFlags;
  728. ULONG TransferBufferLength;
  729. PVOID TransferBuffer;
  730. PMDL TransferBufferMDL; // *optional*
  731. struct _URB *UrbLink; // *optional* link to next urb request
  732. // if this is a chain of commands
  733. struct _URB_HCD_AREA hca; // fields for HCD use
  734. //
  735. // this block contains transfer fields
  736. // specific to isochronous transfers
  737. //
  738. // 32 bit frame number to begin this transfer on, must be within 1000
  739. // frames of the current USB frame or an error is returned.
  740. // START_ISO_TRANSFER_ASAP flag in transferFlags:
  741. // If this flag is set and no transfers have been submitted
  742. // for the pipe then the transfer will begin on the next frame
  743. // and StartFrame will be updated with the frame number the transfer
  744. // was started on.
  745. // If this flag is set and the pipe has active transfers then
  746. // the transfer will be queued to begin on the frame after the
  747. // last transfer queued is completed.
  748. //
  749. ULONG StartFrame;
  750. // number of packets that make up this request
  751. ULONG NumberOfPackets;
  752. // number of packets that completed with errors
  753. ULONG ErrorCount;
  754. USBD_ISO_PACKET_DESCRIPTOR IsoPacket[1];
  755. };
  756. #if 0
  757. //
  758. // new for USB 2.0
  759. // client is responsible for initailizing all fields
  760. // of the setup packet
  761. // option URB timeout, if nonzero the request will be
  762. // timed out after the speified number of ms and completed
  763. // with USBD_STATUS_TIMEOUT.
  764. struct _URB_TIMEOUT {
  765. ULONG TimeoutValue; // timeout in ms, 0 = no timeout
  766. #ifdef WIN64
  767. ULONG Pad1;
  768. #endif
  769. } URB_TIMEOUT, *PURB_TIMEOUT;
  770. struct _URB_RAW_CONTROL_TRANSFER {
  771. struct _URB_HEADER Hdr; // function code indicates get or set.
  772. USBD_PIPE_HANDLE PipeHandle;
  773. ULONG TransferFlags;
  774. ULONG TransferBufferLength;
  775. PVOID TransferBuffer;
  776. PMDL TransferBufferMDL; // *optional*
  777. PVOID Reservedxxx;
  778. PVOID HcdTransferContext; // usbport context
  779. URB_TIMEOUT UrbTimeout;
  780. PVOID Reservedxxx[5];
  781. struct _URB_HCD_AREA hcaXXX;
  782. USB_DEFAULT_PIPE_SETUP_PACKET SetupPacket;
  783. };
  784. //optption flags
  785. //
  786. // option_1
  787. // 'safe abort' stall abort if data is data is bieing received for
  788. // the endpoint
  789. XXX_OPTION_1
  790. // option_2
  791. // enable 'throttleing' on this endpoint bulk_opt_2
  792. XXX_OPTION_2
  793. // option_3
  794. // enable short packet/small transfer optimization bulk_opt_1
  795. XXX_OPTION_3
  796. // option_4
  797. // enable 'irpless' interface for this endpoint
  798. struct _URB_SET_PIPE_PARAMETERS {
  799. struct _URB_HEADER Hdr;
  800. USBD_PIPE_HANDLE PipeHandle;
  801. // This is the maximum thruput of the device
  802. // under optimal conditions
  803. // ie if a device can ony supply or receive 64 bytes/ms
  804. // then set this value to 64.
  805. // this is value is used by the operating system to
  806. // optimize the scheduling of transfers.
  807. // It will default to the maximum for the endpoint type
  808. ULONG DeviceMaxThruput;
  809. // Max Packet size for the endpoint this value defaults to
  810. // the endpoint supplied value and may be subsequently changed
  811. // by the driver.
  812. // This parameter may be used to dymically adjust the packet
  813. // size of an endpoint without re-configuring the device or
  814. // interface.
  815. USHORT MaximumPacketSize;
  816. };
  817. struct _URB_GET_PIPE_PARAMETERS {
  818. struct _URB_HEADER Hdr; // function code indicates get or set.
  819. USBD_PIPE_HANDLE PipeHandle;
  820. USB_ENDPOINT_DESCRIPTOR EndpointDescriptor;
  821. };
  822. #endif
  823. typedef struct _URB {
  824. union {
  825. struct _URB_HEADER
  826. UrbHeader;
  827. struct _URB_SELECT_INTERFACE
  828. UrbSelectInterface;
  829. struct _URB_SELECT_CONFIGURATION
  830. UrbSelectConfiguration;
  831. struct _URB_PIPE_REQUEST
  832. UrbPipeRequest;
  833. struct _URB_FRAME_LENGTH_CONTROL
  834. UrbFrameLengthControl;
  835. struct _URB_GET_FRAME_LENGTH
  836. UrbGetFrameLength;
  837. struct _URB_SET_FRAME_LENGTH
  838. UrbSetFrameLength;
  839. struct _URB_GET_CURRENT_FRAME_NUMBER
  840. UrbGetCurrentFrameNumber;
  841. struct _URB_CONTROL_TRANSFER
  842. UrbControlTransfer;
  843. struct _URB_BULK_OR_INTERRUPT_TRANSFER
  844. UrbBulkOrInterruptTransfer;
  845. struct _URB_ISOCH_TRANSFER
  846. UrbIsochronousTransfer;
  847. // for standard control transfers on the default pipe
  848. struct _URB_CONTROL_DESCRIPTOR_REQUEST
  849. UrbControlDescriptorRequest;
  850. struct _URB_CONTROL_GET_STATUS_REQUEST
  851. UrbControlGetStatusRequest;
  852. struct _URB_CONTROL_FEATURE_REQUEST
  853. UrbControlFeatureRequest;
  854. struct _URB_CONTROL_VENDOR_OR_CLASS_REQUEST
  855. UrbControlVendorClassRequest;
  856. struct _URB_CONTROL_GET_INTERFACE_REQUEST
  857. UrbControlGetInterfaceRequest;
  858. struct _URB_CONTROL_GET_CONFIGURATION_REQUEST
  859. UrbControlGetConfigurationRequest;
  860. struct _URB_OS_FEATURE_DESCRIPTOR_REQUEST
  861. UrbOSFeatureDescriptorRequest;
  862. };
  863. } URB, *PURB;
  864. #endif /* __USB_H__ */