2005-05-01 20:38:29 +00:00
|
|
|
|
/*
|
2007-10-31 08:58:04 +00:00
|
|
|
|
* PROJECT: ReactOS i8042 (ps/2 keyboard-mouse controller) driver
|
|
|
|
|
* LICENSE: GPL - See COPYING in the top level directory
|
|
|
|
|
* FILE: drivers/input/i8042prt/keyboard.c
|
|
|
|
|
* PURPOSE: Keyboard specific functions
|
|
|
|
|
* PROGRAMMERS: Copyright Victor Kirhenshtein (sauros@iname.com)
|
|
|
|
|
Copyright Jason Filby (jasonfilby@yahoo.com)
|
|
|
|
|
Copyright Martijn Vernooij (o112w8r02@sneakemail.com)
|
|
|
|
|
Copyright 2006-2007 Herv<EFBFBD> Poussineau (hpoussin@reactos.org)
|
2005-05-01 20:38:29 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* INCLUDES ****************************************************************/
|
|
|
|
|
|
2005-10-21 20:28:05 +00:00
|
|
|
|
#include "i8042prt.h"
|
2007-07-06 18:14:23 +00:00
|
|
|
|
|
2005-05-01 20:38:29 +00:00
|
|
|
|
/* GLOBALS *******************************************************************/
|
|
|
|
|
|
2007-10-31 08:58:04 +00:00
|
|
|
|
static IO_WORKITEM_ROUTINE i8042PowerWorkItem;
|
2005-05-01 20:38:29 +00:00
|
|
|
|
|
2007-10-31 08:58:04 +00:00
|
|
|
|
/* This structure starts with the same layout as KEYBOARD_INDICATOR_TRANSLATION */
|
2005-05-01 20:38:29 +00:00
|
|
|
|
typedef struct _LOCAL_KEYBOARD_INDICATOR_TRANSLATION {
|
2009-02-11 17:21:10 +00:00
|
|
|
|
USHORT NumberOfIndicatorKeys;
|
|
|
|
|
INDICATOR_LIST IndicatorList[3];
|
2005-05-01 20:38:29 +00:00
|
|
|
|
} LOCAL_KEYBOARD_INDICATOR_TRANSLATION, *PLOCAL_KEYBOARD_INDICATOR_TRANSLATION;
|
|
|
|
|
|
|
|
|
|
static LOCAL_KEYBOARD_INDICATOR_TRANSLATION IndicatorTranslation = { 3, {
|
2009-02-11 17:21:10 +00:00
|
|
|
|
{0x3A, KEYBOARD_CAPS_LOCK_ON},
|
|
|
|
|
{0x45, KEYBOARD_NUM_LOCK_ON},
|
|
|
|
|
{0x46, KEYBOARD_SCROLL_LOCK_ON}}};
|
2005-05-01 20:38:29 +00:00
|
|
|
|
|
|
|
|
|
/* FUNCTIONS *****************************************************************/
|
|
|
|
|
|
|
|
|
|
/*
|
2009-02-11 17:21:10 +00:00
|
|
|
|
* These functions are callbacks for filter driver custom interrupt
|
|
|
|
|
* service routines.
|
|
|
|
|
*/
|
2007-10-31 08:58:04 +00:00
|
|
|
|
/*static VOID NTAPI
|
|
|
|
|
i8042KbdIsrWritePort(
|
2009-02-11 17:21:10 +00:00
|
|
|
|
IN PVOID Context,
|
|
|
|
|
IN UCHAR Value)
|
2005-05-01 20:38:29 +00:00
|
|
|
|
{
|
2009-02-11 17:21:10 +00:00
|
|
|
|
PI8042_KEYBOARD_EXTENSION DeviceExtension;
|
|
|
|
|
|
|
|
|
|
DeviceExtension = (PI8042_KEYBOARD_EXTENSION)Context;
|
|
|
|
|
|
|
|
|
|
if (DeviceExtension->KeyboardHook.IsrWritePort)
|
|
|
|
|
{
|
|
|
|
|
DeviceExtension->KeyboardHook.IsrWritePort(
|
|
|
|
|
DeviceExtension->KeyboardHook.CallContext,
|
|
|
|
|
Value);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
i8042IsrWritePort(Context, Value, 0);
|
2007-10-31 08:58:04 +00:00
|
|
|
|
}*/
|
2005-05-01 20:38:29 +00:00
|
|
|
|
|
2007-10-31 08:58:04 +00:00
|
|
|
|
static VOID NTAPI
|
2009-02-11 17:21:10 +00:00
|
|
|
|
i8042KbdQueuePacket(
|
|
|
|
|
IN PVOID Context)
|
2005-05-01 20:38:29 +00:00
|
|
|
|
{
|
2009-02-11 17:21:10 +00:00
|
|
|
|
PI8042_KEYBOARD_EXTENSION DeviceExtension;
|
2007-10-31 08:58:04 +00:00
|
|
|
|
|
2009-02-11 17:21:10 +00:00
|
|
|
|
DeviceExtension = (PI8042_KEYBOARD_EXTENSION)Context;
|
2007-10-31 08:58:04 +00:00
|
|
|
|
|
2009-02-11 17:21:10 +00:00
|
|
|
|
DeviceExtension->KeyComplete = TRUE;
|
|
|
|
|
DeviceExtension->KeysInBuffer++;
|
|
|
|
|
if (DeviceExtension->KeysInBuffer > DeviceExtension->Common.PortDeviceExtension->Settings.KeyboardDataQueueSize)
|
|
|
|
|
{
|
|
|
|
|
WARN_(I8042PRT, "Keyboard buffer overflow\n");
|
|
|
|
|
DeviceExtension->KeysInBuffer--;
|
|
|
|
|
}
|
2005-05-01 20:38:29 +00:00
|
|
|
|
|
2009-02-11 17:21:10 +00:00
|
|
|
|
TRACE_(I8042PRT, "Irq completes key\n");
|
|
|
|
|
KeInsertQueueDpc(&DeviceExtension->DpcKeyboard, NULL, NULL);
|
2005-05-01 20:38:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2009-02-11 17:21:10 +00:00
|
|
|
|
* These functions are callbacks for filter driver custom
|
|
|
|
|
* initialization routines.
|
|
|
|
|
*/
|
2007-11-22 11:27:17 +00:00
|
|
|
|
NTSTATUS NTAPI
|
2009-02-11 17:21:10 +00:00
|
|
|
|
i8042SynchWritePortKbd(
|
|
|
|
|
IN PVOID Context,
|
|
|
|
|
IN UCHAR Value,
|
|
|
|
|
IN BOOLEAN WaitForAck)
|
2005-05-01 20:38:29 +00:00
|
|
|
|
{
|
2009-02-11 17:21:10 +00:00
|
|
|
|
return i8042SynchWritePort(
|
|
|
|
|
(PPORT_DEVICE_EXTENSION)Context,
|
|
|
|
|
0,
|
|
|
|
|
Value,
|
|
|
|
|
WaitForAck);
|
2005-05-01 20:38:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-10-31 08:58:04 +00:00
|
|
|
|
/*
|
2009-02-11 17:21:10 +00:00
|
|
|
|
* Process the keyboard internal device requests
|
|
|
|
|
*/
|
2007-10-31 08:58:04 +00:00
|
|
|
|
VOID NTAPI
|
2009-02-11 17:21:10 +00:00
|
|
|
|
i8042KbdStartIo(
|
|
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
|
IN PIRP Irp)
|
2005-05-01 20:38:29 +00:00
|
|
|
|
{
|
2009-02-11 17:21:10 +00:00
|
|
|
|
PIO_STACK_LOCATION Stack;
|
|
|
|
|
PI8042_KEYBOARD_EXTENSION DeviceExtension;
|
|
|
|
|
PPORT_DEVICE_EXTENSION PortDeviceExtension;
|
|
|
|
|
|
|
|
|
|
Stack = IoGetCurrentIrpStackLocation(Irp);
|
|
|
|
|
DeviceExtension = (PI8042_KEYBOARD_EXTENSION)DeviceObject->DeviceExtension;
|
|
|
|
|
PortDeviceExtension = DeviceExtension->Common.PortDeviceExtension;
|
|
|
|
|
|
|
|
|
|
switch (Stack->Parameters.DeviceIoControl.IoControlCode)
|
|
|
|
|
{
|
|
|
|
|
case IOCTL_KEYBOARD_SET_INDICATORS:
|
|
|
|
|
{
|
|
|
|
|
TRACE_(I8042PRT, "IOCTL_KEYBOARD_SET_INDICATORS\n");
|
|
|
|
|
INFO_(I8042PRT, "Leds: {%s%s%s }\n",
|
|
|
|
|
DeviceExtension->KeyboardIndicators.LedFlags & KEYBOARD_CAPS_LOCK_ON ? " CAPSLOCK" : "",
|
|
|
|
|
DeviceExtension->KeyboardIndicators.LedFlags & KEYBOARD_NUM_LOCK_ON ? " NUMLOCK" : "",
|
|
|
|
|
DeviceExtension->KeyboardIndicators.LedFlags & KEYBOARD_SCROLL_LOCK_ON ? " SCROLLLOCK" : "");
|
|
|
|
|
|
|
|
|
|
PortDeviceExtension->PacketBuffer[0] = KBD_CMD_SET_LEDS;
|
|
|
|
|
PortDeviceExtension->PacketBuffer[1] = 0;
|
|
|
|
|
if (DeviceExtension->KeyboardIndicators.LedFlags & KEYBOARD_CAPS_LOCK_ON)
|
|
|
|
|
PortDeviceExtension->PacketBuffer[1] |= KBD_LED_CAPS;
|
|
|
|
|
|
|
|
|
|
if (DeviceExtension->KeyboardIndicators.LedFlags & KEYBOARD_NUM_LOCK_ON)
|
|
|
|
|
PortDeviceExtension->PacketBuffer[1] |= KBD_LED_NUM;
|
|
|
|
|
|
|
|
|
|
if (DeviceExtension->KeyboardIndicators.LedFlags & KEYBOARD_SCROLL_LOCK_ON)
|
|
|
|
|
PortDeviceExtension->PacketBuffer[1] |= KBD_LED_SCROLL;
|
|
|
|
|
|
|
|
|
|
i8042StartPacket(
|
|
|
|
|
PortDeviceExtension,
|
|
|
|
|
&DeviceExtension->Common,
|
|
|
|
|
PortDeviceExtension->PacketBuffer,
|
|
|
|
|
2,
|
|
|
|
|
Irp);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
{
|
|
|
|
|
ERR_(I8042PRT, "Unknown ioctl code 0x%lx\n",
|
|
|
|
|
Stack->Parameters.DeviceIoControl.IoControlCode);
|
|
|
|
|
ASSERT(FALSE);
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-10-31 08:58:04 +00:00
|
|
|
|
}
|
2005-05-01 20:38:29 +00:00
|
|
|
|
|
2007-10-31 08:58:04 +00:00
|
|
|
|
static VOID
|
2009-02-11 17:21:10 +00:00
|
|
|
|
i8042PacketDpc(
|
|
|
|
|
IN PPORT_DEVICE_EXTENSION DeviceExtension)
|
2007-10-31 08:58:04 +00:00
|
|
|
|
{
|
2009-02-11 17:21:10 +00:00
|
|
|
|
BOOLEAN FinishIrp = FALSE;
|
|
|
|
|
KIRQL Irql;
|
|
|
|
|
NTSTATUS Result = STATUS_INTERNAL_ERROR; /* Shouldn't happen */
|
|
|
|
|
|
|
|
|
|
/* If the interrupt happens before this is setup, the key
|
|
|
|
|
* was already in the buffer. Too bad! */
|
|
|
|
|
if (!DeviceExtension->HighestDIRQLInterrupt)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
Irql = KeAcquireInterruptSpinLock(DeviceExtension->HighestDIRQLInterrupt);
|
|
|
|
|
|
|
|
|
|
if (DeviceExtension->Packet.State == Idle
|
|
|
|
|
&& DeviceExtension->PacketComplete)
|
|
|
|
|
{
|
|
|
|
|
FinishIrp = TRUE;
|
|
|
|
|
Result = DeviceExtension->PacketResult;
|
|
|
|
|
DeviceExtension->PacketComplete = FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
KeReleaseInterruptSpinLock(DeviceExtension->HighestDIRQLInterrupt, Irql);
|
|
|
|
|
|
|
|
|
|
if (!FinishIrp)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (DeviceExtension->CurrentIrp)
|
|
|
|
|
{
|
|
|
|
|
DeviceExtension->CurrentIrp->IoStatus.Status = Result;
|
|
|
|
|
IoCompleteRequest(DeviceExtension->CurrentIrp, IO_NO_INCREMENT);
|
|
|
|
|
IoStartNextPacket(DeviceExtension->CurrentIrpDevice, FALSE);
|
|
|
|
|
DeviceExtension->CurrentIrp = NULL;
|
|
|
|
|
DeviceExtension->CurrentIrpDevice = NULL;
|
|
|
|
|
}
|
2007-10-31 08:58:04 +00:00
|
|
|
|
}
|
2005-05-01 20:38:29 +00:00
|
|
|
|
|
2007-10-31 08:58:04 +00:00
|
|
|
|
static VOID NTAPI
|
2009-02-11 17:21:10 +00:00
|
|
|
|
i8042PowerWorkItem(
|
|
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
|
IN PVOID Context)
|
2007-10-31 08:58:04 +00:00
|
|
|
|
{
|
2009-02-11 17:21:10 +00:00
|
|
|
|
PI8042_KEYBOARD_EXTENSION DeviceExtension;
|
|
|
|
|
PIRP WaitingIrp;
|
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
|
|
|
|
DeviceExtension = (PI8042_KEYBOARD_EXTENSION)Context;
|
|
|
|
|
|
2009-06-19 00:17:15 +00:00
|
|
|
|
UNREFERENCED_PARAMETER(DeviceObject);
|
|
|
|
|
|
2009-02-11 17:21:10 +00:00
|
|
|
|
/* See http://blogs.msdn.com/doronh/archive/2006/09/08/746961.aspx */
|
|
|
|
|
|
|
|
|
|
/* Register GUID_DEVICE_SYS_BUTTON interface and report capability */
|
|
|
|
|
if (DeviceExtension->NewCaps != DeviceExtension->ReportedCaps)
|
|
|
|
|
{
|
2010-03-25 03:24:44 +00:00
|
|
|
|
WaitingIrp = InterlockedExchangePointer((PVOID)&DeviceExtension->PowerIrp, NULL);
|
2009-02-11 17:21:10 +00:00
|
|
|
|
if (WaitingIrp)
|
|
|
|
|
{
|
|
|
|
|
/* Cancel the current power irp, as capability changed */
|
|
|
|
|
WaitingIrp->IoStatus.Status = STATUS_UNSUCCESSFUL;
|
|
|
|
|
WaitingIrp->IoStatus.Information = sizeof(ULONG);
|
|
|
|
|
IoCompleteRequest(WaitingIrp, IO_NO_INCREMENT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (DeviceExtension->PowerInterfaceName.MaximumLength == 0)
|
|
|
|
|
{
|
|
|
|
|
/* We have never registred this interface ; do it */
|
|
|
|
|
Status = IoRegisterDeviceInterface(
|
|
|
|
|
DeviceExtension->Common.Pdo,
|
|
|
|
|
&GUID_DEVICE_SYS_BUTTON,
|
|
|
|
|
NULL,
|
|
|
|
|
&DeviceExtension->PowerInterfaceName);
|
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
|
{
|
|
|
|
|
/* We can't do more yet, ignore the keypress... */
|
|
|
|
|
WARN_(I8042PRT, "IoRegisterDeviceInterface(GUID_DEVICE_SYS_BUTTON) failed with status 0x%08lx\n",
|
|
|
|
|
Status);
|
|
|
|
|
DeviceExtension->PowerInterfaceName.MaximumLength = 0;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* Disable the interface. Once activated again, capabilities would be asked again */
|
|
|
|
|
Status = IoSetDeviceInterfaceState(
|
|
|
|
|
&DeviceExtension->PowerInterfaceName,
|
|
|
|
|
FALSE);
|
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
|
{
|
|
|
|
|
/* Ignore the key press... */
|
|
|
|
|
WARN_(I8042PRT, "Disabling interface %wZ failed with status 0x%08lx\n",
|
|
|
|
|
&DeviceExtension->PowerInterfaceName, Status);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* Enable the interface. This leads to receving a IOCTL_GET_SYS_BUTTON_CAPS,
|
|
|
|
|
* so we can report new capability */
|
|
|
|
|
Status = IoSetDeviceInterfaceState(
|
|
|
|
|
&DeviceExtension->PowerInterfaceName,
|
|
|
|
|
TRUE);
|
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
|
{
|
|
|
|
|
/* Ignore the key press... */
|
|
|
|
|
WARN_(I8042PRT, "Enabling interface %wZ failed with status 0x%08lx\n",
|
|
|
|
|
&DeviceExtension->PowerInterfaceName, Status);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Directly complete the IOCTL_GET_SYS_BUTTON_EVENT Irp (if any) */
|
2010-03-25 03:24:44 +00:00
|
|
|
|
WaitingIrp = InterlockedExchangePointer((PVOID)&DeviceExtension->PowerIrp, NULL);
|
2009-02-11 17:21:10 +00:00
|
|
|
|
if (WaitingIrp)
|
|
|
|
|
{
|
|
|
|
|
PULONG pEvent = (PULONG)WaitingIrp->AssociatedIrp.SystemBuffer;
|
|
|
|
|
|
|
|
|
|
WaitingIrp->IoStatus.Status = STATUS_SUCCESS;
|
|
|
|
|
WaitingIrp->IoStatus.Information = sizeof(ULONG);
|
|
|
|
|
*pEvent = InterlockedExchange((PLONG)&DeviceExtension->LastPowerKey, 0);
|
|
|
|
|
IoCompleteRequest(WaitingIrp, IO_NO_INCREMENT);
|
|
|
|
|
}
|
2007-10-31 08:58:04 +00:00
|
|
|
|
}
|
2005-05-01 20:38:29 +00:00
|
|
|
|
|
2007-10-31 08:58:04 +00:00
|
|
|
|
/* Return TRUE if it was a power key */
|
|
|
|
|
static BOOLEAN
|
2009-02-11 17:21:10 +00:00
|
|
|
|
HandlePowerKeys(
|
|
|
|
|
IN PI8042_KEYBOARD_EXTENSION DeviceExtension)
|
2007-10-31 08:58:04 +00:00
|
|
|
|
{
|
2009-02-11 17:21:10 +00:00
|
|
|
|
PKEYBOARD_INPUT_DATA InputData;
|
|
|
|
|
ULONG KeyPress;
|
|
|
|
|
|
|
|
|
|
InputData = DeviceExtension->KeyboardBuffer + DeviceExtension->KeysInBuffer - 1;
|
|
|
|
|
if (!(InputData->Flags & KEY_E0))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
if (InputData->Flags & KEY_BREAK)
|
|
|
|
|
/* We already took care of the key press */
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
|
|
switch (InputData->MakeCode)
|
|
|
|
|
{
|
|
|
|
|
case KEYBOARD_POWER_CODE:
|
|
|
|
|
KeyPress = SYS_BUTTON_POWER;
|
|
|
|
|
break;
|
|
|
|
|
case KEYBOARD_SLEEP_CODE:
|
|
|
|
|
KeyPress = SYS_BUTTON_SLEEP;
|
|
|
|
|
break;
|
|
|
|
|
case KEYBOARD_WAKE_CODE:
|
|
|
|
|
KeyPress = SYS_BUTTON_WAKE;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Our work can only be done at passive level, so use a workitem */
|
|
|
|
|
DeviceExtension->NewCaps |= KeyPress;
|
|
|
|
|
InterlockedExchange((PLONG)&DeviceExtension->LastPowerKey, KeyPress);
|
|
|
|
|
IoQueueWorkItem(
|
|
|
|
|
DeviceExtension->PowerWorkItem,
|
|
|
|
|
&i8042PowerWorkItem,
|
|
|
|
|
DelayedWorkQueue,
|
|
|
|
|
DeviceExtension);
|
|
|
|
|
return TRUE;
|
2005-05-01 20:38:29 +00:00
|
|
|
|
}
|
2005-05-08 02:16:32 +00:00
|
|
|
|
|
2007-10-31 08:58:04 +00:00
|
|
|
|
static VOID NTAPI
|
2009-02-11 17:21:10 +00:00
|
|
|
|
i8042KbdDpcRoutine(
|
|
|
|
|
IN PKDPC Dpc,
|
|
|
|
|
IN PVOID DeferredContext,
|
|
|
|
|
IN PVOID SystemArgument1,
|
|
|
|
|
IN PVOID SystemArgument2)
|
2005-05-01 20:38:29 +00:00
|
|
|
|
{
|
2009-02-11 17:21:10 +00:00
|
|
|
|
PI8042_KEYBOARD_EXTENSION DeviceExtension;
|
|
|
|
|
PPORT_DEVICE_EXTENSION PortDeviceExtension;
|
|
|
|
|
ULONG KeysTransferred = 0;
|
|
|
|
|
ULONG KeysInBufferCopy;
|
|
|
|
|
KIRQL Irql;
|
|
|
|
|
|
2009-06-19 00:17:15 +00:00
|
|
|
|
UNREFERENCED_PARAMETER(Dpc);
|
|
|
|
|
UNREFERENCED_PARAMETER(SystemArgument1);
|
|
|
|
|
UNREFERENCED_PARAMETER(SystemArgument2);
|
|
|
|
|
|
2009-02-11 17:21:10 +00:00
|
|
|
|
DeviceExtension = (PI8042_KEYBOARD_EXTENSION)DeferredContext;
|
|
|
|
|
PortDeviceExtension = DeviceExtension->Common.PortDeviceExtension;
|
|
|
|
|
|
|
|
|
|
if (HandlePowerKeys(DeviceExtension))
|
|
|
|
|
{
|
|
|
|
|
DeviceExtension->KeyComplete = FALSE;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
i8042PacketDpc(PortDeviceExtension);
|
|
|
|
|
if (!DeviceExtension->KeyComplete)
|
|
|
|
|
return;
|
|
|
|
|
/* We got the interrupt as it was being enabled, too bad */
|
|
|
|
|
if (!PortDeviceExtension->HighestDIRQLInterrupt)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
Irql = KeAcquireInterruptSpinLock(PortDeviceExtension->HighestDIRQLInterrupt);
|
|
|
|
|
|
|
|
|
|
DeviceExtension->KeyComplete = FALSE;
|
|
|
|
|
KeysInBufferCopy = DeviceExtension->KeysInBuffer;
|
|
|
|
|
|
|
|
|
|
KeReleaseInterruptSpinLock(PortDeviceExtension->HighestDIRQLInterrupt, Irql);
|
|
|
|
|
|
|
|
|
|
TRACE_(I8042PRT, "Send a key\n");
|
|
|
|
|
|
|
|
|
|
if (!DeviceExtension->KeyboardData.ClassService)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
INFO_(I8042PRT, "Sending %lu key(s)\n", KeysInBufferCopy);
|
|
|
|
|
(*(PSERVICE_CALLBACK_ROUTINE)DeviceExtension->KeyboardData.ClassService)(
|
|
|
|
|
DeviceExtension->KeyboardData.ClassDeviceObject,
|
|
|
|
|
DeviceExtension->KeyboardBuffer,
|
|
|
|
|
DeviceExtension->KeyboardBuffer + KeysInBufferCopy,
|
|
|
|
|
&KeysTransferred);
|
|
|
|
|
|
|
|
|
|
KeAcquireInterruptSpinLock(PortDeviceExtension->HighestDIRQLInterrupt);
|
|
|
|
|
DeviceExtension->KeysInBuffer -= KeysTransferred;
|
|
|
|
|
KeReleaseInterruptSpinLock(PortDeviceExtension->HighestDIRQLInterrupt, Irql);
|
2005-05-01 20:38:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2009-02-11 17:21:10 +00:00
|
|
|
|
* Runs the keyboard IOCTL dispatch.
|
|
|
|
|
*/
|
2007-10-31 08:58:04 +00:00
|
|
|
|
NTSTATUS NTAPI
|
2009-02-11 17:21:10 +00:00
|
|
|
|
i8042KbdDeviceControl(
|
|
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
|
IN PIRP Irp)
|
2005-05-01 20:38:29 +00:00
|
|
|
|
{
|
2009-02-11 17:21:10 +00:00
|
|
|
|
PIO_STACK_LOCATION Stack;
|
|
|
|
|
PI8042_KEYBOARD_EXTENSION DeviceExtension;
|
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
|
|
|
|
Stack = IoGetCurrentIrpStackLocation(Irp);
|
|
|
|
|
Irp->IoStatus.Information = 0;
|
|
|
|
|
DeviceExtension = (PI8042_KEYBOARD_EXTENSION)DeviceObject->DeviceExtension;
|
|
|
|
|
|
|
|
|
|
switch (Stack->Parameters.DeviceIoControl.IoControlCode)
|
|
|
|
|
{
|
|
|
|
|
case IOCTL_GET_SYS_BUTTON_CAPS:
|
|
|
|
|
{
|
|
|
|
|
/* Part of GUID_DEVICE_SYS_BUTTON interface */
|
|
|
|
|
PULONG pCaps;
|
|
|
|
|
TRACE_(I8042PRT, "IOCTL_GET_SYS_BUTTON_CAPS\n");
|
|
|
|
|
|
|
|
|
|
if (Stack->Parameters.DeviceIoControl.OutputBufferLength != sizeof(ULONG))
|
|
|
|
|
Status = STATUS_INVALID_PARAMETER;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pCaps = (PULONG)Irp->AssociatedIrp.SystemBuffer;
|
|
|
|
|
*pCaps = DeviceExtension->NewCaps;
|
|
|
|
|
DeviceExtension->ReportedCaps = DeviceExtension->NewCaps;
|
|
|
|
|
Irp->IoStatus.Information = sizeof(ULONG);
|
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case IOCTL_GET_SYS_BUTTON_EVENT:
|
|
|
|
|
{
|
|
|
|
|
/* Part of GUID_DEVICE_SYS_BUTTON interface */
|
|
|
|
|
PIRP WaitingIrp;
|
|
|
|
|
TRACE_(I8042PRT, "IOCTL_GET_SYS_BUTTON_EVENT\n");
|
|
|
|
|
|
|
|
|
|
if (Stack->Parameters.DeviceIoControl.OutputBufferLength != sizeof(ULONG))
|
|
|
|
|
Status = STATUS_INVALID_PARAMETER;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
WaitingIrp = InterlockedCompareExchangePointer(
|
2010-03-25 03:24:44 +00:00
|
|
|
|
(PVOID)&DeviceExtension->PowerIrp,
|
2009-02-11 17:21:10 +00:00
|
|
|
|
Irp,
|
|
|
|
|
NULL);
|
|
|
|
|
/* Check if an Irp is already pending */
|
|
|
|
|
if (WaitingIrp)
|
|
|
|
|
{
|
|
|
|
|
/* Unable to have a 2nd pending IRP for this IOCTL */
|
|
|
|
|
WARN_(I8042PRT, "Unable to pend a second IRP for IOCTL_GET_SYS_BUTTON_EVENT\n");
|
|
|
|
|
Status = STATUS_INVALID_PARAMETER;
|
|
|
|
|
Irp->IoStatus.Status = Status;
|
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ULONG PowerKey;
|
|
|
|
|
PowerKey = InterlockedExchange((PLONG)&DeviceExtension->LastPowerKey, 0);
|
|
|
|
|
if (PowerKey != 0)
|
|
|
|
|
{
|
2010-03-25 03:24:44 +00:00
|
|
|
|
(VOID)InterlockedCompareExchangePointer((PVOID)&DeviceExtension->PowerIrp, NULL, Irp);
|
2009-02-11 17:21:10 +00:00
|
|
|
|
*(PULONG)Irp->AssociatedIrp.SystemBuffer = PowerKey;
|
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
|
Irp->IoStatus.Status = Status;
|
|
|
|
|
Irp->IoStatus.Information = sizeof(ULONG);
|
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
TRACE_(I8042PRT, "Pending IOCTL_GET_SYS_BUTTON_EVENT\n");
|
|
|
|
|
Status = STATUS_PENDING;
|
|
|
|
|
Irp->IoStatus.Status = Status;
|
|
|
|
|
IoMarkIrpPending(Irp);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return Status;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
{
|
|
|
|
|
ERR_(I8042PRT, "IRP_MJ_DEVICE_CONTROL / unknown ioctl code 0x%lx\n",
|
|
|
|
|
Stack->Parameters.DeviceIoControl.IoControlCode);
|
|
|
|
|
ASSERT(FALSE);
|
|
|
|
|
return ForwardIrpAndForget(DeviceObject, Irp);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Irp->IoStatus.Status = Status;
|
|
|
|
|
if (Status == STATUS_PENDING)
|
|
|
|
|
IoMarkIrpPending(Irp);
|
|
|
|
|
else
|
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
|
|
|
|
|
|
return Status;
|
2005-05-01 20:38:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2009-02-11 17:21:10 +00:00
|
|
|
|
* Runs the keyboard IOCTL_INTERNAL dispatch.
|
|
|
|
|
*/
|
2007-10-31 08:58:04 +00:00
|
|
|
|
NTSTATUS NTAPI
|
2009-02-11 17:21:10 +00:00
|
|
|
|
i8042KbdInternalDeviceControl(
|
|
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
|
IN PIRP Irp)
|
2005-05-01 20:38:29 +00:00
|
|
|
|
{
|
2009-02-11 17:21:10 +00:00
|
|
|
|
PIO_STACK_LOCATION Stack;
|
|
|
|
|
PI8042_KEYBOARD_EXTENSION DeviceExtension;
|
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
|
|
|
|
Stack = IoGetCurrentIrpStackLocation(Irp);
|
|
|
|
|
Irp->IoStatus.Information = 0;
|
|
|
|
|
DeviceExtension = (PI8042_KEYBOARD_EXTENSION)DeviceObject->DeviceExtension;
|
|
|
|
|
|
|
|
|
|
switch (Stack->Parameters.DeviceIoControl.IoControlCode)
|
|
|
|
|
{
|
|
|
|
|
case IOCTL_INTERNAL_KEYBOARD_CONNECT:
|
|
|
|
|
{
|
|
|
|
|
SIZE_T Size;
|
|
|
|
|
PIO_WORKITEM WorkItem = NULL;
|
|
|
|
|
PI8042_HOOK_WORKITEM WorkItemData = NULL;
|
|
|
|
|
|
|
|
|
|
TRACE_(I8042PRT, "IRP_MJ_INTERNAL_DEVICE_CONTROL / IOCTL_INTERNAL_KEYBOARD_CONNECT\n");
|
|
|
|
|
if (Stack->Parameters.DeviceIoControl.InputBufferLength != sizeof(CONNECT_DATA))
|
|
|
|
|
{
|
|
|
|
|
Status = STATUS_INVALID_PARAMETER;
|
|
|
|
|
goto cleanup;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DeviceExtension->KeyboardData =
|
|
|
|
|
*((PCONNECT_DATA)Stack->Parameters.DeviceIoControl.Type3InputBuffer);
|
|
|
|
|
|
|
|
|
|
/* Send IOCTL_INTERNAL_I8042_HOOK_KEYBOARD to device stack */
|
|
|
|
|
WorkItem = IoAllocateWorkItem(DeviceObject);
|
|
|
|
|
if (!WorkItem)
|
|
|
|
|
{
|
|
|
|
|
WARN_(I8042PRT, "IoAllocateWorkItem() failed\n");
|
|
|
|
|
Status = STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
|
goto cleanup;
|
|
|
|
|
}
|
|
|
|
|
WorkItemData = ExAllocatePoolWithTag(
|
|
|
|
|
NonPagedPool,
|
|
|
|
|
sizeof(I8042_HOOK_WORKITEM),
|
|
|
|
|
I8042PRT_TAG);
|
|
|
|
|
if (!WorkItemData)
|
|
|
|
|
{
|
|
|
|
|
WARN_(I8042PRT, "ExAllocatePoolWithTag() failed\n");
|
|
|
|
|
Status = STATUS_NO_MEMORY;
|
|
|
|
|
goto cleanup;
|
|
|
|
|
}
|
|
|
|
|
WorkItemData->WorkItem = WorkItem;
|
|
|
|
|
WorkItemData->Irp = Irp;
|
|
|
|
|
|
|
|
|
|
/* Initialize extension */
|
|
|
|
|
DeviceExtension->Common.Type = Keyboard;
|
|
|
|
|
Size = DeviceExtension->Common.PortDeviceExtension->Settings.KeyboardDataQueueSize * sizeof(KEYBOARD_INPUT_DATA);
|
|
|
|
|
DeviceExtension->KeyboardBuffer = ExAllocatePoolWithTag(
|
|
|
|
|
NonPagedPool,
|
|
|
|
|
Size,
|
|
|
|
|
I8042PRT_TAG);
|
|
|
|
|
if (!DeviceExtension->KeyboardBuffer)
|
|
|
|
|
{
|
|
|
|
|
WARN_(I8042PRT, "ExAllocatePoolWithTag() failed\n");
|
|
|
|
|
Status = STATUS_NO_MEMORY;
|
|
|
|
|
goto cleanup;
|
|
|
|
|
}
|
|
|
|
|
RtlZeroMemory(DeviceExtension->KeyboardBuffer, Size);
|
|
|
|
|
KeInitializeDpc(
|
|
|
|
|
&DeviceExtension->DpcKeyboard,
|
|
|
|
|
i8042KbdDpcRoutine,
|
|
|
|
|
DeviceExtension);
|
|
|
|
|
DeviceExtension->PowerWorkItem = IoAllocateWorkItem(DeviceObject);
|
|
|
|
|
if (!DeviceExtension->PowerWorkItem)
|
|
|
|
|
{
|
|
|
|
|
WARN_(I8042PRT, "IoAllocateWorkItem() failed\n");
|
|
|
|
|
Status = STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
|
goto cleanup;
|
|
|
|
|
}
|
|
|
|
|
DeviceExtension->DebugWorkItem = IoAllocateWorkItem(DeviceObject);
|
|
|
|
|
if (!DeviceExtension->DebugWorkItem)
|
|
|
|
|
{
|
|
|
|
|
WARN_(I8042PRT, "IoAllocateWorkItem() failed\n");
|
|
|
|
|
Status = STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
|
goto cleanup;
|
|
|
|
|
}
|
|
|
|
|
DeviceExtension->Common.PortDeviceExtension->KeyboardExtension = DeviceExtension;
|
|
|
|
|
DeviceExtension->Common.PortDeviceExtension->Flags |= KEYBOARD_CONNECTED;
|
|
|
|
|
|
|
|
|
|
IoMarkIrpPending(Irp);
|
|
|
|
|
/* FIXME: DeviceExtension->KeyboardHook.IsrWritePort = ; */
|
|
|
|
|
DeviceExtension->KeyboardHook.QueueKeyboardPacket = i8042KbdQueuePacket;
|
|
|
|
|
DeviceExtension->KeyboardHook.CallContext = DeviceExtension;
|
|
|
|
|
IoQueueWorkItem(WorkItem,
|
|
|
|
|
i8042SendHookWorkItem,
|
|
|
|
|
DelayedWorkQueue,
|
|
|
|
|
WorkItemData);
|
|
|
|
|
Status = STATUS_PENDING;
|
|
|
|
|
break;
|
2005-05-01 20:38:29 +00:00
|
|
|
|
|
2007-10-31 08:58:04 +00:00
|
|
|
|
cleanup:
|
2009-02-11 17:21:10 +00:00
|
|
|
|
if (DeviceExtension->KeyboardBuffer)
|
|
|
|
|
ExFreePoolWithTag(DeviceExtension->KeyboardBuffer, I8042PRT_TAG);
|
|
|
|
|
if (DeviceExtension->PowerWorkItem)
|
|
|
|
|
IoFreeWorkItem(DeviceExtension->PowerWorkItem);
|
|
|
|
|
if (DeviceExtension->DebugWorkItem)
|
|
|
|
|
IoFreeWorkItem(DeviceExtension->DebugWorkItem);
|
|
|
|
|
if (WorkItem)
|
|
|
|
|
IoFreeWorkItem(WorkItem);
|
|
|
|
|
if (WorkItemData)
|
|
|
|
|
ExFreePoolWithTag(WorkItemData, I8042PRT_TAG);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case IOCTL_INTERNAL_KEYBOARD_DISCONNECT:
|
|
|
|
|
{
|
|
|
|
|
TRACE_(I8042PRT, "IRP_MJ_INTERNAL_DEVICE_CONTROL / IOCTL_INTERNAL_KEYBOARD_DISCONNECT\n");
|
|
|
|
|
/* MSDN says that operation is to implemented.
|
|
|
|
|
* To implement it, we just have to do:
|
|
|
|
|
* DeviceExtension->KeyboardData.ClassService = NULL;
|
|
|
|
|
*/
|
|
|
|
|
Status = STATUS_NOT_IMPLEMENTED;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case IOCTL_INTERNAL_I8042_HOOK_KEYBOARD:
|
|
|
|
|
{
|
|
|
|
|
TRACE_(I8042PRT, "IRP_MJ_INTERNAL_DEVICE_CONTROL / IOCTL_INTERNAL_I8042_HOOK_KEYBOARD\n");
|
|
|
|
|
/* Nothing to do here */
|
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2009-05-29 17:11:46 +00:00
|
|
|
|
case IOCTL_KEYBOARD_QUERY_ATTRIBUTES:
|
|
|
|
|
{
|
|
|
|
|
DPRINT1("IOCTL_KEYBOARD_QUERY_ATTRIBUTES not implemented\n");
|
2009-05-29 17:25:03 +00:00
|
|
|
|
#if 0
|
|
|
|
|
/* FIXME: KeyboardAttributes are not initialized anywhere */
|
|
|
|
|
TRACE_(I8042PRT, "IRP_MJ_INTERNAL_DEVICE_CONTROL / IOCTL_KEYBOARD_QUERY_ATTRIBUTES\n");
|
|
|
|
|
if (Stack->Parameters.DeviceIoControl.OutputBufferLength < sizeof(KEYBOARD_ATTRIBUTES))
|
|
|
|
|
{
|
|
|
|
|
Status = STATUS_BUFFER_TOO_SMALL;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*(PKEYBOARD_ATTRIBUTES) Irp->AssociatedIrp.SystemBuffer = DeviceExtension->KeyboardAttributes;
|
|
|
|
|
Irp->IoStatus.Information = sizeof(KEYBOARD_ATTRIBUTES);
|
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
|
break;
|
|
|
|
|
#endif
|
2009-05-29 17:11:46 +00:00
|
|
|
|
Status = STATUS_NOT_IMPLEMENTED;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case IOCTL_KEYBOARD_QUERY_TYPEMATIC:
|
|
|
|
|
{
|
|
|
|
|
DPRINT1("IOCTL_KEYBOARD_QUERY_TYPEMATIC not implemented\n");
|
|
|
|
|
Status = STATUS_NOT_IMPLEMENTED;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case IOCTL_KEYBOARD_SET_TYPEMATIC:
|
|
|
|
|
{
|
|
|
|
|
DPRINT1("IOCTL_KEYBOARD_SET_TYPEMATIC not implemented\n");
|
|
|
|
|
Status = STATUS_NOT_IMPLEMENTED;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2009-02-11 17:21:10 +00:00
|
|
|
|
case IOCTL_KEYBOARD_QUERY_INDICATOR_TRANSLATION:
|
|
|
|
|
{
|
|
|
|
|
TRACE_(I8042PRT, "IRP_MJ_INTERNAL_DEVICE_CONTROL / IOCTL_KEYBOARD_QUERY_INDICATOR_TRANSLATION\n");
|
|
|
|
|
|
|
|
|
|
/* We should check the UnitID, but it's kind of pointless as
|
|
|
|
|
* all keyboards are supposed to have the same one
|
|
|
|
|
*/
|
|
|
|
|
if (Stack->Parameters.DeviceIoControl.OutputBufferLength < sizeof(LOCAL_KEYBOARD_INDICATOR_TRANSLATION))
|
|
|
|
|
{
|
|
|
|
|
Status = STATUS_BUFFER_TOO_SMALL;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
RtlCopyMemory(
|
|
|
|
|
Irp->AssociatedIrp.SystemBuffer,
|
|
|
|
|
&IndicatorTranslation,
|
|
|
|
|
sizeof(LOCAL_KEYBOARD_INDICATOR_TRANSLATION));
|
|
|
|
|
Irp->IoStatus.Information = sizeof(LOCAL_KEYBOARD_INDICATOR_TRANSLATION);
|
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case IOCTL_KEYBOARD_QUERY_INDICATORS:
|
|
|
|
|
{
|
|
|
|
|
TRACE_(I8042PRT, "IRP_MJ_INTERNAL_DEVICE_CONTROL / IOCTL_KEYBOARD_QUERY_INDICATORS\n");
|
|
|
|
|
|
|
|
|
|
if (Stack->Parameters.DeviceIoControl.InputBufferLength < sizeof(KEYBOARD_INDICATOR_PARAMETERS))
|
|
|
|
|
{
|
|
|
|
|
Status = STATUS_BUFFER_TOO_SMALL;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
RtlCopyMemory(
|
|
|
|
|
Irp->AssociatedIrp.SystemBuffer,
|
|
|
|
|
&DeviceExtension->KeyboardIndicators,
|
|
|
|
|
sizeof(KEYBOARD_INDICATOR_PARAMETERS));
|
|
|
|
|
Irp->IoStatus.Information = sizeof(KEYBOARD_INDICATOR_PARAMETERS);
|
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case IOCTL_KEYBOARD_SET_INDICATORS:
|
|
|
|
|
{
|
|
|
|
|
TRACE_(I8042PRT, "IRP_MJ_INTERNAL_DEVICE_CONTROL / IOCTL_KEYBOARD_SET_INDICATORS\n");
|
|
|
|
|
|
|
|
|
|
if (Stack->Parameters.DeviceIoControl.InputBufferLength < sizeof(KEYBOARD_INDICATOR_PARAMETERS))
|
|
|
|
|
{
|
|
|
|
|
Status = STATUS_BUFFER_TOO_SMALL;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
RtlCopyMemory(
|
|
|
|
|
&DeviceExtension->KeyboardIndicators,
|
|
|
|
|
Irp->AssociatedIrp.SystemBuffer,
|
|
|
|
|
sizeof(KEYBOARD_INDICATOR_PARAMETERS));
|
|
|
|
|
Status = STATUS_PENDING;
|
|
|
|
|
IoMarkIrpPending(Irp);
|
|
|
|
|
IoStartPacket(DeviceObject, Irp, NULL, NULL);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
{
|
|
|
|
|
ERR_(I8042PRT, "IRP_MJ_INTERNAL_DEVICE_CONTROL / unknown ioctl code 0x%lx\n",
|
|
|
|
|
Stack->Parameters.DeviceIoControl.IoControlCode);
|
|
|
|
|
ASSERT(FALSE);
|
|
|
|
|
return ForwardIrpAndForget(DeviceObject, Irp);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Irp->IoStatus.Status = Status;
|
|
|
|
|
if (Status != STATUS_PENDING)
|
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
|
return Status;
|
2005-05-01 20:38:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-10-31 08:58:04 +00:00
|
|
|
|
/*
|
2009-02-11 17:21:10 +00:00
|
|
|
|
* Call the customization hook. The ToReturn parameter is about wether
|
|
|
|
|
* we should go on with the interrupt. The return value is what
|
|
|
|
|
* we should return (indicating to the system wether someone else
|
|
|
|
|
* should try to handle the interrupt)
|
|
|
|
|
*/
|
2007-10-31 08:58:04 +00:00
|
|
|
|
static BOOLEAN
|
2009-02-11 17:21:10 +00:00
|
|
|
|
i8042KbdCallIsrHook(
|
|
|
|
|
IN PI8042_KEYBOARD_EXTENSION DeviceExtension,
|
|
|
|
|
IN UCHAR Status,
|
|
|
|
|
IN UCHAR Input,
|
|
|
|
|
OUT PBOOLEAN ToReturn)
|
2005-05-06 21:18:20 +00:00
|
|
|
|
{
|
2009-02-11 17:21:10 +00:00
|
|
|
|
BOOLEAN HookReturn, HookContinue;
|
|
|
|
|
|
|
|
|
|
HookContinue = FALSE;
|
|
|
|
|
|
|
|
|
|
if (DeviceExtension->KeyboardHook.IsrRoutine)
|
|
|
|
|
{
|
|
|
|
|
HookReturn = DeviceExtension->KeyboardHook.IsrRoutine(
|
|
|
|
|
DeviceExtension->KeyboardHook.Context,
|
|
|
|
|
DeviceExtension->KeyboardBuffer + DeviceExtension->KeysInBuffer,
|
|
|
|
|
&DeviceExtension->Common.PortDeviceExtension->Packet,
|
|
|
|
|
Status,
|
|
|
|
|
&Input,
|
|
|
|
|
&HookContinue,
|
|
|
|
|
&DeviceExtension->KeyboardScanState);
|
|
|
|
|
|
|
|
|
|
if (!HookContinue)
|
|
|
|
|
{
|
|
|
|
|
*ToReturn = HookReturn;
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return FALSE;
|
2005-05-06 21:18:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-10-31 08:58:04 +00:00
|
|
|
|
BOOLEAN NTAPI
|
2009-02-11 17:21:10 +00:00
|
|
|
|
i8042KbdInterruptService(
|
|
|
|
|
IN PKINTERRUPT Interrupt,
|
|
|
|
|
PVOID Context)
|
2005-05-01 20:38:29 +00:00
|
|
|
|
{
|
2009-02-11 17:21:10 +00:00
|
|
|
|
PI8042_KEYBOARD_EXTENSION DeviceExtension;
|
|
|
|
|
PPORT_DEVICE_EXTENSION PortDeviceExtension;
|
|
|
|
|
PKEYBOARD_INPUT_DATA InputData;
|
|
|
|
|
ULONG Counter;
|
2009-06-19 00:17:15 +00:00
|
|
|
|
UCHAR PortStatus = 0, Output = 0;
|
2009-02-11 17:21:10 +00:00
|
|
|
|
BOOLEAN ToReturn = FALSE;
|
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
2009-06-19 00:17:15 +00:00
|
|
|
|
UNREFERENCED_PARAMETER(Interrupt);
|
|
|
|
|
|
2009-02-11 17:21:10 +00:00
|
|
|
|
DeviceExtension = (PI8042_KEYBOARD_EXTENSION)Context;
|
|
|
|
|
PortDeviceExtension = DeviceExtension->Common.PortDeviceExtension;
|
|
|
|
|
InputData = DeviceExtension->KeyboardBuffer + DeviceExtension->KeysInBuffer;
|
|
|
|
|
Counter = PortDeviceExtension->Settings.PollStatusIterations;
|
|
|
|
|
|
|
|
|
|
while (Counter)
|
|
|
|
|
{
|
|
|
|
|
Status = i8042ReadStatus(PortDeviceExtension, &PortStatus);
|
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
|
{
|
|
|
|
|
WARN_(I8042PRT, "i8042ReadStatus() failed with status 0x%08lx\n", Status);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
Status = i8042ReadKeyboardData(PortDeviceExtension, &Output);
|
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
|
break;
|
|
|
|
|
KeStallExecutionProcessor(1);
|
|
|
|
|
Counter--;
|
|
|
|
|
}
|
|
|
|
|
if (Counter == 0)
|
|
|
|
|
{
|
|
|
|
|
WARN_(I8042PRT, "Spurious i8042 keyboard interrupt\n");
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
INFO_(I8042PRT, "Got: 0x%02x\n", Output);
|
|
|
|
|
|
|
|
|
|
if (PortDeviceExtension->Settings.CrashOnCtrlScroll)
|
|
|
|
|
{
|
|
|
|
|
/* Test for CTRL + SCROLL LOCK twice */
|
2009-12-23 18:43:27 +00:00
|
|
|
|
static const UCHAR ScanCodes[] = { 0x1d, 0x46, 0xc6, 0x46, 0 };
|
2009-02-11 17:21:10 +00:00
|
|
|
|
|
|
|
|
|
if (Output == ScanCodes[DeviceExtension->ComboPosition])
|
|
|
|
|
{
|
|
|
|
|
DeviceExtension->ComboPosition++;
|
|
|
|
|
if (ScanCodes[DeviceExtension->ComboPosition] == 0)
|
|
|
|
|
KeBugCheck(MANUALLY_INITIATED_CRASH);
|
|
|
|
|
}
|
2009-12-23 18:43:27 +00:00
|
|
|
|
else if (Output == 0xfa)
|
|
|
|
|
{
|
|
|
|
|
/* Ignore ACK */
|
|
|
|
|
}
|
2009-02-11 17:21:10 +00:00
|
|
|
|
else if (Output == ScanCodes[0])
|
|
|
|
|
DeviceExtension->ComboPosition = 1;
|
|
|
|
|
else
|
|
|
|
|
DeviceExtension->ComboPosition = 0;
|
2009-12-23 18:43:27 +00:00
|
|
|
|
|
|
|
|
|
/* Test for TAB + key combination */
|
|
|
|
|
if (InputData->MakeCode == 0x0F)
|
|
|
|
|
DeviceExtension->TabPressed = !(InputData->Flags & KEY_BREAK);
|
|
|
|
|
else if (DeviceExtension->TabPressed)
|
|
|
|
|
{
|
|
|
|
|
DeviceExtension->TabPressed = FALSE;
|
|
|
|
|
|
|
|
|
|
/* Send request to the kernel debugger.
|
|
|
|
|
* Unknown requests will be ignored. */
|
|
|
|
|
KdSystemDebugControl(' soR',
|
|
|
|
|
(PVOID)(ULONG_PTR)InputData->MakeCode,
|
|
|
|
|
0,
|
|
|
|
|
NULL,
|
|
|
|
|
0,
|
|
|
|
|
NULL,
|
|
|
|
|
KernelMode);
|
|
|
|
|
}
|
2009-02-11 17:21:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (i8042KbdCallIsrHook(DeviceExtension, PortStatus, Output, &ToReturn))
|
|
|
|
|
return ToReturn;
|
|
|
|
|
|
|
|
|
|
if (i8042PacketIsr(PortDeviceExtension, Output))
|
|
|
|
|
{
|
|
|
|
|
if (PortDeviceExtension->PacketComplete)
|
|
|
|
|
{
|
|
|
|
|
TRACE_(I8042PRT, "Packet complete\n");
|
|
|
|
|
KeInsertQueueDpc(&DeviceExtension->DpcKeyboard, NULL, NULL);
|
|
|
|
|
}
|
|
|
|
|
TRACE_(I8042PRT, "Irq eaten by packet\n");
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TRACE_(I8042PRT, "Irq is keyboard input\n");
|
|
|
|
|
|
|
|
|
|
if (DeviceExtension->KeyboardScanState == Normal)
|
|
|
|
|
{
|
|
|
|
|
switch (Output)
|
|
|
|
|
{
|
|
|
|
|
case 0xe0:
|
|
|
|
|
DeviceExtension->KeyboardScanState = GotE0;
|
|
|
|
|
return TRUE;
|
|
|
|
|
case 0xe1:
|
|
|
|
|
DeviceExtension->KeyboardScanState = GotE1;
|
|
|
|
|
return TRUE;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Update InputData */
|
|
|
|
|
InputData->Flags = 0;
|
|
|
|
|
switch (DeviceExtension->KeyboardScanState)
|
|
|
|
|
{
|
|
|
|
|
case GotE0:
|
|
|
|
|
InputData->Flags |= KEY_E0;
|
|
|
|
|
break;
|
|
|
|
|
case GotE1:
|
|
|
|
|
InputData->Flags |= KEY_E1;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
DeviceExtension->KeyboardScanState = Normal;
|
|
|
|
|
if (Output & 0x80)
|
|
|
|
|
InputData->Flags |= KEY_BREAK;
|
|
|
|
|
else
|
|
|
|
|
InputData->Flags |= KEY_MAKE;
|
|
|
|
|
InputData->MakeCode = Output & 0x7f;
|
|
|
|
|
InputData->Reserved = 0;
|
|
|
|
|
|
|
|
|
|
DeviceExtension->KeyboardHook.QueueKeyboardPacket(DeviceExtension->KeyboardHook.CallContext);
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
2005-05-01 20:38:29 +00:00
|
|
|
|
}
|