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