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-09-13 10:48:53 +02:00
|
|
|
#define EXPECT_QUEUE_BUFFER_SIZE (64 * sizeof(struct hid_expect))
|
|
|
|
|
|
|
|
struct expect_queue
|
|
|
|
{
|
|
|
|
KSPIN_LOCK lock;
|
|
|
|
struct hid_expect *pos;
|
|
|
|
struct hid_expect *end;
|
|
|
|
struct hid_expect spurious;
|
|
|
|
struct hid_expect *buffer;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void expect_queue_init( struct expect_queue *queue )
|
|
|
|
{
|
|
|
|
KeInitializeSpinLock( &queue->lock );
|
|
|
|
queue->buffer = ExAllocatePool( PagedPool, EXPECT_QUEUE_BUFFER_SIZE );
|
|
|
|
RtlSecureZeroMemory( queue->buffer, EXPECT_QUEUE_BUFFER_SIZE );
|
|
|
|
queue->pos = queue->buffer;
|
|
|
|
queue->end = queue->buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void expect_queue_cleanup( struct expect_queue *queue )
|
|
|
|
{
|
|
|
|
ExFreePool( queue->buffer );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void expect_queue_reset( struct expect_queue *queue, void *buffer, unsigned int size )
|
|
|
|
{
|
|
|
|
struct hid_expect *missing, *missing_end, *tmp;
|
|
|
|
KIRQL irql;
|
|
|
|
|
|
|
|
missing = ExAllocatePool( PagedPool, EXPECT_QUEUE_BUFFER_SIZE );
|
|
|
|
RtlSecureZeroMemory( missing, EXPECT_QUEUE_BUFFER_SIZE );
|
|
|
|
missing_end = missing;
|
|
|
|
|
|
|
|
KeAcquireSpinLock( &queue->lock, &irql );
|
|
|
|
tmp = queue->pos;
|
|
|
|
while (tmp < queue->end) *missing_end++ = *tmp++;
|
|
|
|
|
|
|
|
queue->pos = queue->buffer;
|
|
|
|
queue->end = queue->buffer;
|
|
|
|
|
|
|
|
if (size) memcpy( queue->end, buffer, size );
|
|
|
|
queue->end = queue->end + size / sizeof(struct hid_expect);
|
|
|
|
KeReleaseSpinLock( &queue->lock, irql );
|
|
|
|
|
|
|
|
tmp = missing;
|
|
|
|
while (tmp != missing_end)
|
|
|
|
{
|
|
|
|
winetest_push_context( "%s expect[%d]", tmp->context, tmp - missing );
|
|
|
|
if (tmp->broken)
|
2021-09-30 10:37:35 +02:00
|
|
|
{
|
|
|
|
todo_wine_if( tmp->todo )
|
2021-09-13 10:48:53 +02:00
|
|
|
win_skip( "broken (code %#x id %u len %u)\n", tmp->code, tmp->report_id, tmp->report_len );
|
2021-09-30 10:37:35 +02:00
|
|
|
}
|
2021-09-13 10:48:53 +02:00
|
|
|
else
|
2021-09-30 10:37:35 +02:00
|
|
|
{
|
|
|
|
todo_wine_if( tmp->todo )
|
2021-09-13 10:48:53 +02:00
|
|
|
ok( 0, "missing (code %#x id %u len %u)\n", tmp->code, tmp->report_id, tmp->report_len );
|
2021-09-30 10:37:35 +02:00
|
|
|
}
|
2021-09-13 10:48:53 +02:00
|
|
|
winetest_pop_context();
|
|
|
|
tmp++;
|
|
|
|
}
|
|
|
|
|
|
|
|
ExFreePool( missing );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void expect_queue_next( struct expect_queue *queue, ULONG code, HID_XFER_PACKET *packet,
|
2021-09-13 10:48:54 +02:00
|
|
|
LONG *index, struct hid_expect *expect, BOOL compare_buf )
|
2021-09-13 10:48:53 +02:00
|
|
|
{
|
|
|
|
struct hid_expect *missing, *missing_end, *tmp;
|
|
|
|
ULONG len = packet->reportBufferLen;
|
|
|
|
BYTE *buf = packet->reportBuffer;
|
|
|
|
BYTE id = packet->reportId;
|
|
|
|
KIRQL irql;
|
|
|
|
|
|
|
|
missing = ExAllocatePool( PagedPool, EXPECT_QUEUE_BUFFER_SIZE );
|
|
|
|
RtlSecureZeroMemory( missing, EXPECT_QUEUE_BUFFER_SIZE );
|
|
|
|
missing_end = missing;
|
|
|
|
|
|
|
|
KeAcquireSpinLock( &queue->lock, &irql );
|
|
|
|
tmp = queue->pos;
|
|
|
|
while (tmp < queue->end)
|
|
|
|
{
|
2021-09-30 10:37:35 +02:00
|
|
|
if (running_under_wine && !tmp->todo) break;
|
|
|
|
if (!running_under_wine && !tmp->broken) break;
|
2021-09-13 10:48:53 +02:00
|
|
|
if (tmp->code == code && tmp->report_id == id && tmp->report_len == len &&
|
2021-09-13 10:48:54 +02:00
|
|
|
(!compare_buf || RtlCompareMemory( tmp->report_buf, buf, len ) == len))
|
2021-09-13 10:48:53 +02:00
|
|
|
break;
|
|
|
|
*missing_end++ = *tmp++;
|
|
|
|
}
|
|
|
|
*index = tmp - queue->buffer;
|
|
|
|
if (tmp < queue->end) queue->pos = tmp + 1;
|
|
|
|
else tmp = &queue->spurious;
|
|
|
|
*expect = *tmp;
|
|
|
|
KeReleaseSpinLock( &queue->lock, irql );
|
|
|
|
|
|
|
|
ok( tmp != &queue->spurious, "got spurious packet\n" );
|
|
|
|
|
2021-09-30 10:37:40 +02:00
|
|
|
winetest_push_context( "%s expect[%d]", tmp->context, tmp - queue->buffer );
|
|
|
|
todo_wine_if( tmp->todo )
|
|
|
|
ok( 1, "found code %#x id %u len %u\n", tmp->code, tmp->report_id, tmp->report_len );
|
|
|
|
winetest_pop_context();
|
|
|
|
|
2021-09-13 10:48:53 +02:00
|
|
|
tmp = missing;
|
|
|
|
while (tmp != missing_end)
|
|
|
|
{
|
|
|
|
winetest_push_context( "%s expect[%d]", tmp->context, tmp - missing );
|
|
|
|
if (tmp->broken)
|
2021-09-30 10:37:35 +02:00
|
|
|
{
|
|
|
|
todo_wine_if( tmp->todo )
|
2021-09-13 10:48:53 +02:00
|
|
|
win_skip( "broken (code %#x id %u len %u)\n", tmp->code, tmp->report_id, tmp->report_len );
|
2021-09-30 10:37:35 +02:00
|
|
|
}
|
2021-09-13 10:48:53 +02:00
|
|
|
else
|
2021-09-30 10:37:35 +02:00
|
|
|
{
|
|
|
|
todo_wine_if( tmp->todo )
|
2021-09-13 10:48:53 +02:00
|
|
|
ok( 0, "missing (code %#x id %u len %u)\n", tmp->code, tmp->report_id, tmp->report_len );
|
2021-09-30 10:37:35 +02:00
|
|
|
}
|
2021-09-13 10:48:53 +02:00
|
|
|
winetest_pop_context();
|
|
|
|
tmp++;
|
|
|
|
}
|
|
|
|
|
|
|
|
ExFreePool( missing );
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct expect_queue expect_queue;
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-09-14 10:38:38 +02:00
|
|
|
struct input_queue
|
|
|
|
{
|
|
|
|
KSPIN_LOCK lock;
|
|
|
|
struct hid_expect *pos;
|
|
|
|
struct hid_expect *end;
|
|
|
|
struct hid_expect *buffer;
|
|
|
|
struct irp_queue pending;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void input_queue_init( struct input_queue *queue )
|
|
|
|
{
|
|
|
|
KeInitializeSpinLock( &queue->lock );
|
|
|
|
queue->buffer = ExAllocatePool( PagedPool, EXPECT_QUEUE_BUFFER_SIZE );
|
|
|
|
RtlSecureZeroMemory( queue->buffer, EXPECT_QUEUE_BUFFER_SIZE );
|
|
|
|
queue->pos = queue->buffer;
|
|
|
|
queue->end = queue->buffer;
|
|
|
|
irp_queue_init( &queue->pending );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void input_queue_cleanup( struct input_queue *queue )
|
|
|
|
{
|
|
|
|
ExFreePool( queue->buffer );
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL input_queue_read_locked( struct input_queue *queue, IRP *irp )
|
|
|
|
{
|
2021-09-17 09:06:23 +02:00
|
|
|
IO_STACK_LOCATION *stack = IoGetCurrentIrpStackLocation( irp );
|
|
|
|
ULONG out_size = stack->Parameters.DeviceIoControl.OutputBufferLength;
|
2021-09-14 10:38:38 +02:00
|
|
|
struct hid_expect *tmp = queue->pos;
|
2021-09-17 09:06:23 +02:00
|
|
|
|
2021-09-14 10:38:38 +02:00
|
|
|
if (tmp >= queue->end) return FALSE;
|
2021-09-17 09:06:23 +02:00
|
|
|
if (tmp->ret_length) out_size = tmp->ret_length;
|
2021-09-14 10:38:38 +02:00
|
|
|
|
2021-09-17 09:06:23 +02:00
|
|
|
memcpy( irp->UserBuffer, tmp->report_buf, out_size );
|
|
|
|
irp->IoStatus.Information = out_size;
|
2021-09-14 10:38:38 +02:00
|
|
|
irp->IoStatus.Status = tmp->ret_status;
|
|
|
|
if (tmp < queue->end) queue->pos = tmp + 1;
|
|
|
|
|
|
|
|
/* loop on the queue data in polled mode */
|
|
|
|
if (polled && queue->pos == queue->end) queue->pos = queue->buffer;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static NTSTATUS input_queue_read( struct input_queue *queue, IRP *irp )
|
|
|
|
{
|
|
|
|
NTSTATUS status;
|
|
|
|
KIRQL irql;
|
|
|
|
|
|
|
|
KeAcquireSpinLock( &queue->lock, &irql );
|
|
|
|
if (input_queue_read_locked( queue, irp )) status = STATUS_SUCCESS;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
IoMarkIrpPending( irp );
|
|
|
|
irp_queue_push( &queue->pending, irp );
|
|
|
|
status = STATUS_PENDING;
|
|
|
|
}
|
|
|
|
KeReleaseSpinLock( &queue->lock, irql );
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void input_queue_reset( struct input_queue *queue, void *in_buf, ULONG in_size )
|
|
|
|
{
|
|
|
|
struct irp_queue completed;
|
|
|
|
ULONG remaining;
|
|
|
|
KIRQL irql;
|
|
|
|
IRP *irp;
|
|
|
|
|
|
|
|
irp_queue_init( &completed );
|
|
|
|
|
|
|
|
KeAcquireSpinLock( &queue->lock, &irql );
|
|
|
|
remaining = queue->end - queue->pos;
|
|
|
|
queue->pos = queue->buffer;
|
|
|
|
queue->end = queue->buffer;
|
|
|
|
memcpy( queue->end, in_buf, in_size );
|
|
|
|
queue->end += in_size / sizeof(struct hid_expect);
|
|
|
|
|
|
|
|
while (!polled && queue->pos < queue->end && (irp = irp_queue_pop( &queue->pending )))
|
|
|
|
{
|
|
|
|
input_queue_read_locked( queue, irp );
|
|
|
|
irp_queue_push( &completed, irp );
|
|
|
|
}
|
|
|
|
KeReleaseSpinLock( &queue->lock, irql );
|
|
|
|
|
|
|
|
if (!polled) ok( !remaining, "unread input\n" );
|
|
|
|
|
|
|
|
while ((irp = irp_queue_pop( &completed ))) IoCompleteRequest( irp, IO_NO_INCREMENT );
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct input_queue input_queue;
|
|
|
|
|
2021-07-06 11:00:48 +02:00
|
|
|
struct hid_device
|
|
|
|
{
|
|
|
|
BOOL removed;
|
|
|
|
KSPIN_LOCK lock;
|
|
|
|
};
|
|
|
|
|
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 );
|
|
|
|
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 );
|
2021-09-14 10:38:38 +02:00
|
|
|
irp_queue_clear( &input_queue.pending );
|
2021-09-09 08:50:08 +02:00
|
|
|
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:
|
2021-09-14 10:38:38 +02:00
|
|
|
irp_queue_clear( &input_queue.pending );
|
2021-09-09 08:50:08 +02:00
|
|
|
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;
|
2021-09-14 10:38:38 +02:00
|
|
|
ULONG out_size = stack->Parameters.DeviceIoControl.OutputBufferLength;
|
2021-04-14 16:40:00 +02:00
|
|
|
const ULONG code = stack->Parameters.DeviceIoControl.IoControlCode;
|
2021-09-13 10:48:53 +02:00
|
|
|
struct hid_expect expect = {0};
|
2021-04-14 16:40:00 +02:00
|
|
|
NTSTATUS ret;
|
2021-07-06 11:00:48 +02:00
|
|
|
BOOL removed;
|
|
|
|
KIRQL irql;
|
2021-09-13 10:48:53 +02:00
|
|
|
LONG index;
|
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-09-13 10:48:53 +02:00
|
|
|
winetest_push_context( "id %d%s", report_id, polled ? " poll" : "" );
|
|
|
|
|
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-09-14 10:38:38 +02:00
|
|
|
ret = input_queue_read( &input_queue, irp );
|
2021-09-09 08:50:08 +02:00
|
|
|
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-13 10:48:56 +02:00
|
|
|
expect_queue_next( &expect_queue, code, packet, &index, &expect, TRUE );
|
|
|
|
winetest_push_context( "%s expect[%d]", expect.context, index );
|
|
|
|
ok( expect.code == code, "got %#x, expected %#x\n", expect.code, code );
|
|
|
|
ok( packet->reportId == expect.report_id, "got id %u\n", packet->reportId );
|
|
|
|
ok( packet->reportBufferLen == expect.report_len, "got len %u\n", packet->reportBufferLen );
|
|
|
|
ok( RtlCompareMemory( packet->reportBuffer, expect.report_buf, expect.report_len ) == expect.report_len,
|
|
|
|
"unexpected data\n" );
|
|
|
|
winetest_pop_context();
|
2021-07-05 10:44:54 +02:00
|
|
|
|
2021-09-17 09:06:23 +02:00
|
|
|
irp->IoStatus.Information = expect.ret_length ? expect.ret_length : expect.report_len;
|
2021-09-13 10:48:56 +02:00
|
|
|
ret = expect.ret_status;
|
2021-09-09 08:50:08 +02:00
|
|
|
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->reportBufferLen >= expected_size, "got len %u\n", packet->reportBufferLen );
|
|
|
|
ok( !!packet->reportBuffer, "got buffer %p\n", packet->reportBuffer );
|
|
|
|
|
2021-09-13 10:48:57 +02:00
|
|
|
expect_queue_next( &expect_queue, code, packet, &index, &expect, FALSE );
|
|
|
|
winetest_push_context( "%s expect[%d]", expect.context, index );
|
|
|
|
ok( expect.code == code, "got %#x, expected %#x\n", expect.code, code );
|
|
|
|
ok( packet->reportId == expect.report_id, "got id %u\n", packet->reportId );
|
|
|
|
ok( packet->reportBufferLen == expect.report_len, "got len %u\n", packet->reportBufferLen );
|
|
|
|
winetest_pop_context();
|
|
|
|
|
2021-09-17 09:06:23 +02:00
|
|
|
irp->IoStatus.Information = expect.ret_length ? expect.ret_length : expect.report_len;
|
|
|
|
memcpy( packet->reportBuffer, expect.report_buf, irp->IoStatus.Information );
|
2021-09-13 10:48:57 +02:00
|
|
|
ret = expect.ret_status;
|
2021-09-09 08:50:08 +02:00
|
|
|
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->reportBufferLen >= expected_size, "got len %u\n", packet->reportBufferLen );
|
|
|
|
ok( !!packet->reportBuffer, "got buffer %p\n", packet->reportBuffer );
|
|
|
|
|
2021-09-13 10:48:55 +02:00
|
|
|
expect_queue_next( &expect_queue, code, packet, &index, &expect, TRUE );
|
|
|
|
winetest_push_context( "%s expect[%d]", expect.context, index );
|
|
|
|
ok( expect.code == code, "got %#x, expected %#x\n", expect.code, code );
|
|
|
|
ok( packet->reportId == expect.report_id, "got id %u\n", packet->reportId );
|
|
|
|
ok( packet->reportBufferLen == expect.report_len, "got len %u\n", packet->reportBufferLen );
|
|
|
|
ok( RtlCompareMemory( packet->reportBuffer, expect.report_buf, expect.report_len ) == expect.report_len,
|
|
|
|
"unexpected data\n" );
|
|
|
|
winetest_pop_context();
|
|
|
|
|
2021-09-17 09:06:23 +02:00
|
|
|
irp->IoStatus.Information = expect.ret_length ? expect.ret_length : expect.report_len;
|
2021-09-13 10:48:55 +02:00
|
|
|
ret = expect.ret_status;
|
2021-09-09 08:50:08 +02:00
|
|
|
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->reportBufferLen >= expected_size, "got len %u\n", packet->reportBufferLen );
|
|
|
|
ok( !!packet->reportBuffer, "got buffer %p\n", packet->reportBuffer );
|
|
|
|
|
2021-09-13 10:48:54 +02:00
|
|
|
expect_queue_next( &expect_queue, code, packet, &index, &expect, FALSE );
|
|
|
|
winetest_push_context( "%s expect[%d]", expect.context, index );
|
|
|
|
ok( expect.code == code, "got %#x, expected %#x\n", expect.code, code );
|
|
|
|
ok( packet->reportId == expect.report_id, "got id %u\n", packet->reportId );
|
|
|
|
ok( packet->reportBufferLen == expect.report_len, "got len %u\n", packet->reportBufferLen );
|
|
|
|
winetest_pop_context();
|
|
|
|
|
2021-09-17 09:06:23 +02:00
|
|
|
irp->IoStatus.Information = expect.ret_length ? expect.ret_length : expect.report_len;
|
|
|
|
memcpy( packet->reportBuffer, expect.report_buf, irp->IoStatus.Information );
|
2021-09-13 10:48:54 +02:00
|
|
|
ret = expect.ret_status;
|
2021-09-09 08:50:08 +02:00
|
|
|
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->reportBufferLen >= expected_size, "got len %u\n", packet->reportBufferLen );
|
|
|
|
ok( !!packet->reportBuffer, "got buffer %p\n", packet->reportBuffer );
|
|
|
|
|
2021-09-13 10:48:54 +02:00
|
|
|
expect_queue_next( &expect_queue, code, packet, &index, &expect, TRUE );
|
2021-09-13 10:48:53 +02:00
|
|
|
winetest_push_context( "%s expect[%d]", expect.context, index );
|
|
|
|
ok( expect.code == code, "got %#x, expected %#x\n", expect.code, code );
|
|
|
|
ok( packet->reportId == expect.report_id, "got id %u\n", packet->reportId );
|
|
|
|
ok( packet->reportBufferLen == expect.report_len, "got len %u\n", packet->reportBufferLen );
|
|
|
|
ok( RtlCompareMemory( packet->reportBuffer, expect.report_buf, expect.report_len ) == expect.report_len,
|
|
|
|
"unexpected data\n" );
|
|
|
|
winetest_pop_context();
|
|
|
|
|
2021-09-17 09:06:23 +02:00
|
|
|
irp->IoStatus.Information = expect.ret_length ? expect.ret_length : expect.report_len;
|
2021-09-13 10:48:53 +02:00
|
|
|
ret = expect.ret_status;
|
2021-09-09 08:50:08 +02:00
|
|
|
break;
|
|
|
|
}
|
2021-07-05 10:44:55 +02:00
|
|
|
|
2021-09-09 08:50:08 +02:00
|
|
|
case IOCTL_HID_GET_STRING:
|
2021-09-14 10:38:40 +02:00
|
|
|
todo_wine
|
|
|
|
ok( 0, "unexpected IOCTL_HID_GET_STRING\n" );
|
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-09-13 10:48:53 +02:00
|
|
|
winetest_pop_context();
|
|
|
|
|
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-13 10:48:53 +02:00
|
|
|
static NTSTATUS( WINAPI *hidclass_driver_ioctl )(DEVICE_OBJECT *device, IRP *irp);
|
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
|
|
|
{
|
2021-09-13 10:48:53 +02:00
|
|
|
IO_STACK_LOCATION *stack = IoGetCurrentIrpStackLocation( irp );
|
|
|
|
ULONG in_size = stack->Parameters.DeviceIoControl.InputBufferLength;
|
|
|
|
ULONG code = stack->Parameters.DeviceIoControl.IoControlCode;
|
2021-04-14 16:40:00 +02:00
|
|
|
|
2021-09-13 10:48:53 +02:00
|
|
|
switch (code)
|
|
|
|
{
|
|
|
|
case IOCTL_WINETEST_HID_SET_EXPECT:
|
|
|
|
expect_queue_reset( &expect_queue, irp->AssociatedIrp.SystemBuffer, in_size );
|
|
|
|
irp->IoStatus.Status = STATUS_SUCCESS;
|
|
|
|
IoCompleteRequest( irp, IO_NO_INCREMENT );
|
|
|
|
return STATUS_SUCCESS;
|
2021-09-14 10:38:38 +02:00
|
|
|
case IOCTL_WINETEST_HID_SEND_INPUT:
|
|
|
|
input_queue_reset( &input_queue, irp->AssociatedIrp.SystemBuffer, in_size );
|
|
|
|
irp->IoStatus.Status = STATUS_SUCCESS;
|
|
|
|
IoCompleteRequest( irp, IO_NO_INCREMENT );
|
|
|
|
return STATUS_SUCCESS;
|
2021-09-13 10:48:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return hidclass_driver_ioctl( device, 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
|
|
|
{
|
2021-09-14 10:38:38 +02:00
|
|
|
input_queue_cleanup( &input_queue );
|
2021-09-13 10:48:53 +02:00
|
|
|
expect_queue_cleanup( &expect_queue );
|
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-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-09-13 10:48:53 +02:00
|
|
|
char *buffer;
|
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-13 10:48:53 +02:00
|
|
|
buffer = ExAllocatePool( PagedPool, info_size + EXPECT_QUEUE_BUFFER_SIZE );
|
|
|
|
ok( buffer != NULL, "ExAllocatePool failed\n" );
|
|
|
|
if (!buffer) return STATUS_NO_MEMORY;
|
|
|
|
|
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-09-13 10:48:53 +02:00
|
|
|
expect_queue_init( &expect_queue );
|
|
|
|
RtlInitUnicodeString( &name_str, L"Expect" );
|
|
|
|
size = info_size + EXPECT_QUEUE_BUFFER_SIZE;
|
|
|
|
ret = ZwQueryValueKey( hkey, &name_str, KeyValuePartialInformation, buffer, size, &size );
|
|
|
|
ok( !ret, "ZwQueryValueKey returned %#x\n", ret );
|
|
|
|
expect_queue_reset( &expect_queue, buffer + info_size, size - info_size );
|
|
|
|
|
2021-09-14 10:38:38 +02:00
|
|
|
input_queue_init( &input_queue );
|
|
|
|
RtlInitUnicodeString( &name_str, L"Input" );
|
|
|
|
size = info_size + EXPECT_QUEUE_BUFFER_SIZE;
|
|
|
|
ret = ZwQueryValueKey( hkey, &name_str, KeyValuePartialInformation, buffer, size, &size );
|
|
|
|
ok( !ret, "ZwQueryValueKey returned %#x\n", ret );
|
|
|
|
input_queue_reset( &input_queue, 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-13 10:48:53 +02:00
|
|
|
ExFreePool( buffer );
|
|
|
|
|
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
|
|
|
|
2021-09-13 10:48:53 +02:00
|
|
|
hidclass_driver_ioctl = driver->MajorFunction[IRP_MJ_DEVICE_CONTROL];
|
|
|
|
driver->MajorFunction[IRP_MJ_DEVICE_CONTROL] = driver_ioctl;
|
|
|
|
|
2021-04-14 16:40:00 +02:00
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|