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