2 * Copyright (c) 2015 Etienne Gemsa <etienne.gemsa@lse.epita.fr>
3 * Copyright (c) 2015 Dmitry V. Levin <ldv@altlinux.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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.
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.
31 #ifdef HAVE_LINUX_INPUT_H
32 #include <linux/input.h>
33 #include "xlat/evdev_abs.h"
34 #include "xlat/evdev_autorepeat.h"
35 #include "xlat/evdev_ff_status.h"
36 #include "xlat/evdev_ff_types.h"
37 #include "xlat/evdev_keycode.h"
38 #include "xlat/evdev_leds.h"
39 #include "xlat/evdev_misc.h"
40 #include "xlat/evdev_mtslots.h"
41 #include "xlat/evdev_prop.h"
42 #include "xlat/evdev_relative_axes.h"
43 #include "xlat/evdev_snd.h"
44 #include "xlat/evdev_switch.h"
45 #include "xlat/evdev_sync.h"
52 decode_envelope(struct ff_envelope *envelope)
54 tprintf(", envelope={attack_length=%" PRIu16 ", attack_level=%" PRIu16
55 ", fade_length=%" PRIu16 ", fade_level=%" PRIx32 "}",
56 envelope->attack_length,
57 envelope->attack_level,
58 envelope->fade_length,
59 envelope->fade_level);
63 ff_effect_ioctl(struct tcb *tcp, long arg)
67 if (!verbose(tcp) || umove(tcp, arg, &ffe) < 0)
71 printxval(evdev_ff_types, ffe.type, "FF_???");
72 tprintf(", id=%" PRIu16 ", direction=%" PRIu16,
73 ffe.id, ffe.direction);
76 tprintf(", trigger={button=%" PRIu16 ", interval=%" PRIu16 "}",
77 ffe.trigger.button, ffe.trigger.interval);
78 tprintf(", replay={lenght=%" PRIu16 ", delay=%" PRIu16 "}",
79 ffe.replay.length, ffe.replay.delay);
82 tprintf(", constant_ef={%" PRIi16,
83 ffe.u.constant.level);
84 decode_envelope(&ffe.u.constant.envelope);
88 tprintf(", ramp={start_level=%" PRIi16
89 ", end_level=%" PRIi16,
90 ffe.u.ramp.start_level,
91 ffe.u.ramp.end_level);
92 decode_envelope(&ffe.u.ramp.envelope);
96 tprintf(", periodic_ef={waveform=%" PRIu16
98 ", magnitude=%" PRIi16
101 ffe.u.periodic.waveform,
102 ffe.u.periodic.period,
103 ffe.u.periodic.magnitude,
104 ffe.u.periodic.offset,
105 ffe.u.periodic.phase);
106 decode_envelope(&ffe.u.periodic.envelope);
107 tprintf(", custom_len=%" PRIu32
108 ", *custom_data=%#lx}",
109 ffe.u.periodic.custom_len,
110 (unsigned long)ffe.u.periodic.custom_data);
113 tprintf(", rumble={strong_magnitude=%" PRIu16
114 ", weak_magnitude=%" PRIu16 "}",
115 ffe.u.rumble.strong_magnitude,
116 ffe.u.rumble.weak_magnitude);
134 abs_ioctl(struct tcb *tcp, long arg)
136 struct input_absinfo absinfo;
138 if (!verbose(tcp) || umove(tcp, arg, &absinfo) < 0)
141 tprintf(", {value=%" PRIu32 ", minimum=%" PRIu32,
142 absinfo.value, absinfo.minimum);
144 tprintf(", maximum=%" PRIu32 ", fuzz=%" PRIu32,
145 absinfo.maximum, absinfo.fuzz);
146 tprintf(", flat=%" PRIu32, absinfo.flat);
147 #ifdef HAVE_STRUCT_INPUT_ABSINFO_RESOLUTION
148 tprintf(", resolution=%" PRIu32, absinfo.resolution);
158 keycode_ioctl(struct tcb *tcp, long arg)
160 unsigned int keycode[2];
167 if (!verbose(tcp) || umove(tcp, arg, &keycode) < 0)
170 tprintf(", [%u, ", keycode[0]);
171 printxval(evdev_keycode, keycode[1], "KEY_???");
176 #ifdef EVIOCGKEYCODE_V2
178 keycode_V2_ioctl(struct tcb *tcp, long arg)
180 struct input_keymap_entry ike;
187 if (!verbose(tcp) || umove(tcp, arg, &ike) < 0)
190 tprintf(", {flags=%" PRIu8 ", len=%" PRIu8, ike.flags, ike.len);
194 tprintf(", index=%" PRIu16 ", keycode=", ike.index);
195 printxval(evdev_keycode, ike.keycode, "KEY_???");
196 tprints(", scancode=[");
197 for (i = 0; i < ARRAY_SIZE(ike.scancode); i++) {
200 tprintf("%" PRIx8, ike.scancode[i]);
208 #endif /* EVIOCGKEYCODE_V2 */
211 getid_ioctl(struct tcb *tcp, long arg)
215 if (!verbose(tcp) || umove(tcp, arg, &id) < 0)
218 tprintf(", {ID_BUS=%" PRIu16 ", ID_VENDOR=%" PRIu16,
219 id.bustype, id.vendor);
221 tprintf(", ID_PRODUCT=%" PRIu16 ", ID_VERSION=%" PRIu16 "}",
222 id.product, id.version);
230 decode_bitset(struct tcb *tcp, long arg, const struct xlat decode_nr[],
231 const unsigned int max_nr, const char *dflt)
237 if ((unsigned long) tcp->u_rval > max_nr)
241 char decoded_arg[size];
243 if (umoven(tcp, arg, size, decoded_arg) < 0)
248 int bit_displayed = 0;
249 int i = next_set_bit(decoded_arg, 0, size);
253 printxval(decode_nr, i, dflt);
255 while ((i = next_set_bit(decoded_arg, i + 1, size)) > 0) {
256 if (abbrev(tcp) && bit_displayed >= 3) {
261 printxval(decode_nr, i, dflt);
273 mtslots_ioctl(struct tcb *tcp, const unsigned int code, long arg)
275 const size_t size = _IOC_SIZE(code) / sizeof(int32_t);
279 int32_t buffer[size];
281 if (!verbose(tcp) || umove(tcp, arg, &buffer) < 0)
285 printxval(evdev_mtslots, buffer[0], "ABS_MT_???");
288 tprints(", values=[");
290 for (i = 1; i < ARRAY_SIZE(buffer); i++)
291 tprintf("%s%d", i > 1 ? ", " : "", buffer[i]);
296 #endif /* EVIOCGMTSLOTS */
300 repeat_ioctl(struct tcb *tcp, long arg)
304 if (!verbose(tcp) || umove(tcp, arg, &val) < 0)
307 tprintf(", [%" PRIu32 " %" PRIu32 "]", val[0], val[1]);
310 #endif /* EVIOCGREP */
313 evdev_read_ioctl(struct tcb *tcp, const unsigned int code, long arg)
321 if ((_IOC_NR(code) & ~EV_MAX) == _IOC_NR(EVIOCGBIT(0, 0))) {
322 switch (_IOC_NR(code) - 0x20) {
324 return decode_bitset(tcp, arg, evdev_sync,
327 return decode_bitset(tcp, arg, evdev_keycode,
330 return decode_bitset(tcp, arg, evdev_relative_axes,
333 return decode_bitset(tcp, arg,
334 evdev_abs, ABS_MAX, "ABS_???");
336 return decode_bitset(tcp, arg,
337 evdev_misc, MSC_MAX, "MSC_???");
340 return decode_bitset(tcp, arg,
341 evdev_switch, SW_MAX, "SW_???");
344 return decode_bitset(tcp, arg,
345 evdev_leds, LED_MAX, "LED_???");
347 return decode_bitset(tcp, arg,
348 evdev_snd, SND_MAX, "SND_???");
350 return decode_bitset(tcp, arg, evdev_autorepeat,
353 return decode_bitset(tcp, arg, evdev_ff_types,
356 printnum_int(tcp, arg, "%d");
359 return decode_bitset(tcp, arg, evdev_ff_status,
360 FF_STATUS_MAX, "FF_STATUS_???");
366 if ((_IOC_NR(code) & ~ABS_MAX) == _IOC_NR(EVIOCGABS(0)))
367 return abs_ioctl(tcp, arg);
372 printnum_int(tcp, arg, "%" PRIx32);
376 printnum_int(tcp, arg, "%" PRIu32);
379 return getid_ioctl(tcp, arg);
382 return repeat_ioctl(tcp, arg);;
385 return keycode_ioctl(tcp, arg);
386 #ifdef EVIOCGKEYCODE_V2
387 case EVIOCGKEYCODE_V2:
388 return keycode_V2_ioctl(tcp, arg);
392 switch (_IOC_NR(code)) {
394 case _IOC_NR(EVIOCGMTSLOTS(0)):
395 return mtslots_ioctl(tcp, code, arg);
397 case _IOC_NR(EVIOCGNAME(0)):
398 case _IOC_NR(EVIOCGPHYS(0)):
399 case _IOC_NR(EVIOCGUNIQ(0)):
401 printstr(tcp, arg, tcp->u_rval - 1);
404 case _IOC_NR(EVIOCGPROP(0)):
405 return decode_bitset(tcp, arg,
406 evdev_prop, INPUT_PROP_MAX, "PROP_???");
408 case _IOC_NR(EVIOCGSND(0)):
409 return decode_bitset(tcp, arg,
410 evdev_snd, SND_MAX, "SND_???");
412 case _IOC_NR(EVIOCGSW(0)):
413 return decode_bitset(tcp, arg,
414 evdev_switch, SW_MAX, "SW_???");
416 case _IOC_NR(EVIOCGKEY(0)):
417 return decode_bitset(tcp, arg,
418 evdev_keycode, KEY_MAX, "KEY_???");
419 case _IOC_NR(EVIOCGLED(0)):
420 return decode_bitset(tcp, arg,
421 evdev_leds, LED_MAX, "LED_???");
428 evdev_write_ioctl(struct tcb *tcp, const unsigned int code, long arg)
433 if ((_IOC_NR(code) & ~ABS_MAX) == _IOC_NR(EVIOCSABS(0)))
434 return abs_ioctl(tcp, arg);
439 return repeat_ioctl(tcp, arg);
442 return keycode_ioctl(tcp, arg);
443 #ifdef EVIOCSKEYCODE_V2
444 case EVIOCSKEYCODE_V2:
445 return keycode_V2_ioctl(tcp, arg);
448 return ff_effect_ioctl(tcp, arg);
458 printnum_int(tcp, arg, "%u");
466 evdev_ioctl(struct tcb *tcp, const unsigned int code, long arg)
468 switch(_IOC_DIR(code)) {
470 return evdev_read_ioctl(tcp, code, arg);
472 if (!evdev_write_ioctl(tcp, code, arg))
473 tprintf(", %lx", arg);
480 #endif /* HAVE_LINUX_INPUT_H */