2016-11-07 20:42:23 +01:00
|
|
|
/* Bus like function for mac HID devices
|
|
|
|
*
|
|
|
|
* Copyright 2016 CodeWeavers, 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
|
|
|
#if 0
|
|
|
|
#pragma makedep unix
|
|
|
|
#endif
|
|
|
|
|
2016-11-07 20:42:23 +01:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
2021-11-03 10:43:50 +01:00
|
|
|
#include <sys/types.h>
|
2016-11-07 20:42:23 +01:00
|
|
|
|
|
|
|
#if defined(HAVE_IOKIT_HID_IOHIDLIB_H)
|
|
|
|
#define DWORD UInt32
|
|
|
|
#define LPDWORD UInt32*
|
|
|
|
#define LONG SInt32
|
|
|
|
#define LPLONG SInt32*
|
|
|
|
#define E_PENDING __carbon_E_PENDING
|
|
|
|
#define ULONG __carbon_ULONG
|
|
|
|
#define E_INVALIDARG __carbon_E_INVALIDARG
|
|
|
|
#define E_OUTOFMEMORY __carbon_E_OUTOFMEMORY
|
|
|
|
#define E_HANDLE __carbon_E_HANDLE
|
|
|
|
#define E_ACCESSDENIED __carbon_E_ACCESSDENIED
|
|
|
|
#define E_UNEXPECTED __carbon_E_UNEXPECTED
|
|
|
|
#define E_FAIL __carbon_E_FAIL
|
|
|
|
#define E_ABORT __carbon_E_ABORT
|
|
|
|
#define E_POINTER __carbon_E_POINTER
|
|
|
|
#define E_NOINTERFACE __carbon_E_NOINTERFACE
|
|
|
|
#define E_NOTIMPL __carbon_E_NOTIMPL
|
|
|
|
#define S_FALSE __carbon_S_FALSE
|
|
|
|
#define S_OK __carbon_S_OK
|
|
|
|
#define HRESULT_FACILITY __carbon_HRESULT_FACILITY
|
|
|
|
#define IS_ERROR __carbon_IS_ERROR
|
|
|
|
#define FAILED __carbon_FAILED
|
|
|
|
#define SUCCEEDED __carbon_SUCCEEDED
|
|
|
|
#define MAKE_HRESULT __carbon_MAKE_HRESULT
|
|
|
|
#define HRESULT __carbon_HRESULT
|
|
|
|
#define STDMETHODCALLTYPE __carbon_STDMETHODCALLTYPE
|
|
|
|
#define PAGE_SHIFT __carbon_PAGE_SHIFT
|
|
|
|
#include <IOKit/IOKitLib.h>
|
|
|
|
#include <IOKit/hid/IOHIDLib.h>
|
|
|
|
#undef ULONG
|
|
|
|
#undef E_INVALIDARG
|
|
|
|
#undef E_OUTOFMEMORY
|
|
|
|
#undef E_HANDLE
|
|
|
|
#undef E_ACCESSDENIED
|
|
|
|
#undef E_UNEXPECTED
|
|
|
|
#undef E_FAIL
|
|
|
|
#undef E_ABORT
|
|
|
|
#undef E_POINTER
|
|
|
|
#undef E_NOINTERFACE
|
|
|
|
#undef E_NOTIMPL
|
|
|
|
#undef S_FALSE
|
|
|
|
#undef S_OK
|
|
|
|
#undef HRESULT_FACILITY
|
|
|
|
#undef IS_ERROR
|
|
|
|
#undef FAILED
|
|
|
|
#undef SUCCEEDED
|
|
|
|
#undef MAKE_HRESULT
|
|
|
|
#undef HRESULT
|
|
|
|
#undef STDMETHODCALLTYPE
|
|
|
|
#undef DWORD
|
|
|
|
#undef LPDWORD
|
|
|
|
#undef LONG
|
|
|
|
#undef LPLONG
|
|
|
|
#undef E_PENDING
|
|
|
|
#undef PAGE_SHIFT
|
|
|
|
#endif /* HAVE_IOKIT_HID_IOHIDLIB_H */
|
|
|
|
|
2021-09-17 08:50:33 +02:00
|
|
|
#include <pthread.h>
|
|
|
|
|
2016-11-07 20:42:23 +01:00
|
|
|
#include "ntstatus.h"
|
|
|
|
#define WIN32_NO_STATUS
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winternl.h"
|
|
|
|
#include "winioctl.h"
|
|
|
|
#include "ddk/wdm.h"
|
2016-11-07 20:42:34 +01:00
|
|
|
#include "ddk/hidtypes.h"
|
2016-11-07 20:42:23 +01:00
|
|
|
#include "wine/debug.h"
|
|
|
|
|
2021-08-23 10:49:39 +02:00
|
|
|
#include "unix_private.h"
|
2016-11-07 20:42:23 +01:00
|
|
|
|
2021-11-09 09:51:08 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(hid);
|
2016-11-07 20:42:23 +01:00
|
|
|
#ifdef HAVE_IOHIDMANAGERCREATE
|
|
|
|
|
2021-09-17 08:50:33 +02:00
|
|
|
static pthread_mutex_t iohid_cs = PTHREAD_MUTEX_INITIALIZER;
|
2021-09-16 10:17:52 +02:00
|
|
|
|
2016-11-07 20:42:23 +01:00
|
|
|
static IOHIDManagerRef hid_manager;
|
2018-09-12 18:22:09 +02:00
|
|
|
static CFRunLoopRef run_loop;
|
2021-08-30 11:22:54 +02:00
|
|
|
static struct list event_queue = LIST_INIT(event_queue);
|
2021-09-16 10:17:52 +02:00
|
|
|
static struct list device_list = LIST_INIT(device_list);
|
2021-08-23 10:49:40 +02:00
|
|
|
static struct iohid_bus_options options;
|
2016-11-07 20:42:23 +01:00
|
|
|
|
2021-09-22 10:30:41 +02:00
|
|
|
struct iohid_device
|
2016-11-07 20:42:23 +01:00
|
|
|
{
|
2021-08-23 10:49:41 +02:00
|
|
|
struct unix_device unix_device;
|
2016-11-07 20:42:23 +01:00
|
|
|
IOHIDDeviceRef device;
|
2016-11-07 20:42:37 +01:00
|
|
|
uint8_t *buffer;
|
2016-11-07 20:42:23 +01:00
|
|
|
};
|
|
|
|
|
2021-09-22 10:30:41 +02:00
|
|
|
static inline struct iohid_device *impl_from_unix_device(struct unix_device *iface)
|
2021-08-23 10:49:41 +02:00
|
|
|
{
|
2021-09-22 10:30:41 +02:00
|
|
|
return CONTAINING_RECORD(iface, struct iohid_device, unix_device);
|
2021-08-23 10:49:41 +02:00
|
|
|
}
|
|
|
|
|
2021-09-22 10:30:41 +02:00
|
|
|
static struct iohid_device *find_device_from_iohid(IOHIDDeviceRef IOHIDDevice)
|
2021-09-16 10:17:52 +02:00
|
|
|
{
|
2021-09-22 10:30:41 +02:00
|
|
|
struct iohid_device *impl;
|
2021-09-16 10:17:52 +02:00
|
|
|
|
2021-09-22 10:30:41 +02:00
|
|
|
LIST_FOR_EACH_ENTRY(impl, &device_list, struct iohid_device, unix_device.entry)
|
|
|
|
if (impl->device == IOHIDDevice) return impl;
|
2021-09-16 10:17:52 +02:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2021-10-05 10:55:50 +02:00
|
|
|
static void CFStringToWSTR(CFStringRef cstr, LPWSTR wstr, int length)
|
|
|
|
{
|
|
|
|
int len = min(CFStringGetLength(cstr), length - 1);
|
|
|
|
CFStringGetCharacters(cstr, CFRangeMake(0, len), (UniChar*)wstr);
|
|
|
|
wstr[len] = 0;
|
|
|
|
}
|
|
|
|
|
2016-11-07 20:42:23 +01:00
|
|
|
static DWORD CFNumberToDWORD(CFNumberRef num)
|
|
|
|
{
|
|
|
|
int dwNum = 0;
|
|
|
|
if (num)
|
|
|
|
CFNumberGetValue(num, kCFNumberIntType, &dwNum);
|
|
|
|
return dwNum;
|
|
|
|
}
|
|
|
|
|
2016-11-07 20:42:37 +01:00
|
|
|
static void handle_IOHIDDeviceIOHIDReportCallback(void *context,
|
|
|
|
IOReturn result, void *sender, IOHIDReportType type,
|
|
|
|
uint32_t reportID, uint8_t *report, CFIndex report_length)
|
|
|
|
{
|
2021-09-15 09:04:43 +02:00
|
|
|
struct unix_device *iface = (struct unix_device *)context;
|
|
|
|
bus_event_queue_input_report(&event_queue, iface, report, report_length);
|
2016-11-07 20:42:37 +01:00
|
|
|
}
|
|
|
|
|
2021-09-03 09:30:49 +02:00
|
|
|
static void iohid_device_destroy(struct unix_device *iface)
|
2021-04-15 06:22:04 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-09-15 09:04:46 +02:00
|
|
|
static NTSTATUS iohid_device_start(struct unix_device *iface)
|
2021-08-18 09:14:18 +02:00
|
|
|
{
|
2021-08-18 09:14:21 +02:00
|
|
|
DWORD length;
|
2021-09-22 10:30:41 +02:00
|
|
|
struct iohid_device *impl = impl_from_unix_device(iface);
|
2021-08-18 09:14:21 +02:00
|
|
|
CFNumberRef num;
|
|
|
|
|
2021-09-22 10:30:41 +02:00
|
|
|
num = IOHIDDeviceGetProperty(impl->device, CFSTR(kIOHIDMaxInputReportSizeKey));
|
2021-08-18 09:14:21 +02:00
|
|
|
length = CFNumberToDWORD(num);
|
2021-09-22 10:30:41 +02:00
|
|
|
impl->buffer = malloc(length);
|
2021-08-18 09:14:21 +02:00
|
|
|
|
2021-09-22 10:30:41 +02:00
|
|
|
IOHIDDeviceRegisterInputReportCallback(impl->device, impl->buffer, length, handle_IOHIDDeviceIOHIDReportCallback, iface);
|
2021-08-18 09:14:18 +02:00
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2021-09-14 08:58:21 +02:00
|
|
|
static void iohid_device_stop(struct unix_device *iface)
|
|
|
|
{
|
2021-09-22 10:30:41 +02:00
|
|
|
struct iohid_device *impl = impl_from_unix_device(iface);
|
2021-09-14 08:58:21 +02:00
|
|
|
|
2021-09-22 10:30:41 +02:00
|
|
|
IOHIDDeviceRegisterInputReportCallback(impl->device, NULL, 0, NULL, NULL);
|
2021-09-16 10:17:52 +02:00
|
|
|
|
2021-09-17 08:50:33 +02:00
|
|
|
pthread_mutex_lock(&iohid_cs);
|
2021-09-22 10:30:41 +02:00
|
|
|
list_remove(&impl->unix_device.entry);
|
2021-09-17 08:50:33 +02:00
|
|
|
pthread_mutex_unlock(&iohid_cs);
|
2021-09-14 08:58:21 +02:00
|
|
|
}
|
|
|
|
|
2021-09-03 09:30:49 +02:00
|
|
|
static NTSTATUS iohid_device_get_report_descriptor(struct unix_device *iface, BYTE *buffer,
|
2022-01-31 10:10:59 +01:00
|
|
|
UINT length, UINT *out_length)
|
2016-11-07 20:42:23 +01:00
|
|
|
{
|
2021-09-22 10:30:41 +02:00
|
|
|
struct iohid_device *impl = impl_from_unix_device(iface);
|
|
|
|
CFDataRef data = IOHIDDeviceGetProperty(impl->device, CFSTR(kIOHIDReportDescriptorKey));
|
2016-11-07 20:42:31 +01:00
|
|
|
int data_length = CFDataGetLength(data);
|
|
|
|
const UInt8 *ptr;
|
|
|
|
|
|
|
|
*out_length = data_length;
|
|
|
|
if (length < data_length)
|
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
|
|
|
|
|
|
|
ptr = CFDataGetBytePtr(data);
|
|
|
|
memcpy(buffer, ptr, data_length);
|
|
|
|
return STATUS_SUCCESS;
|
2016-11-07 20:42:23 +01:00
|
|
|
}
|
|
|
|
|
2021-09-03 09:30:49 +02:00
|
|
|
static void iohid_device_set_output_report(struct unix_device *iface, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io)
|
2016-11-07 20:42:23 +01:00
|
|
|
{
|
2016-11-07 20:42:41 +01:00
|
|
|
IOReturn result;
|
2021-09-22 10:30:41 +02:00
|
|
|
struct iohid_device *impl = impl_from_unix_device(iface);
|
|
|
|
result = IOHIDDeviceSetReport(impl->device, kIOHIDReportTypeOutput, packet->reportId,
|
2021-08-18 09:14:22 +02:00
|
|
|
packet->reportBuffer, packet->reportBufferLen);
|
2016-11-07 20:42:41 +01:00
|
|
|
if (result == kIOReturnSuccess)
|
|
|
|
{
|
2021-08-18 09:14:22 +02:00
|
|
|
io->Information = packet->reportBufferLen;
|
|
|
|
io->Status = STATUS_SUCCESS;
|
2016-11-07 20:42:41 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-08-18 09:14:22 +02:00
|
|
|
io->Information = 0;
|
|
|
|
io->Status = STATUS_UNSUCCESSFUL;
|
2016-11-07 20:42:41 +01:00
|
|
|
}
|
2016-11-07 20:42:23 +01:00
|
|
|
}
|
|
|
|
|
2021-09-03 09:30:49 +02:00
|
|
|
static void iohid_device_get_feature_report(struct unix_device *iface, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io)
|
2016-11-07 20:42:23 +01:00
|
|
|
{
|
2016-11-07 20:42:45 +01:00
|
|
|
IOReturn ret;
|
2021-08-18 09:14:22 +02:00
|
|
|
CFIndex report_length = packet->reportBufferLen;
|
2021-09-22 10:30:41 +02:00
|
|
|
struct iohid_device *impl = impl_from_unix_device(iface);
|
2016-11-07 20:42:45 +01:00
|
|
|
|
2021-09-22 10:30:41 +02:00
|
|
|
ret = IOHIDDeviceGetReport(impl->device, kIOHIDReportTypeFeature, packet->reportId,
|
2021-08-18 09:14:22 +02:00
|
|
|
packet->reportBuffer, &report_length);
|
2016-11-07 20:42:45 +01:00
|
|
|
if (ret == kIOReturnSuccess)
|
|
|
|
{
|
2021-08-18 09:14:22 +02:00
|
|
|
io->Information = report_length;
|
|
|
|
io->Status = STATUS_SUCCESS;
|
2016-11-07 20:42:45 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-08-18 09:14:22 +02:00
|
|
|
io->Information = 0;
|
|
|
|
io->Status = STATUS_UNSUCCESSFUL;
|
2016-11-07 20:42:45 +01:00
|
|
|
}
|
2016-11-07 20:42:23 +01:00
|
|
|
}
|
|
|
|
|
2021-09-03 09:30:49 +02:00
|
|
|
static void iohid_device_set_feature_report(struct unix_device *iface, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io)
|
2016-11-07 20:42:23 +01:00
|
|
|
{
|
2016-11-07 20:42:45 +01:00
|
|
|
IOReturn result;
|
2021-09-22 10:30:41 +02:00
|
|
|
struct iohid_device *impl = impl_from_unix_device(iface);
|
2016-11-07 20:42:45 +01:00
|
|
|
|
2021-09-22 10:30:41 +02:00
|
|
|
result = IOHIDDeviceSetReport(impl->device, kIOHIDReportTypeFeature, packet->reportId,
|
2021-08-18 09:14:22 +02:00
|
|
|
packet->reportBuffer, packet->reportBufferLen);
|
2016-11-07 20:42:45 +01:00
|
|
|
if (result == kIOReturnSuccess)
|
|
|
|
{
|
2021-08-18 09:14:22 +02:00
|
|
|
io->Information = packet->reportBufferLen;
|
|
|
|
io->Status = STATUS_SUCCESS;
|
2016-11-07 20:42:45 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-08-18 09:14:22 +02:00
|
|
|
io->Information = 0;
|
|
|
|
io->Status = STATUS_UNSUCCESSFUL;
|
2016-11-07 20:42:45 +01:00
|
|
|
}
|
2016-11-07 20:42:23 +01:00
|
|
|
}
|
|
|
|
|
2021-09-22 10:30:42 +02:00
|
|
|
static const struct raw_device_vtbl iohid_device_vtbl =
|
2016-11-07 20:42:23 +01:00
|
|
|
{
|
2021-09-03 09:30:49 +02:00
|
|
|
iohid_device_destroy,
|
|
|
|
iohid_device_start,
|
2021-09-14 08:58:21 +02:00
|
|
|
iohid_device_stop,
|
2021-09-03 09:30:49 +02:00
|
|
|
iohid_device_get_report_descriptor,
|
|
|
|
iohid_device_set_output_report,
|
|
|
|
iohid_device_get_feature_report,
|
|
|
|
iohid_device_set_feature_report,
|
2016-11-07 20:42:23 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static void handle_DeviceMatchingCallback(void *context, IOReturn result, void *sender, IOHIDDeviceRef IOHIDDevice)
|
|
|
|
{
|
2021-09-03 09:30:48 +02:00
|
|
|
struct device_desc desc =
|
|
|
|
{
|
|
|
|
.input = -1,
|
2021-10-05 10:55:50 +02:00
|
|
|
.serialnumber = {'0','0','0','0',0},
|
2021-09-03 09:30:48 +02:00
|
|
|
};
|
2021-09-22 10:30:41 +02:00
|
|
|
struct iohid_device *impl;
|
2021-10-05 10:55:50 +02:00
|
|
|
CFStringRef str;
|
2016-11-07 20:42:23 +01:00
|
|
|
|
2021-09-03 09:30:48 +02:00
|
|
|
desc.vid = CFNumberToDWORD(IOHIDDeviceGetProperty(IOHIDDevice, CFSTR(kIOHIDVendorIDKey)));
|
|
|
|
desc.pid = CFNumberToDWORD(IOHIDDeviceGetProperty(IOHIDDevice, CFSTR(kIOHIDProductIDKey)));
|
|
|
|
desc.version = CFNumberToDWORD(IOHIDDeviceGetProperty(IOHIDDevice, CFSTR(kIOHIDVersionNumberKey)));
|
|
|
|
desc.uid = CFNumberToDWORD(IOHIDDeviceGetProperty(IOHIDDevice, CFSTR(kIOHIDLocationIDKey)));
|
2016-11-07 20:42:23 +01:00
|
|
|
|
2020-11-24 01:48:44 +01:00
|
|
|
if (IOHIDDeviceOpen(IOHIDDevice, 0) != kIOReturnSuccess)
|
|
|
|
{
|
2021-09-03 09:30:48 +02:00
|
|
|
ERR("Failed to open HID device %p (vid %04x, pid %04x)\n", IOHIDDevice, desc.vid, desc.pid);
|
2020-11-24 01:48:44 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
IOHIDDeviceScheduleWithRunLoop(IOHIDDevice, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
|
|
|
|
|
2021-09-13 13:01:46 +02:00
|
|
|
str = IOHIDDeviceGetProperty(IOHIDDevice, CFSTR(kIOHIDManufacturerKey));
|
2021-10-05 10:55:50 +02:00
|
|
|
if (str) CFStringToWSTR(str, desc.manufacturer, ARRAY_SIZE(desc.manufacturer));
|
2021-09-13 13:01:47 +02:00
|
|
|
str = IOHIDDeviceGetProperty(IOHIDDevice, CFSTR(kIOHIDProductKey));
|
2021-10-05 10:55:50 +02:00
|
|
|
if (str) CFStringToWSTR(str, desc.product, ARRAY_SIZE(desc.product));
|
2021-09-13 13:01:48 +02:00
|
|
|
str = IOHIDDeviceGetProperty(IOHIDDevice, CFSTR(kIOHIDSerialNumberKey));
|
2021-10-05 10:55:50 +02:00
|
|
|
if (str) CFStringToWSTR(str, desc.serialnumber, ARRAY_SIZE(desc.serialnumber));
|
2021-09-13 13:01:46 +02:00
|
|
|
|
2018-02-14 19:24:27 +01:00
|
|
|
if (IOHIDDeviceConformsTo(IOHIDDevice, kHIDPage_GenericDesktop, kHIDUsage_GD_GamePad) ||
|
|
|
|
IOHIDDeviceConformsTo(IOHIDDevice, kHIDPage_GenericDesktop, kHIDUsage_GD_Joystick))
|
|
|
|
{
|
2021-09-03 09:30:48 +02:00
|
|
|
if (is_xbox_gamepad(desc.vid, desc.pid))
|
|
|
|
desc.is_gamepad = TRUE;
|
2018-02-14 19:24:27 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
int axes=0, buttons=0;
|
|
|
|
CFArrayRef element_array = IOHIDDeviceCopyMatchingElements(
|
|
|
|
IOHIDDevice, NULL, kIOHIDOptionsTypeNone);
|
|
|
|
|
|
|
|
if (element_array) {
|
|
|
|
CFIndex index;
|
|
|
|
CFIndex count = CFArrayGetCount(element_array);
|
|
|
|
for (index = 0; index < count; index++)
|
|
|
|
{
|
|
|
|
IOHIDElementRef element = (IOHIDElementRef)CFArrayGetValueAtIndex(element_array, index);
|
|
|
|
if (element)
|
|
|
|
{
|
|
|
|
int type = IOHIDElementGetType(element);
|
|
|
|
if (type == kIOHIDElementTypeInput_Button) buttons++;
|
|
|
|
if (type == kIOHIDElementTypeInput_Axis) axes++;
|
|
|
|
if (type == kIOHIDElementTypeInput_Misc)
|
|
|
|
{
|
|
|
|
uint32_t usage = IOHIDElementGetUsage(element);
|
|
|
|
switch (usage)
|
|
|
|
{
|
|
|
|
case kHIDUsage_GD_X:
|
|
|
|
case kHIDUsage_GD_Y:
|
|
|
|
case kHIDUsage_GD_Z:
|
|
|
|
case kHIDUsage_GD_Rx:
|
|
|
|
case kHIDUsage_GD_Ry:
|
|
|
|
case kHIDUsage_GD_Rz:
|
|
|
|
case kHIDUsage_GD_Slider:
|
|
|
|
axes ++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CFRelease(element_array);
|
|
|
|
}
|
2021-09-03 09:30:48 +02:00
|
|
|
desc.is_gamepad = (axes == 6 && buttons >= 14);
|
2018-02-14 19:24:27 +01:00
|
|
|
}
|
|
|
|
}
|
2016-11-07 20:42:23 +01:00
|
|
|
|
2021-09-03 09:30:48 +02:00
|
|
|
TRACE("dev %p, desc %s.\n", IOHIDDevice, debugstr_device_desc(&desc));
|
|
|
|
|
2021-09-22 10:30:42 +02:00
|
|
|
if (!(impl = raw_device_create(&iohid_device_vtbl, sizeof(struct iohid_device)))) return;
|
2021-09-22 10:30:41 +02:00
|
|
|
list_add_tail(&device_list, &impl->unix_device.entry);
|
|
|
|
impl->device = IOHIDDevice;
|
|
|
|
impl->buffer = NULL;
|
2021-08-23 10:49:41 +02:00
|
|
|
|
2021-09-22 10:30:41 +02:00
|
|
|
bus_event_queue_device_created(&event_queue, &impl->unix_device, &desc);
|
2016-11-07 20:42:23 +01:00
|
|
|
}
|
|
|
|
|
2016-11-07 20:42:27 +01:00
|
|
|
static void handle_RemovalCallback(void *context, IOReturn result, void *sender, IOHIDDeviceRef IOHIDDevice)
|
|
|
|
{
|
2021-09-22 10:30:41 +02:00
|
|
|
struct iohid_device *impl;
|
2021-09-16 10:17:52 +02:00
|
|
|
|
2016-11-07 20:42:27 +01:00
|
|
|
TRACE("OS/X IOHID Device Removed %p\n", IOHIDDevice);
|
2016-11-07 20:42:37 +01:00
|
|
|
IOHIDDeviceRegisterInputReportCallback(IOHIDDevice, NULL, 0, NULL, NULL);
|
|
|
|
/* Note: Yes, we leak the buffer. But according to research there is no
|
|
|
|
safe way to deallocate that buffer. */
|
2020-11-24 01:48:44 +01:00
|
|
|
IOHIDDeviceUnscheduleFromRunLoop(IOHIDDevice, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
|
|
|
|
IOHIDDeviceClose(IOHIDDevice, 0);
|
2021-09-16 10:17:52 +02:00
|
|
|
|
2021-09-22 10:30:41 +02:00
|
|
|
impl = find_device_from_iohid(IOHIDDevice);
|
|
|
|
if (impl) bus_event_queue_device_removed(&event_queue, &impl->unix_device);
|
2021-09-16 10:17:52 +02:00
|
|
|
else WARN("failed to find device for iohid device %p\n", IOHIDDevice);
|
2016-11-07 20:42:27 +01:00
|
|
|
}
|
|
|
|
|
2021-09-17 08:50:34 +02:00
|
|
|
NTSTATUS iohid_bus_init(void *args)
|
2016-11-07 20:42:23 +01:00
|
|
|
{
|
2021-08-23 10:49:40 +02:00
|
|
|
TRACE("args %p\n", args);
|
|
|
|
|
|
|
|
options = *(struct iohid_bus_options *)args;
|
|
|
|
|
2021-08-23 10:49:38 +02:00
|
|
|
if (!(hid_manager = IOHIDManagerCreate(kCFAllocatorDefault, 0L)))
|
|
|
|
{
|
|
|
|
ERR("IOHID manager creation failed\n");
|
|
|
|
return STATUS_UNSUCCESSFUL;
|
|
|
|
}
|
|
|
|
|
2018-09-12 18:22:09 +02:00
|
|
|
run_loop = CFRunLoopGetCurrent();
|
2016-11-07 20:42:23 +01:00
|
|
|
|
|
|
|
IOHIDManagerSetDeviceMatching(hid_manager, NULL);
|
|
|
|
IOHIDManagerRegisterDeviceMatchingCallback(hid_manager, handle_DeviceMatchingCallback, NULL);
|
2016-11-07 20:42:27 +01:00
|
|
|
IOHIDManagerRegisterDeviceRemovalCallback(hid_manager, handle_RemovalCallback, NULL);
|
2016-11-07 20:42:23 +01:00
|
|
|
IOHIDManagerScheduleWithRunLoop(hid_manager, run_loop, kCFRunLoopDefaultMode);
|
2021-08-23 10:49:38 +02:00
|
|
|
return STATUS_SUCCESS;
|
2016-11-07 20:42:23 +01:00
|
|
|
}
|
|
|
|
|
2021-09-17 08:50:34 +02:00
|
|
|
NTSTATUS iohid_bus_wait(void *args)
|
2016-11-07 20:42:23 +01:00
|
|
|
{
|
2021-08-30 11:22:54 +02:00
|
|
|
struct bus_event *result = args;
|
2021-09-16 10:17:52 +02:00
|
|
|
CFRunLoopRunResult ret;
|
2021-08-30 11:22:54 +02:00
|
|
|
|
2021-09-15 09:04:43 +02:00
|
|
|
/* cleanup previously returned event */
|
|
|
|
bus_event_cleanup(result);
|
|
|
|
|
2021-08-30 11:22:54 +02:00
|
|
|
do
|
|
|
|
{
|
|
|
|
if (bus_event_queue_pop(&event_queue, result)) return STATUS_PENDING;
|
2021-09-17 08:50:33 +02:00
|
|
|
pthread_mutex_lock(&iohid_cs);
|
2021-09-16 10:17:52 +02:00
|
|
|
ret = CFRunLoopRunInMode(kCFRunLoopDefaultMode, 10, TRUE);
|
2021-09-17 08:50:33 +02:00
|
|
|
pthread_mutex_unlock(&iohid_cs);
|
2021-09-16 10:17:52 +02:00
|
|
|
} while (ret != kCFRunLoopRunStopped);
|
2016-11-07 20:42:23 +01:00
|
|
|
|
2021-08-23 10:49:38 +02:00
|
|
|
TRACE("IOHID main loop exiting\n");
|
2021-08-30 11:22:54 +02:00
|
|
|
bus_event_queue_destroy(&event_queue);
|
2021-08-23 10:49:38 +02:00
|
|
|
IOHIDManagerRegisterDeviceMatchingCallback(hid_manager, NULL, NULL);
|
|
|
|
IOHIDManagerRegisterDeviceRemovalCallback(hid_manager, NULL, NULL);
|
|
|
|
CFRelease(hid_manager);
|
2016-11-07 20:42:23 +01:00
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2021-09-17 08:50:34 +02:00
|
|
|
NTSTATUS iohid_bus_stop(void *args)
|
2018-09-12 18:22:09 +02:00
|
|
|
{
|
2021-08-23 10:49:38 +02:00
|
|
|
if (!run_loop) return STATUS_SUCCESS;
|
2019-09-27 12:37:48 +02:00
|
|
|
|
2019-05-30 06:02:28 +02:00
|
|
|
IOHIDManagerUnscheduleFromRunLoop(hid_manager, run_loop, kCFRunLoopDefaultMode);
|
|
|
|
CFRunLoopStop(run_loop);
|
2021-08-23 10:49:38 +02:00
|
|
|
return STATUS_SUCCESS;
|
2018-09-12 18:22:09 +02:00
|
|
|
}
|
|
|
|
|
2016-11-07 20:42:23 +01:00
|
|
|
#else
|
|
|
|
|
2021-09-17 08:50:34 +02:00
|
|
|
NTSTATUS iohid_bus_init(void *args)
|
2021-08-23 10:49:38 +02:00
|
|
|
{
|
|
|
|
WARN("IOHID support not compiled in!\n");
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2021-09-17 08:50:34 +02:00
|
|
|
NTSTATUS iohid_bus_wait(void *args)
|
2016-11-07 20:42:23 +01:00
|
|
|
{
|
2021-08-23 10:49:38 +02:00
|
|
|
WARN("IOHID support not compiled in!\n");
|
2016-11-07 20:42:23 +01:00
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2021-09-17 08:50:34 +02:00
|
|
|
NTSTATUS iohid_bus_stop(void *args)
|
2018-09-12 18:22:09 +02:00
|
|
|
{
|
2021-08-23 10:49:38 +02:00
|
|
|
WARN("IOHID support not compiled in!\n");
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
2018-09-12 18:22:09 +02:00
|
|
|
}
|
|
|
|
|
2016-11-07 20:42:23 +01:00
|
|
|
#endif /* HAVE_IOHIDMANAGERCREATE */
|