2007-11-02 12:36:50 +00:00
|
|
|
|
/*
|
2005-10-31 00:14:45 +00:00
|
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
|
* PROJECT: ReactOS Mouse class driver
|
|
|
|
|
* FILE: drivers/mouclass/mouclass.c
|
|
|
|
|
* PURPOSE: Mouse class driver
|
2007-11-02 12:36:50 +00:00
|
|
|
|
*
|
2005-10-31 00:14:45 +00:00
|
|
|
|
* PROGRAMMERS: Herv<EFBFBD> Poussineau (hpoussin@reactos.org)
|
|
|
|
|
*/
|
2000-10-18 09:11:01 +00:00
|
|
|
|
|
2005-10-31 00:14:45 +00:00
|
|
|
|
#define INITGUID
|
|
|
|
|
#include "mouclass.h"
|
2000-10-18 09:11:01 +00:00
|
|
|
|
|
2007-06-04 09:25:04 +00:00
|
|
|
|
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;
|
2007-11-02 12:36:50 +00:00
|
|
|
|
static DRIVER_CANCEL ClassCancelRoutine;
|
|
|
|
|
static NTSTATUS
|
|
|
|
|
HandleReadIrp(
|
|
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
|
IN PIRP Irp,
|
|
|
|
|
BOOLEAN IsInStartIo);
|
2007-06-04 09:25:04 +00:00
|
|
|
|
|
2005-10-31 00:14:45 +00:00
|
|
|
|
static VOID NTAPI
|
|
|
|
|
DriverUnload(IN PDRIVER_OBJECT DriverObject)
|
|
|
|
|
{
|
|
|
|
|
// nothing to do here yet
|
|
|
|
|
}
|
2000-10-18 09:11:01 +00:00
|
|
|
|
|
2005-10-31 00:14:45 +00:00
|
|
|
|
static NTSTATUS NTAPI
|
2005-11-05 08:37:01 +00:00
|
|
|
|
ClassCreate(
|
2005-10-31 00:14:45 +00:00
|
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
|
IN PIRP Irp)
|
|
|
|
|
{
|
2008-07-25 20:24:46 +00:00
|
|
|
|
TRACE_(CLASS_NAME, "IRP_MJ_CREATE\n");
|
2000-10-18 09:11:01 +00:00
|
|
|
|
|
2005-10-31 00:14:45 +00:00
|
|
|
|
if (!((PCOMMON_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->IsClassDO)
|
|
|
|
|
return ForwardIrpAndForget(DeviceObject, Irp);
|
2002-12-16 23:23:21 +00:00
|
|
|
|
|
2005-10-31 00:14:45 +00:00
|
|
|
|
/* FIXME: open all associated Port devices */
|
2006-04-25 22:22:22 +00:00
|
|
|
|
Irp->IoStatus.Status = STATUS_SUCCESS;
|
|
|
|
|
Irp->IoStatus.Information = 0;
|
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
2005-10-31 00:14:45 +00:00
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
|
}
|
2005-10-06 21:39:18 +00:00
|
|
|
|
|
2005-10-31 00:14:45 +00:00
|
|
|
|
static NTSTATUS NTAPI
|
2005-11-05 08:37:01 +00:00
|
|
|
|
ClassClose(
|
2005-10-31 00:14:45 +00:00
|
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
|
IN PIRP Irp)
|
|
|
|
|
{
|
2008-07-25 20:24:46 +00:00
|
|
|
|
TRACE_(CLASS_NAME, "IRP_MJ_CLOSE\n");
|
2005-10-31 00:14:45 +00:00
|
|
|
|
|
|
|
|
|
if (!((PCOMMON_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->IsClassDO)
|
|
|
|
|
return ForwardIrpAndForget(DeviceObject, Irp);
|
2005-06-03 17:09:47 +00:00
|
|
|
|
|
2005-10-31 00:14:45 +00:00
|
|
|
|
/* FIXME: close all associated Port devices */
|
2006-04-25 22:22:22 +00:00
|
|
|
|
Irp->IoStatus.Status = STATUS_SUCCESS;
|
|
|
|
|
Irp->IoStatus.Information = 0;
|
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
2005-10-31 00:14:45 +00:00
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static NTSTATUS NTAPI
|
2005-11-05 08:37:01 +00:00
|
|
|
|
ClassCleanup(
|
|
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
|
IN PIRP Irp)
|
|
|
|
|
{
|
2008-07-25 20:24:46 +00:00
|
|
|
|
TRACE_(CLASS_NAME, "IRP_MJ_CLEANUP\n");
|
2005-11-05 08:37:01 +00:00
|
|
|
|
|
|
|
|
|
if (!((PCOMMON_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->IsClassDO)
|
|
|
|
|
return ForwardIrpAndForget(DeviceObject, Irp);
|
|
|
|
|
|
|
|
|
|
/* FIXME: cleanup all associated Port devices */
|
2006-04-25 22:22:22 +00:00
|
|
|
|
Irp->IoStatus.Status = STATUS_SUCCESS;
|
|
|
|
|
Irp->IoStatus.Information = 0;
|
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
2005-11-05 08:37:01 +00:00
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static NTSTATUS NTAPI
|
|
|
|
|
ClassRead(
|
2005-10-31 00:14:45 +00:00
|
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
|
IN PIRP Irp)
|
2000-10-18 09:11:01 +00:00
|
|
|
|
{
|
2007-11-02 12:36:50 +00:00
|
|
|
|
PCLASS_DEVICE_EXTENSION DeviceExtension = DeviceObject->DeviceExtension;
|
|
|
|
|
KIRQL OldIrql;
|
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
2008-07-25 20:24:46 +00:00
|
|
|
|
TRACE_(CLASS_NAME, "IRP_MJ_READ\n");
|
2005-10-31 00:14:45 +00:00
|
|
|
|
|
2007-11-02 12:36:50 +00:00
|
|
|
|
ASSERT(DeviceExtension->Common.IsClassDO);
|
|
|
|
|
|
2005-10-31 00:14:45 +00:00
|
|
|
|
if (!((PCOMMON_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->IsClassDO)
|
|
|
|
|
return ForwardIrpAndForget(DeviceObject, Irp);
|
|
|
|
|
|
|
|
|
|
if (IoGetCurrentIrpStackLocation(Irp)->Parameters.Read.Length < sizeof(MOUSE_INPUT_DATA))
|
|
|
|
|
{
|
|
|
|
|
Irp->IoStatus.Status = STATUS_BUFFER_TOO_SMALL;
|
|
|
|
|
Irp->IoStatus.Information = 0;
|
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
|
|
|
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-02 12:36:50 +00:00
|
|
|
|
KeAcquireSpinLock(&DeviceExtension->SpinLock, &OldIrql);
|
|
|
|
|
Status = HandleReadIrp(DeviceObject, Irp, FALSE);
|
|
|
|
|
KeReleaseSpinLock(&DeviceExtension->SpinLock, OldIrql);
|
|
|
|
|
return Status;
|
2000-10-18 09:11:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-11-05 08:37:01 +00:00
|
|
|
|
static NTSTATUS NTAPI
|
|
|
|
|
ClassDeviceControl(
|
|
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
|
IN PIRP Irp)
|
|
|
|
|
{
|
|
|
|
|
PCLASS_DEVICE_EXTENSION DeviceExtension;
|
2007-11-02 13:01:15 +00:00
|
|
|
|
NTSTATUS Status = STATUS_NOT_SUPPORTED;
|
2005-11-05 08:37:01 +00:00
|
|
|
|
|
2008-07-25 20:24:46 +00:00
|
|
|
|
TRACE_(CLASS_NAME, "IRP_MJ_DEVICE_CONTROL\n");
|
2005-11-05 08:37:01 +00:00
|
|
|
|
|
|
|
|
|
if (!((PCOMMON_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->IsClassDO)
|
|
|
|
|
return ForwardIrpAndForget(DeviceObject, Irp);
|
|
|
|
|
|
|
|
|
|
DeviceExtension = (PCLASS_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
|
|
|
|
|
|
|
|
|
|
switch (IoGetCurrentIrpStackLocation(Irp)->Parameters.DeviceIoControl.IoControlCode)
|
|
|
|
|
{
|
|
|
|
|
case IOCTL_MOUSE_QUERY_ATTRIBUTES:
|
2006-02-24 13:38:14 +00:00
|
|
|
|
{
|
|
|
|
|
/* FIXME: We hope that all devices will return the same result.
|
|
|
|
|
* Ask only the first one */
|
|
|
|
|
PLIST_ENTRY Head = &((PCLASS_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->ListHead;
|
|
|
|
|
if (Head->Flink != Head)
|
|
|
|
|
{
|
2006-07-17 22:13:40 +00:00
|
|
|
|
/* We have at least one device */
|
2006-02-24 13:38:14 +00:00
|
|
|
|
PPORT_DEVICE_EXTENSION DevExt = CONTAINING_RECORD(Head->Flink, PORT_DEVICE_EXTENSION, ListEntry);
|
|
|
|
|
IoGetCurrentIrpStackLocation(Irp)->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL;
|
|
|
|
|
IoSkipCurrentIrpStackLocation(Irp);
|
|
|
|
|
return IoCallDriver(DevExt->DeviceObject, Irp);
|
|
|
|
|
}
|
2005-11-05 08:37:01 +00:00
|
|
|
|
break;
|
2006-02-24 13:38:14 +00:00
|
|
|
|
}
|
2005-11-05 08:37:01 +00:00
|
|
|
|
default:
|
2008-07-25 20:24:46 +00:00
|
|
|
|
WARN_(CLASS_NAME, "IRP_MJ_DEVICE_CONTROL / unknown I/O control code 0x%lx\n",
|
2005-11-05 08:37:01 +00:00
|
|
|
|
IoGetCurrentIrpStackLocation(Irp)->Parameters.DeviceIoControl.IoControlCode);
|
2006-04-16 07:17:34 +00:00
|
|
|
|
ASSERT(FALSE);
|
2006-02-24 13:38:14 +00:00
|
|
|
|
break;
|
2005-11-05 08:37:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Irp->IoStatus.Status = Status;
|
|
|
|
|
Irp->IoStatus.Information = 0;
|
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
|
}
|
|
|
|
|
|
2005-10-31 00:14:45 +00:00
|
|
|
|
static NTSTATUS NTAPI
|
|
|
|
|
IrpStub(
|
|
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
|
IN PIRP Irp)
|
2000-10-18 09:11:01 +00:00
|
|
|
|
{
|
2005-10-31 00:14:45 +00:00
|
|
|
|
NTSTATUS Status = STATUS_NOT_SUPPORTED;
|
|
|
|
|
|
|
|
|
|
if (!((PCOMMON_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->IsClassDO)
|
|
|
|
|
{
|
|
|
|
|
/* Forward some IRPs to lower device */
|
|
|
|
|
switch (IoGetCurrentIrpStackLocation(Irp)->MajorFunction)
|
|
|
|
|
{
|
2005-12-18 20:50:26 +00:00
|
|
|
|
case IRP_MJ_PNP:
|
2005-10-31 00:14:45 +00:00
|
|
|
|
case IRP_MJ_INTERNAL_DEVICE_CONTROL:
|
|
|
|
|
return ForwardIrpAndForget(DeviceObject, Irp);
|
|
|
|
|
default:
|
|
|
|
|
{
|
2008-07-25 20:24:46 +00:00
|
|
|
|
ERR_(CLASS_NAME, "Port DO stub for major function 0x%lx\n",
|
2005-10-31 00:14:45 +00:00
|
|
|
|
IoGetCurrentIrpStackLocation(Irp)->MajorFunction);
|
|
|
|
|
ASSERT(FALSE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2008-07-25 20:24:46 +00:00
|
|
|
|
ERR_(CLASS_NAME, "Class DO stub for major function 0x%lx\n",
|
2005-10-31 00:14:45 +00:00
|
|
|
|
IoGetCurrentIrpStackLocation(Irp)->MajorFunction);
|
|
|
|
|
ASSERT(FALSE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Irp->IoStatus.Status = Status;
|
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
|
return Status;
|
2000-10-18 09:11:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-10-31 00:14:45 +00:00
|
|
|
|
static NTSTATUS
|
|
|
|
|
ReadRegistryEntries(
|
|
|
|
|
IN PUNICODE_STRING RegistryPath,
|
2005-11-05 08:37:01 +00:00
|
|
|
|
IN PCLASS_DRIVER_EXTENSION DriverExtension)
|
2000-10-18 09:11:01 +00:00
|
|
|
|
{
|
2005-11-05 08:37:01 +00:00
|
|
|
|
UNICODE_STRING ParametersRegistryKey;
|
2005-10-31 00:14:45 +00:00
|
|
|
|
RTL_QUERY_REGISTRY_TABLE Parameters[4];
|
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
|
|
|
|
ULONG DefaultConnectMultiplePorts = 1;
|
2005-11-05 08:37:01 +00:00
|
|
|
|
ULONG DefaultDataQueueSize = 0x64;
|
2007-03-17 20:53:05 +00:00
|
|
|
|
PCWSTR DefaultDeviceBaseName = L"PointerClass";
|
2005-11-05 08:37:01 +00:00
|
|
|
|
|
|
|
|
|
ParametersRegistryKey.Length = 0;
|
|
|
|
|
ParametersRegistryKey.MaximumLength = RegistryPath->Length + sizeof(L"\\Parameters") + sizeof(UNICODE_NULL);
|
2007-06-04 09:25:04 +00:00
|
|
|
|
ParametersRegistryKey.Buffer = ExAllocatePoolWithTag(PagedPool, ParametersRegistryKey.MaximumLength, CLASS_TAG);
|
2005-11-05 08:37:01 +00:00
|
|
|
|
if (!ParametersRegistryKey.Buffer)
|
|
|
|
|
{
|
2008-07-25 20:24:46 +00:00
|
|
|
|
WARN_(CLASS_NAME, "ExAllocatePoolWithTag() failed\n");
|
2007-06-04 09:25:04 +00:00
|
|
|
|
return STATUS_NO_MEMORY;
|
2005-11-05 08:37:01 +00:00
|
|
|
|
}
|
|
|
|
|
RtlCopyUnicodeString(&ParametersRegistryKey, RegistryPath);
|
|
|
|
|
RtlAppendUnicodeToString(&ParametersRegistryKey, L"\\Parameters");
|
|
|
|
|
ParametersRegistryKey.Buffer[ParametersRegistryKey.Length / sizeof(WCHAR)] = UNICODE_NULL;
|
2005-10-31 00:14:45 +00:00
|
|
|
|
|
|
|
|
|
RtlZeroMemory(Parameters, sizeof(Parameters));
|
|
|
|
|
|
|
|
|
|
Parameters[0].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_REGISTRY_OPTIONAL;
|
|
|
|
|
Parameters[0].Name = L"ConnectMultiplePorts";
|
|
|
|
|
Parameters[0].EntryContext = &DriverExtension->ConnectMultiplePorts;
|
|
|
|
|
Parameters[0].DefaultType = REG_DWORD;
|
|
|
|
|
Parameters[0].DefaultData = &DefaultConnectMultiplePorts;
|
|
|
|
|
Parameters[0].DefaultLength = sizeof(ULONG);
|
2005-11-05 08:37:01 +00:00
|
|
|
|
|
2005-10-31 00:14:45 +00:00
|
|
|
|
Parameters[1].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_REGISTRY_OPTIONAL;
|
|
|
|
|
Parameters[1].Name = L"MouseDataQueueSize";
|
2005-11-05 08:37:01 +00:00
|
|
|
|
Parameters[1].EntryContext = &DriverExtension->DataQueueSize;
|
2005-10-31 00:14:45 +00:00
|
|
|
|
Parameters[1].DefaultType = REG_DWORD;
|
2005-11-05 08:37:01 +00:00
|
|
|
|
Parameters[1].DefaultData = &DefaultDataQueueSize;
|
2005-10-31 00:14:45 +00:00
|
|
|
|
Parameters[1].DefaultLength = sizeof(ULONG);
|
2005-11-05 08:37:01 +00:00
|
|
|
|
|
2005-10-31 00:14:45 +00:00
|
|
|
|
Parameters[2].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_REGISTRY_OPTIONAL;
|
|
|
|
|
Parameters[2].Name = L"PointerDeviceBaseName";
|
2005-11-05 08:37:01 +00:00
|
|
|
|
Parameters[2].EntryContext = &DriverExtension->DeviceBaseName;
|
2005-10-31 00:14:45 +00:00
|
|
|
|
Parameters[2].DefaultType = REG_SZ;
|
2007-03-17 20:53:05 +00:00
|
|
|
|
Parameters[2].DefaultData = (PVOID)DefaultDeviceBaseName;
|
2005-11-09 11:16:43 +00:00
|
|
|
|
Parameters[2].DefaultLength = 0;
|
2005-10-31 00:14:45 +00:00
|
|
|
|
|
|
|
|
|
Status = RtlQueryRegistryValues(
|
|
|
|
|
RTL_REGISTRY_ABSOLUTE,
|
2005-11-05 08:37:01 +00:00
|
|
|
|
ParametersRegistryKey.Buffer,
|
2005-10-31 00:14:45 +00:00
|
|
|
|
Parameters,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
|
{
|
|
|
|
|
/* Check values */
|
|
|
|
|
if (DriverExtension->ConnectMultiplePorts != 0
|
|
|
|
|
&& DriverExtension->ConnectMultiplePorts != 1)
|
|
|
|
|
{
|
|
|
|
|
DriverExtension->ConnectMultiplePorts = DefaultConnectMultiplePorts;
|
|
|
|
|
}
|
2005-11-05 08:37:01 +00:00
|
|
|
|
if (DriverExtension->DataQueueSize == 0)
|
2005-10-31 00:14:45 +00:00
|
|
|
|
{
|
2005-11-05 08:37:01 +00:00
|
|
|
|
DriverExtension->DataQueueSize = DefaultDataQueueSize;
|
2005-10-31 00:14:45 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2005-11-05 08:37:01 +00:00
|
|
|
|
else if (Status == STATUS_OBJECT_NAME_NOT_FOUND)
|
|
|
|
|
{
|
|
|
|
|
/* Registry path doesn't exist. Set defaults */
|
|
|
|
|
DriverExtension->ConnectMultiplePorts = DefaultConnectMultiplePorts;
|
|
|
|
|
DriverExtension->DataQueueSize = DefaultDataQueueSize;
|
2007-03-17 20:53:05 +00:00
|
|
|
|
if (RtlCreateUnicodeString(&DriverExtension->DeviceBaseName, DefaultDeviceBaseName))
|
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
|
else
|
|
|
|
|
Status = STATUS_NO_MEMORY;
|
2005-11-05 08:37:01 +00:00
|
|
|
|
}
|
2005-10-31 00:14:45 +00:00
|
|
|
|
|
2007-06-04 09:25:04 +00:00
|
|
|
|
ExFreePoolWithTag(ParametersRegistryKey.Buffer, CLASS_TAG);
|
2005-10-31 00:14:45 +00:00
|
|
|
|
return Status;
|
2000-10-18 09:11:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-10-31 00:14:45 +00:00
|
|
|
|
static NTSTATUS
|
2005-11-05 08:37:01 +00:00
|
|
|
|
CreateClassDeviceObject(
|
2005-10-31 00:14:45 +00:00
|
|
|
|
IN PDRIVER_OBJECT DriverObject,
|
|
|
|
|
OUT PDEVICE_OBJECT *ClassDO OPTIONAL)
|
2000-10-18 09:11:01 +00:00
|
|
|
|
{
|
2005-11-05 08:37:01 +00:00
|
|
|
|
PCLASS_DRIVER_EXTENSION DriverExtension;
|
2005-10-31 00:14:45 +00:00
|
|
|
|
ULONG DeviceId = 0;
|
|
|
|
|
ULONG PrefixLength;
|
|
|
|
|
UNICODE_STRING DeviceNameU;
|
|
|
|
|
PWSTR DeviceIdW = NULL; /* Pointer into DeviceNameU.Buffer */
|
|
|
|
|
PDEVICE_OBJECT Fdo;
|
2005-11-05 08:37:01 +00:00
|
|
|
|
PCLASS_DEVICE_EXTENSION DeviceExtension;
|
2005-10-31 00:14:45 +00:00
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
2008-07-25 20:24:46 +00:00
|
|
|
|
TRACE_(CLASS_NAME, "CreateClassDeviceObject(0x%p)\n", DriverObject);
|
2005-10-31 00:14:45 +00:00
|
|
|
|
|
|
|
|
|
/* Create new device object */
|
|
|
|
|
DriverExtension = IoGetDriverObjectExtension(DriverObject, DriverObject);
|
|
|
|
|
DeviceNameU.Length = 0;
|
|
|
|
|
DeviceNameU.MaximumLength =
|
2005-11-05 08:37:01 +00:00
|
|
|
|
wcslen(L"\\Device\\") * sizeof(WCHAR) /* "\Device\" */
|
|
|
|
|
+ DriverExtension->DeviceBaseName.Length /* "PointerClass" */
|
|
|
|
|
+ 4 * sizeof(WCHAR) /* Id between 0 and 9999 */
|
|
|
|
|
+ sizeof(UNICODE_NULL); /* Final NULL char */
|
2007-06-04 09:25:04 +00:00
|
|
|
|
DeviceNameU.Buffer = ExAllocatePoolWithTag(PagedPool, DeviceNameU.MaximumLength, CLASS_TAG);
|
2005-10-31 00:14:45 +00:00
|
|
|
|
if (!DeviceNameU.Buffer)
|
|
|
|
|
{
|
2008-07-25 20:24:46 +00:00
|
|
|
|
WARN_(CLASS_NAME, "ExAllocatePoolWithTag() failed\n");
|
2007-06-04 09:25:04 +00:00
|
|
|
|
return STATUS_NO_MEMORY;
|
2005-10-31 00:14:45 +00:00
|
|
|
|
}
|
|
|
|
|
Status = RtlAppendUnicodeToString(&DeviceNameU, L"\\Device\\");
|
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
|
{
|
2008-07-25 20:24:46 +00:00
|
|
|
|
WARN_(CLASS_NAME, "RtlAppendUnicodeToString() failed with status 0x%08lx\n", Status);
|
2005-10-31 00:14:45 +00:00
|
|
|
|
goto cleanup;
|
|
|
|
|
}
|
2005-11-05 08:37:01 +00:00
|
|
|
|
Status = RtlAppendUnicodeStringToString(&DeviceNameU, &DriverExtension->DeviceBaseName);
|
2005-10-31 00:14:45 +00:00
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
|
{
|
2008-07-25 20:24:46 +00:00
|
|
|
|
WARN_(CLASS_NAME, "RtlAppendUnicodeStringToString() failed with status 0x%08lx\n", Status);
|
2005-10-31 00:14:45 +00:00
|
|
|
|
goto cleanup;
|
|
|
|
|
}
|
|
|
|
|
PrefixLength = DeviceNameU.MaximumLength - 4 * sizeof(WCHAR) - sizeof(UNICODE_NULL);
|
|
|
|
|
DeviceIdW = &DeviceNameU.Buffer[PrefixLength / sizeof(WCHAR)];
|
|
|
|
|
while (DeviceId < 9999)
|
|
|
|
|
{
|
2007-03-18 00:27:02 +00:00
|
|
|
|
DeviceNameU.Length = (USHORT)(PrefixLength + swprintf(DeviceIdW, L"%lu", DeviceId) * sizeof(WCHAR));
|
2005-10-31 00:14:45 +00:00
|
|
|
|
Status = IoCreateDevice(
|
|
|
|
|
DriverObject,
|
2005-11-05 08:37:01 +00:00
|
|
|
|
sizeof(CLASS_DEVICE_EXTENSION),
|
2005-10-31 00:14:45 +00:00
|
|
|
|
&DeviceNameU,
|
|
|
|
|
FILE_DEVICE_MOUSE,
|
|
|
|
|
FILE_DEVICE_SECURE_OPEN,
|
2009-05-23 02:02:48 +00:00
|
|
|
|
FALSE,
|
2005-10-31 00:14:45 +00:00
|
|
|
|
&Fdo);
|
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
|
goto cleanup;
|
|
|
|
|
else if (Status != STATUS_OBJECT_NAME_COLLISION)
|
|
|
|
|
{
|
2008-07-25 20:24:46 +00:00
|
|
|
|
WARN_(CLASS_NAME, "IoCreateDevice() failed with status 0x%08lx\n", Status);
|
2005-10-31 00:14:45 +00:00
|
|
|
|
goto cleanup;
|
|
|
|
|
}
|
|
|
|
|
DeviceId++;
|
|
|
|
|
}
|
2008-07-25 20:24:46 +00:00
|
|
|
|
WARN_(CLASS_NAME, "Too many devices starting with '\\Device\\%wZ'\n", &DriverExtension->DeviceBaseName);
|
2006-01-02 11:32:03 +00:00
|
|
|
|
Status = STATUS_TOO_MANY_NAMES;
|
2005-10-31 00:14:45 +00:00
|
|
|
|
cleanup:
|
|
|
|
|
if (!NT_SUCCESS(Status))
|
2005-11-05 08:37:01 +00:00
|
|
|
|
{
|
2007-06-04 09:25:04 +00:00
|
|
|
|
ExFreePoolWithTag(DeviceNameU.Buffer, CLASS_TAG);
|
2005-10-31 00:14:45 +00:00
|
|
|
|
return Status;
|
2005-11-05 08:37:01 +00:00
|
|
|
|
}
|
2005-10-31 00:14:45 +00:00
|
|
|
|
|
2005-11-05 08:37:01 +00:00
|
|
|
|
DeviceExtension = (PCLASS_DEVICE_EXTENSION)Fdo->DeviceExtension;
|
|
|
|
|
RtlZeroMemory(DeviceExtension, sizeof(CLASS_DEVICE_EXTENSION));
|
2005-10-31 00:14:45 +00:00
|
|
|
|
DeviceExtension->Common.IsClassDO = TRUE;
|
|
|
|
|
DeviceExtension->DriverExtension = DriverExtension;
|
2006-02-24 13:38:14 +00:00
|
|
|
|
InitializeListHead(&DeviceExtension->ListHead);
|
|
|
|
|
KeInitializeSpinLock(&DeviceExtension->ListSpinLock);
|
|
|
|
|
KeInitializeSpinLock(&DeviceExtension->SpinLock);
|
2005-10-31 00:14:45 +00:00
|
|
|
|
DeviceExtension->InputCount = 0;
|
2007-11-02 12:36:50 +00:00
|
|
|
|
DeviceExtension->PortData = ExAllocatePoolWithTag(NonPagedPool, DeviceExtension->DriverExtension->DataQueueSize * sizeof(MOUSE_INPUT_DATA), CLASS_TAG);
|
2006-07-11 13:38:59 +00:00
|
|
|
|
if (!DeviceExtension->PortData)
|
|
|
|
|
{
|
2007-06-04 09:25:04 +00:00
|
|
|
|
ExFreePoolWithTag(DeviceNameU.Buffer, CLASS_TAG);
|
|
|
|
|
return STATUS_NO_MEMORY;
|
2006-07-11 13:38:59 +00:00
|
|
|
|
}
|
2006-07-17 22:13:40 +00:00
|
|
|
|
DeviceExtension->DeviceName = DeviceNameU.Buffer;
|
2005-10-31 00:14:45 +00:00
|
|
|
|
Fdo->Flags |= DO_POWER_PAGABLE;
|
|
|
|
|
Fdo->Flags &= ~DO_DEVICE_INITIALIZING;
|
2009-05-23 22:50:07 +00:00
|
|
|
|
Fdo->Flags |= DO_BUFFERED_IO;
|
2005-10-31 00:14:45 +00:00
|
|
|
|
|
2005-11-09 11:16:43 +00:00
|
|
|
|
/* Add entry entry to HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\[DeviceBaseName] */
|
|
|
|
|
RtlWriteRegistryValue(
|
|
|
|
|
RTL_REGISTRY_DEVICEMAP,
|
|
|
|
|
DriverExtension->DeviceBaseName.Buffer,
|
2006-07-17 22:13:40 +00:00
|
|
|
|
DeviceExtension->DeviceName,
|
2005-11-09 11:16:43 +00:00
|
|
|
|
REG_SZ,
|
|
|
|
|
DriverExtension->RegistryPath.Buffer,
|
|
|
|
|
DriverExtension->RegistryPath.MaximumLength);
|
2005-10-31 00:14:45 +00:00
|
|
|
|
|
|
|
|
|
if (ClassDO)
|
|
|
|
|
*ClassDO = Fdo;
|
|
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
2001-05-26 08:19:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-04-25 22:22:22 +00:00
|
|
|
|
static NTSTATUS
|
2006-07-17 22:13:40 +00:00
|
|
|
|
FillEntries(
|
2006-04-25 22:22:22 +00:00
|
|
|
|
IN PDEVICE_OBJECT ClassDeviceObject,
|
|
|
|
|
IN PIRP Irp,
|
2006-07-17 22:13:40 +00:00
|
|
|
|
IN PMOUSE_INPUT_DATA DataStart,
|
|
|
|
|
IN SIZE_T NumberOfEntries)
|
2006-04-25 22:22:22 +00:00
|
|
|
|
{
|
|
|
|
|
NTSTATUS Status = STATUS_SUCCESS;
|
|
|
|
|
|
|
|
|
|
if (ClassDeviceObject->Flags & DO_BUFFERED_IO)
|
|
|
|
|
{
|
|
|
|
|
RtlCopyMemory(
|
|
|
|
|
Irp->AssociatedIrp.SystemBuffer,
|
|
|
|
|
DataStart,
|
2006-07-17 22:13:40 +00:00
|
|
|
|
NumberOfEntries * sizeof(MOUSE_INPUT_DATA));
|
2006-04-25 22:22:22 +00:00
|
|
|
|
}
|
|
|
|
|
else if (ClassDeviceObject->Flags & DO_DIRECT_IO)
|
|
|
|
|
{
|
|
|
|
|
PVOID DestAddress = MmGetSystemAddressForMdlSafe(Irp->MdlAddress, NormalPagePriority);
|
|
|
|
|
if (DestAddress)
|
|
|
|
|
{
|
|
|
|
|
RtlCopyMemory(
|
|
|
|
|
DestAddress,
|
|
|
|
|
DataStart,
|
2006-07-17 22:13:40 +00:00
|
|
|
|
NumberOfEntries * sizeof(MOUSE_INPUT_DATA));
|
2006-04-25 22:22:22 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
Status = STATUS_UNSUCCESSFUL;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2008-11-30 19:28:11 +00:00
|
|
|
|
_SEH2_TRY
|
2006-04-25 22:22:22 +00:00
|
|
|
|
{
|
|
|
|
|
RtlCopyMemory(
|
|
|
|
|
Irp->UserBuffer,
|
|
|
|
|
DataStart,
|
2006-07-17 22:13:40 +00:00
|
|
|
|
NumberOfEntries * sizeof(MOUSE_INPUT_DATA));
|
2006-04-25 22:22:22 +00:00
|
|
|
|
}
|
2008-11-30 19:28:11 +00:00
|
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
2006-04-25 22:22:22 +00:00
|
|
|
|
{
|
2008-11-30 19:28:11 +00:00
|
|
|
|
Status = _SEH2_GetExceptionCode();
|
2006-04-25 22:22:22 +00:00
|
|
|
|
}
|
2008-11-30 19:28:11 +00:00
|
|
|
|
_SEH2_END;
|
2006-04-25 22:22:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
|
}
|
|
|
|
|
|
2007-03-18 00:27:02 +00:00
|
|
|
|
static BOOLEAN NTAPI
|
2005-11-05 08:37:01 +00:00
|
|
|
|
ClassCallback(
|
2005-10-31 00:14:45 +00:00
|
|
|
|
IN PDEVICE_OBJECT ClassDeviceObject,
|
2005-11-05 08:37:01 +00:00
|
|
|
|
IN OUT PMOUSE_INPUT_DATA DataStart,
|
|
|
|
|
IN PMOUSE_INPUT_DATA DataEnd,
|
2005-10-31 00:14:45 +00:00
|
|
|
|
IN OUT PULONG ConsumedCount)
|
|
|
|
|
{
|
2005-11-05 08:37:01 +00:00
|
|
|
|
PCLASS_DEVICE_EXTENSION ClassDeviceExtension = ClassDeviceObject->DeviceExtension;
|
2005-10-31 00:14:45 +00:00
|
|
|
|
KIRQL OldIrql;
|
2007-03-18 00:27:02 +00:00
|
|
|
|
SIZE_T InputCount = DataEnd - DataStart;
|
|
|
|
|
SIZE_T ReadSize;
|
2005-10-31 00:14:45 +00:00
|
|
|
|
|
2008-07-25 20:24:46 +00:00
|
|
|
|
TRACE_(CLASS_NAME, "ClassCallback()\n");
|
2005-10-31 00:14:45 +00:00
|
|
|
|
|
2007-11-02 12:36:50 +00:00
|
|
|
|
ASSERT(ClassDeviceExtension->Common.IsClassDO);
|
2005-10-31 00:14:45 +00:00
|
|
|
|
|
2007-11-02 12:36:50 +00:00
|
|
|
|
KeAcquireSpinLock(&ClassDeviceExtension->SpinLock, &OldIrql);
|
|
|
|
|
if (InputCount > 0)
|
2005-10-31 00:14:45 +00:00
|
|
|
|
{
|
2005-11-05 08:37:01 +00:00
|
|
|
|
if (ClassDeviceExtension->InputCount + InputCount > ClassDeviceExtension->DriverExtension->DataQueueSize)
|
2006-05-03 14:42:28 +00:00
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
* We're exceeding the buffer, and data will be thrown away...
|
|
|
|
|
* FIXME: What could we do, as we are at DISPATCH_LEVEL?
|
|
|
|
|
*/
|
2005-11-05 08:37:01 +00:00
|
|
|
|
ReadSize = ClassDeviceExtension->DriverExtension->DataQueueSize - ClassDeviceExtension->InputCount;
|
2006-05-03 14:42:28 +00:00
|
|
|
|
}
|
2005-10-31 00:14:45 +00:00
|
|
|
|
else
|
|
|
|
|
ReadSize = InputCount;
|
|
|
|
|
|
|
|
|
|
/*
|
2005-11-05 08:37:01 +00:00
|
|
|
|
* Move the input data from the port data queue to our class data
|
2005-10-31 00:14:45 +00:00
|
|
|
|
* queue.
|
|
|
|
|
*/
|
2006-07-11 13:38:59 +00:00
|
|
|
|
RtlCopyMemory(
|
|
|
|
|
&ClassDeviceExtension->PortData[ClassDeviceExtension->InputCount],
|
2005-11-05 08:37:01 +00:00
|
|
|
|
(PCHAR)DataStart,
|
2005-10-31 00:14:45 +00:00
|
|
|
|
sizeof(MOUSE_INPUT_DATA) * ReadSize);
|
|
|
|
|
|
2006-07-11 13:38:59 +00:00
|
|
|
|
/* Move the counter up */
|
2005-10-31 00:14:45 +00:00
|
|
|
|
ClassDeviceExtension->InputCount += ReadSize;
|
|
|
|
|
|
2007-03-18 00:27:02 +00:00
|
|
|
|
(*ConsumedCount) += (ULONG)ReadSize;
|
2005-10-31 00:14:45 +00:00
|
|
|
|
|
2007-11-02 12:36:50 +00:00
|
|
|
|
/* Complete pending IRP (if any) */
|
|
|
|
|
if (ClassDeviceExtension->PendingIrp)
|
|
|
|
|
HandleReadIrp(ClassDeviceObject, ClassDeviceExtension->PendingIrp, FALSE);
|
2005-10-31 00:14:45 +00:00
|
|
|
|
}
|
2007-11-02 12:36:50 +00:00
|
|
|
|
KeReleaseSpinLock(&ClassDeviceExtension->SpinLock, OldIrql);
|
2005-10-31 00:14:45 +00:00
|
|
|
|
|
2008-07-25 20:24:46 +00:00
|
|
|
|
TRACE_(CLASS_NAME, "Leaving ClassCallback()\n");
|
2005-10-31 00:14:45 +00:00
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2005-11-05 08:37:01 +00:00
|
|
|
|
/* Send IOCTL_INTERNAL_*_CONNECT to port */
|
2005-10-31 00:14:45 +00:00
|
|
|
|
static NTSTATUS
|
2005-11-05 08:37:01 +00:00
|
|
|
|
ConnectPortDriver(
|
|
|
|
|
IN PDEVICE_OBJECT PortDO,
|
|
|
|
|
IN PDEVICE_OBJECT ClassDO)
|
2005-10-31 00:14:45 +00:00
|
|
|
|
{
|
|
|
|
|
KEVENT Event;
|
|
|
|
|
PIRP Irp;
|
|
|
|
|
IO_STATUS_BLOCK IoStatus;
|
|
|
|
|
CONNECT_DATA ConnectData;
|
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
2008-07-25 20:24:46 +00:00
|
|
|
|
TRACE_(CLASS_NAME, "Connecting PortDO %p to ClassDO %p\n", PortDO, ClassDO);
|
2006-07-13 22:20:54 +00:00
|
|
|
|
|
2005-10-31 00:14:45 +00:00
|
|
|
|
KeInitializeEvent(&Event, NotificationEvent, FALSE);
|
|
|
|
|
|
2005-11-05 08:37:01 +00:00
|
|
|
|
ConnectData.ClassDeviceObject = ClassDO;
|
|
|
|
|
ConnectData.ClassService = ClassCallback;
|
2005-10-31 00:14:45 +00:00
|
|
|
|
|
2006-07-17 22:13:40 +00:00
|
|
|
|
Irp = IoBuildDeviceIoControlRequest(
|
|
|
|
|
IOCTL_INTERNAL_MOUSE_CONNECT,
|
2005-11-05 08:37:01 +00:00
|
|
|
|
PortDO,
|
2005-10-31 00:14:45 +00:00
|
|
|
|
&ConnectData, sizeof(CONNECT_DATA),
|
|
|
|
|
NULL, 0,
|
|
|
|
|
TRUE, &Event, &IoStatus);
|
2006-07-17 22:13:40 +00:00
|
|
|
|
if (!Irp)
|
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
2005-10-31 00:14:45 +00:00
|
|
|
|
|
2005-11-05 08:37:01 +00:00
|
|
|
|
Status = IoCallDriver(PortDO, Irp);
|
2005-10-31 00:14:45 +00:00
|
|
|
|
|
|
|
|
|
if (Status == STATUS_PENDING)
|
|
|
|
|
KeWaitForSingleObject(&Event, Suspended, KernelMode, FALSE, NULL);
|
|
|
|
|
else
|
|
|
|
|
IoStatus.Status = Status;
|
|
|
|
|
|
2005-11-05 08:37:01 +00:00
|
|
|
|
if (NT_SUCCESS(IoStatus.Status))
|
2006-02-24 13:38:14 +00:00
|
|
|
|
{
|
2005-11-05 08:37:01 +00:00
|
|
|
|
ObReferenceObject(PortDO);
|
2006-02-24 13:38:14 +00:00
|
|
|
|
ExInterlockedInsertTailList(
|
|
|
|
|
&((PCLASS_DEVICE_EXTENSION)ClassDO->DeviceExtension)->ListHead,
|
|
|
|
|
&((PPORT_DEVICE_EXTENSION)PortDO->DeviceExtension)->ListEntry,
|
|
|
|
|
&((PCLASS_DEVICE_EXTENSION)ClassDO->DeviceExtension)->ListSpinLock);
|
|
|
|
|
if (ClassDO->StackSize <= PortDO->StackSize)
|
|
|
|
|
{
|
|
|
|
|
/* Increase the stack size, in case we have to
|
|
|
|
|
* forward some IRPs to the port device object
|
|
|
|
|
*/
|
|
|
|
|
ClassDO->StackSize = PortDO->StackSize + 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
2005-11-05 08:37:01 +00:00
|
|
|
|
|
2005-10-31 00:14:45 +00:00
|
|
|
|
return IoStatus.Status;
|
|
|
|
|
}
|
|
|
|
|
|
2006-07-17 22:13:40 +00:00
|
|
|
|
/* Send IOCTL_INTERNAL_*_DISCONNECT to port + destroy the Port DO */
|
|
|
|
|
static VOID
|
|
|
|
|
DestroyPortDriver(
|
2006-07-13 22:20:54 +00:00
|
|
|
|
IN PDEVICE_OBJECT PortDO)
|
|
|
|
|
{
|
2006-07-17 22:13:40 +00:00
|
|
|
|
PPORT_DEVICE_EXTENSION DeviceExtension;
|
|
|
|
|
PCLASS_DEVICE_EXTENSION ClassDeviceExtension;
|
|
|
|
|
PCLASS_DRIVER_EXTENSION DriverExtension;
|
|
|
|
|
KEVENT Event;
|
|
|
|
|
PIRP Irp;
|
|
|
|
|
IO_STATUS_BLOCK IoStatus;
|
|
|
|
|
KIRQL OldIrql;
|
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
2008-07-25 20:24:46 +00:00
|
|
|
|
TRACE_(CLASS_NAME, "Destroying PortDO %p\n", PortDO);
|
2006-07-13 22:20:54 +00:00
|
|
|
|
|
2006-07-17 22:13:40 +00:00
|
|
|
|
DeviceExtension = (PPORT_DEVICE_EXTENSION)PortDO->DeviceExtension;
|
|
|
|
|
ClassDeviceExtension = DeviceExtension->ClassDO->DeviceExtension;
|
|
|
|
|
DriverExtension = IoGetDriverObjectExtension(PortDO->DriverObject, PortDO->DriverObject);
|
|
|
|
|
|
|
|
|
|
/* Send IOCTL_INTERNAL_*_DISCONNECT */
|
|
|
|
|
KeInitializeEvent(&Event, NotificationEvent, FALSE);
|
|
|
|
|
Irp = IoBuildDeviceIoControlRequest(
|
|
|
|
|
IOCTL_INTERNAL_MOUSE_DISCONNECT,
|
|
|
|
|
PortDO,
|
|
|
|
|
NULL, 0,
|
|
|
|
|
NULL, 0,
|
|
|
|
|
TRUE, &Event, &IoStatus);
|
|
|
|
|
if (Irp)
|
|
|
|
|
{
|
|
|
|
|
Status = IoCallDriver(PortDO, Irp);
|
|
|
|
|
if (Status == STATUS_PENDING)
|
|
|
|
|
KeWaitForSingleObject(&Event, Suspended, KernelMode, FALSE, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Remove from ClassDeviceExtension->ListHead list */
|
|
|
|
|
KeAcquireSpinLock(&ClassDeviceExtension->ListSpinLock, &OldIrql);
|
|
|
|
|
RemoveHeadList(DeviceExtension->ListEntry.Blink);
|
|
|
|
|
KeReleaseSpinLock(&ClassDeviceExtension->ListSpinLock, OldIrql);
|
|
|
|
|
|
|
|
|
|
/* Remove entry from HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\[DeviceBaseName] */
|
|
|
|
|
RtlDeleteRegistryValue(
|
|
|
|
|
RTL_REGISTRY_DEVICEMAP,
|
|
|
|
|
DriverExtension->DeviceBaseName.Buffer,
|
|
|
|
|
ClassDeviceExtension->DeviceName);
|
|
|
|
|
|
|
|
|
|
if (DeviceExtension->LowerDevice)
|
|
|
|
|
IoDetachDevice(DeviceExtension->LowerDevice);
|
|
|
|
|
ObDereferenceObject(PortDO);
|
|
|
|
|
|
|
|
|
|
if (!DriverExtension->ConnectMultiplePorts && DeviceExtension->ClassDO)
|
|
|
|
|
{
|
2007-06-04 09:25:04 +00:00
|
|
|
|
ExFreePoolWithTag(ClassDeviceExtension->PortData, CLASS_TAG);
|
|
|
|
|
ExFreePoolWithTag((PVOID)ClassDeviceExtension->DeviceName, CLASS_TAG);
|
2006-07-17 22:13:40 +00:00
|
|
|
|
IoDeleteDevice(DeviceExtension->ClassDO);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IoDeleteDevice(PortDO);
|
2006-07-13 22:20:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-10-31 00:14:45 +00:00
|
|
|
|
static NTSTATUS NTAPI
|
2005-11-05 08:37:01 +00:00
|
|
|
|
ClassAddDevice(
|
2005-10-31 00:14:45 +00:00
|
|
|
|
IN PDRIVER_OBJECT DriverObject,
|
|
|
|
|
IN PDEVICE_OBJECT Pdo)
|
|
|
|
|
{
|
2005-11-05 08:37:01 +00:00
|
|
|
|
PCLASS_DRIVER_EXTENSION DriverExtension;
|
2006-04-16 07:17:34 +00:00
|
|
|
|
PDEVICE_OBJECT Fdo = NULL;
|
|
|
|
|
PPORT_DEVICE_EXTENSION DeviceExtension = NULL;
|
2005-10-31 00:14:45 +00:00
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
2008-07-25 20:24:46 +00:00
|
|
|
|
TRACE_(CLASS_NAME, "ClassAddDevice called. Pdo = 0x%p\n", Pdo);
|
2005-10-31 00:14:45 +00:00
|
|
|
|
|
|
|
|
|
DriverExtension = IoGetDriverObjectExtension(DriverObject, DriverObject);
|
|
|
|
|
|
2005-11-09 11:16:43 +00:00
|
|
|
|
if (Pdo == NULL)
|
2006-09-30 22:41:23 +00:00
|
|
|
|
/* We may get a NULL Pdo at the first call as we're a legacy driver. Ignore it */
|
|
|
|
|
return STATUS_SUCCESS;
|
2005-11-09 11:16:43 +00:00
|
|
|
|
|
2005-10-31 00:14:45 +00:00
|
|
|
|
/* Create new device object */
|
|
|
|
|
Status = IoCreateDevice(
|
|
|
|
|
DriverObject,
|
2005-11-05 08:37:01 +00:00
|
|
|
|
sizeof(PORT_DEVICE_EXTENSION),
|
2005-10-31 00:14:45 +00:00
|
|
|
|
NULL,
|
|
|
|
|
Pdo->DeviceType,
|
2006-04-25 22:22:22 +00:00
|
|
|
|
Pdo->Characteristics & FILE_DEVICE_SECURE_OPEN ? FILE_DEVICE_SECURE_OPEN : 0,
|
2009-05-23 02:02:48 +00:00
|
|
|
|
FALSE,
|
2005-10-31 00:14:45 +00:00
|
|
|
|
&Fdo);
|
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
|
{
|
2008-07-25 20:24:46 +00:00
|
|
|
|
WARN_(CLASS_NAME, "IoCreateDevice() failed with status 0x%08lx\n", Status);
|
2006-04-16 07:17:34 +00:00
|
|
|
|
goto cleanup;
|
2005-10-31 00:14:45 +00:00
|
|
|
|
}
|
2007-11-02 12:36:50 +00:00
|
|
|
|
IoSetStartIoAttributes(Fdo, TRUE, TRUE);
|
2005-10-31 00:14:45 +00:00
|
|
|
|
|
2005-11-05 08:37:01 +00:00
|
|
|
|
DeviceExtension = (PPORT_DEVICE_EXTENSION)Fdo->DeviceExtension;
|
2007-07-05 01:22:40 +00:00
|
|
|
|
RtlZeroMemory(DeviceExtension, sizeof(PORT_DEVICE_EXTENSION));
|
2005-10-31 00:14:45 +00:00
|
|
|
|
DeviceExtension->Common.IsClassDO = FALSE;
|
2006-02-24 13:38:14 +00:00
|
|
|
|
DeviceExtension->DeviceObject = Fdo;
|
2005-10-31 00:14:45 +00:00
|
|
|
|
DeviceExtension->PnpState = dsStopped;
|
|
|
|
|
Status = IoAttachDeviceToDeviceStackSafe(Fdo, Pdo, &DeviceExtension->LowerDevice);
|
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
|
{
|
2008-07-25 20:24:46 +00:00
|
|
|
|
WARN_(CLASS_NAME, "IoAttachDeviceToDeviceStackSafe() failed with status 0x%08lx\n", Status);
|
2006-04-16 07:17:34 +00:00
|
|
|
|
goto cleanup;
|
2005-10-31 00:14:45 +00:00
|
|
|
|
}
|
2005-11-18 17:28:19 +00:00
|
|
|
|
if (DeviceExtension->LowerDevice->Flags & DO_POWER_PAGABLE)
|
|
|
|
|
Fdo->Flags |= DO_POWER_PAGABLE;
|
|
|
|
|
if (DeviceExtension->LowerDevice->Flags & DO_BUFFERED_IO)
|
|
|
|
|
Fdo->Flags |= DO_BUFFERED_IO;
|
2006-04-25 22:22:22 +00:00
|
|
|
|
if (DeviceExtension->LowerDevice->Flags & DO_DIRECT_IO)
|
|
|
|
|
Fdo->Flags |= DO_DIRECT_IO;
|
2005-10-31 00:14:45 +00:00
|
|
|
|
|
|
|
|
|
if (DriverExtension->ConnectMultiplePorts)
|
2006-04-16 07:17:34 +00:00
|
|
|
|
DeviceExtension->ClassDO = DriverExtension->MainClassDeviceObject;
|
2005-10-31 00:14:45 +00:00
|
|
|
|
else
|
2006-04-16 07:17:34 +00:00
|
|
|
|
{
|
|
|
|
|
/* We need a new class device object for this Fdo */
|
|
|
|
|
Status = CreateClassDeviceObject(
|
|
|
|
|
DriverObject,
|
|
|
|
|
&DeviceExtension->ClassDO);
|
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
|
{
|
2008-07-25 20:24:46 +00:00
|
|
|
|
WARN_(CLASS_NAME, "CreateClassDeviceObject() failed with status 0x%08lx\n", Status);
|
2006-04-16 07:17:34 +00:00
|
|
|
|
goto cleanup;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Status = ConnectPortDriver(Fdo, DeviceExtension->ClassDO);
|
2005-10-31 00:14:45 +00:00
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
|
{
|
2008-07-25 20:24:46 +00:00
|
|
|
|
WARN_(CLASS_NAME, "ConnectPortDriver() failed with status 0x%08lx\n", Status);
|
2006-04-16 07:17:34 +00:00
|
|
|
|
goto cleanup;
|
2005-10-31 00:14:45 +00:00
|
|
|
|
}
|
2005-11-05 08:37:01 +00:00
|
|
|
|
Fdo->Flags &= ~DO_DEVICE_INITIALIZING;
|
2005-10-31 00:14:45 +00:00
|
|
|
|
|
2006-07-17 22:13:40 +00:00
|
|
|
|
/* Register interface ; ignore the error (if any) as having
|
|
|
|
|
* a registred interface is not so important... */
|
2006-09-30 22:41:23 +00:00
|
|
|
|
Status = IoRegisterDeviceInterface(
|
2005-10-31 00:14:45 +00:00
|
|
|
|
Pdo,
|
|
|
|
|
&GUID_DEVINTERFACE_MOUSE,
|
|
|
|
|
NULL,
|
2005-11-05 08:37:01 +00:00
|
|
|
|
&DeviceExtension->InterfaceName);
|
2006-07-17 22:13:40 +00:00
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
|
DeviceExtension->InterfaceName.Length = 0;
|
2005-10-31 00:14:45 +00:00
|
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
2006-04-16 07:17:34 +00:00
|
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
|
if (Fdo)
|
2006-07-17 22:13:40 +00:00
|
|
|
|
DestroyPortDriver(Fdo);
|
2006-04-16 07:17:34 +00:00
|
|
|
|
return Status;
|
2005-10-31 00:14:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static VOID NTAPI
|
2007-11-02 12:36:50 +00:00
|
|
|
|
ClassCancelRoutine(
|
2005-10-31 00:14:45 +00:00
|
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
|
IN PIRP Irp)
|
2007-11-02 12:36:50 +00:00
|
|
|
|
{
|
|
|
|
|
PCLASS_DEVICE_EXTENSION ClassDeviceExtension = DeviceObject->DeviceExtension;
|
|
|
|
|
KIRQL OldIrql;
|
|
|
|
|
BOOLEAN wasQueued = FALSE;
|
|
|
|
|
|
2008-07-25 20:24:46 +00:00
|
|
|
|
TRACE_(CLASS_NAME, "ClassCancelRoutine(DeviceObject %p, Irp %p)\n", DeviceObject, Irp);
|
2007-11-02 12:36:50 +00:00
|
|
|
|
|
|
|
|
|
ASSERT(ClassDeviceExtension->Common.IsClassDO);
|
|
|
|
|
|
2008-04-21 12:10:55 +00:00
|
|
|
|
IoReleaseCancelSpinLock(Irp->CancelIrql);
|
|
|
|
|
|
2007-11-02 12:36:50 +00:00
|
|
|
|
KeAcquireSpinLock(&ClassDeviceExtension->SpinLock, &OldIrql);
|
2008-04-21 12:10:55 +00:00
|
|
|
|
|
2007-11-02 12:36:50 +00:00
|
|
|
|
if (ClassDeviceExtension->PendingIrp == Irp)
|
|
|
|
|
{
|
|
|
|
|
ClassDeviceExtension->PendingIrp = NULL;
|
|
|
|
|
wasQueued = TRUE;
|
|
|
|
|
}
|
|
|
|
|
KeReleaseSpinLock(&ClassDeviceExtension->SpinLock, OldIrql);
|
|
|
|
|
|
|
|
|
|
if (wasQueued)
|
|
|
|
|
{
|
|
|
|
|
Irp->IoStatus.Status = STATUS_CANCELLED;
|
|
|
|
|
Irp->IoStatus.Information = 0;
|
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* Hm, this shouldn't happen */
|
|
|
|
|
ASSERT(FALSE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static NTSTATUS
|
|
|
|
|
HandleReadIrp(
|
|
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
|
IN PIRP Irp,
|
|
|
|
|
BOOLEAN IsInStartIo)
|
2005-10-31 00:14:45 +00:00
|
|
|
|
{
|
2005-11-05 08:37:01 +00:00
|
|
|
|
PCLASS_DEVICE_EXTENSION DeviceExtension = DeviceObject->DeviceExtension;
|
2007-11-02 12:36:50 +00:00
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
2008-07-25 20:24:46 +00:00
|
|
|
|
TRACE_(CLASS_NAME, "HandleReadIrp(DeviceObject %p, Irp %p)\n", DeviceObject, Irp);
|
2005-10-31 00:14:45 +00:00
|
|
|
|
|
|
|
|
|
ASSERT(DeviceExtension->Common.IsClassDO);
|
|
|
|
|
|
|
|
|
|
if (DeviceExtension->InputCount > 0)
|
|
|
|
|
{
|
2006-07-17 22:13:40 +00:00
|
|
|
|
SIZE_T NumberOfEntries;
|
|
|
|
|
|
|
|
|
|
NumberOfEntries = MIN(
|
|
|
|
|
DeviceExtension->InputCount,
|
|
|
|
|
IoGetCurrentIrpStackLocation(Irp)->Parameters.Read.Length / sizeof(MOUSE_INPUT_DATA));
|
2005-10-31 00:14:45 +00:00
|
|
|
|
|
2006-07-17 22:13:40 +00:00
|
|
|
|
Status = FillEntries(
|
2006-04-25 22:22:22 +00:00
|
|
|
|
DeviceObject,
|
|
|
|
|
Irp,
|
2006-07-17 22:13:40 +00:00
|
|
|
|
DeviceExtension->PortData,
|
|
|
|
|
NumberOfEntries);
|
2005-10-31 00:14:45 +00:00
|
|
|
|
|
2006-04-25 22:22:22 +00:00
|
|
|
|
if (NT_SUCCESS(Status))
|
2005-10-31 00:14:45 +00:00
|
|
|
|
{
|
2006-07-17 22:13:40 +00:00
|
|
|
|
if (DeviceExtension->InputCount > NumberOfEntries)
|
2006-04-25 22:22:22 +00:00
|
|
|
|
{
|
|
|
|
|
RtlMoveMemory(
|
2006-07-11 13:38:59 +00:00
|
|
|
|
&DeviceExtension->PortData[0],
|
2006-07-17 22:13:40 +00:00
|
|
|
|
&DeviceExtension->PortData[NumberOfEntries],
|
|
|
|
|
(DeviceExtension->InputCount - NumberOfEntries) * sizeof(MOUSE_INPUT_DATA));
|
2006-04-25 22:22:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-07-17 22:13:40 +00:00
|
|
|
|
DeviceExtension->InputCount -= NumberOfEntries;
|
2006-04-25 22:22:22 +00:00
|
|
|
|
|
2006-07-17 22:13:40 +00:00
|
|
|
|
Irp->IoStatus.Information = NumberOfEntries * sizeof(MOUSE_INPUT_DATA);
|
2005-10-31 00:14:45 +00:00
|
|
|
|
}
|
2006-04-25 22:22:22 +00:00
|
|
|
|
|
|
|
|
|
/* Go to next packet and complete this request */
|
|
|
|
|
Irp->IoStatus.Status = Status;
|
2005-10-31 00:14:45 +00:00
|
|
|
|
|
2007-11-02 12:36:50 +00:00
|
|
|
|
(VOID)IoSetCancelRoutine(Irp, NULL);
|
2007-07-06 17:14:24 +00:00
|
|
|
|
IoCompleteRequest(Irp, IO_MOUSE_INCREMENT);
|
2007-11-02 12:36:50 +00:00
|
|
|
|
DeviceExtension->PendingIrp = NULL;
|
2005-10-31 00:14:45 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2007-11-02 12:36:50 +00:00
|
|
|
|
(VOID)IoSetCancelRoutine(Irp, ClassCancelRoutine);
|
|
|
|
|
if (Irp->Cancel && IoSetCancelRoutine(Irp, NULL))
|
|
|
|
|
{
|
|
|
|
|
DeviceExtension->PendingIrp = NULL;
|
|
|
|
|
Status = STATUS_CANCELLED;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
IoMarkIrpPending(Irp);
|
|
|
|
|
DeviceExtension->PendingIrp = Irp;
|
|
|
|
|
Status = STATUS_PENDING;
|
|
|
|
|
}
|
2005-10-31 00:14:45 +00:00
|
|
|
|
}
|
2007-11-02 12:36:50 +00:00
|
|
|
|
return Status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static VOID NTAPI
|
|
|
|
|
ClassStartIo(
|
|
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
|
IN PIRP Irp)
|
|
|
|
|
{
|
|
|
|
|
PCLASS_DEVICE_EXTENSION DeviceExtension = DeviceObject->DeviceExtension;
|
|
|
|
|
KIRQL OldIrql;
|
|
|
|
|
|
2008-07-25 20:24:46 +00:00
|
|
|
|
TRACE_(CLASS_NAME, "ClassStartIo(DeviceObject %p, Irp %p)\n", DeviceObject, Irp);
|
2007-11-02 12:36:50 +00:00
|
|
|
|
|
|
|
|
|
ASSERT(DeviceExtension->Common.IsClassDO);
|
|
|
|
|
|
|
|
|
|
KeAcquireSpinLock(&DeviceExtension->SpinLock, &OldIrql);
|
|
|
|
|
HandleReadIrp(DeviceObject, Irp, TRUE);
|
|
|
|
|
KeReleaseSpinLock(&DeviceExtension->SpinLock, OldIrql);
|
2005-10-31 00:14:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-09-30 22:41:23 +00:00
|
|
|
|
static VOID NTAPI
|
2005-10-31 00:14:45 +00:00
|
|
|
|
SearchForLegacyDrivers(
|
2005-10-31 16:46:46 +00:00
|
|
|
|
IN PDRIVER_OBJECT DriverObject,
|
2006-09-30 22:41:23 +00:00
|
|
|
|
IN PVOID Context, /* PCLASS_DRIVER_EXTENSION */
|
|
|
|
|
IN ULONG Count)
|
2005-10-31 00:14:45 +00:00
|
|
|
|
{
|
2005-10-31 16:46:46 +00:00
|
|
|
|
UNICODE_STRING DeviceMapKeyU = RTL_CONSTANT_STRING(L"\\REGISTRY\\MACHINE\\HARDWARE\\DEVICEMAP");
|
2006-09-30 22:41:23 +00:00
|
|
|
|
PCLASS_DRIVER_EXTENSION DriverExtension;
|
2008-12-03 17:29:38 +00:00
|
|
|
|
UNICODE_STRING PortBaseName = { 0, 0, NULL };
|
2005-10-31 16:46:46 +00:00
|
|
|
|
PKEY_VALUE_BASIC_INFORMATION KeyValueInformation = NULL;
|
|
|
|
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
|
|
|
|
HANDLE hDeviceMapKey = (HANDLE)-1;
|
|
|
|
|
HANDLE hPortKey = (HANDLE)-1;
|
|
|
|
|
ULONG Index = 0;
|
|
|
|
|
ULONG Size, ResultLength;
|
2005-10-31 00:14:45 +00:00
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
2008-07-25 20:24:46 +00:00
|
|
|
|
TRACE_(CLASS_NAME, "SearchForLegacyDrivers(%p %p %lu)\n",
|
2006-09-30 22:41:23 +00:00
|
|
|
|
DriverObject, Context, Count);
|
|
|
|
|
|
|
|
|
|
if (Count != 1)
|
|
|
|
|
return;
|
|
|
|
|
DriverExtension = (PCLASS_DRIVER_EXTENSION)Context;
|
|
|
|
|
|
2005-10-31 16:46:46 +00:00
|
|
|
|
/* Create port base name, by replacing Class by Port at the end of the class base name */
|
2007-03-18 00:27:02 +00:00
|
|
|
|
Status = DuplicateUnicodeString(
|
2005-10-31 16:46:46 +00:00
|
|
|
|
RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE,
|
2005-11-05 08:37:01 +00:00
|
|
|
|
&DriverExtension->DeviceBaseName,
|
2005-10-31 16:46:46 +00:00
|
|
|
|
&PortBaseName);
|
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
|
{
|
2008-07-25 20:24:46 +00:00
|
|
|
|
WARN_(CLASS_NAME, "DuplicateUnicodeString() failed with status 0x%08lx\n", Status);
|
2005-10-31 16:46:46 +00:00
|
|
|
|
goto cleanup;
|
|
|
|
|
}
|
|
|
|
|
PortBaseName.Length -= (sizeof(L"Class") - sizeof(UNICODE_NULL));
|
|
|
|
|
RtlAppendUnicodeToString(&PortBaseName, L"Port");
|
2005-10-31 00:14:45 +00:00
|
|
|
|
|
2005-10-31 16:46:46 +00:00
|
|
|
|
/* Allocate memory */
|
|
|
|
|
Size = sizeof(KEY_VALUE_BASIC_INFORMATION) + MAX_PATH;
|
2007-06-04 09:25:04 +00:00
|
|
|
|
KeyValueInformation = ExAllocatePoolWithTag(PagedPool, Size, CLASS_TAG);
|
2005-10-31 16:46:46 +00:00
|
|
|
|
if (!KeyValueInformation)
|
2005-10-31 00:14:45 +00:00
|
|
|
|
{
|
2008-07-25 20:24:46 +00:00
|
|
|
|
WARN_(CLASS_NAME, "ExAllocatePoolWithTag() failed\n");
|
2007-06-04 09:25:04 +00:00
|
|
|
|
Status = STATUS_NO_MEMORY;
|
2005-10-31 16:46:46 +00:00
|
|
|
|
goto cleanup;
|
2005-10-31 00:14:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-10-31 16:46:46 +00:00
|
|
|
|
/* Open HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP */
|
|
|
|
|
InitializeObjectAttributes(&ObjectAttributes, &DeviceMapKeyU, OBJ_KERNEL_HANDLE | OBJ_CASE_INSENSITIVE, NULL, NULL);
|
|
|
|
|
Status = ZwOpenKey(&hDeviceMapKey, 0, &ObjectAttributes);
|
2005-11-05 08:37:01 +00:00
|
|
|
|
if (Status == STATUS_OBJECT_NAME_NOT_FOUND)
|
|
|
|
|
{
|
2008-07-25 20:24:46 +00:00
|
|
|
|
INFO_(CLASS_NAME, "HKLM\\HARDWARE\\DEVICEMAP is non-existent\n");
|
2005-11-05 08:37:01 +00:00
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
|
goto cleanup;
|
|
|
|
|
}
|
|
|
|
|
else if (!NT_SUCCESS(Status))
|
2005-10-31 00:14:45 +00:00
|
|
|
|
{
|
2008-07-25 20:24:46 +00:00
|
|
|
|
WARN_(CLASS_NAME, "ZwOpenKey() failed with status 0x%08lx\n", Status);
|
2005-10-31 16:46:46 +00:00
|
|
|
|
goto cleanup;
|
2005-10-31 00:14:45 +00:00
|
|
|
|
}
|
2005-10-31 16:46:46 +00:00
|
|
|
|
|
|
|
|
|
/* Open sub key */
|
|
|
|
|
InitializeObjectAttributes(&ObjectAttributes, &PortBaseName, OBJ_KERNEL_HANDLE | OBJ_CASE_INSENSITIVE, hDeviceMapKey, NULL);
|
|
|
|
|
Status = ZwOpenKey(&hPortKey, KEY_QUERY_VALUE, &ObjectAttributes);
|
2005-11-05 08:37:01 +00:00
|
|
|
|
if (Status == STATUS_OBJECT_NAME_NOT_FOUND)
|
|
|
|
|
{
|
2008-07-25 20:24:46 +00:00
|
|
|
|
INFO_(CLASS_NAME, "HKLM\\HARDWARE\\DEVICEMAP\\%wZ is non-existent\n", &PortBaseName);
|
2005-11-05 08:37:01 +00:00
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
|
goto cleanup;
|
|
|
|
|
}
|
|
|
|
|
else if (!NT_SUCCESS(Status))
|
2005-10-31 00:14:45 +00:00
|
|
|
|
{
|
2008-07-25 20:24:46 +00:00
|
|
|
|
WARN_(CLASS_NAME, "ZwOpenKey() failed with status 0x%08lx\n", Status);
|
2005-10-31 16:46:46 +00:00
|
|
|
|
goto cleanup;
|
2005-10-31 00:14:45 +00:00
|
|
|
|
}
|
2005-10-31 16:46:46 +00:00
|
|
|
|
|
|
|
|
|
/* Read each value name */
|
|
|
|
|
while (ZwEnumerateValueKey(hPortKey, Index++, KeyValueBasicInformation, KeyValueInformation, Size, &ResultLength) == STATUS_SUCCESS)
|
|
|
|
|
{
|
|
|
|
|
UNICODE_STRING PortName;
|
|
|
|
|
PDEVICE_OBJECT PortDeviceObject = NULL;
|
|
|
|
|
PFILE_OBJECT FileObject = NULL;
|
|
|
|
|
|
2007-03-18 00:27:02 +00:00
|
|
|
|
PortName.Length = PortName.MaximumLength = (USHORT)KeyValueInformation->NameLength;
|
2005-10-31 16:46:46 +00:00
|
|
|
|
PortName.Buffer = KeyValueInformation->Name;
|
|
|
|
|
|
|
|
|
|
/* Open the device object pointer */
|
|
|
|
|
Status = IoGetDeviceObjectPointer(&PortName, FILE_READ_ATTRIBUTES, &FileObject, &PortDeviceObject);
|
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
|
{
|
2008-07-25 20:24:46 +00:00
|
|
|
|
WARN_(CLASS_NAME, "IoGetDeviceObjectPointer(%wZ) failed with status 0x%08lx\n", &PortName, Status);
|
2006-02-24 13:38:14 +00:00
|
|
|
|
continue;
|
2005-10-31 16:46:46 +00:00
|
|
|
|
}
|
2008-07-25 20:24:46 +00:00
|
|
|
|
INFO_(CLASS_NAME, "Legacy driver found\n");
|
2005-10-31 16:46:46 +00:00
|
|
|
|
|
2006-02-24 13:38:14 +00:00
|
|
|
|
Status = ClassAddDevice(DriverObject, PortDeviceObject);
|
|
|
|
|
if (!NT_SUCCESS(Status))
|
2005-10-31 16:46:46 +00:00
|
|
|
|
{
|
2006-02-24 13:38:14 +00:00
|
|
|
|
/* FIXME: Log the error */
|
2008-07-25 20:24:46 +00:00
|
|
|
|
WARN_(CLASS_NAME, "ClassAddDevice() failed with status 0x%08lx\n", Status);
|
2005-10-31 16:46:46 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
|
if (KeyValueInformation != NULL)
|
2007-06-04 09:25:04 +00:00
|
|
|
|
ExFreePoolWithTag(KeyValueInformation, CLASS_TAG);
|
2005-10-31 16:46:46 +00:00
|
|
|
|
if (hDeviceMapKey != (HANDLE)-1)
|
|
|
|
|
ZwClose(hDeviceMapKey);
|
|
|
|
|
if (hPortKey != (HANDLE)-1)
|
|
|
|
|
ZwClose(hPortKey);
|
2005-10-31 00:14:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Standard DriverEntry method.
|
|
|
|
|
*/
|
|
|
|
|
NTSTATUS NTAPI
|
|
|
|
|
DriverEntry(
|
|
|
|
|
IN PDRIVER_OBJECT DriverObject,
|
|
|
|
|
IN PUNICODE_STRING RegistryPath)
|
2000-10-18 09:11:01 +00:00
|
|
|
|
{
|
2005-11-05 08:37:01 +00:00
|
|
|
|
PCLASS_DRIVER_EXTENSION DriverExtension;
|
2005-10-31 00:14:45 +00:00
|
|
|
|
ULONG i;
|
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
|
|
|
|
Status = IoAllocateDriverObjectExtension(
|
|
|
|
|
DriverObject,
|
|
|
|
|
DriverObject,
|
2005-11-05 08:37:01 +00:00
|
|
|
|
sizeof(CLASS_DRIVER_EXTENSION),
|
2005-10-31 00:14:45 +00:00
|
|
|
|
(PVOID*)&DriverExtension);
|
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
|
{
|
2008-07-25 20:24:46 +00:00
|
|
|
|
WARN_(CLASS_NAME, "IoAllocateDriverObjectExtension() failed with status 0x%08lx\n", Status);
|
2005-10-31 00:14:45 +00:00
|
|
|
|
return Status;
|
|
|
|
|
}
|
2005-11-05 08:37:01 +00:00
|
|
|
|
RtlZeroMemory(DriverExtension, sizeof(CLASS_DRIVER_EXTENSION));
|
2005-10-31 00:14:45 +00:00
|
|
|
|
|
2007-03-18 00:27:02 +00:00
|
|
|
|
Status = DuplicateUnicodeString(
|
2005-11-09 11:16:43 +00:00
|
|
|
|
RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE,
|
|
|
|
|
RegistryPath,
|
|
|
|
|
&DriverExtension->RegistryPath);
|
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
|
{
|
2008-07-25 20:24:46 +00:00
|
|
|
|
WARN_(CLASS_NAME, "DuplicateUnicodeString() failed with status 0x%08lx\n", Status);
|
2005-11-09 11:16:43 +00:00
|
|
|
|
return Status;
|
|
|
|
|
}
|
|
|
|
|
|
2005-10-31 00:14:45 +00:00
|
|
|
|
Status = ReadRegistryEntries(RegistryPath, DriverExtension);
|
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
|
{
|
2008-07-25 20:24:46 +00:00
|
|
|
|
WARN_(CLASS_NAME, "ReadRegistryEntries() failed with status 0x%08lx\n", Status);
|
2005-10-31 00:14:45 +00:00
|
|
|
|
return Status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (DriverExtension->ConnectMultiplePorts == 1)
|
|
|
|
|
{
|
2005-11-05 08:37:01 +00:00
|
|
|
|
Status = CreateClassDeviceObject(
|
2005-10-31 00:14:45 +00:00
|
|
|
|
DriverObject,
|
2005-11-05 08:37:01 +00:00
|
|
|
|
&DriverExtension->MainClassDeviceObject);
|
2005-10-31 00:14:45 +00:00
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
|
{
|
2008-07-25 20:24:46 +00:00
|
|
|
|
WARN_(CLASS_NAME, "CreateClassDeviceObject() failed with status 0x%08lx\n", Status);
|
2005-10-31 00:14:45 +00:00
|
|
|
|
return Status;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-11-05 08:37:01 +00:00
|
|
|
|
DriverObject->DriverExtension->AddDevice = ClassAddDevice;
|
2005-10-31 00:14:45 +00:00
|
|
|
|
DriverObject->DriverUnload = DriverUnload;
|
|
|
|
|
|
2005-12-18 20:50:26 +00:00
|
|
|
|
for (i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++)
|
2005-10-31 00:14:45 +00:00
|
|
|
|
DriverObject->MajorFunction[i] = IrpStub;
|
|
|
|
|
|
2005-11-05 08:37:01 +00:00
|
|
|
|
DriverObject->MajorFunction[IRP_MJ_CREATE] = ClassCreate;
|
|
|
|
|
DriverObject->MajorFunction[IRP_MJ_CLOSE] = ClassClose;
|
|
|
|
|
DriverObject->MajorFunction[IRP_MJ_CLEANUP] = ClassCleanup;
|
|
|
|
|
DriverObject->MajorFunction[IRP_MJ_READ] = ClassRead;
|
|
|
|
|
DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = ClassDeviceControl;
|
2006-02-24 13:38:14 +00:00
|
|
|
|
DriverObject->MajorFunction[IRP_MJ_INTERNAL_DEVICE_CONTROL] = ForwardIrpAndForget;
|
2005-11-05 08:37:01 +00:00
|
|
|
|
DriverObject->DriverStartIo = ClassStartIo;
|
2005-10-31 00:14:45 +00:00
|
|
|
|
|
2006-09-30 22:41:23 +00:00
|
|
|
|
/* We will detect the legacy devices later */
|
|
|
|
|
IoRegisterDriverReinitialization(
|
|
|
|
|
DriverObject,
|
|
|
|
|
SearchForLegacyDrivers,
|
|
|
|
|
DriverExtension);
|
|
|
|
|
|
2005-11-09 11:16:43 +00:00
|
|
|
|
return STATUS_SUCCESS;
|
2000-10-18 09:11:01 +00:00
|
|
|
|
}
|