winebus.sys: Enforce all axis values to be 32bit.

Signed-off-by: Rémi Bernon <rbernon@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Rémi Bernon 2021-09-21 08:36:40 +02:00 committed by Alexandre Julliard
parent 059764e87e
commit d7c4867257
4 changed files with 30 additions and 70 deletions

View File

@ -51,9 +51,9 @@
#include "hidusage.h"
#ifdef WORDS_BIGENDIAN
# define LE_WORD(x) RtlUshortByteSwap(x)
# define LE_DWORD(x) RtlUlongByteSwap(x)
#else
# define LE_WORD(x) (x)
# define LE_DWORD(x) (x)
#endif
#include "unix_private.h"
@ -175,24 +175,20 @@ static void set_button_value(struct platform_private *ext, int index, int value)
static void set_axis_value(struct platform_private *ext, int index, short value, BOOL controller)
{
WORD *report = (WORD *)(ext->report_buffer + ext->axis_start);
DWORD *report = (DWORD *)(ext->report_buffer + ext->axis_start);
if (controller && (index == SDL_CONTROLLER_AXIS_TRIGGERLEFT || index == SDL_CONTROLLER_AXIS_TRIGGERRIGHT))
report[index] = LE_WORD(value);
report[index] = LE_DWORD(value);
else
report[index] = LE_WORD(value) + 32768;
report[index] = LE_DWORD(value) + 32768;
}
static void set_ball_value(struct platform_private *ext, int index, int value1, int value2)
{
int offset;
offset = ext->ball_start + (index * sizeof(WORD));
if (value1 > 127) value1 = 127;
if (value1 < -127) value1 = -127;
if (value2 > 127) value2 = 127;
if (value2 < -127) value2 = -127;
*((WORD*)&ext->report_buffer[offset]) = LE_WORD(value1);
*((WORD*)&ext->report_buffer[offset + sizeof(WORD)]) = LE_WORD(value2);
offset = ext->ball_start + (index * sizeof(DWORD));
*(DWORD *)&ext->report_buffer[offset] = LE_DWORD(value1);
*(DWORD *)&ext->report_buffer[offset + sizeof(DWORD)] = LE_DWORD(value2);
}
static void set_hat_value(struct platform_private *ext, int index, int value)
@ -308,7 +304,7 @@ static NTSTATUS build_report_descriptor(struct platform_private *ext)
ext->axis_start = report_size;
if (axis_count)
{
report_size += (sizeof(WORD) * axis_count);
report_size += (sizeof(DWORD) * axis_count);
}
ball_count = pSDL_JoystickNumBalls(ext->sdl_joystick);
@ -320,7 +316,7 @@ static NTSTATUS build_report_descriptor(struct platform_private *ext)
FIXME("Capping ball + axis at 9\n");
ball_count = (9-axis_count)/2;
}
report_size += (sizeof(WORD) * 2 * ball_count);
report_size += (sizeof(DWORD) * 2 * ball_count);
}
/* For now lump all buttons just into incremental usages, Ignore Keys */
@ -340,18 +336,18 @@ static NTSTATUS build_report_descriptor(struct platform_private *ext)
if (axis_count == 6 && button_count >= 14)
{
if (!hid_descriptor_add_axes(&ext->desc, axis_count, HID_USAGE_PAGE_GENERIC,
controller_usages, FALSE, 16, 0, 0xffff))
controller_usages, FALSE, 0, 0xffff))
return STATUS_NO_MEMORY;
}
else if (axis_count)
{
if (!hid_descriptor_add_axes(&ext->desc, axis_count, HID_USAGE_PAGE_GENERIC,
joystick_usages, FALSE, 16, 0, 0xffff))
joystick_usages, FALSE, 0, 0xffff))
return STATUS_NO_MEMORY;
}
if (ball_count && !hid_descriptor_add_axes(&ext->desc, ball_count * 2, HID_USAGE_PAGE_GENERIC,
&joystick_usages[axis_count], TRUE, 8, 0x81, 0x7f))
&joystick_usages[axis_count], TRUE, INT32_MIN, INT32_MAX))
return STATUS_NO_MEMORY;
if (button_count && !hid_descriptor_add_buttons(&ext->desc, HID_USAGE_PAGE_BUTTON, 1, button_count))
@ -420,11 +416,11 @@ static NTSTATUS build_mapped_report_descriptor(struct platform_private *ext)
static const int BUTTON_BIT_COUNT = CONTROLLER_NUM_BUTTONS + CONTROLLER_NUM_HATSWITCHES * 4;
ext->axis_start = 0;
ext->button_start = CONTROLLER_NUM_AXES * sizeof(WORD);
ext->button_start = CONTROLLER_NUM_AXES * sizeof(DWORD);
ext->hat_bit_offs = CONTROLLER_NUM_BUTTONS;
ext->buffer_length = (BUTTON_BIT_COUNT + 7) / 8
+ CONTROLLER_NUM_AXES * sizeof(WORD);
+ CONTROLLER_NUM_AXES * sizeof(DWORD);
TRACE("Report will be %i bytes\n", ext->buffer_length);
@ -432,15 +428,15 @@ static NTSTATUS build_mapped_report_descriptor(struct platform_private *ext)
return STATUS_NO_MEMORY;
if (!hid_descriptor_add_axes(&ext->desc, 2, HID_USAGE_PAGE_GENERIC, left_axis_usages,
FALSE, 16, 0, 0xffff))
FALSE, 0, 0xffff))
return STATUS_NO_MEMORY;
if (!hid_descriptor_add_axes(&ext->desc, 2, HID_USAGE_PAGE_GENERIC, right_axis_usages,
FALSE, 16, 0, 0xffff))
FALSE, 0, 0xffff))
return STATUS_NO_MEMORY;
if (!hid_descriptor_add_axes(&ext->desc, 2, HID_USAGE_PAGE_GENERIC, trigger_axis_usages,
FALSE, 16, 0, 0x7fff))
FALSE, 0, 0x7fff))
return STATUS_NO_MEMORY;
if (!hid_descriptor_add_buttons(&ext->desc, HID_USAGE_PAGE_BUTTON, 1, CONTROLLER_NUM_BUTTONS))

