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.

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