ReactOS  0.4.15-dev-1200-gc3b3fcd
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 {
609  PDEVICE_OBJECT Fdo = NULL;
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 */
623  DriverObject,
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;
642  Status = IoAttachDeviceToDeviceStackSafe(Fdo, Pdo, &DeviceExtension->LowerDevice);
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 */
661  DriverObject,
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 
689 cleanup:
690  if (Fdo)
691  DestroyPortDriver(Fdo);
692  return Status;
693 }
#define DO_DEVICE_INITIALIZING
Definition: env_spec_w32.h:399
#define DO_POWER_PAGABLE
_In_ PDEVICE_OBJECT Pdo
Definition: classpnp.h:318
#define TRUE
Definition: types.h:120
COMMON_DEVICE_EXTENSION Common
Definition: kbdclass.h:42
LONG NTSTATUS
Definition: precomp.h:26
static NTSTATUS ConnectPortDriver(IN PDEVICE_OBJECT PortDO, IN PDEVICE_OBJECT ClassDO)
Definition: mouclass.c:491
#define DO_DIRECT_IO
Definition: env_spec_w32.h:396
PDEVICE_OBJECT ClassDO
Definition: kbdclass.h:48
#define FALSE
Definition: types.h:117
UNICODE_STRING InterfaceName
Definition: kbdclass.h:50
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
#define TRACE_(x)
Definition: compat.h:76
static VOID DestroyPortDriver(IN PDEVICE_OBJECT PortDO)
Definition: mouclass.c:545
NTSTATUS NTAPI IoAttachDeviceToDeviceStackSafe(IN PDEVICE_OBJECT SourceDevice, IN PDEVICE_OBJECT TargetDevice, IN OUT PDEVICE_OBJECT *AttachedToDeviceObject)
Definition: device.c:980
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
VOID NTAPI IoSetStartIoAttributes(IN PDEVICE_OBJECT DeviceObject, IN BOOLEAN DeferredStartIo, IN BOOLEAN NonCancelable)
Definition: device.c:1798
#define DO_BUFFERED_IO
Definition: env_spec_w32.h:394
PDEVICE_OBJECT LowerDevice
Definition: kbdclass.h:47
Status
Definition: gdiplustypes.h:24
struct _PORT_DEVICE_EXTENSION * PPORT_DEVICE_EXTENSION
PVOID NTAPI IoGetDriverObjectExtension(IN PDRIVER_OBJECT DriverObject, IN PVOID ClientIdentificationAddress)
Definition: driver.c:1866
const TCHAR * CLASS_NAME
Definition: enumwnd.c:16
static NTSTATUS CreateClassDeviceObject(IN PDRIVER_OBJECT DriverObject, OUT PDEVICE_OBJECT *ClassDO OPTIONAL)
Definition: mouclass.c:281
PPCI_DRIVER_EXTENSION DriverExtension
Definition: pci.c:41
NTSTATUS NTAPI IoRegisterDeviceInterface(IN PDEVICE_OBJECT PhysicalDeviceObject, IN CONST GUID *InterfaceClassGuid, IN PUNICODE_STRING ReferenceString OPTIONAL, OUT PUNICODE_STRING SymbolicLinkName)
Definition: deviface.c:955
NTSTATUS NTAPI IoCreateDevice(IN PDRIVER_OBJECT DriverObject, IN ULONG DeviceExtensionSize, IN PUNICODE_STRING DeviceName, IN DEVICE_TYPE DeviceType, IN ULONG DeviceCharacteristics, IN BOOLEAN Exclusive, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1031
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
char * cleanup(char *str)
Definition: wpickclick.c:99
#define FILE_DEVICE_SECURE_OPEN
Definition: cdrw_usr.h:46
PDEVICE_OBJECT DeviceObject
Definition: kbdclass.h:45
return STATUS_SUCCESS
Definition: btrfs.c:3014
PORT_DEVICE_STATE PnpState
Definition: kbdclass.h:46
#define WARN_(ch,...)
Definition: debug.h:157

◆ 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;
443  KIRQL OldIrql;
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 }
signed char * PCHAR
Definition: retypes.h:7
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define TRUE
Definition: types.h:120
static NTSTATUS HandleReadIrp(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, BOOLEAN IsInStartIo)
Definition: mouclass.c:732
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define FALSE
Definition: types.h:117
#define TRACE_(x)
Definition: compat.h:76
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
const TCHAR * CLASS_NAME
Definition: enumwnd.c:16
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
unsigned int ULONG
Definition: retypes.h:1

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;
701  KIRQL OldIrql;
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 }
_In_ PIRP Irp
Definition: csq.h:116
#define TRUE
Definition: types.h:120
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define FALSE
Definition: types.h:117
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
#define TRACE_(x)
Definition: compat.h:76
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
#define STATUS_CANCELLED
Definition: udferr_usr.h:170
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
const TCHAR * CLASS_NAME
Definition: enumwnd.c:16
VOID NTAPI IoReleaseCancelSpinLock(IN KIRQL Irql)
Definition: util.c:150
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define DPRINT1
Definition: precomp.h:8
#define IO_NO_INCREMENT
Definition: iotypes.h:581

