ReactOS  0.4.15-dev-507-g90aff8d
i8042prt.c File Reference
#include "i8042prt.h"
#include <debug.h>
Include dependency graph for i8042prt.c:

Go to the source code of this file.

Functions

 _Dispatch_type_ (IRP_MJ_DEVICE_CONTROL)
 
VOID NTAPI i8042SendHookWorkItem (IN PDEVICE_OBJECT DeviceObject, IN PVOID Context)
 
static VOID NTAPI i8042StartIo (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
static BOOLEAN i8042PacketWrite (IN PPORT_DEVICE_EXTENSION DeviceExtension)
 
BOOLEAN i8042PacketIsr (IN PPORT_DEVICE_EXTENSION DeviceExtension, IN UCHAR Output)
 
NTSTATUS i8042StartPacket (IN PPORT_DEVICE_EXTENSION DeviceExtension, IN PFDO_DEVICE_EXTENSION FdoDeviceExtension, IN PUCHAR Bytes, IN ULONG ByteCount, IN PIRP Irp)
 
static NTSTATUS NTAPI i8042DeviceControl (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
static NTSTATUS NTAPI i8042InternalDeviceControl (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
static NTSTATUS NTAPI i8042Power (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
static NTSTATUS NTAPI i8042SystemControl (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS NTAPI DriverEntry (IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath)
 

Variables

static DRIVER_STARTIO i8042StartIo
 

Function Documentation

◆ _Dispatch_type_()

_Dispatch_type_ ( IRP_MJ_DEVICE_CONTROL  )

Definition at line 21 of file i8042prt.c.

35 {
37  PFDO_DEVICE_EXTENSION DeviceExtension = NULL;
38  PDEVICE_OBJECT Fdo = NULL;
39  ULONG DeviceExtensionSize;
41 
42  TRACE_(I8042PRT, "i8042AddDevice(%p %p)\n", DriverObject, Pdo);
43 
45 
46  if (Pdo == NULL)
47  {
48  /* We're getting a NULL Pdo at the first call as
49  * we are a legacy driver. Ignore it */
50  return STATUS_SUCCESS;
51  }
52 
53  /* Create new device object. As we don't know if the device would be a keyboard
54  * or a mouse, we have to allocate the biggest device extension. */
55  DeviceExtensionSize = MAX(sizeof(I8042_KEYBOARD_EXTENSION), sizeof(I8042_MOUSE_EXTENSION));
58  DeviceExtensionSize,
59  NULL,
60  Pdo->DeviceType,
62  TRUE,
63  &Fdo);
64  if (!NT_SUCCESS(Status))
65  {
66  WARN_(I8042PRT, "IoCreateDevice() failed with status 0x%08lx\n", Status);
67  goto cleanup;
68  }
69 
70  DeviceExtension = (PFDO_DEVICE_EXTENSION)Fdo->DeviceExtension;
71  RtlZeroMemory(DeviceExtension, DeviceExtensionSize);
72  DeviceExtension->Type = Unknown;
73  DeviceExtension->Fdo = Fdo;
74  DeviceExtension->Pdo = Pdo;
75  DeviceExtension->PortDeviceExtension = &DriverExtension->Port;
76  Status = IoAttachDeviceToDeviceStackSafe(Fdo, Pdo, &DeviceExtension->LowerDevice);
77  if (!NT_SUCCESS(Status))
78  {
79  WARN_(I8042PRT, "IoAttachDeviceToDeviceStackSafe() failed with status 0x%08lx\n", Status);
80  goto cleanup;
81  }
82 
84  &DriverExtension->DeviceListHead,
85  &DeviceExtension->ListEntry,
86  &DriverExtension->DeviceListLock);
87 
89  return STATUS_SUCCESS;
90 
91 cleanup:
92  if (DeviceExtension && DeviceExtension->LowerDevice)
93  IoDetachDevice(DeviceExtension->LowerDevice);
94  if (Fdo)
95  IoDeleteDevice(Fdo);
96  return Status;
97 }
#define DO_DEVICE_INITIALIZING
Definition: env_spec_w32.h:399
#define TRUE
Definition: types.h:120
_In_ PDEVICE_OBJECT Pdo
Definition: classpnp.h:301
PLIST_ENTRY NTAPI ExInterlockedInsertTailList(IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY ListEntry, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:140
LIST_ENTRY ListEntry
Definition: pci.h:83
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI IoDetachDevice(IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:1296
struct _FDO_DEVICE_EXTENSION * PFDO_DEVICE_EXTENSION
struct _I8042_DRIVER_EXTENSION * PI8042_DRIVER_EXTENSION
PPORT_DEVICE_EXTENSION PortDeviceExtension
Definition: i8042prt.h:134
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
#define TRACE_(x)
Definition: compat.h:66
NTSTATUS NTAPI IoAttachDeviceToDeviceStackSafe(IN PDEVICE_OBJECT SourceDevice, IN PDEVICE_OBJECT TargetDevice, IN OUT PDEVICE_OBJECT *AttachedToDeviceObject)
Definition: device.c:980
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
I8042_DEVICE_TYPE Type
Definition: i8042prt.h:122
PVOID NTAPI IoGetDriverObjectExtension(IN PDRIVER_OBJECT DriverObject, IN PVOID ClientIdentificationAddress)
Definition: driver.c:1857
PPCI_DRIVER_EXTENSION DriverExtension
Definition: pci.c:41
Status
Definition: gdiplustypes.h:24
T MAX(T a, T b)
Definition: polytest.cpp:85
PDEVICE_OBJECT Fdo
Definition: i8042prt.h:126
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
PDEVICE_OBJECT Pdo
Definition: i8042prt.h:128
unsigned int ULONG
Definition: retypes.h:1
NTSTATUS NTAPI IoCreateDevice(IN PDRIVER_OBJECT DriverObject, IN ULONG DeviceExtensionSize, IN PUNICODE_STRING DeviceName, IN DEVICE_TYPE DeviceType, IN ULONG DeviceCharacteristics, IN BOOLEAN Exclusive, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1031
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
char * cleanup(char *str)
Definition: wpickclick.c:99
#define FILE_DEVICE_SECURE_OPEN
Definition: cdrw_usr.h:46
PDEVICE_OBJECT LowerDevice
Definition: i8042prt.h:130
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define WARN_(ch,...)
Definition: debug.h:157

◆ DriverEntry()

NTSTATUS NTAPI DriverEntry ( IN PDRIVER_OBJECT  DriverObject,
IN PUNICODE_STRING  RegistryPath 
)

Definition at line 482 of file i8042prt.c.

485 {
488 
490  DriverObject,
491  DriverObject,
492  sizeof(I8042_DRIVER_EXTENSION),
494  if (!NT_SUCCESS(Status))
495  {
496  WARN_(I8042PRT, "IoAllocateDriverObjectExtension() failed with status 0x%08lx\n", Status);
497  return Status;
498  }
500  KeInitializeSpinLock(&DriverExtension->Port.SpinLock);
501  InitializeListHead(&DriverExtension->DeviceListHead);
502  KeInitializeSpinLock(&DriverExtension->DeviceListLock);
503 
506  RegistryPath,
507  &DriverExtension->RegistryPath);
508  if (!NT_SUCCESS(Status))
509  {
510  WARN_(I8042PRT, "DuplicateUnicodeString() failed with status 0x%08lx\n", Status);
511  return Status;
512  }
513 
515  if (!NT_SUCCESS(Status))
516  {
517  WARN_(I8042PRT, "ReadRegistryEntries() failed with status 0x%08lx\n", Status);
518  return Status;
519  }
520 
523 
532 
534 
535  return STATUS_SUCCESS;
536 }
static NTSTATUS NTAPI i8042SystemControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: i8042prt.c:474
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
NTSTATUS NTAPI IoAllocateDriverObjectExtension(IN PDRIVER_OBJECT DriverObject, IN PVOID ClientIdentificationAddress, IN ULONG DriverObjectExtensionSize, OUT PVOID *DriverObjectExtension)
Definition: driver.c:1779
NTSTATUS NTAPI i8042Pnp(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: pnp.c:675
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI i8042Create(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: createclose.c:18
NTSTATUS NTAPI i8042Close(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: createclose.c:46
DRIVER_ADD_DEVICE i8042AddDevice
Definition: i8042prt.h:324
static NTSTATUS NTAPI i8042InternalDeviceControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: i8042prt.c:411
PDRIVER_EXTENSION DriverExtension
Definition: iotypes.h:2176
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
Definition: kefuncs.h:238
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
#define RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE
Definition: isapnp.h:82
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static DRIVER_STARTIO i8042StartIo
Definition: i8042prt.c:20
NTSTATUS DuplicateUnicodeString(IN ULONG Flags, IN PCUNICODE_STRING SourceString, OUT PUNICODE_STRING DestinationString)
Definition: misc.c:72
#define IRP_MJ_INTERNAL_DEVICE_CONTROL
#define IRP_MJ_POWER
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
NTSTATUS NTAPI i8042Cleanup(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: createclose.c:32
PPCI_DRIVER_EXTENSION DriverExtension
Definition: pci.c:41
#define IRP_MJ_SYSTEM_CONTROL
Status
Definition: gdiplustypes.h:24
PDRIVER_ADD_DEVICE AddDevice
Definition: iotypes.h:2114
static NTSTATUS NTAPI i8042DeviceControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: i8042prt.c:390
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
NTSTATUS ReadRegistryEntries(IN PUNICODE_STRING RegistryPath, OUT PI8042_SETTINGS Settings)
Definition: registry.c:21
static NTSTATUS NTAPI i8042Power(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: i8042prt.c:461
#define IRP_MJ_CLEANUP
PDRIVER_DISPATCH MajorFunction[IRP_MJ_MAXIMUM_FUNCTION+1]
Definition: iotypes.h:2183
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
_In_ PUNICODE_STRING RegistryPath
Definition: wmip.h:28
VOID NTAPI i8042InitializeHwHacks(VOID)
Definition: hwhacks.c:183
PDRIVER_STARTIO DriverStartIo
Definition: iotypes.h:2181
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define WARN_(ch,...)
Definition: debug.h:157
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52

◆ i8042DeviceControl()

static NTSTATUS NTAPI i8042DeviceControl ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)
static

Definition at line 390 of file i8042prt.c.

393 {
394  PFDO_DEVICE_EXTENSION DeviceExtension;
395 
396  TRACE_(I8042PRT, "i8042DeviceControl(%p %p)\n", DeviceObject, Irp);
398 
399  switch (DeviceExtension->Type)
400  {
401  case Keyboard:
403  default:
404  Irp->IoStatus.Status = STATUS_INVALID_DEVICE_REQUEST;
407  }
408 }
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
DRIVER_DISPATCH i8042KbdDeviceControl
Definition: i8042prt.h:316
struct _FDO_DEVICE_EXTENSION * PFDO_DEVICE_EXTENSION
PVOID DeviceExtension
Definition: env_spec_w32.h:418
#define IoCompleteRequest
Definition: irp.c:1240
switch(r->id)
Definition: btrfs.c:2980
#define TRACE_(x)
Definition: compat.h:66
I8042_DEVICE_TYPE Type
Definition: i8042prt.h:122
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1569
#define IO_NO_INCREMENT
Definition: iotypes.h:568

Referenced by DriverEntry().

◆ i8042InternalDeviceControl()

static NTSTATUS NTAPI i8042InternalDeviceControl ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)
static

Definition at line 411 of file i8042prt.c.

414 {
415  PFDO_DEVICE_EXTENSION DeviceExtension;
418 
419  TRACE_(I8042PRT, "i8042InternalDeviceControl(%p %p)\n", DeviceObject, Irp);
421 
422  switch (DeviceExtension->Type)
423  {
424  case Unknown:
425  {
426  ControlCode = IoGetCurrentIrpStackLocation(Irp)->Parameters.DeviceIoControl.IoControlCode;
427  switch (ControlCode)
428  {
431  break;
434  break;
435  default:
436  ERR_(I8042PRT, "Unknown IO control code 0x%lx\n", ControlCode);
437  ASSERT(FALSE);
439  break;
440  }
441  break;
442  }
443  case Keyboard:
445  break;
446  case Mouse:
448  break;
449  default:
450  ERR_(I8042PRT, "Unknown FDO type %u\n", DeviceExtension->Type);
451  ASSERT(FALSE);
454  break;
455  }
456 
457  return Status;
458 }
_In_ PIRP Irp
Definition: csq.h:116
#define ERR_(ch,...)
Definition: debug.h:156
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
struct _FDO_DEVICE_EXTENSION * PFDO_DEVICE_EXTENSION
#define STATUS_INTERNAL_ERROR
Definition: ntstatus.h:451
PVOID DeviceExtension
Definition: env_spec_w32.h:418
#define IoCompleteRequest
Definition: irp.c:1240
_IRQL_requires_same_ typedef _In_ ULONG ControlCode
Definition: wmitypes.h:55
switch(r->id)
Definition: btrfs.c:2980
#define TRACE_(x)
Definition: compat.h:66
#define IOCTL_INTERNAL_KEYBOARD_CONNECT
Definition: kbdmou.h:56
I8042_DEVICE_TYPE Type
Definition: i8042prt.h:122
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define IOCTL_INTERNAL_MOUSE_CONNECT
Definition: kbdmou.h:68
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1569
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:568
DRIVER_DISPATCH i8042MouInternalDeviceControl
Definition: i8042prt.h:367
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2774
DRIVER_DISPATCH i8042KbdInternalDeviceControl
Definition: i8042prt.h:318

Referenced by DriverEntry().

◆ i8042PacketIsr()

BOOLEAN i8042PacketIsr ( IN PPORT_DEVICE_EXTENSION  DeviceExtension,
IN UCHAR  Output 
)

Definition at line 271 of file i8042prt.c.

274 {
275  if (DeviceExtension->Packet.State == Idle)
276  return FALSE;
277 
278  switch (Output)
279  {
280  case KBD_RESEND:
281  DeviceExtension->PacketResends++;
282  if (DeviceExtension->PacketResends > DeviceExtension->Settings.ResendIterations)
283  {
284  DeviceExtension->Packet.State = Idle;
285  DeviceExtension->PacketComplete = TRUE;
286  DeviceExtension->PacketResult = STATUS_IO_TIMEOUT;
287  DeviceExtension->PacketResends = 0;
288  return TRUE;
289  }
290  DeviceExtension->Packet.CurrentByte--;
291  break;
292 
293  case KBD_NACK:
294  DeviceExtension->Packet.State = Idle;
295  DeviceExtension->PacketComplete = TRUE;
296  DeviceExtension->PacketResult = STATUS_UNEXPECTED_IO_ERROR;
297  DeviceExtension->PacketResends = 0;
298  return TRUE;
299 
300  default:
301  DeviceExtension->PacketResends = 0;
302  }
303 
304  if (DeviceExtension->Packet.CurrentByte >= DeviceExtension->Packet.ByteCount)
305  {
306  DeviceExtension->Packet.State = Idle;
307  DeviceExtension->PacketComplete = TRUE;
308  DeviceExtension->PacketResult = STATUS_SUCCESS;
309  return TRUE;
310  }
311 
312  if (!i8042PacketWrite(DeviceExtension))
313  {
314  DeviceExtension->Packet.State = Idle;
315  DeviceExtension->PacketComplete = TRUE;
316  DeviceExtension->PacketResult = STATUS_IO_TIMEOUT;
317  return TRUE;
318  }
319  DeviceExtension->Packet.CurrentByte++;
320 
321  return TRUE;
322 }
#define TRUE
Definition: types.h:120
static BOOLEAN i8042PacketWrite(IN PPORT_DEVICE_EXTENSION DeviceExtension)
Definition: i8042prt.c:248
Definition: ntdd8042.h:62
Definition: arc.h:85
#define KBD_RESEND
Definition: i8042prt.h:244
#define STATUS_IO_TIMEOUT
Definition: udferr_usr.h:163
#define STATUS_UNEXPECTED_IO_ERROR
Definition: ntstatus.h:455
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define KBD_NACK
Definition: i8042prt.h:243

Referenced by i8042KbdInterruptService(), and i8042MouInterruptService().

◆ i8042PacketWrite()

static BOOLEAN i8042PacketWrite ( IN PPORT_DEVICE_EXTENSION  DeviceExtension)
static

Definition at line 248 of file i8042prt.c.

250 {
251  UCHAR Port = DeviceExtension->PacketPort;
252 
253  if (Port)
254  {
255  if (!i8042Write(DeviceExtension,
256  DeviceExtension->ControlPort,
257  Port))
258  {
259  /* something is really wrong! */
260  WARN_(I8042PRT, "Failed to send packet byte!\n");
261  return FALSE;
262  }
263  }
264 
265  return i8042Write(DeviceExtension,
266  DeviceExtension->DataPort,
267  DeviceExtension->Packet.Bytes[DeviceExtension->Packet.CurrentByte]);
268 }
CPPORT Port[4]
Definition: headless.c:34
BOOLEAN i8042Write(IN PPORT_DEVICE_EXTENSION DeviceExtension, IN PUCHAR addr, IN UCHAR data)
Definition: readwrite.c:199
unsigned char UCHAR
Definition: xmlstorage.h:181
#define WARN_(ch,...)
Definition: debug.h:157

Referenced by i8042PacketIsr(), and i8042StartPacket().

◆ i8042Power()

static NTSTATUS NTAPI i8042Power ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)
static

Definition at line 461 of file i8042prt.c.

464 {
466  PDEVICE_OBJECT LowerDevice = DeviceExtension->LowerDevice;
467 
470  return PoCallDriver(LowerDevice, Irp);
471 }
_In_ PIRP Irp
Definition: csq.h:116
PVOID DeviceExtension
Definition: env_spec_w32.h:418
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1569
VOID NTAPI PoStartNextPowerIrp(IN PIRP Irp)
Definition: power.c:737
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
PDEVICE_OBJECT LowerDevice
Definition: i8042prt.h:130

Referenced by DriverEntry().

◆ i8042SendHookWorkItem()

VOID NTAPI i8042SendHookWorkItem ( IN PDEVICE_OBJECT  DeviceObject,
IN PVOID  Context 
)

Definition at line 100 of file i8042prt.c.

103 {
104  PI8042_HOOK_WORKITEM WorkItemData;
105  PFDO_DEVICE_EXTENSION FdoDeviceExtension;
106  PPORT_DEVICE_EXTENSION PortDeviceExtension;
107  PDEVICE_OBJECT TopOfStack = NULL;
112  KEVENT Event;
113  PIRP NewIrp;
115 
116  TRACE_(I8042PRT, "i8042SendHookWorkItem(%p %p)\n", DeviceObject, Context);
117 
118  WorkItemData = (PI8042_HOOK_WORKITEM)Context;
119  FdoDeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
120  PortDeviceExtension = FdoDeviceExtension->PortDeviceExtension;
121 
122  switch (FdoDeviceExtension->Type)
123  {
124  case Keyboard:
125  {
126  PI8042_KEYBOARD_EXTENSION DeviceExtension;
127  DeviceExtension = (PI8042_KEYBOARD_EXTENSION)FdoDeviceExtension;
129  InputBuffer = &DeviceExtension->KeyboardHook;
131  break;
132  }
133  case Mouse:
134  {
135  PI8042_MOUSE_EXTENSION DeviceExtension;
136  DeviceExtension = (PI8042_MOUSE_EXTENSION)FdoDeviceExtension;
138  InputBuffer = &DeviceExtension->MouseHook;
140  break;
141  }
142  default:
143  {
144  ERR_(I8042PRT, "Unknown FDO type %u\n", FdoDeviceExtension->Type);
145  ASSERT(FALSE);
146  WorkItemData->Irp->IoStatus.Status = STATUS_INTERNAL_ERROR;
147  goto cleanup;
148  }
149  }
150 
153 
156  TopOfStack,
157  InputBuffer,
159  NULL,
160  0,
161  TRUE,
162  &Event,
163  &IoStatus);
164 
165  if (!NewIrp)
166  {
167  WARN_(I8042PRT, "IoBuildDeviceIoControlRequest() failed\n");
169  goto cleanup;
170  }
171 
172  Status = IoCallDriver(TopOfStack, NewIrp);
173  if (Status == STATUS_PENDING)
174  {
176  &Event,
177  Executive,
178  KernelMode,
179  FALSE,
180  NULL);
181  Status = IoStatus.Status;
182  }
183  if (!NT_SUCCESS(Status))
184  {
185  WARN_(I8042PRT, "IoCallDriver() failed with status 0x%08lx\n", Status);
186  goto cleanup;
187  }
188 
189  if (FdoDeviceExtension->Type == Keyboard)
190  {
191  PI8042_KEYBOARD_EXTENSION DeviceExtension;
192 
193  DeviceExtension = (PI8042_KEYBOARD_EXTENSION)FdoDeviceExtension;
194  /* Call the hooked initialization if it exists */
195  if (DeviceExtension->KeyboardHook.InitializationRoutine)
196  {
197  Status = DeviceExtension->KeyboardHook.InitializationRoutine(
198  DeviceExtension->KeyboardHook.Context,
199  PortDeviceExtension,
202  FALSE);
203  if (!NT_SUCCESS(Status))
204  {
205  WARN_(I8042PRT, "KeyboardHook.InitializationRoutine() failed with status 0x%08lx\n", Status);
206  WorkItemData->Irp->IoStatus.Status = Status;
207  goto cleanup;
208  }
209  }
210  }
211 
212  WorkItemData->Irp->IoStatus.Status = STATUS_SUCCESS;
213 
214 cleanup:
215  if (TopOfStack != NULL)
216  ObDereferenceObject(TopOfStack);
217  WorkItemData->Irp->IoStatus.Information = 0;
218  IoCompleteRequest(WorkItemData->Irp, IO_NO_INCREMENT);
219 
220  IoFreeWorkItem(WorkItemData->WorkItem);
221  ExFreePoolWithTag(WorkItemData, I8042PRT_TAG);
222 }
#define TRUE
Definition: types.h:120
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG IoControlCode
Definition: fltkernel.h:1383
PIO_WORKITEM WorkItem
Definition: i8042prt.h:203
IN PLARGE_INTEGER IN ULONG IN BOOLEAN IN ULONG IN BOOLEAN OUT PIO_STATUS_BLOCK IoStatus
Definition: fatprocs.h:2659
#define ERR_(ch,...)
Definition: debug.h:156
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
IO_STATUS_BLOCK IoStatus
struct _INTERNAL_I8042_HOOK_KEYBOARD INTERNAL_I8042_HOOK_KEYBOARD
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
VOID NTAPI IoFreeWorkItem(IN PIO_WORKITEM IoWorkItem)
Definition: iowork.c:64
struct _I8042_KEYBOARD_EXTENSION * PI8042_KEYBOARD_EXTENSION
Definition: i8042prt.h:63
struct _FDO_DEVICE_EXTENSION * PFDO_DEVICE_EXTENSION
#define I8042PRT_TAG
Definition: i8042prt.h:12
CHAR InputBuffer[80]
Definition: conmgr.c:33
#define STATUS_INTERNAL_ERROR
Definition: ntstatus.h:451
PPORT_DEVICE_EXTENSION PortDeviceExtension
Definition: i8042prt.h:134
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:437
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
switch(r->id)
Definition: btrfs.c:2980
PDEVICE_OBJECT NTAPI IoGetAttachedDeviceReference(PDEVICE_OBJECT DeviceObject)
Definition: device.c:1406
#define TRACE_(x)
Definition: compat.h:66
INTERNAL_I8042_HOOK_KEYBOARD KeyboardHook
Definition: i8042prt.h:141
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
NTSTATUS NTAPI i8042SynchWritePortKbd(IN PVOID Context, IN UCHAR Value, IN BOOLEAN WaitForAck)
Definition: keyboard.c:87
I8042_DEVICE_TYPE Type
Definition: i8042prt.h:122
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
INTERNAL_I8042_HOOK_MOUSE MouseHook
Definition: i8042prt.h:179
NTSTATUS NTAPI i8042SynchReadPort(IN PVOID Context, OUT PUCHAR Value, IN BOOLEAN WaitForAck)
Definition: readwrite.c:125
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG _In_ ULONG InputBufferLength
Definition: fltkernel.h:1372
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1569
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define IOCTL_INTERNAL_I8042_HOOK_MOUSE
Definition: ntdd8042.h:45
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
PIRP NTAPI IoBuildDeviceIoControlRequest(IN ULONG IoControlCode, IN PDEVICE_OBJECT DeviceObject, IN PVOID InputBuffer, IN ULONG InputBufferLength, IN PVOID OutputBuffer, IN ULONG OutputBufferLength, IN BOOLEAN InternalDeviceIoControl, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:881
struct _I8042_HOOK_WORKITEM * PI8042_HOOK_WORKITEM
#define IOCTL_INTERNAL_I8042_HOOK_KEYBOARD
Definition: ntdd8042.h:36
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:568
char * cleanup(char *str)
Definition: wpickclick.c:99
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
return STATUS_SUCCESS
Definition: btrfs.c:3014
struct _INTERNAL_I8042_HOOK_MOUSE INTERNAL_I8042_HOOK_MOUSE
OUT PI8042_KEYBOARD_INITIALIZATION_ROUTINE InitializationRoutine
Definition: ntdd8042.h:178
#define WARN_(ch,...)
Definition: debug.h:157
struct _I8042_MOUSE_EXTENSION * PI8042_MOUSE_EXTENSION
Definition: i8042prt.h:65

◆ i8042StartIo()

static VOID NTAPI i8042StartIo ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)
static

Definition at line 225 of file i8042prt.c.

228 {
229  PFDO_DEVICE_EXTENSION DeviceExtension;
230 
232  switch (DeviceExtension->Type)
233  {
234  case Keyboard:
236  break;
237  default:
238  ERR_(I8042PRT, "Unknown FDO type %u\n", DeviceExtension->Type);
239  ASSERT(FALSE);
240  break;
241  }
242 }
_In_ PIRP Irp
Definition: csq.h:116
#define ERR_(ch,...)
Definition: debug.h:156
struct _FDO_DEVICE_EXTENSION * PFDO_DEVICE_EXTENSION
DRIVER_STARTIO i8042KbdStartIo
Definition: i8042prt.h:314
PVOID DeviceExtension
Definition: env_spec_w32.h:418
switch(r->id)
Definition: btrfs.c:2980
I8042_DEVICE_TYPE Type
Definition: i8042prt.h:122
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1569

◆ i8042StartPacket()

NTSTATUS i8042StartPacket ( IN PPORT_DEVICE_EXTENSION  DeviceExtension,
IN PFDO_DEVICE_EXTENSION  FdoDeviceExtension,
IN PUCHAR  Bytes,
IN ULONG  ByteCount,
IN PIRP  Irp 
)

Definition at line 329 of file i8042prt.c.

335 {
336  KIRQL Irql;
338 
339  Irql = KeAcquireInterruptSpinLock(DeviceExtension->HighestDIRQLInterrupt);
340 
341  if (DeviceExtension->Packet.State != Idle)
342  {
344  goto done;
345  }
346 
347  switch (FdoDeviceExtension->Type)
348  {
349  case Keyboard: DeviceExtension->PacketPort = 0; break;
350  case Mouse: DeviceExtension->PacketPort = CTRL_WRITE_MOUSE; break;
351  default:
352  ERR_(I8042PRT, "Unknown FDO type %u\n", FdoDeviceExtension->Type);
353  ASSERT(FALSE);
355  goto done;
356  }
357 
358  DeviceExtension->Packet.Bytes = Bytes;
359  DeviceExtension->Packet.CurrentByte = 0;
360  DeviceExtension->Packet.ByteCount = ByteCount;
361  DeviceExtension->Packet.State = SendingBytes;
362  DeviceExtension->PacketResult = Status = STATUS_PENDING;
363  DeviceExtension->CurrentIrp = Irp;
364  DeviceExtension->CurrentIrpDevice = FdoDeviceExtension->Fdo;
365 
366  if (!i8042PacketWrite(DeviceExtension))
367  {
369  DeviceExtension->Packet.State = Idle;
370  DeviceExtension->PacketResult = STATUS_ABANDONED;
371  goto done;
372  }
373 
374  DeviceExtension->Packet.CurrentByte++;
375 
376 done:
377  KeReleaseInterruptSpinLock(DeviceExtension->HighestDIRQLInterrupt, Irql);
378 
379  if (Status != STATUS_PENDING)
380  {
381  DeviceExtension->CurrentIrp = NULL;
382  DeviceExtension->CurrentIrpDevice = NULL;
383  Irp->IoStatus.Status = Status;
385  }
386  return Status;
387 }
_In_ PIRP Irp
Definition: csq.h:116
#define ERR_(ch,...)
Definition: debug.h:156
LONG NTSTATUS
Definition: precomp.h:26
_In_ UINT Bytes
Definition: mmcopy.h:9
_Out_ PKIRQL Irql
Definition: csq.h:179
#define STATUS_INTERNAL_ERROR
Definition: ntstatus.h:451
UCHAR KIRQL
Definition: env_spec_w32.h:591
static BOOLEAN i8042PacketWrite(IN PPORT_DEVICE_EXTENSION DeviceExtension)
Definition: i8042prt.c:248
VOID NTAPI KeReleaseInterruptSpinLock(IN PKINTERRUPT Interrupt, IN KIRQL OldIrql)
Definition: spinlock.c:165
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
Definition: ntdd8042.h:62
#define STATUS_PENDING
Definition: ntstatus.h:82
KIRQL NTAPI KeAcquireInterruptSpinLock(IN PKINTERRUPT Interrupt)
Definition: spinlock.c:148
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS _In_ LARGE_INTEGER ByteCount
Definition: iotypes.h:1063
Status
Definition: gdiplustypes.h:24
#define STATUS_DEVICE_BUSY
Definition: udferr_usr.h:129
#define STATUS_IO_TIMEOUT
Definition: udferr_usr.h:163
#define IO_NO_INCREMENT
Definition: iotypes.h:568
#define STATUS_ABANDONED
Definition: ntstatus.h:75
#define CTRL_WRITE_MOUSE
Definition: i8042prt.h:228

Referenced by i8042KbdStartIo().

◆ i8042SystemControl()

static NTSTATUS NTAPI i8042SystemControl ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)
static

Definition at line 474 of file i8042prt.c.

477 {
479 }
_In_ PIRP Irp
Definition: csq.h:116
DRIVER_DISPATCH ForwardIrpAndForget
Definition: i8042prt.h:341
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1569

Referenced by DriverEntry().

Variable Documentation

◆ i8042StartIo

DRIVER_STARTIO i8042StartIo
static

Definition at line 20 of file i8042prt.c.

Referenced by DriverEntry().