ReactOS  0.4.15-dev-318-g99b52df
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 IrpStub (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 IrpStub
 
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 612 of file mouclass.c.

615 {
617  PDEVICE_OBJECT Fdo = NULL;
618  PPORT_DEVICE_EXTENSION DeviceExtension = NULL;
620 
621  TRACE_(CLASS_NAME, "ClassAddDevice called. Pdo = 0x%p\n", Pdo);
622 
624 
625  if (Pdo == NULL)
626  /* We may get a NULL Pdo at the first call as we're a legacy driver. Ignore it */
627  return STATUS_SUCCESS;
628 
629  /* Create new device object */
631  DriverObject,
632  sizeof(PORT_DEVICE_EXTENSION),
633  NULL,
634  Pdo->DeviceType,
635  Pdo->Characteristics & FILE_DEVICE_SECURE_OPEN ? FILE_DEVICE_SECURE_OPEN : 0,
636  FALSE,
637  &Fdo);
638  if (!NT_SUCCESS(Status))
639  {
640  WARN_(CLASS_NAME, "IoCreateDevice() failed with status 0x%08lx\n", Status);
641  goto cleanup;
642  }
644 
645  DeviceExtension = (PPORT_DEVICE_EXTENSION)Fdo->DeviceExtension;
646  RtlZeroMemory(DeviceExtension, sizeof(PORT_DEVICE_EXTENSION));
647  DeviceExtension->Common.IsClassDO = FALSE;
648  DeviceExtension->DeviceObject = Fdo;
649  DeviceExtension->PnpState = dsStopped;
650  Status = IoAttachDeviceToDeviceStackSafe(Fdo, Pdo, &DeviceExtension->LowerDevice);
651  if (!NT_SUCCESS(Status))
652  {
653  WARN_(CLASS_NAME, "IoAttachDeviceToDeviceStackSafe() failed with status 0x%08lx\n", Status);
654  goto cleanup;
655  }
656  if (DeviceExtension->LowerDevice->Flags & DO_POWER_PAGABLE)
657  Fdo->Flags |= DO_POWER_PAGABLE;
658  if (DeviceExtension->LowerDevice->Flags & DO_BUFFERED_IO)
659  Fdo->Flags |= DO_BUFFERED_IO;
660  if (DeviceExtension->LowerDevice->Flags & DO_DIRECT_IO)
661  Fdo->Flags |= DO_DIRECT_IO;
662 
663  if (DriverExtension->ConnectMultiplePorts)
664  DeviceExtension->ClassDO = DriverExtension->MainClassDeviceObject;
665  else
666  {
667  /* We need a new class device object for this Fdo */
669  DriverObject,
670  &DeviceExtension->ClassDO);
671  if (!NT_SUCCESS(Status))
672  {
673  WARN_(CLASS_NAME, "CreateClassDeviceObject() failed with status 0x%08lx\n", Status);
674  goto cleanup;
675  }
676  }
677  Status = ConnectPortDriver(Fdo, DeviceExtension->ClassDO);
678  if (!NT_SUCCESS(Status))
679  {
680  WARN_(CLASS_NAME, "ConnectPortDriver() failed with status 0x%08lx\n", Status);
681  goto cleanup;
682  }
683  Fdo->Flags &= ~DO_DEVICE_INITIALIZING;
684 
685  /* Register interface ; ignore the error (if any) as having
686  * a registered interface is not so important... */
688  Pdo,
689  &GUID_DEVINTERFACE_MOUSE,
690  NULL,
691  &DeviceExtension->InterfaceName);
692  if (!NT_SUCCESS(Status))
693  DeviceExtension->InterfaceName.Length = 0;
694 
695  return STATUS_SUCCESS;
696 
697 cleanup:
698  if (Fdo)
699  DestroyPortDriver(Fdo);
700  return Status;
701 }
#define DO_DEVICE_INITIALIZING
Definition: env_spec_w32.h:399
#define DO_POWER_PAGABLE
#define TRUE
Definition: types.h:120
_In_ PDEVICE_OBJECT Pdo
Definition: classpnp.h:301
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:499
#define DO_DIRECT_IO
Definition: env_spec_w32.h:396
PDEVICE_OBJECT ClassDO
Definition: kbdclass.h:48
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:66
static VOID DestroyPortDriver(IN PDEVICE_OBJECT PortDO)
Definition: mouclass.c:553
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
struct _PORT_DEVICE_EXTENSION * PPORT_DEVICE_EXTENSION
PVOID NTAPI IoGetDriverObjectExtension(IN PDRIVER_OBJECT DriverObject, IN PVOID ClientIdentificationAddress)
Definition: driver.c:1857
const TCHAR * CLASS_NAME
Definition: enumwnd.c:16
static NTSTATUS CreateClassDeviceObject(IN PDRIVER_OBJECT DriverObject, OUT PDEVICE_OBJECT *ClassDO OPTIONAL)
Definition: mouclass.c:289
PPCI_DRIVER_EXTENSION DriverExtension
Definition: pci.c:41
Status
Definition: gdiplustypes.h:24
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:261
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 444 of file mouclass.c.

