ntdd8042.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /*
  2. * ntdd8042.h
  3. *
  4. * i8042 IOCTL interface.
  5. *
  6. * This file is part of the mingw-w64 runtime package.
  7. * No warranty is given; refer to the file DISCLAIMER within this package.
  8. *
  9. * Initial contributor is Casper S. Hornstrup <chorns@users.sourceforge.net>
  10. *
  11. * THIS SOFTWARE IS NOT COPYRIGHTED
  12. *
  13. * This source code is offered for use in the public domain. You may
  14. * use, modify or distribute it freely.
  15. *
  16. * This code is distributed in the hope that it will be useful but
  17. * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
  18. * DISCLAIMED. This includes but is not limited to warranties of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  20. *
  21. */
  22. #ifndef _NTDD8042_
  23. #define _NTDD8042_
  24. #include <winapifamily.h>
  25. #if WINAPI_FAMILY_PARTITION (WINAPI_PARTITION_DESKTOP)
  26. #include "ntddkbd.h"
  27. #include "ntddmou.h"
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. #define IOCTL_INTERNAL_I8042_CONTROLLER_WRITE_BUFFER \
  32. CTL_CODE(FILE_DEVICE_KEYBOARD, 0x0FF2, METHOD_NEITHER, FILE_ANY_ACCESS)
  33. #define IOCTL_INTERNAL_I8042_HOOK_KEYBOARD \
  34. CTL_CODE(FILE_DEVICE_KEYBOARD, 0x0FF0, METHOD_NEITHER, FILE_ANY_ACCESS)
  35. #define IOCTL_INTERNAL_I8042_KEYBOARD_START_INFORMATION \
  36. CTL_CODE(FILE_DEVICE_KEYBOARD, 0x0FF3, METHOD_NEITHER, FILE_ANY_ACCESS)
  37. #define IOCTL_INTERNAL_I8042_KEYBOARD_WRITE_BUFFER \
  38. CTL_CODE(FILE_DEVICE_KEYBOARD, 0x0FF1, METHOD_NEITHER, FILE_ANY_ACCESS)
  39. #define IOCTL_INTERNAL_I8042_HOOK_MOUSE \
  40. CTL_CODE(FILE_DEVICE_MOUSE, 0x0FF0, METHOD_NEITHER, FILE_ANY_ACCESS)
  41. #define IOCTL_INTERNAL_I8042_MOUSE_START_INFORMATION \
  42. CTL_CODE(FILE_DEVICE_MOUSE, 0x0FF3, METHOD_NEITHER, FILE_ANY_ACCESS)
  43. #define IOCTL_INTERNAL_I8042_MOUSE_WRITE_BUFFER \
  44. CTL_CODE(FILE_DEVICE_MOUSE, 0x0FF1, METHOD_NEITHER, FILE_ANY_ACCESS)
  45. #define I8042_POWER_SYS_BUTTON 0x0001
  46. #define I8042_SLEEP_SYS_BUTTON 0x0002
  47. #define I8042_WAKE_SYS_BUTTON 0x0004
  48. #define I8042_SYS_BUTTONS (I8042_POWER_SYS_BUTTON | \
  49. I8042_SLEEP_SYS_BUTTON | \
  50. I8042_WAKE_SYS_BUTTON)
  51. typedef enum _TRANSMIT_STATE {
  52. Idle = 0,
  53. SendingBytes
  54. } TRANSMIT_STATE;
  55. typedef struct _OUTPUT_PACKET {
  56. PUCHAR Bytes;
  57. ULONG CurrentByte;
  58. ULONG ByteCount;
  59. TRANSMIT_STATE State;
  60. } OUTPUT_PACKET, *POUTPUT_PACKET;
  61. typedef enum _KEYBOARD_SCAN_STATE {
  62. Normal,
  63. GotE0,
  64. GotE1
  65. } KEYBOARD_SCAN_STATE, *PKEYBOARD_SCAN_STATE;
  66. typedef enum _MOUSE_STATE {
  67. MouseIdle,
  68. XMovement,
  69. YMovement,
  70. ZMovement,
  71. MouseExpectingACK,
  72. MouseResetting
  73. } MOUSE_STATE, *PMOUSE_STATE;
  74. typedef enum _MOUSE_RESET_SUBSTATE {
  75. ExpectingReset,
  76. ExpectingResetId,
  77. ExpectingGetDeviceIdACK,
  78. ExpectingGetDeviceIdValue,
  79. ExpectingSetResolutionDefaultACK,
  80. ExpectingSetResolutionDefaultValueACK,
  81. ExpectingSetResolutionACK,
  82. ExpectingSetResolutionValueACK,
  83. ExpectingSetScaling1to1ACK,
  84. ExpectingSetScaling1to1ACK2,
  85. ExpectingSetScaling1to1ACK3,
  86. ExpectingReadMouseStatusACK,
  87. ExpectingReadMouseStatusByte1,
  88. ExpectingReadMouseStatusByte2,
  89. ExpectingReadMouseStatusByte3,
  90. StartPnPIdDetection,
  91. ExpectingLoopSetSamplingRateACK,
  92. ExpectingLoopSetSamplingRateValueACK,
  93. ExpectingPnpIdByte1,
  94. ExpectingPnpIdByte2,
  95. ExpectingPnpIdByte3,
  96. ExpectingPnpIdByte4,
  97. ExpectingPnpIdByte5,
  98. ExpectingPnpIdByte6,
  99. ExpectingPnpIdByte7,
  100. EnableWheel,
  101. Enable5Buttons,
  102. ExpectingGetDeviceId2ACK,
  103. ExpectingGetDeviceId2Value,
  104. ExpectingSetSamplingRateACK,
  105. ExpectingSetSamplingRateValueACK,
  106. ExpectingEnableACK,
  107. ExpectingFinalResolutionACK,
  108. ExpectingFinalResolutionValueACK,
  109. ExpectingGetDeviceIdDetectACK,
  110. ExpectingGetDeviceIdDetectValue,
  111. CustomHookStateMinimum = 100,
  112. CustomHookStateMaximum = 999,
  113. I8042ReservedMinimum = 1000
  114. } MOUSE_RESET_SUBSTATE, *PMOUSE_RESET_SUBSTATE;
  115. typedef struct _INTERNAL_I8042_START_INFORMATION {
  116. ULONG Size;
  117. PKINTERRUPT InterruptObject;
  118. ULONG Reserved[8];
  119. } INTERNAL_I8042_START_INFORMATION, *PINTERNAL_I8042_START_INFORMATION;
  120. typedef VOID
  121. (NTAPI *PI8042_ISR_WRITE_PORT)(
  122. PVOID Context,
  123. UCHAR Value);
  124. typedef VOID
  125. (NTAPI *PI8042_QUEUE_PACKET)(
  126. PVOID Context);
  127. typedef NTSTATUS
  128. (NTAPI *PI8042_SYNCH_READ_PORT) (
  129. PVOID Context,
  130. PUCHAR Value,
  131. BOOLEAN WaitForACK);
  132. typedef NTSTATUS
  133. (NTAPI *PI8042_SYNCH_WRITE_PORT)(
  134. PVOID Context,
  135. UCHAR Value,
  136. BOOLEAN WaitForACK);
  137. typedef NTSTATUS
  138. (NTAPI *PI8042_KEYBOARD_INITIALIZATION_ROUTINE)(
  139. PVOID InitializationContext,
  140. PVOID SynchFuncContext,
  141. PI8042_SYNCH_READ_PORT ReadPort,
  142. PI8042_SYNCH_WRITE_PORT WritePort,
  143. PBOOLEAN TurnTranslationOn);
  144. typedef BOOLEAN
  145. (NTAPI *PI8042_KEYBOARD_ISR)(
  146. PVOID IsrContext,
  147. PKEYBOARD_INPUT_DATA CurrentInput,
  148. POUTPUT_PACKET CurrentOutput,
  149. UCHAR StatusByte,
  150. PUCHAR Byte,
  151. PBOOLEAN ContinueProcessing,
  152. PKEYBOARD_SCAN_STATE ScanState);
  153. typedef struct _INTERNAL_I8042_HOOK_KEYBOARD {
  154. PVOID Context;
  155. PI8042_KEYBOARD_INITIALIZATION_ROUTINE InitializationRoutine;
  156. PI8042_KEYBOARD_ISR IsrRoutine;
  157. PI8042_ISR_WRITE_PORT IsrWritePort;
  158. PI8042_QUEUE_PACKET QueueKeyboardPacket;
  159. PVOID CallContext;
  160. } INTERNAL_I8042_HOOK_KEYBOARD, *PINTERNAL_I8042_HOOK_KEYBOARD;
  161. typedef BOOLEAN
  162. (NTAPI *PI8042_MOUSE_ISR)(
  163. PVOID IsrContext,
  164. PMOUSE_INPUT_DATA CurrentInput,
  165. POUTPUT_PACKET CurrentOutput,
  166. UCHAR StatusByte,
  167. PUCHAR Byte,
  168. PBOOLEAN ContinueProcessing,
  169. PMOUSE_STATE MouseState,
  170. PMOUSE_RESET_SUBSTATE ResetSubState);
  171. typedef struct _INTERNAL_I8042_HOOK_MOUSE {
  172. PVOID Context;
  173. PI8042_MOUSE_ISR IsrRoutine;
  174. PI8042_ISR_WRITE_PORT IsrWritePort;
  175. PI8042_QUEUE_PACKET QueueMousePacket;
  176. PVOID CallContext;
  177. } INTERNAL_I8042_HOOK_MOUSE, *PINTERNAL_I8042_HOOK_MOUSE;
  178. #ifdef __cplusplus
  179. }
  180. #endif
  181. #endif
  182. #endif /* _NTDD8042_ */