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.

468 lines
24 KiB

  1. /***************************************************************************
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. USBUTIL.H
  5. Abstract:
  6. Public interface for generic USB routines - must be called at PASSIVE_LEVEL
  7. Environment:
  8. Kernel Mode Only
  9. Notes:
  10. THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  11. KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  12. IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  13. PURPOSE.
  14. Copyright (c) 2001 Microsoft Corporation. All Rights Reserved.
  15. Revision History:
  16. 01/08/2001 : created
  17. Authors:
  18. Tom Green
  19. ****************************************************************************/
  20. #ifndef __USBUTIL_H__
  21. #define __USBUTIL_H__
  22. //#include "intread.h"
  23. #define USBWRAP_NOTIFICATION_READ_COMPLETE 0x01
  24. #define USBWRAP_NOTIFICATION_READ_ERROR 0x02
  25. #define USBWRAP_NOTIFICATION_READ_COMPLETE_DIRECT 0x04
  26. #define USBWRAP_NOTIFICATION_BUFFER_CLIENT_FREE 0x10
  27. #define PUMP_STOPPED 0x0
  28. #define PUMP_STARTED 0x01
  29. #ifndef PINGPONG_COUNT
  30. #define PINGPONG_COUNT 3
  31. #endif
  32. #define USBInitializeBulkTransfers USBInitializeInterruptTransfers
  33. #define USBStartBulkTransfers USBStartInterruptTransfers
  34. #define USBStopBulkTransfers USBStopInterruptTransfers
  35. #define USBReleaseBulkTransfers USBReleaseInterruptTransfers
  36. #if DBG
  37. #define DBG_USBUTIL_ERROR 0x0001
  38. #define DBG_USBUTIL_ENTRY_EXIT 0x0002
  39. #define DBG_USBUTIL_FATAL_ERROR 0x0004
  40. #define DBG_USBUTIL_USB_ERROR 0x0008
  41. #define DBG_USBUTIL_DEVICE_ERROR 0x0010
  42. #define DBG_USBUTIL_PNP_ERROR 0x0020
  43. #define DBG_USBUTIL_POWER_ERROR 0x0040
  44. #define DBG_USBUTIL_OTHER_ERROR 0x0080
  45. #define DBG_USBUTIL_TRACE 0x0100
  46. extern ULONG USBUtil_DebugTraceLevel;
  47. typedef
  48. ULONG
  49. (__cdecl *PUSB_WRAP_PRINT)(
  50. PCH Format,
  51. ...
  52. );
  53. extern PUSB_WRAP_PRINT USBUtil_DbgPrint;
  54. #endif // DBG
  55. typedef enum _REQUEST_RECIPIENT
  56. {
  57. Device,
  58. Interface,
  59. Endpoint,
  60. Other
  61. } REQUEST_RECIPIENT;
  62. // prototype for callback into client driver for completion of interrupt requests
  63. typedef NTSTATUS (*INTERRUPT_CALLBACK)(IN PVOID Context,
  64. IN PVOID Buffer,
  65. ULONG BufferLength,
  66. ULONG NotificationType,
  67. OUT PBOOLEAN QueueData);
  68. //typedef struct _USB_WRAPPER_PINGPONG *PUSB_WRAPPER_PINGPONG;
  69. //typedef struct _INTERRUPT_READ_WRAPPER INTERRUPT_READ_WRAPPER;
  70. typedef PVOID USB_WRAPPER_HANDLE;
  71. // prototypes
  72. #define USBCallSync(LowerDevObj,Urb,MillisecondsTimeout,RemoveLock) \
  73. USBCallSyncEx(LowerDevObj,Urb,MillisecondsTimeout,RemoveLock, sizeof(IO_REMOVE_LOCK))
  74. /************************************************************************/
  75. /* USBCallSync */
  76. /************************************************************************/
  77. /* */
  78. /* Routine Description: */
  79. /* */
  80. /* Send URB down USB stack. Synchronous call. */
  81. /* Caller is responsible for URB (allocating and freeing) */
  82. /* */
  83. /* Arguments: */
  84. /* */
  85. /* LowerDevObj - pointer to a device object */
  86. /* Urb - pointer to URB */
  87. /* MillisecondsTimeout - milliseconds to wait for completion */
  88. /* RemoveLock - pointer to remove lock */
  89. /* */
  90. /* Return Value: */
  91. /* */
  92. /* NTSTATUS */
  93. /* */
  94. /************************************************************************/
  95. NTSTATUS
  96. USBCallSyncEx(IN PDEVICE_OBJECT LowerDevObj,
  97. IN PURB Urb,
  98. IN LONG MillisecondsTimeout,
  99. IN PIO_REMOVE_LOCK RemoveLock,
  100. IN ULONG RemLockSize);
  101. #define USBVendorRequest(LowerDevObj, \
  102. Recipient, \
  103. Request, \
  104. Value, \
  105. Index, \
  106. Buffer, \
  107. BufferSize, \
  108. Read, \
  109. MillisecondsTimeout, \
  110. RemoveLock) \
  111. USBVendorRequestEx(LowerDevObj, \
  112. Recipient, \
  113. Request, \
  114. Value, \
  115. Index, \
  116. Buffer, \
  117. BufferSize, \
  118. Read, \
  119. MillisecondsTimeout, \
  120. RemoveLock, \
  121. sizeof(IO_REMOVE_LOCK))
  122. /************************************************************************/
  123. /* USBVendorRequest */
  124. /************************************************************************/
  125. /* */
  126. /* Routine Description: */
  127. /* */
  128. /* Issue USB vendor specific request */
  129. /* */
  130. /* Arguments: */
  131. /* */
  132. /* LowerDevObj - pointer to a device object */
  133. /* Request - request field of vendor specific command */
  134. /* Value - value field of vendor specific command */
  135. /* Index - index field of vendor specific command */
  136. /* Buffer - pointer to data buffer */
  137. /* BufferSize - data buffer length */
  138. /* Read - data direction flag */
  139. /* Timeout - number of milliseconds to wait for completion */
  140. /* RemoveLock - pointer to remove lock */
  141. /* */
  142. /* Return Value: */
  143. /* */
  144. /* NTSTATUS */
  145. /* */
  146. /************************************************************************/
  147. NTSTATUS
  148. USBVendorRequestEx(IN PDEVICE_OBJECT LowerDevObj,
  149. IN REQUEST_RECIPIENT Recipient,
  150. IN UCHAR Request,
  151. IN USHORT Value,
  152. IN USHORT Index,
  153. IN OUT PVOID Buffer,
  154. IN OUT PULONG BufferSize,
  155. IN BOOLEAN Read,
  156. IN LONG MillisecondsTimeout,
  157. IN PIO_REMOVE_LOCK RemoveLock,
  158. IN ULONG RemLockSize);
  159. /************************************************************************/
  160. /* USBClassRequest */
  161. /************************************************************************/
  162. /* */
  163. /* Routine Description: */
  164. /* */
  165. /* Issue USB Class specific request */
  166. /* */
  167. /* Arguments: */
  168. /* */
  169. /* LowerDevObj - pointer to a device object */
  170. /* Request - request field of class specific command */
  171. /* Value - value field of class specific command */
  172. /* Index - index field of class specific command */
  173. /* Buffer - pointer to data buffer */
  174. /* BufferSize - data buffer length */
  175. /* Read - data direction flag */
  176. /* RemoveLock - pointer to remove lock */
  177. /* Timeout - number of milliseconds to wait for completion */
  178. /* */
  179. /* Return Value: */
  180. /* */
  181. /* NTSTATUS */
  182. /* */
  183. /************************************************************************/
  184. #define USBClassRequest(LowerDevObj, \
  185. Recipient, \
  186. Request, \
  187. Value, \
  188. Index, \
  189. Buffer, \
  190. BufferSize, \
  191. Read, \
  192. MillisecondsTimeout, \
  193. RemoveLock) \
  194. USBClassRequestEx(LowerDevObj, \
  195. Recipient, \
  196. Request, \
  197. Value, \
  198. Index, \
  199. Buffer, \
  200. BufferSize, \
  201. Read, \
  202. MillisecondsTimeout, \
  203. RemoveLock, \
  204. sizeof(IO_REMOVE_LOCK))
  205. NTSTATUS
  206. USBClassRequestEx(IN PDEVICE_OBJECT LowerDevObj,
  207. IN REQUEST_RECIPIENT Recipient,
  208. IN UCHAR Request,
  209. IN USHORT Value,
  210. IN USHORT Index,
  211. IN OUT PVOID Buffer,
  212. IN OUT PULONG BufferSize,
  213. IN BOOLEAN Read,
  214. IN LONG MillisecondsTimeout,
  215. IN PIO_REMOVE_LOCK RemoveLock,
  216. IN ULONG RemLockSize);
  217. /************************************************************************/
  218. /* USBInitializeInterruptTransfers */
  219. /************************************************************************/
  220. /* */
  221. /* Routine Description: */
  222. /* */
  223. /* Initialize interrupt read pipe */
  224. /* */
  225. /* Arguments: */
  226. /* */
  227. /* DeviceObject - pointer to the device object */
  228. /* LowerDevObj - pointer to the lower device object */
  229. /* Buffer - pointer to buffer for data from interrupt pipe */
  230. /* BuffSize - size of buffer passed in */
  231. /* InterruptPipe - pipe descriptor */
  232. /* DriverContext - context passed to driver callback routine */
  233. /* DriverCallback - driver routines called on completion */
  234. /* RemoveLock - pointer to remove lock for device */
  235. /* */
  236. /* Return Value: */
  237. /* */
  238. /* USB_WRAPPER_HANDLE */
  239. /* */
  240. /************************************************************************/
  241. #define USBInitializeInterruptTransfers(DeviceObject, \
  242. LowerDevObj, \
  243. MaxTransferSize, \
  244. InterruptPipe, \
  245. DriverContext, \
  246. DriverCallback, \
  247. NotificationTypes, \
  248. RemoveLock) \
  249. USBInitializeInterruptTransfersEx(DeviceObject, \
  250. LowerDevObj, \
  251. MaxTransferSize, \
  252. InterruptPipe, \
  253. DriverContext, \
  254. DriverCallback, \
  255. NotificationTypes, \
  256. PINGPONG_COUNT, \
  257. RemoveLock, \
  258. sizeof(IO_REMOVE_LOCK))
  259. USB_WRAPPER_HANDLE
  260. USBInitializeInterruptTransfersEx(IN PDEVICE_OBJECT DeviceObject,
  261. IN PDEVICE_OBJECT LowerDevObj,
  262. IN ULONG MaxTransferSize,
  263. IN PUSBD_PIPE_INFORMATION InterruptPipe,
  264. IN PVOID DriverContext,
  265. IN INTERRUPT_CALLBACK DriverCallback,
  266. IN ULONG NotificationTypes,
  267. IN ULONG PingPongCount,
  268. IN PIO_REMOVE_LOCK RemoveLock,
  269. IN ULONG RemLockSize);
  270. /************************************************************************/
  271. /* USBStartInterruptTransfers */
  272. /************************************************************************/
  273. /* */
  274. /* Routine Description: */
  275. /* */
  276. /* Start transfers on interrupt pipe */
  277. /* */
  278. /* Arguments: */
  279. /* */
  280. /* WrapperHandle - pointer to wrapper handle from Init call */
  281. /* */
  282. /* Return Value: */
  283. /* */
  284. /* NTSTATUS */
  285. /* */
  286. /************************************************************************/
  287. NTSTATUS
  288. USBStartInterruptTransfers(IN USB_WRAPPER_HANDLE WrapperHandle);
  289. /************************************************************************/
  290. /* USBStopInterruptTransfers */
  291. /************************************************************************/
  292. /* */
  293. /* Routine Description: */
  294. /* */
  295. /* Stop transfers on interrupt pipe and free resources */
  296. /* */
  297. /* Arguments: */
  298. /* */
  299. /* WrapperHandle - pointer to wrapper handle from Start call */
  300. /* */
  301. /* Return Value: */
  302. /* */
  303. /* NTSTATUS */
  304. /* */
  305. /************************************************************************/
  306. NTSTATUS
  307. USBStopInterruptTransfers(IN USB_WRAPPER_HANDLE WrapperHandle);
  308. /************************************************************************/
  309. /* USBStopInterruptTransfers */
  310. /************************************************************************/
  311. /* */
  312. /* Routine Description: */
  313. /* */
  314. /* Frees all resources allocated in */
  315. /* USBInitializeInterruptTransfers */
  316. /* */
  317. /* Arguments: */
  318. /* */
  319. /* WrapperHandle - pointer to wrapper handle from Init call */
  320. /* */
  321. /* Return Value: */
  322. /* */
  323. /* NTSTATUS */
  324. /* */
  325. /************************************************************************/
  326. NTSTATUS
  327. USBReleaseInterruptTransfers(IN USB_WRAPPER_HANDLE WrapperHandle);
  328. /************************************************************************/
  329. /* USBStartSelectiveSuspend */
  330. /************************************************************************/
  331. /* */
  332. /* Routine Description: */
  333. /* */
  334. /* Start selective suspend support for device */
  335. /* */
  336. /* Arguments: */
  337. /* */
  338. /* LowerDevObj - pointer to device object */
  339. /* */
  340. /* Return Value: */
  341. /* */
  342. /* USB_WRAPPER_HANDLE */
  343. /* */
  344. /************************************************************************/
  345. USB_WRAPPER_HANDLE
  346. USBStartSelectiveSuspend(IN PDEVICE_OBJECT LowerDevObj);
  347. /************************************************************************/
  348. /* USBStopSelectiveSuspend */
  349. /************************************************************************/
  350. /* */
  351. /* Routine Description: */
  352. /* */
  353. /* Stop selective suspend support for device */
  354. /* */
  355. /* Arguments: */
  356. /* */
  357. /* WrapperHandle - wrapper handle returned by start routine */
  358. /* */
  359. /* Return Value: */
  360. /* */
  361. /* NTSTATUS */
  362. /* */
  363. /************************************************************************/
  364. NTSTATUS
  365. USBStopSelectiveSuspend(IN USB_WRAPPER_HANDLE WrapperHandle);
  366. /************************************************************************/
  367. /* USBRequestIdle */
  368. /************************************************************************/
  369. /* */
  370. /* Routine Description: */
  371. /* */
  372. /* Idle request for device */
  373. /* */
  374. /* Arguments: */
  375. /* */
  376. /* WrapperHandle - wrapper handle returned by start routine */
  377. /* */
  378. /* Return Value: */
  379. /* */
  380. /* NTSTATUS */
  381. /* */
  382. /************************************************************************/
  383. NTSTATUS
  384. USBRequestIdle(IN USB_WRAPPER_HANDLE WrapperHandle);
  385. /************************************************************************/
  386. /* USBRequestWake */
  387. /************************************************************************/
  388. /* */
  389. /* Routine Description: */
  390. /* */
  391. /* Wake request for device */
  392. /* */
  393. /* Arguments: */
  394. /* */
  395. /* WrapperHandle - wrapper handle returned by start routine */
  396. /* */
  397. /* Return Value: */
  398. /* */
  399. /* NTSTATUS */
  400. /* */
  401. /************************************************************************/
  402. NTSTATUS
  403. USBRequestWake(IN USB_WRAPPER_HANDLE WrapperHandle);
  404. #endif // __USBUTIL_H__