2 * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
34 * The C library's definition of struct termios might differ from
35 * the kernel one, and we need to use the kernel layout.
37 #include <linux/termios.h>
42 #endif /* HAVE_TERMIO_H */
47 #ifdef HAVE_SYS_FILIO_H
48 #include <sys/filio.h>
51 static const struct xlat tcxonc_options[] = {
60 static const struct xlat tcflsh_options[] = {
61 { TCIFLUSH, "TCIFLUSH" },
62 { TCOFLUSH, "TCOFLUSH" },
63 { TCIOFLUSH, "TCIOFLUSH" },
68 static const struct xlat baud_options[] = {
93 { B115200, "B115200" },
96 { B230400, "B230400" },
99 { B460800, "B460800" },
102 { B500000, "B500000" },
105 { B576000, "B576000" },
108 { B921600, "B921600" },
111 { B1000000, "B1000000" },
114 { B1152000, "B1152000" },
117 { B1500000, "B1500000" },
120 { B2000000, "B2000000" },
123 { B2500000, "B2500000" },
126 { B3000000, "B3000000" },
129 { B3500000, "B3500000" },
132 { B4000000, "B4000000" },
143 static const struct xlat modem_flags[] = {
145 { TIOCM_LE, "TIOCM_LE", },
148 { TIOCM_DTR, "TIOCM_DTR", },
151 { TIOCM_RTS, "TIOCM_RTS", },
154 { TIOCM_ST, "TIOCM_ST", },
157 { TIOCM_SR, "TIOCM_SR", },
160 { TIOCM_CTS, "TIOCM_CTS", },
163 { TIOCM_CAR, "TIOCM_CAR", },
166 { TIOCM_CD, "TIOCM_CD", },
169 { TIOCM_RNG, "TIOCM_RNG", },
172 { TIOCM_RI, "TIOCM_RI", },
175 { TIOCM_DSR, "TIOCM_DSR", },
182 term_ioctl(tcp, code, arg)
190 #define TCGETS TIOCGETA
191 #define TCSETS TIOCSETA
192 #define TCSETSW TIOCSETAW
193 #define TCSETSF TIOCSETAF
206 /* ioctls with termios or termio args */
215 if (!verbose(tcp) || umove(tcp, arg, &tios) < 0)
220 printxval(baud_options, tios.c_cflag & CBAUD, "B???");
222 printxval(baud_options, tios.c_ispeed, "B???");
223 if (tios.c_ispeed != tios.c_ospeed) {
225 printxval(baud_options, tios.c_ospeed, "B???");
229 tprintf(" %sopost %sisig %sicanon %secho ...}",
230 (tios.c_oflag & OPOST) ? "" : "-",
231 (tios.c_lflag & ISIG) ? "" : "-",
232 (tios.c_lflag & ICANON) ? "" : "-",
233 (tios.c_lflag & ECHO) ? "" : "-");
236 tprintf(", {c_iflags=%#lx, c_oflags=%#lx, ",
237 (long) tios.c_iflag, (long) tios.c_oflag);
238 tprintf("c_cflags=%#lx, c_lflags=%#lx, ",
239 (long) tios.c_cflag, (long) tios.c_lflag);
240 #if !defined(SVR4) && !defined(FREEBSD)
241 tprintf("c_line=%u, ", tios.c_line);
243 if (!(tios.c_lflag & ICANON))
244 tprintf("c_cc[VMIN]=%d, c_cc[VTIME]=%d, ",
245 tios.c_cc[VMIN], tios.c_cc[VTIME]);
247 for (i = 0; i < NCCS; i++)
248 tprintf("\\x%02x", tios.c_cc[i]);
260 if (!verbose(tcp) || umove(tcp, arg, &tio) < 0)
264 printxval(baud_options, tio.c_cflag & CBAUD, "B???");
265 tprintf(" %sopost %sisig %sicanon %secho ...}",
266 (tio.c_oflag & OPOST) ? "" : "-",
267 (tio.c_lflag & ISIG) ? "" : "-",
268 (tio.c_lflag & ICANON) ? "" : "-",
269 (tio.c_lflag & ECHO) ? "" : "-");
272 tprintf(", {c_iflags=%#lx, c_oflags=%#lx, ",
273 (long) tio.c_iflag, (long) tio.c_oflag);
274 tprintf("c_cflags=%#lx, c_lflags=%#lx, ",
275 (long) tio.c_cflag, (long) tio.c_lflag);
276 tprintf("c_line=%u, ", tio.c_line);
278 if (!(tio.c_lflag & ICANON))
279 tprintf("c_cc[_VMIN]=%d, c_cc[_VTIME]=%d, ",
280 tio.c_cc[_VMIN], tio.c_cc[_VTIME]);
282 if (!(tio.c_lflag & ICANON))
283 tprintf("c_cc[VMIN]=%d, c_cc[VTIME]=%d, ",
284 tio.c_cc[VMIN], tio.c_cc[VTIME]);
287 for (i = 0; i < NCC; i++)
288 tprintf("\\x%02x", tio.c_cc[i]);
293 /* ioctls with winsize or ttysize args */
300 if (!verbose(tcp) || umove(tcp, arg, &ws) < 0)
302 tprintf(", {ws_row=%d, ws_col=%d, ws_xpixel=%d, ws_ypixel=%d}",
303 ws.ws_row, ws.ws_col, ws.ws_xpixel, ws.ws_ypixel);
305 #endif /* TIOCGWINSZ */
312 if (!verbose(tcp) || umove(tcp, arg, &ts) < 0)
314 tprintf(", {ts_lines=%d, ts_cols=%d}",
315 ts.ts_lines, ts.ts_cols);
319 /* ioctls with a direct decodable arg */
323 printxval(tcxonc_options, arg, "TC???");
329 printxval(tcflsh_options, arg, "TC???");
333 /* ioctls with an indirect parameter displayed as modem flags */
340 if (umove(tcp, arg, &arg) < 0)
343 printflags(modem_flags, arg, "TIOCM_???");
346 #endif /* TIOCMGET */
348 /* ioctls with an indirect parameter displayed in decimal */
417 printnum(tcp, arg, "%d");
421 /* ioctls with an indirect parameter displayed in hex */
424 printnum(tcp, arg, "%#x");
428 /* ioctls with an indirect parameter displayed as a char */
434 printstr(tcp, arg, 1);
437 /* ioctls with no parameters */
456 /* ioctls which are unknown */