View File

@ -28,6 +28,7 @@
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
@ -78,10 +79,8 @@
#endif
#ifdef WORDS_BIGENDIAN
#define LE_WORD(x) RtlUshortByteSwap(x)
#define LE_DWORD(x) RtlUlongByteSwap(x)
#else
#define LE_WORD(x) (x)
#define LE_DWORD(x) (x)
#endif
@ -389,9 +388,7 @@ static void set_rel_axis_value(struct wine_input_private *ext, int code, int val
if (code < HID_REL_MAX && REL_TO_HID_MAP[code][0] != 0)
{
index = ext->rel_map[code];
if (value > 127) value = 127;
if (value < -127) value = -127;
ext->current_report_buffer[index] = value;
*(DWORD *)&ext->current_report_buffer[index] = LE_DWORD(value);
}
}
@ -474,7 +471,7 @@ static NTSTATUS build_report_descriptor(struct wine_input_private *ext, struct u
if (!(usage.UsagePage = ABS_TO_HID_MAP[i][0])) continue;
if (!(usage.Usage = ABS_TO_HID_MAP[i][1])) continue;
if (!hid_descriptor_add_axes(&ext->desc, 1, usage.UsagePage, &usage.Usage, FALSE, 32,
if (!hid_descriptor_add_axes(&ext->desc, 1, usage.UsagePage, &usage.Usage, FALSE,
LE_DWORD(abs_info[i].minimum), LE_DWORD(abs_info[i].maximum)))
return STATUS_NO_MEMORY;
@ -490,12 +487,12 @@ static NTSTATUS build_report_descriptor(struct wine_input_private *ext, struct u
if (!(usage.UsagePage = REL_TO_HID_MAP[i][0])) continue;
if (!(usage.Usage = REL_TO_HID_MAP[i][1])) continue;
if (!hid_descriptor_add_axes(&ext->desc, 1, usage.UsagePage, &usage.Usage, TRUE, 8,
0x81, 0x7f))
if (!hid_descriptor_add_axes(&ext->desc, 1, usage.UsagePage, &usage.Usage, TRUE,
INT32_MIN, INT32_MAX))
return STATUS_NO_MEMORY;
ext->rel_map[i] = report_size;
report_size++;
report_size += 4;
rel_count++;
}

View File

@ -148,7 +148,7 @@ BOOL hid_descriptor_add_hatswitch(struct hid_descriptor *desc, INT count)
}
BOOL hid_descriptor_add_axes(struct hid_descriptor *desc, BYTE count, USAGE usage_page,
const USAGE *usages, BOOL rel, INT size, LONG min, LONG max)
const USAGE *usages, BOOL rel, LONG min, LONG max)
{
const BYTE template_begin[] =
{
@ -159,33 +159,13 @@ BOOL hid_descriptor_add_axes(struct hid_descriptor *desc, BYTE count, USAGE usag
{
END_COLLECTION,
};
const BYTE template_1[] =
{
LOGICAL_MINIMUM(1, min),
LOGICAL_MAXIMUM(1, max),
PHYSICAL_MINIMUM(1, min),
PHYSICAL_MAXIMUM(1, max),
REPORT_SIZE(1, size),
REPORT_COUNT(1, count),
INPUT(1, Data|Var|(rel ? Rel : Abs)),
};
const BYTE template_2[] =
{
LOGICAL_MINIMUM(2, min),
LOGICAL_MAXIMUM(2, max),
PHYSICAL_MINIMUM(2, min),
PHYSICAL_MAXIMUM(2, max),
REPORT_SIZE(1, size),
REPORT_COUNT(1, count),
INPUT(1, Data|Var|(rel ? Rel : Abs)),
};
const BYTE template_4[] =
const BYTE template[] =
{
LOGICAL_MINIMUM(4, min),
LOGICAL_MAXIMUM(4, max),
PHYSICAL_MINIMUM(4, min),
PHYSICAL_MAXIMUM(4, max),
REPORT_SIZE(1, size),
REPORT_SIZE(1, 32),
REPORT_COUNT(1, count),
INPUT(1, Data|Var|(rel ? Rel : Abs)),
};
@ -200,21 +180,8 @@ BOOL hid_descriptor_add_axes(struct hid_descriptor *desc, BYTE count, USAGE usag
return FALSE;
}
if (size >= 16)
{
if (!hid_descriptor_append(desc, template_4, sizeof(template_4)))
return FALSE;
}
else if (size >= 8)
{
if (!hid_descriptor_append(desc, template_2, sizeof(template_2)))
return FALSE;
}
else
{
if (!hid_descriptor_append(desc, template_1, sizeof(template_1)))
return FALSE;
}
if (!hid_descriptor_append(desc, template, sizeof(template)))
return FALSE;
if (!hid_descriptor_append(desc, template_end, sizeof(template_end)))
return FALSE;

View File

@ -85,7 +85,7 @@ extern BOOL hid_descriptor_add_buttons(struct hid_descriptor *desc, USAGE usage_
extern BOOL hid_descriptor_add_padding(struct hid_descriptor *desc, BYTE bitcount) DECLSPEC_HIDDEN;
extern BOOL hid_descriptor_add_hatswitch(struct hid_descriptor *desc, INT count) DECLSPEC_HIDDEN;
extern BOOL hid_descriptor_add_axes(struct hid_descriptor *desc, BYTE count, USAGE usage_page,
const USAGE *usages, BOOL rel, INT size, LONG min, LONG max) DECLSPEC_HIDDEN;
const USAGE *usages, BOOL rel, LONG min, LONG max) DECLSPEC_HIDDEN;
extern BOOL hid_descriptor_add_haptics(struct hid_descriptor *desc) DECLSPEC_HIDDEN;