2011-12-25 20:21:34 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS Universal Serial Bus Human Interface Device Driver
|
|
|
|
* LICENSE: GPL - See COPYING in the top level directory
|
|
|
|
* FILE: drivers/hid/hidclass/hidclass.c
|
|
|
|
* PURPOSE: HID Class Driver
|
|
|
|
* PROGRAMMERS:
|
|
|
|
* Michael Martin (michael.martin@reactos.org)
|
|
|
|
* Johannes Anderwald (johannes.anderwald@reactos.org)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "precomp.h"
|
|
|
|
|
2014-01-03 10:56:03 +00:00
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
|
|
|
|
2011-12-25 20:21:34 +00:00
|
|
|
static LPWSTR ClientIdentificationAddress = L"HIDCLASS";
|
2011-12-25 23:07:50 +00:00
|
|
|
static ULONG HidClassDeviceNumber = 0;
|
2011-12-25 20:21:34 +00:00
|
|
|
|
2013-05-12 15:31:01 +00:00
|
|
|
NTSTATUS
|
2011-12-25 20:21:34 +00:00
|
|
|
NTAPI
|
2013-05-12 15:31:01 +00:00
|
|
|
DllInitialize(
|
|
|
|
IN PUNICODE_STRING RegistryPath)
|
2011-12-25 20:21:34 +00:00
|
|
|
{
|
2013-05-12 15:31:01 +00:00
|
|
|
return STATUS_SUCCESS;
|
2011-12-25 20:21:34 +00:00
|
|
|
}
|
|
|
|
|
2013-05-12 15:31:01 +00:00
|
|
|
NTSTATUS
|
2011-12-25 20:21:34 +00:00
|
|
|
NTAPI
|
2013-05-12 15:31:01 +00:00
|
|
|
DllUnload(VOID)
|
2011-12-25 20:21:34 +00:00
|
|
|
{
|
2013-05-12 15:31:01 +00:00
|
|
|
return STATUS_SUCCESS;
|
2011-12-25 20:21:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
HidClassAddDevice(
|
|
|
|
IN PDRIVER_OBJECT DriverObject,
|
|
|
|
IN PDEVICE_OBJECT PhysicalDeviceObject)
|
|
|
|
{
|
2011-12-25 23:07:50 +00:00
|
|
|
WCHAR CharDeviceName[64];
|
|
|
|
NTSTATUS Status;
|
|
|
|
UNICODE_STRING DeviceName;
|
|
|
|
PDEVICE_OBJECT NewDeviceObject;
|
2011-12-30 14:34:07 +00:00
|
|
|
PHIDCLASS_FDO_EXTENSION FDODeviceExtension;
|
2011-12-25 23:07:50 +00:00
|
|
|
ULONG DeviceExtensionSize;
|
|
|
|
PHIDCLASS_DRIVER_EXTENSION DriverExtension;
|
|
|
|
|
|
|
|
/* increment device number */
|
|
|
|
InterlockedIncrement((PLONG)&HidClassDeviceNumber);
|
|
|
|
|
|
|
|
/* construct device name */
|
|
|
|
swprintf(CharDeviceName, L"\\Device\\_HID%08x", HidClassDeviceNumber);
|
|
|
|
|
|
|
|
/* initialize device name */
|
|
|
|
RtlInitUnicodeString(&DeviceName, CharDeviceName);
|
|
|
|
|
|
|
|
/* get driver object extension */
|
2013-05-12 15:31:01 +00:00
|
|
|
DriverExtension = IoGetDriverObjectExtension(DriverObject, ClientIdentificationAddress);
|
2011-12-25 23:07:50 +00:00
|
|
|
if (!DriverExtension)
|
|
|
|
{
|
|
|
|
/* device removed */
|
|
|
|
ASSERT(FALSE);
|
|
|
|
return STATUS_DEVICE_CONFIGURATION_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* calculate device extension size */
|
2011-12-30 14:34:07 +00:00
|
|
|
DeviceExtensionSize = sizeof(HIDCLASS_FDO_EXTENSION) + DriverExtension->DeviceExtensionSize;
|
2011-12-25 23:07:50 +00:00
|
|
|
|
|
|
|
/* now create the device */
|
|
|
|
Status = IoCreateDevice(DriverObject, DeviceExtensionSize, &DeviceName, FILE_DEVICE_UNKNOWN, 0, FALSE, &NewDeviceObject);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
/* failed to create device object */
|
|
|
|
ASSERT(FALSE);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get device extension */
|
2013-05-12 15:31:01 +00:00
|
|
|
FDODeviceExtension = NewDeviceObject->DeviceExtension;
|
2011-12-25 23:07:50 +00:00
|
|
|
|
|
|
|
/* zero device extension */
|
2011-12-30 14:34:07 +00:00
|
|
|
RtlZeroMemory(FDODeviceExtension, sizeof(HIDCLASS_FDO_EXTENSION));
|
2011-12-25 23:07:50 +00:00
|
|
|
|
|
|
|
/* initialize device extension */
|
2012-02-05 15:36:00 +00:00
|
|
|
FDODeviceExtension->Common.IsFDO = TRUE;
|
|
|
|
FDODeviceExtension->Common.DriverExtension = DriverExtension;
|
2011-12-30 14:34:07 +00:00
|
|
|
FDODeviceExtension->Common.HidDeviceExtension.PhysicalDeviceObject = PhysicalDeviceObject;
|
|
|
|
FDODeviceExtension->Common.HidDeviceExtension.MiniDeviceExtension = (PVOID)((ULONG_PTR)FDODeviceExtension + sizeof(HIDCLASS_FDO_EXTENSION));
|
|
|
|
FDODeviceExtension->Common.HidDeviceExtension.NextDeviceObject = IoAttachDeviceToDeviceStack(NewDeviceObject, PhysicalDeviceObject);
|
2012-02-05 15:36:00 +00:00
|
|
|
if (FDODeviceExtension->Common.HidDeviceExtension.NextDeviceObject == NULL)
|
|
|
|
{
|
|
|
|
/* no PDO */
|
|
|
|
IoDeleteDevice(NewDeviceObject);
|
|
|
|
DPRINT1("[HIDCLASS] failed to attach to device stack\n");
|
|
|
|
return STATUS_DEVICE_REMOVED;
|
|
|
|
}
|
2011-12-25 23:07:50 +00:00
|
|
|
|
|
|
|
/* sanity check */
|
2011-12-30 14:34:07 +00:00
|
|
|
ASSERT(FDODeviceExtension->Common.HidDeviceExtension.NextDeviceObject);
|
2011-12-25 23:07:50 +00:00
|
|
|
|
|
|
|
/* increment stack size */
|
|
|
|
NewDeviceObject->StackSize++;
|
|
|
|
|
|
|
|
/* init device object */
|
|
|
|
NewDeviceObject->Flags |= DO_BUFFERED_IO | DO_POWER_PAGABLE;
|
|
|
|
NewDeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
|
|
|
|
|
|
|
|
/* now call driver provided add device routine */
|
|
|
|
ASSERT(DriverExtension->AddDevice != 0);
|
|
|
|
Status = DriverExtension->AddDevice(DriverObject, NewDeviceObject);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
/* failed */
|
|
|
|
DPRINT1("HIDCLASS: AddDevice failed with %x\n", Status);
|
2011-12-30 14:34:07 +00:00
|
|
|
IoDetachDevice(FDODeviceExtension->Common.HidDeviceExtension.NextDeviceObject);
|
2011-12-25 23:07:50 +00:00
|
|
|
IoDeleteDevice(NewDeviceObject);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* succeeded */
|
|
|
|
return Status;
|
2011-12-25 20:21:34 +00:00
|
|
|
}
|
|
|
|
|
2011-12-26 03:37:22 +00:00
|
|
|
VOID
|
2011-12-25 20:21:34 +00:00
|
|
|
NTAPI
|
|
|
|
HidClassDriverUnload(
|
|
|
|
IN PDRIVER_OBJECT DriverObject)
|
|
|
|
{
|
2017-02-06 15:49:23 +00:00
|
|
|
UNIMPLEMENTED;
|
2011-12-25 20:21:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
2011-12-30 14:34:07 +00:00
|
|
|
HidClass_Create(
|
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp)
|
|
|
|
{
|
2011-12-31 19:09:26 +00:00
|
|
|
PIO_STACK_LOCATION IoStack;
|
|
|
|
PHIDCLASS_COMMON_DEVICE_EXTENSION CommonDeviceExtension;
|
|
|
|
PHIDCLASS_PDO_DEVICE_EXTENSION PDODeviceExtension;
|
|
|
|
PHIDCLASS_FILEOP_CONTEXT Context;
|
|
|
|
|
|
|
|
//
|
|
|
|
// get device extension
|
|
|
|
//
|
2013-05-12 15:31:01 +00:00
|
|
|
CommonDeviceExtension = DeviceObject->DeviceExtension;
|
2011-12-31 19:09:26 +00:00
|
|
|
if (CommonDeviceExtension->IsFDO)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// only supported for PDO
|
|
|
|
//
|
|
|
|
Irp->IoStatus.Status = STATUS_UNSUCCESSFUL;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
return STATUS_UNSUCCESSFUL;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// must be a PDO
|
|
|
|
//
|
|
|
|
ASSERT(CommonDeviceExtension->IsFDO == FALSE);
|
|
|
|
|
|
|
|
//
|
|
|
|
// get device extension
|
|
|
|
//
|
2013-05-12 15:31:01 +00:00
|
|
|
PDODeviceExtension = DeviceObject->DeviceExtension;
|
2011-12-31 19:09:26 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// get stack location
|
|
|
|
//
|
|
|
|
IoStack = IoGetCurrentIrpStackLocation(Irp);
|
|
|
|
|
2012-02-12 02:53:34 +00:00
|
|
|
DPRINT("ShareAccess %x\n", IoStack->Parameters.Create.ShareAccess);
|
|
|
|
DPRINT("Options %x\n", IoStack->Parameters.Create.Options);
|
|
|
|
DPRINT("DesiredAccess %x\n", IoStack->Parameters.Create.SecurityContext->DesiredAccess);
|
2011-12-31 19:09:26 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// allocate context
|
|
|
|
//
|
2013-05-12 15:44:58 +00:00
|
|
|
Context = ExAllocatePoolWithTag(NonPagedPool, sizeof(HIDCLASS_FILEOP_CONTEXT), HIDCLASS_TAG);
|
2011-12-31 19:09:26 +00:00
|
|
|
if (!Context)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// no memory
|
|
|
|
//
|
|
|
|
Irp->IoStatus.Status = STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// init context
|
|
|
|
//
|
|
|
|
RtlZeroMemory(Context, sizeof(HIDCLASS_FILEOP_CONTEXT));
|
|
|
|
Context->DeviceExtension = PDODeviceExtension;
|
|
|
|
KeInitializeSpinLock(&Context->Lock);
|
|
|
|
InitializeListHead(&Context->ReadPendingIrpListHead);
|
|
|
|
InitializeListHead(&Context->IrpCompletedListHead);
|
2012-02-21 01:16:56 +00:00
|
|
|
KeInitializeEvent(&Context->IrpReadComplete, NotificationEvent, FALSE);
|
2011-12-31 19:09:26 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// store context
|
|
|
|
//
|
|
|
|
ASSERT(IoStack->FileObject);
|
2013-05-12 15:31:01 +00:00
|
|
|
IoStack->FileObject->FsContext = Context;
|
2011-12-31 19:09:26 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// done
|
|
|
|
//
|
|
|
|
Irp->IoStatus.Status = STATUS_SUCCESS;
|
2011-12-31 04:13:37 +00:00
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
2011-12-31 19:09:26 +00:00
|
|
|
return STATUS_SUCCESS;
|
2011-12-30 14:34:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
HidClass_Close(
|
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp)
|
|
|
|
{
|
2011-12-31 19:09:26 +00:00
|
|
|
PIO_STACK_LOCATION IoStack;
|
|
|
|
PHIDCLASS_COMMON_DEVICE_EXTENSION CommonDeviceExtension;
|
2012-02-21 01:16:56 +00:00
|
|
|
PHIDCLASS_FILEOP_CONTEXT IrpContext;
|
|
|
|
BOOLEAN IsRequestPending = FALSE;
|
|
|
|
KIRQL OldLevel;
|
|
|
|
PLIST_ENTRY Entry;
|
|
|
|
PIRP ListIrp;
|
2011-12-31 19:09:26 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// get device extension
|
|
|
|
//
|
2013-05-12 15:31:01 +00:00
|
|
|
CommonDeviceExtension = DeviceObject->DeviceExtension;
|
2011-12-31 19:09:26 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// is it a FDO request
|
|
|
|
//
|
|
|
|
if (CommonDeviceExtension->IsFDO)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// how did the request get there
|
|
|
|
//
|
|
|
|
Irp->IoStatus.Status = STATUS_INVALID_PARAMETER_1;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
return STATUS_INVALID_PARAMETER_1;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// get stack location
|
|
|
|
//
|
|
|
|
IoStack = IoGetCurrentIrpStackLocation(Irp);
|
|
|
|
|
|
|
|
//
|
|
|
|
// sanity checks
|
|
|
|
//
|
|
|
|
ASSERT(IoStack->FileObject);
|
|
|
|
ASSERT(IoStack->FileObject->FsContext);
|
|
|
|
|
|
|
|
//
|
|
|
|
// get irp context
|
|
|
|
//
|
2013-05-12 15:31:01 +00:00
|
|
|
IrpContext = IoStack->FileObject->FsContext;
|
2012-02-21 01:16:56 +00:00
|
|
|
ASSERT(IrpContext);
|
2011-12-31 19:09:26 +00:00
|
|
|
|
|
|
|
//
|
2012-02-21 01:16:56 +00:00
|
|
|
// acquire lock
|
2011-12-31 19:09:26 +00:00
|
|
|
//
|
2012-02-21 01:16:56 +00:00
|
|
|
KeAcquireSpinLock(&IrpContext->Lock, &OldLevel);
|
|
|
|
|
|
|
|
if (!IsListEmpty(&IrpContext->ReadPendingIrpListHead))
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// FIXME cancel irp
|
|
|
|
//
|
|
|
|
IsRequestPending = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// signal stop
|
|
|
|
//
|
|
|
|
IrpContext->StopInProgress = TRUE;
|
|
|
|
|
|
|
|
//
|
|
|
|
// release lock
|
|
|
|
//
|
|
|
|
KeReleaseSpinLock(&IrpContext->Lock, OldLevel);
|
|
|
|
|
|
|
|
if (IsRequestPending)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// wait for request to complete
|
|
|
|
//
|
|
|
|
DPRINT1("[HIDCLASS] Waiting for read irp completion...\n");
|
|
|
|
KeWaitForSingleObject(&IrpContext->IrpReadComplete, Executive, KernelMode, FALSE, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// acquire lock
|
|
|
|
//
|
|
|
|
KeAcquireSpinLock(&IrpContext->Lock, &OldLevel);
|
|
|
|
|
|
|
|
//
|
|
|
|
// sanity check
|
|
|
|
//
|
|
|
|
ASSERT(IsListEmpty(&IrpContext->ReadPendingIrpListHead));
|
|
|
|
|
|
|
|
//
|
|
|
|
// now free all irps
|
|
|
|
//
|
2013-05-12 15:23:34 +00:00
|
|
|
while (!IsListEmpty(&IrpContext->IrpCompletedListHead))
|
2012-02-21 01:16:56 +00:00
|
|
|
{
|
|
|
|
//
|
|
|
|
// remove head irp
|
|
|
|
//
|
|
|
|
Entry = RemoveHeadList(&IrpContext->IrpCompletedListHead);
|
|
|
|
|
|
|
|
//
|
|
|
|
// get irp
|
|
|
|
//
|
2013-05-12 15:31:01 +00:00
|
|
|
ListIrp = CONTAINING_RECORD(Entry, IRP, Tail.Overlay.ListEntry);
|
2012-02-21 01:16:56 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// free the irp
|
|
|
|
//
|
|
|
|
IoFreeIrp(ListIrp);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// release lock
|
|
|
|
//
|
|
|
|
KeReleaseSpinLock(&IrpContext->Lock, OldLevel);
|
|
|
|
|
2011-12-31 19:09:26 +00:00
|
|
|
//
|
|
|
|
// remove context
|
|
|
|
//
|
|
|
|
IoStack->FileObject->FsContext = NULL;
|
|
|
|
|
|
|
|
//
|
|
|
|
// free context
|
|
|
|
//
|
2013-05-12 15:44:58 +00:00
|
|
|
ExFreePoolWithTag(IrpContext, HIDCLASS_TAG);
|
2011-12-31 19:09:26 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// complete request
|
|
|
|
//
|
|
|
|
Irp->IoStatus.Status = STATUS_SUCCESS;
|
2011-12-31 04:13:37 +00:00
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
2011-12-31 19:09:26 +00:00
|
|
|
return STATUS_SUCCESS;
|
2011-12-30 14:34:07 +00:00
|
|
|
}
|
|
|
|
|
2011-12-31 19:09:26 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
HidClass_ReadCompleteIrp(
|
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp,
|
|
|
|
IN PVOID Ctx)
|
|
|
|
{
|
|
|
|
PHIDCLASS_IRP_CONTEXT IrpContext;
|
|
|
|
KIRQL OldLevel;
|
2012-01-01 22:48:08 +00:00
|
|
|
PUCHAR Address;
|
|
|
|
ULONG Offset;
|
2012-01-02 12:00:51 +00:00
|
|
|
PHIDP_COLLECTION_DESC CollectionDescription;
|
|
|
|
PHIDP_REPORT_IDS ReportDescription;
|
2012-02-21 01:16:56 +00:00
|
|
|
BOOLEAN IsEmpty;
|
2011-12-31 19:09:26 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// get irp context
|
|
|
|
//
|
2013-05-12 15:31:01 +00:00
|
|
|
IrpContext = Ctx;
|
2011-12-31 19:09:26 +00:00
|
|
|
|
2012-02-23 00:34:36 +00:00
|
|
|
DPRINT("HidClass_ReadCompleteIrp Irql %lu\n", KeGetCurrentIrql());
|
|
|
|
DPRINT("HidClass_ReadCompleteIrp Status %lx\n", Irp->IoStatus.Status);
|
|
|
|
DPRINT("HidClass_ReadCompleteIrp Length %lu\n", Irp->IoStatus.Information);
|
|
|
|
DPRINT("HidClass_ReadCompleteIrp Irp %p\n", Irp);
|
|
|
|
DPRINT("HidClass_ReadCompleteIrp InputReportBuffer %p\n", IrpContext->InputReportBuffer);
|
|
|
|
DPRINT("HidClass_ReadCompleteIrp InputReportBufferLength %li\n", IrpContext->InputReportBufferLength);
|
|
|
|
DPRINT("HidClass_ReadCompleteIrp OriginalIrp %p\n", IrpContext->OriginalIrp);
|
2011-12-31 19:09:26 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// copy result
|
|
|
|
//
|
|
|
|
if (Irp->IoStatus.Information)
|
|
|
|
{
|
|
|
|
//
|
2012-01-01 22:48:08 +00:00
|
|
|
// get address
|
2011-12-31 19:09:26 +00:00
|
|
|
//
|
2013-05-12 17:16:41 +00:00
|
|
|
Address = MmGetSystemAddressForMdlSafe(IrpContext->OriginalIrp->MdlAddress, NormalPagePriority);
|
2012-01-01 22:48:08 +00:00
|
|
|
if (Address)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// reports may have a report id prepended
|
|
|
|
//
|
2012-01-02 12:00:51 +00:00
|
|
|
Offset = 0;
|
2012-01-01 22:48:08 +00:00
|
|
|
|
|
|
|
//
|
2012-01-02 12:00:51 +00:00
|
|
|
// get collection description
|
2012-01-01 22:48:08 +00:00
|
|
|
//
|
2013-05-12 15:23:34 +00:00
|
|
|
CollectionDescription = HidClassPDO_GetCollectionDescription(&IrpContext->FileOp->DeviceExtension->Common.DeviceDescription,
|
|
|
|
IrpContext->FileOp->DeviceExtension->CollectionNumber);
|
2012-01-02 12:00:51 +00:00
|
|
|
ASSERT(CollectionDescription);
|
|
|
|
|
|
|
|
//
|
|
|
|
// get report description
|
|
|
|
//
|
2013-05-12 15:23:34 +00:00
|
|
|
ReportDescription = HidClassPDO_GetReportDescription(&IrpContext->FileOp->DeviceExtension->Common.DeviceDescription,
|
|
|
|
IrpContext->FileOp->DeviceExtension->CollectionNumber);
|
2012-01-02 12:00:51 +00:00
|
|
|
ASSERT(ReportDescription);
|
|
|
|
|
|
|
|
if (CollectionDescription && ReportDescription)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// calculate offset
|
|
|
|
//
|
|
|
|
ASSERT(CollectionDescription->InputLength >= ReportDescription->InputLength);
|
|
|
|
Offset = CollectionDescription->InputLength - ReportDescription->InputLength;
|
|
|
|
}
|
2012-01-01 22:48:08 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// copy result
|
|
|
|
//
|
|
|
|
RtlCopyMemory(&Address[Offset], IrpContext->InputReportBuffer, IrpContext->InputReportBufferLength);
|
|
|
|
}
|
2011-12-31 19:09:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// copy result status
|
|
|
|
//
|
|
|
|
IrpContext->OriginalIrp->IoStatus.Status = Irp->IoStatus.Status;
|
2013-05-05 14:51:27 +00:00
|
|
|
IrpContext->OriginalIrp->IoStatus.Information = Irp->IoStatus.Information;
|
2011-12-31 19:09:26 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// free input report buffer
|
|
|
|
//
|
2013-05-12 15:44:58 +00:00
|
|
|
ExFreePoolWithTag(IrpContext->InputReportBuffer, HIDCLASS_TAG);
|
2011-12-31 19:09:26 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// remove us from pending list
|
|
|
|
//
|
|
|
|
KeAcquireSpinLock(&IrpContext->FileOp->Lock, &OldLevel);
|
|
|
|
|
|
|
|
//
|
|
|
|
// remove from pending list
|
|
|
|
//
|
|
|
|
RemoveEntryList(&Irp->Tail.Overlay.ListEntry);
|
|
|
|
|
2012-02-21 01:16:56 +00:00
|
|
|
//
|
|
|
|
// is list empty
|
|
|
|
//
|
|
|
|
IsEmpty = IsListEmpty(&IrpContext->FileOp->ReadPendingIrpListHead);
|
|
|
|
|
2012-01-01 22:48:08 +00:00
|
|
|
//
|
|
|
|
// insert into completed list
|
|
|
|
//
|
|
|
|
InsertTailList(&IrpContext->FileOp->IrpCompletedListHead, &Irp->Tail.Overlay.ListEntry);
|
|
|
|
|
2011-12-31 19:09:26 +00:00
|
|
|
//
|
|
|
|
// release lock
|
|
|
|
//
|
|
|
|
KeReleaseSpinLock(&IrpContext->FileOp->Lock, OldLevel);
|
|
|
|
|
2012-01-01 22:48:08 +00:00
|
|
|
//
|
|
|
|
// complete original request
|
|
|
|
//
|
|
|
|
IoCompleteRequest(IrpContext->OriginalIrp, IO_NO_INCREMENT);
|
|
|
|
|
2012-02-21 01:16:56 +00:00
|
|
|
|
2012-02-23 01:51:55 +00:00
|
|
|
DPRINT("StopInProgress %x IsEmpty %x\n", IrpContext->FileOp->StopInProgress, IsEmpty);
|
2012-02-21 01:16:56 +00:00
|
|
|
if (IrpContext->FileOp->StopInProgress && IsEmpty)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// last pending irp
|
|
|
|
//
|
|
|
|
DPRINT1("[HIDCLASS] LastPendingTransfer Signalling\n");
|
|
|
|
KeSetEvent(&IrpContext->FileOp->IrpReadComplete, 0, FALSE);
|
|
|
|
}
|
|
|
|
|
2012-02-23 00:34:36 +00:00
|
|
|
if (IrpContext->FileOp->StopInProgress && IsEmpty)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// last pending irp
|
|
|
|
//
|
|
|
|
DPRINT1("[HIDCLASS] LastPendingTransfer Signalling\n");
|
|
|
|
KeSetEvent(&IrpContext->FileOp->IrpReadComplete, 0, FALSE);
|
|
|
|
}
|
|
|
|
|
2011-12-31 19:09:26 +00:00
|
|
|
//
|
|
|
|
// free irp context
|
|
|
|
//
|
2013-05-12 15:44:58 +00:00
|
|
|
ExFreePoolWithTag(IrpContext, HIDCLASS_TAG);
|
2011-12-31 19:09:26 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// done
|
|
|
|
//
|
2012-01-01 22:48:08 +00:00
|
|
|
return STATUS_MORE_PROCESSING_REQUIRED;
|
|
|
|
}
|
|
|
|
|
|
|
|
PIRP
|
|
|
|
HidClass_GetIrp(
|
|
|
|
IN PHIDCLASS_FILEOP_CONTEXT Context)
|
|
|
|
{
|
|
|
|
KIRQL OldLevel;
|
|
|
|
PIRP Irp = NULL;
|
|
|
|
PLIST_ENTRY ListEntry;
|
|
|
|
|
|
|
|
//
|
|
|
|
// acquire lock
|
|
|
|
//
|
|
|
|
KeAcquireSpinLock(&Context->Lock, &OldLevel);
|
|
|
|
|
|
|
|
//
|
|
|
|
// is list empty?
|
|
|
|
//
|
|
|
|
if (!IsListEmpty(&Context->IrpCompletedListHead))
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// grab first entry
|
|
|
|
//
|
|
|
|
ListEntry = RemoveHeadList(&Context->IrpCompletedListHead);
|
|
|
|
|
|
|
|
//
|
|
|
|
// get irp
|
|
|
|
//
|
2013-05-12 15:31:01 +00:00
|
|
|
Irp = CONTAINING_RECORD(ListEntry, IRP, Tail.Overlay.ListEntry);
|
2012-01-01 22:48:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// release lock
|
|
|
|
//
|
|
|
|
KeReleaseSpinLock(&Context->Lock, OldLevel);
|
|
|
|
|
|
|
|
//
|
|
|
|
// done
|
|
|
|
//
|
|
|
|
return Irp;
|
2011-12-31 19:09:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
HidClass_BuildIrp(
|
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP RequestIrp,
|
|
|
|
IN PHIDCLASS_FILEOP_CONTEXT Context,
|
|
|
|
IN ULONG DeviceIoControlCode,
|
|
|
|
IN ULONG BufferLength,
|
|
|
|
OUT PIRP *OutIrp,
|
|
|
|
OUT PHIDCLASS_IRP_CONTEXT *OutIrpContext)
|
|
|
|
{
|
|
|
|
PIRP Irp;
|
|
|
|
PIO_STACK_LOCATION IoStack;
|
|
|
|
PHIDCLASS_IRP_CONTEXT IrpContext;
|
2012-01-01 22:48:08 +00:00
|
|
|
PHIDCLASS_PDO_DEVICE_EXTENSION PDODeviceExtension;
|
2012-01-02 12:00:51 +00:00
|
|
|
PHIDP_COLLECTION_DESC CollectionDescription;
|
|
|
|
PHIDP_REPORT_IDS ReportDescription;
|
2011-12-31 19:09:26 +00:00
|
|
|
|
|
|
|
//
|
2012-01-01 22:48:08 +00:00
|
|
|
// get an irp from fresh list
|
2011-12-31 19:09:26 +00:00
|
|
|
//
|
2012-01-01 22:48:08 +00:00
|
|
|
Irp = HidClass_GetIrp(Context);
|
2011-12-31 19:09:26 +00:00
|
|
|
if (!Irp)
|
|
|
|
{
|
|
|
|
//
|
2012-01-01 22:48:08 +00:00
|
|
|
// build new irp
|
2011-12-31 19:09:26 +00:00
|
|
|
//
|
2012-01-01 22:48:08 +00:00
|
|
|
Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE);
|
|
|
|
if (!Irp)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// no memory
|
|
|
|
//
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// re-use irp
|
|
|
|
//
|
|
|
|
IoReuseIrp(Irp, STATUS_SUCCESS);
|
2011-12-31 19:09:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// allocate completion context
|
|
|
|
//
|
2013-05-12 15:44:58 +00:00
|
|
|
IrpContext = ExAllocatePoolWithTag(NonPagedPool, sizeof(HIDCLASS_IRP_CONTEXT), HIDCLASS_TAG);
|
2011-12-31 19:09:26 +00:00
|
|
|
if (!IrpContext)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// no memory
|
|
|
|
//
|
|
|
|
IoFreeIrp(Irp);
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
}
|
|
|
|
|
2012-01-01 22:48:08 +00:00
|
|
|
//
|
|
|
|
// get device extension
|
|
|
|
//
|
2013-05-12 15:31:01 +00:00
|
|
|
PDODeviceExtension = DeviceObject->DeviceExtension;
|
2012-01-01 22:48:08 +00:00
|
|
|
ASSERT(PDODeviceExtension->Common.IsFDO == FALSE);
|
|
|
|
|
2011-12-31 19:09:26 +00:00
|
|
|
//
|
|
|
|
// init irp context
|
|
|
|
//
|
|
|
|
RtlZeroMemory(IrpContext, sizeof(HIDCLASS_IRP_CONTEXT));
|
|
|
|
IrpContext->OriginalIrp = RequestIrp;
|
|
|
|
IrpContext->FileOp = Context;
|
|
|
|
|
2012-01-02 12:00:51 +00:00
|
|
|
//
|
|
|
|
// get collection description
|
|
|
|
//
|
2013-05-12 15:23:34 +00:00
|
|
|
CollectionDescription = HidClassPDO_GetCollectionDescription(&IrpContext->FileOp->DeviceExtension->Common.DeviceDescription,
|
|
|
|
IrpContext->FileOp->DeviceExtension->CollectionNumber);
|
2012-01-02 12:00:51 +00:00
|
|
|
ASSERT(CollectionDescription);
|
|
|
|
|
|
|
|
//
|
|
|
|
// get report description
|
|
|
|
//
|
2013-05-12 15:23:34 +00:00
|
|
|
ReportDescription = HidClassPDO_GetReportDescription(&IrpContext->FileOp->DeviceExtension->Common.DeviceDescription,
|
|
|
|
IrpContext->FileOp->DeviceExtension->CollectionNumber);
|
2012-01-02 12:00:51 +00:00
|
|
|
ASSERT(ReportDescription);
|
|
|
|
|
|
|
|
//
|
|
|
|
// sanity check
|
|
|
|
//
|
|
|
|
ASSERT(CollectionDescription->InputLength >= ReportDescription->InputLength);
|
|
|
|
|
2012-02-23 00:34:36 +00:00
|
|
|
if (Context->StopInProgress)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// stop in progress
|
|
|
|
//
|
|
|
|
DPRINT1("[HIDCLASS] Stop In Progress\n");
|
|
|
|
Irp->IoStatus.Status = STATUS_CANCELLED;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
return STATUS_CANCELLED;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-01-02 12:00:51 +00:00
|
|
|
//
|
|
|
|
// store report length
|
|
|
|
//
|
|
|
|
IrpContext->InputReportBufferLength = ReportDescription->InputLength;
|
|
|
|
|
2011-12-31 19:09:26 +00:00
|
|
|
//
|
|
|
|
// allocate buffer
|
|
|
|
//
|
2013-05-12 15:44:58 +00:00
|
|
|
IrpContext->InputReportBuffer = ExAllocatePoolWithTag(NonPagedPool, IrpContext->InputReportBufferLength, HIDCLASS_TAG);
|
2011-12-31 19:09:26 +00:00
|
|
|
if (!IrpContext->InputReportBuffer)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// no memory
|
|
|
|
//
|
|
|
|
IoFreeIrp(Irp);
|
2013-05-12 15:44:58 +00:00
|
|
|
ExFreePoolWithTag(IrpContext, HIDCLASS_TAG);
|
2011-12-31 19:09:26 +00:00
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// get stack location
|
|
|
|
//
|
|
|
|
IoStack = IoGetNextIrpStackLocation(Irp);
|
|
|
|
|
|
|
|
//
|
|
|
|
// init stack location
|
|
|
|
//
|
|
|
|
IoStack->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL;
|
|
|
|
IoStack->Parameters.DeviceIoControl.IoControlCode = DeviceIoControlCode;
|
|
|
|
IoStack->Parameters.DeviceIoControl.OutputBufferLength = IrpContext->InputReportBufferLength;
|
|
|
|
IoStack->Parameters.DeviceIoControl.InputBufferLength = 0;
|
|
|
|
IoStack->Parameters.DeviceIoControl.Type3InputBuffer = NULL;
|
|
|
|
Irp->UserBuffer = IrpContext->InputReportBuffer;
|
|
|
|
IoStack->DeviceObject = DeviceObject;
|
|
|
|
|
|
|
|
//
|
|
|
|
// store result
|
|
|
|
//
|
|
|
|
*OutIrp = Irp;
|
|
|
|
*OutIrpContext = IrpContext;
|
|
|
|
|
|
|
|
//
|
|
|
|
// done
|
|
|
|
//
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2011-12-30 14:34:07 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
HidClass_Read(
|
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp)
|
|
|
|
{
|
2011-12-31 19:09:26 +00:00
|
|
|
PIO_STACK_LOCATION IoStack;
|
|
|
|
PHIDCLASS_FILEOP_CONTEXT Context;
|
|
|
|
KIRQL OldLevel;
|
|
|
|
NTSTATUS Status;
|
|
|
|
PIRP NewIrp;
|
|
|
|
PHIDCLASS_IRP_CONTEXT NewIrpContext;
|
2012-01-01 22:48:08 +00:00
|
|
|
PHIDCLASS_COMMON_DEVICE_EXTENSION CommonDeviceExtension;
|
2011-12-31 19:09:26 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// get current stack location
|
|
|
|
//
|
|
|
|
IoStack = IoGetCurrentIrpStackLocation(Irp);
|
|
|
|
|
2012-01-01 22:48:08 +00:00
|
|
|
//
|
|
|
|
// get device extension
|
|
|
|
//
|
2013-05-12 15:31:01 +00:00
|
|
|
CommonDeviceExtension = DeviceObject->DeviceExtension;
|
2012-01-01 22:48:08 +00:00
|
|
|
ASSERT(CommonDeviceExtension->IsFDO == FALSE);
|
|
|
|
|
2011-12-31 19:09:26 +00:00
|
|
|
//
|
|
|
|
// sanity check
|
|
|
|
//
|
|
|
|
ASSERT(IoStack->FileObject);
|
|
|
|
ASSERT(IoStack->FileObject->FsContext);
|
|
|
|
|
|
|
|
//
|
|
|
|
// get context
|
|
|
|
//
|
2013-05-12 15:31:01 +00:00
|
|
|
Context = IoStack->FileObject->FsContext;
|
2011-12-31 19:09:26 +00:00
|
|
|
ASSERT(Context);
|
|
|
|
|
|
|
|
//
|
|
|
|
// FIXME support polled devices
|
|
|
|
//
|
|
|
|
ASSERT(Context->DeviceExtension->Common.DriverExtension->DevicesArePolled == FALSE);
|
|
|
|
|
2012-02-21 01:16:56 +00:00
|
|
|
if (Context->StopInProgress)
|
|
|
|
{
|
2013-05-12 15:23:34 +00:00
|
|
|
//
|
|
|
|
// stop in progress
|
|
|
|
//
|
|
|
|
DPRINT1("[HIDCLASS] Stop In Progress\n");
|
|
|
|
Irp->IoStatus.Status = STATUS_CANCELLED;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
return STATUS_CANCELLED;
|
2012-02-21 01:16:56 +00:00
|
|
|
}
|
|
|
|
|
2011-12-31 19:09:26 +00:00
|
|
|
//
|
|
|
|
// build irp request
|
|
|
|
//
|
2013-05-12 15:23:34 +00:00
|
|
|
Status = HidClass_BuildIrp(DeviceObject,
|
|
|
|
Irp,
|
|
|
|
Context,
|
|
|
|
IOCTL_HID_READ_REPORT,
|
|
|
|
IoStack->Parameters.Read.Length,
|
|
|
|
&NewIrp,
|
|
|
|
&NewIrpContext);
|
2011-12-31 19:09:26 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// failed
|
|
|
|
//
|
|
|
|
DPRINT1("HidClass_BuildIrp failed with %x\n", Status);
|
|
|
|
Irp->IoStatus.Status = Status;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// acquire lock
|
|
|
|
//
|
|
|
|
KeAcquireSpinLock(&Context->Lock, &OldLevel);
|
|
|
|
|
|
|
|
//
|
|
|
|
// insert irp into pending list
|
|
|
|
//
|
|
|
|
InsertTailList(&Context->ReadPendingIrpListHead, &NewIrp->Tail.Overlay.ListEntry);
|
|
|
|
|
|
|
|
//
|
|
|
|
// set completion routine
|
|
|
|
//
|
|
|
|
IoSetCompletionRoutine(NewIrp, HidClass_ReadCompleteIrp, NewIrpContext, TRUE, TRUE, TRUE);
|
|
|
|
|
|
|
|
//
|
|
|
|
// make next location current
|
|
|
|
//
|
|
|
|
IoSetNextIrpStackLocation(NewIrp);
|
|
|
|
|
|
|
|
//
|
|
|
|
// release spin lock
|
|
|
|
//
|
|
|
|
KeReleaseSpinLock(&Context->Lock, OldLevel);
|
|
|
|
|
|
|
|
//
|
|
|
|
// mark irp pending
|
|
|
|
//
|
|
|
|
IoMarkIrpPending(Irp);
|
|
|
|
|
|
|
|
//
|
2013-05-12 15:23:34 +00:00
|
|
|
// let's dispatch the request
|
2011-12-31 19:09:26 +00:00
|
|
|
//
|
|
|
|
ASSERT(Context->DeviceExtension);
|
2012-01-01 22:48:08 +00:00
|
|
|
Status = Context->DeviceExtension->Common.DriverExtension->MajorFunction[IRP_MJ_INTERNAL_DEVICE_CONTROL](Context->DeviceExtension->FDODeviceObject, NewIrp);
|
2011-12-31 19:09:26 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// complete
|
|
|
|
//
|
2012-01-01 22:48:08 +00:00
|
|
|
return STATUS_PENDING;
|
2011-12-30 14:34:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
HidClass_Write(
|
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp)
|
|
|
|
{
|
2019-05-14 12:18:21 +00:00
|
|
|
PIO_STACK_LOCATION IoStack;
|
|
|
|
PHIDCLASS_COMMON_DEVICE_EXTENSION CommonDeviceExtension;
|
|
|
|
PIRP SubIrp;
|
|
|
|
KEVENT Event;
|
|
|
|
IO_STATUS_BLOCK IoStatusBlock;
|
|
|
|
HID_XFER_PACKET XferPacket;
|
|
|
|
NTSTATUS Status;
|
|
|
|
ULONG Length;
|
|
|
|
|
|
|
|
IoStack = IoGetCurrentIrpStackLocation(Irp);
|
|
|
|
Length = IoStack->Parameters.Write.Length;
|
|
|
|
if (Length < 1)
|
|
|
|
{
|
|
|
|
Irp->IoStatus.Status = STATUS_INVALID_PARAMETER;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
RtlZeroMemory(&XferPacket, sizeof(XferPacket));
|
|
|
|
XferPacket.reportBufferLen = Length;
|
|
|
|
XferPacket.reportBuffer = Irp->UserBuffer;
|
|
|
|
XferPacket.reportId = XferPacket.reportBuffer[0];
|
|
|
|
|
|
|
|
CommonDeviceExtension = DeviceObject->DeviceExtension;
|
|
|
|
SubIrp = IoBuildDeviceIoControlRequest(
|
|
|
|
IOCTL_HID_WRITE_REPORT,
|
|
|
|
CommonDeviceExtension->HidDeviceExtension.NextDeviceObject,
|
|
|
|
NULL, 0,
|
|
|
|
NULL, 0,
|
|
|
|
TRUE,
|
|
|
|
&Event,
|
|
|
|
&IoStatusBlock);
|
|
|
|
if (!SubIrp)
|
|
|
|
{
|
|
|
|
Irp->IoStatus.Status = STATUS_NO_MEMORY;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
SubIrp->UserBuffer = &XferPacket;
|
|
|
|
KeInitializeEvent(&Event, SynchronizationEvent, FALSE);
|
|
|
|
Status = IoCallDriver(CommonDeviceExtension->HidDeviceExtension.NextDeviceObject, SubIrp);
|
|
|
|
if (Status == STATUS_PENDING)
|
|
|
|
{
|
|
|
|
KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL);
|
|
|
|
Status = IoStatusBlock.Status;
|
|
|
|
}
|
|
|
|
Irp->IoStatus.Status = Status;
|
2011-12-31 04:13:37 +00:00
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
2019-05-14 12:18:21 +00:00
|
|
|
return Status;
|
2011-12-30 14:34:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
HidClass_DeviceControl(
|
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp)
|
|
|
|
{
|
2011-12-31 03:33:14 +00:00
|
|
|
PIO_STACK_LOCATION IoStack;
|
|
|
|
PHIDCLASS_COMMON_DEVICE_EXTENSION CommonDeviceExtension;
|
|
|
|
PHID_COLLECTION_INFORMATION CollectionInformation;
|
2012-01-02 12:00:51 +00:00
|
|
|
PHIDP_COLLECTION_DESC CollectionDescription;
|
|
|
|
PHIDCLASS_PDO_DEVICE_EXTENSION PDODeviceExtension;
|
2011-12-31 03:33:14 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// get device extension
|
|
|
|
//
|
2013-05-12 15:31:01 +00:00
|
|
|
CommonDeviceExtension = DeviceObject->DeviceExtension;
|
2012-01-27 14:08:40 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// only PDO are supported
|
|
|
|
//
|
|
|
|
if (CommonDeviceExtension->IsFDO)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// invalid request
|
|
|
|
//
|
|
|
|
DPRINT1("[HIDCLASS] DeviceControl Irp for FDO arrived\n");
|
2013-05-05 15:04:49 +00:00
|
|
|
Irp->IoStatus.Status = STATUS_INVALID_PARAMETER_1;
|
2012-01-27 14:08:40 +00:00
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
return STATUS_INVALID_PARAMETER_1;
|
|
|
|
}
|
|
|
|
|
2012-01-02 12:00:51 +00:00
|
|
|
ASSERT(CommonDeviceExtension->IsFDO == FALSE);
|
|
|
|
|
|
|
|
//
|
|
|
|
// get pdo device extension
|
|
|
|
//
|
2013-05-12 15:31:01 +00:00
|
|
|
PDODeviceExtension = DeviceObject->DeviceExtension;
|
2011-12-31 03:33:14 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// get stack location
|
|
|
|
//
|
|
|
|
IoStack = IoGetCurrentIrpStackLocation(Irp);
|
|
|
|
|
2013-05-12 15:23:34 +00:00
|
|
|
switch (IoStack->Parameters.DeviceIoControl.IoControlCode)
|
2011-12-31 03:33:14 +00:00
|
|
|
{
|
|
|
|
case IOCTL_HID_GET_COLLECTION_INFORMATION:
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// check if output buffer is big enough
|
|
|
|
//
|
|
|
|
if (IoStack->Parameters.DeviceIoControl.OutputBufferLength < sizeof(HID_COLLECTION_INFORMATION))
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// invalid buffer size
|
|
|
|
//
|
|
|
|
Irp->IoStatus.Status = STATUS_INVALID_BUFFER_SIZE;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
return STATUS_INVALID_BUFFER_SIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// get output buffer
|
|
|
|
//
|
2013-05-12 15:31:01 +00:00
|
|
|
CollectionInformation = Irp->AssociatedIrp.SystemBuffer;
|
2011-12-31 03:33:14 +00:00
|
|
|
ASSERT(CollectionInformation);
|
|
|
|
|
2012-01-02 12:00:51 +00:00
|
|
|
//
|
|
|
|
// get collection description
|
|
|
|
//
|
2013-05-12 15:23:34 +00:00
|
|
|
CollectionDescription = HidClassPDO_GetCollectionDescription(&CommonDeviceExtension->DeviceDescription,
|
|
|
|
PDODeviceExtension->CollectionNumber);
|
2012-01-02 12:00:51 +00:00
|
|
|
ASSERT(CollectionDescription);
|
|
|
|
|
2011-12-31 03:33:14 +00:00
|
|
|
//
|
|
|
|
// init result buffer
|
|
|
|
//
|
2012-01-02 12:00:51 +00:00
|
|
|
CollectionInformation->DescriptorSize = CollectionDescription->PreparsedDataLength;
|
2011-12-31 03:33:14 +00:00
|
|
|
CollectionInformation->Polled = CommonDeviceExtension->DriverExtension->DevicesArePolled;
|
2011-12-31 19:09:26 +00:00
|
|
|
CollectionInformation->VendorID = CommonDeviceExtension->Attributes.VendorID;
|
|
|
|
CollectionInformation->ProductID = CommonDeviceExtension->Attributes.ProductID;
|
|
|
|
CollectionInformation->VersionNumber = CommonDeviceExtension->Attributes.VersionNumber;
|
2011-12-31 03:33:14 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// complete request
|
|
|
|
//
|
|
|
|
Irp->IoStatus.Information = sizeof(HID_COLLECTION_INFORMATION);
|
|
|
|
Irp->IoStatus.Status = STATUS_SUCCESS;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
case IOCTL_HID_GET_COLLECTION_DESCRIPTOR:
|
|
|
|
{
|
|
|
|
//
|
2012-01-02 12:00:51 +00:00
|
|
|
// get collection description
|
2011-12-31 03:33:14 +00:00
|
|
|
//
|
2013-05-12 15:23:34 +00:00
|
|
|
CollectionDescription = HidClassPDO_GetCollectionDescription(&CommonDeviceExtension->DeviceDescription,
|
|
|
|
PDODeviceExtension->CollectionNumber);
|
2012-01-02 12:00:51 +00:00
|
|
|
ASSERT(CollectionDescription);
|
2011-12-31 03:33:14 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// check if output buffer is big enough
|
|
|
|
//
|
2012-01-02 12:00:51 +00:00
|
|
|
if (IoStack->Parameters.DeviceIoControl.OutputBufferLength < CollectionDescription->PreparsedDataLength)
|
2011-12-31 03:33:14 +00:00
|
|
|
{
|
|
|
|
//
|
|
|
|
// invalid buffer size
|
|
|
|
//
|
|
|
|
Irp->IoStatus.Status = STATUS_INVALID_BUFFER_SIZE;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
return STATUS_INVALID_BUFFER_SIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// copy result
|
|
|
|
//
|
|
|
|
ASSERT(Irp->UserBuffer);
|
2012-01-02 12:00:51 +00:00
|
|
|
RtlCopyMemory(Irp->UserBuffer, CollectionDescription->PreparsedData, CollectionDescription->PreparsedDataLength);
|
2011-12-31 03:33:14 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// complete request
|
|
|
|
//
|
2012-01-02 12:00:51 +00:00
|
|
|
Irp->IoStatus.Information = CollectionDescription->PreparsedDataLength;
|
2011-12-31 03:33:14 +00:00
|
|
|
Irp->IoStatus.Status = STATUS_SUCCESS;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
2019-04-19 20:40:32 +00:00
|
|
|
case IOCTL_HID_GET_FEATURE:
|
|
|
|
{
|
|
|
|
PIRP SubIrp;
|
|
|
|
KEVENT Event;
|
|
|
|
IO_STATUS_BLOCK IoStatusBlock;
|
|
|
|
HID_XFER_PACKET XferPacket;
|
|
|
|
NTSTATUS Status;
|
|
|
|
PHIDP_REPORT_IDS ReportDescription;
|
|
|
|
|
|
|
|
if (IoStack->Parameters.DeviceIoControl.InputBufferLength < 1)
|
|
|
|
{
|
|
|
|
Irp->IoStatus.Status = STATUS_INVALID_PARAMETER;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
ReportDescription = HidClassPDO_GetReportDescriptionByReportID(&PDODeviceExtension->Common.DeviceDescription, ((PUCHAR)Irp->AssociatedIrp.SystemBuffer)[0]);
|
|
|
|
if (!ReportDescription || IoStack->Parameters.DeviceIoControl.OutputBufferLength < ReportDescription->FeatureLength)
|
|
|
|
{
|
|
|
|
Irp->IoStatus.Status = STATUS_INVALID_PARAMETER;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
RtlZeroMemory(&XferPacket, sizeof(XferPacket));
|
|
|
|
XferPacket.reportBufferLen = ReportDescription->FeatureLength;
|
|
|
|
XferPacket.reportBuffer = MmGetSystemAddressForMdlSafe(Irp->MdlAddress, NormalPagePriority);
|
|
|
|
XferPacket.reportId = ((PUCHAR)Irp->AssociatedIrp.SystemBuffer)[0];
|
|
|
|
if (!XferPacket.reportBuffer)
|
|
|
|
{
|
|
|
|
Irp->IoStatus.Status = STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
}
|
|
|
|
|
|
|
|
SubIrp = IoBuildDeviceIoControlRequest(
|
|
|
|
IOCTL_HID_GET_FEATURE,
|
|
|
|
CommonDeviceExtension->HidDeviceExtension.NextDeviceObject,
|
|
|
|
NULL, 0,
|
|
|
|
NULL, 0,
|
|
|
|
TRUE,
|
|
|
|
&Event,
|
|
|
|
&IoStatusBlock);
|
|
|
|
if (!SubIrp)
|
|
|
|
{
|
|
|
|
Irp->IoStatus.Status = STATUS_NO_MEMORY;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
SubIrp->UserBuffer = &XferPacket;
|
|
|
|
KeInitializeEvent(&Event, SynchronizationEvent, FALSE);
|
|
|
|
Status = IoCallDriver(CommonDeviceExtension->HidDeviceExtension.NextDeviceObject, SubIrp);
|
|
|
|
if (Status == STATUS_PENDING)
|
|
|
|
{
|
|
|
|
KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL);
|
|
|
|
Status = IoStatusBlock.Status;
|
|
|
|
}
|
|
|
|
Irp->IoStatus.Status = Status;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
case IOCTL_HID_SET_FEATURE:
|
|
|
|
{
|
|
|
|
PIRP SubIrp;
|
|
|
|
KEVENT Event;
|
|
|
|
IO_STATUS_BLOCK IoStatusBlock;
|
|
|
|
HID_XFER_PACKET XferPacket;
|
|
|
|
NTSTATUS Status;
|
|
|
|
PHIDP_REPORT_IDS ReportDescription;
|
|
|
|
|
|
|
|
if (IoStack->Parameters.DeviceIoControl.InputBufferLength < 1)
|
|
|
|
{
|
|
|
|
Irp->IoStatus.Status = STATUS_INVALID_PARAMETER;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
ReportDescription = HidClassPDO_GetReportDescriptionByReportID(&PDODeviceExtension->Common.DeviceDescription, ((PUCHAR)Irp->AssociatedIrp.SystemBuffer)[0]);
|
|
|
|
if (!ReportDescription || IoStack->Parameters.DeviceIoControl.InputBufferLength < ReportDescription->FeatureLength)
|
|
|
|
{
|
|
|
|
Irp->IoStatus.Status = STATUS_INVALID_PARAMETER;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
RtlZeroMemory(&XferPacket, sizeof(XferPacket));
|
|
|
|
XferPacket.reportBufferLen = ReportDescription->FeatureLength;
|
|
|
|
XferPacket.reportBuffer = Irp->AssociatedIrp.SystemBuffer;
|
|
|
|
XferPacket.reportId = XferPacket.reportBuffer[0];
|
|
|
|
|
|
|
|
SubIrp = IoBuildDeviceIoControlRequest(
|
|
|
|
IOCTL_HID_SET_FEATURE,
|
|
|
|
CommonDeviceExtension->HidDeviceExtension.NextDeviceObject,
|
|
|
|
NULL, 0,
|
|
|
|
NULL, 0,
|
|
|
|
TRUE,
|
|
|
|
&Event,
|
|
|
|
&IoStatusBlock);
|
|
|
|
if (!SubIrp)
|
|
|
|
{
|
|
|
|
Irp->IoStatus.Status = STATUS_NO_MEMORY;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
SubIrp->UserBuffer = &XferPacket;
|
|
|
|
KeInitializeEvent(&Event, SynchronizationEvent, FALSE);
|
|
|
|
Status = IoCallDriver(CommonDeviceExtension->HidDeviceExtension.NextDeviceObject, SubIrp);
|
|
|
|
if (Status == STATUS_PENDING)
|
|
|
|
{
|
|
|
|
KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL);
|
|
|
|
Status = IoStatusBlock.Status;
|
|
|
|
}
|
|
|
|
Irp->IoStatus.Status = Status;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
return Status;
|
|
|
|
}
|
2011-12-31 03:33:14 +00:00
|
|
|
default:
|
|
|
|
{
|
|
|
|
DPRINT1("[HIDCLASS] DeviceControl IoControlCode 0x%x not implemented\n", IoStack->Parameters.DeviceIoControl.IoControlCode);
|
|
|
|
Irp->IoStatus.Status = STATUS_NOT_IMPLEMENTED;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
}
|
2011-12-30 14:34:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
HidClass_InternalDeviceControl(
|
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp)
|
|
|
|
{
|
2017-02-06 15:49:23 +00:00
|
|
|
UNIMPLEMENTED;
|
2011-12-30 14:34:07 +00:00
|
|
|
ASSERT(FALSE);
|
2012-01-01 22:48:08 +00:00
|
|
|
Irp->IoStatus.Status = STATUS_NOT_IMPLEMENTED;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
2011-12-30 14:34:07 +00:00
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
HidClass_Power(
|
2011-12-25 20:21:34 +00:00
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp)
|
|
|
|
{
|
2013-05-24 17:36:14 +00:00
|
|
|
PHIDCLASS_COMMON_DEVICE_EXTENSION CommonDeviceExtension;
|
|
|
|
CommonDeviceExtension = DeviceObject->DeviceExtension;
|
2021-06-11 12:29:21 +00:00
|
|
|
|
2013-05-24 17:36:14 +00:00
|
|
|
if (CommonDeviceExtension->IsFDO)
|
|
|
|
{
|
|
|
|
IoCopyCurrentIrpStackLocationToNext(Irp);
|
|
|
|
return HidClassFDO_DispatchRequest(DeviceObject, Irp);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Irp->IoStatus.Status = STATUS_SUCCESS;
|
|
|
|
PoStartNextPowerIrp(Irp);
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
2011-12-25 20:21:34 +00:00
|
|
|
}
|
|
|
|
|
2011-12-30 14:34:07 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
HidClass_PnP(
|
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp)
|
|
|
|
{
|
|
|
|
PHIDCLASS_COMMON_DEVICE_EXTENSION CommonDeviceExtension;
|
|
|
|
|
|
|
|
//
|
|
|
|
// get common device extension
|
|
|
|
//
|
2013-05-12 15:31:01 +00:00
|
|
|
CommonDeviceExtension = DeviceObject->DeviceExtension;
|
2011-12-30 14:34:07 +00:00
|
|
|
|
|
|
|
//
|
2011-12-31 03:33:14 +00:00
|
|
|
// check type of device object
|
2011-12-30 14:34:07 +00:00
|
|
|
//
|
2011-12-31 03:33:14 +00:00
|
|
|
if (CommonDeviceExtension->IsFDO)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// handle request
|
|
|
|
//
|
|
|
|
return HidClassFDO_PnP(DeviceObject, Irp);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// handle request
|
|
|
|
//
|
|
|
|
return HidClassPDO_PnP(DeviceObject, Irp);
|
|
|
|
}
|
2011-12-30 14:34:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
HidClass_DispatchDefault(
|
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp)
|
|
|
|
{
|
|
|
|
PHIDCLASS_COMMON_DEVICE_EXTENSION CommonDeviceExtension;
|
|
|
|
|
|
|
|
//
|
|
|
|
// get common device extension
|
|
|
|
//
|
2013-05-12 15:31:01 +00:00
|
|
|
CommonDeviceExtension = DeviceObject->DeviceExtension;
|
2011-12-30 14:34:07 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// FIXME: support PDO
|
|
|
|
//
|
|
|
|
ASSERT(CommonDeviceExtension->IsFDO == TRUE);
|
|
|
|
|
|
|
|
//
|
|
|
|
// skip current irp stack location
|
|
|
|
//
|
|
|
|
IoSkipCurrentIrpStackLocation(Irp);
|
|
|
|
|
|
|
|
//
|
|
|
|
// dispatch to lower device object
|
|
|
|
//
|
2012-01-01 22:48:08 +00:00
|
|
|
return IoCallDriver(CommonDeviceExtension->HidDeviceExtension.NextDeviceObject, Irp);
|
2011-12-30 14:34:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
HidClassDispatch(
|
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp)
|
|
|
|
{
|
|
|
|
PIO_STACK_LOCATION IoStack;
|
|
|
|
|
|
|
|
//
|
|
|
|
// get current stack location
|
|
|
|
//
|
|
|
|
IoStack = IoGetCurrentIrpStackLocation(Irp);
|
2012-01-01 22:48:08 +00:00
|
|
|
DPRINT("[HIDCLASS] Dispatch Major %x Minor %x\n", IoStack->MajorFunction, IoStack->MinorFunction);
|
2011-12-30 14:34:07 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// dispatch request based on major function
|
|
|
|
//
|
2013-05-12 15:23:34 +00:00
|
|
|
switch (IoStack->MajorFunction)
|
2011-12-30 14:34:07 +00:00
|
|
|
{
|
|
|
|
case IRP_MJ_CREATE:
|
|
|
|
return HidClass_Create(DeviceObject, Irp);
|
|
|
|
case IRP_MJ_CLOSE:
|
|
|
|
return HidClass_Close(DeviceObject, Irp);
|
|
|
|
case IRP_MJ_READ:
|
|
|
|
return HidClass_Read(DeviceObject, Irp);
|
|
|
|
case IRP_MJ_WRITE:
|
|
|
|
return HidClass_Write(DeviceObject, Irp);
|
|
|
|
case IRP_MJ_DEVICE_CONTROL:
|
|
|
|
return HidClass_DeviceControl(DeviceObject, Irp);
|
|
|
|
case IRP_MJ_INTERNAL_DEVICE_CONTROL:
|
|
|
|
return HidClass_InternalDeviceControl(DeviceObject, Irp);
|
|
|
|
case IRP_MJ_POWER:
|
|
|
|
return HidClass_Power(DeviceObject, Irp);
|
|
|
|
case IRP_MJ_PNP:
|
|
|
|
return HidClass_PnP(DeviceObject, Irp);
|
|
|
|
default:
|
|
|
|
return HidClass_DispatchDefault(DeviceObject, Irp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-25 20:21:34 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
HidRegisterMinidriver(
|
|
|
|
IN PHID_MINIDRIVER_REGISTRATION MinidriverRegistration)
|
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
|
|
|
PHIDCLASS_DRIVER_EXTENSION DriverExtension;
|
|
|
|
|
|
|
|
/* check if the version matches */
|
|
|
|
if (MinidriverRegistration->Revision > HID_REVISION)
|
|
|
|
{
|
|
|
|
/* revision mismatch */
|
|
|
|
ASSERT(FALSE);
|
|
|
|
return STATUS_REVISION_MISMATCH;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* now allocate the driver object extension */
|
2013-05-12 17:16:41 +00:00
|
|
|
Status = IoAllocateDriverObjectExtension(MinidriverRegistration->DriverObject,
|
|
|
|
ClientIdentificationAddress,
|
|
|
|
sizeof(HIDCLASS_DRIVER_EXTENSION),
|
|
|
|
(PVOID *)&DriverExtension);
|
2011-12-25 20:21:34 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
/* failed to allocate driver extension */
|
|
|
|
ASSERT(FALSE);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* zero driver extension */
|
|
|
|
RtlZeroMemory(DriverExtension, sizeof(HIDCLASS_DRIVER_EXTENSION));
|
|
|
|
|
|
|
|
/* init driver extension */
|
|
|
|
DriverExtension->DriverObject = MinidriverRegistration->DriverObject;
|
|
|
|
DriverExtension->DeviceExtensionSize = MinidriverRegistration->DeviceExtensionSize;
|
|
|
|
DriverExtension->DevicesArePolled = MinidriverRegistration->DevicesArePolled;
|
|
|
|
DriverExtension->AddDevice = MinidriverRegistration->DriverObject->DriverExtension->AddDevice;
|
|
|
|
DriverExtension->DriverUnload = MinidriverRegistration->DriverObject->DriverUnload;
|
|
|
|
|
|
|
|
/* copy driver dispatch routines */
|
2013-05-12 15:23:34 +00:00
|
|
|
RtlCopyMemory(DriverExtension->MajorFunction,
|
|
|
|
MinidriverRegistration->DriverObject->MajorFunction,
|
2013-05-12 17:16:41 +00:00
|
|
|
sizeof(PDRIVER_DISPATCH) * (IRP_MJ_MAXIMUM_FUNCTION + 1));
|
2011-12-25 20:21:34 +00:00
|
|
|
|
|
|
|
/* initialize lock */
|
|
|
|
KeInitializeSpinLock(&DriverExtension->Lock);
|
|
|
|
|
|
|
|
/* now replace dispatch routines */
|
|
|
|
DriverExtension->DriverObject->DriverExtension->AddDevice = HidClassAddDevice;
|
|
|
|
DriverExtension->DriverObject->DriverUnload = HidClassDriverUnload;
|
|
|
|
DriverExtension->DriverObject->MajorFunction[IRP_MJ_CREATE] = HidClassDispatch;
|
|
|
|
DriverExtension->DriverObject->MajorFunction[IRP_MJ_CLOSE] = HidClassDispatch;
|
|
|
|
DriverExtension->DriverObject->MajorFunction[IRP_MJ_READ] = HidClassDispatch;
|
|
|
|
DriverExtension->DriverObject->MajorFunction[IRP_MJ_WRITE] = HidClassDispatch;
|
|
|
|
DriverExtension->DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = HidClassDispatch;
|
|
|
|
DriverExtension->DriverObject->MajorFunction[IRP_MJ_INTERNAL_DEVICE_CONTROL] = HidClassDispatch;
|
|
|
|
DriverExtension->DriverObject->MajorFunction[IRP_MJ_POWER] = HidClassDispatch;
|
|
|
|
DriverExtension->DriverObject->MajorFunction[IRP_MJ_PNP] = HidClassDispatch;
|
|
|
|
|
|
|
|
/* done */
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|