Source code of Windows XP (NT5)
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.

490 lines
12 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. private.h
  5. Abstract:
  6. Prototypes and definitions for the usb scanner device driver.
  7. Author:
  8. Environment:
  9. kernel mode only
  10. Notes:
  11. Revision History:
  12. --*/
  13. //
  14. // Includes
  15. //
  16. #include "debug.h"
  17. //
  18. // Defines
  19. //
  20. #ifndef max
  21. #define max(a,b) (((a) > (b)) ? (a) : (b))
  22. #endif
  23. #ifndef min
  24. #define min(a,b) (((a) < (b)) ? (a) : (b))
  25. #endif
  26. #ifndef ARRAYSIZE
  27. #define ARRAYSIZE(a) (sizeof(a)/sizeof(a[0]))
  28. #endif
  29. #define TAG_USBSCAN 0x55495453 // "STIU"
  30. #define TAG_USBD 0x44425355 // "USBD"
  31. #define USBSCAN_OBJECTNAME_A "\\\\.\\Usbscan"
  32. #define USBSCAN_OBJECTNAME_W L"\\\\.\\Usbscan"
  33. #define USBSCAN_REG_CREATEFILE L"CreateFileName"
  34. #define USBSCAN_TIMEOUT_READ 120 // 120 sec
  35. #define USBSCAN_TIMEOUT_WRITE 120 // 120 sec
  36. #define USBSCAN_TIMEOUT_EVENT 0 // no timeout
  37. #define USBSCAN_TIMEOUT_OTHER 120 // 120 sec
  38. #define USBSCAN_REG_TIMEOUT_READ L"TimeoutRead"
  39. #define USBSCAN_REG_TIMEOUT_WRITE L"TimeoutWrite"
  40. #define USBSCAN_REG_TIMEOUT_EVENT L"TimeoutEvent"
  41. #define USBSCAN_MAX_CREATEFILENAME 64 // 64 characters
  42. //
  43. // Private IOCTL to workaround #446466 (Whistler)
  44. //
  45. #define IOCTL_SEND_USB_REQUEST_PTP CTL_CODE(FILE_DEVICE_USB_SCAN,IOCTL_INDEX+20,METHOD_BUFFERED,FILE_ANY_ACCESS)
  46. //
  47. // Pipe buffer structure for the read pipe only.
  48. //
  49. typedef struct _PIPEBUFFER {
  50. PUCHAR pStartBuffer;
  51. PUCHAR pBuffer;
  52. PUCHAR pNextByte;
  53. ULONG RemainingData;
  54. KEVENT ReadSyncEvent;
  55. } PIPEBUFFER, *PPIPEBUFFER;
  56. //
  57. // Device Extension
  58. //
  59. typedef struct _USBSCAN_DEVICE_EXTENSION {
  60. PDEVICE_OBJECT pStackDeviceObject;
  61. PDEVICE_OBJECT pPhysicalDeviceObject;
  62. ULONG DeviceInstance;
  63. UNICODE_STRING DeviceName;
  64. UNICODE_STRING SymbolicLinkName;
  65. KEVENT PendingIoEvent;
  66. ULONG PendingIoCount;
  67. BOOLEAN AcceptingRequests;
  68. BOOLEAN Stopped;
  69. //
  70. // USB descriptors from the device
  71. //
  72. PUSB_DEVICE_DESCRIPTOR pDeviceDescriptor;
  73. PUSB_CONFIGURATION_DESCRIPTOR pConfigurationDescriptor;
  74. PUSB_INTERFACE_DESCRIPTOR pInterfaceDescriptor;
  75. PUSB_ENDPOINT_DESCRIPTOR pEndpointDescriptor;
  76. USBD_CONFIGURATION_HANDLE ConfigurationHandle;
  77. USBD_PIPE_INFORMATION PipeInfo[MAX_NUM_PIPES];
  78. ULONG NumberOfPipes;
  79. ULONG IndexBulkIn;
  80. ULONG IndexBulkOut;
  81. ULONG IndexInterrupt;
  82. //
  83. // Name of the device interface
  84. //
  85. UNICODE_STRING InterfaceNameString;
  86. //
  87. // Read pipe buffer
  88. //
  89. PIPEBUFFER ReadPipeBuffer[MAX_NUM_PIPES];
  90. //
  91. // Power management variables
  92. //
  93. PIRP pPowerIrp;
  94. DEVICE_CAPABILITIES DeviceCapabilities;
  95. DEVICE_POWER_STATE CurrentDevicePowerState;
  96. } USBSCAN_DEVICE_EXTENSION, *PUSBSCAN_DEVICE_EXTENSION;
  97. typedef struct _TRANSFER_CONTEXT {
  98. ULONG RemainingTransferLength;
  99. ULONG ChunkSize;
  100. ULONG NBytesTransferred;
  101. PUCHAR pTransferBuffer;
  102. PUCHAR pOriginalTransferBuffer;
  103. PMDL pTransferMdl;
  104. ULONG PipeIndex;
  105. PURB pUrb;
  106. BOOLEAN fDestinedForReadBuffer;
  107. BOOLEAN fNextReadBlocked;
  108. PIRP pThisIrp;
  109. PDEVICE_OBJECT pDeviceObject;
  110. LARGE_INTEGER Timeout;
  111. KDPC TimerDpc;
  112. KTIMER Timer;
  113. } TRANSFER_CONTEXT, *PTRANSFER_CONTEXT;
  114. typedef struct _USBSCAN_FILE_CONTEXT {
  115. LONG PipeIndex;
  116. ULONG TimeoutRead;
  117. ULONG TimeoutWrite;
  118. ULONG TimeoutEvent;
  119. } USBSCAN_FILE_CONTEXT, *PUSBSCAN_FILE_CONTEXT;
  120. typedef struct _USBSCAN_PACKTES {
  121. PIRP pIrp;
  122. ULONG TimeoutCounter;
  123. BOOLEAN bCompleted;
  124. LIST_ENTRY PacketsEntry;
  125. } USBSCAN_PACKETS, *PUSBSCAN_PACKETS;
  126. #ifdef _WIN64
  127. typedef struct _IO_BLOCK_32 {
  128. IN unsigned uOffset;
  129. IN unsigned uLength;
  130. IN OUT CHAR * POINTER_32 pbyData;
  131. IN unsigned uIndex;
  132. } IO_BLOCK_32, *PIO_BLOCK_32;
  133. typedef struct _IO_BLOCK_EX_32 {
  134. IN unsigned uOffset;
  135. IN unsigned uLength;
  136. IN OUT CHAR * POINTER_32 pbyData;
  137. IN unsigned uIndex;
  138. IN UCHAR bRequest; // Specific request
  139. IN UCHAR bmRequestType; // Bitmap - charateristics of request
  140. IN UCHAR fTransferDirectionIn; // TRUE - Device-->Host; FALSE - Host-->Device
  141. } IO_BLOCK_EX_32, *PIO_BLOCK_EX_32;
  142. #endif // _WIN64
  143. //
  144. // prototypes
  145. //
  146. NTSTATUS // in usbscan.c
  147. DriverEntry(
  148. IN PDRIVER_OBJECT DriverObject,
  149. IN PUNICODE_STRING RegistryPath
  150. );
  151. VOID // in usbscan.c
  152. USUnload(
  153. IN PDRIVER_OBJECT DriverObject
  154. );
  155. VOID // in usbscan.c
  156. USIncrementIoCount(
  157. IN PDEVICE_OBJECT pDeviceObject
  158. );
  159. LONG // in usbscan.c
  160. USDecrementIoCount(
  161. IN PDEVICE_OBJECT pDeviceObject
  162. );
  163. NTSTATUS // in usbscan.c
  164. USDeferIrpCompletion(
  165. IN PDEVICE_OBJECT pDeviceObject,
  166. IN PIRP pIrp,
  167. IN PVOID Context
  168. );
  169. NTSTATUS // in usbscan.c
  170. USCreateSymbolicLink(
  171. PUSBSCAN_DEVICE_EXTENSION pde
  172. );
  173. NTSTATUS // in usbscan.c
  174. USDestroySymbolicLink(
  175. PUSBSCAN_DEVICE_EXTENSION pde
  176. );
  177. NTSTATUS // in usbscan.c
  178. USPnp(
  179. IN PDEVICE_OBJECT pDeviceObject,
  180. IN PIRP pIrp
  181. );
  182. NTSTATUS // in usbscan.c
  183. USPnpAddDevice(
  184. IN PDRIVER_OBJECT pDriverObject,
  185. IN OUT PDEVICE_OBJECT pPhysicalDeviceObject
  186. );
  187. NTSTATUS // in usbscan.c
  188. USGetUSBDeviceDescriptor(
  189. IN PDEVICE_OBJECT pDeviceObject
  190. );
  191. NTSTATUS // in usbscan.c
  192. USBSCAN_CallUSBD(
  193. IN PDEVICE_OBJECT pDeviceObject,
  194. IN PURB pUrb
  195. );
  196. NTSTATUS // in usbscan.c
  197. USConfigureDevice(
  198. IN PDEVICE_OBJECT pDeviceObject
  199. );
  200. NTSTATUS // in usbscan.c
  201. USUnConfigureDevice(
  202. IN PDEVICE_OBJECT pDeviceObject
  203. );
  204. NTSTATUS // in usbscan.c
  205. UsbScanReadDeviceRegistry(
  206. IN PUSBSCAN_DEVICE_EXTENSION pExtension,
  207. IN PCWSTR pKeyName,
  208. OUT PVOID *ppvData
  209. );
  210. NTSTATUS // in usbscan.c
  211. UsbScanWriteDeviceRegistry(
  212. IN PUSBSCAN_DEVICE_EXTENSION pExtension,
  213. IN PCWSTR pKeyName,
  214. IN ULONG Type,
  215. IN PVOID pvData,
  216. IN ULONG DataSize
  217. );
  218. PURB
  219. USCreateConfigurationRequest(
  220. IN PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor,
  221. IN OUT PUSHORT Siz
  222. );
  223. #ifdef ORIGINAL_POOLTRACK
  224. PVOID // in usbscan.c
  225. USAllocatePool(
  226. IN POOL_TYPE PoolType,
  227. IN ULONG ulNumberOfBytes
  228. );
  229. VOID // in usbscan.c
  230. USFreePool(
  231. IN PVOID pvAddress
  232. );
  233. #else // ORIGINAL_POOLTRACK
  234. #define USAllocatePool(a, b) ExAllocatePoolWithTag(a, b, NAME_POOLTAG)
  235. #define USFreePool(a) ExFreePool(a)
  236. #endif // ORIGINAL_POOLTRACK
  237. NTSTATUS // in ioctl.c
  238. USDeviceControl(
  239. IN PDEVICE_OBJECT pDeviceObject,
  240. IN PIRP pIrp
  241. );
  242. NTSTATUS // in ioctl.c
  243. USReadWriteRegisters(
  244. IN PDEVICE_OBJECT pDeviceObject,
  245. IN PIO_BLOCK pIoBlock,
  246. IN BOOLEAN fRead,
  247. IN ULONG IoBlockSize
  248. );
  249. NTSTATUS // in ioctl.c
  250. USPassThruUSBRequest(
  251. IN PDEVICE_OBJECT pDeviceObject,
  252. IN PIO_BLOCK_EX pIoBlockEx,
  253. IN ULONG InLength,
  254. IN ULONG OutLength
  255. );
  256. NTSTATUS // in ioctl.c
  257. USPassThruUSBRequestPTP(
  258. IN PDEVICE_OBJECT pDeviceObject,
  259. IN PIO_BLOCK_EX pIoBlockEx,
  260. IN ULONG InLength,
  261. IN ULONG OutLength
  262. );
  263. NTSTATUS // in ioctl.c
  264. USCancelPipe(
  265. IN PDEVICE_OBJECT pDeviceObject,
  266. IN PIRP pIrp,
  267. IN PIPE_TYPE PipeType,
  268. IN BOOLEAN fAbort
  269. );
  270. NTSTATUS // in ioctl.c
  271. USAbortResetPipe(
  272. IN PDEVICE_OBJECT pDeviceObject,
  273. IN ULONG uIndex,
  274. IN BOOLEAN fAbort
  275. );
  276. NTSTATUS // in ocrw.c
  277. USOpen(
  278. IN PDEVICE_OBJECT pDeviceObject,
  279. IN PIRP pIrp
  280. );
  281. NTSTATUS // in ocrw.c
  282. USClose(
  283. IN PDEVICE_OBJECT pDeviceObject,
  284. IN PIRP pIrp
  285. );
  286. NTSTATUS // in ocrw.c
  287. USFlush(
  288. IN PDEVICE_OBJECT pDeviceObject,
  289. IN PIRP pIrp
  290. );
  291. NTSTATUS // in ocrw.c
  292. USRead(
  293. IN PDEVICE_OBJECT pDeviceObject,
  294. IN PIRP pIrp
  295. );
  296. NTSTATUS // in ocrw.c
  297. USWrite(
  298. IN PDEVICE_OBJECT pDeviceObject,
  299. IN PIRP pIrp
  300. );
  301. NTSTATUS // in ocrw.c
  302. USTransfer(
  303. IN PDEVICE_OBJECT pDeviceObject,
  304. IN PIRP pIrp,
  305. IN ULONG PipeIndex,
  306. IN PVOID pBuffer,
  307. IN PMDL pMdl,
  308. IN ULONG TransferSize,
  309. IN PULONG pTimeout
  310. );
  311. NTSTATUS // in ocrw.c
  312. USTransferComplete(
  313. IN PDEVICE_OBJECT pDeviceObject,
  314. IN PIRP pIrp,
  315. IN PTRANSFER_CONTEXT pTransferContext
  316. );
  317. VOID // in ocrw.c
  318. USCancelIrp(
  319. IN PDEVICE_OBJECT pDeviceObject,
  320. IN PIRP pIrp
  321. );
  322. NTSTATUS // in ocrw.c
  323. USEnqueueIrp(
  324. IN PDEVICE_OBJECT pDeviceObject,
  325. IN PUSBSCAN_PACKETS pPackets
  326. );
  327. PUSBSCAN_PACKETS // in ocrw.c
  328. USDequeueIrp(
  329. IN PDEVICE_OBJECT pDeviceObject,
  330. IN PIRP pIrp
  331. );
  332. VOID // in ocrw.c
  333. USWaitThread(
  334. IN PVOID pTransferContext
  335. );
  336. ULONG
  337. USGetPipeIndexToUse(
  338. IN PDEVICE_OBJECT pDeviceObject,
  339. IN PIRP pIrp,
  340. IN ULONG PipeIndex
  341. );
  342. VOID
  343. USTimerDpc(
  344. IN PKDPC pDpc,
  345. IN PVOID pIrp,
  346. IN PVOID SystemArgument1,
  347. IN PVOID SystemArgument2
  348. );
  349. NTSTATUS // in power.c
  350. USPower(
  351. IN PDEVICE_OBJECT pDeviceObject,
  352. IN PIRP pIrp
  353. );
  354. NTSTATUS // in power.c
  355. USPoRequestCompletion(
  356. IN PDEVICE_OBJECT pPdo,
  357. IN UCHAR MinorFunction,
  358. IN POWER_STATE PowerState,
  359. IN PDEVICE_OBJECT pDeviceObject,
  360. IN PIO_STATUS_BLOCK pIoStatus
  361. );
  362. USPowerIrpComplete( // in power.c
  363. IN PDEVICE_OBJECT pPdo,
  364. IN PIRP pIrp,
  365. IN PDEVICE_OBJECT pDeviceObject
  366. );
  367. NTSTATUS // in power.c
  368. USSetDevicePowerState(
  369. IN PDEVICE_OBJECT pDeviceObject,
  370. IN DEVICE_POWER_STATE DeviceState,
  371. IN PBOOLEAN pHookIt
  372. );
  373. NTSTATUS
  374. USCallNextDriverSynch(
  375. IN PUSBSCAN_DEVICE_EXTENSION pde,
  376. IN PIRP pIrp
  377. );
  378. NTSTATUS
  379. UsbScanHandleInterface(
  380. PDEVICE_OBJECT DeviceObject,
  381. PUNICODE_STRING InterfaceName,
  382. BOOLEAN Create
  383. );
  384. VOID
  385. UsbScanLogError(
  386. IN PDRIVER_OBJECT DriverObject,
  387. IN PDEVICE_OBJECT DeviceObject OPTIONAL,
  388. IN ULONG SequenceNumber,
  389. IN UCHAR MajorFunctionCode,
  390. IN UCHAR RetryCount,
  391. IN ULONG UniqueErrorValue,
  392. IN NTSTATUS FinalStatus,
  393. IN NTSTATUS SpecificIOStatus
  394. );