449 {
450  PCLASS_DEVICE_EXTENSION ClassDeviceExtension = ClassDeviceObject->DeviceExtension;
451  KIRQL OldIrql;
452  SIZE_T InputCount = DataEnd - DataStart;
453  SIZE_T ReadSize;
454 
455  TRACE_(CLASS_NAME, "ClassCallback()\n");
456 
457  ASSERT(ClassDeviceExtension->Common.IsClassDO);
458 
459  KeAcquireSpinLock(&ClassDeviceExtension->SpinLock, &OldIrql);
460  if (InputCount > 0)
461  {
462  if (ClassDeviceExtension->InputCount + InputCount > ClassDeviceExtension->DriverExtension->DataQueueSize)
463  {
464  /*
465  * We're exceeding the buffer, and data will be thrown away...
466  * FIXME: What could we do, as we are at DISPATCH_LEVEL?
467  */
468  ReadSize = ClassDeviceExtension->DriverExtension->DataQueueSize - ClassDeviceExtension->InputCount;
469  }
470  else
471  ReadSize = InputCount;
472 
473  /*
474  * Move the input data from the port data queue to our class data
475  * queue.
476  */
478  &ClassDeviceExtension->PortData[ClassDeviceExtension->InputCount],
479  (PCHAR)DataStart,
480  sizeof(MOUSE_INPUT_DATA) * ReadSize);
481 
482  /* Move the counter up */
483  ClassDeviceExtension->InputCount += ReadSize;
484 
485  (*ConsumedCount) += (ULONG)ReadSize;
486 
487  /* Complete pending IRP (if any) */
488  if (ClassDeviceExtension->PendingIrp)
489  HandleReadIrp(ClassDeviceObject, ClassDeviceExtension->PendingIrp, FALSE);
490  }
491  KeReleaseSpinLock(&ClassDeviceExtension->SpinLock, OldIrql);
492 
493  TRACE_(CLASS_NAME, "Leaving ClassCallback()\n");
494  return TRUE;
495 }
signed char * PCHAR
Definition: retypes.h:7
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
static NTSTATUS HandleReadIrp(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, BOOLEAN IsInStartIo)
Definition: mouclass.c:740
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define TRACE_(x)
Definition: compat.h:66
#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:79
#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 704 of file mouclass.c.

707 {
708  PCLASS_DEVICE_EXTENSION ClassDeviceExtension = DeviceObject->DeviceExtension;
709  KIRQL OldIrql;
710  BOOLEAN wasQueued = FALSE;
711 
712  TRACE_(CLASS_NAME, "ClassCancelRoutine(DeviceObject %p, Irp %p)\n", DeviceObject, Irp);
713 
714  ASSERT(ClassDeviceExtension->Common.IsClassDO);
715 
716  IoReleaseCancelSpinLock(Irp->CancelIrql);
717 
718  KeAcquireSpinLock(&ClassDeviceExtension->SpinLock, &OldIrql);
719 
720  if (ClassDeviceExtension->PendingIrp == Irp)
721  {
722  ClassDeviceExtension->PendingIrp = NULL;
723  wasQueued = TRUE;
724  }
725  KeReleaseSpinLock(&ClassDeviceExtension->SpinLock, OldIrql);
726 
727  if (wasQueued)
728  {
729  Irp->IoStatus.Status = STATUS_CANCELLED;
730  Irp->IoStatus.Information = 0;
732  }
733  else
734  {
735  DPRINT1("Cancelled IRP is not pending. Race condition?\n");
736  }
737 }
#define TRUE
Definition: types.h:120
_In_ PIRP Irp
Definition: csq.h:116
UCHAR KIRQL
Definition: env_spec_w32.h:591
PVOID DeviceExtension
Definition: env_spec_w32.h:418
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
#define TRACE_(x)
Definition: compat.h:66
#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: fatprocs.h:1560
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define DPRINT1
Definition: precomp.h:8
#define IO_NO_INCREMENT
Definition: iotypes.h:566

