]> granicus.if.org Git - strace/blob - evdev_mpers.c
Add PAF_ARRAY_TRUNCATED flag for print_array_ex
[strace] / evdev_mpers.c
1 /*
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-2018 The strace developers.
5  * All rights reserved.
6  *
7  * SPDX-License-Identifier: LGPL-2.1-or-later
8  */
9
10 #include "defs.h"
11
12 #ifdef HAVE_LINUX_INPUT_H
13
14 # include DEF_MPERS_TYPE(struct_ff_effect)
15
16 # include <linux/ioctl.h>
17 # include <linux/input.h>
18
19 typedef struct ff_effect struct_ff_effect;
20
21 #endif /* HAVE_LINUX_INPUT_H */
22
23 #include MPERS_DEFS
24
25 #ifdef HAVE_LINUX_INPUT_H
26
27 static void
28 decode_envelope(void *const data)
29 {
30         const struct ff_envelope *const envelope = data;
31
32         tprintf(", envelope={attack_length=%" PRIu16
33                 ", attack_level=%" PRIu16
34                 ", fade_length=%" PRIu16
35                 ", fade_level=%#x}",
36                 envelope->attack_length,
37                 envelope->attack_level,
38                 envelope->fade_length,
39                 envelope->fade_level);
40 }
41
42 static int
43 ff_effect_ioctl(struct tcb *const tcp, const kernel_ulong_t arg)
44 {
45         tprints(", ");
46
47         struct_ff_effect ffe;
48
49         if (umove_or_printaddr(tcp, arg, &ffe))
50                 return RVAL_IOCTL_DECODED;
51
52         tprints("{type=");
53         print_evdev_ff_type(ffe.type);
54         tprintf(", id=%" PRIu16
55                 ", direction=%" PRIu16 ", ",
56                 ffe.id,
57                 ffe.direction);
58
59         if (abbrev(tcp)) {
60                 tprints("...}");
61                 return RVAL_IOCTL_DECODED;
62         }
63
64         tprintf("trigger={button=%" PRIu16
65                 ", interval=%" PRIu16 "}"
66                 ", replay={length=%" PRIu16
67                 ", delay=%" PRIu16 "}",
68                 ffe.trigger.button,
69                 ffe.trigger.interval,
70                 ffe.replay.length,
71                 ffe.replay.delay);
72
73         switch (ffe.type) {
74                 case FF_CONSTANT:
75                         tprintf(", constant={level=%" PRId16,
76                                 ffe.u.constant.level);
77                         decode_envelope(&ffe.u.constant.envelope);
78                         tprints("}");
79                         break;
80                 case FF_RAMP:
81                         tprintf(", ramp={start_level=%" PRId16
82                                 ", end_level=%" PRId16,
83                                 ffe.u.ramp.start_level,
84                                 ffe.u.ramp.end_level);
85                         decode_envelope(&ffe.u.ramp.envelope);
86                         tprints("}");
87                         break;
88                 case FF_PERIODIC:
89                         tprintf(", periodic={waveform=%" PRIu16
90                                 ", period=%" PRIu16
91                                 ", magnitude=%" PRId16
92                                 ", offset=%" PRId16
93                                 ", phase=%" PRIu16,
94                                 ffe.u.periodic.waveform,
95                                 ffe.u.periodic.period,
96                                 ffe.u.periodic.magnitude,
97                                 ffe.u.periodic.offset,
98                                 ffe.u.periodic.phase);
99                         decode_envelope(&ffe.u.periodic.envelope);
100                         tprintf(", custom_len=%u, custom_data=",
101                                 ffe.u.periodic.custom_len);
102                         printaddr(ptr_to_kulong(ffe.u.periodic.custom_data));
103                         tprints("}");
104                         break;
105                 case FF_RUMBLE:
106                         tprintf(", rumble={strong_magnitude=%" PRIu16
107                                 ", weak_magnitude=%" PRIu16 "}",
108                                 ffe.u.rumble.strong_magnitude,
109                                 ffe.u.rumble.weak_magnitude);
110                         break;
111                 default:
112                         break;
113         }
114
115         tprints("}");
116
117         return RVAL_IOCTL_DECODED;
118 }
119
120 MPERS_PRINTER_DECL(int, evdev_write_ioctl_mpers, struct tcb *const tcp,
121                    const unsigned int code, const kernel_ulong_t arg)
122 {
123         switch (code) {
124                 case EVIOCSFF:
125                         return ff_effect_ioctl(tcp, arg);
126                 default:
127                         return RVAL_DECODED;
128         }
129 }
130
131 #endif /* HAVE_LINUX_INPUT_H */