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.

322 lines
5.3 KiB

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