Commit | Line | Data |
---|---|---|
ace3d861 DH |
1 | #ifndef __UHID_H_ |
2 | #define __UHID_H_ | |
3 | ||
4 | /* | |
5 | * User-space I/O driver support for HID subsystem | |
6 | * Copyright (c) 2012 David Herrmann | |
7 | */ | |
8 | ||
9 | /* | |
10 | * This program is free software; you can redistribute it and/or modify it | |
11 | * under the terms of the GNU General Public License as published by the Free | |
12 | * Software Foundation; either version 2 of the License, or (at your option) | |
13 | * any later version. | |
14 | */ | |
15 | ||
16 | /* | |
17 | * Public header for user-space communication. We try to keep every structure | |
18 | * aligned but to be safe we also use __attribute__((__packed__)). Therefore, | |
19 | * the communication should be ABI compatible even between architectures. | |
20 | */ | |
21 | ||
22 | #include <linux/input.h> | |
23 | #include <linux/types.h> | |
4522643a | 24 | #include <linux/hid.h> |
ace3d861 DH |
25 | |
26 | enum uhid_event_type { | |
50598e70 | 27 | __UHID_LEGACY_CREATE, |
d365c6cf | 28 | UHID_DESTROY, |
ec4b7dea DH |
29 | UHID_START, |
30 | UHID_STOP, | |
e7191474 DH |
31 | UHID_OPEN, |
32 | UHID_CLOSE, | |
3b3baa82 | 33 | UHID_OUTPUT, |
50598e70 DH |
34 | __UHID_LEGACY_OUTPUT_EV, |
35 | __UHID_LEGACY_INPUT, | |
36 | UHID_GET_REPORT, | |
37 | UHID_GET_REPORT_REPLY, | |
4522643a PG |
38 | UHID_CREATE2, |
39 | UHID_INPUT2, | |
11c22155 DH |
40 | UHID_SET_REPORT, |
41 | UHID_SET_REPORT_REPLY, | |
ace3d861 DH |
42 | }; |
43 | ||
4522643a PG |
44 | struct uhid_create2_req { |
45 | __u8 name[128]; | |
46 | __u8 phys[64]; | |
47 | __u8 uniq[64]; | |
48 | __u16 rd_size; | |
49 | __u16 bus; | |
50 | __u32 vendor; | |
51 | __u32 product; | |
52 | __u32 version; | |
53 | __u32 country; | |
54 | __u8 rd_data[HID_MAX_DESCRIPTOR_SIZE]; | |
55 | } __attribute__((__packed__)); | |
56 | ||
c2b2f16c DH |
57 | enum uhid_dev_flag { |
58 | UHID_DEV_NUMBERED_FEATURE_REPORTS = (1ULL << 0), | |
59 | UHID_DEV_NUMBERED_OUTPUT_REPORTS = (1ULL << 1), | |
60 | UHID_DEV_NUMBERED_INPUT_REPORTS = (1ULL << 2), | |
61 | }; | |
62 | ||
63 | struct uhid_start_req { | |
64 | __u64 dev_flags; | |
65 | }; | |
66 | ||
5e87a36a DH |
67 | #define UHID_DATA_MAX 4096 |
68 | ||
3b3baa82 DH |
69 | enum uhid_report_type { |
70 | UHID_FEATURE_REPORT, | |
71 | UHID_OUTPUT_REPORT, | |
72 | UHID_INPUT_REPORT, | |
73 | }; | |
74 | ||
50598e70 DH |
75 | struct uhid_input2_req { |
76 | __u16 size; | |
77 | __u8 data[UHID_DATA_MAX]; | |
78 | } __attribute__((__packed__)); | |
79 | ||
80 | struct uhid_output_req { | |
5e87a36a DH |
81 | __u8 data[UHID_DATA_MAX]; |
82 | __u16 size; | |
50598e70 | 83 | __u8 rtype; |
5e87a36a DH |
84 | } __attribute__((__packed__)); |
85 | ||
50598e70 DH |
86 | struct uhid_get_report_req { |
87 | __u32 id; | |
88 | __u8 rnum; | |
89 | __u8 rtype; | |
90 | } __attribute__((__packed__)); | |
91 | ||
92 | struct uhid_get_report_reply_req { | |
93 | __u32 id; | |
94 | __u16 err; | |
4522643a PG |
95 | __u16 size; |
96 | __u8 data[UHID_DATA_MAX]; | |
97 | } __attribute__((__packed__)); | |
98 | ||
11c22155 DH |
99 | struct uhid_set_report_req { |
100 | __u32 id; | |
101 | __u8 rnum; | |
102 | __u8 rtype; | |
103 | __u16 size; | |
104 | __u8 data[UHID_DATA_MAX]; | |
105 | } __attribute__((__packed__)); | |
106 | ||
107 | struct uhid_set_report_reply_req { | |
108 | __u32 id; | |
109 | __u16 err; | |
110 | } __attribute__((__packed__)); | |
111 | ||
50598e70 DH |
112 | /* |
113 | * Compat Layer | |
114 | * All these commands and requests are obsolete. You should avoid using them in | |
115 | * new code. We support them for backwards-compatibility, but you might not get | |
116 | * access to new feature in case you use them. | |
117 | */ | |
118 | ||
119 | enum uhid_legacy_event_type { | |
120 | UHID_CREATE = __UHID_LEGACY_CREATE, | |
121 | UHID_OUTPUT_EV = __UHID_LEGACY_OUTPUT_EV, | |
122 | UHID_INPUT = __UHID_LEGACY_INPUT, | |
123 | UHID_FEATURE = UHID_GET_REPORT, | |
124 | UHID_FEATURE_ANSWER = UHID_GET_REPORT_REPLY, | |
125 | }; | |
126 | ||
127 | /* Obsolete! Use UHID_CREATE2. */ | |
128 | struct uhid_create_req { | |
129 | __u8 name[128]; | |
130 | __u8 phys[64]; | |
131 | __u8 uniq[64]; | |
132 | __u8 __user *rd_data; | |
133 | __u16 rd_size; | |
134 | ||
135 | __u16 bus; | |
136 | __u32 vendor; | |
137 | __u32 product; | |
138 | __u32 version; | |
139 | __u32 country; | |
140 | } __attribute__((__packed__)); | |
141 | ||
142 | /* Obsolete! Use UHID_INPUT2. */ | |
143 | struct uhid_input_req { | |
3b3baa82 DH |
144 | __u8 data[UHID_DATA_MAX]; |
145 | __u16 size; | |
3b3baa82 DH |
146 | } __attribute__((__packed__)); |
147 | ||
50598e70 | 148 | /* Obsolete! Kernel uses UHID_OUTPUT exclusively now. */ |
f80e1360 DH |
149 | struct uhid_output_ev_req { |
150 | __u16 type; | |
151 | __u16 code; | |
152 | __s32 value; | |
153 | } __attribute__((__packed__)); | |
154 | ||
fa71f32b | 155 | /* Obsolete! Kernel uses ABI compatible UHID_GET_REPORT. */ |
fcfcf0de DH |
156 | struct uhid_feature_req { |
157 | __u32 id; | |
158 | __u8 rnum; | |
159 | __u8 rtype; | |
160 | } __attribute__((__packed__)); | |
161 | ||
fa71f32b | 162 | /* Obsolete! Use ABI compatible UHID_GET_REPORT_REPLY. */ |
fcfcf0de DH |
163 | struct uhid_feature_answer_req { |
164 | __u32 id; | |
165 | __u16 err; | |
166 | __u16 size; | |
167 | __u8 data[UHID_DATA_MAX]; | |
fee5dfec | 168 | } __attribute__((__packed__)); |
fcfcf0de | 169 | |
50598e70 DH |
170 | /* |
171 | * UHID Events | |
172 | * All UHID events from and to the kernel are encoded as "struct uhid_event". | |
173 | * The "type" field contains a UHID_* type identifier. All payload depends on | |
174 | * that type and can be accessed via ev->u.XYZ accordingly. | |
175 | * If user-space writes short events, they're extended with 0s by the kernel. If | |
176 | * the kernel writes short events, user-space shall extend them with 0s. | |
177 | */ | |
fa71f32b | 178 | |
ace3d861 DH |
179 | struct uhid_event { |
180 | __u32 type; | |
d365c6cf DH |
181 | |
182 | union { | |
183 | struct uhid_create_req create; | |
5e87a36a | 184 | struct uhid_input_req input; |
3b3baa82 | 185 | struct uhid_output_req output; |
f80e1360 | 186 | struct uhid_output_ev_req output_ev; |
fcfcf0de | 187 | struct uhid_feature_req feature; |
fa71f32b | 188 | struct uhid_get_report_req get_report; |
fcfcf0de | 189 | struct uhid_feature_answer_req feature_answer; |
fa71f32b | 190 | struct uhid_get_report_reply_req get_report_reply; |
4522643a PG |
191 | struct uhid_create2_req create2; |
192 | struct uhid_input2_req input2; | |
11c22155 DH |
193 | struct uhid_set_report_req set_report; |
194 | struct uhid_set_report_reply_req set_report_reply; | |
c2b2f16c | 195 | struct uhid_start_req start; |
d365c6cf | 196 | } u; |
ace3d861 DH |
197 | } __attribute__((__packed__)); |
198 | ||
199 | #endif /* __UHID_H_ */ |