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