From: Soumyajyotii Ssarkar <[email protected]> The HID class descriptors of the mouse interfaces carry the length of the report descriptor as a hard-coded 52. Any change to the report descriptor then has to update both copies by hand, and Windows stops recognising the mouse if the advertised length does not match the descriptor exactly.
Move qemu_mouse_hid_report_descriptor above the interface descriptors and compute the length with sizeof(). No functional change. Suggested-by: Alex Bennée <[email protected]> Suggested-by: Helge Deller <[email protected]> Signed-off-by: Soumyajyotii Ssarkar <[email protected]> --- hw/usb/dev-hid.c | 74 +++++++++++++++++++++++++++--------------------- 1 file changed, 42 insertions(+), 32 deletions(-) diff --git a/hw/usb/dev-hid.c b/hw/usb/dev-hid.c index ae19d60203..2c10e88c85 100644 --- a/hw/usb/dev-hid.c +++ b/hw/usb/dev-hid.c @@ -76,6 +76,42 @@ static const USBDescStrings desc_strings = { [STR_SERIAL_KEYBOARD] = "68284", }; +/* + * The interface descriptors below advertise the length of this report + * descriptor. + * Note: Windows stops recognising the mouse if it does not match + * exactly. + */ +static const uint8_t qemu_mouse_hid_report_descriptor[] = { + 0x05, 0x01, /* Usage Page (Generic Desktop) */ + 0x09, 0x02, /* Usage (Mouse) */ + 0xa1, 0x01, /* Collection (Application) */ + 0x09, 0x01, /* Usage (Pointer) */ + 0xa1, 0x00, /* Collection (Physical) */ + 0x05, 0x09, /* Usage Page (Button) */ + 0x19, 0x01, /* Usage Minimum (1) */ + 0x29, 0x05, /* Usage Maximum (5) */ + 0x15, 0x00, /* Logical Minimum (0) */ + 0x25, 0x01, /* Logical Maximum (1) */ + 0x95, 0x05, /* Report Count (5) */ + 0x75, 0x01, /* Report Size (1) */ + 0x81, 0x02, /* Input (Data, Variable, Absolute) */ + 0x95, 0x01, /* Report Count (1) */ + 0x75, 0x03, /* Report Size (3) */ + 0x81, 0x01, /* Input (Constant) */ + 0x05, 0x01, /* Usage Page (Generic Desktop) */ + 0x09, 0x30, /* Usage (X) */ + 0x09, 0x31, /* Usage (Y) */ + 0x09, 0x38, /* Usage (Wheel) */ + 0x15, 0x81, /* Logical Minimum (-0x7f) */ + 0x25, 0x7f, /* Logical Maximum (0x7f) */ + 0x75, 0x08, /* Report Size (8) */ + 0x95, 0x03, /* Report Count (3) */ + 0x81, 0x06, /* Input (Data, Variable, Relative) */ + 0xc0, /* End Collection */ + 0xc0, /* End Collection */ +}; + static const USBDescIface desc_iface_mouse = { .bInterfaceNumber = 0, .bNumEndpoints = 1, @@ -93,7 +129,9 @@ static const USBDescIface desc_iface_mouse = { 0x00, /* u8 country_code */ 0x01, /* u8 num_descriptors */ USB_DT_REPORT, /* u8 type: Report */ - 52, 0, /* u16 len */ + /* u16 len */ + sizeof(qemu_mouse_hid_report_descriptor) & 0xff, + sizeof(qemu_mouse_hid_report_descriptor) >> 8, }, }, }, @@ -124,7 +162,9 @@ static const USBDescIface desc_iface_mouse2 = { 0x00, /* u8 country_code */ 0x01, /* u8 num_descriptors */ USB_DT_REPORT, /* u8 type: Report */ - 52, 0, /* u16 len */ + /* u16 len */ + sizeof(qemu_mouse_hid_report_descriptor) & 0xff, + sizeof(qemu_mouse_hid_report_descriptor) >> 8, }, }, }, @@ -453,36 +493,6 @@ static const USBDesc desc_keyboard2 = { .msos = &desc_msos_suspend, }; -static const uint8_t qemu_mouse_hid_report_descriptor[] = { - 0x05, 0x01, /* Usage Page (Generic Desktop) */ - 0x09, 0x02, /* Usage (Mouse) */ - 0xa1, 0x01, /* Collection (Application) */ - 0x09, 0x01, /* Usage (Pointer) */ - 0xa1, 0x00, /* Collection (Physical) */ - 0x05, 0x09, /* Usage Page (Button) */ - 0x19, 0x01, /* Usage Minimum (1) */ - 0x29, 0x05, /* Usage Maximum (5) */ - 0x15, 0x00, /* Logical Minimum (0) */ - 0x25, 0x01, /* Logical Maximum (1) */ - 0x95, 0x05, /* Report Count (5) */ - 0x75, 0x01, /* Report Size (1) */ - 0x81, 0x02, /* Input (Data, Variable, Absolute) */ - 0x95, 0x01, /* Report Count (1) */ - 0x75, 0x03, /* Report Size (3) */ - 0x81, 0x01, /* Input (Constant) */ - 0x05, 0x01, /* Usage Page (Generic Desktop) */ - 0x09, 0x30, /* Usage (X) */ - 0x09, 0x31, /* Usage (Y) */ - 0x09, 0x38, /* Usage (Wheel) */ - 0x15, 0x81, /* Logical Minimum (-0x7f) */ - 0x25, 0x7f, /* Logical Maximum (0x7f) */ - 0x75, 0x08, /* Report Size (8) */ - 0x95, 0x03, /* Report Count (3) */ - 0x81, 0x06, /* Input (Data, Variable, Relative) */ - 0xc0, /* End Collection */ - 0xc0, /* End Collection */ -}; - static const uint8_t qemu_tablet_hid_report_descriptor[] = { 0x05, 0x01, /* Usage Page (Generic Desktop) */ 0x09, 0x02, /* Usage (Mouse) */ -- 2.56.0
