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) */
|
2021-10-05 09:11:52 +02:00
|
|
|
if (pid == 0x0b00) return TRUE; /* Xbox Elite 2 */
|
|
|
|
if (pid == 0x0b05) return TRUE; /* Xbox Elite 2 Wireless */
|
|
|
|
if (pid == 0x0b12) return TRUE; /* Xbox Series */
|
|
|
|
if (pid == 0x0b13) return TRUE; /* Xbox Series Wireless */
|
2021-09-16 10:17:54 +02:00
|
|
|
if (pid == 0x0719) return TRUE; /* Xbox 360 Wireless Adapter */
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2021-10-18 17:16:45 +02:00
|
|
|
BOOL is_dualshock4_gamepad(WORD vid, WORD pid)
|
|
|
|
{
|
|
|
|
if (vid != 0x054c) return FALSE;
|
|
|
|
if (pid == 0x05c4) return TRUE; /* DualShock 4 [CUH-ZCT1x] */
|
|
|
|
if (pid == 0x09cc) return TRUE; /* DualShock 4 [CUH-ZCT2x] */
|
|
|
|
if (pid == 0x0ba0) return TRUE; /* Dualshock 4 Wireless Adaptor */
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2022-01-27 18:17:57 +01:00
|
|
|
BOOL is_dualsense_gamepad(WORD vid, WORD pid)
|
|
|
|
{
|
|
|
|
if (vid == 0x054c && pid == 0x0ce6) return TRUE;
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-01-31 10:10:59 +01:00
|
|
|
static NTSTATUS mouse_haptics_start(struct unix_device *iface, UINT duration,
|
2021-09-23 08:55:30 +02:00
|
|
|
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-10-01 09:31:00 +02:00
|
|
|
static NTSTATUS mouse_physical_device_control(struct unix_device *iface, USAGE control)
|
|
|
|
{
|
|
|
|
return STATUS_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
|
2021-11-19 09:39:39 +01:00
|
|
|
static NTSTATUS mouse_physical_device_set_gain(struct unix_device *iface, BYTE percent)
|
2021-11-17 11:51:50 +01:00
|
|
|
{
|
|
|
|
return STATUS_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
|
2021-10-04 09:51:31 +02:00
|
|
|
static NTSTATUS mouse_physical_effect_control(struct unix_device *iface, BYTE index,
|
|
|
|
USAGE control, BYTE iterations)
|
|
|
|
{
|
|
|
|
return STATUS_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
|
2021-10-05 08:43:22 +02:00
|
|
|
static NTSTATUS mouse_physical_effect_update(struct unix_device *iface, BYTE index,
|
|
|
|
struct effect_params *params)
|
|
|
|
{
|
|
|
|
return STATUS_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
|
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-10-01 09:31:00 +02:00
|
|
|
mouse_physical_device_control,
|
2021-11-17 11:51:50 +01:00
|
|
|
mouse_physical_device_set_gain,
|
2021-10-04 09:51:31 +02:00
|
|
|
mouse_physical_effect_control,
|
2021-10-05 08:43:22 +02:00
|
|
|
mouse_physical_effect_update,
|
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-10-05 10:55:50 +02:00
|
|
|
.manufacturer = {'T','h','e',' ','W','i','n','e',' ','P','r','o','j','e','c','t',0},
|
|
|
|
.product = {'W','i','n','e',' ','H','I','D',' ','m','o','u','s','e',0},
|
|
|
|
.serialnumber = {'0','0','0','0',0},
|
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)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-01-31 10:10:59 +01:00
|
|
|
static NTSTATUS keyboard_haptics_start(struct unix_device *iface, UINT duration,
|
2021-09-23 08:55:30 +02:00
|
|
|
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-10-01 09:31:00 +02:00
|
|
|
static NTSTATUS keyboard_physical_device_control(struct unix_device *iface, USAGE control)
|
|
|
|
{
|
|
|
|
return STATUS_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
|
2021-11-19 09:39:39 +01:00
|
|
|
static NTSTATUS keyboard_physical_device_set_gain(struct unix_device *iface, BYTE percent)
|
2021-11-17 11:51:50 +01:00
|
|
|
{
|
|
|
|
return STATUS_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
|
2021-10-04 09:51:31 +02:00
|
|
|
static NTSTATUS keyboard_physical_effect_control(struct unix_device *iface, BYTE index,
|
|
|
|
USAGE control, BYTE iterations)
|
|
|
|
{
|
|
|
|
return STATUS_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
|
2021-10-05 08:43:22 +02:00
|
|
|
static NTSTATUS keyboard_physical_effect_update(struct unix_device *iface, BYTE index,
|
|
|
|
struct effect_params *params)
|
|
|
|
{
|
|
|
|
return STATUS_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
|
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-10-01 09:31:00 +02:00
|
|
|
keyboard_physical_device_control,
|
2021-11-17 11:51:50 +01:00
|
|
|
keyboard_physical_device_set_gain,
|
2021-10-04 09:51:31 +02:00
|
|
|
keyboard_physical_effect_control,
|
2021-10-05 08:43:22 +02:00
|
|
|
keyboard_physical_effect_update,
|
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-10-05 10:55:50 +02:00
|
|
|
.manufacturer = {'T','h','e',' ','W','i','n','e',' ','P','r','o','j','e','c','t',0},
|
|
|
|
.product = {'W','i','n','e',' ','H','I','D',' ','k','e','y','b','o','a','r','d',0},
|
|
|
|
.serialnumber = {'0','0','0','0',0},
|
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-10-08 12:36:44 +02:00
|
|
|
if (unix_device_incref(device) == 1) /* being destroyed */
|
|
|
|
{
|
|
|
|
free(event);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2021-09-16 10:17:52 +02:00
|
|
|
|
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-10-08 12:36:44 +02:00
|
|
|
if (unix_device_incref(device) == 1) /* being destroyed */
|
|
|
|
{
|
|
|
|
free(event);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2021-09-16 10:17:52 +02:00
|
|
|
|
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;
|
|
|
|
|
2021-10-08 12:36:44 +02:00
|
|
|
if (unix_device_incref(device) == 1) /* being destroyed */
|
|
|
|
{
|
|
|
|
free(event);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2021-09-15 09:04:41 +02:00
|
|
|
|
|
|
|
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-10-04 10:23:39 +02:00
|
|
|
if (tmp->type != BUS_EVENT_TYPE_INPUT_REPORT) size = sizeof(*tmp);
|
|
|
|
else size = offsetof(struct bus_event, input_report.buffer[tmp->input_report.length]);
|
2021-09-15 09:04:41 +02:00
|
|
|
|
|
|
|
memcpy(event, tmp, size);
|
2021-09-17 08:50:32 +02:00
|
|
|
free(tmp);
|
2021-08-30 11:22:52 +02:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|