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.

359 lines
7.8 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. fakemodem.h
  5. Environment:
  6. Kernel mode
  7. --*/
  8. #define INITGUID
  9. #include <stddef.h>
  10. #include <stdarg.h>
  11. #include <stdio.h>
  12. #include <ntddk.h>
  13. #include <ntddser.h>
  14. #include <wmistr.h>
  15. #include <wmilib.h>
  16. #include <windef.h>
  17. #include <wmistr.h>
  18. #include <wdmguid.h>
  19. #include <string.h>
  20. #ifdef DEFINE_GUID
  21. DEFINE_GUID(GUID_CLASS_MODEM,0x2c7089aa, 0x2e0e,0x11d1,0xb1, 0x14, 0x00, 0xc0, 0x4f, 0xc2, 0xaa, 0xe4);
  22. #endif //DEFINE_GUID
  23. #define PNP_DEBUG 1
  24. #define ALLOCATE_PAGED_POOL(_y) ExAllocatePoolWithTag(PagedPool,_y,'wkaF')
  25. #define ALLOCATE_NONPAGED_POOL(_y) ExAllocatePoolWithTag(NonPagedPool,_y,'wkaF')
  26. #define FREE_POOL(_x) {ExFreePool(_x);_x=NULL;};
  27. #define DO_TYPE_PDO ' ODP'
  28. #define DO_TYPE_FDO ' ODF'
  29. #define DO_TYPE_DEL_PDO 'ODPx'
  30. #define DO_TYPE_DEL_FDO 'ODFx'
  31. #define DEVICE_OBJECT_NAME_LENGTH 128
  32. extern ULONG DebugFlags;
  33. #if DBG
  34. #define DEBUG_FLAG_ERROR 0x0001
  35. #define DEBUG_FLAG_INIT 0x0002
  36. #define DEBUG_FLAG_PNP 0x0004
  37. #define DEBUG_FLAG_POWER 0x0008
  38. #define DEBUG_FLAG_WMI 0x0010
  39. #define DEBUG_FLAG_TRACE 0x0020
  40. #define D_INIT(_x) if (DebugFlags & DEBUG_FLAG_INIT) {_x}
  41. #define D_PNP(_x) if (DebugFlags & DEBUG_FLAG_PNP) {_x}
  42. #define D_POWER(_x) if (DebugFlags & DEBUG_FLAG_POWER) {_x}
  43. #define D_TRACE(_x) if (DebugFlags & DEBUG_FLAG_TRACE) {_x}
  44. #define D_ERROR(_x) if (DebugFlags & DEBUG_FLAG_ERROR) {_x}
  45. #define D_WMI(_x) if (DebugFlags & DEBUG_FLAG_WMI) {_x}
  46. #else
  47. #define D_INIT(_x) {}
  48. #define D_PNP(_x) {}
  49. #define D_POWER(_x) {}
  50. #define D_TRACE(_x) {}
  51. #define D_ERROR(_x) {}
  52. #define D_WMI(_x) {}
  53. #endif
  54. #define OBJECT_DIRECTORY L"DosDevices"
  55. #define READ_BUFFER_SIZE 128
  56. #define COMMAND_MATCH_STATE_IDLE 0
  57. #define COMMAND_MATCH_STATE_GOT_A 1
  58. #define COMMAND_MATCH_STATE_GOT_T 2
  59. typedef struct _DEVICE_EXTENSION
  60. {
  61. ULONG DoType;
  62. KSPIN_LOCK SpinLock;
  63. PDEVICE_OBJECT DeviceObject;
  64. LONG ReferenceCount;
  65. UNICODE_STRING InterfaceNameString;
  66. ULONG OpenCount;
  67. BOOLEAN Removing;
  68. BOOLEAN Started;
  69. KEVENT RemoveEvent;
  70. LIST_ENTRY HoldList;
  71. LIST_ENTRY RestartList;
  72. KEVENT PdoStartEvent;
  73. KDPC ReadDpc;
  74. PIRP CurrentReadIrp;
  75. LIST_ENTRY ReadQueue;
  76. PIRP CurrentWriteIrp;
  77. LIST_ENTRY WriteQueue;
  78. PIRP CurrentMaskIrp;
  79. LIST_ENTRY MaskQueue;
  80. ULONG CurrentMask;
  81. PDEVICE_OBJECT Pdo;
  82. PDEVICE_OBJECT LowerDevice;
  83. SERIAL_TIMEOUTS CurrentTimeouts;
  84. ULONG ReadBufferBegin;
  85. ULONG ReadBufferEnd;
  86. ULONG BytesInReadBuffer;
  87. UCHAR CommandMatchState;
  88. BOOLEAN ConnectCommand;
  89. BOOLEAN IgnoreNextChar;
  90. BOOLEAN CapsQueried;
  91. ULONG ModemStatus;
  92. BOOLEAN CurrentlyConnected;
  93. BOOLEAN ConnectionStateChanged;
  94. UCHAR ReadBuffer[READ_BUFFER_SIZE];
  95. DEVICE_POWER_STATE SystemPowerStateMap[PowerSystemMaximum];
  96. SYSTEM_POWER_STATE SystemWake;
  97. DEVICE_POWER_STATE DeviceWake;
  98. BOOLEAN WakeOnRingEnabled;
  99. ERESOURCE OpenCloseResource;
  100. } DEVICE_EXTENSION, *PDEVICE_EXTENSION;
  101. extern UNICODE_STRING DriverEntryRegPath;
  102. #define RemoveReferenceForDispatch RemoveReference
  103. #define RemoveReferenceForIrp RemoveReference
  104. // Function prototypes
  105. NTSTATUS
  106. DriverEntry(
  107. IN PDRIVER_OBJECT DriverObject,
  108. IN PUNICODE_STRING RegistryPath
  109. );
  110. VOID
  111. FakeModemUnload(
  112. IN PDRIVER_OBJECT DriverObject
  113. );
  114. NTSTATUS
  115. FakeModemAddDevice(
  116. IN PDRIVER_OBJECT DriverObject,
  117. IN PDEVICE_OBJECT Pdo
  118. );
  119. NTSTATUS
  120. GetRegistryKeyValue (
  121. IN HANDLE Handle,
  122. IN PWCHAR KeyNameString,
  123. IN ULONG KeyNameStringLength,
  124. IN PVOID Data,
  125. IN ULONG DataLength
  126. );
  127. NTSTATUS
  128. FakeModemHandleSymbolicLink(
  129. PDEVICE_OBJECT Pdo,
  130. BOOLEAN Create,
  131. PUNICODE_STRING InterfaceName,
  132. PDEVICE_OBJECT Fdo
  133. );
  134. NTSTATUS
  135. QueryDeviceCaps(
  136. PDEVICE_OBJECT Pdo,
  137. PDEVICE_CAPABILITIES Capabilities
  138. );
  139. NTSTATUS
  140. ModemSetRegistryKeyValue(
  141. IN PDEVICE_OBJECT Pdo,
  142. IN ULONG DevInstKeyType,
  143. IN PWCHAR KeyNameString,
  144. IN ULONG DataType,
  145. IN PVOID Data,
  146. IN ULONG DataLength);
  147. NTSTATUS
  148. ModemGetRegistryKeyValue (
  149. IN PDEVICE_OBJECT Pdo,
  150. IN ULONG DevInstKeyType,
  151. IN PWCHAR KeyNameString,
  152. IN PVOID Data,
  153. IN ULONG DataLength
  154. );
  155. NTSTATUS
  156. FakeModemIoControl(
  157. IN PDEVICE_OBJECT DeviceObject,
  158. IN PIRP Irp
  159. );
  160. NTSTATUS
  161. FakeModemOpen(
  162. IN PDEVICE_OBJECT DeviceObject,
  163. IN PIRP Irp
  164. );
  165. NTSTATUS
  166. FakeModemClose(
  167. IN PDEVICE_OBJECT DeviceObject,
  168. IN PIRP Irp
  169. );
  170. NTSTATUS
  171. FakeModemCleanup(
  172. IN PDEVICE_OBJECT DeviceObject,
  173. IN PIRP Irp
  174. );
  175. void
  176. FakeModemKillPendingIrps(
  177. PDEVICE_OBJECT DeviceObject
  178. );
  179. NTSTATUS
  180. ForwardIrp(
  181. PDEVICE_OBJECT NextDevice,
  182. PIRP Irp
  183. );
  184. NTSTATUS
  185. FakeModemAdapterIoCompletion(
  186. IN PDEVICE_OBJECT DeviceObject,
  187. IN PIRP Irp,
  188. IN PKEVENT pdoIoCompletedEvent
  189. );
  190. NTSTATUS
  191. WaitForLowerDriverToCompleteIrp(
  192. PDEVICE_OBJECT TargetDeviceObject,
  193. PIRP Irp,
  194. PKEVENT Event
  195. );
  196. NTSTATUS
  197. FakeModemPnP(
  198. IN PDEVICE_OBJECT DeviceObject,
  199. IN PIRP Irp
  200. );
  201. NTSTATUS
  202. FakeModemDealWithResources(
  203. IN PDEVICE_OBJECT Fdo,
  204. IN PIRP Irp
  205. );
  206. VOID
  207. DevicePowerCompleteRoutine(
  208. PDEVICE_OBJECT DeviceObject,
  209. IN UCHAR MinorFunction,
  210. IN POWER_STATE PowerState,
  211. IN PVOID Context,
  212. IN PIO_STATUS_BLOCK IoStatus
  213. );
  214. NTSTATUS
  215. FakeModemPower(
  216. IN PDEVICE_OBJECT DeviceObject,
  217. IN PIRP Irp
  218. );
  219. NTSTATUS
  220. FakeModemRead(
  221. IN PDEVICE_OBJECT DeviceObject,
  222. IN PIRP Irp
  223. );
  224. NTSTATUS
  225. FakeModemWrite(
  226. IN PDEVICE_OBJECT DeviceObject,
  227. IN PIRP Irp
  228. );
  229. VOID
  230. WriteIrpWorker(
  231. IN PDEVICE_OBJECT DeviceObject
  232. );
  233. VOID
  234. ProcessWriteBytes(
  235. PDEVICE_EXTENSION DeviceExtension,
  236. PUCHAR Characters,
  237. ULONG Length
  238. );
  239. VOID
  240. PutCharInReadBuffer(
  241. PDEVICE_EXTENSION DeviceExtension,
  242. UCHAR Character
  243. );
  244. VOID
  245. ReadIrpWorker(
  246. PDEVICE_OBJECT DeviceObject
  247. );
  248. VOID
  249. TryToSatisfyRead(
  250. PDEVICE_EXTENSION DeviceExtension
  251. );
  252. VOID
  253. WriteCancelRoutine(
  254. IN PDEVICE_OBJECT DeviceObject,
  255. IN PIRP Irp
  256. );
  257. VOID
  258. ReadCancelRoutine(
  259. IN PDEVICE_OBJECT DeviceObject,
  260. IN PIRP Irp
  261. );
  262. VOID
  263. ProcessConnectionStateChange(
  264. IN PDEVICE_OBJECT DeviceObject
  265. );
  266. NTSTATUS
  267. CheckStateAndAddReference(
  268. PDEVICE_OBJECT DeviceObject,
  269. PIRP Irp
  270. );
  271. VOID
  272. RemoveReferenceAndCompleteRequest(
  273. PDEVICE_OBJECT DeviceObject,
  274. PIRP Irp,
  275. NTSTATUS StatusToReturn
  276. );
  277. VOID
  278. RemoveReference(
  279. PDEVICE_OBJECT DeviceObject
  280. );
  281. VOID
  282. FakeModemKillAllReadsOrWrites(
  283. IN PDEVICE_OBJECT DeviceObject,
  284. IN PLIST_ENTRY QueueToClean,
  285. IN PIRP *CurrentOpIrp
  286. );