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.

516 lines
16 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. USBDLIB.H
  5. Abstract:
  6. Services exported by USBD.
  7. Environment:
  8. Kernel & user mode
  9. Revision History:
  10. 06-10-96 : created
  11. --*/
  12. #ifndef __USBDLIB_H__
  13. #define __USBDLIB_H__
  14. typedef struct _USBD_INTERFACE_LIST_ENTRY {
  15. PUSB_INTERFACE_DESCRIPTOR InterfaceDescriptor;
  16. PUSBD_INTERFACE_INFORMATION Interface;
  17. } USBD_INTERFACE_LIST_ENTRY, *PUSBD_INTERFACE_LIST_ENTRY;
  18. //
  19. // Macros for building URB requests
  20. //
  21. #define UsbBuildInterruptOrBulkTransferRequest(urb, \
  22. length, \
  23. pipeHandle, \
  24. transferBuffer, \
  25. transferBufferMDL, \
  26. transferBufferLength, \
  27. transferFlags, \
  28. link) { \
  29. (urb)->UrbHeader.Function = URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER; \
  30. (urb)->UrbHeader.Length = (length); \
  31. (urb)->UrbBulkOrInterruptTransfer.PipeHandle = (pipeHandle); \
  32. (urb)->UrbBulkOrInterruptTransfer.TransferBufferLength = (transferBufferLength); \
  33. (urb)->UrbBulkOrInterruptTransfer.TransferBufferMDL = (transferBufferMDL); \
  34. (urb)->UrbBulkOrInterruptTransfer.TransferBuffer = (transferBuffer); \
  35. (urb)->UrbBulkOrInterruptTransfer.TransferFlags = (transferFlags); \
  36. (urb)->UrbBulkOrInterruptTransfer.UrbLink = (link); }
  37. #define UsbBuildGetDescriptorRequest(urb, \
  38. length, \
  39. descriptorType, \
  40. descriptorIndex, \
  41. languageId, \
  42. transferBuffer, \
  43. transferBufferMDL, \
  44. transferBufferLength, \
  45. link) { \
  46. (urb)->UrbHeader.Function = URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE; \
  47. (urb)->UrbHeader.Length = (length); \
  48. (urb)->UrbControlDescriptorRequest.TransferBufferLength = (transferBufferLength); \
  49. (urb)->UrbControlDescriptorRequest.TransferBufferMDL = (transferBufferMDL); \
  50. (urb)->UrbControlDescriptorRequest.TransferBuffer = (transferBuffer); \
  51. (urb)->UrbControlDescriptorRequest.DescriptorType = (descriptorType); \
  52. (urb)->UrbControlDescriptorRequest.Index = (descriptorIndex); \
  53. (urb)->UrbControlDescriptorRequest.LanguageId = (languageId); \
  54. (urb)->UrbControlDescriptorRequest.UrbLink = (link); }
  55. #define UsbBuildGetStatusRequest(urb, \
  56. op, \
  57. index, \
  58. transferBuffer, \
  59. transferBufferMDL, \
  60. link) { \
  61. (urb)->UrbHeader.Function = (op); \
  62. (urb)->UrbHeader.Length = sizeof(struct _URB_CONTROL_GET_STATUS_REQUEST); \
  63. (urb)->UrbControlGetStatusRequest.TransferBufferLength = sizeof(USHORT); \
  64. (urb)->UrbControlGetStatusRequest.TransferBufferMDL = (transferBufferMDL); \
  65. (urb)->UrbControlGetStatusRequest.TransferBuffer = (transferBuffer); \
  66. (urb)->UrbControlGetStatusRequest.Index = (index); \
  67. (urb)->UrbControlGetStatusRequest.UrbLink = (link); }
  68. #define UsbBuildFeatureRequest(urb, \
  69. op, \
  70. featureSelector, \
  71. index, \
  72. link) { \
  73. (urb)->UrbHeader.Function = (op); \
  74. (urb)->UrbHeader.Length = sizeof(struct _URB_CONTROL_FEATURE_REQUEST); \
  75. (urb)->UrbControlFeatureRequest.FeatureSelector = (featureSelector); \
  76. (urb)->UrbControlFeatureRequest.Index = (index); \
  77. (urb)->UrbControlFeatureRequest.UrbLink = (link); }
  78. #define UsbBuildSelectConfigurationRequest(urb, \
  79. length, \
  80. configurationDescriptor) { \
  81. (urb)->UrbHeader.Function = URB_FUNCTION_SELECT_CONFIGURATION; \
  82. (urb)->UrbHeader.Length = (length); \
  83. (urb)->UrbSelectConfiguration.ConfigurationDescriptor = (configurationDescriptor); }
  84. #define UsbBuildSelectInterfaceRequest(urb, \
  85. length, \
  86. configurationHandle, \
  87. interfaceNumber, \
  88. alternateSetting) { \
  89. (urb)->UrbHeader.Function = URB_FUNCTION_SELECT_INTERFACE; \
  90. (urb)->UrbHeader.Length = (length); \
  91. (urb)->UrbSelectInterface.Interface.AlternateSetting = (alternateSetting); \
  92. (urb)->UrbSelectInterface.Interface.InterfaceNumber = (interfaceNumber); \
  93. (urb)->UrbSelectInterface.ConfigurationHandle = (configurationHandle); }
  94. #define UsbBuildVendorRequest(urb, \
  95. cmd, \
  96. length, \
  97. transferFlags, \
  98. reservedbits, \
  99. request, \
  100. value, \
  101. index, \
  102. transferBuffer, \
  103. transferBufferMDL, \
  104. transferBufferLength, \
  105. link) { \
  106. (urb)->UrbHeader.Function = cmd; \
  107. (urb)->UrbHeader.Length = (length); \
  108. (urb)->UrbControlVendorClassRequest.TransferBufferLength = (transferBufferLength); \
  109. (urb)->UrbControlVendorClassRequest.TransferBufferMDL = (transferBufferMDL); \
  110. (urb)->UrbControlVendorClassRequest.TransferBuffer = (transferBuffer); \
  111. (urb)->UrbControlVendorClassRequest.RequestTypeReservedBits = (reservedbits); \
  112. (urb)->UrbControlVendorClassRequest.Request = (request); \
  113. (urb)->UrbControlVendorClassRequest.Value = (value); \
  114. (urb)->UrbControlVendorClassRequest.Index = (index); \
  115. (urb)->UrbControlVendorClassRequest.TransferFlags = (transferFlags); \
  116. (urb)->UrbControlVendorClassRequest.UrbLink = (link); }
  117. // This is just a special vendor class request.
  118. #define UsbBuildOsFeatureDescriptorRequest(urb, \
  119. length, \
  120. interface, \
  121. index, \
  122. transferBuffer, \
  123. transferBufferMDL, \
  124. transferBufferLength, \
  125. link) { \
  126. (urb)->UrbHeader.Function = URB_FUNCTION_GET_MS_FEATURE_DESCRIPTOR; \
  127. (urb)->UrbHeader.Length = (length); \
  128. (urb)->UrbOSFeatureDescriptorRequest.TransferBufferLength = (transferBufferLength); \
  129. (urb)->UrbOSFeatureDescriptorRequest.TransferBufferMDL = (transferBufferMDL); \
  130. (urb)->UrbOSFeatureDescriptorRequest.TransferBuffer = (transferBuffer); \
  131. (urb)->UrbOSFeatureDescriptorRequest.InterfaceNumber = (interface); \
  132. (urb)->UrbOSFeatureDescriptorRequest.MS_FeatureDescriptorIndex = (index); \
  133. (urb)->UrbOSFeatureDescriptorRequest.UrbLink = (link); }
  134. //
  135. // Get the USB status code
  136. //
  137. #define URB_STATUS(urb) ((urb)->UrbHeader.Status)
  138. //
  139. // Macros used for select interface and select configuration requests
  140. //
  141. //
  142. // Calculates the size needed for a SELECT_CONFIGURATION URB request given
  143. // the number of interfaces and the total number of pipes in all interfaces
  144. // selected.
  145. //
  146. #ifdef OSR21_COMPAT
  147. #define GET_SELECT_CONFIGURATION_REQUEST_SIZE(totalInterfaces, totalPipes) \
  148. (sizeof(struct _URB_SELECT_CONFIGURATION) + \
  149. ((totalInterfaces-1) * sizeof(USBD_INTERFACE_INFORMATION)) + \
  150. ((totalPipes)*sizeof(USBD_PIPE_INFORMATION)))
  151. #else
  152. #define GET_SELECT_CONFIGURATION_REQUEST_SIZE(totalInterfaces, totalPipes) \
  153. (sizeof(struct _URB_SELECT_CONFIGURATION) + \
  154. ((totalInterfaces-1) * sizeof(USBD_INTERFACE_INFORMATION)) + \
  155. ((totalPipes-1)*sizeof(USBD_PIPE_INFORMATION)))
  156. #endif
  157. //
  158. // Calculates the size needed for a SELECT_INTERFACE URB request given
  159. // the number of pipes in the alternate interface selected.
  160. //
  161. #ifdef OSR21_COMPAT
  162. #define GET_SELECT_INTERFACE_REQUEST_SIZE(totalPipes) \
  163. (sizeof(struct _URB_SELECT_INTERFACE) + \
  164. ((totalPipes)*sizeof(USBD_PIPE_INFORMATION)))
  165. #else
  166. #define GET_SELECT_INTERFACE_REQUEST_SIZE(totalPipes) \
  167. (sizeof(struct _URB_SELECT_INTERFACE) + \
  168. ((totalPipes-1)*sizeof(USBD_PIPE_INFORMATION)))
  169. #endif
  170. //
  171. // Calculates the size of the interface information structure needed to describe
  172. // a give interface based on the number of endpoints.
  173. //
  174. #ifdef OSR21_COMPAT
  175. #define GET_USBD_INTERFACE_SIZE(numEndpoints) (sizeof(USBD_INTERFACE_INFORMATION) + \
  176. sizeof(USBD_PIPE_INFORMATION)*(numEndpoints))
  177. #else
  178. #define GET_USBD_INTERFACE_SIZE(numEndpoints) (sizeof(USBD_INTERFACE_INFORMATION) + \
  179. (sizeof(USBD_PIPE_INFORMATION)*(numEndpoints)) \
  180. - sizeof(USBD_PIPE_INFORMATION))
  181. #endif
  182. //
  183. // Calculates the size of an iso urb request given the number of packets
  184. //
  185. #define GET_ISO_URB_SIZE(n) (sizeof(struct _URB_ISOCH_TRANSFER)+\
  186. sizeof(USBD_ISO_PACKET_DESCRIPTOR)*n)
  187. #ifndef _USBD_
  188. DECLSPEC_IMPORT
  189. VOID
  190. USBD_Debug_LogEntry(
  191. IN CHAR *Name,
  192. IN ULONG Info1,
  193. IN ULONG Info2,
  194. IN ULONG Info3
  195. );
  196. DECLSPEC_IMPORT
  197. VOID
  198. USBD_GetUSBDIVersion(
  199. PUSBD_VERSION_INFORMATION VersionInformation
  200. );
  201. DECLSPEC_IMPORT
  202. PUSB_INTERFACE_DESCRIPTOR
  203. USBD_ParseConfigurationDescriptor(
  204. IN PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor,
  205. IN UCHAR InterfaceNumber,
  206. IN UCHAR AlternateSetting
  207. );
  208. /*++
  209. Routine Description:
  210. This function is replaced by USBD_ParseConfigurationDescriptorEx
  211. Arguments:
  212. Return Value:
  213. --*/
  214. DECLSPEC_IMPORT
  215. PURB
  216. USBD_CreateConfigurationRequest(
  217. IN PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor,
  218. IN OUT PUSHORT Siz
  219. );
  220. /*++
  221. Routine Description:
  222. This function is replaced by USBD_CreateConfigurationRequestEx
  223. Arguments:
  224. Return Value:
  225. --*/
  226. //
  227. // These APIS replace USBD_CreateConfigurationRequest,
  228. // USBD_ParseConfigurationDescriptor
  229. //
  230. DECLSPEC_IMPORT
  231. PUSB_COMMON_DESCRIPTOR
  232. USBD_ParseDescriptors(
  233. IN PVOID DescriptorBuffer,
  234. IN ULONG TotalLength,
  235. IN PVOID StartPosition,
  236. IN LONG DescriptorType
  237. );
  238. /*++
  239. Routine Description:
  240. Parses a group of standard USB configuration descriptors (returned from a device) for
  241. a specific descriptor type.
  242. Arguments:
  243. DescriptorBuffer - pointer to a block of contiguous USB desscriptors
  244. TotalLength - size in bytes of the Descriptor buffer
  245. StartPosition - starting position in the buffer to begin parsing,
  246. this must point to the begining of a USB descriptor.
  247. DescriptorType - USB descritor type to locate.
  248. Return Value:
  249. pointer to a usb descriptor with a DescriptorType field matching the
  250. input parameter or NULL if not found.
  251. --*/
  252. DECLSPEC_IMPORT
  253. PUSB_INTERFACE_DESCRIPTOR
  254. USBD_ParseConfigurationDescriptorEx(
  255. IN PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor,
  256. IN PVOID StartPosition,
  257. IN LONG InterfaceNumber,
  258. IN LONG AlternateSetting,
  259. IN LONG InterfaceClass,
  260. IN LONG InterfaceSubClass,
  261. IN LONG InterfaceProtocol
  262. );
  263. /*++
  264. Routine Description:
  265. Parses a standard USB configuration descriptor (returned from a device) for
  266. a specific interface, alternate setting class subclass or protocol codes
  267. Arguments:
  268. ConfigurationDescriptor - pointer to USB configuration descriptor, returned
  269. from a device (includes all interface and endpoint
  270. descriptors).
  271. StartPosition - pointer to starting position within the configuration
  272. descrptor to begin parsing -- this must be a valid usb
  273. descriptor.
  274. InterfaceNumber - interface number to find, (-1) match any
  275. AlternateSetting - alt setting number to find, (-1) match any
  276. InterfaceClass - class to find, (-1) match any
  277. InterfaceSubClass - subclass to find, (-1) match any
  278. InterfaceProtocol - protocol to find, (-1) match any
  279. Return Value:
  280. returns a pointer to the first interface descriptor matching the parameters
  281. passed in (starting from startposition) or NULL if no match is found.
  282. --*/
  283. DECLSPEC_IMPORT
  284. PURB
  285. USBD_CreateConfigurationRequestEx(
  286. IN PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor,
  287. IN PUSBD_INTERFACE_LIST_ENTRY InterfaceList
  288. );
  289. /*++
  290. Routine Description:
  291. Allocates and initilaizes a urb of sufficient size to configure a device
  292. based on the list of interfaces passed in.
  293. The interface list is a contiguous array of USBD_INTERFACE_LIST_ENTRIES
  294. each pointing to a specific interface descriptor to be incorporated in
  295. the request, the list is terminated by a list entry with an
  296. InterfaceDescriptor pointer of NULL.
  297. On return the interface field of each list entry is filled in with a pointer
  298. to the USBD_INTERFACE_INFORMATION structure within the URB corrisponding to
  299. the same interface descriptor.
  300. Arguments:
  301. ConfigurationDescriptor - pointer to USB configuration descriptor, returned
  302. from a device (includes all interface and endpoint
  303. descriptors).
  304. InterfaceList - list of interfaces we are interested in.
  305. Return Value:
  306. Pointer to initailized select_configuration urb.
  307. --*/
  308. __declspec(dllexport)
  309. ULONG
  310. USBD_GetInterfaceLength(
  311. IN PUSB_INTERFACE_DESCRIPTOR InterfaceDescriptor,
  312. IN PUCHAR BufferEnd
  313. );
  314. /*++
  315. Routine Description:
  316. Returns the length (in bytes) of a given interface descriptor
  317. including all endpoint and class descriptors
  318. Arguments:
  319. InterfaceDescriptor
  320. BufferEnd - Pointer to the end of the buffer containing the descriptors
  321. Return Value:
  322. length of descriptors
  323. --*/
  324. __declspec(dllexport)
  325. VOID
  326. USBD_RegisterHcFilter(
  327. PDEVICE_OBJECT DeviceObject,
  328. PDEVICE_OBJECT FilterDeviceObject
  329. );
  330. /*++
  331. Routine Description:
  332. Called by an HC filter driver after it attaches to the top
  333. of the host controller driver stack.
  334. Arguments:
  335. DeviceObject - current top of stack
  336. FilterDeviceObject - device object for the filter driver
  337. Return Value:
  338. none
  339. --*/
  340. __declspec(dllexport)
  341. NTSTATUS
  342. USBD_GetPdoRegistryParameter(
  343. IN PDEVICE_OBJECT PhysicalDeviceObject,
  344. IN OUT PVOID Parameter,
  345. IN ULONG ParameterLength,
  346. IN PWCHAR KeyName,
  347. IN ULONG KeyNameLength
  348. );
  349. /*++
  350. Routine Description:
  351. Arguments:
  352. Return Value:
  353. --*/
  354. __declspec(dllexport)
  355. NTSTATUS
  356. USBD_QueryBusTime(
  357. IN PDEVICE_OBJECT RootHubPdo,
  358. IN PULONG CurrentFrame
  359. );
  360. /*++
  361. Routine Description:
  362. Returns the current frame, callable at any IRQL
  363. Arguments:
  364. Return Value:
  365. --*/
  366. DECLSPEC_IMPORT
  367. ULONG
  368. USBD_CalculateUsbBandwidth(
  369. ULONG MaxPacketSize,
  370. UCHAR EndpointType,
  371. BOOLEAN LowSpeed
  372. );
  373. /*++
  374. Routine Description:
  375. Returns bus bw consumed based on the endpoint type and
  376. packet size
  377. Arguments:
  378. Return Value:
  379. --*/
  380. #endif /* _USBD_ */
  381. #endif /* __USBDLIB_H__ */