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.

667 lines
14 KiB

  1. /*++
  2. Copyright (c) 1989, 1990, 1991, 1992, 1993, 1994 - 1998 Microsoft Corporation
  3. Module Name:
  4. mouclass.h
  5. Abstract:
  6. These are the structures and defines that are used in the
  7. mouse class driver.
  8. Revision History:
  9. --*/
  10. #ifndef _MOUCLASS_
  11. #define _MOUCLASS_
  12. #include <ntddmou.h>
  13. #include "wmilib.h"
  14. #define MOUSE_POOL_TAG 'CouM'
  15. #undef ExAllocatePool
  16. #define ExAllocatePool(Type, Bytes) ExAllocatePoolWithTag(Type, Bytes, MOUSE_POOL_TAG)
  17. //
  18. // Define the default number of elements in the class input data queue.
  19. //
  20. #define DATA_QUEUE_SIZE 100
  21. #define MAXIMUM_PORTS_SERVICED 10
  22. #define NAME_MAX 256
  23. #define DUMP_COUNT 4
  24. #define DEFAULT_DEBUG_LEVEL 0
  25. #define MAX(a,b) (((a) < (b)) ? (b) : (a))
  26. #if DBG
  27. #define MouPrint(x) MouDebugPrint x
  28. #else
  29. #define MouPrint(x)
  30. #endif
  31. #define MOUSE_WAIT_WAKE_ENABLE L"WaitWakeEnabled"
  32. #define IS_TRUSTED_FILE_FOR_READ(x) (&DriverEntry == (x)->FsContext2)
  33. #define SET_TRUSTED_FILE_FOR_READ(x) ((x)->FsContext2 = &DriverEntry)
  34. #define CLEAR_TRUSTED_FILE_FOR_READ(x) ((x)->FsContext2 = NULL)
  35. #define ALLOW_OVERFLOW TRUE
  36. //
  37. // Port description
  38. //
  39. // Used only with the
  40. // allforoneandoneforall turned off (AKA ConnectOneClassToOnePort
  41. // turned on). This is the file sent to the ports.
  42. //
  43. typedef struct _PORT {
  44. //
  45. // The file Pointer to the port;
  46. //
  47. PFILE_OBJECT File;
  48. //
  49. // The port itself
  50. //
  51. struct _DEVICE_EXTENSION * Port;
  52. //
  53. // Port flags
  54. //
  55. BOOLEAN Enabled;
  56. BOOLEAN Reserved[2];
  57. BOOLEAN Free;
  58. } PORT, *PPORT;
  59. #define PORT_WORKING(port) ((port)->Enabled && !(port)->Free)
  60. //
  61. // Class device extension.
  62. //
  63. typedef struct _DEVICE_EXTENSION {
  64. //
  65. // Back pointer to the Device Object created for this port.
  66. //
  67. PDEVICE_OBJECT Self;
  68. //
  69. // Pointer to the active Class DeviceObject;
  70. // If the AFOAOFA (all for one and one for all) switch is on then this
  71. // points to the device object named as the first keyboard.
  72. //
  73. PDEVICE_OBJECT TrueClassDevice;
  74. //
  75. // The Target port device Object to which all mouse IRPs are sent.
  76. //
  77. PDEVICE_OBJECT TopPort;
  78. //
  79. // The PDO if applicable.
  80. //
  81. PDEVICE_OBJECT PDO;
  82. //
  83. // A remove lock to keep track of outstanding I/Os to prevent the device
  84. // object from leaving before such time as all I/O has been completed.
  85. //
  86. IO_REMOVE_LOCK RemoveLock;
  87. //
  88. // It this port a Plug and Play port
  89. //
  90. BOOLEAN PnP;
  91. BOOLEAN Started;
  92. //
  93. // Indicates whether it is okay to log overflow errors.
  94. //
  95. BOOLEAN OkayToLogOverflow;
  96. KSPIN_LOCK WaitWakeSpinLock;
  97. //
  98. // Is the Trusted Subsystem Connected
  99. //
  100. ULONG TrustedSubsystemCount;
  101. //
  102. // Number of input data items currently in the InputData queue.
  103. //
  104. ULONG InputCount;
  105. //
  106. // A Unicode string pointing to the symbolic link for the Device Interface
  107. // of this device object.
  108. //
  109. UNICODE_STRING SymbolicLinkName;
  110. //
  111. // Start of the class input data queue (really a circular buffer).
  112. //
  113. PMOUSE_INPUT_DATA InputData;
  114. //
  115. // Insertion pointer for InputData.
  116. //
  117. PMOUSE_INPUT_DATA DataIn;
  118. //
  119. // Removal pointer for InputData.
  120. //
  121. PMOUSE_INPUT_DATA DataOut;
  122. //
  123. // Mouse attributes.
  124. //
  125. MOUSE_ATTRIBUTES MouseAttributes;
  126. //
  127. // Spinlock used to synchronize access to the input data queue and its
  128. // insertion/removal pointers.
  129. //
  130. KSPIN_LOCK SpinLock;
  131. //
  132. // Queue of pended read requests sent to this port. Access to this queue is
  133. // guarded by SpinLock
  134. //
  135. LIST_ENTRY ReadQueue;
  136. //
  137. // Request sequence number (used for error logging).
  138. //
  139. ULONG SequenceNumber;
  140. //
  141. // The "D" and "S" states of the current device
  142. //
  143. DEVICE_POWER_STATE DeviceState;
  144. SYSTEM_POWER_STATE SystemState;
  145. ULONG UnitId;
  146. //
  147. // WMI Information
  148. //
  149. WMILIB_CONTEXT WmiLibInfo;
  150. //
  151. // Mapping of system to device states when a wait wake irp is active
  152. //
  153. DEVICE_POWER_STATE SystemToDeviceState[PowerSystemHibernate];
  154. //
  155. // Minimum amount of power needed to wake the device
  156. //
  157. DEVICE_POWER_STATE MinDeviceWakeState;
  158. //
  159. // Lowest system state that the machine can be in and have the device wake it up
  160. //
  161. SYSTEM_POWER_STATE MinSystemWakeState;
  162. //
  163. // Actual wait wake irp
  164. //
  165. PIRP WaitWakeIrp;
  166. //
  167. // Duplicate wait wake irp getting completed because another was queued.
  168. //
  169. PIRP ExtraWaitWakeIrp;
  170. //
  171. // Target Device Notification Handle
  172. //
  173. PVOID TargetNotifyHandle;
  174. //
  175. // Only used for a legacy port device
  176. //
  177. LIST_ENTRY Link;
  178. //
  179. // Used only for a legacy port device when grand master mode is off
  180. //
  181. PFILE_OBJECT File;
  182. //
  183. // Used for a legacy port device
  184. //
  185. BOOLEAN Enabled;
  186. //
  187. // Indicates whether it is okay to send wait wake irps down the stack
  188. // (does NOT reflect if the bus can implement or not)
  189. //
  190. BOOLEAN WaitWakeEnabled;
  191. //
  192. // Indicates whether we have received a surprise removed irp
  193. //
  194. BOOLEAN SurpriseRemoved;
  195. } DEVICE_EXTENSION, *PDEVICE_EXTENSION;
  196. //
  197. // On some busses, we can power down the bus, but not the system, in this case
  198. // we still need to allow the device to wake said bus, therefore
  199. // waitwake-supported should not rely on systemstate.
  200. //
  201. // #define WAITWAKE_SUPPORTED(port) ((port)->MinDeviceWakeState > PowerDeviceUnspecified) && \
  202. // (port)->MinSystemWakeState > PowerSystemWorking)
  203. #define WAITWAKE_SUPPORTED(port) ((port)->MinDeviceWakeState > PowerDeviceD0 && \
  204. (port)->MinSystemWakeState > PowerSystemWorking)
  205. // #define WAITWAKE_ON(port) ((port)->WaitWakeIrp != 0)
  206. #define WAITWAKE_ON(port) \
  207. (InterlockedCompareExchangePointer(&(port)->WaitWakeIrp, NULL, NULL) != NULL)
  208. #define SHOULD_SEND_WAITWAKE(port) (WAITWAKE_SUPPORTED(port) && \
  209. !WAITWAKE_ON(port) && \
  210. MouseClassCheckWaitWakeEnabled(port))
  211. //
  212. // Global shared data
  213. //
  214. typedef struct _GLOBALS {
  215. //
  216. // Declare the global debug flag for this driver.
  217. //
  218. ULONG Debug;
  219. //
  220. // If ConnectOneClassToOnePort is off aka we want "All for one and one for
  221. // all behavior" then we need to create the one Master DO to which all
  222. // the goods go.
  223. //
  224. PDEVICE_EXTENSION GrandMaster;
  225. //
  226. // List of ClassDevices that associated with the same name
  227. // aka the all for one and one for all flag is set
  228. //
  229. PPORT AssocClassList;
  230. ULONG NumAssocClass;
  231. LONG Opens;
  232. ULONG NumberLegacyPorts;
  233. FAST_MUTEX Mutex;
  234. //
  235. // Specifies the type of class-port connection to make. A '1'
  236. // indicates a 1:1 relationship between class device objects and
  237. // port device objects. A '0' indicates a 1:many relationship.
  238. //
  239. ULONG ConnectOneClassToOnePort;
  240. //
  241. // Number of port drivers serviced by this class driver.
  242. //
  243. ULONG PortsServiced;
  244. //
  245. // IntialDevice Extension
  246. //
  247. DEVICE_EXTENSION InitExtension;
  248. //
  249. // A list of the registry path to the service parameters.
  250. //
  251. UNICODE_STRING RegistryPath;
  252. //
  253. // The base name for all class objects created as mice.
  254. //
  255. UNICODE_STRING BaseClassName;
  256. WCHAR BaseClassBuffer[NAME_MAX];
  257. //
  258. // Linked list of all the legacy device objects that were created in
  259. // DriverEntry or FindMorePorts. We maintain this list so we can delete
  260. // them when we unload.
  261. //
  262. LIST_ENTRY LegacyDeviceList;
  263. } GLOBALS, *PGLOBALS;
  264. //
  265. // Mouse configuration information.
  266. //
  267. typedef struct _MOUSE_CONFIGURATION_INFORMATION {
  268. //
  269. // Maximum size of class input data queue, in bytes.
  270. //
  271. ULONG DataQueueSize;
  272. } MOUSE_CONFIGURATION_INFORMATION, *PMOUSE_CONFIGURATION_INFORMATION;
  273. typedef struct _MOUSE_WORK_ITEM_DATA {
  274. PIRP Irp;
  275. PDEVICE_EXTENSION Data;
  276. PIO_WORKITEM Item;
  277. BOOLEAN WaitWakeState;
  278. } MOUSE_WORK_ITEM_DATA, *PMOUSE_WORK_ITEM_DATA;
  279. #define MouseClassDeleteLegacyDevice(de) \
  280. { \
  281. if (de->InputData) { \
  282. ExFreePool (de->InputData); \
  283. de->InputData = de->DataIn = de->DataOut = NULL; \
  284. } \
  285. IoDeleteDevice (de->Self); \
  286. de = NULL; \
  287. }
  288. ///
  289. // Function Declairations
  290. //
  291. NTSTATUS
  292. MouseAddDeviceEx(
  293. IN PDEVICE_EXTENSION NewDeviceObject,
  294. IN PWCHAR FullClassName,
  295. IN PFILE_OBJECT File
  296. );
  297. NTSTATUS
  298. MouseAddDevice(
  299. IN PDRIVER_OBJECT DriverObject,
  300. IN PDEVICE_OBJECT PhysicalDeviceObject
  301. );
  302. void
  303. MouseClassGetWaitWakeEnableState(
  304. IN PDEVICE_EXTENSION Data
  305. );
  306. NTSTATUS
  307. DriverEntry(
  308. IN PDRIVER_OBJECT DriverObject,
  309. IN PUNICODE_STRING RegistryPath
  310. );
  311. NTSTATUS
  312. MouseClassPassThrough(
  313. IN PDEVICE_OBJECT DeviceObject,
  314. IN PIRP Irp
  315. );
  316. VOID
  317. MouseClassCancel(
  318. IN PDEVICE_OBJECT DeviceObject,
  319. IN PIRP Irp
  320. );
  321. NTSTATUS
  322. MouseClassCleanup(
  323. IN PDEVICE_OBJECT DeviceObject,
  324. IN PIRP Irp
  325. );
  326. NTSTATUS
  327. MouseClassDeviceControl(
  328. IN PDEVICE_OBJECT DeviceObject,
  329. IN PIRP Irp
  330. );
  331. NTSTATUS
  332. MouseClassFlush(
  333. IN PDEVICE_OBJECT DeviceObject,
  334. IN PIRP Irp
  335. );
  336. NTSTATUS
  337. MouseClassCreate(
  338. IN PDEVICE_OBJECT DeviceObject,
  339. IN PIRP Irp
  340. );
  341. NTSTATUS
  342. MouseClassClose(
  343. IN PDEVICE_OBJECT DeviceObject,
  344. IN PIRP Irp
  345. );
  346. NTSTATUS
  347. MouseClassRead(
  348. IN PDEVICE_OBJECT DeviceObject,
  349. IN PIRP Irp
  350. );
  351. NTSTATUS
  352. MouseClassReadCopyData(
  353. IN PDEVICE_EXTENSION DeviceExtension,
  354. IN PIRP Irp
  355. );
  356. PIRP
  357. MouseClassDequeueRead(
  358. IN PDEVICE_EXTENSION DeviceExtension
  359. );
  360. PIRP
  361. MouseClassDequeueReadByFileObject(
  362. IN PDEVICE_EXTENSION DeviceExtension,
  363. IN PFILE_OBJECT FileObject
  364. );
  365. BOOLEAN
  366. MouseClassCheckWaitWakeEnabled (
  367. IN PDEVICE_EXTENSION Data
  368. );
  369. BOOLEAN
  370. MouseClassCreateWaitWakeIrp (
  371. IN PDEVICE_EXTENSION Data
  372. );
  373. NTSTATUS
  374. MouseSendIrpSynchronously (
  375. IN PDEVICE_OBJECT DeviceObject,
  376. IN PIRP Irp,
  377. IN BOOLEAN CopyToNext
  378. );
  379. NTSTATUS
  380. MousePnP (
  381. IN PDEVICE_OBJECT DeviceObject,
  382. IN PIRP Irp
  383. );
  384. VOID
  385. MouseClassServiceCallback(
  386. IN PDEVICE_OBJECT DeviceObject,
  387. IN PMOUSE_INPUT_DATA InputDataStart,
  388. IN PMOUSE_INPUT_DATA InputDataEnd,
  389. IN OUT PULONG InputDataConsumed
  390. );
  391. NTSTATUS
  392. MouseClassPower (
  393. IN PDEVICE_OBJECT DeviceObject,
  394. IN PIRP Irp
  395. );
  396. VOID
  397. MouseClassUnload(
  398. IN PDRIVER_OBJECT DriverObject
  399. );
  400. VOID
  401. MouConfiguration();
  402. NTSTATUS
  403. MouCreateClassObject(
  404. IN PDRIVER_OBJECT DriverObject,
  405. IN PDEVICE_EXTENSION TmpDeviceExtension,
  406. OUT PDEVICE_OBJECT * ClassDeviceObject,
  407. OUT PWCHAR * FullDeviceName,
  408. IN BOOLEAN Legacy
  409. );
  410. VOID
  411. MouDebugPrint(
  412. ULONG DebugPrintLevel,
  413. PCCHAR DebugMessage,
  414. ...
  415. );
  416. NTSTATUS
  417. MouDeterminePortsServiced(
  418. IN PUNICODE_STRING BasePortName,
  419. IN OUT PULONG NumberPortsServiced
  420. );
  421. NTSTATUS
  422. MouDeviceMapQueryCallback(
  423. IN PWSTR ValueName,
  424. IN ULONG ValueType,
  425. IN PVOID ValueData,
  426. IN ULONG ValueLength,
  427. IN PVOID Context,
  428. IN PVOID EntryContext
  429. );
  430. NTSTATUS
  431. MouEnableDisablePort(
  432. IN BOOLEAN EnableFlag,
  433. IN PIRP Irp,
  434. IN PDEVICE_EXTENSION Port,
  435. IN PFILE_OBJECT * File
  436. );
  437. NTSTATUS
  438. MouSendConnectRequest(
  439. IN PDEVICE_EXTENSION ClassData,
  440. IN PVOID ServiceCallback
  441. );
  442. VOID
  443. MouInitializeDataQueue(
  444. IN PVOID Context
  445. );
  446. VOID
  447. MouseClassFindMorePorts(
  448. PDRIVER_OBJECT DriverObject,
  449. PVOID Context,
  450. ULONG Count
  451. );
  452. NTSTATUS
  453. MouseClassEnableGlobalPort(
  454. IN PDEVICE_EXTENSION Port,
  455. IN BOOLEAN Enabled
  456. );
  457. NTSTATUS
  458. MouseClassPlugPlayNotification(
  459. IN PVOID NotificationStructure,
  460. IN PDEVICE_EXTENSION Port
  461. );
  462. void
  463. MouseClassLogError(
  464. PVOID Object,
  465. ULONG ErrorCode,
  466. ULONG UniqueErrorValue,
  467. NTSTATUS FinalStatus,
  468. ULONG DumpCount,
  469. ULONG *DumpData,
  470. UCHAR MajorFunction
  471. );
  472. BOOLEAN
  473. MouseClassCreateWaitWakeIrp (
  474. IN PDEVICE_EXTENSION Data
  475. );
  476. void
  477. MouseClassCreateWaitWakeIrpWorker (
  478. IN PDEVICE_OBJECT DeviceObject,
  479. IN PMOUSE_WORK_ITEM_DATA ItemData
  480. );
  481. NTSTATUS
  482. MouseToggleWaitWake(
  483. PDEVICE_EXTENSION Data,
  484. BOOLEAN WaitWakeState
  485. );
  486. VOID
  487. MouseToggleWaitWakeWorker(
  488. IN PDEVICE_OBJECT DeviceObject,
  489. IN PMOUSE_WORK_ITEM_DATA ItemData
  490. );
  491. NTSTATUS
  492. MouseQueryDeviceKey (
  493. IN HANDLE Handle,
  494. IN PWCHAR ValueNameString,
  495. OUT PVOID Data,
  496. IN ULONG DataLength
  497. );
  498. NTSTATUS
  499. MouseClassSystemControl(
  500. IN PDEVICE_OBJECT DeviceObject,
  501. IN PIRP Irp
  502. );
  503. NTSTATUS
  504. MouseClassSetWmiDataItem(
  505. IN PDEVICE_OBJECT DeviceObject,
  506. IN PIRP Irp,
  507. IN ULONG GuidIndex,
  508. IN ULONG InstanceIndex,
  509. IN ULONG DataItemId,
  510. IN ULONG BufferSize,
  511. IN PUCHAR Buffer
  512. );
  513. NTSTATUS
  514. MouseClassSetWmiDataBlock(
  515. IN PDEVICE_OBJECT DeviceObject,
  516. IN PIRP Irp,
  517. IN ULONG GuidIndex,
  518. IN ULONG InstanceIndex,
  519. IN ULONG BufferSize,
  520. IN PUCHAR Buffer
  521. );
  522. NTSTATUS
  523. MouseClassQueryWmiDataBlock(
  524. IN PDEVICE_OBJECT DeviceObject,
  525. IN PIRP Irp,
  526. IN ULONG GuidIndex,
  527. IN ULONG InstanceIndex,
  528. IN ULONG InstanceCount,
  529. IN OUT PULONG InstanceLengthArray,
  530. IN ULONG BufferAvail,
  531. OUT PUCHAR Buffer
  532. );
  533. NTSTATUS
  534. MouseClassQueryWmiRegInfo(
  535. IN PDEVICE_OBJECT DeviceObject,
  536. OUT ULONG *RegFlags,
  537. OUT PUNICODE_STRING InstanceName,
  538. OUT PUNICODE_STRING *RegistryPath,
  539. OUT PUNICODE_STRING MofResourceName,
  540. OUT PDEVICE_OBJECT *Pdo
  541. );
  542. #endif // _MOUCLASS_