2 * Copyright (c) 2015 Etienne Gemsa <etienne.gemsa@lse.epita.fr>
3 * Copyright (c) 2015-2016 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 DEF_MPERS_TYPE(struct_ff_effect)
35 # include <linux/ioctl.h>
36 # include <linux/input.h>
38 typedef struct ff_effect struct_ff_effect;
40 #endif /* HAVE_LINUX_INPUT_H */
44 #ifdef HAVE_LINUX_INPUT_H
46 # 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"
64 decode_envelope(void *const data)
66 const struct ff_envelope *const envelope = data;
68 tprintf(", envelope={attack_length=%" PRIu16
69 ", attack_level=%" PRIu16
70 ", fade_length=%" PRIu16
72 envelope->attack_length,
73 envelope->attack_level,
74 envelope->fade_length,
75 envelope->fade_level);
79 ff_effect_ioctl(struct tcb *const tcp, const kernel_ulong_t arg)
85 if (umove_or_printaddr(tcp, arg, &ffe))
89 printxval(evdev_ff_types, ffe.type, "FF_???");
90 tprintf(", id=%" PRIu16
91 ", direction=%" PRIu16 ", ",
100 tprintf("trigger={button=%" PRIu16
101 ", interval=%" PRIu16 "}"
102 ", replay={length=%" PRIu16
103 ", delay=%" PRIu16 "}",
105 ffe.trigger.interval,
111 tprintf(", constant={level=%" PRId16,
112 ffe.u.constant.level);
113 decode_envelope(&ffe.u.constant.envelope);
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);
125 tprintf(", periodic={waveform=%" PRIu16
127 ", magnitude=%" PRId16
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);
136 tprintf(", custom_len=%u, custom_data=",
137 ffe.u.periodic.custom_len);
138 printaddr(ptr_to_kulong(ffe.u.periodic.custom_data));
142 tprintf(", rumble={strong_magnitude=%" PRIu16
143 ", weak_magnitude=%" PRIu16 "}",
144 ffe.u.rumble.strong_magnitude,
145 ffe.u.rumble.weak_magnitude);
157 abs_ioctl(struct tcb *const tcp, const kernel_ulong_t arg)
161 struct input_absinfo absinfo;
163 if (!umove_or_printaddr(tcp, arg, &absinfo)) {
176 # ifdef HAVE_STRUCT_INPUT_ABSINFO_RESOLUTION
177 tprintf(", resolution=%u",
191 keycode_ioctl(struct tcb *const tcp, const kernel_ulong_t arg)
195 unsigned int keycode[2];
197 if (!umove_or_printaddr(tcp, arg, &keycode)) {
198 tprintf("[%u, ", keycode[0]);
199 printxval(evdev_keycode, keycode[1], "KEY_???");
206 # ifdef EVIOCGKEYCODE_V2
208 keycode_V2_ioctl(struct tcb *const tcp, const kernel_ulong_t arg)
212 struct input_keymap_entry ike;
214 if (umove_or_printaddr(tcp, arg, &ike))
217 tprintf("{flags=%" PRIu8
218 ", len=%" PRIu8 ", ",
225 tprintf("index=%" PRIu16 ", keycode=", ike.index);
226 printxval(evdev_keycode, ike.keycode, "KEY_???");
227 tprints(", scancode=[");
228 for (i = 0; i < ARRAY_SIZE(ike.scancode); i++) {
231 tprintf("%" PRIx8, ike.scancode[i]);
242 # endif /* EVIOCGKEYCODE_V2 */
245 getid_ioctl(struct tcb *const tcp, const kernel_ulong_t arg)
251 if (!umove_or_printaddr(tcp, arg, &id))
252 tprintf("{ID_BUS=%" PRIu16
253 ", ID_VENDOR=%" PRIu16
254 ", ID_PRODUCT=%" PRIu16
255 ", ID_VERSION=%" PRIu16 "}",
265 decode_bitset(struct tcb *const tcp, const kernel_ulong_t arg,
266 const struct xlat decode_nr[], const unsigned int max_nr,
267 const char *const dflt)
272 if ((kernel_ulong_t) tcp->u_rval > max_nr)
276 char decoded_arg[size];
278 if (umove_or_printaddr(tcp, arg, &decoded_arg))
283 int bit_displayed = 0;
284 int i = next_set_bit(decoded_arg, 0, size);
288 printxval(decode_nr, i, dflt);
290 while ((i = next_set_bit(decoded_arg, i + 1, size)) > 0) {
291 if (abbrev(tcp) && bit_displayed >= 3) {
296 printxval(decode_nr, i, dflt);
306 # ifdef EVIOCGMTSLOTS
308 mtslots_ioctl(struct tcb *const tcp, const unsigned int code,
309 const kernel_ulong_t arg)
313 const size_t size = _IOC_SIZE(code) / sizeof(int);
321 if (umove_or_printaddr(tcp, arg, &buffer))
325 printxval(evdev_mtslots, buffer[0], "ABS_MT_???");
327 tprints(", values=[");
330 for (i = 1; i < ARRAY_SIZE(buffer); i++)
331 tprintf("%s%d", i > 1 ? ", " : "", buffer[i]);
337 # endif /* EVIOCGMTSLOTS */
339 # if defined EVIOCGREP || defined EVIOCSREP
341 repeat_ioctl(struct tcb *const tcp, const kernel_ulong_t arg)
344 printpair_int(tcp, arg, "%u");
347 # endif /* EVIOCGREP || EVIOCSREP */
350 bit_ioctl(struct tcb *const tcp, const unsigned int ev_nr,
351 const kernel_ulong_t arg)
355 return decode_bitset(tcp, arg, evdev_sync,
358 return decode_bitset(tcp, arg, evdev_keycode,
361 return decode_bitset(tcp, arg, evdev_relative_axes,
364 return decode_bitset(tcp, arg, evdev_abs,
367 return decode_bitset(tcp, arg, evdev_misc,
371 return decode_bitset(tcp, arg, evdev_switch,
375 return decode_bitset(tcp, arg, evdev_leds,
378 return decode_bitset(tcp, arg, evdev_snd,
381 return decode_bitset(tcp, arg, evdev_autorepeat,
384 return decode_bitset(tcp, arg, evdev_ff_types,
388 printnum_int(tcp, arg, "%d");
391 return decode_bitset(tcp, arg, evdev_ff_status,
392 FF_STATUS_MAX, "FF_STATUS_???");
401 evdev_read_ioctl(struct tcb *const tcp, const unsigned int code,
402 const kernel_ulong_t arg)
404 /* fixed-number fixed-length commands */
408 printnum_int(tcp, arg, "%#x");
412 printnum_int(tcp, arg, "%u");
415 return getid_ioctl(tcp, arg);
418 return repeat_ioctl(tcp, arg);
421 return keycode_ioctl(tcp, arg);
422 # ifdef EVIOCGKEYCODE_V2
423 case EVIOCGKEYCODE_V2:
424 return keycode_V2_ioctl(tcp, arg);
428 /* fixed-number variable-length commands */
429 switch (_IOC_NR(code)) {
430 # ifdef EVIOCGMTSLOTS
431 case _IOC_NR(EVIOCGMTSLOTS(0)):
432 return mtslots_ioctl(tcp, code, arg);
434 case _IOC_NR(EVIOCGNAME(0)):
435 case _IOC_NR(EVIOCGPHYS(0)):
436 case _IOC_NR(EVIOCGUNIQ(0)):
441 printstrn(tcp, arg, tcp->u_rval);
444 case _IOC_NR(EVIOCGPROP(0)):
445 return decode_bitset(tcp, arg, evdev_prop,
446 INPUT_PROP_MAX, "PROP_???");
448 case _IOC_NR(EVIOCGSND(0)):
449 return decode_bitset(tcp, arg, evdev_snd,
452 case _IOC_NR(EVIOCGSW(0)):
453 return decode_bitset(tcp, arg, evdev_switch,
456 case _IOC_NR(EVIOCGKEY(0)):
457 return decode_bitset(tcp, arg, evdev_keycode,
459 case _IOC_NR(EVIOCGLED(0)):
460 return decode_bitset(tcp, arg, evdev_leds,
464 /* multi-number fixed-length commands */
465 if ((_IOC_NR(code) & ~ABS_MAX) == _IOC_NR(EVIOCGABS(0)))
466 return abs_ioctl(tcp, arg);
468 /* multi-number variable-length commands */
469 if ((_IOC_NR(code) & ~EV_MAX) == _IOC_NR(EVIOCGBIT(0, 0)))
470 return bit_ioctl(tcp, _IOC_NR(code) & EV_MAX, arg);
476 evdev_write_ioctl(struct tcb *const tcp, const unsigned int code,
477 const kernel_ulong_t arg)
479 /* fixed-number fixed-length commands */
483 return repeat_ioctl(tcp, arg);
486 return keycode_ioctl(tcp, arg);
487 # ifdef EVIOCSKEYCODE_V2
488 case EVIOCSKEYCODE_V2:
489 return keycode_V2_ioctl(tcp, arg);
492 return ff_effect_ioctl(tcp, arg);
494 tprintf(", %d", (int) arg);
500 tprintf(", %" PRI_klu, arg);
502 # ifdef EVIOCSCLOCKID
505 printnum_int(tcp, arg, "%u");
510 /* multi-number fixed-length commands */
511 if ((_IOC_NR(code) & ~ABS_MAX) == _IOC_NR(EVIOCSABS(0)))
512 return abs_ioctl(tcp, arg);
517 MPERS_PRINTER_DECL(int, evdev_ioctl, struct tcb *const tcp,
518 const unsigned int code, const kernel_ulong_t arg)
520 switch(_IOC_DIR(code)) {
524 return evdev_read_ioctl(tcp, code, arg);
526 return evdev_write_ioctl(tcp, code, arg) | RVAL_DECODED;
532 #endif /* HAVE_LINUX_INPUT_H */