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