2015-09-09 17:20:11 +02:00
|
|
|
/*
|
2021-04-16 04:03:58 +02:00
|
|
|
* Human Interface Device class driver
|
2015-09-09 17:20:11 +02:00
|
|
|
*
|
|
|
|
* Copyright 2015 Aric Stewart
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define NONAMELESSUNION
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include "hid.h"
|
2021-04-16 04:04:01 +02:00
|
|
|
#include "ntddmou.h"
|
2021-04-22 21:26:51 +02:00
|
|
|
#include "ntddkbd.h"
|
2015-09-09 17:20:11 +02:00
|
|
|
#include "ddk/hidtypes.h"
|
2018-08-17 01:37:42 +02:00
|
|
|
#include "ddk/wdm.h"
|
2016-04-05 15:45:34 +02:00
|
|
|
#include "regstr.h"
|
2015-09-09 17:20:11 +02:00
|
|
|
#include "wine/debug.h"
|
2021-04-16 04:04:01 +02:00
|
|
|
#include "wine/asm.h"
|
2015-09-09 17:20:11 +02:00
|
|
|
#include "wine/list.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(hid);
|
|
|
|
|
2021-04-16 04:04:01 +02:00
|
|
|
#if defined(__i386__) && !defined(_WIN32)
|
|
|
|
|
|
|
|
extern void * WINAPI wrap_fastcall_func1( void *func, const void *a );
|
|
|
|
__ASM_STDCALL_FUNC( wrap_fastcall_func1, 8,
|
|
|
|
"popl %ecx\n\t"
|
|
|
|
"popl %eax\n\t"
|
|
|
|
"xchgl (%esp),%ecx\n\t"
|
|
|
|
"jmp *%eax" );
|
|
|
|
|
|
|
|
#define call_fastcall_func1(func,a) wrap_fastcall_func1(func,a)
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
#define call_fastcall_func1(func,a) func(a)
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2021-04-16 04:03:58 +02:00
|
|
|
static struct list minidriver_list = LIST_INIT(minidriver_list);
|
|
|
|
|
|
|
|
static minidriver *find_minidriver(DRIVER_OBJECT *driver)
|
|
|
|
{
|
|
|
|
minidriver *md;
|
|
|
|
LIST_FOR_EACH_ENTRY(md, &minidriver_list, minidriver, entry)
|
|
|
|
{
|
|
|
|
if (md->minidriver.DriverObject == driver)
|
|
|
|
return md;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-06-05 16:22:16 +02:00
|
|
|
static NTSTATUS get_device_id(DEVICE_OBJECT *device, BUS_QUERY_ID_TYPE type, WCHAR *id)
|
2016-08-12 15:17:55 +02:00
|
|
|
{
|
|
|
|
IO_STACK_LOCATION *irpsp;
|
|
|
|
IO_STATUS_BLOCK irp_status;
|
2021-04-18 02:43:25 +02:00
|
|
|
KEVENT event;
|
2016-08-12 15:17:55 +02:00
|
|
|
IRP *irp;
|
|
|
|
|
2021-04-18 02:43:25 +02:00
|
|
|
KeInitializeEvent(&event, NotificationEvent, FALSE);
|
|
|
|
irp = IoBuildSynchronousFsdRequest(IRP_MJ_PNP, device, NULL, 0, NULL, &event, &irp_status);
|
2016-08-12 15:17:55 +02:00
|
|
|
if (irp == NULL)
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
|
|
|
|
irpsp = IoGetNextIrpStackLocation(irp);
|
|
|
|
irpsp->MinorFunction = IRP_MN_QUERY_ID;
|
|
|
|
irpsp->Parameters.QueryId.IdType = type;
|
|
|
|
|
2021-04-18 02:43:25 +02:00
|
|
|
if (IoCallDriver(device, irp) == STATUS_PENDING)
|
|
|
|
KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, NULL);
|
2016-08-12 15:17:55 +02:00
|
|
|
|
2021-04-18 02:43:25 +02:00
|
|
|
wcscpy(id, (WCHAR *)irp_status.Information);
|
|
|
|
ExFreePool((WCHAR *)irp_status.Information);
|
|
|
|
return irp_status.u.Status;
|
2016-08-12 15:17:55 +02:00
|
|
|
}
|
|
|
|
|
2021-04-18 02:43:26 +02:00
|
|
|
/* user32 reserves 1 & 2 for winemouse and winekeyboard,
|
|
|
|
* keep this in sync with user_private.h */
|
|
|
|
#define WINE_MOUSE_HANDLE 1
|
|
|
|
#define WINE_KEYBOARD_HANDLE 2
|
|
|
|
|
|
|
|
static UINT32 alloc_rawinput_handle(void)
|
|
|
|
{
|
|
|
|
static LONG counter = WINE_KEYBOARD_HANDLE + 1;
|
|
|
|
return InterlockedIncrement(&counter);
|
|
|
|
}
|
|
|
|
|
2021-04-16 04:04:01 +02:00
|
|
|
static NTSTATUS WINAPI driver_add_device(DRIVER_OBJECT *driver, DEVICE_OBJECT *bus_pdo)
|
2015-09-09 17:20:11 +02:00
|
|
|
{
|
2021-04-20 06:37:10 +02:00
|
|
|
WCHAR device_id[MAX_DEVICE_ID_LEN], instance_id[MAX_DEVICE_ID_LEN];
|
|
|
|
BASE_DEVICE_EXTENSION *ext;
|
|
|
|
DEVICE_OBJECT *fdo;
|
2015-09-09 17:20:11 +02:00
|
|
|
NTSTATUS status;
|
|
|
|
minidriver *minidriver;
|
|
|
|
|
2021-04-16 04:04:01 +02:00
|
|
|
if ((status = get_device_id(bus_pdo, BusQueryDeviceID, device_id)))
|
2019-06-05 16:22:16 +02:00
|
|
|
{
|
|
|
|
ERR("Failed to get PDO device id, status %#x.\n", status);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2021-04-16 04:04:01 +02:00
|
|
|
if ((status = get_device_id(bus_pdo, BusQueryInstanceID, instance_id)))
|
2016-08-12 15:17:55 +02:00
|
|
|
{
|
2019-06-05 16:22:16 +02:00
|
|
|
ERR("Failed to get PDO instance id, status %#x.\n", status);
|
2016-08-12 15:17:55 +02:00
|
|
|
return status;
|
|
|
|
}
|
2015-09-09 17:20:11 +02:00
|
|
|
|
2021-04-16 04:04:01 +02:00
|
|
|
TRACE("Adding device to PDO %p, id %s\\%s.\n", bus_pdo, debugstr_w(device_id), debugstr_w(instance_id));
|
2015-09-09 17:20:11 +02:00
|
|
|
minidriver = find_minidriver(driver);
|
|
|
|
|
2021-04-16 04:04:01 +02:00
|
|
|
if ((status = IoCreateDevice(driver, sizeof(*ext) + minidriver->minidriver.DeviceExtensionSize,
|
|
|
|
NULL, FILE_DEVICE_BUS_EXTENDER, 0, FALSE, &fdo)))
|
2015-09-09 17:20:11 +02:00
|
|
|
{
|
2021-04-16 04:04:01 +02:00
|
|
|
ERR("Failed to create bus FDO, status %#x.\n", status);
|
2015-09-09 17:20:11 +02:00
|
|
|
return status;
|
|
|
|
}
|
2021-04-16 04:04:01 +02:00
|
|
|
ext = fdo->DeviceExtension;
|
|
|
|
ext->is_fdo = TRUE;
|
|
|
|
ext->u.fdo.hid_ext.MiniDeviceExtension = ext + 1;
|
2021-04-18 02:43:27 +02:00
|
|
|
ext->u.fdo.hid_ext.PhysicalDeviceObject = bus_pdo;
|
2021-04-16 04:04:01 +02:00
|
|
|
ext->u.fdo.hid_ext.NextDeviceObject = bus_pdo;
|
|
|
|
swprintf(ext->device_id, ARRAY_SIZE(ext->device_id), L"HID\\%s", wcsrchr(device_id, '\\') + 1);
|
|
|
|
wcscpy(ext->instance_id, instance_id);
|
|
|
|
|
|
|
|
status = minidriver->AddDevice(minidriver->minidriver.DriverObject, fdo);
|
2015-09-09 17:20:11 +02:00
|
|
|
if (status != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
ERR("Minidriver AddDevice failed (%x)\n",status);
|
2021-04-16 04:04:01 +02:00
|
|
|
IoDeleteDevice(fdo);
|
2015-09-09 17:20:11 +02:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2021-04-20 06:37:10 +02:00
|
|
|
IoAttachDeviceToDeviceStack(fdo, bus_pdo);
|
|
|
|
fdo->Flags &= ~DO_DEVICE_INITIALIZING;
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void create_child(minidriver *minidriver, DEVICE_OBJECT *fdo)
|
|
|
|
{
|
|
|
|
BASE_DEVICE_EXTENSION *fdo_ext = fdo->DeviceExtension, *pdo_ext;
|
|
|
|
HID_DEVICE_ATTRIBUTES attr = {0};
|
|
|
|
HID_DESCRIPTOR descriptor;
|
|
|
|
DEVICE_OBJECT *child_pdo;
|
|
|
|
BYTE *reportDescriptor;
|
|
|
|
UNICODE_STRING string;
|
|
|
|
WCHAR pdo_name[255];
|
|
|
|
USAGE page, usage;
|
|
|
|
NTSTATUS status;
|
|
|
|
INT i;
|
|
|
|
|
2021-04-16 04:04:01 +02:00
|
|
|
status = call_minidriver(IOCTL_HID_GET_DEVICE_ATTRIBUTES, fdo, NULL, 0, &attr, sizeof(attr));
|
2015-09-09 17:20:11 +02:00
|
|
|
if (status != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
ERR("Minidriver failed to get Attributes(%x)\n",status);
|
2021-04-20 06:37:10 +02:00
|
|
|
return;
|
2015-09-09 17:20:11 +02:00
|
|
|
}
|
|
|
|
|
2021-04-20 06:37:10 +02:00
|
|
|
swprintf(pdo_name, ARRAY_SIZE(pdo_name), L"\\Device\\HID#%p&%p", fdo->DriverObject,
|
|
|
|
fdo_ext->u.fdo.hid_ext.PhysicalDeviceObject);
|
2021-04-16 04:04:01 +02:00
|
|
|
RtlInitUnicodeString(&string, pdo_name);
|
2021-04-20 06:37:10 +02:00
|
|
|
if ((status = IoCreateDevice(fdo->DriverObject, sizeof(*pdo_ext), &string, 0, 0, FALSE, &child_pdo)))
|
2021-04-16 04:04:01 +02:00
|
|
|
{
|
|
|
|
ERR("Failed to create child PDO, status %#x.\n", status);
|
2021-04-20 06:37:10 +02:00
|
|
|
return;
|
2021-04-16 04:04:01 +02:00
|
|
|
}
|
2021-04-20 06:37:10 +02:00
|
|
|
fdo_ext->u.fdo.child_pdo = child_pdo;
|
2021-04-16 04:04:01 +02:00
|
|
|
|
|
|
|
pdo_ext = child_pdo->DeviceExtension;
|
|
|
|
pdo_ext->u.pdo.parent_fdo = fdo;
|
|
|
|
InitializeListHead(&pdo_ext->u.pdo.irp_queue);
|
|
|
|
KeInitializeSpinLock(&pdo_ext->u.pdo.irp_queue_lock);
|
2021-04-20 06:37:10 +02:00
|
|
|
wcscpy(pdo_ext->device_id, fdo_ext->device_id);
|
|
|
|
wcscpy(pdo_ext->instance_id, fdo_ext->instance_id);
|
2015-09-09 17:20:11 +02:00
|
|
|
|
2021-04-16 04:04:01 +02:00
|
|
|
pdo_ext->u.pdo.information.VendorID = attr.VendorID;
|
|
|
|
pdo_ext->u.pdo.information.ProductID = attr.ProductID;
|
|
|
|
pdo_ext->u.pdo.information.VersionNumber = attr.VersionNumber;
|
|
|
|
pdo_ext->u.pdo.information.Polled = minidriver->minidriver.DevicesArePolled;
|
|
|
|
|
|
|
|
status = call_minidriver(IOCTL_HID_GET_DEVICE_DESCRIPTOR, fdo, NULL, 0, &descriptor, sizeof(descriptor));
|
2015-09-14 16:58:30 +02:00
|
|
|
if (status != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
ERR("Cannot get Device Descriptor(%x)\n",status);
|
2021-04-16 04:04:01 +02:00
|
|
|
IoDeleteDevice(child_pdo);
|
2021-04-20 06:37:10 +02:00
|
|
|
return;
|
2015-09-14 16:58:30 +02:00
|
|
|
}
|
|
|
|
for (i = 0; i < descriptor.bNumDescriptors; i++)
|
|
|
|
if (descriptor.DescriptorList[i].bReportType == HID_REPORT_DESCRIPTOR_TYPE)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (i >= descriptor.bNumDescriptors)
|
|
|
|
{
|
|
|
|
ERR("No Report Descriptor found in reply\n");
|
2021-04-16 04:04:01 +02:00
|
|
|
IoDeleteDevice(child_pdo);
|
2021-04-20 06:37:10 +02:00
|
|
|
return;
|
2015-09-14 16:58:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
reportDescriptor = HeapAlloc(GetProcessHeap(), 0, descriptor.DescriptorList[i].wReportLength);
|
2021-04-16 04:04:01 +02:00
|
|
|
status = call_minidriver(IOCTL_HID_GET_REPORT_DESCRIPTOR, fdo, NULL, 0,
|
2015-09-14 16:58:30 +02:00
|
|
|
reportDescriptor, descriptor.DescriptorList[i].wReportLength);
|
|
|
|
if (status != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
ERR("Cannot get Report Descriptor(%x)\n",status);
|
|
|
|
HeapFree(GetProcessHeap(), 0, reportDescriptor);
|
2021-04-16 04:04:01 +02:00
|
|
|
IoDeleteDevice(child_pdo);
|
2021-04-20 06:37:10 +02:00
|
|
|
return;
|
2015-09-14 16:58:30 +02:00
|
|
|
}
|
|
|
|
|
2021-04-16 04:04:01 +02:00
|
|
|
pdo_ext->u.pdo.preparsed_data = ParseDescriptor(reportDescriptor, descriptor.DescriptorList[i].wReportLength);
|
2015-09-14 16:58:30 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, reportDescriptor);
|
2021-04-16 04:04:01 +02:00
|
|
|
if (!pdo_ext->u.pdo.preparsed_data)
|
2016-03-03 19:53:06 +01:00
|
|
|
{
|
|
|
|
ERR("Cannot parse Report Descriptor\n");
|
2021-04-16 04:04:01 +02:00
|
|
|
IoDeleteDevice(child_pdo);
|
2021-04-20 06:37:10 +02:00
|
|
|
return;
|
2016-03-03 19:53:06 +01:00
|
|
|
}
|
|
|
|
|
2021-04-16 04:04:01 +02:00
|
|
|
pdo_ext->u.pdo.information.DescriptorSize = pdo_ext->u.pdo.preparsed_data->dwSize;
|
2015-09-14 16:58:30 +02:00
|
|
|
|
2021-04-20 06:37:10 +02:00
|
|
|
IoInvalidateDeviceRelations(fdo_ext->u.fdo.hid_ext.PhysicalDeviceObject, BusRelations);
|
2015-09-09 17:20:11 +02:00
|
|
|
|
2021-04-18 02:43:26 +02:00
|
|
|
page = pdo_ext->u.pdo.preparsed_data->caps.UsagePage;
|
|
|
|
usage = pdo_ext->u.pdo.preparsed_data->caps.Usage;
|
|
|
|
if (page == HID_USAGE_PAGE_GENERIC && usage == HID_USAGE_GENERIC_MOUSE)
|
|
|
|
pdo_ext->u.pdo.rawinput_handle = WINE_MOUSE_HANDLE;
|
|
|
|
else if (page == HID_USAGE_PAGE_GENERIC && usage == HID_USAGE_GENERIC_KEYBOARD)
|
|
|
|
pdo_ext->u.pdo.rawinput_handle = WINE_KEYBOARD_HANDLE;
|
|
|
|
else
|
|
|
|
pdo_ext->u.pdo.rawinput_handle = alloc_rawinput_handle();
|
2015-09-09 17:20:11 +02:00
|
|
|
|
2021-04-16 04:04:01 +02:00
|
|
|
pdo_ext->u.pdo.poll_interval = DEFAULT_POLL_INTERVAL;
|
2015-09-09 17:20:11 +02:00
|
|
|
|
2021-04-16 04:04:01 +02:00
|
|
|
pdo_ext->u.pdo.ring_buffer = RingBuffer_Create(
|
|
|
|
sizeof(HID_XFER_PACKET) + pdo_ext->u.pdo.preparsed_data->caps.InputReportByteLength);
|
2015-09-11 17:45:54 +02:00
|
|
|
|
2021-04-16 04:04:01 +02:00
|
|
|
HID_StartDeviceThread(child_pdo);
|
2015-09-09 17:20:11 +02:00
|
|
|
}
|
|
|
|
|
2021-04-16 04:04:01 +02:00
|
|
|
static NTSTATUS fdo_pnp(DEVICE_OBJECT *device, IRP *irp)
|
2018-08-06 16:21:12 +02:00
|
|
|
{
|
2021-04-16 04:04:01 +02:00
|
|
|
minidriver *minidriver = find_minidriver(device->DriverObject);
|
|
|
|
IO_STACK_LOCATION *stack = IoGetCurrentIrpStackLocation(irp);
|
2018-11-14 03:48:18 +01:00
|
|
|
BASE_DEVICE_EXTENSION *ext = device->DeviceExtension;
|
2018-08-06 16:21:12 +02:00
|
|
|
|
2021-04-16 04:04:01 +02:00
|
|
|
TRACE("irp %p, minor function %#x.\n", irp, stack->MinorFunction);
|
|
|
|
|
|
|
|
switch (stack->MinorFunction)
|
2018-11-14 03:48:18 +01:00
|
|
|
{
|
2021-04-16 04:04:01 +02:00
|
|
|
case IRP_MN_QUERY_DEVICE_RELATIONS:
|
|
|
|
{
|
|
|
|
DEVICE_RELATIONS *devices;
|
2021-04-20 06:37:10 +02:00
|
|
|
DEVICE_OBJECT *child;
|
2018-11-14 03:48:18 +01:00
|
|
|
|
2021-04-16 04:04:01 +02:00
|
|
|
if (stack->Parameters.QueryDeviceRelations.Type != BusRelations)
|
|
|
|
return minidriver->PNPDispatch(device, irp);
|
|
|
|
|
|
|
|
if (!(devices = ExAllocatePool(PagedPool, offsetof(DEVICE_RELATIONS, Objects[1]))))
|
|
|
|
{
|
|
|
|
irp->IoStatus.u.Status = STATUS_NO_MEMORY;
|
|
|
|
IoCompleteRequest(irp, IO_NO_INCREMENT);
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
}
|
2019-07-03 01:07:58 +02:00
|
|
|
|
2021-04-20 06:37:10 +02:00
|
|
|
if ((child = ext->u.fdo.child_pdo))
|
|
|
|
{
|
|
|
|
devices->Objects[0] = ext->u.fdo.child_pdo;
|
|
|
|
call_fastcall_func1(ObfReferenceObject, ext->u.fdo.child_pdo);
|
|
|
|
devices->Count = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
devices->Count = 0;
|
|
|
|
}
|
2021-04-16 04:04:01 +02:00
|
|
|
|
|
|
|
irp->IoStatus.Information = (ULONG_PTR)devices;
|
|
|
|
irp->IoStatus.u.Status = STATUS_SUCCESS;
|
|
|
|
IoSkipCurrentIrpStackLocation(irp);
|
|
|
|
return IoCallDriver(ext->u.fdo.hid_ext.NextDeviceObject, irp);
|
|
|
|
}
|
|
|
|
|
2021-04-20 06:37:10 +02:00
|
|
|
case IRP_MN_START_DEVICE:
|
|
|
|
{
|
|
|
|
NTSTATUS ret;
|
|
|
|
|
|
|
|
if ((ret = minidriver->PNPDispatch(device, irp)))
|
|
|
|
return ret;
|
|
|
|
create_child(minidriver, device);
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2021-04-16 04:04:01 +02:00
|
|
|
case IRP_MN_REMOVE_DEVICE:
|
|
|
|
{
|
|
|
|
NTSTATUS ret;
|
|
|
|
|
|
|
|
ret = minidriver->PNPDispatch(device, irp);
|
|
|
|
|
|
|
|
IoDetachDevice(ext->u.fdo.hid_ext.NextDeviceObject);
|
|
|
|
IoDeleteDevice(device);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
return minidriver->PNPDispatch(device, irp);
|
|
|
|
}
|
2018-08-06 16:21:12 +02:00
|
|
|
}
|
|
|
|
|
2021-04-16 04:04:01 +02:00
|
|
|
static NTSTATUS pdo_pnp(DEVICE_OBJECT *device, IRP *irp)
|
2016-04-05 15:45:34 +02:00
|
|
|
{
|
|
|
|
IO_STACK_LOCATION *irpsp = IoGetCurrentIrpStackLocation(irp);
|
2021-04-16 04:04:01 +02:00
|
|
|
BASE_DEVICE_EXTENSION *ext = device->DeviceExtension;
|
|
|
|
NTSTATUS status = irp->IoStatus.u.Status;
|
2016-04-05 15:45:34 +02:00
|
|
|
|
2021-04-16 04:04:01 +02:00
|
|
|
TRACE("irp %p, minor function %#x.\n", irp, irpsp->MinorFunction);
|
2016-04-05 15:45:34 +02:00
|
|
|
|
|
|
|
switch(irpsp->MinorFunction)
|
|
|
|
{
|
|
|
|
case IRP_MN_QUERY_ID:
|
|
|
|
{
|
2019-06-05 16:22:14 +02:00
|
|
|
WCHAR *id = ExAllocatePool(PagedPool, sizeof(WCHAR) * REGSTR_VAL_MAX_HCID_LEN);
|
2016-04-23 20:03:10 +02:00
|
|
|
TRACE("IRP_MN_QUERY_ID[%i]\n", irpsp->Parameters.QueryId.IdType);
|
|
|
|
switch (irpsp->Parameters.QueryId.IdType)
|
2016-04-05 15:45:34 +02:00
|
|
|
{
|
|
|
|
case BusQueryHardwareIDs:
|
|
|
|
case BusQueryCompatibleIDs:
|
|
|
|
{
|
|
|
|
WCHAR *ptr;
|
|
|
|
ptr = id;
|
2019-06-05 16:22:16 +02:00
|
|
|
/* Device instance ID */
|
|
|
|
lstrcpyW(ptr, ext->device_id);
|
|
|
|
ptr += lstrlenW(ext->device_id);
|
2020-11-15 23:11:21 +01:00
|
|
|
lstrcpyW(ptr, L"\\");
|
2019-06-05 16:22:16 +02:00
|
|
|
ptr += 1;
|
2019-06-05 08:36:39 +02:00
|
|
|
lstrcpyW(ptr, ext->instance_id);
|
2016-04-05 15:45:34 +02:00
|
|
|
ptr += lstrlenW(ext->instance_id) + 1;
|
|
|
|
/* Device ID */
|
2019-06-05 08:36:39 +02:00
|
|
|
lstrcpyW(ptr, ext->device_id);
|
2016-04-05 15:45:34 +02:00
|
|
|
ptr += lstrlenW(ext->device_id) + 1;
|
|
|
|
/* Bus ID */
|
2020-11-15 23:11:21 +01:00
|
|
|
lstrcpyW(ptr, L"HID");
|
|
|
|
ptr += lstrlenW(L"HID") + 1;
|
2016-04-05 15:45:34 +02:00
|
|
|
*ptr = 0;
|
|
|
|
irp->IoStatus.Information = (ULONG_PTR)id;
|
2021-04-16 04:04:01 +02:00
|
|
|
status = STATUS_SUCCESS;
|
2016-04-05 15:45:34 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case BusQueryDeviceID:
|
2019-06-05 08:36:39 +02:00
|
|
|
lstrcpyW(id, ext->device_id);
|
2016-04-05 15:45:34 +02:00
|
|
|
irp->IoStatus.Information = (ULONG_PTR)id;
|
2021-04-16 04:04:01 +02:00
|
|
|
status = STATUS_SUCCESS;
|
2016-04-05 15:45:34 +02:00
|
|
|
break;
|
|
|
|
case BusQueryInstanceID:
|
2019-06-05 08:36:39 +02:00
|
|
|
lstrcpyW(id, ext->instance_id);
|
2016-04-05 15:45:34 +02:00
|
|
|
irp->IoStatus.Information = (ULONG_PTR)id;
|
2021-04-16 04:04:01 +02:00
|
|
|
status = STATUS_SUCCESS;
|
2016-04-05 15:45:34 +02:00
|
|
|
break;
|
2021-04-11 04:57:15 +02:00
|
|
|
|
|
|
|
case BusQueryContainerID:
|
2016-04-23 20:03:10 +02:00
|
|
|
case BusQueryDeviceSerialNumber:
|
2021-04-11 04:57:15 +02:00
|
|
|
FIXME("unimplemented id type %#x\n", irpsp->Parameters.QueryId.IdType);
|
2019-08-22 06:16:50 +02:00
|
|
|
ExFreePool(id);
|
2016-04-23 20:03:10 +02:00
|
|
|
break;
|
2016-04-05 15:45:34 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2018-08-17 01:37:42 +02:00
|
|
|
|
2021-04-16 04:04:01 +02:00
|
|
|
case IRP_MN_QUERY_CAPABILITIES:
|
|
|
|
{
|
|
|
|
DEVICE_CAPABILITIES *caps = irpsp->Parameters.DeviceCapabilities.Capabilities;
|
2018-08-17 01:37:42 +02:00
|
|
|
|
2021-04-16 04:04:01 +02:00
|
|
|
caps->RawDeviceOK = 1;
|
|
|
|
status = STATUS_SUCCESS;
|
|
|
|
break;
|
2018-08-17 01:37:42 +02:00
|
|
|
}
|
2021-04-16 04:04:01 +02:00
|
|
|
|
|
|
|
case IRP_MN_START_DEVICE:
|
|
|
|
if ((status = IoRegisterDeviceInterface(device, &GUID_DEVINTERFACE_HID, NULL, &ext->u.pdo.link_name)))
|
|
|
|
{
|
|
|
|
ERR("Failed to register interface, status %#x.\n", status);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME: This should probably be done in mouhid.sys. */
|
|
|
|
if (ext->u.pdo.preparsed_data->caps.UsagePage == HID_USAGE_PAGE_GENERIC
|
|
|
|
&& ext->u.pdo.preparsed_data->caps.Usage == HID_USAGE_GENERIC_MOUSE)
|
|
|
|
{
|
|
|
|
if (!IoRegisterDeviceInterface(device, &GUID_DEVINTERFACE_MOUSE, NULL, &ext->u.pdo.mouse_link_name))
|
|
|
|
ext->u.pdo.is_mouse = TRUE;
|
|
|
|
}
|
2021-04-22 21:26:51 +02:00
|
|
|
if (ext->u.pdo.preparsed_data->caps.UsagePage == HID_USAGE_PAGE_GENERIC
|
|
|
|
&& ext->u.pdo.preparsed_data->caps.Usage == HID_USAGE_GENERIC_KEYBOARD)
|
|
|
|
{
|
|
|
|
if (!IoRegisterDeviceInterface(device, &GUID_DEVINTERFACE_KEYBOARD, NULL, &ext->u.pdo.keyboard_link_name))
|
|
|
|
ext->u.pdo.is_keyboard = TRUE;
|
|
|
|
}
|
2021-04-16 04:04:01 +02:00
|
|
|
|
|
|
|
IoSetDeviceInterfaceState(&ext->u.pdo.link_name, TRUE);
|
|
|
|
if (ext->u.pdo.is_mouse)
|
|
|
|
IoSetDeviceInterfaceState(&ext->u.pdo.mouse_link_name, TRUE);
|
2021-04-22 21:26:51 +02:00
|
|
|
if (ext->u.pdo.is_keyboard)
|
|
|
|
IoSetDeviceInterfaceState(&ext->u.pdo.keyboard_link_name, TRUE);
|
2021-04-16 04:04:01 +02:00
|
|
|
status = STATUS_SUCCESS;
|
|
|
|
break;
|
|
|
|
|
2016-08-17 17:30:52 +02:00
|
|
|
case IRP_MN_REMOVE_DEVICE:
|
|
|
|
{
|
2021-04-16 04:04:01 +02:00
|
|
|
IRP *queued_irp;
|
|
|
|
|
|
|
|
IoSetDeviceInterfaceState(&ext->u.pdo.link_name, FALSE);
|
|
|
|
if (ext->u.pdo.is_mouse)
|
|
|
|
IoSetDeviceInterfaceState(&ext->u.pdo.mouse_link_name, FALSE);
|
2021-04-22 21:26:51 +02:00
|
|
|
if (ext->u.pdo.is_keyboard)
|
|
|
|
IoSetDeviceInterfaceState(&ext->u.pdo.keyboard_link_name, TRUE);
|
2021-04-16 04:04:01 +02:00
|
|
|
|
|
|
|
if (ext->u.pdo.thread)
|
|
|
|
{
|
|
|
|
SetEvent(ext->u.pdo.halt_event);
|
|
|
|
WaitForSingleObject(ext->u.pdo.thread, INFINITE);
|
|
|
|
}
|
|
|
|
CloseHandle(ext->u.pdo.halt_event);
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, ext->u.pdo.preparsed_data);
|
|
|
|
if (ext->u.pdo.ring_buffer)
|
|
|
|
RingBuffer_Destroy(ext->u.pdo.ring_buffer);
|
|
|
|
|
|
|
|
while ((queued_irp = pop_irp_from_queue(ext)))
|
|
|
|
{
|
|
|
|
queued_irp->IoStatus.u.Status = STATUS_DEVICE_REMOVED;
|
|
|
|
IoCompleteRequest(queued_irp, IO_NO_INCREMENT);
|
|
|
|
}
|
|
|
|
|
|
|
|
RtlFreeUnicodeString(&ext->u.pdo.link_name);
|
|
|
|
|
|
|
|
irp->IoStatus.u.Status = STATUS_SUCCESS;
|
|
|
|
IoCompleteRequest(irp, IO_NO_INCREMENT);
|
|
|
|
IoDeleteDevice(device);
|
|
|
|
return STATUS_SUCCESS;
|
2016-08-17 17:30:52 +02:00
|
|
|
}
|
2021-04-16 04:04:01 +02:00
|
|
|
|
|
|
|
case IRP_MN_SURPRISE_REMOVAL:
|
|
|
|
status = STATUS_SUCCESS;
|
|
|
|
break;
|
|
|
|
|
2016-04-05 15:45:34 +02:00
|
|
|
default:
|
2021-04-16 04:04:01 +02:00
|
|
|
FIXME("Unhandled minor function %#x.\n", irpsp->MinorFunction);
|
2016-04-05 15:45:34 +02:00
|
|
|
}
|
|
|
|
|
2021-04-16 04:04:01 +02:00
|
|
|
irp->IoStatus.u.Status = status;
|
2016-04-05 15:45:34 +02:00
|
|
|
IoCompleteRequest( irp, IO_NO_INCREMENT );
|
2021-04-16 04:04:01 +02:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static NTSTATUS WINAPI driver_pnp(DEVICE_OBJECT *device, IRP *irp)
|
|
|
|
{
|
|
|
|
BASE_DEVICE_EXTENSION *ext = device->DeviceExtension;
|
|
|
|
|
|
|
|
if (ext->is_fdo)
|
|
|
|
return fdo_pnp(device, irp);
|
|
|
|
else
|
|
|
|
return pdo_pnp(device, irp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static NTSTATUS WINAPI driver_create(DEVICE_OBJECT *device, IRP *irp)
|
|
|
|
{
|
|
|
|
BASE_DEVICE_EXTENSION *ext = device->DeviceExtension;
|
|
|
|
|
|
|
|
if (ext->is_fdo)
|
|
|
|
{
|
|
|
|
irp->IoStatus.u.Status = STATUS_UNSUCCESSFUL;
|
|
|
|
IoCompleteRequest(irp, IO_NO_INCREMENT);
|
|
|
|
return STATUS_UNSUCCESSFUL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pdo_create(device, irp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static NTSTATUS WINAPI driver_close(DEVICE_OBJECT *device, IRP *irp)
|
|
|
|
{
|
|
|
|
return pdo_close(device, irp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static NTSTATUS WINAPI driver_ioctl(DEVICE_OBJECT *device, IRP *irp)
|
|
|
|
{
|
|
|
|
return pdo_ioctl(device, irp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static NTSTATUS WINAPI driver_read(DEVICE_OBJECT *device, IRP *irp)
|
|
|
|
{
|
|
|
|
return pdo_read(device, irp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static NTSTATUS WINAPI driver_write(DEVICE_OBJECT *device, IRP *irp)
|
|
|
|
{
|
|
|
|
return pdo_write(device, irp);
|
2016-04-05 15:45:34 +02:00
|
|
|
}
|
2021-04-16 04:03:58 +02:00
|
|
|
|
|
|
|
static void WINAPI driver_unload(DRIVER_OBJECT *driver)
|
|
|
|
{
|
|
|
|
minidriver *md;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
if ((md = find_minidriver(driver)))
|
|
|
|
{
|
|
|
|
if (md->DriverUnload)
|
|
|
|
md->DriverUnload(md->minidriver.DriverObject);
|
|
|
|
list_remove(&md->entry);
|
|
|
|
HeapFree(GetProcessHeap(), 0, md);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS WINAPI HidRegisterMinidriver(HID_MINIDRIVER_REGISTRATION *registration)
|
|
|
|
{
|
|
|
|
minidriver *driver;
|
|
|
|
|
|
|
|
if (!(driver = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*driver))))
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
|
|
|
|
driver->DriverUnload = registration->DriverObject->DriverUnload;
|
|
|
|
registration->DriverObject->DriverUnload = driver_unload;
|
|
|
|
|
2021-04-16 04:04:01 +02:00
|
|
|
registration->DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = driver_ioctl;
|
|
|
|
registration->DriverObject->MajorFunction[IRP_MJ_READ] = driver_read;
|
|
|
|
registration->DriverObject->MajorFunction[IRP_MJ_WRITE] = driver_write;
|
|
|
|
registration->DriverObject->MajorFunction[IRP_MJ_CREATE] = driver_create;
|
|
|
|
registration->DriverObject->MajorFunction[IRP_MJ_CLOSE] = driver_close;
|
2021-04-16 04:03:58 +02:00
|
|
|
|
|
|
|
driver->PNPDispatch = registration->DriverObject->MajorFunction[IRP_MJ_PNP];
|
|
|
|
registration->DriverObject->MajorFunction[IRP_MJ_PNP] = driver_pnp;
|
|
|
|
|
|
|
|
driver->AddDevice = registration->DriverObject->DriverExtension->AddDevice;
|
|
|
|
registration->DriverObject->DriverExtension->AddDevice = driver_add_device;
|
|
|
|
|
|
|
|
driver->minidriver = *registration;
|
|
|
|
list_add_tail(&minidriver_list, &driver->entry);
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS call_minidriver(ULONG code, DEVICE_OBJECT *device, void *in_buff, ULONG in_size, void *out_buff, ULONG out_size)
|
|
|
|
{
|
|
|
|
IRP *irp;
|
|
|
|
IO_STATUS_BLOCK io;
|
|
|
|
KEVENT event;
|
|
|
|
|
|
|
|
KeInitializeEvent(&event, NotificationEvent, FALSE);
|
|
|
|
|
|
|
|
irp = IoBuildDeviceIoControlRequest(code, device, in_buff, in_size,
|
|
|
|
out_buff, out_size, TRUE, &event, &io);
|
|
|
|
|
|
|
|
if (IoCallDriver(device, irp) == STATUS_PENDING)
|
|
|
|
KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, NULL);
|
|
|
|
|
|
|
|
return io.u.Status;
|
|
|
|
}
|