2021-04-14 16:40:00 +02:00
|
|
|
/*
|
|
|
|
* HID Plug and Play test driver
|
|
|
|
*
|
|
|
|
* Copyright 2021 Zebediah Figura
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "ntstatus.h"
|
|
|
|
#define WIN32_NO_STATUS
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winternl.h"
|
|
|
|
#include "winioctl.h"
|
|
|
|
#include "ddk/wdm.h"
|
|
|
|
#include "hidusage.h"
|
|
|
|
#include "ddk/hidpi.h"
|
|
|
|
#include "ddk/hidport.h"
|
|
|
|
|
|
|
|
#include "wine/list.h"
|
|
|
|
|
2021-09-09 08:50:08 +02:00
|
|
|
#include "driver_hid.h"
|
2021-04-14 16:40:00 +02:00
|
|
|
|
|
|
|
static UNICODE_STRING control_symlink;
|
|
|
|
|
|
|
|
static unsigned int got_start_device;
|
2021-09-10 09:22:42 +02:00
|
|
|
static HID_DEVICE_ATTRIBUTES attributes;
|
2021-09-10 09:22:41 +02:00
|
|
|
static char report_descriptor_buf[4096];
|
|
|
|
static DWORD report_descriptor_len;
|
2021-09-10 09:22:43 +02:00
|
|
|
static HIDP_CAPS caps;
|
2021-06-16 11:20:50 +02:00
|
|
|
static DWORD report_id;
|
2021-07-06 11:00:49 +02:00
|
|
|
static DWORD polled;
|
2021-04-14 16:40:00 +02:00
|
|
|
|
2021-07-06 11:00:48 +02:00
|
|
|
struct irp_queue
|
|
|
|
{
|
|
|
|
KSPIN_LOCK lock;
|
|
|
|
LIST_ENTRY list;
|
|
|
|
};
|
|
|
|
|
2021-09-09 08:50:08 +02:00
|
|
|
static IRP *irp_queue_pop( struct irp_queue *queue )
|
2021-07-06 11:00:48 +02:00
|
|
|
{
|
|
|
|
KIRQL irql;
|
|
|
|
IRP *irp;
|
|
|
|
|
2021-09-09 08:50:08 +02:00
|
|
|
KeAcquireSpinLock( &queue->lock, &irql );
|
|
|
|
if (IsListEmpty( &queue->list )) irp = NULL;
|
|
|
|
else irp = CONTAINING_RECORD( RemoveHeadList( &queue->list ), IRP, Tail.Overlay.ListEntry );
|
|
|
|
KeReleaseSpinLock( &queue->lock, irql );
|
2021-07-06 11:00:48 +02:00
|
|
|
|
|
|
|
return irp;
|
|
|
|
}
|
|
|
|
|
2021-09-09 08:50:08 +02:00
|
|
|
static void irp_queue_push( struct irp_queue *queue, IRP *irp )
|
2021-07-06 11:00:48 +02:00
|
|
|
{
|
|
|
|
KIRQL irql;
|
|
|
|
|
2021-09-09 08:50:08 +02:00
|
|
|
KeAcquireSpinLock( &queue->lock, &irql );
|
|
|
|
InsertTailList( &queue->list, &irp->Tail.Overlay.ListEntry );
|
|
|
|
KeReleaseSpinLock( &queue->lock, irql );
|
2021-07-06 11:00:48 +02:00
|
|
|
}
|
|
|
|
|
2021-09-09 08:50:08 +02:00
|
|
|
static void irp_queue_clear( struct irp_queue *queue )
|
2021-07-06 11:00:48 +02:00
|
|
|
{
|
|
|
|
IRP *irp;
|
|
|
|
|
2021-09-09 08:50:08 +02:00
|
|
|
while ((irp = irp_queue_pop( queue )))
|
2021-07-06 11:00:48 +02:00
|
|
|
{
|
|
|
|
irp->IoStatus.Status = STATUS_DELETE_PENDING;
|
2021-09-09 08:50:08 +02:00
|
|
|
IoCompleteRequest( irp, IO_NO_INCREMENT );
|
2021-07-06 11:00:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-09 08:50:08 +02:00
|
|
|
static void irp_queue_init( struct irp_queue *queue )
|
2021-07-06 11:00:48 +02:00
|
|
|
{
|
2021-09-09 08:50:08 +02:00
|
|
|
KeInitializeSpinLock( &queue->lock );
|
|
|
|
InitializeListHead( &queue->list );
|
2021-07-06 11:00:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
struct hid_device
|
|
|
|
{
|
|
|
|
BOOL removed;
|
|
|
|
KSPIN_LOCK lock;
|
|
|
|
struct irp_queue irp_queue;
|
|
|
|
};
|
|
|
|
|
2021-09-09 08:50:08 +02:00
|
|
|
static NTSTATUS WINAPI driver_pnp( DEVICE_OBJECT *device, IRP *irp )
|
2021-04-14 16:40:00 +02:00
|
|
|
{
|
2021-09-09 08:50:08 +02:00
|
|
|
IO_STACK_LOCATION *stack = IoGetCurrentIrpStackLocation( irp );
|
2021-04-14 16:40:00 +02:00
|
|
|
HID_DEVICE_EXTENSION *ext = device->DeviceExtension;
|
2021-07-06 11:00:48 +02:00
|
|
|
struct hid_device *impl = ext->MiniDeviceExtension;
|
|
|
|
KIRQL irql;
|
2021-04-14 16:40:00 +02:00
|
|
|
|
2021-09-09 08:50:08 +02:00
|
|
|
if (winetest_debug > 1) trace( "pnp %#x\n", stack->MinorFunction );
|
2021-04-14 16:40:00 +02:00
|
|
|
|
|
|
|
switch (stack->MinorFunction)
|
|
|
|
{
|
2021-09-09 08:50:08 +02:00
|
|
|
case IRP_MN_START_DEVICE:
|
|
|
|
++got_start_device;
|
|
|
|
impl->removed = FALSE;
|
|
|
|
KeInitializeSpinLock( &impl->lock );
|
|
|
|
irp_queue_init( &impl->irp_queue );
|
|
|
|
IoSetDeviceInterfaceState( &control_symlink, TRUE );
|
|
|
|
irp->IoStatus.Status = STATUS_SUCCESS;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IRP_MN_SURPRISE_REMOVAL:
|
|
|
|
case IRP_MN_QUERY_REMOVE_DEVICE:
|
|
|
|
KeAcquireSpinLock( &impl->lock, &irql );
|
|
|
|
impl->removed = TRUE;
|
|
|
|
KeReleaseSpinLock( &impl->lock, irql );
|
|
|
|
irp_queue_clear( &impl->irp_queue );
|
|
|
|
irp->IoStatus.Status = STATUS_SUCCESS;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IRP_MN_CANCEL_REMOVE_DEVICE:
|
|
|
|
KeAcquireSpinLock( &impl->lock, &irql );
|
|
|
|
impl->removed = FALSE;
|
|
|
|
KeReleaseSpinLock( &impl->lock, irql );
|
|
|
|
irp->IoStatus.Status = STATUS_SUCCESS;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IRP_MN_STOP_DEVICE:
|
|
|
|
irp->IoStatus.Status = STATUS_SUCCESS;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IRP_MN_REMOVE_DEVICE:
|
|
|
|
irp_queue_clear( &impl->irp_queue );
|
|
|
|
IoSetDeviceInterfaceState( &control_symlink, FALSE );
|
|
|
|
irp->IoStatus.Status = STATUS_SUCCESS;
|
|
|
|
break;
|
2021-04-14 16:40:00 +02:00
|
|
|
}
|
|
|
|
|
2021-09-09 08:50:08 +02:00
|
|
|
IoSkipCurrentIrpStackLocation( irp );
|
|
|
|
return IoCallDriver( ext->NextDeviceObject, irp );
|
2021-04-14 16:40:00 +02:00
|
|
|
}
|
|
|
|
|
2021-09-09 08:50:08 +02:00
|
|
|
static NTSTATUS WINAPI driver_power( DEVICE_OBJECT *device, IRP *irp )
|
2021-04-14 16:40:00 +02:00
|
|
|
{
|
|
|
|
HID_DEVICE_EXTENSION *ext = device->DeviceExtension;
|
|
|
|
|
|
|
|
/* We do not expect power IRPs as part of normal operation. */
|
2021-09-09 08:50:08 +02:00
|
|
|
ok( 0, "unexpected call\n" );
|
2021-04-14 16:40:00 +02:00
|
|
|
|
2021-09-09 08:50:08 +02:00
|
|
|
PoStartNextPowerIrp( irp );
|
|
|
|
IoSkipCurrentIrpStackLocation( irp );
|
|
|
|
return PoCallDriver( ext->NextDeviceObject, irp );
|
2021-04-14 16:40:00 +02:00
|
|
|
}
|
|
|
|
|
2021-09-09 08:50:08 +02:00
|
|
|
static NTSTATUS WINAPI driver_internal_ioctl( DEVICE_OBJECT *device, IRP *irp )
|
2021-04-14 16:40:00 +02:00
|
|
|
{
|
2021-09-09 08:50:08 +02:00
|
|
|
IO_STACK_LOCATION *stack = IoGetCurrentIrpStackLocation( irp );
|
2021-07-06 11:00:48 +02:00
|
|
|
HID_DEVICE_EXTENSION *ext = device->DeviceExtension;
|
|
|
|
struct hid_device *impl = ext->MiniDeviceExtension;
|
2021-04-14 16:40:00 +02:00
|
|
|
const ULONG in_size = stack->Parameters.DeviceIoControl.InputBufferLength;
|
|
|
|
const ULONG out_size = stack->Parameters.DeviceIoControl.OutputBufferLength;
|
|
|
|
const ULONG code = stack->Parameters.DeviceIoControl.IoControlCode;
|
2021-08-02 12:25:24 +02:00
|
|
|
static BYTE seq = 0;
|
2021-04-14 16:40:00 +02:00
|
|
|
NTSTATUS ret;
|
2021-07-06 11:00:48 +02:00
|
|
|
BOOL removed;
|
|
|
|
KIRQL irql;
|
2021-04-14 16:40:00 +02:00
|
|
|
|
2021-09-09 08:50:08 +02:00
|
|
|
if (winetest_debug > 1) trace( "ioctl %#x\n", code );
|
2021-04-14 16:40:00 +02:00
|
|
|
|
2021-09-09 08:50:08 +02:00
|
|
|
ok( got_start_device, "expected IRP_MN_START_DEVICE before any ioctls\n" );
|
2021-04-14 16:40:00 +02:00
|
|
|
|
|
|
|
irp->IoStatus.Information = 0;
|
|
|
|
|
2021-09-09 08:50:08 +02:00
|
|
|
KeAcquireSpinLock( &impl->lock, &irql );
|
2021-07-06 11:00:48 +02:00
|
|
|
removed = impl->removed;
|
2021-09-09 08:50:08 +02:00
|
|
|
KeReleaseSpinLock( &impl->lock, irql );
|
2021-07-06 11:00:48 +02:00
|
|
|
|
|
|
|
if (removed)
|
|
|
|
{
|
|
|
|
irp->IoStatus.Status = STATUS_DELETE_PENDING;
|
2021-09-09 08:50:08 +02:00
|
|
|
IoCompleteRequest( irp, IO_NO_INCREMENT );
|
2021-07-06 11:00:48 +02:00
|
|
|
return STATUS_DELETE_PENDING;
|
|
|
|
}
|
|
|
|
|
2021-04-14 16:40:00 +02:00
|
|
|
switch (code)
|
|
|
|
{
|
2021-09-09 08:50:08 +02:00
|
|
|
case IOCTL_HID_GET_DEVICE_DESCRIPTOR:
|
|
|
|
{
|
|
|
|
HID_DESCRIPTOR *desc = irp->UserBuffer;
|
2021-04-14 16:40:00 +02:00
|
|
|
|
2021-09-09 08:50:08 +02:00
|
|
|
ok( !in_size, "got input size %u\n", in_size );
|
|
|
|
ok( out_size == sizeof(*desc), "got output size %u\n", out_size );
|
2021-04-14 16:40:00 +02:00
|
|
|
|
2021-09-09 08:50:08 +02:00
|
|
|
if (out_size == sizeof(*desc))
|
2021-04-14 16:40:00 +02:00
|
|
|
{
|
2021-09-09 08:50:08 +02:00
|
|
|
ok( !desc->bLength, "got size %u\n", desc->bLength );
|
|
|
|
|
|
|
|
desc->bLength = sizeof(*desc);
|
|
|
|
desc->bDescriptorType = HID_HID_DESCRIPTOR_TYPE;
|
|
|
|
desc->bcdHID = HID_REVISION;
|
|
|
|
desc->bCountry = 0;
|
|
|
|
desc->bNumDescriptors = 1;
|
|
|
|
desc->DescriptorList[0].bReportType = HID_REPORT_DESCRIPTOR_TYPE;
|
2021-09-10 09:22:41 +02:00
|
|
|
desc->DescriptorList[0].wReportLength = report_descriptor_len;
|
2021-09-09 08:50:08 +02:00
|
|
|
irp->IoStatus.Information = sizeof(*desc);
|
2021-04-14 16:40:00 +02:00
|
|
|
}
|
2021-09-09 08:50:08 +02:00
|
|
|
ret = STATUS_SUCCESS;
|
|
|
|
break;
|
|
|
|
}
|
2021-04-14 16:40:00 +02:00
|
|
|
|
2021-09-09 08:50:08 +02:00
|
|
|
case IOCTL_HID_GET_REPORT_DESCRIPTOR:
|
|
|
|
ok( !in_size, "got input size %u\n", in_size );
|
2021-09-10 09:22:41 +02:00
|
|
|
ok( out_size == report_descriptor_len, "got output size %u\n", out_size );
|
2021-09-09 08:50:08 +02:00
|
|
|
|
2021-09-10 09:22:41 +02:00
|
|
|
if (out_size == report_descriptor_len)
|
2021-06-04 11:12:15 +02:00
|
|
|
{
|
2021-09-10 09:22:41 +02:00
|
|
|
memcpy( irp->UserBuffer, report_descriptor_buf, report_descriptor_len );
|
|
|
|
irp->IoStatus.Information = report_descriptor_len;
|
2021-06-04 11:12:15 +02:00
|
|
|
}
|
2021-09-09 08:50:08 +02:00
|
|
|
ret = STATUS_SUCCESS;
|
|
|
|
break;
|
2021-04-14 16:40:00 +02:00
|
|
|
|
2021-09-09 08:50:08 +02:00
|
|
|
case IOCTL_HID_GET_DEVICE_ATTRIBUTES:
|
|
|
|
ok( !in_size, "got input size %u\n", in_size );
|
2021-09-10 09:22:42 +02:00
|
|
|
ok( out_size == sizeof(attributes), "got output size %u\n", out_size );
|
2021-07-06 11:00:51 +02:00
|
|
|
|
2021-09-10 09:22:42 +02:00
|
|
|
if (out_size == sizeof(attributes))
|
2021-09-09 08:50:08 +02:00
|
|
|
{
|
2021-09-10 09:22:42 +02:00
|
|
|
memcpy( irp->UserBuffer, &attributes, sizeof(attributes) );
|
|
|
|
irp->IoStatus.Information = sizeof(attributes);
|
2021-07-06 11:00:51 +02:00
|
|
|
}
|
2021-09-09 08:50:08 +02:00
|
|
|
ret = STATUS_SUCCESS;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IOCTL_HID_READ_REPORT:
|
|
|
|
{
|
2021-09-10 09:22:43 +02:00
|
|
|
ULONG expected_size = caps.InputReportByteLength - (report_id ? 0 : 1);
|
2021-09-09 08:50:08 +02:00
|
|
|
ok( !in_size, "got input size %u\n", in_size );
|
|
|
|
ok( out_size == expected_size, "got output size %u\n", out_size );
|
2021-07-06 11:00:51 +02:00
|
|
|
|
2021-09-09 08:50:08 +02:00
|
|
|
if (polled)
|
2021-07-05 10:44:53 +02:00
|
|
|
{
|
2021-09-09 08:50:08 +02:00
|
|
|
memset( irp->UserBuffer, 0xa5, expected_size );
|
|
|
|
if (report_id) ((char *)irp->UserBuffer)[0] = report_id;
|
|
|
|
((char *)irp->UserBuffer)[1] = seq++;
|
2021-07-05 10:44:53 +02:00
|
|
|
irp->IoStatus.Information = 3;
|
|
|
|
ret = STATUS_SUCCESS;
|
|
|
|
}
|
2021-09-09 08:50:08 +02:00
|
|
|
else
|
2021-07-05 10:44:56 +02:00
|
|
|
{
|
2021-09-09 08:50:08 +02:00
|
|
|
IoMarkIrpPending( irp );
|
|
|
|
irp_queue_push( &impl->irp_queue, irp );
|
|
|
|
ret = STATUS_PENDING;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2021-07-05 10:44:56 +02:00
|
|
|
|
2021-09-09 08:50:08 +02:00
|
|
|
case IOCTL_HID_WRITE_REPORT:
|
|
|
|
{
|
|
|
|
HID_XFER_PACKET *packet = irp->UserBuffer;
|
2021-09-10 09:22:43 +02:00
|
|
|
ULONG expected_size = caps.OutputReportByteLength - (report_id ? 0 : 1);
|
2021-07-05 10:44:56 +02:00
|
|
|
|
2021-09-09 08:50:08 +02:00
|
|
|
ok( in_size == sizeof(*packet), "got input size %u\n", in_size );
|
|
|
|
ok( !out_size, "got output size %u\n", out_size );
|
|
|
|
ok( packet->reportBufferLen >= expected_size, "got report size %u\n", packet->reportBufferLen );
|
2021-07-05 10:44:56 +02:00
|
|
|
|
2021-09-09 08:50:08 +02:00
|
|
|
if (report_id)
|
|
|
|
ok( packet->reportBuffer[0] == report_id, "got report id %x\n", packet->reportBuffer[0] );
|
|
|
|
else ok( packet->reportBuffer[0] == 0xcd, "got first byte %x\n", packet->reportBuffer[0] );
|
2021-07-05 10:44:54 +02:00
|
|
|
|
2021-09-09 08:50:08 +02:00
|
|
|
irp->IoStatus.Information = 3;
|
|
|
|
ret = STATUS_SUCCESS;
|
|
|
|
break;
|
|
|
|
}
|
2021-07-05 10:44:54 +02:00
|
|
|
|
2021-09-09 08:50:08 +02:00
|
|
|
case IOCTL_HID_GET_INPUT_REPORT:
|
|
|
|
{
|
|
|
|
HID_XFER_PACKET *packet = irp->UserBuffer;
|
2021-09-10 09:22:43 +02:00
|
|
|
ULONG expected_size = caps.InputReportByteLength - (report_id ? 0 : 1);
|
2021-09-09 08:50:08 +02:00
|
|
|
ok( !in_size, "got input size %u\n", in_size );
|
|
|
|
ok( out_size == sizeof(*packet), "got output size %u\n", out_size );
|
|
|
|
|
|
|
|
ok( packet->reportId == report_id, "got id %u\n", packet->reportId );
|
|
|
|
ok( packet->reportBufferLen >= expected_size, "got len %u\n", packet->reportBufferLen );
|
|
|
|
ok( !!packet->reportBuffer, "got buffer %p\n", packet->reportBuffer );
|
|
|
|
|
|
|
|
memset( packet->reportBuffer, 0xa5, 3 );
|
|
|
|
if (report_id) ((char *)packet->reportBuffer)[0] = report_id;
|
|
|
|
irp->IoStatus.Information = 3;
|
|
|
|
ret = STATUS_SUCCESS;
|
|
|
|
break;
|
|
|
|
}
|
2021-07-05 10:44:54 +02:00
|
|
|
|
2021-09-09 08:50:08 +02:00
|
|
|
case IOCTL_HID_SET_OUTPUT_REPORT:
|
|
|
|
{
|
|
|
|
HID_XFER_PACKET *packet = irp->UserBuffer;
|
2021-09-10 09:22:43 +02:00
|
|
|
ULONG expected_size = caps.OutputReportByteLength - (report_id ? 0 : 1);
|
2021-09-09 08:50:08 +02:00
|
|
|
ok( in_size == sizeof(*packet), "got input size %u\n", in_size );
|
|
|
|
ok( !out_size, "got output size %u\n", out_size );
|
|
|
|
|
|
|
|
ok( packet->reportId == report_id, "got id %u\n", packet->reportId );
|
|
|
|
ok( packet->reportBufferLen >= expected_size, "got len %u\n", packet->reportBufferLen );
|
|
|
|
ok( !!packet->reportBuffer, "got buffer %p\n", packet->reportBuffer );
|
|
|
|
|
|
|
|
irp->IoStatus.Information = 3;
|
|
|
|
ret = STATUS_SUCCESS;
|
|
|
|
break;
|
|
|
|
}
|
2021-07-05 10:44:55 +02:00
|
|
|
|
2021-09-09 08:50:08 +02:00
|
|
|
case IOCTL_HID_GET_FEATURE:
|
|
|
|
{
|
|
|
|
HID_XFER_PACKET *packet = irp->UserBuffer;
|
2021-09-10 09:22:43 +02:00
|
|
|
ULONG expected_size = caps.FeatureReportByteLength - (report_id ? 0 : 1);
|
2021-09-09 08:50:08 +02:00
|
|
|
ok( !in_size, "got input size %u\n", in_size );
|
|
|
|
ok( out_size == sizeof(*packet), "got output size %u\n", out_size );
|
|
|
|
|
|
|
|
ok( packet->reportId == report_id, "got id %u\n", packet->reportId );
|
|
|
|
ok( packet->reportBufferLen >= expected_size, "got len %u\n", packet->reportBufferLen );
|
|
|
|
ok( !!packet->reportBuffer, "got buffer %p\n", packet->reportBuffer );
|
|
|
|
|
|
|
|
memset( packet->reportBuffer, 0xa5, 3 );
|
|
|
|
if (report_id) ((char *)packet->reportBuffer)[0] = report_id;
|
|
|
|
irp->IoStatus.Information = 3;
|
|
|
|
ret = STATUS_SUCCESS;
|
|
|
|
break;
|
|
|
|
}
|
2021-07-05 10:44:55 +02:00
|
|
|
|
2021-09-09 08:50:08 +02:00
|
|
|
case IOCTL_HID_SET_FEATURE:
|
|
|
|
{
|
|
|
|
HID_XFER_PACKET *packet = irp->UserBuffer;
|
2021-09-10 09:22:43 +02:00
|
|
|
ULONG expected_size = caps.FeatureReportByteLength - (report_id ? 0 : 1);
|
2021-09-09 08:50:08 +02:00
|
|
|
ok( in_size == sizeof(*packet), "got input size %u\n", in_size );
|
|
|
|
ok( !out_size, "got output size %u\n", out_size );
|
|
|
|
|
|
|
|
ok( packet->reportId == report_id, "got id %u\n", packet->reportId );
|
|
|
|
ok( packet->reportBufferLen >= expected_size, "got len %u\n", packet->reportBufferLen );
|
|
|
|
ok( !!packet->reportBuffer, "got buffer %p\n", packet->reportBuffer );
|
|
|
|
|
|
|
|
irp->IoStatus.Information = 3;
|
|
|
|
ret = STATUS_SUCCESS;
|
|
|
|
break;
|
|
|
|
}
|
2021-07-05 10:44:55 +02:00
|
|
|
|
2021-09-09 08:50:08 +02:00
|
|
|
case IOCTL_HID_GET_STRING:
|
|
|
|
ok( !in_size, "got input size %u\n", in_size );
|
|
|
|
ok( out_size == 128, "got output size %u\n", out_size );
|
2021-04-14 16:40:00 +02:00
|
|
|
|
2021-09-09 08:50:08 +02:00
|
|
|
memcpy( irp->UserBuffer, L"Wine Test", sizeof(L"Wine Test") );
|
|
|
|
irp->IoStatus.Information = sizeof(L"Wine Test");
|
|
|
|
ret = STATUS_SUCCESS;
|
|
|
|
break;
|
2021-04-14 16:40:00 +02:00
|
|
|
|
2021-09-09 08:50:08 +02:00
|
|
|
default:
|
|
|
|
ok( 0, "unexpected ioctl %#x\n", code );
|
|
|
|
ret = STATUS_NOT_IMPLEMENTED;
|
2021-04-14 16:40:00 +02:00
|
|
|
}
|
|
|
|
|
2021-07-06 11:00:48 +02:00
|
|
|
if (ret != STATUS_PENDING)
|
|
|
|
{
|
|
|
|
irp->IoStatus.Status = ret;
|
2021-09-09 08:50:08 +02:00
|
|
|
IoCompleteRequest( irp, IO_NO_INCREMENT );
|
2021-07-06 11:00:48 +02:00
|
|
|
}
|
2021-04-14 16:40:00 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-09-09 08:50:08 +02:00
|
|
|
static NTSTATUS WINAPI driver_ioctl( DEVICE_OBJECT *device, IRP *irp )
|
2021-04-14 16:40:00 +02:00
|
|
|
{
|
|
|
|
HID_DEVICE_EXTENSION *ext = device->DeviceExtension;
|
|
|
|
|
2021-09-09 08:50:08 +02:00
|
|
|
ok( 0, "unexpected call\n" );
|
|
|
|
IoSkipCurrentIrpStackLocation( irp );
|
|
|
|
return IoCallDriver( ext->NextDeviceObject, irp );
|
2021-04-14 16:40:00 +02:00
|
|
|
}
|
|
|
|
|
2021-09-09 08:50:08 +02:00
|
|
|
static NTSTATUS WINAPI driver_add_device( DRIVER_OBJECT *driver, DEVICE_OBJECT *fdo )
|
2021-04-14 16:40:00 +02:00
|
|
|
{
|
|
|
|
HID_DEVICE_EXTENSION *ext = fdo->DeviceExtension;
|
|
|
|
NTSTATUS ret;
|
|
|
|
|
|
|
|
/* We should be given the FDO, not the PDO. */
|
2021-09-09 08:50:08 +02:00
|
|
|
ok( !!ext->PhysicalDeviceObject, "expected non-NULL pdo\n" );
|
|
|
|
ok( ext->NextDeviceObject == ext->PhysicalDeviceObject, "got pdo %p, next %p\n",
|
|
|
|
ext->PhysicalDeviceObject, ext->NextDeviceObject );
|
|
|
|
todo_wine
|
|
|
|
ok( ext->NextDeviceObject->AttachedDevice == fdo, "wrong attached device\n" );
|
2021-04-14 16:40:00 +02:00
|
|
|
|
2021-09-09 08:50:08 +02:00
|
|
|
ret = IoRegisterDeviceInterface( ext->PhysicalDeviceObject, &control_class, NULL, &control_symlink );
|
|
|
|
ok( !ret, "got %#x\n", ret );
|
2021-04-14 16:40:00 +02:00
|
|
|
|
|
|
|
fdo->Flags &= ~DO_DEVICE_INITIALIZING;
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2021-09-09 08:50:08 +02:00
|
|
|
static NTSTATUS WINAPI driver_create( DEVICE_OBJECT *device, IRP *irp )
|
2021-04-14 16:40:00 +02:00
|
|
|
{
|
2021-09-09 08:50:08 +02:00
|
|
|
ok( 0, "unexpected call\n" );
|
2021-04-14 16:40:00 +02:00
|
|
|
irp->IoStatus.Status = STATUS_SUCCESS;
|
2021-09-09 08:50:08 +02:00
|
|
|
IoCompleteRequest( irp, IO_NO_INCREMENT );
|
2021-04-14 16:40:00 +02:00
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2021-09-09 08:50:08 +02:00
|
|
|
static NTSTATUS WINAPI driver_close( DEVICE_OBJECT *device, IRP *irp )
|
2021-04-14 16:40:00 +02:00
|
|
|
{
|
2021-09-09 08:50:08 +02:00
|
|
|
ok( 0, "unexpected call\n" );
|
2021-04-14 16:40:00 +02:00
|
|
|
irp->IoStatus.Status = STATUS_SUCCESS;
|
2021-09-09 08:50:08 +02:00
|
|
|
IoCompleteRequest( irp, IO_NO_INCREMENT );
|
2021-04-14 16:40:00 +02:00
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2021-09-09 08:50:08 +02:00
|
|
|
static void WINAPI driver_unload( DRIVER_OBJECT *driver )
|
2021-04-14 16:40:00 +02:00
|
|
|
{
|
|
|
|
winetest_cleanup();
|
|
|
|
}
|
|
|
|
|
2021-09-09 08:50:08 +02:00
|
|
|
NTSTATUS WINAPI DriverEntry( DRIVER_OBJECT *driver, UNICODE_STRING *registry )
|
2021-04-14 16:40:00 +02:00
|
|
|
{
|
2021-06-16 11:20:50 +02:00
|
|
|
static const int info_size = offsetof( KEY_VALUE_PARTIAL_INFORMATION, Data );
|
2021-09-10 09:22:41 +02:00
|
|
|
char buffer[offsetof( KEY_VALUE_PARTIAL_INFORMATION, Data ) + sizeof(report_descriptor_buf)];
|
2021-04-14 16:40:00 +02:00
|
|
|
HID_MINIDRIVER_REGISTRATION params =
|
|
|
|
{
|
|
|
|
.Revision = HID_REVISION,
|
|
|
|
.DriverObject = driver,
|
2021-07-06 11:00:48 +02:00
|
|
|
.DeviceExtensionSize = sizeof(struct hid_device),
|
2021-04-14 16:40:00 +02:00
|
|
|
.RegistryPath = registry,
|
|
|
|
};
|
2021-06-16 11:20:50 +02:00
|
|
|
UNICODE_STRING name_str;
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
2021-04-14 16:40:00 +02:00
|
|
|
NTSTATUS ret;
|
2021-06-16 11:20:50 +02:00
|
|
|
HANDLE hkey;
|
|
|
|
DWORD size;
|
2021-04-14 16:40:00 +02:00
|
|
|
|
2021-09-09 08:50:08 +02:00
|
|
|
if ((ret = winetest_init())) return ret;
|
2021-04-14 16:40:00 +02:00
|
|
|
|
2021-09-09 08:50:08 +02:00
|
|
|
InitializeObjectAttributes( &attr, registry, 0, NULL, NULL );
|
|
|
|
ret = ZwOpenKey( &hkey, KEY_ALL_ACCESS, &attr );
|
|
|
|
ok( !ret, "ZwOpenKey returned %#x\n", ret );
|
2021-06-16 11:20:50 +02:00
|
|
|
|
2021-09-09 08:50:08 +02:00
|
|
|
RtlInitUnicodeString( &name_str, L"ReportID" );
|
2021-06-16 11:20:50 +02:00
|
|
|
size = info_size + sizeof(report_id);
|
2021-09-09 08:50:08 +02:00
|
|
|
ret = ZwQueryValueKey( hkey, &name_str, KeyValuePartialInformation, buffer, size, &size );
|
|
|
|
ok( !ret, "ZwQueryValueKey returned %#x\n", ret );
|
|
|
|
memcpy( &report_id, buffer + info_size, size - info_size );
|
2021-06-16 11:20:50 +02:00
|
|
|
|
2021-09-09 08:50:08 +02:00
|
|
|
RtlInitUnicodeString( &name_str, L"PolledMode" );
|
2021-07-06 11:00:49 +02:00
|
|
|
size = info_size + sizeof(polled);
|
2021-09-09 08:50:08 +02:00
|
|
|
ret = ZwQueryValueKey( hkey, &name_str, KeyValuePartialInformation, buffer, size, &size );
|
|
|
|
ok( !ret, "ZwQueryValueKey returned %#x\n", ret );
|
|
|
|
memcpy( &polled, buffer + info_size, size - info_size );
|
2021-07-06 11:00:49 +02:00
|
|
|
params.DevicesArePolled = polled;
|
|
|
|
|
2021-09-10 09:22:41 +02:00
|
|
|
RtlInitUnicodeString( &name_str, L"Descriptor" );
|
|
|
|
size = info_size + sizeof(report_descriptor_buf);
|
|
|
|
ret = ZwQueryValueKey( hkey, &name_str, KeyValuePartialInformation, buffer, size, &size );
|
|
|
|
ok( !ret, "ZwQueryValueKey returned %#x\n", ret );
|
|
|
|
memcpy( report_descriptor_buf, buffer + info_size, size - info_size );
|
|
|
|
report_descriptor_len = size - info_size;
|
|
|
|
|
2021-09-10 09:22:42 +02:00
|
|
|
RtlInitUnicodeString( &name_str, L"Attributes" );
|
|
|
|
size = info_size + sizeof(attributes);
|
|
|
|
ret = ZwQueryValueKey( hkey, &name_str, KeyValuePartialInformation, buffer, size, &size );
|
|
|
|
ok( !ret, "ZwQueryValueKey returned %#x\n", ret );
|
|
|
|
memcpy( &attributes, buffer + info_size, size - info_size );
|
|
|
|
|
2021-09-10 09:22:43 +02:00
|
|
|
RtlInitUnicodeString( &name_str, L"Caps" );
|
|
|
|
size = info_size + sizeof(caps);
|
|
|
|
ret = ZwQueryValueKey( hkey, &name_str, KeyValuePartialInformation, buffer, size, &size );
|
|
|
|
ok( !ret, "ZwQueryValueKey returned %#x\n", ret );
|
|
|
|
memcpy( &caps, buffer + info_size, size - info_size );
|
|
|
|
|
2021-04-14 16:40:00 +02:00
|
|
|
driver->DriverExtension->AddDevice = driver_add_device;
|
|
|
|
driver->DriverUnload = driver_unload;
|
|
|
|
driver->MajorFunction[IRP_MJ_PNP] = driver_pnp;
|
|
|
|
driver->MajorFunction[IRP_MJ_POWER] = driver_power;
|
|
|
|
driver->MajorFunction[IRP_MJ_DEVICE_CONTROL] = driver_ioctl;
|
|
|
|
driver->MajorFunction[IRP_MJ_INTERNAL_DEVICE_CONTROL] = driver_internal_ioctl;
|
|
|
|
driver->MajorFunction[IRP_MJ_CREATE] = driver_create;
|
|
|
|
driver->MajorFunction[IRP_MJ_CLOSE] = driver_close;
|
|
|
|
|
2021-09-09 08:50:08 +02:00
|
|
|
ret = HidRegisterMinidriver( ¶ms );
|
|
|
|
ok( !ret, "got %#x\n", ret );
|
2021-04-14 16:40:00 +02:00
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|