Line data Source code
1 : /*
2 : * HID support for Linux
3 : *
4 : * Copyright (c) 1999 Andreas Gal
5 : * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
6 : * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
7 : * Copyright (c) 2006-2007 Jiri Kosina
8 : */
9 :
10 : /*
11 : * This program is free software; you can redistribute it and/or modify it
12 : * under the terms of the GNU General Public License as published by the Free
13 : * Software Foundation; either version 2 of the License, or (at your option)
14 : * any later version.
15 : */
16 :
17 : #include <linux/module.h>
18 : #include <linux/slab.h>
19 : #include <linux/init.h>
20 : #include <linux/kernel.h>
21 : #include <linux/list.h>
22 : #include <linux/mm.h>
23 : #include <linux/spinlock.h>
24 : #include <asm/unaligned.h>
25 : #include <asm/byteorder.h>
26 : #include <linux/input.h>
27 : #include <linux/wait.h>
28 : #include <linux/vmalloc.h>
29 : #include <linux/sched.h>
30 :
31 : #include <linux/hid.h>
32 : #include <linux/hiddev.h>
33 : #include <linux/hid-debug.h>
34 : #include <linux/hidraw.h>
35 :
36 : #include "hid-ids.h"
37 :
38 : /*
39 : * Version Information
40 : */
41 :
42 : #define DRIVER_DESC "HID core driver"
43 : #define DRIVER_LICENSE "GPL"
44 :
45 1 : int hid_debug = 0;
46 : module_param_named(debug, hid_debug, int, 0600);
47 : MODULE_PARM_DESC(debug, "toggle HID debugging messages");
48 : EXPORT_SYMBOL_GPL(hid_debug);
49 :
50 : /*
51 : * Register a new report for a device.
52 : */
53 :
54 : static struct hid_report *hid_register_report(struct hid_device *device, unsigned type, unsigned id)
55 : {
56 0 : struct hid_report_enum *report_enum = device->report_enum + type;
57 0 : struct hid_report *report;
58 0 :
59 0 : if (report_enum->report_id_hash[id])
60 0 : return report_enum->report_id_hash[id];
61 :
62 0 : if (!(report = kzalloc(sizeof(struct hid_report), GFP_KERNEL)))
63 0 : return NULL;
64 :
65 0 : if (id != 0)
66 0 : report_enum->numbered = 1;
67 :
68 0 : report->id = id;
69 0 : report->type = type;
70 0 : report->size = 0;
71 0 : report->device = device;
72 0 : report_enum->report_id_hash[id] = report;
73 :
74 0 : list_add_tail(&report->list, &report_enum->report_list);
75 :
76 0 : return report;
77 : }
78 :
79 : /*
80 : * Register a new field for this report.
81 : */
82 :
83 : static struct hid_field *hid_register_field(struct hid_report *report, unsigned usages, unsigned values)
84 : {
85 : struct hid_field *field;
86 0 :
87 0 : if (report->maxfield == HID_MAX_FIELDS) {
88 0 : dbg_hid("too many fields in report\n");
89 0 : return NULL;
90 : }
91 :
92 0 : if (!(field = kzalloc(sizeof(struct hid_field) + usages * sizeof(struct hid_usage)
93 0 : + values * sizeof(unsigned), GFP_KERNEL))) return NULL;
94 :
95 0 : field->index = report->maxfield++;
96 0 : report->field[field->index] = field;
97 0 : field->usage = (struct hid_usage *)(field + 1);
98 0 : field->value = (s32 *)(field->usage + usages);
99 0 : field->report = report;
100 :
101 0 : return field;
102 : }
103 :
104 : /*
105 : * Open a collection. The type/usage is pushed on the stack.
106 : */
107 :
108 : static int open_collection(struct hid_parser *parser, unsigned type)
109 : {
110 0 : struct hid_collection *collection;
111 0 : unsigned usage;
112 0 :
113 0 : usage = parser->local.usage[0];
114 0 :
115 0 : if (parser->collection_stack_ptr == HID_COLLECTION_STACK_SIZE) {
116 0 : dbg_hid("collection stack overflow\n");
117 0 : return -1;
118 : }
119 :
120 0 : if (parser->device->maxcollection == parser->device->collection_size) {
121 0 : collection = kmalloc(sizeof(struct hid_collection) *
122 : parser->device->collection_size * 2, GFP_KERNEL);
123 0 : if (collection == NULL) {
124 0 : dbg_hid("failed to reallocate collection array\n");
125 0 : return -1;
126 : }
127 0 : memcpy(collection, parser->device->collection,
128 : sizeof(struct hid_collection) *
129 : parser->device->collection_size);
130 0 : memset(collection + parser->device->collection_size, 0,
131 : sizeof(struct hid_collection) *
132 : parser->device->collection_size);
133 0 : kfree(parser->device->collection);
134 0 : parser->device->collection = collection;
135 0 : parser->device->collection_size *= 2;
136 : }
137 :
138 0 : parser->collection_stack[parser->collection_stack_ptr++] =
139 : parser->device->maxcollection;
140 :
141 0 : collection = parser->device->collection +
142 : parser->device->maxcollection++;
143 0 : collection->type = type;
144 0 : collection->usage = usage;
145 0 : collection->level = parser->collection_stack_ptr - 1;
146 :
147 0 : if (type == HID_COLLECTION_APPLICATION)
148 0 : parser->device->maxapplication++;
149 :
150 0 : return 0;
151 : }
152 :
153 : /*
154 : * Close a collection.
155 : */
156 :
157 : static int close_collection(struct hid_parser *parser)
158 : {
159 0 : if (!parser->collection_stack_ptr) {
160 0 : dbg_hid("collection stack underflow\n");
161 0 : return -1;
162 : }
163 0 : parser->collection_stack_ptr--;
164 0 : return 0;
165 : }
166 :
167 : /*
168 : * Climb up the stack, search for the specified collection type
169 : * and return the usage.
170 : */
171 :
172 : static unsigned hid_lookup_collection(struct hid_parser *parser, unsigned type)
173 : {
174 0 : int n;
175 0 : for (n = parser->collection_stack_ptr - 1; n >= 0; n--)
176 0 : if (parser->device->collection[parser->collection_stack[n]].type == type)
177 0 : return parser->device->collection[parser->collection_stack[n]].usage;
178 0 : return 0; /* we know nothing about this usage type */
179 : }
180 :
181 : /*
182 : * Add a usage to the temporary parser table.
183 : */
184 :
185 : static int hid_add_usage(struct hid_parser *parser, unsigned usage)
186 : {
187 0 : if (parser->local.usage_index >= HID_MAX_USAGES) {
188 0 : dbg_hid("usage index exceeded\n");
189 0 : return -1;
190 : }
191 0 : parser->local.usage[parser->local.usage_index] = usage;
192 0 : parser->local.collection_index[parser->local.usage_index] =
193 : parser->collection_stack_ptr ?
194 : parser->collection_stack[parser->collection_stack_ptr - 1] : 0;
195 0 : parser->local.usage_index++;
196 0 : return 0;
197 : }
198 :
199 : /*
200 : * Register a new field for this report.
201 : */
202 :
203 : static int hid_add_field(struct hid_parser *parser, unsigned report_type, unsigned flags)
204 : {
205 0 : struct hid_report *report;
206 0 : struct hid_field *field;
207 0 : int usages;
208 0 : unsigned offset;
209 0 : int i;
210 0 :
211 0 : if (!(report = hid_register_report(parser->device, report_type, parser->global.report_id))) {
212 0 : dbg_hid("hid_register_report failed\n");
213 0 : return -1;
214 : }
215 :
216 0 : if (parser->global.logical_maximum < parser->global.logical_minimum) {
217 0 : dbg_hid("logical range invalid %d %d\n", parser->global.logical_minimum, parser->global.logical_maximum);
218 0 : return -1;
219 : }
220 :
221 0 : offset = report->size;
222 0 : report->size += parser->global.report_size * parser->global.report_count;
223 :
224 0 : if (!parser->local.usage_index) /* Ignore padding fields */
225 0 : return 0;
226 :
227 0 : usages = max_t(int, parser->local.usage_index, parser->global.report_count);
228 :
229 0 : if ((field = hid_register_field(report, usages, parser->global.report_count)) == NULL)
230 0 : return 0;
231 :
232 0 : field->physical = hid_lookup_collection(parser, HID_COLLECTION_PHYSICAL);
233 0 : field->logical = hid_lookup_collection(parser, HID_COLLECTION_LOGICAL);
234 0 : field->application = hid_lookup_collection(parser, HID_COLLECTION_APPLICATION);
235 :
236 0 : for (i = 0; i < usages; i++) {
237 0 : int j = i;
238 0 : /* Duplicate the last usage we parsed if we have excess values */
239 0 : if (i >= parser->local.usage_index)
240 0 : j = parser->local.usage_index - 1;
241 0 : field->usage[i].hid = parser->local.usage[j];
242 0 : field->usage[i].collection_index =
243 : parser->local.collection_index[j];
244 : }
245 :
246 0 : field->maxusage = usages;
247 0 : field->flags = flags;
248 0 : field->report_offset = offset;
249 0 : field->report_type = report_type;
250 0 : field->report_size = parser->global.report_size;
251 0 : field->report_count = parser->global.report_count;
252 0 : field->logical_minimum = parser->global.logical_minimum;
253 0 : field->logical_maximum = parser->global.logical_maximum;
254 0 : field->physical_minimum = parser->global.physical_minimum;
255 0 : field->physical_maximum = parser->global.physical_maximum;
256 0 : field->unit_exponent = parser->global.unit_exponent;
257 0 : field->unit = parser->global.unit;
258 :
259 0 : return 0;
260 : }
261 :
262 : /*
263 : * Read data value from item.
264 : */
265 :
266 : static u32 item_udata(struct hid_item *item)
267 : {
268 0 : switch (item->size) {
269 0 : case 1: return item->data.u8;
270 0 : case 2: return item->data.u16;
271 0 : case 4: return item->data.u32;
272 0 : }
273 0 : return 0;
274 : }
275 :
276 : static s32 item_sdata(struct hid_item *item)
277 : {
278 0 : switch (item->size) {
279 0 : case 1: return item->data.s8;
280 0 : case 2: return item->data.s16;
281 0 : case 4: return item->data.s32;
282 0 : }
283 0 : return 0;
284 : }
285 :
286 : /*
287 : * Process a global item.
288 : */
289 :
290 : static int hid_parser_global(struct hid_parser *parser, struct hid_item *item)
291 : {
292 0 : switch (item->tag) {
293 0 : case HID_GLOBAL_ITEM_TAG_PUSH:
294 0 :
295 0 : if (parser->global_stack_ptr == HID_GLOBAL_STACK_SIZE) {
296 0 : dbg_hid("global enviroment stack overflow\n");
297 0 : return -1;
298 : }
299 :
300 0 : memcpy(parser->global_stack + parser->global_stack_ptr++,
301 : &parser->global, sizeof(struct hid_global));
302 0 : return 0;
303 0 :
304 0 : case HID_GLOBAL_ITEM_TAG_POP:
305 :
306 0 : if (!parser->global_stack_ptr) {
307 0 : dbg_hid("global enviroment stack underflow\n");
308 0 : return -1;
309 : }
310 :
311 0 : memcpy(&parser->global, parser->global_stack +
312 : --parser->global_stack_ptr, sizeof(struct hid_global));
313 0 : return 0;
314 0 :
315 0 : case HID_GLOBAL_ITEM_TAG_USAGE_PAGE:
316 0 : parser->global.usage_page = item_udata(item);
317 0 : return 0;
318 0 :
319 0 : case HID_GLOBAL_ITEM_TAG_LOGICAL_MINIMUM:
320 0 : parser->global.logical_minimum = item_sdata(item);
321 0 : return 0;
322 0 :
323 0 : case HID_GLOBAL_ITEM_TAG_LOGICAL_MAXIMUM:
324 0 : if (parser->global.logical_minimum < 0)
325 0 : parser->global.logical_maximum = item_sdata(item);
326 : else
327 0 : parser->global.logical_maximum = item_udata(item);
328 0 : return 0;
329 0 :
330 0 : case HID_GLOBAL_ITEM_TAG_PHYSICAL_MINIMUM:
331 0 : parser->global.physical_minimum = item_sdata(item);
332 0 : return 0;
333 0 :
334 0 : case HID_GLOBAL_ITEM_TAG_PHYSICAL_MAXIMUM:
335 0 : if (parser->global.physical_minimum < 0)
336 0 : parser->global.physical_maximum = item_sdata(item);
337 : else
338 0 : parser->global.physical_maximum = item_udata(item);
339 0 : return 0;
340 0 :
341 0 : case HID_GLOBAL_ITEM_TAG_UNIT_EXPONENT:
342 0 : parser->global.unit_exponent = item_sdata(item);
343 0 : return 0;
344 0 :
345 0 : case HID_GLOBAL_ITEM_TAG_UNIT:
346 0 : parser->global.unit = item_udata(item);
347 0 : return 0;
348 0 :
349 0 : case HID_GLOBAL_ITEM_TAG_REPORT_SIZE:
350 0 : parser->global.report_size = item_udata(item);
351 0 : if (parser->global.report_size > 32) {
352 0 : dbg_hid("invalid report_size %d\n",
353 : parser->global.report_size);
354 0 : return -1;
355 : }
356 0 : return 0;
357 0 :
358 0 : case HID_GLOBAL_ITEM_TAG_REPORT_COUNT:
359 0 : parser->global.report_count = item_udata(item);
360 0 : if (parser->global.report_count > HID_MAX_USAGES) {
361 0 : dbg_hid("invalid report_count %d\n",
362 : parser->global.report_count);
363 0 : return -1;
364 : }
365 0 : return 0;
366 0 :
367 0 : case HID_GLOBAL_ITEM_TAG_REPORT_ID:
368 0 : parser->global.report_id = item_udata(item);
369 0 : if (parser->global.report_id == 0) {
370 0 : dbg_hid("report_id 0 is invalid\n");
371 0 : return -1;
372 : }
373 0 : return 0;
374 0 :
375 0 : default:
376 0 : dbg_hid("unknown global tag 0x%x\n", item->tag);
377 0 : return -1;
378 : }
379 : }
380 :
381 : /*
382 : * Process a local item.
383 : */
384 :
385 : static int hid_parser_local(struct hid_parser *parser, struct hid_item *item)
386 : {
387 0 : __u32 data;
388 0 : unsigned n;
389 0 :
390 0 : if (item->size == 0) {
391 0 : dbg_hid("item data expected for local item\n");
392 0 : return -1;
393 : }
394 :
395 0 : data = item_udata(item);
396 :
397 : switch (item->tag) {
398 0 : case HID_LOCAL_ITEM_TAG_DELIMITER:
399 :
400 0 : if (data) {
401 : /*
402 : * We treat items before the first delimiter
403 : * as global to all usage sets (branch 0).
404 : * In the moment we process only these global
405 : * items and the first delimiter set.
406 : */
407 0 : if (parser->local.delimiter_depth != 0) {
408 0 : dbg_hid("nested delimiters\n");
409 0 : return -1;
410 : }
411 0 : parser->local.delimiter_depth++;
412 0 : parser->local.delimiter_branch++;
413 : } else {
414 0 : if (parser->local.delimiter_depth < 1) {
415 0 : dbg_hid("bogus close delimiter\n");
416 0 : return -1;
417 : }
418 0 : parser->local.delimiter_depth--;
419 : }
420 0 : return 1;
421 0 :
422 0 : case HID_LOCAL_ITEM_TAG_USAGE:
423 :
424 0 : if (parser->local.delimiter_branch > 1) {
425 0 : dbg_hid("alternative usage ignored\n");
426 0 : return 0;
427 : }
428 :
429 0 : if (item->size <= 2)
430 0 : data = (parser->global.usage_page << 16) + data;
431 :
432 0 : return hid_add_usage(parser, data);
433 0 :
434 0 : case HID_LOCAL_ITEM_TAG_USAGE_MINIMUM:
435 :
436 0 : if (parser->local.delimiter_branch > 1) {
437 0 : dbg_hid("alternative usage ignored\n");
438 0 : return 0;
439 : }
440 :
441 0 : if (item->size <= 2)
442 0 : data = (parser->global.usage_page << 16) + data;
443 :
444 0 : parser->local.usage_minimum = data;
445 0 : return 0;
446 0 :
447 0 : case HID_LOCAL_ITEM_TAG_USAGE_MAXIMUM:
448 :
449 0 : if (parser->local.delimiter_branch > 1) {
450 0 : dbg_hid("alternative usage ignored\n");
451 0 : return 0;
452 : }
453 :
454 0 : if (item->size <= 2)
455 0 : data = (parser->global.usage_page << 16) + data;
456 :
457 0 : for (n = parser->local.usage_minimum; n <= data; n++)
458 0 : if (hid_add_usage(parser, n)) {
459 0 : dbg_hid("hid_add_usage failed\n");
460 0 : return -1;
461 : }
462 0 : return 0;
463 0 :
464 0 : default:
465 0 :
466 0 : dbg_hid("unknown local item tag 0x%x\n", item->tag);
467 0 : return 0;
468 : }
469 : return 0;
470 : }
471 :
472 : /*
473 : * Process a main item.
474 : */
475 :
476 : static int hid_parser_main(struct hid_parser *parser, struct hid_item *item)
477 : {
478 0 : __u32 data;
479 0 : int ret;
480 :
481 0 : data = item_udata(item);
482 :
483 : switch (item->tag) {
484 0 : case HID_MAIN_ITEM_TAG_BEGIN_COLLECTION:
485 0 : ret = open_collection(parser, data & 0xff);
486 0 : break;
487 0 : case HID_MAIN_ITEM_TAG_END_COLLECTION:
488 0 : ret = close_collection(parser);
489 0 : break;
490 0 : case HID_MAIN_ITEM_TAG_INPUT:
491 0 : ret = hid_add_field(parser, HID_INPUT_REPORT, data);
492 0 : break;
493 0 : case HID_MAIN_ITEM_TAG_OUTPUT:
494 0 : ret = hid_add_field(parser, HID_OUTPUT_REPORT, data);
495 0 : break;
496 0 : case HID_MAIN_ITEM_TAG_FEATURE:
497 0 : ret = hid_add_field(parser, HID_FEATURE_REPORT, data);
498 0 : break;
499 0 : default:
500 0 : dbg_hid("unknown main item tag 0x%x\n", item->tag);
501 0 : ret = 0;
502 0 : }
503 :
504 0 : memset(&parser->local, 0, sizeof(parser->local)); /* Reset the local parser environment */
505 :
506 0 : return ret;
507 : }
508 :
509 : /*
510 : * Process a reserved item.
511 : */
512 :
513 : static int hid_parser_reserved(struct hid_parser *parser, struct hid_item *item)
514 : {
515 0 : dbg_hid("reserved item type, tag 0x%x\n", item->tag);
516 0 : return 0;
517 : }
518 :
519 : /*
520 : * Free a report and all registered fields. The field->usage and
521 : * field->value table's are allocated behind the field, so we need
522 : * only to free(field) itself.
523 : */
524 :
525 : static void hid_free_report(struct hid_report *report)
526 : {
527 0 : unsigned n;
528 :
529 0 : for (n = 0; n < report->maxfield; n++)
530 0 : kfree(report->field[n]);
531 0 : kfree(report);
532 0 : }
533 :
534 : /*
535 : * Free a device structure, all reports, and all fields.
536 : */
537 :
538 : static void hid_device_release(struct device *dev)
539 : {
540 0 : struct hid_device *device = container_of(dev, struct hid_device, dev);
541 0 : unsigned i, j;
542 0 :
543 0 : for (i = 0; i < HID_REPORT_TYPES; i++) {
544 0 : struct hid_report_enum *report_enum = device->report_enum + i;
545 0 :
546 0 : for (j = 0; j < 256; j++) {
547 0 : struct hid_report *report = report_enum->report_id_hash[j];
548 0 : if (report)
549 0 : hid_free_report(report);
550 : }
551 : }
552 :
553 0 : kfree(device->rdesc);
554 0 : kfree(device->collection);
555 0 : kfree(device);
556 0 : }
557 :
558 : /*
559 : * Fetch a report description item from the data stream. We support long
560 : * items, though they are not used yet.
561 : */
562 :
563 : static u8 *fetch_item(__u8 *start, __u8 *end, struct hid_item *item)
564 : {
565 0 : u8 b;
566 0 :
567 0 : if ((end - start) <= 0)
568 0 : return NULL;
569 0 :
570 0 : b = *start++;
571 :
572 0 : item->type = (b >> 2) & 3;
573 0 : item->tag = (b >> 4) & 15;
574 :
575 0 : if (item->tag == HID_ITEM_TAG_LONG) {
576 :
577 0 : item->format = HID_ITEM_FORMAT_LONG;
578 :
579 0 : if ((end - start) < 2)
580 0 : return NULL;
581 :
582 0 : item->size = *start++;
583 0 : item->tag = *start++;
584 :
585 0 : if ((end - start) < item->size)
586 0 : return NULL;
587 :
588 0 : item->data.longdata = start;
589 0 : start += item->size;
590 0 : return start;
591 : }
592 :
593 0 : item->format = HID_ITEM_FORMAT_SHORT;
594 0 : item->size = b & 3;
595 :
596 0 : switch (item->size) {
597 0 : case 0:
598 0 : return start;
599 0 :
600 0 : case 1:
601 0 : if ((end - start) < 1)
602 0 : return NULL;
603 0 : item->data.u8 = *start++;
604 0 : return start;
605 0 :
606 0 : case 2:
607 0 : if ((end - start) < 2)
608 0 : return NULL;
609 0 : item->data.u16 = get_unaligned_le16(start);
610 0 : start = (__u8 *)((__le16 *)start + 1);
611 0 : return start;
612 0 :
613 0 : case 3:
614 0 : item->size++;
615 0 : if ((end - start) < 4)
616 0 : return NULL;
617 0 : item->data.u32 = get_unaligned_le32(start);
618 0 : start = (__u8 *)((__le32 *)start + 1);
619 0 : return start;
620 0 : }
621 :
622 0 : return NULL;
623 : }
624 :
625 : /**
626 : * hid_parse_report - parse device report
627 : *
628 : * @device: hid device
629 : * @start: report start
630 : * @size: report size
631 : *
632 : * Parse a report description into a hid_device structure. Reports are
633 : * enumerated, fields are attached to these reports.
634 : * 0 returned on success, otherwise nonzero error value.
635 : */
636 : int hid_parse_report(struct hid_device *device, __u8 *start,
637 : unsigned size)
638 0 : {
639 0 : struct hid_parser *parser;
640 0 : struct hid_item item;
641 0 : __u8 *end;
642 0 : int ret;
643 0 : static int (*dispatch_type[])(struct hid_parser *parser,
644 0 : struct hid_item *item) = {
645 0 : hid_parser_main,
646 0 : hid_parser_global,
647 : hid_parser_local,
648 : hid_parser_reserved
649 : };
650 :
651 0 : if (device->driver->report_fixup)
652 0 : device->driver->report_fixup(device, start, size);
653 :
654 0 : device->rdesc = kmalloc(size, GFP_KERNEL);
655 0 : if (device->rdesc == NULL)
656 0 : return -ENOMEM;
657 0 : memcpy(device->rdesc, start, size);
658 0 : device->rsize = size;
659 :
660 0 : parser = vmalloc(sizeof(struct hid_parser));
661 0 : if (!parser) {
662 0 : ret = -ENOMEM;
663 0 : goto err;
664 : }
665 :
666 0 : memset(parser, 0, sizeof(struct hid_parser));
667 0 : parser->device = device;
668 :
669 0 : end = start + size;
670 0 : ret = -EINVAL;
671 0 : while ((start = fetch_item(start, end, &item)) != NULL) {
672 0 :
673 0 : if (item.format != HID_ITEM_FORMAT_SHORT) {
674 0 : dbg_hid("unexpected long global item\n");
675 0 : goto err;
676 : }
677 :
678 0 : if (dispatch_type[item.type](parser, &item)) {
679 0 : dbg_hid("item %u %u %u %u parsing failed\n",
680 : item.format, (unsigned)item.size, (unsigned)item.type, (unsigned)item.tag);
681 0 : goto err;
682 : }
683 :
684 0 : if (start == end) {
685 0 : if (parser->collection_stack_ptr) {
686 0 : dbg_hid("unbalanced collection at end of report description\n");
687 0 : goto err;
688 : }
689 0 : if (parser->local.delimiter_depth) {
690 0 : dbg_hid("unbalanced delimiter at end of report description\n");
691 0 : goto err;
692 : }
693 0 : vfree(parser);
694 0 : return 0;
695 : }
696 : }
697 :
698 0 : dbg_hid("item fetching failed at offset %d\n", (int)(end - start));
699 : err:
700 0 : vfree(parser);
701 0 : return ret;
702 : }
703 : EXPORT_SYMBOL_GPL(hid_parse_report);
704 0 :
705 : /*
706 : * Convert a signed n-bit integer to signed 32-bit integer. Common
707 : * cases are done through the compiler, the screwed things has to be
708 : * done by hand.
709 : */
710 :
711 : static s32 snto32(__u32 value, unsigned n)
712 : {
713 0 : switch (n) {
714 0 : case 8: return ((__s8)value);
715 0 : case 16: return ((__s16)value);
716 0 : case 32: return ((__s32)value);
717 0 : }
718 0 : return value & (1 << (n - 1)) ? value | (-1 << n) : value;
719 : }
720 :
721 : /*
722 : * Convert a signed 32-bit integer to a signed n-bit integer.
723 : */
724 :
725 : static u32 s32ton(__s32 value, unsigned n)
726 : {
727 0 : s32 a = value >> (n - 1);
728 0 : if (a && a != -1)
729 0 : return value < 0 ? 1 << (n - 1) : (1 << (n - 1)) - 1;
730 0 : return value & ((1 << n) - 1);
731 : }
732 :
733 : /*
734 : * Extract/implement a data field from/to a little endian report (bit array).
735 : *
736 : * Code sort-of follows HID spec:
737 : * http://www.usb.org/developers/devclass_docs/HID1_11.pdf
738 : *
739 : * While the USB HID spec allows unlimited length bit fields in "report
740 : * descriptors", most devices never use more than 16 bits.
741 : * One model of UPS is claimed to report "LINEV" as a 32-bit field.
742 : * Search linux-kernel and linux-usb-devel archives for "hid-core extract".
743 : */
744 :
745 : static __inline__ __u32 extract(__u8 *report, unsigned offset, unsigned n)
746 : {
747 0 : u64 x;
748 0 :
749 0 : if (n > 32)
750 0 : printk(KERN_WARNING "HID: extract() called with n (%d) > 32! (%s)\n",
751 : n, current->comm);
752 :
753 0 : report += offset >> 3; /* adjust byte index */
754 0 : offset &= 7; /* now only need bit offset into one byte */
755 0 : x = get_unaligned_le64(report);
756 0 : x = (x >> offset) & ((1ULL << n) - 1); /* extract bit field */
757 0 : return (u32) x;
758 : }
759 :
760 : /*
761 : * "implement" : set bits in a little endian bit stream.
762 : * Same concepts as "extract" (see comments above).
763 : * The data mangled in the bit stream remains in little endian
764 : * order the whole time. It make more sense to talk about
765 : * endianness of register values by considering a register
766 : * a "cached" copy of the little endiad bit stream.
767 : */
768 : static __inline__ void implement(__u8 *report, unsigned offset, unsigned n, __u32 value)
769 : {
770 : u64 x;
771 0 : u64 m = (1ULL << n) - 1;
772 0 :
773 0 : if (n > 32)
774 0 : printk(KERN_WARNING "HID: implement() called with n (%d) > 32! (%s)\n",
775 0 : n, current->comm);
776 0 :
777 0 : if (value > m)
778 0 : printk(KERN_WARNING "HID: implement() called with too large value %d! (%s)\n",
779 : value, current->comm);
780 0 : WARN_ON(value > m);
781 0 : value &= m;
782 :
783 0 : report += offset >> 3;
784 0 : offset &= 7;
785 :
786 0 : x = get_unaligned_le64(report);
787 0 : x &= ~(m << offset);
788 0 : x |= ((u64)value) << offset;
789 0 : put_unaligned_le64(x, report);
790 0 : }
791 :
792 : /*
793 : * Search an array for a value.
794 : */
795 :
796 : static __inline__ int search(__s32 *array, __s32 value, unsigned n)
797 : {
798 0 : while (n--) {
799 0 : if (*array++ == value)
800 0 : return 0;
801 : }
802 0 : return -1;
803 : }
804 0 :
805 : /**
806 : * hid_match_report - check if driver's raw_event should be called
807 : *
808 : * @hid: hid device
809 : * @report_type: type to match against
810 : *
811 : * compare hid->driver->report_table->report_type to report->type
812 : */
813 : static int hid_match_report(struct hid_device *hid, struct hid_report *report)
814 : {
815 0 : const struct hid_report_id *id = hid->driver->report_table;
816 :
817 0 : if (!id) /* NULL means all */
818 0 : return 1;
819 :
820 0 : for (; id->report_type != HID_TERMINATOR; id++)
821 0 : if (id->report_type == HID_ANY_ID ||
822 0 : id->report_type == report->type)
823 0 : return 1;
824 0 : return 0;
825 : }
826 :
827 : /**
828 : * hid_match_usage - check if driver's event should be called
829 : *
830 : * @hid: hid device
831 : * @usage: usage to match against
832 : *
833 : * compare hid->driver->usage_table->usage_{type,code} to
834 : * usage->usage_{type,code}
835 : */
836 : static int hid_match_usage(struct hid_device *hid, struct hid_usage *usage)
837 : {
838 0 : const struct hid_usage_id *id = hid->driver->usage_table;
839 :
840 0 : if (!id) /* NULL means all */
841 0 : return 1;
842 :
843 0 : for (; id->usage_type != HID_ANY_ID - 1; id++)
844 0 : if ((id->usage_hid == HID_ANY_ID ||
845 0 : id->usage_hid == usage->hid) &&
846 : (id->usage_type == HID_ANY_ID ||
847 : id->usage_type == usage->type) &&
848 : (id->usage_code == HID_ANY_ID ||
849 : id->usage_code == usage->code))
850 0 : return 1;
851 0 : return 0;
852 : }
853 :
854 : static void hid_process_event(struct hid_device *hid, struct hid_field *field,
855 : struct hid_usage *usage, __s32 value, int interrupt)
856 : {
857 0 : struct hid_driver *hdrv = hid->driver;
858 0 : int ret;
859 0 :
860 : hid_dump_input(hid, usage, value);
861 :
862 0 : if (hdrv && hdrv->event && hid_match_usage(hid, usage)) {
863 0 : ret = hdrv->event(hid, field, usage, value);
864 0 : if (ret != 0) {
865 0 : if (ret < 0)
866 0 : dbg_hid("%s's event failed with %d\n",
867 : hdrv->name, ret);
868 0 : return;
869 : }
870 : }
871 :
872 0 : if (hid->claimed & HID_CLAIMED_INPUT)
873 0 : hidinput_hid_event(hid, field, usage, value);
874 0 : if (hid->claimed & HID_CLAIMED_HIDDEV && interrupt && hid->hiddev_hid_event)
875 0 : hid->hiddev_hid_event(hid, field, usage, value);
876 0 : }
877 :
878 : /*
879 : * Analyse a received field, and fetch the data from it. The field
880 : * content is stored for next report processing (we do differential
881 : * reporting to the layer).
882 : */
883 :
884 : static void hid_input_field(struct hid_device *hid, struct hid_field *field,
885 : __u8 *data, int interrupt)
886 : {
887 0 : unsigned n;
888 0 : unsigned count = field->report_count;
889 0 : unsigned offset = field->report_offset;
890 0 : unsigned size = field->report_size;
891 0 : __s32 min = field->logical_minimum;
892 0 : __s32 max = field->logical_maximum;
893 0 : __s32 *value;
894 0 :
895 0 : if (!(value = kmalloc(sizeof(__s32) * count, GFP_ATOMIC)))
896 0 : return;
897 0 :
898 0 : for (n = 0; n < count; n++) {
899 0 :
900 0 : value[n] = min < 0 ? snto32(extract(data, offset + n * size, size), size) :
901 : extract(data, offset + n * size, size);
902 :
903 0 : if (!(field->flags & HID_MAIN_ITEM_VARIABLE) /* Ignore report if ErrorRollOver */
904 : && value[n] >= min && value[n] <= max
905 : && field->usage[value[n] - min].hid == HID_UP_KEYBOARD + 1)
906 0 : goto exit;
907 : }
908 :
909 0 : for (n = 0; n < count; n++) {
910 0 :
911 0 : if (HID_MAIN_ITEM_VARIABLE & field->flags) {
912 0 : hid_process_event(hid, field, &field->usage[n], value[n], interrupt);
913 0 : continue;
914 : }
915 :
916 0 : if (field->value[n] >= min && field->value[n] <= max
917 : && field->usage[field->value[n] - min].hid
918 : && search(value, field->value[n], count))
919 0 : hid_process_event(hid, field, &field->usage[field->value[n] - min], 0, interrupt);
920 :
921 0 : if (value[n] >= min && value[n] <= max
922 : && field->usage[value[n] - min].hid
923 : && search(field->value, value[n], count))
924 0 : hid_process_event(hid, field, &field->usage[value[n] - min], 1, interrupt);
925 : }
926 :
927 0 : memcpy(field->value, value, count * sizeof(__s32));
928 : exit:
929 0 : kfree(value);
930 0 : }
931 :
932 : /*
933 0 : * Output the field into the report.
934 : */
935 :
936 : static void hid_output_field(struct hid_field *field, __u8 *data)
937 : {
938 0 : unsigned count = field->report_count;
939 0 : unsigned offset = field->report_offset;
940 0 : unsigned size = field->report_size;
941 0 : unsigned bitsused = offset + count * size;
942 0 : unsigned n;
943 0 :
944 : /* make sure the unused bits in the last byte are zeros */
945 0 : if (count > 0 && size > 0 && (bitsused % 8) != 0)
946 0 : data[(bitsused-1)/8] &= (1 << (bitsused % 8)) - 1;
947 :
948 0 : for (n = 0; n < count; n++) {
949 0 : if (field->logical_minimum < 0) /* signed values */
950 0 : implement(data, offset + n * size, size, s32ton(field->value[n], size));
951 : else /* unsigned values */
952 0 : implement(data, offset + n * size, size, field->value[n]);
953 : }
954 : }
955 0 :
956 : /*
957 : * Create a report.
958 : */
959 :
960 : void hid_output_report(struct hid_report *report, __u8 *data)
961 : {
962 0 : unsigned n;
963 0 :
964 0 : if (report->id > 0)
965 0 : *data++ = report->id;
966 :
967 0 : for (n = 0; n < report->maxfield; n++)
968 0 : hid_output_field(report->field[n], data);
969 0 : }
970 : EXPORT_SYMBOL_GPL(hid_output_report);
971 :
972 : /*
973 : * Set a field value. The report this field belongs to has to be
974 0 : * created and transferred to the device, to set this value in the
975 : * device.
976 : */
977 :
978 : int hid_set_field(struct hid_field *field, unsigned offset, __s32 value)
979 : {
980 0 : unsigned size = field->report_size;
981 0 :
982 0 : hid_dump_input(field->report->device, field->usage + offset, value);
983 :
984 0 : if (offset >= field->report_count) {
985 0 : dbg_hid("offset (%d) exceeds report_count (%d)\n", offset, field->report_count);
986 0 : return -1;
987 : }
988 0 : if (field->logical_minimum < 0) {
989 0 : if (value != snto32(s32ton(value, size), size)) {
990 0 : dbg_hid("value %d is out of range\n", value);
991 0 : return -1;
992 : }
993 : }
994 0 : field->value[offset] = value;
995 0 : return 0;
996 : }
997 : EXPORT_SYMBOL_GPL(hid_set_field);
998 :
999 : static struct hid_report *hid_get_report(struct hid_report_enum *report_enum,
1000 : const u8 *data)
1001 0 : {
1002 0 : struct hid_report *report;
1003 0 : unsigned int n = 0; /* Normally report number is 0 */
1004 :
1005 : /* Device uses numbered reports, data[0] is report number */
1006 0 : if (report_enum->numbered)
1007 0 : n = *data;
1008 :
1009 0 : report = report_enum->report_id_hash[n];
1010 0 : if (report == NULL)
1011 0 : dbg_hid("undefined report_id %u received\n", n);
1012 :
1013 0 : return report;
1014 : }
1015 :
1016 : void hid_report_raw_event(struct hid_device *hid, int type, u8 *data, int size,
1017 : int interrupt)
1018 : {
1019 0 : struct hid_report_enum *report_enum = hid->report_enum + type;
1020 0 : struct hid_report *report;
1021 0 : unsigned int a;
1022 0 : int rsize, csize = size;
1023 0 : u8 *cdata = data;
1024 0 :
1025 0 : report = hid_get_report(report_enum, data);
1026 0 : if (!report)
1027 0 : return;
1028 :
1029 0 : if (report_enum->numbered) {
1030 0 : cdata++;
1031 0 : csize--;
1032 : }
1033 :
1034 0 : rsize = ((report->size - 1) >> 3) + 1;
1035 :
1036 0 : if (csize < rsize) {
1037 0 : dbg_hid("report %d is too short, (%d < %d)\n", report->id,
1038 : csize, rsize);
1039 0 : memset(cdata + csize, 0, rsize - csize);
1040 : }
1041 :
1042 0 : if ((hid->claimed & HID_CLAIMED_HIDDEV) && hid->hiddev_report_event)
1043 0 : hid->hiddev_report_event(hid, report);
1044 0 : if (hid->claimed & HID_CLAIMED_HIDRAW) {
1045 : /* numbered reports need to be passed with the report num */
1046 0 : if (report_enum->numbered)
1047 0 : hidraw_report_event(hid, data - 1, size + 1);
1048 : else
1049 0 : hidraw_report_event(hid, data, size);
1050 : }
1051 :
1052 0 : for (a = 0; a < report->maxfield; a++)
1053 0 : hid_input_field(hid, report->field[a], cdata, interrupt);
1054 0 :
1055 0 : if (hid->claimed & HID_CLAIMED_INPUT)
1056 0 : hidinput_report_event(hid, report);
1057 0 : }
1058 : EXPORT_SYMBOL_GPL(hid_report_raw_event);
1059 :
1060 : /**
1061 : * hid_input_report - report data from lower layer (usb, bt...)
1062 : *
1063 : * @hid: hid device
1064 : * @type: HID report type (HID_*_REPORT)
1065 : * @data: report contents
1066 : * @size: size of data parameter
1067 : * @interrupt: distinguish between interrupt and control transfers
1068 : *
1069 : * This is data entry for lower layers.
1070 : */
1071 : int hid_input_report(struct hid_device *hid, int type, u8 *data, int size, int interrupt)
1072 : {
1073 0 : struct hid_report_enum *report_enum;
1074 0 : struct hid_driver *hdrv;
1075 0 : struct hid_report *report;
1076 0 : char *buf;
1077 0 : unsigned int i;
1078 0 : int ret;
1079 0 :
1080 0 : if (!hid || !hid->driver)
1081 0 : return -ENODEV;
1082 0 : report_enum = hid->report_enum + type;
1083 0 : hdrv = hid->driver;
1084 :
1085 0 : if (!size) {
1086 0 : dbg_hid("empty report\n");
1087 0 : return -1;
1088 : }
1089 :
1090 0 : buf = kmalloc(sizeof(char) * HID_DEBUG_BUFSIZE, GFP_ATOMIC);
1091 :
1092 0 : if (!buf) {
1093 0 : report = hid_get_report(report_enum, data);
1094 0 : goto nomem;
1095 : }
1096 :
1097 0 : snprintf(buf, HID_DEBUG_BUFSIZE - 1,
1098 : "\nreport (size %u) (%snumbered)\n", size, report_enum->numbered ? "" : "un");
1099 : hid_debug_event(hid, buf);
1100 :
1101 0 : report = hid_get_report(report_enum, data);
1102 0 : if (!report) {
1103 0 : kfree(buf);
1104 0 : return -1;
1105 : }
1106 :
1107 : /* dump the report */
1108 0 : snprintf(buf, HID_DEBUG_BUFSIZE - 1,
1109 : "report %d (size %u) = ", report->id, size);
1110 : hid_debug_event(hid, buf);
1111 0 : for (i = 0; i < size; i++) {
1112 0 : snprintf(buf, HID_DEBUG_BUFSIZE - 1,
1113 0 : " %02x", data[i]);
1114 : hid_debug_event(hid, buf);
1115 : }
1116 : hid_debug_event(hid, "\n");
1117 :
1118 0 : kfree(buf);
1119 :
1120 0 : nomem:
1121 0 : if (hdrv && hdrv->raw_event && hid_match_report(hid, report)) {
1122 0 : ret = hdrv->raw_event(hid, report, data, size);
1123 0 : if (ret != 0)
1124 0 : return ret < 0 ? ret : 0;
1125 : }
1126 :
1127 0 : hid_report_raw_event(hid, type, data, size, interrupt);
1128 :
1129 0 : return 0;
1130 : }
1131 : EXPORT_SYMBOL_GPL(hid_input_report);
1132 :
1133 : static bool hid_match_one_id(struct hid_device *hdev,
1134 : const struct hid_device_id *id)
1135 : {
1136 0 : return id->bus == hdev->bus &&
1137 : (id->vendor == HID_ANY_ID || id->vendor == hdev->vendor) &&
1138 : (id->product == HID_ANY_ID || id->product == hdev->product);
1139 : }
1140 :
1141 : static const struct hid_device_id *hid_match_id(struct hid_device *hdev,
1142 : const struct hid_device_id *id)
1143 0 : {
1144 0 : for (; id->bus; id++)
1145 0 : if (hid_match_one_id(hdev, id))
1146 0 : return id;
1147 :
1148 0 : return NULL;
1149 : }
1150 :
1151 1 : static const struct hid_device_id hid_hiddev_list[] = {
1152 : { HID_USB_DEVICE(USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS) },
1153 : { HID_USB_DEVICE(USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS1) },
1154 : { }
1155 : };
1156 :
1157 : static bool hid_hiddev(struct hid_device *hdev)
1158 : {
1159 0 : return !!hid_match_id(hdev, hid_hiddev_list);
1160 : }
1161 :
1162 : int hid_connect(struct hid_device *hdev, unsigned int connect_mask)
1163 : {
1164 0 : static const char *types[] = { "Device", "Pointer", "Mouse", "Device",
1165 0 : "Joystick", "Gamepad", "Keyboard", "Keypad",
1166 0 : "Multi-Axis Controller"
1167 0 : };
1168 0 : const char *type, *bus;
1169 0 : char buf[64];
1170 0 : unsigned int i;
1171 0 : int len;
1172 0 :
1173 0 : if (hdev->bus != BUS_USB)
1174 0 : connect_mask &= ~HID_CONNECT_HIDDEV;
1175 0 : if (hid_hiddev(hdev))
1176 0 : connect_mask |= HID_CONNECT_HIDDEV_FORCE;
1177 0 :
1178 0 : if ((connect_mask & HID_CONNECT_HIDINPUT) && !hidinput_connect(hdev,
1179 0 : connect_mask & HID_CONNECT_HIDINPUT_FORCE))
1180 0 : hdev->claimed |= HID_CLAIMED_INPUT;
1181 0 : if ((connect_mask & HID_CONNECT_HIDDEV) && hdev->hiddev_connect &&
1182 : !hdev->hiddev_connect(hdev,
1183 : connect_mask & HID_CONNECT_HIDDEV_FORCE))
1184 0 : hdev->claimed |= HID_CLAIMED_HIDDEV;
1185 0 : if ((connect_mask & HID_CONNECT_HIDRAW) && !hidraw_connect(hdev))
1186 0 : hdev->claimed |= HID_CLAIMED_HIDRAW;
1187 :
1188 0 : if (!hdev->claimed) {
1189 0 : dev_err(&hdev->dev, "claimed by neither input, hiddev nor "
1190 : "hidraw\n");
1191 0 : return -ENODEV;
1192 : }
1193 :
1194 0 : if ((hdev->claimed & HID_CLAIMED_INPUT) &&
1195 : (connect_mask & HID_CONNECT_FF) && hdev->ff_init)
1196 0 : hdev->ff_init(hdev);
1197 :
1198 0 : len = 0;
1199 0 : if (hdev->claimed & HID_CLAIMED_INPUT)
1200 0 : len += sprintf(buf + len, "input");
1201 0 : if (hdev->claimed & HID_CLAIMED_HIDDEV)
1202 0 : len += sprintf(buf + len, "%shiddev%d", len ? "," : "",
1203 : hdev->minor);
1204 0 : if (hdev->claimed & HID_CLAIMED_HIDRAW)
1205 0 : len += sprintf(buf + len, "%shidraw%d", len ? "," : "",
1206 : ((struct hidraw *)hdev->hidraw)->minor);
1207 :
1208 0 : type = "Device";
1209 0 : for (i = 0; i < hdev->maxcollection; i++) {
1210 0 : struct hid_collection *col = &hdev->collection[i];
1211 0 : if (col->type == HID_COLLECTION_APPLICATION &&
1212 : (col->usage & HID_USAGE_PAGE) == HID_UP_GENDESK &&
1213 : (col->usage & 0xffff) < ARRAY_SIZE(types)) {
1214 0 : type = types[col->usage & 0xffff];
1215 0 : break;
1216 : }
1217 : }
1218 :
1219 : switch (hdev->bus) {
1220 0 : case BUS_USB:
1221 0 : bus = "USB";
1222 0 : break;
1223 0 : case BUS_BLUETOOTH:
1224 0 : bus = "BLUETOOTH";
1225 0 : break;
1226 0 : default:
1227 0 : bus = "<UNKNOWN>";
1228 0 : }
1229 :
1230 0 : dev_info(&hdev->dev, "%s: %s HID v%x.%02x %s [%s] on %s\n",
1231 : buf, bus, hdev->version >> 8, hdev->version & 0xff,
1232 : type, hdev->name, hdev->phys);
1233 :
1234 0 : return 0;
1235 : }
1236 : EXPORT_SYMBOL_GPL(hid_connect);
1237 :
1238 : void hid_disconnect(struct hid_device *hdev)
1239 : {
1240 0 : if (hdev->claimed & HID_CLAIMED_INPUT)
1241 0 : hidinput_disconnect(hdev);
1242 0 : if (hdev->claimed & HID_CLAIMED_HIDDEV)
1243 0 : hdev->hiddev_disconnect(hdev);
1244 0 : if (hdev->claimed & HID_CLAIMED_HIDRAW)
1245 0 : hidraw_disconnect(hdev);
1246 0 : }
1247 : EXPORT_SYMBOL_GPL(hid_disconnect);
1248 :
1249 : /* a list of devices for which there is a specialized driver on HID bus */
1250 1 : static const struct hid_device_id hid_blacklist[] = {
1251 1 : { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_WCP32PU) },
1252 : { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_X5_005D) },
1253 : { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ATV_IRCONTROL) },
1254 : { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL4) },
1255 : { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MIGHTYMOUSE) },
1256 : { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI) },
1257 : { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO) },
1258 : { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI) },
1259 : { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ISO) },
1260 : { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_JIS) },
1261 : { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ANSI) },
1262 : { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO) },
1263 : { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS) },
1264 : { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI) },
1265 : { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO) },
1266 : { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS) },
1267 : { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_ANSI) },
1268 : { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_ISO) },
1269 : { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_JIS) },
1270 : { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ANSI) },
1271 : { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ISO) },
1272 : { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_JIS) },
1273 : { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI) },
1274 : { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO) },
1275 : { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS) },
1276 : { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI) },
1277 : { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ISO) },
1278 : { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_JIS) },
1279 : { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI) },
1280 : { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ISO) },
1281 : { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_JIS) },
1282 : { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI) },
1283 : { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ISO) },
1284 : { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_JIS) },
1285 : { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI) },
1286 : { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ISO) },
1287 : { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_JIS) },
1288 : { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI) },
1289 : { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO) },
1290 : { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS) },
1291 : { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY) },
1292 : { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) },
1293 : { HID_USB_DEVICE(USB_VENDOR_ID_BELKIN, USB_DEVICE_ID_FLIP_KVM) },
1294 : { HID_USB_DEVICE(USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION) },
1295 : { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_TACTICAL_PAD) },
1296 : { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_1) },
1297 : { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_2) },
1298 : { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_3) },
1299 : { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_MOUSE) },
1300 : { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, 0x0006) },
1301 : { HID_USB_DEVICE(USB_VENDOR_ID_EZKEY, USB_DEVICE_ID_BTC_8193) },
1302 : { HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PSX_ADAPTOR) },
1303 : { HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PCS_ADAPTOR) },
1304 : { HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0003) },
1305 : { HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0012) },
1306 : { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE) },
1307 : { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE_2) },
1308 : { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE_3) },
1309 : { HID_USB_DEVICE(USB_VENDOR_ID_KENSINGTON, USB_DEVICE_ID_KS_SLIMBLADE) },
1310 : { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_ERGO_525V) },
1311 : { HID_USB_DEVICE(USB_VENDOR_ID_LABTEC, USB_DEVICE_ID_LABTEC_WIRELESS_KEYBOARD) },
1312 : { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_MX3000_RECEIVER) },
1313 : { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER) },
1314 : { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER_2) },
1315 : { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RECEIVER) },
1316 : { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_DESKTOP) },
1317 : { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_EDGE) },
1318 : { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_MINI) },
1319 : { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_ELITE_KBD) },
1320 : { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_CORDLESS_DESKTOP_LX500) },
1321 : { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_EXTREME_3D) },
1322 : { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WHEEL) },
1323 : { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD) },
1324 : { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2_2) },
1325 : { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WINGMAN_F3D) },
1326 : { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WINGMAN_FFG ) },
1327 : { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_FORCE3D_PRO) },
1328 : { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL) },
1329 : { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL2) },
1330 : { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G25_WHEEL) },
1331 : { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2) },
1332 : { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_SPACETRAVELLER) },
1333 : { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_SPACENAVIGATOR) },
1334 : { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_SIDEWINDER_GV) },
1335 : { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_NE4K) },
1336 : { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_LK6K) },
1337 : { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_USB) },
1338 : { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_WIRELESS_OPTICAL_DESKTOP_3_0) },
1339 : { HID_USB_DEVICE(USB_VENDOR_ID_MONTEREY, USB_DEVICE_ID_GENIUS_KB29E) },
1340 : { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN) },
1341 : { HID_USB_DEVICE(USB_VENDOR_ID_PETALYNX, USB_DEVICE_ID_PETALYNX_MAXTER_REMOTE) },
1342 : { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_IR_REMOTE) },
1343 : { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) },
1344 : { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGX_MOUSE) },
1345 : { HID_USB_DEVICE(USB_VENDOR_ID_SUNPLUS, USB_DEVICE_ID_SUNPLUS_WDESKTOP) },
1346 : { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb300) },
1347 : { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb304) },
1348 : { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb323) },
1349 : { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb324) },
1350 : { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb651) },
1351 : { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb654) },
1352 : { HID_USB_DEVICE(USB_VENDOR_ID_TOPSEED, USB_DEVICE_ID_TOPSEED_CYBERLINK) },
1353 : { HID_USB_DEVICE(USB_VENDOR_ID_TWINHAN, USB_DEVICE_ID_TWINHAN_IR_REMOTE) },
1354 : { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_SMARTJOY_PLUS) },
1355 : { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH) },
1356 : { HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0005) },
1357 : { HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0030) },
1358 :
1359 : { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_BT) },
1360 : { }
1361 : };
1362 :
1363 : struct hid_dynid {
1364 : struct list_head list;
1365 : struct hid_device_id id;
1366 : };
1367 :
1368 : /**
1369 : * store_new_id - add a new HID device ID to this driver and re-probe devices
1370 : * @driver: target device driver
1371 : * @buf: buffer for scanning device ID data
1372 : * @count: input size
1373 : *
1374 : * Adds a new dynamic hid device ID to this driver,
1375 : * and causes the driver to probe for all devices again.
1376 : */
1377 : static ssize_t store_new_id(struct device_driver *drv, const char *buf,
1378 : size_t count)
1379 1 : {
1380 3 : struct hid_driver *hdrv = container_of(drv, struct hid_driver, driver);
1381 1 : struct hid_dynid *dynid;
1382 1 : __u32 bus, vendor, product;
1383 2 : unsigned long driver_data = 0;
1384 1 : int ret;
1385 1 :
1386 2 : ret = sscanf(buf, "%x %x %x %lx",
1387 1 : &bus, &vendor, &product, &driver_data);
1388 3 : if (ret < 3)
1389 1 : return -EINVAL;
1390 :
1391 3 : dynid = kzalloc(sizeof(*dynid), GFP_KERNEL);
1392 2 : if (!dynid)
1393 1 : return -ENOMEM;
1394 :
1395 1 : dynid->id.bus = bus;
1396 1 : dynid->id.vendor = vendor;
1397 1 : dynid->id.product = product;
1398 1 : dynid->id.driver_data = driver_data;
1399 :
1400 2 : spin_lock(&hdrv->dyn_lock);
1401 2 : list_add_tail(&dynid->list, &hdrv->dyn_list);
1402 2 : spin_unlock(&hdrv->dyn_lock);
1403 :
1404 1 : ret = 0;
1405 3 : if (get_driver(&hdrv->driver)) {
1406 1 : ret = driver_attach(&hdrv->driver);
1407 1 : put_driver(&hdrv->driver);
1408 : }
1409 :
1410 6 : return ret ? : count;
1411 : }
1412 1 : static DRIVER_ATTR(new_id, S_IWUSR, NULL, store_new_id);
1413 :
1414 : static void hid_free_dynids(struct hid_driver *hdrv)
1415 : {
1416 0 : struct hid_dynid *dynid, *n;
1417 0 :
1418 0 : spin_lock(&hdrv->dyn_lock);
1419 0 : list_for_each_entry_safe(dynid, n, &hdrv->dyn_list, list) {
1420 0 : list_del(&dynid->list);
1421 0 : kfree(dynid);
1422 : }
1423 0 : spin_unlock(&hdrv->dyn_lock);
1424 0 : }
1425 :
1426 : static const struct hid_device_id *hid_match_device(struct hid_device *hdev,
1427 : struct hid_driver *hdrv)
1428 0 : {
1429 0 : struct hid_dynid *dynid;
1430 0 :
1431 0 : spin_lock(&hdrv->dyn_lock);
1432 0 : list_for_each_entry(dynid, &hdrv->dyn_list, list) {
1433 0 : if (hid_match_one_id(hdev, &dynid->id)) {
1434 0 : spin_unlock(&hdrv->dyn_lock);
1435 0 : return &dynid->id;
1436 : }
1437 : }
1438 0 : spin_unlock(&hdrv->dyn_lock);
1439 :
1440 0 : return hid_match_id(hdev, hdrv->id_table);
1441 : }
1442 :
1443 : static int hid_bus_match(struct device *dev, struct device_driver *drv)
1444 : {
1445 0 : struct hid_driver *hdrv = container_of(drv, struct hid_driver, driver);
1446 0 : struct hid_device *hdev = container_of(dev, struct hid_device, dev);
1447 0 :
1448 0 : if (!hid_match_device(hdev, hdrv))
1449 0 : return 0;
1450 0 :
1451 0 : /* generic wants all non-blacklisted */
1452 0 : if (!strncmp(hdrv->name, "generic-", 8))
1453 0 : return !hid_match_id(hdev, hid_blacklist);
1454 :
1455 0 : return 1;
1456 : }
1457 :
1458 : static int hid_device_probe(struct device *dev)
1459 : {
1460 0 : struct hid_driver *hdrv = container_of(dev->driver,
1461 0 : struct hid_driver, driver);
1462 0 : struct hid_device *hdev = container_of(dev, struct hid_device, dev);
1463 0 : const struct hid_device_id *id;
1464 0 : int ret = 0;
1465 0 :
1466 0 : if (!hdev->driver) {
1467 0 : id = hid_match_device(hdev, hdrv);
1468 0 : if (id == NULL)
1469 0 : return -ENODEV;
1470 :
1471 0 : hdev->driver = hdrv;
1472 0 : if (hdrv->probe) {
1473 0 : ret = hdrv->probe(hdev, id);
1474 : } else { /* default probe */
1475 0 : ret = hid_parse(hdev);
1476 0 : if (!ret)
1477 0 : ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
1478 : }
1479 0 : if (ret)
1480 0 : hdev->driver = NULL;
1481 : }
1482 0 : return ret;
1483 : }
1484 :
1485 : static int hid_device_remove(struct device *dev)
1486 : {
1487 0 : struct hid_device *hdev = container_of(dev, struct hid_device, dev);
1488 0 : struct hid_driver *hdrv = hdev->driver;
1489 0 :
1490 0 : if (hdrv) {
1491 0 : if (hdrv->remove)
1492 0 : hdrv->remove(hdev);
1493 : else /* default remove */
1494 0 : hid_hw_stop(hdev);
1495 0 : hdev->driver = NULL;
1496 : }
1497 :
1498 0 : return 0;
1499 : }
1500 :
1501 : static int hid_uevent(struct device *dev, struct kobj_uevent_env *env)
1502 : {
1503 0 : struct hid_device *hdev = container_of(dev, struct hid_device, dev);
1504 0 :
1505 0 : if (add_uevent_var(env, "HID_ID=%04X:%08X:%08X",
1506 0 : hdev->bus, hdev->vendor, hdev->product))
1507 0 : return -ENOMEM;
1508 0 :
1509 0 : if (add_uevent_var(env, "HID_NAME=%s", hdev->name))
1510 0 : return -ENOMEM;
1511 :
1512 0 : if (add_uevent_var(env, "HID_PHYS=%s", hdev->phys))
1513 0 : return -ENOMEM;
1514 :
1515 0 : if (add_uevent_var(env, "HID_UNIQ=%s", hdev->uniq))
1516 0 : return -ENOMEM;
1517 :
1518 0 : if (add_uevent_var(env, "MODALIAS=hid:b%04Xv%08Xp%08X",
1519 : hdev->bus, hdev->vendor, hdev->product))
1520 0 : return -ENOMEM;
1521 :
1522 0 : return 0;
1523 : }
1524 :
1525 1 : static struct bus_type hid_bus_type = {
1526 : .name = "hid",
1527 : .match = hid_bus_match,
1528 : .probe = hid_device_probe,
1529 : .remove = hid_device_remove,
1530 : .uevent = hid_uevent,
1531 : };
1532 :
1533 : /* a list of devices that shouldn't be handled by HID core at all */
1534 1 : static const struct hid_device_id hid_ignore_list[] = {
1535 : { HID_USB_DEVICE(USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_FLAIR) },
1536 : { HID_USB_DEVICE(USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_302) },
1537 : { HID_USB_DEVICE(USB_VENDOR_ID_ADS_TECH, USB_DEVICE_ID_ADS_TECH_RADIO_SI470X) },
1538 : { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_01) },
1539 : { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_10) },
1540 : { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_20) },
1541 : { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_21) },
1542 : { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_22) },
1543 : { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_23) },
1544 : { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_24) },
1545 : { HID_USB_DEVICE(USB_VENDOR_ID_AIRCABLE, USB_DEVICE_ID_AIRCABLE1) },
1546 : { HID_USB_DEVICE(USB_VENDOR_ID_ALCOR, USB_DEVICE_ID_ALCOR_USBRS232) },
1547 : { HID_USB_DEVICE(USB_VENDOR_ID_ASUS, USB_DEVICE_ID_ASUS_LCM)},
1548 : { HID_USB_DEVICE(USB_VENDOR_ID_ASUS, USB_DEVICE_ID_ASUS_LCM2)},
1549 : { HID_USB_DEVICE(USB_VENDOR_ID_AVERMEDIA, USB_DEVICE_ID_AVER_FM_MR800) },
1550 : { HID_USB_DEVICE(USB_VENDOR_ID_BERKSHIRE, USB_DEVICE_ID_BERKSHIRE_PCWD) },
1551 : { HID_USB_DEVICE(USB_VENDOR_ID_CIDC, 0x0103) },
1552 : { HID_USB_DEVICE(USB_VENDOR_ID_CYGNAL, USB_DEVICE_ID_CYGNAL_RADIO_SI470X) },
1553 : { HID_USB_DEVICE(USB_VENDOR_ID_CMEDIA, USB_DEVICE_ID_CM109) },
1554 : { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_HIDCOM) },
1555 : { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_ULTRAMOUSE) },
1556 : { HID_USB_DEVICE(USB_VENDOR_ID_DEALEXTREAME, USB_DEVICE_ID_DEALEXTREAME_RADIO_SI4701) },
1557 : { HID_USB_DEVICE(USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EARTHMATE) },
1558 : { HID_USB_DEVICE(USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EM_LT20) },
1559 : { HID_USB_DEVICE(USB_VENDOR_ID_ESSENTIAL_REALITY, USB_DEVICE_ID_ESSENTIAL_REALITY_P5) },
1560 : { HID_USB_DEVICE(USB_VENDOR_ID_ETT, USB_DEVICE_ID_TC5UH) },
1561 : { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0001) },
1562 : { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0002) },
1563 : { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0003) },
1564 : { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0004) },
1565 : { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_4_PHIDGETSERVO_30) },
1566 : { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_1_PHIDGETSERVO_30) },
1567 : { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_0_4_IF_KIT) },
1568 : { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_16_16_IF_KIT) },
1569 : { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_8_8_8_IF_KIT) },
1570 : { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_8_7_IF_KIT) },
1571 : { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_8_8_IF_KIT) },
1572 : { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_PHIDGET_MOTORCONTROL) },
1573 : { HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_SUPER_Q2) },
1574 : { HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_GOGOPEN) },
1575 : { HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_PENPOWER) },
1576 : { HID_USB_DEVICE(USB_VENDOR_ID_GRETAGMACBETH, USB_DEVICE_ID_GRETAGMACBETH_HUEY) },
1577 : { HID_USB_DEVICE(USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_POWERMATE) },
1578 : { HID_USB_DEVICE(USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_SOUNDKNOB) },
1579 : { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_90) },
1580 : { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_100) },
1581 : { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_101) },
1582 : { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_103) },
1583 : { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_104) },
1584 : { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_105) },
1585 : { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_106) },
1586 : { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_107) },
1587 : { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_108) },
1588 : { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_200) },
1589 : { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_201) },
1590 : { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_202) },
1591 : { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_203) },
1592 : { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_204) },
1593 : { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_205) },
1594 : { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_206) },
1595 : { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_207) },
1596 : { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_300) },
1597 : { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_301) },
1598 : { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_302) },
1599 : { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_303) },
1600 : { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_304) },
1601 : { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_305) },
1602 : { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_306) },
1603 : { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_307) },
1604 : { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_308) },
1605 : { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_309) },
1606 : { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_400) },
1607 : { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_401) },
1608 : { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_402) },
1609 : { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_403) },
1610 : { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_404) },
1611 : { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_405) },
1612 : { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_500) },
1613 : { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_501) },
1614 : { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_502) },
1615 : { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_503) },
1616 : { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_504) },
1617 : { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1000) },
1618 : { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1001) },
1619 : { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1002) },
1620 : { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1003) },
1621 : { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1004) },
1622 : { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1005) },
1623 : { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1006) },
1624 : { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1007) },
1625 : { HID_USB_DEVICE(USB_VENDOR_ID_IMATION, USB_DEVICE_ID_DISC_STAKKA) },
1626 : { HID_USB_DEVICE(USB_VENDOR_ID_KBGEAR, USB_DEVICE_ID_KBGEAR_JAMSTUDIO) },
1627 : { HID_USB_DEVICE(USB_VENDOR_ID_KWORLD, USB_DEVICE_ID_KWORLD_RADIO_FM700) },
1628 : { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_GPEN_560) },
1629 : { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_KYE, 0x0058) },
1630 : { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CASSY) },
1631 : { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POCKETCASSY) },
1632 : { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOBILECASSY) },
1633 : { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_JWM) },
1634 : { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_DMMP) },
1635 : { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIP) },
1636 : { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY1) },
1637 : { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY2) },
1638 : { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_VIDEOCOM) },
1639 : { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_COM3LAB) },
1640 : { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_TELEPORT) },
1641 : { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_NETWORKANALYSER) },
1642 : { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POWERCONTROL) },
1643 : { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MACHINETEST) },
1644 : { HID_USB_DEVICE(USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1024LS) },
1645 : { HID_USB_DEVICE(USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1208LS) },
1646 : { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICKIT1) },
1647 : { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICKIT2) },
1648 : { HID_USB_DEVICE(USB_VENDOR_ID_NATIONAL_SEMICONDUCTOR, USB_DEVICE_ID_N_S_HARMONY) },
1649 : { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100) },
1650 : { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 20) },
1651 : { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 30) },
1652 : { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 100) },
1653 : { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 108) },
1654 : { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 118) },
1655 : { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 200) },
1656 : { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 300) },
1657 : { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 400) },
1658 : { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 500) },
1659 : { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0001) },
1660 : { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0002) },
1661 : { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0003) },
1662 : { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0004) },
1663 : { HID_USB_DEVICE(USB_VENDOR_ID_PHILIPS, USB_DEVICE_ID_PHILIPS_IEEE802154_DONGLE) },
1664 : { HID_USB_DEVICE(USB_VENDOR_ID_POWERCOM, USB_DEVICE_ID_POWERCOM_UPS) },
1665 : { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_LABPRO) },
1666 : { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_GOTEMP) },
1667 : { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_SKIP) },
1668 : { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_CYCLOPS) },
1669 : { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_LCSPEC) },
1670 : { HID_USB_DEVICE(USB_VENDOR_ID_WACOM, HID_ANY_ID) },
1671 : { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_4_PHIDGETSERVO_20) },
1672 : { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_1_PHIDGETSERVO_20) },
1673 : { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_8_8_4_IF_KIT) },
1674 : { HID_USB_DEVICE(USB_VENDOR_ID_YEALINK, USB_DEVICE_ID_YEALINK_P1K_P4K_B2K) },
1675 : { }
1676 : };
1677 :
1678 : /**
1679 : * hid_mouse_ignore_list - mouse devices which should not be handled by the hid layer
1680 : *
1681 : * There are composite devices for which we want to ignore only a certain
1682 : * interface. This is a list of devices for which only the mouse interface will
1683 : * be ignored. This allows a dedicated driver to take care of the interface.
1684 : */
1685 1 : static const struct hid_device_id hid_mouse_ignore_list[] = {
1686 : /* appletouch driver */
1687 : { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI) },
1688 : { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO) },
1689 : { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI) },
1690 : { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ISO) },
1691 : { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_JIS) },
1692 : { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ANSI) },
1693 : { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO) },
1694 : { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS) },
1695 : { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI) },
1696 : { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO) },
1697 : { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS) },
1698 : { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI) },
1699 : { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO) },
1700 : { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS) },
1701 : { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI) },
1702 : { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ISO) },
1703 : { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_JIS) },
1704 : { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI) },
1705 : { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ISO) },
1706 : { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_JIS) },
1707 : { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI) },
1708 : { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ISO) },
1709 : { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_JIS) },
1710 : { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY) },
1711 : { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) },
1712 : { }
1713 : };
1714 :
1715 : static bool hid_ignore(struct hid_device *hdev)
1716 : {
1717 0 : switch (hdev->vendor) {
1718 0 : case USB_VENDOR_ID_CODEMERCS:
1719 : /* ignore all Code Mercenaries IOWarrior devices */
1720 0 : if (hdev->product >= USB_DEVICE_ID_CODEMERCS_IOW_FIRST &&
1721 : hdev->product <= USB_DEVICE_ID_CODEMERCS_IOW_LAST)
1722 0 : return true;
1723 0 : break;
1724 0 : case USB_VENDOR_ID_LOGITECH:
1725 0 : if (hdev->product >= USB_DEVICE_ID_LOGITECH_HARMONY_FIRST &&
1726 : hdev->product <= USB_DEVICE_ID_LOGITECH_HARMONY_LAST)
1727 0 : return true;
1728 0 : break;
1729 0 : case USB_VENDOR_ID_SOUNDGRAPH:
1730 0 : if (hdev->product >= USB_DEVICE_ID_SOUNDGRAPH_IMON_FIRST &&
1731 : hdev->product <= USB_DEVICE_ID_SOUNDGRAPH_IMON_LAST)
1732 0 : return true;
1733 0 : break;
1734 0 : }
1735 :
1736 0 : if (hdev->type == HID_TYPE_USBMOUSE &&
1737 : hid_match_id(hdev, hid_mouse_ignore_list))
1738 0 : return true;
1739 :
1740 0 : return !!hid_match_id(hdev, hid_ignore_list);
1741 : }
1742 :
1743 : int hid_add_device(struct hid_device *hdev)
1744 : {
1745 0 : static atomic_t id = ATOMIC_INIT(0);
1746 0 : int ret;
1747 0 :
1748 0 : if (WARN_ON(hdev->status & HID_STAT_ADDED))
1749 0 : return -EBUSY;
1750 0 :
1751 0 : /* we need to kill them here, otherwise they will stay allocated to
1752 : * wait for coming driver */
1753 0 : if (hid_ignore(hdev))
1754 0 : return -ENODEV;
1755 :
1756 : /* XXX hack, any other cleaner solution after the driver core
1757 : * is converted to allow more than 20 bytes as the device name? */
1758 0 : dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
1759 : hdev->vendor, hdev->product, atomic_inc_return(&id));
1760 :
1761 0 : ret = device_add(&hdev->dev);
1762 0 : if (!ret)
1763 0 : hdev->status |= HID_STAT_ADDED;
1764 :
1765 : hid_debug_register(hdev, dev_name(&hdev->dev));
1766 :
1767 0 : return ret;
1768 : }
1769 : EXPORT_SYMBOL_GPL(hid_add_device);
1770 :
1771 : /**
1772 : * hid_allocate_device - allocate new hid device descriptor
1773 : *
1774 : * Allocate and initialize hid device, so that hid_destroy_device might be
1775 : * used to free it.
1776 : *
1777 : * New hid_device pointer is returned on success, otherwise ERR_PTR encoded
1778 : * error value.
1779 : */
1780 : struct hid_device *hid_allocate_device(void)
1781 : {
1782 0 : struct hid_device *hdev;
1783 0 : unsigned int i;
1784 0 : int ret = -ENOMEM;
1785 0 :
1786 0 : hdev = kzalloc(sizeof(*hdev), GFP_KERNEL);
1787 0 : if (hdev == NULL)
1788 0 : return ERR_PTR(ret);
1789 0 :
1790 0 : device_initialize(&hdev->dev);
1791 0 : hdev->dev.release = hid_device_release;
1792 0 : hdev->dev.bus = &hid_bus_type;
1793 :
1794 0 : hdev->collection = kcalloc(HID_DEFAULT_NUM_COLLECTIONS,
1795 : sizeof(struct hid_collection), GFP_KERNEL);
1796 0 : if (hdev->collection == NULL)
1797 0 : goto err;
1798 0 : hdev->collection_size = HID_DEFAULT_NUM_COLLECTIONS;
1799 :
1800 0 : for (i = 0; i < HID_REPORT_TYPES; i++)
1801 0 : INIT_LIST_HEAD(&hdev->report_enum[i].report_list);
1802 0 :
1803 0 : init_waitqueue_head(&hdev->debug_wait);
1804 0 : INIT_LIST_HEAD(&hdev->debug_list);
1805 :
1806 0 : return hdev;
1807 0 : err:
1808 0 : put_device(&hdev->dev);
1809 0 : return ERR_PTR(ret);
1810 : }
1811 : EXPORT_SYMBOL_GPL(hid_allocate_device);
1812 :
1813 : static void hid_remove_device(struct hid_device *hdev)
1814 : {
1815 0 : if (hdev->status & HID_STAT_ADDED) {
1816 0 : device_del(&hdev->dev);
1817 : hid_debug_unregister(hdev);
1818 0 : hdev->status &= ~HID_STAT_ADDED;
1819 : }
1820 0 : }
1821 :
1822 : /**
1823 : * hid_destroy_device - free previously allocated device
1824 : *
1825 : * @hdev: hid device
1826 : *
1827 : * If you allocate hid_device through hid_allocate_device, you should ever
1828 : * free by this function.
1829 : */
1830 : void hid_destroy_device(struct hid_device *hdev)
1831 : {
1832 0 : hid_remove_device(hdev);
1833 0 : put_device(&hdev->dev);
1834 0 : }
1835 : EXPORT_SYMBOL_GPL(hid_destroy_device);
1836 :
1837 : int __hid_register_driver(struct hid_driver *hdrv, struct module *owner,
1838 : const char *mod_name)
1839 0 : {
1840 0 : int ret;
1841 :
1842 0 : hdrv->driver.name = hdrv->name;
1843 0 : hdrv->driver.bus = &hid_bus_type;
1844 0 : hdrv->driver.owner = owner;
1845 0 : hdrv->driver.mod_name = mod_name;
1846 :
1847 0 : INIT_LIST_HEAD(&hdrv->dyn_list);
1848 0 : spin_lock_init(&hdrv->dyn_lock);
1849 :
1850 0 : ret = driver_register(&hdrv->driver);
1851 0 : if (ret)
1852 0 : return ret;
1853 :
1854 0 : ret = driver_create_file(&hdrv->driver, &driver_attr_new_id);
1855 0 : if (ret)
1856 0 : driver_unregister(&hdrv->driver);
1857 :
1858 0 : return ret;
1859 : }
1860 : EXPORT_SYMBOL_GPL(__hid_register_driver);
1861 :
1862 : void hid_unregister_driver(struct hid_driver *hdrv)
1863 : {
1864 0 : driver_remove_file(&hdrv->driver, &driver_attr_new_id);
1865 0 : driver_unregister(&hdrv->driver);
1866 0 : hid_free_dynids(hdrv);
1867 0 : }
1868 : EXPORT_SYMBOL_GPL(hid_unregister_driver);
1869 :
1870 : int hid_check_keys_pressed(struct hid_device *hid)
1871 : {
1872 0 : struct hid_input *hidinput;
1873 0 : int i;
1874 0 :
1875 0 : if (!(hid->claimed & HID_CLAIMED_INPUT))
1876 0 : return 0;
1877 :
1878 0 : list_for_each_entry(hidinput, &hid->inputs, list) {
1879 0 : for (i = 0; i < BITS_TO_LONGS(KEY_MAX); i++)
1880 0 : if (hidinput->input->key[i])
1881 0 : return 1;
1882 : }
1883 :
1884 0 : return 0;
1885 : }
1886 :
1887 : EXPORT_SYMBOL_GPL(hid_check_keys_pressed);
1888 :
1889 : static int __init hid_init(void)
1890 : {
1891 1 : int ret;
1892 :
1893 2 : if (hid_debug)
1894 1 : printk(KERN_WARNING "HID: hid_debug is now used solely for parser and driver debugging.\n"
1895 : "HID: debugfs is now used for inspecting the device (report descriptor, reports)\n");
1896 :
1897 1 : ret = bus_register(&hid_bus_type);
1898 2 : if (ret) {
1899 1 : printk(KERN_ERR "HID: can't register hid bus\n");
1900 1 : goto err;
1901 : }
1902 :
1903 2 : ret = hidraw_init();
1904 2 : if (ret)
1905 1 : goto err_bus;
1906 :
1907 : hid_debug_init();
1908 :
1909 1 : return 0;
1910 1 : err_bus:
1911 1 : bus_unregister(&hid_bus_type);
1912 : err:
1913 3 : return ret;
1914 : }
1915 :
1916 : static void __exit hid_exit(void)
1917 : {
1918 : hid_debug_exit();
1919 4 : hidraw_exit();
1920 2 : bus_unregister(&hid_bus_type);
1921 2 : }
1922 :
1923 : module_init(hid_init);
1924 : module_exit(hid_exit);
1925 1 :
1926 : MODULE_AUTHOR("Andreas Gal");
1927 : MODULE_AUTHOR("Vojtech Pavlik");
1928 : MODULE_AUTHOR("Jiri Kosina");
1929 : MODULE_LICENSE(DRIVER_LICENSE);
1930 :
|