51 Irp->IoStatus.Information = 0;
68 Irp->IoStatus.Information = 0;
85 Irp->IoStatus.Information = 0;
101 ASSERT(DeviceExtension->Common.IsClassDO);
109 Irp->IoStatus.Information = 0;
146 if (Head->
Flink != Head)
163 while (
Entry != Head)
186 WARN_(
CLASS_NAME,
"IRP_MJ_DEVICE_CONTROL / unknown I/O control code 0x%lx\n",
193 Irp->IoStatus.Information = 0;
239 ULONG DefaultConnectMultiplePorts = 1;
240 ULONG DefaultDataQueueSize = 0x64;
241 PCWSTR DefaultDeviceBaseName =
L"KeyboardClass";
243 ParametersRegistryKey.
Length = 0;
246 if (!ParametersRegistryKey.
Buffer)
261 Parameters[0].DefaultData = &DefaultConnectMultiplePorts;
268 Parameters[1].DefaultData = &DefaultDataQueueSize;
280 ParametersRegistryKey.
Buffer,
356 DeviceIdW = &DeviceNameU.
Buffer[PrefixLength /
sizeof(
WCHAR)];
357 while (DeviceId < 9999)
388 DeviceExtension->Common.IsClassDO =
TRUE;
393 DeviceExtension->InputCount = 0;
395 if (!DeviceExtension->PortData)
400 DeviceExtension->DeviceName = DeviceNameU.
Buffer;
403 Fdo->Flags &= ~DO_DEVICE_INITIALIZING;
409 DeviceExtension->DeviceName,
432 Irp->AssociatedIrp.SystemBuffer,
477 SIZE_T InputCount = DataEnd - DataStart;
482 ASSERT(ClassDeviceExtension->Common.IsClassDO);
487 if (ClassDeviceExtension->InputCount + InputCount > ClassDeviceExtension->DriverExtension->DataQueueSize)
493 ReadSize = ClassDeviceExtension->DriverExtension->DataQueueSize - ClassDeviceExtension->InputCount;
496 ReadSize = InputCount;
503 &ClassDeviceExtension->PortData[ClassDeviceExtension->InputCount],
508 ClassDeviceExtension->InputCount += ReadSize;
510 (*ConsumedCount) += (
ULONG)ReadSize;
513 if (ClassDeviceExtension->PendingIrp)
534 TRACE_(
CLASS_NAME,
"Connecting PortDO %p to ClassDO %p\n", PortDO, ClassDO);
564 if (ClassDO->StackSize <= PortDO->StackSize)
569 ClassDO->StackSize = PortDO->StackSize + 1;
620 ClassDeviceExtension->DeviceName);
708 Fdo->Flags &= ~DO_DEVICE_INITIALIZING;
714 &GUID_DEVINTERFACE_KEYBOARD,
739 ASSERT(ClassDeviceExtension->Common.IsClassDO);
745 if (ClassDeviceExtension->PendingIrp ==
Irp)
747 ClassDeviceExtension->PendingIrp =
NULL;
755 Irp->IoStatus.Information = 0;
760 DPRINT1(
"Cancelled IRP is not pending. Race condition?\n");
776 ASSERT(DeviceExtension->Common.IsClassDO);
778 if (DeviceExtension->InputCount > 0)
782 NumberOfEntries =
MIN(
783 DeviceExtension->InputCount,
789 DeviceExtension->PortData,
794 if (DeviceExtension->InputCount > NumberOfEntries)
797 &DeviceExtension->PortData[0],
798 &DeviceExtension->PortData[NumberOfEntries],
802 DeviceExtension->InputCount -= NumberOfEntries;
812 DeviceExtension->PendingIrp =
NULL;
819 DeviceExtension->PendingIrp =
NULL;
825 DeviceExtension->PendingIrp =
Irp;
928 ASSERT(DeviceExtension->Common.IsClassDO);
975 if (!KeyValueInformation)
1002 INFO_(
CLASS_NAME,
"HKLM\\HARDWARE\\DEVICEMAP\\%wZ is non-existent\n", &PortBaseName);
1042 if (KeyValueInformation !=
NULL)
1044 if (hDeviceMapKey != (
HANDLE)-1)
1046 if (hPortKey != (
HANDLE)-1)
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
static UNICODE_STRING PortName
#define FILE_DEVICE_SECURE_OPEN
NTSYSAPI BOOLEAN NTAPI RtlCreateUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
#define NT_SUCCESS(StatCode)
static void cleanup(void)
DRIVER_INITIALIZE DriverEntry
_In_ PIO_STACK_LOCATION IrpSp
#define RemoveEntryList(Entry)
#define ExAllocatePoolWithTag(hernya, size, tag)
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
#define KeInitializeEvent(pEvt, foo, foo2)
#define KeReleaseSpinLock(sl, irql)
NTSTATUS RtlAppendUnicodeToString(IN PUNICODE_STRING Str1, IN PWSTR Str2)
#define KeAcquireSpinLock(sl, irql)
#define InitializeListHead(ListHead)
#define KeInitializeSpinLock(sl)
#define RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE
struct _PORT_DEVICE_EXTENSION * PPORT_DEVICE_EXTENSION
NTSTATUS DuplicateUnicodeString(IN ULONG Flags, IN PCUNICODE_STRING SourceString, OUT PUNICODE_STRING DestinationString)
DRIVER_DISPATCH ForwardIrpAndForget
#define EXCEPTION_EXECUTE_HANDLER
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define OBJ_KERNEL_HANDLE
#define OBJ_CASE_INSENSITIVE
NTSYSAPI NTSTATUS WINAPI RtlDeleteRegistryValue(ULONG, PCWSTR, PCWSTR)
NTSYSAPI NTSTATUS WINAPI RtlWriteRegistryValue(ULONG, PCWSTR, PCWSTR, ULONG, PVOID, ULONG)
NTSYSAPI NTSTATUS WINAPI RtlQueryRegistryValues(ULONG, PCWSTR, PRTL_QUERY_REGISTRY_TABLE, PVOID, PVOID)
PLIST_ENTRY NTAPI ExInterlockedInsertTailList(IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY ListEntry, IN OUT PKSPIN_LOCK Lock)
IoSetCancelRoutine(Irp, CancelRoutine)
static DRIVER_DISPATCH ClassDeviceControl
static DRIVER_DISPATCH ClassRead
static VOID DestroyPortDriver(IN PDEVICE_OBJECT PortDO)
static DRIVER_ADD_DEVICE ClassAddDevice
static NTSTATUS FillEntries(IN PDEVICE_OBJECT ClassDeviceObject, IN PIRP Irp, IN PKEYBOARD_INPUT_DATA DataStart, IN SIZE_T NumberOfEntries)
static DRIVER_CANCEL ClassCancelRoutine
static VOID NTAPI SearchForLegacyDrivers(IN PDRIVER_OBJECT DriverObject, IN PVOID Context, IN ULONG Count)
static NTSTATUS ReadRegistryEntries(IN PUNICODE_STRING RegistryPath, IN PCLASS_DRIVER_EXTENSION DriverExtension)
static DRIVER_DISPATCH ClassClose
static NTSTATUS ConnectPortDriver(IN PDEVICE_OBJECT PortDO, IN PDEVICE_OBJECT ClassDO)
static NTSTATUS NTAPI ClassPnp(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
static DRIVER_DISPATCH ClassCleanup
static BOOLEAN NTAPI ClassCallback(IN PDEVICE_OBJECT ClassDeviceObject, IN OUT PKEYBOARD_INPUT_DATA DataStart, IN PKEYBOARD_INPUT_DATA DataEnd, IN OUT PULONG ConsumedCount)
static NTSTATUS CreateClassDeviceObject(IN PDRIVER_OBJECT DriverObject, OUT PDEVICE_OBJECT *ClassDO OPTIONAL)
static DRIVER_DISPATCH ClassPower
static DRIVER_DISPATCH ClassCreate
static DRIVER_STARTIO ClassStartIo
static DRIVER_UNLOAD DriverUnload
static NTSTATUS HandleReadIrp(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, BOOLEAN IsInStartIo)
struct _CLASS_DRIVER_EXTENSION * PCLASS_DRIVER_EXTENSION
#define IOCTL_INTERNAL_KEYBOARD_CONNECT
#define IOCTL_INTERNAL_KEYBOARD_DISCONNECT
#define ExFreePoolWithTag(_P, _T)
#define InitializeObjectAttributes(p, n, a, r, s)
__in UCHAR __in POWER_STATE __in_opt PVOID __in PIO_STATUS_BLOCK IoStatus
NTSYSAPI NTSTATUS NTAPI ZwOpenFile(_Out_ PHANDLE FileHandle, _In_ ACCESS_MASK DesiredAccess, _In_ POBJECT_ATTRIBUTES ObjectAttributes, _Out_ PIO_STATUS_BLOCK IoStatusBlock, _In_ ULONG ShareAccess, _In_ ULONG OpenOptions)
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
DRIVER_DISPATCH(nfs41_FsdDispatch)
NTSYSAPI VOID NTAPI RtlCopyUnicodeString(PUNICODE_STRING DestinationString, PUNICODE_STRING SourceString)
struct _KEY_VALUE_BASIC_INFORMATION KEY_VALUE_BASIC_INFORMATION
@ KeyValueBasicInformation
NTSYSAPI NTSTATUS NTAPI RtlAppendUnicodeStringToString(PUNICODE_STRING Destination, PUNICODE_STRING Source)
#define FILE_READ_ATTRIBUTES
#define RTL_REGISTRY_ABSOLUTE
#define RTL_REGISTRY_DEVICEMAP
#define RTL_QUERY_REGISTRY_DIRECT
#define RTL_REGISTRY_OPTIONAL
struct _KEYBOARD_INPUT_DATA KEYBOARD_INPUT_DATA
#define IOCTL_KEYBOARD_QUERY_TYPEMATIC
#define IOCTL_KEYBOARD_QUERY_INDICATORS
#define IOCTL_KEYBOARD_SET_INDICATORS
#define IOCTL_KEYBOARD_QUERY_ATTRIBUTES
#define IOCTL_KEYBOARD_QUERY_INDICATOR_TRANSLATION
#define IOCTL_KEYBOARD_SET_TYPEMATIC
#define IoSkipCurrentIrpStackLocation(Irp)
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)
NTSTATUS NTAPI IoAttachDeviceToDeviceStackSafe(IN PDEVICE_OBJECT SourceDevice, IN PDEVICE_OBJECT TargetDevice, IN OUT PDEVICE_OBJECT *AttachedToDeviceObject)
VOID NTAPI IoDetachDevice(IN PDEVICE_OBJECT TargetDevice)
VOID NTAPI IoSetStartIoAttributes(IN PDEVICE_OBJECT DeviceObject, IN BOOLEAN DeferredStartIo, IN BOOLEAN NonCancelable)
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
NTSTATUS NTAPI IoGetDeviceObjectPointer(IN PUNICODE_STRING ObjectName, IN ACCESS_MASK DesiredAccess, OUT PFILE_OBJECT *FileObject, OUT PDEVICE_OBJECT *DeviceObject)
NTSTATUS NTAPI IoRegisterDeviceInterface(IN PDEVICE_OBJECT PhysicalDeviceObject, IN CONST GUID *InterfaceClassGuid, IN PUNICODE_STRING ReferenceString OPTIONAL, OUT PUNICODE_STRING SymbolicLinkName)
PVOID NTAPI IoGetDriverObjectExtension(IN PDRIVER_OBJECT DriverObject, IN PVOID ClientIdentificationAddress)
VOID NTAPI IoRegisterDriverReinitialization(IN PDRIVER_OBJECT DriverObject, IN PDRIVER_REINITIALIZE ReinitRoutine, IN PVOID Context)
NTSTATUS NTAPI IoAllocateDriverObjectExtension(IN PDRIVER_OBJECT DriverObject, IN PVOID ClientIdentificationAddress, IN ULONG DriverObjectExtensionSize, OUT PVOID *DriverObjectExtension)
#define IoCompleteRequest
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)
BOOLEAN NTAPI IoForwardIrpSynchronously(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
VOID NTAPI IoReleaseCancelSpinLock(IN KIRQL Irql)
VOID NTAPI IoAcquireCancelSpinLock(OUT PKIRQL Irql)
VOID NTAPI PoStartNextPowerIrp(IN PIRP Irp)
#define STATUS_TOO_MANY_NAMES
#define STATUS_NOT_SUPPORTED
PPCI_DRIVER_EXTENSION DriverExtension
#define FILE_DEVICE_KEYBOARD
#define _SEH2_GetExceptionCode()
#define _SEH2_EXCEPT(...)
#define IRP_MJ_DEVICE_CONTROL
#define STATUS_BUFFER_TOO_SMALL
PULONG MinorVersion OPTIONAL
base of all file and directory entries
PDEVICE_OBJECT ClassDeviceObject
struct _IO_STACK_LOCATION::@3970::@3974 Read
struct _IO_STACK_LOCATION::@1575::@1576 DeviceIoControl
struct _LIST_ENTRY * Flink
PDEVICE_OBJECT DeviceObject
UNICODE_STRING InterfaceName
PORT_DEVICE_STATE PnpState
COMMON_DEVICE_EXTENSION Common
PDEVICE_OBJECT LowerDevice
#define RTL_CONSTANT_STRING(s)
#define RtlCopyMemory(Destination, Source, Length)
#define RtlZeroMemory(Destination, Length)
#define RtlMoveMemory(Destination, Source, Length)
#define CONTAINING_RECORD(address, type, field)
#define STATUS_UNSUCCESSFUL
#define STATUS_OBJECT_NAME_COLLISION
#define STATUS_INSUFFICIENT_RESOURCES
#define STATUS_OBJECT_NAME_NOT_FOUND
_In_ WDFCOLLECTION _In_ ULONG Index
_In_ PDEVICE_OBJECT DeviceObject
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG _Out_ PULONG ResultLength
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
_In_ UCHAR _In_ UCHAR MinorFunction
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING RegistryPath
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
_Must_inspect_result_ _In_ WDFDEVICE Fdo
_Must_inspect_result_ _In_ WDFQUEUE _In_opt_ WDFREQUEST _In_opt_ WDFFILEOBJECT _Inout_opt_ PWDF_REQUEST_PARAMETERS Parameters
WDF_EXTERN_C_START typedef _Must_inspect_result_ _In_ WDFDRIVER _In_opt_ PWDF_OBJECT_ATTRIBUTES _In_ PDEVICE_OBJECT _In_opt_ PDEVICE_OBJECT _In_opt_ PDEVICE_OBJECT Pdo
#define IRP_MN_START_DEVICE
#define IRP_MN_REMOVE_DEVICE
#define IRP_MJ_INTERNAL_DEVICE_CONTROL
#define IRP_MN_STOP_DEVICE
#define IO_KEYBOARD_INCREMENT
#define IRP_MN_QUERY_POWER
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
#define MmGetSystemAddressForMdlSafe(_Mdl, _Priority)
#define ObDereferenceObject
#define ObReferenceObject