◆ 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 
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
PVOID DeviceExtension
Definition: env_spec_w32.h:418
#define IoCompleteRequest
Definition: irp.c:1240
#define TRACE_(x)
Definition: compat.h:66
const TCHAR * CLASS_NAME
Definition: enumwnd.c:16
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define IO_NO_INCREMENT
Definition: iotypes.h:566
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 
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
PVOID DeviceExtension
Definition: env_spec_w32.h:418
#define IoCompleteRequest
Definition: irp.c:1240
#define TRACE_(x)
Definition: compat.h:66
const TCHAR * CLASS_NAME
Definition: enumwnd.c:16
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define IO_NO_INCREMENT
Definition: iotypes.h:566
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 
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
PVOID DeviceExtension
Definition: env_spec_w32.h:418
#define IoCompleteRequest
Definition: irp.c:1240
#define TRACE_(x)
Definition: compat.h:66
const TCHAR * CLASS_NAME
Definition: enumwnd.c:16
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define IO_NO_INCREMENT
Definition: iotypes.h:566
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 
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 */
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
PVOID DeviceExtension
Definition: env_spec_w32.h:418
#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:66
struct _LIST_ENTRY * Flink
Definition: typedefs.h:120
#define IRP_MJ_INTERNAL_DEVICE_CONTROL
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
_In_ PPCI_DEVICE_PRESENCE_PARAMETERS Parameters
Definition: iotypes.h:872
#define IOCTL_MOUSE_QUERY_ATTRIBUTES
Definition: ntddmou.h:32
const TCHAR * CLASS_NAME
Definition: enumwnd.c:16
Definition: typedefs.h:118
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
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:409
#define IO_NO_INCREMENT
Definition: iotypes.h:566
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 810 of file mouclass.c.

