1/*
2 * ntdd8042.h
3 *
4 * i8042 IOCTL interface.
5 *
6 * This file is part of the w32api package.
7 *
8 * Contributors:
9 *   Created by 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
23#ifndef _NTDD8042_
24#define _NTDD8042_
25
26#include "ntddkbd.h"
27#include "ntddmou.h"
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33#define IOCTL_INTERNAL_I8042_CONTROLLER_WRITE_BUFFER \
34  CTL_CODE(FILE_DEVICE_KEYBOARD, 0x0FF2, METHOD_NEITHER, FILE_ANY_ACCESS)
35
36#define IOCTL_INTERNAL_I8042_HOOK_KEYBOARD \
37  CTL_CODE(FILE_DEVICE_KEYBOARD, 0x0FF0, METHOD_NEITHER, FILE_ANY_ACCESS)
38
39#define IOCTL_INTERNAL_I8042_KEYBOARD_START_INFORMATION \
40  CTL_CODE(FILE_DEVICE_KEYBOARD, 0x0FF3, METHOD_NEITHER, FILE_ANY_ACCESS)
41
42#define IOCTL_INTERNAL_I8042_KEYBOARD_WRITE_BUFFER \
43  CTL_CODE(FILE_DEVICE_KEYBOARD, 0x0FF1, METHOD_NEITHER, FILE_ANY_ACCESS)
44
45#define IOCTL_INTERNAL_I8042_HOOK_MOUSE \
46  CTL_CODE(FILE_DEVICE_MOUSE, 0x0FF0, METHOD_NEITHER, FILE_ANY_ACCESS)
47
48#define IOCTL_INTERNAL_I8042_MOUSE_START_INFORMATION \
49  CTL_CODE(FILE_DEVICE_MOUSE, 0x0FF3, METHOD_NEITHER, FILE_ANY_ACCESS)
50
51#define IOCTL_INTERNAL_I8042_MOUSE_WRITE_BUFFER \
52  CTL_CODE(FILE_DEVICE_MOUSE, 0x0FF1, METHOD_NEITHER, FILE_ANY_ACCESS)
53
54#define I8042_POWER_SYS_BUTTON            0x0001
55#define I8042_SLEEP_SYS_BUTTON            0x0002
56#define I8042_WAKE_SYS_BUTTON             0x0004
57#define I8042_SYS_BUTTONS                 (I8042_POWER_SYS_BUTTON | \
58                                           I8042_SLEEP_SYS_BUTTON | \
59                                           I8042_WAKE_SYS_BUTTON)
60
61typedef enum _TRANSMIT_STATE {
62  Idle = 0,
63  SendingBytes
64} TRANSMIT_STATE;
65
66typedef struct _OUTPUT_PACKET {
67  PUCHAR  Bytes;
68  ULONG  CurrentByte;
69  ULONG  ByteCount;
70  TRANSMIT_STATE  State;
71} OUTPUT_PACKET, *POUTPUT_PACKET;
72
73typedef enum _KEYBOARD_SCAN_STATE {
74  Normal,
75  GotE0,
76  GotE1
77} KEYBOARD_SCAN_STATE, *PKEYBOARD_SCAN_STATE;
78
79typedef enum _MOUSE_STATE {
80  MouseIdle,
81  XMovement,
82  YMovement,
83  ZMovement,
84  MouseExpectingACK,
85  MouseResetting
86} MOUSE_STATE, *PMOUSE_STATE;
87
88typedef enum _MOUSE_RESET_SUBSTATE {
89	ExpectingReset,
90	ExpectingResetId,
91	ExpectingGetDeviceIdACK,
92	ExpectingGetDeviceIdValue,
93	ExpectingSetResolutionDefaultACK,
94	ExpectingSetResolutionDefaultValueACK,
95	ExpectingSetResolutionACK,
96	ExpectingSetResolutionValueACK,
97	ExpectingSetScaling1to1ACK,
98	ExpectingSetScaling1to1ACK2,
99	ExpectingSetScaling1to1ACK3,
100	ExpectingReadMouseStatusACK,
101	ExpectingReadMouseStatusByte1,
102	ExpectingReadMouseStatusByte2,
103	ExpectingReadMouseStatusByte3,
104	StartPnPIdDetection,
105	ExpectingLoopSetSamplingRateACK,
106	ExpectingLoopSetSamplingRateValueACK,
107	ExpectingPnpIdByte1,
108	ExpectingPnpIdByte2,
109	ExpectingPnpIdByte3,
110	ExpectingPnpIdByte4,
111	ExpectingPnpIdByte5,
112	ExpectingPnpIdByte6,
113	ExpectingPnpIdByte7,
114	EnableWheel,
115	Enable5Buttons,
116	ExpectingGetDeviceId2ACK,
117	ExpectingGetDeviceId2Value,
118	ExpectingSetSamplingRateACK,
119	ExpectingSetSamplingRateValueACK,
120	ExpectingEnableACK,
121	ExpectingFinalResolutionACK,
122	ExpectingFinalResolutionValueACK,
123	ExpectingGetDeviceIdDetectACK,
124	ExpectingGetDeviceIdDetectValue,
125	CustomHookStateMinimum = 100,
126	CustomHookStateMaximum = 999,
127	I8042ReservedMinimum = 1000
128} MOUSE_RESET_SUBSTATE, *PMOUSE_RESET_SUBSTATE;
129
130typedef struct _INTERNAL_I8042_START_INFORMATION {
131  ULONG  Size;
132  PKINTERRUPT  InterruptObject;
133  ULONG  Reserved[8];
134} INTERNAL_I8042_START_INFORMATION, *PINTERNAL_I8042_START_INFORMATION;
135
136typedef VOID
137(NTAPI *PI8042_ISR_WRITE_PORT)(
138  PVOID  Context,
139  UCHAR  Value);
140
141typedef VOID
142(NTAPI *PI8042_QUEUE_PACKET)(
143  PVOID  Context);
144
145typedef NTSTATUS
146(NTAPI *PI8042_SYNCH_READ_PORT) (
147  PVOID  Context,
148  PUCHAR  Value,
149  BOOLEAN  WaitForACK);
150
151typedef NTSTATUS
152(NTAPI *PI8042_SYNCH_WRITE_PORT)(
153  PVOID  Context,
154  UCHAR  Value,
155  BOOLEAN  WaitForACK);
156
157
158typedef NTSTATUS
159(NTAPI *PI8042_KEYBOARD_INITIALIZATION_ROUTINE)(
160  PVOID  InitializationContext,
161  PVOID  SynchFuncContext,
162  PI8042_SYNCH_READ_PORT  ReadPort,
163  PI8042_SYNCH_WRITE_PORT  WritePort,
164  PBOOLEAN  TurnTranslationOn);
165
166typedef BOOLEAN
167(NTAPI *PI8042_KEYBOARD_ISR)(
168  PVOID  IsrContext,
169  PKEYBOARD_INPUT_DATA  CurrentInput,
170  POUTPUT_PACKET  CurrentOutput,
171  UCHAR  StatusByte,
172  PUCHAR  Byte,
173  PBOOLEAN  ContinueProcessing,
174  PKEYBOARD_SCAN_STATE  ScanState);
175
176typedef struct _INTERNAL_I8042_HOOK_KEYBOARD {
177	PVOID  Context;
178	PI8042_KEYBOARD_INITIALIZATION_ROUTINE  InitializationRoutine;
179	PI8042_KEYBOARD_ISR  IsrRoutine;
180	PI8042_ISR_WRITE_PORT  IsrWritePort;
181	PI8042_QUEUE_PACKET  QueueKeyboardPacket;
182	PVOID  CallContext;
183} INTERNAL_I8042_HOOK_KEYBOARD, *PINTERNAL_I8042_HOOK_KEYBOARD;
184
185typedef BOOLEAN
186(NTAPI *PI8042_MOUSE_ISR)(
187  PVOID  IsrContext,
188  PMOUSE_INPUT_DATA  CurrentInput,
189  POUTPUT_PACKET  CurrentOutput,
190  UCHAR  StatusByte,
191  PUCHAR  Byte,
192  PBOOLEAN  ContinueProcessing,
193  PMOUSE_STATE  MouseState,
194  PMOUSE_RESET_SUBSTATE  ResetSubState);
195
196typedef struct _INTERNAL_I8042_HOOK_MOUSE {
197  PVOID  Context;
198  PI8042_MOUSE_ISR  IsrRoutine;
199  PI8042_ISR_WRITE_PORT  IsrWritePort;
200  PI8042_QUEUE_PACKET  QueueMousePacket;
201  PVOID  CallContext;
202} INTERNAL_I8042_HOOK_MOUSE, *PINTERNAL_I8042_HOOK_MOUSE;
203
204#ifdef __cplusplus
205}
206#endif
207
208#endif /* _NTDD8042_ */
209