197
169
0x81, /* u8 ep_bEndpointAddress; IN Endpoint 1 */
198
170
0x03, /* u8 ep_bmAttributes; Interrupt */
199
171
0x08, 0x00, /* u16 ep_wMaxPacketSize; */
200
0x0a, /* u8 ep_bInterval; (255ms -- usb 2.0 spec) */
203
static const uint8_t qemu_keyboard_config_descriptor[] = {
204
/* one configuration */
205
0x09, /* u8 bLength; */
206
USB_DT_CONFIG, /* u8 bDescriptorType; Configuration */
207
0x22, 0x00, /* u16 wTotalLength; */
208
0x01, /* u8 bNumInterfaces; (1) */
209
0x01, /* u8 bConfigurationValue; */
210
0x06, /* u8 iConfiguration; */
211
0xa0, /* u8 bmAttributes;
216
0x32, /* u8 MaxPower; */
219
* USB 2.0, single TT organization (mandatory):
220
* one interface, protocol 0
222
* USB 2.0, multiple TT organization (optional):
223
* two interfaces, protocols 1 (like single TT)
224
* and 2 (multiple TT mode) ... config is
230
0x09, /* u8 if_bLength; */
231
USB_DT_INTERFACE, /* u8 if_bDescriptorType; Interface */
232
0x00, /* u8 if_bInterfaceNumber; */
233
0x00, /* u8 if_bAlternateSetting; */
234
0x01, /* u8 if_bNumEndpoints; */
235
0x03, /* u8 if_bInterfaceClass; HID */
236
0x01, /* u8 if_bInterfaceSubClass; Boot */
237
0x01, /* u8 if_bInterfaceProtocol; Keyboard */
238
0x07, /* u8 if_iInterface; */
241
0x09, /* u8 bLength; */
242
USB_DT_HID, /* u8 bDescriptorType; */
243
0x11, 0x01, /* u16 HID_class */
244
0x00, /* u8 country_code */
245
0x01, /* u8 num_descriptors */
246
USB_DT_REPORT, /* u8 type; Report */
247
0x3f, 0x00, /* u16 len */
249
/* one endpoint (status change endpoint) */
250
0x07, /* u8 ep_bLength; */
251
USB_DT_ENDPOINT, /* u8 ep_bDescriptorType; Endpoint */
252
USB_DIR_IN | 0x01, /* u8 ep_bEndpointAddress; IN Endpoint 1 */
253
0x03, /* u8 ep_bmAttributes; Interrupt */
254
0x08, 0x00, /* u16 ep_wMaxPacketSize; */
255
0x0a, /* u8 ep_bInterval; (255ms -- usb 2.0 spec) */
172
0x03, /* u8 ep_bInterval; (255ms -- usb 2.0 spec) */
258
175
static const uint8_t qemu_mouse_hid_report_descriptor[] = {
259
0x05, 0x01, /* Usage Page (Generic Desktop) */
260
0x09, 0x02, /* Usage (Mouse) */
261
0xa1, 0x01, /* Collection (Application) */
262
0x09, 0x01, /* Usage (Pointer) */
263
0xa1, 0x00, /* Collection (Physical) */
264
0x05, 0x09, /* Usage Page (Button) */
265
0x19, 0x01, /* Usage Minimum (1) */
266
0x29, 0x03, /* Usage Maximum (3) */
267
0x15, 0x00, /* Logical Minimum (0) */
268
0x25, 0x01, /* Logical Maximum (1) */
269
0x95, 0x03, /* Report Count (3) */
270
0x75, 0x01, /* Report Size (1) */
271
0x81, 0x02, /* Input (Data, Variable, Absolute) */
272
0x95, 0x01, /* Report Count (1) */
273
0x75, 0x05, /* Report Size (5) */
274
0x81, 0x01, /* Input (Constant) */
275
0x05, 0x01, /* Usage Page (Generic Desktop) */
276
0x09, 0x30, /* Usage (X) */
277
0x09, 0x31, /* Usage (Y) */
278
0x09, 0x38, /* Usage (Wheel) */
279
0x15, 0x81, /* Logical Minimum (-0x7f) */
280
0x25, 0x7f, /* Logical Maximum (0x7f) */
281
0x75, 0x08, /* Report Size (8) */
282
0x95, 0x03, /* Report Count (3) */
283
0x81, 0x06, /* Input (Data, Variable, Relative) */
284
0xc0, /* End Collection */
285
0xc0, /* End Collection */
176
0x05, 0x01, 0x09, 0x02, 0xA1, 0x01, 0x09, 0x01,
177
0xA1, 0x00, 0x05, 0x09, 0x19, 0x01, 0x29, 0x03,
178
0x15, 0x00, 0x25, 0x01, 0x95, 0x03, 0x75, 0x01,
179
0x81, 0x02, 0x95, 0x01, 0x75, 0x05, 0x81, 0x01,
180
0x05, 0x01, 0x09, 0x30, 0x09, 0x31, 0x15, 0x81,
181
0x25, 0x7F, 0x75, 0x08, 0x95, 0x02, 0x81, 0x06,
288
185
static const uint8_t qemu_tablet_hid_report_descriptor[] = {
289
0x05, 0x01, /* Usage Page (Generic Desktop) */
290
0x09, 0x01, /* Usage (Pointer) */
291
0xa1, 0x01, /* Collection (Application) */
292
0x09, 0x01, /* Usage (Pointer) */
293
0xa1, 0x00, /* Collection (Physical) */
294
0x05, 0x09, /* Usage Page (Button) */
295
0x19, 0x01, /* Usage Minimum (1) */
296
0x29, 0x03, /* Usage Maximum (3) */
297
0x15, 0x00, /* Logical Minimum (0) */
298
0x25, 0x01, /* Logical Maximum (1) */
299
0x95, 0x03, /* Report Count (3) */
300
0x75, 0x01, /* Report Size (1) */
301
0x81, 0x02, /* Input (Data, Variable, Absolute) */
302
0x95, 0x01, /* Report Count (1) */
303
0x75, 0x05, /* Report Size (5) */
304
0x81, 0x01, /* Input (Constant) */
305
0x05, 0x01, /* Usage Page (Generic Desktop) */
306
0x09, 0x30, /* Usage (X) */
307
0x09, 0x31, /* Usage (Y) */
308
0x15, 0x00, /* Logical Minimum (0) */
309
0x26, 0xfe, 0x7f, /* Logical Maximum (0x7fff) */
310
0x35, 0x00, /* Physical Minimum (0) */
311
0x46, 0xfe, 0x7f, /* Physical Maximum (0x7fff) */
312
0x75, 0x10, /* Report Size (16) */
313
0x95, 0x02, /* Report Count (2) */
314
0x81, 0x02, /* Input (Data, Variable, Absolute) */
315
0x05, 0x01, /* Usage Page (Generic Desktop) */
316
0x09, 0x38, /* Usage (Wheel) */
317
0x15, 0x81, /* Logical Minimum (-0x7f) */
318
0x25, 0x7f, /* Logical Maximum (0x7f) */
319
0x35, 0x00, /* Physical Minimum (same as logical) */
320
0x45, 0x00, /* Physical Maximum (same as logical) */
321
0x75, 0x08, /* Report Size (8) */
322
0x95, 0x01, /* Report Count (1) */
323
0x81, 0x06, /* Input (Data, Variable, Relative) */
324
0xc0, /* End Collection */
325
0xc0, /* End Collection */
328
static const uint8_t qemu_keyboard_hid_report_descriptor[] = {
329
0x05, 0x01, /* Usage Page (Generic Desktop) */
330
0x09, 0x06, /* Usage (Keyboard) */
331
0xa1, 0x01, /* Collection (Application) */
332
0x75, 0x01, /* Report Size (1) */
333
0x95, 0x08, /* Report Count (8) */
334
0x05, 0x07, /* Usage Page (Key Codes) */
335
0x19, 0xe0, /* Usage Minimum (224) */
336
0x29, 0xe7, /* Usage Maximum (231) */
337
0x15, 0x00, /* Logical Minimum (0) */
338
0x25, 0x01, /* Logical Maximum (1) */
339
0x81, 0x02, /* Input (Data, Variable, Absolute) */
340
0x95, 0x01, /* Report Count (1) */
341
0x75, 0x08, /* Report Size (8) */
342
0x81, 0x01, /* Input (Constant) */
343
0x95, 0x05, /* Report Count (5) */
344
0x75, 0x01, /* Report Size (1) */
345
0x05, 0x08, /* Usage Page (LEDs) */
346
0x19, 0x01, /* Usage Minimum (1) */
347
0x29, 0x05, /* Usage Maximum (5) */
348
0x91, 0x02, /* Output (Data, Variable, Absolute) */
349
0x95, 0x01, /* Report Count (1) */
350
0x75, 0x03, /* Report Size (3) */
351
0x91, 0x01, /* Output (Constant) */
352
0x95, 0x06, /* Report Count (6) */
353
0x75, 0x08, /* Report Size (8) */
354
0x15, 0x00, /* Logical Minimum (0) */
355
0x25, 0xff, /* Logical Maximum (255) */
356
0x05, 0x07, /* Usage Page (Key Codes) */
357
0x19, 0x00, /* Usage Minimum (0) */
358
0x29, 0xff, /* Usage Maximum (255) */
359
0x81, 0x00, /* Input (Data, Array) */
360
0xc0, /* End Collection */
363
#define USB_HID_USAGE_ERROR_ROLLOVER 0x01
364
#define USB_HID_USAGE_POSTFAIL 0x02
365
#define USB_HID_USAGE_ERROR_UNDEFINED 0x03
367
/* Indices are QEMU keycodes, values are from HID Usage Table. Indices
368
* above 0x80 are for keys that come after 0xe0 or 0xe1+0x1d or 0xe1+0x9d. */
369
static const uint8_t usb_hid_usage_keys[0x100] = {
370
0x00, 0x29, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23,
371
0x24, 0x25, 0x26, 0x27, 0x2d, 0x2e, 0x2a, 0x2b,
372
0x14, 0x1a, 0x08, 0x15, 0x17, 0x1c, 0x18, 0x0c,
373
0x12, 0x13, 0x2f, 0x30, 0x28, 0xe0, 0x04, 0x16,
374
0x07, 0x09, 0x0a, 0x0b, 0x0d, 0x0e, 0x0f, 0x33,
375
0x34, 0x35, 0xe1, 0x31, 0x1d, 0x1b, 0x06, 0x19,
376
0x05, 0x11, 0x10, 0x36, 0x37, 0x38, 0xe5, 0x55,
377
0xe2, 0x2c, 0x32, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e,
378
0x3f, 0x40, 0x41, 0x42, 0x43, 0x53, 0x47, 0x5f,
379
0x60, 0x61, 0x56, 0x5c, 0x5d, 0x5e, 0x57, 0x59,
380
0x5a, 0x5b, 0x62, 0x63, 0x00, 0x00, 0x00, 0x44,
381
0x45, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e,
382
0xe8, 0xe9, 0x71, 0x72, 0x73, 0x00, 0x00, 0x00,
383
0x00, 0x00, 0x00, 0x85, 0x00, 0x00, 0x00, 0x00,
384
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
385
0x00, 0x00, 0x00, 0x00, 0x00, 0xe3, 0xe7, 0x65,
387
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
388
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
389
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
390
0x00, 0x00, 0x00, 0x00, 0x58, 0xe4, 0x00, 0x00,
391
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
392
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
393
0x00, 0x00, 0x00, 0x00, 0x00, 0x54, 0x00, 0x46,
394
0xe6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
395
0x00, 0x00, 0x00, 0x00, 0x00, 0x48, 0x00, 0x4a,
396
0x52, 0x4b, 0x00, 0x50, 0x00, 0x4f, 0x00, 0x4d,
397
0x51, 0x4e, 0x49, 0x4c, 0x00, 0x00, 0x00, 0x00,
398
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
399
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
400
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
401
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
402
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
186
0x05, 0x01, /* Usage Page Generic Desktop */
187
0x09, 0x01, /* Usage Mouse */
188
0xA1, 0x01, /* Collection Application */
189
0x09, 0x01, /* Usage Pointer */
190
0xA1, 0x00, /* Collection Physical */
191
0x05, 0x09, /* Usage Page Button */
192
0x19, 0x01, /* Usage Minimum Button 1 */
193
0x29, 0x03, /* Usage Maximum Button 3 */
194
0x15, 0x00, /* Logical Minimum 0 */
195
0x25, 0x01, /* Logical Maximum 1 */
196
0x95, 0x03, /* Report Count 3 */
197
0x75, 0x01, /* Report Size 1 */
198
0x81, 0x02, /* Input (Data, Var, Abs) */
199
0x95, 0x01, /* Report Count 1 */
200
0x75, 0x05, /* Report Size 5 */
201
0x81, 0x01, /* Input (Cnst, Var, Abs) */
202
0x05, 0x01, /* Usage Page Generic Desktop */
203
0x09, 0x30, /* Usage X */
204
0x09, 0x31, /* Usage Y */
205
0x15, 0x00, /* Logical Minimum 0 */
206
0x26, 0xFF, 0x7F, /* Logical Maximum 0x7fff */
207
0x35, 0x00, /* Physical Minimum 0 */
208
0x46, 0xFE, 0x7F, /* Physical Maximum 0x7fff */
209
0x75, 0x10, /* Report Size 16 */
210
0x95, 0x02, /* Report Count 2 */
211
0x81, 0x02, /* Input (Data, Var, Abs) */
212
0x05, 0x01, /* Usage Page Generic Desktop */
213
0x09, 0x38, /* Usage Wheel */
214
0x15, 0x81, /* Logical Minimum -127 */
215
0x25, 0x7F, /* Logical Maximum 127 */
216
0x35, 0x00, /* Physical Minimum 0 (same as logical) */
217
0x45, 0x00, /* Physical Maximum 0 (same as logical) */
218
0x75, 0x08, /* Report Size 8 */
219
0x95, 0x01, /* Report Count 1 */
220
0x81, 0x02, /* Input (Data, Var, Rel) */
221
0xC0, /* End Collection */
222
0xC0, /* End Collection */
405
225
static void usb_mouse_event(void *opaque,
406
226
int dx1, int dy1, int dz1, int buttons_state)
408
USBHIDState *hs = opaque;
409
USBMouseState *s = &hs->ptr;
228
USBMouseState *s = opaque;
414
233
s->buttons_state = buttons_state;
418
236
static void usb_tablet_event(void *opaque,
419
237
int x, int y, int dz, int buttons_state)
421
USBHIDState *hs = opaque;
422
USBMouseState *s = &hs->ptr;
239
USBMouseState *s = opaque;
427
244
s->buttons_state = buttons_state;
431
static void usb_keyboard_event(void *opaque, int keycode)
433
USBHIDState *hs = opaque;
434
USBKeyboardState *s = &hs->kbd;
435
uint8_t hid_code, key;
438
key = keycode & 0x7f;
439
hid_code = usb_hid_usage_keys[key | ((s->modifiers >> 1) & (1 << 7))];
440
s->modifiers &= ~(1 << 8);
449
if (s->modifiers & (1 << 9)) {
450
s->modifiers ^= 3 << 8;
454
if (keycode & (1 << 7)) {
455
s->modifiers &= ~(1 << (hid_code & 0x0f));
459
s->modifiers |= 1 << (hid_code & 0x0f);
463
if (keycode & (1 << 7)) {
464
for (i = s->keys - 1; i >= 0; i --)
465
if (s->key[i] == hid_code) {
466
s->key[i] = s->key[-- s->keys];
467
s->key[s->keys] = 0x00;
471
for (i = s->keys - 1; i >= 0; i --)
472
if (s->key[i] == hid_code)
474
if (s->keys < sizeof(s->key))
475
s->key[s->keys ++] = hid_code;
479
247
static inline int int_clamp(int val, int vmin, int vmax)