Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com> |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
| 8 | * 1. Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer in the |
| 12 | * documentation and/or other materials provided with the distribution. |
| 13 | * 3. The name of the author may not be used to endorse or promote products |
| 14 | * derived from this software without specific prior written permission. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 26 | */ |
| 27 | |
| 28 | #include "defs.h" |
Roland McGrath | 6e87ee0 | 2003-01-14 07:53:40 +0000 | [diff] [blame] | 29 | /* |
| 30 | * The C library's definition of struct termios might differ from |
| 31 | * the kernel one, and we need to use the kernel layout. |
| 32 | */ |
| 33 | #include <linux/termios.h> |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 34 | |
Dmitry V. Levin | fd3cdc0 | 2015-07-13 20:10:20 +0000 | [diff] [blame] | 35 | #include "xlat/tcxonc_options.h" |
| 36 | #include "xlat/tcflsh_options.h" |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 37 | #include "xlat/baud_options.h" |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 38 | #include "xlat/modem_flags.h" |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 39 | |
Dmitry V. Levin | fd3cdc0 | 2015-07-13 20:10:20 +0000 | [diff] [blame] | 40 | static void |
| 41 | decode_termios(struct tcb *tcp, const long addr) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 42 | { |
| 43 | struct termios tios; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 44 | int i; |
| 45 | |
Dmitry V. Levin | fd3cdc0 | 2015-07-13 20:10:20 +0000 | [diff] [blame] | 46 | if (!verbose(tcp)) |
| 47 | return; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 48 | |
Dmitry V. Levin | fd3cdc0 | 2015-07-13 20:10:20 +0000 | [diff] [blame] | 49 | tprints(", "); |
| 50 | if (umove_or_printaddr(tcp, addr, &tios)) |
| 51 | return; |
| 52 | if (abbrev(tcp)) { |
| 53 | tprints("{"); |
| 54 | printxval(baud_options, tios.c_cflag & CBAUD, "B???"); |
| 55 | tprintf(" %sopost %sisig %sicanon %secho ...}", |
| 56 | (tios.c_oflag & OPOST) ? "" : "-", |
| 57 | (tios.c_lflag & ISIG) ? "" : "-", |
| 58 | (tios.c_lflag & ICANON) ? "" : "-", |
| 59 | (tios.c_lflag & ECHO) ? "" : "-"); |
| 60 | return; |
| 61 | } |
| 62 | tprintf("{c_iflags=%#lx, c_oflags=%#lx, ", |
| 63 | (long) tios.c_iflag, (long) tios.c_oflag); |
| 64 | tprintf("c_cflags=%#lx, c_lflags=%#lx, ", |
| 65 | (long) tios.c_cflag, (long) tios.c_lflag); |
| 66 | tprintf("c_line=%u, ", tios.c_line); |
| 67 | if (!(tios.c_lflag & ICANON)) |
| 68 | tprintf("c_cc[VMIN]=%d, c_cc[VTIME]=%d, ", |
| 69 | tios.c_cc[VMIN], tios.c_cc[VTIME]); |
| 70 | tprintf("c_cc=\""); |
| 71 | for (i = 0; i < NCCS; i++) |
| 72 | tprintf("\\x%02x", tios.c_cc[i]); |
| 73 | tprintf("\"}"); |
| 74 | } |
| 75 | |
| 76 | static void |
| 77 | decode_termio(struct tcb *tcp, const long addr) |
| 78 | { |
| 79 | struct termio tio; |
| 80 | int i; |
| 81 | |
| 82 | if (!verbose(tcp)) |
| 83 | return; |
| 84 | |
| 85 | tprints(", "); |
| 86 | if (umove_or_printaddr(tcp, addr, &tio)) |
| 87 | return; |
| 88 | if (abbrev(tcp)) { |
| 89 | tprints("{"); |
| 90 | printxval(baud_options, tio.c_cflag & CBAUD, "B???"); |
| 91 | tprintf(" %sopost %sisig %sicanon %secho ...}", |
| 92 | (tio.c_oflag & OPOST) ? "" : "-", |
| 93 | (tio.c_lflag & ISIG) ? "" : "-", |
| 94 | (tio.c_lflag & ICANON) ? "" : "-", |
| 95 | (tio.c_lflag & ECHO) ? "" : "-"); |
| 96 | return; |
| 97 | } |
| 98 | tprintf("{c_iflags=%#lx, c_oflags=%#lx, ", |
| 99 | (long) tio.c_iflag, (long) tio.c_oflag); |
| 100 | tprintf("c_cflags=%#lx, c_lflags=%#lx, ", |
| 101 | (long) tio.c_cflag, (long) tio.c_lflag); |
| 102 | tprintf("c_line=%u, ", tio.c_line); |
| 103 | #ifdef _VMIN |
| 104 | if (!(tio.c_lflag & ICANON)) |
| 105 | tprintf("c_cc[_VMIN]=%d, c_cc[_VTIME]=%d, ", |
| 106 | tio.c_cc[_VMIN], tio.c_cc[_VTIME]); |
| 107 | #else /* !_VMIN */ |
| 108 | if (!(tio.c_lflag & ICANON)) |
| 109 | tprintf("c_cc[VMIN]=%d, c_cc[VTIME]=%d, ", |
| 110 | tio.c_cc[VMIN], tio.c_cc[VTIME]); |
| 111 | #endif /* !_VMIN */ |
| 112 | tprintf("c_cc=\""); |
| 113 | for (i = 0; i < NCC; i++) |
| 114 | tprintf("\\x%02x", tio.c_cc[i]); |
| 115 | tprintf("\"}"); |
| 116 | } |
| 117 | |
| 118 | static void |
| 119 | decode_winsize(struct tcb *tcp, const long addr) |
| 120 | { |
| 121 | struct winsize ws; |
| 122 | |
| 123 | if (!verbose(tcp)) |
| 124 | return; |
| 125 | |
| 126 | tprints(", "); |
| 127 | if (umove_or_printaddr(tcp, addr, &ws)) |
| 128 | return; |
| 129 | tprintf("{ws_row=%d, ws_col=%d, ws_xpixel=%d, ws_ypixel=%d}", |
| 130 | ws.ws_row, ws.ws_col, ws.ws_xpixel, ws.ws_ypixel); |
| 131 | } |
| 132 | |
| 133 | #ifdef TIOCGSIZE |
| 134 | static void |
| 135 | decode_ttysize(struct tcb *tcp, const long addr) |
| 136 | { |
| 137 | struct ttysize ts; |
| 138 | |
| 139 | if (!verbose(tcp)) |
| 140 | return; |
| 141 | |
| 142 | tprints(", "); |
| 143 | if (umove_or_printaddr(tcp, addr, &ts)) |
| 144 | return; |
| 145 | tprintf("{ts_lines=%d, ts_cols=%d}", |
| 146 | ts.ts_lines, ts.ts_cols); |
| 147 | } |
| 148 | #endif |
| 149 | |
| 150 | static void |
| 151 | decode_modem_flags(struct tcb *tcp, const long addr) |
| 152 | { |
| 153 | int i; |
| 154 | |
| 155 | if (!verbose(tcp)) |
| 156 | return; |
| 157 | |
| 158 | tprints(", "); |
| 159 | if (umove_or_printaddr(tcp, addr, &i)) |
| 160 | return; |
| 161 | tprints("["); |
| 162 | printflags(modem_flags, i, "TIOCM_???"); |
| 163 | tprints("]"); |
| 164 | } |
| 165 | |
| 166 | int |
| 167 | term_ioctl(struct tcb *tcp, const unsigned int code, const long arg) |
| 168 | { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 169 | switch (code) { |
Dmitry V. Levin | fd3cdc0 | 2015-07-13 20:10:20 +0000 | [diff] [blame] | 170 | /* struct termios */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 171 | case TCGETS: |
Dmitry V. Levin | fd3cdc0 | 2015-07-13 20:10:20 +0000 | [diff] [blame] | 172 | #ifdef TCGETS2 |
| 173 | case TCGETS2: |
| 174 | #endif |
| 175 | case TIOCGLCKTRMIOS: |
| 176 | if (entering(tcp)) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 177 | return 0; |
| 178 | case TCSETS: |
Dmitry V. Levin | fd3cdc0 | 2015-07-13 20:10:20 +0000 | [diff] [blame] | 179 | #ifdef TCSETS2 |
| 180 | case TCSETS2: |
| 181 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 182 | case TCSETSW: |
Dmitry V. Levin | fd3cdc0 | 2015-07-13 20:10:20 +0000 | [diff] [blame] | 183 | #ifdef TCSETSW2 |
| 184 | case TCSETSW2: |
| 185 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 186 | case TCSETSF: |
Dmitry V. Levin | fd3cdc0 | 2015-07-13 20:10:20 +0000 | [diff] [blame] | 187 | #ifdef TCSETSF2 |
| 188 | case TCSETSF2: |
| 189 | #endif |
| 190 | case TIOCSLCKTRMIOS: |
| 191 | decode_termios(tcp, arg); |
| 192 | break; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 193 | |
Dmitry V. Levin | fd3cdc0 | 2015-07-13 20:10:20 +0000 | [diff] [blame] | 194 | /* struct termio */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 195 | case TCGETA: |
Dmitry V. Levin | fd3cdc0 | 2015-07-13 20:10:20 +0000 | [diff] [blame] | 196 | if (entering(tcp)) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 197 | return 0; |
| 198 | case TCSETA: |
| 199 | case TCSETAW: |
| 200 | case TCSETAF: |
Dmitry V. Levin | fd3cdc0 | 2015-07-13 20:10:20 +0000 | [diff] [blame] | 201 | decode_termio(tcp, arg); |
| 202 | break; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 203 | |
Dmitry V. Levin | fd3cdc0 | 2015-07-13 20:10:20 +0000 | [diff] [blame] | 204 | /* struct winsize */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 205 | case TIOCGWINSZ: |
Dmitry V. Levin | fd3cdc0 | 2015-07-13 20:10:20 +0000 | [diff] [blame] | 206 | if (entering(tcp)) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 207 | return 0; |
| 208 | case TIOCSWINSZ: |
Dmitry V. Levin | fd3cdc0 | 2015-07-13 20:10:20 +0000 | [diff] [blame] | 209 | decode_winsize(tcp, arg); |
| 210 | break; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 211 | |
Dmitry V. Levin | fd3cdc0 | 2015-07-13 20:10:20 +0000 | [diff] [blame] | 212 | /* struct ttysize */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 213 | #ifdef TIOCGSIZE |
| 214 | case TIOCGSIZE: |
Dmitry V. Levin | fd3cdc0 | 2015-07-13 20:10:20 +0000 | [diff] [blame] | 215 | if (entering(tcp)) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 216 | return 0; |
| 217 | case TIOCSSIZE: |
Dmitry V. Levin | fd3cdc0 | 2015-07-13 20:10:20 +0000 | [diff] [blame] | 218 | decode_ttysize(tcp, arg); |
| 219 | break; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 220 | #endif |
| 221 | |
| 222 | /* ioctls with a direct decodable arg */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 223 | case TCXONC: |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 224 | tprints(", "); |
Dmitry V. Levin | 9b8ca23 | 2016-05-16 23:36:14 +0000 | [diff] [blame] | 225 | printxval_long(tcxonc_options, arg, "TC???"); |
Dmitry V. Levin | fd3cdc0 | 2015-07-13 20:10:20 +0000 | [diff] [blame] | 226 | break; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 227 | case TCFLSH: |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 228 | tprints(", "); |
Dmitry V. Levin | 9b8ca23 | 2016-05-16 23:36:14 +0000 | [diff] [blame] | 229 | printxval_long(tcflsh_options, arg, "TC???"); |
Dmitry V. Levin | fd3cdc0 | 2015-07-13 20:10:20 +0000 | [diff] [blame] | 230 | break; |
| 231 | case TCSBRK: |
| 232 | case TCSBRKP: |
Denys Vlasenko | 6a4ac6c | 2011-10-22 04:52:18 +0200 | [diff] [blame] | 233 | case TIOCSCTTY: |
Dmitry V. Levin | fd3cdc0 | 2015-07-13 20:10:20 +0000 | [diff] [blame] | 234 | tprintf(", %d", (int) arg); |
| 235 | break; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 236 | |
| 237 | /* ioctls with an indirect parameter displayed as modem flags */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 238 | case TIOCMGET: |
Dmitry V. Levin | fd3cdc0 | 2015-07-13 20:10:20 +0000 | [diff] [blame] | 239 | if (entering(tcp)) |
| 240 | return 0; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 241 | case TIOCMBIS: |
| 242 | case TIOCMBIC: |
| 243 | case TIOCMSET: |
Dmitry V. Levin | fd3cdc0 | 2015-07-13 20:10:20 +0000 | [diff] [blame] | 244 | decode_modem_flags(tcp, arg); |
| 245 | break; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 246 | |
| 247 | /* ioctls with an indirect parameter displayed in decimal */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 248 | case TIOCGPGRP: |
Dmitry V. Levin | fd3cdc0 | 2015-07-13 20:10:20 +0000 | [diff] [blame] | 249 | case TIOCGSID: |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 250 | case TIOCGETD: |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 251 | case TIOCGSOFTCAR: |
Wichert Akkerman | 2e2553a | 1999-05-09 00:29:58 +0000 | [diff] [blame] | 252 | case TIOCGPTN: |
Dmitry V. Levin | fd3cdc0 | 2015-07-13 20:10:20 +0000 | [diff] [blame] | 253 | case FIONREAD: |
| 254 | case TIOCOUTQ: |
| 255 | #ifdef TIOCGEXCL |
| 256 | case TIOCGEXCL: |
Wichert Akkerman | 2e2553a | 1999-05-09 00:29:58 +0000 | [diff] [blame] | 257 | #endif |
Dmitry V. Levin | fd3cdc0 | 2015-07-13 20:10:20 +0000 | [diff] [blame] | 258 | #ifdef TIOCGDEV |
| 259 | case TIOCGDEV: |
| 260 | #endif |
| 261 | if (entering(tcp)) |
| 262 | return 0; |
| 263 | case TIOCSPGRP: |
| 264 | case TIOCSETD: |
| 265 | case FIONBIO: |
| 266 | case FIOASYNC: |
| 267 | case TIOCPKT: |
| 268 | case TIOCSSOFTCAR: |
| 269 | case TIOCSPTLCK: |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 270 | tprints(", "); |
Roland McGrath | bcd2c95 | 2008-07-22 00:21:43 +0000 | [diff] [blame] | 271 | printnum_int(tcp, arg, "%d"); |
Dmitry V. Levin | fd3cdc0 | 2015-07-13 20:10:20 +0000 | [diff] [blame] | 272 | break; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 273 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 274 | /* ioctls with an indirect parameter displayed as a char */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 275 | case TIOCSTI: |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 276 | tprints(", "); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 277 | printstr(tcp, arg, 1); |
Dmitry V. Levin | fd3cdc0 | 2015-07-13 20:10:20 +0000 | [diff] [blame] | 278 | break; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 279 | |
| 280 | /* ioctls with no parameters */ |
| 281 | |
Dmitry V. Levin | fd3cdc0 | 2015-07-13 20:10:20 +0000 | [diff] [blame] | 282 | case TIOCSBRK: |
| 283 | case TIOCCBRK: |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 284 | case TIOCCONS: |
Dmitry V. Levin | fd3cdc0 | 2015-07-13 20:10:20 +0000 | [diff] [blame] | 285 | case TIOCNOTTY: |
| 286 | case TIOCEXCL: |
| 287 | case TIOCNXCL: |
| 288 | case FIOCLEX: |
| 289 | case FIONCLEX: |
| 290 | #ifdef TIOCVHANGUP |
| 291 | case TIOCVHANGUP: |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 292 | #endif |
Dmitry V. Levin | fd3cdc0 | 2015-07-13 20:10:20 +0000 | [diff] [blame] | 293 | #ifdef TIOCSSERIAL |
| 294 | case TIOCSSERIAL: |
| 295 | #endif |
| 296 | break; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 297 | |
| 298 | /* ioctls which are unknown */ |
| 299 | |
| 300 | default: |
Dmitry V. Levin | fd3cdc0 | 2015-07-13 20:10:20 +0000 | [diff] [blame] | 301 | return RVAL_DECODED; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 302 | } |
Dmitry V. Levin | fd3cdc0 | 2015-07-13 20:10:20 +0000 | [diff] [blame] | 303 | |
| 304 | return RVAL_DECODED | 1; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 305 | } |