1#ifndef __HID_H
2#define __HID_H
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33#include <linux/types.h>
34#include <linux/slab.h>
35#include <linux/list.h>
36
37
38
39
40
41#define USB_INTERFACE_CLASS_HID 3
42
43
44
45
46
47
48
49struct hid_item {
50 unsigned format;
51 __u8 size;
52 __u8 type;
53 __u8 tag;
54 union {
55 __u8 u8;
56 __s8 s8;
57 __u16 u16;
58 __s16 s16;
59 __u32 u32;
60 __s32 s32;
61 __u8 *longdata;
62 } data;
63};
64
65
66
67
68
69#define HID_ITEM_FORMAT_SHORT 0
70#define HID_ITEM_FORMAT_LONG 1
71
72
73
74
75
76#define HID_ITEM_TAG_LONG 15
77
78
79
80
81
82#define HID_ITEM_TYPE_MAIN 0
83#define HID_ITEM_TYPE_GLOBAL 1
84#define HID_ITEM_TYPE_LOCAL 2
85#define HID_ITEM_TYPE_RESERVED 3
86
87
88
89
90
91#define HID_MAIN_ITEM_TAG_INPUT 8
92#define HID_MAIN_ITEM_TAG_OUTPUT 9
93#define HID_MAIN_ITEM_TAG_FEATURE 11
94#define HID_MAIN_ITEM_TAG_BEGIN_COLLECTION 10
95#define HID_MAIN_ITEM_TAG_END_COLLECTION 12
96
97
98
99
100
101#define HID_MAIN_ITEM_CONSTANT 0x001
102#define HID_MAIN_ITEM_VARIABLE 0x002
103#define HID_MAIN_ITEM_RELATIVE 0x004
104#define HID_MAIN_ITEM_WRAP 0x008
105#define HID_MAIN_ITEM_NONLINEAR 0x010
106#define HID_MAIN_ITEM_NO_PREFERRED 0x020
107#define HID_MAIN_ITEM_NULL_STATE 0x040
108#define HID_MAIN_ITEM_VOLATILE 0x080
109#define HID_MAIN_ITEM_BUFFERED_BYTE 0x100
110
111
112
113
114
115#define HID_COLLECTION_PHYSICAL 0
116#define HID_COLLECTION_APPLICATION 1
117#define HID_COLLECTION_LOGICAL 2
118
119
120
121
122
123#define HID_GLOBAL_ITEM_TAG_USAGE_PAGE 0
124#define HID_GLOBAL_ITEM_TAG_LOGICAL_MINIMUM 1
125#define HID_GLOBAL_ITEM_TAG_LOGICAL_MAXIMUM 2
126#define HID_GLOBAL_ITEM_TAG_PHYSICAL_MINIMUM 3
127#define HID_GLOBAL_ITEM_TAG_PHYSICAL_MAXIMUM 4
128#define HID_GLOBAL_ITEM_TAG_UNIT_EXPONENT 5
129#define HID_GLOBAL_ITEM_TAG_UNIT 6
130#define HID_GLOBAL_ITEM_TAG_REPORT_SIZE 7
131#define HID_GLOBAL_ITEM_TAG_REPORT_ID 8
132#define HID_GLOBAL_ITEM_TAG_REPORT_COUNT 9
133#define HID_GLOBAL_ITEM_TAG_PUSH 10
134#define HID_GLOBAL_ITEM_TAG_POP 11
135
136
137
138
139
140#define HID_LOCAL_ITEM_TAG_USAGE 0
141#define HID_LOCAL_ITEM_TAG_USAGE_MINIMUM 1
142#define HID_LOCAL_ITEM_TAG_USAGE_MAXIMUM 2
143#define HID_LOCAL_ITEM_TAG_DESIGNATOR_INDEX 3
144#define HID_LOCAL_ITEM_TAG_DESIGNATOR_MINIMUM 4
145#define HID_LOCAL_ITEM_TAG_DESIGNATOR_MAXIMUM 5
146#define HID_LOCAL_ITEM_TAG_STRING_INDEX 7
147#define HID_LOCAL_ITEM_TAG_STRING_MINIMUM 8
148#define HID_LOCAL_ITEM_TAG_STRING_MAXIMUM 9
149#define HID_LOCAL_ITEM_TAG_DELIMITER 10
150
151
152
153
154
155#define HID_USAGE_PAGE 0xffff0000
156
157#define HID_UP_GENDESK 0x00010000
158#define HID_UP_KEYBOARD 0x00070000
159#define HID_UP_LED 0x00080000
160#define HID_UP_BUTTON 0x00090000
161#define HID_UP_CONSUMER 0x000c0000
162#define HID_UP_DIGITIZER 0x000d0000
163#define HID_UP_PID 0x000f0000
164
165#define HID_USAGE 0x0000ffff
166
167#define HID_GD_POINTER 0x00010001
168#define HID_GD_MOUSE 0x00010002
169#define HID_GD_JOYSTICK 0x00010004
170#define HID_GD_GAMEPAD 0x00010005
171#define HID_GD_HATSWITCH 0x00010039
172
173
174
175
176
177#define HID_INPUT_REPORT 0
178#define HID_OUTPUT_REPORT 1
179#define HID_FEATURE_REPORT 2
180
181
182
183
184
185#define HID_QUIRK_INVERT 0x01
186#define HID_QUIRK_NOTOUCH 0x02
187#define HID_QUIRK_IGNORE 0x04
188#define HID_QUIRK_NOGET 0x08
189#define HID_QUIRK_HIDDEV 0x10
190#define HID_QUIRK_BADPAD 0x20
191#define HID_QUIRK_MULTI_INPUT 0x40
192
193
194
195
196
197
198
199struct hid_global {
200 unsigned usage_page;
201 __s32 logical_minimum;
202 __s32 logical_maximum;
203 __s32 physical_minimum;
204 __s32 physical_maximum;
205 unsigned unit_exponent;
206 unsigned unit;
207 unsigned report_id;
208 unsigned report_size;
209 unsigned report_count;
210};
211
212
213
214
215
216#define HID_MAX_DESCRIPTOR_SIZE 4096
217#define HID_MAX_USAGES 1024
218#define HID_MAX_APPLICATIONS 16
219#define HID_DEFAULT_NUM_COLLECTIONS 16
220
221struct hid_local {
222 unsigned usage[HID_MAX_USAGES];
223 unsigned collection_index[HID_MAX_USAGES];
224 unsigned usage_index;
225 unsigned usage_minimum;
226 unsigned delimiter_depth;
227 unsigned delimiter_branch;
228};
229
230
231
232
233
234
235struct hid_collection {
236 unsigned type;
237 unsigned usage;
238 unsigned level;
239};
240
241struct hid_usage {
242 unsigned hid;
243 unsigned collection_index;
244 __u16 code;
245 __u8 type;
246 __s8 hat_min;
247 __s8 hat_max;
248};
249
250struct hid_field {
251 unsigned physical;
252 unsigned logical;
253 unsigned application;
254 struct hid_usage *usage;
255 unsigned maxusage;
256 unsigned flags;
257 unsigned report_offset;
258 unsigned report_size;
259 unsigned report_count;
260 unsigned report_type;
261 __s32 *value;
262 __s32 logical_minimum;
263 __s32 logical_maximum;
264 __s32 physical_minimum;
265 __s32 physical_maximum;
266 unsigned unit_exponent;
267 unsigned unit;
268 struct hid_report *report;
269 unsigned index;
270};
271
272#define HID_MAX_FIELDS 64
273
274struct hid_report {
275 struct list_head list;
276 unsigned id;
277 unsigned type;
278 struct hid_field *field[HID_MAX_FIELDS];
279 unsigned maxfield;
280 unsigned size;
281 unsigned idx;
282 unsigned char *data;
283 struct hid_device *device;
284};
285
286struct hid_report_enum {
287 unsigned numbered;
288 struct list_head report_list;
289 struct hid_report *report_id_hash[256];
290};
291
292#define HID_REPORT_TYPES 3
293
294#define HID_BUFFER_SIZE 32
295#define HID_CONTROL_FIFO_SIZE 8
296
297struct hid_control_fifo {
298 struct usb_ctrlrequest dr;
299 char buffer[HID_BUFFER_SIZE];
300};
301
302#define HID_CLAIMED_INPUT 1
303#define HID_CLAIMED_HIDDEV 2
304
305struct hid_input {
306 struct list_head list;
307 struct hid_report *report;
308 struct input_dev input;
309};
310
311struct hid_device {
312 __u8 *rdesc;
313 unsigned rsize;
314 struct hid_collection *collection;
315 unsigned collection_size;
316 unsigned maxcollection;
317 unsigned maxapplication;
318 unsigned version;
319 unsigned country;
320 struct hid_report_enum report_enum[HID_REPORT_TYPES];
321
322 struct usb_device *dev;
323 int ifnum;
324
325 struct urb urb;
326 char buffer[HID_BUFFER_SIZE];
327
328 struct urb urbout;
329 struct hid_control_fifo out[HID_CONTROL_FIFO_SIZE];
330 unsigned char outhead, outtail;
331
332 unsigned claimed;
333 unsigned quirks;
334
335 struct list_head inputs;
336 void *hiddev;
337 int minor;
338
339 int open;
340 char name[128];
341};
342
343#define HID_GLOBAL_STACK_SIZE 4
344#define HID_COLLECTION_STACK_SIZE 4
345
346struct hid_parser {
347 struct hid_global global;
348 struct hid_global global_stack[HID_GLOBAL_STACK_SIZE];
349 unsigned global_stack_ptr;
350 struct hid_local local;
351 unsigned collection_stack[HID_COLLECTION_STACK_SIZE];
352 unsigned collection_stack_ptr;
353 struct hid_device *device;
354};
355
356struct hid_class_descriptor {
357 __u8 bDescriptorType;
358 __u16 wDescriptorLength;
359} __attribute__ ((packed));
360
361struct hid_descriptor {
362 __u8 bLength;
363 __u8 bDescriptorType;
364 __u16 bcdHID;
365 __u8 bCountryCode;
366 __u8 bNumDescriptors;
367
368 struct hid_class_descriptor desc[1];
369} __attribute__ ((packed));
370
371
372#ifdef DEBUG
373#include "hid-debug.h"
374#else
375#define hid_dump_input(a,b) do { } while (0)
376#define hid_dump_device(c) do { } while (0)
377#endif
378
379#endif
380
381#ifdef CONFIG_USB_HIDINPUT
382#define IS_INPUT_APPLICATION(a) (((a >= 0x00010000) && (a <= 0x00010008)) || (a == 0x00010080) || ( a == 0x000c0001))
383extern void hidinput_hid_event(struct hid_device *, struct hid_field *, struct hid_usage *, __s32);
384extern int hidinput_connect(struct hid_device *);
385extern void hidinput_disconnect(struct hid_device *);
386#else
387#define IS_INPUT_APPLICATION(a) (0)
388static inline void hidinput_hid_event(struct hid_device *hid, struct hid_field *field, struct hid_usage *usage, __s32 value) { }
389static inline int hidinput_connect(struct hid_device *hid) { return -ENODEV; }
390static inline void hidinput_disconnect(struct hid_device *hid) { }
391#endif
392
393int hid_open(struct hid_device *);
394void hid_close(struct hid_device *);
395int hid_find_field(struct hid_device *, unsigned int, unsigned int, struct hid_field **);
396int hid_set_field(struct hid_field *, unsigned, __s32);
397void hid_write_report(struct hid_device *, struct hid_report *);
398void hid_read_report(struct hid_device *, struct hid_report *);
399void hid_init_reports(struct hid_device *hid);
400