813 {
819 
820  switch (IrpSp->MinorFunction)
821  {
822  case IRP_MN_START_DEVICE:
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 
847  case IRP_MN_STOP_DEVICE:
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: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
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
static VOID DestroyPortDriver(IN PDEVICE_OBJECT PortDO)
Definition: mouclass.c:553
#define IRP_MN_STOP_DEVICE
return Iosb
Definition: create.c:4426
#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
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
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:409
#define IO_NO_INCREMENT
Definition: iotypes.h:566
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
return STATUS_SUCCESS
Definition: btrfs.c:3014

Referenced by DriverEntry().

◆ ClassRead()

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

Definition at line 91 of file mouclass.c.

94 {
96  KIRQL OldIrql;
98 
99  TRACE_(CLASS_NAME, "IRP_MJ_READ\n");
100 
101  ASSERT(DeviceExtension->Common.IsClassDO);
102 
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:740
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
UCHAR KIRQL
Definition: env_spec_w32.h:591
PVOID DeviceExtension
Definition: env_spec_w32.h:418
#define IoCompleteRequest
Definition: irp.c:1240
#define TRACE_(x)
Definition: compat.h:66
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
_In_ PPCI_DEVICE_PRESENCE_PARAMETERS Parameters
Definition: iotypes.h:872
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
const TCHAR * CLASS_NAME
Definition: enumwnd.c:16
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define IO_NO_INCREMENT
Definition: iotypes.h:566

◆ ClassStartIo()

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

Definition at line 886 of file mouclass.c.

889 {
891  KIRQL OldIrql;
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 }
#define TRUE
Definition: types.h:120
_In_ PIRP Irp
Definition: csq.h:116
static NTSTATUS HandleReadIrp(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, BOOLEAN IsInStartIo)
Definition: mouclass.c:740
UCHAR KIRQL
Definition: env_spec_w32.h:591
PVOID DeviceExtension
Definition: env_spec_w32.h:418
#define TRACE_(x)
Definition: compat.h:66
#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: fatprocs.h:1560
#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 499 of file mouclass.c.

502 {
503  KEVENT Event;
504  PIRP Irp;
506  CONNECT_DATA ConnectData;
508 
509  TRACE_(CLASS_NAME, "Connecting PortDO %p to ClassDO %p\n", PortDO, ClassDO);
510 
512 
513  ConnectData.ClassDeviceObject = ClassDO;
514  ConnectData.ClassService = ClassCallback;
515 
518  PortDO,
519  &ConnectData, sizeof(CONNECT_DATA),
520  NULL, 0,
521  TRUE, &Event, &IoStatus);
522  if (!Irp)
524 
525  Status = IoCallDriver(PortDO, Irp);
526 
527  if (Status == STATUS_PENDING)
529  else
530  IoStatus.Status = Status;
531 
532  if (NT_SUCCESS(IoStatus.Status))
533  {
534  ObReferenceObject(PortDO);
536  &((PCLASS_DEVICE_EXTENSION)ClassDO->DeviceExtension)->ListHead,
537  &((PPORT_DEVICE_EXTENSION)PortDO->DeviceExtension)->ListEntry,
538  &((PCLASS_DEVICE_EXTENSION)ClassDO->DeviceExtension)->ListSpinLock);
539  if (ClassDO->StackSize <= PortDO->StackSize)
540  {
541  /* Increase the stack size, in case we have to
542  * forward some IRPs to the port device object
543  */
544  ClassDO->StackSize = PortDO->StackSize + 1;
545  }
546  }
547 
548  return IoStatus.Status;
549 }
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:444
#define TRUE
Definition: types.h:120
#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:2650
_In_ PIRP Irp
Definition: csq.h:116
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
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:435
smooth NULL
Definition: ftsmooth.c:416
#define TRACE_(x)
Definition: compat.h:66
#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
const TCHAR * CLASS_NAME
Definition: enumwnd.c:16
Status
Definition: gdiplustypes.h:24
#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 289 of file mouclass.c.

292 {
294  ULONG DeviceId = 0;
295  ULONG PrefixLength;
296  UNICODE_STRING DeviceNameU;
297  PWSTR DeviceIdW = NULL; /* Pointer into DeviceNameU.Buffer */
298  PDEVICE_OBJECT Fdo;
299  PCLASS_DEVICE_EXTENSION DeviceExtension;
301 
302  TRACE_(CLASS_NAME, "CreateClassDeviceObject(0x%p)\n", DriverObject);
303 
304  /* Create new device object */
306  DeviceNameU.Length = 0;
307  DeviceNameU.MaximumLength =
308  wcslen(L"\\Device\\") * sizeof(WCHAR) /* "\Device\" */
309  + DriverExtension->DeviceBaseName.Length /* "PointerClass" */
310  + 4 * sizeof(WCHAR) /* Id between 0 and 9999 */
311  + sizeof(UNICODE_NULL); /* Final NULL char */
312  DeviceNameU.Buffer = ExAllocatePoolWithTag(PagedPool, DeviceNameU.MaximumLength, CLASS_TAG);
313  if (!DeviceNameU.Buffer)
314  {
315  WARN_(CLASS_NAME, "ExAllocatePoolWithTag() failed\n");
316  return STATUS_NO_MEMORY;
317  }
318  Status = RtlAppendUnicodeToString(&DeviceNameU, L"\\Device\\");
319  if (!NT_SUCCESS(Status))
320  {
321  WARN_(CLASS_NAME, "RtlAppendUnicodeToString() failed with status 0x%08lx\n", Status);
322  goto cleanup;
323  }
324  Status = RtlAppendUnicodeStringToString(&DeviceNameU, &DriverExtension->DeviceBaseName);
325  if (!NT_SUCCESS(Status))
326  {
327  WARN_(CLASS_NAME, "RtlAppendUnicodeStringToString() failed with status 0x%08lx\n", Status);
328  goto cleanup;
329  }
330  PrefixLength = DeviceNameU.MaximumLength - 4 * sizeof(WCHAR) - sizeof(UNICODE_NULL);
331  DeviceIdW = &DeviceNameU.Buffer[PrefixLength / sizeof(WCHAR)];
332  while (DeviceId < 9999)
333  {
334  DeviceNameU.Length = (USHORT)(PrefixLength + swprintf(DeviceIdW, L"%lu", DeviceId) * sizeof(WCHAR));
336  DriverObject,
337  sizeof(CLASS_DEVICE_EXTENSION),
338  &DeviceNameU,
341  FALSE,
342  &Fdo);
343  if (NT_SUCCESS(Status))
344  goto cleanup;
346  {
347  WARN_(CLASS_NAME, "IoCreateDevice() failed with status 0x%08lx\n", Status);
348  goto cleanup;
349  }
350  DeviceId++;
351  }
352  WARN_(CLASS_NAME, "Too many devices starting with '\\Device\\%wZ'\n", &DriverExtension->DeviceBaseName);
354 cleanup:
355  if (!NT_SUCCESS(Status))
356  {
357  ExFreePoolWithTag(DeviceNameU.Buffer, CLASS_TAG);
358  return Status;
359  }
360 
361  DeviceExtension = (PCLASS_DEVICE_EXTENSION)Fdo->DeviceExtension;
362  RtlZeroMemory(DeviceExtension, sizeof(CLASS_DEVICE_EXTENSION));
363  DeviceExtension->Common.IsClassDO = TRUE;
364  DeviceExtension->DriverExtension = DriverExtension;
365  InitializeListHead(&DeviceExtension->ListHead);
366  KeInitializeSpinLock(&DeviceExtension->ListSpinLock);
367  KeInitializeSpinLock(&DeviceExtension->SpinLock);
368  DeviceExtension->InputCount = 0;
369  DeviceExtension->PortData = ExAllocatePoolWithTag(NonPagedPool, DeviceExtension->DriverExtension->DataQueueSize * sizeof(MOUSE_INPUT_DATA), CLASS_TAG);
370  if (!DeviceExtension->PortData)
371  {
372  ExFreePoolWithTag(DeviceNameU.Buffer, CLASS_TAG);
373  return STATUS_NO_MEMORY;
374  }
375  DeviceExtension->DeviceName = DeviceNameU.Buffer;
376  Fdo->Flags |= DO_POWER_PAGABLE;
377  Fdo->Flags &= ~DO_DEVICE_INITIALIZING;
378  Fdo->Flags |= DO_BUFFERED_IO;
379 
380  /* Add entry entry to HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\[DeviceBaseName] */
383  DriverExtension->DeviceBaseName.Buffer,
384  DeviceExtension->DeviceName,
385  REG_SZ,
386  DriverExtension->RegistryPath.Buffer,
387  DriverExtension->RegistryPath.MaximumLength);
388 
389  if (ClassDO)
390  *ClassDO = Fdo;
391 
392  return STATUS_SUCCESS;
393 }
#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
#define TRUE
Definition: types.h:120
USHORT MaximumLength
Definition: env_spec_w32.h:370
uint16_t * PWSTR
Definition: typedefs.h:55
LONG NTSTATUS
Definition: precomp.h:26
struct _CLASS_DEVICE_EXTENSION * PCLASS_DEVICE_EXTENSION
#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:66
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
static const WCHAR L[]
Definition: oid.c:1250
PVOID NTAPI IoGetDriverObjectExtension(IN PDRIVER_OBJECT DriverObject, IN PVOID ClientIdentificationAddress)
Definition: driver.c:1857
const TCHAR * CLASS_NAME
Definition: enumwnd.c:16
PPCI_DRIVER_EXTENSION DriverExtension
Definition: pci.c:41
Status
Definition: gdiplustypes.h:24
unsigned short USHORT
Definition: pedump.c:61
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
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:261
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:427
#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 553 of file mouclass.c.

