ReactOS  0.4.15-dev-313-g8fde48b
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 IrpStub (IN PDEVICE_OBJECT DeviceObject, 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
 
static DRIVER_DISPATCH IrpStub
 

Function Documentation

◆ _Dispatch_type_()

_Dispatch_type_ ( IRP_MJ_DEVICE_CONTROL  )

Definition at line 22 of file i8042prt.c.

36 {
38  PFDO_DEVICE_EXTENSION DeviceExtension = NULL;
39  PDEVICE_OBJECT Fdo = NULL;
40  ULONG DeviceExtensionSize;
42 
43  TRACE_(I8042PRT, "i8042AddDevice(%p %p)\n", DriverObject, Pdo);
44 
46 
47  if (Pdo == NULL)
48  {
49  /* We're getting a NULL Pdo at the first call as
50  * we are a legacy driver. Ignore it */
51  return STATUS_SUCCESS;
52  }
53 
54  /* Create new device object. As we don't know if the device would be a keyboard
55  * or a mouse, we have to allocate the biggest device extension. */
56  DeviceExtensionSize = MAX(sizeof(I8042_KEYBOARD_EXTENSION), sizeof(I8042_MOUSE_EXTENSION));
59  DeviceExtensionSize,
60  NULL,
61  Pdo->DeviceType,
63  TRUE,
64  &Fdo);
65  if (!NT_SUCCESS(Status))
66  {
67  WARN_(I8042PRT, "IoCreateDevice() failed with status 0x%08lx\n", Status);
68  goto cleanup;
69  }
70 
71  DeviceExtension = (PFDO_DEVICE_EXTENSION)Fdo->DeviceExtension;
72  RtlZeroMemory(DeviceExtension, DeviceExtensionSize);
73  DeviceExtension->Type = Unknown;
74  DeviceExtension->Fdo = Fdo;
75  DeviceExtension->Pdo = Pdo;
76  DeviceExtension->PortDeviceExtension = &DriverExtension->Port;
77  Status = IoAttachDeviceToDeviceStackSafe(Fdo, Pdo, &DeviceExtension->LowerDevice);
78  if (!NT_SUCCESS(Status))
79  {
80  WARN_(I8042PRT, "IoAttachDeviceToDeviceStackSafe() failed with status 0x%08lx\n", Status);
81  goto cleanup;
82  }
83 
85  &DriverExtension->DeviceListHead,
86  &DeviceExtension->ListEntry,
87  &DriverExtension->DeviceListLock);
88 
90  return STATUS_SUCCESS;
91 
92 cleanup:
93  if (DeviceExtension && DeviceExtension->LowerDevice)
94  IoDetachDevice(DeviceExtension->LowerDevice);
95  if (Fdo)
96  IoDeleteDevice(Fdo);
97  return Status;
98 }
#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 497 of file i8042prt.c.

