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
33 # include <linux/ioctl.h>
34 # include <linux/input.h>
35 # include "xlat/evdev_abs.h"
36 # include "xlat/evdev_autorepeat.h"
37 # include "xlat/evdev_ff_status.h"
38 # include "xlat/evdev_ff_types.h"
39 # include "xlat/evdev_keycode.h"
40 # include "xlat/evdev_leds.h"
41 # include "xlat/evdev_misc.h"
42 # include "xlat/evdev_mtslots.h"
43 # include "xlat/evdev_prop.h"
44 # include "xlat/evdev_relative_axes.h"
45 # include "xlat/evdev_snd.h"
46 # include "xlat/evdev_switch.h"
47 # include "xlat/evdev_sync.h"
54 decode_envelope(const struct ff_envelope *envelope)
56 tprintf(", envelope={attack_length=%" PRIu16
57 ", attack_level=%" PRIu16
58 ", fade_length=%" PRIu16
60 envelope->attack_length,
61 envelope->attack_level,
62 envelope->fade_length,
63 envelope->fade_level);
67 ff_effect_ioctl(struct tcb *tcp, long arg)
73 if (umove_or_printaddr(tcp, arg, &ffe))
77 printxval(evdev_ff_types, ffe.type, "FF_???");
78 tprintf(", id=%" PRIu16
79 ", direction=%" PRIu16 ", ",
88 tprintf("trigger={button=%" PRIu16
89 ", interval=%" PRIu16 "}"
90 ", replay={length=%" PRIu16
91 ", delay=%" PRIu16 "}",
99 tprintf(", constant={level=%" PRId16,
100 ffe.u.constant.level);
101 decode_envelope(&ffe.u.constant.envelope);
105 tprintf(", ramp={start_level=%" PRId16
106 ", end_level=%" PRId16,
107 ffe.u.ramp.start_level,
108 ffe.u.ramp.end_level);
109 decode_envelope(&ffe.u.ramp.envelope);
113 tprintf(", periodic={waveform=%" PRIu16
115 ", magnitude=%" PRId16
118 ffe.u.periodic.waveform,
119 ffe.u.periodic.period,
120 ffe.u.periodic.magnitude,
121 ffe.u.periodic.offset,
122 ffe.u.periodic.phase);
123 decode_envelope(&ffe.u.periodic.envelope);
124 tprintf(", custom_len=%u"
125 ", custom_data=%#lx}",
126 ffe.u.periodic.custom_len,
127 (unsigned long) ffe.u.periodic.custom_data);
130 tprintf(", rumble={strong_magnitude=%" PRIu16
131 ", weak_magnitude=%" PRIu16 "}",
132 ffe.u.rumble.strong_magnitude,
133 ffe.u.rumble.weak_magnitude);
145 abs_ioctl(struct tcb *tcp, long arg)
149 struct input_absinfo absinfo;
151 if (!umove_or_printaddr(tcp, arg, &absinfo)) {
164 # ifdef HAVE_STRUCT_INPUT_ABSINFO_RESOLUTION
165 tprintf(", resolution=%u",
179 keycode_ioctl(struct tcb *tcp, long arg)
183 unsigned int keycode[2];
185 if (!umove_or_printaddr(tcp, arg, &keycode)) {
186 tprintf("[%u, ", keycode[0]);
187 printxval(evdev_keycode, keycode[1], "KEY_???");
194 # ifdef EVIOCGKEYCODE_V2
196 keycode_V2_ioctl(struct tcb *tcp, long arg)
200 struct input_keymap_entry ike;
202 if (umove_or_printaddr(tcp, arg, &ike))
205 tprintf("{flags=%" PRIu8
206 ", len=%" PRIu8 ", ",
213 tprintf("index=%" PRIu16 ", keycode=", ike.index);
214 printxval(evdev_keycode, ike.keycode, "KEY_???");
215 tprints(", scancode=[");
216 for (i = 0; i < ARRAY_SIZE(ike.scancode); i++) {
219 tprintf("%" PRIx8, ike.scancode[i]);
230 # endif /* EVIOCGKEYCODE_V2 */
233 getid_ioctl(struct tcb *tcp, long arg)
239 if (!umove_or_printaddr(tcp, arg, &id))
240 tprintf("{ID_BUS=%" PRIu16
241 ", ID_VENDOR=%" PRIu16
242 ", ID_PRODUCT=%" PRIu16
243 ", ID_VERSION=%" PRIu16 "}",
253 decode_bitset(struct tcb *tcp, long arg, const struct xlat decode_nr[],
254 const unsigned int max_nr, const char *dflt)
259 if ((unsigned long) tcp->u_rval > max_nr)
263 char decoded_arg[size];
265 if (umove_or_printaddr(tcp, arg, &decoded_arg))
270 int bit_displayed = 0;
271 int i = next_set_bit(decoded_arg, 0, size);
275 printxval(decode_nr, i, dflt);
277 while ((i = next_set_bit(decoded_arg, i + 1, size)) > 0) {
278 if (abbrev(tcp) && bit_displayed >= 3) {
283 printxval(decode_nr, i, dflt);
293 # ifdef EVIOCGMTSLOTS
295 mtslots_ioctl(struct tcb *tcp, const unsigned int code, long arg)
299 const size_t size = _IOC_SIZE(code) / sizeof(int);
307 if (umove_or_printaddr(tcp, arg, &buffer))
311 printxval(evdev_mtslots, buffer[0], "ABS_MT_???");
313 tprints(", values=[");
316 for (i = 1; i < ARRAY_SIZE(buffer); i++)
317 tprintf("%s%d", i > 1 ? ", " : "", buffer[i]);
323 # endif /* EVIOCGMTSLOTS */
325 # if defined EVIOCGREP || defined EVIOCSREP
327 repeat_ioctl(struct tcb *tcp, long arg)
330 printpair_int(tcp, arg, "%u");
333 # endif /* EVIOCGREP || EVIOCSREP */
336 bit_ioctl(struct tcb *tcp, const unsigned int ev_nr, const long arg)
340 return decode_bitset(tcp, arg, evdev_sync,
343 return decode_bitset(tcp, arg, evdev_keycode,
346 return decode_bitset(tcp, arg, evdev_relative_axes,
349 return decode_bitset(tcp, arg, evdev_abs,
352 return decode_bitset(tcp, arg, evdev_misc,
356 return decode_bitset(tcp, arg, evdev_switch,
360 return decode_bitset(tcp, arg, evdev_leds,
363 return decode_bitset(tcp, arg, evdev_snd,
366 return decode_bitset(tcp, arg, evdev_autorepeat,
369 return decode_bitset(tcp, arg, evdev_ff_types,
373 printnum_int(tcp, arg, "%d");
376 return decode_bitset(tcp, arg, evdev_ff_status,
377 FF_STATUS_MAX, "FF_STATUS_???");
386 evdev_read_ioctl(struct tcb *tcp, const unsigned int code, const long arg)
388 /* fixed-number fixed-length commands */
392 printnum_int(tcp, arg, "%#x");
396 printnum_int(tcp, arg, "%u");
399 return getid_ioctl(tcp, arg);
402 return repeat_ioctl(tcp, arg);
405 return keycode_ioctl(tcp, arg);
406 # ifdef EVIOCGKEYCODE_V2
407 case EVIOCGKEYCODE_V2:
408 return keycode_V2_ioctl(tcp, arg);
412 /* fixed-number variable-length commands */
413 switch (_IOC_NR(code)) {
414 # ifdef EVIOCGMTSLOTS
415 case _IOC_NR(EVIOCGMTSLOTS(0)):
416 return mtslots_ioctl(tcp, code, arg);
418 case _IOC_NR(EVIOCGNAME(0)):
419 case _IOC_NR(EVIOCGPHYS(0)):
420 case _IOC_NR(EVIOCGUNIQ(0)):
425 printstr(tcp, arg, tcp->u_rval);
428 case _IOC_NR(EVIOCGPROP(0)):
429 return decode_bitset(tcp, arg, evdev_prop,
430 INPUT_PROP_MAX, "PROP_???");
432 case _IOC_NR(EVIOCGSND(0)):
433 return decode_bitset(tcp, arg, evdev_snd,
436 case _IOC_NR(EVIOCGSW(0)):
437 return decode_bitset(tcp, arg, evdev_switch,
440 case _IOC_NR(EVIOCGKEY(0)):
441 return decode_bitset(tcp, arg, evdev_keycode,
443 case _IOC_NR(EVIOCGLED(0)):
444 return decode_bitset(tcp, arg, evdev_leds,
448 /* multi-number fixed-length commands */
449 if ((_IOC_NR(code) & ~ABS_MAX) == _IOC_NR(EVIOCGABS(0)))
450 return abs_ioctl(tcp, arg);
452 /* multi-number variable-length commands */
453 if ((_IOC_NR(code) & ~EV_MAX) == _IOC_NR(EVIOCGBIT(0, 0)))
454 return bit_ioctl(tcp, _IOC_NR(code) & EV_MAX, arg);
460 evdev_write_ioctl(struct tcb *tcp, const unsigned int code, const long arg)
462 /* fixed-number fixed-length commands */
466 return repeat_ioctl(tcp, arg);
469 return keycode_ioctl(tcp, arg);
470 # ifdef EVIOCSKEYCODE_V2
471 case EVIOCSKEYCODE_V2:
472 return keycode_V2_ioctl(tcp, arg);
475 return ff_effect_ioctl(tcp, arg);
477 tprintf(", %d", (int) arg);
483 tprintf(", %lu", arg);
485 # ifdef EVIOCSCLOCKID
488 printnum_int(tcp, arg, "%u");
493 /* multi-number fixed-length commands */
494 if ((_IOC_NR(code) & ~ABS_MAX) == _IOC_NR(EVIOCSABS(0)))
495 return abs_ioctl(tcp, arg);
501 evdev_ioctl(struct tcb *tcp, const unsigned int code, long arg)
503 switch(_IOC_DIR(code)) {
507 return evdev_read_ioctl(tcp, code, arg);
509 return evdev_write_ioctl(tcp, code, arg) | RVAL_DECODED;
515 #endif /* HAVE_LINUX_INPUT_H */