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.

309 lines
6.5 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1998 - 1999
  3. Module Name:
  4. prntpnp.c
  5. Abstract:
  6. printer class driver defines and functions decl.
  7. Author:
  8. George Chrysanthakopoulos (georgioc)
  9. Environment:
  10. kernel mode only
  11. Notes:
  12. Revision History:
  13. --*/
  14. #include "ntddk.h"
  15. #include "scsi.h"
  16. #include "classpnp.h"
  17. #ifndef _PRINTPNP_
  18. #define _PRINTPNP_
  19. #if DBG
  20. ULONG PrintDebugLevel;
  21. #define DEBUGPRINT1(_x_) {if (PrintDebugLevel >= 1) \
  22. KdPrint (_x_);}
  23. #define DEBUGPRINT2(_x_) {if (PrintDebugLevel >= 2) \
  24. KdPrint (_x_);}
  25. #define DEBUGPRINT3(_x_) {if (PrintDebugLevel >= 3) \
  26. KdPrint (_x_);}
  27. #define DEBUGPRINT4(_x_) {if (PrintDebugLevel >= 4) \
  28. KdPrint (_x_);}
  29. #else
  30. #define DEBUGPRINT1(_x_)
  31. #define DEBUGPRINT2(_x_)
  32. #define DEBUGPRINT3(_x_)
  33. #define DEBUGPRINT4(_x_)
  34. #endif
  35. NTSTATUS
  36. PrinterAddDevice(
  37. IN PDRIVER_OBJECT DriverObject,
  38. IN PDEVICE_OBJECT PhysicalDeviceObject
  39. );
  40. NTSTATUS
  41. PrinterEnumerateDevice(
  42. IN PDEVICE_OBJECT Fdo
  43. );
  44. NTSTATUS
  45. PrinterQueryId(
  46. IN PDEVICE_OBJECT Pdo,
  47. IN BUS_QUERY_ID_TYPE IdType,
  48. IN PUNICODE_STRING UnicodeIdString
  49. );
  50. NTSTATUS
  51. PrinterCompletionRoutine(
  52. IN PDEVICE_OBJECT DeviceObject,
  53. IN PIRP Irp,
  54. IN PKEVENT Event
  55. );
  56. NTSTATUS
  57. PrinterGetId
  58. (
  59. IN PUCHAR DeviceIdString,
  60. IN ULONG Type,
  61. OUT PUCHAR resultString,
  62. OUT PUCHAR descriptionString
  63. );
  64. NTSTATUS
  65. PrinterStopDevice(
  66. IN PDEVICE_OBJECT DeviceObject,
  67. IN UCHAR Type
  68. );
  69. NTSTATUS
  70. PrinterInitPdo(
  71. IN PDEVICE_OBJECT Pdo
  72. );
  73. NTSTATUS
  74. PrinterInitFdo(
  75. IN PDEVICE_OBJECT Fdo
  76. );
  77. VOID
  78. PrinterRegisterPort(
  79. IN PPHYSICAL_DEVICE_EXTENSION DeviceExtension
  80. );
  81. NTSTATUS
  82. PrinterStartPdo(
  83. IN PDEVICE_OBJECT Pdo
  84. );
  85. NTSTATUS
  86. PrinterQueryPnpCapabilities(
  87. IN PDEVICE_OBJECT DeviceObject,
  88. IN PDEVICE_CAPABILITIES Capabilities
  89. );
  90. NTSTATUS
  91. CreatePrinterDeviceObject(
  92. IN PDRIVER_OBJECT DriverObject,
  93. IN PDEVICE_OBJECT PhysicalDeviceObject,
  94. IN PULONG DeviceCount
  95. );
  96. NTSTATUS
  97. PrinterDeviceControl(
  98. IN PDEVICE_OBJECT DeviceObject,
  99. IN PIRP Irp
  100. );
  101. NTSTATUS
  102. PrinterStartDevice(
  103. IN PDEVICE_OBJECT Fdo
  104. );
  105. NTSTATUS
  106. PrinterCreatePdo(
  107. IN PDEVICE_OBJECT Fdo,
  108. OUT PDEVICE_OBJECT *Pdo
  109. );
  110. NTSTATUS
  111. PrinterRemoveDevice(
  112. IN PDEVICE_OBJECT DeviceObject,
  113. IN UCHAR Type
  114. );
  115. NTSTATUS
  116. PrinterSystemControl(
  117. PDEVICE_OBJECT Fdo,
  118. PIRP Irp
  119. );
  120. NTSTATUS
  121. PrinterPowerControl(
  122. PDEVICE_OBJECT Fdo,
  123. PIRP Irp
  124. );
  125. NTSTATUS
  126. PrinterOpenClose(
  127. IN PDEVICE_OBJECT DeviceObject,
  128. IN PIRP Irp
  129. );
  130. NTSTATUS
  131. PrinterReadWrite(
  132. IN PDEVICE_OBJECT DeviceObject,
  133. IN PIRP Irp
  134. );
  135. NTSTATUS
  136. PrinterIssueCommand(
  137. IN PDEVICE_OBJECT Fdo,
  138. IN UCHAR Scsiop
  139. );
  140. VOID
  141. SplitRequest(
  142. IN PDEVICE_OBJECT DeviceObject,
  143. IN PIRP Irp,
  144. IN ULONG MaximumBytes
  145. );
  146. NTSTATUS
  147. PrinterWriteComplete(
  148. IN PDEVICE_OBJECT Fdo,
  149. IN PIRP Irp,
  150. IN PVOID Context
  151. );
  152. VOID
  153. PrinterRetryRequest(
  154. PDEVICE_OBJECT DeviceObject,
  155. PIRP Irp,
  156. PSCSI_REQUEST_BLOCK Srb
  157. );
  158. VOID
  159. PrinterWriteTimeoutDpc(
  160. IN PKDPC Dpc,
  161. IN PVOID Context,
  162. IN PVOID SystemArgument1,
  163. IN PVOID SystemArgument2
  164. );
  165. VOID
  166. PrinterResubmitWrite(
  167. PDEVICE_OBJECT DeviceObject,
  168. PVOID Context
  169. );
  170. #define DEVICE_EXTENSION_SIZE sizeof(FUNCTIONAL_DEVICE_EXTENSION) + sizeof(PRINTER_DATA)
  171. #define PRINTER_TIMEOUT 100
  172. #define PRINTER_SRB_LIST_SIZE 4
  173. #define PRINTER_TAG 'tnrp'
  174. #define BLOCKED_WRITE_TIMEOUT 3 // seconds
  175. #define PORT_NUM_VALUE_NAME L"Port Number"
  176. #define BASE_PORT_NAME_VALUE_NAME L"Base Name"
  177. #define BASE_PORT_DESCRIPTION L"IEEE 1394 Printer Port"
  178. #define BASE_PORT_DESCRIPTION_VALUE_NAME L"Port Description"
  179. #define RECYCLABLE_VALUE_NAME L"Recyclable"
  180. #define BASE_1394_PORT_NAME L"1394_"
  181. #define BASE_SCSI_PORT_NAME L"SCSI"
  182. #define MAX_PRINT_XFER 0x00ffffff
  183. #define MAX_NUM_PRINTERS 20
  184. typedef struct _PRINTER_DATA {
  185. ULONG DeviceFlags;
  186. KSPIN_LOCK SplitRequestSpinLock;
  187. UNICODE_STRING UnicodeLinkName;
  188. UNICODE_STRING UnicodeDeviceString;
  189. UCHAR DeviceName[256];
  190. PUCHAR DeviceIdString;
  191. ULONG PortNumber;
  192. ULONG LptNumber;
  193. //
  194. // See comments in PrinterWriteComplete() for a description
  195. // of the following fields
  196. //
  197. PIO_COMPLETION_ROUTINE WriteCompletionRoutine;
  198. KTIMER Timer;
  199. LARGE_INTEGER DueTime;
  200. KDPC TimerDpc;
  201. /*
  202. * Queued write irp and associated srb.
  203. */
  204. PIRP WriteIrp;
  205. PSCSI_REQUEST_BLOCK WriteSrb;
  206. NTSTATUS LastWriteStatus;
  207. } PRINTER_DATA, *PPRINTER_DATA;
  208. static const GUID PNPPRINT_GUID =
  209. { 0x28d78fad, 0x5a12, 0x11d1, { 0xae, 0x5b, 0x0, 0x0, 0xf8, 0x3, 0xa8, 0xc2 } };
  210. //
  211. // Support for the following ioctl allows SCSIPRNT to behave like the
  212. // USB, etc printing stacks, to keep USBMON.DLL happy
  213. //
  214. // From ntos\dd\usbprint\ioctl.h & windows\spooler\monitors\dynamon\ioctl.h
  215. //
  216. #define USBPRINT_IOCTL_INDEX 0x0000
  217. #define IOCTL_USBPRINT_GET_LPT_STATUS CTL_CODE(FILE_DEVICE_UNKNOWN, \
  218. USBPRINT_IOCTL_INDEX+12, \
  219. METHOD_BUFFERED, \
  220. FILE_ANY_ACCESS)
  221. //
  222. // The following ioctl allows a smart client / port monitor to en/disable
  223. // the blocking write behavior on 1394 printers
  224. //
  225. #define SCSIPRNT_IOCTL_INDEX 0x123
  226. #define IOCTL_SCSIPRNT_1394_BLOCKING_WRITE CTL_CODE(FILE_DEVICE_UNKNOWN, \
  227. SCSIPRNT_IOCTL_INDEX, \
  228. METHOD_BUFFERED, \
  229. FILE_ANY_ACCESS)
  230. BOOLEAN SetWriteIrp(PPRINTER_DATA PrinterData, PIRP WriteIrp, PSCSI_REQUEST_BLOCK Srb);
  231. PIRP GetWriteIrp(PPRINTER_DATA PrinterData, PSCSI_REQUEST_BLOCK *Srb);
  232. #endif