◆ 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 }
_In_ PIRP Irp
Definition: csq.h:116
DRIVER_DISPATCH ForwardIrpAndForget
Definition: i8042prt.h:341
#define IoCompleteRequest
Definition: irp.c:1240
#define TRACE_(x)
Definition: compat.h:76
const TCHAR * CLASS_NAME
Definition: enumwnd.c:16
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
#define IO_NO_INCREMENT
Definition: iotypes.h:581
return STATUS_SUCCESS
Definition: btrfs.c:3014

◆ 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 }
_In_ PIRP Irp
Definition: csq.h:116
DRIVER_DISPATCH ForwardIrpAndForget
Definition: i8042prt.h:341
#define IoCompleteRequest
Definition: irp.c:1240
#define TRACE_(x)
Definition: compat.h:76
const TCHAR * CLASS_NAME
Definition: enumwnd.c:16
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
#define IO_NO_INCREMENT
Definition: iotypes.h:581
return STATUS_SUCCESS
Definition: btrfs.c:3014

◆ 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 }
_In_ PIRP Irp
Definition: csq.h:116
DRIVER_DISPATCH ForwardIrpAndForget
Definition: i8042prt.h:341
#define IoCompleteRequest
Definition: irp.c:1240
#define TRACE_(x)
Definition: compat.h:76
const TCHAR * CLASS_NAME
Definition: enumwnd.c:16
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
#define IO_NO_INCREMENT
Definition: iotypes.h:581
return STATUS_SUCCESS
Definition: btrfs.c:3014

◆ 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 
136  switch (IoGetCurrentIrpStackLocation(Irp)->Parameters.DeviceIoControl.IoControlCode)
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",
155  IoGetCurrentIrpStackLocation(Irp)->Parameters.DeviceIoControl.IoControlCode);
156  ASSERT(FALSE);
157  break;
158  }
159 
160  Irp->IoStatus.Status = Status;
161  Irp->IoStatus.Information = 0;
163 
164  return Status;
165 }
_In_ PIRP Irp
Definition: csq.h:116
DRIVER_DISPATCH ForwardIrpAndForget
Definition: i8042prt.h:341
LONG NTSTATUS
Definition: precomp.h:26
struct _CLASS_DEVICE_EXTENSION * PCLASS_DEVICE_EXTENSION
#define FALSE
Definition: types.h:117
#define IoCompleteRequest
Definition: irp.c:1240
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
#define TRACE_(x)
Definition: compat.h:76
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
#define IRP_MJ_INTERNAL_DEVICE_CONTROL
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Status
Definition: gdiplustypes.h:24
_In_ PPCI_DEVICE_PRESENCE_PARAMETERS Parameters
Definition: iotypes.h:887
#define IOCTL_MOUSE_QUERY_ATTRIBUTES
Definition: ntddmou.h:32
const TCHAR * CLASS_NAME
Definition: enumwnd.c:16
Definition: typedefs.h:119
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2789
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:423
#define IO_NO_INCREMENT
Definition: iotypes.h:581
PDEVICE_OBJECT DeviceObject
Definition: kbdclass.h:45
#define WARN_(ch,...)
Definition: debug.h:157