555 {
556  PPORT_DEVICE_EXTENSION DeviceExtension;
557  PCLASS_DEVICE_EXTENSION ClassDeviceExtension;
559  KEVENT Event;
560  PIRP Irp;
562  KIRQL OldIrql;
564 
565  TRACE_(CLASS_NAME, "Destroying PortDO %p\n", PortDO);
566 
567  DeviceExtension = (PPORT_DEVICE_EXTENSION)PortDO->DeviceExtension;
568  ClassDeviceExtension = DeviceExtension->ClassDO->DeviceExtension;
569  DriverExtension = IoGetDriverObjectExtension(PortDO->DriverObject, PortDO->DriverObject);
570 
571  /* Send IOCTL_INTERNAL_*_DISCONNECT */
575  PortDO,
576  NULL, 0,
577  NULL, 0,
578  TRUE, &Event, &IoStatus);
579  if (Irp)
580  {
581  Status = IoCallDriver(PortDO, Irp);
582  if (Status == STATUS_PENDING)
584  }
585 
586  /* Remove from ClassDeviceExtension->ListHead list */
587  KeAcquireSpinLock(&ClassDeviceExtension->ListSpinLock, &OldIrql);
588  RemoveEntryList(&DeviceExtension->ListEntry);
589  KeReleaseSpinLock(&ClassDeviceExtension->ListSpinLock, OldIrql);
590 
591  /* Remove entry from HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\[DeviceBaseName] */
594  DriverExtension->DeviceBaseName.Buffer,
595  ClassDeviceExtension->DeviceName);
596 
597  if (DeviceExtension->LowerDevice)
598  IoDetachDevice(DeviceExtension->LowerDevice);
599  ObDereferenceObject(PortDO);
600 
601  if (!DriverExtension->ConnectMultiplePorts && DeviceExtension->ClassDO)
602  {
603  ExFreePoolWithTag(ClassDeviceExtension->PortData, CLASS_TAG);
604  ExFreePoolWithTag((PVOID)ClassDeviceExtension->DeviceName, CLASS_TAG);
605  IoDeleteDevice(DeviceExtension->ClassDO);
606  }
607 
608  IoDeleteDevice(PortDO);
609 }
#define CLASS_TAG
Definition: kbdclass.h:11
#define TRUE
Definition: types.h:120
IN PLARGE_INTEGER IN ULONG IN BOOLEAN IN ULONG IN BOOLEAN OUT PIO_STATUS_BLOCK IoStatus
Definition: fatprocs.h:2650
_In_ PIRP Irp
Definition: csq.h:116
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
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:435
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
#define TRACE_(x)
Definition: compat.h:66
#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
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:1857
const TCHAR * CLASS_NAME
Definition: enumwnd.c:16
PPCI_DRIVER_EXTENSION DriverExtension
Definition: pci.c:41
Status
Definition: gdiplustypes.h:24
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 1021 of file mouclass.c.

