Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015 Etienne Gemsa <etienne.gemsa@lse.epita.fr> |
| 3 | * Copyright (c) 2015 Dmitry V. Levin <ldv@altlinux.org> |
| 4 | * All rights reserved. |
| 5 | * |
| 6 | * Redistribution and use in source and binary forms, with or without |
| 7 | * modification, are permitted provided that the following conditions |
| 8 | * are met: |
| 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. |
| 16 | * |
| 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. |
| 27 | */ |
| 28 | |
| 29 | #include "defs.h" |
| 30 | |
| 31 | #ifdef HAVE_LINUX_INPUT_H |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 32 | |
Dmitry V. Levin | 8d85c23 | 2016-05-27 00:39:33 +0000 | [diff] [blame] | 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" |
| 48 | |
| 49 | # ifndef SYN_MAX |
| 50 | # define SYN_MAX 0xf |
| 51 | # endif |
Dmitry V. Levin | 19dadf9 | 2015-02-22 02:50:33 +0300 | [diff] [blame] | 52 | |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 53 | static void |
Dmitry V. Levin | c758ed0 | 2016-05-27 00:40:53 +0000 | [diff] [blame] | 54 | decode_envelope(const struct ff_envelope *envelope) |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 55 | { |
Dmitry V. Levin | c758ed0 | 2016-05-27 00:40:53 +0000 | [diff] [blame] | 56 | tprintf(", envelope={attack_length=%" PRIu16 |
| 57 | ", attack_level=%" PRIu16 |
| 58 | ", fade_length=%" PRIu16 |
| 59 | ", fade_level=%#x}", |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 60 | envelope->attack_length, |
| 61 | envelope->attack_level, |
| 62 | envelope->fade_length, |
| 63 | envelope->fade_level); |
| 64 | } |
| 65 | |
| 66 | static int |
| 67 | ff_effect_ioctl(struct tcb *tcp, long arg) |
| 68 | { |
Dmitry V. Levin | 3a45eb3 | 2016-05-27 00:41:02 +0000 | [diff] [blame] | 69 | tprints(", "); |
| 70 | |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 71 | struct ff_effect ffe; |
| 72 | |
Dmitry V. Levin | 3a45eb3 | 2016-05-27 00:41:02 +0000 | [diff] [blame] | 73 | if (umove_or_printaddr(tcp, arg, &ffe)) |
| 74 | return 1; |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 75 | |
Dmitry V. Levin | 3a45eb3 | 2016-05-27 00:41:02 +0000 | [diff] [blame] | 76 | tprints("{type="); |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 77 | printxval(evdev_ff_types, ffe.type, "FF_???"); |
Dmitry V. Levin | 3a45eb3 | 2016-05-27 00:41:02 +0000 | [diff] [blame] | 78 | tprintf(", id=%" PRIu16 |
| 79 | ", direction=%" PRIu16 ", ", |
| 80 | ffe.id, |
| 81 | ffe.direction); |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 82 | |
Dmitry V. Levin | 3a45eb3 | 2016-05-27 00:41:02 +0000 | [diff] [blame] | 83 | if (abbrev(tcp)) { |
| 84 | tprints("...}"); |
| 85 | return 1; |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 86 | } |
| 87 | |
Dmitry V. Levin | 3a45eb3 | 2016-05-27 00:41:02 +0000 | [diff] [blame] | 88 | tprintf("trigger={button=%" PRIu16 |
| 89 | ", interval=%" PRIu16 "}" |
| 90 | ", replay={length=%" PRIu16 |
| 91 | ", delay=%" PRIu16 "}", |
| 92 | ffe.trigger.button, |
| 93 | ffe.trigger.interval, |
| 94 | ffe.replay.length, |
| 95 | ffe.replay.delay); |
| 96 | |
| 97 | switch (ffe.type) { |
| 98 | case FF_CONSTANT: |
| 99 | tprintf(", constant={level=%" PRId16, |
| 100 | ffe.u.constant.level); |
| 101 | decode_envelope(&ffe.u.constant.envelope); |
| 102 | tprints("}"); |
| 103 | break; |
| 104 | case FF_RAMP: |
| 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); |
| 110 | tprints("}"); |
| 111 | break; |
| 112 | case FF_PERIODIC: |
| 113 | tprintf(", periodic={waveform=%" PRIu16 |
| 114 | ", period=%" PRIu16 |
| 115 | ", magnitude=%" PRId16 |
| 116 | ", offset=%" PRId16 |
| 117 | ", phase=%" PRIu16, |
| 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); |
| 128 | break; |
| 129 | case FF_RUMBLE: |
| 130 | tprintf(", rumble={strong_magnitude=%" PRIu16 |
| 131 | ", weak_magnitude=%" PRIu16 "}", |
| 132 | ffe.u.rumble.strong_magnitude, |
| 133 | ffe.u.rumble.weak_magnitude); |
| 134 | break; |
| 135 | default: |
| 136 | break; |
| 137 | } |
| 138 | |
| 139 | tprints("}"); |
| 140 | |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 141 | return 1; |
| 142 | } |
| 143 | |
| 144 | static int |
| 145 | abs_ioctl(struct tcb *tcp, long arg) |
| 146 | { |
Dmitry V. Levin | e167006 | 2016-05-27 00:41:14 +0000 | [diff] [blame] | 147 | tprints(", "); |
| 148 | |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 149 | struct input_absinfo absinfo; |
| 150 | |
Dmitry V. Levin | e167006 | 2016-05-27 00:41:14 +0000 | [diff] [blame] | 151 | if (!umove_or_printaddr(tcp, arg, &absinfo)) { |
| 152 | tprintf("{value=%u" |
| 153 | ", minimum=%u, ", |
| 154 | absinfo.value, |
| 155 | absinfo.minimum); |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 156 | |
Dmitry V. Levin | e167006 | 2016-05-27 00:41:14 +0000 | [diff] [blame] | 157 | if (!abbrev(tcp)) { |
| 158 | tprintf("maximum=%u" |
| 159 | ", fuzz=%u" |
| 160 | ", flat=%u", |
| 161 | absinfo.maximum, |
| 162 | absinfo.fuzz, |
| 163 | absinfo.flat); |
Dmitry V. Levin | 8d85c23 | 2016-05-27 00:39:33 +0000 | [diff] [blame] | 164 | # ifdef HAVE_STRUCT_INPUT_ABSINFO_RESOLUTION |
Dmitry V. Levin | e167006 | 2016-05-27 00:41:14 +0000 | [diff] [blame] | 165 | tprintf(", resolution=%u", |
| 166 | absinfo.resolution); |
Dmitry V. Levin | 8d85c23 | 2016-05-27 00:39:33 +0000 | [diff] [blame] | 167 | # endif |
Dmitry V. Levin | e167006 | 2016-05-27 00:41:14 +0000 | [diff] [blame] | 168 | } else { |
| 169 | tprints("..."); |
| 170 | } |
| 171 | |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 172 | tprints("}"); |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 173 | } |
Dmitry V. Levin | e167006 | 2016-05-27 00:41:14 +0000 | [diff] [blame] | 174 | |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 175 | return 1; |
| 176 | } |
| 177 | |
| 178 | static int |
| 179 | keycode_ioctl(struct tcb *tcp, long arg) |
| 180 | { |
Dmitry V. Levin | 7954e2a | 2016-05-27 00:41:25 +0000 | [diff] [blame] | 181 | tprints(", "); |
| 182 | |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 183 | unsigned int keycode[2]; |
| 184 | |
Dmitry V. Levin | 7954e2a | 2016-05-27 00:41:25 +0000 | [diff] [blame] | 185 | if (!umove_or_printaddr(tcp, arg, &keycode)) { |
| 186 | tprintf("[%u, ", keycode[0]); |
| 187 | printxval(evdev_keycode, keycode[1], "KEY_???"); |
| 188 | tprints("]"); |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 189 | } |
| 190 | |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 191 | return 1; |
| 192 | } |
| 193 | |
Dmitry V. Levin | 8d85c23 | 2016-05-27 00:39:33 +0000 | [diff] [blame] | 194 | # ifdef EVIOCGKEYCODE_V2 |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 195 | static int |
| 196 | keycode_V2_ioctl(struct tcb *tcp, long arg) |
| 197 | { |
Dmitry V. Levin | 13f8e8f | 2016-05-27 00:41:34 +0000 | [diff] [blame] | 198 | tprints(", "); |
| 199 | |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 200 | struct input_keymap_entry ike; |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 201 | |
Dmitry V. Levin | 13f8e8f | 2016-05-27 00:41:34 +0000 | [diff] [blame] | 202 | if (umove_or_printaddr(tcp, arg, &ike)) |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 203 | return 1; |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 204 | |
Dmitry V. Levin | 13f8e8f | 2016-05-27 00:41:34 +0000 | [diff] [blame] | 205 | tprintf("{flags=%" PRIu8 |
| 206 | ", len=%" PRIu8 ", ", |
| 207 | ike.flags, |
| 208 | ike.len); |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 209 | |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 210 | if (!abbrev(tcp)) { |
Dmitry V. Levin | 7d8b41a | 2015-02-21 23:05:26 +0000 | [diff] [blame] | 211 | unsigned int i; |
| 212 | |
Dmitry V. Levin | 13f8e8f | 2016-05-27 00:41:34 +0000 | [diff] [blame] | 213 | tprintf("index=%" PRIu16 ", keycode=", ike.index); |
Dmitry V. Levin | 7d8b41a | 2015-02-21 23:05:26 +0000 | [diff] [blame] | 214 | printxval(evdev_keycode, ike.keycode, "KEY_???"); |
| 215 | tprints(", scancode=["); |
| 216 | for (i = 0; i < ARRAY_SIZE(ike.scancode); i++) { |
| 217 | if (i > 0) |
| 218 | tprints(", "); |
| 219 | tprintf("%" PRIx8, ike.scancode[i]); |
| 220 | } |
Dmitry V. Levin | 13f8e8f | 2016-05-27 00:41:34 +0000 | [diff] [blame] | 221 | tprints("]"); |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 222 | } else { |
Dmitry V. Levin | 13f8e8f | 2016-05-27 00:41:34 +0000 | [diff] [blame] | 223 | tprints("..."); |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 224 | } |
Dmitry V. Levin | 13f8e8f | 2016-05-27 00:41:34 +0000 | [diff] [blame] | 225 | |
| 226 | tprints("}"); |
| 227 | |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 228 | return 1; |
| 229 | } |
Dmitry V. Levin | 8d85c23 | 2016-05-27 00:39:33 +0000 | [diff] [blame] | 230 | # endif /* EVIOCGKEYCODE_V2 */ |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 231 | |
| 232 | static int |
| 233 | getid_ioctl(struct tcb *tcp, long arg) |
| 234 | { |
Dmitry V. Levin | e54f98a | 2016-05-27 00:41:43 +0000 | [diff] [blame^] | 235 | tprints(", "); |
| 236 | |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 237 | struct input_id id; |
| 238 | |
Dmitry V. Levin | e54f98a | 2016-05-27 00:41:43 +0000 | [diff] [blame^] | 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 "}", |
| 244 | id.bustype, |
| 245 | id.vendor, |
| 246 | id.product, |
| 247 | id.version); |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 248 | |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 249 | return 1; |
| 250 | } |
| 251 | |
| 252 | static int |
| 253 | decode_bitset(struct tcb *tcp, long arg, const struct xlat decode_nr[], |
| 254 | const unsigned int max_nr, const char *dflt) |
| 255 | { |
| 256 | if (!verbose(tcp)) |
| 257 | return 0; |
| 258 | |
| 259 | unsigned int size; |
| 260 | if ((unsigned long) tcp->u_rval > max_nr) |
| 261 | size = max_nr; |
| 262 | else |
| 263 | size = tcp->u_rval; |
| 264 | char decoded_arg[size]; |
| 265 | |
| 266 | if (umoven(tcp, arg, size, decoded_arg) < 0) |
| 267 | return 0; |
| 268 | |
| 269 | tprints(", ["); |
| 270 | |
| 271 | int bit_displayed = 0; |
| 272 | int i = next_set_bit(decoded_arg, 0, size); |
| 273 | if (i < 0) { |
| 274 | tprints(" 0 "); |
| 275 | } else { |
| 276 | printxval(decode_nr, i, dflt); |
| 277 | |
| 278 | while ((i = next_set_bit(decoded_arg, i + 1, size)) > 0) { |
| 279 | if (abbrev(tcp) && bit_displayed >= 3) { |
| 280 | tprints(", ..."); |
| 281 | break; |
| 282 | } |
| 283 | tprints(", "); |
| 284 | printxval(decode_nr, i, dflt); |
| 285 | bit_displayed++; |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | tprints("]"); |
| 290 | |
| 291 | return 1; |
| 292 | } |
| 293 | |
Dmitry V. Levin | 8d85c23 | 2016-05-27 00:39:33 +0000 | [diff] [blame] | 294 | # ifdef EVIOCGMTSLOTS |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 295 | static int |
| 296 | mtslots_ioctl(struct tcb *tcp, const unsigned int code, long arg) |
| 297 | { |
| 298 | const size_t size = _IOC_SIZE(code) / sizeof(int32_t); |
| 299 | if (!size) |
| 300 | return 0; |
| 301 | |
| 302 | int32_t buffer[size]; |
| 303 | |
| 304 | if (!verbose(tcp) || umove(tcp, arg, &buffer) < 0) |
| 305 | return 0; |
| 306 | |
| 307 | tprints(", {code="); |
| 308 | printxval(evdev_mtslots, buffer[0], "ABS_MT_???"); |
| 309 | |
| 310 | unsigned int i; |
| 311 | tprints(", values=["); |
| 312 | |
| 313 | for (i = 1; i < ARRAY_SIZE(buffer); i++) |
| 314 | tprintf("%s%d", i > 1 ? ", " : "", buffer[i]); |
| 315 | |
| 316 | tprints("]}"); |
| 317 | return 1; |
| 318 | } |
Dmitry V. Levin | 8d85c23 | 2016-05-27 00:39:33 +0000 | [diff] [blame] | 319 | # endif /* EVIOCGMTSLOTS */ |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 320 | |
Dmitry V. Levin | 8d85c23 | 2016-05-27 00:39:33 +0000 | [diff] [blame] | 321 | # if defined EVIOCGREP || defined EVIOCSREP |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 322 | static int |
| 323 | repeat_ioctl(struct tcb *tcp, long arg) |
| 324 | { |
Dmitry V. Levin | b679508 | 2015-07-06 22:33:39 +0000 | [diff] [blame] | 325 | tprints(", "); |
| 326 | printpair_int(tcp, arg, "%u"); |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 327 | return 1; |
| 328 | } |
Dmitry V. Levin | 8d85c23 | 2016-05-27 00:39:33 +0000 | [diff] [blame] | 329 | # endif /* EVIOCGREP || EVIOCSREP */ |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 330 | |
| 331 | static int |
Dmitry V. Levin | 53767d8 | 2016-05-27 00:40:18 +0000 | [diff] [blame] | 332 | bit_ioctl(struct tcb *tcp, const unsigned int ev_nr, const long arg) |
| 333 | { |
| 334 | switch (ev_nr) { |
| 335 | case EV_SYN: |
| 336 | return decode_bitset(tcp, arg, evdev_sync, |
| 337 | SYN_MAX, "SYN_???"); |
| 338 | case EV_KEY: |
| 339 | return decode_bitset(tcp, arg, evdev_keycode, |
| 340 | KEY_MAX, "KEY_???"); |
| 341 | case EV_REL: |
| 342 | return decode_bitset(tcp, arg, evdev_relative_axes, |
| 343 | REL_MAX, "REL_???"); |
| 344 | case EV_ABS: |
| 345 | return decode_bitset(tcp, arg, |
| 346 | evdev_abs, ABS_MAX, "ABS_???"); |
| 347 | case EV_MSC: |
| 348 | return decode_bitset(tcp, arg, |
| 349 | evdev_misc, MSC_MAX, "MSC_???"); |
| 350 | # ifdef EV_SW |
| 351 | case EV_SW: |
| 352 | return decode_bitset(tcp, arg, |
| 353 | evdev_switch, SW_MAX, "SW_???"); |
| 354 | # endif |
| 355 | case EV_LED: |
| 356 | return decode_bitset(tcp, arg, |
| 357 | evdev_leds, LED_MAX, "LED_???"); |
| 358 | case EV_SND: |
| 359 | return decode_bitset(tcp, arg, |
| 360 | evdev_snd, SND_MAX, "SND_???"); |
| 361 | case EV_REP: |
| 362 | return decode_bitset(tcp, arg, evdev_autorepeat, |
| 363 | REP_MAX, "REP_???"); |
| 364 | case EV_FF: |
| 365 | return decode_bitset(tcp, arg, evdev_ff_types, |
| 366 | FF_MAX, "FF_???"); |
| 367 | case EV_PWR: |
| 368 | printnum_int(tcp, arg, "%d"); |
| 369 | return 1; |
| 370 | case EV_FF_STATUS: |
| 371 | return decode_bitset(tcp, arg, evdev_ff_status, |
| 372 | FF_STATUS_MAX, "FF_STATUS_???"); |
| 373 | default: |
| 374 | return 0; |
| 375 | } |
| 376 | } |
| 377 | |
| 378 | static int |
Dmitry V. Levin | 8a18f80 | 2016-05-27 00:40:10 +0000 | [diff] [blame] | 379 | evdev_read_ioctl(struct tcb *tcp, const unsigned int code, const long arg) |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 380 | { |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 381 | if (syserror(tcp)) |
| 382 | return 0; |
| 383 | |
Dmitry V. Levin | 8a18f80 | 2016-05-27 00:40:10 +0000 | [diff] [blame] | 384 | /* fixed-number fixed-length commands */ |
| 385 | switch (code) { |
| 386 | case EVIOCGVERSION: |
| 387 | tprints(", "); |
| 388 | printnum_int(tcp, arg, "%" PRIx32); |
| 389 | return 1; |
| 390 | case EVIOCGEFFECTS: |
| 391 | tprints(", "); |
| 392 | printnum_int(tcp, arg, "%" PRIu32); |
| 393 | return 1; |
| 394 | case EVIOCGID: |
| 395 | return getid_ioctl(tcp, arg); |
| 396 | # ifdef EVIOCGREP |
| 397 | case EVIOCGREP: |
| 398 | return repeat_ioctl(tcp, arg);; |
| 399 | # endif |
| 400 | case EVIOCGKEYCODE: |
| 401 | return keycode_ioctl(tcp, arg); |
| 402 | # ifdef EVIOCGKEYCODE_V2 |
| 403 | case EVIOCGKEYCODE_V2: |
| 404 | return keycode_V2_ioctl(tcp, arg); |
| 405 | # endif |
| 406 | } |
| 407 | |
| 408 | /* fixed-number variable-length commands */ |
| 409 | switch (_IOC_NR(code)) { |
| 410 | # ifdef EVIOCGMTSLOTS |
| 411 | case _IOC_NR(EVIOCGMTSLOTS(0)): |
| 412 | return mtslots_ioctl(tcp, code, arg); |
| 413 | # endif |
| 414 | case _IOC_NR(EVIOCGNAME(0)): |
| 415 | case _IOC_NR(EVIOCGPHYS(0)): |
| 416 | case _IOC_NR(EVIOCGUNIQ(0)): |
| 417 | tprints(", "); |
| 418 | printstr(tcp, arg, tcp->u_rval - 1); |
| 419 | return 1; |
| 420 | # ifdef EVIOCGPROP |
| 421 | case _IOC_NR(EVIOCGPROP(0)): |
| 422 | return decode_bitset(tcp, arg, |
| 423 | evdev_prop, INPUT_PROP_MAX, "PROP_???"); |
| 424 | # endif |
| 425 | case _IOC_NR(EVIOCGSND(0)): |
| 426 | return decode_bitset(tcp, arg, |
| 427 | evdev_snd, SND_MAX, "SND_???"); |
| 428 | # ifdef EVIOCGSW |
| 429 | case _IOC_NR(EVIOCGSW(0)): |
| 430 | return decode_bitset(tcp, arg, |
| 431 | evdev_switch, SW_MAX, "SW_???"); |
| 432 | # endif |
| 433 | case _IOC_NR(EVIOCGKEY(0)): |
| 434 | return decode_bitset(tcp, arg, |
| 435 | evdev_keycode, KEY_MAX, "KEY_???"); |
| 436 | case _IOC_NR(EVIOCGLED(0)): |
| 437 | return decode_bitset(tcp, arg, |
| 438 | evdev_leds, LED_MAX, "LED_???"); |
| 439 | } |
| 440 | |
| 441 | /* multi-number fixed-length commands */ |
| 442 | if ((_IOC_NR(code) & ~ABS_MAX) == _IOC_NR(EVIOCGABS(0))) |
| 443 | return abs_ioctl(tcp, arg); |
| 444 | |
| 445 | /* multi-number variable-length commands */ |
Dmitry V. Levin | 53767d8 | 2016-05-27 00:40:18 +0000 | [diff] [blame] | 446 | if ((_IOC_NR(code) & ~EV_MAX) == _IOC_NR(EVIOCGBIT(0, 0))) |
| 447 | return bit_ioctl(tcp, _IOC_NR(code) & EV_MAX, arg); |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 448 | |
Dmitry V. Levin | 8a18f80 | 2016-05-27 00:40:10 +0000 | [diff] [blame] | 449 | return 0; |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | static int |
Dmitry V. Levin | 8a18f80 | 2016-05-27 00:40:10 +0000 | [diff] [blame] | 453 | evdev_write_ioctl(struct tcb *tcp, const unsigned int code, const long arg) |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 454 | { |
Dmitry V. Levin | 8a18f80 | 2016-05-27 00:40:10 +0000 | [diff] [blame] | 455 | /* fixed-number fixed-length commands */ |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 456 | switch (code) { |
Dmitry V. Levin | 8d85c23 | 2016-05-27 00:39:33 +0000 | [diff] [blame] | 457 | # ifdef EVIOCSREP |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 458 | case EVIOCSREP: |
| 459 | return repeat_ioctl(tcp, arg); |
Dmitry V. Levin | 8d85c23 | 2016-05-27 00:39:33 +0000 | [diff] [blame] | 460 | # endif |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 461 | case EVIOCSKEYCODE: |
| 462 | return keycode_ioctl(tcp, arg); |
Dmitry V. Levin | 8d85c23 | 2016-05-27 00:39:33 +0000 | [diff] [blame] | 463 | # ifdef EVIOCSKEYCODE_V2 |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 464 | case EVIOCSKEYCODE_V2: |
| 465 | return keycode_V2_ioctl(tcp, arg); |
Dmitry V. Levin | 8d85c23 | 2016-05-27 00:39:33 +0000 | [diff] [blame] | 466 | # endif |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 467 | case EVIOCSFF: |
| 468 | return ff_effect_ioctl(tcp, arg); |
| 469 | case EVIOCRMFF: |
Dmitry V. Levin | 0039424 | 2016-05-27 00:40:27 +0000 | [diff] [blame] | 470 | tprintf(", %d", (int) arg); |
| 471 | return 1; |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 472 | case EVIOCGRAB: |
Dmitry V. Levin | 8d85c23 | 2016-05-27 00:39:33 +0000 | [diff] [blame] | 473 | # ifdef EVIOCREVOKE |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 474 | case EVIOCREVOKE: |
Dmitry V. Levin | 8d85c23 | 2016-05-27 00:39:33 +0000 | [diff] [blame] | 475 | # endif |
Dmitry V. Levin | 9635df4 | 2016-05-27 00:40:45 +0000 | [diff] [blame] | 476 | tprintf(", %lu", arg); |
| 477 | return 1; |
| 478 | # ifdef EVIOCSCLOCKID |
| 479 | case EVIOCSCLOCKID: |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 480 | tprints(", "); |
| 481 | printnum_int(tcp, arg, "%u"); |
| 482 | return 1; |
Dmitry V. Levin | 9635df4 | 2016-05-27 00:40:45 +0000 | [diff] [blame] | 483 | # endif |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 484 | } |
Dmitry V. Levin | 8a18f80 | 2016-05-27 00:40:10 +0000 | [diff] [blame] | 485 | |
| 486 | /* multi-number fixed-length commands */ |
| 487 | if ((_IOC_NR(code) & ~ABS_MAX) == _IOC_NR(EVIOCSABS(0))) |
| 488 | return abs_ioctl(tcp, arg); |
| 489 | |
| 490 | return 0; |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | int |
| 494 | evdev_ioctl(struct tcb *tcp, const unsigned int code, long arg) |
| 495 | { |
| 496 | switch(_IOC_DIR(code)) { |
| 497 | case _IOC_READ: |
Dmitry V. Levin | 2114e08 | 2016-05-27 00:40:02 +0000 | [diff] [blame] | 498 | if (entering(tcp)) |
| 499 | return 0; |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 500 | return evdev_read_ioctl(tcp, code, arg); |
| 501 | case _IOC_WRITE: |
Dmitry V. Levin | 2114e08 | 2016-05-27 00:40:02 +0000 | [diff] [blame] | 502 | return evdev_write_ioctl(tcp, code, arg) | RVAL_DECODED; |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 503 | default: |
Dmitry V. Levin | 2114e08 | 2016-05-27 00:40:02 +0000 | [diff] [blame] | 504 | return RVAL_DECODED; |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 505 | } |
| 506 | } |
| 507 | |
| 508 | #endif /* HAVE_LINUX_INPUT_H */ |