Skip to content

Commit

Permalink
HID: glorious: fix Glorious Model I HID report
Browse files Browse the repository at this point in the history
The Glorious Model I mouse has a buggy HID report descriptor for its
keyboard endpoint (used for programmable buttons). For report ID 2, there
is a mismatch between Logical Minimum and Usage Minimum in the array that
reports keycodes.

The offending portion of the descriptor: (from hid-decode)

0x95, 0x05,                    //  Report Count (5)                   30
0x75, 0x08,                    //  Report Size (8)                    32
0x15, 0x00,                    //  Logical Minimum (0)                34
0x25, 0x65,                    //  Logical Maximum (101)              36
0x05, 0x07,                    //  Usage Page (Keyboard)              38
0x19, 0x01,                    //  Usage Minimum (1)                  40
0x29, 0x65,                    //  Usage Maximum (101)                42
0x81, 0x00,                    //  Input (Data,Arr,Abs)               44

This bug shifts all programmed keycodes up by 1. Importantly, this causes
"empty" array indexes of 0x00 to be interpreted as 0x01, ErrorRollOver.
The presence of ErrorRollOver causes the system to ignore all keypresses
from the endpoint and breaks the ability to use the programmable buttons.

Setting byte 41 to 0x00 fixes this, and causes keycodes to be interpreted
correctly.

Also, USB_VENDOR_ID_GLORIOUS is changed to USB_VENDOR_ID_SINOWEALTH,
and a new ID for Laview Technology is added. Glorious seems to be
white-labeling controller boards or mice from these vendors. There isn't a
single canonical vendor ID for Glorious products.

Signed-off-by: Brett Raye <[email protected]>
Signed-off-by: Jiri Kosina <[email protected]>
  • Loading branch information
braye authored and Jiri Kosina committed Nov 21, 2023
1 parent fc43e9c commit a5e913c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
16 changes: 14 additions & 2 deletions drivers/hid/hid-glorious.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ MODULE_DESCRIPTION("HID driver for Glorious PC Gaming Race mice");
* Glorious Model O and O- specify the const flag in the consumer input
* report descriptor, which leads to inputs being ignored. Fix this
* by patching the descriptor.
*
* Glorious Model I incorrectly specifes the Usage Minimum for its
* keyboard HID report, causing keycodes to be misinterpreted.
* Fix this by setting Usage Minimum to 0 in that report.
*/
static __u8 *glorious_report_fixup(struct hid_device *hdev, __u8 *rdesc,
unsigned int *rsize)
Expand All @@ -32,6 +36,10 @@ static __u8 *glorious_report_fixup(struct hid_device *hdev, __u8 *rdesc,
rdesc[85] = rdesc[113] = rdesc[141] = \
HID_MAIN_ITEM_VARIABLE | HID_MAIN_ITEM_RELATIVE;
}
if (*rsize == 156 && rdesc[41] == 1) {
hid_info(hdev, "patching Glorious Model I keyboard report descriptor\n");
rdesc[41] = 0;
}
return rdesc;
}

Expand All @@ -44,6 +52,8 @@ static void glorious_update_name(struct hid_device *hdev)
model = "Model O"; break;
case USB_DEVICE_ID_GLORIOUS_MODEL_D:
model = "Model D"; break;
case USB_DEVICE_ID_GLORIOUS_MODEL_I:
model = "Model I"; break;
}

snprintf(hdev->name, sizeof(hdev->name), "%s %s", "Glorious", model);
Expand All @@ -66,10 +76,12 @@ static int glorious_probe(struct hid_device *hdev,
}

static const struct hid_device_id glorious_devices[] = {
{ HID_USB_DEVICE(USB_VENDOR_ID_GLORIOUS,
{ HID_USB_DEVICE(USB_VENDOR_ID_SINOWEALTH,
USB_DEVICE_ID_GLORIOUS_MODEL_O) },
{ HID_USB_DEVICE(USB_VENDOR_ID_GLORIOUS,
{ HID_USB_DEVICE(USB_VENDOR_ID_SINOWEALTH,
USB_DEVICE_ID_GLORIOUS_MODEL_D) },
{ HID_USB_DEVICE(USB_VENDOR_ID_LAVIEW,
USB_DEVICE_ID_GLORIOUS_MODEL_I) },
{ }
};
MODULE_DEVICE_TABLE(hid, glorious_devices);
Expand Down
11 changes: 7 additions & 4 deletions drivers/hid/hid-ids.h
Original file line number Diff line number Diff line change
Expand Up @@ -511,10 +511,6 @@
#define USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_010A 0x010a
#define USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_E100 0xe100

#define USB_VENDOR_ID_GLORIOUS 0x258a
#define USB_DEVICE_ID_GLORIOUS_MODEL_D 0x0033
#define USB_DEVICE_ID_GLORIOUS_MODEL_O 0x0036

#define I2C_VENDOR_ID_GOODIX 0x27c6
#define I2C_DEVICE_ID_GOODIX_01F0 0x01f0

Expand Down Expand Up @@ -745,6 +741,9 @@
#define USB_VENDOR_ID_LABTEC 0x1020
#define USB_DEVICE_ID_LABTEC_WIRELESS_KEYBOARD 0x0006

#define USB_VENDOR_ID_LAVIEW 0x22D4
#define USB_DEVICE_ID_GLORIOUS_MODEL_I 0x1503

#define USB_VENDOR_ID_LCPOWER 0x1241
#define USB_DEVICE_ID_LCPOWER_LC1000 0xf767

Expand Down Expand Up @@ -1160,6 +1159,10 @@
#define USB_VENDOR_ID_SIGMATEL 0x066F
#define USB_DEVICE_ID_SIGMATEL_STMP3780 0x3780

#define USB_VENDOR_ID_SINOWEALTH 0x258a
#define USB_DEVICE_ID_GLORIOUS_MODEL_D 0x0033
#define USB_DEVICE_ID_GLORIOUS_MODEL_O 0x0036

#define USB_VENDOR_ID_SIS_TOUCH 0x0457
#define USB_DEVICE_ID_SIS9200_TOUCH 0x9200
#define USB_DEVICE_ID_SIS817_TOUCH 0x0817
Expand Down

0 comments on commit a5e913c

Please sign in to comment.