1024 {
1026  ULONG i;
1027  NTSTATUS Status;
1028 
1030  DriverObject,
1031  DriverObject,
1032  sizeof(CLASS_DRIVER_EXTENSION),
1033  (PVOID*)&DriverExtension);
1034  if (!NT_SUCCESS(Status))
1035  {
1036  WARN_(CLASS_NAME, "IoAllocateDriverObjectExtension() failed with status 0x%08lx\n", Status);
1037  return Status;
1038  }
1040 
1043  RegistryPath,
1044  &DriverExtension->RegistryPath);
1045  if (!NT_SUCCESS(Status))
1046  {
1047  WARN_(CLASS_NAME, "DuplicateUnicodeString() failed with status 0x%08lx\n", Status);
1048  return Status;
1049  }
1050 
1052  if (!NT_SUCCESS(Status))
1053  {
1054  WARN_(CLASS_NAME, "ReadRegistryEntries() failed with status 0x%08lx\n", Status);
1055  return Status;
1056  }
1057 
1058  if (DriverExtension->ConnectMultiplePorts == 1)
1059  {
1061  DriverObject,
1062  &DriverExtension->MainClassDeviceObject);
1063  if (!NT_SUCCESS(Status))
1064  {
1065  WARN_(CLASS_NAME, "CreateClassDeviceObject() failed with status 0x%08lx\n", Status);
1066  return Status;
1067  }
1068  }
1069 
1072 
1073  for (i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++)
1075 
1084 
1085  /* We will detect the legacy devices later */
1087  DriverObject,
1089  DriverExtension);
1090 
1091  return STATUS_SUCCESS;
1092 }
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
static NTSTATUS ReadRegistryEntries(IN PUNICODE_STRING RegistryPath, IN PCLASS_DRIVER_EXTENSION DriverExtension)
Definition: mouclass.c:206
NTSTATUS NTAPI IoAllocateDriverObjectExtension(IN PDRIVER_OBJECT DriverObject, IN PVOID ClientIdentificationAddress, IN ULONG DriverObjectExtensionSize, OUT PVOID *DriverObjectExtension)
Definition: driver.c:1779
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
DRIVER_DISPATCH ForwardIrpAndForget
Definition: i8042prt.h:341
#define IRP_MJ_MAXIMUM_FUNCTION
LONG NTSTATUS
Definition: precomp.h:26
static DRIVER_STARTIO ClassStartIo
Definition: mouclass.c:25
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:1750
static DRIVER_DISPATCH ClassCreate
Definition: mouclass.c:18
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
static DRIVER_ADD_DEVICE ClassAddDevice
Definition: mouclass.c:24
PDRIVER_EXTENSION DriverExtension
Definition: iotypes.h:2174
static NTSTATUS NTAPI ClassPnp(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: mouclass.c:810
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:903
#define RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE
Definition: isapnp.h:82
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
static DRIVER_DISPATCH IrpStub
Definition: mouclass.c:23
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
PDRIVER_UNLOAD DriverUnload
Definition: iotypes.h:2180
const TCHAR * CLASS_NAME
Definition: enumwnd.c:16
static NTSTATUS CreateClassDeviceObject(IN PDRIVER_OBJECT DriverObject, OUT PDEVICE_OBJECT *ClassDO OPTIONAL)
Definition: mouclass.c:289
PPCI_DRIVER_EXTENSION DriverExtension
Definition: pci.c:41
Status
Definition: gdiplustypes.h:24
PDRIVER_ADD_DEVICE AddDevice
Definition: iotypes.h:2112
#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:2181
unsigned int ULONG
Definition: retypes.h:1
static DRIVER_DISPATCH ClassCleanup
Definition: mouclass.c:20
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
_In_ PUNICODE_STRING RegistryPath
Definition: wmip.h:28
PDRIVER_STARTIO DriverStartIo
Definition: iotypes.h:2179
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 396 of file mouclass.c.

401 {
403 
404  if (ClassDeviceObject->Flags & DO_BUFFERED_IO)
405  {
407  Irp->AssociatedIrp.SystemBuffer,
408  DataStart,
409  NumberOfEntries * sizeof(MOUSE_INPUT_DATA));
410  }
411  else if (ClassDeviceObject->Flags & DO_DIRECT_IO)
412  {
413  PVOID DestAddress = MmGetSystemAddressForMdlSafe(Irp->MdlAddress, NormalPagePriority);
414  if (DestAddress)
415  {
417  DestAddress,
418  DataStart,
419  NumberOfEntries * sizeof(MOUSE_INPUT_DATA));
420  }
421  else
423  }
424  else
425  {
426  _SEH2_TRY
427  {
429  Irp->UserBuffer,
430  DataStart,
431  NumberOfEntries * sizeof(MOUSE_INPUT_DATA));
432  }
434  {
436  }
437  _SEH2_END;
438  }
439 
440  return Status;
441 }
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:4250
#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:4424
#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 740 of file mouclass.c.

