blob: b7b64024d480504cd115efa21eee35265bc6f83c [file] [log] [blame]
Etienne Gemsa4f750b92015-02-20 17:14:10 +01001/*
2 * Copyright (c) 2015 Etienne Gemsa <etienne.gemsa@lse.epita.fr>
Dmitry V. Levin43c8a5d2016-05-27 00:49:08 +00003 * Copyright (c) 2015-2016 Dmitry V. Levin <ldv@altlinux.org>
Etienne Gemsa4f750b92015-02-20 17:14:10 +01004 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include "defs.h"
30
31#ifdef HAVE_LINUX_INPUT_H
Etienne Gemsa4f750b92015-02-20 17:14:10 +010032
Dmitry V. Levin43c8a5d2016-05-27 00:49:08 +000033#include DEF_MPERS_TYPE(struct_ff_effect)
34
Dmitry V. Levin8d85c232016-05-27 00:39:33 +000035# include <linux/ioctl.h>
36# include <linux/input.h>
Dmitry V. Levin43c8a5d2016-05-27 00:49:08 +000037
38typedef struct ff_effect struct_ff_effect;
39
40#endif /* HAVE_LINUX_BTRFS_H */
41
42#include MPERS_DEFS
43
44#ifdef HAVE_LINUX_INPUT_H
45
Dmitry V. Levin8d85c232016-05-27 00:39:33 +000046# include "xlat/evdev_autorepeat.h"
47# include "xlat/evdev_ff_status.h"
48# include "xlat/evdev_ff_types.h"
49# include "xlat/evdev_keycode.h"
50# include "xlat/evdev_leds.h"
51# include "xlat/evdev_misc.h"
52# include "xlat/evdev_mtslots.h"
53# include "xlat/evdev_prop.h"
54# include "xlat/evdev_relative_axes.h"
55# include "xlat/evdev_snd.h"
56# include "xlat/evdev_switch.h"
57# include "xlat/evdev_sync.h"
58
59# ifndef SYN_MAX
60# define SYN_MAX 0xf
61# endif
Dmitry V. Levin19dadf92015-02-22 02:50:33 +030062
Etienne Gemsa4f750b92015-02-20 17:14:10 +010063static void
Dmitry V. Levin43c8a5d2016-05-27 00:49:08 +000064decode_envelope(void *const data)
Etienne Gemsa4f750b92015-02-20 17:14:10 +010065{
Dmitry V. Levin43c8a5d2016-05-27 00:49:08 +000066 const struct ff_envelope *const envelope = data;
67
Dmitry V. Levinc758ed02016-05-27 00:40:53 +000068 tprintf(", envelope={attack_length=%" PRIu16
69 ", attack_level=%" PRIu16
70 ", fade_length=%" PRIu16
71 ", fade_level=%#x}",
Etienne Gemsa4f750b92015-02-20 17:14:10 +010072 envelope->attack_length,
73 envelope->attack_level,
74 envelope->fade_length,
75 envelope->fade_level);
76}
77
78static int
79ff_effect_ioctl(struct tcb *tcp, long arg)
80{
Dmitry V. Levin3a45eb32016-05-27 00:41:02 +000081 tprints(", ");
82
Dmitry V. Levin43c8a5d2016-05-27 00:49:08 +000083 struct_ff_effect ffe;
Etienne Gemsa4f750b92015-02-20 17:14:10 +010084
Dmitry V. Levin3a45eb32016-05-27 00:41:02 +000085 if (umove_or_printaddr(tcp, arg, &ffe))
86 return 1;
Etienne Gemsa4f750b92015-02-20 17:14:10 +010087
Dmitry V. Levin3a45eb32016-05-27 00:41:02 +000088 tprints("{type=");
Etienne Gemsa4f750b92015-02-20 17:14:10 +010089 printxval(evdev_ff_types, ffe.type, "FF_???");
Dmitry V. Levin3a45eb32016-05-27 00:41:02 +000090 tprintf(", id=%" PRIu16
91 ", direction=%" PRIu16 ", ",
92 ffe.id,
93 ffe.direction);
Etienne Gemsa4f750b92015-02-20 17:14:10 +010094
Dmitry V. Levin3a45eb32016-05-27 00:41:02 +000095 if (abbrev(tcp)) {
96 tprints("...}");
97 return 1;
Etienne Gemsa4f750b92015-02-20 17:14:10 +010098 }
99
Dmitry V. Levin3a45eb32016-05-27 00:41:02 +0000100 tprintf("trigger={button=%" PRIu16
101 ", interval=%" PRIu16 "}"
102 ", replay={length=%" PRIu16
103 ", delay=%" PRIu16 "}",
104 ffe.trigger.button,
105 ffe.trigger.interval,
106 ffe.replay.length,
107 ffe.replay.delay);
108
109 switch (ffe.type) {
110 case FF_CONSTANT:
111 tprintf(", constant={level=%" PRId16,
112 ffe.u.constant.level);
113 decode_envelope(&ffe.u.constant.envelope);
114 tprints("}");
115 break;
116 case FF_RAMP:
117 tprintf(", ramp={start_level=%" PRId16
118 ", end_level=%" PRId16,
119 ffe.u.ramp.start_level,
120 ffe.u.ramp.end_level);
121 decode_envelope(&ffe.u.ramp.envelope);
122 tprints("}");
123 break;
124 case FF_PERIODIC:
125 tprintf(", periodic={waveform=%" PRIu16
126 ", period=%" PRIu16
127 ", magnitude=%" PRId16
128 ", offset=%" PRId16
129 ", phase=%" PRIu16,
130 ffe.u.periodic.waveform,
131 ffe.u.periodic.period,
132 ffe.u.periodic.magnitude,
133 ffe.u.periodic.offset,
134 ffe.u.periodic.phase);
135 decode_envelope(&ffe.u.periodic.envelope);
Dmitry V. Levin484326d2016-06-11 01:28:21 +0000136 tprintf(", custom_len=%u, custom_data=",
137 ffe.u.periodic.custom_len);
138 printaddr((unsigned long) ffe.u.periodic.custom_data);
139 tprints("}");
Dmitry V. Levin3a45eb32016-05-27 00:41:02 +0000140 break;
141 case FF_RUMBLE:
142 tprintf(", rumble={strong_magnitude=%" PRIu16
143 ", weak_magnitude=%" PRIu16 "}",
144 ffe.u.rumble.strong_magnitude,
145 ffe.u.rumble.weak_magnitude);
146 break;
147 default:
148 break;
149 }
150
151 tprints("}");
152
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100153 return 1;
154}
155
156static int
157abs_ioctl(struct tcb *tcp, long arg)
158{
Dmitry V. Levine1670062016-05-27 00:41:14 +0000159 tprints(", ");
160
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100161 struct input_absinfo absinfo;
162
Dmitry V. Levine1670062016-05-27 00:41:14 +0000163 if (!umove_or_printaddr(tcp, arg, &absinfo)) {
164 tprintf("{value=%u"
165 ", minimum=%u, ",
166 absinfo.value,
167 absinfo.minimum);
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100168
Dmitry V. Levine1670062016-05-27 00:41:14 +0000169 if (!abbrev(tcp)) {
170 tprintf("maximum=%u"
171 ", fuzz=%u"
172 ", flat=%u",
173 absinfo.maximum,
174 absinfo.fuzz,
175 absinfo.flat);
Dmitry V. Levin8d85c232016-05-27 00:39:33 +0000176# ifdef HAVE_STRUCT_INPUT_ABSINFO_RESOLUTION
Dmitry V. Levine1670062016-05-27 00:41:14 +0000177 tprintf(", resolution=%u",
178 absinfo.resolution);
Dmitry V. Levin8d85c232016-05-27 00:39:33 +0000179# endif
Dmitry V. Levine1670062016-05-27 00:41:14 +0000180 } else {
181 tprints("...");
182 }
183
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100184 tprints("}");
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100185 }
Dmitry V. Levine1670062016-05-27 00:41:14 +0000186
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100187 return 1;
188}
189
190static int
191keycode_ioctl(struct tcb *tcp, long arg)
192{
Dmitry V. Levin7954e2a2016-05-27 00:41:25 +0000193 tprints(", ");
194
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100195 unsigned int keycode[2];
196
Dmitry V. Levin7954e2a2016-05-27 00:41:25 +0000197 if (!umove_or_printaddr(tcp, arg, &keycode)) {
198 tprintf("[%u, ", keycode[0]);
199 printxval(evdev_keycode, keycode[1], "KEY_???");
200 tprints("]");
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100201 }
202
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100203 return 1;
204}
205
Dmitry V. Levin8d85c232016-05-27 00:39:33 +0000206# ifdef EVIOCGKEYCODE_V2
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100207static int
208keycode_V2_ioctl(struct tcb *tcp, long arg)
209{
Dmitry V. Levin13f8e8f2016-05-27 00:41:34 +0000210 tprints(", ");
211
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100212 struct input_keymap_entry ike;
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100213
Dmitry V. Levin13f8e8f2016-05-27 00:41:34 +0000214 if (umove_or_printaddr(tcp, arg, &ike))
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100215 return 1;
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100216
Dmitry V. Levin13f8e8f2016-05-27 00:41:34 +0000217 tprintf("{flags=%" PRIu8
218 ", len=%" PRIu8 ", ",
219 ike.flags,
220 ike.len);
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100221
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100222 if (!abbrev(tcp)) {
Dmitry V. Levin7d8b41a2015-02-21 23:05:26 +0000223 unsigned int i;
224
Dmitry V. Levin13f8e8f2016-05-27 00:41:34 +0000225 tprintf("index=%" PRIu16 ", keycode=", ike.index);
Dmitry V. Levin7d8b41a2015-02-21 23:05:26 +0000226 printxval(evdev_keycode, ike.keycode, "KEY_???");
227 tprints(", scancode=[");
228 for (i = 0; i < ARRAY_SIZE(ike.scancode); i++) {
229 if (i > 0)
230 tprints(", ");
231 tprintf("%" PRIx8, ike.scancode[i]);
232 }
Dmitry V. Levin13f8e8f2016-05-27 00:41:34 +0000233 tprints("]");
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100234 } else {
Dmitry V. Levin13f8e8f2016-05-27 00:41:34 +0000235 tprints("...");
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100236 }
Dmitry V. Levin13f8e8f2016-05-27 00:41:34 +0000237
238 tprints("}");
239
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100240 return 1;
241}
Dmitry V. Levin8d85c232016-05-27 00:39:33 +0000242# endif /* EVIOCGKEYCODE_V2 */
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100243
244static int
245getid_ioctl(struct tcb *tcp, long arg)
246{
Dmitry V. Levine54f98a2016-05-27 00:41:43 +0000247 tprints(", ");
248
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100249 struct input_id id;
250
Dmitry V. Levine54f98a2016-05-27 00:41:43 +0000251 if (!umove_or_printaddr(tcp, arg, &id))
252 tprintf("{ID_BUS=%" PRIu16
253 ", ID_VENDOR=%" PRIu16
254 ", ID_PRODUCT=%" PRIu16
255 ", ID_VERSION=%" PRIu16 "}",
256 id.bustype,
257 id.vendor,
258 id.product,
259 id.version);
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100260
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100261 return 1;
262}
263
264static int
265decode_bitset(struct tcb *tcp, long arg, const struct xlat decode_nr[],
266 const unsigned int max_nr, const char *dflt)
267{
Dmitry V. Levin14a810e2016-05-27 00:41:51 +0000268 tprints(", ");
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100269
270 unsigned int size;
271 if ((unsigned long) tcp->u_rval > max_nr)
272 size = max_nr;
273 else
274 size = tcp->u_rval;
275 char decoded_arg[size];
276
Dmitry V. Levin14a810e2016-05-27 00:41:51 +0000277 if (umove_or_printaddr(tcp, arg, &decoded_arg))
278 return 1;
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100279
Dmitry V. Levin14a810e2016-05-27 00:41:51 +0000280 tprints("[");
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100281
282 int bit_displayed = 0;
283 int i = next_set_bit(decoded_arg, 0, size);
284 if (i < 0) {
285 tprints(" 0 ");
286 } else {
287 printxval(decode_nr, i, dflt);
288
289 while ((i = next_set_bit(decoded_arg, i + 1, size)) > 0) {
290 if (abbrev(tcp) && bit_displayed >= 3) {
291 tprints(", ...");
292 break;
293 }
294 tprints(", ");
295 printxval(decode_nr, i, dflt);
296 bit_displayed++;
297 }
298 }
299
300 tprints("]");
301
302 return 1;
303}
304
Dmitry V. Levin8d85c232016-05-27 00:39:33 +0000305# ifdef EVIOCGMTSLOTS
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100306static int
307mtslots_ioctl(struct tcb *tcp, const unsigned int code, long arg)
308{
Dmitry V. Levin563f0ce2016-05-27 00:41:59 +0000309 tprints(", ");
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100310
Dmitry V. Levin563f0ce2016-05-27 00:41:59 +0000311 const size_t size = _IOC_SIZE(code) / sizeof(int);
312 if (!size) {
313 printaddr(arg);
314 return 1;
315 }
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100316
Dmitry V. Levin563f0ce2016-05-27 00:41:59 +0000317 int buffer[size];
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100318
Dmitry V. Levin563f0ce2016-05-27 00:41:59 +0000319 if (umove_or_printaddr(tcp, arg, &buffer))
320 return 1;
321
322 tprints("{code=");
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100323 printxval(evdev_mtslots, buffer[0], "ABS_MT_???");
324
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100325 tprints(", values=[");
326
Dmitry V. Levin563f0ce2016-05-27 00:41:59 +0000327 unsigned int i;
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100328 for (i = 1; i < ARRAY_SIZE(buffer); i++)
329 tprintf("%s%d", i > 1 ? ", " : "", buffer[i]);
330
331 tprints("]}");
Dmitry V. Levin563f0ce2016-05-27 00:41:59 +0000332
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100333 return 1;
334}
Dmitry V. Levin8d85c232016-05-27 00:39:33 +0000335# endif /* EVIOCGMTSLOTS */
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100336
Dmitry V. Levin8d85c232016-05-27 00:39:33 +0000337# if defined EVIOCGREP || defined EVIOCSREP
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100338static int
339repeat_ioctl(struct tcb *tcp, long arg)
340{
Dmitry V. Levinb6795082015-07-06 22:33:39 +0000341 tprints(", ");
342 printpair_int(tcp, arg, "%u");
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100343 return 1;
344}
Dmitry V. Levin8d85c232016-05-27 00:39:33 +0000345# endif /* EVIOCGREP || EVIOCSREP */
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100346
347static int
Dmitry V. Levin53767d82016-05-27 00:40:18 +0000348bit_ioctl(struct tcb *tcp, const unsigned int ev_nr, const long arg)
349{
350 switch (ev_nr) {
351 case EV_SYN:
352 return decode_bitset(tcp, arg, evdev_sync,
Dmitry V. Levin3f23c0c2016-05-27 00:42:25 +0000353 SYN_MAX, "SYN_???");
Dmitry V. Levin53767d82016-05-27 00:40:18 +0000354 case EV_KEY:
355 return decode_bitset(tcp, arg, evdev_keycode,
Dmitry V. Levin3f23c0c2016-05-27 00:42:25 +0000356 KEY_MAX, "KEY_???");
Dmitry V. Levin53767d82016-05-27 00:40:18 +0000357 case EV_REL:
358 return decode_bitset(tcp, arg, evdev_relative_axes,
Dmitry V. Levin3f23c0c2016-05-27 00:42:25 +0000359 REL_MAX, "REL_???");
Dmitry V. Levin53767d82016-05-27 00:40:18 +0000360 case EV_ABS:
Dmitry V. Levin3f23c0c2016-05-27 00:42:25 +0000361 return decode_bitset(tcp, arg, evdev_abs,
362 ABS_MAX, "ABS_???");
Dmitry V. Levin53767d82016-05-27 00:40:18 +0000363 case EV_MSC:
Dmitry V. Levin3f23c0c2016-05-27 00:42:25 +0000364 return decode_bitset(tcp, arg, evdev_misc,
365 MSC_MAX, "MSC_???");
Dmitry V. Levin53767d82016-05-27 00:40:18 +0000366# ifdef EV_SW
367 case EV_SW:
Dmitry V. Levin3f23c0c2016-05-27 00:42:25 +0000368 return decode_bitset(tcp, arg, evdev_switch,
369 SW_MAX, "SW_???");
Dmitry V. Levin53767d82016-05-27 00:40:18 +0000370# endif
371 case EV_LED:
Dmitry V. Levin3f23c0c2016-05-27 00:42:25 +0000372 return decode_bitset(tcp, arg, evdev_leds,
373 LED_MAX, "LED_???");
Dmitry V. Levin53767d82016-05-27 00:40:18 +0000374 case EV_SND:
Dmitry V. Levin3f23c0c2016-05-27 00:42:25 +0000375 return decode_bitset(tcp, arg, evdev_snd,
376 SND_MAX, "SND_???");
Dmitry V. Levin53767d82016-05-27 00:40:18 +0000377 case EV_REP:
378 return decode_bitset(tcp, arg, evdev_autorepeat,
Dmitry V. Levin3f23c0c2016-05-27 00:42:25 +0000379 REP_MAX, "REP_???");
Dmitry V. Levin53767d82016-05-27 00:40:18 +0000380 case EV_FF:
381 return decode_bitset(tcp, arg, evdev_ff_types,
Dmitry V. Levin3f23c0c2016-05-27 00:42:25 +0000382 FF_MAX, "FF_???");
Dmitry V. Levin53767d82016-05-27 00:40:18 +0000383 case EV_PWR:
Dmitry V. Levin47be9f22016-05-28 00:12:01 +0000384 tprints(", ");
Dmitry V. Levin53767d82016-05-27 00:40:18 +0000385 printnum_int(tcp, arg, "%d");
386 return 1;
387 case EV_FF_STATUS:
388 return decode_bitset(tcp, arg, evdev_ff_status,
Dmitry V. Levin3f23c0c2016-05-27 00:42:25 +0000389 FF_STATUS_MAX, "FF_STATUS_???");
Dmitry V. Levin53767d82016-05-27 00:40:18 +0000390 default:
Dmitry V. Levinaa21c072016-05-28 00:49:17 +0000391 tprints(", ");
392 printaddr(arg);
393 return 1;
Dmitry V. Levin53767d82016-05-27 00:40:18 +0000394 }
395}
396
397static int
Dmitry V. Levin8a18f802016-05-27 00:40:10 +0000398evdev_read_ioctl(struct tcb *tcp, const unsigned int code, const long arg)
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100399{
Dmitry V. Levin8a18f802016-05-27 00:40:10 +0000400 /* fixed-number fixed-length commands */
401 switch (code) {
402 case EVIOCGVERSION:
403 tprints(", ");
Dmitry V. Levinb29569a2016-05-27 00:42:07 +0000404 printnum_int(tcp, arg, "%#x");
Dmitry V. Levin8a18f802016-05-27 00:40:10 +0000405 return 1;
406 case EVIOCGEFFECTS:
407 tprints(", ");
Dmitry V. Levin3f23c0c2016-05-27 00:42:25 +0000408 printnum_int(tcp, arg, "%u");
Dmitry V. Levin8a18f802016-05-27 00:40:10 +0000409 return 1;
410 case EVIOCGID:
411 return getid_ioctl(tcp, arg);
412# ifdef EVIOCGREP
413 case EVIOCGREP:
Dmitry V. Levin3f23c0c2016-05-27 00:42:25 +0000414 return repeat_ioctl(tcp, arg);
Dmitry V. Levin8a18f802016-05-27 00:40:10 +0000415# endif
416 case EVIOCGKEYCODE:
417 return keycode_ioctl(tcp, arg);
418# ifdef EVIOCGKEYCODE_V2
419 case EVIOCGKEYCODE_V2:
420 return keycode_V2_ioctl(tcp, arg);
421# endif
422 }
423
424 /* fixed-number variable-length commands */
425 switch (_IOC_NR(code)) {
426# ifdef EVIOCGMTSLOTS
427 case _IOC_NR(EVIOCGMTSLOTS(0)):
428 return mtslots_ioctl(tcp, code, arg);
429# endif
430 case _IOC_NR(EVIOCGNAME(0)):
431 case _IOC_NR(EVIOCGPHYS(0)):
432 case _IOC_NR(EVIOCGUNIQ(0)):
433 tprints(", ");
Dmitry V. Levin10de2eb2016-05-27 00:42:18 +0000434 if (syserror(tcp))
435 printaddr(arg);
436 else
437 printstr(tcp, arg, tcp->u_rval);
Dmitry V. Levin8a18f802016-05-27 00:40:10 +0000438 return 1;
439# ifdef EVIOCGPROP
440 case _IOC_NR(EVIOCGPROP(0)):
Dmitry V. Levin3f23c0c2016-05-27 00:42:25 +0000441 return decode_bitset(tcp, arg, evdev_prop,
442 INPUT_PROP_MAX, "PROP_???");
Dmitry V. Levin8a18f802016-05-27 00:40:10 +0000443# endif
444 case _IOC_NR(EVIOCGSND(0)):
Dmitry V. Levin3f23c0c2016-05-27 00:42:25 +0000445 return decode_bitset(tcp, arg, evdev_snd,
446 SND_MAX, "SND_???");
Dmitry V. Levin8a18f802016-05-27 00:40:10 +0000447# ifdef EVIOCGSW
448 case _IOC_NR(EVIOCGSW(0)):
Dmitry V. Levin3f23c0c2016-05-27 00:42:25 +0000449 return decode_bitset(tcp, arg, evdev_switch,
450 SW_MAX, "SW_???");
Dmitry V. Levin8a18f802016-05-27 00:40:10 +0000451# endif
452 case _IOC_NR(EVIOCGKEY(0)):
Dmitry V. Levin3f23c0c2016-05-27 00:42:25 +0000453 return decode_bitset(tcp, arg, evdev_keycode,
454 KEY_MAX, "KEY_???");
Dmitry V. Levin8a18f802016-05-27 00:40:10 +0000455 case _IOC_NR(EVIOCGLED(0)):
Dmitry V. Levin3f23c0c2016-05-27 00:42:25 +0000456 return decode_bitset(tcp, arg, evdev_leds,
457 LED_MAX, "LED_???");
Dmitry V. Levin8a18f802016-05-27 00:40:10 +0000458 }
459
460 /* multi-number fixed-length commands */
461 if ((_IOC_NR(code) & ~ABS_MAX) == _IOC_NR(EVIOCGABS(0)))
462 return abs_ioctl(tcp, arg);
463
464 /* multi-number variable-length commands */
Dmitry V. Levin53767d82016-05-27 00:40:18 +0000465 if ((_IOC_NR(code) & ~EV_MAX) == _IOC_NR(EVIOCGBIT(0, 0)))
466 return bit_ioctl(tcp, _IOC_NR(code) & EV_MAX, arg);
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100467
Dmitry V. Levin8a18f802016-05-27 00:40:10 +0000468 return 0;
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100469}
470
471static int
Dmitry V. Levin8a18f802016-05-27 00:40:10 +0000472evdev_write_ioctl(struct tcb *tcp, const unsigned int code, const long arg)
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100473{
Dmitry V. Levin8a18f802016-05-27 00:40:10 +0000474 /* fixed-number fixed-length commands */
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100475 switch (code) {
Dmitry V. Levin8d85c232016-05-27 00:39:33 +0000476# ifdef EVIOCSREP
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100477 case EVIOCSREP:
478 return repeat_ioctl(tcp, arg);
Dmitry V. Levin8d85c232016-05-27 00:39:33 +0000479# endif
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100480 case EVIOCSKEYCODE:
481 return keycode_ioctl(tcp, arg);
Dmitry V. Levin8d85c232016-05-27 00:39:33 +0000482# ifdef EVIOCSKEYCODE_V2
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100483 case EVIOCSKEYCODE_V2:
484 return keycode_V2_ioctl(tcp, arg);
Dmitry V. Levin8d85c232016-05-27 00:39:33 +0000485# endif
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100486 case EVIOCSFF:
487 return ff_effect_ioctl(tcp, arg);
488 case EVIOCRMFF:
Dmitry V. Levin00394242016-05-27 00:40:27 +0000489 tprintf(", %d", (int) arg);
490 return 1;
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100491 case EVIOCGRAB:
Dmitry V. Levin8d85c232016-05-27 00:39:33 +0000492# ifdef EVIOCREVOKE
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100493 case EVIOCREVOKE:
Dmitry V. Levin8d85c232016-05-27 00:39:33 +0000494# endif
Dmitry V. Levin9635df42016-05-27 00:40:45 +0000495 tprintf(", %lu", arg);
496 return 1;
497# ifdef EVIOCSCLOCKID
498 case EVIOCSCLOCKID:
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100499 tprints(", ");
500 printnum_int(tcp, arg, "%u");
501 return 1;
Dmitry V. Levin9635df42016-05-27 00:40:45 +0000502# endif
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100503 }
Dmitry V. Levin8a18f802016-05-27 00:40:10 +0000504
505 /* multi-number fixed-length commands */
506 if ((_IOC_NR(code) & ~ABS_MAX) == _IOC_NR(EVIOCSABS(0)))
507 return abs_ioctl(tcp, arg);
508
509 return 0;
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100510}
511
Dmitry V. Levin43c8a5d2016-05-27 00:49:08 +0000512MPERS_PRINTER_DECL(int, evdev_ioctl, struct tcb *tcp,
513 const unsigned int code, const long arg)
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100514{
515 switch(_IOC_DIR(code)) {
516 case _IOC_READ:
Dmitry V. Levin2114e082016-05-27 00:40:02 +0000517 if (entering(tcp))
518 return 0;
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100519 return evdev_read_ioctl(tcp, code, arg);
520 case _IOC_WRITE:
Dmitry V. Levin2114e082016-05-27 00:40:02 +0000521 return evdev_write_ioctl(tcp, code, arg) | RVAL_DECODED;
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100522 default:
Dmitry V. Levin2114e082016-05-27 00:40:02 +0000523 return RVAL_DECODED;
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100524 }
525}
526
527#endif /* HAVE_LINUX_INPUT_H */