bellard | 59ae540 | 2005-11-05 16:57:08 +0000 | [diff] [blame] | 1 | /* |
| 2 | * QEMU USB HID devices |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 3 | * |
bellard | 59ae540 | 2005-11-05 16:57:08 +0000 | [diff] [blame] | 4 | * Copyright (c) 2005 Fabrice Bellard |
balrog | 47b2d33 | 2007-06-22 08:16:00 +0000 | [diff] [blame] | 5 | * Copyright (c) 2007 OpenMoko, Inc. (andrew@openedhand.com) |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 6 | * |
bellard | 59ae540 | 2005-11-05 16:57:08 +0000 | [diff] [blame] | 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 8 | * of this software and associated documentation files (the "Software"), to deal |
| 9 | * in the Software without restriction, including without limitation the rights |
| 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 11 | * copies of the Software, and to permit persons to whom the Software is |
| 12 | * furnished to do so, subject to the following conditions: |
| 13 | * |
| 14 | * The above copyright notice and this permission notice shall be included in |
| 15 | * all copies or substantial portions of the Software. |
| 16 | * |
| 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 20 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 23 | * THE SOFTWARE. |
| 24 | */ |
Markus Armbruster | 0b8fa32 | 2019-05-23 16:35:07 +0200 | [diff] [blame] | 25 | |
Peter Maydell | e532b2e | 2016-01-26 18:17:12 +0000 | [diff] [blame] | 26 | #include "qemu/osdep.h" |
Paolo Bonzini | 28ecbae | 2012-11-28 12:06:30 +0100 | [diff] [blame] | 27 | #include "ui/console.h" |
Gerd Hoffmann | f1ae32a | 2012-03-07 14:55:18 +0100 | [diff] [blame] | 28 | #include "hw/usb.h" |
Markus Armbruster | d645427 | 2019-08-12 07:23:45 +0200 | [diff] [blame] | 29 | #include "migration/vmstate.h" |
Michael S. Tsirkin | 463581a | 2018-05-03 22:50:48 +0300 | [diff] [blame] | 30 | #include "desc.h" |
Markus Armbruster | da34e65 | 2016-03-14 09:01:28 +0100 | [diff] [blame] | 31 | #include "qapi/error.h" |
Markus Armbruster | 0b8fa32 | 2019-05-23 16:35:07 +0200 | [diff] [blame] | 32 | #include "qemu/module.h" |
Paolo Bonzini | 1de7afc | 2012-12-17 18:20:00 +0100 | [diff] [blame] | 33 | #include "qemu/timer.h" |
Paolo Bonzini | 0d09e41 | 2013-02-05 17:06:20 +0100 | [diff] [blame] | 34 | #include "hw/input/hid.h" |
César Belley | 84b6c23 | 2020-08-12 11:41:23 +0200 | [diff] [blame] | 35 | #include "hw/usb/hid.h" |
Markus Armbruster | a27bd6c | 2019-08-12 07:23:51 +0200 | [diff] [blame] | 36 | #include "hw/qdev-properties.h" |
Eduardo Habkost | db1015e | 2020-09-03 16:43:22 -0400 | [diff] [blame] | 37 | #include "qom/object.h" |
bellard | 59ae540 | 2005-11-05 16:57:08 +0000 | [diff] [blame] | 38 | |
Eduardo Habkost | db1015e | 2020-09-03 16:43:22 -0400 | [diff] [blame] | 39 | struct USBHIDState { |
Gerd Hoffmann | 0d878ee | 2011-07-15 13:12:44 +0200 | [diff] [blame] | 40 | USBDevice dev; |
Gerd Hoffmann | 7567b51 | 2012-01-17 13:25:46 +0100 | [diff] [blame] | 41 | USBEndpoint *intr; |
Gerd Hoffmann | 0d878ee | 2011-07-15 13:12:44 +0200 | [diff] [blame] | 42 | HIDState hid; |
Hans de Goede | 427e3aa | 2012-11-17 12:47:18 +0100 | [diff] [blame] | 43 | uint32_t usb_version; |
Gerd Hoffmann | f85d283 | 2014-05-19 15:26:51 +0200 | [diff] [blame] | 44 | char *display; |
| 45 | uint32_t head; |
Eduardo Habkost | db1015e | 2020-09-03 16:43:22 -0400 | [diff] [blame] | 46 | }; |
balrog | 47b2d33 | 2007-06-22 08:16:00 +0000 | [diff] [blame] | 47 | |
Gonglei | f566912 | 2015-05-06 20:55:26 +0800 | [diff] [blame] | 48 | #define TYPE_USB_HID "usb-hid" |
Eduardo Habkost | 8063396 | 2020-09-16 14:25:19 -0400 | [diff] [blame] | 49 | OBJECT_DECLARE_SIMPLE_TYPE(USBHIDState, USB_HID) |
Gonglei | f566912 | 2015-05-06 20:55:26 +0800 | [diff] [blame] | 50 | |
Gerd Hoffmann | 0e4e969 | 2010-11-17 11:05:05 +0100 | [diff] [blame] | 51 | enum { |
| 52 | STR_MANUFACTURER = 1, |
| 53 | STR_PRODUCT_MOUSE, |
| 54 | STR_PRODUCT_TABLET, |
| 55 | STR_PRODUCT_KEYBOARD, |
Gerd Hoffmann | b63e105 | 2019-01-10 13:51:08 +0100 | [diff] [blame] | 56 | STR_SERIAL_COMPAT, |
Gerd Hoffmann | 0e4e969 | 2010-11-17 11:05:05 +0100 | [diff] [blame] | 57 | STR_CONFIG_MOUSE, |
| 58 | STR_CONFIG_TABLET, |
| 59 | STR_CONFIG_KEYBOARD, |
Gerd Hoffmann | b63e105 | 2019-01-10 13:51:08 +0100 | [diff] [blame] | 60 | STR_SERIAL_MOUSE, |
| 61 | STR_SERIAL_TABLET, |
| 62 | STR_SERIAL_KEYBOARD, |
bellard | 59ae540 | 2005-11-05 16:57:08 +0000 | [diff] [blame] | 63 | }; |
| 64 | |
Gerd Hoffmann | 0e4e969 | 2010-11-17 11:05:05 +0100 | [diff] [blame] | 65 | static const USBDescStrings desc_strings = { |
Crístian Viana | 93bfef4 | 2012-05-30 00:35:51 -0300 | [diff] [blame] | 66 | [STR_MANUFACTURER] = "QEMU", |
Gerd Hoffmann | 0e4e969 | 2010-11-17 11:05:05 +0100 | [diff] [blame] | 67 | [STR_PRODUCT_MOUSE] = "QEMU USB Mouse", |
| 68 | [STR_PRODUCT_TABLET] = "QEMU USB Tablet", |
| 69 | [STR_PRODUCT_KEYBOARD] = "QEMU USB Keyboard", |
Gerd Hoffmann | b63e105 | 2019-01-10 13:51:08 +0100 | [diff] [blame] | 70 | [STR_SERIAL_COMPAT] = "42", |
Gerd Hoffmann | 0e4e969 | 2010-11-17 11:05:05 +0100 | [diff] [blame] | 71 | [STR_CONFIG_MOUSE] = "HID Mouse", |
| 72 | [STR_CONFIG_TABLET] = "HID Tablet", |
| 73 | [STR_CONFIG_KEYBOARD] = "HID Keyboard", |
Gerd Hoffmann | b63e105 | 2019-01-10 13:51:08 +0100 | [diff] [blame] | 74 | [STR_SERIAL_MOUSE] = "89126", |
| 75 | [STR_SERIAL_TABLET] = "28754", |
| 76 | [STR_SERIAL_KEYBOARD] = "68284", |
bellard | 09b26c5 | 2006-04-12 21:09:08 +0000 | [diff] [blame] | 77 | }; |
| 78 | |
Gerd Hoffmann | 0e4e969 | 2010-11-17 11:05:05 +0100 | [diff] [blame] | 79 | static const USBDescIface desc_iface_mouse = { |
| 80 | .bInterfaceNumber = 0, |
| 81 | .bNumEndpoints = 1, |
| 82 | .bInterfaceClass = USB_CLASS_HID, |
| 83 | .bInterfaceSubClass = 0x01, /* boot */ |
| 84 | .bInterfaceProtocol = 0x02, |
| 85 | .ndesc = 1, |
| 86 | .descs = (USBDescOther[]) { |
| 87 | { |
| 88 | /* HID descriptor */ |
| 89 | .data = (uint8_t[]) { |
| 90 | 0x09, /* u8 bLength */ |
| 91 | USB_DT_HID, /* u8 bDescriptorType */ |
| 92 | 0x01, 0x00, /* u16 HID_class */ |
| 93 | 0x00, /* u8 country_code */ |
| 94 | 0x01, /* u8 num_descriptors */ |
| 95 | USB_DT_REPORT, /* u8 type: Report */ |
| 96 | 52, 0, /* u16 len */ |
| 97 | }, |
| 98 | }, |
| 99 | }, |
| 100 | .eps = (USBDescEndpoint[]) { |
| 101 | { |
| 102 | .bEndpointAddress = USB_DIR_IN | 0x01, |
| 103 | .bmAttributes = USB_ENDPOINT_XFER_INT, |
| 104 | .wMaxPacketSize = 4, |
| 105 | .bInterval = 0x0a, |
| 106 | }, |
| 107 | }, |
bellard | 59ae540 | 2005-11-05 16:57:08 +0000 | [diff] [blame] | 108 | }; |
| 109 | |
Jan Vesely | 58e4fee | 2014-09-29 22:21:10 -0400 | [diff] [blame] | 110 | static const USBDescIface desc_iface_mouse2 = { |
| 111 | .bInterfaceNumber = 0, |
| 112 | .bNumEndpoints = 1, |
| 113 | .bInterfaceClass = USB_CLASS_HID, |
| 114 | .bInterfaceSubClass = 0x01, /* boot */ |
| 115 | .bInterfaceProtocol = 0x02, |
| 116 | .ndesc = 1, |
| 117 | .descs = (USBDescOther[]) { |
| 118 | { |
| 119 | /* HID descriptor */ |
| 120 | .data = (uint8_t[]) { |
| 121 | 0x09, /* u8 bLength */ |
| 122 | USB_DT_HID, /* u8 bDescriptorType */ |
| 123 | 0x01, 0x00, /* u16 HID_class */ |
| 124 | 0x00, /* u8 country_code */ |
| 125 | 0x01, /* u8 num_descriptors */ |
| 126 | USB_DT_REPORT, /* u8 type: Report */ |
| 127 | 52, 0, /* u16 len */ |
| 128 | }, |
| 129 | }, |
| 130 | }, |
| 131 | .eps = (USBDescEndpoint[]) { |
| 132 | { |
| 133 | .bEndpointAddress = USB_DIR_IN | 0x01, |
| 134 | .bmAttributes = USB_ENDPOINT_XFER_INT, |
| 135 | .wMaxPacketSize = 4, |
| 136 | .bInterval = 7, /* 2 ^ (8-1) * 125 usecs = 8 ms */ |
| 137 | }, |
| 138 | }, |
| 139 | }; |
| 140 | |
Gerd Hoffmann | 0e4e969 | 2010-11-17 11:05:05 +0100 | [diff] [blame] | 141 | static const USBDescIface desc_iface_tablet = { |
| 142 | .bInterfaceNumber = 0, |
| 143 | .bNumEndpoints = 1, |
| 144 | .bInterfaceClass = USB_CLASS_HID, |
Phil Dennis-Jordan | 0cd089e | 2017-01-25 18:24:35 +0100 | [diff] [blame] | 145 | .bInterfaceProtocol = 0x00, |
Gerd Hoffmann | 0e4e969 | 2010-11-17 11:05:05 +0100 | [diff] [blame] | 146 | .ndesc = 1, |
| 147 | .descs = (USBDescOther[]) { |
| 148 | { |
| 149 | /* HID descriptor */ |
| 150 | .data = (uint8_t[]) { |
| 151 | 0x09, /* u8 bLength */ |
| 152 | USB_DT_HID, /* u8 bDescriptorType */ |
| 153 | 0x01, 0x00, /* u16 HID_class */ |
| 154 | 0x00, /* u8 country_code */ |
| 155 | 0x01, /* u8 num_descriptors */ |
| 156 | USB_DT_REPORT, /* u8 type: Report */ |
| 157 | 74, 0, /* u16 len */ |
| 158 | }, |
| 159 | }, |
| 160 | }, |
| 161 | .eps = (USBDescEndpoint[]) { |
| 162 | { |
| 163 | .bEndpointAddress = USB_DIR_IN | 0x01, |
| 164 | .bmAttributes = USB_ENDPOINT_XFER_INT, |
| 165 | .wMaxPacketSize = 8, |
| 166 | .bInterval = 0x0a, |
| 167 | }, |
| 168 | }, |
| 169 | }; |
balrog | 47b2d33 | 2007-06-22 08:16:00 +0000 | [diff] [blame] | 170 | |
Hans de Goede | 427e3aa | 2012-11-17 12:47:18 +0100 | [diff] [blame] | 171 | static const USBDescIface desc_iface_tablet2 = { |
| 172 | .bInterfaceNumber = 0, |
| 173 | .bNumEndpoints = 1, |
| 174 | .bInterfaceClass = USB_CLASS_HID, |
Phil Dennis-Jordan | 0cd089e | 2017-01-25 18:24:35 +0100 | [diff] [blame] | 175 | .bInterfaceProtocol = 0x00, |
Hans de Goede | 427e3aa | 2012-11-17 12:47:18 +0100 | [diff] [blame] | 176 | .ndesc = 1, |
| 177 | .descs = (USBDescOther[]) { |
| 178 | { |
| 179 | /* HID descriptor */ |
| 180 | .data = (uint8_t[]) { |
| 181 | 0x09, /* u8 bLength */ |
| 182 | USB_DT_HID, /* u8 bDescriptorType */ |
| 183 | 0x01, 0x00, /* u16 HID_class */ |
| 184 | 0x00, /* u8 country_code */ |
| 185 | 0x01, /* u8 num_descriptors */ |
| 186 | USB_DT_REPORT, /* u8 type: Report */ |
| 187 | 74, 0, /* u16 len */ |
| 188 | }, |
| 189 | }, |
| 190 | }, |
| 191 | .eps = (USBDescEndpoint[]) { |
| 192 | { |
| 193 | .bEndpointAddress = USB_DIR_IN | 0x01, |
| 194 | .bmAttributes = USB_ENDPOINT_XFER_INT, |
| 195 | .wMaxPacketSize = 8, |
| 196 | .bInterval = 4, /* 2 ^ (4-1) * 125 usecs = 1 ms */ |
| 197 | }, |
| 198 | }, |
| 199 | }; |
| 200 | |
Gerd Hoffmann | 0e4e969 | 2010-11-17 11:05:05 +0100 | [diff] [blame] | 201 | static const USBDescIface desc_iface_keyboard = { |
| 202 | .bInterfaceNumber = 0, |
| 203 | .bNumEndpoints = 1, |
| 204 | .bInterfaceClass = USB_CLASS_HID, |
| 205 | .bInterfaceSubClass = 0x01, /* boot */ |
| 206 | .bInterfaceProtocol = 0x01, /* keyboard */ |
| 207 | .ndesc = 1, |
| 208 | .descs = (USBDescOther[]) { |
| 209 | { |
| 210 | /* HID descriptor */ |
| 211 | .data = (uint8_t[]) { |
| 212 | 0x09, /* u8 bLength */ |
| 213 | USB_DT_HID, /* u8 bDescriptorType */ |
| 214 | 0x11, 0x01, /* u16 HID_class */ |
| 215 | 0x00, /* u8 country_code */ |
| 216 | 0x01, /* u8 num_descriptors */ |
| 217 | USB_DT_REPORT, /* u8 type: Report */ |
| 218 | 0x3f, 0, /* u16 len */ |
| 219 | }, |
| 220 | }, |
| 221 | }, |
| 222 | .eps = (USBDescEndpoint[]) { |
| 223 | { |
| 224 | .bEndpointAddress = USB_DIR_IN | 0x01, |
| 225 | .bmAttributes = USB_ENDPOINT_XFER_INT, |
| 226 | .wMaxPacketSize = 8, |
| 227 | .bInterval = 0x0a, |
| 228 | }, |
| 229 | }, |
| 230 | }; |
balrog | 47b2d33 | 2007-06-22 08:16:00 +0000 | [diff] [blame] | 231 | |
Jan Vesely | b13ce07 | 2014-09-29 22:21:11 -0400 | [diff] [blame] | 232 | static const USBDescIface desc_iface_keyboard2 = { |
| 233 | .bInterfaceNumber = 0, |
| 234 | .bNumEndpoints = 1, |
| 235 | .bInterfaceClass = USB_CLASS_HID, |
| 236 | .bInterfaceSubClass = 0x01, /* boot */ |
| 237 | .bInterfaceProtocol = 0x01, /* keyboard */ |
| 238 | .ndesc = 1, |
| 239 | .descs = (USBDescOther[]) { |
| 240 | { |
| 241 | /* HID descriptor */ |
| 242 | .data = (uint8_t[]) { |
| 243 | 0x09, /* u8 bLength */ |
| 244 | USB_DT_HID, /* u8 bDescriptorType */ |
| 245 | 0x11, 0x01, /* u16 HID_class */ |
| 246 | 0x00, /* u8 country_code */ |
| 247 | 0x01, /* u8 num_descriptors */ |
| 248 | USB_DT_REPORT, /* u8 type: Report */ |
| 249 | 0x3f, 0, /* u16 len */ |
| 250 | }, |
| 251 | }, |
| 252 | }, |
| 253 | .eps = (USBDescEndpoint[]) { |
| 254 | { |
| 255 | .bEndpointAddress = USB_DIR_IN | 0x01, |
| 256 | .bmAttributes = USB_ENDPOINT_XFER_INT, |
| 257 | .wMaxPacketSize = 8, |
| 258 | .bInterval = 7, /* 2 ^ (8-1) * 125 usecs = 8 ms */ |
| 259 | }, |
| 260 | }, |
| 261 | }; |
| 262 | |
Gerd Hoffmann | 0e4e969 | 2010-11-17 11:05:05 +0100 | [diff] [blame] | 263 | static const USBDescDevice desc_device_mouse = { |
| 264 | .bcdUSB = 0x0100, |
| 265 | .bMaxPacketSize0 = 8, |
| 266 | .bNumConfigurations = 1, |
| 267 | .confs = (USBDescConfig[]) { |
| 268 | { |
| 269 | .bNumInterfaces = 1, |
| 270 | .bConfigurationValue = 1, |
| 271 | .iConfiguration = STR_CONFIG_MOUSE, |
Pantelis Koukousoulas | bd93976 | 2013-12-16 09:42:49 +0200 | [diff] [blame] | 272 | .bmAttributes = USB_CFG_ATT_ONE | USB_CFG_ATT_WAKEUP, |
Gerd Hoffmann | 0e4e969 | 2010-11-17 11:05:05 +0100 | [diff] [blame] | 273 | .bMaxPower = 50, |
Brad Hards | add7508 | 2011-04-03 15:33:19 +1000 | [diff] [blame] | 274 | .nif = 1, |
Gerd Hoffmann | 0e4e969 | 2010-11-17 11:05:05 +0100 | [diff] [blame] | 275 | .ifs = &desc_iface_mouse, |
| 276 | }, |
| 277 | }, |
| 278 | }; |
balrog | 47b2d33 | 2007-06-22 08:16:00 +0000 | [diff] [blame] | 279 | |
Jan Vesely | 58e4fee | 2014-09-29 22:21:10 -0400 | [diff] [blame] | 280 | static const USBDescDevice desc_device_mouse2 = { |
| 281 | .bcdUSB = 0x0200, |
| 282 | .bMaxPacketSize0 = 64, |
| 283 | .bNumConfigurations = 1, |
| 284 | .confs = (USBDescConfig[]) { |
| 285 | { |
| 286 | .bNumInterfaces = 1, |
| 287 | .bConfigurationValue = 1, |
| 288 | .iConfiguration = STR_CONFIG_MOUSE, |
| 289 | .bmAttributes = USB_CFG_ATT_ONE | USB_CFG_ATT_WAKEUP, |
| 290 | .bMaxPower = 50, |
| 291 | .nif = 1, |
| 292 | .ifs = &desc_iface_mouse2, |
| 293 | }, |
| 294 | }, |
| 295 | }; |
| 296 | |
Gerd Hoffmann | 0e4e969 | 2010-11-17 11:05:05 +0100 | [diff] [blame] | 297 | static const USBDescDevice desc_device_tablet = { |
| 298 | .bcdUSB = 0x0100, |
| 299 | .bMaxPacketSize0 = 8, |
| 300 | .bNumConfigurations = 1, |
| 301 | .confs = (USBDescConfig[]) { |
| 302 | { |
| 303 | .bNumInterfaces = 1, |
| 304 | .bConfigurationValue = 1, |
| 305 | .iConfiguration = STR_CONFIG_TABLET, |
Pantelis Koukousoulas | bd93976 | 2013-12-16 09:42:49 +0200 | [diff] [blame] | 306 | .bmAttributes = USB_CFG_ATT_ONE | USB_CFG_ATT_WAKEUP, |
Gerd Hoffmann | 0e4e969 | 2010-11-17 11:05:05 +0100 | [diff] [blame] | 307 | .bMaxPower = 50, |
Brad Hards | add7508 | 2011-04-03 15:33:19 +1000 | [diff] [blame] | 308 | .nif = 1, |
Gerd Hoffmann | 0e4e969 | 2010-11-17 11:05:05 +0100 | [diff] [blame] | 309 | .ifs = &desc_iface_tablet, |
| 310 | }, |
| 311 | }, |
| 312 | }; |
balrog | 47b2d33 | 2007-06-22 08:16:00 +0000 | [diff] [blame] | 313 | |
Hans de Goede | 427e3aa | 2012-11-17 12:47:18 +0100 | [diff] [blame] | 314 | static const USBDescDevice desc_device_tablet2 = { |
| 315 | .bcdUSB = 0x0200, |
| 316 | .bMaxPacketSize0 = 64, |
| 317 | .bNumConfigurations = 1, |
| 318 | .confs = (USBDescConfig[]) { |
| 319 | { |
| 320 | .bNumInterfaces = 1, |
| 321 | .bConfigurationValue = 1, |
| 322 | .iConfiguration = STR_CONFIG_TABLET, |
Pantelis Koukousoulas | bd93976 | 2013-12-16 09:42:49 +0200 | [diff] [blame] | 323 | .bmAttributes = USB_CFG_ATT_ONE | USB_CFG_ATT_WAKEUP, |
Hans de Goede | 427e3aa | 2012-11-17 12:47:18 +0100 | [diff] [blame] | 324 | .bMaxPower = 50, |
| 325 | .nif = 1, |
| 326 | .ifs = &desc_iface_tablet2, |
| 327 | }, |
| 328 | }, |
| 329 | }; |
| 330 | |
Gerd Hoffmann | 0e4e969 | 2010-11-17 11:05:05 +0100 | [diff] [blame] | 331 | static const USBDescDevice desc_device_keyboard = { |
| 332 | .bcdUSB = 0x0100, |
| 333 | .bMaxPacketSize0 = 8, |
| 334 | .bNumConfigurations = 1, |
| 335 | .confs = (USBDescConfig[]) { |
| 336 | { |
| 337 | .bNumInterfaces = 1, |
| 338 | .bConfigurationValue = 1, |
| 339 | .iConfiguration = STR_CONFIG_KEYBOARD, |
Pantelis Koukousoulas | bd93976 | 2013-12-16 09:42:49 +0200 | [diff] [blame] | 340 | .bmAttributes = USB_CFG_ATT_ONE | USB_CFG_ATT_WAKEUP, |
Gerd Hoffmann | 0e4e969 | 2010-11-17 11:05:05 +0100 | [diff] [blame] | 341 | .bMaxPower = 50, |
Brad Hards | add7508 | 2011-04-03 15:33:19 +1000 | [diff] [blame] | 342 | .nif = 1, |
Gerd Hoffmann | 0e4e969 | 2010-11-17 11:05:05 +0100 | [diff] [blame] | 343 | .ifs = &desc_iface_keyboard, |
| 344 | }, |
| 345 | }, |
| 346 | }; |
| 347 | |
Jan Vesely | b13ce07 | 2014-09-29 22:21:11 -0400 | [diff] [blame] | 348 | static const USBDescDevice desc_device_keyboard2 = { |
| 349 | .bcdUSB = 0x0200, |
| 350 | .bMaxPacketSize0 = 64, |
| 351 | .bNumConfigurations = 1, |
| 352 | .confs = (USBDescConfig[]) { |
| 353 | { |
| 354 | .bNumInterfaces = 1, |
| 355 | .bConfigurationValue = 1, |
| 356 | .iConfiguration = STR_CONFIG_KEYBOARD, |
| 357 | .bmAttributes = USB_CFG_ATT_ONE | USB_CFG_ATT_WAKEUP, |
| 358 | .bMaxPower = 50, |
| 359 | .nif = 1, |
| 360 | .ifs = &desc_iface_keyboard2, |
| 361 | }, |
| 362 | }, |
| 363 | }; |
| 364 | |
Gerd Hoffmann | 88678fb | 2013-11-20 07:33:50 +0100 | [diff] [blame] | 365 | static const USBDescMSOS desc_msos_suspend = { |
| 366 | .SelectiveSuspendEnabled = true, |
| 367 | }; |
| 368 | |
Gerd Hoffmann | 0e4e969 | 2010-11-17 11:05:05 +0100 | [diff] [blame] | 369 | static const USBDesc desc_mouse = { |
| 370 | .id = { |
| 371 | .idVendor = 0x0627, |
| 372 | .idProduct = 0x0001, |
| 373 | .bcdDevice = 0, |
| 374 | .iManufacturer = STR_MANUFACTURER, |
| 375 | .iProduct = STR_PRODUCT_MOUSE, |
Gerd Hoffmann | b63e105 | 2019-01-10 13:51:08 +0100 | [diff] [blame] | 376 | .iSerialNumber = STR_SERIAL_MOUSE, |
Gerd Hoffmann | 0e4e969 | 2010-11-17 11:05:05 +0100 | [diff] [blame] | 377 | }, |
| 378 | .full = &desc_device_mouse, |
| 379 | .str = desc_strings, |
Gerd Hoffmann | 88678fb | 2013-11-20 07:33:50 +0100 | [diff] [blame] | 380 | .msos = &desc_msos_suspend, |
Gerd Hoffmann | 0e4e969 | 2010-11-17 11:05:05 +0100 | [diff] [blame] | 381 | }; |
| 382 | |
Jan Vesely | 58e4fee | 2014-09-29 22:21:10 -0400 | [diff] [blame] | 383 | static const USBDesc desc_mouse2 = { |
| 384 | .id = { |
| 385 | .idVendor = 0x0627, |
| 386 | .idProduct = 0x0001, |
| 387 | .bcdDevice = 0, |
| 388 | .iManufacturer = STR_MANUFACTURER, |
| 389 | .iProduct = STR_PRODUCT_MOUSE, |
Gerd Hoffmann | b63e105 | 2019-01-10 13:51:08 +0100 | [diff] [blame] | 390 | .iSerialNumber = STR_SERIAL_MOUSE, |
Jan Vesely | 58e4fee | 2014-09-29 22:21:10 -0400 | [diff] [blame] | 391 | }, |
| 392 | .full = &desc_device_mouse, |
| 393 | .high = &desc_device_mouse2, |
| 394 | .str = desc_strings, |
| 395 | .msos = &desc_msos_suspend, |
| 396 | }; |
| 397 | |
Gerd Hoffmann | 0e4e969 | 2010-11-17 11:05:05 +0100 | [diff] [blame] | 398 | static const USBDesc desc_tablet = { |
| 399 | .id = { |
| 400 | .idVendor = 0x0627, |
| 401 | .idProduct = 0x0001, |
| 402 | .bcdDevice = 0, |
| 403 | .iManufacturer = STR_MANUFACTURER, |
| 404 | .iProduct = STR_PRODUCT_TABLET, |
Gerd Hoffmann | b63e105 | 2019-01-10 13:51:08 +0100 | [diff] [blame] | 405 | .iSerialNumber = STR_SERIAL_TABLET, |
Gerd Hoffmann | 0e4e969 | 2010-11-17 11:05:05 +0100 | [diff] [blame] | 406 | }, |
| 407 | .full = &desc_device_tablet, |
| 408 | .str = desc_strings, |
Gerd Hoffmann | 88678fb | 2013-11-20 07:33:50 +0100 | [diff] [blame] | 409 | .msos = &desc_msos_suspend, |
Gerd Hoffmann | 0e4e969 | 2010-11-17 11:05:05 +0100 | [diff] [blame] | 410 | }; |
| 411 | |
Hans de Goede | 427e3aa | 2012-11-17 12:47:18 +0100 | [diff] [blame] | 412 | static const USBDesc desc_tablet2 = { |
| 413 | .id = { |
| 414 | .idVendor = 0x0627, |
| 415 | .idProduct = 0x0001, |
| 416 | .bcdDevice = 0, |
| 417 | .iManufacturer = STR_MANUFACTURER, |
| 418 | .iProduct = STR_PRODUCT_TABLET, |
Gerd Hoffmann | b63e105 | 2019-01-10 13:51:08 +0100 | [diff] [blame] | 419 | .iSerialNumber = STR_SERIAL_TABLET, |
Hans de Goede | 427e3aa | 2012-11-17 12:47:18 +0100 | [diff] [blame] | 420 | }, |
| 421 | .full = &desc_device_tablet, |
| 422 | .high = &desc_device_tablet2, |
| 423 | .str = desc_strings, |
Gerd Hoffmann | 88678fb | 2013-11-20 07:33:50 +0100 | [diff] [blame] | 424 | .msos = &desc_msos_suspend, |
Hans de Goede | 427e3aa | 2012-11-17 12:47:18 +0100 | [diff] [blame] | 425 | }; |
| 426 | |
Gerd Hoffmann | 0e4e969 | 2010-11-17 11:05:05 +0100 | [diff] [blame] | 427 | static const USBDesc desc_keyboard = { |
| 428 | .id = { |
| 429 | .idVendor = 0x0627, |
| 430 | .idProduct = 0x0001, |
| 431 | .bcdDevice = 0, |
| 432 | .iManufacturer = STR_MANUFACTURER, |
| 433 | .iProduct = STR_PRODUCT_KEYBOARD, |
Gerd Hoffmann | b63e105 | 2019-01-10 13:51:08 +0100 | [diff] [blame] | 434 | .iSerialNumber = STR_SERIAL_KEYBOARD, |
Gerd Hoffmann | 0e4e969 | 2010-11-17 11:05:05 +0100 | [diff] [blame] | 435 | }, |
| 436 | .full = &desc_device_keyboard, |
| 437 | .str = desc_strings, |
Gerd Hoffmann | 88678fb | 2013-11-20 07:33:50 +0100 | [diff] [blame] | 438 | .msos = &desc_msos_suspend, |
balrog | 47b2d33 | 2007-06-22 08:16:00 +0000 | [diff] [blame] | 439 | }; |
| 440 | |
Jan Vesely | b13ce07 | 2014-09-29 22:21:11 -0400 | [diff] [blame] | 441 | static const USBDesc desc_keyboard2 = { |
| 442 | .id = { |
| 443 | .idVendor = 0x0627, |
| 444 | .idProduct = 0x0001, |
| 445 | .bcdDevice = 0, |
| 446 | .iManufacturer = STR_MANUFACTURER, |
| 447 | .iProduct = STR_PRODUCT_KEYBOARD, |
Gerd Hoffmann | b63e105 | 2019-01-10 13:51:08 +0100 | [diff] [blame] | 448 | .iSerialNumber = STR_SERIAL_KEYBOARD, |
Jan Vesely | b13ce07 | 2014-09-29 22:21:11 -0400 | [diff] [blame] | 449 | }, |
| 450 | .full = &desc_device_keyboard, |
| 451 | .high = &desc_device_keyboard2, |
| 452 | .str = desc_strings, |
| 453 | .msos = &desc_msos_suspend, |
| 454 | }; |
| 455 | |
bellard | 59ae540 | 2005-11-05 16:57:08 +0000 | [diff] [blame] | 456 | static const uint8_t qemu_mouse_hid_report_descriptor[] = { |
balrog | 976f8ee | 2008-05-17 19:55:28 +0000 | [diff] [blame] | 457 | 0x05, 0x01, /* Usage Page (Generic Desktop) */ |
| 458 | 0x09, 0x02, /* Usage (Mouse) */ |
| 459 | 0xa1, 0x01, /* Collection (Application) */ |
| 460 | 0x09, 0x01, /* Usage (Pointer) */ |
| 461 | 0xa1, 0x00, /* Collection (Physical) */ |
| 462 | 0x05, 0x09, /* Usage Page (Button) */ |
| 463 | 0x19, 0x01, /* Usage Minimum (1) */ |
Noah Bergbauer | 1e2d555 | 2021-11-26 15:04:37 +0100 | [diff] [blame] | 464 | 0x29, 0x05, /* Usage Maximum (5) */ |
balrog | 976f8ee | 2008-05-17 19:55:28 +0000 | [diff] [blame] | 465 | 0x15, 0x00, /* Logical Minimum (0) */ |
| 466 | 0x25, 0x01, /* Logical Maximum (1) */ |
Noah Bergbauer | 1e2d555 | 2021-11-26 15:04:37 +0100 | [diff] [blame] | 467 | 0x95, 0x05, /* Report Count (5) */ |
balrog | 976f8ee | 2008-05-17 19:55:28 +0000 | [diff] [blame] | 468 | 0x75, 0x01, /* Report Size (1) */ |
| 469 | 0x81, 0x02, /* Input (Data, Variable, Absolute) */ |
| 470 | 0x95, 0x01, /* Report Count (1) */ |
Noah Bergbauer | 1e2d555 | 2021-11-26 15:04:37 +0100 | [diff] [blame] | 471 | 0x75, 0x03, /* Report Size (3) */ |
balrog | 976f8ee | 2008-05-17 19:55:28 +0000 | [diff] [blame] | 472 | 0x81, 0x01, /* Input (Constant) */ |
| 473 | 0x05, 0x01, /* Usage Page (Generic Desktop) */ |
| 474 | 0x09, 0x30, /* Usage (X) */ |
| 475 | 0x09, 0x31, /* Usage (Y) */ |
| 476 | 0x09, 0x38, /* Usage (Wheel) */ |
| 477 | 0x15, 0x81, /* Logical Minimum (-0x7f) */ |
| 478 | 0x25, 0x7f, /* Logical Maximum (0x7f) */ |
| 479 | 0x75, 0x08, /* Report Size (8) */ |
| 480 | 0x95, 0x03, /* Report Count (3) */ |
| 481 | 0x81, 0x06, /* Input (Data, Variable, Relative) */ |
| 482 | 0xc0, /* End Collection */ |
| 483 | 0xc0, /* End Collection */ |
bellard | 59ae540 | 2005-11-05 16:57:08 +0000 | [diff] [blame] | 484 | }; |
| 485 | |
bellard | 09b26c5 | 2006-04-12 21:09:08 +0000 | [diff] [blame] | 486 | static const uint8_t qemu_tablet_hid_report_descriptor[] = { |
balrog | 976f8ee | 2008-05-17 19:55:28 +0000 | [diff] [blame] | 487 | 0x05, 0x01, /* Usage Page (Generic Desktop) */ |
Phil Dennis-Jordan | 0cd089e | 2017-01-25 18:24:35 +0100 | [diff] [blame] | 488 | 0x09, 0x02, /* Usage (Mouse) */ |
balrog | 976f8ee | 2008-05-17 19:55:28 +0000 | [diff] [blame] | 489 | 0xa1, 0x01, /* Collection (Application) */ |
| 490 | 0x09, 0x01, /* Usage (Pointer) */ |
| 491 | 0xa1, 0x00, /* Collection (Physical) */ |
| 492 | 0x05, 0x09, /* Usage Page (Button) */ |
| 493 | 0x19, 0x01, /* Usage Minimum (1) */ |
| 494 | 0x29, 0x03, /* Usage Maximum (3) */ |
| 495 | 0x15, 0x00, /* Logical Minimum (0) */ |
| 496 | 0x25, 0x01, /* Logical Maximum (1) */ |
| 497 | 0x95, 0x03, /* Report Count (3) */ |
| 498 | 0x75, 0x01, /* Report Size (1) */ |
| 499 | 0x81, 0x02, /* Input (Data, Variable, Absolute) */ |
| 500 | 0x95, 0x01, /* Report Count (1) */ |
| 501 | 0x75, 0x05, /* Report Size (5) */ |
| 502 | 0x81, 0x01, /* Input (Constant) */ |
| 503 | 0x05, 0x01, /* Usage Page (Generic Desktop) */ |
| 504 | 0x09, 0x30, /* Usage (X) */ |
| 505 | 0x09, 0x31, /* Usage (Y) */ |
| 506 | 0x15, 0x00, /* Logical Minimum (0) */ |
balrog | de5c2d0 | 2008-09-15 22:26:35 +0000 | [diff] [blame] | 507 | 0x26, 0xff, 0x7f, /* Logical Maximum (0x7fff) */ |
balrog | 976f8ee | 2008-05-17 19:55:28 +0000 | [diff] [blame] | 508 | 0x35, 0x00, /* Physical Minimum (0) */ |
balrog | de5c2d0 | 2008-09-15 22:26:35 +0000 | [diff] [blame] | 509 | 0x46, 0xff, 0x7f, /* Physical Maximum (0x7fff) */ |
balrog | 976f8ee | 2008-05-17 19:55:28 +0000 | [diff] [blame] | 510 | 0x75, 0x10, /* Report Size (16) */ |
| 511 | 0x95, 0x02, /* Report Count (2) */ |
| 512 | 0x81, 0x02, /* Input (Data, Variable, Absolute) */ |
| 513 | 0x05, 0x01, /* Usage Page (Generic Desktop) */ |
| 514 | 0x09, 0x38, /* Usage (Wheel) */ |
| 515 | 0x15, 0x81, /* Logical Minimum (-0x7f) */ |
| 516 | 0x25, 0x7f, /* Logical Maximum (0x7f) */ |
| 517 | 0x35, 0x00, /* Physical Minimum (same as logical) */ |
| 518 | 0x45, 0x00, /* Physical Maximum (same as logical) */ |
| 519 | 0x75, 0x08, /* Report Size (8) */ |
| 520 | 0x95, 0x01, /* Report Count (1) */ |
| 521 | 0x81, 0x06, /* Input (Data, Variable, Relative) */ |
| 522 | 0xc0, /* End Collection */ |
| 523 | 0xc0, /* End Collection */ |
bellard | 09b26c5 | 2006-04-12 21:09:08 +0000 | [diff] [blame] | 524 | }; |
| 525 | |
balrog | 47b2d33 | 2007-06-22 08:16:00 +0000 | [diff] [blame] | 526 | static const uint8_t qemu_keyboard_hid_report_descriptor[] = { |
| 527 | 0x05, 0x01, /* Usage Page (Generic Desktop) */ |
| 528 | 0x09, 0x06, /* Usage (Keyboard) */ |
| 529 | 0xa1, 0x01, /* Collection (Application) */ |
| 530 | 0x75, 0x01, /* Report Size (1) */ |
| 531 | 0x95, 0x08, /* Report Count (8) */ |
| 532 | 0x05, 0x07, /* Usage Page (Key Codes) */ |
| 533 | 0x19, 0xe0, /* Usage Minimum (224) */ |
| 534 | 0x29, 0xe7, /* Usage Maximum (231) */ |
| 535 | 0x15, 0x00, /* Logical Minimum (0) */ |
| 536 | 0x25, 0x01, /* Logical Maximum (1) */ |
| 537 | 0x81, 0x02, /* Input (Data, Variable, Absolute) */ |
| 538 | 0x95, 0x01, /* Report Count (1) */ |
| 539 | 0x75, 0x08, /* Report Size (8) */ |
| 540 | 0x81, 0x01, /* Input (Constant) */ |
| 541 | 0x95, 0x05, /* Report Count (5) */ |
| 542 | 0x75, 0x01, /* Report Size (1) */ |
| 543 | 0x05, 0x08, /* Usage Page (LEDs) */ |
| 544 | 0x19, 0x01, /* Usage Minimum (1) */ |
| 545 | 0x29, 0x05, /* Usage Maximum (5) */ |
| 546 | 0x91, 0x02, /* Output (Data, Variable, Absolute) */ |
| 547 | 0x95, 0x01, /* Report Count (1) */ |
| 548 | 0x75, 0x03, /* Report Size (3) */ |
| 549 | 0x91, 0x01, /* Output (Constant) */ |
| 550 | 0x95, 0x06, /* Report Count (6) */ |
| 551 | 0x75, 0x08, /* Report Size (8) */ |
| 552 | 0x15, 0x00, /* Logical Minimum (0) */ |
| 553 | 0x25, 0xff, /* Logical Maximum (255) */ |
| 554 | 0x05, 0x07, /* Usage Page (Key Codes) */ |
| 555 | 0x19, 0x00, /* Usage Minimum (0) */ |
| 556 | 0x29, 0xff, /* Usage Maximum (255) */ |
| 557 | 0x81, 0x00, /* Input (Data, Array) */ |
| 558 | 0xc0, /* End Collection */ |
| 559 | }; |
| 560 | |
Gerd Hoffmann | 8bde680 | 2011-07-15 14:37:15 +0200 | [diff] [blame] | 561 | static void usb_hid_changed(HIDState *hs) |
balrog | 47e699d | 2008-09-29 00:25:17 +0000 | [diff] [blame] | 562 | { |
Gerd Hoffmann | 8bde680 | 2011-07-15 14:37:15 +0200 | [diff] [blame] | 563 | USBHIDState *us = container_of(hs, USBHIDState, hid); |
balrog | 47e699d | 2008-09-29 00:25:17 +0000 | [diff] [blame] | 564 | |
Gerd Hoffmann | 8550a02 | 2013-01-29 12:44:35 +0100 | [diff] [blame] | 565 | usb_wakeup(us->intr, 0); |
balrog | 47e699d | 2008-09-29 00:25:17 +0000 | [diff] [blame] | 566 | } |
| 567 | |
Gerd Hoffmann | 8bde680 | 2011-07-15 14:37:15 +0200 | [diff] [blame] | 568 | static void usb_hid_handle_reset(USBDevice *dev) |
balrog | 47b2d33 | 2007-06-22 08:16:00 +0000 | [diff] [blame] | 569 | { |
Gonglei | f566912 | 2015-05-06 20:55:26 +0800 | [diff] [blame] | 570 | USBHIDState *us = USB_HID(dev); |
balrog | 47b2d33 | 2007-06-22 08:16:00 +0000 | [diff] [blame] | 571 | |
Gerd Hoffmann | dcfda67 | 2011-07-15 15:08:01 +0200 | [diff] [blame] | 572 | hid_reset(&us->hid); |
Kevin O'Connor | 68735b6 | 2010-02-13 18:32:17 -0500 | [diff] [blame] | 573 | } |
| 574 | |
Hans de Goede | 9a77a0f | 2012-11-01 17:15:01 +0100 | [diff] [blame] | 575 | static void usb_hid_handle_control(USBDevice *dev, USBPacket *p, |
Hans de Goede | 007fd62 | 2011-02-02 16:33:13 +0100 | [diff] [blame] | 576 | int request, int value, int index, int length, uint8_t *data) |
bellard | 59ae540 | 2005-11-05 16:57:08 +0000 | [diff] [blame] | 577 | { |
Gonglei | f566912 | 2015-05-06 20:55:26 +0800 | [diff] [blame] | 578 | USBHIDState *us = USB_HID(dev); |
Gerd Hoffmann | 0d878ee | 2011-07-15 13:12:44 +0200 | [diff] [blame] | 579 | HIDState *hs = &us->hid; |
Gerd Hoffmann | 0e4e969 | 2010-11-17 11:05:05 +0100 | [diff] [blame] | 580 | int ret; |
bellard | 59ae540 | 2005-11-05 16:57:08 +0000 | [diff] [blame] | 581 | |
Hans de Goede | 007fd62 | 2011-02-02 16:33:13 +0100 | [diff] [blame] | 582 | ret = usb_desc_handle_control(dev, p, request, value, index, length, data); |
Gerd Hoffmann | 0e4e969 | 2010-11-17 11:05:05 +0100 | [diff] [blame] | 583 | if (ret >= 0) { |
Hans de Goede | 9a77a0f | 2012-11-01 17:15:01 +0100 | [diff] [blame] | 584 | return; |
Gerd Hoffmann | 0e4e969 | 2010-11-17 11:05:05 +0100 | [diff] [blame] | 585 | } |
| 586 | |
Gerd Hoffmann | 0d878ee | 2011-07-15 13:12:44 +0200 | [diff] [blame] | 587 | switch (request) { |
bellard | 59ae540 | 2005-11-05 16:57:08 +0000 | [diff] [blame] | 588 | /* hid specific requests */ |
| 589 | case InterfaceRequest | USB_REQ_GET_DESCRIPTOR: |
Gerd Hoffmann | 0d878ee | 2011-07-15 13:12:44 +0200 | [diff] [blame] | 590 | switch (value >> 8) { |
bellard | 59ae540 | 2005-11-05 16:57:08 +0000 | [diff] [blame] | 591 | case 0x22: |
Gerd Hoffmann | 0d878ee | 2011-07-15 13:12:44 +0200 | [diff] [blame] | 592 | if (hs->kind == HID_MOUSE) { |
Paolo Bonzini | 7d37435 | 2018-12-13 23:37:37 +0100 | [diff] [blame] | 593 | memcpy(data, qemu_mouse_hid_report_descriptor, |
| 594 | sizeof(qemu_mouse_hid_report_descriptor)); |
Hans de Goede | 9a77a0f | 2012-11-01 17:15:01 +0100 | [diff] [blame] | 595 | p->actual_length = sizeof(qemu_mouse_hid_report_descriptor); |
Gerd Hoffmann | 0d878ee | 2011-07-15 13:12:44 +0200 | [diff] [blame] | 596 | } else if (hs->kind == HID_TABLET) { |
| 597 | memcpy(data, qemu_tablet_hid_report_descriptor, |
Paolo Bonzini | 7d37435 | 2018-12-13 23:37:37 +0100 | [diff] [blame] | 598 | sizeof(qemu_tablet_hid_report_descriptor)); |
Hans de Goede | 9a77a0f | 2012-11-01 17:15:01 +0100 | [diff] [blame] | 599 | p->actual_length = sizeof(qemu_tablet_hid_report_descriptor); |
Gerd Hoffmann | 0d878ee | 2011-07-15 13:12:44 +0200 | [diff] [blame] | 600 | } else if (hs->kind == HID_KEYBOARD) { |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 601 | memcpy(data, qemu_keyboard_hid_report_descriptor, |
balrog | 47b2d33 | 2007-06-22 08:16:00 +0000 | [diff] [blame] | 602 | sizeof(qemu_keyboard_hid_report_descriptor)); |
Hans de Goede | 9a77a0f | 2012-11-01 17:15:01 +0100 | [diff] [blame] | 603 | p->actual_length = sizeof(qemu_keyboard_hid_report_descriptor); |
balrog | 47b2d33 | 2007-06-22 08:16:00 +0000 | [diff] [blame] | 604 | } |
| 605 | break; |
bellard | 59ae540 | 2005-11-05 16:57:08 +0000 | [diff] [blame] | 606 | default: |
| 607 | goto fail; |
| 608 | } |
| 609 | break; |
César Belley | 84b6c23 | 2020-08-12 11:41:23 +0200 | [diff] [blame] | 610 | case HID_GET_REPORT: |
Gerd Hoffmann | 0d878ee | 2011-07-15 13:12:44 +0200 | [diff] [blame] | 611 | if (hs->kind == HID_MOUSE || hs->kind == HID_TABLET) { |
Hans de Goede | 9a77a0f | 2012-11-01 17:15:01 +0100 | [diff] [blame] | 612 | p->actual_length = hid_pointer_poll(hs, data, length); |
Gerd Hoffmann | 0d878ee | 2011-07-15 13:12:44 +0200 | [diff] [blame] | 613 | } else if (hs->kind == HID_KEYBOARD) { |
Hans de Goede | 9a77a0f | 2012-11-01 17:15:01 +0100 | [diff] [blame] | 614 | p->actual_length = hid_keyboard_poll(hs, data, length); |
Gerd Hoffmann | e7e7389 | 2011-07-08 13:19:01 +0200 | [diff] [blame] | 615 | } |
balrog | 47b2d33 | 2007-06-22 08:16:00 +0000 | [diff] [blame] | 616 | break; |
César Belley | 84b6c23 | 2020-08-12 11:41:23 +0200 | [diff] [blame] | 617 | case HID_SET_REPORT: |
Gerd Hoffmann | 0d878ee | 2011-07-15 13:12:44 +0200 | [diff] [blame] | 618 | if (hs->kind == HID_KEYBOARD) { |
Hans de Goede | 9a77a0f | 2012-11-01 17:15:01 +0100 | [diff] [blame] | 619 | p->actual_length = hid_keyboard_write(hs, data, length); |
Gerd Hoffmann | 0d878ee | 2011-07-15 13:12:44 +0200 | [diff] [blame] | 620 | } else { |
balrog | 47b2d33 | 2007-06-22 08:16:00 +0000 | [diff] [blame] | 621 | goto fail; |
Gerd Hoffmann | 0d878ee | 2011-07-15 13:12:44 +0200 | [diff] [blame] | 622 | } |
balrog | 47b2d33 | 2007-06-22 08:16:00 +0000 | [diff] [blame] | 623 | break; |
César Belley | 84b6c23 | 2020-08-12 11:41:23 +0200 | [diff] [blame] | 624 | case HID_GET_PROTOCOL: |
Gerd Hoffmann | 0d878ee | 2011-07-15 13:12:44 +0200 | [diff] [blame] | 625 | if (hs->kind != HID_KEYBOARD && hs->kind != HID_MOUSE) { |
balrog | 47b2d33 | 2007-06-22 08:16:00 +0000 | [diff] [blame] | 626 | goto fail; |
Gerd Hoffmann | 0d878ee | 2011-07-15 13:12:44 +0200 | [diff] [blame] | 627 | } |
Gerd Hoffmann | b069d34 | 2011-07-15 15:52:33 +0200 | [diff] [blame] | 628 | data[0] = hs->protocol; |
Hans de Goede | 9a77a0f | 2012-11-01 17:15:01 +0100 | [diff] [blame] | 629 | p->actual_length = 1; |
balrog | 47b2d33 | 2007-06-22 08:16:00 +0000 | [diff] [blame] | 630 | break; |
César Belley | 84b6c23 | 2020-08-12 11:41:23 +0200 | [diff] [blame] | 631 | case HID_SET_PROTOCOL: |
Gerd Hoffmann | 0d878ee | 2011-07-15 13:12:44 +0200 | [diff] [blame] | 632 | if (hs->kind != HID_KEYBOARD && hs->kind != HID_MOUSE) { |
balrog | 47b2d33 | 2007-06-22 08:16:00 +0000 | [diff] [blame] | 633 | goto fail; |
Gerd Hoffmann | 0d878ee | 2011-07-15 13:12:44 +0200 | [diff] [blame] | 634 | } |
Gerd Hoffmann | b069d34 | 2011-07-15 15:52:33 +0200 | [diff] [blame] | 635 | hs->protocol = value; |
balrog | 47b2d33 | 2007-06-22 08:16:00 +0000 | [diff] [blame] | 636 | break; |
César Belley | 84b6c23 | 2020-08-12 11:41:23 +0200 | [diff] [blame] | 637 | case HID_GET_IDLE: |
Gerd Hoffmann | b069d34 | 2011-07-15 15:52:33 +0200 | [diff] [blame] | 638 | data[0] = hs->idle; |
Hans de Goede | 9a77a0f | 2012-11-01 17:15:01 +0100 | [diff] [blame] | 639 | p->actual_length = 1; |
bellard | 59ae540 | 2005-11-05 16:57:08 +0000 | [diff] [blame] | 640 | break; |
César Belley | 84b6c23 | 2020-08-12 11:41:23 +0200 | [diff] [blame] | 641 | case HID_SET_IDLE: |
Gerd Hoffmann | b069d34 | 2011-07-15 15:52:33 +0200 | [diff] [blame] | 642 | hs->idle = (uint8_t) (value >> 8); |
Hans de Goede | 027c03f | 2012-12-14 14:35:38 +0100 | [diff] [blame] | 643 | hid_set_next_idle(hs); |
Gerd Hoffmann | 21635e1 | 2011-08-09 12:35:57 +0200 | [diff] [blame] | 644 | if (hs->kind == HID_MOUSE || hs->kind == HID_TABLET) { |
| 645 | hid_pointer_activate(hs); |
| 646 | } |
bellard | 59ae540 | 2005-11-05 16:57:08 +0000 | [diff] [blame] | 647 | break; |
| 648 | default: |
| 649 | fail: |
Hans de Goede | 9a77a0f | 2012-11-01 17:15:01 +0100 | [diff] [blame] | 650 | p->status = USB_RET_STALL; |
bellard | 59ae540 | 2005-11-05 16:57:08 +0000 | [diff] [blame] | 651 | break; |
| 652 | } |
bellard | 59ae540 | 2005-11-05 16:57:08 +0000 | [diff] [blame] | 653 | } |
| 654 | |
Hans de Goede | 9a77a0f | 2012-11-01 17:15:01 +0100 | [diff] [blame] | 655 | static void usb_hid_handle_data(USBDevice *dev, USBPacket *p) |
bellard | 59ae540 | 2005-11-05 16:57:08 +0000 | [diff] [blame] | 656 | { |
Gonglei | f566912 | 2015-05-06 20:55:26 +0800 | [diff] [blame] | 657 | USBHIDState *us = USB_HID(dev); |
Gerd Hoffmann | 0d878ee | 2011-07-15 13:12:44 +0200 | [diff] [blame] | 658 | HIDState *hs = &us->hid; |
Gerd Hoffmann | 3f67e2e | 2021-05-03 15:29:11 +0200 | [diff] [blame] | 659 | g_autofree uint8_t *buf = g_malloc(p->iov.size); |
Hans de Goede | 9a77a0f | 2012-11-01 17:15:01 +0100 | [diff] [blame] | 660 | int len = 0; |
bellard | 59ae540 | 2005-11-05 16:57:08 +0000 | [diff] [blame] | 661 | |
Gerd Hoffmann | 0d878ee | 2011-07-15 13:12:44 +0200 | [diff] [blame] | 662 | switch (p->pid) { |
bellard | 59ae540 | 2005-11-05 16:57:08 +0000 | [diff] [blame] | 663 | case USB_TOKEN_IN: |
Gerd Hoffmann | 079d0b7 | 2012-01-12 13:23:01 +0100 | [diff] [blame] | 664 | if (p->ep->nr == 1) { |
Gerd Hoffmann | 299aa1c | 2012-02-23 15:24:24 +0100 | [diff] [blame] | 665 | if (hs->kind == HID_MOUSE || hs->kind == HID_TABLET) { |
| 666 | hid_pointer_activate(hs); |
| 667 | } |
Hans de Goede | 027c03f | 2012-12-14 14:35:38 +0100 | [diff] [blame] | 668 | if (!hid_has_events(hs)) { |
Hans de Goede | 9a77a0f | 2012-11-01 17:15:01 +0100 | [diff] [blame] | 669 | p->status = USB_RET_NAK; |
| 670 | return; |
Paolo Bonzini | 13f8b97 | 2011-01-12 13:19:20 +0100 | [diff] [blame] | 671 | } |
Hans de Goede | 027c03f | 2012-12-14 14:35:38 +0100 | [diff] [blame] | 672 | hid_set_next_idle(hs); |
Gerd Hoffmann | 0d878ee | 2011-07-15 13:12:44 +0200 | [diff] [blame] | 673 | if (hs->kind == HID_MOUSE || hs->kind == HID_TABLET) { |
Hans de Goede | 9a77a0f | 2012-11-01 17:15:01 +0100 | [diff] [blame] | 674 | len = hid_pointer_poll(hs, buf, p->iov.size); |
Gerd Hoffmann | 0d878ee | 2011-07-15 13:12:44 +0200 | [diff] [blame] | 675 | } else if (hs->kind == HID_KEYBOARD) { |
Hans de Goede | 9a77a0f | 2012-11-01 17:15:01 +0100 | [diff] [blame] | 676 | len = hid_keyboard_poll(hs, buf, p->iov.size); |
Paolo Bonzini | 13f8b97 | 2011-01-12 13:19:20 +0100 | [diff] [blame] | 677 | } |
Hans de Goede | 9a77a0f | 2012-11-01 17:15:01 +0100 | [diff] [blame] | 678 | usb_packet_copy(p, buf, len); |
bellard | 59ae540 | 2005-11-05 16:57:08 +0000 | [diff] [blame] | 679 | } else { |
| 680 | goto fail; |
| 681 | } |
| 682 | break; |
| 683 | case USB_TOKEN_OUT: |
| 684 | default: |
| 685 | fail: |
Hans de Goede | 9a77a0f | 2012-11-01 17:15:01 +0100 | [diff] [blame] | 686 | p->status = USB_RET_STALL; |
bellard | 59ae540 | 2005-11-05 16:57:08 +0000 | [diff] [blame] | 687 | break; |
| 688 | } |
bellard | 59ae540 | 2005-11-05 16:57:08 +0000 | [diff] [blame] | 689 | } |
| 690 | |
Markus Armbruster | b69c3c2 | 2020-05-05 17:29:24 +0200 | [diff] [blame] | 691 | static void usb_hid_unrealize(USBDevice *dev) |
bellard | 059809e | 2006-07-19 18:06:15 +0000 | [diff] [blame] | 692 | { |
Gonglei | f566912 | 2015-05-06 20:55:26 +0800 | [diff] [blame] | 693 | USBHIDState *us = USB_HID(dev); |
bellard | 059809e | 2006-07-19 18:06:15 +0000 | [diff] [blame] | 694 | |
Gerd Hoffmann | 8bde680 | 2011-07-15 14:37:15 +0200 | [diff] [blame] | 695 | hid_free(&us->hid); |
| 696 | } |
| 697 | |
Jan Vesely | ff326ff | 2014-09-29 22:21:09 -0400 | [diff] [blame] | 698 | static void usb_hid_initfn(USBDevice *dev, int kind, |
| 699 | const USBDesc *usb1, const USBDesc *usb2, |
| 700 | Error **errp) |
bellard | 09b26c5 | 2006-04-12 21:09:08 +0000 | [diff] [blame] | 701 | { |
Gonglei | f566912 | 2015-05-06 20:55:26 +0800 | [diff] [blame] | 702 | USBHIDState *us = USB_HID(dev); |
Jan Vesely | ff326ff | 2014-09-29 22:21:09 -0400 | [diff] [blame] | 703 | switch (us->usb_version) { |
| 704 | case 1: |
| 705 | dev->usb_desc = usb1; |
| 706 | break; |
| 707 | case 2: |
| 708 | dev->usb_desc = usb2; |
| 709 | break; |
| 710 | default: |
| 711 | dev->usb_desc = NULL; |
| 712 | } |
| 713 | if (!dev->usb_desc) { |
| 714 | error_setg(errp, "Invalid usb version %d for usb hid device", |
| 715 | us->usb_version); |
| 716 | return; |
| 717 | } |
Gerd Hoffmann | a980a06 | 2010-11-26 20:20:41 +0100 | [diff] [blame] | 718 | |
Gerd Hoffmann | b63e105 | 2019-01-10 13:51:08 +0100 | [diff] [blame] | 719 | usb_desc_create_serial(dev); |
Gerd Hoffmann | a980a06 | 2010-11-26 20:20:41 +0100 | [diff] [blame] | 720 | usb_desc_init(dev); |
Gerd Hoffmann | 7567b51 | 2012-01-17 13:25:46 +0100 | [diff] [blame] | 721 | us->intr = usb_ep_get(dev, USB_TOKEN_IN, 1); |
Gerd Hoffmann | 8bde680 | 2011-07-15 14:37:15 +0200 | [diff] [blame] | 722 | hid_init(&us->hid, kind, usb_hid_changed); |
Gerd Hoffmann | f85d283 | 2014-05-19 15:26:51 +0200 | [diff] [blame] | 723 | if (us->display && us->hid.s) { |
| 724 | qemu_input_handler_bind(us->hid.s, us->display, us->head, NULL); |
| 725 | } |
Gerd Hoffmann | 806b602 | 2009-08-31 14:23:59 +0200 | [diff] [blame] | 726 | } |
bellard | 09b26c5 | 2006-04-12 21:09:08 +0000 | [diff] [blame] | 727 | |
Gonglei | 276b7ac | 2014-09-19 14:48:36 +0800 | [diff] [blame] | 728 | static void usb_tablet_realize(USBDevice *dev, Error **errp) |
Gerd Hoffmann | 806b602 | 2009-08-31 14:23:59 +0200 | [diff] [blame] | 729 | { |
Hans de Goede | 427e3aa | 2012-11-17 12:47:18 +0100 | [diff] [blame] | 730 | |
Jan Vesely | ff326ff | 2014-09-29 22:21:09 -0400 | [diff] [blame] | 731 | usb_hid_initfn(dev, HID_TABLET, &desc_tablet, &desc_tablet2, errp); |
Gerd Hoffmann | 806b602 | 2009-08-31 14:23:59 +0200 | [diff] [blame] | 732 | } |
bellard | 1f6e24e | 2006-06-26 21:00:51 +0000 | [diff] [blame] | 733 | |
Gonglei | 276b7ac | 2014-09-19 14:48:36 +0800 | [diff] [blame] | 734 | static void usb_mouse_realize(USBDevice *dev, Error **errp) |
Gerd Hoffmann | 806b602 | 2009-08-31 14:23:59 +0200 | [diff] [blame] | 735 | { |
Jan Vesely | 58e4fee | 2014-09-29 22:21:10 -0400 | [diff] [blame] | 736 | usb_hid_initfn(dev, HID_MOUSE, &desc_mouse, &desc_mouse2, errp); |
Gerd Hoffmann | 806b602 | 2009-08-31 14:23:59 +0200 | [diff] [blame] | 737 | } |
| 738 | |
Gonglei | 276b7ac | 2014-09-19 14:48:36 +0800 | [diff] [blame] | 739 | static void usb_keyboard_realize(USBDevice *dev, Error **errp) |
Gerd Hoffmann | 806b602 | 2009-08-31 14:23:59 +0200 | [diff] [blame] | 740 | { |
Jan Vesely | b13ce07 | 2014-09-29 22:21:11 -0400 | [diff] [blame] | 741 | usb_hid_initfn(dev, HID_KEYBOARD, &desc_keyboard, &desc_keyboard2, errp); |
Gerd Hoffmann | 806b602 | 2009-08-31 14:23:59 +0200 | [diff] [blame] | 742 | } |
| 743 | |
Gerd Hoffmann | 3a3286b | 2011-10-12 12:54:35 +0200 | [diff] [blame] | 744 | static int usb_ptr_post_load(void *opaque, int version_id) |
| 745 | { |
| 746 | USBHIDState *s = opaque; |
| 747 | |
| 748 | if (s->dev.remote_wakeup) { |
| 749 | hid_pointer_activate(&s->hid); |
| 750 | } |
| 751 | return 0; |
| 752 | } |
| 753 | |
Gerd Hoffmann | ee59e6b | 2010-12-10 14:40:30 +0100 | [diff] [blame] | 754 | static const VMStateDescription vmstate_usb_ptr = { |
| 755 | .name = "usb-ptr", |
| 756 | .version_id = 1, |
| 757 | .minimum_version_id = 1, |
Gerd Hoffmann | 3a3286b | 2011-10-12 12:54:35 +0200 | [diff] [blame] | 758 | .post_load = usb_ptr_post_load, |
Juan Quintela | 6e3d652 | 2014-04-16 13:31:26 +0200 | [diff] [blame] | 759 | .fields = (VMStateField[]) { |
Gerd Hoffmann | ee59e6b | 2010-12-10 14:40:30 +0100 | [diff] [blame] | 760 | VMSTATE_USB_DEVICE(dev, USBHIDState), |
Michael Walle | 1f42d22 | 2011-08-09 23:54:54 +0200 | [diff] [blame] | 761 | VMSTATE_HID_POINTER_DEVICE(hid, USBHIDState), |
Gerd Hoffmann | ee59e6b | 2010-12-10 14:40:30 +0100 | [diff] [blame] | 762 | VMSTATE_END_OF_LIST() |
| 763 | } |
| 764 | }; |
| 765 | |
| 766 | static const VMStateDescription vmstate_usb_kbd = { |
| 767 | .name = "usb-kbd", |
| 768 | .version_id = 1, |
| 769 | .minimum_version_id = 1, |
Juan Quintela | 6e3d652 | 2014-04-16 13:31:26 +0200 | [diff] [blame] | 770 | .fields = (VMStateField[]) { |
Gerd Hoffmann | ee59e6b | 2010-12-10 14:40:30 +0100 | [diff] [blame] | 771 | VMSTATE_USB_DEVICE(dev, USBHIDState), |
Michael Walle | 1f42d22 | 2011-08-09 23:54:54 +0200 | [diff] [blame] | 772 | VMSTATE_HID_KEYBOARD_DEVICE(hid, USBHIDState), |
Gerd Hoffmann | ee59e6b | 2010-12-10 14:40:30 +0100 | [diff] [blame] | 773 | VMSTATE_END_OF_LIST() |
| 774 | } |
| 775 | }; |
| 776 | |
Anthony Liguori | 7f59560 | 2011-12-04 16:13:14 -0600 | [diff] [blame] | 777 | static void usb_hid_class_initfn(ObjectClass *klass, void *data) |
Anthony Liguori | 62aed76 | 2011-12-15 14:53:10 -0600 | [diff] [blame] | 778 | { |
| 779 | USBDeviceClass *uc = USB_DEVICE_CLASS(klass); |
| 780 | |
Anthony Liguori | 62aed76 | 2011-12-15 14:53:10 -0600 | [diff] [blame] | 781 | uc->handle_reset = usb_hid_handle_reset; |
| 782 | uc->handle_control = usb_hid_handle_control; |
| 783 | uc->handle_data = usb_hid_handle_data; |
Marc-André Lureau | c4fe970 | 2017-02-21 18:14:45 +0400 | [diff] [blame] | 784 | uc->unrealize = usb_hid_unrealize; |
Hans de Goede | 427e3aa | 2012-11-17 12:47:18 +0100 | [diff] [blame] | 785 | uc->handle_attach = usb_desc_attach; |
Anthony Liguori | 62aed76 | 2011-12-15 14:53:10 -0600 | [diff] [blame] | 786 | } |
| 787 | |
Gonglei | f566912 | 2015-05-06 20:55:26 +0800 | [diff] [blame] | 788 | static const TypeInfo usb_hid_type_info = { |
| 789 | .name = TYPE_USB_HID, |
| 790 | .parent = TYPE_USB_DEVICE, |
| 791 | .instance_size = sizeof(USBHIDState), |
| 792 | .abstract = true, |
| 793 | .class_init = usb_hid_class_initfn, |
| 794 | }; |
| 795 | |
Hans de Goede | 427e3aa | 2012-11-17 12:47:18 +0100 | [diff] [blame] | 796 | static Property usb_tablet_properties[] = { |
| 797 | DEFINE_PROP_UINT32("usb_version", USBHIDState, usb_version, 2), |
Gerd Hoffmann | f85d283 | 2014-05-19 15:26:51 +0200 | [diff] [blame] | 798 | DEFINE_PROP_STRING("display", USBHIDState, display), |
| 799 | DEFINE_PROP_UINT32("head", USBHIDState, head, 0), |
Hans de Goede | 427e3aa | 2012-11-17 12:47:18 +0100 | [diff] [blame] | 800 | DEFINE_PROP_END_OF_LIST(), |
| 801 | }; |
| 802 | |
Anthony Liguori | 7f59560 | 2011-12-04 16:13:14 -0600 | [diff] [blame] | 803 | static void usb_tablet_class_initfn(ObjectClass *klass, void *data) |
| 804 | { |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 805 | DeviceClass *dc = DEVICE_CLASS(klass); |
Anthony Liguori | 7f59560 | 2011-12-04 16:13:14 -0600 | [diff] [blame] | 806 | USBDeviceClass *uc = USB_DEVICE_CLASS(klass); |
| 807 | |
Gonglei | 276b7ac | 2014-09-19 14:48:36 +0800 | [diff] [blame] | 808 | uc->realize = usb_tablet_realize; |
Anthony Liguori | 7f59560 | 2011-12-04 16:13:14 -0600 | [diff] [blame] | 809 | uc->product_desc = "QEMU USB Tablet"; |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 810 | dc->vmsd = &vmstate_usb_ptr; |
Marc-André Lureau | 4f67d30 | 2020-01-10 19:30:32 +0400 | [diff] [blame] | 811 | device_class_set_props(dc, usb_tablet_properties); |
Marcel Apfelbaum | 31efd2e | 2013-08-22 20:11:36 +0300 | [diff] [blame] | 812 | set_bit(DEVICE_CATEGORY_INPUT, dc->categories); |
Anthony Liguori | 7f59560 | 2011-12-04 16:13:14 -0600 | [diff] [blame] | 813 | } |
| 814 | |
Andreas Färber | 8c43a6f | 2013-01-10 16:19:07 +0100 | [diff] [blame] | 815 | static const TypeInfo usb_tablet_info = { |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 816 | .name = "usb-tablet", |
Gonglei | f566912 | 2015-05-06 20:55:26 +0800 | [diff] [blame] | 817 | .parent = TYPE_USB_HID, |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 818 | .class_init = usb_tablet_class_initfn, |
Anthony Liguori | 62aed76 | 2011-12-15 14:53:10 -0600 | [diff] [blame] | 819 | }; |
| 820 | |
Jan Vesely | 58e4fee | 2014-09-29 22:21:10 -0400 | [diff] [blame] | 821 | static Property usb_mouse_properties[] = { |
| 822 | DEFINE_PROP_UINT32("usb_version", USBHIDState, usb_version, 2), |
| 823 | DEFINE_PROP_END_OF_LIST(), |
| 824 | }; |
| 825 | |
Anthony Liguori | 62aed76 | 2011-12-15 14:53:10 -0600 | [diff] [blame] | 826 | static void usb_mouse_class_initfn(ObjectClass *klass, void *data) |
| 827 | { |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 828 | DeviceClass *dc = DEVICE_CLASS(klass); |
Anthony Liguori | 62aed76 | 2011-12-15 14:53:10 -0600 | [diff] [blame] | 829 | USBDeviceClass *uc = USB_DEVICE_CLASS(klass); |
| 830 | |
Gonglei | 276b7ac | 2014-09-19 14:48:36 +0800 | [diff] [blame] | 831 | uc->realize = usb_mouse_realize; |
Anthony Liguori | 62aed76 | 2011-12-15 14:53:10 -0600 | [diff] [blame] | 832 | uc->product_desc = "QEMU USB Mouse"; |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 833 | dc->vmsd = &vmstate_usb_ptr; |
Marc-André Lureau | 4f67d30 | 2020-01-10 19:30:32 +0400 | [diff] [blame] | 834 | device_class_set_props(dc, usb_mouse_properties); |
Marcel Apfelbaum | 125ee0e | 2013-07-29 17:17:45 +0300 | [diff] [blame] | 835 | set_bit(DEVICE_CATEGORY_INPUT, dc->categories); |
Anthony Liguori | 62aed76 | 2011-12-15 14:53:10 -0600 | [diff] [blame] | 836 | } |
| 837 | |
Andreas Färber | 8c43a6f | 2013-01-10 16:19:07 +0100 | [diff] [blame] | 838 | static const TypeInfo usb_mouse_info = { |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 839 | .name = "usb-mouse", |
Gonglei | f566912 | 2015-05-06 20:55:26 +0800 | [diff] [blame] | 840 | .parent = TYPE_USB_HID, |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 841 | .class_init = usb_mouse_class_initfn, |
Anthony Liguori | 62aed76 | 2011-12-15 14:53:10 -0600 | [diff] [blame] | 842 | }; |
| 843 | |
Gerd Hoffmann | f85d283 | 2014-05-19 15:26:51 +0200 | [diff] [blame] | 844 | static Property usb_keyboard_properties[] = { |
Jan Vesely | b13ce07 | 2014-09-29 22:21:11 -0400 | [diff] [blame] | 845 | DEFINE_PROP_UINT32("usb_version", USBHIDState, usb_version, 2), |
Gerd Hoffmann | f85d283 | 2014-05-19 15:26:51 +0200 | [diff] [blame] | 846 | DEFINE_PROP_STRING("display", USBHIDState, display), |
| 847 | DEFINE_PROP_END_OF_LIST(), |
| 848 | }; |
| 849 | |
Anthony Liguori | 62aed76 | 2011-12-15 14:53:10 -0600 | [diff] [blame] | 850 | static void usb_keyboard_class_initfn(ObjectClass *klass, void *data) |
| 851 | { |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 852 | DeviceClass *dc = DEVICE_CLASS(klass); |
Anthony Liguori | 62aed76 | 2011-12-15 14:53:10 -0600 | [diff] [blame] | 853 | USBDeviceClass *uc = USB_DEVICE_CLASS(klass); |
| 854 | |
Gonglei | 276b7ac | 2014-09-19 14:48:36 +0800 | [diff] [blame] | 855 | uc->realize = usb_keyboard_realize; |
Anthony Liguori | 62aed76 | 2011-12-15 14:53:10 -0600 | [diff] [blame] | 856 | uc->product_desc = "QEMU USB Keyboard"; |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 857 | dc->vmsd = &vmstate_usb_kbd; |
Marc-André Lureau | 4f67d30 | 2020-01-10 19:30:32 +0400 | [diff] [blame] | 858 | device_class_set_props(dc, usb_keyboard_properties); |
Marcel Apfelbaum | 125ee0e | 2013-07-29 17:17:45 +0300 | [diff] [blame] | 859 | set_bit(DEVICE_CATEGORY_INPUT, dc->categories); |
Anthony Liguori | 62aed76 | 2011-12-15 14:53:10 -0600 | [diff] [blame] | 860 | } |
| 861 | |
Andreas Färber | 8c43a6f | 2013-01-10 16:19:07 +0100 | [diff] [blame] | 862 | static const TypeInfo usb_keyboard_info = { |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 863 | .name = "usb-kbd", |
Gonglei | f566912 | 2015-05-06 20:55:26 +0800 | [diff] [blame] | 864 | .parent = TYPE_USB_HID, |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 865 | .class_init = usb_keyboard_class_initfn, |
Gerd Hoffmann | 806b602 | 2009-08-31 14:23:59 +0200 | [diff] [blame] | 866 | }; |
| 867 | |
Andreas Färber | 83f7d43 | 2012-02-09 15:20:55 +0100 | [diff] [blame] | 868 | static void usb_hid_register_types(void) |
Gerd Hoffmann | 806b602 | 2009-08-31 14:23:59 +0200 | [diff] [blame] | 869 | { |
Gonglei | f566912 | 2015-05-06 20:55:26 +0800 | [diff] [blame] | 870 | type_register_static(&usb_hid_type_info); |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 871 | type_register_static(&usb_tablet_info); |
Anthony Liguori | ba02430 | 2011-12-08 14:56:53 -0600 | [diff] [blame] | 872 | usb_legacy_register("usb-tablet", "tablet", NULL); |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 873 | type_register_static(&usb_mouse_info); |
Anthony Liguori | ba02430 | 2011-12-08 14:56:53 -0600 | [diff] [blame] | 874 | usb_legacy_register("usb-mouse", "mouse", NULL); |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 875 | type_register_static(&usb_keyboard_info); |
Anthony Liguori | ba02430 | 2011-12-08 14:56:53 -0600 | [diff] [blame] | 876 | usb_legacy_register("usb-kbd", "keyboard", NULL); |
Gerd Hoffmann | 806b602 | 2009-08-31 14:23:59 +0200 | [diff] [blame] | 877 | } |
Andreas Färber | 83f7d43 | 2012-02-09 15:20:55 +0100 | [diff] [blame] | 878 | |
| 879 | type_init(usb_hid_register_types) |