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.

599 lines
14 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. serenum.h
  5. Abstract:
  6. This module contains the common private declarations for the serial port
  7. enumerator.
  8. @@BEGIN_DDKSPLIT
  9. Author:
  10. Jay Senior
  11. @@END_DDKSPLIT
  12. Environment:
  13. kernel mode only
  14. Notes:
  15. Revision History:
  16. --*/
  17. #ifndef SERENUM_H
  18. #define SERENUM_H
  19. #define SERENUM_QDR_LOCK 0x00000001
  20. #define SERENUM_OPEN_LOCK 0x00000002
  21. #define SERENUM_POWER_LOCK 0x00000004
  22. #define SERENUM_STOP_LOCK 0x00000008
  23. #define SERENUM_EXPOSE_LOCK 0x00000010
  24. //#define SERENUM_COMPATIBLE_IDS L"SerialPort\\SerialDevice\0\0"
  25. //#define SERENUM_COMPATIBLE_IDS_LENGTH 25 // NB wide characters.
  26. #define SERENUM_INSTANCE_IDS L"0000"
  27. #define SERENUM_INSTANCE_IDS_LENGTH 5
  28. //
  29. // Default wait between line state changes in pnp enum protocol
  30. //
  31. #define SERENUM_DEFAULT_WAIT 2000000
  32. //
  33. // Timeout to read data from a serial port (in ms)
  34. //
  35. #define SERENUM_SERIAL_READ_TIME 240
  36. //#define SERENUM_INSTANCE_ID_BASE L"Serenum\\Inst_000"
  37. //#define SERENUM_INSTANCE_ID_BASE_LENGTH 12
  38. //#define SERENUM_INSTANCE_ID_BASE_PORT_INDEX 10
  39. #define SERENUM_PDO_NAME_BASE L"\\Serial\\"
  40. #define SERENUM_POOL_TAG (ULONG)'mneS'
  41. #undef ExAllocatePool
  42. #define ExAllocatePool(type, size) \
  43. ExAllocatePoolWithTag(type, size, SERENUM_POOL_TAG)
  44. #pragma warning(error:4100) // Unreferenced formal parameter
  45. #pragma warning(error:4705) // Statement has no effect
  46. //
  47. // Debugging Output Levels
  48. //
  49. #define SER_DBG_STARTUP_SHUTDOWN_MASK 0x0000000F
  50. #define SER_DBG_SS_NOISE 0x00000001
  51. #define SER_DBG_SS_TRACE 0x00000002
  52. #define SER_DBG_SS_INFO 0x00000004
  53. #define SER_DBG_SS_ERROR 0x00000008
  54. #define SER_DBG_PNP_MASK 0x000000F0
  55. #define SER_DBG_PNP_NOISE 0x00000010
  56. #define SER_DBG_PNP_TRACE 0x00000020
  57. #define SER_DBG_PNP_INFO 0x00000040
  58. #define SER_DBG_PNP_ERROR 0x00000080
  59. #define SER_DBG_PNP_DUMP_PACKET 0x00000100
  60. #define SER_DEFAULT_DEBUG_OUTPUT_LEVEL 0
  61. #if DBG
  62. #define Serenum_KdPrint(_d_,_l_, _x_) \
  63. if ((_d_)->DebugLevel & (_l_)) { \
  64. DbgPrint ("SerEnum.SYS: "); \
  65. DbgPrint _x_; \
  66. }
  67. //#define Serenum_KdPrint_Cont(_d_,_l_, _x_) \
  68. // if ((_d_)->DebugLevel & (_l_)) { \
  69. // DbgPrint _x_; \
  70. // }
  71. #define Serenum_KdPrint_Def(_l_, _x_) \
  72. if (SER_DEFAULT_DEBUG_OUTPUT_LEVEL & (_l_)) { \
  73. DbgPrint ("SerEnum.SYS: "); \
  74. DbgPrint _x_; \
  75. }
  76. #define TRAP() DbgBreakPoint()
  77. #define DbgRaiseIrql(_x_,_y_) KeRaiseIrql(_x_,_y_)
  78. #define DbgLowerIrql(_x_) KeLowerIrql(_x_)
  79. #else
  80. #define Serenum_KdPrint(_d_, _l_, _x_)
  81. #define Serenum_KdPrint_Cont(_d_, _l_, _x_)
  82. #define Serenum_KdPrint_Def(_l_, _x_)
  83. #define TRAP()
  84. #define DbgRaiseIrql(_x_,_y_)
  85. #define DbgLowerIrql(_x_)
  86. #endif
  87. #if !defined(MIN)
  88. #define MIN(_A_,_B_) (((_A_) < (_B_)) ? (_A_) : (_B_))
  89. #endif
  90. //
  91. // A common header for the device extensions of the PDOs and FDO
  92. //
  93. typedef struct _COMMON_DEVICE_DATA
  94. {
  95. PDEVICE_OBJECT Self;
  96. // A backpointer to the device object for which this is the extension
  97. BOOLEAN IsFDO;
  98. // Are we currently in a query power state?
  99. BOOLEAN Removed;
  100. // Has this device been removed? Should we fail any requests?
  101. ULONG DebugLevel;
  102. SYSTEM_POWER_STATE SystemState;
  103. DEVICE_POWER_STATE DeviceState;
  104. } COMMON_DEVICE_DATA, *PCOMMON_DEVICE_DATA;
  105. //
  106. // The device extension for the PDOs.
  107. // That is the serial ports of which this bus driver enumerates.
  108. // (IE there is a PDO for the 201 serial port).
  109. //
  110. typedef struct _PDO_DEVICE_DATA
  111. {
  112. COMMON_DEVICE_DATA;
  113. PDEVICE_OBJECT ParentFdo;
  114. // A back pointer to the bus
  115. UNICODE_STRING HardwareIDs;
  116. // Either in the form of bus\device
  117. // or *PNPXXXX - meaning root enumerated
  118. UNICODE_STRING CompIDs;
  119. // compatible ids to the hardware id
  120. UNICODE_STRING DeviceIDs;
  121. // Format: bus\device
  122. //
  123. // Text describing device
  124. //
  125. UNICODE_STRING DevDesc;
  126. UNICODE_STRING SerialNo;
  127. UNICODE_STRING PnPRev;
  128. BOOLEAN Started;
  129. BOOLEAN Attached;
  130. // When a device (PDO) is found on a bus and presented as a device relation
  131. // to the PlugPlay system, Attached is set to TRUE, and Removed to FALSE.
  132. // When the bus driver determines that this PDO is no longer valid, because
  133. // the device has gone away, it informs the PlugPlay system of the new
  134. // device relastions, but it does not delete the device object at that time.
  135. // The PDO is deleted only when the PlugPlay system has sent a remove IRP,
  136. // and there is no longer a device on the bus.
  137. //
  138. // If the PlugPlay system sends a remove IRP then the Removed field is set
  139. // to true, and all client (non PlugPlay system) accesses are failed.
  140. // If the device is removed from the bus Attached is set to FALSE.
  141. //
  142. // During a query relations Irp Minor call, only the PDOs that are
  143. // attached to the bus (and all that are attached to the bus) are returned
  144. // (even if they have been removed).
  145. //
  146. // During a remove device Irp Minor call, if and only if, attached is set
  147. // to FALSE, the PDO is deleted.
  148. //
  149. } PDO_DEVICE_DATA, *PPDO_DEVICE_DATA;
  150. //
  151. // The device extension of the bus itself. From whence the PDO's are born.
  152. //
  153. typedef struct _FDO_DEVICE_DATA
  154. {
  155. COMMON_DEVICE_DATA;
  156. UCHAR PdoIndex;
  157. // A number to keep track of the Pdo we're allocating.
  158. // Increment every time we create a new PDO. It's ok that it wraps.
  159. BOOLEAN Started;
  160. // Are we on, have resources, etc?
  161. BOOLEAN NumPDOs;
  162. // The PDOs currently enumerated.
  163. BOOLEAN NewNumPDOs;
  164. BOOLEAN NewPDOForcedRemove;
  165. BOOLEAN PDOForcedRemove;
  166. // Was the last PDO removed by force using the internal ioctl?
  167. // If so, when the next Query Device Relations is called, return only the
  168. // currently enumerated pdos
  169. //
  170. // Our child PDO; we're hoping he will be a doctor someday
  171. //
  172. PDEVICE_OBJECT AttachedPDO;
  173. //
  174. // The new PDO after we've done enumeration
  175. //
  176. PDEVICE_OBJECT NewPDO;
  177. PPDO_DEVICE_DATA PdoData;
  178. PPDO_DEVICE_DATA NewPdoData;
  179. PDEVICE_OBJECT UnderlyingPDO;
  180. PDEVICE_OBJECT TopOfStack;
  181. // the underlying bus PDO and the actual device object to which our
  182. // FDO is attached
  183. ULONG OutstandingIO;
  184. // the number of IRPs sent from the bus to the underlying device object
  185. KEVENT RemoveEvent;
  186. // On remove device plugplay request we must wait until all outstanding
  187. // requests have been completed before we can actually delete the device
  188. // object.
  189. UNICODE_STRING DevClassAssocName;
  190. // The name returned from IoRegisterDeviceClass Association,
  191. // which is used as a handle for IoSetDev... and friends.
  192. SYSTEM_POWER_STATE SystemWake;
  193. DEVICE_POWER_STATE DeviceWake;
  194. KSEMAPHORE CreateSemaphore;
  195. PRKSEMAPHORE PCreateSemaphore;
  196. //
  197. // How many times we should skip enumerating devices
  198. // after our stack is built
  199. //
  200. ULONG SkipEnumerations;
  201. //
  202. // Spinlock to protect enumerations
  203. //
  204. KSPIN_LOCK EnumerationLock;
  205. //
  206. // Flags containing state of enumeration
  207. //
  208. ULONG EnumFlags;
  209. //
  210. // Pointer to protocol thread object
  211. //
  212. PVOID ThreadObj;
  213. //
  214. // Pointer to work item to clean up thread ref
  215. //
  216. PIO_WORKITEM EnumWorkItem;
  217. //
  218. // Status of last thread create or STATUS_UNSUCCESSFUL if just not pending
  219. //
  220. NTSTATUS ProtocolThreadStatus;
  221. //
  222. // Count of running protocol threads
  223. //
  224. LONG ProtocolThreadCount;
  225. } FDO_DEVICE_DATA, *PFDO_DEVICE_DATA;
  226. typedef struct _SERENUM_RELEASE_CONTEXT {
  227. PVOID ThreadObject;
  228. PIO_WORKITEM WorkItem;
  229. } SERENUM_RELEASE_CONTEXT, *PSERENUM_RELEASE_CONTEXT;
  230. #define SERENUM_ENUMFLAG_CLEAN 0x0L
  231. #define SERENUM_ENUMFLAG_PENDING 0x1L
  232. #define SERENUM_ENUMFLAG_DIRTY 0x2L
  233. #define SERENUM_ENUMFLAG_REMOVED 0x4L
  234. //
  235. // Free the buffer associated with a Unicode string
  236. // and re-init it to NULL
  237. //
  238. #define SerenumFreeUnicodeString(PStr) \
  239. { \
  240. if ((PStr)->Buffer != NULL) { \
  241. ExFreePool((PStr)->Buffer); \
  242. } \
  243. RtlInitUnicodeString((PStr), NULL); \
  244. }
  245. //
  246. // Prototypes
  247. //
  248. NTSTATUS
  249. Serenum_CreateClose (
  250. IN PDEVICE_OBJECT DeviceObject,
  251. IN PIRP Irp
  252. );
  253. NTSTATUS
  254. Serenum_IoCtl (
  255. IN PDEVICE_OBJECT DeviceObject,
  256. IN PIRP Irp
  257. );
  258. NTSTATUS
  259. Serenum_InternIoCtl (
  260. IN PDEVICE_OBJECT DeviceObject,
  261. IN PIRP Irp
  262. );
  263. VOID
  264. Serenum_DriverUnload (
  265. IN PDRIVER_OBJECT DriverObject
  266. );
  267. NTSTATUS
  268. Serenum_PnP (
  269. IN PDEVICE_OBJECT DeviceObject,
  270. IN PIRP Irp
  271. );
  272. NTSTATUS
  273. Serenum_Power (
  274. IN PDEVICE_OBJECT DeviceObject,
  275. IN PIRP Irp
  276. );
  277. NTSTATUS
  278. Serenum_AddDevice(
  279. IN PDRIVER_OBJECT DriverObject,
  280. IN PDEVICE_OBJECT BusDeviceObject
  281. );
  282. NTSTATUS
  283. Serenum_PnPRemove (
  284. PDEVICE_OBJECT Device,
  285. PPDO_DEVICE_DATA PdoData
  286. );
  287. NTSTATUS
  288. Serenum_FDO_PnP (
  289. IN PDEVICE_OBJECT DeviceObject,
  290. IN PIRP Irp,
  291. IN PIO_STACK_LOCATION IrpStack,
  292. IN PFDO_DEVICE_DATA DeviceData
  293. );
  294. NTSTATUS
  295. Serenum_PDO_PnP (
  296. IN PDEVICE_OBJECT DeviceObject,
  297. IN PIRP Irp,
  298. IN PIO_STACK_LOCATION IrpStack,
  299. IN PPDO_DEVICE_DATA DeviceData
  300. );
  301. NTSTATUS
  302. Serenum_IncIoCount (
  303. PFDO_DEVICE_DATA Data
  304. );
  305. VOID
  306. Serenum_DecIoCount (
  307. PFDO_DEVICE_DATA Data
  308. );
  309. NTSTATUS
  310. Serenum_DispatchPassThrough(
  311. IN PDEVICE_OBJECT DeviceObject,
  312. IN PIRP Irp
  313. );
  314. NTSTATUS
  315. Serenum_ReenumerateDevices(
  316. IN PIRP Irp,
  317. IN PFDO_DEVICE_DATA DeviceData,
  318. IN PBOOLEAN PSameDevice
  319. );
  320. NTSTATUS
  321. Serenum_EnumComplete (
  322. IN PDEVICE_OBJECT DeviceObject,
  323. IN PIRP Irp,
  324. IN PVOID Context
  325. );
  326. NTSTATUS
  327. Serenum_InitMultiString(PFDO_DEVICE_DATA FdoData, PUNICODE_STRING MultiString,
  328. ...);
  329. int
  330. Serenum_GetDevOtherID(
  331. PCHAR input,
  332. PCHAR output
  333. );
  334. NTSTATUS
  335. Serenum_GetDevPnPRev(
  336. PFDO_DEVICE_DATA FdoData,
  337. PCHAR input,
  338. PCHAR output,
  339. int *start) ;
  340. void Serenum_GetDevName(
  341. PCHAR input,
  342. PCHAR output,
  343. int *start);
  344. void Serenum_GetDevSerialNo(
  345. PCHAR input,
  346. PCHAR output,
  347. int *start);
  348. void Serenum_GetDevClass(
  349. PCHAR input,
  350. PCHAR output,
  351. int *start);
  352. void Serenum_GetDevCompId(
  353. PCHAR input,
  354. PCHAR output,
  355. int *start);
  356. void Serenum_GetDevDesc(
  357. PCHAR input,
  358. PCHAR output,
  359. int *start);
  360. NTSTATUS
  361. Serenum_ParseData(PFDO_DEVICE_DATA FdoData, PCHAR ReadBuffer, ULONG BufferLen,
  362. PUNICODE_STRING hardwareIDs, PUNICODE_STRING compIDs,
  363. PUNICODE_STRING deviceIDs, PUNICODE_STRING PDeviceDesc,
  364. PUNICODE_STRING serialNo, PUNICODE_STRING pnpRev);
  365. NTSTATUS
  366. Serenum_ReadSerialPort(OUT PCHAR PReadBuffer, IN USHORT Buflen,
  367. IN ULONG Timeout, OUT PUSHORT nActual,
  368. OUT PIO_STATUS_BLOCK IoStatusBlock,
  369. IN const PFDO_DEVICE_DATA FdoData);
  370. NTSTATUS
  371. Serenum_Wait (
  372. IN PKTIMER Timer,
  373. IN LARGE_INTEGER DueTime );
  374. #define Serenum_IoSyncIoctl(Ioctl, Internal, PDevObj, PEvent) \
  375. Serenum_IoSyncIoctlEx((Ioctl), (Internal), (PDevObj), (PEvent), \
  376. NULL, 0, NULL, 0)
  377. NTSTATUS
  378. Serenum_IoSyncIoctlEx(ULONG Ioctl, BOOLEAN Internal, PDEVICE_OBJECT PDevObj,
  379. PKEVENT PEvent, PVOID PInBuffer, ULONG InBufferLen,
  380. PVOID POutBuffer, ULONG OutBufferLen);
  381. NTSTATUS
  382. Serenum_IoSyncReqWithIrp(
  383. PIRP Irp,
  384. UCHAR MajorFunction,
  385. PKEVENT event,
  386. PDEVICE_OBJECT devobj );
  387. NTSTATUS
  388. Serenum_IoSyncReq(
  389. PDEVICE_OBJECT Target,
  390. IN PIRP Irp,
  391. PKEVENT event
  392. );
  393. NTSTATUS
  394. Serenum_CopyUniString (
  395. PUNICODE_STRING source,
  396. PUNICODE_STRING dest);
  397. void
  398. Serenum_FixptToAscii(
  399. int n,
  400. PCHAR output);
  401. int
  402. Serenum_HToI(char c);
  403. int
  404. Serenum_SzCopy (
  405. PCHAR source,
  406. PCHAR dest);
  407. void
  408. Serenum_PDO_EnumMarkMissing(
  409. PFDO_DEVICE_DATA FdoData,
  410. PPDO_DEVICE_DATA PdoData);
  411. int
  412. Serenum_StrLen (
  413. PCHAR string);
  414. NTSTATUS
  415. Serenum_GetRegistryKeyValue (
  416. IN HANDLE Handle,
  417. IN PWCHAR KeyNameString,
  418. IN ULONG KeyNameStringLength,
  419. IN PVOID Data,
  420. IN ULONG DataLength,
  421. OUT PULONG ActualLength);
  422. void
  423. Serenum_InitPDO (
  424. PDEVICE_OBJECT pdoData,
  425. PFDO_DEVICE_DATA fdoData
  426. );
  427. void
  428. SerenumScanOtherIdForMouse(IN PCHAR PBuffer, IN ULONG BufLen,
  429. OUT PCHAR *PpMouseId);
  430. NTSTATUS
  431. SerenumSyncCompletion(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp,
  432. IN PKEVENT SerenumSyncEvent);
  433. NTSTATUS
  434. SerenumDoEnumProtocol(PFDO_DEVICE_DATA PFdoData, PUCHAR *PpBuf, PUSHORT PNBytes,
  435. PBOOLEAN PDSRMissing);
  436. BOOLEAN
  437. SerenumValidateID(IN PUNICODE_STRING PId);
  438. BOOLEAN
  439. SerenumCheckForLegacyDevice(IN PFDO_DEVICE_DATA PFdoData, IN PCHAR PReadBuf,
  440. IN ULONG BufferLen,
  441. IN OUT PUNICODE_STRING PHardwareIDs,
  442. IN OUT PUNICODE_STRING PCompIDs,
  443. IN OUT PUNICODE_STRING PDeviceIDs);
  444. NTSTATUS
  445. SerenumStartProtocolThread(IN PFDO_DEVICE_DATA PFdoData);
  446. VOID
  447. SerenumReleaseThreadReference(IN PDEVICE_OBJECT PDevObj, IN PVOID PContext);
  448. VOID
  449. SerenumWaitForEnumThreadTerminate(IN PFDO_DEVICE_DATA PFdoData);
  450. #endif // ndef SERENUM_H