◆ 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  {
814  case IRP_MN_START_DEVICE:
816  if (NT_SUCCESS(Status))
817  {
819  &DeviceExtension->InterfaceName,
821  NULL,
822  NULL);
823 
824  Status = ZwOpenFile(&DeviceExtension->FileHandle,
827  &Iosb,
828  0,
829  0);
830  if (!NT_SUCCESS(Status))
831  DeviceExtension->FileHandle = NULL;
832  }
833  else
834  DeviceExtension->FileHandle = NULL;
835  Irp->IoStatus.Status = Status;
837  return Status;
838 
839  case IRP_MN_STOP_DEVICE:
840  if (DeviceExtension->FileHandle)
841  {
842  ZwClose(DeviceExtension->FileHandle);
843  DeviceExtension->FileHandle = NULL;
844  }
846  break;
847 
849  if (DeviceExtension->FileHandle)
850  {
851  ZwClose(DeviceExtension->FileHandle);
852  DeviceExtension->FileHandle = NULL;
853  }
855  Status = IoCallDriver(DeviceExtension->LowerDevice, Irp);
857  return Status;
858 
859  default:
860  Status = Irp->IoStatus.Status;
861  break;
862  }
863 
864  Irp->IoStatus.Status = Status;
866  {
868  return IoCallDriver(DeviceExtension->LowerDevice, Irp);
869  }
870  else
871  {
873  return Status;
874  }
875 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define IRP_MN_REMOVE_DEVICE
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
_In_ PIRP Irp
Definition: csq.h:116
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
LONG NTSTATUS
Definition: precomp.h:26
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define FILE_READ_DATA
Definition: nt_native.h:628
UNICODE_STRING InterfaceName
Definition: kbdclass.h:50
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
static VOID DestroyPortDriver(IN PDEVICE_OBJECT PortDO)
Definition: mouclass.c:545
#define IRP_MN_STOP_DEVICE
return Iosb
Definition: create.c:4402
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
PDEVICE_OBJECT LowerDevice
Definition: kbdclass.h:47
#define IRP_MN_START_DEVICE
DRIVER_DISPATCH ForwardIrpAndWait
Definition: i8042prt.h:343
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)
Status
Definition: gdiplustypes.h:24
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2789
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4137
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:423
#define IO_NO_INCREMENT
Definition: iotypes.h:581
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
return STATUS_SUCCESS
Definition: btrfs.c:3014

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:
187  case IRP_MN_QUERY_POWER:
188  Irp->IoStatus.Status = STATUS_SUCCESS;
189  break;
190  }
191  Status = Irp->IoStatus.Status;
194  return Status;
195 }
#define IRP_MN_QUERY_POWER
_In_ PIRP Irp
Definition: csq.h:116
COMMON_DEVICE_EXTENSION Common
Definition: kbdclass.h:42
LONG NTSTATUS
Definition: precomp.h:26
#define IoCompleteRequest
Definition: irp.c:1240
PDEVICE_OBJECT LowerDevice
Definition: kbdclass.h:47
Status
Definition: gdiplustypes.h:24
#define IRP_MN_SET_POWER
_In_ UCHAR MinorFunction
Definition: pofuncs.h:42
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2789
VOID NTAPI PoStartNextPowerIrp(IN PIRP Irp)
Definition: power.c:737
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
#define IO_NO_INCREMENT
Definition: iotypes.h:581
return STATUS_SUCCESS
Definition: btrfs.c:3014

◆ 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;
96  KIRQL OldIrql;
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 
106  if (IoGetCurrentIrpStackLocation(Irp)->Parameters.Read.Length < sizeof(MOUSE_INPUT_DATA))
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 }
_In_ PIRP Irp
Definition: csq.h:116
DRIVER_DISPATCH ForwardIrpAndForget
Definition: i8042prt.h:341
LONG NTSTATUS
Definition: precomp.h:26
static NTSTATUS HandleReadIrp(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, BOOLEAN IsInStartIo)
Definition: mouclass.c:732
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define FALSE
Definition: types.h:117
#define IoCompleteRequest
Definition: irp.c:1240
#define TRACE_(x)
Definition: compat.h:76
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Status
Definition: gdiplustypes.h:24
_In_ PPCI_DEVICE_PRESENCE_PARAMETERS Parameters
Definition: iotypes.h:887
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
const TCHAR * CLASS_NAME
Definition: enumwnd.c:16
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2789
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define IO_NO_INCREMENT
Definition: iotypes.h:581

◆ ClassStartIo()

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

Definition at line 878 of file mouclass.c.

881 {
882  PCLASS_DEVICE_EXTENSION DeviceExtension = DeviceObject->DeviceExtension;
883  KIRQL OldIrql;
884 
885  TRACE_(CLASS_NAME, "ClassStartIo(DeviceObject %p, Irp %p)\n", DeviceObject, Irp);
886 
887  ASSERT(DeviceExtension->Common.IsClassDO);
888 
889  KeAcquireSpinLock(&DeviceExtension->SpinLock, &OldIrql);
891  KeReleaseSpinLock(&DeviceExtension->SpinLock, OldIrql);
892 }
_In_ PIRP Irp
Definition: csq.h:116
#define TRUE
Definition: types.h:120
static NTSTATUS HandleReadIrp(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, BOOLEAN IsInStartIo)
Definition: mouclass.c:732
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define TRACE_(x)
Definition: compat.h:76
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
const TCHAR * CLASS_NAME
Definition: enumwnd.c:16
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627

