blob: db15ef9b112eb8e2658cd01a26b30b0ef95525ec [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
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +000050#ifdef TCLFLSH
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000051static struct xlat tcflsh_options[] = {
52 { TCIFLUSH, "TCIFLUSH" },
53 { TCOFLUSH, "TCOFLUSH" },
54 { TCIOFLUSH, "TCIOFLUSH" },
55 { 0, NULL },
56};
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +000057#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000058
59static 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 Akkerman5ae21ea2000-05-01 01:53:59 +000080#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 Akkerman76baf7c1999-02-19 00:21:36 +0000125#ifdef EXTA
126 { EXTA, "EXTA" },
127#endif
128#ifdef EXTB
129 { EXTB, "EXTB" },
130#endif
131 { 0, NULL },
132};
133
134static 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
172int
173term_ioctl(tcp, code, arg)
174struct tcb *tcp;
175long code, arg;
176{
177 struct termios tios;
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000178#ifndef FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000179 struct termio tio;
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000180#else
181 struct termios tio;
182#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000183 struct winsize ws;
184#ifdef TIOCGSIZE
185 struct ttysize ts;
186#endif
187 int i;
188
189 if (entering(tcp))
190 return 0;
191
192 switch (code) {
193
194 /* ioctls with termios or termio args */
195
196#ifdef TCGETS
197 case TCGETS:
198 if (syserror(tcp))
199 return 0;
200 case TCSETS:
201 case TCSETSW:
202 case TCSETSF:
203 if (!verbose(tcp) || umove(tcp, arg, &tios) < 0)
204 return 0;
205 if (abbrev(tcp)) {
206 tprintf(", {");
207 printxval(baud_options, tios.c_cflag & CBAUD, "B???");
208 tprintf(" %sopost %sisig %sicanon %secho ...}",
209 (tios.c_oflag & OPOST) ? "" : "-",
210 (tios.c_lflag & ISIG) ? "" : "-",
211 (tios.c_lflag & ICANON) ? "" : "-",
212 (tios.c_lflag & ECHO) ? "" : "-");
213 return 1;
214 }
215 tprintf(", {c_iflags=%#lx, c_oflags=%#lx, ",
216 (long) tios.c_iflag, (long) tios.c_oflag);
217 tprintf("c_cflags=%#lx, c_lflags=%#lx, ",
218 (long) tios.c_cflag, (long) tios.c_lflag);
219#ifndef SVR4
220 tprintf("c_line=%u, ", tios.c_line);
221#endif
222 if (!(tios.c_lflag & ICANON))
223 tprintf("c_cc[VMIN]=%d, c_cc[VTIME]=%d, ",
224 tios.c_cc[VMIN], tios.c_cc[VTIME]);
225 tprintf("c_cc=\"");
226 for (i = 0; i < NCCS; i++)
227 tprintf("\\x%02x", tios.c_cc[i]);
228 tprintf("\"}");
229 return 1;
230#endif /* TCGETS */
231
232#ifdef TCGETA
233 case TCGETA:
234 if (syserror(tcp))
235 return 0;
236 case TCSETA:
237 case TCSETAW:
238 case TCSETAF:
239 if (!verbose(tcp) || umove(tcp, arg, &tio) < 0)
240 return 0;
241 if (abbrev(tcp)) {
242 tprintf(", {");
243 printxval(baud_options, tio.c_cflag & CBAUD, "B???");
244 tprintf(" %sopost %sisig %sicanon %secho ...}",
245 (tio.c_oflag & OPOST) ? "" : "-",
246 (tio.c_lflag & ISIG) ? "" : "-",
247 (tio.c_lflag & ICANON) ? "" : "-",
248 (tio.c_lflag & ECHO) ? "" : "-");
249 return 1;
250 }
251 tprintf(", {c_iflags=%#lx, c_oflags=%#lx, ",
252 (long) tio.c_iflag, (long) tio.c_oflag);
253 tprintf("c_cflags=%#lx, c_lflags=%#lx, ",
254 (long) tio.c_cflag, (long) tio.c_lflag);
255 tprintf("c_line=%u, ", tio.c_line);
256#ifdef _VMIN
257 if (!(tio.c_lflag & ICANON))
258 tprintf("c_cc[_VMIN]=%d, c_cc[_VTIME]=%d, ",
259 tio.c_cc[_VMIN], tio.c_cc[_VTIME]);
260#else /* !_VMIN */
261 if (!(tio.c_lflag & ICANON))
262 tprintf("c_cc[VMIN]=%d, c_cc[VTIME]=%d, ",
263 tio.c_cc[VMIN], tio.c_cc[VTIME]);
264#endif /* !_VMIN */
265 tprintf("c_cc=\"");
266 for (i = 0; i < NCC; i++)
267 tprintf("\\x%02x", tio.c_cc[i]);
268 tprintf("\"}");
269 return 1;
270#endif /* TCGETA */
271
272 /* ioctls with winsize or ttysize args */
273
274#ifdef TIOCGWINSZ
275 case TIOCGWINSZ:
276 if (syserror(tcp))
277 return 0;
278 case TIOCSWINSZ:
279 if (!verbose(tcp) || umove(tcp, arg, &ws) < 0)
280 return 0;
281 tprintf(", {ws_row=%d, ws_col=%d, ws_xpixel=%d, ws_ypixel=%d}",
282 ws.ws_row, ws.ws_col, ws.ws_xpixel, ws.ws_ypixel);
283 return 1;
284#endif /* TIOCGWINSZ */
285
286#ifdef TIOCGSIZE
287 case TIOCGSIZE:
288 if (syserror(tcp))
289 return 0;
290 case TIOCSSIZE:
291 if (!verbose(tcp) || umove(tcp, arg, &ts) < 0)
292 return 0;
293 tprintf(", {ts_lines=%d, ts_cols=%d}",
294 ts.ts_lines, ts.ts_cols);
295 return 1;
296#endif
297
298 /* ioctls with a direct decodable arg */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000299#ifdef TCXONC
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000300 case TCXONC:
301 tprintf(", ");
302 printxval(tcxonc_options, arg, "TC???");
303 return 1;
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000304#endif
305#ifdef TCLFLSH
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000306 case TCFLSH:
307 tprintf(", ");
308 printxval(tcflsh_options, arg, "TC???");
309 return 1;
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000310#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000311
312 /* ioctls with an indirect parameter displayed as modem flags */
313
314#ifdef TIOCMGET
315 case TIOCMGET:
316 case TIOCMBIS:
317 case TIOCMBIC:
318 case TIOCMSET:
319 if (umove(tcp, arg, &arg) < 0)
320 return 0;
321 tprintf(", [");
322 if (!printflags(modem_flags, arg))
323 tprintf("0");
324 tprintf("]");
325 return 1;
326#endif /* TIOCMGET */
327
328 /* ioctls with an indirect parameter displayed in decimal */
329
330 case TIOCSPGRP:
331 case TIOCGPGRP:
332#ifdef TIOCGETPGRP
333 case TIOCGETPGRP:
334#endif
335#ifdef TIOCSETPGRP
336 case TIOCSETPGRP:
337#endif
338#ifdef FIONREAD
339 case FIONREAD:
340#endif
341 case TIOCOUTQ:
342#ifdef FIONBIO
343 case FIONBIO:
344#endif
345#ifdef FIOASYNC
346 case FIOASYNC:
347#endif
348#ifdef FIOGETOWN
349 case FIOGETOWN:
350#endif
351#ifdef FIOSETOWN
352 case FIOSETOWN:
353#endif
354#ifdef TIOCGETD
355 case TIOCGETD:
356#endif
357#ifdef TIOCSETD
358 case TIOCSETD:
359#endif
360#ifdef TIOCPKT
361 case TIOCPKT:
362#endif
363#ifdef TIOCREMOTE
364 case TIOCREMOTE:
365#endif
366#ifdef TIOCUCNTL
367 case TIOCUCNTL:
368#endif
369#ifdef TIOCTCNTL
370 case TIOCTCNTL:
371#endif
372#ifdef TIOCSIGNAL
373 case TIOCSIGNAL:
374#endif
375#ifdef TIOCSSOFTCAR
376 case TIOCSSOFTCAR:
377#endif
378#ifdef TIOCGSOFTCAR
379 case TIOCGSOFTCAR:
380#endif
381#ifdef TIOCISPACE
382 case TIOCISPACE:
383#endif
384#ifdef TIOCISIZE
385 case TIOCISIZE:
386#endif
387#ifdef TIOCSINTR
388 case TIOCSINTR:
389#endif
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000390#ifdef TIOCSPTLCK
391 case TIOCSPTLCK:
392#endif
393#ifdef TIOCGPTN
394 case TIOCGPTN:
395#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000396 tprintf(", ");
397 printnum(tcp, arg, "%d");
398 return 1;
399
400#if 0
401 /* ioctls with an indirect parameter displayed in hex */
402
403 tprintf(", ");
404 printnum(tcp, arg, "%#x");
405 return 1;
406#endif
407
408 /* ioctls with an indirect parameter displayed as a char */
409
410#ifdef TIOCSTI
411 case TIOCSTI:
412#endif
413 tprintf(", ");
414 printstr(tcp, arg, 1);
415 return 1;
416
417 /* ioctls with no parameters */
418
419#ifdef TIOCSCTTY
420 case TIOCSCTTY:
421#endif
422#ifdef TIOCNOTTY
423 case TIOCNOTTY:
424#endif
425#ifdef FIOCLEX
426 case FIOCLEX:
427#endif
428#ifdef FIONCLEX
429 case FIONCLEX:
430#endif
431#ifdef TIOCCONS
432 case TIOCCONS:
433#endif
434 return 1;
435
436 /* ioctls which are unknown */
437
438 default:
439 return 0;
440 }
441}
442