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.

303 lines
6.0 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 PCOMMON_DEVICE_EXTENSION Extension,
  162. IN PVOID SystemArgument1,
  163. IN PVOID SystemArgument2
  164. );
  165. VOID
  166. PrinterResubmitWrite(
  167. PDEVICE_OBJECT DeviceObject,
  168. PVOID Context
  169. );
  170. VOID
  171. PrinterCancel(
  172. PDEVICE_OBJECT DeviceObject,
  173. PIRP Irp
  174. );
  175. #define DEVICE_EXTENSION_SIZE sizeof(FUNCTIONAL_DEVICE_EXTENSION) + sizeof(PRINTER_DATA)
  176. #define PRINTER_TIMEOUT 100
  177. #define PRINTER_SRB_LIST_SIZE 4
  178. #define PRINTER_TAG 'tnrp'
  179. #define BLOCKED_WRITE_TIMEOUT 3 // seconds
  180. #define PORT_NUM_VALUE_NAME L"Port Number"
  181. #define BASE_PORT_NAME_VALUE_NAME L"Base Name"
  182. #define BASE_PORT_DESCRIPTION L"IEEE 1394 Printer Port"
  183. #define BASE_PORT_DESCRIPTION_VALUE_NAME L"Port Description"
  184. #define RECYCLABLE_VALUE_NAME L"Recyclable"
  185. #define BASE_1394_PORT_NAME L"1394_"
  186. #define BASE_SCSI_PORT_NAME L"SCSI"
  187. #define MAX_PRINT_XFER 0x00ffffff
  188. #define MAX_NUM_PRINTERS 20
  189. typedef struct _PRINTER_DATA {
  190. ULONG DeviceFlags;
  191. KSPIN_LOCK SplitRequestSpinLock;
  192. UNICODE_STRING UnicodeLinkName;
  193. UNICODE_STRING UnicodeDeviceString;
  194. UCHAR DeviceName[256];
  195. PUCHAR DeviceIdString;
  196. ULONG PortNumber;
  197. ULONG LptNumber;
  198. //
  199. // See comments in PrinterWriteComplete() for a description
  200. // of the following fields
  201. //
  202. PIO_COMPLETION_ROUTINE WriteCompletionRoutine;
  203. KTIMER Timer;
  204. LARGE_INTEGER DueTime;
  205. KDPC TimerDpc;
  206. PIRP WriteIrp;
  207. NTSTATUS LastWriteStatus;
  208. } PRINTER_DATA, *PPRINTER_DATA;
  209. static const GUID PNPPRINT_GUID =
  210. { 0x28d78fad, 0x5a12, 0x11d1, { 0xae, 0x5b, 0x0, 0x0, 0xf8, 0x3, 0xa8, 0xc2 } };
  211. //
  212. // Support for the following ioctl allows SCSIPRNT to behave like the
  213. // USB, etc printing stacks, to keep USBMON.DLL happy
  214. //
  215. // From ntos\dd\usbprint\ioctl.h & windows\spooler\monitors\dynamon\ioctl.h
  216. //
  217. #define USBPRINT_IOCTL_INDEX 0x0000
  218. #define IOCTL_USBPRINT_GET_LPT_STATUS CTL_CODE(FILE_DEVICE_UNKNOWN, \
  219. USBPRINT_IOCTL_INDEX+12, \
  220. METHOD_BUFFERED, \
  221. FILE_ANY_ACCESS)
  222. //
  223. // The following ioctl allows a smart client / port monitor to en/disable
  224. // the blocking write behavior on 1394 printers
  225. //
  226. #define SCSIPRNT_IOCTL_INDEX 0x123
  227. #define IOCTL_SCSIPRNT_1394_BLOCKING_WRITE CTL_CODE(FILE_DEVICE_UNKNOWN, \
  228. SCSIPRNT_IOCTL_INDEX, \
  229. METHOD_BUFFERED, \
  230. FILE_ANY_ACCESS)
  231. #endif