]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * USB HID support for Linux | |
3 | * | |
4 | * Copyright (c) 1999 Andreas Gal | |
bf0964dc MH |
5 | * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz> |
6 | * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc | |
1da177e4 LT |
7 | */ |
8 | ||
9 | /* | |
10 | * This program is free software; you can redistribute it and/or modify it | |
11 | * under the terms of the GNU General Public License as published by the Free | |
12 | * Software Foundation; either version 2 of the License, or (at your option) | |
13 | * any later version. | |
14 | */ | |
15 | ||
16 | #include <linux/module.h> | |
17 | #include <linux/slab.h> | |
18 | #include <linux/init.h> | |
19 | #include <linux/kernel.h> | |
20 | #include <linux/sched.h> | |
21 | #include <linux/list.h> | |
22 | #include <linux/mm.h> | |
23 | #include <linux/smp_lock.h> | |
24 | #include <linux/spinlock.h> | |
25 | #include <asm/unaligned.h> | |
26 | #include <asm/byteorder.h> | |
27 | #include <linux/input.h> | |
28 | #include <linux/wait.h> | |
29 | ||
30 | #undef DEBUG | |
31 | #undef DEBUG_DATA | |
32 | ||
33 | #include <linux/usb.h> | |
34 | ||
35 | #include "hid.h" | |
36 | #include <linux/hiddev.h> | |
37 | ||
38 | /* | |
39 | * Version Information | |
40 | */ | |
41 | ||
bf0964dc | 42 | #define DRIVER_VERSION "v2.6" |
1da177e4 LT |
43 | #define DRIVER_AUTHOR "Andreas Gal, Vojtech Pavlik" |
44 | #define DRIVER_DESC "USB HID core driver" | |
45 | #define DRIVER_LICENSE "GPL" | |
46 | ||
47 | static char *hid_types[] = {"Device", "Pointer", "Mouse", "Device", "Joystick", | |
48 | "Gamepad", "Keyboard", "Keypad", "Multi-Axis Controller"}; | |
49 | /* | |
50 | * Module parameters. | |
51 | */ | |
52 | ||
53 | static unsigned int hid_mousepoll_interval; | |
54 | module_param_named(mousepoll, hid_mousepoll_interval, uint, 0644); | |
55 | MODULE_PARM_DESC(mousepoll, "Polling interval of mice"); | |
56 | ||
57 | /* | |
58 | * Register a new report for a device. | |
59 | */ | |
60 | ||
61 | static struct hid_report *hid_register_report(struct hid_device *device, unsigned type, unsigned id) | |
62 | { | |
63 | struct hid_report_enum *report_enum = device->report_enum + type; | |
64 | struct hid_report *report; | |
65 | ||
66 | if (report_enum->report_id_hash[id]) | |
67 | return report_enum->report_id_hash[id]; | |
68 | ||
bbdb7daf | 69 | if (!(report = kzalloc(sizeof(struct hid_report), GFP_KERNEL))) |
1da177e4 | 70 | return NULL; |
1da177e4 LT |
71 | |
72 | if (id != 0) | |
73 | report_enum->numbered = 1; | |
74 | ||
75 | report->id = id; | |
76 | report->type = type; | |
77 | report->size = 0; | |
78 | report->device = device; | |
79 | report_enum->report_id_hash[id] = report; | |
80 | ||
81 | list_add_tail(&report->list, &report_enum->report_list); | |
82 | ||
83 | return report; | |
84 | } | |
85 | ||
86 | /* | |
87 | * Register a new field for this report. | |
88 | */ | |
89 | ||
90 | static struct hid_field *hid_register_field(struct hid_report *report, unsigned usages, unsigned values) | |
91 | { | |
92 | struct hid_field *field; | |
93 | ||
94 | if (report->maxfield == HID_MAX_FIELDS) { | |
95 | dbg("too many fields in report"); | |
96 | return NULL; | |
97 | } | |
98 | ||
bbdb7daf | 99 | if (!(field = kzalloc(sizeof(struct hid_field) + usages * sizeof(struct hid_usage) |
1da177e4 LT |
100 | + values * sizeof(unsigned), GFP_KERNEL))) return NULL; |
101 | ||
1da177e4 LT |
102 | field->index = report->maxfield++; |
103 | report->field[field->index] = field; | |
104 | field->usage = (struct hid_usage *)(field + 1); | |
105 | field->value = (unsigned *)(field->usage + usages); | |
106 | field->report = report; | |
107 | ||
108 | return field; | |
109 | } | |
110 | ||
111 | /* | |
112 | * Open a collection. The type/usage is pushed on the stack. | |
113 | */ | |
114 | ||
115 | static int open_collection(struct hid_parser *parser, unsigned type) | |
116 | { | |
117 | struct hid_collection *collection; | |
118 | unsigned usage; | |
119 | ||
120 | usage = parser->local.usage[0]; | |
121 | ||
122 | if (parser->collection_stack_ptr == HID_COLLECTION_STACK_SIZE) { | |
123 | dbg("collection stack overflow"); | |
124 | return -1; | |
125 | } | |
126 | ||
127 | if (parser->device->maxcollection == parser->device->collection_size) { | |
128 | collection = kmalloc(sizeof(struct hid_collection) * | |
129 | parser->device->collection_size * 2, GFP_KERNEL); | |
130 | if (collection == NULL) { | |
131 | dbg("failed to reallocate collection array"); | |
132 | return -1; | |
133 | } | |
134 | memcpy(collection, parser->device->collection, | |
135 | sizeof(struct hid_collection) * | |
136 | parser->device->collection_size); | |
137 | memset(collection + parser->device->collection_size, 0, | |
138 | sizeof(struct hid_collection) * | |
139 | parser->device->collection_size); | |
140 | kfree(parser->device->collection); | |
141 | parser->device->collection = collection; | |
142 | parser->device->collection_size *= 2; | |
143 | } | |
144 | ||
145 | parser->collection_stack[parser->collection_stack_ptr++] = | |
146 | parser->device->maxcollection; | |
147 | ||
148 | collection = parser->device->collection + | |
149 | parser->device->maxcollection++; | |
150 | collection->type = type; | |
151 | collection->usage = usage; | |
152 | collection->level = parser->collection_stack_ptr - 1; | |
153 | ||
154 | if (type == HID_COLLECTION_APPLICATION) | |
155 | parser->device->maxapplication++; | |
156 | ||
157 | return 0; | |
158 | } | |
159 | ||
160 | /* | |
161 | * Close a collection. | |
162 | */ | |
163 | ||
164 | static int close_collection(struct hid_parser *parser) | |
165 | { | |
166 | if (!parser->collection_stack_ptr) { | |
167 | dbg("collection stack underflow"); | |
168 | return -1; | |
169 | } | |
170 | parser->collection_stack_ptr--; | |
171 | return 0; | |
172 | } | |
173 | ||
174 | /* | |
175 | * Climb up the stack, search for the specified collection type | |
176 | * and return the usage. | |
177 | */ | |
178 | ||
179 | static unsigned hid_lookup_collection(struct hid_parser *parser, unsigned type) | |
180 | { | |
181 | int n; | |
182 | for (n = parser->collection_stack_ptr - 1; n >= 0; n--) | |
183 | if (parser->device->collection[parser->collection_stack[n]].type == type) | |
184 | return parser->device->collection[parser->collection_stack[n]].usage; | |
185 | return 0; /* we know nothing about this usage type */ | |
186 | } | |
187 | ||
188 | /* | |
189 | * Add a usage to the temporary parser table. | |
190 | */ | |
191 | ||
192 | static int hid_add_usage(struct hid_parser *parser, unsigned usage) | |
193 | { | |
194 | if (parser->local.usage_index >= HID_MAX_USAGES) { | |
195 | dbg("usage index exceeded"); | |
196 | return -1; | |
197 | } | |
198 | parser->local.usage[parser->local.usage_index] = usage; | |
199 | parser->local.collection_index[parser->local.usage_index] = | |
200 | parser->collection_stack_ptr ? | |
201 | parser->collection_stack[parser->collection_stack_ptr - 1] : 0; | |
202 | parser->local.usage_index++; | |
203 | return 0; | |
204 | } | |
205 | ||
206 | /* | |
207 | * Register a new field for this report. | |
208 | */ | |
209 | ||
210 | static int hid_add_field(struct hid_parser *parser, unsigned report_type, unsigned flags) | |
211 | { | |
212 | struct hid_report *report; | |
213 | struct hid_field *field; | |
214 | int usages; | |
215 | unsigned offset; | |
216 | int i; | |
217 | ||
218 | if (!(report = hid_register_report(parser->device, report_type, parser->global.report_id))) { | |
219 | dbg("hid_register_report failed"); | |
220 | return -1; | |
221 | } | |
222 | ||
223 | if (parser->global.logical_maximum < parser->global.logical_minimum) { | |
224 | dbg("logical range invalid %d %d", parser->global.logical_minimum, parser->global.logical_maximum); | |
225 | return -1; | |
226 | } | |
227 | ||
228 | offset = report->size; | |
229 | report->size += parser->global.report_size * parser->global.report_count; | |
230 | ||
231 | if (!parser->local.usage_index) /* Ignore padding fields */ | |
05f091ab | 232 | return 0; |
1da177e4 LT |
233 | |
234 | usages = max_t(int, parser->local.usage_index, parser->global.report_count); | |
235 | ||
236 | if ((field = hid_register_field(report, usages, parser->global.report_count)) == NULL) | |
237 | return 0; | |
238 | ||
239 | field->physical = hid_lookup_collection(parser, HID_COLLECTION_PHYSICAL); | |
240 | field->logical = hid_lookup_collection(parser, HID_COLLECTION_LOGICAL); | |
241 | field->application = hid_lookup_collection(parser, HID_COLLECTION_APPLICATION); | |
242 | ||
243 | for (i = 0; i < usages; i++) { | |
244 | int j = i; | |
245 | /* Duplicate the last usage we parsed if we have excess values */ | |
246 | if (i >= parser->local.usage_index) | |
247 | j = parser->local.usage_index - 1; | |
248 | field->usage[i].hid = parser->local.usage[j]; | |
249 | field->usage[i].collection_index = | |
250 | parser->local.collection_index[j]; | |
251 | } | |
252 | ||
253 | field->maxusage = usages; | |
254 | field->flags = flags; | |
255 | field->report_offset = offset; | |
256 | field->report_type = report_type; | |
257 | field->report_size = parser->global.report_size; | |
258 | field->report_count = parser->global.report_count; | |
259 | field->logical_minimum = parser->global.logical_minimum; | |
260 | field->logical_maximum = parser->global.logical_maximum; | |
261 | field->physical_minimum = parser->global.physical_minimum; | |
262 | field->physical_maximum = parser->global.physical_maximum; | |
263 | field->unit_exponent = parser->global.unit_exponent; | |
264 | field->unit = parser->global.unit; | |
265 | ||
266 | return 0; | |
267 | } | |
268 | ||
269 | /* | |
270 | * Read data value from item. | |
271 | */ | |
272 | ||
273 | static __inline__ __u32 item_udata(struct hid_item *item) | |
274 | { | |
275 | switch (item->size) { | |
276 | case 1: return item->data.u8; | |
277 | case 2: return item->data.u16; | |
278 | case 4: return item->data.u32; | |
279 | } | |
280 | return 0; | |
281 | } | |
282 | ||
283 | static __inline__ __s32 item_sdata(struct hid_item *item) | |
284 | { | |
285 | switch (item->size) { | |
286 | case 1: return item->data.s8; | |
287 | case 2: return item->data.s16; | |
288 | case 4: return item->data.s32; | |
289 | } | |
290 | return 0; | |
291 | } | |
292 | ||
293 | /* | |
294 | * Process a global item. | |
295 | */ | |
296 | ||
297 | static int hid_parser_global(struct hid_parser *parser, struct hid_item *item) | |
298 | { | |
299 | switch (item->tag) { | |
300 | ||
301 | case HID_GLOBAL_ITEM_TAG_PUSH: | |
302 | ||
303 | if (parser->global_stack_ptr == HID_GLOBAL_STACK_SIZE) { | |
304 | dbg("global enviroment stack overflow"); | |
305 | return -1; | |
306 | } | |
307 | ||
308 | memcpy(parser->global_stack + parser->global_stack_ptr++, | |
309 | &parser->global, sizeof(struct hid_global)); | |
310 | return 0; | |
311 | ||
312 | case HID_GLOBAL_ITEM_TAG_POP: | |
313 | ||
314 | if (!parser->global_stack_ptr) { | |
315 | dbg("global enviroment stack underflow"); | |
316 | return -1; | |
317 | } | |
318 | ||
319 | memcpy(&parser->global, parser->global_stack + --parser->global_stack_ptr, | |
320 | sizeof(struct hid_global)); | |
321 | return 0; | |
322 | ||
323 | case HID_GLOBAL_ITEM_TAG_USAGE_PAGE: | |
324 | parser->global.usage_page = item_udata(item); | |
325 | return 0; | |
326 | ||
327 | case HID_GLOBAL_ITEM_TAG_LOGICAL_MINIMUM: | |
328 | parser->global.logical_minimum = item_sdata(item); | |
329 | return 0; | |
330 | ||
331 | case HID_GLOBAL_ITEM_TAG_LOGICAL_MAXIMUM: | |
332 | if (parser->global.logical_minimum < 0) | |
333 | parser->global.logical_maximum = item_sdata(item); | |
334 | else | |
335 | parser->global.logical_maximum = item_udata(item); | |
336 | return 0; | |
337 | ||
338 | case HID_GLOBAL_ITEM_TAG_PHYSICAL_MINIMUM: | |
339 | parser->global.physical_minimum = item_sdata(item); | |
340 | return 0; | |
341 | ||
342 | case HID_GLOBAL_ITEM_TAG_PHYSICAL_MAXIMUM: | |
343 | if (parser->global.physical_minimum < 0) | |
344 | parser->global.physical_maximum = item_sdata(item); | |
345 | else | |
346 | parser->global.physical_maximum = item_udata(item); | |
347 | return 0; | |
348 | ||
349 | case HID_GLOBAL_ITEM_TAG_UNIT_EXPONENT: | |
350 | parser->global.unit_exponent = item_sdata(item); | |
351 | return 0; | |
352 | ||
353 | case HID_GLOBAL_ITEM_TAG_UNIT: | |
354 | parser->global.unit = item_udata(item); | |
355 | return 0; | |
356 | ||
357 | case HID_GLOBAL_ITEM_TAG_REPORT_SIZE: | |
358 | if ((parser->global.report_size = item_udata(item)) > 32) { | |
359 | dbg("invalid report_size %d", parser->global.report_size); | |
360 | return -1; | |
361 | } | |
362 | return 0; | |
363 | ||
364 | case HID_GLOBAL_ITEM_TAG_REPORT_COUNT: | |
365 | if ((parser->global.report_count = item_udata(item)) > HID_MAX_USAGES) { | |
366 | dbg("invalid report_count %d", parser->global.report_count); | |
367 | return -1; | |
368 | } | |
369 | return 0; | |
370 | ||
371 | case HID_GLOBAL_ITEM_TAG_REPORT_ID: | |
372 | if ((parser->global.report_id = item_udata(item)) == 0) { | |
373 | dbg("report_id 0 is invalid"); | |
374 | return -1; | |
375 | } | |
376 | return 0; | |
377 | ||
378 | default: | |
379 | dbg("unknown global tag 0x%x", item->tag); | |
380 | return -1; | |
381 | } | |
382 | } | |
383 | ||
384 | /* | |
385 | * Process a local item. | |
386 | */ | |
387 | ||
388 | static int hid_parser_local(struct hid_parser *parser, struct hid_item *item) | |
389 | { | |
390 | __u32 data; | |
391 | unsigned n; | |
392 | ||
393 | if (item->size == 0) { | |
394 | dbg("item data expected for local item"); | |
395 | return -1; | |
396 | } | |
397 | ||
398 | data = item_udata(item); | |
399 | ||
400 | switch (item->tag) { | |
401 | ||
402 | case HID_LOCAL_ITEM_TAG_DELIMITER: | |
403 | ||
404 | if (data) { | |
405 | /* | |
406 | * We treat items before the first delimiter | |
407 | * as global to all usage sets (branch 0). | |
408 | * In the moment we process only these global | |
409 | * items and the first delimiter set. | |
410 | */ | |
411 | if (parser->local.delimiter_depth != 0) { | |
412 | dbg("nested delimiters"); | |
413 | return -1; | |
414 | } | |
415 | parser->local.delimiter_depth++; | |
416 | parser->local.delimiter_branch++; | |
417 | } else { | |
418 | if (parser->local.delimiter_depth < 1) { | |
419 | dbg("bogus close delimiter"); | |
420 | return -1; | |
421 | } | |
422 | parser->local.delimiter_depth--; | |
423 | } | |
424 | return 1; | |
425 | ||
426 | case HID_LOCAL_ITEM_TAG_USAGE: | |
427 | ||
428 | if (parser->local.delimiter_branch > 1) { | |
429 | dbg("alternative usage ignored"); | |
430 | return 0; | |
431 | } | |
432 | ||
433 | if (item->size <= 2) | |
434 | data = (parser->global.usage_page << 16) + data; | |
435 | ||
436 | return hid_add_usage(parser, data); | |
437 | ||
438 | case HID_LOCAL_ITEM_TAG_USAGE_MINIMUM: | |
439 | ||
440 | if (parser->local.delimiter_branch > 1) { | |
441 | dbg("alternative usage ignored"); | |
442 | return 0; | |
443 | } | |
444 | ||
445 | if (item->size <= 2) | |
446 | data = (parser->global.usage_page << 16) + data; | |
447 | ||
448 | parser->local.usage_minimum = data; | |
449 | return 0; | |
450 | ||
451 | case HID_LOCAL_ITEM_TAG_USAGE_MAXIMUM: | |
452 | ||
453 | if (parser->local.delimiter_branch > 1) { | |
454 | dbg("alternative usage ignored"); | |
455 | return 0; | |
456 | } | |
457 | ||
458 | if (item->size <= 2) | |
459 | data = (parser->global.usage_page << 16) + data; | |
460 | ||
461 | for (n = parser->local.usage_minimum; n <= data; n++) | |
462 | if (hid_add_usage(parser, n)) { | |
463 | dbg("hid_add_usage failed\n"); | |
464 | return -1; | |
465 | } | |
466 | return 0; | |
467 | ||
468 | default: | |
469 | ||
470 | dbg("unknown local item tag 0x%x", item->tag); | |
471 | return 0; | |
472 | } | |
473 | return 0; | |
474 | } | |
475 | ||
476 | /* | |
477 | * Process a main item. | |
478 | */ | |
479 | ||
480 | static int hid_parser_main(struct hid_parser *parser, struct hid_item *item) | |
481 | { | |
482 | __u32 data; | |
483 | int ret; | |
484 | ||
485 | data = item_udata(item); | |
486 | ||
487 | switch (item->tag) { | |
488 | case HID_MAIN_ITEM_TAG_BEGIN_COLLECTION: | |
489 | ret = open_collection(parser, data & 0xff); | |
490 | break; | |
491 | case HID_MAIN_ITEM_TAG_END_COLLECTION: | |
492 | ret = close_collection(parser); | |
493 | break; | |
494 | case HID_MAIN_ITEM_TAG_INPUT: | |
495 | ret = hid_add_field(parser, HID_INPUT_REPORT, data); | |
496 | break; | |
497 | case HID_MAIN_ITEM_TAG_OUTPUT: | |
498 | ret = hid_add_field(parser, HID_OUTPUT_REPORT, data); | |
499 | break; | |
500 | case HID_MAIN_ITEM_TAG_FEATURE: | |
501 | ret = hid_add_field(parser, HID_FEATURE_REPORT, data); | |
502 | break; | |
503 | default: | |
504 | dbg("unknown main item tag 0x%x", item->tag); | |
505 | ret = 0; | |
506 | } | |
507 | ||
508 | memset(&parser->local, 0, sizeof(parser->local)); /* Reset the local parser environment */ | |
509 | ||
510 | return ret; | |
511 | } | |
512 | ||
513 | /* | |
514 | * Process a reserved item. | |
515 | */ | |
516 | ||
517 | static int hid_parser_reserved(struct hid_parser *parser, struct hid_item *item) | |
518 | { | |
519 | dbg("reserved item type, tag 0x%x", item->tag); | |
520 | return 0; | |
521 | } | |
522 | ||
523 | /* | |
524 | * Free a report and all registered fields. The field->usage and | |
525 | * field->value table's are allocated behind the field, so we need | |
526 | * only to free(field) itself. | |
527 | */ | |
528 | ||
529 | static void hid_free_report(struct hid_report *report) | |
530 | { | |
531 | unsigned n; | |
532 | ||
533 | for (n = 0; n < report->maxfield; n++) | |
534 | kfree(report->field[n]); | |
535 | kfree(report); | |
536 | } | |
537 | ||
538 | /* | |
539 | * Free a device structure, all reports, and all fields. | |
540 | */ | |
541 | ||
542 | static void hid_free_device(struct hid_device *device) | |
543 | { | |
544 | unsigned i,j; | |
545 | ||
1da177e4 LT |
546 | for (i = 0; i < HID_REPORT_TYPES; i++) { |
547 | struct hid_report_enum *report_enum = device->report_enum + i; | |
548 | ||
549 | for (j = 0; j < 256; j++) { | |
550 | struct hid_report *report = report_enum->report_id_hash[j]; | |
551 | if (report) | |
552 | hid_free_report(report); | |
553 | } | |
554 | } | |
555 | ||
1bc3c9e1 | 556 | kfree(device->rdesc); |
1da177e4 LT |
557 | kfree(device); |
558 | } | |
559 | ||
560 | /* | |
561 | * Fetch a report description item from the data stream. We support long | |
562 | * items, though they are not used yet. | |
563 | */ | |
564 | ||
565 | static u8 *fetch_item(__u8 *start, __u8 *end, struct hid_item *item) | |
566 | { | |
567 | u8 b; | |
568 | ||
569 | if ((end - start) <= 0) | |
570 | return NULL; | |
571 | ||
572 | b = *start++; | |
573 | ||
574 | item->type = (b >> 2) & 3; | |
575 | item->tag = (b >> 4) & 15; | |
576 | ||
577 | if (item->tag == HID_ITEM_TAG_LONG) { | |
578 | ||
579 | item->format = HID_ITEM_FORMAT_LONG; | |
580 | ||
581 | if ((end - start) < 2) | |
582 | return NULL; | |
583 | ||
584 | item->size = *start++; | |
585 | item->tag = *start++; | |
586 | ||
587 | if ((end - start) < item->size) | |
588 | return NULL; | |
589 | ||
590 | item->data.longdata = start; | |
591 | start += item->size; | |
592 | return start; | |
593 | } | |
594 | ||
595 | item->format = HID_ITEM_FORMAT_SHORT; | |
596 | item->size = b & 3; | |
597 | ||
598 | switch (item->size) { | |
599 | ||
600 | case 0: | |
601 | return start; | |
602 | ||
603 | case 1: | |
604 | if ((end - start) < 1) | |
605 | return NULL; | |
606 | item->data.u8 = *start++; | |
607 | return start; | |
608 | ||
609 | case 2: | |
610 | if ((end - start) < 2) | |
611 | return NULL; | |
612 | item->data.u16 = le16_to_cpu(get_unaligned((__le16*)start)); | |
613 | start = (__u8 *)((__le16 *)start + 1); | |
614 | return start; | |
615 | ||
616 | case 3: | |
617 | item->size++; | |
618 | if ((end - start) < 4) | |
619 | return NULL; | |
620 | item->data.u32 = le32_to_cpu(get_unaligned((__le32*)start)); | |
621 | start = (__u8 *)((__le32 *)start + 1); | |
622 | return start; | |
623 | } | |
624 | ||
625 | return NULL; | |
626 | } | |
627 | ||
628 | /* | |
629 | * Parse a report description into a hid_device structure. Reports are | |
630 | * enumerated, fields are attached to these reports. | |
631 | */ | |
632 | ||
633 | static struct hid_device *hid_parse_report(__u8 *start, unsigned size) | |
634 | { | |
635 | struct hid_device *device; | |
636 | struct hid_parser *parser; | |
637 | struct hid_item item; | |
638 | __u8 *end; | |
639 | unsigned i; | |
640 | static int (*dispatch_type[])(struct hid_parser *parser, | |
641 | struct hid_item *item) = { | |
642 | hid_parser_main, | |
643 | hid_parser_global, | |
644 | hid_parser_local, | |
645 | hid_parser_reserved | |
646 | }; | |
647 | ||
bbdb7daf | 648 | if (!(device = kzalloc(sizeof(struct hid_device), GFP_KERNEL))) |
1da177e4 | 649 | return NULL; |
1da177e4 | 650 | |
bbdb7daf | 651 | if (!(device->collection = kzalloc(sizeof(struct hid_collection) * |
1da177e4 LT |
652 | HID_DEFAULT_NUM_COLLECTIONS, GFP_KERNEL))) { |
653 | kfree(device); | |
654 | return NULL; | |
655 | } | |
1da177e4 LT |
656 | device->collection_size = HID_DEFAULT_NUM_COLLECTIONS; |
657 | ||
658 | for (i = 0; i < HID_REPORT_TYPES; i++) | |
659 | INIT_LIST_HEAD(&device->report_enum[i].report_list); | |
660 | ||
661 | if (!(device->rdesc = (__u8 *)kmalloc(size, GFP_KERNEL))) { | |
662 | kfree(device->collection); | |
663 | kfree(device); | |
664 | return NULL; | |
665 | } | |
666 | memcpy(device->rdesc, start, size); | |
667 | device->rsize = size; | |
668 | ||
bbdb7daf | 669 | if (!(parser = kzalloc(sizeof(struct hid_parser), GFP_KERNEL))) { |
1da177e4 LT |
670 | kfree(device->rdesc); |
671 | kfree(device->collection); | |
672 | kfree(device); | |
673 | return NULL; | |
674 | } | |
1da177e4 LT |
675 | parser->device = device; |
676 | ||
677 | end = start + size; | |
678 | while ((start = fetch_item(start, end, &item)) != NULL) { | |
679 | ||
680 | if (item.format != HID_ITEM_FORMAT_SHORT) { | |
681 | dbg("unexpected long global item"); | |
682 | kfree(device->collection); | |
683 | hid_free_device(device); | |
684 | kfree(parser); | |
685 | return NULL; | |
686 | } | |
687 | ||
688 | if (dispatch_type[item.type](parser, &item)) { | |
689 | dbg("item %u %u %u %u parsing failed\n", | |
690 | item.format, (unsigned)item.size, (unsigned)item.type, (unsigned)item.tag); | |
691 | kfree(device->collection); | |
692 | hid_free_device(device); | |
693 | kfree(parser); | |
694 | return NULL; | |
695 | } | |
696 | ||
697 | if (start == end) { | |
698 | if (parser->collection_stack_ptr) { | |
699 | dbg("unbalanced collection at end of report description"); | |
700 | kfree(device->collection); | |
701 | hid_free_device(device); | |
702 | kfree(parser); | |
703 | return NULL; | |
704 | } | |
705 | if (parser->local.delimiter_depth) { | |
706 | dbg("unbalanced delimiter at end of report description"); | |
707 | kfree(device->collection); | |
708 | hid_free_device(device); | |
709 | kfree(parser); | |
710 | return NULL; | |
711 | } | |
712 | kfree(parser); | |
713 | return device; | |
714 | } | |
715 | } | |
716 | ||
717 | dbg("item fetching failed at offset %d\n", (int)(end - start)); | |
718 | kfree(device->collection); | |
719 | hid_free_device(device); | |
720 | kfree(parser); | |
721 | return NULL; | |
722 | } | |
723 | ||
724 | /* | |
725 | * Convert a signed n-bit integer to signed 32-bit integer. Common | |
726 | * cases are done through the compiler, the screwed things has to be | |
727 | * done by hand. | |
728 | */ | |
729 | ||
730 | static __inline__ __s32 snto32(__u32 value, unsigned n) | |
731 | { | |
732 | switch (n) { | |
733 | case 8: return ((__s8)value); | |
734 | case 16: return ((__s16)value); | |
735 | case 32: return ((__s32)value); | |
736 | } | |
737 | return value & (1 << (n - 1)) ? value | (-1 << n) : value; | |
738 | } | |
739 | ||
740 | /* | |
741 | * Convert a signed 32-bit integer to a signed n-bit integer. | |
742 | */ | |
743 | ||
744 | static __inline__ __u32 s32ton(__s32 value, unsigned n) | |
745 | { | |
746 | __s32 a = value >> (n - 1); | |
747 | if (a && a != -1) | |
748 | return value < 0 ? 1 << (n - 1) : (1 << (n - 1)) - 1; | |
749 | return value & ((1 << n) - 1); | |
750 | } | |
751 | ||
752 | /* | |
4550718f | 753 | * Extract/implement a data field from/to a little endian report (bit array). |
1da177e4 LT |
754 | */ |
755 | ||
756 | static __inline__ __u32 extract(__u8 *report, unsigned offset, unsigned n) | |
757 | { | |
4550718f GG |
758 | u32 x; |
759 | ||
760 | report += offset >> 3; /* adjust byte index */ | |
761 | offset &= 8 - 1; | |
762 | x = get_unaligned((u32 *) report); | |
763 | x = le32_to_cpu(x); | |
764 | x = (x >> offset) & ((1 << n) - 1); | |
765 | return x; | |
1da177e4 LT |
766 | } |
767 | ||
768 | static __inline__ void implement(__u8 *report, unsigned offset, unsigned n, __u32 value) | |
769 | { | |
4550718f GG |
770 | u32 x; |
771 | ||
772 | report += offset >> 3; | |
773 | offset &= 8 - 1; | |
774 | x = get_unaligned((u32 *)report); | |
775 | x &= cpu_to_le32(~((((__u32) 1 << n) - 1) << offset)); | |
776 | x |= cpu_to_le32(value << offset); | |
777 | put_unaligned(x,(u32 *)report); | |
1da177e4 LT |
778 | } |
779 | ||
780 | /* | |
781 | * Search an array for a value. | |
782 | */ | |
783 | ||
784 | static __inline__ int search(__s32 *array, __s32 value, unsigned n) | |
785 | { | |
786 | while (n--) { | |
787 | if (*array++ == value) | |
788 | return 0; | |
789 | } | |
790 | return -1; | |
791 | } | |
792 | ||
7d12e780 | 793 | static void hid_process_event(struct hid_device *hid, struct hid_field *field, struct hid_usage *usage, __s32 value, int interrupt) |
1da177e4 LT |
794 | { |
795 | hid_dump_input(usage, value); | |
796 | if (hid->claimed & HID_CLAIMED_INPUT) | |
7d12e780 | 797 | hidinput_hid_event(hid, field, usage, value); |
bc5d0482 | 798 | if (hid->claimed & HID_CLAIMED_HIDDEV && interrupt) |
7d12e780 | 799 | hiddev_hid_event(hid, field, usage, value); |
1da177e4 LT |
800 | } |
801 | ||
802 | /* | |
803 | * Analyse a received field, and fetch the data from it. The field | |
804 | * content is stored for next report processing (we do differential | |
805 | * reporting to the layer). | |
806 | */ | |
807 | ||
7d12e780 | 808 | static void hid_input_field(struct hid_device *hid, struct hid_field *field, __u8 *data, int interrupt) |
1da177e4 LT |
809 | { |
810 | unsigned n; | |
811 | unsigned count = field->report_count; | |
812 | unsigned offset = field->report_offset; | |
813 | unsigned size = field->report_size; | |
814 | __s32 min = field->logical_minimum; | |
815 | __s32 max = field->logical_maximum; | |
816 | __s32 *value; | |
817 | ||
818 | if (!(value = kmalloc(sizeof(__s32) * count, GFP_ATOMIC))) | |
819 | return; | |
820 | ||
821 | for (n = 0; n < count; n++) { | |
822 | ||
823 | value[n] = min < 0 ? snto32(extract(data, offset + n * size, size), size) : | |
824 | extract(data, offset + n * size, size); | |
825 | ||
826 | if (!(field->flags & HID_MAIN_ITEM_VARIABLE) /* Ignore report if ErrorRollOver */ | |
827 | && value[n] >= min && value[n] <= max | |
828 | && field->usage[value[n] - min].hid == HID_UP_KEYBOARD + 1) | |
829 | goto exit; | |
830 | } | |
831 | ||
832 | for (n = 0; n < count; n++) { | |
833 | ||
834 | if (HID_MAIN_ITEM_VARIABLE & field->flags) { | |
7d12e780 | 835 | hid_process_event(hid, field, &field->usage[n], value[n], interrupt); |
1da177e4 LT |
836 | continue; |
837 | } | |
838 | ||
839 | if (field->value[n] >= min && field->value[n] <= max | |
840 | && field->usage[field->value[n] - min].hid | |
841 | && search(value, field->value[n], count)) | |
7d12e780 | 842 | hid_process_event(hid, field, &field->usage[field->value[n] - min], 0, interrupt); |
1da177e4 LT |
843 | |
844 | if (value[n] >= min && value[n] <= max | |
845 | && field->usage[value[n] - min].hid | |
846 | && search(field->value, value[n], count)) | |
7d12e780 | 847 | hid_process_event(hid, field, &field->usage[value[n] - min], 1, interrupt); |
1da177e4 LT |
848 | } |
849 | ||
850 | memcpy(field->value, value, count * sizeof(__s32)); | |
851 | exit: | |
852 | kfree(value); | |
853 | } | |
854 | ||
7d12e780 | 855 | static int hid_input_report(int type, struct urb *urb, int interrupt) |
1da177e4 LT |
856 | { |
857 | struct hid_device *hid = urb->context; | |
858 | struct hid_report_enum *report_enum = hid->report_enum + type; | |
859 | u8 *data = urb->transfer_buffer; | |
860 | int len = urb->actual_length; | |
861 | struct hid_report *report; | |
862 | int n, size; | |
863 | ||
864 | if (!len) { | |
865 | dbg("empty report"); | |
866 | return -1; | |
867 | } | |
868 | ||
869 | #ifdef DEBUG_DATA | |
870 | printk(KERN_DEBUG __FILE__ ": report (size %u) (%snumbered)\n", len, report_enum->numbered ? "" : "un"); | |
871 | #endif | |
872 | ||
873 | n = 0; /* Normally report number is 0 */ | |
874 | if (report_enum->numbered) { /* Device uses numbered reports, data[0] is report number */ | |
875 | n = *data++; | |
876 | len--; | |
877 | } | |
878 | ||
879 | #ifdef DEBUG_DATA | |
880 | { | |
881 | int i; | |
882 | printk(KERN_DEBUG __FILE__ ": report %d (size %u) = ", n, len); | |
883 | for (i = 0; i < len; i++) | |
884 | printk(" %02x", data[i]); | |
885 | printk("\n"); | |
886 | } | |
887 | #endif | |
888 | ||
889 | if (!(report = report_enum->report_id_hash[n])) { | |
890 | dbg("undefined report_id %d received", n); | |
891 | return -1; | |
892 | } | |
893 | ||
894 | size = ((report->size - 1) >> 3) + 1; | |
895 | ||
cd610457 | 896 | if (len < size) { |
1da177e4 | 897 | dbg("report %d is too short, (%d < %d)", report->id, len, size); |
cd610457 AK |
898 | memset(data + len, 0, size - len); |
899 | } | |
1da177e4 LT |
900 | |
901 | if (hid->claimed & HID_CLAIMED_HIDDEV) | |
902 | hiddev_report_event(hid, report); | |
903 | ||
904 | for (n = 0; n < report->maxfield; n++) | |
7d12e780 | 905 | hid_input_field(hid, report->field[n], data, interrupt); |
1da177e4 LT |
906 | |
907 | if (hid->claimed & HID_CLAIMED_INPUT) | |
908 | hidinput_report_event(hid, report); | |
909 | ||
910 | return 0; | |
911 | } | |
912 | ||
aef4e266 AS |
913 | /* |
914 | * Input submission and I/O error handler. | |
915 | */ | |
916 | ||
917 | static void hid_io_error(struct hid_device *hid); | |
918 | ||
919 | /* Start up the input URB */ | |
920 | static int hid_start_in(struct hid_device *hid) | |
921 | { | |
922 | unsigned long flags; | |
923 | int rc = 0; | |
924 | ||
925 | spin_lock_irqsave(&hid->inlock, flags); | |
926 | if (hid->open > 0 && !test_bit(HID_SUSPENDED, &hid->iofl) && | |
927 | !test_and_set_bit(HID_IN_RUNNING, &hid->iofl)) { | |
928 | rc = usb_submit_urb(hid->urbin, GFP_ATOMIC); | |
929 | if (rc != 0) | |
930 | clear_bit(HID_IN_RUNNING, &hid->iofl); | |
931 | } | |
932 | spin_unlock_irqrestore(&hid->inlock, flags); | |
933 | return rc; | |
934 | } | |
935 | ||
936 | /* I/O retry timer routine */ | |
937 | static void hid_retry_timeout(unsigned long _hid) | |
938 | { | |
939 | struct hid_device *hid = (struct hid_device *) _hid; | |
940 | ||
941 | dev_dbg(&hid->intf->dev, "retrying intr urb\n"); | |
942 | if (hid_start_in(hid)) | |
943 | hid_io_error(hid); | |
944 | } | |
945 | ||
946 | /* Workqueue routine to reset the device */ | |
947 | static void hid_reset(void *_hid) | |
948 | { | |
949 | struct hid_device *hid = (struct hid_device *) _hid; | |
950 | int rc_lock, rc; | |
951 | ||
952 | dev_dbg(&hid->intf->dev, "resetting device\n"); | |
953 | rc = rc_lock = usb_lock_device_for_reset(hid->dev, hid->intf); | |
954 | if (rc_lock >= 0) { | |
df9a1f48 | 955 | rc = usb_reset_composite_device(hid->dev, hid->intf); |
aef4e266 AS |
956 | if (rc_lock) |
957 | usb_unlock_device(hid->dev); | |
958 | } | |
959 | clear_bit(HID_RESET_PENDING, &hid->iofl); | |
960 | ||
df9a1f48 AS |
961 | switch (rc) { |
962 | case 0: | |
963 | if (!test_bit(HID_IN_RUNNING, &hid->iofl)) | |
aef4e266 | 964 | hid_io_error(hid); |
df9a1f48 AS |
965 | break; |
966 | default: | |
aef4e266 AS |
967 | err("can't reset device, %s-%s/input%d, status %d", |
968 | hid->dev->bus->bus_name, | |
969 | hid->dev->devpath, | |
970 | hid->ifnum, rc); | |
df9a1f48 AS |
971 | /* FALLTHROUGH */ |
972 | case -EHOSTUNREACH: | |
973 | case -ENODEV: | |
974 | case -EINTR: | |
975 | break; | |
976 | } | |
aef4e266 AS |
977 | } |
978 | ||
979 | /* Main I/O error handler */ | |
980 | static void hid_io_error(struct hid_device *hid) | |
981 | { | |
982 | unsigned long flags; | |
983 | ||
984 | spin_lock_irqsave(&hid->inlock, flags); | |
985 | ||
986 | /* Stop when disconnected */ | |
987 | if (usb_get_intfdata(hid->intf) == NULL) | |
988 | goto done; | |
989 | ||
990 | /* When an error occurs, retry at increasing intervals */ | |
991 | if (hid->retry_delay == 0) { | |
992 | hid->retry_delay = 13; /* Then 26, 52, 104, 104, ... */ | |
993 | hid->stop_retry = jiffies + msecs_to_jiffies(1000); | |
994 | } else if (hid->retry_delay < 100) | |
995 | hid->retry_delay *= 2; | |
996 | ||
997 | if (time_after(jiffies, hid->stop_retry)) { | |
998 | ||
999 | /* Retries failed, so do a port reset */ | |
1000 | if (!test_and_set_bit(HID_RESET_PENDING, &hid->iofl)) { | |
1001 | if (schedule_work(&hid->reset_work)) | |
1002 | goto done; | |
1003 | clear_bit(HID_RESET_PENDING, &hid->iofl); | |
1004 | } | |
1005 | } | |
1006 | ||
1007 | mod_timer(&hid->io_retry, | |
1008 | jiffies + msecs_to_jiffies(hid->retry_delay)); | |
1009 | done: | |
1010 | spin_unlock_irqrestore(&hid->inlock, flags); | |
1011 | } | |
1012 | ||
1da177e4 LT |
1013 | /* |
1014 | * Input interrupt completion handler. | |
1015 | */ | |
1016 | ||
7d12e780 | 1017 | static void hid_irq_in(struct urb *urb) |
1da177e4 LT |
1018 | { |
1019 | struct hid_device *hid = urb->context; | |
1020 | int status; | |
1021 | ||
1022 | switch (urb->status) { | |
1023 | case 0: /* success */ | |
aef4e266 | 1024 | hid->retry_delay = 0; |
7d12e780 | 1025 | hid_input_report(HID_INPUT_REPORT, urb, 1); |
1da177e4 LT |
1026 | break; |
1027 | case -ECONNRESET: /* unlink */ | |
1028 | case -ENOENT: | |
1da177e4 | 1029 | case -ESHUTDOWN: /* unplug */ |
aef4e266 | 1030 | clear_bit(HID_IN_RUNNING, &hid->iofl); |
1da177e4 | 1031 | return; |
aef4e266 AS |
1032 | case -EILSEQ: /* protocol error or unplug */ |
1033 | case -EPROTO: /* protocol error or unplug */ | |
38e2bfc9 PZ |
1034 | case -ETIME: /* protocol error or unplug */ |
1035 | case -ETIMEDOUT: /* Should never happen, but... */ | |
aef4e266 AS |
1036 | clear_bit(HID_IN_RUNNING, &hid->iofl); |
1037 | hid_io_error(hid); | |
1038 | return; | |
1da177e4 LT |
1039 | default: /* error */ |
1040 | warn("input irq status %d received", urb->status); | |
1041 | } | |
1042 | ||
1043 | status = usb_submit_urb(urb, SLAB_ATOMIC); | |
aef4e266 AS |
1044 | if (status) { |
1045 | clear_bit(HID_IN_RUNNING, &hid->iofl); | |
1046 | if (status != -EPERM) { | |
1047 | err("can't resubmit intr, %s-%s/input%d, status %d", | |
1048 | hid->dev->bus->bus_name, | |
1049 | hid->dev->devpath, | |
1050 | hid->ifnum, status); | |
1051 | hid_io_error(hid); | |
1052 | } | |
1053 | } | |
1da177e4 LT |
1054 | } |
1055 | ||
1056 | /* | |
1057 | * Output the field into the report. | |
1058 | */ | |
1059 | ||
1060 | static void hid_output_field(struct hid_field *field, __u8 *data) | |
1061 | { | |
1062 | unsigned count = field->report_count; | |
1063 | unsigned offset = field->report_offset; | |
1064 | unsigned size = field->report_size; | |
1065 | unsigned n; | |
1066 | ||
1067 | for (n = 0; n < count; n++) { | |
1068 | if (field->logical_minimum < 0) /* signed values */ | |
1069 | implement(data, offset + n * size, size, s32ton(field->value[n], size)); | |
1070 | else /* unsigned values */ | |
1071 | implement(data, offset + n * size, size, field->value[n]); | |
1072 | } | |
1073 | } | |
1074 | ||
1075 | /* | |
1076 | * Create a report. | |
1077 | */ | |
1078 | ||
1079 | static void hid_output_report(struct hid_report *report, __u8 *data) | |
1080 | { | |
1081 | unsigned n; | |
1082 | ||
1083 | if (report->id > 0) | |
1084 | *data++ = report->id; | |
1085 | ||
1086 | for (n = 0; n < report->maxfield; n++) | |
1087 | hid_output_field(report->field[n], data); | |
1088 | } | |
1089 | ||
1090 | /* | |
1091 | * Set a field value. The report this field belongs to has to be | |
1092 | * created and transferred to the device, to set this value in the | |
1093 | * device. | |
1094 | */ | |
1095 | ||
1096 | int hid_set_field(struct hid_field *field, unsigned offset, __s32 value) | |
1097 | { | |
1098 | unsigned size = field->report_size; | |
1099 | ||
1100 | hid_dump_input(field->usage + offset, value); | |
1101 | ||
1102 | if (offset >= field->report_count) { | |
1103 | dbg("offset (%d) exceeds report_count (%d)", offset, field->report_count); | |
1104 | hid_dump_field(field, 8); | |
1105 | return -1; | |
1106 | } | |
1107 | if (field->logical_minimum < 0) { | |
1108 | if (value != snto32(s32ton(value, size), size)) { | |
1109 | dbg("value %d is out of range", value); | |
1110 | return -1; | |
1111 | } | |
1112 | } | |
1113 | field->value[offset] = value; | |
1114 | return 0; | |
1115 | } | |
1116 | ||
1117 | /* | |
1118 | * Find a report field with a specified HID usage. | |
1119 | */ | |
f287caee | 1120 | #if 0 |
1da177e4 LT |
1121 | struct hid_field *hid_find_field_by_usage(struct hid_device *hid, __u32 wanted_usage, int type) |
1122 | { | |
1123 | struct hid_report *report; | |
1124 | int i; | |
1125 | ||
1126 | list_for_each_entry(report, &hid->report_enum[type].report_list, list) | |
1127 | for (i = 0; i < report->maxfield; i++) | |
1128 | if (report->field[i]->logical == wanted_usage) | |
1129 | return report->field[i]; | |
1130 | return NULL; | |
1131 | } | |
f287caee | 1132 | #endif /* 0 */ |
1da177e4 LT |
1133 | |
1134 | static int hid_submit_out(struct hid_device *hid) | |
1135 | { | |
1136 | struct hid_report *report; | |
1137 | ||
1138 | report = hid->out[hid->outtail]; | |
1139 | ||
1140 | hid_output_report(report, hid->outbuf); | |
1141 | hid->urbout->transfer_buffer_length = ((report->size - 1) >> 3) + 1 + (report->id > 0); | |
1142 | hid->urbout->dev = hid->dev; | |
1143 | ||
1144 | dbg("submitting out urb"); | |
1145 | ||
1146 | if (usb_submit_urb(hid->urbout, GFP_ATOMIC)) { | |
1147 | err("usb_submit_urb(out) failed"); | |
1148 | return -1; | |
1149 | } | |
1150 | ||
1151 | return 0; | |
1152 | } | |
1153 | ||
1154 | static int hid_submit_ctrl(struct hid_device *hid) | |
1155 | { | |
1156 | struct hid_report *report; | |
1157 | unsigned char dir; | |
1158 | int len; | |
1159 | ||
1160 | report = hid->ctrl[hid->ctrltail].report; | |
1161 | dir = hid->ctrl[hid->ctrltail].dir; | |
1162 | ||
1163 | len = ((report->size - 1) >> 3) + 1 + (report->id > 0); | |
1164 | if (dir == USB_DIR_OUT) { | |
1165 | hid_output_report(report, hid->ctrlbuf); | |
1166 | hid->urbctrl->pipe = usb_sndctrlpipe(hid->dev, 0); | |
1167 | hid->urbctrl->transfer_buffer_length = len; | |
1168 | } else { | |
1169 | int maxpacket, padlen; | |
1170 | ||
1171 | hid->urbctrl->pipe = usb_rcvctrlpipe(hid->dev, 0); | |
1172 | maxpacket = usb_maxpacket(hid->dev, hid->urbctrl->pipe, 0); | |
1173 | if (maxpacket > 0) { | |
1174 | padlen = (len + maxpacket - 1) / maxpacket; | |
1175 | padlen *= maxpacket; | |
bf0964dc MH |
1176 | if (padlen > hid->bufsize) |
1177 | padlen = hid->bufsize; | |
1da177e4 LT |
1178 | } else |
1179 | padlen = 0; | |
1180 | hid->urbctrl->transfer_buffer_length = padlen; | |
1181 | } | |
1182 | hid->urbctrl->dev = hid->dev; | |
1183 | ||
1184 | hid->cr->bRequestType = USB_TYPE_CLASS | USB_RECIP_INTERFACE | dir; | |
1185 | hid->cr->bRequest = (dir == USB_DIR_OUT) ? HID_REQ_SET_REPORT : HID_REQ_GET_REPORT; | |
1186 | hid->cr->wValue = cpu_to_le16(((report->type + 1) << 8) | report->id); | |
1187 | hid->cr->wIndex = cpu_to_le16(hid->ifnum); | |
1188 | hid->cr->wLength = cpu_to_le16(len); | |
1189 | ||
1190 | dbg("submitting ctrl urb: %s wValue=0x%04x wIndex=0x%04x wLength=%u", | |
1191 | hid->cr->bRequest == HID_REQ_SET_REPORT ? "Set_Report" : "Get_Report", | |
1192 | hid->cr->wValue, hid->cr->wIndex, hid->cr->wLength); | |
1193 | ||
1194 | if (usb_submit_urb(hid->urbctrl, GFP_ATOMIC)) { | |
1195 | err("usb_submit_urb(ctrl) failed"); | |
1196 | return -1; | |
1197 | } | |
1198 | ||
1199 | return 0; | |
1200 | } | |
1201 | ||
1202 | /* | |
1203 | * Output interrupt completion handler. | |
1204 | */ | |
1205 | ||
7d12e780 | 1206 | static void hid_irq_out(struct urb *urb) |
1da177e4 LT |
1207 | { |
1208 | struct hid_device *hid = urb->context; | |
1209 | unsigned long flags; | |
1210 | int unplug = 0; | |
1211 | ||
1212 | switch (urb->status) { | |
1213 | case 0: /* success */ | |
c4786ca8 | 1214 | break; |
1da177e4 | 1215 | case -ESHUTDOWN: /* unplug */ |
1da177e4 | 1216 | unplug = 1; |
aef4e266 AS |
1217 | case -EILSEQ: /* protocol error or unplug */ |
1218 | case -EPROTO: /* protocol error or unplug */ | |
1da177e4 LT |
1219 | case -ECONNRESET: /* unlink */ |
1220 | case -ENOENT: | |
1221 | break; | |
1222 | default: /* error */ | |
1223 | warn("output irq status %d received", urb->status); | |
1224 | } | |
1225 | ||
1226 | spin_lock_irqsave(&hid->outlock, flags); | |
1227 | ||
1228 | if (unplug) | |
1229 | hid->outtail = hid->outhead; | |
1230 | else | |
1231 | hid->outtail = (hid->outtail + 1) & (HID_OUTPUT_FIFO_SIZE - 1); | |
1232 | ||
1233 | if (hid->outhead != hid->outtail) { | |
1234 | if (hid_submit_out(hid)) { | |
53b3531b | 1235 | clear_bit(HID_OUT_RUNNING, &hid->iofl); |
1da177e4 LT |
1236 | wake_up(&hid->wait); |
1237 | } | |
1238 | spin_unlock_irqrestore(&hid->outlock, flags); | |
1239 | return; | |
1240 | } | |
1241 | ||
1242 | clear_bit(HID_OUT_RUNNING, &hid->iofl); | |
1243 | spin_unlock_irqrestore(&hid->outlock, flags); | |
1244 | wake_up(&hid->wait); | |
1245 | } | |
1246 | ||
1247 | /* | |
1248 | * Control pipe completion handler. | |
1249 | */ | |
1250 | ||
7d12e780 | 1251 | static void hid_ctrl(struct urb *urb) |
1da177e4 LT |
1252 | { |
1253 | struct hid_device *hid = urb->context; | |
1254 | unsigned long flags; | |
1255 | int unplug = 0; | |
1256 | ||
1257 | spin_lock_irqsave(&hid->ctrllock, flags); | |
1258 | ||
1259 | switch (urb->status) { | |
1260 | case 0: /* success */ | |
1261 | if (hid->ctrl[hid->ctrltail].dir == USB_DIR_IN) | |
7d12e780 | 1262 | hid_input_report(hid->ctrl[hid->ctrltail].report->type, urb, 0); |
c4786ca8 | 1263 | break; |
1da177e4 | 1264 | case -ESHUTDOWN: /* unplug */ |
1da177e4 | 1265 | unplug = 1; |
aef4e266 AS |
1266 | case -EILSEQ: /* protocol error or unplug */ |
1267 | case -EPROTO: /* protocol error or unplug */ | |
1da177e4 LT |
1268 | case -ECONNRESET: /* unlink */ |
1269 | case -ENOENT: | |
1270 | case -EPIPE: /* report not available */ | |
1271 | break; | |
1272 | default: /* error */ | |
1273 | warn("ctrl urb status %d received", urb->status); | |
1274 | } | |
1275 | ||
1276 | if (unplug) | |
1277 | hid->ctrltail = hid->ctrlhead; | |
1278 | else | |
1279 | hid->ctrltail = (hid->ctrltail + 1) & (HID_CONTROL_FIFO_SIZE - 1); | |
1280 | ||
1281 | if (hid->ctrlhead != hid->ctrltail) { | |
1282 | if (hid_submit_ctrl(hid)) { | |
1283 | clear_bit(HID_CTRL_RUNNING, &hid->iofl); | |
1284 | wake_up(&hid->wait); | |
1285 | } | |
1286 | spin_unlock_irqrestore(&hid->ctrllock, flags); | |
1287 | return; | |
1288 | } | |
1289 | ||
1290 | clear_bit(HID_CTRL_RUNNING, &hid->iofl); | |
1291 | spin_unlock_irqrestore(&hid->ctrllock, flags); | |
1292 | wake_up(&hid->wait); | |
1293 | } | |
1294 | ||
1295 | void hid_submit_report(struct hid_device *hid, struct hid_report *report, unsigned char dir) | |
1296 | { | |
1297 | int head; | |
1298 | unsigned long flags; | |
1299 | ||
1300 | if ((hid->quirks & HID_QUIRK_NOGET) && dir == USB_DIR_IN) | |
1301 | return; | |
1302 | ||
1303 | if (hid->urbout && dir == USB_DIR_OUT && report->type == HID_OUTPUT_REPORT) { | |
1304 | ||
1305 | spin_lock_irqsave(&hid->outlock, flags); | |
1306 | ||
1307 | if ((head = (hid->outhead + 1) & (HID_OUTPUT_FIFO_SIZE - 1)) == hid->outtail) { | |
1308 | spin_unlock_irqrestore(&hid->outlock, flags); | |
1309 | warn("output queue full"); | |
1310 | return; | |
1311 | } | |
1312 | ||
1313 | hid->out[hid->outhead] = report; | |
1314 | hid->outhead = head; | |
1315 | ||
1316 | if (!test_and_set_bit(HID_OUT_RUNNING, &hid->iofl)) | |
1317 | if (hid_submit_out(hid)) | |
1318 | clear_bit(HID_OUT_RUNNING, &hid->iofl); | |
1319 | ||
1320 | spin_unlock_irqrestore(&hid->outlock, flags); | |
1321 | return; | |
1322 | } | |
1323 | ||
1324 | spin_lock_irqsave(&hid->ctrllock, flags); | |
1325 | ||
1326 | if ((head = (hid->ctrlhead + 1) & (HID_CONTROL_FIFO_SIZE - 1)) == hid->ctrltail) { | |
1327 | spin_unlock_irqrestore(&hid->ctrllock, flags); | |
1328 | warn("control queue full"); | |
1329 | return; | |
1330 | } | |
1331 | ||
1332 | hid->ctrl[hid->ctrlhead].report = report; | |
1333 | hid->ctrl[hid->ctrlhead].dir = dir; | |
1334 | hid->ctrlhead = head; | |
1335 | ||
1336 | if (!test_and_set_bit(HID_CTRL_RUNNING, &hid->iofl)) | |
1337 | if (hid_submit_ctrl(hid)) | |
1338 | clear_bit(HID_CTRL_RUNNING, &hid->iofl); | |
1339 | ||
1340 | spin_unlock_irqrestore(&hid->ctrllock, flags); | |
1341 | } | |
1342 | ||
1343 | int hid_wait_io(struct hid_device *hid) | |
1344 | { | |
1345 | if (!wait_event_timeout(hid->wait, (!test_bit(HID_CTRL_RUNNING, &hid->iofl) && | |
1346 | !test_bit(HID_OUT_RUNNING, &hid->iofl)), | |
1347 | 10*HZ)) { | |
1348 | dbg("timeout waiting for ctrl or out queue to clear"); | |
1349 | return -1; | |
1350 | } | |
1351 | ||
1352 | return 0; | |
1353 | } | |
1354 | ||
854561b0 VP |
1355 | static int hid_set_idle(struct usb_device *dev, int ifnum, int report, int idle) |
1356 | { | |
71387bd7 | 1357 | return usb_control_msg(dev, usb_sndctrlpipe(dev, 0), |
854561b0 VP |
1358 | HID_REQ_SET_IDLE, USB_TYPE_CLASS | USB_RECIP_INTERFACE, (idle << 8) | report, |
1359 | ifnum, NULL, 0, USB_CTRL_SET_TIMEOUT); | |
1360 | } | |
1361 | ||
1da177e4 LT |
1362 | static int hid_get_class_descriptor(struct usb_device *dev, int ifnum, |
1363 | unsigned char type, void *buf, int size) | |
1364 | { | |
1365 | int result, retries = 4; | |
1366 | ||
1367 | memset(buf,0,size); // Make sure we parse really received data | |
1368 | ||
1369 | do { | |
1370 | result = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), | |
1371 | USB_REQ_GET_DESCRIPTOR, USB_RECIP_INTERFACE | USB_DIR_IN, | |
1372 | (type << 8), ifnum, buf, size, USB_CTRL_GET_TIMEOUT); | |
1373 | retries--; | |
1374 | } while (result < size && retries); | |
1375 | return result; | |
1376 | } | |
1377 | ||
1378 | int hid_open(struct hid_device *hid) | |
1379 | { | |
aef4e266 AS |
1380 | ++hid->open; |
1381 | if (hid_start_in(hid)) | |
1382 | hid_io_error(hid); | |
1da177e4 LT |
1383 | return 0; |
1384 | } | |
1385 | ||
1386 | void hid_close(struct hid_device *hid) | |
1387 | { | |
1388 | if (!--hid->open) | |
1389 | usb_kill_urb(hid->urbin); | |
1390 | } | |
1391 | ||
1d3e2023 DR |
1392 | #define USB_VENDOR_ID_PANJIT 0x134c |
1393 | ||
1da177e4 LT |
1394 | /* |
1395 | * Initialize all reports | |
1396 | */ | |
1397 | ||
1398 | void hid_init_reports(struct hid_device *hid) | |
1399 | { | |
1400 | struct hid_report *report; | |
1401 | int err, ret; | |
1402 | ||
bf0964dc | 1403 | list_for_each_entry(report, &hid->report_enum[HID_INPUT_REPORT].report_list, list) |
1da177e4 | 1404 | hid_submit_report(hid, report, USB_DIR_IN); |
1da177e4 LT |
1405 | |
1406 | list_for_each_entry(report, &hid->report_enum[HID_FEATURE_REPORT].report_list, list) | |
1407 | hid_submit_report(hid, report, USB_DIR_IN); | |
1408 | ||
1409 | err = 0; | |
1410 | ret = hid_wait_io(hid); | |
1411 | while (ret) { | |
1412 | err |= ret; | |
1413 | if (test_bit(HID_CTRL_RUNNING, &hid->iofl)) | |
1414 | usb_kill_urb(hid->urbctrl); | |
1415 | if (test_bit(HID_OUT_RUNNING, &hid->iofl)) | |
1416 | usb_kill_urb(hid->urbout); | |
1417 | ret = hid_wait_io(hid); | |
1418 | } | |
1419 | ||
1420 | if (err) | |
de289fdf | 1421 | warn("timeout initializing reports"); |
1da177e4 LT |
1422 | } |
1423 | ||
6f8d9e26 JR |
1424 | #define USB_VENDOR_ID_GTCO 0x078c |
1425 | #define USB_DEVICE_ID_GTCO_90 0x0090 | |
1426 | #define USB_DEVICE_ID_GTCO_100 0x0100 | |
1427 | #define USB_DEVICE_ID_GTCO_101 0x0101 | |
1428 | #define USB_DEVICE_ID_GTCO_103 0x0103 | |
1429 | #define USB_DEVICE_ID_GTCO_104 0x0104 | |
1430 | #define USB_DEVICE_ID_GTCO_105 0x0105 | |
1431 | #define USB_DEVICE_ID_GTCO_106 0x0106 | |
1432 | #define USB_DEVICE_ID_GTCO_107 0x0107 | |
1433 | #define USB_DEVICE_ID_GTCO_108 0x0108 | |
1434 | #define USB_DEVICE_ID_GTCO_200 0x0200 | |
1435 | #define USB_DEVICE_ID_GTCO_201 0x0201 | |
1436 | #define USB_DEVICE_ID_GTCO_202 0x0202 | |
1437 | #define USB_DEVICE_ID_GTCO_203 0x0203 | |
1438 | #define USB_DEVICE_ID_GTCO_204 0x0204 | |
1439 | #define USB_DEVICE_ID_GTCO_205 0x0205 | |
1440 | #define USB_DEVICE_ID_GTCO_206 0x0206 | |
1441 | #define USB_DEVICE_ID_GTCO_207 0x0207 | |
1442 | #define USB_DEVICE_ID_GTCO_300 0x0300 | |
1443 | #define USB_DEVICE_ID_GTCO_301 0x0301 | |
1444 | #define USB_DEVICE_ID_GTCO_302 0x0302 | |
1445 | #define USB_DEVICE_ID_GTCO_303 0x0303 | |
1446 | #define USB_DEVICE_ID_GTCO_304 0x0304 | |
1447 | #define USB_DEVICE_ID_GTCO_305 0x0305 | |
1448 | #define USB_DEVICE_ID_GTCO_306 0x0306 | |
1449 | #define USB_DEVICE_ID_GTCO_307 0x0307 | |
1450 | #define USB_DEVICE_ID_GTCO_308 0x0308 | |
1451 | #define USB_DEVICE_ID_GTCO_309 0x0309 | |
1452 | #define USB_DEVICE_ID_GTCO_400 0x0400 | |
1453 | #define USB_DEVICE_ID_GTCO_401 0x0401 | |
1454 | #define USB_DEVICE_ID_GTCO_402 0x0402 | |
1455 | #define USB_DEVICE_ID_GTCO_403 0x0403 | |
1456 | #define USB_DEVICE_ID_GTCO_404 0x0404 | |
f0649024 | 1457 | #define USB_DEVICE_ID_GTCO_405 0x0405 |
6f8d9e26 JR |
1458 | #define USB_DEVICE_ID_GTCO_500 0x0500 |
1459 | #define USB_DEVICE_ID_GTCO_501 0x0501 | |
1460 | #define USB_DEVICE_ID_GTCO_502 0x0502 | |
1461 | #define USB_DEVICE_ID_GTCO_503 0x0503 | |
1462 | #define USB_DEVICE_ID_GTCO_504 0x0504 | |
1463 | #define USB_DEVICE_ID_GTCO_1000 0x1000 | |
1464 | #define USB_DEVICE_ID_GTCO_1001 0x1001 | |
1465 | #define USB_DEVICE_ID_GTCO_1002 0x1002 | |
1466 | #define USB_DEVICE_ID_GTCO_1003 0x1003 | |
1467 | #define USB_DEVICE_ID_GTCO_1004 0x1004 | |
1468 | #define USB_DEVICE_ID_GTCO_1005 0x1005 | |
1469 | #define USB_DEVICE_ID_GTCO_1006 0x1006 | |
1470 | ||
1da177e4 | 1471 | #define USB_VENDOR_ID_WACOM 0x056a |
1da177e4 | 1472 | |
53880546 SV |
1473 | #define USB_VENDOR_ID_ACECAD 0x0460 |
1474 | #define USB_DEVICE_ID_ACECAD_FLAIR 0x0004 | |
1475 | #define USB_DEVICE_ID_ACECAD_302 0x0008 | |
1476 | ||
1da177e4 LT |
1477 | #define USB_VENDOR_ID_KBGEAR 0x084e |
1478 | #define USB_DEVICE_ID_KBGEAR_JAMSTUDIO 0x1001 | |
1479 | ||
1480 | #define USB_VENDOR_ID_AIPTEK 0x08ca | |
1481 | #define USB_DEVICE_ID_AIPTEK_01 0x0001 | |
1482 | #define USB_DEVICE_ID_AIPTEK_10 0x0010 | |
1483 | #define USB_DEVICE_ID_AIPTEK_20 0x0020 | |
1484 | #define USB_DEVICE_ID_AIPTEK_21 0x0021 | |
1485 | #define USB_DEVICE_ID_AIPTEK_22 0x0022 | |
1486 | #define USB_DEVICE_ID_AIPTEK_23 0x0023 | |
1487 | #define USB_DEVICE_ID_AIPTEK_24 0x0024 | |
1488 | ||
1489 | #define USB_VENDOR_ID_GRIFFIN 0x077d | |
1490 | #define USB_DEVICE_ID_POWERMATE 0x0410 | |
1491 | #define USB_DEVICE_ID_SOUNDKNOB 0x04AA | |
1492 | ||
1493 | #define USB_VENDOR_ID_ATEN 0x0557 | |
1494 | #define USB_DEVICE_ID_ATEN_UC100KM 0x2004 | |
1495 | #define USB_DEVICE_ID_ATEN_CS124U 0x2202 | |
1496 | #define USB_DEVICE_ID_ATEN_2PORTKVM 0x2204 | |
1497 | #define USB_DEVICE_ID_ATEN_4PORTKVM 0x2205 | |
1498 | #define USB_DEVICE_ID_ATEN_4PORTKVMC 0x2208 | |
1499 | ||
1500 | #define USB_VENDOR_ID_TOPMAX 0x0663 | |
1501 | #define USB_DEVICE_ID_TOPMAX_COBRAPAD 0x0103 | |
1502 | ||
1503 | #define USB_VENDOR_ID_HAPP 0x078b | |
1504 | #define USB_DEVICE_ID_UGCI_DRIVING 0x0010 | |
1505 | #define USB_DEVICE_ID_UGCI_FLYING 0x0020 | |
1506 | #define USB_DEVICE_ID_UGCI_FIGHTING 0x0030 | |
1507 | ||
1508 | #define USB_VENDOR_ID_MGE 0x0463 | |
1509 | #define USB_DEVICE_ID_MGE_UPS 0xffff | |
1510 | #define USB_DEVICE_ID_MGE_UPS1 0x0001 | |
1511 | ||
1512 | #define USB_VENDOR_ID_ONTRAK 0x0a07 | |
1513 | #define USB_DEVICE_ID_ONTRAK_ADU100 0x0064 | |
1514 | ||
1da177e4 LT |
1515 | #define USB_VENDOR_ID_ESSENTIAL_REALITY 0x0d7f |
1516 | #define USB_DEVICE_ID_ESSENTIAL_REALITY_P5 0x0100 | |
1517 | ||
1518 | #define USB_VENDOR_ID_A4TECH 0x09da | |
1519 | #define USB_DEVICE_ID_A4TECH_WCP32PU 0x0006 | |
1520 | ||
61cdecd9 | 1521 | #define USB_VENDOR_ID_AASHIMA 0x06d6 |
6345fdfd | 1522 | #define USB_DEVICE_ID_AASHIMA_GAMEPAD 0x0025 |
61cdecd9 | 1523 | #define USB_DEVICE_ID_AASHIMA_PREDATOR 0x0026 |
6345fdfd | 1524 | |
1da177e4 LT |
1525 | #define USB_VENDOR_ID_CYPRESS 0x04b4 |
1526 | #define USB_DEVICE_ID_CYPRESS_MOUSE 0x0001 | |
1527 | #define USB_DEVICE_ID_CYPRESS_HIDCOM 0x5500 | |
7d25258f | 1528 | #define USB_DEVICE_ID_CYPRESS_ULTRAMOUSE 0x7417 |
1da177e4 LT |
1529 | |
1530 | #define USB_VENDOR_ID_BERKSHIRE 0x0c98 | |
1531 | #define USB_DEVICE_ID_BERKSHIRE_PCWD 0x1140 | |
1532 | ||
1533 | #define USB_VENDOR_ID_ALPS 0x0433 | |
1534 | #define USB_DEVICE_ID_IBM_GAMEPAD 0x1101 | |
1535 | ||
1536 | #define USB_VENDOR_ID_SAITEK 0x06a3 | |
1537 | #define USB_DEVICE_ID_SAITEK_RUMBLEPAD 0xff17 | |
1538 | ||
1539 | #define USB_VENDOR_ID_NEC 0x073e | |
1540 | #define USB_DEVICE_ID_NEC_USB_GAME_PAD 0x0301 | |
1541 | ||
1542 | #define USB_VENDOR_ID_CHIC 0x05fe | |
1543 | #define USB_DEVICE_ID_CHIC_GAMEPAD 0x0014 | |
1544 | ||
1545 | #define USB_VENDOR_ID_GLAB 0x06c2 | |
1546 | #define USB_DEVICE_ID_4_PHIDGETSERVO_30 0x0038 | |
1547 | #define USB_DEVICE_ID_1_PHIDGETSERVO_30 0x0039 | |
1da177e4 | 1548 | #define USB_DEVICE_ID_0_0_4_IF_KIT 0x0040 |
d5176b41 SY |
1549 | #define USB_DEVICE_ID_0_16_16_IF_KIT 0x0044 |
1550 | #define USB_DEVICE_ID_8_8_8_IF_KIT 0x0045 | |
1551 | #define USB_DEVICE_ID_0_8_7_IF_KIT 0x0051 | |
1da177e4 | 1552 | #define USB_DEVICE_ID_0_8_8_IF_KIT 0x0053 |
d5176b41 | 1553 | #define USB_DEVICE_ID_PHIDGET_MOTORCONTROL 0x0058 |
1da177e4 LT |
1554 | |
1555 | #define USB_VENDOR_ID_WISEGROUP 0x0925 | |
1556 | #define USB_DEVICE_ID_1_PHIDGETSERVO_20 0x8101 | |
1557 | #define USB_DEVICE_ID_4_PHIDGETSERVO_20 0x8104 | |
d5176b41 | 1558 | #define USB_DEVICE_ID_8_8_4_IF_KIT 0x8201 |
e65335ef | 1559 | #define USB_DEVICE_ID_DUAL_USB_JOYPAD 0x8866 |
1da177e4 | 1560 | |
b857c651 NG |
1561 | #define USB_VENDOR_ID_WISEGROUP_LTD 0x6677 |
1562 | #define USB_DEVICE_ID_SMARTJOY_DUAL_PLUS 0x8802 | |
1563 | ||
1da177e4 LT |
1564 | #define USB_VENDOR_ID_CODEMERCS 0x07c0 |
1565 | #define USB_DEVICE_ID_CODEMERCS_IOW40 0x1500 | |
1566 | #define USB_DEVICE_ID_CODEMERCS_IOW24 0x1501 | |
1567 | #define USB_DEVICE_ID_CODEMERCS_IOW48 0x1502 | |
1568 | #define USB_DEVICE_ID_CODEMERCS_IOW28 0x1503 | |
1569 | ||
1570 | #define USB_VENDOR_ID_DELORME 0x1163 | |
1571 | #define USB_DEVICE_ID_DELORME_EARTHMATE 0x0100 | |
dc1d1003 | 1572 | #define USB_DEVICE_ID_DELORME_EM_LT20 0x0200 |
1da177e4 LT |
1573 | |
1574 | #define USB_VENDOR_ID_MCC 0x09db | |
1575 | #define USB_DEVICE_ID_MCC_PMD1024LS 0x0076 | |
1576 | #define USB_DEVICE_ID_MCC_PMD1208LS 0x007a | |
1577 | ||
4871d3be GKH |
1578 | #define USB_VENDOR_ID_VERNIER 0x08f7 |
1579 | #define USB_DEVICE_ID_VERNIER_LABPRO 0x0001 | |
1580 | #define USB_DEVICE_ID_VERNIER_GOTEMP 0x0002 | |
1581 | #define USB_DEVICE_ID_VERNIER_SKIP 0x0003 | |
1582 | #define USB_DEVICE_ID_VERNIER_CYCLOPS 0x0004 | |
1583 | ||
8fd6db47 | 1584 | #define USB_VENDOR_ID_LD 0x0f11 |
ba3e66e9 MH |
1585 | #define USB_DEVICE_ID_LD_CASSY 0x1000 |
1586 | #define USB_DEVICE_ID_LD_POCKETCASSY 0x1010 | |
1587 | #define USB_DEVICE_ID_LD_MOBILECASSY 0x1020 | |
1588 | #define USB_DEVICE_ID_LD_JWM 0x1080 | |
1589 | #define USB_DEVICE_ID_LD_DMMP 0x1081 | |
1590 | #define USB_DEVICE_ID_LD_UMIP 0x1090 | |
1591 | #define USB_DEVICE_ID_LD_XRAY1 0x1100 | |
1592 | #define USB_DEVICE_ID_LD_XRAY2 0x1101 | |
1593 | #define USB_DEVICE_ID_LD_VIDEOCOM 0x1200 | |
1594 | #define USB_DEVICE_ID_LD_COM3LAB 0x2000 | |
1595 | #define USB_DEVICE_ID_LD_TELEPORT 0x2010 | |
1596 | #define USB_DEVICE_ID_LD_NETWORKANALYSER 0x2020 | |
1597 | #define USB_DEVICE_ID_LD_POWERCONTROL 0x2030 | |
1598 | #define USB_DEVICE_ID_LD_MACHINETEST 0x2040 | |
8fd6db47 | 1599 | |
c58de6d9 | 1600 | #define USB_VENDOR_ID_APPLE 0x05ac |
a82e49b8 | 1601 | #define USB_DEVICE_ID_APPLE_MIGHTYMOUSE 0x0304 |
1da177e4 | 1602 | |
940824b0 VP |
1603 | #define USB_VENDOR_ID_CHERRY 0x046a |
1604 | #define USB_DEVICE_ID_CHERRY_CYMOTION 0x0023 | |
1605 | ||
5cd330f4 HV |
1606 | #define USB_VENDOR_ID_YEALINK 0x6993 |
1607 | #define USB_DEVICE_ID_YEALINK_P1K_P4K_B2K 0xb001 | |
8fd80133 JS |
1608 | |
1609 | #define USB_VENDOR_ID_ALCOR 0x058f | |
1610 | #define USB_DEVICE_ID_ALCOR_USBRS232 0x9720 | |
1611 | ||
931e24b9 RB |
1612 | #define USB_VENDOR_ID_SUN 0x0430 |
1613 | #define USB_DEVICE_ID_RARITAN_KVM_DONGLE 0xcdab | |
1614 | ||
1da177e4 LT |
1615 | /* |
1616 | * Alphabetically sorted blacklist by quirk type. | |
1617 | */ | |
1618 | ||
4c4c9432 | 1619 | static const struct hid_blacklist { |
1da177e4 LT |
1620 | __u16 idVendor; |
1621 | __u16 idProduct; | |
1622 | unsigned quirks; | |
1623 | } hid_blacklist[] = { | |
1624 | ||
1625 | { USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_01, HID_QUIRK_IGNORE }, | |
1626 | { USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_10, HID_QUIRK_IGNORE }, | |
1627 | { USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_20, HID_QUIRK_IGNORE }, | |
1628 | { USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_21, HID_QUIRK_IGNORE }, | |
1629 | { USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_22, HID_QUIRK_IGNORE }, | |
1630 | { USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_23, HID_QUIRK_IGNORE }, | |
1631 | { USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_24, HID_QUIRK_IGNORE }, | |
8fd80133 | 1632 | { USB_VENDOR_ID_ALCOR, USB_DEVICE_ID_ALCOR_USBRS232, HID_QUIRK_IGNORE }, |
1da177e4 LT |
1633 | { USB_VENDOR_ID_BERKSHIRE, USB_DEVICE_ID_BERKSHIRE_PCWD, HID_QUIRK_IGNORE }, |
1634 | { USB_VENDOR_ID_CODEMERCS, USB_DEVICE_ID_CODEMERCS_IOW40, HID_QUIRK_IGNORE }, | |
1635 | { USB_VENDOR_ID_CODEMERCS, USB_DEVICE_ID_CODEMERCS_IOW24, HID_QUIRK_IGNORE }, | |
1636 | { USB_VENDOR_ID_CODEMERCS, USB_DEVICE_ID_CODEMERCS_IOW48, HID_QUIRK_IGNORE }, | |
1637 | { USB_VENDOR_ID_CODEMERCS, USB_DEVICE_ID_CODEMERCS_IOW28, HID_QUIRK_IGNORE }, | |
1638 | { USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_HIDCOM, HID_QUIRK_IGNORE }, | |
7d25258f | 1639 | { USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_ULTRAMOUSE, HID_QUIRK_IGNORE }, |
1da177e4 | 1640 | { USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EARTHMATE, HID_QUIRK_IGNORE }, |
dc1d1003 | 1641 | { USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EM_LT20, HID_QUIRK_IGNORE }, |
1da177e4 LT |
1642 | { USB_VENDOR_ID_ESSENTIAL_REALITY, USB_DEVICE_ID_ESSENTIAL_REALITY_P5, HID_QUIRK_IGNORE }, |
1643 | { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_4_PHIDGETSERVO_30, HID_QUIRK_IGNORE }, | |
1644 | { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_1_PHIDGETSERVO_30, HID_QUIRK_IGNORE }, | |
1da177e4 | 1645 | { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_0_4_IF_KIT, HID_QUIRK_IGNORE }, |
d5176b41 SY |
1646 | { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_16_16_IF_KIT, HID_QUIRK_IGNORE }, |
1647 | { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_8_8_8_IF_KIT, HID_QUIRK_IGNORE }, | |
1648 | { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_8_7_IF_KIT, HID_QUIRK_IGNORE }, | |
1da177e4 | 1649 | { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_8_8_IF_KIT, HID_QUIRK_IGNORE }, |
d5176b41 | 1650 | { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_PHIDGET_MOTORCONTROL, HID_QUIRK_IGNORE }, |
1da177e4 LT |
1651 | { USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_POWERMATE, HID_QUIRK_IGNORE }, |
1652 | { USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_SOUNDKNOB, HID_QUIRK_IGNORE }, | |
6f8d9e26 JR |
1653 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_90, HID_QUIRK_IGNORE }, |
1654 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_100, HID_QUIRK_IGNORE }, | |
1655 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_101, HID_QUIRK_IGNORE }, | |
1656 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_103, HID_QUIRK_IGNORE }, | |
1657 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_104, HID_QUIRK_IGNORE }, | |
1658 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_105, HID_QUIRK_IGNORE }, | |
1659 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_106, HID_QUIRK_IGNORE }, | |
1660 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_107, HID_QUIRK_IGNORE }, | |
1661 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_108, HID_QUIRK_IGNORE }, | |
1662 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_200, HID_QUIRK_IGNORE }, | |
1663 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_201, HID_QUIRK_IGNORE }, | |
1664 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_202, HID_QUIRK_IGNORE }, | |
1665 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_203, HID_QUIRK_IGNORE }, | |
1666 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_204, HID_QUIRK_IGNORE }, | |
1667 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_205, HID_QUIRK_IGNORE }, | |
1668 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_206, HID_QUIRK_IGNORE }, | |
1669 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_207, HID_QUIRK_IGNORE }, | |
1670 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_300, HID_QUIRK_IGNORE }, | |
1671 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_301, HID_QUIRK_IGNORE }, | |
1672 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_302, HID_QUIRK_IGNORE }, | |
1673 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_303, HID_QUIRK_IGNORE }, | |
1674 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_304, HID_QUIRK_IGNORE }, | |
1675 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_305, HID_QUIRK_IGNORE }, | |
1676 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_306, HID_QUIRK_IGNORE }, | |
1677 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_307, HID_QUIRK_IGNORE }, | |
1678 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_308, HID_QUIRK_IGNORE }, | |
1679 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_309, HID_QUIRK_IGNORE }, | |
1680 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_400, HID_QUIRK_IGNORE }, | |
1681 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_401, HID_QUIRK_IGNORE }, | |
1682 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_402, HID_QUIRK_IGNORE }, | |
1683 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_403, HID_QUIRK_IGNORE }, | |
1684 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_404, HID_QUIRK_IGNORE }, | |
f0649024 | 1685 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_405, HID_QUIRK_IGNORE }, |
6f8d9e26 JR |
1686 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_500, HID_QUIRK_IGNORE }, |
1687 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_501, HID_QUIRK_IGNORE }, | |
1688 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_502, HID_QUIRK_IGNORE }, | |
1689 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_503, HID_QUIRK_IGNORE }, | |
1690 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_504, HID_QUIRK_IGNORE }, | |
1691 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1000, HID_QUIRK_IGNORE }, | |
1692 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1001, HID_QUIRK_IGNORE }, | |
1693 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1002, HID_QUIRK_IGNORE }, | |
1694 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1003, HID_QUIRK_IGNORE }, | |
1695 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1004, HID_QUIRK_IGNORE }, | |
1696 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1005, HID_QUIRK_IGNORE }, | |
1697 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1006, HID_QUIRK_IGNORE }, | |
1da177e4 | 1698 | { USB_VENDOR_ID_KBGEAR, USB_DEVICE_ID_KBGEAR_JAMSTUDIO, HID_QUIRK_IGNORE }, |
ba3e66e9 MH |
1699 | { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CASSY, HID_QUIRK_IGNORE }, |
1700 | { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POCKETCASSY, HID_QUIRK_IGNORE }, | |
1701 | { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOBILECASSY, HID_QUIRK_IGNORE }, | |
1702 | { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_JWM, HID_QUIRK_IGNORE }, | |
1703 | { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_DMMP, HID_QUIRK_IGNORE }, | |
1704 | { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIP, HID_QUIRK_IGNORE }, | |
1705 | { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY1, HID_QUIRK_IGNORE }, | |
1706 | { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY2, HID_QUIRK_IGNORE }, | |
1707 | { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_VIDEOCOM, HID_QUIRK_IGNORE }, | |
1708 | { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_COM3LAB, HID_QUIRK_IGNORE }, | |
1709 | { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_TELEPORT, HID_QUIRK_IGNORE }, | |
1710 | { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_NETWORKANALYSER, HID_QUIRK_IGNORE }, | |
1711 | { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POWERCONTROL, HID_QUIRK_IGNORE }, | |
1712 | { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MACHINETEST, HID_QUIRK_IGNORE }, | |
1da177e4 LT |
1713 | { USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1024LS, HID_QUIRK_IGNORE }, |
1714 | { USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1208LS, HID_QUIRK_IGNORE }, | |
1715 | { USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS, HID_QUIRK_IGNORE }, | |
1716 | { USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS1, HID_QUIRK_IGNORE }, | |
1717 | { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100, HID_QUIRK_IGNORE }, | |
03270634 SH |
1718 | { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 20, HID_QUIRK_IGNORE }, |
1719 | { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 30, HID_QUIRK_IGNORE }, | |
1da177e4 | 1720 | { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 100, HID_QUIRK_IGNORE }, |
03270634 SH |
1721 | { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 108, HID_QUIRK_IGNORE }, |
1722 | { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 118, HID_QUIRK_IGNORE }, | |
1da177e4 LT |
1723 | { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 200, HID_QUIRK_IGNORE }, |
1724 | { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 300, HID_QUIRK_IGNORE }, | |
1725 | { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 400, HID_QUIRK_IGNORE }, | |
1726 | { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 500, HID_QUIRK_IGNORE }, | |
4871d3be GKH |
1727 | { USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_LABPRO, HID_QUIRK_IGNORE }, |
1728 | { USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_GOTEMP, HID_QUIRK_IGNORE }, | |
1729 | { USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_SKIP, HID_QUIRK_IGNORE }, | |
1730 | { USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_CYCLOPS, HID_QUIRK_IGNORE }, | |
1da177e4 LT |
1731 | { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_4_PHIDGETSERVO_20, HID_QUIRK_IGNORE }, |
1732 | { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_1_PHIDGETSERVO_20, HID_QUIRK_IGNORE }, | |
d5176b41 | 1733 | { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_8_8_4_IF_KIT, HID_QUIRK_IGNORE }, |
5cd330f4 | 1734 | { USB_VENDOR_ID_YEALINK, USB_DEVICE_ID_YEALINK_P1K_P4K_B2K, HID_QUIRK_IGNORE }, |
1da177e4 | 1735 | |
53880546 SV |
1736 | { USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_FLAIR, HID_QUIRK_IGNORE }, |
1737 | { USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_302, HID_QUIRK_IGNORE }, | |
1738 | ||
1da177e4 LT |
1739 | { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_UC100KM, HID_QUIRK_NOGET }, |
1740 | { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_CS124U, HID_QUIRK_NOGET }, | |
1741 | { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_2PORTKVM, HID_QUIRK_NOGET }, | |
1742 | { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_4PORTKVM, HID_QUIRK_NOGET }, | |
1743 | { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_4PORTKVMC, HID_QUIRK_NOGET }, | |
931e24b9 | 1744 | { USB_VENDOR_ID_SUN, USB_DEVICE_ID_RARITAN_KVM_DONGLE, HID_QUIRK_NOGET }, |
e65335ef | 1745 | { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_DUAL_USB_JOYPAD, HID_QUIRK_NOGET | HID_QUIRK_MULTI_INPUT }, |
b857c651 | 1746 | { USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SMARTJOY_DUAL_PLUS, HID_QUIRK_NOGET | HID_QUIRK_MULTI_INPUT }, |
1da177e4 | 1747 | |
a82e49b8 | 1748 | { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MIGHTYMOUSE, HID_QUIRK_MIGHTYMOUSE | HID_QUIRK_INVERT_HWHEEL }, |
1da177e4 LT |
1749 | { USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_WCP32PU, HID_QUIRK_2WHEEL_MOUSE_HACK_7 }, |
1750 | { USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_MOUSE, HID_QUIRK_2WHEEL_MOUSE_HACK_5 }, | |
1751 | ||
6345fdfd | 1752 | { USB_VENDOR_ID_AASHIMA, USB_DEVICE_ID_AASHIMA_GAMEPAD, HID_QUIRK_BADPAD }, |
61cdecd9 | 1753 | { USB_VENDOR_ID_AASHIMA, USB_DEVICE_ID_AASHIMA_PREDATOR, HID_QUIRK_BADPAD }, |
1da177e4 LT |
1754 | { USB_VENDOR_ID_ALPS, USB_DEVICE_ID_IBM_GAMEPAD, HID_QUIRK_BADPAD }, |
1755 | { USB_VENDOR_ID_CHIC, USB_DEVICE_ID_CHIC_GAMEPAD, HID_QUIRK_BADPAD }, | |
1756 | { USB_VENDOR_ID_HAPP, USB_DEVICE_ID_UGCI_DRIVING, HID_QUIRK_BADPAD | HID_QUIRK_MULTI_INPUT }, | |
1757 | { USB_VENDOR_ID_HAPP, USB_DEVICE_ID_UGCI_FLYING, HID_QUIRK_BADPAD | HID_QUIRK_MULTI_INPUT }, | |
1758 | { USB_VENDOR_ID_HAPP, USB_DEVICE_ID_UGCI_FIGHTING, HID_QUIRK_BADPAD | HID_QUIRK_MULTI_INPUT }, | |
1759 | { USB_VENDOR_ID_NEC, USB_DEVICE_ID_NEC_USB_GAME_PAD, HID_QUIRK_BADPAD }, | |
1760 | { USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_RUMBLEPAD, HID_QUIRK_BADPAD }, | |
1761 | { USB_VENDOR_ID_TOPMAX, USB_DEVICE_ID_TOPMAX_COBRAPAD, HID_QUIRK_BADPAD }, | |
1762 | ||
940824b0 VP |
1763 | { USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION, HID_QUIRK_CYMOTION }, |
1764 | ||
eab9edd2 MH |
1765 | { USB_VENDOR_ID_APPLE, 0x020E, HID_QUIRK_POWERBOOK_HAS_FN }, |
1766 | { USB_VENDOR_ID_APPLE, 0x020F, HID_QUIRK_POWERBOOK_HAS_FN }, | |
1767 | { USB_VENDOR_ID_APPLE, 0x0214, HID_QUIRK_POWERBOOK_HAS_FN }, | |
1768 | { USB_VENDOR_ID_APPLE, 0x0215, HID_QUIRK_POWERBOOK_HAS_FN }, | |
1769 | { USB_VENDOR_ID_APPLE, 0x0216, HID_QUIRK_POWERBOOK_HAS_FN }, | |
5c218e3b RR |
1770 | { USB_VENDOR_ID_APPLE, 0x0217, HID_QUIRK_POWERBOOK_HAS_FN }, |
1771 | { USB_VENDOR_ID_APPLE, 0x0218, HID_QUIRK_POWERBOOK_HAS_FN }, | |
1772 | { USB_VENDOR_ID_APPLE, 0x0219, HID_QUIRK_POWERBOOK_HAS_FN }, | |
eab9edd2 MH |
1773 | { USB_VENDOR_ID_APPLE, 0x030A, HID_QUIRK_POWERBOOK_HAS_FN }, |
1774 | { USB_VENDOR_ID_APPLE, 0x030B, HID_QUIRK_POWERBOOK_HAS_FN }, | |
1775 | ||
1d3e2023 DR |
1776 | { USB_VENDOR_ID_PANJIT, 0x0001, HID_QUIRK_IGNORE }, |
1777 | { USB_VENDOR_ID_PANJIT, 0x0002, HID_QUIRK_IGNORE }, | |
1778 | { USB_VENDOR_ID_PANJIT, 0x0003, HID_QUIRK_IGNORE }, | |
1779 | { USB_VENDOR_ID_PANJIT, 0x0004, HID_QUIRK_IGNORE }, | |
1780 | ||
1da177e4 LT |
1781 | { 0, 0 } |
1782 | }; | |
1783 | ||
bf0964dc MH |
1784 | /* |
1785 | * Traverse the supplied list of reports and find the longest | |
1786 | */ | |
1787 | static void hid_find_max_report(struct hid_device *hid, unsigned int type, int *max) | |
1788 | { | |
1789 | struct hid_report *report; | |
1790 | int size; | |
1791 | ||
1792 | list_for_each_entry(report, &hid->report_enum[type].report_list, list) { | |
1793 | size = ((report->size - 1) >> 3) + 1; | |
1794 | if (type == HID_INPUT_REPORT && hid->report_enum[type].numbered) | |
1795 | size++; | |
1796 | if (*max < size) | |
1797 | *max = size; | |
1798 | } | |
1799 | } | |
1800 | ||
1da177e4 LT |
1801 | static int hid_alloc_buffers(struct usb_device *dev, struct hid_device *hid) |
1802 | { | |
bf0964dc | 1803 | if (!(hid->inbuf = usb_buffer_alloc(dev, hid->bufsize, SLAB_ATOMIC, &hid->inbuf_dma))) |
1da177e4 | 1804 | return -1; |
bf0964dc | 1805 | if (!(hid->outbuf = usb_buffer_alloc(dev, hid->bufsize, SLAB_ATOMIC, &hid->outbuf_dma))) |
1da177e4 LT |
1806 | return -1; |
1807 | if (!(hid->cr = usb_buffer_alloc(dev, sizeof(*(hid->cr)), SLAB_ATOMIC, &hid->cr_dma))) | |
1808 | return -1; | |
bf0964dc | 1809 | if (!(hid->ctrlbuf = usb_buffer_alloc(dev, hid->bufsize, SLAB_ATOMIC, &hid->ctrlbuf_dma))) |
1da177e4 LT |
1810 | return -1; |
1811 | ||
1812 | return 0; | |
1813 | } | |
1814 | ||
1815 | static void hid_free_buffers(struct usb_device *dev, struct hid_device *hid) | |
1816 | { | |
1817 | if (hid->inbuf) | |
bf0964dc | 1818 | usb_buffer_free(dev, hid->bufsize, hid->inbuf, hid->inbuf_dma); |
1da177e4 | 1819 | if (hid->outbuf) |
bf0964dc | 1820 | usb_buffer_free(dev, hid->bufsize, hid->outbuf, hid->outbuf_dma); |
1da177e4 LT |
1821 | if (hid->cr) |
1822 | usb_buffer_free(dev, sizeof(*(hid->cr)), hid->cr, hid->cr_dma); | |
1823 | if (hid->ctrlbuf) | |
bf0964dc | 1824 | usb_buffer_free(dev, hid->bufsize, hid->ctrlbuf, hid->ctrlbuf_dma); |
1da177e4 LT |
1825 | } |
1826 | ||
940824b0 VP |
1827 | /* |
1828 | * Cherry Cymotion keyboard have an invalid HID report descriptor, | |
1829 | * that needs fixing before we can parse it. | |
1830 | */ | |
1831 | ||
1832 | static void hid_fixup_cymotion_descriptor(char *rdesc, int rsize) | |
1833 | { | |
1834 | if (rsize >= 17 && rdesc[11] == 0x3c && rdesc[12] == 0x02) { | |
1835 | info("Fixing up Cherry Cymotion report descriptor"); | |
1836 | rdesc[11] = rdesc[16] = 0xff; | |
1837 | rdesc[12] = rdesc[17] = 0x03; | |
1838 | } | |
1839 | } | |
1840 | ||
1da177e4 LT |
1841 | static struct hid_device *usb_hid_configure(struct usb_interface *intf) |
1842 | { | |
1843 | struct usb_host_interface *interface = intf->cur_altsetting; | |
1844 | struct usb_device *dev = interface_to_usbdev (intf); | |
1845 | struct hid_descriptor *hdesc; | |
1846 | struct hid_device *hid; | |
1847 | unsigned quirks = 0, rsize = 0; | |
c5b7c7c3 DT |
1848 | char *rdesc; |
1849 | int n, len, insize = 0; | |
1da177e4 | 1850 | |
ea186651 | 1851 | /* Ignore all Wacom devices */ |
c03efdb2 | 1852 | if (le16_to_cpu(dev->descriptor.idVendor) == USB_VENDOR_ID_WACOM) |
ea186651 PC |
1853 | return NULL; |
1854 | ||
1da177e4 LT |
1855 | for (n = 0; hid_blacklist[n].idVendor; n++) |
1856 | if ((hid_blacklist[n].idVendor == le16_to_cpu(dev->descriptor.idVendor)) && | |
1857 | (hid_blacklist[n].idProduct == le16_to_cpu(dev->descriptor.idProduct))) | |
1858 | quirks = hid_blacklist[n].quirks; | |
1859 | ||
0f28b55d AS |
1860 | /* Many keyboards and mice don't like to be polled for reports, |
1861 | * so we will always set the HID_QUIRK_NOGET flag for them. */ | |
1862 | if (interface->desc.bInterfaceSubClass == USB_INTERFACE_SUBCLASS_BOOT) { | |
1863 | if (interface->desc.bInterfaceProtocol == USB_INTERFACE_PROTOCOL_KEYBOARD || | |
1864 | interface->desc.bInterfaceProtocol == USB_INTERFACE_PROTOCOL_MOUSE) | |
1865 | quirks |= HID_QUIRK_NOGET; | |
1866 | } | |
1867 | ||
1da177e4 LT |
1868 | if (quirks & HID_QUIRK_IGNORE) |
1869 | return NULL; | |
1870 | ||
c5b7c7c3 DT |
1871 | if (usb_get_extra_descriptor(interface, HID_DT_HID, &hdesc) && |
1872 | (!interface->desc.bNumEndpoints || | |
1873 | usb_get_extra_descriptor(&interface->endpoint[0], HID_DT_HID, &hdesc))) { | |
1874 | dbg("class descriptor not present\n"); | |
1875 | return NULL; | |
1da177e4 LT |
1876 | } |
1877 | ||
1878 | for (n = 0; n < hdesc->bNumDescriptors; n++) | |
1879 | if (hdesc->desc[n].bDescriptorType == HID_DT_REPORT) | |
1880 | rsize = le16_to_cpu(hdesc->desc[n].wDescriptorLength); | |
1881 | ||
1882 | if (!rsize || rsize > HID_MAX_DESCRIPTOR_SIZE) { | |
1883 | dbg("weird size of report descriptor (%u)", rsize); | |
1884 | return NULL; | |
1885 | } | |
1886 | ||
1887 | if (!(rdesc = kmalloc(rsize, GFP_KERNEL))) { | |
1888 | dbg("couldn't allocate rdesc memory"); | |
1889 | return NULL; | |
1890 | } | |
1891 | ||
854561b0 VP |
1892 | hid_set_idle(dev, interface->desc.bInterfaceNumber, 0, 0); |
1893 | ||
1da177e4 LT |
1894 | if ((n = hid_get_class_descriptor(dev, interface->desc.bInterfaceNumber, HID_DT_REPORT, rdesc, rsize)) < 0) { |
1895 | dbg("reading report descriptor failed"); | |
1896 | kfree(rdesc); | |
1897 | return NULL; | |
1898 | } | |
1899 | ||
940824b0 VP |
1900 | if ((quirks & HID_QUIRK_CYMOTION)) |
1901 | hid_fixup_cymotion_descriptor(rdesc, rsize); | |
1902 | ||
1da177e4 LT |
1903 | #ifdef DEBUG_DATA |
1904 | printk(KERN_DEBUG __FILE__ ": report descriptor (size %u, read %d) = ", rsize, n); | |
1905 | for (n = 0; n < rsize; n++) | |
1906 | printk(" %02x", (unsigned char) rdesc[n]); | |
1907 | printk("\n"); | |
1908 | #endif | |
1909 | ||
1910 | if (!(hid = hid_parse_report(rdesc, n))) { | |
1911 | dbg("parsing report descriptor failed"); | |
1912 | kfree(rdesc); | |
1913 | return NULL; | |
1914 | } | |
1915 | ||
1916 | kfree(rdesc); | |
1917 | hid->quirks = quirks; | |
1918 | ||
bf0964dc MH |
1919 | hid->bufsize = HID_MIN_BUFFER_SIZE; |
1920 | hid_find_max_report(hid, HID_INPUT_REPORT, &hid->bufsize); | |
1921 | hid_find_max_report(hid, HID_OUTPUT_REPORT, &hid->bufsize); | |
1922 | hid_find_max_report(hid, HID_FEATURE_REPORT, &hid->bufsize); | |
1923 | ||
1924 | if (hid->bufsize > HID_MAX_BUFFER_SIZE) | |
1925 | hid->bufsize = HID_MAX_BUFFER_SIZE; | |
1926 | ||
1927 | hid_find_max_report(hid, HID_INPUT_REPORT, &insize); | |
1928 | ||
1929 | if (insize > HID_MAX_BUFFER_SIZE) | |
1930 | insize = HID_MAX_BUFFER_SIZE; | |
1931 | ||
1da177e4 LT |
1932 | if (hid_alloc_buffers(dev, hid)) { |
1933 | hid_free_buffers(dev, hid); | |
1934 | goto fail; | |
1935 | } | |
1936 | ||
1937 | for (n = 0; n < interface->desc.bNumEndpoints; n++) { | |
1938 | ||
1939 | struct usb_endpoint_descriptor *endpoint; | |
1940 | int pipe; | |
1941 | int interval; | |
1942 | ||
1943 | endpoint = &interface->endpoint[n].desc; | |
1944 | if ((endpoint->bmAttributes & 3) != 3) /* Not an interrupt endpoint */ | |
1945 | continue; | |
1946 | ||
1da177e4 | 1947 | interval = endpoint->bInterval; |
1da177e4 LT |
1948 | |
1949 | /* Change the polling interval of mice. */ | |
1950 | if (hid->collection->usage == HID_GD_MOUSE && hid_mousepoll_interval > 0) | |
1951 | interval = hid_mousepoll_interval; | |
05f091ab | 1952 | |
1da177e4 LT |
1953 | if (endpoint->bEndpointAddress & USB_DIR_IN) { |
1954 | if (hid->urbin) | |
1955 | continue; | |
1956 | if (!(hid->urbin = usb_alloc_urb(0, GFP_KERNEL))) | |
1957 | goto fail; | |
1958 | pipe = usb_rcvintpipe(dev, endpoint->bEndpointAddress); | |
bf0964dc | 1959 | usb_fill_int_urb(hid->urbin, dev, pipe, hid->inbuf, insize, |
1da177e4 LT |
1960 | hid_irq_in, hid, interval); |
1961 | hid->urbin->transfer_dma = hid->inbuf_dma; | |
b375a049 | 1962 | hid->urbin->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; |
1da177e4 LT |
1963 | } else { |
1964 | if (hid->urbout) | |
1965 | continue; | |
1966 | if (!(hid->urbout = usb_alloc_urb(0, GFP_KERNEL))) | |
1967 | goto fail; | |
1968 | pipe = usb_sndintpipe(dev, endpoint->bEndpointAddress); | |
1969 | usb_fill_int_urb(hid->urbout, dev, pipe, hid->outbuf, 0, | |
1970 | hid_irq_out, hid, interval); | |
1971 | hid->urbout->transfer_dma = hid->outbuf_dma; | |
b375a049 | 1972 | hid->urbout->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; |
1da177e4 LT |
1973 | } |
1974 | } | |
1975 | ||
1976 | if (!hid->urbin) { | |
1977 | err("couldn't find an input interrupt endpoint"); | |
1978 | goto fail; | |
1979 | } | |
1980 | ||
1981 | init_waitqueue_head(&hid->wait); | |
1982 | ||
aef4e266 AS |
1983 | INIT_WORK(&hid->reset_work, hid_reset, hid); |
1984 | setup_timer(&hid->io_retry, hid_retry_timeout, (unsigned long) hid); | |
1985 | ||
1986 | spin_lock_init(&hid->inlock); | |
1da177e4 LT |
1987 | spin_lock_init(&hid->outlock); |
1988 | spin_lock_init(&hid->ctrllock); | |
1989 | ||
1990 | hid->version = le16_to_cpu(hdesc->bcdHID); | |
1991 | hid->country = hdesc->bCountryCode; | |
1992 | hid->dev = dev; | |
1993 | hid->intf = intf; | |
1994 | hid->ifnum = interface->desc.bInterfaceNumber; | |
1995 | ||
1996 | hid->name[0] = 0; | |
1997 | ||
c5b7c7c3 DT |
1998 | if (dev->manufacturer) |
1999 | strlcpy(hid->name, dev->manufacturer, sizeof(hid->name)); | |
2000 | ||
2001 | if (dev->product) { | |
2002 | if (dev->manufacturer) | |
2003 | strlcat(hid->name, " ", sizeof(hid->name)); | |
2004 | strlcat(hid->name, dev->product, sizeof(hid->name)); | |
2005 | } | |
2006 | ||
2007 | if (!strlen(hid->name)) | |
2008 | snprintf(hid->name, sizeof(hid->name), "HID %04x:%04x", | |
2009 | le16_to_cpu(dev->descriptor.idVendor), | |
2010 | le16_to_cpu(dev->descriptor.idProduct)); | |
1da177e4 | 2011 | |
c5b7c7c3 DT |
2012 | usb_make_path(dev, hid->phys, sizeof(hid->phys)); |
2013 | strlcat(hid->phys, "/input", sizeof(hid->phys)); | |
2014 | len = strlen(hid->phys); | |
2015 | if (len < sizeof(hid->phys) - 1) | |
2016 | snprintf(hid->phys + len, sizeof(hid->phys) - len, | |
2017 | "%d", intf->altsetting[0].desc.bInterfaceNumber); | |
1da177e4 LT |
2018 | |
2019 | if (usb_string(dev, dev->descriptor.iSerialNumber, hid->uniq, 64) <= 0) | |
2020 | hid->uniq[0] = 0; | |
2021 | ||
1da177e4 LT |
2022 | hid->urbctrl = usb_alloc_urb(0, GFP_KERNEL); |
2023 | if (!hid->urbctrl) | |
2024 | goto fail; | |
c5b7c7c3 | 2025 | |
1da177e4 LT |
2026 | usb_fill_control_urb(hid->urbctrl, dev, 0, (void *) hid->cr, |
2027 | hid->ctrlbuf, 1, hid_ctrl, hid); | |
2028 | hid->urbctrl->setup_dma = hid->cr_dma; | |
2029 | hid->urbctrl->transfer_dma = hid->ctrlbuf_dma; | |
b375a049 | 2030 | hid->urbctrl->transfer_flags |= (URB_NO_TRANSFER_DMA_MAP | URB_NO_SETUP_DMA_MAP); |
1da177e4 LT |
2031 | |
2032 | return hid; | |
2033 | ||
2034 | fail: | |
2035 | ||
2036 | if (hid->urbin) | |
2037 | usb_free_urb(hid->urbin); | |
2038 | if (hid->urbout) | |
2039 | usb_free_urb(hid->urbout); | |
2040 | if (hid->urbctrl) | |
2041 | usb_free_urb(hid->urbctrl); | |
2042 | hid_free_buffers(dev, hid); | |
2043 | hid_free_device(hid); | |
2044 | ||
2045 | return NULL; | |
2046 | } | |
2047 | ||
2048 | static void hid_disconnect(struct usb_interface *intf) | |
2049 | { | |
2050 | struct hid_device *hid = usb_get_intfdata (intf); | |
2051 | ||
2052 | if (!hid) | |
2053 | return; | |
2054 | ||
aef4e266 | 2055 | spin_lock_irq(&hid->inlock); /* Sync with error handler */ |
1da177e4 | 2056 | usb_set_intfdata(intf, NULL); |
aef4e266 | 2057 | spin_unlock_irq(&hid->inlock); |
1da177e4 LT |
2058 | usb_kill_urb(hid->urbin); |
2059 | usb_kill_urb(hid->urbout); | |
2060 | usb_kill_urb(hid->urbctrl); | |
2061 | ||
aef4e266 AS |
2062 | del_timer_sync(&hid->io_retry); |
2063 | flush_scheduled_work(); | |
2064 | ||
1da177e4 LT |
2065 | if (hid->claimed & HID_CLAIMED_INPUT) |
2066 | hidinput_disconnect(hid); | |
2067 | if (hid->claimed & HID_CLAIMED_HIDDEV) | |
2068 | hiddev_disconnect(hid); | |
2069 | ||
2070 | usb_free_urb(hid->urbin); | |
2071 | usb_free_urb(hid->urbctrl); | |
2072 | if (hid->urbout) | |
2073 | usb_free_urb(hid->urbout); | |
2074 | ||
2075 | hid_free_buffers(hid->dev, hid); | |
2076 | hid_free_device(hid); | |
2077 | } | |
2078 | ||
2079 | static int hid_probe(struct usb_interface *intf, const struct usb_device_id *id) | |
2080 | { | |
2081 | struct hid_device *hid; | |
2082 | char path[64]; | |
2083 | int i; | |
2084 | char *c; | |
2085 | ||
2086 | dbg("HID probe called for ifnum %d", | |
2087 | intf->altsetting->desc.bInterfaceNumber); | |
2088 | ||
2089 | if (!(hid = usb_hid_configure(intf))) | |
479f6ea8 | 2090 | return -ENODEV; |
1da177e4 LT |
2091 | |
2092 | hid_init_reports(hid); | |
2093 | hid_dump_device(hid); | |
2094 | ||
2095 | if (!hidinput_connect(hid)) | |
2096 | hid->claimed |= HID_CLAIMED_INPUT; | |
2097 | if (!hiddev_connect(hid)) | |
2098 | hid->claimed |= HID_CLAIMED_HIDDEV; | |
2099 | ||
2100 | usb_set_intfdata(intf, hid); | |
2101 | ||
2102 | if (!hid->claimed) { | |
2103 | printk ("HID device not claimed by input or hiddev\n"); | |
2104 | hid_disconnect(intf); | |
479f6ea8 | 2105 | return -ENODEV; |
1da177e4 LT |
2106 | } |
2107 | ||
2108 | printk(KERN_INFO); | |
2109 | ||
2110 | if (hid->claimed & HID_CLAIMED_INPUT) | |
2111 | printk("input"); | |
2112 | if (hid->claimed == (HID_CLAIMED_INPUT | HID_CLAIMED_HIDDEV)) | |
2113 | printk(","); | |
2114 | if (hid->claimed & HID_CLAIMED_HIDDEV) | |
2115 | printk("hiddev%d", hid->minor); | |
2116 | ||
2117 | c = "Device"; | |
2118 | for (i = 0; i < hid->maxcollection; i++) { | |
2119 | if (hid->collection[i].type == HID_COLLECTION_APPLICATION && | |
2120 | (hid->collection[i].usage & HID_USAGE_PAGE) == HID_UP_GENDESK && | |
2121 | (hid->collection[i].usage & 0xffff) < ARRAY_SIZE(hid_types)) { | |
2122 | c = hid_types[hid->collection[i].usage & 0xffff]; | |
2123 | break; | |
2124 | } | |
2125 | } | |
2126 | ||
2127 | usb_make_path(interface_to_usbdev(intf), path, 63); | |
2128 | ||
2129 | printk(": USB HID v%x.%02x %s [%s] on %s\n", | |
2130 | hid->version >> 8, hid->version & 0xff, c, hid->name, path); | |
2131 | ||
2132 | return 0; | |
2133 | } | |
2134 | ||
27d72e85 | 2135 | static int hid_suspend(struct usb_interface *intf, pm_message_t message) |
1da177e4 LT |
2136 | { |
2137 | struct hid_device *hid = usb_get_intfdata (intf); | |
2138 | ||
aef4e266 AS |
2139 | spin_lock_irq(&hid->inlock); /* Sync with error handler */ |
2140 | set_bit(HID_SUSPENDED, &hid->iofl); | |
2141 | spin_unlock_irq(&hid->inlock); | |
2142 | del_timer(&hid->io_retry); | |
1da177e4 | 2143 | usb_kill_urb(hid->urbin); |
1da177e4 LT |
2144 | dev_dbg(&intf->dev, "suspend\n"); |
2145 | return 0; | |
2146 | } | |
2147 | ||
2148 | static int hid_resume(struct usb_interface *intf) | |
2149 | { | |
2150 | struct hid_device *hid = usb_get_intfdata (intf); | |
2151 | int status; | |
2152 | ||
aef4e266 | 2153 | clear_bit(HID_SUSPENDED, &hid->iofl); |
df9a1f48 | 2154 | hid->retry_delay = 0; |
aef4e266 | 2155 | status = hid_start_in(hid); |
1da177e4 LT |
2156 | dev_dbg(&intf->dev, "resume status %d\n", status); |
2157 | return status; | |
2158 | } | |
2159 | ||
df9a1f48 AS |
2160 | /* Treat USB reset pretty much the same as suspend/resume */ |
2161 | static void hid_pre_reset(struct usb_interface *intf) | |
2162 | { | |
2163 | /* FIXME: What if the interface is already suspended? */ | |
2164 | hid_suspend(intf, PMSG_ON); | |
2165 | } | |
2166 | ||
2167 | static void hid_post_reset(struct usb_interface *intf) | |
2168 | { | |
2169 | struct usb_device *dev = interface_to_usbdev (intf); | |
2170 | ||
2171 | hid_set_idle(dev, intf->cur_altsetting->desc.bInterfaceNumber, 0, 0); | |
2172 | /* FIXME: Any more reinitialization needed? */ | |
2173 | ||
2174 | hid_resume(intf); | |
2175 | } | |
2176 | ||
1da177e4 LT |
2177 | static struct usb_device_id hid_usb_ids [] = { |
2178 | { .match_flags = USB_DEVICE_ID_MATCH_INT_CLASS, | |
2179 | .bInterfaceClass = USB_INTERFACE_CLASS_HID }, | |
2180 | { } /* Terminating entry */ | |
2181 | }; | |
2182 | ||
2183 | MODULE_DEVICE_TABLE (usb, hid_usb_ids); | |
2184 | ||
2185 | static struct usb_driver hid_driver = { | |
1da177e4 LT |
2186 | .name = "usbhid", |
2187 | .probe = hid_probe, | |
2188 | .disconnect = hid_disconnect, | |
2189 | .suspend = hid_suspend, | |
2190 | .resume = hid_resume, | |
df9a1f48 AS |
2191 | .pre_reset = hid_pre_reset, |
2192 | .post_reset = hid_post_reset, | |
1da177e4 LT |
2193 | .id_table = hid_usb_ids, |
2194 | }; | |
2195 | ||
2196 | static int __init hid_init(void) | |
2197 | { | |
2198 | int retval; | |
2199 | retval = hiddev_init(); | |
2200 | if (retval) | |
2201 | goto hiddev_init_fail; | |
2202 | retval = usb_register(&hid_driver); | |
2203 | if (retval) | |
2204 | goto usb_register_fail; | |
2205 | info(DRIVER_VERSION ":" DRIVER_DESC); | |
2206 | ||
2207 | return 0; | |
2208 | usb_register_fail: | |
2209 | hiddev_exit(); | |
2210 | hiddev_init_fail: | |
2211 | return retval; | |
2212 | } | |
2213 | ||
2214 | static void __exit hid_exit(void) | |
2215 | { | |
2216 | usb_deregister(&hid_driver); | |
2217 | hiddev_exit(); | |
2218 | } | |
2219 | ||
2220 | module_init(hid_init); | |
2221 | module_exit(hid_exit); | |
2222 | ||
2223 | MODULE_AUTHOR(DRIVER_AUTHOR); | |
2224 | MODULE_DESCRIPTION(DRIVER_DESC); | |
2225 | MODULE_LICENSE(DRIVER_LICENSE); |