2 * HID support for Linux
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 Jiri Kosina
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)
17 #include <linux/module.h>
18 #include <linux/slab.h>
19 #include <linux/init.h>
20 #include <linux/kernel.h>
21 #include <linux/sched.h>
22 #include <linux/list.h>
24 #include <linux/smp_lock.h>
25 #include <linux/spinlock.h>
26 #include <asm/unaligned.h>
27 #include <asm/byteorder.h>
28 #include <linux/input.h>
29 #include <linux/wait.h>
34 #include <linux/hid.h>
35 #include <linux/hiddev.h>
41 #define DRIVER_VERSION "v2.6"
42 #define DRIVER_AUTHOR "Andreas Gal, Vojtech Pavlik"
43 #define DRIVER_DESC "USB HID core driver"
44 #define DRIVER_LICENSE "GPL"
50 static unsigned int hid_mousepoll_interval
;
51 module_param_named(mousepoll
, hid_mousepoll_interval
, uint
, 0644);
52 MODULE_PARM_DESC(mousepoll
, "Polling interval of mice");
55 * Register a new report for a device.
58 static struct hid_report
*hid_register_report(struct hid_device
*device
, unsigned type
, unsigned id
)
60 struct hid_report_enum
*report_enum
= device
->report_enum
+ type
;
61 struct hid_report
*report
;
63 if (report_enum
->report_id_hash
[id
])
64 return report_enum
->report_id_hash
[id
];
66 if (!(report
= kzalloc(sizeof(struct hid_report
), GFP_KERNEL
)))
70 report_enum
->numbered
= 1;
75 report
->device
= device
;
76 report_enum
->report_id_hash
[id
] = report
;
78 list_add_tail(&report
->list
, &report_enum
->report_list
);
84 * Register a new field for this report.
87 static struct hid_field
*hid_register_field(struct hid_report
*report
, unsigned usages
, unsigned values
)
89 struct hid_field
*field
;
91 if (report
->maxfield
== HID_MAX_FIELDS
) {
92 dbg("too many fields in report");
96 if (!(field
= kzalloc(sizeof(struct hid_field
) + usages
* sizeof(struct hid_usage
)
97 + values
* sizeof(unsigned), GFP_KERNEL
))) return NULL
;
99 field
->index
= report
->maxfield
++;
100 report
->field
[field
->index
] = field
;
101 field
->usage
= (struct hid_usage
*)(field
+ 1);
102 field
->value
= (unsigned *)(field
->usage
+ usages
);
103 field
->report
= report
;
109 * Open a collection. The type/usage is pushed on the stack.
112 static int open_collection(struct hid_parser
*parser
, unsigned type
)
114 struct hid_collection
*collection
;
117 usage
= parser
->local
.usage
[0];
119 if (parser
->collection_stack_ptr
== HID_COLLECTION_STACK_SIZE
) {
120 dbg("collection stack overflow");
124 if (parser
->device
->maxcollection
== parser
->device
->collection_size
) {
125 collection
= kmalloc(sizeof(struct hid_collection
) *
126 parser
->device
->collection_size
* 2, GFP_KERNEL
);
127 if (collection
== NULL
) {
128 dbg("failed to reallocate collection array");
131 memcpy(collection
, parser
->device
->collection
,
132 sizeof(struct hid_collection
) *
133 parser
->device
->collection_size
);
134 memset(collection
+ parser
->device
->collection_size
, 0,
135 sizeof(struct hid_collection
) *
136 parser
->device
->collection_size
);
137 kfree(parser
->device
->collection
);
138 parser
->device
->collection
= collection
;
139 parser
->device
->collection_size
*= 2;
142 parser
->collection_stack
[parser
->collection_stack_ptr
++] =
143 parser
->device
->maxcollection
;
145 collection
= parser
->device
->collection
+
146 parser
->device
->maxcollection
++;
147 collection
->type
= type
;
148 collection
->usage
= usage
;
149 collection
->level
= parser
->collection_stack_ptr
- 1;
151 if (type
== HID_COLLECTION_APPLICATION
)
152 parser
->device
->maxapplication
++;
158 * Close a collection.
161 static int close_collection(struct hid_parser
*parser
)
163 if (!parser
->collection_stack_ptr
) {
164 dbg("collection stack underflow");
167 parser
->collection_stack_ptr
--;
172 * Climb up the stack, search for the specified collection type
173 * and return the usage.
176 static unsigned hid_lookup_collection(struct hid_parser
*parser
, unsigned type
)
179 for (n
= parser
->collection_stack_ptr
- 1; n
>= 0; n
--)
180 if (parser
->device
->collection
[parser
->collection_stack
[n
]].type
== type
)
181 return parser
->device
->collection
[parser
->collection_stack
[n
]].usage
;
182 return 0; /* we know nothing about this usage type */
186 * Add a usage to the temporary parser table.
189 static int hid_add_usage(struct hid_parser
*parser
, unsigned usage
)
191 if (parser
->local
.usage_index
>= HID_MAX_USAGES
) {
192 dbg("usage index exceeded");
195 parser
->local
.usage
[parser
->local
.usage_index
] = usage
;
196 parser
->local
.collection_index
[parser
->local
.usage_index
] =
197 parser
->collection_stack_ptr
?
198 parser
->collection_stack
[parser
->collection_stack_ptr
- 1] : 0;
199 parser
->local
.usage_index
++;
204 * Register a new field for this report.
207 static int hid_add_field(struct hid_parser
*parser
, unsigned report_type
, unsigned flags
)
209 struct hid_report
*report
;
210 struct hid_field
*field
;
215 if (!(report
= hid_register_report(parser
->device
, report_type
, parser
->global
.report_id
))) {
216 dbg("hid_register_report failed");
220 if (parser
->global
.logical_maximum
< parser
->global
.logical_minimum
) {
221 dbg("logical range invalid %d %d", parser
->global
.logical_minimum
, parser
->global
.logical_maximum
);
225 offset
= report
->size
;
226 report
->size
+= parser
->global
.report_size
* parser
->global
.report_count
;
228 if (!parser
->local
.usage_index
) /* Ignore padding fields */
231 usages
= max_t(int, parser
->local
.usage_index
, parser
->global
.report_count
);
233 if ((field
= hid_register_field(report
, usages
, parser
->global
.report_count
)) == NULL
)
236 field
->physical
= hid_lookup_collection(parser
, HID_COLLECTION_PHYSICAL
);
237 field
->logical
= hid_lookup_collection(parser
, HID_COLLECTION_LOGICAL
);
238 field
->application
= hid_lookup_collection(parser
, HID_COLLECTION_APPLICATION
);
240 for (i
= 0; i
< usages
; i
++) {
242 /* Duplicate the last usage we parsed if we have excess values */
243 if (i
>= parser
->local
.usage_index
)
244 j
= parser
->local
.usage_index
- 1;
245 field
->usage
[i
].hid
= parser
->local
.usage
[j
];
246 field
->usage
[i
].collection_index
=
247 parser
->local
.collection_index
[j
];
250 field
->maxusage
= usages
;
251 field
->flags
= flags
;
252 field
->report_offset
= offset
;
253 field
->report_type
= report_type
;
254 field
->report_size
= parser
->global
.report_size
;
255 field
->report_count
= parser
->global
.report_count
;
256 field
->logical_minimum
= parser
->global
.logical_minimum
;
257 field
->logical_maximum
= parser
->global
.logical_maximum
;
258 field
->physical_minimum
= parser
->global
.physical_minimum
;
259 field
->physical_maximum
= parser
->global
.physical_maximum
;
260 field
->unit_exponent
= parser
->global
.unit_exponent
;
261 field
->unit
= parser
->global
.unit
;
267 * Read data value from item.
270 static u32
item_udata(struct hid_item
*item
)
272 switch (item
->size
) {
273 case 1: return item
->data
.u8
;
274 case 2: return item
->data
.u16
;
275 case 4: return item
->data
.u32
;
280 static s32
item_sdata(struct hid_item
*item
)
282 switch (item
->size
) {
283 case 1: return item
->data
.s8
;
284 case 2: return item
->data
.s16
;
285 case 4: return item
->data
.s32
;
291 * Process a global item.
294 static int hid_parser_global(struct hid_parser
*parser
, struct hid_item
*item
)
298 case HID_GLOBAL_ITEM_TAG_PUSH
:
300 if (parser
->global_stack_ptr
== HID_GLOBAL_STACK_SIZE
) {
301 dbg("global enviroment stack overflow");
305 memcpy(parser
->global_stack
+ parser
->global_stack_ptr
++,
306 &parser
->global
, sizeof(struct hid_global
));
309 case HID_GLOBAL_ITEM_TAG_POP
:
311 if (!parser
->global_stack_ptr
) {
312 dbg("global enviroment stack underflow");
316 memcpy(&parser
->global
, parser
->global_stack
+ --parser
->global_stack_ptr
,
317 sizeof(struct hid_global
));
320 case HID_GLOBAL_ITEM_TAG_USAGE_PAGE
:
321 parser
->global
.usage_page
= item_udata(item
);
324 case HID_GLOBAL_ITEM_TAG_LOGICAL_MINIMUM
:
325 parser
->global
.logical_minimum
= item_sdata(item
);
328 case HID_GLOBAL_ITEM_TAG_LOGICAL_MAXIMUM
:
329 if (parser
->global
.logical_minimum
< 0)
330 parser
->global
.logical_maximum
= item_sdata(item
);
332 parser
->global
.logical_maximum
= item_udata(item
);
335 case HID_GLOBAL_ITEM_TAG_PHYSICAL_MINIMUM
:
336 parser
->global
.physical_minimum
= item_sdata(item
);
339 case HID_GLOBAL_ITEM_TAG_PHYSICAL_MAXIMUM
:
340 if (parser
->global
.physical_minimum
< 0)
341 parser
->global
.physical_maximum
= item_sdata(item
);
343 parser
->global
.physical_maximum
= item_udata(item
);
346 case HID_GLOBAL_ITEM_TAG_UNIT_EXPONENT
:
347 parser
->global
.unit_exponent
= item_sdata(item
);
350 case HID_GLOBAL_ITEM_TAG_UNIT
:
351 parser
->global
.unit
= item_udata(item
);
354 case HID_GLOBAL_ITEM_TAG_REPORT_SIZE
:
355 if ((parser
->global
.report_size
= item_udata(item
)) > 32) {
356 dbg("invalid report_size %d", parser
->global
.report_size
);
361 case HID_GLOBAL_ITEM_TAG_REPORT_COUNT
:
362 if ((parser
->global
.report_count
= item_udata(item
)) > HID_MAX_USAGES
) {
363 dbg("invalid report_count %d", parser
->global
.report_count
);
368 case HID_GLOBAL_ITEM_TAG_REPORT_ID
:
369 if ((parser
->global
.report_id
= item_udata(item
)) == 0) {
370 dbg("report_id 0 is invalid");
376 dbg("unknown global tag 0x%x", item
->tag
);
382 * Process a local item.
385 static int hid_parser_local(struct hid_parser
*parser
, struct hid_item
*item
)
390 if (item
->size
== 0) {
391 dbg("item data expected for local item");
395 data
= item_udata(item
);
399 case HID_LOCAL_ITEM_TAG_DELIMITER
:
403 * We treat items before the first delimiter
404 * as global to all usage sets (branch 0).
405 * In the moment we process only these global
406 * items and the first delimiter set.
408 if (parser
->local
.delimiter_depth
!= 0) {
409 dbg("nested delimiters");
412 parser
->local
.delimiter_depth
++;
413 parser
->local
.delimiter_branch
++;
415 if (parser
->local
.delimiter_depth
< 1) {
416 dbg("bogus close delimiter");
419 parser
->local
.delimiter_depth
--;
423 case HID_LOCAL_ITEM_TAG_USAGE
:
425 if (parser
->local
.delimiter_branch
> 1) {
426 dbg("alternative usage ignored");
431 data
= (parser
->global
.usage_page
<< 16) + data
;
433 return hid_add_usage(parser
, data
);
435 case HID_LOCAL_ITEM_TAG_USAGE_MINIMUM
:
437 if (parser
->local
.delimiter_branch
> 1) {
438 dbg("alternative usage ignored");
443 data
= (parser
->global
.usage_page
<< 16) + data
;
445 parser
->local
.usage_minimum
= data
;
448 case HID_LOCAL_ITEM_TAG_USAGE_MAXIMUM
:
450 if (parser
->local
.delimiter_branch
> 1) {
451 dbg("alternative usage ignored");
456 data
= (parser
->global
.usage_page
<< 16) + data
;
458 for (n
= parser
->local
.usage_minimum
; n
<= data
; n
++)
459 if (hid_add_usage(parser
, n
)) {
460 dbg("hid_add_usage failed\n");
467 dbg("unknown local item tag 0x%x", item
->tag
);
474 * Process a main item.
477 static int hid_parser_main(struct hid_parser
*parser
, struct hid_item
*item
)
482 data
= item_udata(item
);
485 case HID_MAIN_ITEM_TAG_BEGIN_COLLECTION
:
486 ret
= open_collection(parser
, data
& 0xff);
488 case HID_MAIN_ITEM_TAG_END_COLLECTION
:
489 ret
= close_collection(parser
);
491 case HID_MAIN_ITEM_TAG_INPUT
:
492 ret
= hid_add_field(parser
, HID_INPUT_REPORT
, data
);
494 case HID_MAIN_ITEM_TAG_OUTPUT
:
495 ret
= hid_add_field(parser
, HID_OUTPUT_REPORT
, data
);
497 case HID_MAIN_ITEM_TAG_FEATURE
:
498 ret
= hid_add_field(parser
, HID_FEATURE_REPORT
, data
);
501 dbg("unknown main item tag 0x%x", item
->tag
);
505 memset(&parser
->local
, 0, sizeof(parser
->local
)); /* Reset the local parser environment */
511 * Process a reserved item.
514 static int hid_parser_reserved(struct hid_parser
*parser
, struct hid_item
*item
)
516 dbg("reserved item type, tag 0x%x", item
->tag
);
521 * Free a report and all registered fields. The field->usage and
522 * field->value table's are allocated behind the field, so we need
523 * only to free(field) itself.
526 static void hid_free_report(struct hid_report
*report
)
530 for (n
= 0; n
< report
->maxfield
; n
++)
531 kfree(report
->field
[n
]);
536 * Free a device structure, all reports, and all fields.
539 void hid_free_device(struct hid_device
*device
)
543 for (i
= 0; i
< HID_REPORT_TYPES
; i
++) {
544 struct hid_report_enum
*report_enum
= device
->report_enum
+ i
;
546 for (j
= 0; j
< 256; j
++) {
547 struct hid_report
*report
= report_enum
->report_id_hash
[j
];
549 hid_free_report(report
);
553 kfree(device
->rdesc
);
556 EXPORT_SYMBOL_GPL(hid_free_device
);
559 * Fetch a report description item from the data stream. We support long
560 * items, though they are not used yet.
563 static u8
*fetch_item(__u8
*start
, __u8
*end
, struct hid_item
*item
)
567 if ((end
- start
) <= 0)
572 item
->type
= (b
>> 2) & 3;
573 item
->tag
= (b
>> 4) & 15;
575 if (item
->tag
== HID_ITEM_TAG_LONG
) {
577 item
->format
= HID_ITEM_FORMAT_LONG
;
579 if ((end
- start
) < 2)
582 item
->size
= *start
++;
583 item
->tag
= *start
++;
585 if ((end
- start
) < item
->size
)
588 item
->data
.longdata
= start
;
593 item
->format
= HID_ITEM_FORMAT_SHORT
;
596 switch (item
->size
) {
602 if ((end
- start
) < 1)
604 item
->data
.u8
= *start
++;
608 if ((end
- start
) < 2)
610 item
->data
.u16
= le16_to_cpu(get_unaligned((__le16
*)start
));
611 start
= (__u8
*)((__le16
*)start
+ 1);
616 if ((end
- start
) < 4)
618 item
->data
.u32
= le32_to_cpu(get_unaligned((__le32
*)start
));
619 start
= (__u8
*)((__le32
*)start
+ 1);
627 * Parse a report description into a hid_device structure. Reports are
628 * enumerated, fields are attached to these reports.
631 struct hid_device
*hid_parse_report(__u8
*start
, unsigned size
)
633 struct hid_device
*device
;
634 struct hid_parser
*parser
;
635 struct hid_item item
;
638 static int (*dispatch_type
[])(struct hid_parser
*parser
,
639 struct hid_item
*item
) = {
646 if (!(device
= kzalloc(sizeof(struct hid_device
), GFP_KERNEL
)))
649 if (!(device
->collection
= kzalloc(sizeof(struct hid_collection
) *
650 HID_DEFAULT_NUM_COLLECTIONS
, GFP_KERNEL
))) {
654 device
->collection_size
= HID_DEFAULT_NUM_COLLECTIONS
;
656 for (i
= 0; i
< HID_REPORT_TYPES
; i
++)
657 INIT_LIST_HEAD(&device
->report_enum
[i
].report_list
);
659 if (!(device
->rdesc
= (__u8
*)kmalloc(size
, GFP_KERNEL
))) {
660 kfree(device
->collection
);
664 memcpy(device
->rdesc
, start
, size
);
665 device
->rsize
= size
;
667 if (!(parser
= kzalloc(sizeof(struct hid_parser
), GFP_KERNEL
))) {
668 kfree(device
->rdesc
);
669 kfree(device
->collection
);
673 parser
->device
= device
;
676 while ((start
= fetch_item(start
, end
, &item
)) != NULL
) {
678 if (item
.format
!= HID_ITEM_FORMAT_SHORT
) {
679 dbg("unexpected long global item");
680 kfree(device
->collection
);
681 hid_free_device(device
);
686 if (dispatch_type
[item
.type
](parser
, &item
)) {
687 dbg("item %u %u %u %u parsing failed\n",
688 item
.format
, (unsigned)item
.size
, (unsigned)item
.type
, (unsigned)item
.tag
);
689 kfree(device
->collection
);
690 hid_free_device(device
);
696 if (parser
->collection_stack_ptr
) {
697 dbg("unbalanced collection at end of report description");
698 kfree(device
->collection
);
699 hid_free_device(device
);
703 if (parser
->local
.delimiter_depth
) {
704 dbg("unbalanced delimiter at end of report description");
705 kfree(device
->collection
);
706 hid_free_device(device
);
715 dbg("item fetching failed at offset %d\n", (int)(end
- start
));
716 kfree(device
->collection
);
717 hid_free_device(device
);
721 EXPORT_SYMBOL_GPL(hid_parse_report
);
724 * Convert a signed n-bit integer to signed 32-bit integer. Common
725 * cases are done through the compiler, the screwed things has to be
729 static s32
snto32(__u32 value
, unsigned n
)
732 case 8: return ((__s8
)value
);
733 case 16: return ((__s16
)value
);
734 case 32: return ((__s32
)value
);
736 return value
& (1 << (n
- 1)) ? value
| (-1 << n
) : value
;
740 * Convert a signed 32-bit integer to a signed n-bit integer.
743 static u32
s32ton(__s32 value
, unsigned n
)
745 s32 a
= value
>> (n
- 1);
747 return value
< 0 ? 1 << (n
- 1) : (1 << (n
- 1)) - 1;
748 return value
& ((1 << n
) - 1);
752 * Extract/implement a data field from/to a little endian report (bit array).
754 * Code sort-of follows HID spec:
755 * http://www.usb.org/developers/devclass_docs/HID1_11.pdf
757 * While the USB HID spec allows unlimited length bit fields in "report
758 * descriptors", most devices never use more than 16 bits.
759 * One model of UPS is claimed to report "LINEV" as a 32-bit field.
760 * Search linux-kernel and linux-usb-devel archives for "hid-core extract".
763 static __inline__ __u32
extract(__u8
*report
, unsigned offset
, unsigned n
)
769 report
+= offset
>> 3; /* adjust byte index */
770 offset
&= 7; /* now only need bit offset into one byte */
771 x
= get_unaligned((u64
*) report
);
773 x
= (x
>> offset
) & ((1ULL << n
) - 1); /* extract bit field */
778 * "implement" : set bits in a little endian bit stream.
779 * Same concepts as "extract" (see comments above).
780 * The data mangled in the bit stream remains in little endian
781 * order the whole time. It make more sense to talk about
782 * endianness of register values by considering a register
783 * a "cached" copy of the little endiad bit stream.
785 static __inline__
void implement(__u8
*report
, unsigned offset
, unsigned n
, __u32 value
)
788 u64 m
= (1ULL << n
) - 1;
795 report
+= offset
>> 3;
798 x
= get_unaligned((u64
*)report
);
799 x
&= cpu_to_le64(~(m
<< offset
));
800 x
|= cpu_to_le64(((u64
) value
) << offset
);
801 put_unaligned(x
, (u64
*) report
);
805 * Search an array for a value.
808 static __inline__
int search(__s32
*array
, __s32 value
, unsigned n
)
811 if (*array
++ == value
)
817 static void hid_process_event(struct hid_device
*hid
, struct hid_field
*field
, struct hid_usage
*usage
, __s32 value
, int interrupt
)
819 hid_dump_input(usage
, value
);
820 if (hid
->claimed
& HID_CLAIMED_INPUT
)
821 hidinput_hid_event(hid
, field
, usage
, value
);
822 if (hid
->claimed
& HID_CLAIMED_HIDDEV
&& interrupt
&& hid
->hiddev_hid_event
)
823 hid
->hiddev_hid_event(hid
, field
, usage
, value
);
827 * Analyse a received field, and fetch the data from it. The field
828 * content is stored for next report processing (we do differential
829 * reporting to the layer).
832 void hid_input_field(struct hid_device
*hid
, struct hid_field
*field
, __u8
*data
, int interrupt
)
835 unsigned count
= field
->report_count
;
836 unsigned offset
= field
->report_offset
;
837 unsigned size
= field
->report_size
;
838 __s32 min
= field
->logical_minimum
;
839 __s32 max
= field
->logical_maximum
;
842 if (!(value
= kmalloc(sizeof(__s32
) * count
, GFP_ATOMIC
)))
845 for (n
= 0; n
< count
; n
++) {
847 value
[n
] = min
< 0 ? snto32(extract(data
, offset
+ n
* size
, size
), size
) :
848 extract(data
, offset
+ n
* size
, size
);
850 if (!(field
->flags
& HID_MAIN_ITEM_VARIABLE
) /* Ignore report if ErrorRollOver */
851 && value
[n
] >= min
&& value
[n
] <= max
852 && field
->usage
[value
[n
] - min
].hid
== HID_UP_KEYBOARD
+ 1)
856 for (n
= 0; n
< count
; n
++) {
858 if (HID_MAIN_ITEM_VARIABLE
& field
->flags
) {
859 hid_process_event(hid
, field
, &field
->usage
[n
], value
[n
], interrupt
);
863 if (field
->value
[n
] >= min
&& field
->value
[n
] <= max
864 && field
->usage
[field
->value
[n
] - min
].hid
865 && search(value
, field
->value
[n
], count
))
866 hid_process_event(hid
, field
, &field
->usage
[field
->value
[n
] - min
], 0, interrupt
);
868 if (value
[n
] >= min
&& value
[n
] <= max
869 && field
->usage
[value
[n
] - min
].hid
870 && search(field
->value
, value
[n
], count
))
871 hid_process_event(hid
, field
, &field
->usage
[value
[n
] - min
], 1, interrupt
);
874 memcpy(field
->value
, value
, count
* sizeof(__s32
));
878 EXPORT_SYMBOL_GPL(hid_input_field
);
881 * Output the field into the report.
884 static void hid_output_field(struct hid_field
*field
, __u8
*data
)
886 unsigned count
= field
->report_count
;
887 unsigned offset
= field
->report_offset
;
888 unsigned size
= field
->report_size
;
891 for (n
= 0; n
< count
; n
++) {
892 if (field
->logical_minimum
< 0) /* signed values */
893 implement(data
, offset
+ n
* size
, size
, s32ton(field
->value
[n
], size
));
894 else /* unsigned values */
895 implement(data
, offset
+ n
* size
, size
, field
->value
[n
]);
903 void hid_output_report(struct hid_report
*report
, __u8
*data
)
908 *data
++ = report
->id
;
910 for (n
= 0; n
< report
->maxfield
; n
++)
911 hid_output_field(report
->field
[n
], data
);
913 EXPORT_SYMBOL_GPL(hid_output_report
);
916 * Set a field value. The report this field belongs to has to be
917 * created and transferred to the device, to set this value in the
921 int hid_set_field(struct hid_field
*field
, unsigned offset
, __s32 value
)
923 unsigned size
= field
->report_size
;
925 hid_dump_input(field
->usage
+ offset
, value
);
927 if (offset
>= field
->report_count
) {
928 dbg("offset (%d) exceeds report_count (%d)", offset
, field
->report_count
);
929 hid_dump_field(field
, 8);
932 if (field
->logical_minimum
< 0) {
933 if (value
!= snto32(s32ton(value
, size
), size
)) {
934 dbg("value %d is out of range", value
);
938 field
->value
[offset
] = value
;
941 EXPORT_SYMBOL_GPL(hid_set_field
);
943 int hid_input_report(struct hid_device
*hid
, int type
, u8
*data
, int size
, int interrupt
)
945 struct hid_report_enum
*report_enum
= hid
->report_enum
+ type
;
946 struct hid_report
*report
;
958 printk(KERN_DEBUG __FILE__
": report (size %u) (%snumbered)\n", len
, report_enum
->numbered
? "" : "un");
961 n
= 0; /* Normally report number is 0 */
962 if (report_enum
->numbered
) { /* Device uses numbered reports, data[0] is report number */
970 printk(KERN_DEBUG __FILE__
": report %d (size %u) = ", n
, size
);
971 for (i
= 0; i
< size
; i
++)
972 printk(" %02x", data
[i
]);
977 if (!(report
= report_enum
->report_id_hash
[n
])) {
978 dbg("undefined report_id %d received", n
);
982 rsize
= ((report
->size
- 1) >> 3) + 1;
985 dbg("report %d is too short, (%d < %d)", report
->id
, size
, rsize
);
989 if ((hid
->claimed
& HID_CLAIMED_HIDDEV
) && hid
->hiddev_report_event
)
990 hid
->hiddev_report_event(hid
, report
);
992 for (n
= 0; n
< report
->maxfield
; n
++)
993 hid_input_field(hid
, report
->field
[n
], data
, interrupt
);
995 if (hid
->claimed
& HID_CLAIMED_INPUT
)
996 hidinput_report_event(hid
, report
);
1000 EXPORT_SYMBOL_GPL(hid_input_report
);
1002 MODULE_LICENSE(DRIVER_LICENSE
);