Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015 Etienne Gemsa <etienne.gemsa@lse.epita.fr> |
Dmitry V. Levin | 43c8a5d | 2016-05-27 00:49:08 +0000 | [diff] [blame] | 3 | * Copyright (c) 2015-2016 Dmitry V. Levin <ldv@altlinux.org> |
Elliott Hughes | 28e98bc | 2018-06-14 16:59:04 -0700 | [diff] [blame] | 4 | * Copyright (c) 2015-2018 The strace developers. |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 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 | |
Elliott Hughes | 03a418e | 2018-06-15 13:11:40 -0700 | [diff] [blame] | 32 | #include "xlat/evdev_abs.h" |
Elliott Hughes | c187376 | 2018-12-19 15:13:36 -0800 | [diff] [blame^] | 33 | #include "xlat/evdev_ev.h" |
Elliott Hughes | 03a418e | 2018-06-15 13:11:40 -0700 | [diff] [blame] | 34 | |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 35 | #ifdef HAVE_LINUX_INPUT_H |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 36 | |
Dmitry V. Levin | 8d85c23 | 2016-05-27 00:39:33 +0000 | [diff] [blame] | 37 | # include <linux/ioctl.h> |
| 38 | # include <linux/input.h> |
Dmitry V. Levin | 43c8a5d | 2016-05-27 00:49:08 +0000 | [diff] [blame] | 39 | |
Dmitry V. Levin | 8d85c23 | 2016-05-27 00:39:33 +0000 | [diff] [blame] | 40 | # include "xlat/evdev_autorepeat.h" |
| 41 | # include "xlat/evdev_ff_status.h" |
| 42 | # include "xlat/evdev_ff_types.h" |
| 43 | # include "xlat/evdev_keycode.h" |
| 44 | # include "xlat/evdev_leds.h" |
| 45 | # include "xlat/evdev_misc.h" |
| 46 | # include "xlat/evdev_mtslots.h" |
| 47 | # include "xlat/evdev_prop.h" |
| 48 | # include "xlat/evdev_relative_axes.h" |
| 49 | # include "xlat/evdev_snd.h" |
| 50 | # include "xlat/evdev_switch.h" |
Dmitry V. Levin | 8d85c23 | 2016-05-27 00:39:33 +0000 | [diff] [blame] | 51 | |
| 52 | # ifndef SYN_MAX |
| 53 | # define SYN_MAX 0xf |
| 54 | # endif |
Dmitry V. Levin | 19dadf9 | 2015-02-22 02:50:33 +0300 | [diff] [blame] | 55 | |
Elliott Hughes | 03a418e | 2018-06-15 13:11:40 -0700 | [diff] [blame] | 56 | const size_t evdev_abs_size = ARRAY_SIZE(evdev_abs) - 1; |
| 57 | |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 58 | static int |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 59 | abs_ioctl(struct tcb *const tcp, const kernel_ulong_t arg) |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 60 | { |
Dmitry V. Levin | e167006 | 2016-05-27 00:41:14 +0000 | [diff] [blame] | 61 | tprints(", "); |
| 62 | |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 63 | struct input_absinfo absinfo; |
| 64 | |
Dmitry V. Levin | e167006 | 2016-05-27 00:41:14 +0000 | [diff] [blame] | 65 | if (!umove_or_printaddr(tcp, arg, &absinfo)) { |
| 66 | tprintf("{value=%u" |
| 67 | ", minimum=%u, ", |
| 68 | absinfo.value, |
| 69 | absinfo.minimum); |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 70 | |
Dmitry V. Levin | e167006 | 2016-05-27 00:41:14 +0000 | [diff] [blame] | 71 | if (!abbrev(tcp)) { |
| 72 | tprintf("maximum=%u" |
| 73 | ", fuzz=%u" |
| 74 | ", flat=%u", |
| 75 | absinfo.maximum, |
| 76 | absinfo.fuzz, |
| 77 | absinfo.flat); |
Dmitry V. Levin | 8d85c23 | 2016-05-27 00:39:33 +0000 | [diff] [blame] | 78 | # ifdef HAVE_STRUCT_INPUT_ABSINFO_RESOLUTION |
Dmitry V. Levin | e167006 | 2016-05-27 00:41:14 +0000 | [diff] [blame] | 79 | tprintf(", resolution=%u", |
| 80 | absinfo.resolution); |
Dmitry V. Levin | 8d85c23 | 2016-05-27 00:39:33 +0000 | [diff] [blame] | 81 | # endif |
Dmitry V. Levin | e167006 | 2016-05-27 00:41:14 +0000 | [diff] [blame] | 82 | } else { |
| 83 | tprints("..."); |
| 84 | } |
| 85 | |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 86 | tprints("}"); |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 87 | } |
Dmitry V. Levin | e167006 | 2016-05-27 00:41:14 +0000 | [diff] [blame] | 88 | |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 89 | return RVAL_IOCTL_DECODED; |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | static int |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 93 | keycode_ioctl(struct tcb *const tcp, const kernel_ulong_t arg) |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 94 | { |
Dmitry V. Levin | 7954e2a | 2016-05-27 00:41:25 +0000 | [diff] [blame] | 95 | tprints(", "); |
| 96 | |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 97 | unsigned int keycode[2]; |
| 98 | |
Dmitry V. Levin | 7954e2a | 2016-05-27 00:41:25 +0000 | [diff] [blame] | 99 | if (!umove_or_printaddr(tcp, arg, &keycode)) { |
| 100 | tprintf("[%u, ", keycode[0]); |
Elliott Hughes | 03a418e | 2018-06-15 13:11:40 -0700 | [diff] [blame] | 101 | printxval_index(evdev_keycode, keycode[1], "KEY_???"); |
Dmitry V. Levin | 7954e2a | 2016-05-27 00:41:25 +0000 | [diff] [blame] | 102 | tprints("]"); |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 103 | } |
| 104 | |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 105 | return RVAL_IOCTL_DECODED; |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 106 | } |
| 107 | |
Dmitry V. Levin | 8d85c23 | 2016-05-27 00:39:33 +0000 | [diff] [blame] | 108 | # ifdef EVIOCGKEYCODE_V2 |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 109 | static int |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 110 | keycode_V2_ioctl(struct tcb *const tcp, const kernel_ulong_t arg) |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 111 | { |
Dmitry V. Levin | 13f8e8f | 2016-05-27 00:41:34 +0000 | [diff] [blame] | 112 | tprints(", "); |
| 113 | |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 114 | struct input_keymap_entry ike; |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 115 | |
Dmitry V. Levin | 13f8e8f | 2016-05-27 00:41:34 +0000 | [diff] [blame] | 116 | if (umove_or_printaddr(tcp, arg, &ike)) |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 117 | return RVAL_IOCTL_DECODED; |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 118 | |
Dmitry V. Levin | 13f8e8f | 2016-05-27 00:41:34 +0000 | [diff] [blame] | 119 | tprintf("{flags=%" PRIu8 |
| 120 | ", len=%" PRIu8 ", ", |
| 121 | ike.flags, |
| 122 | ike.len); |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 123 | |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 124 | if (!abbrev(tcp)) { |
Dmitry V. Levin | 7d8b41a | 2015-02-21 23:05:26 +0000 | [diff] [blame] | 125 | unsigned int i; |
| 126 | |
Dmitry V. Levin | 13f8e8f | 2016-05-27 00:41:34 +0000 | [diff] [blame] | 127 | tprintf("index=%" PRIu16 ", keycode=", ike.index); |
Elliott Hughes | 03a418e | 2018-06-15 13:11:40 -0700 | [diff] [blame] | 128 | printxval_index(evdev_keycode, ike.keycode, "KEY_???"); |
Dmitry V. Levin | 7d8b41a | 2015-02-21 23:05:26 +0000 | [diff] [blame] | 129 | tprints(", scancode=["); |
| 130 | for (i = 0; i < ARRAY_SIZE(ike.scancode); i++) { |
| 131 | if (i > 0) |
| 132 | tprints(", "); |
| 133 | tprintf("%" PRIx8, ike.scancode[i]); |
| 134 | } |
Dmitry V. Levin | 13f8e8f | 2016-05-27 00:41:34 +0000 | [diff] [blame] | 135 | tprints("]"); |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 136 | } else { |
Dmitry V. Levin | 13f8e8f | 2016-05-27 00:41:34 +0000 | [diff] [blame] | 137 | tprints("..."); |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 138 | } |
Dmitry V. Levin | 13f8e8f | 2016-05-27 00:41:34 +0000 | [diff] [blame] | 139 | |
| 140 | tprints("}"); |
| 141 | |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 142 | return RVAL_IOCTL_DECODED; |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 143 | } |
Dmitry V. Levin | 8d85c23 | 2016-05-27 00:39:33 +0000 | [diff] [blame] | 144 | # endif /* EVIOCGKEYCODE_V2 */ |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 145 | |
| 146 | static int |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 147 | getid_ioctl(struct tcb *const tcp, const kernel_ulong_t arg) |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 148 | { |
Dmitry V. Levin | e54f98a | 2016-05-27 00:41:43 +0000 | [diff] [blame] | 149 | tprints(", "); |
| 150 | |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 151 | struct input_id id; |
| 152 | |
Dmitry V. Levin | e54f98a | 2016-05-27 00:41:43 +0000 | [diff] [blame] | 153 | if (!umove_or_printaddr(tcp, arg, &id)) |
| 154 | tprintf("{ID_BUS=%" PRIu16 |
| 155 | ", ID_VENDOR=%" PRIu16 |
| 156 | ", ID_PRODUCT=%" PRIu16 |
| 157 | ", ID_VERSION=%" PRIu16 "}", |
| 158 | id.bustype, |
| 159 | id.vendor, |
| 160 | id.product, |
| 161 | id.version); |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 162 | |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 163 | return RVAL_IOCTL_DECODED; |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | static int |
Elliott Hughes | 03a418e | 2018-06-15 13:11:40 -0700 | [diff] [blame] | 167 | decode_bitset_(struct tcb *const tcp, const kernel_ulong_t arg, |
| 168 | const struct xlat decode_nr[], const unsigned int max_nr, |
| 169 | const char *const dflt, size_t decode_nr_size, enum xlat_type xt) |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 170 | { |
Dmitry V. Levin | 14a810e | 2016-05-27 00:41:51 +0000 | [diff] [blame] | 171 | tprints(", "); |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 172 | |
| 173 | unsigned int size; |
Elliott Hughes | c187376 | 2018-12-19 15:13:36 -0800 | [diff] [blame^] | 174 | if ((kernel_ulong_t) tcp->u_rval > max_nr / 8) |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 175 | size = max_nr; |
| 176 | else |
Elliott Hughes | c187376 | 2018-12-19 15:13:36 -0800 | [diff] [blame^] | 177 | size = tcp->u_rval * 8; |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 178 | char decoded_arg[size]; |
| 179 | |
Dmitry V. Levin | 14a810e | 2016-05-27 00:41:51 +0000 | [diff] [blame] | 180 | if (umove_or_printaddr(tcp, arg, &decoded_arg)) |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 181 | return RVAL_IOCTL_DECODED; |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 182 | |
Dmitry V. Levin | 14a810e | 2016-05-27 00:41:51 +0000 | [diff] [blame] | 183 | tprints("["); |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 184 | |
| 185 | int bit_displayed = 0; |
| 186 | int i = next_set_bit(decoded_arg, 0, size); |
| 187 | if (i < 0) { |
| 188 | tprints(" 0 "); |
| 189 | } else { |
Elliott Hughes | 03a418e | 2018-06-15 13:11:40 -0700 | [diff] [blame] | 190 | printxval_dispatch(decode_nr, decode_nr_size, i, dflt, xt); |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 191 | |
| 192 | while ((i = next_set_bit(decoded_arg, i + 1, size)) > 0) { |
| 193 | if (abbrev(tcp) && bit_displayed >= 3) { |
| 194 | tprints(", ..."); |
| 195 | break; |
| 196 | } |
| 197 | tprints(", "); |
Elliott Hughes | 03a418e | 2018-06-15 13:11:40 -0700 | [diff] [blame] | 198 | printxval_dispatch(decode_nr, decode_nr_size, i, dflt, |
| 199 | xt); |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 200 | bit_displayed++; |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | tprints("]"); |
| 205 | |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 206 | return RVAL_IOCTL_DECODED; |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 207 | } |
| 208 | |
Elliott Hughes | 03a418e | 2018-06-15 13:11:40 -0700 | [diff] [blame] | 209 | #define decode_bitset(tcp_, arg_, decode_nr_, max_nr_, dflt_, xt_) \ |
| 210 | decode_bitset_((tcp_), (arg_), (decode_nr_), (max_nr_), \ |
| 211 | (dflt_), ARRAY_SIZE(decode_nr_), (xt_)) |
| 212 | |
Dmitry V. Levin | 8d85c23 | 2016-05-27 00:39:33 +0000 | [diff] [blame] | 213 | # ifdef EVIOCGMTSLOTS |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 214 | static int |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 215 | mtslots_ioctl(struct tcb *const tcp, const unsigned int code, |
| 216 | const kernel_ulong_t arg) |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 217 | { |
Dmitry V. Levin | 563f0ce | 2016-05-27 00:41:59 +0000 | [diff] [blame] | 218 | tprints(", "); |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 219 | |
Dmitry V. Levin | 563f0ce | 2016-05-27 00:41:59 +0000 | [diff] [blame] | 220 | const size_t size = _IOC_SIZE(code) / sizeof(int); |
| 221 | if (!size) { |
| 222 | printaddr(arg); |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 223 | return RVAL_IOCTL_DECODED; |
Dmitry V. Levin | 563f0ce | 2016-05-27 00:41:59 +0000 | [diff] [blame] | 224 | } |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 225 | |
Dmitry V. Levin | 563f0ce | 2016-05-27 00:41:59 +0000 | [diff] [blame] | 226 | int buffer[size]; |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 227 | |
Dmitry V. Levin | 563f0ce | 2016-05-27 00:41:59 +0000 | [diff] [blame] | 228 | if (umove_or_printaddr(tcp, arg, &buffer)) |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 229 | return RVAL_IOCTL_DECODED; |
Dmitry V. Levin | 563f0ce | 2016-05-27 00:41:59 +0000 | [diff] [blame] | 230 | |
| 231 | tprints("{code="); |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 232 | printxval(evdev_mtslots, buffer[0], "ABS_MT_???"); |
| 233 | |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 234 | tprints(", values=["); |
| 235 | |
Dmitry V. Levin | 563f0ce | 2016-05-27 00:41:59 +0000 | [diff] [blame] | 236 | unsigned int i; |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 237 | for (i = 1; i < ARRAY_SIZE(buffer); i++) |
| 238 | tprintf("%s%d", i > 1 ? ", " : "", buffer[i]); |
| 239 | |
| 240 | tprints("]}"); |
Dmitry V. Levin | 563f0ce | 2016-05-27 00:41:59 +0000 | [diff] [blame] | 241 | |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 242 | return RVAL_IOCTL_DECODED; |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 243 | } |
Dmitry V. Levin | 8d85c23 | 2016-05-27 00:39:33 +0000 | [diff] [blame] | 244 | # endif /* EVIOCGMTSLOTS */ |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 245 | |
Dmitry V. Levin | 8d85c23 | 2016-05-27 00:39:33 +0000 | [diff] [blame] | 246 | # if defined EVIOCGREP || defined EVIOCSREP |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 247 | static int |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 248 | repeat_ioctl(struct tcb *const tcp, const kernel_ulong_t arg) |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 249 | { |
Dmitry V. Levin | b679508 | 2015-07-06 22:33:39 +0000 | [diff] [blame] | 250 | tprints(", "); |
| 251 | printpair_int(tcp, arg, "%u"); |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 252 | return RVAL_IOCTL_DECODED; |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 253 | } |
Dmitry V. Levin | 8d85c23 | 2016-05-27 00:39:33 +0000 | [diff] [blame] | 254 | # endif /* EVIOCGREP || EVIOCSREP */ |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 255 | |
| 256 | static int |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 257 | bit_ioctl(struct tcb *const tcp, const unsigned int ev_nr, |
| 258 | const kernel_ulong_t arg) |
Dmitry V. Levin | 53767d8 | 2016-05-27 00:40:18 +0000 | [diff] [blame] | 259 | { |
| 260 | switch (ev_nr) { |
Elliott Hughes | c187376 | 2018-12-19 15:13:36 -0800 | [diff] [blame^] | 261 | case 0: |
| 262 | return decode_bitset(tcp, arg, evdev_ev, |
| 263 | EV_MAX, "EV_???", XT_SORTED); |
Dmitry V. Levin | 53767d8 | 2016-05-27 00:40:18 +0000 | [diff] [blame] | 264 | case EV_KEY: |
| 265 | return decode_bitset(tcp, arg, evdev_keycode, |
Elliott Hughes | 03a418e | 2018-06-15 13:11:40 -0700 | [diff] [blame] | 266 | KEY_MAX, "KEY_???", XT_INDEXED); |
Dmitry V. Levin | 53767d8 | 2016-05-27 00:40:18 +0000 | [diff] [blame] | 267 | case EV_REL: |
| 268 | return decode_bitset(tcp, arg, evdev_relative_axes, |
Elliott Hughes | 03a418e | 2018-06-15 13:11:40 -0700 | [diff] [blame] | 269 | REL_MAX, "REL_???", XT_INDEXED); |
Dmitry V. Levin | 53767d8 | 2016-05-27 00:40:18 +0000 | [diff] [blame] | 270 | case EV_ABS: |
Dmitry V. Levin | 3f23c0c | 2016-05-27 00:42:25 +0000 | [diff] [blame] | 271 | return decode_bitset(tcp, arg, evdev_abs, |
Elliott Hughes | 03a418e | 2018-06-15 13:11:40 -0700 | [diff] [blame] | 272 | ABS_MAX, "ABS_???", XT_INDEXED); |
Dmitry V. Levin | 53767d8 | 2016-05-27 00:40:18 +0000 | [diff] [blame] | 273 | case EV_MSC: |
Dmitry V. Levin | 3f23c0c | 2016-05-27 00:42:25 +0000 | [diff] [blame] | 274 | return decode_bitset(tcp, arg, evdev_misc, |
Elliott Hughes | 03a418e | 2018-06-15 13:11:40 -0700 | [diff] [blame] | 275 | MSC_MAX, "MSC_???", XT_INDEXED); |
Dmitry V. Levin | 53767d8 | 2016-05-27 00:40:18 +0000 | [diff] [blame] | 276 | case EV_SW: |
Dmitry V. Levin | 3f23c0c | 2016-05-27 00:42:25 +0000 | [diff] [blame] | 277 | return decode_bitset(tcp, arg, evdev_switch, |
Elliott Hughes | 03a418e | 2018-06-15 13:11:40 -0700 | [diff] [blame] | 278 | SW_MAX, "SW_???", XT_INDEXED); |
Dmitry V. Levin | 53767d8 | 2016-05-27 00:40:18 +0000 | [diff] [blame] | 279 | case EV_LED: |
Dmitry V. Levin | 3f23c0c | 2016-05-27 00:42:25 +0000 | [diff] [blame] | 280 | return decode_bitset(tcp, arg, evdev_leds, |
Elliott Hughes | 03a418e | 2018-06-15 13:11:40 -0700 | [diff] [blame] | 281 | LED_MAX, "LED_???", XT_INDEXED); |
Dmitry V. Levin | 53767d8 | 2016-05-27 00:40:18 +0000 | [diff] [blame] | 282 | case EV_SND: |
Dmitry V. Levin | 3f23c0c | 2016-05-27 00:42:25 +0000 | [diff] [blame] | 283 | return decode_bitset(tcp, arg, evdev_snd, |
Elliott Hughes | 03a418e | 2018-06-15 13:11:40 -0700 | [diff] [blame] | 284 | SND_MAX, "SND_???", XT_INDEXED); |
Dmitry V. Levin | 53767d8 | 2016-05-27 00:40:18 +0000 | [diff] [blame] | 285 | case EV_REP: |
| 286 | return decode_bitset(tcp, arg, evdev_autorepeat, |
Elliott Hughes | 03a418e | 2018-06-15 13:11:40 -0700 | [diff] [blame] | 287 | REP_MAX, "REP_???", XT_INDEXED); |
Dmitry V. Levin | 53767d8 | 2016-05-27 00:40:18 +0000 | [diff] [blame] | 288 | case EV_FF: |
| 289 | return decode_bitset(tcp, arg, evdev_ff_types, |
Elliott Hughes | 03a418e | 2018-06-15 13:11:40 -0700 | [diff] [blame] | 290 | FF_MAX, "FF_???", XT_SORTED); |
Dmitry V. Levin | 53767d8 | 2016-05-27 00:40:18 +0000 | [diff] [blame] | 291 | case EV_PWR: |
Dmitry V. Levin | 47be9f2 | 2016-05-28 00:12:01 +0000 | [diff] [blame] | 292 | tprints(", "); |
Dmitry V. Levin | 53767d8 | 2016-05-27 00:40:18 +0000 | [diff] [blame] | 293 | printnum_int(tcp, arg, "%d"); |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 294 | return RVAL_IOCTL_DECODED; |
Dmitry V. Levin | 53767d8 | 2016-05-27 00:40:18 +0000 | [diff] [blame] | 295 | case EV_FF_STATUS: |
| 296 | return decode_bitset(tcp, arg, evdev_ff_status, |
Elliott Hughes | 03a418e | 2018-06-15 13:11:40 -0700 | [diff] [blame] | 297 | FF_STATUS_MAX, "FF_STATUS_???", |
| 298 | XT_INDEXED); |
Dmitry V. Levin | 53767d8 | 2016-05-27 00:40:18 +0000 | [diff] [blame] | 299 | default: |
Dmitry V. Levin | aa21c07 | 2016-05-28 00:49:17 +0000 | [diff] [blame] | 300 | tprints(", "); |
| 301 | printaddr(arg); |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 302 | return RVAL_IOCTL_DECODED; |
Dmitry V. Levin | 53767d8 | 2016-05-27 00:40:18 +0000 | [diff] [blame] | 303 | } |
| 304 | } |
| 305 | |
| 306 | static int |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 307 | evdev_read_ioctl(struct tcb *const tcp, const unsigned int code, |
| 308 | const kernel_ulong_t arg) |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 309 | { |
Dmitry V. Levin | 8a18f80 | 2016-05-27 00:40:10 +0000 | [diff] [blame] | 310 | /* fixed-number fixed-length commands */ |
| 311 | switch (code) { |
| 312 | case EVIOCGVERSION: |
| 313 | tprints(", "); |
Dmitry V. Levin | b29569a | 2016-05-27 00:42:07 +0000 | [diff] [blame] | 314 | printnum_int(tcp, arg, "%#x"); |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 315 | return RVAL_IOCTL_DECODED; |
Dmitry V. Levin | 8a18f80 | 2016-05-27 00:40:10 +0000 | [diff] [blame] | 316 | case EVIOCGEFFECTS: |
| 317 | tprints(", "); |
Dmitry V. Levin | 3f23c0c | 2016-05-27 00:42:25 +0000 | [diff] [blame] | 318 | printnum_int(tcp, arg, "%u"); |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 319 | return RVAL_IOCTL_DECODED; |
Dmitry V. Levin | 8a18f80 | 2016-05-27 00:40:10 +0000 | [diff] [blame] | 320 | case EVIOCGID: |
| 321 | return getid_ioctl(tcp, arg); |
| 322 | # ifdef EVIOCGREP |
| 323 | case EVIOCGREP: |
Dmitry V. Levin | 3f23c0c | 2016-05-27 00:42:25 +0000 | [diff] [blame] | 324 | return repeat_ioctl(tcp, arg); |
Dmitry V. Levin | 8a18f80 | 2016-05-27 00:40:10 +0000 | [diff] [blame] | 325 | # endif |
| 326 | case EVIOCGKEYCODE: |
| 327 | return keycode_ioctl(tcp, arg); |
| 328 | # ifdef EVIOCGKEYCODE_V2 |
| 329 | case EVIOCGKEYCODE_V2: |
| 330 | return keycode_V2_ioctl(tcp, arg); |
| 331 | # endif |
| 332 | } |
| 333 | |
| 334 | /* fixed-number variable-length commands */ |
| 335 | switch (_IOC_NR(code)) { |
| 336 | # ifdef EVIOCGMTSLOTS |
| 337 | case _IOC_NR(EVIOCGMTSLOTS(0)): |
| 338 | return mtslots_ioctl(tcp, code, arg); |
| 339 | # endif |
| 340 | case _IOC_NR(EVIOCGNAME(0)): |
| 341 | case _IOC_NR(EVIOCGPHYS(0)): |
| 342 | case _IOC_NR(EVIOCGUNIQ(0)): |
| 343 | tprints(", "); |
Dmitry V. Levin | 10de2eb | 2016-05-27 00:42:18 +0000 | [diff] [blame] | 344 | if (syserror(tcp)) |
| 345 | printaddr(arg); |
| 346 | else |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 347 | printstrn(tcp, arg, tcp->u_rval); |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 348 | return RVAL_IOCTL_DECODED; |
Dmitry V. Levin | 8a18f80 | 2016-05-27 00:40:10 +0000 | [diff] [blame] | 349 | # ifdef EVIOCGPROP |
| 350 | case _IOC_NR(EVIOCGPROP(0)): |
Dmitry V. Levin | 3f23c0c | 2016-05-27 00:42:25 +0000 | [diff] [blame] | 351 | return decode_bitset(tcp, arg, evdev_prop, |
Elliott Hughes | 03a418e | 2018-06-15 13:11:40 -0700 | [diff] [blame] | 352 | INPUT_PROP_MAX, "PROP_???", |
| 353 | XT_INDEXED); |
Dmitry V. Levin | 8a18f80 | 2016-05-27 00:40:10 +0000 | [diff] [blame] | 354 | # endif |
| 355 | case _IOC_NR(EVIOCGSND(0)): |
Dmitry V. Levin | 3f23c0c | 2016-05-27 00:42:25 +0000 | [diff] [blame] | 356 | return decode_bitset(tcp, arg, evdev_snd, |
Elliott Hughes | 03a418e | 2018-06-15 13:11:40 -0700 | [diff] [blame] | 357 | SND_MAX, "SND_???", XT_INDEXED); |
Dmitry V. Levin | 8a18f80 | 2016-05-27 00:40:10 +0000 | [diff] [blame] | 358 | # ifdef EVIOCGSW |
| 359 | case _IOC_NR(EVIOCGSW(0)): |
Dmitry V. Levin | 3f23c0c | 2016-05-27 00:42:25 +0000 | [diff] [blame] | 360 | return decode_bitset(tcp, arg, evdev_switch, |
Elliott Hughes | 03a418e | 2018-06-15 13:11:40 -0700 | [diff] [blame] | 361 | SW_MAX, "SW_???", XT_INDEXED); |
Dmitry V. Levin | 8a18f80 | 2016-05-27 00:40:10 +0000 | [diff] [blame] | 362 | # endif |
| 363 | case _IOC_NR(EVIOCGKEY(0)): |
Dmitry V. Levin | 3f23c0c | 2016-05-27 00:42:25 +0000 | [diff] [blame] | 364 | return decode_bitset(tcp, arg, evdev_keycode, |
Elliott Hughes | 03a418e | 2018-06-15 13:11:40 -0700 | [diff] [blame] | 365 | KEY_MAX, "KEY_???", XT_INDEXED); |
Dmitry V. Levin | 8a18f80 | 2016-05-27 00:40:10 +0000 | [diff] [blame] | 366 | case _IOC_NR(EVIOCGLED(0)): |
Dmitry V. Levin | 3f23c0c | 2016-05-27 00:42:25 +0000 | [diff] [blame] | 367 | return decode_bitset(tcp, arg, evdev_leds, |
Elliott Hughes | 03a418e | 2018-06-15 13:11:40 -0700 | [diff] [blame] | 368 | LED_MAX, "LED_???", XT_INDEXED); |
Dmitry V. Levin | 8a18f80 | 2016-05-27 00:40:10 +0000 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | /* multi-number fixed-length commands */ |
| 372 | if ((_IOC_NR(code) & ~ABS_MAX) == _IOC_NR(EVIOCGABS(0))) |
| 373 | return abs_ioctl(tcp, arg); |
| 374 | |
| 375 | /* multi-number variable-length commands */ |
Dmitry V. Levin | 53767d8 | 2016-05-27 00:40:18 +0000 | [diff] [blame] | 376 | if ((_IOC_NR(code) & ~EV_MAX) == _IOC_NR(EVIOCGBIT(0, 0))) |
| 377 | return bit_ioctl(tcp, _IOC_NR(code) & EV_MAX, arg); |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 378 | |
Dmitry V. Levin | 8a18f80 | 2016-05-27 00:40:10 +0000 | [diff] [blame] | 379 | return 0; |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | static int |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 383 | evdev_write_ioctl(struct tcb *const tcp, const unsigned int code, |
| 384 | const kernel_ulong_t arg) |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 385 | { |
Dmitry V. Levin | 8a18f80 | 2016-05-27 00:40:10 +0000 | [diff] [blame] | 386 | /* fixed-number fixed-length commands */ |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 387 | switch (code) { |
Dmitry V. Levin | 8d85c23 | 2016-05-27 00:39:33 +0000 | [diff] [blame] | 388 | # ifdef EVIOCSREP |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 389 | case EVIOCSREP: |
| 390 | return repeat_ioctl(tcp, arg); |
Dmitry V. Levin | 8d85c23 | 2016-05-27 00:39:33 +0000 | [diff] [blame] | 391 | # endif |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 392 | case EVIOCSKEYCODE: |
| 393 | return keycode_ioctl(tcp, arg); |
Dmitry V. Levin | 8d85c23 | 2016-05-27 00:39:33 +0000 | [diff] [blame] | 394 | # ifdef EVIOCSKEYCODE_V2 |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 395 | case EVIOCSKEYCODE_V2: |
| 396 | return keycode_V2_ioctl(tcp, arg); |
Dmitry V. Levin | 8d85c23 | 2016-05-27 00:39:33 +0000 | [diff] [blame] | 397 | # endif |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 398 | case EVIOCRMFF: |
Dmitry V. Levin | 0039424 | 2016-05-27 00:40:27 +0000 | [diff] [blame] | 399 | tprintf(", %d", (int) arg); |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 400 | return RVAL_IOCTL_DECODED; |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 401 | case EVIOCGRAB: |
Dmitry V. Levin | 8d85c23 | 2016-05-27 00:39:33 +0000 | [diff] [blame] | 402 | # ifdef EVIOCREVOKE |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 403 | case EVIOCREVOKE: |
Dmitry V. Levin | 8d85c23 | 2016-05-27 00:39:33 +0000 | [diff] [blame] | 404 | # endif |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 405 | tprintf(", %" PRI_klu, arg); |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 406 | return RVAL_IOCTL_DECODED; |
Dmitry V. Levin | 9635df4 | 2016-05-27 00:40:45 +0000 | [diff] [blame] | 407 | # ifdef EVIOCSCLOCKID |
| 408 | case EVIOCSCLOCKID: |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 409 | tprints(", "); |
| 410 | printnum_int(tcp, arg, "%u"); |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 411 | return RVAL_IOCTL_DECODED; |
Dmitry V. Levin | 9635df4 | 2016-05-27 00:40:45 +0000 | [diff] [blame] | 412 | # endif |
Elliott Hughes | 28e98bc | 2018-06-14 16:59:04 -0700 | [diff] [blame] | 413 | default: { |
| 414 | int rc = evdev_write_ioctl_mpers(tcp, code, arg); |
| 415 | |
| 416 | if (rc != RVAL_DECODED) |
| 417 | return rc; |
| 418 | } |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 419 | } |
Dmitry V. Levin | 8a18f80 | 2016-05-27 00:40:10 +0000 | [diff] [blame] | 420 | |
| 421 | /* multi-number fixed-length commands */ |
| 422 | if ((_IOC_NR(code) & ~ABS_MAX) == _IOC_NR(EVIOCSABS(0))) |
| 423 | return abs_ioctl(tcp, arg); |
| 424 | |
| 425 | return 0; |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 426 | } |
| 427 | |
Elliott Hughes | 28e98bc | 2018-06-14 16:59:04 -0700 | [diff] [blame] | 428 | void |
| 429 | print_evdev_ff_type(const kernel_ulong_t val) |
| 430 | { |
| 431 | printxval(evdev_ff_types, val, "FF_???"); |
| 432 | } |
| 433 | |
| 434 | int |
| 435 | evdev_ioctl(struct tcb *const tcp, |
| 436 | const unsigned int code, const kernel_ulong_t arg) |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 437 | { |
Elliott Hughes | dc75b01 | 2017-07-05 13:54:44 -0700 | [diff] [blame] | 438 | switch (_IOC_DIR(code)) { |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 439 | case _IOC_READ: |
Dmitry V. Levin | 2114e08 | 2016-05-27 00:40:02 +0000 | [diff] [blame] | 440 | if (entering(tcp)) |
| 441 | return 0; |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 442 | return evdev_read_ioctl(tcp, code, arg); |
| 443 | case _IOC_WRITE: |
Dmitry V. Levin | 2114e08 | 2016-05-27 00:40:02 +0000 | [diff] [blame] | 444 | return evdev_write_ioctl(tcp, code, arg) | RVAL_DECODED; |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 445 | default: |
Dmitry V. Levin | 2114e08 | 2016-05-27 00:40:02 +0000 | [diff] [blame] | 446 | return RVAL_DECODED; |
Etienne Gemsa | 4f750b9 | 2015-02-20 17:14:10 +0100 | [diff] [blame] | 447 | } |
| 448 | } |
| 449 | |
| 450 | #endif /* HAVE_LINUX_INPUT_H */ |