#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));
//
// get device extension
//
- CommonDeviceExtension = (PHIDCLASS_COMMON_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
+ CommonDeviceExtension = DeviceObject->DeviceExtension;
if (CommonDeviceExtension->IsFDO)
{
#ifndef __REACTOS__
//
// get device extension
//
- PDODeviceExtension = (PHIDCLASS_PDO_DEVICE_EXTENSION)CommonDeviceExtension;
+ PDODeviceExtension = DeviceObject->DeviceExtension;
//
// get stack location
//
// allocate context
//
- Context = (PHIDCLASS_FILEOP_CONTEXT)ExAllocatePool(NonPagedPool, sizeof(HIDCLASS_FILEOP_CONTEXT));
+ Context = ExAllocatePoolWithTag(NonPagedPool, sizeof(HIDCLASS_FILEOP_CONTEXT), HIDCLASS_TAG);
if (!Context)
{
//
// store context
//
ASSERT(IoStack->FileObject);
- IoStack->FileObject->FsContext = (PVOID)Context;
+ IoStack->FileObject->FsContext = Context;
//
// done
//
// get device extension
//
- CommonDeviceExtension = (PHIDCLASS_COMMON_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
+ CommonDeviceExtension = DeviceObject->DeviceExtension;
//
// is it a FDO request
//
// get irp context
//
- IrpContext = (PHIDCLASS_FILEOP_CONTEXT)IoStack->FileObject->FsContext;
+ IrpContext = IoStack->FileObject->FsContext;
ASSERT(IrpContext);
//
//
// now free all irps
//
- while(!IsListEmpty(&IrpContext->IrpCompletedListHead))
+ while (!IsListEmpty(&IrpContext->IrpCompletedListHead))
{
//
// remove head irp
//
// get irp
//
- ListIrp = (PIRP)CONTAINING_RECORD(Entry, IRP, Tail.Overlay.ListEntry);
+ ListIrp = CONTAINING_RECORD(Entry, IRP, Tail.Overlay.ListEntry);
//
// free the irp
//
KeReleaseSpinLock(&IrpContext->Lock, OldLevel);
-
-
-
//
// remove context
//
//
// free context
//
- ExFreePool(IrpContext);
+ ExFreePoolWithTag(IrpContext, HIDCLASS_TAG);
//
// complete request
return STATUS_SUCCESS;
}
-PVOID
-HidClass_GetSystemAddress(
- IN PMDL ReportMDL)
-{
- //
- // sanity check
- //
- ASSERT(ReportMDL);
-
- if (ReportMDL->MdlFlags & (MDL_SOURCE_IS_NONPAGED_POOL | MDL_MAPPED_TO_SYSTEM_VA))
- {
- //
- // buffer is non paged pool
- //
- return ReportMDL->MappedSystemVa;
- }
- else
- {
- //
- // map mdl
- //
- return MmMapLockedPages(ReportMDL, KernelMode);
- }
-}
-
NTSTATUS
NTAPI
HidClass_ReadCompleteIrp(
//
// get irp context
//
- IrpContext = (PHIDCLASS_IRP_CONTEXT)Ctx;
+ IrpContext = Ctx;
DPRINT("HidClass_ReadCompleteIrp Irql %lu\n", KeGetCurrentIrql());
DPRINT("HidClass_ReadCompleteIrp Status %lx\n", Irp->IoStatus.Status);
//
// get address
//
- Address = (PUCHAR)HidClass_GetSystemAddress(IrpContext->OriginalIrp->MdlAddress);
+ Address = MmGetSystemAddressForMdlSafe(IrpContext->OriginalIrp->MdlAddress, NormalPagePriority);
if (Address)
{
//
//
// get collection description
//
- CollectionDescription = HidClassPDO_GetCollectionDescription(&IrpContext->FileOp->DeviceExtension->Common.DeviceDescription, IrpContext->FileOp->DeviceExtension->CollectionNumber);
+ 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);
+ ReportDescription = HidClassPDO_GetReportDescription(&IrpContext->FileOp->DeviceExtension->Common.DeviceDescription,
+ IrpContext->FileOp->DeviceExtension->CollectionNumber);
ASSERT(ReportDescription);
if (CollectionDescription && ReportDescription)
// 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);
+ ExFreePoolWithTag(IrpContext->InputReportBuffer, HIDCLASS_TAG);
//
// remove us from pending list
//
// free irp context
//
- ExFreePool(IrpContext);
+ ExFreePoolWithTag(IrpContext, HIDCLASS_TAG);
//
// done
//
// get irp
//
- Irp = (PIRP)CONTAINING_RECORD(ListEntry, IRP, Tail.Overlay.ListEntry);
+ Irp = CONTAINING_RECORD(ListEntry, IRP, Tail.Overlay.ListEntry);
}
//
//
// allocate completion context
//
- IrpContext = (PHIDCLASS_IRP_CONTEXT)ExAllocatePool(NonPagedPool, sizeof(HIDCLASS_IRP_CONTEXT));
+ IrpContext = ExAllocatePoolWithTag(NonPagedPool, sizeof(HIDCLASS_IRP_CONTEXT), HIDCLASS_TAG);
if (!IrpContext)
{
//
//
// get device extension
//
- PDODeviceExtension = (PHIDCLASS_PDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
+ PDODeviceExtension = DeviceObject->DeviceExtension;
ASSERT(PDODeviceExtension->Common.IsFDO == FALSE);
//
//
// get collection description
//
- CollectionDescription = HidClassPDO_GetCollectionDescription(&IrpContext->FileOp->DeviceExtension->Common.DeviceDescription, IrpContext->FileOp->DeviceExtension->CollectionNumber);
+ 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);
+ ReportDescription = HidClassPDO_GetReportDescription(&IrpContext->FileOp->DeviceExtension->Common.DeviceDescription,
+ IrpContext->FileOp->DeviceExtension->CollectionNumber);
ASSERT(ReportDescription);
//
}
-
//
// store report length
//
//
// allocate buffer
//
- IrpContext->InputReportBuffer = ExAllocatePool(NonPagedPool, IrpContext->InputReportBufferLength);
+ 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;
}
return STATUS_SUCCESS;
}
-
NTSTATUS
NTAPI
HidClass_Read(
//
// get device extension
//
- CommonDeviceExtension = (PHIDCLASS_COMMON_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
+ CommonDeviceExtension = DeviceObject->DeviceExtension;
ASSERT(CommonDeviceExtension->IsFDO == FALSE);
//
//
// get context
//
- Context = (PHIDCLASS_FILEOP_CONTEXT)IoStack->FileObject->FsContext;
+ Context = IoStack->FileObject->FsContext;
ASSERT(Context);
//
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;
-
+ //
+ // 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.Read.Length, &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](Context->DeviceExtension->FDODeviceObject, NewIrp);
//
// get device extension
//
- CommonDeviceExtension = (PHIDCLASS_COMMON_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
+ CommonDeviceExtension = DeviceObject->DeviceExtension;
//
// only PDO are supported
// invalid request
//
DPRINT1("[HIDCLASS] DeviceControl Irp for FDO arrived\n");
- Irp->IoStatus.Status = STATUS_INVALID_PARAMETER;
+ Irp->IoStatus.Status = STATUS_INVALID_PARAMETER_1;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return STATUS_INVALID_PARAMETER_1;
}
//
// get pdo device extension
//
- PDODeviceExtension = (PHIDCLASS_PDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
+ 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);
+ CollectionDescription = HidClassPDO_GetCollectionDescription(&CommonDeviceExtension->DeviceDescription,
+ PDODeviceExtension->CollectionNumber);
ASSERT(CollectionDescription);
//
//
// get collection description
//
- CollectionDescription = HidClassPDO_GetCollectionDescription(&CommonDeviceExtension->DeviceDescription, PDODeviceExtension->CollectionNumber);
+ CollectionDescription = HidClassPDO_GetCollectionDescription(&CommonDeviceExtension->DeviceDescription,
+ PDODeviceExtension->CollectionNumber);
ASSERT(CollectionDescription);
//
return STATUS_NOT_IMPLEMENTED;
}
-
NTSTATUS
NTAPI
HidClass_Power(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp)
{
- UNIMPLEMENTED
- 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
return IoCallDriver(CommonDeviceExtension->HidDeviceExtension.NextDeviceObject, Irp);
}
-
NTSTATUS
NTAPI
HidClassDispatch(
//
// 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);