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. |
| 26 | * |
| 27 | * $Id$ |
| 28 | */ |
| 29 | |
| 30 | #include "defs.h" |
| 31 | |
Wichert Akkerman | 2e2553a | 1999-05-09 00:29:58 +0000 | [diff] [blame] | 32 | #ifdef HAVE_TERMIO_H |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 33 | #include <termio.h> |
Wichert Akkerman | 2e2553a | 1999-05-09 00:29:58 +0000 | [diff] [blame] | 34 | #endif /* HAVE_TERMIO_H */ |
| 35 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 36 | #include <termios.h> |
Wichert Akkerman | 2e2553a | 1999-05-09 00:29:58 +0000 | [diff] [blame] | 37 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 38 | #ifdef HAVE_SYS_FILIO_H |
| 39 | #include <sys/filio.h> |
| 40 | #endif |
| 41 | |
| 42 | static struct xlat tcxonc_options[] = { |
| 43 | { TCOOFF, "TCOOFF" }, |
| 44 | { TCOON, "TCOON" }, |
| 45 | { TCIOFF, "TCIOFF" }, |
| 46 | { TCION, "TCION" }, |
| 47 | { 0, NULL }, |
| 48 | }; |
| 49 | |
Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 50 | #ifdef TCLFLSH |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 51 | static struct xlat tcflsh_options[] = { |
| 52 | { TCIFLUSH, "TCIFLUSH" }, |
| 53 | { TCOFLUSH, "TCOFLUSH" }, |
| 54 | { TCIOFLUSH, "TCIOFLUSH" }, |
| 55 | { 0, NULL }, |
| 56 | }; |
Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 57 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 58 | |
| 59 | static struct xlat baud_options[] = { |
| 60 | { B0, "B0" }, |
| 61 | { B50, "B50" }, |
| 62 | { B75, "B75" }, |
| 63 | { B110, "B110" }, |
| 64 | { B134, "B134" }, |
| 65 | { B150, "B150" }, |
| 66 | { B200, "B200" }, |
| 67 | { B300, "B300" }, |
| 68 | { B600, "B600" }, |
| 69 | { B1200, "B1200" }, |
| 70 | { B1800, "B1800" }, |
| 71 | { B2400, "B2400" }, |
| 72 | { B4800, "B4800" }, |
| 73 | { B9600, "B9600" }, |
| 74 | #ifdef B19200 |
| 75 | { B19200, "B19200" }, |
| 76 | #endif |
| 77 | #ifdef B38400 |
| 78 | { B38400, "B38400" }, |
| 79 | #endif |
Wichert Akkerman | 5ae21ea | 2000-05-01 01:53:59 +0000 | [diff] [blame] | 80 | #ifdef B57600 |
| 81 | { B57600, "B57600" }, |
| 82 | #endif |
| 83 | #ifdef B115200 |
| 84 | { B115200, "B115200" }, |
| 85 | #endif |
| 86 | #ifdef B230400 |
| 87 | { B230400, "B230400" }, |
| 88 | #endif |
| 89 | #ifdef B460800 |
| 90 | { B460800, "B460800" }, |
| 91 | #endif |
| 92 | #ifdef B500000 |
| 93 | { B500000, "B500000" }, |
| 94 | #endif |
| 95 | #ifdef B576000 |
| 96 | { B576000, "B576000" }, |
| 97 | #endif |
| 98 | #ifdef B921600 |
| 99 | { B921600, "B921600" }, |
| 100 | #endif |
| 101 | #ifdef B1000000 |
| 102 | { B1000000, "B1000000" }, |
| 103 | #endif |
| 104 | #ifdef B1152000 |
| 105 | { B1152000, "B1152000" }, |
| 106 | #endif |
| 107 | #ifdef B1500000 |
| 108 | { B1500000, "B1500000" }, |
| 109 | #endif |
| 110 | #ifdef B2000000 |
| 111 | { B2000000, "B2000000" }, |
| 112 | #endif |
| 113 | #ifdef B2500000 |
| 114 | { B2500000, "B2500000" }, |
| 115 | #endif |
| 116 | #ifdef B3000000 |
| 117 | { B3000000, "B3000000" }, |
| 118 | #endif |
| 119 | #ifdef B3500000 |
| 120 | { B3500000, "B3500000" }, |
| 121 | #endif |
| 122 | #ifdef B4000000 |
| 123 | { B4000000, "B4000000" }, |
| 124 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 125 | #ifdef EXTA |
| 126 | { EXTA, "EXTA" }, |
| 127 | #endif |
| 128 | #ifdef EXTB |
| 129 | { EXTB, "EXTB" }, |
| 130 | #endif |
| 131 | { 0, NULL }, |
| 132 | }; |
| 133 | |
| 134 | static struct xlat modem_flags[] = { |
| 135 | #ifdef TIOCM_LE |
| 136 | { TIOCM_LE, "TIOCM_LE", }, |
| 137 | #endif |
| 138 | #ifdef TIOCM_DTR |
| 139 | { TIOCM_DTR, "TIOCM_DTR", }, |
| 140 | #endif |
| 141 | #ifdef TIOCM_RTS |
| 142 | { TIOCM_RTS, "TIOCM_RTS", }, |
| 143 | #endif |
| 144 | #ifdef TIOCM_ST |
| 145 | { TIOCM_ST, "TIOCM_ST", }, |
| 146 | #endif |
| 147 | #ifdef TIOCM_SR |
| 148 | { TIOCM_SR, "TIOCM_SR", }, |
| 149 | #endif |
| 150 | #ifdef TIOCM_CTS |
| 151 | { TIOCM_CTS, "TIOCM_CTS", }, |
| 152 | #endif |
| 153 | #ifdef TIOCM_CAR |
| 154 | { TIOCM_CAR, "TIOCM_CAR", }, |
| 155 | #endif |
| 156 | #ifdef TIOCM_CD |
| 157 | { TIOCM_CD, "TIOCM_CD", }, |
| 158 | #endif |
| 159 | #ifdef TIOCM_RNG |
| 160 | { TIOCM_RNG, "TIOCM_RNG", }, |
| 161 | #endif |
| 162 | #ifdef TIOCM_RI |
| 163 | { TIOCM_RI, "TIOCM_RI", }, |
| 164 | #endif |
| 165 | #ifdef TIOCM_DSR |
| 166 | { TIOCM_DSR, "TIOCM_DSR", }, |
| 167 | #endif |
| 168 | { 0, NULL, }, |
| 169 | }; |
| 170 | |
| 171 | |
| 172 | int |
| 173 | term_ioctl(tcp, code, arg) |
| 174 | struct tcb *tcp; |
| 175 | long code, arg; |
| 176 | { |
| 177 | struct termios tios; |
Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 178 | #ifndef FREEBSD |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 179 | struct termio tio; |
Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 180 | #else |
Wichert Akkerman | 2e4ffe5 | 2000-09-03 23:57:48 +0000 | [diff] [blame] | 181 | #define TCGETS TIOCGETA |
| 182 | #define TCSETS TIOCSETA |
| 183 | #define TCSETSW TIOCSETAW |
| 184 | #define TCSETSF TIOCSETAF |
Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 185 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 186 | struct winsize ws; |
| 187 | #ifdef TIOCGSIZE |
| 188 | struct ttysize ts; |
| 189 | #endif |
| 190 | int i; |
| 191 | |
| 192 | if (entering(tcp)) |
| 193 | return 0; |
| 194 | |
| 195 | switch (code) { |
| 196 | |
| 197 | /* ioctls with termios or termio args */ |
| 198 | |
| 199 | #ifdef TCGETS |
| 200 | case TCGETS: |
| 201 | if (syserror(tcp)) |
| 202 | return 0; |
| 203 | case TCSETS: |
| 204 | case TCSETSW: |
| 205 | case TCSETSF: |
| 206 | if (!verbose(tcp) || umove(tcp, arg, &tios) < 0) |
| 207 | return 0; |
| 208 | if (abbrev(tcp)) { |
| 209 | tprintf(", {"); |
Wichert Akkerman | 2e4ffe5 | 2000-09-03 23:57:48 +0000 | [diff] [blame] | 210 | #ifndef FREEBSD |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 211 | printxval(baud_options, tios.c_cflag & CBAUD, "B???"); |
Wichert Akkerman | 2e4ffe5 | 2000-09-03 23:57:48 +0000 | [diff] [blame] | 212 | #else |
| 213 | printxval(baud_options, tios.c_ispeed, "B???"); |
| 214 | if (tios.c_ispeed != tios.c_ospeed) { |
| 215 | tprintf(" (in)"); |
| 216 | printxval(baud_options, tios.c_ospeed, "B???"); |
| 217 | tprintf(" (out)"); |
| 218 | } |
| 219 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 220 | tprintf(" %sopost %sisig %sicanon %secho ...}", |
| 221 | (tios.c_oflag & OPOST) ? "" : "-", |
| 222 | (tios.c_lflag & ISIG) ? "" : "-", |
| 223 | (tios.c_lflag & ICANON) ? "" : "-", |
| 224 | (tios.c_lflag & ECHO) ? "" : "-"); |
| 225 | return 1; |
| 226 | } |
| 227 | tprintf(", {c_iflags=%#lx, c_oflags=%#lx, ", |
| 228 | (long) tios.c_iflag, (long) tios.c_oflag); |
| 229 | tprintf("c_cflags=%#lx, c_lflags=%#lx, ", |
| 230 | (long) tios.c_cflag, (long) tios.c_lflag); |
Wichert Akkerman | 2e4ffe5 | 2000-09-03 23:57:48 +0000 | [diff] [blame] | 231 | #if !defined(SVR4) && !defined(FREEBSD) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 232 | tprintf("c_line=%u, ", tios.c_line); |
| 233 | #endif |
| 234 | if (!(tios.c_lflag & ICANON)) |
| 235 | tprintf("c_cc[VMIN]=%d, c_cc[VTIME]=%d, ", |
| 236 | tios.c_cc[VMIN], tios.c_cc[VTIME]); |
| 237 | tprintf("c_cc=\""); |
| 238 | for (i = 0; i < NCCS; i++) |
| 239 | tprintf("\\x%02x", tios.c_cc[i]); |
| 240 | tprintf("\"}"); |
| 241 | return 1; |
| 242 | #endif /* TCGETS */ |
| 243 | |
| 244 | #ifdef TCGETA |
| 245 | case TCGETA: |
| 246 | if (syserror(tcp)) |
| 247 | return 0; |
| 248 | case TCSETA: |
| 249 | case TCSETAW: |
| 250 | case TCSETAF: |
| 251 | if (!verbose(tcp) || umove(tcp, arg, &tio) < 0) |
| 252 | return 0; |
| 253 | if (abbrev(tcp)) { |
| 254 | tprintf(", {"); |
| 255 | printxval(baud_options, tio.c_cflag & CBAUD, "B???"); |
| 256 | tprintf(" %sopost %sisig %sicanon %secho ...}", |
| 257 | (tio.c_oflag & OPOST) ? "" : "-", |
| 258 | (tio.c_lflag & ISIG) ? "" : "-", |
| 259 | (tio.c_lflag & ICANON) ? "" : "-", |
| 260 | (tio.c_lflag & ECHO) ? "" : "-"); |
| 261 | return 1; |
| 262 | } |
| 263 | tprintf(", {c_iflags=%#lx, c_oflags=%#lx, ", |
| 264 | (long) tio.c_iflag, (long) tio.c_oflag); |
| 265 | tprintf("c_cflags=%#lx, c_lflags=%#lx, ", |
| 266 | (long) tio.c_cflag, (long) tio.c_lflag); |
| 267 | tprintf("c_line=%u, ", tio.c_line); |
| 268 | #ifdef _VMIN |
| 269 | if (!(tio.c_lflag & ICANON)) |
| 270 | tprintf("c_cc[_VMIN]=%d, c_cc[_VTIME]=%d, ", |
| 271 | tio.c_cc[_VMIN], tio.c_cc[_VTIME]); |
| 272 | #else /* !_VMIN */ |
| 273 | if (!(tio.c_lflag & ICANON)) |
| 274 | tprintf("c_cc[VMIN]=%d, c_cc[VTIME]=%d, ", |
| 275 | tio.c_cc[VMIN], tio.c_cc[VTIME]); |
| 276 | #endif /* !_VMIN */ |
| 277 | tprintf("c_cc=\""); |
| 278 | for (i = 0; i < NCC; i++) |
| 279 | tprintf("\\x%02x", tio.c_cc[i]); |
| 280 | tprintf("\"}"); |
| 281 | return 1; |
| 282 | #endif /* TCGETA */ |
| 283 | |
| 284 | /* ioctls with winsize or ttysize args */ |
| 285 | |
| 286 | #ifdef TIOCGWINSZ |
| 287 | case TIOCGWINSZ: |
| 288 | if (syserror(tcp)) |
| 289 | return 0; |
| 290 | case TIOCSWINSZ: |
| 291 | if (!verbose(tcp) || umove(tcp, arg, &ws) < 0) |
| 292 | return 0; |
| 293 | tprintf(", {ws_row=%d, ws_col=%d, ws_xpixel=%d, ws_ypixel=%d}", |
| 294 | ws.ws_row, ws.ws_col, ws.ws_xpixel, ws.ws_ypixel); |
| 295 | return 1; |
| 296 | #endif /* TIOCGWINSZ */ |
| 297 | |
| 298 | #ifdef TIOCGSIZE |
| 299 | case TIOCGSIZE: |
| 300 | if (syserror(tcp)) |
| 301 | return 0; |
| 302 | case TIOCSSIZE: |
| 303 | if (!verbose(tcp) || umove(tcp, arg, &ts) < 0) |
| 304 | return 0; |
| 305 | tprintf(", {ts_lines=%d, ts_cols=%d}", |
| 306 | ts.ts_lines, ts.ts_cols); |
| 307 | return 1; |
| 308 | #endif |
| 309 | |
| 310 | /* ioctls with a direct decodable arg */ |
Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 311 | #ifdef TCXONC |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 312 | case TCXONC: |
| 313 | tprintf(", "); |
| 314 | printxval(tcxonc_options, arg, "TC???"); |
| 315 | return 1; |
Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 316 | #endif |
| 317 | #ifdef TCLFLSH |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 318 | case TCFLSH: |
| 319 | tprintf(", "); |
| 320 | printxval(tcflsh_options, arg, "TC???"); |
| 321 | return 1; |
Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 322 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 323 | |
| 324 | /* ioctls with an indirect parameter displayed as modem flags */ |
| 325 | |
| 326 | #ifdef TIOCMGET |
| 327 | case TIOCMGET: |
| 328 | case TIOCMBIS: |
| 329 | case TIOCMBIC: |
| 330 | case TIOCMSET: |
| 331 | if (umove(tcp, arg, &arg) < 0) |
| 332 | return 0; |
| 333 | tprintf(", ["); |
| 334 | if (!printflags(modem_flags, arg)) |
| 335 | tprintf("0"); |
| 336 | tprintf("]"); |
| 337 | return 1; |
| 338 | #endif /* TIOCMGET */ |
| 339 | |
| 340 | /* ioctls with an indirect parameter displayed in decimal */ |
| 341 | |
| 342 | case TIOCSPGRP: |
| 343 | case TIOCGPGRP: |
| 344 | #ifdef TIOCGETPGRP |
| 345 | case TIOCGETPGRP: |
| 346 | #endif |
| 347 | #ifdef TIOCSETPGRP |
| 348 | case TIOCSETPGRP: |
| 349 | #endif |
| 350 | #ifdef FIONREAD |
| 351 | case FIONREAD: |
| 352 | #endif |
| 353 | case TIOCOUTQ: |
| 354 | #ifdef FIONBIO |
| 355 | case FIONBIO: |
| 356 | #endif |
| 357 | #ifdef FIOASYNC |
| 358 | case FIOASYNC: |
| 359 | #endif |
| 360 | #ifdef FIOGETOWN |
| 361 | case FIOGETOWN: |
| 362 | #endif |
| 363 | #ifdef FIOSETOWN |
| 364 | case FIOSETOWN: |
| 365 | #endif |
| 366 | #ifdef TIOCGETD |
| 367 | case TIOCGETD: |
| 368 | #endif |
| 369 | #ifdef TIOCSETD |
| 370 | case TIOCSETD: |
| 371 | #endif |
| 372 | #ifdef TIOCPKT |
| 373 | case TIOCPKT: |
| 374 | #endif |
| 375 | #ifdef TIOCREMOTE |
| 376 | case TIOCREMOTE: |
| 377 | #endif |
| 378 | #ifdef TIOCUCNTL |
| 379 | case TIOCUCNTL: |
| 380 | #endif |
| 381 | #ifdef TIOCTCNTL |
| 382 | case TIOCTCNTL: |
| 383 | #endif |
| 384 | #ifdef TIOCSIGNAL |
| 385 | case TIOCSIGNAL: |
| 386 | #endif |
| 387 | #ifdef TIOCSSOFTCAR |
| 388 | case TIOCSSOFTCAR: |
| 389 | #endif |
| 390 | #ifdef TIOCGSOFTCAR |
| 391 | case TIOCGSOFTCAR: |
| 392 | #endif |
| 393 | #ifdef TIOCISPACE |
| 394 | case TIOCISPACE: |
| 395 | #endif |
| 396 | #ifdef TIOCISIZE |
| 397 | case TIOCISIZE: |
| 398 | #endif |
| 399 | #ifdef TIOCSINTR |
| 400 | case TIOCSINTR: |
| 401 | #endif |
Wichert Akkerman | 2e2553a | 1999-05-09 00:29:58 +0000 | [diff] [blame] | 402 | #ifdef TIOCSPTLCK |
| 403 | case TIOCSPTLCK: |
| 404 | #endif |
| 405 | #ifdef TIOCGPTN |
| 406 | case TIOCGPTN: |
| 407 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 408 | tprintf(", "); |
| 409 | printnum(tcp, arg, "%d"); |
| 410 | return 1; |
| 411 | |
| 412 | #if 0 |
| 413 | /* ioctls with an indirect parameter displayed in hex */ |
| 414 | |
| 415 | tprintf(", "); |
| 416 | printnum(tcp, arg, "%#x"); |
| 417 | return 1; |
| 418 | #endif |
| 419 | |
| 420 | /* ioctls with an indirect parameter displayed as a char */ |
| 421 | |
| 422 | #ifdef TIOCSTI |
| 423 | case TIOCSTI: |
| 424 | #endif |
| 425 | tprintf(", "); |
| 426 | printstr(tcp, arg, 1); |
| 427 | return 1; |
| 428 | |
| 429 | /* ioctls with no parameters */ |
| 430 | |
| 431 | #ifdef TIOCSCTTY |
| 432 | case TIOCSCTTY: |
| 433 | #endif |
| 434 | #ifdef TIOCNOTTY |
| 435 | case TIOCNOTTY: |
| 436 | #endif |
| 437 | #ifdef FIOCLEX |
| 438 | case FIOCLEX: |
| 439 | #endif |
| 440 | #ifdef FIONCLEX |
| 441 | case FIONCLEX: |
| 442 | #endif |
| 443 | #ifdef TIOCCONS |
| 444 | case TIOCCONS: |
| 445 | #endif |
| 446 | return 1; |
| 447 | |
| 448 | /* ioctls which are unknown */ |
| 449 | |
| 450 | default: |
| 451 | return 0; |
| 452 | } |
| 453 | } |
| 454 | |