blob: 5fad3b52f65ccb6780b1b8fe0387381e58ce24f8 [file] [log] [blame]
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001/*
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
Roland McGrath6e87ee02003-01-14 07:53:40 +000032#ifdef LINUX
33/*
34 * The C library's definition of struct termios might differ from
35 * the kernel one, and we need to use the kernel layout.
36 */
37#include <linux/termios.h>
38#else
39
Wichert Akkerman2e2553a1999-05-09 00:29:58 +000040#ifdef HAVE_TERMIO_H
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000041#include <termio.h>
Wichert Akkerman2e2553a1999-05-09 00:29:58 +000042#endif /* HAVE_TERMIO_H */
43
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000044#include <termios.h>
Roland McGrath6e87ee02003-01-14 07:53:40 +000045#endif
Wichert Akkerman2e2553a1999-05-09 00:29:58 +000046
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000047#ifdef HAVE_SYS_FILIO_H
48#include <sys/filio.h>
49#endif
50
51static struct xlat tcxonc_options[] = {
52 { TCOOFF, "TCOOFF" },
53 { TCOON, "TCOON" },
54 { TCIOFF, "TCIOFF" },
55 { TCION, "TCION" },
56 { 0, NULL },
57};
58
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +000059#ifdef TCLFLSH
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000060static struct xlat tcflsh_options[] = {
61 { TCIFLUSH, "TCIFLUSH" },
62 { TCOFLUSH, "TCOFLUSH" },
63 { TCIOFLUSH, "TCIOFLUSH" },
64 { 0, NULL },
65};
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +000066#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000067
68static struct xlat baud_options[] = {
69 { B0, "B0" },
70 { B50, "B50" },
71 { B75, "B75" },
72 { B110, "B110" },
73 { B134, "B134" },
74 { B150, "B150" },
75 { B200, "B200" },
76 { B300, "B300" },
77 { B600, "B600" },
78 { B1200, "B1200" },
79 { B1800, "B1800" },
80 { B2400, "B2400" },
81 { B4800, "B4800" },
82 { B9600, "B9600" },
83#ifdef B19200
84 { B19200, "B19200" },
85#endif
86#ifdef B38400
87 { B38400, "B38400" },
88#endif
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +000089#ifdef B57600
90 { B57600, "B57600" },
91#endif
92#ifdef B115200
93 { B115200, "B115200" },
94#endif
95#ifdef B230400
96 { B230400, "B230400" },
97#endif
98#ifdef B460800
99 { B460800, "B460800" },
100#endif
101#ifdef B500000
102 { B500000, "B500000" },
103#endif
104#ifdef B576000
105 { B576000, "B576000" },
106#endif
107#ifdef B921600
108 { B921600, "B921600" },
109#endif
110#ifdef B1000000
111 { B1000000, "B1000000" },
112#endif
113#ifdef B1152000
114 { B1152000, "B1152000" },
115#endif
116#ifdef B1500000
117 { B1500000, "B1500000" },
118#endif
119#ifdef B2000000
120 { B2000000, "B2000000" },
121#endif
122#ifdef B2500000
123 { B2500000, "B2500000" },
124#endif
125#ifdef B3000000
126 { B3000000, "B3000000" },
127#endif
128#ifdef B3500000
129 { B3500000, "B3500000" },
130#endif
131#ifdef B4000000
132 { B4000000, "B4000000" },
133#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000134#ifdef EXTA
135 { EXTA, "EXTA" },
136#endif
137#ifdef EXTB
138 { EXTB, "EXTB" },
139#endif
140 { 0, NULL },
141};
142
143static struct xlat modem_flags[] = {
144#ifdef TIOCM_LE
145 { TIOCM_LE, "TIOCM_LE", },
146#endif
147#ifdef TIOCM_DTR
148 { TIOCM_DTR, "TIOCM_DTR", },
149#endif
150#ifdef TIOCM_RTS
151 { TIOCM_RTS, "TIOCM_RTS", },
152#endif
153#ifdef TIOCM_ST
154 { TIOCM_ST, "TIOCM_ST", },
155#endif
156#ifdef TIOCM_SR
157 { TIOCM_SR, "TIOCM_SR", },
158#endif
159#ifdef TIOCM_CTS
160 { TIOCM_CTS, "TIOCM_CTS", },
161#endif
162#ifdef TIOCM_CAR
163 { TIOCM_CAR, "TIOCM_CAR", },
164#endif
165#ifdef TIOCM_CD
166 { TIOCM_CD, "TIOCM_CD", },
167#endif
168#ifdef TIOCM_RNG
169 { TIOCM_RNG, "TIOCM_RNG", },
170#endif
171#ifdef TIOCM_RI
172 { TIOCM_RI, "TIOCM_RI", },
173#endif
174#ifdef TIOCM_DSR
175 { TIOCM_DSR, "TIOCM_DSR", },
176#endif
177 { 0, NULL, },
178};
179
180
181int
182term_ioctl(tcp, code, arg)
183struct tcb *tcp;
184long code, arg;
185{
186 struct termios tios;
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000187#ifndef FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000188 struct termio tio;
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000189#else
Wichert Akkerman2e4ffe52000-09-03 23:57:48 +0000190 #define TCGETS TIOCGETA
191 #define TCSETS TIOCSETA
192 #define TCSETSW TIOCSETAW
193 #define TCSETSF TIOCSETAF
Roland McGrath6e87ee02003-01-14 07:53:40 +0000194#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000195 struct winsize ws;
196#ifdef TIOCGSIZE
197 struct ttysize ts;
198#endif
199 int i;
200
201 if (entering(tcp))
202 return 0;
203
204 switch (code) {
205
206 /* ioctls with termios or termio args */
207
208#ifdef TCGETS
209 case TCGETS:
210 if (syserror(tcp))
211 return 0;
212 case TCSETS:
213 case TCSETSW:
214 case TCSETSF:
215 if (!verbose(tcp) || umove(tcp, arg, &tios) < 0)
216 return 0;
217 if (abbrev(tcp)) {
218 tprintf(", {");
Roland McGrath6e87ee02003-01-14 07:53:40 +0000219#ifndef FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000220 printxval(baud_options, tios.c_cflag & CBAUD, "B???");
Wichert Akkerman2e4ffe52000-09-03 23:57:48 +0000221#else
222 printxval(baud_options, tios.c_ispeed, "B???");
223 if (tios.c_ispeed != tios.c_ospeed) {
224 tprintf(" (in)");
225 printxval(baud_options, tios.c_ospeed, "B???");
226 tprintf(" (out)");
227 }
Roland McGrath6e87ee02003-01-14 07:53:40 +0000228#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000229 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) ? "" : "-");
234 return 1;
235 }
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);
Wichert Akkerman2e4ffe52000-09-03 23:57:48 +0000240#if !defined(SVR4) && !defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000241 tprintf("c_line=%u, ", tios.c_line);
242#endif
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]);
246 tprintf("c_cc=\"");
247 for (i = 0; i < NCCS; i++)
248 tprintf("\\x%02x", tios.c_cc[i]);
249 tprintf("\"}");
250 return 1;
251#endif /* TCGETS */
252
253#ifdef TCGETA
254 case TCGETA:
255 if (syserror(tcp))
256 return 0;
257 case TCSETA:
258 case TCSETAW:
259 case TCSETAF:
260 if (!verbose(tcp) || umove(tcp, arg, &tio) < 0)
261 return 0;
262 if (abbrev(tcp)) {
263 tprintf(", {");
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) ? "" : "-");
270 return 1;
271 }
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);
277#ifdef _VMIN
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]);
281#else /* !_VMIN */
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]);
285#endif /* !_VMIN */
286 tprintf("c_cc=\"");
287 for (i = 0; i < NCC; i++)
288 tprintf("\\x%02x", tio.c_cc[i]);
289 tprintf("\"}");
290 return 1;
291#endif /* TCGETA */
292
293 /* ioctls with winsize or ttysize args */
294
295#ifdef TIOCGWINSZ
296 case TIOCGWINSZ:
297 if (syserror(tcp))
298 return 0;
299 case TIOCSWINSZ:
300 if (!verbose(tcp) || umove(tcp, arg, &ws) < 0)
301 return 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);
304 return 1;
305#endif /* TIOCGWINSZ */
306
307#ifdef TIOCGSIZE
308 case TIOCGSIZE:
309 if (syserror(tcp))
310 return 0;
311 case TIOCSSIZE:
312 if (!verbose(tcp) || umove(tcp, arg, &ts) < 0)
313 return 0;
314 tprintf(", {ts_lines=%d, ts_cols=%d}",
315 ts.ts_lines, ts.ts_cols);
316 return 1;
317#endif
318
319 /* ioctls with a direct decodable arg */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000320#ifdef TCXONC
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000321 case TCXONC:
322 tprintf(", ");
323 printxval(tcxonc_options, arg, "TC???");
324 return 1;
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000325#endif
326#ifdef TCLFLSH
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000327 case TCFLSH:
328 tprintf(", ");
329 printxval(tcflsh_options, arg, "TC???");
330 return 1;
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000331#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000332
333 /* ioctls with an indirect parameter displayed as modem flags */
334
335#ifdef TIOCMGET
336 case TIOCMGET:
337 case TIOCMBIS:
338 case TIOCMBIC:
339 case TIOCMSET:
340 if (umove(tcp, arg, &arg) < 0)
341 return 0;
342 tprintf(", [");
343 if (!printflags(modem_flags, arg))
344 tprintf("0");
345 tprintf("]");
346 return 1;
347#endif /* TIOCMGET */
348
349 /* ioctls with an indirect parameter displayed in decimal */
350
351 case TIOCSPGRP:
352 case TIOCGPGRP:
353#ifdef TIOCGETPGRP
354 case TIOCGETPGRP:
355#endif
356#ifdef TIOCSETPGRP
357 case TIOCSETPGRP:
358#endif
359#ifdef FIONREAD
360 case FIONREAD:
361#endif
362 case TIOCOUTQ:
363#ifdef FIONBIO
364 case FIONBIO:
365#endif
366#ifdef FIOASYNC
367 case FIOASYNC:
368#endif
369#ifdef FIOGETOWN
370 case FIOGETOWN:
371#endif
372#ifdef FIOSETOWN
373 case FIOSETOWN:
374#endif
375#ifdef TIOCGETD
376 case TIOCGETD:
377#endif
378#ifdef TIOCSETD
379 case TIOCSETD:
380#endif
381#ifdef TIOCPKT
382 case TIOCPKT:
383#endif
384#ifdef TIOCREMOTE
385 case TIOCREMOTE:
386#endif
387#ifdef TIOCUCNTL
388 case TIOCUCNTL:
389#endif
390#ifdef TIOCTCNTL
391 case TIOCTCNTL:
392#endif
393#ifdef TIOCSIGNAL
394 case TIOCSIGNAL:
395#endif
396#ifdef TIOCSSOFTCAR
397 case TIOCSSOFTCAR:
398#endif
399#ifdef TIOCGSOFTCAR
400 case TIOCGSOFTCAR:
401#endif
402#ifdef TIOCISPACE
403 case TIOCISPACE:
404#endif
405#ifdef TIOCISIZE
406 case TIOCISIZE:
407#endif
408#ifdef TIOCSINTR
409 case TIOCSINTR:
410#endif
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000411#ifdef TIOCSPTLCK
412 case TIOCSPTLCK:
413#endif
414#ifdef TIOCGPTN
415 case TIOCGPTN:
416#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000417 tprintf(", ");
418 printnum(tcp, arg, "%d");
419 return 1;
420
421#if 0
422 /* ioctls with an indirect parameter displayed in hex */
423
424 tprintf(", ");
425 printnum(tcp, arg, "%#x");
426 return 1;
427#endif
428
429 /* ioctls with an indirect parameter displayed as a char */
430
431#ifdef TIOCSTI
432 case TIOCSTI:
433#endif
434 tprintf(", ");
435 printstr(tcp, arg, 1);
436 return 1;
437
438 /* ioctls with no parameters */
439
440#ifdef TIOCSCTTY
441 case TIOCSCTTY:
442#endif
443#ifdef TIOCNOTTY
444 case TIOCNOTTY:
445#endif
446#ifdef FIOCLEX
447 case FIOCLEX:
448#endif
449#ifdef FIONCLEX
450 case FIONCLEX:
451#endif
452#ifdef TIOCCONS
453 case TIOCCONS:
454#endif
455 return 1;
456
457 /* ioctls which are unknown */
458
459 default:
460 return 0;
461 }
462}