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