744 {
747  KIRQL OldIrql;
748 
749  TRACE_(CLASS_NAME, "HandleReadIrp(DeviceObject %p, Irp %p)\n", DeviceObject, Irp);
750 
751  ASSERT(DeviceExtension->Common.IsClassDO);
752 
753  if (DeviceExtension->InputCount > 0)
754  {
755  SIZE_T NumberOfEntries;
756 
757  NumberOfEntries = MIN(
758  DeviceExtension->InputCount,
760 
762  DeviceObject,
763  Irp,
764  DeviceExtension->PortData,
765  NumberOfEntries);
766 
767  if (NT_SUCCESS(Status))
768  {
769  if (DeviceExtension->InputCount > NumberOfEntries)
770  {
772  &DeviceExtension->PortData[0],
773  &DeviceExtension->PortData[NumberOfEntries],
774  (DeviceExtension->InputCount - NumberOfEntries) * sizeof(MOUSE_INPUT_DATA));
775  }
776 
777  DeviceExtension->InputCount -= NumberOfEntries;
778 
779  Irp->IoStatus.Information = NumberOfEntries * sizeof(MOUSE_INPUT_DATA);
780  }
781 
782  /* Go to next packet and complete this request */
783  Irp->IoStatus.Status = Status;
784 
787  DeviceExtension->PendingIrp = NULL;
788  }
789  else
790  {
792  if (Irp->Cancel)
793  {
794  DeviceExtension->PendingIrp = NULL;
796  }
797  else
798  {
800  DeviceExtension->PendingIrp = Irp;
803  }
805  }
806  return Status;
807 }
_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:396
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:263
T MIN(T a, T b)
Definition: polytest.cpp:79
UCHAR KIRQL
Definition: env_spec_w32.h:591
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
#define TRACE_(x)
Definition: compat.h:66
#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)
_In_ PPCI_DEVICE_PRESENCE_PARAMETERS Parameters
Definition: iotypes.h:872
_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
Status
Definition: gdiplustypes.h:24
static DRIVER_CANCEL ClassCancelRoutine
Definition: mouclass.c:26
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
ULONG_PTR SIZE_T
Definition: typedefs.h:79
#define IO_MOUSE_INCREMENT
Definition: iotypes.h:571
IoMarkIrpPending(Irp)

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

◆ IrpStub()

static NTSTATUS NTAPI IrpStub ( 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 some IRPs to lower device */
179  switch (IoGetCurrentIrpStackLocation(Irp)->MajorFunction)
180  {
181  case IRP_MJ_POWER:
184  return PoCallDriver(DeviceExtension->LowerDevice, Irp);
185  default:
186  {
187  ERR_(CLASS_NAME, "Port DO stub for major function 0x%lx\n",
188  IoGetCurrentIrpStackLocation(Irp)->MajorFunction);
189  ASSERT(FALSE);
190  }
191  }
192  }
193  else
194  {
195  ERR_(CLASS_NAME, "Class DO stub for major function 0x%lx\n",
196  IoGetCurrentIrpStackLocation(Irp)->MajorFunction);
197  ASSERT(FALSE);
198  }
199 
200  Irp->IoStatus.Status = Status;
202  return Status;
203 }
_In_ PIRP Irp
Definition: csq.h:116
COMMON_DEVICE_EXTENSION Common
Definition: kbdclass.h:42
#define ERR_(ch,...)
Definition: debug.h:156
LONG NTSTATUS
Definition: precomp.h:26
PVOID DeviceExtension
Definition: env_spec_w32.h:418
#define IoCompleteRequest
Definition: irp.c:1240
PDEVICE_OBJECT LowerDevice
Definition: kbdclass.h:47
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define IRP_MJ_POWER
const TCHAR * CLASS_NAME
Definition: enumwnd.c:16
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
VOID NTAPI PoStartNextPowerIrp(IN PIRP Irp)
Definition: power.c:737
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:409
#define IO_NO_INCREMENT
Definition: iotypes.h:566

