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.

445 lines
8.7 KiB

  1. /*++
  2. Copyright (c) 1997-1998 Microsoft Corporation
  3. Module Name:
  4. USBPRINT.h
  5. Abstract:
  6. Environment:
  7. Kernel & user mode
  8. Revision History:
  9. 5-10-96 : created
  10. --*/
  11. #ifdef DRIVER
  12. extern int iGMessageLevel;
  13. #define BOOL CHAR
  14. #define TRUE 1
  15. #define FALSE 0
  16. #define MAX_ID_SIZE 1024
  17. #define ID_OVERHEAD 15 //this is enough for the 'USBPRINT' at the beginning of the ID, and the crc at the end
  18. #define MAX_NUM_PRINTERS 512
  19. #define USBP_TAG 0x50425355 /* "USBP" */
  20. #define FAILURE_TIMEOUT -10000 * 5000 // 5 seconds
  21. #define USBPRINT_NAME_MAX 64
  22. #define USB_BASE_NAME L"USB"
  23. #define DEVICE_CAPABILITY_VERSION 1
  24. //
  25. // we support up to 10 pipe handles
  26. //
  27. #define USBPRINT_MAX_PIPES 10
  28. //
  29. // defines used for ISO test
  30. //
  31. #define USBPRINT_MAX_IRP 2
  32. #define USBPRINT_NUM_ISO_PACKETS_PER_REQUEST 32
  33. #define USBPRINT_MAX_STREAM_PACKET 8
  34. #define PORT_NUM_VALUE_NAME L"Port Number"
  35. #define PORT_BASE_NAME L"Base Name"
  36. #define USBPRINT_STREAM_TIMEOUT_INTERVAL 100
  37. // {28D78FAD-5A12-11d1-AE5B-0000F803A8C2}
  38. static const GUID USBPRINT_GUID =
  39. { 0x28d78fad, 0x5a12, 0x11d1, { 0xae, 0x5b, 0x0, 0x0, 0xf8, 0x3, 0xa8, 0xc2 } };
  40. /*typedef struct _USBPRINT_PIPE { we don't use this struct anymore. Just use PUSBD_PIPE_INFORMATION directly
  41. BOOLEAN Opened;
  42. UCHAR Pad[3];
  43. PUSBD_PIPE_INFORMATION PipeInfo;
  44. WCHAR Name[USBPRINT_NAME_MAX];
  45. LARGE_INTEGER BytesXfered;
  46. LARGE_INTEGER ElapsedTime;
  47. LARGE_INTEGER TimerStart;
  48. LARGE_INTEGER ElapsedCycles;
  49. LARGE_INTEGER CyclesStart;
  50. BOOLEAN bPerfTimerEnabled; //yy Bunch of perf fields here. remove them
  51. } USBPRINT_PIPE, *PUSBPRINT_PIPE; */
  52. typedef struct _USBPRINT_RW_CONTEXT {
  53. PURB Urb;
  54. BOOLEAN IsWrite;
  55. PDEVICE_OBJECT DeviceObject;
  56. } USBPRINT_RW_CONTEXT, *PUSBPRINT_RW_CONTEXT;
  57. #define MAX_INTERFACE 2
  58. // 999 is limit of USBMON's scope due to USB_XXX port name format.
  59. #define MAX_PORT_NUMBER 999
  60. // USB_001 is the lowest port number available.
  61. #define MIN_PORT_NUMBER 1
  62. //
  63. // Structure representing blocks of unallocated ports.
  64. //
  65. typedef struct _FREE_PORTS
  66. {
  67. ULONG iBottomOfRange; // The bottom free port number in this block.
  68. ULONG iTopOfRange; // The top free port number in this block.
  69. struct _FREE_PORTS * pNextBlock; // Pointer to the next block pf free ports.
  70. } FREE_PORTS, *PFREE_PORTS;
  71. typedef struct _DEVICE_EXTENSION {
  72. BOOLEAN IsChildDevice;
  73. // Device object we call when submitting Urbs
  74. PDEVICE_OBJECT TopOfStackDeviceObject;
  75. PDEVICE_OBJECT PhysicalDeviceObject;
  76. PDEVICE_OBJECT ChildDevice;
  77. BOOL bChildDeviceHere;
  78. UCHAR DeviceIdString[MAX_ID_SIZE];
  79. BOOLEAN bBadDeviceID;
  80. KSPIN_LOCK WakeSpinLock;
  81. BOOLEAN bD0IrpPending;
  82. DEVICE_POWER_STATE CurrentDevicePowerState;
  83. // configuration handle for the configuration the
  84. // device is currently in
  85. USBD_CONFIGURATION_HANDLE ConfigurationHandle;
  86. // ptr to the USB device descriptor
  87. // for this device
  88. PUSB_DEVICE_DESCRIPTOR DeviceDescriptor;
  89. // we support one interface
  90. // this is a copy of the info structure
  91. // returned from select_configuration or
  92. // select_interface
  93. PUSBD_INTERFACE_INFORMATION Interface;
  94. DEVICE_CAPABILITIES DeviceCapabilities;
  95. BOOLEAN bReadSupported;
  96. PIRP PowerIrp;
  97. KEVENT RemoveEvent;
  98. ULONG PendingIoCount;
  99. // Name buffer for our named Functional device object link
  100. WCHAR DeviceLinkNameBuffer[USBPRINT_NAME_MAX];
  101. BOOLEAN AcceptingRequests;
  102. UCHAR Pad[3];
  103. PUSBD_PIPE_INFORMATION pWritePipe;
  104. PUSBD_PIPE_INFORMATION pReadPipe;
  105. BOOL bReadPipeExists;
  106. UNICODE_STRING DeviceLinkName;
  107. ULONG ulInstanceNumber;
  108. ULONG OpenCnt;
  109. HANDLE hInterfaceKey;
  110. LONG ResetWorkItemPending;
  111. // selective suspend support
  112. PIRP PendingIdleIrp;
  113. PUSB_IDLE_CALLBACK_INFO IdleCallbackInfo;
  114. DEVICE_POWER_STATE DeviceWake;
  115. } DEVICE_EXTENSION, *PDEVICE_EXTENSION;
  116. typedef struct _CHILD_DEVICE_EXTENSION
  117. {
  118. BOOLEAN IsChildDevice;
  119. PDEVICE_OBJECT ParentDeviceObject;
  120. ULONG ulInstanceNumber;
  121. } CHILD_DEVICE_EXTENSION, *PCHILD_DEVICE_EXTENSION;
  122. typedef struct _USBPRINT_TRANSFER_OBJECT {
  123. struct _USBPRINT_STREAM_OBJECT *StreamObject;
  124. PIRP Irp;
  125. PURB Urb;
  126. PUCHAR DataBuffer;
  127. } USBPRINT_TRANSFER_OBJECT, *PUSBPRINT_TRANSFER_OBJECT;
  128. typedef struct _USBPRINT_STREAM_OBJECT {
  129. PDEVICE_OBJECT DeviceObject;
  130. ULONG PendingIrps;
  131. PIRP StopIrp;
  132. PUSBPRINT_TRANSFER_OBJECT TransferObjectList[USBPRINT_MAX_IRP];
  133. PUSBD_PIPE_INFORMATION PipeInfo;
  134. KDPC TimeoutDpc;
  135. KTIMER TimeoutTimer;
  136. BOOLEAN EnableTimeoutDPC;
  137. BOOLEAN StreamError;
  138. } USBPRINT_STREAM_OBJECT, *PUSBPRINT_STREAM_OBJECT;
  139. typedef struct _USBPRINT_WORKITEM_CONTEXT
  140. {
  141. PIO_WORKITEM ioWorkItem;
  142. PDEVICE_OBJECT deviceObject;
  143. PUSBD_PIPE_INFORMATION pPipeInfo;
  144. PIRP irp;
  145. } USBPRINT_WORKITEM_CONTEXT,*PUSBPRINT_WORKITEM_CONTEXT;
  146. #if DBG
  147. #define USBPRINT_KdPrint_old(_x_) \
  148. {\
  149. DbgPrint _x_ ;\
  150. DbgPrint("Old USBPRINT\n");\
  151. }
  152. #define USBPRINT_KdPrint0(_x_) \
  153. { \
  154. if(iGMessageLevel>=0) \
  155. DbgPrint _x_; \
  156. }
  157. #define USBPRINT_KdPrint1(_x_) \
  158. { \
  159. if(iGMessageLevel>=1) \
  160. DbgPrint _x_; \
  161. }
  162. #define USBPRINT_KdPrint2(_x_) \
  163. { \
  164. if(iGMessageLevel>=2) \
  165. DbgPrint _x_; \
  166. }
  167. #define USBPRINT_KdPrint3(_x_) \
  168. { \
  169. if(iGMessageLevel>=3) \
  170. DbgPrint _x_; \
  171. }
  172. #ifdef NTKERN
  173. #define TRAP() _asm {int 3}
  174. #else
  175. #define TRAP() DbgBreakPoint()
  176. #endif
  177. #else
  178. #define USBPRINT_KdPrint_old(_x_)
  179. #define USBPRINT_KdPrint0(_x_)
  180. #define USBPRINT_KdPrint1(_x_)
  181. #define USBPRINT_KdPrint2(_x_)
  182. #define USBPRINT_KdPrint3(_x_)
  183. #define USBPRINT_KdPrint4(_x_)
  184. #define TRAP()
  185. #endif
  186. NTSTATUS
  187. USBPRINT_Dispatch(
  188. IN PDEVICE_OBJECT DeviceObject,
  189. IN PIRP Irp
  190. );
  191. VOID
  192. USBPRINT_Unload(
  193. IN PDRIVER_OBJECT DriverObject
  194. );
  195. NTSTATUS
  196. USBPRINT_StartDevice(
  197. IN PDEVICE_OBJECT DeviceObject
  198. );
  199. NTSTATUS
  200. USBPRINT_StopDevice(
  201. IN PDEVICE_OBJECT DeviceObject
  202. );
  203. NTSTATUS
  204. USBPRINT_RemoveDevice(
  205. IN PDEVICE_OBJECT DeviceObject
  206. );
  207. NTSTATUS
  208. USBPRINT_CallUSBD(
  209. IN PDEVICE_OBJECT DeviceObject,
  210. IN PURB Urb,
  211. IN PLARGE_INTEGER pTimeout
  212. );
  213. NTSTATUS
  214. USBPRINT_PnPAddDevice(
  215. IN PDRIVER_OBJECT DriverObject,
  216. IN PDEVICE_OBJECT PhysicalDeviceObject
  217. );
  218. NTSTATUS
  219. USBPRINT_CreateDeviceObject(
  220. IN PDRIVER_OBJECT DriverObject,
  221. IN PDEVICE_OBJECT *DeviceObject
  222. );
  223. NTSTATUS
  224. USBPRINT_ConfigureDevice(
  225. IN PDEVICE_OBJECT DeviceObject
  226. );
  227. NTSTATUS
  228. USBPRINT_Write(
  229. IN PDEVICE_OBJECT DeviceObject,
  230. IN PIRP Irp
  231. );
  232. NTSTATUS
  233. USBPRINT_Create(
  234. IN PDEVICE_OBJECT DeviceObject,
  235. IN PIRP Irp
  236. );
  237. NTSTATUS
  238. USBPRINT_Read(
  239. IN PDEVICE_OBJECT DeviceObject,
  240. IN PIRP Irp
  241. );
  242. NTSTATUS
  243. USBPRINT_ProcessIOCTL(
  244. IN PDEVICE_OBJECT DeviceObject,
  245. IN PIRP Irp
  246. );
  247. NTSTATUS
  248. USBPRINT_SelectInterface(
  249. IN PDEVICE_OBJECT DeviceObject,
  250. IN PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor
  251. );
  252. PUSB_CONFIGURATION_DESCRIPTOR
  253. USBPRINT_GetConfigDescriptor(
  254. IN PDEVICE_OBJECT DeviceObject
  255. );
  256. NTSTATUS
  257. USBPRINT_BuildPipeList(
  258. IN PDEVICE_OBJECT DeviceObject
  259. );
  260. NTSTATUS
  261. USBPRINT_Close(
  262. IN PDEVICE_OBJECT DeviceObject,
  263. IN PIRP Irp
  264. );
  265. NTSTATUS
  266. USBPRINT_ResetPipe(
  267. IN PDEVICE_OBJECT DeviceObject,
  268. IN PUSBD_PIPE_INFORMATION Pipe,
  269. IN BOOLEAN IsoClearStall
  270. );
  271. NTSTATUS
  272. USBPRINT_StopIsoStream(
  273. IN PDEVICE_OBJECT DeviceObject,
  274. IN PUSBPRINT_STREAM_OBJECT StreamObject,
  275. IN PIRP Irp
  276. );
  277. NTSTATUS
  278. USBPRINT_StartIsoStream(
  279. IN PDEVICE_OBJECT DeviceObject,
  280. IN PUSBD_PIPE_INFORMATION PipeInfo,
  281. IN PIRP Irp
  282. );
  283. NTSTATUS
  284. USBPRINT_IsoIrp_Complete(
  285. IN PDEVICE_OBJECT DeviceObject,
  286. IN PIRP Irp,
  287. IN PVOID Context
  288. );
  289. VOID
  290. USBPRINT_IncrementIoCount(
  291. IN PDEVICE_OBJECT DeviceObject
  292. );
  293. LONG
  294. USBPRINT_DecrementIoCount(
  295. IN PDEVICE_OBJECT DeviceObject
  296. );
  297. NTSTATUS
  298. USBPRINT_ReconfigureDevice(
  299. IN PDEVICE_OBJECT DeviceObject
  300. );
  301. NTSTATUS
  302. USBPRINT_ProcessPowerIrp(
  303. IN PDEVICE_OBJECT DeviceObject,
  304. IN PIRP Irp
  305. );
  306. int
  307. USBPRINT_Get1284Id(
  308. IN PDEVICE_OBJECT DeviceObject,
  309. PVOID pIoBuffer,int iLen
  310. );
  311. NTSTATUS USBPRINT_ResetWorkItem(IN PDEVICE_OBJECT deviceObject, IN PVOID Context);
  312. NTSTATUS USBPRINT_AbortPendingRequests(PDEVICE_OBJECT DeviceObject);
  313. NTSTATUS USBPRINT_GetPhysicalUSBPortStatus(PDEVICE_OBJECT DeviceObject,ULONG *PortStatus);
  314. VOID
  315. USBPRINT_FdoIdleNotificationCallback(IN PDEVICE_EXTENSION DevExt);
  316. NTSTATUS
  317. USBPRINT_FdoIdleNotificationRequestComplete(
  318. PDEVICE_OBJECT DeviceObject,
  319. PIRP Irp,
  320. PDEVICE_EXTENSION DevExt
  321. );
  322. NTSTATUS
  323. USBPRINT_FdoSubmitIdleRequestIrp(IN PDEVICE_EXTENSION DevExt);
  324. VOID
  325. USBPRINT_FdoRequestWake(IN PDEVICE_EXTENSION DevExt);
  326. #endif