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.

564 lines
14 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. mouhid.h
  5. Abstract:
  6. This module contains the private definitions for the HID Mouse Filter
  7. Driver.
  8. Note: This is not a WDM driver as it will not run on Memphis (you need a
  9. vxd mapper to do mice for Memphis) and it uses event logs
  10. Environment:
  11. Kernel mode only.
  12. Revision History:
  13. Jan-1997 : Initial writing, Dan Markarian
  14. --*/
  15. #ifndef _MOUHID_H
  16. #define _MOUHID_H
  17. #include "ntddk.h"
  18. #include "hidusage.h"
  19. #include "hidpi.h"
  20. #include "ntddmou.h"
  21. #include "kbdmou.h"
  22. #include "mouhidm.h"
  23. #include "wmilib.h"
  24. //
  25. // Allocate memory with our own pool tag. Note that Windows 95/NT are little
  26. // endian systems.
  27. //
  28. #define MOUHID_POOL_TAG (ULONG) 'lCdH'
  29. #undef ExAllocatePool
  30. #define ExAllocatePool(type, size) \
  31. ExAllocatePoolWithTag (type, size, MOUHID_POOL_TAG);
  32. //
  33. // Sometimes we allocate a bunch of structures together and need to split the
  34. // allocation among these different structures. Use this macro to get the
  35. // lengths of the different structures aligned properly.
  36. //
  37. #if defined(_WIN64)
  38. #define ALIGNPTRLEN(x) ((x + 0x7) >> 3) << 3
  39. #else // defined(_WIN64)
  40. #define ALIGNPTRLEN(x) x
  41. #endif // defined(_WIN64)
  42. //
  43. // Registry ProblemFlags masks.
  44. //
  45. #define PROBLEM_BAD_ABSOLUTE_FLAG_X_Y 0x00000001
  46. #define PROBLEM_BAD_PHYSICAL_MIN_MAX_X 0x00000002
  47. #define PROBLEM_BAD_PHYSICAL_MIN_MAX_Y 0x00000004
  48. #define PROBLEM_BAD_PHYSICAL_MIN_MAX_Z 0x00000008
  49. //
  50. // Flags to indicate whether read completed synchronously or asynchronously
  51. //
  52. #define MOUHID_START_READ 0x01
  53. #define MOUHID_END_READ 0x02
  54. #define MOUHID_IMMEDIATE_READ 0x03
  55. //
  56. // I cannot find this constant after a bit of searching so I am making it up
  57. // emperically for now.
  58. //
  59. // When we have an absolute mouse we need to scale its maximum value to the
  60. // Raw Input User Thread's maximum value.
  61. //
  62. #define MOUHID_RIUT_ABSOLUTE_POINTER_MAX 0xFFFF
  63. //
  64. // Debug messaging and breakpoint macros.
  65. //
  66. #define DBG_STARTUP_SHUTDOWN_MASK 0x0000000F
  67. #define DBG_SS_NOISE 0x00000001
  68. #define DBG_SS_TRACE 0x00000002
  69. #define DBG_SS_INFO 0x00000004
  70. #define DBG_SS_ERROR 0x00000008
  71. #define DBG_CALL_MASK 0x000000F0
  72. #define DBG_CALL_NOISE 0x00000010
  73. #define DBG_CALL_TRACE 0x00000020
  74. #define DBG_CALL_INFO 0x00000040
  75. #define DBG_CALL_ERROR 0x00000080
  76. #define DBG_IOCTL_MASK 0x00000F00
  77. #define DBG_IOCTL_NOISE 0x00000100
  78. #define DBG_IOCTL_TRACE 0x00000200
  79. #define DBG_IOCTL_INFO 0x00000400
  80. #define DBG_IOCTL_ERROR 0x00000800
  81. #define DBG_READ_MASK 0x0000F000
  82. #define DBG_READ_NOISE 0x00001000
  83. #define DBG_READ_TRACE 0x00002000
  84. #define DBG_READ_INFO 0x00004000
  85. #define DBG_READ_ERROR 0x00008000
  86. #define DBG_CREATE_CLOSE_MASK 0x000F0000
  87. #define DBG_CC_NOISE 0x00010000
  88. #define DBG_CC_TRACE 0x00020000
  89. #define DBG_CC_INFO 0x00040000
  90. #define DBG_CC_ERROR 0x00080000
  91. #define DBG_POWER_MASK 0x00F00000
  92. #define DBG_POWER_NOISE 0x00100000
  93. #define DBG_POWER_TRACE 0x00200000
  94. #define DBG_POWER_INFO 0x00400000
  95. #define DBG_POWER_ERROR 0x00800000
  96. #define DBG_PNP_MASK 0x0F000000
  97. #define DBG_PNP_NOISE 0x01000000
  98. #define DBG_PNP_TRACE 0x02000000
  99. #define DBG_PNP_INFO 0x04000000
  100. #define DBG_PNP_ERROR 0x08000000
  101. #define DBG_CANCEL_MASK 0xF0000000
  102. #define DBG_CANCEL_NOISE 0x10000000
  103. #define DBG_CANCEL_TRACE 0x20000000
  104. #define DBG_CANCEL_INFO 0x40000000
  105. #define DBG_CANCEL_ERROR 0x80000000
  106. #define DEFAULT_DEBUG_OUTPUT_LEVEL 0x88888888
  107. #if DBG
  108. #define Print(_l_, _x_) \
  109. if (Globals.DebugLevel & (_l_)) { \
  110. DbgPrint ("MouHid: "); \
  111. DbgPrint _x_; \
  112. }
  113. #define TRAP() DbgBreakPoint()
  114. #else
  115. #define Print(_l_,_x_)
  116. #define TRAP()
  117. #endif
  118. #define MAX(_A_,_B_) (((_A_) < (_B_)) ? (_B_) : (_A_))
  119. #define MIN(_A_,_B_) (((_A_) < (_B_)) ? (_A_) : (_B_))
  120. #define FLIP_FLOP_WHEEL L"FlipFlopWheel" // should we change polarity of wheel
  121. #define SCALING_FACTOR_WHEEL L"WheelScalingFactor" // The per-raden scaling factor
  122. //
  123. // Structures
  124. //
  125. typedef struct _GLOBALS {
  126. #if DBG
  127. //
  128. // The level of trace output sent to the debugger. See HidCli_KdPrint above.
  129. //
  130. ULONG DebugLevel;
  131. #endif
  132. //
  133. // Configuration flag indicating that we must treat all mouse movement as
  134. // relative data. Overrides .IsAbsolute flag reported by the HID device.
  135. // To set this switch, place a value of the same name into the parameters
  136. // key.
  137. //
  138. BOOLEAN TreatAbsoluteAsRelative;
  139. //
  140. // When using a HID device of usage type HID_USAGE_GENERIC_POINTER (not
  141. // of HID_USAGE_GENERIC_MOUSE).
  142. // This switch overwrites the "TreatAbsoluteAsRelative" switch.
  143. //
  144. BOOLEAN TreatAbsolutePointerAsAbsolute;
  145. //
  146. // Do not Accept HID_USAGE_GENERIC_POINTER as a device. (AKA only use HID
  147. // devices that declare themselves as HID_USAGE_GENERIC_MOUSE.)
  148. //
  149. BOOLEAN UseOnlyMice;
  150. BOOLEAN Reserved[1];
  151. //
  152. // Pointer to this driver's null-terminated registry path.
  153. //
  154. UNICODE_STRING RegistryPath;
  155. //
  156. // Unit ID given to the keyboard class driver
  157. //
  158. ULONG UnitId;
  159. } GLOBALS;
  160. extern GLOBALS Globals;
  161. typedef struct _DEVICE_EXTENSION
  162. {
  163. //
  164. // Pointer back to the this extension's device object.
  165. //
  166. PDEVICE_OBJECT Self;
  167. //
  168. // The top of the stack before this filter was added. AKA the location
  169. // to which all IRPS should be directed.
  170. //
  171. PDEVICE_OBJECT TopOfStack;
  172. //
  173. // "THE PDO" (ejected by Hidclass)
  174. //
  175. PDEVICE_OBJECT PDO;
  176. //
  177. // Flag indicating permission to send callbacks to the mouse class driver.
  178. //
  179. LONG EnableCount;
  180. //
  181. // Read interlock value to protect us from running out of stack space
  182. //
  183. ULONG ReadInterlock;
  184. //
  185. // Has the device been taken out from under us?
  186. // Has it been started?
  187. //
  188. BOOLEAN Started;
  189. BOOLEAN ShuttingDown;
  190. BOOLEAN Initialized;
  191. USHORT UnitId;
  192. // Should the polarity of the wheel be backwards.
  193. BOOLEAN FlipFlop;
  194. BOOLEAN Reserved[3];
  195. ULONG WheelScalingFactor;
  196. //
  197. // Write and Feature Irps get passed straight down, but read Irps do not.
  198. // For this reason we keep around a read Irp, which we created.
  199. //
  200. PIRP ReadIrp;
  201. //
  202. // Flags indicating problems with the mouse HID device (such as bad
  203. // absolute X-Y axes, bad physical minimum and maximum).
  204. //
  205. ULONG ProblemFlags;
  206. //
  207. // A file pointer to be used for reading
  208. //
  209. PFILE_OBJECT ReadFile;
  210. //
  211. // Event used to synchronize the completion of the read irp and the close irp
  212. //
  213. KEVENT ReadCompleteEvent;
  214. //
  215. // Event used to indicate that a read irp has been sent and is now cancelable.
  216. //
  217. KEVENT ReadSentEvent;
  218. //
  219. // A pointer to the HID extension.
  220. //
  221. struct _HID_EXTENSION * HidExtension;
  222. //
  223. // Pointer to the mouse class device object and callback routine
  224. // above us, Used as the first parameter and the MouseClassCallback().
  225. // routine itself.
  226. //
  227. CONNECT_DATA ConnectData;
  228. //
  229. // Remove Lock object to project IRP_MN_REMOVE_DEVICE
  230. //
  231. IO_REMOVE_LOCK RemoveLock;
  232. //
  233. // A fast mutex to prevent Create from trouncing close, as one starts the
  234. // read loop and the other shuts it down.
  235. //
  236. FAST_MUTEX CreateCloseMutex;
  237. //
  238. // An event to halt the deletion of a device until it is ready to go.
  239. //
  240. KEVENT StartEvent;
  241. //
  242. // Buffer for a single mouse data packet so that we might hand it to
  243. // the mouse class driver.
  244. //
  245. MOUSE_INPUT_DATA InputData;
  246. //
  247. // Buffer for the mouse attributes.
  248. //
  249. MOUSE_ATTRIBUTES Attributes;
  250. USHORT AttributesAllignmentProblem; //
  251. //
  252. // An attachment point for the global list o devices
  253. //
  254. LIST_ENTRY Link;
  255. //
  256. // WMI Information
  257. //
  258. WMILIB_CONTEXT WmiLibInfo;
  259. } DEVICE_EXTENSION, * PDEVICE_EXTENSION;
  260. typedef struct _HID_EXTENSION {
  261. //
  262. // Indicates the bit size of each X,Y,Z usage value. This information is
  263. // used should the usage's physical minimum/maximum limits be invalid (a
  264. // common problem).
  265. //
  266. struct {
  267. USHORT X;
  268. USHORT Y;
  269. USHORT Z;
  270. USHORT Reserved;
  271. } BitSize;
  272. //
  273. // The maximum allowed values of X and Y.
  274. //
  275. LONG MaxX;
  276. LONG MaxY;
  277. //
  278. // Should this mouse be treated as an absolute device.
  279. //
  280. BOOLEAN IsAbsolute;
  281. //
  282. // Flag indicating whether or not a wheel usage (Z axis) exists.
  283. //
  284. BOOLEAN HasNoWheelUsage;
  285. //
  286. // Flag indicating whether or not a z axis exists on this mouse;
  287. //
  288. BOOLEAN HasNoZUsage;
  289. BOOLEAN Reserved;
  290. //
  291. // The maximum number of usages that can be returned from a single read
  292. // report.
  293. USHORT MaxUsages;
  294. USHORT Reserved2;
  295. //
  296. // The preparsed data associated with this hid device.
  297. //
  298. PHIDP_PREPARSED_DATA Ppd;
  299. //
  300. // The capabilities of this hid device
  301. //
  302. HIDP_CAPS Caps;
  303. //
  304. // Pointers into the buffer at the end of this structure (dynamic size).
  305. //
  306. PCHAR InputBuffer;
  307. PUSAGE CurrentUsageList;
  308. PUSAGE PreviousUsageList;
  309. PUSAGE BreakUsageList;
  310. PUSAGE MakeUsageList;
  311. //
  312. // MDLs describing the buffer at the end of this structure (dynamic size).
  313. //
  314. PMDL InputMdl;
  315. //
  316. // Buffer of dynamic size, allocated at run-time. It is used to hold one
  317. // input report and 4 x .MaxUsageList usages (4 = previous, current, make,
  318. // and break usages).
  319. //
  320. CHAR Buffer[];
  321. } HID_EXTENSION, * PHID_EXTENSION;
  322. //
  323. // Prototypes.
  324. //
  325. NTSTATUS
  326. DriverEntry(
  327. IN PDRIVER_OBJECT DriverObject,
  328. IN PUNICODE_STRING RegistryPath
  329. );
  330. NTSTATUS
  331. MouHid_AddDevice (
  332. IN PDRIVER_OBJECT MouHidDriver, // The kbd Driver object.
  333. IN PDEVICE_OBJECT PDO
  334. );
  335. NTSTATUS
  336. MouHid_Close (
  337. IN PDEVICE_OBJECT DeviceObject,
  338. IN PIRP Irp
  339. );
  340. NTSTATUS
  341. MouHid_Create (
  342. IN PDEVICE_OBJECT DeviceObject,
  343. IN PIRP Irp
  344. );
  345. NTSTATUS
  346. MouHid_CallHidClass(
  347. IN PDEVICE_EXTENSION Data,
  348. IN ULONG Ioctl,
  349. PVOID InputBuffer,
  350. ULONG InputBufferLength,
  351. PVOID OutputBuffer,
  352. ULONG OutputBufferLength
  353. );
  354. VOID
  355. MouHid_LogError(
  356. IN PDRIVER_OBJECT DriverObject,
  357. IN NTSTATUS ErrorCode,
  358. IN PWSTR ErrorInsertionString OPTIONAL
  359. );
  360. NTSTATUS
  361. MouHid_StartDevice (
  362. IN PDEVICE_EXTENSION Data
  363. );
  364. NTSTATUS
  365. MouHid_StartRead (
  366. IN PDEVICE_EXTENSION Data
  367. );
  368. NTSTATUS
  369. MouHid_PnP (
  370. IN PDEVICE_OBJECT DeviceObject,
  371. IN PIRP Irp
  372. );
  373. NTSTATUS
  374. MouHid_Power (
  375. IN PDEVICE_OBJECT DeviceObject,
  376. IN PIRP Irp
  377. );
  378. NTSTATUS
  379. MouHid_Power (
  380. IN PDEVICE_OBJECT DeviceObject,
  381. IN PIRP Irp
  382. );
  383. NTSTATUS
  384. MouHid_PnPComplete (
  385. IN PDEVICE_OBJECT DeviceObject,
  386. IN PIRP Irp,
  387. IN PVOID Context
  388. );
  389. NTSTATUS
  390. MouHid_GetRegistryParameters ();
  391. VOID
  392. MouHid_Unload(
  393. IN PDRIVER_OBJECT Driver
  394. );
  395. NTSTATUS
  396. MouHid_IOCTL (
  397. IN PDEVICE_OBJECT DeviceObject,
  398. IN PIRP Irp
  399. );
  400. NTSTATUS
  401. MouHid_Flush (
  402. IN PDEVICE_OBJECT DeviceObject,
  403. IN PIRP Irp
  404. );
  405. NTSTATUS
  406. KbdHid_Power (
  407. IN PDEVICE_OBJECT DeviceObject,
  408. IN PIRP Irp
  409. );
  410. NTSTATUS
  411. MouHid_PassThrough (
  412. IN PDEVICE_OBJECT DeviceObject,
  413. IN PIRP Irp
  414. );
  415. NTSTATUS
  416. MouHid_SystemControl(
  417. IN PDEVICE_OBJECT DeviceObject,
  418. IN PIRP Irp
  419. );
  420. NTSTATUS
  421. MouHid_SetWmiDataItem(
  422. IN PDEVICE_OBJECT DeviceObject,
  423. IN PIRP Irp,
  424. IN ULONG GuidIndex,
  425. IN ULONG InstanceIndex,
  426. IN ULONG DataItemId,
  427. IN ULONG BufferSize,
  428. IN PUCHAR Buffer
  429. );
  430. NTSTATUS
  431. MouHid_SetWmiDataBlock(
  432. IN PDEVICE_OBJECT DeviceObject,
  433. IN PIRP Irp,
  434. IN ULONG GuidIndex,
  435. IN ULONG InstanceIndex,
  436. IN ULONG BufferSize,
  437. IN PUCHAR Buffer
  438. );
  439. NTSTATUS
  440. MouHid_QueryWmiDataBlock(
  441. IN PDEVICE_OBJECT DeviceObject,
  442. IN PIRP Irp,
  443. IN ULONG GuidIndex,
  444. IN ULONG InstanceIndex,
  445. IN ULONG InstanceCount,
  446. IN OUT PULONG InstanceLengthArray,
  447. IN ULONG BufferAvail,
  448. OUT PUCHAR Buffer
  449. );
  450. NTSTATUS
  451. MouHid_QueryWmiRegInfo(
  452. IN PDEVICE_OBJECT DeviceObject,
  453. OUT ULONG *RegFlags,
  454. OUT PUNICODE_STRING InstanceName,
  455. OUT PUNICODE_STRING *RegistryPath,
  456. OUT PUNICODE_STRING MofResourceName,
  457. OUT PDEVICE_OBJECT *Pdo
  458. );
  459. extern WMIGUIDREGINFO MouHid_WmiGuidList[1];
  460. #endif //_MOUHID_H