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.

671 lines
16 KiB

  1. /*++
  2. Copyright (c) 1989-1998 Microsoft Corporation, All Rights Reserved
  3. Copyright (c) 1993 Logitech Inc.
  4. Module Name:
  5. mouser.h
  6. Abstract:
  7. These are the structures and defines that are used in the
  8. serial mouse filter driver.
  9. Revision History:
  10. --*/
  11. #ifndef _MOUSER_
  12. #define _MOUSER_
  13. #include <ntddk.h>
  14. #include <ntddmou.h>
  15. #include <ntddser.h>
  16. #include "kbdmou.h"
  17. #include "wmilib.h"
  18. #define SERMOU_POOL_TAG (ULONG) 'resM'
  19. #undef ExAllocatePool
  20. #define ExAllocatePool(type, size) \
  21. ExAllocatePoolWithTag (type, size, SERMOU_POOL_TAG);
  22. //
  23. // Default number of buttons and sample rate for the serial mouse.
  24. //
  25. #define MOUSE_NUMBER_OF_BUTTONS 2
  26. #define MOUSE_SAMPLE_RATE 40 // 1200 baud
  27. #define DETECTION_TIMEOUT_DEFAULT 50 // expressed in 10ths of a second
  28. //
  29. // Protocol handler state constants.
  30. //
  31. #define STATE0 0 // Sync bit, buttons and high x & y bits
  32. #define STATE1 1 // lower x bits
  33. #define STATE2 2 // lower y bits
  34. #define STATE3 3 // Switch 2, extended packet bit & low z data
  35. #define STATE4 4 // high z data
  36. #define STATE_MAX 5
  37. //
  38. // Useful constants.
  39. //
  40. #define MOUSE_BUTTON_1 0x01
  41. #define MOUSE_BUTTON_2 0x02
  42. #define MOUSE_BUTTON_3 0x04
  43. #define MOUSE_BUTTON_LEFT 0x01
  44. #define MOUSE_BUTTON_RIGHT 0x02
  45. #define MOUSE_BUTTON_MIDDLE 0x04
  46. //
  47. // Conversion factor for milliseconds to microseconds.
  48. //
  49. #define MS_TO_MICROSECONDS 1000
  50. //
  51. // 150/200 millisecond pause expressed in 100's of nanoseconds
  52. // 200 ms * 1000 us/ms * 10 ns/100 us
  53. //
  54. #define PAUSE_200_MS (200 * 1000 * 10)
  55. #define PAUSE_150_MS (150 * 1000 * 10)
  56. //
  57. // convert milliseconds to 100's of nanoseconds
  58. // 1000 us/ms * 10 ns/100 us
  59. //
  60. #define MS_TO_100_NS 10000
  61. //
  62. // Protocol handler static data.
  63. //
  64. typedef struct _HANDLER_DATA {
  65. ULONG Error; // Error count
  66. ULONG State; // Keep the current state
  67. ULONG PreviousButtons; // The previous button state
  68. UCHAR Raw[STATE_MAX]; // Accumulate raw data
  69. } HANDLER_DATA, *PHANDLER_DATA;
  70. //
  71. // Define the protocol handler type.
  72. //
  73. typedef BOOLEAN
  74. (*PPROTOCOL_HANDLER)(
  75. IN PVOID DevicExtension,
  76. IN PMOUSE_INPUT_DATA CurrentInput,
  77. IN PHANDLER_DATA HandlerData,
  78. IN UCHAR Value,
  79. IN UCHAR LineState);
  80. //
  81. // Defines for DeviceExtension->HardwarePresent.
  82. // These should match the values in i8042prt
  83. //
  84. #define MOUSE_HARDWARE_PRESENT 0x02
  85. #define BALLPOINT_HARDWARE_PRESENT 0x04
  86. #define WHEELMOUSE_HARDWARE_PRESENT 0x08
  87. #define SERIAL_MOUSE_START_READ 0x01
  88. #define SERIAL_MOUSE_END_READ 0x02
  89. #define SERIAL_MOUSE_IMMEDIATE_READ 0x03
  90. //
  91. // Port device extension.
  92. //
  93. typedef struct _DEVICE_EXTENSION {
  94. //
  95. // Debug flags
  96. //
  97. ULONG DebugFlags;
  98. //
  99. // Pointer back to the this extension's device object.
  100. //
  101. PDEVICE_OBJECT Self;
  102. //
  103. // An event to halt the deletion of a device until it is ready to go.
  104. //
  105. KEVENT StartEvent;
  106. //
  107. // The top of the stack before this filter was added. AKA the location
  108. // to which all IRPS should be directed.
  109. //
  110. PDEVICE_OBJECT TopOfStack;
  111. //
  112. // "THE PDO" (ejected by serenum)
  113. //
  114. PDEVICE_OBJECT PDO;
  115. //
  116. // Remove Lock object to protect IRP_MN_REMOVE_DEVICE
  117. //
  118. IO_REMOVE_LOCK RemoveLock;
  119. ULONG ReadInterlock;
  120. //
  121. // Pointer to the mouse class device object and callback routine
  122. // above us, Used as the first parameter and the MouseClassCallback().
  123. // routine itself.
  124. //
  125. CONNECT_DATA ConnectData;
  126. //
  127. // Reference count for number of mouse enables.
  128. //
  129. LONG EnableCount;
  130. //
  131. // Sermouse created irp used to bounce reads down to the serial driver
  132. //
  133. PIRP ReadIrp;
  134. //
  135. // Sermouse created irp used to detect when the mouse has been hot plugged
  136. //
  137. PIRP DetectionIrp;
  138. ULONG SerialEventBits;
  139. //
  140. // WMI Information
  141. //
  142. WMILIB_CONTEXT WmiLibInfo;
  143. //
  144. // Attributes of the mouse
  145. //
  146. MOUSE_ATTRIBUTES MouseAttributes;
  147. //
  148. // Current mouse input packet.
  149. //
  150. MOUSE_INPUT_DATA InputData;
  151. //
  152. // Timer used during startup to follow power cycle detection protocol
  153. //
  154. KTIMER DelayTimer;
  155. //
  156. // Bits to use when testing if the device has been removed
  157. //
  158. ULONG WaitEventMask;
  159. ULONG ModemStatusBits;
  160. //
  161. // Request sequence number (used for error logging).
  162. //
  163. ULONG SequenceNumber;
  164. //
  165. // Pointer to the interrupt protocol handler routine.
  166. //
  167. PPROTOCOL_HANDLER ProtocolHandler;
  168. //
  169. // Static state machine handler data.
  170. //
  171. HANDLER_DATA HandlerData;
  172. DEVICE_POWER_STATE PowerState;
  173. SERIAL_BASIC_SETTINGS SerialBasicSettings;
  174. KSPIN_LOCK PnpStateLock;
  175. KEVENT StopEvent;
  176. //
  177. // Has the device been taken out from under us?
  178. // Has it been started?
  179. //
  180. BOOLEAN Removed;
  181. BOOLEAN SurpriseRemoved;
  182. BOOLEAN Started;
  183. BOOLEAN Stopped;
  184. BOOLEAN RemovalDetected;
  185. //
  186. // Buffer used in the read irp
  187. //
  188. UCHAR ReadBuffer[1];
  189. //
  190. // Set to false if all the lines are low on the first attempt at detection
  191. // If false, all further attempts at detection are stopped
  192. //
  193. BOOLEAN DetectionSupported;
  194. BOOLEAN WaitWakePending;
  195. BOOLEAN PoweringDown;
  196. } DEVICE_EXTENSION, *PDEVICE_EXTENSION;
  197. //
  198. // Function prototypes.
  199. //
  200. /*
  201. PUNICODE_STRING
  202. SerialMouseGetRegistryPath(
  203. PDRIVER_OBJECT DriverObject
  204. );
  205. */
  206. #define SerialMouseGetRegistryPath(DriverObject) \
  207. (PUNICODE_STRING)IoGetDriverObjectExtension(DriverObject, (PVOID) 1)
  208. NTSTATUS
  209. DriverEntry(
  210. IN PDRIVER_OBJECT DriverObject,
  211. IN PUNICODE_STRING RegistryPath
  212. );
  213. NTSTATUS
  214. SerialMouseCompletionRoutine (
  215. IN PDEVICE_OBJECT DeviceObject,
  216. IN PIRP Irp,
  217. IN PVOID Context
  218. );
  219. VOID
  220. SerialMouseClosePort(
  221. PDEVICE_EXTENSION DeviceExtension,
  222. PIRP Irp
  223. );
  224. NTSTATUS
  225. SerialMouseSpinUpRead(
  226. PDEVICE_EXTENSION DeviceExtension
  227. );
  228. NTSTATUS
  229. SerialMouseStartDevice(
  230. PDEVICE_EXTENSION DeviceExtension,
  231. PIRP Irp,
  232. BOOLEAN CloseOnFailure
  233. );
  234. NTSTATUS
  235. SerialMouseInitializeDevice (
  236. IN PDEVICE_EXTENSION DeviceExtension
  237. );
  238. VOID
  239. SerialMouseStartDetection(
  240. PDEVICE_EXTENSION DeviceExtension
  241. );
  242. VOID
  243. SerialMouseStopDetection(
  244. PDEVICE_EXTENSION DeviceExtension
  245. );
  246. VOID
  247. SerialMouseDetectionDpc(
  248. IN PKDPC Dpc,
  249. IN PDEVICE_OBJECT DeviceObject,
  250. IN PVOID SystemArg1,
  251. IN PVOID SystemArg2
  252. );
  253. VOID
  254. SerialMouseDetectionRoutine(
  255. PDEVICE_EXTENSION DeviceExtension
  256. );
  257. NTSTATUS
  258. SerialMouseSendIrpSynchronously (
  259. IN PDEVICE_OBJECT DeviceObject,
  260. IN PIRP Irp,
  261. IN BOOLEAN CopyToNext
  262. );
  263. NTSTATUS
  264. SerialMouseFlush(
  265. IN PDEVICE_OBJECT DeviceObject,
  266. IN PIRP Irp
  267. );
  268. NTSTATUS
  269. SerialMouseInternalDeviceControl(
  270. IN PDEVICE_OBJECT DeviceObject,
  271. IN PIRP Irp
  272. );
  273. NTSTATUS
  274. SerialMouseAddDevice (
  275. IN PDRIVER_OBJECT Driver,
  276. IN PDEVICE_OBJECT PDO
  277. );
  278. NTSTATUS
  279. SerialMouseCreate(
  280. IN PDEVICE_OBJECT DeviceObject,
  281. IN PIRP Irp
  282. );
  283. NTSTATUS
  284. SerialMouseClose(
  285. IN PDEVICE_OBJECT DeviceObject,
  286. IN PIRP Irp
  287. );
  288. NTSTATUS
  289. SerialMousePnP(
  290. IN PDEVICE_OBJECT DeviceObject,
  291. IN PIRP Irp
  292. );
  293. NTSTATUS
  294. SerialMousePower(
  295. IN PDEVICE_OBJECT DeviceObject,
  296. IN PIRP Irp
  297. );
  298. VOID
  299. SerialMouseRemoveDevice(
  300. PDEVICE_EXTENSION DeviceExtension,
  301. PIRP Irp
  302. );
  303. NTSTATUS
  304. SerialMouseSystemControl(
  305. IN PDEVICE_OBJECT DeviceObject,
  306. IN PIRP Irp
  307. );
  308. VOID
  309. SerialMouseUnload(
  310. IN PDRIVER_OBJECT DriverObject
  311. );
  312. NTSTATUS
  313. SerialMouseInitializeHardware(
  314. IN PDEVICE_EXTENSION DeviceExtension
  315. );
  316. VOID
  317. SerialMouseGetDebugFlags(
  318. IN PUNICODE_STRING RegPath
  319. );
  320. VOID
  321. SerialMouseServiceParameters(
  322. IN PDEVICE_EXTENSION DeviceExtension,
  323. IN HANDLE Handle
  324. );
  325. NTSTATUS
  326. SerialMouseInitializePort(
  327. PDEVICE_EXTENSION DeviceExtension
  328. );
  329. VOID
  330. SerialMouseRestorePort(
  331. PDEVICE_EXTENSION DeviceExtension
  332. );
  333. NTSTATUS
  334. SerialMouseSetReadTimeouts(
  335. PDEVICE_EXTENSION DeviceExtension,
  336. ULONG Timeout
  337. );
  338. NTSTATUS
  339. SerialMousepIoSyncIoctl(
  340. BOOLEAN Internal,
  341. ULONG Ioctl,
  342. PDEVICE_OBJECT DeviceObject,
  343. PKEVENT Event,
  344. PIO_STATUS_BLOCK Iosb
  345. );
  346. /*--
  347. NTSTATUS
  348. SerialMouseIoSyncIoctl(
  349. ULONG Ioctl,
  350. PDEVICE_OBJECT DeviceObject,
  351. PKEVENT Event,
  352. PIO_STATUS_BLOCK Iosb
  353. );
  354. ++*/
  355. #define SerialMouseIoSyncIoctl(Ioctl, DeviceObject, Event, Iosb) \
  356. SerialMousepIoSyncIoctl(FALSE, Ioctl, DeviceObject, Event, Iosb)
  357. /*--
  358. NTSTATUS
  359. SerialMouseIoSyncInteralIoctl(
  360. ULONG Ioctl,
  361. PDEVICE_OBJECT DeviceObject,
  362. PKEVENT Event,
  363. PIO_STATUS_BLOCK Iosb
  364. );
  365. ++*/
  366. #define SerialMouseIoSyncInternalIoctl(Ioctl, DeviceObject, Event, Iosb) \
  367. SerialMousepIoSyncIoctl(TRUE, Ioctl, DeviceObject, Event, Iosb)
  368. NTSTATUS
  369. SerialMousepIoSyncIoctlEx(
  370. BOOLEAN Internal,
  371. ULONG Ioctl, // io control code
  372. PDEVICE_OBJECT DeviceObject, // object to call
  373. PKEVENT Event, // event to wait on
  374. PIO_STATUS_BLOCK Iosb, // used inside IRP
  375. PVOID InBuffer, OPTIONAL // input buffer
  376. ULONG InBufferLen, OPTIONAL // input buffer length
  377. PVOID OutBuffer, OPTIONAL // output buffer
  378. ULONG OutBufferLen OPTIONAL // output buffer length
  379. );
  380. /*--
  381. NTSTATUS
  382. SerialMouseIoSyncIoctlEx(
  383. ULONG Ioctl, // io control code
  384. PDEVICE_OBJECT DeviceObject, // object to call
  385. PKEVENT Event, // event to wait on
  386. PIO_STATUS_BLOCK Iosb, // used inside IRP
  387. PVOID InBuffer, OPTIONAL // input buffer
  388. ULONG InBufferLen, OPTIONAL // input buffer length
  389. PVOID OutBuffer, OPTIONAL // output buffer
  390. ULONG OutBufferLen OPTIONAL // output buffer length
  391. );
  392. ++*/
  393. #define SerialMouseIoSyncIoctlEx(Ioctl, DeviceObject, Event, Iosb, \
  394. InBuffer, InBufferLen, OutBuffer, \
  395. OutBufferLen) \
  396. SerialMousepIoSyncIoctlEx(FALSE, Ioctl, DeviceObject, Event, Iosb, \
  397. InBuffer, InBufferLen, OutBuffer, \
  398. OutBufferLen)
  399. /*--
  400. NTSTATUS
  401. SerialMouseIoSyncInternalIoctlEx(
  402. ULONG Ioctl, // io control code
  403. PDEVICE_OBJECT DeviceObject, // object to call
  404. PKEVENT Event, // event to wait on
  405. PIO_STATUS_BLOCK Iosb, // used inside IRP
  406. PVOID InBuffer, OPTIONAL // input buffer
  407. ULONG InBufferLen, OPTIONAL // input buffer length
  408. PVOID OutBuffer, OPTIONAL // output buffer
  409. ULONG OutBufferLen OPTIONAL // output buffer length
  410. );
  411. ++*/
  412. #define SerialMouseIoSyncInternalIoctlEx(Ioctl, DeviceObject, Event, Iosb, \
  413. InBuffer, InBufferLen, OutBuffer, \
  414. OutBufferLen) \
  415. SerialMousepIoSyncIoctlEx(TRUE, Ioctl, DeviceObject, Event, Iosb, \
  416. InBuffer, InBufferLen, OutBuffer, \
  417. OutBufferLen)
  418. NTSTATUS
  419. SerialMouseReadSerialPort (
  420. PDEVICE_EXTENSION DeviceExtension,
  421. PCHAR ReadBuffer,
  422. USHORT Buflen,
  423. PUSHORT ActualBytesRead
  424. );
  425. NTSTATUS
  426. SerialMouseWriteSerialPort (
  427. PDEVICE_EXTENSION DeviceExtension,
  428. PCHAR WriteBuffer,
  429. ULONG NumBytes,
  430. PIO_STATUS_BLOCK IoStatusBlock
  431. );
  432. NTSTATUS
  433. SerialMouseWait (
  434. IN PDEVICE_EXTENSION DeviceExtension,
  435. IN LONG Timeout
  436. );
  437. NTSTATUS
  438. SerialMouseReadComplete (
  439. IN PDEVICE_OBJECT DeviceObject,
  440. IN PIRP Irp,
  441. IN PDEVICE_EXTENSION DeviceExtension
  442. );
  443. NTSTATUS
  444. SerialMouseStartRead (
  445. IN PDEVICE_EXTENSION DeviceExtension
  446. );
  447. //
  448. // ioctl.c and SerialMouse definitions
  449. //
  450. //
  451. // Function prototypes
  452. //
  453. NTSTATUS
  454. SerialMouseSetFifo(
  455. PDEVICE_EXTENSION DeviceExtension,
  456. UCHAR Value
  457. );
  458. NTSTATUS
  459. SerialMouseGetLineCtrl(
  460. PDEVICE_EXTENSION DeviceExtension,
  461. PSERIAL_LINE_CONTROL SerialLineControl
  462. );
  463. NTSTATUS
  464. SerialMouseSetLineCtrl(
  465. PDEVICE_EXTENSION DeviceExtension,
  466. PSERIAL_LINE_CONTROL SerialLineControl
  467. );
  468. NTSTATUS
  469. SerialMouseGetModemCtrl(
  470. PDEVICE_EXTENSION DeviceExtension,
  471. PULONG ModemCtrl
  472. );
  473. NTSTATUS
  474. SerialMouseSetModemCtrl(
  475. PDEVICE_EXTENSION DeviceExtension,
  476. ULONG Value,
  477. PULONG OldValue OPTIONAL
  478. );
  479. NTSTATUS
  480. SerialMouseGetBaudRate(
  481. PDEVICE_EXTENSION DeviceExtension,
  482. PULONG BaudRate
  483. );
  484. NTSTATUS
  485. SerialMouseSetBaudRate(
  486. PDEVICE_EXTENSION DeviceExtension,
  487. ULONG BaudRate
  488. );
  489. NTSTATUS
  490. SerialMouseReadChar(
  491. PDEVICE_EXTENSION DeviceExtension,
  492. PUCHAR Value
  493. );
  494. NTSTATUS
  495. SerialMouseFlushReadBuffer(
  496. PDEVICE_EXTENSION DeviceExtension
  497. );
  498. NTSTATUS
  499. SerialMouseWriteChar(
  500. PDEVICE_EXTENSION DeviceExtension,
  501. UCHAR Value
  502. );
  503. NTSTATUS
  504. SerialMouseWriteString(
  505. PDEVICE_EXTENSION DeviceExtension,
  506. PSZ Buffer
  507. );
  508. NTSTATUS
  509. SerialMouseSetWmiDataItem(
  510. IN PDEVICE_OBJECT DeviceObject,
  511. IN PIRP Irp,
  512. IN ULONG GuidIndex,
  513. IN ULONG InstanceIndex,
  514. IN ULONG DataItemId,
  515. IN ULONG BufferSize,
  516. IN PUCHAR Buffer
  517. );
  518. NTSTATUS
  519. SerialMouseSetWmiDataBlock(
  520. IN PDEVICE_OBJECT DeviceObject,
  521. IN PIRP Irp,
  522. IN ULONG GuidIndex,
  523. IN ULONG InstanceIndex,
  524. IN ULONG BufferSize,
  525. IN PUCHAR Buffer
  526. );
  527. NTSTATUS
  528. SerialMouseQueryWmiDataBlock(
  529. IN PDEVICE_OBJECT DeviceObject,
  530. IN PIRP Irp,
  531. IN ULONG GuidIndex,
  532. IN ULONG InstanceIndex,
  533. IN ULONG InstanceCount,
  534. IN OUT PULONG InstanceLengthArray,
  535. IN ULONG BufferAvail,
  536. OUT PUCHAR Buffer
  537. );
  538. NTSTATUS
  539. SerialMouseQueryWmiRegInfo(
  540. IN PDEVICE_OBJECT DeviceObject,
  541. OUT PULONG RegFlags,
  542. OUT PUNICODE_STRING InstanceName,
  543. OUT PUNICODE_STRING *RegistryPath,
  544. OUT PUNICODE_STRING MofResourceName,
  545. OUT PDEVICE_OBJECT *Pdo
  546. );
  547. extern WMIGUIDREGINFO WmiGuidList[1];
  548. #endif // _MOUSER_