2011-12-31 03:33:14 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS Universal Serial Bus Human Interface Device Driver
|
|
|
|
* LICENSE: GPL - See COPYING in the top level directory
|
|
|
|
* FILE: drivers/hid/hidclass/fdo.c
|
|
|
|
* PURPOSE: HID Class Driver
|
|
|
|
* PROGRAMMERS:
|
|
|
|
* Michael Martin (michael.martin@reactos.org)
|
|
|
|
* Johannes Anderwald (johannes.anderwald@reactos.org)
|
|
|
|
*/
|
2013-05-12 15:23:34 +00:00
|
|
|
|
2011-12-31 03:33:14 +00:00
|
|
|
#include "precomp.h"
|
|
|
|
|
2014-01-03 10:56:03 +00:00
|
|
|
#include <wdmguid.h>
|
|
|
|
|
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
|
|
|
|
2012-01-02 12:00:51 +00:00
|
|
|
PHIDP_COLLECTION_DESC
|
|
|
|
HidClassPDO_GetCollectionDescription(
|
|
|
|
PHIDP_DEVICE_DESC DeviceDescription,
|
|
|
|
ULONG CollectionNumber)
|
|
|
|
{
|
|
|
|
ULONG Index;
|
|
|
|
|
|
|
|
for(Index = 0; Index < DeviceDescription->CollectionDescLength; Index++)
|
|
|
|
{
|
|
|
|
if (DeviceDescription->CollectionDesc[Index].CollectionNumber == CollectionNumber)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// found collection
|
|
|
|
//
|
|
|
|
return &DeviceDescription->CollectionDesc[Index];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// failed to find collection
|
|
|
|
//
|
|
|
|
DPRINT1("[HIDCLASS] GetCollectionDescription CollectionNumber %x not found\n", CollectionNumber);
|
|
|
|
ASSERT(FALSE);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
PHIDP_REPORT_IDS
|
|
|
|
HidClassPDO_GetReportDescription(
|
|
|
|
PHIDP_DEVICE_DESC DeviceDescription,
|
|
|
|
ULONG CollectionNumber)
|
|
|
|
{
|
|
|
|
ULONG Index;
|
|
|
|
|
2013-05-12 15:23:34 +00:00
|
|
|
for (Index = 0; Index < DeviceDescription->ReportIDsLength; Index++)
|
2012-01-02 12:00:51 +00:00
|
|
|
{
|
|
|
|
if (DeviceDescription->ReportIDs[Index].CollectionNumber == CollectionNumber)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// found collection
|
|
|
|
//
|
|
|
|
return &DeviceDescription->ReportIDs[Index];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// failed to find collection
|
|
|
|
//
|
|
|
|
DPRINT1("[HIDCLASS] GetReportDescription CollectionNumber %x not found\n", CollectionNumber);
|
|
|
|
ASSERT(FALSE);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-04-19 20:40:32 +00:00
|
|
|
PHIDP_REPORT_IDS
|
|
|
|
HidClassPDO_GetReportDescriptionByReportID(
|
|
|
|
PHIDP_DEVICE_DESC DeviceDescription,
|
|
|
|
UCHAR ReportID)
|
|
|
|
{
|
|
|
|
ULONG Index;
|
|
|
|
|
|
|
|
for (Index = 0; Index < DeviceDescription->ReportIDsLength; Index++)
|
|
|
|
{
|
|
|
|
if (DeviceDescription->ReportIDs[Index].ReportID == ReportID)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// found report id
|
|
|
|
//
|
|
|
|
return &DeviceDescription->ReportIDs[Index];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// failed to find report id
|
|
|
|
//
|
|
|
|
DPRINT1("[HIDCLASS] GetReportDescriptionByReportID ReportID %x not found\n", ReportID);
|
|
|
|
ASSERT(FALSE);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-12-31 03:33:14 +00:00
|
|
|
NTSTATUS
|
|
|
|
HidClassPDO_HandleQueryDeviceId(
|
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp)
|
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
|
|
|
LPWSTR Buffer;
|
|
|
|
LPWSTR NewBuffer, Ptr;
|
|
|
|
ULONG Length;
|
|
|
|
|
|
|
|
//
|
|
|
|
// copy current stack location
|
|
|
|
//
|
|
|
|
IoCopyCurrentIrpStackLocationToNext(Irp);
|
|
|
|
|
|
|
|
//
|
|
|
|
// call mini-driver
|
|
|
|
//
|
|
|
|
Status = HidClassFDO_DispatchRequestSynchronous(DeviceObject, Irp);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// failed
|
|
|
|
//
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// get buffer
|
|
|
|
//
|
|
|
|
Buffer = (LPWSTR)Irp->IoStatus.Information;
|
|
|
|
Length = wcslen(Buffer);
|
|
|
|
|
|
|
|
//
|
|
|
|
// allocate new buffer
|
|
|
|
//
|
2013-05-12 15:44:58 +00:00
|
|
|
NewBuffer = ExAllocatePoolWithTag(NonPagedPool, (Length + 1) * sizeof(WCHAR), HIDCLASS_TAG);
|
2011-12-31 03:33:14 +00:00
|
|
|
if (!NewBuffer)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// failed to allocate buffer
|
|
|
|
//
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// replace bus
|
|
|
|
//
|
|
|
|
wcscpy(NewBuffer, L"HID\\");
|
|
|
|
|
|
|
|
//
|
|
|
|
// get offset to first '\\'
|
|
|
|
//
|
|
|
|
Ptr = wcschr(Buffer, L'\\');
|
|
|
|
if (Ptr)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// append result
|
|
|
|
//
|
|
|
|
wcscat(NewBuffer, Ptr + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// free old buffer
|
|
|
|
//
|
2013-05-12 15:44:58 +00:00
|
|
|
ExFreePoolWithTag(Buffer, 0);
|
2011-12-31 03:33:14 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// store result
|
|
|
|
//
|
2012-02-12 02:53:34 +00:00
|
|
|
DPRINT("NewBuffer %S\n", NewBuffer);
|
2011-12-31 03:33:14 +00:00
|
|
|
Irp->IoStatus.Information = (ULONG_PTR)NewBuffer;
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
HidClassPDO_HandleQueryHardwareId(
|
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp)
|
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
|
|
|
PHIDCLASS_PDO_DEVICE_EXTENSION PDODeviceExtension;
|
2012-01-30 16:47:39 +00:00
|
|
|
WCHAR Buffer[200];
|
2011-12-31 03:33:14 +00:00
|
|
|
ULONG Offset = 0;
|
|
|
|
LPWSTR Ptr;
|
2012-01-02 12:00:51 +00:00
|
|
|
PHIDP_COLLECTION_DESC CollectionDescription;
|
2011-12-31 03:33:14 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// get device extension
|
|
|
|
//
|
2013-05-12 15:31:01 +00:00
|
|
|
PDODeviceExtension = DeviceObject->DeviceExtension;
|
2013-05-12 15:23:34 +00:00
|
|
|
ASSERT(PDODeviceExtension->Common.IsFDO == FALSE);
|
2011-12-31 03:33:14 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// copy current stack location
|
|
|
|
//
|
|
|
|
IoCopyCurrentIrpStackLocationToNext(Irp);
|
|
|
|
|
|
|
|
//
|
|
|
|
// call mini-driver
|
|
|
|
//
|
|
|
|
Status = HidClassFDO_DispatchRequestSynchronous(DeviceObject, Irp);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// failed
|
|
|
|
//
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2012-01-02 12:00:51 +00:00
|
|
|
if (PDODeviceExtension->Common.DeviceDescription.CollectionDescLength > 1)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// multi-tlc device
|
|
|
|
//
|
|
|
|
Offset = swprintf(&Buffer[Offset], L"HID\\Vid_%04x&Pid_%04x&Rev_%04x&Col%02x", PDODeviceExtension->Common.Attributes.VendorID, PDODeviceExtension->Common.Attributes.ProductID, PDODeviceExtension->Common.Attributes.VersionNumber, PDODeviceExtension->CollectionNumber) + 1;
|
|
|
|
Offset += swprintf(&Buffer[Offset], L"HID\\Vid_%04x&Pid_%04x&Col%02x", PDODeviceExtension->Common.Attributes.VendorID, PDODeviceExtension->Common.Attributes.ProductID, PDODeviceExtension->CollectionNumber) + 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// single tlc device
|
|
|
|
//
|
2012-01-21 17:02:16 +00:00
|
|
|
Offset = swprintf(&Buffer[Offset], L"HID\\Vid_%04x&Pid_%04x&Rev_%04x", PDODeviceExtension->Common.Attributes.VendorID, PDODeviceExtension->Common.Attributes.ProductID, PDODeviceExtension->Common.Attributes.VersionNumber) + 1;
|
|
|
|
Offset += swprintf(&Buffer[Offset], L"HID\\Vid_%04x&Pid_%04x", PDODeviceExtension->Common.Attributes.VendorID, PDODeviceExtension->Common.Attributes.ProductID) + 1;
|
2012-01-02 12:00:51 +00:00
|
|
|
}
|
|
|
|
|
2011-12-31 03:33:14 +00:00
|
|
|
//
|
2012-01-02 12:00:51 +00:00
|
|
|
// get collection description
|
2011-12-31 03:33:14 +00:00
|
|
|
//
|
2012-01-02 12:00:51 +00:00
|
|
|
CollectionDescription = HidClassPDO_GetCollectionDescription(&PDODeviceExtension->Common.DeviceDescription, PDODeviceExtension->CollectionNumber);
|
|
|
|
ASSERT(CollectionDescription);
|
2011-12-31 03:33:14 +00:00
|
|
|
|
2012-01-02 12:00:51 +00:00
|
|
|
if (CollectionDescription->UsagePage == HID_USAGE_PAGE_GENERIC)
|
2011-12-31 03:33:14 +00:00
|
|
|
{
|
2013-05-12 15:23:34 +00:00
|
|
|
switch (CollectionDescription->Usage)
|
2011-12-31 03:33:14 +00:00
|
|
|
{
|
|
|
|
case HID_USAGE_GENERIC_POINTER:
|
|
|
|
case HID_USAGE_GENERIC_MOUSE:
|
|
|
|
//
|
|
|
|
// Pointer / Mouse
|
|
|
|
//
|
|
|
|
Offset += swprintf(&Buffer[Offset], L"HID_DEVICE_SYSTEM_MOUSE") + 1;
|
|
|
|
break;
|
|
|
|
case HID_USAGE_GENERIC_GAMEPAD:
|
|
|
|
case HID_USAGE_GENERIC_JOYSTICK:
|
|
|
|
//
|
|
|
|
// Joystick / Gamepad
|
|
|
|
//
|
|
|
|
Offset += swprintf(&Buffer[Offset], L"HID_DEVICE_SYSTEM_GAME") + 1;
|
|
|
|
break;
|
|
|
|
case HID_USAGE_GENERIC_KEYBOARD:
|
|
|
|
case HID_USAGE_GENERIC_KEYPAD:
|
|
|
|
//
|
|
|
|
// Keyboard / Keypad
|
|
|
|
//
|
|
|
|
Offset += swprintf(&Buffer[Offset], L"HID_DEVICE_SYSTEM_KEYBOARD") + 1;
|
|
|
|
break;
|
|
|
|
case HID_USAGE_GENERIC_SYSTEM_CTL:
|
|
|
|
//
|
|
|
|
// System Control
|
|
|
|
//
|
|
|
|
Offset += swprintf(&Buffer[Offset], L"HID_DEVICE_SYSTEM_CONTROL") + 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-01-02 12:00:51 +00:00
|
|
|
else if (CollectionDescription->UsagePage == HID_USAGE_PAGE_CONSUMER && CollectionDescription->Usage == HID_USAGE_CONSUMERCTRL)
|
2011-12-31 03:33:14 +00:00
|
|
|
{
|
|
|
|
//
|
|
|
|
// Consumer Audio Control
|
|
|
|
//
|
|
|
|
Offset += swprintf(&Buffer[Offset], L"HID_DEVICE_SYSTEM_CONSUMER") + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2012-02-02 18:10:11 +00:00
|
|
|
// add HID_DEVICE_UP:0001_U:0002'
|
2011-12-31 03:33:14 +00:00
|
|
|
//
|
2012-02-02 18:10:11 +00:00
|
|
|
Offset += swprintf(&Buffer[Offset], L"HID_DEVICE_UP:%04x_U:%04x", CollectionDescription->UsagePage, CollectionDescription->Usage) + 1;
|
2011-12-31 03:33:14 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// add HID
|
|
|
|
//
|
|
|
|
Offset +=swprintf(&Buffer[Offset], L"HID_DEVICE") + 1;
|
|
|
|
|
|
|
|
//
|
|
|
|
// free old buffer
|
|
|
|
//
|
2013-05-12 15:44:58 +00:00
|
|
|
ExFreePoolWithTag((PVOID)Irp->IoStatus.Information, 0);
|
2011-12-31 03:33:14 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// allocate buffer
|
|
|
|
//
|
2013-05-12 15:44:58 +00:00
|
|
|
Ptr = ExAllocatePoolWithTag(NonPagedPool, (Offset + 1) * sizeof(WCHAR), HIDCLASS_TAG);
|
2011-12-31 03:33:14 +00:00
|
|
|
if (!Ptr)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// no memory
|
|
|
|
//
|
|
|
|
Irp->IoStatus.Information = 0;
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// copy buffer
|
|
|
|
//
|
|
|
|
RtlCopyMemory(Ptr, Buffer, Offset * sizeof(WCHAR));
|
|
|
|
Ptr[Offset] = UNICODE_NULL;
|
|
|
|
|
|
|
|
//
|
|
|
|
// store result
|
|
|
|
//
|
|
|
|
Irp->IoStatus.Information = (ULONG_PTR)Ptr;
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
HidClassPDO_HandleQueryInstanceId(
|
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp)
|
|
|
|
{
|
2012-01-30 16:47:39 +00:00
|
|
|
LPWSTR Buffer;
|
|
|
|
PHIDCLASS_PDO_DEVICE_EXTENSION PDODeviceExtension;
|
2011-12-31 03:33:14 +00:00
|
|
|
|
|
|
|
//
|
2012-01-30 16:47:39 +00:00
|
|
|
// get device extension
|
2011-12-31 03:33:14 +00:00
|
|
|
//
|
2013-05-12 15:31:01 +00:00
|
|
|
PDODeviceExtension = DeviceObject->DeviceExtension;
|
2013-05-12 15:23:34 +00:00
|
|
|
ASSERT(PDODeviceExtension->Common.IsFDO == FALSE);
|
2011-12-31 03:33:14 +00:00
|
|
|
|
|
|
|
//
|
2012-01-30 16:47:39 +00:00
|
|
|
// allocate buffer
|
2011-12-31 03:33:14 +00:00
|
|
|
//
|
2013-05-12 15:44:58 +00:00
|
|
|
Buffer = ExAllocatePoolWithTag(NonPagedPool, 5 * sizeof(WCHAR), HIDCLASS_TAG);
|
2012-01-30 16:47:39 +00:00
|
|
|
if (!Buffer)
|
2011-12-31 03:33:14 +00:00
|
|
|
{
|
|
|
|
//
|
|
|
|
// failed
|
|
|
|
//
|
2012-01-30 16:47:39 +00:00
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
2011-12-31 03:33:14 +00:00
|
|
|
}
|
2012-01-30 16:47:39 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// write device id
|
|
|
|
//
|
|
|
|
swprintf(Buffer, L"%04x", PDODeviceExtension->CollectionNumber);
|
|
|
|
Irp->IoStatus.Information = (ULONG_PTR)Buffer;
|
|
|
|
|
|
|
|
//
|
|
|
|
// done
|
|
|
|
//
|
|
|
|
return STATUS_SUCCESS;
|
2011-12-31 03:33:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
HidClassPDO_HandleQueryCompatibleId(
|
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp)
|
|
|
|
{
|
2012-01-05 18:22:48 +00:00
|
|
|
LPWSTR Buffer;
|
2011-12-31 03:33:14 +00:00
|
|
|
|
2013-05-12 15:44:58 +00:00
|
|
|
Buffer = ExAllocatePoolWithTag(NonPagedPool, 2 * sizeof(WCHAR), HIDCLASS_TAG);
|
2012-01-05 18:22:48 +00:00
|
|
|
if (!Buffer)
|
2011-12-31 03:33:14 +00:00
|
|
|
{
|
|
|
|
//
|
2012-01-05 18:22:48 +00:00
|
|
|
// no memory
|
2011-12-31 03:33:14 +00:00
|
|
|
//
|
2012-01-05 18:22:48 +00:00
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
2011-12-31 03:33:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2012-01-05 18:22:48 +00:00
|
|
|
// zero buffer
|
|
|
|
//
|
|
|
|
Buffer[0] = 0;
|
|
|
|
Buffer[1] = 0;
|
|
|
|
|
|
|
|
//
|
|
|
|
// store result
|
2011-12-31 03:33:14 +00:00
|
|
|
//
|
2012-01-05 18:22:48 +00:00
|
|
|
Irp->IoStatus.Information = (ULONG_PTR)Buffer;
|
|
|
|
return STATUS_SUCCESS;
|
2011-12-31 03:33:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
HidClassPDO_PnP(
|
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp)
|
|
|
|
{
|
|
|
|
PHIDCLASS_PDO_DEVICE_EXTENSION PDODeviceExtension;
|
|
|
|
PIO_STACK_LOCATION IoStack;
|
|
|
|
NTSTATUS Status;
|
|
|
|
PPNP_BUS_INFORMATION BusInformation;
|
|
|
|
PDEVICE_RELATIONS DeviceRelation;
|
2012-02-05 15:36:00 +00:00
|
|
|
ULONG Index, bFound;
|
2011-12-31 03:33:14 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// get device extension
|
|
|
|
//
|
2013-05-12 15:31:01 +00:00
|
|
|
PDODeviceExtension = DeviceObject->DeviceExtension;
|
2011-12-31 03:33:14 +00:00
|
|
|
ASSERT(PDODeviceExtension->Common.IsFDO == FALSE);
|
|
|
|
|
|
|
|
//
|
|
|
|
// get current irp stack location
|
|
|
|
//
|
|
|
|
IoStack = IoGetCurrentIrpStackLocation(Irp);
|
|
|
|
|
|
|
|
//
|
|
|
|
// handle request
|
|
|
|
//
|
2013-05-12 15:23:34 +00:00
|
|
|
switch (IoStack->MinorFunction)
|
2011-12-31 03:33:14 +00:00
|
|
|
{
|
|
|
|
case IRP_MN_QUERY_ID:
|
|
|
|
{
|
2013-05-12 15:23:34 +00:00
|
|
|
if (IoStack->Parameters.QueryId.IdType == BusQueryDeviceID)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// handle query device id
|
|
|
|
//
|
|
|
|
Status = HidClassPDO_HandleQueryDeviceId(DeviceObject, Irp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (IoStack->Parameters.QueryId.IdType == BusQueryHardwareIDs)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// handle instance id
|
|
|
|
//
|
|
|
|
Status = HidClassPDO_HandleQueryHardwareId(DeviceObject, Irp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (IoStack->Parameters.QueryId.IdType == BusQueryInstanceID)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// handle instance id
|
|
|
|
//
|
|
|
|
Status = HidClassPDO_HandleQueryInstanceId(DeviceObject, Irp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (IoStack->Parameters.QueryId.IdType == BusQueryCompatibleIDs)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// handle instance id
|
|
|
|
//
|
|
|
|
Status = HidClassPDO_HandleQueryCompatibleId(DeviceObject, Irp);
|
|
|
|
break;
|
|
|
|
}
|
2013-05-12 15:31:01 +00:00
|
|
|
|
2013-05-12 15:23:34 +00:00
|
|
|
DPRINT1("[HIDCLASS]: IRP_MN_QUERY_ID IdType %x unimplemented\n", IoStack->Parameters.QueryId.IdType);
|
|
|
|
Status = STATUS_NOT_SUPPORTED;
|
|
|
|
Irp->IoStatus.Information = 0;
|
|
|
|
break;
|
2011-12-31 03:33:14 +00:00
|
|
|
}
|
|
|
|
case IRP_MN_QUERY_CAPABILITIES:
|
|
|
|
{
|
|
|
|
if (IoStack->Parameters.DeviceCapabilities.Capabilities == NULL)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// invalid request
|
|
|
|
//
|
|
|
|
Status = STATUS_DEVICE_CONFIGURATION_ERROR;
|
2012-06-06 15:41:08 +00:00
|
|
|
break;
|
2011-12-31 03:33:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// copy capabilities
|
|
|
|
//
|
2013-05-12 15:23:34 +00:00
|
|
|
RtlCopyMemory(IoStack->Parameters.DeviceCapabilities.Capabilities,
|
|
|
|
&PDODeviceExtension->Capabilities,
|
|
|
|
sizeof(DEVICE_CAPABILITIES));
|
2011-12-31 03:33:14 +00:00
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case IRP_MN_QUERY_BUS_INFORMATION:
|
|
|
|
{
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
2013-05-12 15:44:58 +00:00
|
|
|
BusInformation = ExAllocatePoolWithTag(NonPagedPool, sizeof(PNP_BUS_INFORMATION), HIDCLASS_TAG);
|
2013-05-12 15:23:34 +00:00
|
|
|
|
2011-12-31 03:33:14 +00:00
|
|
|
//
|
|
|
|
// fill in result
|
|
|
|
//
|
|
|
|
RtlCopyMemory(&BusInformation->BusTypeGuid, &GUID_BUS_TYPE_HID, sizeof(GUID));
|
|
|
|
BusInformation->LegacyBusType = PNPBus;
|
|
|
|
BusInformation->BusNumber = 0; //FIXME
|
|
|
|
|
|
|
|
//
|
|
|
|
// store result
|
|
|
|
//
|
|
|
|
Irp->IoStatus.Information = (ULONG_PTR)BusInformation;
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case IRP_MN_QUERY_PNP_DEVICE_STATE:
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// FIXME set flags when driver fails / disabled
|
|
|
|
//
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case IRP_MN_QUERY_DEVICE_RELATIONS:
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// only target relations are supported
|
|
|
|
//
|
|
|
|
if (IoStack->Parameters.QueryDeviceRelations.Type != TargetDeviceRelation)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// not supported
|
|
|
|
//
|
|
|
|
Status = Irp->IoStatus.Status;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// allocate device relations
|
|
|
|
//
|
2013-05-12 15:44:58 +00:00
|
|
|
DeviceRelation = ExAllocatePoolWithTag(NonPagedPool, sizeof(DEVICE_RELATIONS), HIDCLASS_TAG);
|
2011-12-31 03:33:14 +00:00
|
|
|
if (!DeviceRelation)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// no memory
|
|
|
|
//
|
|
|
|
Status = STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// init device relation
|
|
|
|
//
|
|
|
|
DeviceRelation->Count = 1;
|
|
|
|
DeviceRelation->Objects[0] = DeviceObject;
|
|
|
|
ObReferenceObject(DeviceRelation->Objects[0]);
|
|
|
|
|
|
|
|
//
|
|
|
|
// store result
|
|
|
|
//
|
|
|
|
Irp->IoStatus.Information = (ULONG_PTR)DeviceRelation;
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case IRP_MN_START_DEVICE:
|
|
|
|
{
|
2011-12-31 04:13:37 +00:00
|
|
|
//
|
|
|
|
// FIXME: support polled devices
|
|
|
|
//
|
|
|
|
ASSERT(PDODeviceExtension->Common.DriverExtension->DevicesArePolled == FALSE);
|
2011-12-31 03:33:14 +00:00
|
|
|
|
|
|
|
//
|
2011-12-31 04:13:37 +00:00
|
|
|
// now register the device interface
|
|
|
|
//
|
2013-05-12 15:23:34 +00:00
|
|
|
Status = IoRegisterDeviceInterface(PDODeviceExtension->Common.HidDeviceExtension.PhysicalDeviceObject,
|
|
|
|
&GUID_DEVINTERFACE_HID,
|
|
|
|
NULL,
|
|
|
|
&PDODeviceExtension->DeviceInterface);
|
2012-02-12 02:53:34 +00:00
|
|
|
DPRINT("[HIDCLASS] IoRegisterDeviceInterfaceState Status %x\n", Status);
|
2011-12-31 04:13:37 +00:00
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// enable device interface
|
|
|
|
//
|
|
|
|
Status = IoSetDeviceInterfaceState(&PDODeviceExtension->DeviceInterface, TRUE);
|
2012-02-12 02:53:34 +00:00
|
|
|
DPRINT("[HIDCLASS] IoSetDeviceInterFaceState %x\n", Status);
|
2011-12-31 04:13:37 +00:00
|
|
|
}
|
2012-02-02 17:42:55 +00:00
|
|
|
|
2011-12-31 04:13:37 +00:00
|
|
|
//
|
2012-02-02 17:42:55 +00:00
|
|
|
// done
|
2011-12-31 03:33:14 +00:00
|
|
|
//
|
2012-02-02 17:42:55 +00:00
|
|
|
Status = STATUS_SUCCESS;
|
2011-12-31 03:33:14 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case IRP_MN_REMOVE_DEVICE:
|
|
|
|
{
|
2012-01-26 03:27:22 +00:00
|
|
|
/* Disable the device interface */
|
|
|
|
if (PDODeviceExtension->DeviceInterface.Length != 0)
|
|
|
|
IoSetDeviceInterfaceState(&PDODeviceExtension->DeviceInterface, FALSE);
|
2011-12-31 03:33:14 +00:00
|
|
|
|
2013-05-12 15:23:34 +00:00
|
|
|
//
|
|
|
|
// remove us from the fdo's pdo list
|
|
|
|
//
|
|
|
|
bFound = FALSE;
|
|
|
|
for (Index = 0; Index < PDODeviceExtension->FDODeviceExtension->DeviceRelations->Count; Index++)
|
|
|
|
{
|
|
|
|
if (PDODeviceExtension->FDODeviceExtension->DeviceRelations->Objects[Index] == DeviceObject)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// remove us
|
|
|
|
//
|
|
|
|
bFound = TRUE;
|
|
|
|
PDODeviceExtension->FDODeviceExtension->DeviceRelations->Objects[Index] = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-02-04 14:10:18 +00:00
|
|
|
|
2012-01-26 03:27:22 +00:00
|
|
|
/* Complete the IRP */
|
|
|
|
Irp->IoStatus.Status = STATUS_SUCCESS;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
|
2012-02-05 15:36:00 +00:00
|
|
|
if (bFound)
|
|
|
|
{
|
|
|
|
/* Delete our device object*/
|
|
|
|
IoDeleteDevice(DeviceObject);
|
|
|
|
}
|
2012-01-26 03:27:22 +00:00
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
2011-12-31 03:33:14 +00:00
|
|
|
}
|
|
|
|
case IRP_MN_QUERY_INTERFACE:
|
|
|
|
{
|
|
|
|
DPRINT1("[HIDCLASS] PDO IRP_MN_QUERY_INTERFACE not implemented\n");
|
|
|
|
|
|
|
|
//
|
|
|
|
// do nothing
|
|
|
|
//
|
|
|
|
Status = Irp->IoStatus.Status;
|
|
|
|
break;
|
|
|
|
}
|
2012-02-04 14:10:18 +00:00
|
|
|
case IRP_MN_QUERY_REMOVE_DEVICE:
|
|
|
|
case IRP_MN_CANCEL_STOP_DEVICE:
|
|
|
|
case IRP_MN_QUERY_STOP_DEVICE:
|
|
|
|
case IRP_MN_CANCEL_REMOVE_DEVICE:
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// no/op
|
|
|
|
//
|
2012-02-23 01:23:30 +00:00
|
|
|
#if 0
|
2012-02-04 14:10:18 +00:00
|
|
|
Status = STATUS_SUCCESS;
|
2012-02-23 01:23:30 +00:00
|
|
|
#else
|
|
|
|
DPRINT1("Denying removal of HID device due to IRP cancellation bugs\n");
|
|
|
|
Status = STATUS_UNSUCCESSFUL;
|
|
|
|
#endif
|
2012-02-04 14:10:18 +00:00
|
|
|
break;
|
|
|
|
}
|
2011-12-31 03:33:14 +00:00
|
|
|
default:
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// do nothing
|
|
|
|
//
|
|
|
|
Status = Irp->IoStatus.Status;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// complete request
|
|
|
|
//
|
|
|
|
if (Status != STATUS_PENDING)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// store result
|
|
|
|
//
|
|
|
|
Irp->IoStatus.Status = Status;
|
|
|
|
|
|
|
|
//
|
|
|
|
// complete request
|
|
|
|
//
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// done processing
|
|
|
|
//
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
HidClassPDO_CreatePDO(
|
2012-01-02 12:00:51 +00:00
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
OUT PDEVICE_RELATIONS *OutDeviceRelations)
|
2011-12-31 03:33:14 +00:00
|
|
|
{
|
|
|
|
PHIDCLASS_FDO_EXTENSION FDODeviceExtension;
|
2015-06-24 10:13:15 +00:00
|
|
|
NTSTATUS Status = STATUS_SUCCESS;
|
2011-12-31 03:33:14 +00:00
|
|
|
PDEVICE_OBJECT PDODeviceObject;
|
|
|
|
PHIDCLASS_PDO_DEVICE_EXTENSION PDODeviceExtension;
|
2012-01-02 12:00:51 +00:00
|
|
|
ULONG Index;
|
|
|
|
PDEVICE_RELATIONS DeviceRelations;
|
|
|
|
ULONG Length;
|
2011-12-31 03:33:14 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// get device extension
|
|
|
|
//
|
2013-05-12 15:31:01 +00:00
|
|
|
FDODeviceExtension = DeviceObject->DeviceExtension;
|
2011-12-31 03:33:14 +00:00
|
|
|
ASSERT(FDODeviceExtension->Common.IsFDO);
|
|
|
|
|
|
|
|
//
|
2012-01-02 12:00:51 +00:00
|
|
|
// first allocate device relations
|
2011-12-31 03:33:14 +00:00
|
|
|
//
|
2017-04-14 09:55:17 +00:00
|
|
|
Length = FIELD_OFFSET(DEVICE_RELATIONS, Objects) + sizeof(PDEVICE_OBJECT) * FDODeviceExtension->Common.DeviceDescription.CollectionDescLength;
|
|
|
|
DeviceRelations = ExAllocatePoolWithTag(PagedPool, Length, HIDCLASS_TAG);
|
2012-01-02 12:00:51 +00:00
|
|
|
if (!DeviceRelations)
|
2011-12-31 03:33:14 +00:00
|
|
|
{
|
|
|
|
//
|
2012-01-02 12:00:51 +00:00
|
|
|
// no memory
|
2011-12-31 03:33:14 +00:00
|
|
|
//
|
2012-01-02 12:00:51 +00:00
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
2011-12-31 03:33:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2012-01-02 12:00:51 +00:00
|
|
|
// zero device relations
|
2011-12-31 03:33:14 +00:00
|
|
|
//
|
2012-01-02 12:00:51 +00:00
|
|
|
RtlZeroMemory(DeviceRelations, Length);
|
2011-12-31 03:33:14 +00:00
|
|
|
|
|
|
|
//
|
2013-05-12 15:23:34 +00:00
|
|
|
// let's create a PDO for top level collection
|
2011-12-31 03:33:14 +00:00
|
|
|
//
|
2012-01-02 12:00:51 +00:00
|
|
|
Index = 0;
|
2015-06-24 10:58:39 +00:00
|
|
|
while (Index < FDODeviceExtension->Common.DeviceDescription.CollectionDescLength)
|
2012-01-02 12:00:51 +00:00
|
|
|
{
|
2015-06-24 10:58:39 +00:00
|
|
|
//
|
2013-05-12 15:23:34 +00:00
|
|
|
// let's create the device object
|
2012-01-02 12:00:51 +00:00
|
|
|
//
|
2013-05-12 15:23:34 +00:00
|
|
|
Status = IoCreateDevice(FDODeviceExtension->Common.DriverExtension->DriverObject,
|
|
|
|
sizeof(HIDCLASS_PDO_DEVICE_EXTENSION),
|
|
|
|
NULL,
|
|
|
|
FILE_DEVICE_UNKNOWN,
|
|
|
|
FILE_AUTOGENERATED_DEVICE_NAME,
|
|
|
|
FALSE,
|
|
|
|
&PDODeviceObject);
|
2012-01-02 12:00:51 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// failed to create device
|
|
|
|
//
|
|
|
|
DPRINT1("[HIDCLASS] Failed to create PDO %x\n", Status);
|
|
|
|
break;
|
|
|
|
}
|
2011-12-31 03:33:14 +00:00
|
|
|
|
2012-01-02 12:00:51 +00:00
|
|
|
//
|
|
|
|
// patch stack size
|
|
|
|
//
|
|
|
|
PDODeviceObject->StackSize = DeviceObject->StackSize + 1;
|
2011-12-31 03:33:14 +00:00
|
|
|
|
2012-01-02 12:00:51 +00:00
|
|
|
//
|
|
|
|
// get device extension
|
|
|
|
//
|
2013-05-12 15:31:01 +00:00
|
|
|
PDODeviceExtension = PDODeviceObject->DeviceExtension;
|
2012-01-02 12:00:51 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// init device extension
|
|
|
|
//
|
|
|
|
PDODeviceExtension->Common.HidDeviceExtension.MiniDeviceExtension = FDODeviceExtension->Common.HidDeviceExtension.MiniDeviceExtension;
|
|
|
|
PDODeviceExtension->Common.HidDeviceExtension.NextDeviceObject = FDODeviceExtension->Common.HidDeviceExtension.NextDeviceObject;
|
|
|
|
PDODeviceExtension->Common.HidDeviceExtension.PhysicalDeviceObject = FDODeviceExtension->Common.HidDeviceExtension.PhysicalDeviceObject;
|
|
|
|
PDODeviceExtension->Common.IsFDO = FALSE;
|
2012-02-04 14:10:18 +00:00
|
|
|
PDODeviceExtension->FDODeviceExtension = FDODeviceExtension;
|
2012-01-02 12:00:51 +00:00
|
|
|
PDODeviceExtension->FDODeviceObject = DeviceObject;
|
|
|
|
PDODeviceExtension->Common.DriverExtension = FDODeviceExtension->Common.DriverExtension;
|
|
|
|
PDODeviceExtension->CollectionNumber = FDODeviceExtension->Common.DeviceDescription.CollectionDesc[Index].CollectionNumber;
|
|
|
|
|
|
|
|
//
|
|
|
|
// copy device data
|
|
|
|
//
|
|
|
|
RtlCopyMemory(&PDODeviceExtension->Common.Attributes, &FDODeviceExtension->Common.Attributes, sizeof(HID_DEVICE_ATTRIBUTES));
|
|
|
|
RtlCopyMemory(&PDODeviceExtension->Common.DeviceDescription, &FDODeviceExtension->Common.DeviceDescription, sizeof(HIDP_DEVICE_DESC));
|
|
|
|
RtlCopyMemory(&PDODeviceExtension->Capabilities, &FDODeviceExtension->Capabilities, sizeof(DEVICE_CAPABILITIES));
|
|
|
|
|
|
|
|
//
|
|
|
|
// set device flags
|
|
|
|
//
|
|
|
|
PDODeviceObject->Flags |= DO_MAP_IO_BUFFER;
|
|
|
|
|
|
|
|
//
|
|
|
|
// device is initialized
|
|
|
|
//
|
|
|
|
PDODeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
|
|
|
|
|
|
|
|
//
|
|
|
|
// store device object in device relations
|
|
|
|
//
|
|
|
|
DeviceRelations->Objects[Index] = PDODeviceObject;
|
|
|
|
DeviceRelations->Count++;
|
|
|
|
|
|
|
|
//
|
|
|
|
// move to next
|
2013-05-12 15:23:34 +00:00
|
|
|
//
|
2012-01-02 12:00:51 +00:00
|
|
|
Index++;
|
|
|
|
|
2015-06-24 10:13:15 +00:00
|
|
|
}
|
2011-12-31 03:33:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
//
|
2012-01-02 12:00:51 +00:00
|
|
|
// check if creating succeeded
|
2011-12-31 03:33:14 +00:00
|
|
|
//
|
2012-01-02 12:00:51 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// failed
|
|
|
|
//
|
2013-05-12 15:23:34 +00:00
|
|
|
for (Index = 0; Index < DeviceRelations->Count; Index++)
|
2012-01-02 12:00:51 +00:00
|
|
|
{
|
|
|
|
//
|
|
|
|
// delete device
|
|
|
|
//
|
|
|
|
IoDeleteDevice(DeviceRelations->Objects[Index]);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// free device relations
|
|
|
|
//
|
2013-05-12 15:44:58 +00:00
|
|
|
ExFreePoolWithTag(DeviceRelations, HIDCLASS_TAG);
|
2012-01-02 12:00:51 +00:00
|
|
|
return Status;
|
|
|
|
}
|
2011-12-31 03:33:14 +00:00
|
|
|
|
|
|
|
//
|
2012-01-02 12:00:51 +00:00
|
|
|
// store device relations
|
2011-12-31 03:33:14 +00:00
|
|
|
//
|
2012-01-02 12:00:51 +00:00
|
|
|
*OutDeviceRelations = DeviceRelations;
|
2011-12-31 03:33:14 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// done
|
|
|
|
//
|
|
|
|
return STATUS_SUCCESS;
|
2013-05-12 15:23:34 +00:00
|
|
|
}
|