blob: 5642e0d7ba466d5d729b50b7f88ecb3c062f7118 [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>
Elliott Hughes77c3ff82017-09-08 17:11:00 -07004 * Copyright (c) 2015-2017 The strace developers.
Etienne Gemsa4f750b92015-02-20 17:14:10 +01005 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30#include "defs.h"
31
32#ifdef HAVE_LINUX_INPUT_H
Etienne Gemsa4f750b92015-02-20 17:14:10 +010033
Dmitry V. Levin43c8a5d2016-05-27 00:49:08 +000034#include DEF_MPERS_TYPE(struct_ff_effect)
35
Dmitry V. Levin8d85c232016-05-27 00:39:33 +000036# include <linux/ioctl.h>
37# include <linux/input.h>
Dmitry V. Levin43c8a5d2016-05-27 00:49:08 +000038
39typedef struct ff_effect struct_ff_effect;
40
Dmitry V. Levin7af5e652016-08-15 21:08:16 +000041#endif /* HAVE_LINUX_INPUT_H */
Dmitry V. Levin43c8a5d2016-05-27 00:49:08 +000042
43#include MPERS_DEFS
44
45#ifdef HAVE_LINUX_INPUT_H
46
Dmitry V. Levin8d85c232016-05-27 00:39:33 +000047# include "xlat/evdev_autorepeat.h"
48# include "xlat/evdev_ff_status.h"
49# include "xlat/evdev_ff_types.h"
50# include "xlat/evdev_keycode.h"
51# include "xlat/evdev_leds.h"
52# include "xlat/evdev_misc.h"
53# include "xlat/evdev_mtslots.h"
54# include "xlat/evdev_prop.h"
55# include "xlat/evdev_relative_axes.h"
56# include "xlat/evdev_snd.h"
57# include "xlat/evdev_switch.h"
58# include "xlat/evdev_sync.h"
59
60# ifndef SYN_MAX
61# define SYN_MAX 0xf
62# endif
Dmitry V. Levin19dadf92015-02-22 02:50:33 +030063
Etienne Gemsa4f750b92015-02-20 17:14:10 +010064static void
Dmitry V. Levin43c8a5d2016-05-27 00:49:08 +000065decode_envelope(void *const data)
Etienne Gemsa4f750b92015-02-20 17:14:10 +010066{
Dmitry V. Levin43c8a5d2016-05-27 00:49:08 +000067 const struct ff_envelope *const envelope = data;
68
Dmitry V. Levinc758ed02016-05-27 00:40:53 +000069 tprintf(", envelope={attack_length=%" PRIu16
70 ", attack_level=%" PRIu16
71 ", fade_length=%" PRIu16
72 ", fade_level=%#x}",
Etienne Gemsa4f750b92015-02-20 17:14:10 +010073 envelope->attack_length,
74 envelope->attack_level,
75 envelope->fade_length,
76 envelope->fade_level);
77}
78
79static int
Elliott Hughesd35df492017-02-15 15:19:05 -080080ff_effect_ioctl(struct tcb *const tcp, const kernel_ulong_t arg)
Etienne Gemsa4f750b92015-02-20 17:14:10 +010081{
Dmitry V. Levin3a45eb32016-05-27 00:41:02 +000082 tprints(", ");
83
Dmitry V. Levin43c8a5d2016-05-27 00:49:08 +000084 struct_ff_effect ffe;
Etienne Gemsa4f750b92015-02-20 17:14:10 +010085
Dmitry V. Levin3a45eb32016-05-27 00:41:02 +000086 if (umove_or_printaddr(tcp, arg, &ffe))
Elliott Hughes77c3ff82017-09-08 17:11:00 -070087 return RVAL_IOCTL_DECODED;
Etienne Gemsa4f750b92015-02-20 17:14:10 +010088
Dmitry V. Levin3a45eb32016-05-27 00:41:02 +000089 tprints("{type=");
Etienne Gemsa4f750b92015-02-20 17:14:10 +010090 printxval(evdev_ff_types, ffe.type, "FF_???");
Dmitry V. Levin3a45eb32016-05-27 00:41:02 +000091 tprintf(", id=%" PRIu16
92 ", direction=%" PRIu16 ", ",
93 ffe.id,
94 ffe.direction);
Etienne Gemsa4f750b92015-02-20 17:14:10 +010095
Dmitry V. Levin3a45eb32016-05-27 00:41:02 +000096 if (abbrev(tcp)) {
97 tprints("...}");
Elliott Hughes77c3ff82017-09-08 17:11:00 -070098 return RVAL_IOCTL_DECODED;
Etienne Gemsa4f750b92015-02-20 17:14:10 +010099 }
100
Dmitry V. Levin3a45eb32016-05-27 00:41:02 +0000101 tprintf("trigger={button=%" PRIu16
102 ", interval=%" PRIu16 "}"
103 ", replay={length=%" PRIu16
104 ", delay=%" PRIu16 "}",
105 ffe.trigger.button,
106 ffe.trigger.interval,
107 ffe.replay.length,
108 ffe.replay.delay);
109
110 switch (ffe.type) {
111 case FF_CONSTANT:
112 tprintf(", constant={level=%" PRId16,
113 ffe.u.constant.level);
114 decode_envelope(&ffe.u.constant.envelope);
115 tprints("}");
116 break;
117 case FF_RAMP:
118 tprintf(", ramp={start_level=%" PRId16
119 ", end_level=%" PRId16,
120 ffe.u.ramp.start_level,
121 ffe.u.ramp.end_level);
122 decode_envelope(&ffe.u.ramp.envelope);
123 tprints("}");
124 break;
125 case FF_PERIODIC:
126 tprintf(", periodic={waveform=%" PRIu16
127 ", period=%" PRIu16
128 ", magnitude=%" PRId16
129 ", offset=%" PRId16
130 ", phase=%" PRIu16,
131 ffe.u.periodic.waveform,
132 ffe.u.periodic.period,
133 ffe.u.periodic.magnitude,
134 ffe.u.periodic.offset,
135 ffe.u.periodic.phase);
136 decode_envelope(&ffe.u.periodic.envelope);
Dmitry V. Levin484326d2016-06-11 01:28:21 +0000137 tprintf(", custom_len=%u, custom_data=",
138 ffe.u.periodic.custom_len);
Elliott Hughesd35df492017-02-15 15:19:05 -0800139 printaddr(ptr_to_kulong(ffe.u.periodic.custom_data));
Dmitry V. Levin484326d2016-06-11 01:28:21 +0000140 tprints("}");
Dmitry V. Levin3a45eb32016-05-27 00:41:02 +0000141 break;
142 case FF_RUMBLE:
143 tprintf(", rumble={strong_magnitude=%" PRIu16
144 ", weak_magnitude=%" PRIu16 "}",
145 ffe.u.rumble.strong_magnitude,
146 ffe.u.rumble.weak_magnitude);
147 break;
148 default:
149 break;
150 }
151
152 tprints("}");
153
Elliott Hughes77c3ff82017-09-08 17:11:00 -0700154 return RVAL_IOCTL_DECODED;
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100155}
156
157static int
Elliott Hughesd35df492017-02-15 15:19:05 -0800158abs_ioctl(struct tcb *const tcp, const kernel_ulong_t arg)
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100159{
Dmitry V. Levine1670062016-05-27 00:41:14 +0000160 tprints(", ");
161
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100162 struct input_absinfo absinfo;
163
Dmitry V. Levine1670062016-05-27 00:41:14 +0000164 if (!umove_or_printaddr(tcp, arg, &absinfo)) {
165 tprintf("{value=%u"
166 ", minimum=%u, ",
167 absinfo.value,
168 absinfo.minimum);
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100169
Dmitry V. Levine1670062016-05-27 00:41:14 +0000170 if (!abbrev(tcp)) {
171 tprintf("maximum=%u"
172 ", fuzz=%u"
173 ", flat=%u",
174 absinfo.maximum,
175 absinfo.fuzz,
176 absinfo.flat);
Dmitry V. Levin8d85c232016-05-27 00:39:33 +0000177# ifdef HAVE_STRUCT_INPUT_ABSINFO_RESOLUTION
Dmitry V. Levine1670062016-05-27 00:41:14 +0000178 tprintf(", resolution=%u",
179 absinfo.resolution);
Dmitry V. Levin8d85c232016-05-27 00:39:33 +0000180# endif
Dmitry V. Levine1670062016-05-27 00:41:14 +0000181 } else {
182 tprints("...");
183 }
184
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100185 tprints("}");
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100186 }
Dmitry V. Levine1670062016-05-27 00:41:14 +0000187
Elliott Hughes77c3ff82017-09-08 17:11:00 -0700188 return RVAL_IOCTL_DECODED;
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100189}
190
191static int
Elliott Hughesd35df492017-02-15 15:19:05 -0800192keycode_ioctl(struct tcb *const tcp, const kernel_ulong_t arg)
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100193{
Dmitry V. Levin7954e2a2016-05-27 00:41:25 +0000194 tprints(", ");
195
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100196 unsigned int keycode[2];
197
Dmitry V. Levin7954e2a2016-05-27 00:41:25 +0000198 if (!umove_or_printaddr(tcp, arg, &keycode)) {
199 tprintf("[%u, ", keycode[0]);
200 printxval(evdev_keycode, keycode[1], "KEY_???");
201 tprints("]");
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100202 }
203
Elliott Hughes77c3ff82017-09-08 17:11:00 -0700204 return RVAL_IOCTL_DECODED;
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100205}
206
Dmitry V. Levin8d85c232016-05-27 00:39:33 +0000207# ifdef EVIOCGKEYCODE_V2
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100208static int
Elliott Hughesd35df492017-02-15 15:19:05 -0800209keycode_V2_ioctl(struct tcb *const tcp, const kernel_ulong_t arg)
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100210{
Dmitry V. Levin13f8e8f2016-05-27 00:41:34 +0000211 tprints(", ");
212
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100213 struct input_keymap_entry ike;
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100214
Dmitry V. Levin13f8e8f2016-05-27 00:41:34 +0000215 if (umove_or_printaddr(tcp, arg, &ike))
Elliott Hughes77c3ff82017-09-08 17:11:00 -0700216 return RVAL_IOCTL_DECODED;
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100217
Dmitry V. Levin13f8e8f2016-05-27 00:41:34 +0000218 tprintf("{flags=%" PRIu8
219 ", len=%" PRIu8 ", ",
220 ike.flags,
221 ike.len);
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100222
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100223 if (!abbrev(tcp)) {
Dmitry V. Levin7d8b41a2015-02-21 23:05:26 +0000224 unsigned int i;
225
Dmitry V. Levin13f8e8f2016-05-27 00:41:34 +0000226 tprintf("index=%" PRIu16 ", keycode=", ike.index);
Dmitry V. Levin7d8b41a2015-02-21 23:05:26 +0000227 printxval(evdev_keycode, ike.keycode, "KEY_???");
228 tprints(", scancode=[");
229 for (i = 0; i < ARRAY_SIZE(ike.scancode); i++) {
230 if (i > 0)
231 tprints(", ");
232 tprintf("%" PRIx8, ike.scancode[i]);
233 }
Dmitry V. Levin13f8e8f2016-05-27 00:41:34 +0000234 tprints("]");
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100235 } else {
Dmitry V. Levin13f8e8f2016-05-27 00:41:34 +0000236 tprints("...");
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100237 }
Dmitry V. Levin13f8e8f2016-05-27 00:41:34 +0000238
239 tprints("}");
240
Elliott Hughes77c3ff82017-09-08 17:11:00 -0700241 return RVAL_IOCTL_DECODED;
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100242}
Dmitry V. Levin8d85c232016-05-27 00:39:33 +0000243# endif /* EVIOCGKEYCODE_V2 */
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100244
245static int
Elliott Hughesd35df492017-02-15 15:19:05 -0800246getid_ioctl(struct tcb *const tcp, const kernel_ulong_t arg)
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100247{
Dmitry V. Levine54f98a2016-05-27 00:41:43 +0000248 tprints(", ");
249
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100250 struct input_id id;
251
Dmitry V. Levine54f98a2016-05-27 00:41:43 +0000252 if (!umove_or_printaddr(tcp, arg, &id))
253 tprintf("{ID_BUS=%" PRIu16
254 ", ID_VENDOR=%" PRIu16
255 ", ID_PRODUCT=%" PRIu16
256 ", ID_VERSION=%" PRIu16 "}",
257 id.bustype,
258 id.vendor,
259 id.product,
260 id.version);
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100261
Elliott Hughes77c3ff82017-09-08 17:11:00 -0700262 return RVAL_IOCTL_DECODED;
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100263}
264
265static int
Elliott Hughesd35df492017-02-15 15:19:05 -0800266decode_bitset(struct tcb *const tcp, const kernel_ulong_t arg,
267 const struct xlat decode_nr[], const unsigned int max_nr,
268 const char *const dflt)
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100269{
Dmitry V. Levin14a810e2016-05-27 00:41:51 +0000270 tprints(", ");
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100271
272 unsigned int size;
Elliott Hughesd35df492017-02-15 15:19:05 -0800273 if ((kernel_ulong_t) tcp->u_rval > max_nr)
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100274 size = max_nr;
275 else
276 size = tcp->u_rval;
277 char decoded_arg[size];
278
Dmitry V. Levin14a810e2016-05-27 00:41:51 +0000279 if (umove_or_printaddr(tcp, arg, &decoded_arg))
Elliott Hughes77c3ff82017-09-08 17:11:00 -0700280 return RVAL_IOCTL_DECODED;
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100281
Dmitry V. Levin14a810e2016-05-27 00:41:51 +0000282 tprints("[");
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100283
284 int bit_displayed = 0;
285 int i = next_set_bit(decoded_arg, 0, size);
286 if (i < 0) {
287 tprints(" 0 ");
288 } else {
289 printxval(decode_nr, i, dflt);
290
291 while ((i = next_set_bit(decoded_arg, i + 1, size)) > 0) {
292 if (abbrev(tcp) && bit_displayed >= 3) {
293 tprints(", ...");
294 break;
295 }
296 tprints(", ");
297 printxval(decode_nr, i, dflt);
298 bit_displayed++;
299 }
300 }
301
302 tprints("]");
303
Elliott Hughes77c3ff82017-09-08 17:11:00 -0700304 return RVAL_IOCTL_DECODED;
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100305}
306
Dmitry V. Levin8d85c232016-05-27 00:39:33 +0000307# ifdef EVIOCGMTSLOTS
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100308static int
Elliott Hughesd35df492017-02-15 15:19:05 -0800309mtslots_ioctl(struct tcb *const tcp, const unsigned int code,
310 const kernel_ulong_t arg)
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100311{
Dmitry V. Levin563f0ce2016-05-27 00:41:59 +0000312 tprints(", ");
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100313
Dmitry V. Levin563f0ce2016-05-27 00:41:59 +0000314 const size_t size = _IOC_SIZE(code) / sizeof(int);
315 if (!size) {
316 printaddr(arg);
Elliott Hughes77c3ff82017-09-08 17:11:00 -0700317 return RVAL_IOCTL_DECODED;
Dmitry V. Levin563f0ce2016-05-27 00:41:59 +0000318 }
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100319
Dmitry V. Levin563f0ce2016-05-27 00:41:59 +0000320 int buffer[size];
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100321
Dmitry V. Levin563f0ce2016-05-27 00:41:59 +0000322 if (umove_or_printaddr(tcp, arg, &buffer))
Elliott Hughes77c3ff82017-09-08 17:11:00 -0700323 return RVAL_IOCTL_DECODED;
Dmitry V. Levin563f0ce2016-05-27 00:41:59 +0000324
325 tprints("{code=");
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100326 printxval(evdev_mtslots, buffer[0], "ABS_MT_???");
327
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100328 tprints(", values=[");
329
Dmitry V. Levin563f0ce2016-05-27 00:41:59 +0000330 unsigned int i;
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100331 for (i = 1; i < ARRAY_SIZE(buffer); i++)
332 tprintf("%s%d", i > 1 ? ", " : "", buffer[i]);
333
334 tprints("]}");
Dmitry V. Levin563f0ce2016-05-27 00:41:59 +0000335
Elliott Hughes77c3ff82017-09-08 17:11:00 -0700336 return RVAL_IOCTL_DECODED;
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100337}
Dmitry V. Levin8d85c232016-05-27 00:39:33 +0000338# endif /* EVIOCGMTSLOTS */
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100339
Dmitry V. Levin8d85c232016-05-27 00:39:33 +0000340# if defined EVIOCGREP || defined EVIOCSREP
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100341static int
Elliott Hughesd35df492017-02-15 15:19:05 -0800342repeat_ioctl(struct tcb *const tcp, const kernel_ulong_t arg)
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100343{
Dmitry V. Levinb6795082015-07-06 22:33:39 +0000344 tprints(", ");
345 printpair_int(tcp, arg, "%u");
Elliott Hughes77c3ff82017-09-08 17:11:00 -0700346 return RVAL_IOCTL_DECODED;
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100347}
Dmitry V. Levin8d85c232016-05-27 00:39:33 +0000348# endif /* EVIOCGREP || EVIOCSREP */
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100349
350static int
Elliott Hughesd35df492017-02-15 15:19:05 -0800351bit_ioctl(struct tcb *const tcp, const unsigned int ev_nr,
352 const kernel_ulong_t arg)
Dmitry V. Levin53767d82016-05-27 00:40:18 +0000353{
354 switch (ev_nr) {
355 case EV_SYN:
356 return decode_bitset(tcp, arg, evdev_sync,
Dmitry V. Levin3f23c0c2016-05-27 00:42:25 +0000357 SYN_MAX, "SYN_???");
Dmitry V. Levin53767d82016-05-27 00:40:18 +0000358 case EV_KEY:
359 return decode_bitset(tcp, arg, evdev_keycode,
Dmitry V. Levin3f23c0c2016-05-27 00:42:25 +0000360 KEY_MAX, "KEY_???");
Dmitry V. Levin53767d82016-05-27 00:40:18 +0000361 case EV_REL:
362 return decode_bitset(tcp, arg, evdev_relative_axes,
Dmitry V. Levin3f23c0c2016-05-27 00:42:25 +0000363 REL_MAX, "REL_???");
Dmitry V. Levin53767d82016-05-27 00:40:18 +0000364 case EV_ABS:
Dmitry V. Levin3f23c0c2016-05-27 00:42:25 +0000365 return decode_bitset(tcp, arg, evdev_abs,
366 ABS_MAX, "ABS_???");
Dmitry V. Levin53767d82016-05-27 00:40:18 +0000367 case EV_MSC:
Dmitry V. Levin3f23c0c2016-05-27 00:42:25 +0000368 return decode_bitset(tcp, arg, evdev_misc,
369 MSC_MAX, "MSC_???");
Dmitry V. Levin53767d82016-05-27 00:40:18 +0000370# ifdef EV_SW
371 case EV_SW:
Dmitry V. Levin3f23c0c2016-05-27 00:42:25 +0000372 return decode_bitset(tcp, arg, evdev_switch,
373 SW_MAX, "SW_???");
Dmitry V. Levin53767d82016-05-27 00:40:18 +0000374# endif
375 case EV_LED:
Dmitry V. Levin3f23c0c2016-05-27 00:42:25 +0000376 return decode_bitset(tcp, arg, evdev_leds,
377 LED_MAX, "LED_???");
Dmitry V. Levin53767d82016-05-27 00:40:18 +0000378 case EV_SND:
Dmitry V. Levin3f23c0c2016-05-27 00:42:25 +0000379 return decode_bitset(tcp, arg, evdev_snd,
380 SND_MAX, "SND_???");
Dmitry V. Levin53767d82016-05-27 00:40:18 +0000381 case EV_REP:
382 return decode_bitset(tcp, arg, evdev_autorepeat,
Dmitry V. Levin3f23c0c2016-05-27 00:42:25 +0000383 REP_MAX, "REP_???");
Dmitry V. Levin53767d82016-05-27 00:40:18 +0000384 case EV_FF:
385 return decode_bitset(tcp, arg, evdev_ff_types,
Dmitry V. Levin3f23c0c2016-05-27 00:42:25 +0000386 FF_MAX, "FF_???");
Dmitry V. Levin53767d82016-05-27 00:40:18 +0000387 case EV_PWR:
Dmitry V. Levin47be9f22016-05-28 00:12:01 +0000388 tprints(", ");
Dmitry V. Levin53767d82016-05-27 00:40:18 +0000389 printnum_int(tcp, arg, "%d");
Elliott Hughes77c3ff82017-09-08 17:11:00 -0700390 return RVAL_IOCTL_DECODED;
Dmitry V. Levin53767d82016-05-27 00:40:18 +0000391 case EV_FF_STATUS:
392 return decode_bitset(tcp, arg, evdev_ff_status,
Dmitry V. Levin3f23c0c2016-05-27 00:42:25 +0000393 FF_STATUS_MAX, "FF_STATUS_???");
Dmitry V. Levin53767d82016-05-27 00:40:18 +0000394 default:
Dmitry V. Levinaa21c072016-05-28 00:49:17 +0000395 tprints(", ");
396 printaddr(arg);
Elliott Hughes77c3ff82017-09-08 17:11:00 -0700397 return RVAL_IOCTL_DECODED;
Dmitry V. Levin53767d82016-05-27 00:40:18 +0000398 }
399}
400
401static int
Elliott Hughesd35df492017-02-15 15:19:05 -0800402evdev_read_ioctl(struct tcb *const tcp, const unsigned int code,
403 const kernel_ulong_t arg)
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100404{
Dmitry V. Levin8a18f802016-05-27 00:40:10 +0000405 /* fixed-number fixed-length commands */
406 switch (code) {
407 case EVIOCGVERSION:
408 tprints(", ");
Dmitry V. Levinb29569a2016-05-27 00:42:07 +0000409 printnum_int(tcp, arg, "%#x");
Elliott Hughes77c3ff82017-09-08 17:11:00 -0700410 return RVAL_IOCTL_DECODED;
Dmitry V. Levin8a18f802016-05-27 00:40:10 +0000411 case EVIOCGEFFECTS:
412 tprints(", ");
Dmitry V. Levin3f23c0c2016-05-27 00:42:25 +0000413 printnum_int(tcp, arg, "%u");
Elliott Hughes77c3ff82017-09-08 17:11:00 -0700414 return RVAL_IOCTL_DECODED;
Dmitry V. Levin8a18f802016-05-27 00:40:10 +0000415 case EVIOCGID:
416 return getid_ioctl(tcp, arg);
417# ifdef EVIOCGREP
418 case EVIOCGREP:
Dmitry V. Levin3f23c0c2016-05-27 00:42:25 +0000419 return repeat_ioctl(tcp, arg);
Dmitry V. Levin8a18f802016-05-27 00:40:10 +0000420# endif
421 case EVIOCGKEYCODE:
422 return keycode_ioctl(tcp, arg);
423# ifdef EVIOCGKEYCODE_V2
424 case EVIOCGKEYCODE_V2:
425 return keycode_V2_ioctl(tcp, arg);
426# endif
427 }
428
429 /* fixed-number variable-length commands */
430 switch (_IOC_NR(code)) {
431# ifdef EVIOCGMTSLOTS
432 case _IOC_NR(EVIOCGMTSLOTS(0)):
433 return mtslots_ioctl(tcp, code, arg);
434# endif
435 case _IOC_NR(EVIOCGNAME(0)):
436 case _IOC_NR(EVIOCGPHYS(0)):
437 case _IOC_NR(EVIOCGUNIQ(0)):
438 tprints(", ");
Dmitry V. Levin10de2eb2016-05-27 00:42:18 +0000439 if (syserror(tcp))
440 printaddr(arg);
441 else
Elliott Hughesd35df492017-02-15 15:19:05 -0800442 printstrn(tcp, arg, tcp->u_rval);
Elliott Hughes77c3ff82017-09-08 17:11:00 -0700443 return RVAL_IOCTL_DECODED;
Dmitry V. Levin8a18f802016-05-27 00:40:10 +0000444# ifdef EVIOCGPROP
445 case _IOC_NR(EVIOCGPROP(0)):
Dmitry V. Levin3f23c0c2016-05-27 00:42:25 +0000446 return decode_bitset(tcp, arg, evdev_prop,
447 INPUT_PROP_MAX, "PROP_???");
Dmitry V. Levin8a18f802016-05-27 00:40:10 +0000448# endif
449 case _IOC_NR(EVIOCGSND(0)):
Dmitry V. Levin3f23c0c2016-05-27 00:42:25 +0000450 return decode_bitset(tcp, arg, evdev_snd,
451 SND_MAX, "SND_???");
Dmitry V. Levin8a18f802016-05-27 00:40:10 +0000452# ifdef EVIOCGSW
453 case _IOC_NR(EVIOCGSW(0)):
Dmitry V. Levin3f23c0c2016-05-27 00:42:25 +0000454 return decode_bitset(tcp, arg, evdev_switch,
455 SW_MAX, "SW_???");
Dmitry V. Levin8a18f802016-05-27 00:40:10 +0000456# endif
457 case _IOC_NR(EVIOCGKEY(0)):
Dmitry V. Levin3f23c0c2016-05-27 00:42:25 +0000458 return decode_bitset(tcp, arg, evdev_keycode,
459 KEY_MAX, "KEY_???");
Dmitry V. Levin8a18f802016-05-27 00:40:10 +0000460 case _IOC_NR(EVIOCGLED(0)):
Dmitry V. Levin3f23c0c2016-05-27 00:42:25 +0000461 return decode_bitset(tcp, arg, evdev_leds,
462 LED_MAX, "LED_???");
Dmitry V. Levin8a18f802016-05-27 00:40:10 +0000463 }
464
465 /* multi-number fixed-length commands */
466 if ((_IOC_NR(code) & ~ABS_MAX) == _IOC_NR(EVIOCGABS(0)))
467 return abs_ioctl(tcp, arg);
468
469 /* multi-number variable-length commands */
Dmitry V. Levin53767d82016-05-27 00:40:18 +0000470 if ((_IOC_NR(code) & ~EV_MAX) == _IOC_NR(EVIOCGBIT(0, 0)))
471 return bit_ioctl(tcp, _IOC_NR(code) & EV_MAX, arg);
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100472
Dmitry V. Levin8a18f802016-05-27 00:40:10 +0000473 return 0;
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100474}
475
476static int
Elliott Hughesd35df492017-02-15 15:19:05 -0800477evdev_write_ioctl(struct tcb *const tcp, const unsigned int code,
478 const kernel_ulong_t arg)
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100479{
Dmitry V. Levin8a18f802016-05-27 00:40:10 +0000480 /* fixed-number fixed-length commands */
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100481 switch (code) {
Dmitry V. Levin8d85c232016-05-27 00:39:33 +0000482# ifdef EVIOCSREP
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100483 case EVIOCSREP:
484 return repeat_ioctl(tcp, arg);
Dmitry V. Levin8d85c232016-05-27 00:39:33 +0000485# endif
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100486 case EVIOCSKEYCODE:
487 return keycode_ioctl(tcp, arg);
Dmitry V. Levin8d85c232016-05-27 00:39:33 +0000488# ifdef EVIOCSKEYCODE_V2
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100489 case EVIOCSKEYCODE_V2:
490 return keycode_V2_ioctl(tcp, arg);
Dmitry V. Levin8d85c232016-05-27 00:39:33 +0000491# endif
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100492 case EVIOCSFF:
493 return ff_effect_ioctl(tcp, arg);
494 case EVIOCRMFF:
Dmitry V. Levin00394242016-05-27 00:40:27 +0000495 tprintf(", %d", (int) arg);
Elliott Hughes77c3ff82017-09-08 17:11:00 -0700496 return RVAL_IOCTL_DECODED;
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100497 case EVIOCGRAB:
Dmitry V. Levin8d85c232016-05-27 00:39:33 +0000498# ifdef EVIOCREVOKE
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100499 case EVIOCREVOKE:
Dmitry V. Levin8d85c232016-05-27 00:39:33 +0000500# endif
Elliott Hughesd35df492017-02-15 15:19:05 -0800501 tprintf(", %" PRI_klu, arg);
Elliott Hughes77c3ff82017-09-08 17:11:00 -0700502 return RVAL_IOCTL_DECODED;
Dmitry V. Levin9635df42016-05-27 00:40:45 +0000503# ifdef EVIOCSCLOCKID
504 case EVIOCSCLOCKID:
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100505 tprints(", ");
506 printnum_int(tcp, arg, "%u");
Elliott Hughes77c3ff82017-09-08 17:11:00 -0700507 return RVAL_IOCTL_DECODED;
Dmitry V. Levin9635df42016-05-27 00:40:45 +0000508# endif
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100509 }
Dmitry V. Levin8a18f802016-05-27 00:40:10 +0000510
511 /* multi-number fixed-length commands */
512 if ((_IOC_NR(code) & ~ABS_MAX) == _IOC_NR(EVIOCSABS(0)))
513 return abs_ioctl(tcp, arg);
514
515 return 0;
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100516}
517
Elliott Hughesd35df492017-02-15 15:19:05 -0800518MPERS_PRINTER_DECL(int, evdev_ioctl, struct tcb *const tcp,
519 const unsigned int code, const kernel_ulong_t arg)
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100520{
Elliott Hughesdc75b012017-07-05 13:54:44 -0700521 switch (_IOC_DIR(code)) {
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100522 case _IOC_READ:
Dmitry V. Levin2114e082016-05-27 00:40:02 +0000523 if (entering(tcp))
524 return 0;
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100525 return evdev_read_ioctl(tcp, code, arg);
526 case _IOC_WRITE:
Dmitry V. Levin2114e082016-05-27 00:40:02 +0000527 return evdev_write_ioctl(tcp, code, arg) | RVAL_DECODED;
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100528 default:
Dmitry V. Levin2114e082016-05-27 00:40:02 +0000529 return RVAL_DECODED;
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100530 }
531}
532
533#endif /* HAVE_LINUX_INPUT_H */