74 WARN_(I8042PRT,
"Keyboard buffer overflow\n");
78 TRACE_(I8042PRT,
"Irq completes key\n");
115 switch (
Stack->Parameters.DeviceIoControl.IoControlCode)
119 TRACE_(I8042PRT,
"IOCTL_KEYBOARD_SET_INDICATORS\n");
120 INFO_(I8042PRT,
"Leds: {%s%s%s }\n",
146 ERR_(I8042PRT,
"Unknown ioctl code 0x%lx\n",
147 Stack->Parameters.DeviceIoControl.IoControlCode);
163 if (!DeviceExtension->HighestDIRQLInterrupt)
168 if (DeviceExtension->Packet.State ==
Idle
169 && DeviceExtension->PacketComplete)
172 Result = DeviceExtension->PacketResult;
173 DeviceExtension->PacketComplete =
FALSE;
181 if (DeviceExtension->CurrentIrp)
183 DeviceExtension->CurrentIrp->IoStatus.Status =
Result;
186 DeviceExtension->CurrentIrp =
NULL;
187 DeviceExtension->CurrentIrpDevice =
NULL;
224 &GUID_DEVICE_SYS_BUTTON,
230 WARN_(I8042PRT,
"IoRegisterDeviceInterface(GUID_DEVICE_SYS_BUTTON) failed with status 0x%08lx\n",
245 WARN_(I8042PRT,
"Disabling interface %wZ failed with status 0x%08lx\n",
258 WARN_(I8042PRT,
"Enabling interface %wZ failed with status 0x%08lx\n",
285 InputData = DeviceExtension->KeyboardBuffer + DeviceExtension->KeysInBuffer - 1;
309 DeviceExtension->NewCaps |= KeyPress;
312 DeviceExtension->PowerWorkItem,
328 ULONG KeysTransferred = 0;
329 ULONG KeysInBufferCopy;
360 TRACE_(I8042PRT,
"Send a key\n");
365 INFO_(I8042PRT,
"Sending %lu key(s)\n", KeysInBufferCopy);
393 Irp->IoStatus.Information = 0;
396 switch (
Stack->Parameters.DeviceIoControl.IoControlCode)
402 TRACE_(I8042PRT,
"IOCTL_GET_SYS_BUTTON_CAPS\n");
404 if (
Stack->Parameters.DeviceIoControl.OutputBufferLength !=
sizeof(
ULONG))
408 pCaps = (
PULONG)
Irp->AssociatedIrp.SystemBuffer;
409 *pCaps = DeviceExtension->
NewCaps;
411 Irp->IoStatus.Information =
sizeof(
ULONG);
420 TRACE_(I8042PRT,
"IOCTL_GET_SYS_BUTTON_EVENT\n");
422 if (
Stack->Parameters.DeviceIoControl.OutputBufferLength !=
sizeof(
ULONG))
434 WARN_(I8042PRT,
"Unable to pend a second IRP for IOCTL_GET_SYS_BUTTON_EVENT\n");
446 *(
PULONG)
Irp->AssociatedIrp.SystemBuffer = PowerKey;
449 Irp->IoStatus.Information =
sizeof(
ULONG);
454 TRACE_(I8042PRT,
"Pending IOCTL_GET_SYS_BUTTON_EVENT\n");
466 ERR_(I8042PRT,
"IRP_MJ_DEVICE_CONTROL / unknown ioctl code 0x%lx\n",
467 Stack->Parameters.DeviceIoControl.IoControlCode);
522 Irp->IoStatus.Information = 0;
525 switch (
Stack->Parameters.DeviceIoControl.IoControlCode)
533 TRACE_(I8042PRT,
"IRP_MJ_INTERNAL_DEVICE_CONTROL / IOCTL_INTERNAL_KEYBOARD_CONNECT\n");
547 WARN_(I8042PRT,
"IoAllocateWorkItem() failed\n");
557 WARN_(I8042PRT,
"ExAllocatePoolWithTag() failed\n");
573 WARN_(I8042PRT,
"ExAllocatePoolWithTag() failed\n");
585 WARN_(I8042PRT,
"IoAllocateWorkItem() failed\n");
592 WARN_(I8042PRT,
"IoAllocateWorkItem() failed\n");
627 TRACE_(I8042PRT,
"IRP_MJ_INTERNAL_DEVICE_CONTROL / IOCTL_INTERNAL_KEYBOARD_DISCONNECT\n");
637 TRACE_(I8042PRT,
"IRP_MJ_INTERNAL_DEVICE_CONTROL / IOCTL_INTERNAL_I8042_HOOK_KEYBOARD\n");
647 TRACE_(I8042PRT,
"IRP_MJ_INTERNAL_DEVICE_CONTROL / IOCTL_KEYBOARD_QUERY_ATTRIBUTES\n");
654 KeyboardAttributes =
Irp->AssociatedIrp.SystemBuffer;
663 DPRINT1(
"IOCTL_KEYBOARD_QUERY_TYPEMATIC not implemented\n");
669 DPRINT1(
"IOCTL_KEYBOARD_SET_TYPEMATIC not implemented\n");
675 TRACE_(I8042PRT,
"IRP_MJ_INTERNAL_DEVICE_CONTROL / IOCTL_KEYBOARD_QUERY_INDICATOR_TRANSLATION\n");
687 Irp->AssociatedIrp.SystemBuffer,
697 TRACE_(I8042PRT,
"IRP_MJ_INTERNAL_DEVICE_CONTROL / IOCTL_KEYBOARD_QUERY_INDICATORS\n");
706 Irp->AssociatedIrp.SystemBuffer,
716 TRACE_(I8042PRT,
"IRP_MJ_INTERNAL_DEVICE_CONTROL / IOCTL_KEYBOARD_SET_INDICATORS\n");
726 Irp->AssociatedIrp.SystemBuffer,
736 ERR_(I8042PRT,
"IRP_MJ_INTERNAL_DEVICE_CONTROL / unknown ioctl code 0x%lx\n",
737 Stack->Parameters.DeviceIoControl.IoControlCode);
764 BOOLEAN HookReturn, HookContinue;
766 HookContinue =
FALSE;
768 if (DeviceExtension->KeyboardHook.IsrRoutine)
770 HookReturn = DeviceExtension->KeyboardHook.IsrRoutine(
771 DeviceExtension->KeyboardHook.Context,
772 DeviceExtension->KeyboardBuffer + DeviceExtension->KeysInBuffer,
773 &DeviceExtension->Common.PortDeviceExtension->Packet,
777 &DeviceExtension->KeyboardScanState);
781 *ToReturn = HookReturn;
814 WARN_(I8042PRT,
"i8042ReadStatus() failed with status 0x%08lx\n",
Status);
825 WARN_(I8042PRT,
"Spurious i8042 keyboard interrupt\n");
834 static const UCHAR ScanCodes[] = { 0x1d, 0x46, 0xc6, 0x46, 0 };
846 else if (
Output == ScanCodes[0])
864 else if (InputData->
MakeCode == 0x30)
891 TRACE_(I8042PRT,
"Packet complete\n");
894 TRACE_(I8042PRT,
"Irq eaten by packet\n");
898 TRACE_(I8042PRT,
"Irq is keyboard input\n");
916 InputData->
Flags = 0;
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
#define InterlockedExchange
DECLSPEC_NORETURN VOID NTAPI KeBugCheck(ULONG BugCheckCode)
#define NT_SUCCESS(StatCode)
static void cleanup(void)
BOOLEAN NTAPI KeInsertQueueDpc(IN PKDPC Dpc, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
VOID NTAPI KeInitializeDpc(IN PKDPC Dpc, IN PKDEFERRED_ROUTINE DeferredRoutine, IN PVOID DeferredContext)
#define InterlockedExchangePointer(Target, Value)
#define ExAllocatePoolWithTag(hernya, size, tag)
#define KeGetCurrentIrql()
_Outptr_ PUSB_DEVICE_HANDLE _In_ PUSB_DEVICE_HANDLE _In_ USHORT PortStatus
NTSTATUS i8042StartPacket(IN PPORT_DEVICE_EXTENSION DeviceExtension, IN PFDO_DEVICE_EXTENSION FdoDeviceExtension, IN PUCHAR Bytes, IN ULONG ByteCount, IN PIRP Irp)
BOOLEAN i8042PacketIsr(IN PPORT_DEVICE_EXTENSION DeviceExtension, IN UCHAR Output)
DRIVER_DISPATCH i8042KbdDeviceControl
DRIVER_DISPATCH i8042KbdInternalDeviceControl
DRIVER_STARTIO i8042KbdStartIo
#define KEYBOARD_CONNECTED
#define KEYBOARD_SLEEP_CODE
KSERVICE_ROUTINE i8042KbdInterruptService
#define KEYBOARD_POWER_CODE
IO_WORKITEM_ROUTINE i8042SendHookWorkItem
#define KEYBOARD_WAKE_CODE
struct _I8042_KEYBOARD_EXTENSION * PI8042_KEYBOARD_EXTENSION
NTSTATUS NTAPI i8042SynchWritePort(IN PPORT_DEVICE_EXTENSION DeviceExtension, IN UCHAR Port, IN UCHAR Value, IN BOOLEAN WaitForAck)
DRIVER_DISPATCH ForwardIrpAndForget
NTSTATUS i8042ReadStatus(IN PPORT_DEVICE_EXTENSION DeviceExtension, OUT PUCHAR Status)
#define i8042ReadKeyboardData(DeviceExtension, Data)
#define InterlockedCompareExchangePointer
VOID NTAPI IoQueueWorkItem(IN PIO_WORKITEM IoWorkItem, IN PIO_WORKITEM_ROUTINE WorkerRoutine, IN WORK_QUEUE_TYPE QueueType, IN PVOID Context)
VOID NTAPI IoFreeWorkItem(IN PIO_WORKITEM IoWorkItem)
PIO_WORKITEM NTAPI IoAllocateWorkItem(IN PDEVICE_OBJECT DeviceObject)
struct _CONNECT_DATA * PCONNECT_DATA
#define IOCTL_INTERNAL_KEYBOARD_CONNECT
VOID(STDAPICALLTYPE * PSERVICE_CALLBACK_ROUTINE)(IN PVOID NormalContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2, IN OUT PVOID SystemArgument3)
#define IOCTL_INTERNAL_KEYBOARD_DISCONNECT
NTSTATUS NTAPI KdSystemDebugControl(_In_ SYSDBG_COMMAND Command, _In_ PVOID InputBuffer, _In_ ULONG InputBufferLength, _Out_ PVOID OutputBuffer, _In_ ULONG OutputBufferLength, _Inout_ PULONG ReturnLength, _In_ KPROCESSOR_MODE PreviousMode)
#define ExFreePoolWithTag(_P, _T)
#define KeStallExecutionProcessor(MicroSeconds)
#define __analysis_assume(expr)
#define UNREFERENCED_PARAMETER(P)
#define IOCTL_INTERNAL_I8042_HOOK_KEYBOARD
struct _KEYBOARD_INPUT_DATA KEYBOARD_INPUT_DATA
#define IOCTL_KEYBOARD_QUERY_TYPEMATIC
#define KEYBOARD_CAPS_LOCK_ON
#define IOCTL_KEYBOARD_QUERY_INDICATORS
#define IOCTL_KEYBOARD_SET_INDICATORS
#define IOCTL_KEYBOARD_QUERY_ATTRIBUTES
#define IOCTL_KEYBOARD_QUERY_INDICATOR_TRANSLATION
#define KEYBOARD_SCROLL_LOCK_ON
#define IOCTL_KEYBOARD_SET_TYPEMATIC
struct _KEYBOARD_ATTRIBUTES KEYBOARD_ATTRIBUTES
struct _KEYBOARD_INDICATOR_PARAMETERS KEYBOARD_INDICATOR_PARAMETERS
#define KEYBOARD_NUM_LOCK_ON
VOID NTAPI IoStartPacket(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PULONG Key, IN PDRIVER_CANCEL CancelFunction)
VOID NTAPI IoStartNextPacket(IN PDEVICE_OBJECT DeviceObject, IN BOOLEAN Cancelable)
NTSTATUS NTAPI IoRegisterDeviceInterface(IN PDEVICE_OBJECT PhysicalDeviceObject, IN CONST GUID *InterfaceClassGuid, IN PUNICODE_STRING ReferenceString OPTIONAL, OUT PUNICODE_STRING SymbolicLinkName)
NTSTATUS NTAPI IoSetDeviceInterfaceState(IN PUNICODE_STRING SymbolicLinkName, IN BOOLEAN Enable)
#define IoCompleteRequest
KIRQL NTAPI KeAcquireInterruptSpinLock(IN PKINTERRUPT Interrupt)
VOID NTAPI KeReleaseInterruptSpinLock(IN PKINTERRUPT Interrupt, IN KIRQL OldIrql)
#define STATUS_INTERNAL_ERROR
#define STATUS_NOT_IMPLEMENTED
#define IOCTL_GET_SYS_BUTTON_CAPS
#define IOCTL_GET_SYS_BUTTON_EVENT
#define STATUS_BUFFER_TOO_SMALL
PDEVICE_OBJECT ClassDeviceObject
PPORT_DEVICE_EXTENSION PortDeviceExtension
CONNECT_DATA KeyboardData
PIO_WORKITEM DebugWorkItem
KEYBOARD_ATTRIBUTES KeyboardAttributes
FDO_DEVICE_EXTENSION Common
INTERNAL_I8042_HOOK_KEYBOARD KeyboardHook
KEYBOARD_SCAN_STATE KeyboardScanState
UNICODE_STRING PowerInterfaceName
KEYBOARD_INDICATOR_PARAMETERS KeyboardIndicators
PKEYBOARD_INPUT_DATA KeyboardBuffer
PIO_WORKITEM PowerWorkItem
ULONG PollStatusIterations
ULONG KeyboardDataQueueSize
IN PI8042_QUEUE_PACKET QueueKeyboardPacket
union _IRP::@1577 AssociatedIrp
KEYBOARD_ID KeyboardIdentifier
ULONG InputDataQueueLength
USHORT NumberOfIndicators
KEYBOARD_TYPEMATIC_PARAMETERS KeyRepeatMinimum
USHORT NumberOfFunctionKeys
INDICATOR_LIST IndicatorList[3]
USHORT NumberOfIndicatorKeys
PKINTERRUPT HighestDIRQLInterrupt
PI8042_KEYBOARD_EXTENSION KeyboardExtension
static LARGE_INTEGER Counter
#define RtlCopyMemory(Destination, Source, Length)
#define RtlZeroMemory(Destination, Length)
#define STATUS_INVALID_PARAMETER
#define STATUS_UNSUCCESSFUL
#define STATUS_INSUFFICIENT_RESOURCES
__analysis_noreturn NTSYSAPI VOID NTAPI DbgBreakPointWithStatus(_In_ ULONG Status)
_In_ PDEVICE_OBJECT DeviceObject
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_POWER_POLICY_IDLE_SETTINGS Settings
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
_Must_inspect_result_ _In_ PWDF_DPC_CONFIG _In_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFDPC * Dpc
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_INTERRUPT_CONFIG _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFINTERRUPT * Interrupt
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
_In_ WDFREQUEST _In_ PIO_STACK_LOCATION Stack
_Must_inspect_result_ _In_ PWDF_WORKITEM_CONFIG _In_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFWORKITEM * WorkItem
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
_In_opt_ PVOID _In_opt_ PVOID SystemArgument1
_In_opt_ PVOID DeferredContext
_In_opt_ PVOID _In_opt_ PVOID _In_opt_ PVOID SystemArgument2