ReactOS 0.4.15-dev-7953-g1f49173
mouclass.c File Reference
#include "mouclass.h"
#include <stdio.h>
#include <kbdmou.h>
#include <pseh/pseh2.h>
#include <debug.h>
Include dependency graph for mouclass.c:

Go to the source code of this file.

Functions

static NTSTATUS HandleReadIrp (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, BOOLEAN IsInStartIo)
 
static VOID NTAPI DriverUnload (IN PDRIVER_OBJECT DriverObject)
 
static NTSTATUS NTAPI ClassCreate (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
static NTSTATUS NTAPI ClassClose (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
static NTSTATUS NTAPI ClassCleanup (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
static NTSTATUS NTAPI ClassRead (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
static NTSTATUS NTAPI ClassDeviceControl (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
static NTSTATUS NTAPI ClassPower (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
static NTSTATUS ReadRegistryEntries (IN PUNICODE_STRING RegistryPath, IN PCLASS_DRIVER_EXTENSION DriverExtension)
 
static NTSTATUS CreateClassDeviceObject (IN PDRIVER_OBJECT DriverObject, OUT PDEVICE_OBJECT *ClassDO OPTIONAL)
 
static NTSTATUS FillEntries (IN PDEVICE_OBJECT ClassDeviceObject, IN PIRP Irp, IN PMOUSE_INPUT_DATA DataStart, IN SIZE_T NumberOfEntries)
 
static BOOLEAN NTAPI ClassCallback (IN PDEVICE_OBJECT ClassDeviceObject, IN OUT PMOUSE_INPUT_DATA DataStart, IN PMOUSE_INPUT_DATA DataEnd, IN OUT PULONG ConsumedCount)
 
static NTSTATUS ConnectPortDriver (IN PDEVICE_OBJECT PortDO, IN PDEVICE_OBJECT ClassDO)
 
static VOID DestroyPortDriver (IN PDEVICE_OBJECT PortDO)
 
static NTSTATUS NTAPI ClassAddDevice (IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT Pdo)
 
static VOID NTAPI ClassCancelRoutine (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
static NTSTATUS NTAPI ClassPnp (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
static VOID NTAPI ClassStartIo (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
static VOID NTAPI SearchForLegacyDrivers (IN PDRIVER_OBJECT DriverObject, IN PVOID Context, IN ULONG Count)
 
NTSTATUS NTAPI DriverEntry (IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath)
 

Variables

static DRIVER_UNLOAD DriverUnload
 
static DRIVER_DISPATCH ClassCreate
 
static DRIVER_DISPATCH ClassClose
 
static DRIVER_DISPATCH ClassCleanup
 
static DRIVER_DISPATCH ClassRead
 
static DRIVER_DISPATCH ClassDeviceControl
 
static DRIVER_DISPATCH ClassPower
 
static DRIVER_ADD_DEVICE ClassAddDevice
 
static DRIVER_STARTIO ClassStartIo
 
static DRIVER_CANCEL ClassCancelRoutine
 

Function Documentation

◆ ClassAddDevice()

static NTSTATUS NTAPI ClassAddDevice ( IN PDRIVER_OBJECT  DriverObject,
IN PDEVICE_OBJECT  Pdo 
)
static

Definition at line 604 of file mouclass.c.

607{
610 PPORT_DEVICE_EXTENSION DeviceExtension = NULL;
612
613 TRACE_(CLASS_NAME, "ClassAddDevice called. Pdo = 0x%p\n", Pdo);
614
616
617 if (Pdo == NULL)
618 /* We may get a NULL Pdo at the first call as we're a legacy driver. Ignore it */
619 return STATUS_SUCCESS;
620
621 /* Create new device object */
624 sizeof(PORT_DEVICE_EXTENSION),
625 NULL,
626 Pdo->DeviceType,
627 Pdo->Characteristics & FILE_DEVICE_SECURE_OPEN ? FILE_DEVICE_SECURE_OPEN : 0,
628 FALSE,
629 &Fdo);
630 if (!NT_SUCCESS(Status))
631 {
632 WARN_(CLASS_NAME, "IoCreateDevice() failed with status 0x%08lx\n", Status);
633 goto cleanup;
634 }
636
637 DeviceExtension = (PPORT_DEVICE_EXTENSION)Fdo->DeviceExtension;
638 RtlZeroMemory(DeviceExtension, sizeof(PORT_DEVICE_EXTENSION));
639 DeviceExtension->Common.IsClassDO = FALSE;
640 DeviceExtension->DeviceObject = Fdo;
641 DeviceExtension->PnpState = dsStopped;
643 if (!NT_SUCCESS(Status))
644 {
645 WARN_(CLASS_NAME, "IoAttachDeviceToDeviceStackSafe() failed with status 0x%08lx\n", Status);
646 goto cleanup;
647 }
648 if (DeviceExtension->LowerDevice->Flags & DO_POWER_PAGABLE)
649 Fdo->Flags |= DO_POWER_PAGABLE;
650 if (DeviceExtension->LowerDevice->Flags & DO_BUFFERED_IO)
651 Fdo->Flags |= DO_BUFFERED_IO;
652 if (DeviceExtension->LowerDevice->Flags & DO_DIRECT_IO)
653 Fdo->Flags |= DO_DIRECT_IO;
654
655 if (DriverExtension->ConnectMultiplePorts)
656 DeviceExtension->ClassDO = DriverExtension->MainClassDeviceObject;
657 else
658 {
659 /* We need a new class device object for this Fdo */
662 &DeviceExtension->ClassDO);
663 if (!NT_SUCCESS(Status))
664 {
665 WARN_(CLASS_NAME, "CreateClassDeviceObject() failed with status 0x%08lx\n", Status);
666 goto cleanup;
667 }
668 }
669 Status = ConnectPortDriver(Fdo, DeviceExtension->ClassDO);
670 if (!NT_SUCCESS(Status))
671 {
672 WARN_(CLASS_NAME, "ConnectPortDriver() failed with status 0x%08lx\n", Status);
673 goto cleanup;
674 }
675 Fdo->Flags &= ~DO_DEVICE_INITIALIZING;
676
677 /* Register interface ; ignore the error (if any) as having
678 * a registered interface is not so important... */
680 Pdo,
681 &GUID_DEVINTERFACE_MOUSE,
682 NULL,
683 &DeviceExtension->InterfaceName);
684 if (!NT_SUCCESS(Status))
685 DeviceExtension->InterfaceName.Length = 0;
686
687 return STATUS_SUCCESS;
688
689cleanup:
690 if (Fdo)
692 return Status;
693}
LONG NTSTATUS
Definition: precomp.h:26
#define FILE_DEVICE_SECURE_OPEN
Definition: cdrw_usr.h:46
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define TRACE_(x)
Definition: compat.h:76
static void cleanup(void)
Definition: main.c:1335
const TCHAR * CLASS_NAME
Definition: enumwnd.c:16
#define DO_BUFFERED_IO
Definition: env_spec_w32.h:394
#define DO_DIRECT_IO
Definition: env_spec_w32.h:396
Status
Definition: gdiplustypes.h:25
struct _PORT_DEVICE_EXTENSION * PPORT_DEVICE_EXTENSION
@ dsStopped
Definition: isapnp.h:34
static VOID DestroyPortDriver(IN PDEVICE_OBJECT PortDO)
Definition: mouclass.c:545
static NTSTATUS ConnectPortDriver(IN PDEVICE_OBJECT PortDO, IN PDEVICE_OBJECT ClassDO)
Definition: mouclass.c:491
static NTSTATUS CreateClassDeviceObject(IN PDRIVER_OBJECT DriverObject, OUT PDEVICE_OBJECT *ClassDO OPTIONAL)
Definition: mouclass.c:281
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
NTSTATUS NTAPI IoAttachDeviceToDeviceStackSafe(IN PDEVICE_OBJECT SourceDevice, IN PDEVICE_OBJECT TargetDevice, IN OUT PDEVICE_OBJECT *AttachedToDeviceObject)
Definition: device.c:980
VOID NTAPI IoSetStartIoAttributes(IN PDEVICE_OBJECT DeviceObject, IN BOOLEAN DeferredStartIo, IN BOOLEAN NonCancelable)
Definition: device.c:1798
NTSTATUS NTAPI IoRegisterDeviceInterface(IN PDEVICE_OBJECT PhysicalDeviceObject, IN CONST GUID *InterfaceClassGuid, IN PUNICODE_STRING ReferenceString OPTIONAL, OUT PUNICODE_STRING SymbolicLinkName)
Definition: deviface.c:955
PVOID NTAPI IoGetDriverObjectExtension(IN PDRIVER_OBJECT DriverObject, IN PVOID ClientIdentificationAddress)
Definition: driver.c:1904
PPCI_DRIVER_EXTENSION DriverExtension
Definition: pci.c:31
#define WARN_(ch,...)
Definition: debug.h:157
#define STATUS_SUCCESS
Definition: shellext.h:65
PDEVICE_OBJECT DeviceObject
Definition: kbdclass.h:45
UNICODE_STRING InterfaceName
Definition: kbdclass.h:50
PORT_DEVICE_STATE PnpState
Definition: kbdclass.h:46
PDEVICE_OBJECT ClassDO
Definition: kbdclass.h:48
COMMON_DEVICE_EXTENSION Common
Definition: kbdclass.h:42
PDEVICE_OBJECT LowerDevice
Definition: kbdclass.h:47
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
_Must_inspect_result_ _In_ WDFDEVICE Fdo
Definition: wdffdo.h:461
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
Definition: wdfminiport.h:72
#define DO_POWER_PAGABLE

◆ ClassCallback()

static BOOLEAN NTAPI ClassCallback ( IN PDEVICE_OBJECT  ClassDeviceObject,
IN OUT PMOUSE_INPUT_DATA  DataStart,
IN PMOUSE_INPUT_DATA  DataEnd,
IN OUT PULONG  ConsumedCount 
)
static

Definition at line 436 of file mouclass.c.

441{
442 PCLASS_DEVICE_EXTENSION ClassDeviceExtension = ClassDeviceObject->DeviceExtension;
444 SIZE_T InputCount = DataEnd - DataStart;
445 SIZE_T ReadSize;
446
447 TRACE_(CLASS_NAME, "ClassCallback()\n");
448
449 ASSERT(ClassDeviceExtension->Common.IsClassDO);
450
451 KeAcquireSpinLock(&ClassDeviceExtension->SpinLock, &OldIrql);
452 if (InputCount > 0)
453 {
454 if (ClassDeviceExtension->InputCount + InputCount > ClassDeviceExtension->DriverExtension->DataQueueSize)
455 {
456 /*
457 * We're exceeding the buffer, and data will be thrown away...
458 * FIXME: What could we do, as we are at DISPATCH_LEVEL?
459 */
460 ReadSize = ClassDeviceExtension->DriverExtension->DataQueueSize - ClassDeviceExtension->InputCount;
461 }
462 else
463 ReadSize = InputCount;
464
465 /*
466 * Move the input data from the port data queue to our class data
467 * queue.
468 */
470 &ClassDeviceExtension->PortData[ClassDeviceExtension->InputCount],
471 (PCHAR)DataStart,
472 sizeof(MOUSE_INPUT_DATA) * ReadSize);
473
474 /* Move the counter up */
475 ClassDeviceExtension->InputCount += ReadSize;
476
477 (*ConsumedCount) += (ULONG)ReadSize;
478
479 /* Complete pending IRP (if any) */
480 if (ClassDeviceExtension->PendingIrp)
481 HandleReadIrp(ClassDeviceObject, ClassDeviceExtension->PendingIrp, FALSE);
482 }
483 KeReleaseSpinLock(&ClassDeviceExtension->SpinLock, OldIrql);
484
485 TRACE_(CLASS_NAME, "Leaving ClassCallback()\n");
486 return TRUE;
487}
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
#define ASSERT(a)
Definition: mode.c:44
static NTSTATUS HandleReadIrp(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, BOOLEAN IsInStartIo)
Definition: mouclass.c:732
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
uint32_t ULONG
Definition: typedefs.h:59
char * PCHAR
Definition: typedefs.h:51
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:778

Referenced by ConnectPortDriver().

◆ ClassCancelRoutine()

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

Definition at line 696 of file mouclass.c.

699{
700 PCLASS_DEVICE_EXTENSION ClassDeviceExtension = DeviceObject->DeviceExtension;
702 BOOLEAN wasQueued = FALSE;
703
704 TRACE_(CLASS_NAME, "ClassCancelRoutine(DeviceObject %p, Irp %p)\n", DeviceObject, Irp);
705
706 ASSERT(ClassDeviceExtension->Common.IsClassDO);
707
708 IoReleaseCancelSpinLock(Irp->CancelIrql);
709
710 KeAcquireSpinLock(&ClassDeviceExtension->SpinLock, &OldIrql);
711
712 if (ClassDeviceExtension->PendingIrp == Irp)
713 {
714 ClassDeviceExtension->PendingIrp = NULL;
715 wasQueued = TRUE;
716 }
717 KeReleaseSpinLock(&ClassDeviceExtension->SpinLock, OldIrql);
718
719 if (wasQueued)
720 {
721 Irp->IoStatus.Status = STATUS_CANCELLED;
722 Irp->IoStatus.Information = 0;
724 }
725 else
726 {
727 DPRINT1("Cancelled IRP is not pending. Race condition?\n");
728 }
729}
unsigned char BOOLEAN
#define DPRINT1
Definition: precomp.h:8
_In_ PIRP Irp
Definition: csq.h:116
#define IoCompleteRequest
Definition: irp.c:1240
VOID NTAPI IoReleaseCancelSpinLock(IN KIRQL Irql)
Definition: util.c:150
#define STATUS_CANCELLED
Definition: udferr_usr.h:170
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
#define IO_NO_INCREMENT
Definition: iotypes.h:598

◆ ClassCleanup()

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

Definition at line 74 of file mouclass.c.

77{
78 TRACE_(CLASS_NAME, "IRP_MJ_CLEANUP\n");
79
80 if (!((PCOMMON_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->IsClassDO)
82
83 /* FIXME: cleanup all associated Port devices */
84 Irp->IoStatus.Status = STATUS_SUCCESS;
85 Irp->IoStatus.Information = 0;
87 return STATUS_SUCCESS;
88}
DRIVER_DISPATCH ForwardIrpAndForget
Definition: i8042prt.h:341

◆ ClassClose()

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

Definition at line 57 of file mouclass.c.

60{
61 TRACE_(CLASS_NAME, "IRP_MJ_CLOSE\n");
62
63 if (!((PCOMMON_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->IsClassDO)
65
66 /* FIXME: close all associated Port devices */
67 Irp->IoStatus.Status = STATUS_SUCCESS;
68 Irp->IoStatus.Information = 0;
70 return STATUS_SUCCESS;
71}

◆ ClassCreate()

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

Definition at line 40 of file mouclass.c.

43{
44 TRACE_(CLASS_NAME, "IRP_MJ_CREATE\n");
45
46 if (!((PCOMMON_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->IsClassDO)
48
49 /* FIXME: open all associated Port devices */
50 Irp->IoStatus.Status = STATUS_SUCCESS;
51 Irp->IoStatus.Information = 0;
53 return STATUS_SUCCESS;
54}

◆ ClassDeviceControl()

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

Definition at line 122 of file mouclass.c.

125{
126 //PCLASS_DEVICE_EXTENSION DeviceExtension;
128
129 TRACE_(CLASS_NAME, "IRP_MJ_DEVICE_CONTROL\n");
130
131 if (!((PCOMMON_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->IsClassDO)
133
134 //DeviceExtension = (PCLASS_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
135
137 {
139 {
140 /* FIXME: We hope that all devices will return the same result.
141 * Ask only the first one */
142 PLIST_ENTRY Head = &((PCLASS_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->ListHead;
143 if (Head->Flink != Head)
144 {
145 /* We have at least one device */
149 return IoCallDriver(DevExt->DeviceObject, Irp);
150 }
151 break;
152 }
153 default:
154 WARN_(CLASS_NAME, "IRP_MJ_DEVICE_CONTROL / unknown I/O control code 0x%lx\n",
156 ASSERT(FALSE);
157 break;
158 }
159
160 Irp->IoStatus.Status = Status;
161 Irp->IoStatus.Information = 0;
163
164 return Status;
165}
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
#define IOCTL_MOUSE_QUERY_ATTRIBUTES
Definition: ntddmou.h:32
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
#define IoCallDriver
Definition: irp.c:1225
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:423
struct _IO_STACK_LOCATION::@1564::@1565 DeviceIoControl
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
_Must_inspect_result_ _In_ WDFQUEUE _In_opt_ WDFREQUEST _In_opt_ WDFFILEOBJECT _Inout_opt_ PWDF_REQUEST_PARAMETERS Parameters
Definition: wdfio.h:869
#define IRP_MJ_INTERNAL_DEVICE_CONTROL

◆ ClassPnp()

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

Definition at line 802 of file mouclass.c.

805{
806 PPORT_DEVICE_EXTENSION DeviceExtension = DeviceObject->DeviceExtension;
811
812 switch (IrpSp->MinorFunction)
813 {
815 if (IoForwardIrpSynchronously(DeviceExtension->LowerDevice, Irp))
816 {
817 Status = Irp->IoStatus.Status;
818 }
819 else
820 {
822 }
823
824 if (NT_SUCCESS(Status))
825 {
827 &DeviceExtension->InterfaceName,
829 NULL,
830 NULL);
831
832 Status = ZwOpenFile(&DeviceExtension->FileHandle,
835 &Iosb,
836 0,
837 0);
838 if (!NT_SUCCESS(Status))
839 DeviceExtension->FileHandle = NULL;
840 }
841 else
842 DeviceExtension->FileHandle = NULL;
843 Irp->IoStatus.Status = Status;
845 return Status;
846
848 if (DeviceExtension->FileHandle)
849 {
850 ZwClose(DeviceExtension->FileHandle);
851 DeviceExtension->FileHandle = NULL;
852 }
854 break;
855
857 if (DeviceExtension->FileHandle)
858 {
859 ZwClose(DeviceExtension->FileHandle);
860 DeviceExtension->FileHandle = NULL;
861 }
863 Status = IoCallDriver(DeviceExtension->LowerDevice, Irp);
865 return Status;
866
867 default:
868 Status = Irp->IoStatus.Status;
869 break;
870 }
871
872 Irp->IoStatus.Status = Status;
874 {
876 return IoCallDriver(DeviceExtension->LowerDevice, Irp);
877 }
878 else
879 {
881 return Status;
882 }
883}
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4137
return Iosb
Definition: create.c:4402
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
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)
#define FILE_READ_DATA
Definition: nt_native.h:628
BOOLEAN NTAPI IoForwardIrpSynchronously(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1625
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define IRP_MN_START_DEVICE
#define IRP_MN_REMOVE_DEVICE
#define IRP_MN_STOP_DEVICE

Referenced by DriverEntry().

◆ ClassPower()

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

Definition at line 168 of file mouclass.c.

171{
173 PPORT_DEVICE_EXTENSION DeviceExtension;
174
175 DeviceExtension = DeviceObject->DeviceExtension;
176 if (!DeviceExtension->Common.IsClassDO)
177 {
178 /* Forward port DO IRPs to lower device */
181 return PoCallDriver(DeviceExtension->LowerDevice, Irp);
182 }
183
185 {
186 case IRP_MN_SET_POWER:
188 Irp->IoStatus.Status = STATUS_SUCCESS;
189 break;
190 }
191 Status = Irp->IoStatus.Status;
194 return Status;
195}
VOID NTAPI PoStartNextPowerIrp(IN PIRP Irp)
Definition: power.c:758
_In_ UCHAR _In_ UCHAR MinorFunction
Definition: wdfdevice.h:1699
#define IRP_MN_SET_POWER
#define IRP_MN_QUERY_POWER

◆ ClassRead()

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

Definition at line 91 of file mouclass.c.

94{
95 PCLASS_DEVICE_EXTENSION DeviceExtension = DeviceObject->DeviceExtension;
98
99 TRACE_(CLASS_NAME, "IRP_MJ_READ\n");
100
101 ASSERT(DeviceExtension->Common.IsClassDO);
102
103 if (!((PCOMMON_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->IsClassDO)
105
107 {
108 Irp->IoStatus.Status = STATUS_BUFFER_TOO_SMALL;
109 Irp->IoStatus.Information = 0;
111
113 }
114
115 KeAcquireSpinLock(&DeviceExtension->SpinLock, &OldIrql);
117 KeReleaseSpinLock(&DeviceExtension->SpinLock, OldIrql);
118 return Status;
119}
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
struct _IO_STACK_LOCATION::@3978::@3982 Read

◆ ClassStartIo()

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

Definition at line 886 of file mouclass.c.

889{
890 PCLASS_DEVICE_EXTENSION DeviceExtension = DeviceObject->DeviceExtension;
892
893 TRACE_(CLASS_NAME, "ClassStartIo(DeviceObject %p, Irp %p)\n", DeviceObject, Irp);
894
895 ASSERT(DeviceExtension->Common.IsClassDO);
896
897 KeAcquireSpinLock(&DeviceExtension->SpinLock, &OldIrql);
899 KeReleaseSpinLock(&DeviceExtension->SpinLock, OldIrql);
900}

◆ ConnectPortDriver()

static NTSTATUS ConnectPortDriver ( IN PDEVICE_OBJECT  PortDO,
IN PDEVICE_OBJECT  ClassDO 
)
static

Definition at line 491 of file mouclass.c.

494{
496 PIRP Irp;
498 CONNECT_DATA ConnectData;
500
501 TRACE_(CLASS_NAME, "Connecting PortDO %p to ClassDO %p\n", PortDO, ClassDO);
502
504
505 ConnectData.ClassDeviceObject = ClassDO;
506 ConnectData.ClassService = ClassCallback;
507
510 PortDO,
511 &ConnectData, sizeof(CONNECT_DATA),
512 NULL, 0,
513 TRUE, &Event, &IoStatus);
514 if (!Irp)
516
517 Status = IoCallDriver(PortDO, Irp);
518
519 if (Status == STATUS_PENDING)
521 else
522 IoStatus.Status = Status;
523
524 if (NT_SUCCESS(IoStatus.Status))
525 {
526 ObReferenceObject(PortDO);
528 &((PCLASS_DEVICE_EXTENSION)ClassDO->DeviceExtension)->ListHead,
529 &((PPORT_DEVICE_EXTENSION)PortDO->DeviceExtension)->ListEntry,
530 &((PCLASS_DEVICE_EXTENSION)ClassDO->DeviceExtension)->ListSpinLock);
531 if (ClassDO->StackSize <= PortDO->StackSize)
532 {
533 /* Increase the stack size, in case we have to
534 * forward some IRPs to the port device object
535 */
536 ClassDO->StackSize = PortDO->StackSize + 1;
537 }
538 }
539
540 return IoStatus.Status;
541}
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
PLIST_ENTRY NTAPI ExInterlockedInsertTailList(IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY ListEntry, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:140
#define IOCTL_INTERNAL_MOUSE_CONNECT
Definition: kbdmou.h:68
static BOOLEAN NTAPI ClassCallback(IN PDEVICE_OBJECT ClassDeviceObject, IN OUT PMOUSE_INPUT_DATA DataStart, IN PMOUSE_INPUT_DATA DataEnd, IN OUT PULONG ConsumedCount)
Definition: mouclass.c:436
__in UCHAR __in POWER_STATE __in_opt PVOID __in PIO_STATUS_BLOCK IoStatus
Definition: mxum.h:159
#define KernelMode
Definition: asm.h:34
@ NotificationEvent
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
#define STATUS_PENDING
Definition: ntstatus.h:82
PVOID ClassService
Definition: kbdmou.h:82
PDEVICE_OBJECT ClassDeviceObject
Definition: kbdmou.h:81
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
@ Suspended
Definition: ketypes.h:420
#define ObReferenceObject
Definition: obfuncs.h:204

Referenced by ClassAddDevice().

◆ CreateClassDeviceObject()

static NTSTATUS CreateClassDeviceObject ( IN PDRIVER_OBJECT  DriverObject,
OUT PDEVICE_OBJECT *ClassDO  OPTIONAL 
)
static

Definition at line 281 of file mouclass.c.

284{
286 ULONG DeviceId = 0;
287 ULONG PrefixLength;
288 UNICODE_STRING DeviceNameU;
289 PWSTR DeviceIdW = NULL; /* Pointer into DeviceNameU.Buffer */
291 PCLASS_DEVICE_EXTENSION DeviceExtension;
293
294 TRACE_(CLASS_NAME, "CreateClassDeviceObject(0x%p)\n", DriverObject);
295
296 /* Create new device object */
298 DeviceNameU.Length = 0;
299 DeviceNameU.MaximumLength =
300 (USHORT)wcslen(L"\\Device\\") * sizeof(WCHAR) /* "\Device\" */
301 + DriverExtension->DeviceBaseName.Length /* "PointerClass" */
302 + 4 * sizeof(WCHAR) /* Id between 0 and 9999 */
303 + sizeof(UNICODE_NULL); /* Final NULL char */
304 DeviceNameU.Buffer = ExAllocatePoolWithTag(PagedPool, DeviceNameU.MaximumLength, CLASS_TAG);
305 if (!DeviceNameU.Buffer)
306 {
307 WARN_(CLASS_NAME, "ExAllocatePoolWithTag() failed\n");
308 return STATUS_NO_MEMORY;
309 }
310 Status = RtlAppendUnicodeToString(&DeviceNameU, L"\\Device\\");
311 if (!NT_SUCCESS(Status))
312 {
313 WARN_(CLASS_NAME, "RtlAppendUnicodeToString() failed with status 0x%08lx\n", Status);
314 goto cleanup;
315 }
316 Status = RtlAppendUnicodeStringToString(&DeviceNameU, &DriverExtension->DeviceBaseName);
317 if (!NT_SUCCESS(Status))
318 {
319 WARN_(CLASS_NAME, "RtlAppendUnicodeStringToString() failed with status 0x%08lx\n", Status);
320 goto cleanup;
321 }
322 PrefixLength = DeviceNameU.MaximumLength - 4 * sizeof(WCHAR) - sizeof(UNICODE_NULL);
323 DeviceIdW = &DeviceNameU.Buffer[PrefixLength / sizeof(WCHAR)];
324 while (DeviceId < 9999)
325 {
326 DeviceNameU.Length = (USHORT)(PrefixLength + swprintf(DeviceIdW, L"%lu", DeviceId) * sizeof(WCHAR));
330 &DeviceNameU,
333 FALSE,
334 &Fdo);
335 if (NT_SUCCESS(Status))
336 goto cleanup;
338 {
339 WARN_(CLASS_NAME, "IoCreateDevice() failed with status 0x%08lx\n", Status);
340 goto cleanup;
341 }
342 DeviceId++;
343 }
344 WARN_(CLASS_NAME, "Too many devices starting with '\\Device\\%wZ'\n", &DriverExtension->DeviceBaseName);
346cleanup:
347 if (!NT_SUCCESS(Status))
348 {
349 ExFreePoolWithTag(DeviceNameU.Buffer, CLASS_TAG);
350 return Status;
351 }
352
353 DeviceExtension = (PCLASS_DEVICE_EXTENSION)Fdo->DeviceExtension;
354 RtlZeroMemory(DeviceExtension, sizeof(CLASS_DEVICE_EXTENSION));
355 DeviceExtension->Common.IsClassDO = TRUE;
356 DeviceExtension->DriverExtension = DriverExtension;
357 InitializeListHead(&DeviceExtension->ListHead);
358 KeInitializeSpinLock(&DeviceExtension->ListSpinLock);
359 KeInitializeSpinLock(&DeviceExtension->SpinLock);
360 DeviceExtension->InputCount = 0;
361 DeviceExtension->PortData = ExAllocatePoolWithTag(NonPagedPool, DeviceExtension->DriverExtension->DataQueueSize * sizeof(MOUSE_INPUT_DATA), CLASS_TAG);
362 if (!DeviceExtension->PortData)
363 {
364 ExFreePoolWithTag(DeviceNameU.Buffer, CLASS_TAG);
365 return STATUS_NO_MEMORY;
366 }
367 DeviceExtension->DeviceName = DeviceNameU.Buffer;
368 Fdo->Flags |= DO_POWER_PAGABLE;
369 Fdo->Flags &= ~DO_DEVICE_INITIALIZING;
370 Fdo->Flags |= DO_BUFFERED_IO;
371
372 /* Add entry entry to HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\[DeviceBaseName] */
375 DriverExtension->DeviceBaseName.Buffer,
376 DeviceExtension->DeviceName,
377 REG_SZ,
378 DriverExtension->RegistryPath.Buffer,
379 DriverExtension->RegistryPath.MaximumLength);
380
381 if (ClassDO)
382 *ClassDO = Fdo;
383
384 return STATUS_SUCCESS;
385}
#define swprintf
Definition: precomp.h:40
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
NTSTATUS RtlAppendUnicodeToString(IN PUNICODE_STRING Str1, IN PWSTR Str2)
Definition: string_lib.cpp:62
#define NonPagedPool
Definition: env_spec_w32.h:307
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define KeInitializeSpinLock(sl)
Definition: env_spec_w32.h:604
#define PagedPool
Definition: env_spec_w32.h:308
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
NTSYSAPI NTSTATUS WINAPI RtlWriteRegistryValue(ULONG, PCWSTR, PCWSTR, ULONG, PVOID, ULONG)
#define CLASS_TAG
Definition: kbdclass.h:11
#define REG_SZ
Definition: layer.c:22
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
NTSYSAPI NTSTATUS NTAPI RtlAppendUnicodeStringToString(PUNICODE_STRING Destination, PUNICODE_STRING Source)
#define RTL_REGISTRY_DEVICEMAP
Definition: nt_native.h:165
#define UNICODE_NULL
#define STATUS_TOO_MANY_NAMES
Definition: ntstatus.h:441
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
#define L(x)
Definition: ntvdm.h:50
unsigned short USHORT
Definition: pedump.c:61
#define FILE_DEVICE_MOUSE
Definition: winioctl.h:121
USHORT MaximumLength
Definition: env_spec_w32.h:370
uint16_t * PWSTR
Definition: typedefs.h:56
#define STATUS_OBJECT_NAME_COLLISION
Definition: udferr_usr.h:150
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by ClassAddDevice(), and DriverEntry().

◆ DestroyPortDriver()

static VOID DestroyPortDriver ( IN PDEVICE_OBJECT  PortDO)
static

Definition at line 545 of file mouclass.c.

547{
548 PPORT_DEVICE_EXTENSION DeviceExtension;
549 PCLASS_DEVICE_EXTENSION ClassDeviceExtension;
552 PIRP Irp;
556
557 TRACE_(CLASS_NAME, "Destroying PortDO %p\n", PortDO);
558
559 DeviceExtension = (PPORT_DEVICE_EXTENSION)PortDO->DeviceExtension;
560 ClassDeviceExtension = DeviceExtension->ClassDO->DeviceExtension;
561 DriverExtension = IoGetDriverObjectExtension(PortDO->DriverObject, PortDO->DriverObject);
562
563 /* Send IOCTL_INTERNAL_*_DISCONNECT */
567 PortDO,
568 NULL, 0,
569 NULL, 0,
570 TRUE, &Event, &IoStatus);
571 if (Irp)
572 {
573 Status = IoCallDriver(PortDO, Irp);
574 if (Status == STATUS_PENDING)
576 }
577
578 /* Remove from ClassDeviceExtension->ListHead list */
579 KeAcquireSpinLock(&ClassDeviceExtension->ListSpinLock, &OldIrql);
580 RemoveEntryList(&DeviceExtension->ListEntry);
581 KeReleaseSpinLock(&ClassDeviceExtension->ListSpinLock, OldIrql);
582
583 /* Remove entry from HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\[DeviceBaseName] */
586 DriverExtension->DeviceBaseName.Buffer,
587 ClassDeviceExtension->DeviceName);
588
589 if (DeviceExtension->LowerDevice)
590 IoDetachDevice(DeviceExtension->LowerDevice);
591 ObDereferenceObject(PortDO);
592
593 if (!DriverExtension->ConnectMultiplePorts && DeviceExtension->ClassDO)
594 {
595 ExFreePoolWithTag(ClassDeviceExtension->PortData, CLASS_TAG);
596 ExFreePoolWithTag((PVOID)ClassDeviceExtension->DeviceName, CLASS_TAG);
597 IoDeleteDevice(DeviceExtension->ClassDO);
598 }
599
600 IoDeleteDevice(PortDO);
601}
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
NTSYSAPI NTSTATUS WINAPI RtlDeleteRegistryValue(ULONG, PCWSTR, PCWSTR)
#define IOCTL_INTERNAL_MOUSE_DISCONNECT
Definition: kbdmou.h:71
VOID NTAPI IoDetachDevice(IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:1296
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
PVOID DeviceExtension
Definition: env_spec_w32.h:418
LIST_ENTRY ListEntry
Definition: kbdclass.h:44
#define ObDereferenceObject
Definition: obfuncs.h:203

Referenced by ClassAddDevice(), and ClassPnp().

◆ DriverEntry()

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

Definition at line 1021 of file mouclass.c.

1024{
1027
1031 sizeof(CLASS_DRIVER_EXTENSION),
1033 if (!NT_SUCCESS(Status))
1034 {
1035 WARN_(CLASS_NAME, "IoAllocateDriverObjectExtension() failed with status 0x%08lx\n", Status);
1036 return Status;
1037 }
1039
1043 &DriverExtension->RegistryPath);
1044 if (!NT_SUCCESS(Status))
1045 {
1046 WARN_(CLASS_NAME, "DuplicateUnicodeString() failed with status 0x%08lx\n", Status);
1047 return Status;
1048 }
1049
1051 if (!NT_SUCCESS(Status))
1052 {
1053 WARN_(CLASS_NAME, "ReadRegistryEntries() failed with status 0x%08lx\n", Status);
1054 return Status;
1055 }
1056
1057 if (DriverExtension->ConnectMultiplePorts == 1)
1058 {
1061 &DriverExtension->MainClassDeviceObject);
1062 if (!NT_SUCCESS(Status))
1063 {
1064 WARN_(CLASS_NAME, "CreateClassDeviceObject() failed with status 0x%08lx\n", Status);
1065 return Status;
1066 }
1067 }
1068
1069 DriverObject->DriverExtension->AddDevice = ClassAddDevice;
1070 DriverObject->DriverUnload = DriverUnload;
1071
1072 DriverObject->MajorFunction[IRP_MJ_CREATE] = ClassCreate;
1073 DriverObject->MajorFunction[IRP_MJ_CLOSE] = ClassClose;
1074 DriverObject->MajorFunction[IRP_MJ_CLEANUP] = ClassCleanup;
1075 DriverObject->MajorFunction[IRP_MJ_READ] = ClassRead;
1076 DriverObject->MajorFunction[IRP_MJ_POWER] = ClassPower;
1077 DriverObject->MajorFunction[IRP_MJ_PNP] = ClassPnp;
1080 DriverObject->DriverStartIo = ClassStartIo;
1081
1082 /* We will detect the legacy devices later */
1087
1088 return STATUS_SUCCESS;
1089}
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
#define RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE
Definition: green.h:15
NTSTATUS DuplicateUnicodeString(IN ULONG Flags, IN PCUNICODE_STRING SourceString, OUT PUNICODE_STRING DestinationString)
Definition: misc.c:31
static DRIVER_DISPATCH ClassDeviceControl
Definition: mouclass.c:22
static DRIVER_DISPATCH ClassRead
Definition: mouclass.c:21
static DRIVER_ADD_DEVICE ClassAddDevice
Definition: mouclass.c:24
static VOID NTAPI SearchForLegacyDrivers(IN PDRIVER_OBJECT DriverObject, IN PVOID Context, IN ULONG Count)
Definition: mouclass.c:903
static NTSTATUS ReadRegistryEntries(IN PUNICODE_STRING RegistryPath, IN PCLASS_DRIVER_EXTENSION DriverExtension)
Definition: mouclass.c:198
static DRIVER_DISPATCH ClassClose
Definition: mouclass.c:19
static NTSTATUS NTAPI ClassPnp(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: mouclass.c:802
static DRIVER_DISPATCH ClassCleanup
Definition: mouclass.c:20
static DRIVER_DISPATCH ClassPower
Definition: mouclass.c:23
static DRIVER_DISPATCH ClassCreate
Definition: mouclass.c:18
static DRIVER_STARTIO ClassStartIo
Definition: mouclass.c:25
static DRIVER_UNLOAD DriverUnload
Definition: mouclass.c:17
VOID NTAPI IoRegisterDriverReinitialization(IN PDRIVER_OBJECT DriverObject, IN PDRIVER_REINITIALIZE ReinitRoutine, IN PVOID Context)
Definition: driver.c:1797
NTSTATUS NTAPI IoAllocateDriverObjectExtension(IN PDRIVER_OBJECT DriverObject, IN PVOID ClientIdentificationAddress, IN ULONG DriverObjectExtensionSize, OUT PVOID *DriverObjectExtension)
Definition: driver.c:1826
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
#define IRP_MJ_READ
Definition: rdpdr.c:46
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING RegistryPath
Definition: wdfdriver.h:215
#define IRP_MJ_POWER
#define IRP_MJ_CLEANUP

◆ DriverUnload()

static VOID NTAPI DriverUnload ( IN PDRIVER_OBJECT  DriverObject)
static

Definition at line 34 of file mouclass.c.

35{
36 // nothing to do here yet
37}

◆ FillEntries()

static NTSTATUS FillEntries ( IN PDEVICE_OBJECT  ClassDeviceObject,
IN PIRP  Irp,
IN PMOUSE_INPUT_DATA  DataStart,
IN SIZE_T  NumberOfEntries 
)
static

Definition at line 388 of file mouclass.c.

393{
395
396 if (ClassDeviceObject->Flags & DO_BUFFERED_IO)
397 {
399 Irp->AssociatedIrp.SystemBuffer,
400 DataStart,
401 NumberOfEntries * sizeof(MOUSE_INPUT_DATA));
402 }
403 else if (ClassDeviceObject->Flags & DO_DIRECT_IO)
404 {
405 PVOID DestAddress = MmGetSystemAddressForMdlSafe(Irp->MdlAddress, NormalPagePriority);
406 if (DestAddress)
407 {
409 DestAddress,
410 DataStart,
411 NumberOfEntries * sizeof(MOUSE_INPUT_DATA));
412 }
413 else
415 }
416 else
417 {
419 {
421 Irp->UserBuffer,
422 DataStart,
423 NumberOfEntries * sizeof(MOUSE_INPUT_DATA));
424 }
426 {
428 }
429 _SEH2_END;
430 }
431
432 return Status;
433}
#define _SEH2_END
Definition: filesup.c:22
#define _SEH2_TRY
Definition: filesup.c:19
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
@ NormalPagePriority
Definition: imports.h:56
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:159
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:34
#define MmGetSystemAddressForMdlSafe(_Mdl, _Priority)

Referenced by HandleReadIrp().

◆ HandleReadIrp()

static NTSTATUS HandleReadIrp ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp,
BOOLEAN  IsInStartIo 
)
static

Definition at line 732 of file mouclass.c.

736{
737 PCLASS_DEVICE_EXTENSION DeviceExtension = DeviceObject->DeviceExtension;
740
741 TRACE_(CLASS_NAME, "HandleReadIrp(DeviceObject %p, Irp %p)\n", DeviceObject, Irp);
742
743 ASSERT(DeviceExtension->Common.IsClassDO);
744
745 if (DeviceExtension->InputCount > 0)
746 {
747 SIZE_T NumberOfEntries;
748
749 NumberOfEntries = MIN(
750 DeviceExtension->InputCount,
752
755 Irp,
756 DeviceExtension->PortData,
757 NumberOfEntries);
758
759 if (NT_SUCCESS(Status))
760 {
761 if (DeviceExtension->InputCount > NumberOfEntries)
762 {
764 &DeviceExtension->PortData[0],
765 &DeviceExtension->PortData[NumberOfEntries],
766 (DeviceExtension->InputCount - NumberOfEntries) * sizeof(MOUSE_INPUT_DATA));
767 }
768
769 DeviceExtension->InputCount -= NumberOfEntries;
770
771 Irp->IoStatus.Information = NumberOfEntries * sizeof(MOUSE_INPUT_DATA);
772 }
773
774 /* Go to next packet and complete this request */
775 Irp->IoStatus.Status = Status;
776
779 DeviceExtension->PendingIrp = NULL;
780 }
781 else
782 {
784 if (Irp->Cancel)
785 {
786 DeviceExtension->PendingIrp = NULL;
788 }
789 else
790 {
792 DeviceExtension->PendingIrp = Irp;
795 }
797 }
798 return Status;
799}
#define VOID
Definition: acefi.h:82
#define MIN(x, y)
Definition: rdesktop.h:171
IoMarkIrpPending(Irp)
IoSetCancelRoutine(Irp, CancelRoutine)
static DRIVER_CANCEL ClassCancelRoutine
Definition: mouclass.c:26
static NTSTATUS FillEntries(IN PDEVICE_OBJECT ClassDeviceObject, IN PIRP Irp, IN PMOUSE_INPUT_DATA DataStart, IN SIZE_T NumberOfEntries)
Definition: mouclass.c:388
struct _MOUSE_INPUT_DATA MOUSE_INPUT_DATA
VOID NTAPI IoAcquireCancelSpinLock(OUT PKIRQL Irql)
Definition: util.c:56
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:264
#define IO_MOUSE_INCREMENT
Definition: iotypes.h:603

Referenced by ClassCallback(), ClassRead(), and ClassStartIo().

◆ ReadRegistryEntries()

static NTSTATUS ReadRegistryEntries ( IN PUNICODE_STRING  RegistryPath,
IN PCLASS_DRIVER_EXTENSION  DriverExtension 
)
static

Definition at line 198 of file mouclass.c.

201{
202 UNICODE_STRING ParametersRegistryKey;
205
206 ULONG DefaultConnectMultiplePorts = 1;
207 ULONG DefaultDataQueueSize = 0x64;
208 PCWSTR DefaultDeviceBaseName = L"PointerClass";
209
210 ParametersRegistryKey.Length = 0;
211 ParametersRegistryKey.MaximumLength = RegistryPath->Length + sizeof(L"\\Parameters") + sizeof(UNICODE_NULL);
212 ParametersRegistryKey.Buffer = ExAllocatePoolWithTag(PagedPool, ParametersRegistryKey.MaximumLength, CLASS_TAG);
213 if (!ParametersRegistryKey.Buffer)
214 {
215 WARN_(CLASS_NAME, "ExAllocatePoolWithTag() failed\n");
216 return STATUS_NO_MEMORY;
217 }
218 RtlCopyUnicodeString(&ParametersRegistryKey, RegistryPath);
219 RtlAppendUnicodeToString(&ParametersRegistryKey, L"\\Parameters");
220 ParametersRegistryKey.Buffer[ParametersRegistryKey.Length / sizeof(WCHAR)] = UNICODE_NULL;
221
223
225 Parameters[0].Name = L"ConnectMultiplePorts";
226 Parameters[0].EntryContext = &DriverExtension->ConnectMultiplePorts;
227 Parameters[0].DefaultType = REG_DWORD;
228 Parameters[0].DefaultData = &DefaultConnectMultiplePorts;
229 Parameters[0].DefaultLength = sizeof(ULONG);
230
232 Parameters[1].Name = L"MouseDataQueueSize";
233 Parameters[1].EntryContext = &DriverExtension->DataQueueSize;
234 Parameters[1].DefaultType = REG_DWORD;
235 Parameters[1].DefaultData = &DefaultDataQueueSize;
236 Parameters[1].DefaultLength = sizeof(ULONG);
237
239 Parameters[2].Name = L"PointerDeviceBaseName";
240 Parameters[2].EntryContext = &DriverExtension->DeviceBaseName;
241 Parameters[2].DefaultType = REG_SZ;
242 Parameters[2].DefaultData = (PVOID)DefaultDeviceBaseName;
243 Parameters[2].DefaultLength = 0;
244
247 ParametersRegistryKey.Buffer,
249 NULL,
250 NULL);
251
252 if (NT_SUCCESS(Status))
253 {
254 /* Check values */
255 if (DriverExtension->ConnectMultiplePorts != 0
256 && DriverExtension->ConnectMultiplePorts != 1)
257 {
258 DriverExtension->ConnectMultiplePorts = DefaultConnectMultiplePorts;
259 }
260 if (DriverExtension->DataQueueSize == 0)
261 {
262 DriverExtension->DataQueueSize = DefaultDataQueueSize;
263 }
264 }
266 {
267 /* Registry path doesn't exist. Set defaults */
268 DriverExtension->ConnectMultiplePorts = DefaultConnectMultiplePorts;
269 DriverExtension->DataQueueSize = DefaultDataQueueSize;
270 if (RtlCreateUnicodeString(&DriverExtension->DeviceBaseName, DefaultDeviceBaseName))
272 else
274 }
275
276 ExFreePoolWithTag(ParametersRegistryKey.Buffer, CLASS_TAG);
277 return Status;
278}
NTSYSAPI BOOLEAN NTAPI RtlCreateUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
NTSYSAPI NTSTATUS WINAPI RtlQueryRegistryValues(ULONG, PCWSTR, PRTL_QUERY_REGISTRY_TABLE, PVOID, PVOID)
NTSYSAPI VOID NTAPI RtlCopyUnicodeString(PUNICODE_STRING DestinationString, PUNICODE_STRING SourceString)
#define RTL_REGISTRY_ABSOLUTE
Definition: nt_native.h:161
#define RTL_QUERY_REGISTRY_DIRECT
Definition: nt_native.h:144
#define RTL_REGISTRY_OPTIONAL
Definition: nt_native.h:169
#define REG_DWORD
Definition: sdbapi.c:596
const uint16_t * PCWSTR
Definition: typedefs.h:57
void * PVOID
Definition: typedefs.h:50
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149

Referenced by DriverEntry().

◆ SearchForLegacyDrivers()

static VOID NTAPI SearchForLegacyDrivers ( IN PDRIVER_OBJECT  DriverObject,
IN PVOID  Context,
IN ULONG  Count 
)
static

Definition at line 903 of file mouclass.c.

907{
908 UNICODE_STRING DeviceMapKeyU = RTL_CONSTANT_STRING(L"\\REGISTRY\\MACHINE\\HARDWARE\\DEVICEMAP");
910 UNICODE_STRING PortBaseName = { 0, 0, NULL };
911 PKEY_VALUE_BASIC_INFORMATION KeyValueInformation = NULL;
913 HANDLE hDeviceMapKey = (HANDLE)-1;
914 HANDLE hPortKey = (HANDLE)-1;
915 ULONG Index = 0;
918
919 TRACE_(CLASS_NAME, "SearchForLegacyDrivers(%p %p %lu)\n",
921
922 if (Count != 1)
923 return;
925
926 /* Create port base name, by replacing Class by Port at the end of the class base name */
929 &DriverExtension->DeviceBaseName,
930 &PortBaseName);
931 if (!NT_SUCCESS(Status))
932 {
933 WARN_(CLASS_NAME, "DuplicateUnicodeString() failed with status 0x%08lx\n", Status);
934 goto cleanup;
935 }
936 PortBaseName.Length -= (sizeof(L"Class") - sizeof(UNICODE_NULL));
937 RtlAppendUnicodeToString(&PortBaseName, L"Port");
938
939 /* Allocate memory */
941 KeyValueInformation = ExAllocatePoolWithTag(PagedPool, Size, CLASS_TAG);
942 if (!KeyValueInformation)
943 {
944 WARN_(CLASS_NAME, "ExAllocatePoolWithTag() failed\n");
946 goto cleanup;
947 }
948
949 /* Open HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP */
951 Status = ZwOpenKey(&hDeviceMapKey, 0, &ObjectAttributes);
953 {
954 INFO_(CLASS_NAME, "HKLM\\HARDWARE\\DEVICEMAP is non-existent\n");
956 goto cleanup;
957 }
958 else if (!NT_SUCCESS(Status))
959 {
960 WARN_(CLASS_NAME, "ZwOpenKey() failed with status 0x%08lx\n", Status);
961 goto cleanup;
962 }
963
964 /* Open sub key */
966 Status = ZwOpenKey(&hPortKey, KEY_QUERY_VALUE, &ObjectAttributes);
968 {
969 INFO_(CLASS_NAME, "HKLM\\HARDWARE\\DEVICEMAP\\%wZ is non-existent\n", &PortBaseName);
971 goto cleanup;
972 }
973 else if (!NT_SUCCESS(Status))
974 {
975 WARN_(CLASS_NAME, "ZwOpenKey() failed with status 0x%08lx\n", Status);
976 goto cleanup;
977 }
978
979 /* Read each value name */
980 while (ZwEnumerateValueKey(hPortKey, Index++, KeyValueBasicInformation, KeyValueInformation, Size, &ResultLength) == STATUS_SUCCESS)
981 {
983 PDEVICE_OBJECT PortDeviceObject = NULL;
985
986 PortName.Length = PortName.MaximumLength = (USHORT)KeyValueInformation->NameLength;
987 PortName.Buffer = KeyValueInformation->Name;
988
989 /* Open the device object pointer */
991 if (!NT_SUCCESS(Status))
992 {
993 WARN_(CLASS_NAME, "IoGetDeviceObjectPointer(%wZ) failed with status 0x%08lx\n", &PortName, Status);
994 continue;
995 }
996 INFO_(CLASS_NAME, "Legacy driver found\n");
997
998 Status = ClassAddDevice(DriverObject, PortDeviceObject);
999 if (!NT_SUCCESS(Status))
1000 {
1001 /* FIXME: Log the error */
1002 WARN_(CLASS_NAME, "ClassAddDevice() failed with status 0x%08lx\n", Status);
1003 }
1004
1006 }
1007
1008cleanup:
1009 if (KeyValueInformation != NULL)
1010 ExFreePoolWithTag(KeyValueInformation, CLASS_TAG);
1011 if (hDeviceMapKey != (HANDLE)-1)
1012 ZwClose(hDeviceMapKey);
1013 if (hPortKey != (HANDLE)-1)
1014 ZwClose(hPortKey);
1015}
static UNICODE_STRING PortName
#define MAX_PATH
Definition: compat.h:34
struct _CLASS_DRIVER_EXTENSION * PCLASS_DRIVER_EXTENSION
int Count
Definition: noreturn.cpp:7
struct _KEY_VALUE_BASIC_INFORMATION KEY_VALUE_BASIC_INFORMATION
@ KeyValueBasicInformation
Definition: nt_native.h:1180
#define FILE_READ_ATTRIBUTES
Definition: nt_native.h:647
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
NTSTATUS NTAPI IoGetDeviceObjectPointer(IN PUNICODE_STRING ObjectName, IN ACCESS_MASK DesiredAccess, OUT PFILE_OBJECT *FileObject, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1435
#define INFO_(ch,...)
Definition: debug.h:159
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
PVOID HANDLE
Definition: typedefs.h:73
_In_ WDFCOLLECTION _In_ ULONG Index
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG _Out_ PULONG ResultLength
Definition: wdfdevice.h:3776
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:550
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
* PFILE_OBJECT
Definition: iotypes.h:1998

Referenced by DriverEntry().

Variable Documentation

◆ ClassAddDevice

DRIVER_ADD_DEVICE ClassAddDevice
static

Definition at line 24 of file mouclass.c.

Referenced by DriverEntry(), and SearchForLegacyDrivers().

◆ ClassCancelRoutine

DRIVER_CANCEL ClassCancelRoutine
static

Definition at line 26 of file mouclass.c.

Referenced by HandleReadIrp().

◆ ClassCleanup

DRIVER_DISPATCH ClassCleanup
static

Definition at line 20 of file mouclass.c.

Referenced by DriverEntry().

◆ ClassClose

DRIVER_DISPATCH ClassClose
static

Definition at line 19 of file mouclass.c.

Referenced by DriverEntry().

◆ ClassCreate

DRIVER_DISPATCH ClassCreate
static

Definition at line 18 of file mouclass.c.

Referenced by DriverEntry().

◆ ClassDeviceControl

DRIVER_DISPATCH ClassDeviceControl
static

Definition at line 22 of file mouclass.c.

Referenced by DriverEntry().

◆ ClassPower

DRIVER_DISPATCH ClassPower
static

Definition at line 23 of file mouclass.c.

Referenced by DriverEntry().

◆ ClassRead

DRIVER_DISPATCH ClassRead
static

Definition at line 21 of file mouclass.c.

Referenced by DriverEntry().

◆ ClassStartIo

DRIVER_STARTIO ClassStartIo
static

Definition at line 25 of file mouclass.c.

Referenced by DriverEntry().

◆ DriverUnload

DRIVER_UNLOAD DriverUnload
static

Definition at line 17 of file mouclass.c.

Referenced by DriverEntry().