◆ ReadRegistryEntries()

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

Definition at line 206 of file mouclass.c.

209 {
210  UNICODE_STRING ParametersRegistryKey;
213 
214  ULONG DefaultConnectMultiplePorts = 1;
215  ULONG DefaultDataQueueSize = 0x64;
216  PCWSTR DefaultDeviceBaseName = L"PointerClass";
217 
218  ParametersRegistryKey.Length = 0;
219  ParametersRegistryKey.MaximumLength = RegistryPath->Length + sizeof(L"\\Parameters") + sizeof(UNICODE_NULL);
220  ParametersRegistryKey.Buffer = ExAllocatePoolWithTag(PagedPool, ParametersRegistryKey.MaximumLength, CLASS_TAG);
221  if (!ParametersRegistryKey.Buffer)
222  {
223  WARN_(CLASS_NAME, "ExAllocatePoolWithTag() failed\n");
224  return STATUS_NO_MEMORY;
225  }
226  RtlCopyUnicodeString(&ParametersRegistryKey, RegistryPath);
227  RtlAppendUnicodeToString(&ParametersRegistryKey, L"\\Parameters");
228  ParametersRegistryKey.Buffer[ParametersRegistryKey.Length / sizeof(WCHAR)] = UNICODE_NULL;
229 
231 
233  Parameters[0].Name = L"ConnectMultiplePorts";
234  Parameters[0].EntryContext = &DriverExtension->ConnectMultiplePorts;
235  Parameters[0].DefaultType = REG_DWORD;
236  Parameters[0].DefaultData = &DefaultConnectMultiplePorts;
237  Parameters[0].DefaultLength = sizeof(ULONG);
238 
240  Parameters[1].Name = L"MouseDataQueueSize";
241  Parameters[1].EntryContext = &DriverExtension->DataQueueSize;
242  Parameters[1].DefaultType = REG_DWORD;
243  Parameters[1].DefaultData = &DefaultDataQueueSize;
244  Parameters[1].DefaultLength = sizeof(ULONG);
245 
247  Parameters[2].Name = L"PointerDeviceBaseName";
248  Parameters[2].EntryContext = &DriverExtension->DeviceBaseName;
249  Parameters[2].DefaultType = REG_SZ;
250  Parameters[2].DefaultData = (PVOID)DefaultDeviceBaseName;
251  Parameters[2].DefaultLength = 0;
252 
255  ParametersRegistryKey.Buffer,
256  Parameters,
257  NULL,
258  NULL);
259 
260  if (NT_SUCCESS(Status))
261  {
262  /* Check values */
263  if (DriverExtension->ConnectMultiplePorts != 0
264  && DriverExtension->ConnectMultiplePorts != 1)
265  {
266  DriverExtension->ConnectMultiplePorts = DefaultConnectMultiplePorts;
267  }
268  if (DriverExtension->DataQueueSize == 0)
269  {
270  DriverExtension->DataQueueSize = DefaultDataQueueSize;
271  }
272  }
274  {
275  /* Registry path doesn't exist. Set defaults */
276  DriverExtension->ConnectMultiplePorts = DefaultConnectMultiplePorts;
277  DriverExtension->DataQueueSize = DefaultDataQueueSize;
278  if (RtlCreateUnicodeString(&DriverExtension->DeviceBaseName, DefaultDeviceBaseName))
280  else
282  }
283 
284  ExFreePoolWithTag(ParametersRegistryKey.Buffer, CLASS_TAG);
285  return Status;
286 }
#define CLASS_TAG
Definition: kbdclass.h:11
const uint16_t * PCWSTR
Definition: typedefs.h:56
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
__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)
_In_ PPCI_DEVICE_PRESENCE_PARAMETERS Parameters
Definition: iotypes.h:872
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
Status
Definition: gdiplustypes.h:24
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
_In_ PUNICODE_STRING RegistryPath
Definition: wmip.h:28
#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 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 
1008 cleanup:
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 }
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:1015
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:593
#define TRACE_(x)
Definition: compat.h:66
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:26
static const UCHAR Index[8]
Definition: usbohci.c:18
PVOID HANDLE
Definition: typedefs.h:72
* PFILE_OBJECT
Definition: iotypes.h:1955
#define FILE_READ_ATTRIBUTES
Definition: nt_native.h:647
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
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
Status
Definition: gdiplustypes.h:24
#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:246
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().

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

◆ IrpStub

DRIVER_DISPATCH IrpStub
static

Definition at line 23 of file mouclass.c.

Referenced by DriverEntry().