2 * Copyright (c) 2015 Etienne Gemsa <etienne.gemsa@lse.epita.fr>
3 * Copyright (c) 2015-2016 Dmitry V. Levin <ldv@altlinux.org>
4 * Copyright (c) 2015-2017 The strace developers.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
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.
32 #ifdef HAVE_LINUX_INPUT_H
34 #include DEF_MPERS_TYPE(struct_ff_effect)
36 # include <linux/ioctl.h>
37 # include <linux/input.h>
39 typedef struct ff_effect struct_ff_effect;
41 #endif /* HAVE_LINUX_INPUT_H */
45 #ifdef HAVE_LINUX_INPUT_H
47 # 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"
65 decode_envelope(void *const data)
67 const struct ff_envelope *const envelope = data;
69 tprintf(", envelope={attack_length=%" PRIu16
70 ", attack_level=%" PRIu16
71 ", fade_length=%" PRIu16
73 envelope->attack_length,
74 envelope->attack_level,
75 envelope->fade_length,
76 envelope->fade_level);
80 ff_effect_ioctl(struct tcb *const tcp, const kernel_ulong_t arg)
86 if (umove_or_printaddr(tcp, arg, &ffe))
87 return RVAL_IOCTL_DECODED;
90 printxval(evdev_ff_types, ffe.type, "FF_???");
91 tprintf(", id=%" PRIu16
92 ", direction=%" PRIu16 ", ",
98 return RVAL_IOCTL_DECODED;
101 tprintf("trigger={button=%" PRIu16
102 ", interval=%" PRIu16 "}"
103 ", replay={length=%" PRIu16
104 ", delay=%" PRIu16 "}",
106 ffe.trigger.interval,
112 tprintf(", constant={level=%" PRId16,
113 ffe.u.constant.level);
114 decode_envelope(&ffe.u.constant.envelope);
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);
126 tprintf(", periodic={waveform=%" PRIu16
128 ", magnitude=%" PRId16
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);
137 tprintf(", custom_len=%u, custom_data=",
138 ffe.u.periodic.custom_len);
139 printaddr(ptr_to_kulong(ffe.u.periodic.custom_data));
143 tprintf(", rumble={strong_magnitude=%" PRIu16
144 ", weak_magnitude=%" PRIu16 "}",
145 ffe.u.rumble.strong_magnitude,
146 ffe.u.rumble.weak_magnitude);
154 return RVAL_IOCTL_DECODED;
158 abs_ioctl(struct tcb *const tcp, const kernel_ulong_t arg)
162 struct input_absinfo absinfo;
164 if (!umove_or_printaddr(tcp, arg, &absinfo)) {
177 # ifdef HAVE_STRUCT_INPUT_ABSINFO_RESOLUTION
178 tprintf(", resolution=%u",
188 return RVAL_IOCTL_DECODED;
192 keycode_ioctl(struct tcb *const tcp, const kernel_ulong_t arg)
196 unsigned int keycode[2];
198 if (!umove_or_printaddr(tcp, arg, &keycode)) {
199 tprintf("[%u, ", keycode[0]);
200 printxval(evdev_keycode, keycode[1], "KEY_???");
204 return RVAL_IOCTL_DECODED;
207 # ifdef EVIOCGKEYCODE_V2
209 keycode_V2_ioctl(struct tcb *const tcp, const kernel_ulong_t arg)
213 struct input_keymap_entry ike;
215 if (umove_or_printaddr(tcp, arg, &ike))
216 return RVAL_IOCTL_DECODED;
218 tprintf("{flags=%" PRIu8
219 ", len=%" PRIu8 ", ",
226 tprintf("index=%" PRIu16 ", keycode=", ike.index);
227 printxval(evdev_keycode, ike.keycode, "KEY_???");
228 tprints(", scancode=[");
229 for (i = 0; i < ARRAY_SIZE(ike.scancode); i++) {
232 tprintf("%" PRIx8, ike.scancode[i]);
241 return RVAL_IOCTL_DECODED;
243 # endif /* EVIOCGKEYCODE_V2 */
246 getid_ioctl(struct tcb *const tcp, const kernel_ulong_t arg)
252 if (!umove_or_printaddr(tcp, arg, &id))
253 tprintf("{ID_BUS=%" PRIu16
254 ", ID_VENDOR=%" PRIu16
255 ", ID_PRODUCT=%" PRIu16
256 ", ID_VERSION=%" PRIu16 "}",
262 return RVAL_IOCTL_DECODED;
266 decode_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)
273 if ((kernel_ulong_t) tcp->u_rval > max_nr)
277 char decoded_arg[size];
279 if (umove_or_printaddr(tcp, arg, &decoded_arg))
280 return RVAL_IOCTL_DECODED;
284 int bit_displayed = 0;
285 int i = next_set_bit(decoded_arg, 0, size);
289 printxval(decode_nr, i, dflt);
291 while ((i = next_set_bit(decoded_arg, i + 1, size)) > 0) {
292 if (abbrev(tcp) && bit_displayed >= 3) {
297 printxval(decode_nr, i, dflt);
304 return RVAL_IOCTL_DECODED;
307 # ifdef EVIOCGMTSLOTS
309 mtslots_ioctl(struct tcb *const tcp, const unsigned int code,
310 const kernel_ulong_t arg)
314 const size_t size = _IOC_SIZE(code) / sizeof(int);
317 return RVAL_IOCTL_DECODED;
322 if (umove_or_printaddr(tcp, arg, &buffer))
323 return RVAL_IOCTL_DECODED;
326 printxval(evdev_mtslots, buffer[0], "ABS_MT_???");
328 tprints(", values=[");
331 for (i = 1; i < ARRAY_SIZE(buffer); i++)
332 tprintf("%s%d", i > 1 ? ", " : "", buffer[i]);
336 return RVAL_IOCTL_DECODED;
338 # endif /* EVIOCGMTSLOTS */
340 # if defined EVIOCGREP || defined EVIOCSREP
342 repeat_ioctl(struct tcb *const tcp, const kernel_ulong_t arg)
345 printpair_int(tcp, arg, "%u");
346 return RVAL_IOCTL_DECODED;
348 # endif /* EVIOCGREP || EVIOCSREP */
351 bit_ioctl(struct tcb *const tcp, const unsigned int ev_nr,
352 const kernel_ulong_t arg)
356 return decode_bitset(tcp, arg, evdev_sync,
359 return decode_bitset(tcp, arg, evdev_keycode,
362 return decode_bitset(tcp, arg, evdev_relative_axes,
365 return decode_bitset(tcp, arg, evdev_abs,
368 return decode_bitset(tcp, arg, evdev_misc,
372 return decode_bitset(tcp, arg, evdev_switch,
376 return decode_bitset(tcp, arg, evdev_leds,
379 return decode_bitset(tcp, arg, evdev_snd,
382 return decode_bitset(tcp, arg, evdev_autorepeat,
385 return decode_bitset(tcp, arg, evdev_ff_types,
389 printnum_int(tcp, arg, "%d");
390 return RVAL_IOCTL_DECODED;
392 return decode_bitset(tcp, arg, evdev_ff_status,
393 FF_STATUS_MAX, "FF_STATUS_???");
397 return RVAL_IOCTL_DECODED;
402 evdev_read_ioctl(struct tcb *const tcp, const unsigned int code,
403 const kernel_ulong_t arg)
405 /* fixed-number fixed-length commands */
409 printnum_int(tcp, arg, "%#x");
410 return RVAL_IOCTL_DECODED;
413 printnum_int(tcp, arg, "%u");
414 return RVAL_IOCTL_DECODED;
416 return getid_ioctl(tcp, arg);
419 return repeat_ioctl(tcp, arg);
422 return keycode_ioctl(tcp, arg);
423 # ifdef EVIOCGKEYCODE_V2
424 case EVIOCGKEYCODE_V2:
425 return keycode_V2_ioctl(tcp, arg);
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);
435 case _IOC_NR(EVIOCGNAME(0)):
436 case _IOC_NR(EVIOCGPHYS(0)):
437 case _IOC_NR(EVIOCGUNIQ(0)):
442 printstrn(tcp, arg, tcp->u_rval);
443 return RVAL_IOCTL_DECODED;
445 case _IOC_NR(EVIOCGPROP(0)):
446 return decode_bitset(tcp, arg, evdev_prop,
447 INPUT_PROP_MAX, "PROP_???");
449 case _IOC_NR(EVIOCGSND(0)):
450 return decode_bitset(tcp, arg, evdev_snd,
453 case _IOC_NR(EVIOCGSW(0)):
454 return decode_bitset(tcp, arg, evdev_switch,
457 case _IOC_NR(EVIOCGKEY(0)):
458 return decode_bitset(tcp, arg, evdev_keycode,
460 case _IOC_NR(EVIOCGLED(0)):
461 return decode_bitset(tcp, arg, evdev_leds,
465 /* multi-number fixed-length commands */
466 if ((_IOC_NR(code) & ~ABS_MAX) == _IOC_NR(EVIOCGABS(0)))
467 return abs_ioctl(tcp, arg);
469 /* multi-number variable-length commands */
470 if ((_IOC_NR(code) & ~EV_MAX) == _IOC_NR(EVIOCGBIT(0, 0)))
471 return bit_ioctl(tcp, _IOC_NR(code) & EV_MAX, arg);
477 evdev_write_ioctl(struct tcb *const tcp, const unsigned int code,
478 const kernel_ulong_t arg)
480 /* fixed-number fixed-length commands */
484 return repeat_ioctl(tcp, arg);
487 return keycode_ioctl(tcp, arg);
488 # ifdef EVIOCSKEYCODE_V2
489 case EVIOCSKEYCODE_V2:
490 return keycode_V2_ioctl(tcp, arg);
493 return ff_effect_ioctl(tcp, arg);
495 tprintf(", %d", (int) arg);
496 return RVAL_IOCTL_DECODED;
501 tprintf(", %" PRI_klu, arg);
502 return RVAL_IOCTL_DECODED;
503 # ifdef EVIOCSCLOCKID
506 printnum_int(tcp, arg, "%u");
507 return RVAL_IOCTL_DECODED;
511 /* multi-number fixed-length commands */
512 if ((_IOC_NR(code) & ~ABS_MAX) == _IOC_NR(EVIOCSABS(0)))
513 return abs_ioctl(tcp, arg);
518 MPERS_PRINTER_DECL(int, evdev_ioctl, struct tcb *const tcp,
519 const unsigned int code, const kernel_ulong_t arg)
521 switch (_IOC_DIR(code)) {
525 return evdev_read_ioctl(tcp, code, arg);
527 return evdev_write_ioctl(tcp, code, arg) | RVAL_DECODED;
533 #endif /* HAVE_LINUX_INPUT_H */