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