2021-08-23 10:49:39 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2021 Rémi Bernon for CodeWeavers
|
|
|
|
*
|
|
|
|
* 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
|
|
|
#if 0
|
|
|
|
#pragma makedep unix
|
|
|
|
#endif
|
|
|
|
|
2021-08-23 10:49:39 +02:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
2021-09-17 08:50:32 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2021-08-23 10:49:39 +02:00
|
|
|
#include "ntstatus.h"
|
|
|
|
#define WIN32_NO_STATUS
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winternl.h"
|
2021-08-30 11:22:55 +02:00
|
|
|
#include "ddk/hidtypes.h"
|
2021-08-23 10:49:39 +02:00
|
|
|
|
|
|
|
#include "wine/debug.h"
|
2021-08-30 11:22:52 +02:00
|
|
|
#include "wine/list.h"
|
2021-08-23 10:49:39 +02:00
|
|
|
#include "wine/unixlib.h"
|
|
|
|
|
|
|
|
#include "unix_private.h"
|
|
|
|
|
2021-09-16 10:17:54 +02:00
|
|
|
BOOL is_xbox_gamepad(WORD vid, WORD pid)
|
|
|
|
{
|
|
|
|
if (vid != 0x045e) return FALSE;
|
|
|
|
if (pid == 0x0202) return TRUE; /* Xbox Controller */
|
|
|
|
if (pid == 0x0285) return TRUE; /* Xbox Controller S */
|
|
|
|
if (pid == 0x0289) return TRUE; /* Xbox Controller S */
|
|
|
|
if (pid == 0x028e) return TRUE; /* Xbox360 Controller */
|
|
|
|
if (pid == 0x028f) return TRUE; /* Xbox360 Wireless Controller */
|
|
|
|
if (pid == 0x02d1) return TRUE; /* Xbox One Controller */
|
|
|
|
if (pid == 0x02dd) return TRUE; /* Xbox One Controller (Covert Forces/Firmware 2015) */
|
|
|
|
if (pid == 0x02e0) return TRUE; /* Xbox One X Controller */
|
|
|
|
if (pid == 0x02e3) return TRUE; /* Xbox One Elite Controller */
|
|
|
|
if (pid == 0x02e6) return TRUE; /* Wireless XBox Controller Dongle */
|
|
|
|
if (pid == 0x02ea) return TRUE; /* Xbox One S Controller */
|
|
|
|
if (pid == 0x02fd) return TRUE; /* Xbox One S Controller (Firmware 2017) */
|
|
|
|
if (pid == 0x0719) return TRUE; /* Xbox 360 Wireless Adapter */
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2021-09-14 08:58:23 +02:00
|
|
|
struct mouse_device
|
|
|
|
{
|
|
|
|
struct unix_device unix_device;
|
|
|
|
};
|
|
|
|
|
2021-09-14 08:58:21 +02:00
|
|
|
static void mouse_destroy(struct unix_device *iface)
|
2021-08-30 11:22:55 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-09-15 09:04:46 +02:00
|
|
|
static NTSTATUS mouse_start(struct unix_device *iface)
|
2021-08-30 11:22:55 +02:00
|
|
|
{
|
2021-09-22 10:30:42 +02:00
|
|
|
if (!hid_device_begin_report_descriptor(iface, HID_USAGE_PAGE_GENERIC, HID_USAGE_GENERIC_MOUSE))
|
2021-08-30 11:22:55 +02:00
|
|
|
return STATUS_NO_MEMORY;
|
2021-09-22 10:30:42 +02:00
|
|
|
if (!hid_device_add_buttons(iface, HID_USAGE_PAGE_BUTTON, 1, 3))
|
2021-08-30 11:22:55 +02:00
|
|
|
return STATUS_NO_MEMORY;
|
2021-09-22 10:30:42 +02:00
|
|
|
if (!hid_device_end_report_descriptor(iface))
|
2021-08-30 11:22:55 +02:00
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2021-09-14 08:58:21 +02:00
|
|
|
static void mouse_stop(struct unix_device *iface)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-09-23 08:55:30 +02:00
|
|
|
static NTSTATUS mouse_haptics_start(struct unix_device *iface, DWORD duration,
|
|
|
|
USHORT rumble_intensity, USHORT buzz_intensity)
|
2021-08-30 11:22:55 +02:00
|
|
|
{
|
2021-09-23 08:55:30 +02:00
|
|
|
return STATUS_NOT_SUPPORTED;
|
2021-08-30 11:22:55 +02:00
|
|
|
}
|
|
|
|
|
2021-09-22 10:30:42 +02:00
|
|
|
static const struct hid_device_vtbl mouse_vtbl =
|
2021-08-30 11:22:55 +02:00
|
|
|
{
|
2021-09-14 08:58:21 +02:00
|
|
|
mouse_destroy,
|
2021-09-03 09:30:49 +02:00
|
|
|
mouse_start,
|
2021-09-14 08:58:21 +02:00
|
|
|
mouse_stop,
|
2021-09-23 08:55:30 +02:00
|
|
|
mouse_haptics_start,
|
2021-08-30 11:22:55 +02:00
|
|
|
};
|
|
|
|
|
2021-09-03 09:30:48 +02:00
|
|
|
static const struct device_desc mouse_device_desc =
|
|
|
|
{
|
2021-09-20 09:37:03 +02:00
|
|
|
.vid = 0x845e,
|
|
|
|
.pid = 0x0001,
|
2021-09-03 09:30:48 +02:00
|
|
|
.input = -1,
|
2021-09-13 13:01:46 +02:00
|
|
|
.manufacturer = {"The Wine Project"},
|
2021-09-13 13:01:47 +02:00
|
|
|
.product = {"Wine HID mouse"},
|
2021-09-13 13:01:48 +02:00
|
|
|
.serialnumber = {"0000"},
|
2021-09-03 09:30:48 +02:00
|
|
|
};
|
2021-08-30 11:22:55 +02:00
|
|
|
|
2021-09-17 08:50:34 +02:00
|
|
|
static NTSTATUS mouse_device_create(void *args)
|
2021-08-30 11:22:55 +02:00
|
|
|
{
|
|
|
|
struct device_create_params *params = args;
|
2021-09-03 09:30:48 +02:00
|
|
|
params->desc = mouse_device_desc;
|
2021-09-22 10:30:42 +02:00
|
|
|
params->device = hid_device_create(&mouse_vtbl, sizeof(struct mouse_device));
|
2021-08-30 11:22:55 +02:00
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2021-09-14 08:58:23 +02:00
|
|
|
struct keyboard_device
|
|
|
|
{
|
|
|
|
struct unix_device unix_device;
|
|
|
|
};
|
|
|
|
|
2021-09-14 08:58:21 +02:00
|
|
|
static void keyboard_destroy(struct unix_device *iface)
|
2021-08-30 11:22:55 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-09-15 09:04:46 +02:00
|
|
|
static NTSTATUS keyboard_start(struct unix_device *iface)
|
2021-08-30 11:22:55 +02:00
|
|
|
{
|
2021-09-22 10:30:42 +02:00
|
|
|
if (!hid_device_begin_report_descriptor(iface, HID_USAGE_PAGE_GENERIC, HID_USAGE_GENERIC_KEYBOARD))
|
2021-08-30 11:22:55 +02:00
|
|
|
return STATUS_NO_MEMORY;
|
2021-09-22 10:30:42 +02:00
|
|
|
if (!hid_device_add_buttons(iface, HID_USAGE_PAGE_KEYBOARD, 0, 101))
|
2021-08-30 11:22:55 +02:00
|
|
|
return STATUS_NO_MEMORY;
|
2021-09-22 10:30:42 +02:00
|
|
|
if (!hid_device_end_report_descriptor(iface))
|
2021-08-30 11:22:55 +02:00
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2021-09-14 08:58:21 +02:00
|
|
|
static void keyboard_stop(struct unix_device *iface)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-09-23 08:55:30 +02:00
|
|
|
static NTSTATUS keyboard_haptics_start(struct unix_device *iface, DWORD duration,
|
|
|
|
USHORT rumble_intensity, USHORT buzz_intensity)
|
2021-08-30 11:22:55 +02:00
|
|
|
{
|
2021-09-23 08:55:30 +02:00
|
|
|
return STATUS_NOT_SUPPORTED;
|
2021-08-30 11:22:55 +02:00
|
|
|
}
|
|
|
|
|
2021-09-22 10:30:42 +02:00
|
|
|
static const struct hid_device_vtbl keyboard_vtbl =
|
2021-08-30 11:22:55 +02:00
|
|
|
{
|
2021-09-14 08:58:21 +02:00
|
|
|
keyboard_destroy,
|
2021-09-03 09:30:49 +02:00
|
|
|
keyboard_start,
|
2021-09-14 08:58:21 +02:00
|
|
|
keyboard_stop,
|
2021-09-23 08:55:30 +02:00
|
|
|
keyboard_haptics_start,
|
2021-08-30 11:22:55 +02:00
|
|
|
};
|
|
|
|
|
2021-09-03 09:30:48 +02:00
|
|
|
static const struct device_desc keyboard_device_desc =
|
|
|
|
{
|
2021-09-20 09:37:03 +02:00
|
|
|
.vid = 0x845e,
|
|
|
|
.pid = 0x0002,
|
2021-09-03 09:30:48 +02:00
|
|
|
.input = -1,
|
2021-09-13 13:01:46 +02:00
|
|
|
.manufacturer = {"The Wine Project"},
|
2021-09-13 13:01:47 +02:00
|
|
|
.product = {"Wine HID keyboard"},
|
2021-09-13 13:01:48 +02:00
|
|
|
.serialnumber = {"0000"},
|
2021-09-03 09:30:48 +02:00
|
|
|
};
|
2021-08-30 11:22:55 +02:00
|
|
|
|
2021-09-17 08:50:34 +02:00
|
|
|
static NTSTATUS keyboard_device_create(void *args)
|
2021-08-30 11:22:55 +02:00
|
|
|
{
|
|
|
|
struct device_create_params *params = args;
|
2021-09-03 09:30:48 +02:00
|
|
|
params->desc = keyboard_device_desc;
|
2021-09-22 10:30:42 +02:00
|
|
|
params->device = hid_device_create(&keyboard_vtbl, sizeof(struct keyboard_device));
|
2021-08-30 11:22:55 +02:00
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2021-09-22 10:30:42 +02:00
|
|
|
void *raw_device_create(const struct raw_device_vtbl *vtbl, SIZE_T size)
|
2021-09-14 08:58:22 +02:00
|
|
|
{
|
|
|
|
struct unix_device *iface;
|
|
|
|
|
2021-09-17 08:50:32 +02:00
|
|
|
if (!(iface = calloc(1, size))) return NULL;
|
2021-09-14 08:58:22 +02:00
|
|
|
iface->vtbl = vtbl;
|
2021-09-15 09:04:41 +02:00
|
|
|
iface->ref = 1;
|
2021-09-14 08:58:22 +02:00
|
|
|
|
|
|
|
return iface;
|
|
|
|
}
|
|
|
|
|
2021-09-15 09:04:41 +02:00
|
|
|
static void unix_device_decref(struct unix_device *iface)
|
|
|
|
{
|
|
|
|
if (!InterlockedDecrement(&iface->ref))
|
|
|
|
{
|
|
|
|
iface->vtbl->destroy(iface);
|
2021-09-17 08:50:32 +02:00
|
|
|
free(iface);
|
2021-09-15 09:04:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG unix_device_incref(struct unix_device *iface)
|
|
|
|
{
|
|
|
|
return InterlockedIncrement(&iface->ref);
|
|
|
|
}
|
|
|
|
|
2021-09-17 08:50:34 +02:00
|
|
|
static NTSTATUS unix_device_remove(void *args)
|
2021-09-03 09:30:49 +02:00
|
|
|
{
|
|
|
|
struct unix_device *iface = args;
|
2021-09-14 08:58:21 +02:00
|
|
|
iface->vtbl->stop(iface);
|
2021-09-15 09:04:41 +02:00
|
|
|
unix_device_decref(iface);
|
2021-09-03 09:30:49 +02:00
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2021-09-17 08:50:34 +02:00
|
|
|
static NTSTATUS unix_device_start(void *args)
|
2021-09-03 09:30:49 +02:00
|
|
|
{
|
2021-09-15 09:04:46 +02:00
|
|
|
struct unix_device *iface = args;
|
|
|
|
return iface->vtbl->start(iface);
|
2021-09-03 09:30:49 +02:00
|
|
|
}
|
|
|
|
|
2021-09-17 08:50:34 +02:00
|
|
|
static NTSTATUS unix_device_get_report_descriptor(void *args)
|
2021-09-03 09:30:49 +02:00
|
|
|
{
|
|
|
|
struct device_descriptor_params *params = args;
|
|
|
|
struct unix_device *iface = params->iface;
|
|
|
|
return iface->vtbl->get_report_descriptor(iface, params->buffer, params->length, params->out_length);
|
|
|
|
}
|
|
|
|
|
2021-09-17 08:50:34 +02:00
|
|
|
static NTSTATUS unix_device_set_output_report(void *args)
|
2021-09-03 09:30:49 +02:00
|
|
|
{
|
|
|
|
struct device_report_params *params = args;
|
|
|
|
struct unix_device *iface = params->iface;
|
|
|
|
iface->vtbl->set_output_report(iface, params->packet, params->io);
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2021-09-17 08:50:34 +02:00
|
|
|
static NTSTATUS unix_device_get_feature_report(void *args)
|
2021-09-03 09:30:49 +02:00
|
|
|
{
|
|
|
|
struct device_report_params *params = args;
|
|
|
|
struct unix_device *iface = params->iface;
|
|
|
|
iface->vtbl->get_feature_report(iface, params->packet, params->io);
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2021-09-17 08:50:34 +02:00
|
|
|
static NTSTATUS unix_device_set_feature_report(void *args)
|
2021-09-03 09:30:49 +02:00
|
|
|
{
|
|
|
|
struct device_report_params *params = args;
|
|
|
|
struct unix_device *iface = params->iface;
|
|
|
|
iface->vtbl->set_feature_report(iface, params->packet, params->io);
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2021-09-17 08:50:34 +02:00
|
|
|
const unixlib_entry_t __wine_unix_call_funcs[] =
|
2021-08-23 10:49:39 +02:00
|
|
|
{
|
|
|
|
sdl_bus_init,
|
|
|
|
sdl_bus_wait,
|
|
|
|
sdl_bus_stop,
|
|
|
|
udev_bus_init,
|
|
|
|
udev_bus_wait,
|
|
|
|
udev_bus_stop,
|
|
|
|
iohid_bus_init,
|
|
|
|
iohid_bus_wait,
|
|
|
|
iohid_bus_stop,
|
2021-08-30 11:22:55 +02:00
|
|
|
mouse_device_create,
|
|
|
|
keyboard_device_create,
|
2021-09-03 09:30:49 +02:00
|
|
|
unix_device_remove,
|
|
|
|
unix_device_start,
|
|
|
|
unix_device_get_report_descriptor,
|
|
|
|
unix_device_set_output_report,
|
|
|
|
unix_device_get_feature_report,
|
|
|
|
unix_device_set_feature_report,
|
2021-08-23 10:49:39 +02:00
|
|
|
};
|
2021-08-30 11:22:52 +02:00
|
|
|
|
2021-09-15 09:04:41 +02:00
|
|
|
void bus_event_cleanup(struct bus_event *event)
|
|
|
|
{
|
2021-09-16 10:17:52 +02:00
|
|
|
if (event->type == BUS_EVENT_TYPE_NONE) return;
|
|
|
|
unix_device_decref(event->device);
|
2021-09-15 09:04:41 +02:00
|
|
|
}
|
|
|
|
|
2021-08-30 11:22:52 +02:00
|
|
|
void bus_event_queue_destroy(struct list *queue)
|
|
|
|
{
|
|
|
|
struct bus_event *event, *next;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY_SAFE(event, next, queue, struct bus_event, entry)
|
2021-09-15 09:04:41 +02:00
|
|
|
{
|
|
|
|
bus_event_cleanup(event);
|
2021-09-17 08:50:32 +02:00
|
|
|
free(event);
|
2021-09-15 09:04:41 +02:00
|
|
|
}
|
2021-08-30 11:22:52 +02:00
|
|
|
}
|
|
|
|
|
2021-09-16 10:17:52 +02:00
|
|
|
BOOL bus_event_queue_device_removed(struct list *queue, struct unix_device *device)
|
2021-08-30 11:22:52 +02:00
|
|
|
{
|
|
|
|
ULONG size = sizeof(struct bus_event);
|
2021-09-17 08:50:32 +02:00
|
|
|
struct bus_event *event = malloc(size);
|
2021-08-30 11:22:52 +02:00
|
|
|
if (!event) return FALSE;
|
|
|
|
|
2021-09-16 10:17:52 +02:00
|
|
|
if (unix_device_incref(device) == 1) return FALSE; /* being destroyed */
|
|
|
|
|
2021-08-30 11:22:52 +02:00
|
|
|
event->type = BUS_EVENT_TYPE_DEVICE_REMOVED;
|
2021-09-16 10:17:52 +02:00
|
|
|
event->device = device;
|
2021-08-30 11:22:52 +02:00
|
|
|
list_add_tail(queue, &event->entry);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2021-09-06 09:17:31 +02:00
|
|
|
BOOL bus_event_queue_device_created(struct list *queue, struct unix_device *device, struct device_desc *desc)
|
|
|
|
{
|
|
|
|
ULONG size = sizeof(struct bus_event);
|
2021-09-17 08:50:32 +02:00
|
|
|
struct bus_event *event = malloc(size);
|
2021-09-06 09:17:31 +02:00
|
|
|
if (!event) return FALSE;
|
|
|
|
|
2021-09-16 10:17:52 +02:00
|
|
|
if (unix_device_incref(device) == 1) return FALSE; /* being destroyed */
|
|
|
|
|
2021-09-06 09:17:31 +02:00
|
|
|
event->type = BUS_EVENT_TYPE_DEVICE_CREATED;
|
2021-09-16 10:17:52 +02:00
|
|
|
event->device = device;
|
2021-09-06 09:17:31 +02:00
|
|
|
event->device_created.desc = *desc;
|
|
|
|
list_add_tail(queue, &event->entry);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2021-09-15 09:04:41 +02:00
|
|
|
BOOL bus_event_queue_input_report(struct list *queue, struct unix_device *device, BYTE *report, USHORT length)
|
|
|
|
{
|
|
|
|
ULONG size = offsetof(struct bus_event, input_report.buffer[length]);
|
2021-09-17 08:50:32 +02:00
|
|
|
struct bus_event *event = malloc(size);
|
2021-09-15 09:04:41 +02:00
|
|
|
if (!event) return FALSE;
|
|
|
|
|
|
|
|
if (unix_device_incref(device) == 1) return FALSE; /* being destroyed */
|
|
|
|
|
|
|
|
event->type = BUS_EVENT_TYPE_INPUT_REPORT;
|
2021-09-16 10:17:52 +02:00
|
|
|
event->device = device;
|
2021-09-15 09:04:41 +02:00
|
|
|
event->input_report.length = length;
|
|
|
|
memcpy(event->input_report.buffer, report, length);
|
|
|
|
list_add_tail(queue, &event->entry);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2021-08-30 11:22:52 +02:00
|
|
|
BOOL bus_event_queue_pop(struct list *queue, struct bus_event *event)
|
|
|
|
{
|
|
|
|
struct list *entry = list_head(queue);
|
|
|
|
struct bus_event *tmp;
|
2021-09-15 09:04:41 +02:00
|
|
|
ULONG size;
|
2021-08-30 11:22:52 +02:00
|
|
|
|
|
|
|
if (!entry) return FALSE;
|
|
|
|
|
|
|
|
tmp = LIST_ENTRY(entry, struct bus_event, entry);
|
|
|
|
list_remove(entry);
|
|
|
|
|
2021-09-15 09:04:41 +02:00
|
|
|
if (event->type != BUS_EVENT_TYPE_INPUT_REPORT) size = sizeof(*event);
|
|
|
|
else size = offsetof(struct bus_event, input_report.buffer[event->input_report.length]);
|
|
|
|
|
|
|
|
memcpy(event, tmp, size);
|
2021-09-17 08:50:32 +02:00
|
|
|
free(tmp);
|
2021-08-30 11:22:52 +02:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|