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 | { |
| 147 | struct input_absinfo absinfo; |
| 148 | |
| 149 | if (!verbose(tcp) || umove(tcp, arg, &absinfo) < 0) |
| 150 | return 0; |
| 151 | |
| 152 | tprintf(", {value=%" PRIu32 ", minimum=%" PRIu32, |
| 153 | absinfo.value, absinfo.minimum); |
| 154 | if (!abbrev(tcp)) { |
| 155 | tprintf(", maximum=%" PRIu32 ", fuzz=%" PRIu32, |
| 156 | absinfo.maximum, absinfo.fuzz); |
Dmitry V. Levin | 19dadf9 | 2015-02-22 02:50:33 +0300 | [diff] [blame] | 157 | tprintf(", flat=%" PRIu32, absinfo.flat); |
Dmitry V. Levin | 8d85c23 | 2016-05-27 00:39:33 +0000 | [diff] [blame] | 158 | # ifdef HAVE_STRUCT_INPUT_ABSINFO_RESOLUTION |
Dmitry V. Levin | 19dadf9 | 2015-02-22 02:50:33 +0300 | [diff] [blame] | 159 | tprintf(", resolution=%" PRIu32, absinfo.resolution); |
Dmitry V. Levin | 8d85c23 | 2016-05-27 00:39:33 +0000 | [diff] [blame] | 160 | # endif |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 161 | tprints("}"); |
| 162 | } else { |
| 163 | tprints(", ...}"); |
| 164 | } |
| 165 | return 1; |
| 166 | } |
| 167 | |
| 168 | static int |
| 169 | keycode_ioctl(struct tcb *tcp, long arg) |
| 170 | { |
| 171 | unsigned int keycode[2]; |
| 172 | |
| 173 | if (!arg) { |
| 174 | tprints(", NULL"); |
| 175 | return 1; |
| 176 | } |
| 177 | |
| 178 | if (!verbose(tcp) || umove(tcp, arg, &keycode) < 0) |
| 179 | return 0; |
| 180 | |
| 181 | tprintf(", [%u, ", keycode[0]); |
| 182 | printxval(evdev_keycode, keycode[1], "KEY_???"); |
| 183 | tprints("]"); |
| 184 | return 1; |
| 185 | } |
| 186 | |
Dmitry V. Levin | 8d85c23 | 2016-05-27 00:39:33 +0000 | [diff] [blame] | 187 | # ifdef EVIOCGKEYCODE_V2 |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 188 | static int |
| 189 | keycode_V2_ioctl(struct tcb *tcp, long arg) |
| 190 | { |
| 191 | struct input_keymap_entry ike; |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 192 | |
| 193 | if (!arg) { |
| 194 | tprints(", NULL"); |
| 195 | return 1; |
| 196 | } |
| 197 | |
| 198 | if (!verbose(tcp) || umove(tcp, arg, &ike) < 0) |
| 199 | return 0; |
| 200 | |
Dmitry V. Levin | 7d8b41a | 2015-02-21 23:05:26 +0000 | [diff] [blame] | 201 | tprintf(", {flags=%" PRIu8 ", len=%" PRIu8, ike.flags, ike.len); |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 202 | if (!abbrev(tcp)) { |
Dmitry V. Levin | 7d8b41a | 2015-02-21 23:05:26 +0000 | [diff] [blame] | 203 | unsigned int i; |
| 204 | |
| 205 | tprintf(", index=%" PRIu16 ", keycode=", ike.index); |
| 206 | printxval(evdev_keycode, ike.keycode, "KEY_???"); |
| 207 | tprints(", scancode=["); |
| 208 | for (i = 0; i < ARRAY_SIZE(ike.scancode); i++) { |
| 209 | if (i > 0) |
| 210 | tprints(", "); |
| 211 | tprintf("%" PRIx8, ike.scancode[i]); |
| 212 | } |
| 213 | tprints("]}"); |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 214 | } else { |
| 215 | tprints(", ...}"); |
| 216 | } |
| 217 | return 1; |
| 218 | } |
Dmitry V. Levin | 8d85c23 | 2016-05-27 00:39:33 +0000 | [diff] [blame] | 219 | # endif /* EVIOCGKEYCODE_V2 */ |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 220 | |
| 221 | static int |
| 222 | getid_ioctl(struct tcb *tcp, long arg) |
| 223 | { |
| 224 | struct input_id id; |
| 225 | |
| 226 | if (!verbose(tcp) || umove(tcp, arg, &id) < 0) |
| 227 | return 0; |
| 228 | |
| 229 | tprintf(", {ID_BUS=%" PRIu16 ", ID_VENDOR=%" PRIu16, |
| 230 | id.bustype, id.vendor); |
| 231 | if (!abbrev(tcp)) { |
| 232 | tprintf(", ID_PRODUCT=%" PRIu16 ", ID_VERSION=%" PRIu16 "}", |
| 233 | id.product, id.version); |
| 234 | } else { |
| 235 | tprints(", ...}"); |
| 236 | } |
| 237 | return 1; |
| 238 | } |
| 239 | |
| 240 | static int |
| 241 | decode_bitset(struct tcb *tcp, long arg, const struct xlat decode_nr[], |
| 242 | const unsigned int max_nr, const char *dflt) |
| 243 | { |
| 244 | if (!verbose(tcp)) |
| 245 | return 0; |
| 246 | |
| 247 | unsigned int size; |
| 248 | if ((unsigned long) tcp->u_rval > max_nr) |
| 249 | size = max_nr; |
| 250 | else |
| 251 | size = tcp->u_rval; |
| 252 | char decoded_arg[size]; |
| 253 | |
| 254 | if (umoven(tcp, arg, size, decoded_arg) < 0) |
| 255 | return 0; |
| 256 | |
| 257 | tprints(", ["); |
| 258 | |
| 259 | int bit_displayed = 0; |
| 260 | int i = next_set_bit(decoded_arg, 0, size); |
| 261 | if (i < 0) { |
| 262 | tprints(" 0 "); |
| 263 | } else { |
| 264 | printxval(decode_nr, i, dflt); |
| 265 | |
| 266 | while ((i = next_set_bit(decoded_arg, i + 1, size)) > 0) { |
| 267 | if (abbrev(tcp) && bit_displayed >= 3) { |
| 268 | tprints(", ..."); |
| 269 | break; |
| 270 | } |
| 271 | tprints(", "); |
| 272 | printxval(decode_nr, i, dflt); |
| 273 | bit_displayed++; |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | tprints("]"); |
| 278 | |
| 279 | return 1; |
| 280 | } |
| 281 | |
Dmitry V. Levin | 8d85c23 | 2016-05-27 00:39:33 +0000 | [diff] [blame] | 282 | # ifdef EVIOCGMTSLOTS |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 283 | static int |
| 284 | mtslots_ioctl(struct tcb *tcp, const unsigned int code, long arg) |
| 285 | { |
| 286 | const size_t size = _IOC_SIZE(code) / sizeof(int32_t); |
| 287 | if (!size) |
| 288 | return 0; |
| 289 | |
| 290 | int32_t buffer[size]; |
| 291 | |
| 292 | if (!verbose(tcp) || umove(tcp, arg, &buffer) < 0) |
| 293 | return 0; |
| 294 | |
| 295 | tprints(", {code="); |
| 296 | printxval(evdev_mtslots, buffer[0], "ABS_MT_???"); |
| 297 | |
| 298 | unsigned int i; |
| 299 | tprints(", values=["); |
| 300 | |
| 301 | for (i = 1; i < ARRAY_SIZE(buffer); i++) |
| 302 | tprintf("%s%d", i > 1 ? ", " : "", buffer[i]); |
| 303 | |
| 304 | tprints("]}"); |
| 305 | return 1; |
| 306 | } |
Dmitry V. Levin | 8d85c23 | 2016-05-27 00:39:33 +0000 | [diff] [blame] | 307 | # endif /* EVIOCGMTSLOTS */ |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 308 | |
Dmitry V. Levin | 8d85c23 | 2016-05-27 00:39:33 +0000 | [diff] [blame] | 309 | # if defined EVIOCGREP || defined EVIOCSREP |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 310 | static int |
| 311 | repeat_ioctl(struct tcb *tcp, long arg) |
| 312 | { |
Dmitry V. Levin | b679508 | 2015-07-06 22:33:39 +0000 | [diff] [blame] | 313 | tprints(", "); |
| 314 | printpair_int(tcp, arg, "%u"); |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 315 | return 1; |
| 316 | } |
Dmitry V. Levin | 8d85c23 | 2016-05-27 00:39:33 +0000 | [diff] [blame] | 317 | # endif /* EVIOCGREP || EVIOCSREP */ |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 318 | |
| 319 | static int |
Dmitry V. Levin | 53767d8 | 2016-05-27 00:40:18 +0000 | [diff] [blame] | 320 | bit_ioctl(struct tcb *tcp, const unsigned int ev_nr, const long arg) |
| 321 | { |
| 322 | switch (ev_nr) { |
| 323 | case EV_SYN: |
| 324 | return decode_bitset(tcp, arg, evdev_sync, |
| 325 | SYN_MAX, "SYN_???"); |
| 326 | case EV_KEY: |
| 327 | return decode_bitset(tcp, arg, evdev_keycode, |
| 328 | KEY_MAX, "KEY_???"); |
| 329 | case EV_REL: |
| 330 | return decode_bitset(tcp, arg, evdev_relative_axes, |
| 331 | REL_MAX, "REL_???"); |
| 332 | case EV_ABS: |
| 333 | return decode_bitset(tcp, arg, |
| 334 | evdev_abs, ABS_MAX, "ABS_???"); |
| 335 | case EV_MSC: |
| 336 | return decode_bitset(tcp, arg, |
| 337 | evdev_misc, MSC_MAX, "MSC_???"); |
| 338 | # ifdef EV_SW |
| 339 | case EV_SW: |
| 340 | return decode_bitset(tcp, arg, |
| 341 | evdev_switch, SW_MAX, "SW_???"); |
| 342 | # endif |
| 343 | case EV_LED: |
| 344 | return decode_bitset(tcp, arg, |
| 345 | evdev_leds, LED_MAX, "LED_???"); |
| 346 | case EV_SND: |
| 347 | return decode_bitset(tcp, arg, |
| 348 | evdev_snd, SND_MAX, "SND_???"); |
| 349 | case EV_REP: |
| 350 | return decode_bitset(tcp, arg, evdev_autorepeat, |
| 351 | REP_MAX, "REP_???"); |
| 352 | case EV_FF: |
| 353 | return decode_bitset(tcp, arg, evdev_ff_types, |
| 354 | FF_MAX, "FF_???"); |
| 355 | case EV_PWR: |
| 356 | printnum_int(tcp, arg, "%d"); |
| 357 | return 1; |
| 358 | case EV_FF_STATUS: |
| 359 | return decode_bitset(tcp, arg, evdev_ff_status, |
| 360 | FF_STATUS_MAX, "FF_STATUS_???"); |
| 361 | default: |
| 362 | return 0; |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | static int |
Dmitry V. Levin | 8a18f80 | 2016-05-27 00:40:10 +0000 | [diff] [blame] | 367 | 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] | 368 | { |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 369 | if (syserror(tcp)) |
| 370 | return 0; |
| 371 | |
Dmitry V. Levin | 8a18f80 | 2016-05-27 00:40:10 +0000 | [diff] [blame] | 372 | /* fixed-number fixed-length commands */ |
| 373 | switch (code) { |
| 374 | case EVIOCGVERSION: |
| 375 | tprints(", "); |
| 376 | printnum_int(tcp, arg, "%" PRIx32); |
| 377 | return 1; |
| 378 | case EVIOCGEFFECTS: |
| 379 | tprints(", "); |
| 380 | printnum_int(tcp, arg, "%" PRIu32); |
| 381 | return 1; |
| 382 | case EVIOCGID: |
| 383 | return getid_ioctl(tcp, arg); |
| 384 | # ifdef EVIOCGREP |
| 385 | case EVIOCGREP: |
| 386 | return repeat_ioctl(tcp, arg);; |
| 387 | # endif |
| 388 | case EVIOCGKEYCODE: |
| 389 | return keycode_ioctl(tcp, arg); |
| 390 | # ifdef EVIOCGKEYCODE_V2 |
| 391 | case EVIOCGKEYCODE_V2: |
| 392 | return keycode_V2_ioctl(tcp, arg); |
| 393 | # endif |
| 394 | } |
| 395 | |
| 396 | /* fixed-number variable-length commands */ |
| 397 | switch (_IOC_NR(code)) { |
| 398 | # ifdef EVIOCGMTSLOTS |
| 399 | case _IOC_NR(EVIOCGMTSLOTS(0)): |
| 400 | return mtslots_ioctl(tcp, code, arg); |
| 401 | # endif |
| 402 | case _IOC_NR(EVIOCGNAME(0)): |
| 403 | case _IOC_NR(EVIOCGPHYS(0)): |
| 404 | case _IOC_NR(EVIOCGUNIQ(0)): |
| 405 | tprints(", "); |
| 406 | printstr(tcp, arg, tcp->u_rval - 1); |
| 407 | return 1; |
| 408 | # ifdef EVIOCGPROP |
| 409 | case _IOC_NR(EVIOCGPROP(0)): |
| 410 | return decode_bitset(tcp, arg, |
| 411 | evdev_prop, INPUT_PROP_MAX, "PROP_???"); |
| 412 | # endif |
| 413 | case _IOC_NR(EVIOCGSND(0)): |
| 414 | return decode_bitset(tcp, arg, |
| 415 | evdev_snd, SND_MAX, "SND_???"); |
| 416 | # ifdef EVIOCGSW |
| 417 | case _IOC_NR(EVIOCGSW(0)): |
| 418 | return decode_bitset(tcp, arg, |
| 419 | evdev_switch, SW_MAX, "SW_???"); |
| 420 | # endif |
| 421 | case _IOC_NR(EVIOCGKEY(0)): |
| 422 | return decode_bitset(tcp, arg, |
| 423 | evdev_keycode, KEY_MAX, "KEY_???"); |
| 424 | case _IOC_NR(EVIOCGLED(0)): |
| 425 | return decode_bitset(tcp, arg, |
| 426 | evdev_leds, LED_MAX, "LED_???"); |
| 427 | } |
| 428 | |
| 429 | /* multi-number fixed-length commands */ |
| 430 | if ((_IOC_NR(code) & ~ABS_MAX) == _IOC_NR(EVIOCGABS(0))) |
| 431 | return abs_ioctl(tcp, arg); |
| 432 | |
| 433 | /* multi-number variable-length commands */ |
Dmitry V. Levin | 53767d8 | 2016-05-27 00:40:18 +0000 | [diff] [blame] | 434 | if ((_IOC_NR(code) & ~EV_MAX) == _IOC_NR(EVIOCGBIT(0, 0))) |
| 435 | return bit_ioctl(tcp, _IOC_NR(code) & EV_MAX, arg); |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 436 | |
Dmitry V. Levin | 8a18f80 | 2016-05-27 00:40:10 +0000 | [diff] [blame] | 437 | return 0; |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | static int |
Dmitry V. Levin | 8a18f80 | 2016-05-27 00:40:10 +0000 | [diff] [blame] | 441 | 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] | 442 | { |
Dmitry V. Levin | 8a18f80 | 2016-05-27 00:40:10 +0000 | [diff] [blame] | 443 | /* fixed-number fixed-length commands */ |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 444 | switch (code) { |
Dmitry V. Levin | 8d85c23 | 2016-05-27 00:39:33 +0000 | [diff] [blame] | 445 | # ifdef EVIOCSREP |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 446 | case EVIOCSREP: |
| 447 | return repeat_ioctl(tcp, arg); |
Dmitry V. Levin | 8d85c23 | 2016-05-27 00:39:33 +0000 | [diff] [blame] | 448 | # endif |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 449 | case EVIOCSKEYCODE: |
| 450 | return keycode_ioctl(tcp, arg); |
Dmitry V. Levin | 8d85c23 | 2016-05-27 00:39:33 +0000 | [diff] [blame] | 451 | # ifdef EVIOCSKEYCODE_V2 |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 452 | case EVIOCSKEYCODE_V2: |
| 453 | return keycode_V2_ioctl(tcp, arg); |
Dmitry V. Levin | 8d85c23 | 2016-05-27 00:39:33 +0000 | [diff] [blame] | 454 | # endif |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 455 | case EVIOCSFF: |
| 456 | return ff_effect_ioctl(tcp, arg); |
| 457 | case EVIOCRMFF: |
Dmitry V. Levin | 0039424 | 2016-05-27 00:40:27 +0000 | [diff] [blame] | 458 | tprintf(", %d", (int) arg); |
| 459 | return 1; |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 460 | case EVIOCGRAB: |
Dmitry V. Levin | 8d85c23 | 2016-05-27 00:39:33 +0000 | [diff] [blame] | 461 | # ifdef EVIOCREVOKE |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 462 | case EVIOCREVOKE: |
Dmitry V. Levin | 8d85c23 | 2016-05-27 00:39:33 +0000 | [diff] [blame] | 463 | # endif |
Dmitry V. Levin | 9635df4 | 2016-05-27 00:40:45 +0000 | [diff] [blame] | 464 | tprintf(", %lu", arg); |
| 465 | return 1; |
| 466 | # ifdef EVIOCSCLOCKID |
| 467 | case EVIOCSCLOCKID: |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 468 | tprints(", "); |
| 469 | printnum_int(tcp, arg, "%u"); |
| 470 | return 1; |
Dmitry V. Levin | 9635df4 | 2016-05-27 00:40:45 +0000 | [diff] [blame] | 471 | # endif |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 472 | } |
Dmitry V. Levin | 8a18f80 | 2016-05-27 00:40:10 +0000 | [diff] [blame] | 473 | |
| 474 | /* multi-number fixed-length commands */ |
| 475 | if ((_IOC_NR(code) & ~ABS_MAX) == _IOC_NR(EVIOCSABS(0))) |
| 476 | return abs_ioctl(tcp, arg); |
| 477 | |
| 478 | return 0; |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 479 | } |
| 480 | |
| 481 | int |
| 482 | evdev_ioctl(struct tcb *tcp, const unsigned int code, long arg) |
| 483 | { |
| 484 | switch(_IOC_DIR(code)) { |
| 485 | case _IOC_READ: |
Dmitry V. Levin | 2114e08 | 2016-05-27 00:40:02 +0000 | [diff] [blame] | 486 | if (entering(tcp)) |
| 487 | return 0; |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 488 | return evdev_read_ioctl(tcp, code, arg); |
| 489 | case _IOC_WRITE: |
Dmitry V. Levin | 2114e08 | 2016-05-27 00:40:02 +0000 | [diff] [blame] | 490 | return evdev_write_ioctl(tcp, code, arg) | RVAL_DECODED; |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 491 | default: |
Dmitry V. Levin | 2114e08 | 2016-05-27 00:40:02 +0000 | [diff] [blame] | 492 | return RVAL_DECODED; |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 493 | } |
| 494 | } |
| 495 | |
| 496 | #endif /* HAVE_LINUX_INPUT_H */ |