◆ ConnectPortDriver()

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

Definition at line 491 of file mouclass.c.

494 {
495  KEVENT Event;
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 }
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
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
IN PLARGE_INTEGER IN ULONG IN BOOLEAN IN ULONG IN BOOLEAN OUT PIO_STATUS_BLOCK IoStatus
Definition: fatprocs.h:2659
_In_ PIRP Irp
Definition: csq.h:116
#define TRUE
Definition: types.h:120
PLIST_ENTRY NTAPI ExInterlockedInsertTailList(IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY ListEntry, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:140
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
#define FALSE
Definition: types.h:117
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:450
smooth NULL
Definition: ftsmooth.c:416
#define TRACE_(x)
Definition: compat.h:76
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
PVOID ClassService
Definition: kbdmou.h:82
#define IOCTL_INTERNAL_MOUSE_CONNECT
Definition: kbdmou.h:68
Status
Definition: gdiplustypes.h:24
const TCHAR * CLASS_NAME
Definition: enumwnd.c:16
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
PIRP NTAPI IoBuildDeviceIoControlRequest(IN ULONG IoControlCode, IN PDEVICE_OBJECT DeviceObject, IN PVOID InputBuffer, IN ULONG InputBufferLength, IN PVOID OutputBuffer, IN ULONG OutputBufferLength, IN BOOLEAN InternalDeviceIoControl, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:881
#define ObReferenceObject
Definition: obfuncs.h:204
PDEVICE_OBJECT ClassDeviceObject
Definition: kbdmou.h:81

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 */
290  PDEVICE_OBJECT Fdo;
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  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));
328  DriverObject,
329  sizeof(CLASS_DEVICE_EXTENSION),
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);
346 cleanup:
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 DO_DEVICE_INITIALIZING
Definition: env_spec_w32.h:399
#define STATUS_OBJECT_NAME_COLLISION
Definition: udferr_usr.h:150
#define CLASS_TAG
Definition: kbdclass.h:11
#define DO_POWER_PAGABLE
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define TRUE
Definition: types.h:120
uint16_t * PWSTR
Definition: typedefs.h:56
LONG NTSTATUS
Definition: precomp.h:26
struct _CLASS_DEVICE_EXTENSION * PCLASS_DEVICE_EXTENSION
#define FALSE
Definition: types.h:117
#define UNICODE_NULL
NTSYSAPI NTSTATUS WINAPI RtlWriteRegistryValue(ULONG, PCWSTR, PCWSTR, ULONG, PVOID, ULONG)
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
Definition: kefuncs.h:238
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
#define TRACE_(x)
Definition: compat.h:76
NTSTATUS RtlAppendUnicodeToString(IN PUNICODE_STRING Str1, IN PWSTR Str2)
Definition: string_lib.cpp:62
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define DO_BUFFERED_IO
Definition: env_spec_w32.h:394
#define swprintf(buf, format,...)
Definition: sprintf.c:56
#define FILE_DEVICE_MOUSE
Definition: winioctl.h:120
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
Status
Definition: gdiplustypes.h:24
static const WCHAR L[]
Definition: oid.c:1250
PVOID NTAPI IoGetDriverObjectExtension(IN PDRIVER_OBJECT DriverObject, IN PVOID ClientIdentificationAddress)
Definition: driver.c:1866
const TCHAR * CLASS_NAME
Definition: enumwnd.c:16
PPCI_DRIVER_EXTENSION DriverExtension
Definition: pci.c:41
unsigned short USHORT
Definition: pedump.c:61
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
NTSYSAPI NTSTATUS NTAPI RtlAppendUnicodeStringToString(PUNICODE_STRING Destination, PUNICODE_STRING Source)
unsigned int ULONG
Definition: retypes.h:1
NTSTATUS NTAPI IoCreateDevice(IN PDRIVER_OBJECT DriverObject, IN ULONG DeviceExtensionSize, IN PUNICODE_STRING DeviceName, IN DEVICE_TYPE DeviceType, IN ULONG DeviceCharacteristics, IN BOOLEAN Exclusive, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1031
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
char * cleanup(char *str)
Definition: wpickclick.c:99
#define FILE_DEVICE_SECURE_OPEN
Definition: cdrw_usr.h:46
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
#define STATUS_TOO_MANY_NAMES
Definition: ntstatus.h:441
#define RTL_REGISTRY_DEVICEMAP
Definition: nt_native.h:165
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define WARN_(ch,...)
Definition: debug.h:157
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define REG_SZ
Definition: layer.c:22

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;
551  KEVENT Event;
552  PIRP Irp;
554  KIRQL OldIrql;
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 CLASS_TAG
Definition: kbdclass.h:11
IN PLARGE_INTEGER IN ULONG IN BOOLEAN IN ULONG IN BOOLEAN OUT PIO_STATUS_BLOCK IoStatus
Definition: fatprocs.h:2659
_In_ PIRP Irp
Definition: csq.h:116
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI IoDetachDevice(IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:1296
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
LIST_ENTRY ListEntry
Definition: kbdclass.h:44
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
PDEVICE_OBJECT ClassDO
Definition: kbdclass.h:48
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define FALSE
Definition: types.h:117
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:450
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
#define TRACE_(x)
Definition: compat.h:76
#define STATUS_PENDING
Definition: ntstatus.h:82
PDEVICE_OBJECT LowerDevice
Definition: kbdclass.h:47
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
#define IOCTL_INTERNAL_MOUSE_DISCONNECT
Definition: kbdmou.h:71
Status
Definition: gdiplustypes.h:24
struct _PORT_DEVICE_EXTENSION * PPORT_DEVICE_EXTENSION
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
NTSYSAPI NTSTATUS WINAPI RtlDeleteRegistryValue(ULONG, PCWSTR, PCWSTR)
PVOID NTAPI IoGetDriverObjectExtension(IN PDRIVER_OBJECT DriverObject, IN PVOID ClientIdentificationAddress)
Definition: driver.c:1866
const TCHAR * CLASS_NAME
Definition: enumwnd.c:16
PPCI_DRIVER_EXTENSION DriverExtension
Definition: pci.c:41
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
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 ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
#define RTL_REGISTRY_DEVICEMAP
Definition: nt_native.h:165

Referenced by ClassAddDevice(), and ClassPnp().

◆ DriverEntry()

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

Definition at line 1013 of file mouclass.c.

1016 {
1018  NTSTATUS Status;
1019 
1021  DriverObject,
1022  DriverObject,
1023  sizeof(CLASS_DRIVER_EXTENSION),
1024  (PVOID*)&DriverExtension);
1025  if (!NT_SUCCESS(Status))
1026  {
1027  WARN_(CLASS_NAME, "IoAllocateDriverObjectExtension() failed with status 0x%08lx\n", Status);
1028  return Status;
1029  }
1031 
1034  RegistryPath,
1035  &DriverExtension->RegistryPath);
1036  if (!NT_SUCCESS(Status))
1037  {
1038  WARN_(CLASS_NAME, "DuplicateUnicodeString() failed with status 0x%08lx\n", Status);
1039  return Status;
1040  }
1041 
1043  if (!NT_SUCCESS(Status))
1044  {
1045  WARN_(CLASS_NAME, "ReadRegistryEntries() failed with status 0x%08lx\n", Status);
1046  return Status;
1047  }
1048 
1049  if (DriverExtension->ConnectMultiplePorts == 1)
1050  {
1052  DriverObject,
1053  &DriverExtension->MainClassDeviceObject);
1054  if (!NT_SUCCESS(Status))
1055  {
1056  WARN_(CLASS_NAME, "CreateClassDeviceObject() failed with status 0x%08lx\n", Status);
1057  return Status;
1058  }
1059  }
1060 
1063 
1073 
1074  /* We will detect the legacy devices later */
1076  DriverObject,
1078  DriverExtension);
1079 
1080  return STATUS_SUCCESS;
1081 }
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
static NTSTATUS ReadRegistryEntries(IN PUNICODE_STRING RegistryPath, IN PCLASS_DRIVER_EXTENSION DriverExtension)
Definition: mouclass.c:198
NTSTATUS NTAPI IoAllocateDriverObjectExtension(IN PDRIVER_OBJECT DriverObject, IN PVOID ClientIdentificationAddress, IN ULONG DriverObjectExtensionSize, OUT PVOID *DriverObjectExtension)
Definition: driver.c:1788
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
DRIVER_DISPATCH ForwardIrpAndForget
Definition: i8042prt.h:341
LONG NTSTATUS
Definition: precomp.h:26
static DRIVER_STARTIO ClassStartIo
Definition: mouclass.c:25
static DRIVER_DISPATCH ClassPower
Definition: mouclass.c:23
static DRIVER_DISPATCH ClassDeviceControl
Definition: mouclass.c:22
VOID NTAPI IoRegisterDriverReinitialization(IN PDRIVER_OBJECT DriverObject, IN PDRIVER_REINITIALIZE ReinitRoutine, IN PVOID Context)
Definition: driver.c:1759
static DRIVER_DISPATCH ClassCreate
Definition: mouclass.c:18
static DRIVER_ADD_DEVICE ClassAddDevice
Definition: mouclass.c:24
PDRIVER_EXTENSION DriverExtension
Definition: iotypes.h:2262
static NTSTATUS NTAPI ClassPnp(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: mouclass.c:802
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
static VOID NTAPI SearchForLegacyDrivers(IN PDRIVER_OBJECT DriverObject, IN PVOID Context, IN ULONG Count)
Definition: mouclass.c:895
#define RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE
Definition: isapnp.h:82
_In_z_ PWSTR RegistryPath
Definition: classp.h:1930
static DRIVER_DISPATCH ClassClose
Definition: mouclass.c:19
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS DuplicateUnicodeString(IN ULONG Flags, IN PCUNICODE_STRING SourceString, OUT PUNICODE_STRING DestinationString)
Definition: misc.c:72
#define IRP_MJ_INTERNAL_DEVICE_CONTROL
static DRIVER_UNLOAD DriverUnload
Definition: mouclass.c:17
#define IRP_MJ_POWER
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
Status
Definition: gdiplustypes.h:24
PDRIVER_UNLOAD DriverUnload
Definition: iotypes.h:2268
const TCHAR * CLASS_NAME
Definition: enumwnd.c:16
static NTSTATUS CreateClassDeviceObject(IN PDRIVER_OBJECT DriverObject, OUT PDEVICE_OBJECT *ClassDO OPTIONAL)
Definition: mouclass.c:281
PPCI_DRIVER_EXTENSION DriverExtension
Definition: pci.c:41
PDRIVER_ADD_DEVICE AddDevice
Definition: iotypes.h:2200
#define IRP_MJ_READ
Definition: rdpdr.c:46
static DRIVER_DISPATCH ClassRead
Definition: mouclass.c:21
#define IRP_MJ_CLEANUP
PDRIVER_DISPATCH MajorFunction[IRP_MJ_MAXIMUM_FUNCTION+1]
Definition: iotypes.h:2269
static DRIVER_DISPATCH ClassCleanup
Definition: mouclass.c:20
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
PDRIVER_STARTIO DriverStartIo
Definition: iotypes.h:2267
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define WARN_(ch,...)
Definition: debug.h:157
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52

◆ 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  {
418  _SEH2_TRY
419  {
421  Irp->UserBuffer,
422  DataStart,
423  NumberOfEntries * sizeof(MOUSE_INPUT_DATA));
424  }
426  {
428  }
429  _SEH2_END;
430  }
431 
432  return Status;
433 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
#define MmGetSystemAddressForMdlSafe(_Mdl, _Priority)
#define DO_DIRECT_IO
Definition: env_spec_w32.h:396
_SEH2_TRY
Definition: create.c:4226
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
#define DO_BUFFERED_IO
Definition: env_spec_w32.h:394
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
Status
Definition: gdiplustypes.h:24
_SEH2_END
Definition: create.c:4400
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
return STATUS_SUCCESS
Definition: btrfs.c:3014

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;
739  KIRQL OldIrql;
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 
754  DeviceObject,
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 }
_In_ PIRP Irp
Definition: csq.h:116
static NTSTATUS FillEntries(IN PDEVICE_OBJECT ClassDeviceObject, IN PIRP Irp, IN PMOUSE_INPUT_DATA DataStart, IN SIZE_T NumberOfEntries)
Definition: mouclass.c:388
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI IoAcquireCancelSpinLock(OUT PKIRQL Irql)
Definition: util.c:56
struct _MOUSE_INPUT_DATA MOUSE_INPUT_DATA
IoSetCancelRoutine(Irp, CancelRoutine)
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:264
T MIN(T a, T b)
Definition: polytest.cpp:79
UCHAR KIRQL
Definition: env_spec_w32.h:591
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
#define TRACE_(x)
Definition: compat.h:76
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
#define STATUS_CANCELLED
Definition: udferr_usr.h:170
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Status
Definition: gdiplustypes.h:24
_In_ PPCI_DEVICE_PRESENCE_PARAMETERS Parameters
Definition: iotypes.h:887
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
#define VOID
Definition: acefi.h:82
const TCHAR * CLASS_NAME
Definition: enumwnd.c:16
VOID NTAPI IoReleaseCancelSpinLock(IN KIRQL Irql)
Definition: util.c:150
static DRIVER_CANCEL ClassCancelRoutine
Definition: mouclass.c:26
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2789
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define IO_MOUSE_INCREMENT
Definition: iotypes.h:586
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
IoMarkIrpPending(Irp)

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,
248  Parameters,
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 }
#define CLASS_TAG
Definition: kbdclass.h:11
const uint16_t * PCWSTR
Definition: typedefs.h:57
NTSYSAPI NTSTATUS WINAPI RtlQueryRegistryValues(ULONG, PCWSTR, PRTL_QUERY_REGISTRY_TABLE, PVOID, PVOID)
USHORT MaximumLength
Definition: env_spec_w32.h:370
LONG NTSTATUS
Definition: precomp.h:26
NTSYSAPI VOID NTAPI RtlCopyUnicodeString(PUNICODE_STRING DestinationString, PUNICODE_STRING SourceString)
#define UNICODE_NULL
smooth NULL
Definition: ftsmooth.c:416
#define RTL_REGISTRY_OPTIONAL
Definition: nt_native.h:169
void * PVOID
Definition: retypes.h:9
NTSTATUS RtlAppendUnicodeToString(IN PUNICODE_STRING Str1, IN PWSTR Str2)
Definition: string_lib.cpp:62
_In_z_ PWSTR RegistryPath
Definition: classp.h:1930
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
NTSYSAPI BOOLEAN NTAPI RtlCreateUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
Status
Definition: gdiplustypes.h:24
_In_ PPCI_DEVICE_PRESENCE_PARAMETERS Parameters
Definition: iotypes.h:887
static const WCHAR L[]
Definition: oid.c:1250
const TCHAR * CLASS_NAME
Definition: enumwnd.c:16
#define RTL_REGISTRY_ABSOLUTE
Definition: nt_native.h:161
PPCI_DRIVER_EXTENSION DriverExtension
Definition: pci.c:41
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define REG_DWORD
Definition: sdbapi.c:596
#define WARN_(ch,...)
Definition: debug.h:157
#define RTL_QUERY_REGISTRY_DIRECT
Definition: nt_native.h:144
#define REG_SZ
Definition: layer.c:22

