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 | #ifdef HAVE_SYS_FILIO_H |
Denys Vlasenko | a6d91de | 2012-03-16 12:02:22 +0100 | [diff] [blame] | 35 | # include <sys/filio.h> |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 36 | #endif |
| 37 | |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 38 | #include "xlat/tcxonc_options.h" |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 39 | |
Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 40 | #ifdef TCLFLSH |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 41 | #include "xlat/tcflsh_options.h" |
Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 42 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 43 | |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 44 | #include "xlat/baud_options.h" |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 45 | #include "xlat/modem_flags.h" |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 46 | |
Dmitry V. Levin | c7afb48 | 2015-01-19 18:44:21 +0000 | [diff] [blame] | 47 | int |
| 48 | term_ioctl(struct tcb *tcp, const unsigned int code, long arg) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 49 | { |
| 50 | struct termios tios; |
| 51 | struct termio tio; |
| 52 | struct winsize ws; |
| 53 | #ifdef TIOCGSIZE |
| 54 | struct ttysize ts; |
| 55 | #endif |
| 56 | int i; |
| 57 | |
| 58 | if (entering(tcp)) |
| 59 | return 0; |
| 60 | |
| 61 | switch (code) { |
| 62 | |
| 63 | /* ioctls with termios or termio args */ |
| 64 | |
| 65 | #ifdef TCGETS |
| 66 | case TCGETS: |
| 67 | if (syserror(tcp)) |
| 68 | return 0; |
| 69 | case TCSETS: |
| 70 | case TCSETSW: |
| 71 | case TCSETSF: |
| 72 | if (!verbose(tcp) || umove(tcp, arg, &tios) < 0) |
| 73 | return 0; |
| 74 | if (abbrev(tcp)) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 75 | tprints(", {"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 76 | printxval(baud_options, tios.c_cflag & CBAUD, "B???"); |
| 77 | tprintf(" %sopost %sisig %sicanon %secho ...}", |
| 78 | (tios.c_oflag & OPOST) ? "" : "-", |
| 79 | (tios.c_lflag & ISIG) ? "" : "-", |
| 80 | (tios.c_lflag & ICANON) ? "" : "-", |
| 81 | (tios.c_lflag & ECHO) ? "" : "-"); |
| 82 | return 1; |
| 83 | } |
| 84 | tprintf(", {c_iflags=%#lx, c_oflags=%#lx, ", |
| 85 | (long) tios.c_iflag, (long) tios.c_oflag); |
| 86 | tprintf("c_cflags=%#lx, c_lflags=%#lx, ", |
| 87 | (long) tios.c_cflag, (long) tios.c_lflag); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 88 | tprintf("c_line=%u, ", tios.c_line); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 89 | if (!(tios.c_lflag & ICANON)) |
| 90 | tprintf("c_cc[VMIN]=%d, c_cc[VTIME]=%d, ", |
| 91 | tios.c_cc[VMIN], tios.c_cc[VTIME]); |
| 92 | tprintf("c_cc=\""); |
| 93 | for (i = 0; i < NCCS; i++) |
| 94 | tprintf("\\x%02x", tios.c_cc[i]); |
| 95 | tprintf("\"}"); |
| 96 | return 1; |
| 97 | #endif /* TCGETS */ |
| 98 | |
| 99 | #ifdef TCGETA |
| 100 | case TCGETA: |
| 101 | if (syserror(tcp)) |
| 102 | return 0; |
| 103 | case TCSETA: |
| 104 | case TCSETAW: |
| 105 | case TCSETAF: |
| 106 | if (!verbose(tcp) || umove(tcp, arg, &tio) < 0) |
| 107 | return 0; |
| 108 | if (abbrev(tcp)) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 109 | tprints(", {"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 110 | printxval(baud_options, tio.c_cflag & CBAUD, "B???"); |
| 111 | tprintf(" %sopost %sisig %sicanon %secho ...}", |
| 112 | (tio.c_oflag & OPOST) ? "" : "-", |
| 113 | (tio.c_lflag & ISIG) ? "" : "-", |
| 114 | (tio.c_lflag & ICANON) ? "" : "-", |
| 115 | (tio.c_lflag & ECHO) ? "" : "-"); |
| 116 | return 1; |
| 117 | } |
| 118 | tprintf(", {c_iflags=%#lx, c_oflags=%#lx, ", |
| 119 | (long) tio.c_iflag, (long) tio.c_oflag); |
| 120 | tprintf("c_cflags=%#lx, c_lflags=%#lx, ", |
| 121 | (long) tio.c_cflag, (long) tio.c_lflag); |
| 122 | tprintf("c_line=%u, ", tio.c_line); |
| 123 | #ifdef _VMIN |
| 124 | if (!(tio.c_lflag & ICANON)) |
| 125 | tprintf("c_cc[_VMIN]=%d, c_cc[_VTIME]=%d, ", |
| 126 | tio.c_cc[_VMIN], tio.c_cc[_VTIME]); |
| 127 | #else /* !_VMIN */ |
| 128 | if (!(tio.c_lflag & ICANON)) |
| 129 | tprintf("c_cc[VMIN]=%d, c_cc[VTIME]=%d, ", |
| 130 | tio.c_cc[VMIN], tio.c_cc[VTIME]); |
| 131 | #endif /* !_VMIN */ |
| 132 | tprintf("c_cc=\""); |
| 133 | for (i = 0; i < NCC; i++) |
| 134 | tprintf("\\x%02x", tio.c_cc[i]); |
| 135 | tprintf("\"}"); |
| 136 | return 1; |
| 137 | #endif /* TCGETA */ |
| 138 | |
| 139 | /* ioctls with winsize or ttysize args */ |
| 140 | |
| 141 | #ifdef TIOCGWINSZ |
| 142 | case TIOCGWINSZ: |
| 143 | if (syserror(tcp)) |
| 144 | return 0; |
| 145 | case TIOCSWINSZ: |
| 146 | if (!verbose(tcp) || umove(tcp, arg, &ws) < 0) |
| 147 | return 0; |
| 148 | tprintf(", {ws_row=%d, ws_col=%d, ws_xpixel=%d, ws_ypixel=%d}", |
| 149 | ws.ws_row, ws.ws_col, ws.ws_xpixel, ws.ws_ypixel); |
| 150 | return 1; |
| 151 | #endif /* TIOCGWINSZ */ |
| 152 | |
| 153 | #ifdef TIOCGSIZE |
| 154 | case TIOCGSIZE: |
| 155 | if (syserror(tcp)) |
| 156 | return 0; |
| 157 | case TIOCSSIZE: |
| 158 | if (!verbose(tcp) || umove(tcp, arg, &ts) < 0) |
| 159 | return 0; |
| 160 | tprintf(", {ts_lines=%d, ts_cols=%d}", |
| 161 | ts.ts_lines, ts.ts_cols); |
| 162 | return 1; |
| 163 | #endif |
| 164 | |
| 165 | /* ioctls with a direct decodable arg */ |
Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 166 | #ifdef TCXONC |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 167 | case TCXONC: |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 168 | tprints(", "); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 169 | printxval(tcxonc_options, arg, "TC???"); |
| 170 | return 1; |
Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 171 | #endif |
| 172 | #ifdef TCLFLSH |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 173 | case TCFLSH: |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 174 | tprints(", "); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 175 | printxval(tcflsh_options, arg, "TC???"); |
| 176 | return 1; |
Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 177 | #endif |
Denys Vlasenko | 6a4ac6c | 2011-10-22 04:52:18 +0200 | [diff] [blame] | 178 | #ifdef TIOCSCTTY |
| 179 | case TIOCSCTTY: |
| 180 | tprintf(", %ld", arg); |
| 181 | return 1; |
| 182 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 183 | |
| 184 | /* ioctls with an indirect parameter displayed as modem flags */ |
| 185 | |
| 186 | #ifdef TIOCMGET |
| 187 | case TIOCMGET: |
| 188 | case TIOCMBIS: |
| 189 | case TIOCMBIC: |
| 190 | case TIOCMSET: |
Roland McGrath | bcd2c95 | 2008-07-22 00:21:43 +0000 | [diff] [blame] | 191 | if (umove(tcp, arg, &i) < 0) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 192 | return 0; |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 193 | tprints(", ["); |
Roland McGrath | bcd2c95 | 2008-07-22 00:21:43 +0000 | [diff] [blame] | 194 | printflags(modem_flags, i, "TIOCM_???"); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 195 | tprints("]"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 196 | return 1; |
| 197 | #endif /* TIOCMGET */ |
| 198 | |
| 199 | /* ioctls with an indirect parameter displayed in decimal */ |
| 200 | |
| 201 | case TIOCSPGRP: |
| 202 | case TIOCGPGRP: |
| 203 | #ifdef TIOCGETPGRP |
| 204 | case TIOCGETPGRP: |
| 205 | #endif |
| 206 | #ifdef TIOCSETPGRP |
| 207 | case TIOCSETPGRP: |
| 208 | #endif |
| 209 | #ifdef FIONREAD |
| 210 | case FIONREAD: |
| 211 | #endif |
| 212 | case TIOCOUTQ: |
| 213 | #ifdef FIONBIO |
| 214 | case FIONBIO: |
| 215 | #endif |
| 216 | #ifdef FIOASYNC |
| 217 | case FIOASYNC: |
| 218 | #endif |
| 219 | #ifdef FIOGETOWN |
| 220 | case FIOGETOWN: |
| 221 | #endif |
| 222 | #ifdef FIOSETOWN |
| 223 | case FIOSETOWN: |
| 224 | #endif |
| 225 | #ifdef TIOCGETD |
| 226 | case TIOCGETD: |
| 227 | #endif |
| 228 | #ifdef TIOCSETD |
| 229 | case TIOCSETD: |
| 230 | #endif |
| 231 | #ifdef TIOCPKT |
| 232 | case TIOCPKT: |
| 233 | #endif |
| 234 | #ifdef TIOCREMOTE |
| 235 | case TIOCREMOTE: |
| 236 | #endif |
| 237 | #ifdef TIOCUCNTL |
| 238 | case TIOCUCNTL: |
| 239 | #endif |
| 240 | #ifdef TIOCTCNTL |
| 241 | case TIOCTCNTL: |
| 242 | #endif |
| 243 | #ifdef TIOCSIGNAL |
| 244 | case TIOCSIGNAL: |
| 245 | #endif |
| 246 | #ifdef TIOCSSOFTCAR |
| 247 | case TIOCSSOFTCAR: |
| 248 | #endif |
| 249 | #ifdef TIOCGSOFTCAR |
| 250 | case TIOCGSOFTCAR: |
| 251 | #endif |
| 252 | #ifdef TIOCISPACE |
| 253 | case TIOCISPACE: |
| 254 | #endif |
| 255 | #ifdef TIOCISIZE |
| 256 | case TIOCISIZE: |
| 257 | #endif |
| 258 | #ifdef TIOCSINTR |
| 259 | case TIOCSINTR: |
| 260 | #endif |
Wichert Akkerman | 2e2553a | 1999-05-09 00:29:58 +0000 | [diff] [blame] | 261 | #ifdef TIOCSPTLCK |
| 262 | case TIOCSPTLCK: |
| 263 | #endif |
| 264 | #ifdef TIOCGPTN |
| 265 | case TIOCGPTN: |
| 266 | #endif |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 267 | tprints(", "); |
Roland McGrath | bcd2c95 | 2008-07-22 00:21:43 +0000 | [diff] [blame] | 268 | printnum_int(tcp, arg, "%d"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 269 | return 1; |
| 270 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 271 | /* ioctls with an indirect parameter displayed as a char */ |
| 272 | |
| 273 | #ifdef TIOCSTI |
| 274 | case TIOCSTI: |
| 275 | #endif |
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); |
| 278 | return 1; |
| 279 | |
| 280 | /* ioctls with no parameters */ |
| 281 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 282 | #ifdef TIOCNOTTY |
| 283 | case TIOCNOTTY: |
| 284 | #endif |
| 285 | #ifdef FIOCLEX |
| 286 | case FIOCLEX: |
| 287 | #endif |
| 288 | #ifdef FIONCLEX |
| 289 | case FIONCLEX: |
| 290 | #endif |
| 291 | #ifdef TIOCCONS |
| 292 | case TIOCCONS: |
| 293 | #endif |
| 294 | return 1; |
| 295 | |
| 296 | /* ioctls which are unknown */ |
| 297 | |
| 298 | default: |
| 299 | return 0; |
| 300 | } |
| 301 | } |