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.

325 lines
5.8 KiB

  1. #define INITGUID
  2. #include <ntddk.h>
  3. #include <ntddser.h>
  4. #include <irenum.h>
  5. #include "queue.h"
  6. #include <ircommdbg.h>
  7. #include <vuart.h>
  8. #include <tdiobj.h>
  9. #define INPUT_BUFFER_SIZE (8092)
  10. typedef struct _READ_STATE {
  11. PACKET_QUEUE Queue;
  12. PIRP CurrentIrp;
  13. ULONG IrpRefCount;
  14. BOOLEAN IrpShouldBeCompleted;
  15. BOOLEAN IrpShouldBeCompletedWithAnyData;
  16. BOOLEAN RefusedDataIndication;
  17. KTIMER IntervalTimer;
  18. KDPC IntervalTimerDpc;
  19. BOOLEAN IntervalTimerSet;
  20. KTIMER TotalTimer;
  21. KDPC TotalTimerDpc;
  22. BOOLEAN TotalTimerSet;
  23. BOOLEAN DtrState;
  24. KSPIN_LOCK ReadLock;
  25. ULONG BytesInBuffer;
  26. PUCHAR NextFilledByte;
  27. PUCHAR NextEmptyByte;
  28. LONG BytesRead;
  29. ULONG IntervalTimeOut;
  30. UCHAR InputBuffer[INPUT_BUFFER_SIZE];
  31. } READ_STATE, *PREAD_STATE;
  32. typedef struct _WRITE_STATE {
  33. PACKET_QUEUE Queue;
  34. LONG BytesWritten;
  35. } WRITE_STATE, *PWRITE_STATE;
  36. typedef struct _MASK_STATE {
  37. PACKET_QUEUE Queue;
  38. ULONG CurrentMask;
  39. ULONG HistoryMask;
  40. PIRP CurrentWaitMaskIrp;
  41. KSPIN_LOCK Lock;
  42. } MASK_STATE, *PMASK_STATE;
  43. typedef struct _UART_STATE {
  44. PACKET_QUEUE Queue;
  45. } UART_STATE, *PUART_STATE;
  46. typedef struct _FDO_DEVICE_EXTENSION {
  47. PDEVICE_OBJECT DeviceObject;
  48. PDEVICE_OBJECT Pdo;
  49. PDEVICE_OBJECT LowerDevice;
  50. TDI_OBJECT_HANDLE TdiObjects;
  51. BOOLEAN Removing;
  52. BOOLEAN Removed;
  53. BOOLEAN OutgoingConnection;
  54. LONG OpenCount;
  55. IRDA_HANDLE ConnectionHandle;
  56. UNICODE_STRING InterfaceName;
  57. ULONG DeviceAddress;
  58. KSPIN_LOCK SpinLock;
  59. SERIAL_TIMEOUTS TimeOuts;
  60. SERIAL_QUEUE_SIZE QueueSizes;
  61. SERIAL_CHARS SerialChars;
  62. SERIAL_HANDFLOW HandFlow;
  63. ULONG MaxSendSize;
  64. WRITE_STATE Write;
  65. MASK_STATE Mask;
  66. UART_STATE Uart;
  67. READ_STATE Read;
  68. } FDO_DEVICE_EXTENSION, *PFDO_DEVICE_EXTENSION;
  69. #define READ_PURGE_CLEAR_BUFFER 0
  70. #define READ_PURGE_ABORT_IRP 1
  71. VOID
  72. WriteStartRoutine(
  73. PVOID Context,
  74. PIRP Irp
  75. );
  76. VOID
  77. MaskStartRoutine(
  78. PVOID Context,
  79. PIRP Irp
  80. );
  81. VOID
  82. UartStartRoutine(
  83. PVOID Context,
  84. PIRP Irp
  85. );
  86. NTSTATUS
  87. IrCommAddDevice(
  88. IN PDRIVER_OBJECT DriverObject,
  89. IN PDEVICE_OBJECT Pdo
  90. );
  91. NTSTATUS
  92. IrCommPnP(
  93. IN PDEVICE_OBJECT DeviceObject,
  94. IN PIRP Irp
  95. );
  96. NTSTATUS
  97. IrCommPower(
  98. IN PDEVICE_OBJECT DeviceObject,
  99. IN PIRP Irp
  100. );
  101. NTSTATUS
  102. IrCommWmi(
  103. IN PDEVICE_OBJECT DeviceObject,
  104. IN PIRP Irp
  105. );
  106. //
  107. // util fucntions
  108. //
  109. #define LEAVE_NEXT_AS_IS FALSE
  110. #define COPY_CURRENT_TO_NEXT TRUE
  111. NTSTATUS
  112. WaitForLowerDriverToCompleteIrp(
  113. PDEVICE_OBJECT TargetDeviceObject,
  114. PIRP Irp,
  115. BOOLEAN CopyCurrentToNext
  116. );
  117. NTSTATUS
  118. ForwardIrp(
  119. PDEVICE_OBJECT NextDevice,
  120. PIRP Irp
  121. );
  122. NTSTATUS
  123. GetRegistryKeyValue (
  124. IN PDEVICE_OBJECT Pdo,
  125. IN ULONG DevInstKeyType,
  126. IN PWCHAR KeyNameString,
  127. IN ULONG ExpectedRegType,
  128. IN PVOID Data,
  129. IN ULONG DataLength
  130. );
  131. NTSTATUS
  132. IrCommHandleSymbolicLink(
  133. PDEVICE_OBJECT Pdo,
  134. PUNICODE_STRING InterfaceName,
  135. BOOLEAN Create
  136. );
  137. NTSTATUS
  138. QueryPdoInformation(
  139. PDEVICE_OBJECT Pdo,
  140. ULONG InformationType,
  141. PVOID Buffer,
  142. ULONG BufferLength
  143. );
  144. VOID
  145. DumpBuffer(
  146. PUCHAR Data,
  147. ULONG Length
  148. );
  149. //
  150. // io dispatch
  151. //
  152. NTSTATUS
  153. IrCommCreate(
  154. PDEVICE_OBJECT DeviceObject,
  155. PIRP Irp
  156. );
  157. NTSTATUS
  158. IrCommClose(
  159. PDEVICE_OBJECT DeviceObject,
  160. PIRP Irp
  161. );
  162. NTSTATUS
  163. IrCommWrite(
  164. PDEVICE_OBJECT DeviceObject,
  165. PIRP Irp
  166. );
  167. NTSTATUS
  168. IrCommCleanup(
  169. PDEVICE_OBJECT DeviceObject,
  170. PIRP Irp
  171. );
  172. NTSTATUS
  173. IrCommQueryInformation(
  174. PDEVICE_OBJECT DeviceObject,
  175. PIRP Irp
  176. );
  177. NTSTATUS
  178. IrCommRead(
  179. PDEVICE_OBJECT DeviceObject,
  180. PIRP Irp
  181. );
  182. NTSTATUS
  183. IrCommDeviceControl(
  184. PDEVICE_OBJECT DeviceObject,
  185. PIRP Irp
  186. );
  187. NTSTATUS
  188. DataAvailibleHandler(
  189. PVOID Context,
  190. PUCHAR Buffer,
  191. ULONG BytesAvailible,
  192. PULONG BytesUsed
  193. );
  194. VOID
  195. ReadStartRoutine(
  196. PVOID Context,
  197. PIRP Irp
  198. );
  199. VOID
  200. IntervalTimeProc(
  201. PKDPC Dpc,
  202. PVOID Context,
  203. PVOID SystemParam1,
  204. PVOID SystemParam2
  205. );
  206. VOID
  207. TotalTimerProc(
  208. PKDPC Dpc,
  209. PVOID Context,
  210. PVOID SystemParam1,
  211. PVOID SystemParam2
  212. );
  213. VOID
  214. EventHandler(
  215. PVOID Context,
  216. UCHAR PI,
  217. UCHAR PL,
  218. PUCHAR PV
  219. );
  220. VOID
  221. ReadPurge(
  222. PFDO_DEVICE_EXTENSION DeviceExtension,
  223. ULONG Flags
  224. );
  225. VOID
  226. EventNotification(
  227. PFDO_DEVICE_EXTENSION DeviceExtension,
  228. ULONG SerialEvent
  229. );
  230. VOID
  231. CleanupIoRequests(
  232. PFDO_DEVICE_EXTENSION DeviceExtension
  233. );