Referenced by DriverEntry().

◆ SearchForLegacyDrivers()

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

Definition at line 895 of file mouclass.c.

899 {
900  UNICODE_STRING DeviceMapKeyU = RTL_CONSTANT_STRING(L"\\REGISTRY\\MACHINE\\HARDWARE\\DEVICEMAP");
902  UNICODE_STRING PortBaseName = { 0, 0, NULL };
903  PKEY_VALUE_BASIC_INFORMATION KeyValueInformation = NULL;
905  HANDLE hDeviceMapKey = (HANDLE)-1;
906  HANDLE hPortKey = (HANDLE)-1;
907  ULONG Index = 0;
910 
911  TRACE_(CLASS_NAME, "SearchForLegacyDrivers(%p %p %lu)\n",
913 
914  if (Count != 1)
915  return;
917 
918  /* Create port base name, by replacing Class by Port at the end of the class base name */
921  &DriverExtension->DeviceBaseName,
922  &PortBaseName);
923  if (!NT_SUCCESS(Status))
924  {
925  WARN_(CLASS_NAME, "DuplicateUnicodeString() failed with status 0x%08lx\n", Status);
926  goto cleanup;
927  }
928  PortBaseName.Length -= (sizeof(L"Class") - sizeof(UNICODE_NULL));
929  RtlAppendUnicodeToString(&PortBaseName, L"Port");
930 
931  /* Allocate memory */
933  KeyValueInformation = ExAllocatePoolWithTag(PagedPool, Size, CLASS_TAG);
934  if (!KeyValueInformation)
935  {
936  WARN_(CLASS_NAME, "ExAllocatePoolWithTag() failed\n");
938  goto cleanup;
939  }
940 
941  /* Open HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP */
943  Status = ZwOpenKey(&hDeviceMapKey, 0, &ObjectAttributes);
945  {
946  INFO_(CLASS_NAME, "HKLM\\HARDWARE\\DEVICEMAP is non-existent\n");
948  goto cleanup;
949  }
950  else if (!NT_SUCCESS(Status))
951  {
952  WARN_(CLASS_NAME, "ZwOpenKey() failed with status 0x%08lx\n", Status);
953  goto cleanup;
954  }
955 
956  /* Open sub key */
958  Status = ZwOpenKey(&hPortKey, KEY_QUERY_VALUE, &ObjectAttributes);
960  {
961  INFO_(CLASS_NAME, "HKLM\\HARDWARE\\DEVICEMAP\\%wZ is non-existent\n", &PortBaseName);
963  goto cleanup;
964  }
965  else if (!NT_SUCCESS(Status))
966  {
967  WARN_(CLASS_NAME, "ZwOpenKey() failed with status 0x%08lx\n", Status);
968  goto cleanup;
969  }
970 
971  /* Read each value name */
972  while (ZwEnumerateValueKey(hPortKey, Index++, KeyValueBasicInformation, KeyValueInformation, Size, &ResultLength) == STATUS_SUCCESS)
973  {
975  PDEVICE_OBJECT PortDeviceObject = NULL;
977 
978  PortName.Length = PortName.MaximumLength = (USHORT)KeyValueInformation->NameLength;
979  PortName.Buffer = KeyValueInformation->Name;
980 
981  /* Open the device object pointer */
983  if (!NT_SUCCESS(Status))
984  {
985  WARN_(CLASS_NAME, "IoGetDeviceObjectPointer(%wZ) failed with status 0x%08lx\n", &PortName, Status);
986  continue;
987  }
988  INFO_(CLASS_NAME, "Legacy driver found\n");
989 
990  Status = ClassAddDevice(DriverObject, PortDeviceObject);
991  if (!NT_SUCCESS(Status))
992  {
993  /* FIXME: Log the error */
994  WARN_(CLASS_NAME, "ClassAddDevice() failed with status 0x%08lx\n", Status);
995  }
996 
998  }
999 
1000 cleanup:
1001  if (KeyValueInformation != NULL)
1002  ExFreePoolWithTag(KeyValueInformation, CLASS_TAG);
1003  if (hDeviceMapKey != (HANDLE)-1)
1004  ZwClose(hDeviceMapKey);
1005  if (hPortKey != (HANDLE)-1)
1006  ZwClose(hPortKey);
1007 }
IN CINT OUT PVOID IN ULONG OUT PULONG ResultLength
Definition: conport.c:47
#define CLASS_TAG
Definition: kbdclass.h:11
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
struct _KEY_VALUE_BASIC_INFORMATION KEY_VALUE_BASIC_INFORMATION
#define INFO_(ch,...)
Definition: debug.h:159
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
USHORT MaximumLength
Definition: env_spec_w32.h:370
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
LONG NTSTATUS
Definition: precomp.h:26
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1223
NTSTATUS NTAPI IoGetDeviceObjectPointer(IN PUNICODE_STRING ObjectName, IN ACCESS_MASK DesiredAccess, OUT PFILE_OBJECT *FileObject, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1435
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define UNICODE_NULL
static DRIVER_ADD_DEVICE ClassAddDevice
Definition: mouclass.c:24
smooth NULL
Definition: ftsmooth.c:416
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:588
#define TRACE_(x)
Definition: compat.h:76
NTSTATUS RtlAppendUnicodeToString(IN PUNICODE_STRING Str1, IN PWSTR Str2)
Definition: string_lib.cpp:62
#define RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE
Definition: isapnp.h:82
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS DuplicateUnicodeString(IN ULONG Flags, IN PCUNICODE_STRING SourceString, OUT PUNICODE_STRING DestinationString)
Definition: misc.c:72
#define MAX_PATH
Definition: compat.h:34
static const UCHAR Index[8]
Definition: usbohci.c:18
PVOID HANDLE
Definition: typedefs.h:73
* PFILE_OBJECT
Definition: iotypes.h:1978
#define FILE_READ_ATTRIBUTES
Definition: nt_native.h:647
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
Status
Definition: gdiplustypes.h:24
static const WCHAR L[]
Definition: oid.c:1250
const TCHAR * CLASS_NAME
Definition: enumwnd.c:16
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
PPCI_DRIVER_EXTENSION DriverExtension
Definition: pci.c:41
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
struct _CLASS_DRIVER_EXTENSION * PCLASS_DRIVER_EXTENSION
unsigned short USHORT
Definition: pedump.c:61
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
unsigned int ULONG
Definition: retypes.h:1
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
char * cleanup(char *str)
Definition: wpickclick.c:99
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define WARN_(ch,...)
Definition: debug.h:157
IN PUNICODE_STRING PortName
Definition: conport.c:35
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14

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().