blob: a4b5b4857faf13ec8a138db6c679844b765823ee [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
Roland McGrathd9f816f2004-09-04 03:39:20 +000051static const struct xlat tcxonc_options[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000052 { 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
Roland McGrathd9f816f2004-09-04 03:39:20 +000060static const struct xlat tcflsh_options[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000061 { 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
Roland McGrathd9f816f2004-09-04 03:39:20 +000068static const struct xlat baud_options[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000069 { 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
Roland McGrathd9f816f2004-09-04 03:39:20 +0000143static const struct xlat modem_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000144#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
Dmitry V. Levine5e60852009-12-31 22:50:49 +0000181int term_ioctl(struct tcb *tcp, long code, long arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000182{
183 struct termios tios;
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000184#ifndef FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000185 struct termio tio;
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000186#else
Wichert Akkerman2e4ffe52000-09-03 23:57:48 +0000187 #define TCGETS TIOCGETA
188 #define TCSETS TIOCSETA
189 #define TCSETSW TIOCSETAW
190 #define TCSETSF TIOCSETAF
Roland McGrath6e87ee02003-01-14 07:53:40 +0000191#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000192 struct winsize ws;
193#ifdef TIOCGSIZE
194 struct ttysize ts;
195#endif
196 int i;
197
198 if (entering(tcp))
199 return 0;
200
201 switch (code) {
202
203 /* ioctls with termios or termio args */
204
205#ifdef TCGETS
206 case TCGETS:
207 if (syserror(tcp))
208 return 0;
209 case TCSETS:
210 case TCSETSW:
211 case TCSETSF:
212 if (!verbose(tcp) || umove(tcp, arg, &tios) < 0)
213 return 0;
214 if (abbrev(tcp)) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200215 tprints(", {");
Roland McGrath6e87ee02003-01-14 07:53:40 +0000216#ifndef FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000217 printxval(baud_options, tios.c_cflag & CBAUD, "B???");
Wichert Akkerman2e4ffe52000-09-03 23:57:48 +0000218#else
219 printxval(baud_options, tios.c_ispeed, "B???");
220 if (tios.c_ispeed != tios.c_ospeed) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200221 tprints(" (in)");
Wichert Akkerman2e4ffe52000-09-03 23:57:48 +0000222 printxval(baud_options, tios.c_ospeed, "B???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200223 tprints(" (out)");
Wichert Akkerman2e4ffe52000-09-03 23:57:48 +0000224 }
Roland McGrath6e87ee02003-01-14 07:53:40 +0000225#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000226 tprintf(" %sopost %sisig %sicanon %secho ...}",
227 (tios.c_oflag & OPOST) ? "" : "-",
228 (tios.c_lflag & ISIG) ? "" : "-",
229 (tios.c_lflag & ICANON) ? "" : "-",
230 (tios.c_lflag & ECHO) ? "" : "-");
231 return 1;
232 }
233 tprintf(", {c_iflags=%#lx, c_oflags=%#lx, ",
234 (long) tios.c_iflag, (long) tios.c_oflag);
235 tprintf("c_cflags=%#lx, c_lflags=%#lx, ",
236 (long) tios.c_cflag, (long) tios.c_lflag);
Wichert Akkerman2e4ffe52000-09-03 23:57:48 +0000237#if !defined(SVR4) && !defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000238 tprintf("c_line=%u, ", tios.c_line);
239#endif
240 if (!(tios.c_lflag & ICANON))
241 tprintf("c_cc[VMIN]=%d, c_cc[VTIME]=%d, ",
242 tios.c_cc[VMIN], tios.c_cc[VTIME]);
243 tprintf("c_cc=\"");
244 for (i = 0; i < NCCS; i++)
245 tprintf("\\x%02x", tios.c_cc[i]);
246 tprintf("\"}");
247 return 1;
248#endif /* TCGETS */
249
250#ifdef TCGETA
251 case TCGETA:
252 if (syserror(tcp))
253 return 0;
254 case TCSETA:
255 case TCSETAW:
256 case TCSETAF:
257 if (!verbose(tcp) || umove(tcp, arg, &tio) < 0)
258 return 0;
259 if (abbrev(tcp)) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200260 tprints(", {");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000261 printxval(baud_options, tio.c_cflag & CBAUD, "B???");
262 tprintf(" %sopost %sisig %sicanon %secho ...}",
263 (tio.c_oflag & OPOST) ? "" : "-",
264 (tio.c_lflag & ISIG) ? "" : "-",
265 (tio.c_lflag & ICANON) ? "" : "-",
266 (tio.c_lflag & ECHO) ? "" : "-");
267 return 1;
268 }
269 tprintf(", {c_iflags=%#lx, c_oflags=%#lx, ",
270 (long) tio.c_iflag, (long) tio.c_oflag);
271 tprintf("c_cflags=%#lx, c_lflags=%#lx, ",
272 (long) tio.c_cflag, (long) tio.c_lflag);
273 tprintf("c_line=%u, ", tio.c_line);
274#ifdef _VMIN
275 if (!(tio.c_lflag & ICANON))
276 tprintf("c_cc[_VMIN]=%d, c_cc[_VTIME]=%d, ",
277 tio.c_cc[_VMIN], tio.c_cc[_VTIME]);
278#else /* !_VMIN */
279 if (!(tio.c_lflag & ICANON))
280 tprintf("c_cc[VMIN]=%d, c_cc[VTIME]=%d, ",
281 tio.c_cc[VMIN], tio.c_cc[VTIME]);
282#endif /* !_VMIN */
283 tprintf("c_cc=\"");
284 for (i = 0; i < NCC; i++)
285 tprintf("\\x%02x", tio.c_cc[i]);
286 tprintf("\"}");
287 return 1;
288#endif /* TCGETA */
289
290 /* ioctls with winsize or ttysize args */
291
292#ifdef TIOCGWINSZ
293 case TIOCGWINSZ:
294 if (syserror(tcp))
295 return 0;
296 case TIOCSWINSZ:
297 if (!verbose(tcp) || umove(tcp, arg, &ws) < 0)
298 return 0;
299 tprintf(", {ws_row=%d, ws_col=%d, ws_xpixel=%d, ws_ypixel=%d}",
300 ws.ws_row, ws.ws_col, ws.ws_xpixel, ws.ws_ypixel);
301 return 1;
302#endif /* TIOCGWINSZ */
303
304#ifdef TIOCGSIZE
305 case TIOCGSIZE:
306 if (syserror(tcp))
307 return 0;
308 case TIOCSSIZE:
309 if (!verbose(tcp) || umove(tcp, arg, &ts) < 0)
310 return 0;
311 tprintf(", {ts_lines=%d, ts_cols=%d}",
312 ts.ts_lines, ts.ts_cols);
313 return 1;
314#endif
315
316 /* ioctls with a direct decodable arg */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000317#ifdef TCXONC
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000318 case TCXONC:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200319 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000320 printxval(tcxonc_options, arg, "TC???");
321 return 1;
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000322#endif
323#ifdef TCLFLSH
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000324 case TCFLSH:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200325 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000326 printxval(tcflsh_options, arg, "TC???");
327 return 1;
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000328#endif
Denys Vlasenko6a4ac6c2011-10-22 04:52:18 +0200329#ifdef TIOCSCTTY
330 case TIOCSCTTY:
331 tprintf(", %ld", arg);
332 return 1;
333#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000334
335 /* ioctls with an indirect parameter displayed as modem flags */
336
337#ifdef TIOCMGET
338 case TIOCMGET:
339 case TIOCMBIS:
340 case TIOCMBIC:
341 case TIOCMSET:
Roland McGrathbcd2c952008-07-22 00:21:43 +0000342 if (umove(tcp, arg, &i) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000343 return 0;
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200344 tprints(", [");
Roland McGrathbcd2c952008-07-22 00:21:43 +0000345 printflags(modem_flags, i, "TIOCM_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200346 tprints("]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000347 return 1;
348#endif /* TIOCMGET */
349
350 /* ioctls with an indirect parameter displayed in decimal */
351
352 case TIOCSPGRP:
353 case TIOCGPGRP:
354#ifdef TIOCGETPGRP
355 case TIOCGETPGRP:
356#endif
357#ifdef TIOCSETPGRP
358 case TIOCSETPGRP:
359#endif
360#ifdef FIONREAD
361 case FIONREAD:
362#endif
363 case TIOCOUTQ:
364#ifdef FIONBIO
365 case FIONBIO:
366#endif
367#ifdef FIOASYNC
368 case FIOASYNC:
369#endif
370#ifdef FIOGETOWN
371 case FIOGETOWN:
372#endif
373#ifdef FIOSETOWN
374 case FIOSETOWN:
375#endif
376#ifdef TIOCGETD
377 case TIOCGETD:
378#endif
379#ifdef TIOCSETD
380 case TIOCSETD:
381#endif
382#ifdef TIOCPKT
383 case TIOCPKT:
384#endif
385#ifdef TIOCREMOTE
386 case TIOCREMOTE:
387#endif
388#ifdef TIOCUCNTL
389 case TIOCUCNTL:
390#endif
391#ifdef TIOCTCNTL
392 case TIOCTCNTL:
393#endif
394#ifdef TIOCSIGNAL
395 case TIOCSIGNAL:
396#endif
397#ifdef TIOCSSOFTCAR
398 case TIOCSSOFTCAR:
399#endif
400#ifdef TIOCGSOFTCAR
401 case TIOCGSOFTCAR:
402#endif
403#ifdef TIOCISPACE
404 case TIOCISPACE:
405#endif
406#ifdef TIOCISIZE
407 case TIOCISIZE:
408#endif
409#ifdef TIOCSINTR
410 case TIOCSINTR:
411#endif
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000412#ifdef TIOCSPTLCK
413 case TIOCSPTLCK:
414#endif
415#ifdef TIOCGPTN
416 case TIOCGPTN:
417#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200418 tprints(", ");
Roland McGrathbcd2c952008-07-22 00:21:43 +0000419 printnum_int(tcp, arg, "%d");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000420 return 1;
421
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000422 /* ioctls with an indirect parameter displayed as a char */
423
424#ifdef TIOCSTI
425 case TIOCSTI:
426#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200427 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000428 printstr(tcp, arg, 1);
429 return 1;
430
431 /* ioctls with no parameters */
432
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000433#ifdef TIOCNOTTY
434 case TIOCNOTTY:
435#endif
436#ifdef FIOCLEX
437 case FIOCLEX:
438#endif
439#ifdef FIONCLEX
440 case FIONCLEX:
441#endif
442#ifdef TIOCCONS
443 case TIOCCONS:
444#endif
445 return 1;
446
447 /* ioctls which are unknown */
448
449 default:
450 return 0;
451 }
452}