#include "precomp.h"
+#define NDEBUG
+#include <debug.h>
+
static LPWSTR ClientIdentificationAddress = L"HIDCLASS";
static ULONG HidClassDeviceNumber = 0;
-ULONG
+NTSTATUS
NTAPI
-DllInitialize(ULONG Unknown)
+DllInitialize(
+ IN PUNICODE_STRING RegistryPath)
{
- return 0;
+ return STATUS_SUCCESS;
}
-ULONG
+NTSTATUS
NTAPI
-DllUnload()
+DllUnload(VOID)
{
- return 0;
+ return STATUS_SUCCESS;
}
NTSTATUS
ULONG DeviceExtensionSize;
PHIDCLASS_DRIVER_EXTENSION DriverExtension;
-
/* increment device number */
InterlockedIncrement((PLONG)&HidClassDeviceNumber);
RtlInitUnicodeString(&DeviceName, CharDeviceName);
/* get driver object extension */
- DriverExtension = (PHIDCLASS_DRIVER_EXTENSION) IoGetDriverObjectExtension(DriverObject, ClientIdentificationAddress);
+ DriverExtension = IoGetDriverObjectExtension(DriverObject, ClientIdentificationAddress);
if (!DriverExtension)
{
/* device removed */
}
/* get device extension */
- FDODeviceExtension = (PHIDCLASS_FDO_EXTENSION)NewDeviceObject->DeviceExtension;
+ FDODeviceExtension = NewDeviceObject->DeviceExtension;
/* zero device extension */
RtlZeroMemory(FDODeviceExtension, sizeof(HIDCLASS_FDO_EXTENSION));
/* initialize device extension */
+ FDODeviceExtension->Common.IsFDO = TRUE;
+ FDODeviceExtension->Common.DriverExtension = DriverExtension;
FDODeviceExtension->Common.HidDeviceExtension.PhysicalDeviceObject = PhysicalDeviceObject;
FDODeviceExtension->Common.HidDeviceExtension.MiniDeviceExtension = (PVOID)((ULONG_PTR)FDODeviceExtension + sizeof(HIDCLASS_FDO_EXTENSION));
FDODeviceExtension->Common.HidDeviceExtension.NextDeviceObject = IoAttachDeviceToDeviceStack(NewDeviceObject, PhysicalDeviceObject);
- FDODeviceExtension->Common.IsFDO = TRUE;
- FDODeviceExtension->Common.DriverExtension = DriverExtension;
+ if (FDODeviceExtension->Common.HidDeviceExtension.NextDeviceObject == NULL)
+ {
+ /* no PDO */
+ IoDeleteDevice(NewDeviceObject);
+ DPRINT1("[HIDCLASS] failed to attach to device stack\n");
+ return STATUS_DEVICE_REMOVED;
+ }
/* sanity check */
ASSERT(FDODeviceExtension->Common.HidDeviceExtension.NextDeviceObject);
IN PDRIVER_OBJECT DriverObject)
{
UNIMPLEMENTED
- ASSERT(FALSE);
}
NTSTATUS
//
// get device extension
//
- CommonDeviceExtension = (PHIDCLASS_COMMON_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
+ CommonDeviceExtension = DeviceObject->DeviceExtension;
if (CommonDeviceExtension->IsFDO)
{
+#ifndef __REACTOS__
+
//
// only supported for PDO
//
- DPRINT1("[HIDCLASS] IRP_MJ_CREATE for FDO\n");
Irp->IoStatus.Status = STATUS_UNSUCCESSFUL;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return STATUS_UNSUCCESSFUL;
+#else
+ //
+ // ReactOS PnP manager [...]
+ //
+ DPRINT1("[HIDCLASS] PnP HACK\n");
+ Irp->IoStatus.Status = STATUS_SUCCESS;
+ IoCompleteRequest(Irp, IO_NO_INCREMENT);
+ return STATUS_SUCCESS;
+#endif
}
//
//
// get device extension
//
- PDODeviceExtension = (PHIDCLASS_PDO_DEVICE_EXTENSION)CommonDeviceExtension;
+ PDODeviceExtension = DeviceObject->DeviceExtension;
//
// get stack location
//
IoStack = IoGetCurrentIrpStackLocation(Irp);
- DPRINT1("ShareAccess %x\n", IoStack->Parameters.Create.ShareAccess);
- DPRINT1("Options %x\n", IoStack->Parameters.Create.Options);
- DPRINT1("DesiredAccess %x\n", IoStack->Parameters.Create.SecurityContext->DesiredAccess);
+ 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);
//
// allocate context
//
- Context = (PHIDCLASS_FILEOP_CONTEXT)ExAllocatePool(NonPagedPool, sizeof(HIDCLASS_FILEOP_CONTEXT));
+ Context = ExAllocatePoolWithTag(NonPagedPool, sizeof(HIDCLASS_FILEOP_CONTEXT), HIDCLASS_TAG);
if (!Context)
{
//
KeInitializeSpinLock(&Context->Lock);
InitializeListHead(&Context->ReadPendingIrpListHead);
InitializeListHead(&Context->IrpCompletedListHead);
+ KeInitializeEvent(&Context->IrpReadComplete, NotificationEvent, FALSE);
//
// store context
//
ASSERT(IoStack->FileObject);
- IoStack->FileObject->FsContext = (PVOID)Context;
+ IoStack->FileObject->FsContext = Context;
//
// done
{
PIO_STACK_LOCATION IoStack;
PHIDCLASS_COMMON_DEVICE_EXTENSION CommonDeviceExtension;
- PHIDCLASS_IRP_CONTEXT IrpContext;
+ PHIDCLASS_FILEOP_CONTEXT IrpContext;
+ BOOLEAN IsRequestPending = FALSE;
+ KIRQL OldLevel;
+ PLIST_ENTRY Entry;
+ PIRP ListIrp;
//
// get device extension
//
- CommonDeviceExtension = (PHIDCLASS_COMMON_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
+ CommonDeviceExtension = DeviceObject->DeviceExtension;
//
// is it a FDO request
//
// get irp context
//
- IrpContext = (PHIDCLASS_IRP_CONTEXT)IoStack->FileObject->FsContext;
+ IrpContext = IoStack->FileObject->FsContext;
+ ASSERT(IrpContext);
//
- // cancel pending irps
+ // acquire lock
//
- UNIMPLEMENTED
+ 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
+ //
+ while (!IsListEmpty(&IrpContext->IrpCompletedListHead))
+ {
+ //
+ // remove head irp
+ //
+ Entry = RemoveHeadList(&IrpContext->IrpCompletedListHead);
+
+ //
+ // get irp
+ //
+ ListIrp = CONTAINING_RECORD(Entry, IRP, Tail.Overlay.ListEntry);
+
+ //
+ // free the irp
+ //
+ IoFreeIrp(ListIrp);
+ }
+
+ //
+ // release lock
+ //
+ KeReleaseSpinLock(&IrpContext->Lock, OldLevel);
//
// remove context
//
// free context
//
- ExFreePool(IrpContext);
+ ExFreePoolWithTag(IrpContext, HIDCLASS_TAG);
//
// complete request
{
PHIDCLASS_IRP_CONTEXT IrpContext;
KIRQL OldLevel;
+ PUCHAR Address;
+ ULONG Offset;
+ PHIDP_COLLECTION_DESC CollectionDescription;
+ PHIDP_REPORT_IDS ReportDescription;
+ BOOLEAN IsEmpty;
//
// get irp context
//
- IrpContext = (PHIDCLASS_IRP_CONTEXT)Ctx;
+ IrpContext = Ctx;
- DPRINT1("HidClass_ReadCompleteIrp Irql %lu\n", KeGetCurrentIrql());
- DPRINT1("HidClass_ReadCompleteIrp Status %lx\n", Irp->IoStatus.Status);
- DPRINT1("HidClass_ReadCompleteIrp Length %lu\n", Irp->IoStatus.Information);
- DPRINT1("HidClass_ReadCompleteIrp Irp %p\n", Irp);
- DPRINT1("HidClass_ReadCompleteIrp InputReportBuffer %p\n", IrpContext->InputReportBuffer);
- DPRINT1("HidClass_ReadCompleteIrp InputReportBufferLength %li\n", IrpContext->InputReportBufferLength);
- DPRINT1("HidClass_ReadCompleteIrp OriginalIrp %p\n", IrpContext->OriginalIrp);
+ 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);
//
// copy result
if (Irp->IoStatus.Information)
{
//
- // copy result
+ // get address
//
- RtlCopyMemory(IrpContext->OriginalIrp->UserBuffer, IrpContext->InputReportBuffer, IrpContext->InputReportBufferLength);
+ Address = MmGetSystemAddressForMdlSafe(IrpContext->OriginalIrp->MdlAddress, NormalPagePriority);
+ if (Address)
+ {
+ //
+ // reports may have a report id prepended
+ //
+ Offset = 0;
+
+ //
+ // get collection description
+ //
+ CollectionDescription = HidClassPDO_GetCollectionDescription(&IrpContext->FileOp->DeviceExtension->Common.DeviceDescription,
+ IrpContext->FileOp->DeviceExtension->CollectionNumber);
+ ASSERT(CollectionDescription);
+
+ //
+ // get report description
+ //
+ ReportDescription = HidClassPDO_GetReportDescription(&IrpContext->FileOp->DeviceExtension->Common.DeviceDescription,
+ IrpContext->FileOp->DeviceExtension->CollectionNumber);
+ ASSERT(ReportDescription);
+
+ if (CollectionDescription && ReportDescription)
+ {
+ //
+ // calculate offset
+ //
+ ASSERT(CollectionDescription->InputLength >= ReportDescription->InputLength);
+ Offset = CollectionDescription->InputLength - ReportDescription->InputLength;
+ }
+
+ //
+ // copy result
+ //
+ RtlCopyMemory(&Address[Offset], IrpContext->InputReportBuffer, IrpContext->InputReportBufferLength);
+ }
}
//
// copy result status
//
IrpContext->OriginalIrp->IoStatus.Status = Irp->IoStatus.Status;
- Irp->IoStatus.Information = Irp->IoStatus.Information;
+ IrpContext->OriginalIrp->IoStatus.Information = Irp->IoStatus.Information;
//
// free input report buffer
//
- ExFreePool(IrpContext->InputReportBuffer);
-
- //
- // complete original request
- //
- IoCompleteRequest(IrpContext->OriginalIrp, IO_NO_INCREMENT);
+ ExFreePoolWithTag(IrpContext->InputReportBuffer, HIDCLASS_TAG);
//
// remove us from pending list
//
RemoveEntryList(&Irp->Tail.Overlay.ListEntry);
+ //
+ // is list empty
+ //
+ IsEmpty = IsListEmpty(&IrpContext->FileOp->ReadPendingIrpListHead);
+
+ //
+ // insert into completed list
+ //
+ InsertTailList(&IrpContext->FileOp->IrpCompletedListHead, &Irp->Tail.Overlay.ListEntry);
+
//
// release lock
//
KeReleaseSpinLock(&IrpContext->FileOp->Lock, OldLevel);
+ //
+ // complete original request
+ //
+ IoCompleteRequest(IrpContext->OriginalIrp, IO_NO_INCREMENT);
+
+
+ DPRINT("StopInProgress %x IsEmpty %x\n", IrpContext->FileOp->StopInProgress, IsEmpty);
+ if (IrpContext->FileOp->StopInProgress && IsEmpty)
+ {
+ //
+ // last pending irp
+ //
+ DPRINT1("[HIDCLASS] LastPendingTransfer Signalling\n");
+ KeSetEvent(&IrpContext->FileOp->IrpReadComplete, 0, FALSE);
+ }
+
+ if (IrpContext->FileOp->StopInProgress && IsEmpty)
+ {
+ //
+ // last pending irp
+ //
+ DPRINT1("[HIDCLASS] LastPendingTransfer Signalling\n");
+ KeSetEvent(&IrpContext->FileOp->IrpReadComplete, 0, FALSE);
+ }
+
//
// free irp context
//
- ExFreePool(IrpContext);
+ ExFreePoolWithTag(IrpContext, HIDCLASS_TAG);
//
// done
//
- return STATUS_SUCCESS;
+ 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
+ //
+ Irp = CONTAINING_RECORD(ListEntry, IRP, Tail.Overlay.ListEntry);
+ }
+
+ //
+ // release lock
+ //
+ KeReleaseSpinLock(&Context->Lock, OldLevel);
+
+ //
+ // done
+ //
+ return Irp;
}
NTSTATUS
PIRP Irp;
PIO_STACK_LOCATION IoStack;
PHIDCLASS_IRP_CONTEXT IrpContext;
+ PHIDCLASS_PDO_DEVICE_EXTENSION PDODeviceExtension;
+ PHIDP_COLLECTION_DESC CollectionDescription;
+ PHIDP_REPORT_IDS ReportDescription;
//
- // build new irp
+ // get an irp from fresh list
//
- Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE);
+ Irp = HidClass_GetIrp(Context);
if (!Irp)
{
//
- // no memory
+ // build new irp
//
- return STATUS_INSUFFICIENT_RESOURCES;
+ Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE);
+ if (!Irp)
+ {
+ //
+ // no memory
+ //
+ return STATUS_INSUFFICIENT_RESOURCES;
+ }
+ }
+ else
+ {
+ //
+ // re-use irp
+ //
+ IoReuseIrp(Irp, STATUS_SUCCESS);
}
//
// allocate completion context
//
- IrpContext = (PHIDCLASS_IRP_CONTEXT)ExAllocatePool(NonPagedPool, sizeof(HIDCLASS_IRP_CONTEXT));
+ IrpContext = ExAllocatePoolWithTag(NonPagedPool, sizeof(HIDCLASS_IRP_CONTEXT), HIDCLASS_TAG);
if (!IrpContext)
{
//
return STATUS_INSUFFICIENT_RESOURCES;
}
+ //
+ // get device extension
+ //
+ PDODeviceExtension = DeviceObject->DeviceExtension;
+ ASSERT(PDODeviceExtension->Common.IsFDO == FALSE);
+
//
// init irp context
//
RtlZeroMemory(IrpContext, sizeof(HIDCLASS_IRP_CONTEXT));
- IrpContext->InputReportBufferLength = BufferLength;
IrpContext->OriginalIrp = RequestIrp;
IrpContext->FileOp = Context;
+ //
+ // get collection description
+ //
+ CollectionDescription = HidClassPDO_GetCollectionDescription(&IrpContext->FileOp->DeviceExtension->Common.DeviceDescription,
+ IrpContext->FileOp->DeviceExtension->CollectionNumber);
+ ASSERT(CollectionDescription);
+
+ //
+ // get report description
+ //
+ ReportDescription = HidClassPDO_GetReportDescription(&IrpContext->FileOp->DeviceExtension->Common.DeviceDescription,
+ IrpContext->FileOp->DeviceExtension->CollectionNumber);
+ ASSERT(ReportDescription);
+
+ //
+ // sanity check
+ //
+ ASSERT(CollectionDescription->InputLength >= ReportDescription->InputLength);
+
+ 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;
+
+ }
+
+ //
+ // store report length
+ //
+ IrpContext->InputReportBufferLength = ReportDescription->InputLength;
+
//
// allocate buffer
//
- IrpContext->InputReportBuffer = ExAllocatePool(NonPagedPool, BufferLength);
+ IrpContext->InputReportBuffer = ExAllocatePoolWithTag(NonPagedPool, IrpContext->InputReportBufferLength, HIDCLASS_TAG);
if (!IrpContext->InputReportBuffer)
{
//
// no memory
//
IoFreeIrp(Irp);
- ExFreePool(IrpContext);
+ ExFreePoolWithTag(IrpContext, HIDCLASS_TAG);
return STATUS_INSUFFICIENT_RESOURCES;
}
*OutIrp = Irp;
*OutIrpContext = IrpContext;
- DPRINT1("IRP %p Buffer %p\n", Irp, Irp->UserBuffer);
-
//
// done
//
return STATUS_SUCCESS;
}
-
NTSTATUS
NTAPI
HidClass_Read(
NTSTATUS Status;
PIRP NewIrp;
PHIDCLASS_IRP_CONTEXT NewIrpContext;
+ PHIDCLASS_COMMON_DEVICE_EXTENSION CommonDeviceExtension;
//
// get current stack location
//
IoStack = IoGetCurrentIrpStackLocation(Irp);
+ //
+ // get device extension
+ //
+ CommonDeviceExtension = DeviceObject->DeviceExtension;
+ ASSERT(CommonDeviceExtension->IsFDO == FALSE);
+
//
// sanity check
//
//
// get context
//
- Context = (PHIDCLASS_FILEOP_CONTEXT)IoStack->FileObject->FsContext;
+ Context = IoStack->FileObject->FsContext;
ASSERT(Context);
//
//
ASSERT(Context->DeviceExtension->Common.DriverExtension->DevicesArePolled == FALSE);
- DPRINT1("[HIDCLASS] IRP_MJ_READ\n");
+ 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;
+ }
//
// build irp request
//
- Status = HidClass_BuildIrp(DeviceObject, Irp, Context, IOCTL_HID_READ_REPORT, IoStack->Parameters.DeviceIoControl.OutputBufferLength, &NewIrp, &NewIrpContext);
+ Status = HidClass_BuildIrp(DeviceObject,
+ Irp,
+ Context,
+ IOCTL_HID_READ_REPORT,
+ IoStack->Parameters.Read.Length,
+ &NewIrp,
+ &NewIrpContext);
if (!NT_SUCCESS(Status))
{
//
IoMarkIrpPending(Irp);
//
- // lets dispatch the request
+ // let's dispatch the request
//
ASSERT(Context->DeviceExtension);
- Status = Context->DeviceExtension->Common.DriverExtension->MajorFunction[IRP_MJ_INTERNAL_DEVICE_CONTROL](DeviceObject, NewIrp);
+ Status = Context->DeviceExtension->Common.DriverExtension->MajorFunction[IRP_MJ_INTERNAL_DEVICE_CONTROL](Context->DeviceExtension->FDODeviceObject, NewIrp);
//
// complete
//
- return Status;
+ return STATUS_PENDING;
}
NTSTATUS
PIO_STACK_LOCATION IoStack;
PHIDCLASS_COMMON_DEVICE_EXTENSION CommonDeviceExtension;
PHID_COLLECTION_INFORMATION CollectionInformation;
+ PHIDP_COLLECTION_DESC CollectionDescription;
+ PHIDCLASS_PDO_DEVICE_EXTENSION PDODeviceExtension;
//
// get device extension
//
- CommonDeviceExtension = (PHIDCLASS_COMMON_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
+ CommonDeviceExtension = DeviceObject->DeviceExtension;
+
+ //
+ // only PDO are supported
+ //
+ if (CommonDeviceExtension->IsFDO)
+ {
+ //
+ // invalid request
+ //
+ DPRINT1("[HIDCLASS] DeviceControl Irp for FDO arrived\n");
+ Irp->IoStatus.Status = STATUS_INVALID_PARAMETER_1;
+ IoCompleteRequest(Irp, IO_NO_INCREMENT);
+ return STATUS_INVALID_PARAMETER_1;
+ }
+
+ ASSERT(CommonDeviceExtension->IsFDO == FALSE);
+
+ //
+ // get pdo device extension
+ //
+ PDODeviceExtension = DeviceObject->DeviceExtension;
//
// get stack location
//
IoStack = IoGetCurrentIrpStackLocation(Irp);
- switch(IoStack->Parameters.DeviceIoControl.IoControlCode)
+ switch (IoStack->Parameters.DeviceIoControl.IoControlCode)
{
case IOCTL_HID_GET_COLLECTION_INFORMATION:
{
//
// get output buffer
//
- CollectionInformation = (PHID_COLLECTION_INFORMATION)Irp->AssociatedIrp.SystemBuffer;
+ CollectionInformation = Irp->AssociatedIrp.SystemBuffer;
ASSERT(CollectionInformation);
+ //
+ // get collection description
+ //
+ CollectionDescription = HidClassPDO_GetCollectionDescription(&CommonDeviceExtension->DeviceDescription,
+ PDODeviceExtension->CollectionNumber);
+ ASSERT(CollectionDescription);
+
//
// init result buffer
//
- CollectionInformation->DescriptorSize = CommonDeviceExtension->DeviceDescription.CollectionDesc[0].PreparsedDataLength; //FIXME which collection is to be retrieved for composite devices / multi collection devices?
+ CollectionInformation->DescriptorSize = CollectionDescription->PreparsedDataLength;
CollectionInformation->Polled = CommonDeviceExtension->DriverExtension->DevicesArePolled;
CollectionInformation->VendorID = CommonDeviceExtension->Attributes.VendorID;
CollectionInformation->ProductID = CommonDeviceExtension->Attributes.ProductID;
case IOCTL_HID_GET_COLLECTION_DESCRIPTOR:
{
//
- // FIXME: which collection to use for composite / multi collection devices...
+ // get collection description
//
+ CollectionDescription = HidClassPDO_GetCollectionDescription(&CommonDeviceExtension->DeviceDescription,
+ PDODeviceExtension->CollectionNumber);
+ ASSERT(CollectionDescription);
//
// check if output buffer is big enough
//
- if (IoStack->Parameters.DeviceIoControl.OutputBufferLength < CommonDeviceExtension->DeviceDescription.CollectionDesc[0].PreparsedDataLength)
+ if (IoStack->Parameters.DeviceIoControl.OutputBufferLength < CollectionDescription->PreparsedDataLength)
{
//
// invalid buffer size
// copy result
//
ASSERT(Irp->UserBuffer);
- RtlCopyMemory(Irp->UserBuffer, CommonDeviceExtension->DeviceDescription.CollectionDesc[0].PreparsedData, CommonDeviceExtension->DeviceDescription.CollectionDesc[0].PreparsedDataLength);
+ RtlCopyMemory(Irp->UserBuffer, CollectionDescription->PreparsedData, CollectionDescription->PreparsedDataLength);
//
// complete request
//
- Irp->IoStatus.Information = CommonDeviceExtension->DeviceDescription.CollectionDesc[0].PreparsedDataLength;
+ Irp->IoStatus.Information = CollectionDescription->PreparsedDataLength;
Irp->IoStatus.Status = STATUS_SUCCESS;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return STATUS_SUCCESS;
{
UNIMPLEMENTED
ASSERT(FALSE);
+ Irp->IoStatus.Status = STATUS_NOT_IMPLEMENTED;
+ IoCompleteRequest(Irp, IO_NO_INCREMENT);
return STATUS_NOT_IMPLEMENTED;
}
-
NTSTATUS
NTAPI
HidClass_Power(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp)
{
- UNIMPLEMENTED
- ASSERT(FALSE);
- return STATUS_NOT_IMPLEMENTED;
+ PHIDCLASS_COMMON_DEVICE_EXTENSION CommonDeviceExtension;
+ CommonDeviceExtension = DeviceObject->DeviceExtension;
+
+ 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;
+ }
}
NTSTATUS
//
// get common device extension
//
- CommonDeviceExtension = (PHIDCLASS_COMMON_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
+ CommonDeviceExtension = DeviceObject->DeviceExtension;
//
// check type of device object
//
// get common device extension
//
- CommonDeviceExtension = (PHIDCLASS_COMMON_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
+ CommonDeviceExtension = DeviceObject->DeviceExtension;
//
// FIXME: support PDO
//
// dispatch to lower device object
//
- return IoCallDriver(CommonDeviceExtension->HidDeviceExtension.NextDeviceObject, Irp);
+ return IoCallDriver(CommonDeviceExtension->HidDeviceExtension.NextDeviceObject, Irp);
}
-
NTSTATUS
NTAPI
HidClassDispatch(
// get current stack location
//
IoStack = IoGetCurrentIrpStackLocation(Irp);
- DPRINT1("[HIDCLASS] Dispatch Major %x Minor %x\n", IoStack->MajorFunction, IoStack->MinorFunction);
+ DPRINT("[HIDCLASS] Dispatch Major %x Minor %x\n", IoStack->MajorFunction, IoStack->MinorFunction);
//
// dispatch request based on major function
//
- switch(IoStack->MajorFunction)
+ switch (IoStack->MajorFunction)
{
case IRP_MJ_CREATE:
return HidClass_Create(DeviceObject, Irp);
}
/* now allocate the driver object extension */
- Status = IoAllocateDriverObjectExtension(MinidriverRegistration->DriverObject, (PVOID)ClientIdentificationAddress, sizeof(HIDCLASS_DRIVER_EXTENSION), (PVOID*)&DriverExtension);
+ Status = IoAllocateDriverObjectExtension(MinidriverRegistration->DriverObject,
+ ClientIdentificationAddress,
+ sizeof(HIDCLASS_DRIVER_EXTENSION),
+ (PVOID *)&DriverExtension);
if (!NT_SUCCESS(Status))
{
/* failed to allocate driver extension */
DriverExtension->DriverUnload = MinidriverRegistration->DriverObject->DriverUnload;
/* copy driver dispatch routines */
- RtlCopyMemory(DriverExtension->MajorFunction, MinidriverRegistration->DriverObject->MajorFunction, sizeof(PDRIVER_DISPATCH) * (IRP_MJ_MAXIMUM_FUNCTION+1));
+ RtlCopyMemory(DriverExtension->MajorFunction,
+ MinidriverRegistration->DriverObject->MajorFunction,
+ sizeof(PDRIVER_DISPATCH) * (IRP_MJ_MAXIMUM_FUNCTION + 1));
/* initialize lock */
KeInitializeSpinLock(&DriverExtension->Lock);