500 {
502  ULONG i;
504 
506  DriverObject,
507  DriverObject,
508  sizeof(I8042_DRIVER_EXTENSION),
510  if (!NT_SUCCESS(Status))
511  {
512  WARN_(I8042PRT, "IoAllocateDriverObjectExtension() failed with status 0x%08lx\n", Status);
513  return Status;
514  }
516  KeInitializeSpinLock(&DriverExtension->Port.SpinLock);
517  InitializeListHead(&DriverExtension->DeviceListHead);
518  KeInitializeSpinLock(&DriverExtension->DeviceListLock);
519 
522  RegistryPath,
523  &DriverExtension->RegistryPath);
524  if (!NT_SUCCESS(Status))
525  {
526  WARN_(I8042PRT, "DuplicateUnicodeString() failed with status 0x%08lx\n", Status);
527  return Status;
528  }
529 
531  if (!NT_SUCCESS(Status))
532  {
533  WARN_(I8042PRT, "ReadRegistryEntries() failed with status 0x%08lx\n", Status);
534  return Status;
535  }
536 
539 
540  for (i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++)
542 
551 
553 
554  return STATUS_SUCCESS;
555 }
static NTSTATUS NTAPI i8042SystemControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: i8042prt.c:489
#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
#define IRP_MJ_MAXIMUM_FUNCTION
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI i8042Create(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: createclose.c:18
static DRIVER_DISPATCH IrpStub
Definition: i8042prt.c:21
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:426
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
PDRIVER_EXTENSION DriverExtension
Definition: iotypes.h:2174
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:2112
static NTSTATUS NTAPI i8042DeviceControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: i8042prt.c:406
#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:476
#define IRP_MJ_CLEANUP
PDRIVER_DISPATCH MajorFunction[IRP_MJ_MAXIMUM_FUNCTION+1]
Definition: iotypes.h:2181
unsigned int ULONG
Definition: retypes.h:1
#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:2179
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 406 of file i8042prt.c.

409 {
410  PFDO_DEVICE_EXTENSION DeviceExtension;
411 
412  TRACE_(I8042PRT, "i8042DeviceControl(%p %p)\n", DeviceObject, Irp);
414 
415  switch (DeviceExtension->Type)
416  {
417  case Keyboard:
419  break;
420  default:
421  return IrpStub(DeviceObject, Irp);
422  }
423 }
_In_ PIRP Irp
Definition: csq.h:116
DRIVER_DISPATCH i8042KbdDeviceControl
Definition: i8042prt.h:316
struct _FDO_DEVICE_EXTENSION * PFDO_DEVICE_EXTENSION
static DRIVER_DISPATCH IrpStub
Definition: i8042prt.c:21
PVOID DeviceExtension
Definition: env_spec_w32.h:418
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:1560

Referenced by DriverEntry().

◆ i8042InternalDeviceControl()

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

Definition at line 426 of file i8042prt.c.

429 {
430  PFDO_DEVICE_EXTENSION DeviceExtension;
433 
434  TRACE_(I8042PRT, "i8042InternalDeviceControl(%p %p)\n", DeviceObject, Irp);
436 
437  switch (DeviceExtension->Type)
438  {
439  case Unknown:
440  {
441  ControlCode = IoGetCurrentIrpStackLocation(Irp)->Parameters.DeviceIoControl.IoControlCode;
442  switch (ControlCode)
443  {
446  break;
449  break;
450  default:
451  ERR_(I8042PRT, "Unknown IO control code 0x%lx\n", ControlCode);
452  ASSERT(FALSE);
454  break;
455  }
456  break;
457  }
458  case Keyboard:
460  break;
461  case Mouse:
463  break;
464  default:
465  ERR_(I8042PRT, "Unknown FDO type %u\n", DeviceExtension->Type);
466  ASSERT(FALSE);
469  break;
470  }
471 
472  return Status;
473 }
_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:1560
__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:566
DRIVER_DISPATCH i8042MouInternalDeviceControl
Definition: i8042prt.h:367
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
DRIVER_DISPATCH i8042KbdInternalDeviceControl
Definition: i8042prt.h:318

Referenced by DriverEntry().

◆ i8042PacketIsr()

BOOLEAN i8042PacketIsr ( IN PPORT_DEVICE_EXTENSION  DeviceExtension,
IN UCHAR  Output 
)

Definition at line 272 of file i8042prt.c.

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

251 {
252  UCHAR Port = DeviceExtension->PacketPort;
253 
254  if (Port)
255  {
256  if (!i8042Write(DeviceExtension,
257  DeviceExtension->ControlPort,
258  Port))
259  {
260  /* something is really wrong! */
261  WARN_(I8042PRT, "Failed to send packet byte!\n");
262  return FALSE;
263  }
264  }
265 
266  return i8042Write(DeviceExtension,
267  DeviceExtension->DataPort,
268  DeviceExtension->Packet.Bytes[DeviceExtension->Packet.CurrentByte]);
269 }
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 476 of file i8042prt.c.

479 {
481  PDEVICE_OBJECT LowerDevice = DeviceExtension->LowerDevice;
482 
485  return PoCallDriver(LowerDevice, Irp);
486 }
_In_ PIRP Irp
Definition: csq.h:116
PVOID DeviceExtension
Definition: env_spec_w32.h:418
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
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 101 of file i8042prt.c.

104 {
105  PI8042_HOOK_WORKITEM WorkItemData;
106  PFDO_DEVICE_EXTENSION FdoDeviceExtension;
107  PPORT_DEVICE_EXTENSION PortDeviceExtension;
108  PDEVICE_OBJECT TopOfStack = NULL;
113  KEVENT Event;
114  PIRP NewIrp;
116 
117  TRACE_(I8042PRT, "i8042SendHookWorkItem(%p %p)\n", DeviceObject, Context);
118 
119  WorkItemData = (PI8042_HOOK_WORKITEM)Context;
120  FdoDeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
121  PortDeviceExtension = FdoDeviceExtension->PortDeviceExtension;
122 
123  switch (FdoDeviceExtension->Type)
124  {
125  case Keyboard:
126  {
127  PI8042_KEYBOARD_EXTENSION DeviceExtension;
128  DeviceExtension = (PI8042_KEYBOARD_EXTENSION)FdoDeviceExtension;
130  InputBuffer = &DeviceExtension->KeyboardHook;
132  break;
133  }
134  case Mouse:
135  {
136  PI8042_MOUSE_EXTENSION DeviceExtension;
137  DeviceExtension = (PI8042_MOUSE_EXTENSION)FdoDeviceExtension;
139  InputBuffer = &DeviceExtension->MouseHook;
141  break;
142  }
143  default:
144  {
145  ERR_(I8042PRT, "Unknown FDO type %u\n", FdoDeviceExtension->Type);
146  ASSERT(FALSE);
147  WorkItemData->Irp->IoStatus.Status = STATUS_INTERNAL_ERROR;
148  goto cleanup;
149  }
150  }
151 
154 
157  TopOfStack,
158  InputBuffer,
160  NULL,
161  0,
162  TRUE,
163  &Event,
164  &IoStatus);
165 
166  if (!NewIrp)
167  {
168  WARN_(I8042PRT, "IoBuildDeviceIoControlRequest() failed\n");
170  goto cleanup;
171  }
172 
173  Status = IoCallDriver(TopOfStack, NewIrp);
174  if (Status == STATUS_PENDING)
175  {
177  &Event,
178  Executive,
179  KernelMode,
180  FALSE,
181  NULL);
182  Status = IoStatus.Status;
183  }
184  if (!NT_SUCCESS(Status))
185  {
186  WARN_(I8042PRT, "IoCallDriver() failed with status 0x%08lx\n", Status);
187  goto cleanup;
188  }
189 
190  if (FdoDeviceExtension->Type == Keyboard)
191  {
192  PI8042_KEYBOARD_EXTENSION DeviceExtension;
193 
194  DeviceExtension = (PI8042_KEYBOARD_EXTENSION)FdoDeviceExtension;
195  /* Call the hooked initialization if it exists */
196  if (DeviceExtension->KeyboardHook.InitializationRoutine)
197  {
198  Status = DeviceExtension->KeyboardHook.InitializationRoutine(
199  DeviceExtension->KeyboardHook.Context,
200  PortDeviceExtension,
203  FALSE);
204  if (!NT_SUCCESS(Status))
205  {
206  WARN_(I8042PRT, "KeyboardHook.InitializationRoutine() failed with status 0x%08lx\n", Status);
207  WorkItemData->Irp->IoStatus.Status = Status;
208  goto cleanup;
209  }
210  }
211  }
212 
213  WorkItemData->Irp->IoStatus.Status = STATUS_SUCCESS;
214 
215 cleanup:
216  if (TopOfStack != NULL)
217  ObDereferenceObject(TopOfStack);
218  WorkItemData->Irp->IoStatus.Information = 0;
219  IoCompleteRequest(WorkItemData->Irp, IO_NO_INCREMENT);
220 
221  IoFreeWorkItem(WorkItemData->WorkItem);
222  ExFreePoolWithTag(WorkItemData, I8042PRT_TAG);
223 }
#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:2650
#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:435
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:1560
#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:566
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 226 of file i8042prt.c.

