2016-09-01 15:18:17 +02:00
|
|
|
/*
|
|
|
|
* WINE Platform native bus driver
|
|
|
|
*
|
|
|
|
* Copyright 2016 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
|
|
|
|
*/
|
2021-09-17 08:50:31 +02:00
|
|
|
|
2016-09-01 15:18:17 +02:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include "ntstatus.h"
|
|
|
|
#define WIN32_NO_STATUS
|
2021-09-17 08:50:31 +02:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winnls.h"
|
2016-09-01 15:18:17 +02:00
|
|
|
#include "winternl.h"
|
2016-10-06 14:19:27 +02:00
|
|
|
#include "winioctl.h"
|
2019-07-03 01:07:55 +02:00
|
|
|
#include "hidusage.h"
|
2016-09-01 15:18:17 +02:00
|
|
|
#include "ddk/wdm.h"
|
2016-10-06 14:19:27 +02:00
|
|
|
#include "ddk/hidport.h"
|
2019-07-03 01:07:55 +02:00
|
|
|
#include "ddk/hidtypes.h"
|
2019-11-12 19:02:20 +01:00
|
|
|
#include "wine/asm.h"
|
2016-09-01 15:18:17 +02:00
|
|
|
#include "wine/debug.h"
|
2016-09-14 09:28:51 +02:00
|
|
|
#include "wine/list.h"
|
2021-08-23 10:49:39 +02:00
|
|
|
#include "wine/unixlib.h"
|
2016-09-01 15:18:17 +02:00
|
|
|
|
2021-08-23 10:49:39 +02:00
|
|
|
#include "unixlib.h"
|
2016-09-08 10:12:50 +02:00
|
|
|
|
2016-09-01 15:18:17 +02:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(plugplay);
|
2016-10-26 17:49:41 +02:00
|
|
|
WINE_DECLARE_DEBUG_CHANNEL(hid_report);
|
2016-09-01 15:18:17 +02:00
|
|
|
|
2019-05-30 06:02:28 +02:00
|
|
|
static DRIVER_OBJECT *driver_obj;
|
|
|
|
|
2019-07-03 01:07:55 +02:00
|
|
|
static DEVICE_OBJECT *mouse_obj;
|
2021-04-22 21:26:49 +02:00
|
|
|
static DEVICE_OBJECT *keyboard_obj;
|
2019-07-03 01:07:55 +02:00
|
|
|
|
2019-11-07 06:54:58 +01:00
|
|
|
/* The root-enumerated device stack. */
|
2021-09-06 09:17:33 +02:00
|
|
|
static DEVICE_OBJECT *bus_pdo;
|
2019-11-07 06:55:02 +01:00
|
|
|
static DEVICE_OBJECT *bus_fdo;
|
2019-11-07 06:54:58 +01:00
|
|
|
|
2021-09-16 10:17:55 +02:00
|
|
|
static HANDLE driver_key;
|
2019-05-30 06:02:29 +02:00
|
|
|
|
2021-08-18 09:14:18 +02:00
|
|
|
enum device_state
|
|
|
|
{
|
|
|
|
DEVICE_STATE_STOPPED,
|
|
|
|
DEVICE_STATE_STARTED,
|
|
|
|
DEVICE_STATE_REMOVED,
|
|
|
|
};
|
|
|
|
|
2016-09-14 09:28:51 +02:00
|
|
|
struct device_extension
|
|
|
|
{
|
2021-08-23 10:49:42 +02:00
|
|
|
struct list entry;
|
|
|
|
DEVICE_OBJECT *device;
|
|
|
|
|
2021-04-15 06:22:03 +02:00
|
|
|
CRITICAL_SECTION cs;
|
2021-08-18 09:14:18 +02:00
|
|
|
enum device_state state;
|
2021-04-15 06:22:05 +02:00
|
|
|
|
2021-09-03 09:30:48 +02:00
|
|
|
struct device_desc desc;
|
|
|
|
DWORD index;
|
2016-10-03 13:29:49 +02:00
|
|
|
|
2021-09-13 13:01:46 +02:00
|
|
|
WCHAR manufacturer[MAX_PATH];
|
2021-09-13 13:01:47 +02:00
|
|
|
WCHAR product[MAX_PATH];
|
2021-09-13 13:01:48 +02:00
|
|
|
WCHAR serialnumber[MAX_PATH];
|
2021-09-13 13:01:46 +02:00
|
|
|
|
2016-10-26 17:49:41 +02:00
|
|
|
BYTE *last_report;
|
|
|
|
DWORD last_report_size;
|
|
|
|
BOOL last_report_read;
|
|
|
|
DWORD buffer_size;
|
|
|
|
LIST_ENTRY irp_queue;
|
|
|
|
|
2021-08-23 10:49:41 +02:00
|
|
|
struct unix_device *unix_device;
|
2016-09-14 09:28:51 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static CRITICAL_SECTION device_list_cs;
|
|
|
|
static CRITICAL_SECTION_DEBUG critsect_debug =
|
|
|
|
{
|
|
|
|
0, 0, &device_list_cs,
|
|
|
|
{ &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
|
|
|
|
0, 0, { (DWORD_PTR)(__FILE__ ": device_list_cs") }
|
|
|
|
};
|
|
|
|
static CRITICAL_SECTION device_list_cs = { &critsect_debug, -1, 0, 0, 0, 0 };
|
|
|
|
|
2021-08-23 10:49:42 +02:00
|
|
|
static struct list device_list = LIST_INIT(device_list);
|
2016-09-14 09:28:51 +02:00
|
|
|
|
2021-09-17 08:50:31 +02:00
|
|
|
static HMODULE instance;
|
2021-09-17 08:50:34 +02:00
|
|
|
static unixlib_handle_t winebus_handle;
|
2021-09-17 08:50:31 +02:00
|
|
|
|
2021-08-23 10:49:39 +02:00
|
|
|
static NTSTATUS winebus_call(unsigned int code, void *args)
|
|
|
|
{
|
2021-09-17 08:50:34 +02:00
|
|
|
return __wine_unix_call(winebus_handle, code, args);
|
2021-08-23 10:49:39 +02:00
|
|
|
}
|
|
|
|
|
2021-09-03 09:30:49 +02:00
|
|
|
static void unix_device_remove(DEVICE_OBJECT *device)
|
|
|
|
{
|
|
|
|
struct device_extension *ext = (struct device_extension *)device->DeviceExtension;
|
|
|
|
winebus_call(device_remove, ext->unix_device);
|
|
|
|
}
|
|
|
|
|
|
|
|
static NTSTATUS unix_device_start(DEVICE_OBJECT *device)
|
|
|
|
{
|
|
|
|
struct device_extension *ext = (struct device_extension *)device->DeviceExtension;
|
2021-09-15 09:04:46 +02:00
|
|
|
return winebus_call(device_start, ext->unix_device);
|
2021-09-03 09:30:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static NTSTATUS unix_device_get_report_descriptor(DEVICE_OBJECT *device, BYTE *buffer, DWORD length, DWORD *out_length)
|
|
|
|
{
|
|
|
|
struct device_extension *ext = (struct device_extension *)device->DeviceExtension;
|
|
|
|
struct device_descriptor_params params =
|
|
|
|
{
|
|
|
|
.iface = ext->unix_device,
|
|
|
|
.buffer = buffer,
|
|
|
|
.length = length,
|
|
|
|
.out_length = out_length
|
|
|
|
};
|
|
|
|
return winebus_call(device_get_report_descriptor, ¶ms);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void unix_device_set_output_report(DEVICE_OBJECT *device, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io)
|
|
|
|
{
|
|
|
|
struct device_extension *ext = (struct device_extension *)device->DeviceExtension;
|
|
|
|
struct device_report_params params =
|
|
|
|
{
|
|
|
|
.iface = ext->unix_device,
|
|
|
|
.packet = packet,
|
|
|
|
.io = io,
|
|
|
|
};
|
|
|
|
winebus_call(device_set_output_report, ¶ms);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void unix_device_get_feature_report(DEVICE_OBJECT *device, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io)
|
|
|
|
{
|
|
|
|
struct device_extension *ext = (struct device_extension *)device->DeviceExtension;
|
|
|
|
struct device_report_params params =
|
|
|
|
{
|
|
|
|
.iface = ext->unix_device,
|
|
|
|
.packet = packet,
|
|
|
|
.io = io,
|
|
|
|
};
|
|
|
|
winebus_call(device_get_feature_report, ¶ms);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void unix_device_set_feature_report(DEVICE_OBJECT *device, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io)
|
|
|
|
{
|
|
|
|
struct device_extension *ext = (struct device_extension *)device->DeviceExtension;
|
|
|
|
struct device_report_params params =
|
|
|
|
{
|
|
|
|
.iface = ext->unix_device,
|
|
|
|
.packet = packet,
|
|
|
|
.io = io,
|
|
|
|
};
|
|
|
|
winebus_call(device_set_feature_report, ¶ms);
|
|
|
|
}
|
|
|
|
|
2021-09-03 09:30:48 +02:00
|
|
|
static DWORD get_device_index(struct device_desc *desc)
|
2016-09-14 09:28:51 +02:00
|
|
|
{
|
2021-08-23 10:49:42 +02:00
|
|
|
struct device_extension *ext;
|
2019-05-15 14:56:05 +02:00
|
|
|
DWORD index = 0;
|
2016-09-14 09:28:51 +02:00
|
|
|
|
2021-08-23 10:49:42 +02:00
|
|
|
LIST_FOR_EACH_ENTRY(ext, &device_list, struct device_extension, entry)
|
2016-09-14 09:28:51 +02:00
|
|
|
{
|
2021-09-03 09:30:48 +02:00
|
|
|
if (ext->desc.vid == desc->vid && ext->desc.pid == desc->pid && ext->desc.input == desc->input)
|
2016-09-14 09:28:51 +02:00
|
|
|
index = max(ext->index + 1, index);
|
|
|
|
}
|
|
|
|
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
|
|
|
static WCHAR *get_instance_id(DEVICE_OBJECT *device)
|
|
|
|
{
|
|
|
|
struct device_extension *ext = (struct device_extension *)device->DeviceExtension;
|
2021-09-17 08:50:31 +02:00
|
|
|
DWORD len = wcslen(ext->serialnumber) + 33;
|
2016-09-14 09:28:51 +02:00
|
|
|
WCHAR *dst;
|
|
|
|
|
2019-06-05 16:22:13 +02:00
|
|
|
if ((dst = ExAllocatePool(PagedPool, len * sizeof(WCHAR))))
|
2021-09-17 08:50:35 +02:00
|
|
|
swprintf(dst, len, L"%i&%s&%x&%i", ext->desc.version, ext->serialnumber, ext->desc.uid, ext->index);
|
2016-09-14 09:28:51 +02:00
|
|
|
|
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
|
2016-09-14 09:29:50 +02:00
|
|
|
static WCHAR *get_device_id(DEVICE_OBJECT *device)
|
|
|
|
{
|
2021-09-17 08:50:35 +02:00
|
|
|
static const WCHAR input_format[] = L"&MI_%02u";
|
2021-09-20 09:37:04 +02:00
|
|
|
static const WCHAR winebus_format[] = L"WINEBUS\\VID_%04X&PID_%04X";
|
2016-09-14 09:29:50 +02:00
|
|
|
struct device_extension *ext = (struct device_extension *)device->DeviceExtension;
|
2021-09-20 09:37:04 +02:00
|
|
|
DWORD pos = 0, len = 0, input_len = 0, winebus_len = 25;
|
2021-09-17 08:50:31 +02:00
|
|
|
WCHAR *dst;
|
2016-09-14 09:29:50 +02:00
|
|
|
|
2021-09-20 09:37:04 +02:00
|
|
|
if (ext->desc.input != -1) input_len = 14;
|
|
|
|
|
|
|
|
len += winebus_len + input_len + 1;
|
|
|
|
|
2019-06-05 16:22:13 +02:00
|
|
|
if ((dst = ExAllocatePool(PagedPool, len * sizeof(WCHAR))))
|
2019-06-04 19:45:21 +02:00
|
|
|
{
|
2021-09-20 09:37:04 +02:00
|
|
|
pos += swprintf(dst + pos, len - pos, winebus_format, ext->desc.vid, ext->desc.pid);
|
|
|
|
if (input_len) pos += swprintf(dst + pos, len - pos, input_format, ext->desc.input);
|
2019-06-04 19:45:21 +02:00
|
|
|
}
|
2016-09-14 09:29:50 +02:00
|
|
|
|
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
|
2021-09-01 07:47:25 +02:00
|
|
|
static WCHAR *get_hardware_ids(DEVICE_OBJECT *device)
|
2016-09-14 09:29:50 +02:00
|
|
|
{
|
2021-09-20 09:37:05 +02:00
|
|
|
static const WCHAR input_format[] = L"&MI_%02u";
|
|
|
|
static const WCHAR winebus_format[] = L"WINEBUS\\VID_%04X&PID_%04X";
|
2016-09-14 09:29:50 +02:00
|
|
|
struct device_extension *ext = (struct device_extension *)device->DeviceExtension;
|
2021-09-20 09:37:05 +02:00
|
|
|
DWORD pos = 0, len = 0, input_len = 0, winebus_len = 25;
|
2019-06-04 19:45:22 +02:00
|
|
|
WCHAR *dst;
|
2016-09-14 09:29:50 +02:00
|
|
|
|
2021-09-20 09:37:05 +02:00
|
|
|
if (ext->desc.input != -1) input_len = 14;
|
|
|
|
|
|
|
|
len += winebus_len + input_len + 1;
|
|
|
|
|
|
|
|
if ((dst = ExAllocatePool(PagedPool, (len + 1) * sizeof(WCHAR))))
|
2016-09-14 09:29:50 +02:00
|
|
|
{
|
2021-09-20 09:37:05 +02:00
|
|
|
pos += swprintf(dst + pos, len - pos, winebus_format, ext->desc.vid, ext->desc.pid);
|
|
|
|
if (input_len) pos += swprintf(dst + pos, len - pos, input_format, ext->desc.input);
|
|
|
|
pos += 1;
|
|
|
|
dst[pos] = 0;
|
2016-09-14 09:29:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
|
2021-09-01 07:47:25 +02:00
|
|
|
static WCHAR *get_compatible_ids(DEVICE_OBJECT *device)
|
|
|
|
{
|
2021-09-17 08:50:35 +02:00
|
|
|
static const WCHAR xinput_compat[] = L"WINEBUS\\WINE_COMP_XINPUT";
|
|
|
|
static const WCHAR hid_compat[] = L"WINEBUS\\WINE_COMP_HID";
|
2021-09-01 07:47:26 +02:00
|
|
|
struct device_extension *ext = (struct device_extension *)device->DeviceExtension;
|
2021-09-01 07:47:25 +02:00
|
|
|
DWORD size = sizeof(hid_compat);
|
|
|
|
WCHAR *dst;
|
|
|
|
|
2021-09-03 09:30:48 +02:00
|
|
|
if (ext->desc.is_gamepad) size += sizeof(xinput_compat);
|
2021-09-01 07:47:26 +02:00
|
|
|
|
2021-09-01 07:47:25 +02:00
|
|
|
if ((dst = ExAllocatePool(PagedPool, size + sizeof(WCHAR))))
|
|
|
|
{
|
2021-09-03 09:30:48 +02:00
|
|
|
if (ext->desc.is_gamepad) memcpy(dst, xinput_compat, sizeof(xinput_compat));
|
2021-09-01 07:47:26 +02:00
|
|
|
memcpy((char *)dst + size - sizeof(hid_compat), hid_compat, sizeof(hid_compat));
|
2021-09-01 07:47:25 +02:00
|
|
|
dst[size / sizeof(WCHAR)] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
|
2021-06-30 10:19:08 +02:00
|
|
|
static void remove_pending_irps(DEVICE_OBJECT *device)
|
|
|
|
{
|
|
|
|
struct device_extension *ext = device->DeviceExtension;
|
|
|
|
LIST_ENTRY *entry;
|
|
|
|
|
|
|
|
while ((entry = RemoveHeadList(&ext->irp_queue)) != &ext->irp_queue)
|
|
|
|
{
|
2021-08-12 09:47:02 +02:00
|
|
|
IRP *queued_irp = CONTAINING_RECORD(entry, IRP, Tail.Overlay.ListEntry);
|
|
|
|
queued_irp->IoStatus.Status = STATUS_DELETE_PENDING;
|
2021-06-30 10:19:08 +02:00
|
|
|
queued_irp->IoStatus.Information = 0;
|
|
|
|
IoCompleteRequest(queued_irp, IO_NO_INCREMENT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-06 09:17:33 +02:00
|
|
|
static DEVICE_OBJECT *bus_create_hid_device(struct device_desc *desc, struct unix_device *unix_device)
|
2016-09-14 09:28:51 +02:00
|
|
|
{
|
|
|
|
struct device_extension *ext;
|
|
|
|
DEVICE_OBJECT *device;
|
|
|
|
UNICODE_STRING nameW;
|
|
|
|
WCHAR dev_name[256];
|
|
|
|
NTSTATUS status;
|
|
|
|
|
2021-09-03 09:30:49 +02:00
|
|
|
TRACE("desc %s, unix_device %p\n", debugstr_device_desc(desc), unix_device);
|
2016-09-14 09:28:51 +02:00
|
|
|
|
2021-09-20 09:37:06 +02:00
|
|
|
swprintf(dev_name, ARRAY_SIZE(dev_name), L"\\Device\\WINEBUS#%p", unix_device);
|
2016-09-14 09:28:51 +02:00
|
|
|
RtlInitUnicodeString(&nameW, dev_name);
|
2021-08-23 10:49:41 +02:00
|
|
|
status = IoCreateDevice(driver_obj, sizeof(struct device_extension), &nameW, 0, 0, FALSE, &device);
|
2016-09-14 09:28:51 +02:00
|
|
|
if (status)
|
|
|
|
{
|
|
|
|
FIXME("failed to create device error %x\n", status);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2021-09-16 10:17:57 +02:00
|
|
|
RtlEnterCriticalSection(&device_list_cs);
|
2016-09-14 09:28:51 +02:00
|
|
|
|
|
|
|
/* fill out device_extension struct */
|
|
|
|
ext = (struct device_extension *)device->DeviceExtension;
|
2021-08-23 10:49:42 +02:00
|
|
|
ext->device = device;
|
2021-09-03 09:30:48 +02:00
|
|
|
ext->desc = *desc;
|
|
|
|
ext->index = get_device_index(desc);
|
2016-10-26 17:49:41 +02:00
|
|
|
ext->last_report = NULL;
|
|
|
|
ext->last_report_size = 0;
|
|
|
|
ext->last_report_read = TRUE;
|
|
|
|
ext->buffer_size = 0;
|
2021-08-23 10:49:41 +02:00
|
|
|
ext->unix_device = unix_device;
|
2016-10-26 17:49:41 +02:00
|
|
|
|
2021-09-13 13:01:46 +02:00
|
|
|
MultiByteToWideChar(CP_UNIXCP, 0, ext->desc.manufacturer, -1, ext->manufacturer, MAX_PATH);
|
2021-09-13 13:01:47 +02:00
|
|
|
MultiByteToWideChar(CP_UNIXCP, 0, ext->desc.product, -1, ext->product, MAX_PATH);
|
2021-09-13 13:01:48 +02:00
|
|
|
MultiByteToWideChar(CP_UNIXCP, 0, ext->desc.serialnumber, -1, ext->serialnumber, MAX_PATH);
|
2021-09-13 13:01:46 +02:00
|
|
|
|
2016-10-26 17:49:41 +02:00
|
|
|
InitializeListHead(&ext->irp_queue);
|
2021-04-15 06:22:03 +02:00
|
|
|
InitializeCriticalSection(&ext->cs);
|
|
|
|
ext->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": cs");
|
2016-09-14 09:28:51 +02:00
|
|
|
|
|
|
|
/* add to list of pnp devices */
|
2021-08-23 10:49:42 +02:00
|
|
|
list_add_tail(&device_list, &ext->entry);
|
2016-09-14 09:28:51 +02:00
|
|
|
|
2021-09-16 10:17:57 +02:00
|
|
|
RtlLeaveCriticalSection(&device_list_cs);
|
2016-09-14 09:28:51 +02:00
|
|
|
return device;
|
|
|
|
}
|
|
|
|
|
2021-09-15 09:04:41 +02:00
|
|
|
static DEVICE_OBJECT *bus_find_unix_device(struct unix_device *unix_device)
|
|
|
|
{
|
|
|
|
struct device_extension *ext;
|
|
|
|
DEVICE_OBJECT *ret = NULL;
|
|
|
|
|
2021-09-16 10:17:57 +02:00
|
|
|
RtlEnterCriticalSection(&device_list_cs);
|
2021-09-15 09:04:41 +02:00
|
|
|
LIST_FOR_EACH_ENTRY(ext, &device_list, struct device_extension, entry)
|
|
|
|
{
|
|
|
|
if (ext->unix_device == unix_device)
|
|
|
|
{
|
|
|
|
ret = ext->device;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-09-16 10:17:57 +02:00
|
|
|
RtlLeaveCriticalSection(&device_list_cs);
|
2021-09-15 09:04:41 +02:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-08-30 11:22:54 +02:00
|
|
|
static void bus_unlink_hid_device(DEVICE_OBJECT *device)
|
2019-11-12 20:03:31 +01:00
|
|
|
{
|
|
|
|
struct device_extension *ext = (struct device_extension *)device->DeviceExtension;
|
|
|
|
|
2021-09-16 10:17:57 +02:00
|
|
|
RtlEnterCriticalSection(&device_list_cs);
|
2021-08-23 10:49:42 +02:00
|
|
|
list_remove(&ext->entry);
|
2021-09-16 10:17:57 +02:00
|
|
|
RtlLeaveCriticalSection(&device_list_cs);
|
2019-11-12 20:03:31 +01:00
|
|
|
}
|
|
|
|
|
2021-09-20 09:37:07 +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
|
|
|
|
|
2018-09-12 18:23:29 +02:00
|
|
|
static NTSTATUS build_device_relations(DEVICE_RELATIONS **devices)
|
|
|
|
{
|
2021-08-23 10:49:42 +02:00
|
|
|
struct device_extension *ext;
|
2018-09-12 18:23:29 +02:00
|
|
|
int i;
|
|
|
|
|
2021-09-16 10:17:57 +02:00
|
|
|
RtlEnterCriticalSection(&device_list_cs);
|
2021-08-23 10:49:42 +02:00
|
|
|
*devices = ExAllocatePool(PagedPool, offsetof(DEVICE_RELATIONS, Objects[list_count(&device_list)]));
|
2018-09-12 18:23:29 +02:00
|
|
|
|
|
|
|
if (!*devices)
|
|
|
|
{
|
2021-09-16 10:17:57 +02:00
|
|
|
RtlLeaveCriticalSection(&device_list_cs);
|
2018-09-12 18:23:29 +02:00
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
}
|
|
|
|
|
|
|
|
i = 0;
|
2021-08-23 10:49:42 +02:00
|
|
|
LIST_FOR_EACH_ENTRY(ext, &device_list, struct device_extension, entry)
|
2018-09-12 18:23:29 +02:00
|
|
|
{
|
2021-08-23 10:49:42 +02:00
|
|
|
(*devices)->Objects[i] = ext->device;
|
|
|
|
call_fastcall_func1(ObfReferenceObject, ext->device);
|
2018-09-12 18:23:29 +02:00
|
|
|
i++;
|
|
|
|
}
|
2021-09-16 10:17:57 +02:00
|
|
|
RtlLeaveCriticalSection(&device_list_cs);
|
2018-09-12 18:23:29 +02:00
|
|
|
(*devices)->Count = i;
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2021-09-17 08:50:35 +02:00
|
|
|
static DWORD check_bus_option(const WCHAR *option, DWORD default_value)
|
2021-08-23 10:49:40 +02:00
|
|
|
{
|
|
|
|
char buffer[FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION, Data[sizeof(DWORD)])];
|
|
|
|
KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)buffer;
|
2021-09-17 08:50:35 +02:00
|
|
|
UNICODE_STRING str;
|
2021-08-23 10:49:40 +02:00
|
|
|
DWORD size;
|
|
|
|
|
2021-09-17 08:50:35 +02:00
|
|
|
RtlInitUnicodeString(&str, option);
|
|
|
|
|
|
|
|
if (NtQueryValueKey(driver_key, &str, KeyValuePartialInformation, info, sizeof(buffer), &size) == STATUS_SUCCESS)
|
2021-08-23 10:49:40 +02:00
|
|
|
{
|
|
|
|
if (info->Type == REG_DWORD) return *(DWORD *)info->Data;
|
|
|
|
}
|
|
|
|
|
|
|
|
return default_value;
|
|
|
|
}
|
|
|
|
|
2021-09-15 09:04:40 +02:00
|
|
|
static NTSTATUS deliver_last_report(struct device_extension *ext, DWORD buffer_length, BYTE* buffer, ULONG_PTR *out_length)
|
|
|
|
{
|
|
|
|
if (buffer_length < ext->last_report_size)
|
|
|
|
{
|
|
|
|
*out_length = 0;
|
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (ext->last_report)
|
|
|
|
memcpy(buffer, ext->last_report, ext->last_report_size);
|
|
|
|
*out_length = ext->last_report_size;
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-15 09:04:43 +02:00
|
|
|
static void process_hid_report(DEVICE_OBJECT *device, BYTE *report, DWORD length)
|
2021-09-15 09:04:40 +02:00
|
|
|
{
|
|
|
|
struct device_extension *ext = (struct device_extension*)device->DeviceExtension;
|
|
|
|
IRP *irp;
|
|
|
|
LIST_ENTRY *entry;
|
|
|
|
|
|
|
|
if (!length || !report)
|
|
|
|
return;
|
|
|
|
|
2021-09-16 10:17:57 +02:00
|
|
|
RtlEnterCriticalSection(&ext->cs);
|
2021-09-15 09:04:40 +02:00
|
|
|
if (length > ext->buffer_size)
|
|
|
|
{
|
2021-09-16 10:17:56 +02:00
|
|
|
RtlFreeHeap(GetProcessHeap(), 0, ext->last_report);
|
|
|
|
ext->last_report = RtlAllocateHeap(GetProcessHeap(), 0, length);
|
2021-09-15 09:04:40 +02:00
|
|
|
if (!ext->last_report)
|
|
|
|
{
|
|
|
|
ERR_(hid_report)("Failed to alloc last report\n");
|
|
|
|
ext->buffer_size = 0;
|
|
|
|
ext->last_report_size = 0;
|
|
|
|
ext->last_report_read = TRUE;
|
2021-09-16 10:17:57 +02:00
|
|
|
RtlLeaveCriticalSection(&ext->cs);
|
2021-09-15 09:04:40 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ext->buffer_size = length;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(ext->last_report, report, length);
|
|
|
|
ext->last_report_size = length;
|
|
|
|
ext->last_report_read = FALSE;
|
|
|
|
|
|
|
|
while ((entry = RemoveHeadList(&ext->irp_queue)) != &ext->irp_queue)
|
|
|
|
{
|
|
|
|
IO_STACK_LOCATION *irpsp;
|
|
|
|
TRACE_(hid_report)("Processing Request\n");
|
|
|
|
irp = CONTAINING_RECORD(entry, IRP, Tail.Overlay.ListEntry);
|
|
|
|
irpsp = IoGetCurrentIrpStackLocation(irp);
|
|
|
|
irp->IoStatus.Status = deliver_last_report(ext,
|
|
|
|
irpsp->Parameters.DeviceIoControl.OutputBufferLength,
|
|
|
|
irp->UserBuffer, &irp->IoStatus.Information);
|
|
|
|
ext->last_report_read = TRUE;
|
|
|
|
IoCompleteRequest(irp, IO_NO_INCREMENT);
|
|
|
|
}
|
2021-09-16 10:17:57 +02:00
|
|
|
RtlLeaveCriticalSection(&ext->cs);
|
2021-09-15 09:04:40 +02:00
|
|
|
}
|
|
|
|
|
2018-09-12 18:23:29 +02:00
|
|
|
static NTSTATUS handle_IRP_MN_QUERY_DEVICE_RELATIONS(IRP *irp)
|
|
|
|
{
|
2021-08-12 09:47:02 +02:00
|
|
|
NTSTATUS status = irp->IoStatus.Status;
|
2018-09-12 18:23:29 +02:00
|
|
|
IO_STACK_LOCATION *irpsp = IoGetCurrentIrpStackLocation( irp );
|
|
|
|
|
2018-09-27 09:24:35 +02:00
|
|
|
TRACE("IRP_MN_QUERY_DEVICE_RELATIONS\n");
|
2018-09-12 18:23:29 +02:00
|
|
|
switch (irpsp->Parameters.QueryDeviceRelations.Type)
|
|
|
|
{
|
|
|
|
case EjectionRelations:
|
|
|
|
case RemovalRelations:
|
|
|
|
case TargetDeviceRelation:
|
|
|
|
case PowerRelations:
|
|
|
|
FIXME("Unhandled Device Relation %x\n",irpsp->Parameters.QueryDeviceRelations.Type);
|
|
|
|
break;
|
|
|
|
case BusRelations:
|
|
|
|
status = build_device_relations((DEVICE_RELATIONS**)&irp->IoStatus.Information);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
FIXME("Unknown Device Relation %x\n",irpsp->Parameters.QueryDeviceRelations.Type);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2016-09-14 09:29:50 +02:00
|
|
|
static NTSTATUS handle_IRP_MN_QUERY_ID(DEVICE_OBJECT *device, IRP *irp)
|
|
|
|
{
|
2021-08-12 09:47:02 +02:00
|
|
|
NTSTATUS status = irp->IoStatus.Status;
|
2016-09-14 09:29:50 +02:00
|
|
|
IO_STACK_LOCATION *irpsp = IoGetCurrentIrpStackLocation( irp );
|
|
|
|
BUS_QUERY_ID_TYPE type = irpsp->Parameters.QueryId.IdType;
|
|
|
|
|
|
|
|
TRACE("(%p, %p)\n", device, irp);
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case BusQueryHardwareIDs:
|
|
|
|
TRACE("BusQueryHardwareIDs\n");
|
2021-09-01 07:47:25 +02:00
|
|
|
irp->IoStatus.Information = (ULONG_PTR)get_hardware_ids(device);
|
2016-09-14 09:29:50 +02:00
|
|
|
break;
|
|
|
|
case BusQueryCompatibleIDs:
|
|
|
|
TRACE("BusQueryCompatibleIDs\n");
|
|
|
|
irp->IoStatus.Information = (ULONG_PTR)get_compatible_ids(device);
|
|
|
|
break;
|
|
|
|
case BusQueryDeviceID:
|
|
|
|
TRACE("BusQueryDeviceID\n");
|
|
|
|
irp->IoStatus.Information = (ULONG_PTR)get_device_id(device);
|
|
|
|
break;
|
|
|
|
case BusQueryInstanceID:
|
|
|
|
TRACE("BusQueryInstanceID\n");
|
|
|
|
irp->IoStatus.Information = (ULONG_PTR)get_instance_id(device);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
FIXME("Unhandled type %08x\n", type);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = irp->IoStatus.Information ? STATUS_SUCCESS : STATUS_NO_MEMORY;
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2019-11-07 06:55:01 +01:00
|
|
|
static void mouse_device_create(void)
|
|
|
|
{
|
2021-09-03 09:30:48 +02:00
|
|
|
struct device_create_params params = {{0}};
|
2021-04-22 21:26:49 +02:00
|
|
|
|
2021-08-30 11:22:55 +02:00
|
|
|
if (winebus_call(mouse_create, ¶ms)) return;
|
2021-09-03 09:30:49 +02:00
|
|
|
mouse_obj = bus_create_hid_device(¶ms.desc, params.device);
|
2021-08-30 11:22:55 +02:00
|
|
|
IoInvalidateDeviceRelations(bus_pdo, BusRelations);
|
2021-04-22 21:26:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void keyboard_device_create(void)
|
|
|
|
{
|
2021-09-03 09:30:48 +02:00
|
|
|
struct device_create_params params = {{0}};
|
2021-08-30 11:22:55 +02:00
|
|
|
|
|
|
|
if (winebus_call(keyboard_create, ¶ms)) return;
|
2021-09-03 09:30:49 +02:00
|
|
|
keyboard_obj = bus_create_hid_device(¶ms.desc, params.device);
|
2021-04-22 21:26:49 +02:00
|
|
|
IoInvalidateDeviceRelations(bus_pdo, BusRelations);
|
|
|
|
}
|
|
|
|
|
2021-08-23 10:49:36 +02:00
|
|
|
static DWORD bus_count;
|
|
|
|
static HANDLE bus_thread[16];
|
|
|
|
|
|
|
|
struct bus_main_params
|
|
|
|
{
|
|
|
|
const WCHAR *name;
|
|
|
|
|
2021-08-23 10:49:40 +02:00
|
|
|
void *init_args;
|
2021-08-23 10:49:36 +02:00
|
|
|
HANDLE init_done;
|
2021-08-23 10:49:39 +02:00
|
|
|
unsigned int init_code;
|
|
|
|
unsigned int wait_code;
|
2021-08-30 11:22:51 +02:00
|
|
|
struct bus_event *bus_event;
|
2021-08-23 10:49:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static DWORD CALLBACK bus_main_thread(void *args)
|
|
|
|
{
|
|
|
|
struct bus_main_params bus = *(struct bus_main_params *)args;
|
2021-08-30 11:22:52 +02:00
|
|
|
DEVICE_OBJECT *device;
|
2021-08-23 10:49:36 +02:00
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
TRACE("%s main loop starting\n", debugstr_w(bus.name));
|
2021-08-23 10:49:40 +02:00
|
|
|
status = winebus_call(bus.init_code, bus.init_args);
|
2021-08-23 10:49:36 +02:00
|
|
|
SetEvent(bus.init_done);
|
|
|
|
TRACE("%s main loop started\n", debugstr_w(bus.name));
|
|
|
|
|
2021-08-30 11:22:51 +02:00
|
|
|
bus.bus_event->type = BUS_EVENT_TYPE_NONE;
|
2021-08-23 10:49:36 +02:00
|
|
|
if (status) WARN("%s bus init returned status %#x\n", debugstr_w(bus.name), status);
|
2021-08-30 11:22:52 +02:00
|
|
|
else while ((status = winebus_call(bus.wait_code, bus.bus_event)) == STATUS_PENDING)
|
|
|
|
{
|
|
|
|
struct bus_event *event = bus.bus_event;
|
|
|
|
switch (event->type)
|
|
|
|
{
|
|
|
|
case BUS_EVENT_TYPE_NONE: break;
|
|
|
|
case BUS_EVENT_TYPE_DEVICE_REMOVED:
|
2021-09-16 10:17:57 +02:00
|
|
|
RtlEnterCriticalSection(&device_list_cs);
|
2021-09-16 10:17:52 +02:00
|
|
|
device = bus_find_unix_device(event->device);
|
|
|
|
if (!device) WARN("could not find device for %s bus device %p\n", debugstr_w(bus.name), event->device);
|
|
|
|
else bus_unlink_hid_device(device);
|
2021-09-16 10:17:57 +02:00
|
|
|
RtlLeaveCriticalSection(&device_list_cs);
|
2021-08-30 11:22:52 +02:00
|
|
|
IoInvalidateDeviceRelations(bus_pdo, BusRelations);
|
|
|
|
break;
|
2021-09-06 09:17:31 +02:00
|
|
|
case BUS_EVENT_TYPE_DEVICE_CREATED:
|
2021-09-16 10:17:52 +02:00
|
|
|
device = bus_create_hid_device(&event->device_created.desc, event->device);
|
2021-09-06 09:17:31 +02:00
|
|
|
if (device) IoInvalidateDeviceRelations(bus_pdo, BusRelations);
|
|
|
|
else
|
|
|
|
{
|
2021-09-16 10:17:52 +02:00
|
|
|
WARN("failed to create device for %s bus device %p\n", debugstr_w(bus.name), event->device);
|
|
|
|
winebus_call(device_remove, event->device);
|
2021-09-06 09:17:31 +02:00
|
|
|
}
|
|
|
|
break;
|
2021-09-15 09:04:41 +02:00
|
|
|
case BUS_EVENT_TYPE_INPUT_REPORT:
|
2021-09-16 10:17:57 +02:00
|
|
|
RtlEnterCriticalSection(&device_list_cs);
|
2021-09-16 10:17:52 +02:00
|
|
|
device = bus_find_unix_device(event->device);
|
|
|
|
if (!device) WARN("could not find device for %s bus device %p\n", debugstr_w(bus.name), event->device);
|
2021-09-15 09:04:41 +02:00
|
|
|
else process_hid_report(device, event->input_report.buffer, event->input_report.length);
|
2021-09-16 10:17:57 +02:00
|
|
|
RtlLeaveCriticalSection(&device_list_cs);
|
2021-09-15 09:04:41 +02:00
|
|
|
break;
|
2021-08-30 11:22:52 +02:00
|
|
|
}
|
|
|
|
}
|
2021-08-23 10:49:36 +02:00
|
|
|
|
|
|
|
if (status) WARN("%s bus wait returned status %#x\n", debugstr_w(bus.name), status);
|
|
|
|
else TRACE("%s main loop exited\n", debugstr_w(bus.name));
|
2021-09-16 10:17:56 +02:00
|
|
|
RtlFreeHeap(GetProcessHeap(), 0, bus.bus_event);
|
2021-08-23 10:49:36 +02:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static NTSTATUS bus_main_thread_start(struct bus_main_params *bus)
|
|
|
|
{
|
2021-09-15 09:04:41 +02:00
|
|
|
DWORD i = bus_count++, max_size;
|
2021-08-23 10:49:36 +02:00
|
|
|
|
|
|
|
if (!(bus->init_done = CreateEventW(NULL, FALSE, FALSE, NULL)))
|
|
|
|
{
|
|
|
|
ERR("failed to create %s bus init done event.\n", debugstr_w(bus->name));
|
|
|
|
bus_count--;
|
|
|
|
return STATUS_UNSUCCESSFUL;
|
|
|
|
}
|
|
|
|
|
2021-09-15 09:04:41 +02:00
|
|
|
max_size = offsetof(struct bus_event, input_report.buffer[0x10000]);
|
2021-09-16 10:17:56 +02:00
|
|
|
if (!(bus->bus_event = RtlAllocateHeap(GetProcessHeap(), 0, max_size)))
|
2021-08-30 11:22:51 +02:00
|
|
|
{
|
|
|
|
ERR("failed to allocate %s bus event.\n", debugstr_w(bus->name));
|
|
|
|
CloseHandle(bus->init_done);
|
|
|
|
bus_count--;
|
|
|
|
return STATUS_UNSUCCESSFUL;
|
|
|
|
}
|
|
|
|
|
2021-08-23 10:49:36 +02:00
|
|
|
if (!(bus_thread[i] = CreateThread(NULL, 0, bus_main_thread, bus, 0, NULL)))
|
|
|
|
{
|
|
|
|
ERR("failed to create %s bus thread.\n", debugstr_w(bus->name));
|
|
|
|
CloseHandle(bus->init_done);
|
|
|
|
bus_count--;
|
|
|
|
return STATUS_UNSUCCESSFUL;
|
|
|
|
}
|
|
|
|
|
|
|
|
WaitForSingleObject(bus->init_done, INFINITE);
|
|
|
|
CloseHandle(bus->init_done);
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2021-09-16 10:17:55 +02:00
|
|
|
static void sdl_bus_free_mappings(struct sdl_bus_options *options)
|
|
|
|
{
|
|
|
|
DWORD count = options->mappings_count;
|
|
|
|
char **mappings = options->mappings;
|
|
|
|
|
2021-09-16 10:17:56 +02:00
|
|
|
while (count) RtlFreeHeap(GetProcessHeap(), 0, mappings[--count]);
|
|
|
|
RtlFreeHeap(GetProcessHeap(), 0, mappings);
|
2021-09-16 10:17:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void sdl_bus_load_mappings(struct sdl_bus_options *options)
|
|
|
|
{
|
|
|
|
ULONG idx = 0, len, count = 0, capacity, info_size, info_max_size;
|
|
|
|
KEY_VALUE_FULL_INFORMATION *info;
|
|
|
|
OBJECT_ATTRIBUTES attr = {0};
|
|
|
|
char **mappings = NULL;
|
|
|
|
UNICODE_STRING path;
|
|
|
|
NTSTATUS status;
|
|
|
|
HANDLE key;
|
|
|
|
|
|
|
|
options->mappings_count = 0;
|
|
|
|
options->mappings = NULL;
|
|
|
|
|
2021-09-17 08:50:35 +02:00
|
|
|
RtlInitUnicodeString(&path, L"map");
|
2021-09-16 10:17:55 +02:00
|
|
|
InitializeObjectAttributes(&attr, &path, OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE, driver_key, NULL);
|
|
|
|
status = NtOpenKey(&key, KEY_ALL_ACCESS, &attr);
|
|
|
|
if (status) return;
|
|
|
|
|
|
|
|
capacity = 1024;
|
2021-09-16 10:17:56 +02:00
|
|
|
mappings = RtlAllocateHeap(GetProcessHeap(), 0, capacity * sizeof(*mappings));
|
2021-09-16 10:17:55 +02:00
|
|
|
info_max_size = offsetof(KEY_VALUE_FULL_INFORMATION, Name) + 512;
|
2021-09-16 10:17:56 +02:00
|
|
|
info = RtlAllocateHeap(GetProcessHeap(), 0, info_max_size);
|
2021-09-16 10:17:55 +02:00
|
|
|
|
|
|
|
while (!status && info && mappings)
|
|
|
|
{
|
|
|
|
status = NtEnumerateValueKey(key, idx, KeyValueFullInformation, info, info_max_size, &info_size);
|
|
|
|
while (status == STATUS_BUFFER_OVERFLOW)
|
|
|
|
{
|
|
|
|
info_max_size = info_size;
|
2021-09-16 10:17:56 +02:00
|
|
|
if (!(info = RtlReAllocateHeap(GetProcessHeap(), 0, info, info_max_size))) break;
|
2021-09-16 10:17:55 +02:00
|
|
|
status = NtEnumerateValueKey(key, idx, KeyValueFullInformation, info, info_max_size, &info_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status == STATUS_NO_MORE_ENTRIES)
|
|
|
|
{
|
|
|
|
options->mappings_count = count;
|
|
|
|
options->mappings = mappings;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
idx++;
|
|
|
|
if (status) break;
|
|
|
|
if (info->Type != REG_SZ) continue;
|
|
|
|
|
|
|
|
RtlUnicodeToMultiByteSize(&len, (WCHAR *)((char *)info + info->DataOffset), info_size - info->DataOffset);
|
|
|
|
if (!len) continue;
|
|
|
|
|
2021-09-16 10:17:56 +02:00
|
|
|
if (!(mappings[count++] = RtlAllocateHeap(GetProcessHeap(), 0, len + 1))) break;
|
2021-09-16 10:17:55 +02:00
|
|
|
if (count > capacity)
|
|
|
|
{
|
|
|
|
capacity = capacity * 3 / 2;
|
2021-09-16 10:17:56 +02:00
|
|
|
if (!(mappings = RtlReAllocateHeap(GetProcessHeap(), 0, mappings, capacity * sizeof(*mappings))))
|
2021-09-16 10:17:55 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
RtlUnicodeToMultiByteN(mappings[count], len, NULL, (WCHAR *)((char *)info + info->DataOffset),
|
|
|
|
info_size - info->DataOffset);
|
|
|
|
if (mappings[len - 1]) mappings[len] = 0;
|
|
|
|
}
|
|
|
|
|
2021-09-16 10:17:56 +02:00
|
|
|
if (mappings) while (count) RtlFreeHeap(GetProcessHeap(), 0, mappings[--count]);
|
|
|
|
RtlFreeHeap(GetProcessHeap(), 0, mappings);
|
2021-09-16 10:17:55 +02:00
|
|
|
|
|
|
|
done:
|
2021-09-16 10:17:56 +02:00
|
|
|
RtlFreeHeap(GetProcessHeap(), 0, info);
|
2021-09-16 10:17:55 +02:00
|
|
|
NtClose(key);
|
|
|
|
}
|
|
|
|
|
2021-08-23 10:49:36 +02:00
|
|
|
static NTSTATUS sdl_driver_init(void)
|
|
|
|
{
|
2021-08-23 10:49:40 +02:00
|
|
|
struct sdl_bus_options bus_options;
|
2021-08-23 10:49:36 +02:00
|
|
|
struct bus_main_params bus =
|
|
|
|
{
|
2021-09-17 08:50:35 +02:00
|
|
|
.name = L"SDL",
|
2021-08-23 10:49:40 +02:00
|
|
|
.init_args = &bus_options,
|
2021-08-23 10:49:39 +02:00
|
|
|
.init_code = sdl_init,
|
|
|
|
.wait_code = sdl_wait,
|
2021-08-23 10:49:36 +02:00
|
|
|
};
|
2021-09-16 10:17:55 +02:00
|
|
|
NTSTATUS status;
|
2021-08-23 10:49:36 +02:00
|
|
|
|
2021-09-17 08:50:35 +02:00
|
|
|
bus_options.map_controllers = check_bus_option(L"Map Controllers", 1);
|
2021-08-23 10:49:40 +02:00
|
|
|
if (!bus_options.map_controllers) TRACE("SDL controller to XInput HID gamepad mapping disabled\n");
|
2021-09-16 10:17:55 +02:00
|
|
|
sdl_bus_load_mappings(&bus_options);
|
2021-08-23 10:49:40 +02:00
|
|
|
|
2021-09-16 10:17:55 +02:00
|
|
|
status = bus_main_thread_start(&bus);
|
|
|
|
sdl_bus_free_mappings(&bus_options);
|
|
|
|
return status;
|
2021-08-23 10:49:36 +02:00
|
|
|
}
|
|
|
|
|
2021-08-23 10:49:37 +02:00
|
|
|
static NTSTATUS udev_driver_init(void)
|
|
|
|
{
|
2021-08-23 10:49:40 +02:00
|
|
|
struct udev_bus_options bus_options;
|
2021-08-23 10:49:37 +02:00
|
|
|
struct bus_main_params bus =
|
|
|
|
{
|
2021-09-17 08:50:35 +02:00
|
|
|
.name = L"UDEV",
|
2021-08-23 10:49:40 +02:00
|
|
|
.init_args = &bus_options,
|
2021-08-23 10:49:39 +02:00
|
|
|
.init_code = udev_init,
|
|
|
|
.wait_code = udev_wait,
|
2021-08-23 10:49:37 +02:00
|
|
|
};
|
|
|
|
|
2021-09-17 08:50:35 +02:00
|
|
|
bus_options.disable_hidraw = check_bus_option(L"DisableHidraw", 0);
|
2021-08-23 10:49:40 +02:00
|
|
|
if (bus_options.disable_hidraw) TRACE("UDEV hidraw devices disabled in registry\n");
|
2021-09-17 08:50:35 +02:00
|
|
|
bus_options.disable_input = check_bus_option(L"DisableInput", 0);
|
2021-08-23 10:49:40 +02:00
|
|
|
if (bus_options.disable_input) TRACE("UDEV input devices disabled in registry\n");
|
|
|
|
|
2021-08-23 10:49:37 +02:00
|
|
|
return bus_main_thread_start(&bus);
|
|
|
|
}
|
|
|
|
|
2021-08-23 10:49:38 +02:00
|
|
|
static NTSTATUS iohid_driver_init(void)
|
|
|
|
{
|
2021-08-23 10:49:40 +02:00
|
|
|
struct iohid_bus_options bus_options;
|
2021-08-23 10:49:38 +02:00
|
|
|
struct bus_main_params bus =
|
|
|
|
{
|
2021-09-17 08:50:35 +02:00
|
|
|
.name = L"IOHID",
|
2021-08-23 10:49:40 +02:00
|
|
|
.init_args = &bus_options,
|
2021-08-23 10:49:39 +02:00
|
|
|
.init_code = iohid_init,
|
|
|
|
.wait_code = iohid_wait,
|
2021-08-23 10:49:38 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
return bus_main_thread_start(&bus);
|
|
|
|
}
|
|
|
|
|
2019-11-07 06:54:58 +01:00
|
|
|
static NTSTATUS fdo_pnp_dispatch(DEVICE_OBJECT *device, IRP *irp)
|
|
|
|
{
|
|
|
|
IO_STACK_LOCATION *irpsp = IoGetCurrentIrpStackLocation(irp);
|
|
|
|
NTSTATUS ret;
|
|
|
|
|
|
|
|
switch (irpsp->MinorFunction)
|
|
|
|
{
|
2019-11-07 06:55:02 +01:00
|
|
|
case IRP_MN_QUERY_DEVICE_RELATIONS:
|
2021-08-12 09:47:02 +02:00
|
|
|
irp->IoStatus.Status = handle_IRP_MN_QUERY_DEVICE_RELATIONS(irp);
|
2019-11-07 06:55:02 +01:00
|
|
|
break;
|
2019-11-07 06:54:58 +01:00
|
|
|
case IRP_MN_START_DEVICE:
|
2019-11-07 06:55:01 +01:00
|
|
|
mouse_device_create();
|
2021-04-22 21:26:49 +02:00
|
|
|
keyboard_device_create();
|
2019-11-07 06:55:01 +01:00
|
|
|
|
2021-09-17 08:50:35 +02:00
|
|
|
if (!check_bus_option(L"Enable SDL", 1) || sdl_driver_init())
|
2019-11-07 06:55:01 +01:00
|
|
|
{
|
2021-08-23 10:49:36 +02:00
|
|
|
udev_driver_init();
|
|
|
|
iohid_driver_init();
|
2019-11-07 06:55:01 +01:00
|
|
|
}
|
2021-08-23 10:49:36 +02:00
|
|
|
|
2021-08-12 09:47:02 +02:00
|
|
|
irp->IoStatus.Status = STATUS_SUCCESS;
|
2019-11-07 06:55:01 +01:00
|
|
|
break;
|
2019-11-07 06:54:58 +01:00
|
|
|
case IRP_MN_SURPRISE_REMOVAL:
|
2021-08-12 09:47:02 +02:00
|
|
|
irp->IoStatus.Status = STATUS_SUCCESS;
|
2019-11-07 06:54:58 +01:00
|
|
|
break;
|
|
|
|
case IRP_MN_REMOVE_DEVICE:
|
2021-08-23 10:49:39 +02:00
|
|
|
winebus_call(sdl_stop, NULL);
|
|
|
|
winebus_call(udev_stop, NULL);
|
|
|
|
winebus_call(iohid_stop, NULL);
|
2021-08-23 10:49:36 +02:00
|
|
|
|
|
|
|
WaitForMultipleObjects(bus_count, bus_thread, TRUE, INFINITE);
|
|
|
|
while (bus_count--) CloseHandle(bus_thread[bus_count]);
|
2019-11-07 06:55:01 +01:00
|
|
|
|
2021-08-12 09:47:02 +02:00
|
|
|
irp->IoStatus.Status = STATUS_SUCCESS;
|
2019-11-07 06:54:58 +01:00
|
|
|
IoSkipCurrentIrpStackLocation(irp);
|
|
|
|
ret = IoCallDriver(bus_pdo, irp);
|
|
|
|
IoDetachDevice(bus_pdo);
|
|
|
|
IoDeleteDevice(device);
|
|
|
|
return ret;
|
|
|
|
default:
|
|
|
|
FIXME("Unhandled minor function %#x.\n", irpsp->MinorFunction);
|
|
|
|
}
|
|
|
|
|
|
|
|
IoSkipCurrentIrpStackLocation(irp);
|
|
|
|
return IoCallDriver(bus_pdo, irp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static NTSTATUS pdo_pnp_dispatch(DEVICE_OBJECT *device, IRP *irp)
|
2016-09-08 10:12:50 +02:00
|
|
|
{
|
2021-04-15 06:22:06 +02:00
|
|
|
struct device_extension *ext = device->DeviceExtension;
|
2021-08-12 09:47:02 +02:00
|
|
|
NTSTATUS status = irp->IoStatus.Status;
|
2016-09-08 10:12:50 +02:00
|
|
|
IO_STACK_LOCATION *irpsp = IoGetCurrentIrpStackLocation(irp);
|
|
|
|
|
2021-04-15 06:22:06 +02:00
|
|
|
TRACE("device %p, irp %p, minor function %#x.\n", device, irp, irpsp->MinorFunction);
|
|
|
|
|
2016-09-08 10:12:50 +02:00
|
|
|
switch (irpsp->MinorFunction)
|
|
|
|
{
|
|
|
|
case IRP_MN_QUERY_ID:
|
2016-09-14 09:29:50 +02:00
|
|
|
status = handle_IRP_MN_QUERY_ID(device, irp);
|
2016-09-08 10:12:50 +02:00
|
|
|
break;
|
2021-04-15 06:22:06 +02:00
|
|
|
|
2016-09-08 10:12:50 +02:00
|
|
|
case IRP_MN_QUERY_CAPABILITIES:
|
2021-02-12 01:56:46 +01:00
|
|
|
status = STATUS_SUCCESS;
|
2016-09-08 10:12:50 +02:00
|
|
|
break;
|
2021-04-15 06:22:06 +02:00
|
|
|
|
2021-04-20 06:37:09 +02:00
|
|
|
case IRP_MN_START_DEVICE:
|
2021-09-16 10:17:57 +02:00
|
|
|
RtlEnterCriticalSection(&ext->cs);
|
2021-08-18 09:14:18 +02:00
|
|
|
if (ext->state != DEVICE_STATE_STOPPED) status = STATUS_SUCCESS;
|
|
|
|
else if (ext->state == DEVICE_STATE_REMOVED) status = STATUS_DELETE_PENDING;
|
2021-09-03 09:30:49 +02:00
|
|
|
else if (!(status = unix_device_start(device))) ext->state = DEVICE_STATE_STARTED;
|
2021-08-18 09:14:18 +02:00
|
|
|
else ERR("failed to start device %p, status %#x\n", device, status);
|
2021-09-16 10:17:57 +02:00
|
|
|
RtlLeaveCriticalSection(&ext->cs);
|
2021-04-20 06:37:09 +02:00
|
|
|
break;
|
|
|
|
|
2021-06-30 10:19:09 +02:00
|
|
|
case IRP_MN_SURPRISE_REMOVAL:
|
2021-09-16 10:17:57 +02:00
|
|
|
RtlEnterCriticalSection(&ext->cs);
|
2021-06-30 10:19:09 +02:00
|
|
|
remove_pending_irps(device);
|
2021-08-18 09:14:18 +02:00
|
|
|
ext->state = DEVICE_STATE_REMOVED;
|
2021-09-16 10:17:57 +02:00
|
|
|
RtlLeaveCriticalSection(&ext->cs);
|
2021-08-12 09:46:59 +02:00
|
|
|
status = STATUS_SUCCESS;
|
2021-06-30 10:19:09 +02:00
|
|
|
break;
|
|
|
|
|
2021-04-15 06:22:06 +02:00
|
|
|
case IRP_MN_REMOVE_DEVICE:
|
2021-06-30 10:19:08 +02:00
|
|
|
remove_pending_irps(device);
|
2021-04-15 06:22:06 +02:00
|
|
|
|
2021-08-16 09:04:28 +02:00
|
|
|
bus_unlink_hid_device(device);
|
2021-09-03 09:30:49 +02:00
|
|
|
unix_device_remove(device);
|
2021-04-15 06:22:06 +02:00
|
|
|
|
|
|
|
ext->cs.DebugInfo->Spare[0] = 0;
|
|
|
|
DeleteCriticalSection(&ext->cs);
|
|
|
|
|
2021-09-16 10:17:56 +02:00
|
|
|
RtlFreeHeap(GetProcessHeap(), 0, ext->last_report);
|
2021-04-15 06:22:06 +02:00
|
|
|
|
2021-08-12 09:47:02 +02:00
|
|
|
irp->IoStatus.Status = STATUS_SUCCESS;
|
2021-04-15 06:22:06 +02:00
|
|
|
IoCompleteRequest(irp, IO_NO_INCREMENT);
|
|
|
|
|
|
|
|
IoDeleteDevice(device);
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
|
2016-09-08 10:12:50 +02:00
|
|
|
default:
|
|
|
|
FIXME("Unhandled function %08x\n", irpsp->MinorFunction);
|
2021-04-16 17:55:32 +02:00
|
|
|
/* fall through */
|
|
|
|
|
|
|
|
case IRP_MN_QUERY_DEVICE_RELATIONS:
|
2016-09-08 10:12:50 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-08-12 09:47:02 +02:00
|
|
|
irp->IoStatus.Status = status;
|
2016-09-08 10:12:50 +02:00
|
|
|
IoCompleteRequest(irp, IO_NO_INCREMENT);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2019-11-07 06:54:58 +01:00
|
|
|
static NTSTATUS WINAPI common_pnp_dispatch(DEVICE_OBJECT *device, IRP *irp)
|
|
|
|
{
|
|
|
|
if (device == bus_fdo)
|
|
|
|
return fdo_pnp_dispatch(device, irp);
|
|
|
|
return pdo_pnp_dispatch(device, irp);
|
|
|
|
}
|
|
|
|
|
2021-09-13 13:01:46 +02:00
|
|
|
static NTSTATUS hid_get_device_string(DEVICE_OBJECT *device, DWORD index, WCHAR *buffer, DWORD buffer_len)
|
|
|
|
{
|
|
|
|
struct device_extension *ext = (struct device_extension *)device->DeviceExtension;
|
|
|
|
DWORD len;
|
|
|
|
|
|
|
|
switch (index)
|
|
|
|
{
|
|
|
|
case HID_STRING_ID_IMANUFACTURER:
|
2021-09-17 08:50:31 +02:00
|
|
|
len = (wcslen(ext->manufacturer) + 1) * sizeof(WCHAR);
|
2021-09-13 13:01:46 +02:00
|
|
|
if (len > buffer_len) return STATUS_BUFFER_TOO_SMALL;
|
|
|
|
else memcpy(buffer, ext->manufacturer, len);
|
|
|
|
return STATUS_SUCCESS;
|
2021-09-13 13:01:47 +02:00
|
|
|
case HID_STRING_ID_IPRODUCT:
|
2021-09-17 08:50:31 +02:00
|
|
|
len = (wcslen(ext->product) + 1) * sizeof(WCHAR);
|
2021-09-13 13:01:47 +02:00
|
|
|
if (len > buffer_len) return STATUS_BUFFER_TOO_SMALL;
|
|
|
|
else memcpy(buffer, ext->product, len);
|
|
|
|
return STATUS_SUCCESS;
|
2021-09-13 13:01:48 +02:00
|
|
|
case HID_STRING_ID_ISERIALNUMBER:
|
2021-09-17 08:50:31 +02:00
|
|
|
len = (wcslen(ext->serialnumber) + 1) * sizeof(WCHAR);
|
2021-09-13 13:01:48 +02:00
|
|
|
if (len > buffer_len) return STATUS_BUFFER_TOO_SMALL;
|
|
|
|
else memcpy(buffer, ext->serialnumber, len);
|
|
|
|
return STATUS_SUCCESS;
|
2021-09-13 13:01:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2019-05-30 06:02:28 +02:00
|
|
|
static NTSTATUS WINAPI hid_internal_dispatch(DEVICE_OBJECT *device, IRP *irp)
|
2016-10-06 14:19:27 +02:00
|
|
|
{
|
|
|
|
IO_STACK_LOCATION *irpsp = IoGetCurrentIrpStackLocation(irp);
|
2016-10-11 14:09:35 +02:00
|
|
|
struct device_extension *ext = (struct device_extension *)device->DeviceExtension;
|
2021-08-12 09:47:01 +02:00
|
|
|
ULONG code, buffer_len = irpsp->Parameters.DeviceIoControl.OutputBufferLength;
|
2021-08-12 09:47:03 +02:00
|
|
|
NTSTATUS status;
|
2016-10-06 14:19:27 +02:00
|
|
|
|
|
|
|
TRACE("(%p, %p)\n", device, irp);
|
|
|
|
|
2019-11-07 06:54:58 +01:00
|
|
|
if (device == bus_fdo)
|
|
|
|
{
|
|
|
|
IoSkipCurrentIrpStackLocation(irp);
|
|
|
|
return IoCallDriver(bus_pdo, irp);
|
|
|
|
}
|
|
|
|
|
2021-09-16 10:17:57 +02:00
|
|
|
RtlEnterCriticalSection(&ext->cs);
|
2021-04-15 06:22:05 +02:00
|
|
|
|
2021-08-18 09:14:18 +02:00
|
|
|
if (ext->state == DEVICE_STATE_REMOVED)
|
2021-04-15 06:22:05 +02:00
|
|
|
{
|
2021-09-16 10:17:57 +02:00
|
|
|
RtlLeaveCriticalSection(&ext->cs);
|
2021-08-12 09:47:02 +02:00
|
|
|
irp->IoStatus.Status = STATUS_DELETE_PENDING;
|
2021-04-15 06:22:05 +02:00
|
|
|
IoCompleteRequest(irp, IO_NO_INCREMENT);
|
|
|
|
return STATUS_DELETE_PENDING;
|
|
|
|
}
|
|
|
|
|
2021-08-12 09:47:01 +02:00
|
|
|
switch ((code = irpsp->Parameters.DeviceIoControl.IoControlCode))
|
2016-10-06 14:19:27 +02:00
|
|
|
{
|
|
|
|
case IOCTL_HID_GET_DEVICE_ATTRIBUTES:
|
|
|
|
{
|
|
|
|
HID_DEVICE_ATTRIBUTES *attr = (HID_DEVICE_ATTRIBUTES *)irp->UserBuffer;
|
|
|
|
TRACE("IOCTL_HID_GET_DEVICE_ATTRIBUTES\n");
|
|
|
|
|
2021-08-12 09:47:01 +02:00
|
|
|
if (buffer_len < sizeof(*attr))
|
2016-10-06 14:19:27 +02:00
|
|
|
{
|
2021-08-12 09:47:03 +02:00
|
|
|
irp->IoStatus.Status = STATUS_BUFFER_TOO_SMALL;
|
2016-10-06 14:19:27 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(attr, 0, sizeof(*attr));
|
2016-10-11 14:09:35 +02:00
|
|
|
attr->Size = sizeof(*attr);
|
2021-09-03 09:30:48 +02:00
|
|
|
attr->VendorID = ext->desc.vid;
|
|
|
|
attr->ProductID = ext->desc.pid;
|
|
|
|
attr->VersionNumber = ext->desc.version;
|
2016-10-11 14:09:35 +02:00
|
|
|
|
2021-08-12 09:47:03 +02:00
|
|
|
irp->IoStatus.Status = STATUS_SUCCESS;
|
2016-10-11 14:09:35 +02:00
|
|
|
irp->IoStatus.Information = sizeof(*attr);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case IOCTL_HID_GET_DEVICE_DESCRIPTOR:
|
|
|
|
{
|
|
|
|
HID_DESCRIPTOR *descriptor = (HID_DESCRIPTOR *)irp->UserBuffer;
|
|
|
|
DWORD length;
|
|
|
|
TRACE("IOCTL_HID_GET_DEVICE_DESCRIPTOR\n");
|
|
|
|
|
2021-08-12 09:47:01 +02:00
|
|
|
if (buffer_len < sizeof(*descriptor))
|
2016-10-11 14:09:35 +02:00
|
|
|
{
|
2021-08-12 09:47:03 +02:00
|
|
|
irp->IoStatus.Status = STATUS_BUFFER_TOO_SMALL;
|
2016-10-11 14:09:35 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-09-03 09:30:49 +02:00
|
|
|
irp->IoStatus.Status = unix_device_get_report_descriptor(device, NULL, 0, &length);
|
2021-08-12 09:47:03 +02:00
|
|
|
if (irp->IoStatus.Status != STATUS_SUCCESS &&
|
|
|
|
irp->IoStatus.Status != STATUS_BUFFER_TOO_SMALL)
|
2016-10-11 14:09:35 +02:00
|
|
|
{
|
|
|
|
WARN("Failed to get platform report descriptor length\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(descriptor, 0, sizeof(*descriptor));
|
|
|
|
descriptor->bLength = sizeof(*descriptor);
|
|
|
|
descriptor->bDescriptorType = HID_HID_DESCRIPTOR_TYPE;
|
|
|
|
descriptor->bcdHID = HID_REVISION;
|
|
|
|
descriptor->bCountry = 0;
|
|
|
|
descriptor->bNumDescriptors = 1;
|
|
|
|
descriptor->DescriptorList[0].bReportType = HID_REPORT_DESCRIPTOR_TYPE;
|
|
|
|
descriptor->DescriptorList[0].wReportLength = length;
|
|
|
|
|
2021-08-12 09:47:03 +02:00
|
|
|
irp->IoStatus.Status = STATUS_SUCCESS;
|
2016-10-11 14:09:35 +02:00
|
|
|
irp->IoStatus.Information = sizeof(*descriptor);
|
2016-10-06 14:19:27 +02:00
|
|
|
break;
|
|
|
|
}
|
2016-10-11 14:09:46 +02:00
|
|
|
case IOCTL_HID_GET_REPORT_DESCRIPTOR:
|
|
|
|
TRACE("IOCTL_HID_GET_REPORT_DESCRIPTOR\n");
|
2021-09-03 09:30:49 +02:00
|
|
|
irp->IoStatus.Status = unix_device_get_report_descriptor(device, irp->UserBuffer, buffer_len, &buffer_len);
|
2021-08-12 09:47:01 +02:00
|
|
|
irp->IoStatus.Information = buffer_len;
|
2016-10-11 14:09:46 +02:00
|
|
|
break;
|
2016-10-14 08:54:52 +02:00
|
|
|
case IOCTL_HID_GET_STRING:
|
|
|
|
{
|
|
|
|
DWORD index = (ULONG_PTR)irpsp->Parameters.DeviceIoControl.Type3InputBuffer;
|
|
|
|
TRACE("IOCTL_HID_GET_STRING[%08x]\n", index);
|
|
|
|
|
2021-09-13 13:01:46 +02:00
|
|
|
irp->IoStatus.Status = hid_get_device_string(device, index, (WCHAR *)irp->UserBuffer, buffer_len);
|
2021-08-12 09:47:03 +02:00
|
|
|
if (irp->IoStatus.Status == STATUS_SUCCESS)
|
2021-09-17 08:50:31 +02:00
|
|
|
irp->IoStatus.Information = (wcslen((WCHAR *)irp->UserBuffer) + 1) * sizeof(WCHAR);
|
2016-10-14 08:54:52 +02:00
|
|
|
break;
|
|
|
|
}
|
2016-10-26 17:49:41 +02:00
|
|
|
case IOCTL_HID_GET_INPUT_REPORT:
|
|
|
|
{
|
|
|
|
HID_XFER_PACKET *packet = (HID_XFER_PACKET*)(irp->UserBuffer);
|
|
|
|
TRACE_(hid_report)("IOCTL_HID_GET_INPUT_REPORT\n");
|
2021-08-12 09:47:03 +02:00
|
|
|
irp->IoStatus.Status = deliver_last_report(ext,
|
2016-10-26 17:49:41 +02:00
|
|
|
packet->reportBufferLen, packet->reportBuffer,
|
|
|
|
&irp->IoStatus.Information);
|
|
|
|
|
2021-08-12 09:47:03 +02:00
|
|
|
if (irp->IoStatus.Status == STATUS_SUCCESS)
|
2016-10-26 17:49:41 +02:00
|
|
|
packet->reportBufferLen = irp->IoStatus.Information;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case IOCTL_HID_READ_REPORT:
|
|
|
|
{
|
|
|
|
TRACE_(hid_report)("IOCTL_HID_READ_REPORT\n");
|
|
|
|
if (!ext->last_report_read)
|
|
|
|
{
|
2021-08-12 09:47:03 +02:00
|
|
|
irp->IoStatus.Status = deliver_last_report(ext,
|
2021-08-12 09:47:01 +02:00
|
|
|
buffer_len, irp->UserBuffer, &irp->IoStatus.Information);
|
2016-10-26 17:49:41 +02:00
|
|
|
ext->last_report_read = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-08-12 09:47:02 +02:00
|
|
|
InsertTailList(&ext->irp_queue, &irp->Tail.Overlay.ListEntry);
|
2021-08-12 09:47:03 +02:00
|
|
|
irp->IoStatus.Status = STATUS_PENDING;
|
2016-10-26 17:49:41 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2016-10-27 15:37:41 +02:00
|
|
|
case IOCTL_HID_SET_OUTPUT_REPORT:
|
|
|
|
case IOCTL_HID_WRITE_REPORT:
|
|
|
|
{
|
|
|
|
HID_XFER_PACKET *packet = (HID_XFER_PACKET*)(irp->UserBuffer);
|
|
|
|
TRACE_(hid_report)("IOCTL_HID_WRITE_REPORT / IOCTL_HID_SET_OUTPUT_REPORT\n");
|
2021-09-03 09:30:49 +02:00
|
|
|
unix_device_set_output_report(device, packet, &irp->IoStatus);
|
2016-10-27 15:37:41 +02:00
|
|
|
break;
|
|
|
|
}
|
2016-11-02 14:12:24 +01:00
|
|
|
case IOCTL_HID_GET_FEATURE:
|
|
|
|
{
|
|
|
|
HID_XFER_PACKET *packet = (HID_XFER_PACKET*)(irp->UserBuffer);
|
|
|
|
TRACE_(hid_report)("IOCTL_HID_GET_FEATURE\n");
|
2021-09-03 09:30:49 +02:00
|
|
|
unix_device_get_feature_report(device, packet, &irp->IoStatus);
|
2016-11-02 14:12:24 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case IOCTL_HID_SET_FEATURE:
|
|
|
|
{
|
|
|
|
HID_XFER_PACKET *packet = (HID_XFER_PACKET*)(irp->UserBuffer);
|
|
|
|
TRACE_(hid_report)("IOCTL_HID_SET_FEATURE\n");
|
2021-09-03 09:30:49 +02:00
|
|
|
unix_device_set_feature_report(device, packet, &irp->IoStatus);
|
2016-11-02 14:12:24 +01:00
|
|
|
break;
|
|
|
|
}
|
2016-10-06 14:19:27 +02:00
|
|
|
default:
|
|
|
|
FIXME("Unsupported ioctl %x (device=%x access=%x func=%x method=%x)\n",
|
|
|
|
code, code >> 16, (code >> 14) & 3, (code >> 2) & 0xfff, code & 3);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-08-13 09:46:12 +02:00
|
|
|
status = irp->IoStatus.Status;
|
2021-09-16 10:17:57 +02:00
|
|
|
RtlLeaveCriticalSection(&ext->cs);
|
2021-04-15 06:22:05 +02:00
|
|
|
|
2021-08-12 09:47:03 +02:00
|
|
|
if (status != STATUS_PENDING) IoCompleteRequest(irp, IO_NO_INCREMENT);
|
2016-10-06 14:19:27 +02:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2019-11-07 06:54:58 +01:00
|
|
|
static NTSTATUS WINAPI driver_add_device(DRIVER_OBJECT *driver, DEVICE_OBJECT *pdo)
|
|
|
|
{
|
|
|
|
NTSTATUS ret;
|
|
|
|
|
|
|
|
TRACE("driver %p, pdo %p.\n", driver, pdo);
|
|
|
|
|
|
|
|
if ((ret = IoCreateDevice(driver, 0, NULL, FILE_DEVICE_BUS_EXTENDER, 0, FALSE, &bus_fdo)))
|
|
|
|
{
|
|
|
|
ERR("Failed to create FDO, status %#x.\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
IoAttachDeviceToDeviceStack(bus_fdo, pdo);
|
|
|
|
bus_pdo = pdo;
|
|
|
|
|
|
|
|
bus_fdo->Flags &= ~DO_DEVICE_INITIALIZING;
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2018-09-12 18:22:09 +02:00
|
|
|
static void WINAPI driver_unload(DRIVER_OBJECT *driver)
|
|
|
|
{
|
2019-05-30 06:02:29 +02:00
|
|
|
NtClose(driver_key);
|
2018-09-12 18:22:09 +02:00
|
|
|
}
|
|
|
|
|
2016-09-01 15:18:17 +02:00
|
|
|
NTSTATUS WINAPI DriverEntry( DRIVER_OBJECT *driver, UNICODE_STRING *path )
|
|
|
|
{
|
2019-05-30 06:02:29 +02:00
|
|
|
OBJECT_ATTRIBUTES attr = {0};
|
|
|
|
NTSTATUS ret;
|
2016-09-08 10:12:50 +02:00
|
|
|
|
2016-09-01 15:18:17 +02:00
|
|
|
TRACE( "(%p, %s)\n", driver, debugstr_w(path->Buffer) );
|
|
|
|
|
2021-09-17 08:50:31 +02:00
|
|
|
RtlPcToFileHeader(&DriverEntry, (void *)&instance);
|
2021-09-17 08:50:34 +02:00
|
|
|
if ((ret = NtQueryVirtualMemory(GetCurrentProcess(), instance, MemoryWineUnixFuncs,
|
|
|
|
&winebus_handle, sizeof(winebus_handle), NULL)))
|
2021-09-17 08:50:31 +02:00
|
|
|
return ret;
|
|
|
|
|
2019-05-30 06:02:29 +02:00
|
|
|
attr.Length = sizeof(attr);
|
|
|
|
attr.ObjectName = path;
|
|
|
|
attr.Attributes = OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE;
|
|
|
|
if ((ret = NtOpenKey(&driver_key, KEY_ALL_ACCESS, &attr)) != STATUS_SUCCESS)
|
|
|
|
ERR("Failed to open driver key, status %#x.\n", ret);
|
|
|
|
|
2019-05-30 06:02:28 +02:00
|
|
|
driver_obj = driver;
|
|
|
|
|
|
|
|
driver->MajorFunction[IRP_MJ_PNP] = common_pnp_dispatch;
|
|
|
|
driver->MajorFunction[IRP_MJ_INTERNAL_DEVICE_CONTROL] = hid_internal_dispatch;
|
2019-11-07 06:54:58 +01:00
|
|
|
driver->DriverExtension->AddDevice = driver_add_device;
|
2019-05-30 06:02:28 +02:00
|
|
|
driver->DriverUnload = driver_unload;
|
|
|
|
|
2016-09-01 15:18:17 +02:00
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|