2021-08-12 10:26:56 +02:00
|
|
|
/*
|
|
|
|
* Common HID report descriptor helpers
|
|
|
|
*
|
|
|
|
* 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-12 10:26:58 +02:00
|
|
|
#include <stdarg.h>
|
2021-09-17 08:50:32 +02:00
|
|
|
#include <stdlib.h>
|
2021-08-12 10:26:58 +02:00
|
|
|
|
|
|
|
#include "ntstatus.h"
|
|
|
|
#define WIN32_NO_STATUS
|
|
|
|
#include "winternl.h"
|
|
|
|
#include "winioctl.h"
|
|
|
|
#include "hidusage.h"
|
|
|
|
#include "ddk/wdm.h"
|
2021-09-23 08:55:28 +02:00
|
|
|
#include "ddk/hidsdi.h"
|
2021-08-12 10:26:58 +02:00
|
|
|
|
2021-09-22 10:30:43 +02:00
|
|
|
#include "wine/debug.h"
|
|
|
|
|
2021-08-30 11:22:55 +02:00
|
|
|
#include "unix_private.h"
|
2021-08-12 10:26:56 +02:00
|
|
|
|
2021-09-22 10:30:43 +02:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(plugplay);
|
|
|
|
|
2021-09-22 10:30:42 +02:00
|
|
|
static BOOL hid_report_descriptor_append(struct hid_report_descriptor *desc, const BYTE *buffer, SIZE_T size)
|
2021-08-12 10:26:56 +02:00
|
|
|
{
|
|
|
|
BYTE *tmp = desc->data;
|
|
|
|
|
|
|
|
if (desc->size + size > desc->max_size)
|
|
|
|
{
|
|
|
|
desc->max_size = max(desc->max_size * 3 / 2, desc->size + size);
|
2021-09-17 08:50:32 +02:00
|
|
|
desc->data = realloc(tmp, desc->max_size);
|
2021-08-12 10:26:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!desc->data)
|
|
|
|
{
|
2021-09-17 08:50:32 +02:00
|
|
|
free(tmp);
|
2021-08-12 10:26:56 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(desc->data + desc->size, buffer, size);
|
|
|
|
desc->size += size;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "psh_hid_macros.h"
|
|
|
|
|
2021-09-22 10:30:42 +02:00
|
|
|
static BOOL hid_report_descriptor_append_usage(struct hid_report_descriptor *desc, USAGE usage)
|
2021-08-12 10:26:57 +02:00
|
|
|
{
|
|
|
|
const BYTE template[] =
|
|
|
|
{
|
|
|
|
USAGE(2, usage),
|
|
|
|
};
|
|
|
|
|
2021-09-22 10:30:42 +02:00
|
|
|
return hid_report_descriptor_append(desc, template, sizeof(template));
|
2021-08-12 10:26:57 +02:00
|
|
|
}
|
|
|
|
|
2021-09-22 10:30:42 +02:00
|
|
|
BOOL hid_device_begin_report_descriptor(struct unix_device *iface, USAGE usage_page, USAGE usage)
|
2021-08-12 10:26:56 +02:00
|
|
|
{
|
2021-09-22 10:30:42 +02:00
|
|
|
struct hid_report_descriptor *desc = &iface->hid_report_descriptor;
|
2021-08-12 10:26:56 +02:00
|
|
|
const BYTE template[] =
|
|
|
|
{
|
|
|
|
USAGE_PAGE(2, usage_page),
|
|
|
|
USAGE(2, usage),
|
|
|
|
COLLECTION(1, Application),
|
|
|
|
USAGE(1, 0),
|
|
|
|
};
|
|
|
|
|
|
|
|
memset(desc, 0, sizeof(*desc));
|
2021-09-22 10:30:42 +02:00
|
|
|
return hid_report_descriptor_append(desc, template, sizeof(template));
|
2021-08-12 10:26:56 +02:00
|
|
|
}
|
|
|
|
|
2021-09-22 10:30:42 +02:00
|
|
|
BOOL hid_device_end_report_descriptor(struct unix_device *iface)
|
2021-09-23 08:55:28 +02:00
|
|
|
{
|
|
|
|
struct hid_report_descriptor *desc = &iface->hid_report_descriptor;
|
|
|
|
static const BYTE template[] =
|
|
|
|
{
|
|
|
|
END_COLLECTION,
|
|
|
|
};
|
|
|
|
|
|
|
|
return hid_report_descriptor_append(desc, template, sizeof(template));
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL hid_device_begin_input_report(struct unix_device *iface)
|
|
|
|
{
|
|
|
|
struct hid_report_descriptor *desc = &iface->hid_report_descriptor;
|
|
|
|
struct hid_device_state *state = &iface->hid_device_state;
|
|
|
|
const BYTE report_id = ++desc->next_report_id[HidP_Input];
|
|
|
|
const BYTE template[] =
|
|
|
|
{
|
|
|
|
COLLECTION(1, Report),
|
|
|
|
REPORT_ID(1, report_id),
|
|
|
|
};
|
|
|
|
|
|
|
|
if (state->report_len)
|
|
|
|
{
|
|
|
|
ERR("input report already created\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
state->id = report_id;
|
|
|
|
state->bit_size += 8;
|
|
|
|
return hid_report_descriptor_append(desc, template, sizeof(template));
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL hid_device_end_input_report(struct unix_device *iface)
|
2021-08-12 10:26:56 +02:00
|
|
|
{
|
2021-09-22 10:30:42 +02:00
|
|
|
struct hid_report_descriptor *desc = &iface->hid_report_descriptor;
|
2021-09-23 08:55:26 +02:00
|
|
|
struct hid_device_state *state = &iface->hid_device_state;
|
2021-08-12 10:26:56 +02:00
|
|
|
static const BYTE template[] =
|
|
|
|
{
|
|
|
|
END_COLLECTION,
|
|
|
|
};
|
|
|
|
|
2021-09-23 08:55:26 +02:00
|
|
|
state->report_len = (state->bit_size + 7) / 8;
|
|
|
|
if (!(state->report_buf = calloc(1, state->report_len))) return FALSE;
|
|
|
|
if (!(state->last_report_buf = calloc(1, state->report_len))) return FALSE;
|
2021-09-23 08:55:28 +02:00
|
|
|
|
|
|
|
state->report_buf[0] = state->id;
|
|
|
|
state->last_report_buf[0] = state->id;
|
2021-09-22 10:30:42 +02:00
|
|
|
return hid_report_descriptor_append(desc, template, sizeof(template));
|
2021-08-12 10:26:56 +02:00
|
|
|
}
|
|
|
|
|
2021-09-22 10:30:43 +02:00
|
|
|
static BOOL hid_device_add_button_count(struct unix_device *iface, BYTE count)
|
|
|
|
{
|
|
|
|
USHORT offset = iface->hid_device_state.bit_size / 8;
|
|
|
|
|
|
|
|
if ((iface->hid_device_state.bit_size % 8) && !iface->hid_device_state.button_count)
|
|
|
|
ERR("buttons should start byte aligned, missing padding!\n");
|
|
|
|
else if (iface->hid_device_state.bit_size + count > 0x80000)
|
|
|
|
ERR("report size overflow, too many elements!\n");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!iface->hid_device_state.button_count) iface->hid_device_state.button_start = offset;
|
|
|
|
iface->hid_device_state.button_count += count;
|
|
|
|
iface->hid_device_state.bit_size += count;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2021-09-22 10:30:42 +02:00
|
|
|
BOOL hid_device_add_buttons(struct unix_device *iface, USAGE usage_page, USAGE usage_min, USAGE usage_max)
|
2021-08-12 10:26:56 +02:00
|
|
|
{
|
2021-09-22 10:30:42 +02:00
|
|
|
struct hid_report_descriptor *desc = &iface->hid_report_descriptor;
|
2021-09-21 08:36:42 +02:00
|
|
|
const USHORT count = usage_max - usage_min + 1;
|
2021-08-12 10:26:56 +02:00
|
|
|
const BYTE template[] =
|
|
|
|
{
|
|
|
|
USAGE_PAGE(2, usage_page),
|
|
|
|
USAGE_MINIMUM(2, usage_min),
|
|
|
|
USAGE_MAXIMUM(2, usage_max),
|
|
|
|
LOGICAL_MINIMUM(1, 0),
|
|
|
|
LOGICAL_MAXIMUM(1, 1),
|
|
|
|
PHYSICAL_MINIMUM(1, 0),
|
|
|
|
PHYSICAL_MAXIMUM(1, 1),
|
2021-09-21 08:36:42 +02:00
|
|
|
REPORT_COUNT(2, count),
|
2021-08-12 10:26:56 +02:00
|
|
|
REPORT_SIZE(1, 1),
|
|
|
|
INPUT(1, Data|Var|Abs),
|
|
|
|
};
|
2021-09-21 08:36:42 +02:00
|
|
|
const BYTE template_pad[] =
|
2021-08-12 10:26:57 +02:00
|
|
|
{
|
2021-09-21 08:36:42 +02:00
|
|
|
REPORT_COUNT(1, 8 - (count % 8)),
|
2021-08-12 10:26:57 +02:00
|
|
|
REPORT_SIZE(1, 1),
|
|
|
|
INPUT(1, Cnst|Var|Abs),
|
|
|
|
};
|
|
|
|
|
2021-09-22 10:30:43 +02:00
|
|
|
if (!hid_device_add_button_count(iface, usage_max - usage_min + 1))
|
|
|
|
return FALSE;
|
|
|
|
|
2021-09-22 10:30:42 +02:00
|
|
|
if (!hid_report_descriptor_append(desc, template, sizeof(template)))
|
2021-09-21 08:36:42 +02:00
|
|
|
return FALSE;
|
|
|
|
|
2021-09-22 10:30:42 +02:00
|
|
|
if ((count % 8) && !hid_report_descriptor_append(desc, template_pad, sizeof(template_pad)))
|
2021-09-21 08:36:42 +02:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
2021-08-12 10:26:57 +02:00
|
|
|
}
|
|
|
|
|
2021-09-22 10:30:43 +02:00
|
|
|
static BOOL hid_device_add_hatswitch_count(struct unix_device *iface, BYTE count)
|
|
|
|
{
|
|
|
|
USHORT offset = iface->hid_device_state.bit_size / 8;
|
|
|
|
|
|
|
|
if (iface->hid_device_state.button_count)
|
|
|
|
ERR("hatswitches should be added before buttons!\n");
|
|
|
|
else if ((iface->hid_device_state.bit_size % 8))
|
|
|
|
ERR("hatswitches should be byte aligned, missing padding!\n");
|
|
|
|
else if (iface->hid_device_state.bit_size + 8 * count > 0x80000)
|
|
|
|
ERR("report size overflow, too many elements!\n");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!iface->hid_device_state.hatswitch_count) iface->hid_device_state.hatswitch_start = offset;
|
|
|
|
iface->hid_device_state.hatswitch_count += count;
|
|
|
|
iface->hid_device_state.bit_size += 8 * count;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2021-09-22 10:30:42 +02:00
|
|
|
BOOL hid_device_add_hatswitch(struct unix_device *iface, INT count)
|
2021-08-12 10:26:57 +02:00
|
|
|
{
|
2021-09-22 10:30:42 +02:00
|
|
|
struct hid_report_descriptor *desc = &iface->hid_report_descriptor;
|
2021-08-12 10:26:57 +02:00
|
|
|
const BYTE template[] =
|
|
|
|
{
|
|
|
|
USAGE_PAGE(1, HID_USAGE_PAGE_GENERIC),
|
|
|
|
USAGE(1, HID_USAGE_GENERIC_HATSWITCH),
|
|
|
|
LOGICAL_MINIMUM(1, 1),
|
|
|
|
LOGICAL_MAXIMUM(1, 8),
|
|
|
|
PHYSICAL_MINIMUM(1, 0),
|
|
|
|
PHYSICAL_MAXIMUM(2, 8),
|
2021-09-21 08:36:41 +02:00
|
|
|
REPORT_SIZE(1, 8),
|
2021-08-12 10:26:57 +02:00
|
|
|
REPORT_COUNT(4, count),
|
|
|
|
UNIT(1, 0x0e /* none */),
|
|
|
|
INPUT(1, Data|Var|Abs|Null),
|
|
|
|
};
|
|
|
|
|
2021-09-22 10:30:43 +02:00
|
|
|
if (!hid_device_add_hatswitch_count(iface, count))
|
|
|
|
return FALSE;
|
|
|
|
|
2021-09-22 10:30:42 +02:00
|
|
|
return hid_report_descriptor_append(desc, template, sizeof(template));
|
2021-08-12 10:26:57 +02:00
|
|
|
}
|
|
|
|
|
2021-09-22 10:30:43 +02:00
|
|
|
static BOOL hid_device_add_axis_count(struct unix_device *iface, BOOL rel, BYTE count)
|
|
|
|
{
|
|
|
|
USHORT offset = iface->hid_device_state.bit_size / 8;
|
|
|
|
|
|
|
|
if (!rel && iface->hid_device_state.rel_axis_count)
|
|
|
|
ERR("absolute axes should be added before relative axes!\n");
|
|
|
|
else if (iface->hid_device_state.button_count || iface->hid_device_state.hatswitch_count)
|
|
|
|
ERR("axes should be added before buttons or hatswitches!\n");
|
|
|
|
else if ((iface->hid_device_state.bit_size % 8))
|
|
|
|
ERR("axes should be byte aligned, missing padding!\n");
|
|
|
|
else if (iface->hid_device_state.bit_size + 32 * count > 0x80000)
|
|
|
|
ERR("report size overflow, too many elements!\n");
|
|
|
|
else if (rel)
|
|
|
|
{
|
|
|
|
if (!iface->hid_device_state.rel_axis_count) iface->hid_device_state.rel_axis_start = offset;
|
|
|
|
iface->hid_device_state.rel_axis_count += count;
|
|
|
|
iface->hid_device_state.bit_size += 32 * count;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!iface->hid_device_state.abs_axis_count) iface->hid_device_state.abs_axis_start = offset;
|
|
|
|
iface->hid_device_state.abs_axis_count += count;
|
|
|
|
iface->hid_device_state.bit_size += 32 * count;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2021-09-22 10:30:42 +02:00
|
|
|
BOOL hid_device_add_axes(struct unix_device *iface, BYTE count, USAGE usage_page,
|
|
|
|
const USAGE *usages, BOOL rel, LONG min, LONG max)
|
2021-08-12 10:26:57 +02:00
|
|
|
{
|
2021-09-22 10:30:42 +02:00
|
|
|
struct hid_report_descriptor *desc = &iface->hid_report_descriptor;
|
2021-08-12 10:26:57 +02:00
|
|
|
const BYTE template_begin[] =
|
|
|
|
{
|
|
|
|
USAGE_PAGE(1, usage_page),
|
|
|
|
COLLECTION(1, Physical),
|
|
|
|
};
|
|
|
|
const BYTE template_end[] =
|
|
|
|
{
|
|
|
|
END_COLLECTION,
|
|
|
|
};
|
2021-09-21 08:36:40 +02:00
|
|
|
const BYTE template[] =
|
2021-08-12 10:26:57 +02:00
|
|
|
{
|
|
|
|
LOGICAL_MINIMUM(4, min),
|
|
|
|
LOGICAL_MAXIMUM(4, max),
|
|
|
|
PHYSICAL_MINIMUM(4, min),
|
|
|
|
PHYSICAL_MAXIMUM(4, max),
|
2021-09-21 08:36:40 +02:00
|
|
|
REPORT_SIZE(1, 32),
|
2021-08-12 10:26:57 +02:00
|
|
|
REPORT_COUNT(1, count),
|
|
|
|
INPUT(1, Data|Var|(rel ? Rel : Abs)),
|
|
|
|
};
|
|
|
|
int i;
|
|
|
|
|
2021-09-22 10:30:43 +02:00
|
|
|
if (!hid_device_add_axis_count(iface, rel, count))
|
|
|
|
return FALSE;
|
|
|
|
|
2021-09-22 10:30:42 +02:00
|
|
|
if (!hid_report_descriptor_append(desc, template_begin, sizeof(template_begin)))
|
2021-08-12 10:26:57 +02:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
2021-09-22 10:30:42 +02:00
|
|
|
if (!hid_report_descriptor_append_usage(desc, usages[i]))
|
2021-08-12 10:26:57 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2021-09-22 10:30:42 +02:00
|
|
|
if (!hid_report_descriptor_append(desc, template, sizeof(template)))
|
2021-09-21 08:36:40 +02:00
|
|
|
return FALSE;
|
2021-08-12 10:26:57 +02:00
|
|
|
|
2021-09-22 10:30:42 +02:00
|
|
|
if (!hid_report_descriptor_append(desc, template_end, sizeof(template_end)))
|
2021-08-12 10:26:57 +02:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2021-09-23 08:55:30 +02:00
|
|
|
BOOL hid_device_add_haptics(struct unix_device *iface)
|
2021-08-12 10:26:58 +02:00
|
|
|
{
|
2021-09-22 10:30:42 +02:00
|
|
|
struct hid_report_descriptor *desc = &iface->hid_report_descriptor;
|
2021-09-23 08:55:28 +02:00
|
|
|
const BYTE report_id = ++desc->next_report_id[HidP_Output];
|
|
|
|
const BYTE template[] =
|
2021-08-12 10:26:58 +02:00
|
|
|
{
|
|
|
|
USAGE_PAGE(2, HID_USAGE_PAGE_VENDOR_DEFINED_BEGIN),
|
2021-09-23 08:55:28 +02:00
|
|
|
COLLECTION(1, Report),
|
|
|
|
REPORT_ID(1, report_id),
|
|
|
|
/* padding */
|
|
|
|
REPORT_COUNT(1, 0x02),
|
|
|
|
REPORT_SIZE(1, 0x08),
|
|
|
|
OUTPUT(1, Data|Var|Abs),
|
|
|
|
/* actuators */
|
|
|
|
USAGE(1, 0x01),
|
|
|
|
LOGICAL_MINIMUM(1, 0x00),
|
|
|
|
LOGICAL_MAXIMUM(1, 0xff),
|
|
|
|
PHYSICAL_MINIMUM(1, 0x00),
|
|
|
|
PHYSICAL_MAXIMUM(1, 0xff),
|
|
|
|
REPORT_SIZE(1, 0x08),
|
|
|
|
REPORT_COUNT(1, 0x02),
|
|
|
|
OUTPUT(1, Data|Var|Abs),
|
|
|
|
/* padding */
|
|
|
|
REPORT_COUNT(1, 0x02),
|
|
|
|
REPORT_SIZE(1, 0x08),
|
|
|
|
OUTPUT(1, Data|Var|Abs),
|
|
|
|
END_COLLECTION,
|
2021-08-12 10:26:58 +02:00
|
|
|
};
|
|
|
|
|
2021-09-23 08:55:30 +02:00
|
|
|
iface->hid_haptics.vendor_report = report_id;
|
2021-09-22 10:30:42 +02:00
|
|
|
return hid_report_descriptor_append(desc, template, sizeof(template));
|
2021-08-12 10:26:58 +02:00
|
|
|
}
|
|
|
|
|
2021-08-12 10:26:56 +02:00
|
|
|
#include "pop_hid_macros.h"
|
2021-09-22 10:30:42 +02:00
|
|
|
|
|
|
|
static void hid_device_destroy(struct unix_device *iface)
|
|
|
|
{
|
|
|
|
iface->hid_vtbl->destroy(iface);
|
|
|
|
free(iface->hid_report_descriptor.data);
|
2021-09-23 08:55:26 +02:00
|
|
|
free(iface->hid_device_state.report_buf);
|
|
|
|
free(iface->hid_device_state.last_report_buf);
|
2021-09-22 10:30:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static NTSTATUS hid_device_start(struct unix_device *iface)
|
|
|
|
{
|
|
|
|
return iface->hid_vtbl->start(iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void hid_device_stop(struct unix_device *iface)
|
|
|
|
{
|
|
|
|
iface->hid_vtbl->stop(iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS hid_device_get_report_descriptor(struct unix_device *iface, BYTE *buffer, DWORD length, DWORD *out_length)
|
|
|
|
{
|
|
|
|
*out_length = iface->hid_report_descriptor.size;
|
|
|
|
if (length < iface->hid_report_descriptor.size) return STATUS_BUFFER_TOO_SMALL;
|
|
|
|
|
|
|
|
memcpy(buffer, iface->hid_report_descriptor.data, iface->hid_report_descriptor.size);
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void hid_device_set_output_report(struct unix_device *iface, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io)
|
|
|
|
{
|
2021-09-23 08:55:30 +02:00
|
|
|
struct hid_haptics *haptics = &iface->hid_haptics;
|
|
|
|
if (packet->reportId == haptics->vendor_report)
|
|
|
|
{
|
|
|
|
WORD left = packet->reportBuffer[2] * 128;
|
|
|
|
WORD right = packet->reportBuffer[3] * 128;
|
|
|
|
|
|
|
|
io->Information = packet->reportBufferLen;
|
|
|
|
io->Status = iface->hid_vtbl->haptics_start(iface, -1, left, right);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
io->Information = 0;
|
|
|
|
io->Status = STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
2021-09-22 10:30:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void hid_device_get_feature_report(struct unix_device *iface, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io)
|
|
|
|
{
|
2021-09-23 08:55:30 +02:00
|
|
|
io->Information = 0;
|
|
|
|
io->Status = STATUS_NOT_IMPLEMENTED;
|
2021-09-22 10:30:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void hid_device_set_feature_report(struct unix_device *iface, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io)
|
|
|
|
{
|
2021-09-23 08:55:30 +02:00
|
|
|
io->Information = 0;
|
|
|
|
io->Status = STATUS_NOT_IMPLEMENTED;
|
2021-09-22 10:30:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct raw_device_vtbl raw_device_vtbl =
|
|
|
|
{
|
|
|
|
hid_device_destroy,
|
|
|
|
hid_device_start,
|
|
|
|
hid_device_stop,
|
|
|
|
hid_device_get_report_descriptor,
|
|
|
|
hid_device_set_output_report,
|
|
|
|
hid_device_get_feature_report,
|
|
|
|
hid_device_set_feature_report,
|
|
|
|
};
|
|
|
|
|
|
|
|
void *hid_device_create(const struct hid_device_vtbl *vtbl, SIZE_T size)
|
|
|
|
{
|
|
|
|
struct unix_device *impl;
|
|
|
|
|
|
|
|
if (!(impl = raw_device_create(&raw_device_vtbl, size))) return NULL;
|
|
|
|
impl->hid_vtbl = vtbl;
|
|
|
|
|
|
|
|
return impl;
|
|
|
|
}
|
2021-09-23 08:55:26 +02:00
|
|
|
|
2021-09-23 08:55:27 +02:00
|
|
|
#ifdef WORDS_BIGENDIAN
|
|
|
|
# define LE_ULONG(x) RtlUlongByteSwap((ULONG)(x))
|
|
|
|
#else
|
|
|
|
# define LE_ULONG(x) ((ULONG)(x))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
BOOL hid_device_set_abs_axis(struct unix_device *iface, ULONG index, LONG value)
|
|
|
|
{
|
|
|
|
struct hid_device_state *state = &iface->hid_device_state;
|
|
|
|
ULONG offset = state->abs_axis_start + index * 4;
|
|
|
|
if (index > state->abs_axis_count) return FALSE;
|
|
|
|
*(ULONG *)(state->report_buf + offset) = LE_ULONG(value);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL hid_device_set_rel_axis(struct unix_device *iface, ULONG index, LONG value)
|
|
|
|
{
|
|
|
|
struct hid_device_state *state = &iface->hid_device_state;
|
|
|
|
ULONG offset = state->rel_axis_start + index * 4;
|
|
|
|
if (index > state->rel_axis_count) return FALSE;
|
|
|
|
*(ULONG *)(state->report_buf + offset) = LE_ULONG(value);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL hid_device_set_button(struct unix_device *iface, ULONG index, BOOL is_set)
|
|
|
|
{
|
|
|
|
struct hid_device_state *state = &iface->hid_device_state;
|
|
|
|
ULONG offset = state->button_start + (index / 8);
|
|
|
|
BYTE mask = (1 << (index % 8));
|
|
|
|
if (index > state->button_count) return FALSE;
|
|
|
|
if (is_set) state->report_buf[offset] |= mask;
|
|
|
|
else state->report_buf[offset] &= ~mask;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* hatswitch x / y vs value:
|
|
|
|
* -1 x +1
|
|
|
|
* +-------->
|
|
|
|
* -1 | 8 1 2
|
|
|
|
* y | 7 0 3
|
|
|
|
* +1 | 6 5 4
|
|
|
|
* v
|
|
|
|
*/
|
|
|
|
static void hatswitch_decompose(BYTE value, LONG *x, LONG *y)
|
|
|
|
{
|
|
|
|
*x = *y = 0;
|
|
|
|
if (value == 8 || value == 1 || value == 2) *y = -1;
|
|
|
|
if (value == 6 || value == 5 || value == 4) *y = +1;
|
|
|
|
if (value == 8 || value == 7 || value == 6) *x = -1;
|
|
|
|
if (value == 2 || value == 3 || value == 4) *x = +1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void hatswitch_compose(LONG x, LONG y, BYTE *value)
|
|
|
|
{
|
|
|
|
if (x == 0 && y == 0) *value = 0;
|
|
|
|
else if (x == 0 && y < 0) *value = 1;
|
|
|
|
else if (x > 0 && y < 0) *value = 2;
|
|
|
|
else if (x > 0 && y == 0) *value = 3;
|
|
|
|
else if (x > 0 && y > 0) *value = 4;
|
|
|
|
else if (x == 0 && y > 0) *value = 5;
|
|
|
|
else if (x < 0 && y > 0) *value = 6;
|
|
|
|
else if (x < 0 && y == 0) *value = 7;
|
|
|
|
else if (x < 0 && y < 0) *value = 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL hid_device_set_hatswitch_x(struct unix_device *iface, ULONG index, LONG new_x)
|
|
|
|
{
|
|
|
|
struct hid_device_state *state = &iface->hid_device_state;
|
|
|
|
ULONG offset = state->hatswitch_start + index;
|
|
|
|
LONG x, y;
|
|
|
|
if (index > state->hatswitch_count) return FALSE;
|
|
|
|
hatswitch_decompose(state->report_buf[offset], &x, &y);
|
|
|
|
hatswitch_compose(new_x, y, &state->report_buf[offset]);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL hid_device_set_hatswitch_y(struct unix_device *iface, ULONG index, LONG new_y)
|
|
|
|
{
|
|
|
|
struct hid_device_state *state = &iface->hid_device_state;
|
|
|
|
ULONG offset = state->hatswitch_start + index;
|
|
|
|
LONG x, y;
|
|
|
|
if (index > state->hatswitch_count) return FALSE;
|
|
|
|
hatswitch_decompose(state->report_buf[offset], &x, &y);
|
|
|
|
hatswitch_compose(x, new_y, &state->report_buf[offset]);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2021-09-23 08:55:26 +02:00
|
|
|
BOOL hid_device_sync_report(struct unix_device *iface)
|
|
|
|
{
|
|
|
|
BOOL dropped;
|
|
|
|
|
|
|
|
if (!(dropped = iface->hid_device_state.dropped))
|
|
|
|
memcpy(iface->hid_device_state.last_report_buf, iface->hid_device_state.report_buf,
|
|
|
|
iface->hid_device_state.report_len);
|
|
|
|
else
|
|
|
|
memcpy(iface->hid_device_state.report_buf, iface->hid_device_state.last_report_buf,
|
|
|
|
iface->hid_device_state.report_len);
|
|
|
|
iface->hid_device_state.dropped = FALSE;
|
|
|
|
|
|
|
|
return !dropped;
|
|
|
|
}
|
|
|
|
|
|
|
|
void hid_device_drop_report(struct unix_device *iface)
|
|
|
|
{
|
|
|
|
iface->hid_device_state.dropped = TRUE;
|
|
|
|
}
|