229 {
230  PFDO_DEVICE_EXTENSION DeviceExtension;
231 
233  switch (DeviceExtension->Type)
234  {
235  case Keyboard:
237  break;
238  default:
239  ERR_(I8042PRT, "Unknown FDO type %u\n", DeviceExtension->Type);
240  ASSERT(FALSE);
241  break;
242  }
243 }
_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:1560

◆ 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 330 of file i8042prt.c.

336 {
337  KIRQL Irql;
339 
340  Irql = KeAcquireInterruptSpinLock(DeviceExtension->HighestDIRQLInterrupt);
341 
342  if (DeviceExtension->Packet.State != Idle)
343  {
345  goto done;
346  }
347 
348  switch (FdoDeviceExtension->Type)
349  {
350  case Keyboard: DeviceExtension->PacketPort = 0; break;
351  case Mouse: DeviceExtension->PacketPort = CTRL_WRITE_MOUSE; break;
352  default:
353  ERR_(I8042PRT, "Unknown FDO type %u\n", FdoDeviceExtension->Type);
354  ASSERT(FALSE);
356  goto done;
357  }
358 
359  DeviceExtension->Packet.Bytes = Bytes;
360  DeviceExtension->Packet.CurrentByte = 0;
361  DeviceExtension->Packet.ByteCount = ByteCount;
362  DeviceExtension->Packet.State = SendingBytes;
363  DeviceExtension->PacketResult = Status = STATUS_PENDING;
364  DeviceExtension->CurrentIrp = Irp;
365  DeviceExtension->CurrentIrpDevice = FdoDeviceExtension->Fdo;
366 
367  if (!i8042PacketWrite(DeviceExtension))
368  {
370  DeviceExtension->Packet.State = Idle;
371  DeviceExtension->PacketResult = STATUS_ABANDONED;
372  goto done;
373  }
374 
375  DeviceExtension->Packet.CurrentByte++;
376 
377 done:
378  KeReleaseInterruptSpinLock(DeviceExtension->HighestDIRQLInterrupt, Irql);
379 
380  if (Status != STATUS_PENDING)
381  {
382  DeviceExtension->CurrentIrp = NULL;
383  DeviceExtension->CurrentIrpDevice = NULL;
384  Irp->IoStatus.Status = Status;
386  }
387  return Status;
388 }
_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:249
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:1061
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:566
#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 489 of file i8042prt.c.

492 {
494 }
_In_ PIRP Irp
Definition: csq.h:116
DRIVER_DISPATCH ForwardIrpAndForget
Definition: i8042prt.h:341
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560

Referenced by DriverEntry().

◆ IrpStub()

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

Definition at line 391 of file i8042prt.c.

394 {
395  NTSTATUS Status = Irp->IoStatus.Status;
396 
398 
399  /* Do nothing */
400  ASSERT(FALSE);
402  return Status;
403 }
_In_ PIRP Irp
Definition: csq.h:116
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
LONG NTSTATUS
Definition: precomp.h:26
#define IoCompleteRequest
Definition: irp.c:1240
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define IO_NO_INCREMENT
Definition: iotypes.h:566

Variable Documentation

◆ i8042StartIo

DRIVER_STARTIO i8042StartIo
static

Definition at line 20 of file i8042prt.c.

Referenced by DriverEntry().

◆ IrpStub

DRIVER_DISPATCH IrpStub
static

Definition at line 21 of file i8042prt.c.

Referenced by DriverEntry(), and i8042DeviceControl().