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 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
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.
17 *
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.
28 */
29
30 #include "defs.h"
31
32 #ifdef HAVE_LINUX_INPUT_H
33
34 #include DEF_MPERS_TYPE(struct_ff_effect)
35
36 # include <linux/ioctl.h>
37 # include <linux/input.h>
38
39 typedef struct ff_effect struct_ff_effect;
40
41 #endif /* HAVE_LINUX_INPUT_H */
42
43 #include MPERS_DEFS
44
45 #ifdef HAVE_LINUX_INPUT_H
46
47 static void
decode_envelope(void * const data)48 decode_envelope(void *const data)
49 {
50 const struct ff_envelope *const envelope = data;
51
52 tprintf(", envelope={attack_length=%" PRIu16
53 ", attack_level=%" PRIu16
54 ", fade_length=%" PRIu16
55 ", fade_level=%#x}",
56 envelope->attack_length,
57 envelope->attack_level,
58 envelope->fade_length,
59 envelope->fade_level);
60 }
61
62 static int
ff_effect_ioctl(struct tcb * const tcp,const kernel_ulong_t arg)63 ff_effect_ioctl(struct tcb *const tcp, const kernel_ulong_t arg)
64 {
65 tprints(", ");
66
67 struct_ff_effect ffe;
68
69 if (umove_or_printaddr(tcp, arg, &ffe))
70 return RVAL_IOCTL_DECODED;
71
72 tprints("{type=");
73 print_evdev_ff_type(ffe.type);
74 tprintf(", id=%" PRIu16
75 ", direction=%" PRIu16 ", ",
76 ffe.id,
77 ffe.direction);
78
79 if (abbrev(tcp)) {
80 tprints("...}");
81 return RVAL_IOCTL_DECODED;
82 }
83
84 tprintf("trigger={button=%" PRIu16
85 ", interval=%" PRIu16 "}"
86 ", replay={length=%" PRIu16
87 ", delay=%" PRIu16 "}",
88 ffe.trigger.button,
89 ffe.trigger.interval,
90 ffe.replay.length,
91 ffe.replay.delay);
92
93 switch (ffe.type) {
94 case FF_CONSTANT:
95 tprintf(", constant={level=%" PRId16,
96 ffe.u.constant.level);
97 decode_envelope(&ffe.u.constant.envelope);
98 tprints("}");
99 break;
100 case FF_RAMP:
101 tprintf(", ramp={start_level=%" PRId16
102 ", end_level=%" PRId16,
103 ffe.u.ramp.start_level,
104 ffe.u.ramp.end_level);
105 decode_envelope(&ffe.u.ramp.envelope);
106 tprints("}");
107 break;
108 case FF_PERIODIC:
109 tprintf(", periodic={waveform=%" PRIu16
110 ", period=%" PRIu16
111 ", magnitude=%" PRId16
112 ", offset=%" PRId16
113 ", phase=%" PRIu16,
114 ffe.u.periodic.waveform,
115 ffe.u.periodic.period,
116 ffe.u.periodic.magnitude,
117 ffe.u.periodic.offset,
118 ffe.u.periodic.phase);
119 decode_envelope(&ffe.u.periodic.envelope);
120 tprintf(", custom_len=%u, custom_data=",
121 ffe.u.periodic.custom_len);
122 printaddr(ptr_to_kulong(ffe.u.periodic.custom_data));
123 tprints("}");
124 break;
125 case FF_RUMBLE:
126 tprintf(", rumble={strong_magnitude=%" PRIu16
127 ", weak_magnitude=%" PRIu16 "}",
128 ffe.u.rumble.strong_magnitude,
129 ffe.u.rumble.weak_magnitude);
130 break;
131 default:
132 break;
133 }
134
135 tprints("}");
136
137 return RVAL_IOCTL_DECODED;
138 }
139
MPERS_PRINTER_DECL(int,evdev_write_ioctl_mpers,struct tcb * const tcp,const unsigned int code,const kernel_ulong_t arg)140 MPERS_PRINTER_DECL(int, evdev_write_ioctl_mpers, struct tcb *const tcp,
141 const unsigned int code, const kernel_ulong_t arg)
142 {
143 switch (code) {
144 case EVIOCSFF:
145 return ff_effect_ioctl(tcp, arg);
146 default:
147 return RVAL_DECODED;
148 }
149 }
150
151 #endif /* HAVE_LINUX_INPUT_H */
152