usb.h 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801
  1. /*++
  2. Copyright (c) 2013 Minoca Corp. All Rights Reserved
  3. Module Name:
  4. usb.h
  5. Abstract:
  6. This header contains definitions for interacting with USB devices.
  7. Author:
  8. Evan Green 15-Jan-2013
  9. --*/
  10. //
  11. // ------------------------------------------------------------------- Includes
  12. //
  13. //
  14. // ---------------------------------------------------------------- Definitions
  15. //
  16. #ifndef USB_API
  17. #define USB_API __DLLIMPORT
  18. #endif
  19. //
  20. // Define the maximum size of a USB hub descriptor.
  21. //
  22. #define USB_HUB_DESCRIPTOR_MAX_SIZE 39
  23. //
  24. // Define the maximum descriptor size.
  25. //
  26. #define USB_MAX_DESCRIPTOR_SIZE 0xFF
  27. //
  28. // Define the hub descriptor type.
  29. //
  30. #define USB_HUB_DESCRIPTOR_TYPE 0x29
  31. //
  32. // Define the values in the Setup Packet's RequestType field.
  33. //
  34. #define USB_SETUP_REQUEST_TO_HOST (1 << 7)
  35. #define USB_SETUP_REQUEST_TO_DEVICE (0 << 7)
  36. #define USB_SETUP_REQUEST_STANDARD (0x0 << 5)
  37. #define USB_SETUP_REQUEST_CLASS (0x1 << 5)
  38. #define USB_SETUP_REQUEST_VENDOR (0x2 << 5)
  39. #define USB_SETUP_REQUEST_DEVICE_RECIPIENT 0x0
  40. #define USB_SETUP_REQUEST_INTERFACE_RECIPIENT 0x1
  41. #define USB_SETUP_REQUEST_ENDPOINT_RECIPIENT 0x2
  42. #define USB_SETUP_REQUEST_OTHER_RECIPIENT 0x3
  43. //
  44. // Define the USB standard requests.
  45. //
  46. #define USB_REQUEST_GET_STATUS 0x0
  47. #define USB_REQUEST_CLEAR_FEATURE 0x1
  48. #define USB_REQUEST_SET_FEATURE 0x3
  49. #define USB_REQUEST_SET_ADDRESS 0x5
  50. #define USB_REQUEST_GET_DESCRIPTOR 0x6
  51. #define USB_REQUEST_SET_DESCRIPTOR 0x7
  52. #define USB_REQUEST_GET_CONFIGURATION 0x8
  53. #define USB_REQUEST_SET_CONFIGURATION 0x9
  54. #define USB_REQUEST_GET_INTERFACE 0xA
  55. #define USB_REQUEST_SET_INTERFACE 0xB
  56. #define USB_REQUEST_SYNCH_FRAME 0xC
  57. //
  58. // Define the USB feature selectors.
  59. //
  60. #define USB_FEATURE_ENDPOINT_HALT 0x0
  61. #define USB_FEATURE_DEVICE_REMOTE_WAKEUP 0x1
  62. #define USB_FEATURE_DEVICE_TEST_MODE 0x2
  63. //
  64. // Define standard Device requests.
  65. //
  66. #define USB_DEVICE_REQUEST_GET_STATUS USB_REQUEST_GET_STATUS
  67. #define USB_DEVICE_REQUEST_CLEAR_FEATURE USB_REQUEST_CLEAR_FEATURE
  68. #define USB_DEVICE_REQUEST_SET_FEATURE USB_REQUEST_SET_FEATURE
  69. #define USB_DEVICE_REQUEST_SET_ADDRESS USB_REQUEST_SET_ADDRESS
  70. #define USB_DEVICE_REQUEST_GET_DESCRIPTOR USB_REQUEST_GET_DESCRIPTOR
  71. #define USB_DEVICE_REQUEST_SET_DESCRIPTOR USB_REQUEST_SET_DESCRIPTOR
  72. #define USB_DEVICE_REQUEST_GET_CONFIGURATION USB_REQUEST_GET_CONFIGURATION
  73. #define USB_DEVICE_REQUEST_SET_CONFIGURATION USB_REQUEST_SET_CONFIGURATION
  74. //
  75. // Define the USB device status bits.
  76. //
  77. #define USB_DEVICE_STATUS_SELF_POWERED 0x1
  78. #define USB_DEVICE_STATUS_REMOTE_WAKEUP 0x2
  79. //
  80. // Define standard Interface requests.
  81. //
  82. #define USB_INTERFACE_REQUEST_GET_STATUS USB_REQUEST_GET_STATUS
  83. #define USB_INTERFACE_REQUEST_CLEAR_FEATURE USB_REQUEST_CLEAR_FEATURE
  84. #define USB_INTERFACE_REQUEST_SET_FEATURE USB_REQUEST_SET_FEATURE
  85. #define USB_INTERFACE_GET_INTERFACE USB_REQUEST_GET_INTERFACE
  86. #define USB_INTERFACE_SET_INTERFACE USB_REQUEST_SET_INTERFACE
  87. //
  88. // Define standard Endpoint requests.
  89. //
  90. #define USB_ENDPOINT_REQUEST_GET_STATUS USB_REQUEST_GET_STATUS
  91. #define USB_ENDPOINT_REQUEST_CLEAR_FEATURE USB_REQUEST_CLEAR_FEATURE
  92. #define USB_ENDPOINT_REQUEST_SET_FEATURE USB_REQUEST_SET_FEATURE
  93. #define USB_ENDPOINT_REQUEST_SYNCH_FRAME USB_REQUEST_SYNCH_FRAME
  94. //
  95. // Define the endpoint address bits in a USB endpoint descriptor.
  96. //
  97. #define USB_ENDPOINT_ADDRESS_DIRECTION_IN 0x80
  98. #define USB_ENDPOINT_ADDRESS_MASK 0x0F
  99. //
  100. // Define the attributes bits in a USB endpoint descriptor.
  101. //
  102. #define USB_ENDPOINT_ATTRIBUTES_TYPE_MASK 0x03
  103. #define USB_ENDPOINT_ATTRIBUTES_TYPE_CONTROL 0x00
  104. #define USB_ENDPOINT_ATTRIBUTES_TYPE_ISOCHRONOUS 0x01
  105. #define USB_ENDPOINT_ATTRIBUTES_TYPE_BULK 0x02
  106. #define USB_ENDPOINT_ATTRIBUTES_TYPE_INTERRUPT 0x03
  107. //
  108. // Define the USB endpoint status bits.
  109. //
  110. #define USB_ENDPOINT_STATUS_HALT 0x1
  111. //
  112. // Define USB Hub characteristics flags.
  113. //
  114. #define USB_HUB_CHARACTERISTIC_POWER_SWITCHING_MASK 0x03
  115. #define USB_HUB_CHARACTERISTIC_POWER_GANGED 0x00
  116. #define USB_HUB_CHARACTERISTIC_POWER_INDIVIDUAL 0x01
  117. #define USB_HUB_CHARACTERISTIC_OVER_CURRENT_MASK 0x0C
  118. #define USB_HUB_CHARACTERISTIC_OVER_CURRENT_GLOBAL 0x00
  119. #define USB_HUB_CHARACTERISTIC_OVER_CURRENT_INDIVIDUAL 0x04
  120. #define USB_HUB_CHARACTERISTIC_OVER_CURRENT_NONE 0x08
  121. #define USB_HUB_CHARACTERISTIC_TT_THINK_MASK 0x30
  122. #define USB_HUB_CHARACTERISTIC_TT_THINK_8_FS_TIMES 0x00
  123. #define USB_HUB_CHARACTERISTIC_TT_THINK_16_FS_TIMES 0x10
  124. #define USB_HUB_CHARACTERISTIC_TT_THINK_24_FS_TIMES 0x20
  125. #define USB_HUB_CHARACTERISTIC_TT_THINK_32_FS_TIMES 0x30
  126. #define USB_HUB_CHARACTERISTIC_INDICATORS_SUPPORTED 0x80
  127. //
  128. // Define USB language IDs.
  129. //
  130. #define USB_LANGUAGE_ENGLISH_US 0x0409
  131. //
  132. // USB Hub definitions
  133. //
  134. //
  135. // Define the size of various hub transfers.
  136. //
  137. #define USB_HUB_MAX_CONTROL_TRANSFER_SIZE \
  138. (USB_HUB_DESCRIPTOR_MAX_SIZE + sizeof(USB_SETUP_PACKET))
  139. #define USB_HUB_MAX_PORT_COUNT 127
  140. #define USB_HUB_MAX_INTERRUPT_SIZE \
  141. (ALIGN_RANGE_UP(USB_HUB_MAX_PORT_COUNT + 1, BITS_PER_BYTE) / BITS_PER_BYTE)
  142. //
  143. // Define Hub class feature selectors (that go in the Value of the setup
  144. // packet).
  145. //
  146. #define USB_HUB_FEATURE_C_HUB_LOCAL_POWER 0
  147. #define USB_HUB_FEATURE_C_HUB_OVER_CURRENT 1
  148. #define USB_HUB_FEATURE_PORT_CONNECTION 0
  149. #define USB_HUB_FEATURE_PORT_ENABLE 1
  150. #define USB_HUB_FEATURE_PORT_SUSPEND 2
  151. #define USB_HUB_FEATURE_PORT_OVER_CURRENT 3
  152. #define USB_HUB_FEATURE_PORT_RESET 4
  153. #define USB_HUB_FEATURE_PORT_POWER 8
  154. #define USB_HUB_FEATURE_PORT_LOW_SPEED 9
  155. #define USB_HUB_FEATURE_C_PORT_CONNECTION 16
  156. #define USB_HUB_FEATURE_C_PORT_ENABLE 17
  157. #define USB_HUB_FEATURE_C_PORT_SUSPEND 18
  158. #define USB_HUB_FEATURE_C_PORT_OVER_CURRENT 19
  159. #define USB_HUB_FEATURE_C_PORT_RESET 20
  160. #define USB_HUB_FEATURE_PORT_TEST 21
  161. #define USB_HUB_FEATURE_PORT_INDICATOR 22
  162. //
  163. // Define hub status bits.
  164. //
  165. #define USB_HUB_HUB_STATUS_LOCAL_POWER (1 << 0)
  166. #define USB_HUB_HUB_STATUS_OVER_CURRENT (1 << 1)
  167. #define USB_HUB_HUB_STATUS_CHANGE_SHIFT 16
  168. //
  169. // Define port status bits.
  170. //
  171. #define USB_HUB_PORT_STATUS_DEVICE_CONNECTED (1 << 0)
  172. #define USB_HUB_PORT_STATUS_ENABLED (1 << 1)
  173. #define USB_HUB_PORT_STATUS_SUSPENDED (1 << 2)
  174. #define USB_HUB_PORT_STATUS_OVER_CURRENT (1 << 3)
  175. #define USB_HUB_PORT_STATUS_RESET (1 << 4)
  176. #define USB_HUB_PORT_STATUS_POWERED_ON (1 << 8)
  177. #define USB_HUB_PORT_STATUS_LOW_SPEED (1 << 9)
  178. #define USB_HUB_PORT_STATUS_HIGH_SPEED (1 << 10)
  179. #define USB_HUB_PORT_STATUS_TEST (1 << 11)
  180. #define USB_HUB_PORT_STATUS_SOFTWARE_INDICATORS (1 << 12)
  181. #define USB_HUB_PORT_STATUS_CHANGE_SHIFT 16
  182. //
  183. // Define indicator values.
  184. //
  185. #define USB_HUB_INDICATOR_AUTOMATIC (0 << 8)
  186. #define USB_HUB_INDICATOR_AMBER (1 << 8)
  187. #define USB_HUB_INDICATOR_GREEN (2 << 8)
  188. #define USB_HUB_INDICATOR_OFF (3 << 8)
  189. #define USB_HUB_INDICATOR_MASK (0xFF << 8)
  190. //
  191. // Define well-known USB device IDs.
  192. //
  193. #define USB_ROOT_HUB_DEVICE_ID "UsbRootHub"
  194. #define USB_COMPOUND_DEVICE_CLASS_ID "UsbCompoundDevice"
  195. #define USB_HID_CLASS_ID "UsbHid"
  196. #define USB_BOOT_KEYBOARD_CLASS_ID "UsbBootKeyboard"
  197. #define USB_BOOT_MOUSE_CLASS_ID "UsbBootMouse"
  198. #define USB_MASS_STORAGE_CLASS_ID "UsbMassStorage"
  199. #define USB_HUB_CLASS_ID "UsbHub"
  200. //
  201. // Define the required subclass and protocol for this device to be a keyboard
  202. // or mouse that follows the boot protocol.
  203. //
  204. #define USB_HID_BOOT_INTERFACE_SUBCLASS 1
  205. #define USB_HID_BOOT_KEYBOARD_PROTOCOL 1
  206. #define USB_HID_BOOT_MOUSE_PROTOCOL 2
  207. //
  208. // Define USB HID standard requests.
  209. //
  210. #define USB_HID_GET_REPORT 0x01
  211. #define USB_HID_GET_IDLE 0x02
  212. #define USB_HID_GET_PROTOCOL 0x03
  213. #define USB_HID_SET_REPORT 0x09
  214. #define USB_HID_SET_IDLE 0x0A
  215. #define USB_HID_SET_PROTOCOL 0x0B
  216. //
  217. // Define USB HID report value fields.
  218. //
  219. #define USB_HID_RERPOT_VALUE_TYPE_MASK (0xFF << 8)
  220. #define USB_HID_REPORT_VALUE_TYPE_SHIFT 8
  221. #define USB_HID_REPORT_VALUE_TYPE_INPUT 1
  222. #define USB_HID_REPORT_VALUE_TYPE_OUTPUT 2
  223. #define USB_HID_REPORT_VALUE_TYPE_FEATURE 3
  224. #define USB_HID_REPORT_VALUE_ID_MASK (0xFF << 0)
  225. #define USB_HID_REPORT_VALUE_ID_SHIFT 0
  226. //
  227. // Define the USB HID protocol request values.
  228. //
  229. #define USB_HID_PROTOCOL_VALUE_BOOT 0
  230. #define USB_HID_PROTOCOL_VALUE_REPORT 1
  231. //
  232. // Define USB Transfer flags.
  233. //
  234. //
  235. // Set this flag to continue trying if a transfer comes up short.
  236. //
  237. #define USB_TRANSFER_FLAG_NO_SHORT_TRANSFERS 0x00000001
  238. //
  239. // Set this flag to prevent an interrupt from firing when the packet completes.
  240. // This is usually only used for internal intermediate transfers.
  241. //
  242. #define USB_TRANSFER_FLAG_NO_INTERRUPT_ON_COMPLETION 0x00000002
  243. //
  244. // Set this flag for non-synchronous transfers from a paging USB mass storage
  245. // device.
  246. //
  247. #define USB_TRANSFER_FLAG_PAGING_DEVICE 0x00000004
  248. //
  249. // Set this flag to force a short, zero-length transfer to be sent if the
  250. // payload is a multiple of the max packet size for the endpoint.
  251. //
  252. #define USB_TRANSFER_FLAG_FORCE_SHORT_TRANSFER 0x00000008
  253. //
  254. // Define the maximum size of a USB string descriptor.
  255. //
  256. #define USB_STRING_DESCRIPTOR_MAX_SIZE 0xFF
  257. //
  258. // ------------------------------------------------------ Data Type Definitions
  259. //
  260. typedef enum _USB_DEVICE_SPEED {
  261. UsbDeviceSpeedInvalid,
  262. UsbDeviceSpeedLow,
  263. UsbDeviceSpeedFull,
  264. UsbDeviceSpeedHigh,
  265. UsbDeviceSpeedSuper,
  266. } USB_DEVICE_SPEED, *PUSB_DEVICE_SPEED;
  267. typedef enum _USB_TRANSFER_TYPE {
  268. UsbTransferTypeInvalid,
  269. UsbTransferTypeControl,
  270. UsbTransferTypeInterrupt,
  271. UsbTransferTypeBulk,
  272. UsbTransferTypeIsochronous,
  273. UsbTransferTypeCount
  274. } USB_TRANSFER_TYPE, *PUSB_TRANSFER_TYPE;
  275. typedef enum _USB_TRANSFER_DIRECTION {
  276. UsbTransferDirectionInvalid,
  277. UsbTransferDirectionIn,
  278. UsbTransferDirectionOut,
  279. UsbTransferBidirectional,
  280. UsbTransferDirectionCount
  281. } USB_TRANSFER_DIRECTION, *PUSB_TRANSFER_DIRECTION;
  282. typedef enum _USB_DESCRIPTOR_TYPE {
  283. UsbDescriptorTypeDevice = 0x01,
  284. UsbDescriptorTypeConfiguration = 0x02,
  285. UsbDescriptorTypeString = 0x03,
  286. UsbDescriptorTypeInterface = 0x04,
  287. UsbDescriptorTypeEndpoint = 0x05,
  288. UsbDescriptorTypeDeviceQualifier = 0x06,
  289. UsbDescriptorTypeOtherSpeedConfiguration = 0x07,
  290. } USB_DESCRIPTOR_TYPE, *PUSB_DESCRIPTOR_TYPE;
  291. typedef enum _USB_INTERFACE_CLASS {
  292. UsbInterfaceClassAudio = 0x01,
  293. UsbInterfaceClassCdcControl = 0x02,
  294. UsbInterfaceClassHid = 0x03,
  295. UsbInterfaceClassPhysical = 0x05,
  296. UsbInterfaceClassImage = 0x06,
  297. UsbInterfaceClassPrinter = 0x07,
  298. UsbInterfaceClassMassStorage = 0x08,
  299. UsbInterfaceClassCdcData = 0x0A,
  300. UsbInterfaceClassSmartCard = 0x0B,
  301. UsbInterfaceClassContentSecurity = 0x0D,
  302. UsbInterfaceClassVideo = 0x0E,
  303. UsbInterfaceClassPersonalHealthcare = 0x0F,
  304. UsbInterfaceClassAudioVideo = 0x10,
  305. UsbInterfaceClassDiagnosticDevice = 0xDC,
  306. UsbInterfaceClassWireless = 0xE0,
  307. UsbInterfaceClassMiscellaneous = 0xEF,
  308. UsbInterfaceClassApplicationSpecific = 0xFE,
  309. UsbInterfaceClassVendor = 0xFF,
  310. } USB_INTERFACE_CLASS, *PUSB_INTERFACE_CLASS;
  311. typedef enum _USB_DEVICE_CLASS {
  312. UsbDeviceClassUseInterface = 0x00,
  313. UsbDeviceClassCdcControl = 0x02,
  314. UsbDeviceClassHid = 0x03,
  315. UsbDeviceClassHub = 0x09,
  316. UsbDeviceClassDiagnosticDevice = 0xDC,
  317. UsbDeviceClassMiscellaneous = 0xEF,
  318. UsbDeviceClassVendor = 0xFF,
  319. } USB_DEVICE_CLASS, *PUSB_DEVICE_CLASS;
  320. typedef enum _USB_ERROR {
  321. UsbErrorNone,
  322. UsbErrorTransferNotStarted,
  323. UsbErrorTransferCancelled,
  324. UsbErrorTransferAllocatedIncorrectly,
  325. UsbErrorTransferSubmittedWhileStillActive,
  326. UsbErrorTransferIncorrectlyFilledOut,
  327. UsbErrorTransferFailedToSubmit,
  328. UsbErrorTransferStalled,
  329. UsbErrorTransferDataBuffer,
  330. UsbErrorTransferBabbleDetected,
  331. UsbErrorTransferNakReceived,
  332. UsbErrorTransferCrcOrTimeoutError,
  333. UsbErrorTransferBitstuff,
  334. UsbErrorTransferMissedMicroFrame,
  335. UsbErrorTransferBufferNotAligned,
  336. UsbErrorTransferDeviceNotConnected,
  337. UsbErrorTransferDeviceIo,
  338. UsbErrorShortPacket,
  339. UsbErrorCount
  340. } USB_ERROR, *PUSB_ERROR;
  341. typedef struct _USB_TRANSFER USB_TRANSFER, *PUSB_TRANSFER;
  342. typedef struct _USB_DEVICE USB_DEVICE, *PUSB_DEVICE;
  343. /*++
  344. Structure Description:
  345. This structure defines the format of the USB Device Descriptor, as defined
  346. by the USB specification.
  347. Members:
  348. Length - Stores the length of the structure.
  349. DescriptorType - Stores a constant indicating that this is a device
  350. descriptor.
  351. UsbSpecification - Stores a binary coded decimal number indicating the
  352. revision of the USB specification this device conforms to.
  353. Class - Stores the class code that the device conforms to. Most class
  354. specifications choose to identify at the interface level as opposed to
  355. here at the device level.
  356. Subclass - Stores the subclass code that the device conforms to.
  357. Protocol - Stores the protocol number of the class/subclass that the device
  358. conforms to.
  359. MaxPacketSize - Stores the maximum supported size of packets on this
  360. default endpoint. Valid values are 8, 16, 32, and 64.
  361. VendorId - Stores the vendor identification number (VID) of the device.
  362. ProductId - Stores the product identification number (PID) of the device.
  363. DeviceRevision - Stores a binary coded decimal hardware revision number.
  364. ManufacturerStringIndex - Stores the index of the Manufacturer String
  365. Descriptor.
  366. ProductStringIndex - Stores the index of the Product Name String Descriptor.
  367. SerialNumberIndex - Stores the index of the Serial Number String Descriptor.
  368. ConfigurationCount - Stores the number of configurations this device
  369. supports.
  370. --*/
  371. typedef struct _USB_DEVICE_DESCRIPTOR {
  372. UCHAR Length;
  373. UCHAR DescriptorType;
  374. USHORT UsbSpecification;
  375. UCHAR Class;
  376. UCHAR Subclass;
  377. UCHAR Protocol;
  378. UCHAR MaxPacketSize;
  379. USHORT VendorId;
  380. USHORT ProductId;
  381. USHORT DeviceRevision;
  382. UCHAR ManufacturerStringIndex;
  383. UCHAR ProductStringIndex;
  384. UCHAR SerialNumberStringIndex;
  385. UCHAR ConfigurationCount;
  386. } PACKED USB_DEVICE_DESCRIPTOR, *PUSB_DEVICE_DESCRIPTOR;
  387. /*++
  388. Structure Description:
  389. This structure defines the format of the USB Configuration Descriptor, as
  390. defined by the USB specification.
  391. Members:
  392. Length - Stores the length of the structure.
  393. DescriptorType - Stores a constant indicating that this is a configuration
  394. descriptor.
  395. TotalLength - Stores the total length of all the data returned (which
  396. includes the interfaces and endpoints).
  397. InterfaceCount - Stores the number of interfaces in this configuration.
  398. ConfigurationValue - Stores the index of this configuration.
  399. StringIndex - Stores the index of the string descriptor describing this
  400. configuration.
  401. Attributes - Stores various attributes about this configuration, mostly
  402. centered around power.
  403. MaxPower - Stores the maximum power consumption of this configuration, in
  404. 2mA units.
  405. --*/
  406. typedef struct _USB_CONFIGURATION_DESCRIPTOR {
  407. UCHAR Length;
  408. UCHAR DescriptorType;
  409. USHORT TotalLength;
  410. UCHAR InterfaceCount;
  411. UCHAR ConfigurationValue;
  412. UCHAR StringIndex;
  413. UCHAR Attributes;
  414. UCHAR MaxPower;
  415. } PACKED USB_CONFIGURATION_DESCRIPTOR, *PUSB_CONFIGURATION_DESCRIPTOR;
  416. /*++
  417. Structure Description:
  418. This structure defines the format of the USB Interface Descriptor, as
  419. defined by the USB specification.
  420. Members:
  421. Length - Stores the length of the structure.
  422. DescriptorType - Stores a constant indicating that this is an interface
  423. descriptor.
  424. InterfaceNumber - Stores the index of this interface.
  425. AlternateNumber - Stores the alternate index of this interface.
  426. EndpointCount - Stores the number of endpoints in this interface, not
  427. counting endpoint zero.
  428. Class - Stores the class code of the interface (assigned by the USB
  429. organization).
  430. Subclass - Stores the subclass code of the interface (assigned by the USB
  431. organization).
  432. Protocol - Stores the protocol code of the interface (assigned by the USB
  433. organization).
  434. StringIndex - Stores the index of the string descriptor describing the
  435. interface.
  436. --*/
  437. typedef struct _USB_INTERFACE_DESCRIPTOR {
  438. UCHAR Length;
  439. UCHAR DescriptorType;
  440. UCHAR InterfaceNumber;
  441. UCHAR AlternateNumber;
  442. UCHAR EndpointCount;
  443. UCHAR Class;
  444. UCHAR Subclass;
  445. UCHAR Protocol;
  446. UCHAR StringIndex;
  447. } PACKED USB_INTERFACE_DESCRIPTOR, *PUSB_INTERFACE_DESCRIPTOR;
  448. /*++
  449. Structure Description:
  450. This structure defines the format of the USB Endpoint Descriptor, as
  451. defined by the USB specification.
  452. Members:
  453. Length - Stores the length of the structure.
  454. DescriptorType - Stores a constant indicating that this is an endpoint
  455. descriptor.
  456. EndpointAddress - Stores the address and direction of this endpoint.
  457. Attributes - Stores a bitfield of attributes of the endpoint.
  458. MaxPacketSize - Stores the maximum packet size this endpoint is capable of
  459. sending or receiving.
  460. Interval - Stores the interval for polling data transfer. This value is in
  461. frame counts, and is ignored for Control endpoints. Isochronous
  462. endpoints must set this to 1, interrupt endpoints may range from 1
  463. to 255, and Bulk OUT endpoints range from 0 to 255 to speceified the
  464. maximum NAK rate.
  465. --*/
  466. typedef struct _USB_ENDPOINT_DESCRIPTOR {
  467. UCHAR Length;
  468. UCHAR DescriptorType;
  469. UCHAR EndpointAddress;
  470. UCHAR Attributes;
  471. USHORT MaxPacketSize;
  472. UCHAR Interval;
  473. } PACKED USB_ENDPOINT_DESCRIPTOR, *PUSB_ENDPOINT_DESCRIPTOR;
  474. /*++
  475. Structure Description:
  476. This structure defines the format of the USB String Descriptor, as defined
  477. by the USB specification. The string itself immediately follows this
  478. descriptor structure.
  479. Members:
  480. Length - Stores the length of the structure.
  481. DescriptorType - Stores a constant indicating that this is a string
  482. descriptor.
  483. --*/
  484. typedef struct _USB_STRING_DESCRIPTOR {
  485. UCHAR Length;
  486. UCHAR DescriptorType;
  487. } PACKED USB_STRING_DESCRIPTOR, *PUSB_STRING_DESCRIPTOR;
  488. /*++
  489. Structure Description:
  490. This structure defines the format of the Setup Packet, as defined
  491. by the USB specification.
  492. Members:
  493. RequestType - Stores a bitfield indicating the transfer direction, transfer
  494. type, and recipient.
  495. Request - Stores the request value.
  496. Value - Stores the value associated with the request.
  497. Index - Stores the index associated with the request.
  498. Length - Stores the number of bytes to transfer if there is a data phase.
  499. --*/
  500. /*++
  501. Structure Description:
  502. This structure defines the format of the USB Hub Descriptor, as defined by
  503. the USB specification.
  504. Members:
  505. Length - Stores the length of the structure.
  506. DescriptorType - Stores a constant indicating that this is a hub descriptor.
  507. PortCount - Stores the number of downstream ports in this hub.
  508. HubCharacteristics - Stores a bitfield of hub characteristics. See
  509. USB_HUB_CHARACTERISTIC_* definitions.
  510. PowerDelayIn2ms - Stores the time, in 2ms intervals, from the time the
  511. power-on sequence begins on a port until the power is good on that
  512. port. Software uses this value to determine how long to wait before
  513. accessing a powered-on port.
  514. HubCurrent - Stores the maximum current requirements of the hub controller
  515. electronics in mA.
  516. DeviceRemovable - Stores a variable-length byte array indicating if a port
  517. has a removable device attached. Within a byte, if no port exists for
  518. a given location, the field representing the port characteristics
  519. returns 0. Each bit is set if the corresponding port is non-removable,
  520. and is clear if the port has a removable device.
  521. --*/
  522. typedef struct _USB_HUB_DESCRIPTOR {
  523. UCHAR Length;
  524. UCHAR DescriptorType;
  525. UCHAR PortCount;
  526. USHORT HubCharacteristics;
  527. UCHAR PowerUpDelayIn2ms;
  528. UCHAR HubCurrent;
  529. UCHAR DeviceRemovable[ANYSIZE_ARRAY];
  530. } PACKED USB_HUB_DESCRIPTOR, *PUSB_HUB_DESCRIPTOR;
  531. /*++
  532. Structure Description:
  533. This structure defines a USB setup packet.
  534. Members:
  535. RequestType - Stores the properties of the request.
  536. Request - Stores the particular type of request in the packet.
  537. Value - Stores request-specific parameters for the device.
  538. Index - Stores request-specific parameters for the device.
  539. Length - Stores the length of the data to be transferred.
  540. --*/
  541. typedef struct _USB_SETUP_PACKET {
  542. UCHAR RequestType;
  543. UCHAR Request;
  544. USHORT Value;
  545. USHORT Index;
  546. USHORT Length;
  547. } PACKED USB_SETUP_PACKET, *PUSB_SETUP_PACKET;
  548. /*++
  549. Structure Description:
  550. This structure defines a USB device description.
  551. Members:
  552. ListEntry - Stores pointers to the next and previous device descriptions
  553. in the parent's child list.
  554. Descriptor - Stores the device descriptor.
  555. ChildListHead - Stores the head of the list of children of this device.
  556. --*/
  557. typedef struct _USB_DEVICE_DESCRIPTION {
  558. LIST_ENTRY ListEntry;
  559. USB_DEVICE_DESCRIPTOR Descriptor;
  560. LIST_ENTRY ChildListHead;
  561. } USB_DEVICE_DESCRIPTION, *PUSB_DEVICE_DESCRIPTION;
  562. /*++
  563. Structure Description:
  564. This structure defines a USB configuration description.
  565. Members:
  566. Descriptor - Stores the configuration descriptor.
  567. Index - Stores the index number of the configuration.
  568. InterfaceListHead - Stores the head of the list of interfaces in this
  569. configuration.
  570. --*/
  571. typedef struct _USB_CONFIGURATION_DESCRIPTION {
  572. USB_CONFIGURATION_DESCRIPTOR Descriptor;
  573. UCHAR Index;
  574. LIST_ENTRY InterfaceListHead;
  575. } USB_CONFIGURATION_DESCRIPTION, *PUSB_CONFIGURATION_DESCRIPTION;
  576. /*++
  577. Structure Description:
  578. This structure defines a USB interface description.
  579. Members:
  580. ListEntry - Stores pointers to the next and previous interfaces in the
  581. parent configuration.
  582. Descriptor - Stores the interface descriptor.
  583. EndpointListHead - Stores the head of the list of endpoints in this
  584. interface.
  585. --*/
  586. typedef struct _USB_INTERFACE_DESCRIPTION {
  587. LIST_ENTRY ListEntry;
  588. USB_INTERFACE_DESCRIPTOR Descriptor;
  589. LIST_ENTRY EndpointListHead;
  590. } USB_INTERFACE_DESCRIPTION, *PUSB_INTERFACE_DESCRIPTION;
  591. /*++
  592. Structure Description:
  593. This structure defines a USB endpoint description.
  594. Members:
  595. ListEntry - Stores pointers to the next and previous endpoints in the
  596. parent interface.
  597. Descriptor - Stores the endpoint descriptor.
  598. --*/
  599. typedef struct _USB_ENDPOINT_DESCRIPTION {
  600. LIST_ENTRY ListEntry;
  601. USB_ENDPOINT_DESCRIPTOR Descriptor;
  602. } USB_ENDPOINT_DESCRIPTION, *PUSB_ENDPOINT_DESCRIPTION;
  603. typedef
  604. VOID
  605. (*PUSB_TRANSFER_CALLBACK) (
  606. PUSB_TRANSFER Transfer
  607. );
  608. /*++
  609. Routine Description:
  610. This routine is called when an asynchronous I/O request completes with
  611. success, failure, or is cancelled.
  612. Arguments:
  613. Transfer - Supplies a pointer to the transfer that completed.
  614. Return Value:
  615. None.
  616. --*/
  617. /*++
  618. Structure Description:
  619. This structure stores information about a USB transfer request.
  620. Members:
  621. Direction - Stores the direction of the USB transfer. This must be
  622. consistent with the endpoint being sent to.
  623. Status - Stores the completion status of the request.
  624. Length - Stores the length of the request, in bytes.
  625. LengthTransferred - Stores the number of bytes that have actually been
  626. transferred.
  627. CallbackRoutine - Stores a pointer to a routine that will be called back
  628. when the transfer completes.
  629. UserData - Stores an area where the user can store a pointer's worth of
  630. data, usually used by the callback routine to identify a request.
  631. Buffer - Stores a pointer to the data buffer.
  632. BufferPhysicalAddress - Stores the physical address of the data buffer.
  633. BufferActualLength - Stores the actual length of the buffer, in bytes. The
  634. buffer must be at least as large as the length, and must be aligned to
  635. a flushable boundary.
  636. Flags - Stores a bitfield of flags regarding the transaction. See
  637. USB_TRANSFER_FLAG_* definitions.
  638. Error - Stores a more detailed and USB specific error code.
  639. --*/
  640. struct _USB_TRANSFER {
  641. USB_TRANSFER_DIRECTION Direction;
  642. KSTATUS Status;
  643. ULONG Length;
  644. ULONG LengthTransferred;
  645. PUSB_TRANSFER_CALLBACK CallbackRoutine;
  646. PVOID UserData;
  647. PVOID Buffer;
  648. PHYSICAL_ADDRESS BufferPhysicalAddress;
  649. ULONG BufferActualLength;
  650. ULONG Flags;
  651. USB_ERROR Error;
  652. };
  653. //
  654. // -------------------------------------------------------------------- Globals
  655. //
  656. //
  657. // -------------------------------------------------------- Function Prototypes
  658. //
  659. USB_API
  660. KSTATUS
  661. UsbDriverAttach (
  662. PDEVICE Device,
  663. PDRIVER Driver,
  664. PHANDLE UsbCoreHandle
  665. );
  666. /*++
  667. Routine Description:
  668. This routine attaches a USB driver to a USB device, and returns a USB
  669. core handle to the device, used for all USB communications. This routine
  670. must be called at low level.
  671. Arguments:
  672. Device - Supplies a pointer to the OS device object representation of the
  673. USB device.
  674. Driver - Supplies a pointer to the driver that will take ownership of the
  675. device.
  676. UsbCoreHandle - Supplies a pointer where the USB Core device handle will
  677. be returned.
  678. Return Value:
  679. Status code.
  680. --*/
  681. USB_API
  682. KSTATUS
  683. UsbEnumerateDeviceForInterface (
  684. HANDLE UsbCoreHandle,
  685. PUSB_INTERFACE_DESCRIPTION InterfaceDescription,
  686. PDEVICE *ChildDevice
  687. );
  688. /*++
  689. Routine Description:
  690. This routine enumerates a child OS device on the requested device and
  691. interface combination. With this interface multiple drivers can
  692. independently operate interfaces of a shared USB device.
  693. Arguments:
  694. UsbCoreHandle - Supplies the core handle to the device containing the
  695. interface to share.
  696. InterfaceDescription - Supplies a pointer to the interface to enumerate a
  697. device for.
  698. ChildDevice - Supplies a pointer to an OS device that will come up to
  699. claim the given interface. This device should be returned in Query
  700. Children calls sent to the parent device so the device can properly
  701. enumerate.
  702. Return Value:
  703. Status code.
  704. --*/
  705. USB_API
  706. PUSB_INTERFACE_DESCRIPTION
  707. UsbGetDesignatedInterface (
  708. PDEVICE Device,
  709. HANDLE UsbCoreHandle
  710. );
  711. /*++
  712. Routine Description:
  713. This routine returns the interface for which the given pseudo-device was
  714. enumerated. This routine is used by general class drivers (like Hub or
  715. Mass Storage) that can interact with an interface without necessarily
  716. taking responsibility for the entire device.
  717. Arguments:
  718. Device - Supplies a pointer to the OS device object representation of the
  719. USB device.
  720. UsbCoreHandle - Supplies the core handle to the device.
  721. Return Value:
  722. Returns a pointer to the interface this pseudo-device is supposed to take
  723. ownership of. If the device only has one interface, then that interface is
  724. returned.
  725. NULL if the OS device was not enumerated for any one particular interface.
  726. --*/
  727. USB_API
  728. KSTATUS
  729. UsbGetDeviceSpeed (
  730. PUSB_DEVICE Device,
  731. PUSB_DEVICE_SPEED Speed
  732. );
  733. /*++
  734. Routine Description:
  735. This routine returns the connected speed of the given USB device.
  736. Arguments:
  737. Device - Supplies a pointer to the device.
  738. Speed - Supplies a pointer where the device speed will be returned.
  739. Return Value:
  740. Status code.
  741. --*/
  742. USB_API
  743. VOID
  744. UsbDetachDevice (
  745. HANDLE UsbCoreHandle
  746. );
  747. /*++
  748. Routine Description:
  749. This routine detaches a USB device from the USB core by marking it as
  750. disconnected, and cancelling all active transfers belonging to the device.
  751. It does not close the device.
  752. Arguments:
  753. UsbCoreHandle - Supplies the core handle to the device that is to be
  754. removed.
  755. Return Value:
  756. None.
  757. --*/
  758. USB_API
  759. KSTATUS
  760. UsbReadDeviceString (
  761. PUSB_DEVICE Device,
  762. UCHAR StringNumber,
  763. USHORT Language,
  764. PUSB_STRING_DESCRIPTOR Buffer
  765. );
  766. /*++
  767. Routine Description:
  768. This routine reads a string descriptor from a USB device.
  769. Arguments:
  770. Device - Supplies a pointer to the device to read from.
  771. StringNumber - Supplies the string descriptor index of the string to read.
  772. Language - Supplies the language code.
  773. Buffer - Supplies a pointer where the string descriptor and data will be
  774. returned. This buffer must be the size of the maximum string descriptor,
  775. which is 256 bytes.
  776. Return Value:
  777. Status code.
  778. --*/
  779. USB_API
  780. HANDLE
  781. UsbDeviceOpen (
  782. PUSB_DEVICE Device
  783. );
  784. /*++
  785. Routine Description:
  786. This routine attempts to open a USB device for I/O.
  787. Arguments:
  788. Device - Supplies a pointer to the device to open.
  789. Return Value:
  790. Returns a handle to the device upon success.
  791. INVALID_HANDLE if the device could not be opened.
  792. --*/
  793. USB_API
  794. VOID
  795. UsbDeviceClose (
  796. HANDLE UsbDeviceHandle
  797. );
  798. /*++
  799. Routine Description:
  800. This routine closes an open USB handle.
  801. Arguments:
  802. UsbDeviceHandle - Supplies the handle returned when the device was opened.
  803. Return Value:
  804. None.
  805. --*/
  806. USB_API
  807. PUSB_TRANSFER
  808. UsbAllocateTransfer (
  809. HANDLE UsbDeviceHandle,
  810. UCHAR EndpointNumber,
  811. ULONG MaxTransferSize,
  812. ULONG Flags
  813. );
  814. /*++
  815. Routine Description:
  816. This routine allocates a new USB transfer structure. This routine must be
  817. used to allocate transfers.
  818. Arguments:
  819. UsbDeviceHandle - Supplies the handle returned when the device was opened.
  820. EndpointNumber - Supplies the endpoint number that the transfer will go to.
  821. MaxTransferSize - Supplies the maximum length, in bytes, of the transfer.
  822. Attempts to submit a transfer with lengths longer than this initialized
  823. length will fail. Longer transfer sizes do require more resources as
  824. they are split into subpackets, so try to be reasonable.
  825. Flags - Supplies a bitfield of flags regarding the transaction. See
  826. USB_TRANSFER_FLAG_* definitions.
  827. Return Value:
  828. Returns a pointer to the new USB transfer on success.
  829. NULL when there are insufficient resources to complete the request.
  830. --*/
  831. USB_API
  832. VOID
  833. UsbDestroyTransfer (
  834. PUSB_TRANSFER Transfer
  835. );
  836. /*++
  837. Routine Description:
  838. This routine destroys an allocated transfer. This transfer must not be
  839. actively transferring.
  840. Arguments:
  841. Transfer - Supplies a pointer to the transfer to destroy.
  842. Return Value:
  843. None.
  844. --*/
  845. USB_API
  846. KSTATUS
  847. UsbSubmitTransfer (
  848. PUSB_TRANSFER Transfer
  849. );
  850. /*++
  851. Routine Description:
  852. This routine submits a USB transfer. The routine returns immediately,
  853. indicating only whether the transfer was submitted successfully. When the
  854. transfer actually completes, the callback routine will be called.
  855. Arguments:
  856. Transfer - Supplies a pointer to the transfer to destroy.
  857. Return Value:
  858. STATUS_SUCCESS if the transfer was submitted to the USB host controller's
  859. queue.
  860. STATUS_INVALID_PARAMETER if one or more of the transfer fields is not
  861. properly filled out.
  862. Failing status codes if the request could not be submitted.
  863. --*/
  864. USB_API
  865. KSTATUS
  866. UsbSubmitSynchronousTransfer (
  867. PUSB_TRANSFER Transfer
  868. );
  869. /*++
  870. Routine Description:
  871. This routine submits a USB transfer, and does not return until the transfer
  872. is completed successfully or with an error. This routine must be called at
  873. low level.
  874. Arguments:
  875. Transfer - Supplies a pointer to the transfer to destroy.
  876. Return Value:
  877. STATUS_SUCCESS if the transfer was submitted to the USB host controller's
  878. queue.
  879. STATUS_INVALID_PARAMETER if one or more of the transfer fields is not
  880. properly filled out.
  881. Failing status codes if the request could not be submitted.
  882. --*/
  883. USB_API
  884. KSTATUS
  885. UsbSubmitPolledTransfer (
  886. PUSB_TRANSFER Transfer
  887. );
  888. /*++
  889. Routine Description:
  890. This routine submits a USB transfer, and does not return until the transfer
  891. is completed successfully or with an error. This routine is meant to be
  892. called in critical code paths at high level.
  893. Arguments:
  894. Transfer - Supplies a pointer to the transfer to submit.
  895. Return Value:
  896. Status code.
  897. --*/
  898. USB_API
  899. KSTATUS
  900. UsbCancelTransfer (
  901. PUSB_TRANSFER Transfer,
  902. BOOL Wait
  903. );
  904. /*++
  905. Routine Description:
  906. This routine cancels a USB transfer, waiting for the transfer to enter the
  907. inactive state before returning. Must be called at low level.
  908. Arguments:
  909. Transfer - Supplies a pointer to the transfer to cancel.
  910. Wait - Supplies a boolean indicating that the caller wants to wait for the
  911. transfer the reach the inactive state. Specify TRUE if unsure.
  912. Return Value:
  913. Returns STATUS_SUCCESS if the transfer was successfully cancelled.
  914. Returns STATUS_TOO_LATE if the transfer was not cancelled, but moved to the
  915. inactive state.
  916. --*/
  917. USB_API
  918. KSTATUS
  919. UsbInitializePagingDeviceTransfers (
  920. VOID
  921. );
  922. /*++
  923. Routine Description:
  924. This routine initializes the USB core to handle special paging device
  925. transfers that are serviced on their own work queue.
  926. Arguments:
  927. None.
  928. Return Value:
  929. Status code.
  930. --*/
  931. USB_API
  932. ULONG
  933. UsbTransferAddReference (
  934. PUSB_TRANSFER Transfer
  935. );
  936. /*++
  937. Routine Description:
  938. This routine adds a reference to a USB transfer.
  939. Arguments:
  940. Transfer - Supplies a pointer to the transfer that is to be referenced.
  941. Return Value:
  942. Returns the old reference count.
  943. --*/
  944. USB_API
  945. ULONG
  946. UsbTransferReleaseReference (
  947. PUSB_TRANSFER Transfer
  948. );
  949. /*++
  950. Routine Description:
  951. This routine releases a reference on a USB transfer.
  952. Arguments:
  953. Transfer - Supplies a pointer to the transfer that is to be dereferenced.
  954. Return Value:
  955. Returns the old reference count.
  956. --*/
  957. USB_API
  958. KSTATUS
  959. UsbGetStatus (
  960. HANDLE UsbDeviceHandle,
  961. UCHAR RequestRecipient,
  962. USHORT Index,
  963. PUSHORT Data
  964. );
  965. /*++
  966. Routine Description:
  967. This routine gets the status from the given device, interface, or endpoint,
  968. as determined based on the request type and index. This routine must be
  969. called at low level.
  970. Arguments:
  971. UsbDeviceHandle - Supplies the handle returned when the device was opened.
  972. RequestRecipient - Supplies the recipient of this get status request.
  973. Index - Supplies the index of this get status request. This can be
  974. zero for devices, an interface number, or an endpoint number.
  975. Data - Supplies a pointer that receives the status from the request.
  976. Return Value:
  977. Status code.
  978. --*/
  979. USB_API
  980. KSTATUS
  981. UsbSetFeature (
  982. HANDLE UsbDeviceHandle,
  983. UCHAR RequestRecipient,
  984. USHORT Feature,
  985. USHORT Index
  986. );
  987. /*++
  988. Routine Description:
  989. This routine sets the given feature for a device, interface or endpoint,
  990. as specified by the request type and index. This routine must be called at
  991. low level.
  992. Arguments:
  993. UsbDeviceHandle - Supplies the handle returned when the device was opened.
  994. RequestRecipient - Supplies the recipient of this clear feature request.
  995. Feature - Supplies the value of this clear feature request.
  996. Index - Supplies the index of this clear feature request. This can be
  997. zero for devices, an interface number, or an endpoint number.
  998. Return Value:
  999. Status code.
  1000. --*/
  1001. USB_API
  1002. KSTATUS
  1003. UsbClearFeature (
  1004. HANDLE UsbDeviceHandle,
  1005. UCHAR RequestType,
  1006. USHORT FeatureSelector,
  1007. USHORT Index
  1008. );
  1009. /*++
  1010. Routine Description:
  1011. This routine sets the configuration to the given configuration value. This
  1012. routine must be called at low level.
  1013. Arguments:
  1014. UsbDeviceHandle - Supplies the handle returned when the device was opened.
  1015. RequestType - Supplies the type of this clear feature request.
  1016. FeatureSelector - Supplies the value of this clear feature request.
  1017. Index - Supplies the index of this clear feature request. This can be
  1018. zero for devices, an interface number, or an endpoint number.
  1019. Return Value:
  1020. Status code.
  1021. --*/
  1022. USB_API
  1023. ULONG
  1024. UsbGetConfigurationCount (
  1025. HANDLE UsbDeviceHandle
  1026. );
  1027. /*++
  1028. Routine Description:
  1029. This routine gets the number of possible configurations in a given device.
  1030. Arguments:
  1031. UsbDeviceHandle - Supplies the handle returned when the device was opened.
  1032. Return Value:
  1033. Returns the number of configurations in the device.
  1034. --*/
  1035. USB_API
  1036. KSTATUS
  1037. UsbGetConfiguration (
  1038. HANDLE UsbDeviceHandle,
  1039. UCHAR ConfigurationNumber,
  1040. BOOL NumberIsIndex,
  1041. PUSB_CONFIGURATION_DESCRIPTION *Configuration
  1042. );
  1043. /*++
  1044. Routine Description:
  1045. This routine gets a configuration out of the given device. This routine will
  1046. send a blocking request to the device. This routine must be called at low
  1047. level.
  1048. Arguments:
  1049. UsbDeviceHandle - Supplies the handle returned when the device was opened.
  1050. ConfigurationNumber - Supplies the index or configuration value of the
  1051. configuration to get.
  1052. NumberIsIndex - Supplies a boolean indicating whether the configuration
  1053. number is an index (TRUE) or a specific configuration value (FALSE).
  1054. Configuration - Supplies a pointer where a pointer to the desired
  1055. configuration will be returned.
  1056. Return Value:
  1057. Status code.
  1058. --*/
  1059. USB_API
  1060. PUSB_CONFIGURATION_DESCRIPTION
  1061. UsbGetActiveConfiguration (
  1062. HANDLE UsbDeviceHandle
  1063. );
  1064. /*++
  1065. Routine Description:
  1066. This routine gets the currently active configuration set in the device.
  1067. Arguments:
  1068. UsbDeviceHandle - Supplies the handle returned when the device was opened.
  1069. Return Value:
  1070. Returns a pointer to the current configuration.
  1071. NULL if the device is not currently configured.
  1072. --*/
  1073. USB_API
  1074. KSTATUS
  1075. UsbSetConfiguration (
  1076. HANDLE UsbDeviceHandle,
  1077. UCHAR ConfigurationNumber,
  1078. BOOL NumberIsIndex
  1079. );
  1080. /*++
  1081. Routine Description:
  1082. This routine sets the configuration to the given configuration value. This
  1083. routine must be called at low level.
  1084. Arguments:
  1085. UsbDeviceHandle - Supplies the handle returned when the device was opened.
  1086. ConfigurationNumber - Supplies the configuration index or value to set.
  1087. NumberIsIndex - Supplies a boolean indicating whether the configuration
  1088. number is an index (TRUE) or a specific configuration value (FALSE).
  1089. Return Value:
  1090. Status code.
  1091. --*/
  1092. USB_API
  1093. KSTATUS
  1094. UsbClaimInterface (
  1095. HANDLE UsbDeviceHandle,
  1096. UCHAR InterfaceNumber
  1097. );
  1098. /*++
  1099. Routine Description:
  1100. This routine claims an interface, preparing it for I/O use. An interface
  1101. can be claimed more than once. This routine must be called at low level.
  1102. Arguments:
  1103. UsbDeviceHandle - Supplies the handle returned when the device was opened.
  1104. InterfaceNumber - Supplies the number of the interface to claim.
  1105. Return Value:
  1106. Status code.
  1107. --*/
  1108. USB_API
  1109. VOID
  1110. UsbReleaseInterface (
  1111. HANDLE UsbDeviceHandle,
  1112. UCHAR InterfaceNumber
  1113. );
  1114. /*++
  1115. Routine Description:
  1116. This routine releases an interface that was previously claimed for I/O.
  1117. After this call, the caller that had claimed the interface should not use
  1118. it again without reclaiming it.
  1119. Arguments:
  1120. UsbDeviceHandle - Supplies the handle returned when the device was opened.
  1121. InterfaceNumber - Supplies the number of the interface to release.
  1122. Return Value:
  1123. Status code.
  1124. --*/
  1125. USB_API
  1126. KSTATUS
  1127. UsbSendControlTransfer (
  1128. HANDLE UsbDeviceHandle,
  1129. USB_TRANSFER_DIRECTION TransferDirection,
  1130. PUSB_SETUP_PACKET SetupPacket,
  1131. PVOID Buffer,
  1132. ULONG BufferLength,
  1133. PULONG LengthTransferred
  1134. );
  1135. /*++
  1136. Routine Description:
  1137. This routine sends a syncrhonous control transfer to or from the given USB
  1138. device.
  1139. Arguments:
  1140. UsbDeviceHandle - Supplies a pointer to the device to talk to.
  1141. TransferDirection - Supplies whether or not the transfer is to the device
  1142. or to the host.
  1143. SetupPacket - Supplies a pointer to the setup packet.
  1144. Buffer - Supplies a pointer to the buffer to be sent or received. This does
  1145. not include the setup packet, this is the optional data portion only.
  1146. BufferLength - Supplies the length of the buffer, not including the setup
  1147. packet.
  1148. LengthTransferred - Supplies a pointer where the number of bytes that were
  1149. actually transfered (not including the setup packet) will be returned.
  1150. Return Value:
  1151. Status code.
  1152. --*/
  1153. USB_API
  1154. PVOID
  1155. UsbGetDeviceToken (
  1156. PUSB_DEVICE Device
  1157. );
  1158. /*++
  1159. Routine Description:
  1160. This routine returns the system device token associated with the given USB
  1161. device.
  1162. Arguments:
  1163. Device - Supplies a pointer to a USB device.
  1164. Return Value:
  1165. Returns a system device token.
  1166. --*/
  1167. USB_API
  1168. BOOL
  1169. UsbIsPolledIoSupported (
  1170. HANDLE UsbDeviceHandle
  1171. );
  1172. /*++
  1173. Routine Description:
  1174. This routine returns a boolean indicating whether or not the given USB
  1175. device's controller supports polled I/O mode. Polled I/O should only be
  1176. used in dire circumstances. That is, during system failure when a crash
  1177. dump file needs to be written over USB Mass Storage at high run level with
  1178. interrupts disabled.
  1179. Arguments:
  1180. UsbDeviceHandle - Supplies the handle returned when the device was opened.
  1181. Return Value:
  1182. Returns a boolean indicating if polled I/O is supported (TRUE) or not
  1183. (FALSE).
  1184. --*/
  1185. USB_API
  1186. KSTATUS
  1187. UsbResetEndpoint (
  1188. HANDLE UsbDeviceHandle,
  1189. UCHAR EndpointNumber
  1190. );
  1191. /*++
  1192. Routine Description:
  1193. This routine resets the given endpoint for the given USB device. This
  1194. includes resetting the data toggle to DATA 0.
  1195. Arguments:
  1196. UsbDeviceHandle - Supplies the handle returned when the device was opened.
  1197. EndpointNumber - Supplies the number of the endpoint to be reset.
  1198. Return Value:
  1199. Status code.
  1200. --*/
  1201. USB_API
  1202. KSTATUS
  1203. UsbFlushEndpoint (
  1204. HANDLE UsbDeviceHandle,
  1205. UCHAR EndpointNumber,
  1206. PULONG TransferCount
  1207. );
  1208. /*++
  1209. Routine Description:
  1210. This routine flushes the given endpoint for the given USB device. This
  1211. includes busily waiting for all active transfers to complete. This is only
  1212. meant to be used at high run level when preparing to write a crash dump
  1213. file using USB Mass Storage.
  1214. Arguments:
  1215. UsbDeviceHandle - Supplies the handle returned when the device was opened.
  1216. EndpointNumber - Supplies the number of the endpoint to be reset.
  1217. TransferCount - Supplies a pointer that receives the total number of
  1218. transfers that were flushed.
  1219. Return Value:
  1220. Status code.
  1221. --*/