blob: 530ffc4cadc35e28ba31503e4a86ffce00f13f77 [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.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000026 */
27
28#include "defs.h"
Roland McGrath6e87ee02003-01-14 07:53:40 +000029/*
30 * The C library's definition of struct termios might differ from
31 * the kernel one, and we need to use the kernel layout.
32 */
33#include <linux/termios.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000034
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +000035#include "xlat/tcxonc_options.h"
36#include "xlat/tcflsh_options.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +000037#include "xlat/baud_options.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +000038#include "xlat/modem_flags.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000039
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +000040static void
41decode_termios(struct tcb *tcp, const long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000042{
43 struct termios tios;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000044 int i;
45
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +000046 if (!verbose(tcp))
47 return;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000048
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +000049 tprints(", ");
50 if (umove_or_printaddr(tcp, addr, &tios))
51 return;
52 if (abbrev(tcp)) {
53 tprints("{");
54 printxval(baud_options, tios.c_cflag & CBAUD, "B???");
55 tprintf(" %sopost %sisig %sicanon %secho ...}",
56 (tios.c_oflag & OPOST) ? "" : "-",
57 (tios.c_lflag & ISIG) ? "" : "-",
58 (tios.c_lflag & ICANON) ? "" : "-",
59 (tios.c_lflag & ECHO) ? "" : "-");
60 return;
61 }
62 tprintf("{c_iflags=%#lx, c_oflags=%#lx, ",
63 (long) tios.c_iflag, (long) tios.c_oflag);
64 tprintf("c_cflags=%#lx, c_lflags=%#lx, ",
65 (long) tios.c_cflag, (long) tios.c_lflag);
66 tprintf("c_line=%u, ", tios.c_line);
67 if (!(tios.c_lflag & ICANON))
68 tprintf("c_cc[VMIN]=%d, c_cc[VTIME]=%d, ",
69 tios.c_cc[VMIN], tios.c_cc[VTIME]);
70 tprintf("c_cc=\"");
71 for (i = 0; i < NCCS; i++)
72 tprintf("\\x%02x", tios.c_cc[i]);
73 tprintf("\"}");
74}
75
76static void
77decode_termio(struct tcb *tcp, const long addr)
78{
79 struct termio tio;
80 int i;
81
82 if (!verbose(tcp))
83 return;
84
85 tprints(", ");
86 if (umove_or_printaddr(tcp, addr, &tio))
87 return;
88 if (abbrev(tcp)) {
89 tprints("{");
90 printxval(baud_options, tio.c_cflag & CBAUD, "B???");
91 tprintf(" %sopost %sisig %sicanon %secho ...}",
92 (tio.c_oflag & OPOST) ? "" : "-",
93 (tio.c_lflag & ISIG) ? "" : "-",
94 (tio.c_lflag & ICANON) ? "" : "-",
95 (tio.c_lflag & ECHO) ? "" : "-");
96 return;
97 }
98 tprintf("{c_iflags=%#lx, c_oflags=%#lx, ",
99 (long) tio.c_iflag, (long) tio.c_oflag);
100 tprintf("c_cflags=%#lx, c_lflags=%#lx, ",
101 (long) tio.c_cflag, (long) tio.c_lflag);
102 tprintf("c_line=%u, ", tio.c_line);
103#ifdef _VMIN
104 if (!(tio.c_lflag & ICANON))
105 tprintf("c_cc[_VMIN]=%d, c_cc[_VTIME]=%d, ",
106 tio.c_cc[_VMIN], tio.c_cc[_VTIME]);
107#else /* !_VMIN */
108 if (!(tio.c_lflag & ICANON))
109 tprintf("c_cc[VMIN]=%d, c_cc[VTIME]=%d, ",
110 tio.c_cc[VMIN], tio.c_cc[VTIME]);
111#endif /* !_VMIN */
112 tprintf("c_cc=\"");
113 for (i = 0; i < NCC; i++)
114 tprintf("\\x%02x", tio.c_cc[i]);
115 tprintf("\"}");
116}
117
118static void
119decode_winsize(struct tcb *tcp, const long addr)
120{
121 struct winsize ws;
122
123 if (!verbose(tcp))
124 return;
125
126 tprints(", ");
127 if (umove_or_printaddr(tcp, addr, &ws))
128 return;
129 tprintf("{ws_row=%d, ws_col=%d, ws_xpixel=%d, ws_ypixel=%d}",
130 ws.ws_row, ws.ws_col, ws.ws_xpixel, ws.ws_ypixel);
131}
132
133#ifdef TIOCGSIZE
134static void
135decode_ttysize(struct tcb *tcp, const long addr)
136{
137 struct ttysize ts;
138
139 if (!verbose(tcp))
140 return;
141
142 tprints(", ");
143 if (umove_or_printaddr(tcp, addr, &ts))
144 return;
145 tprintf("{ts_lines=%d, ts_cols=%d}",
146 ts.ts_lines, ts.ts_cols);
147}
148#endif
149
150static void
151decode_modem_flags(struct tcb *tcp, const long addr)
152{
153 int i;
154
155 if (!verbose(tcp))
156 return;
157
158 tprints(", ");
159 if (umove_or_printaddr(tcp, addr, &i))
160 return;
161 tprints("[");
162 printflags(modem_flags, i, "TIOCM_???");
163 tprints("]");
164}
165
166int
167term_ioctl(struct tcb *tcp, const unsigned int code, const long arg)
168{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000169 switch (code) {
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +0000170 /* struct termios */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000171 case TCGETS:
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +0000172#ifdef TCGETS2
173 case TCGETS2:
174#endif
175 case TIOCGLCKTRMIOS:
176 if (entering(tcp))
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000177 return 0;
178 case TCSETS:
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +0000179#ifdef TCSETS2
180 case TCSETS2:
181#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000182 case TCSETSW:
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +0000183#ifdef TCSETSW2
184 case TCSETSW2:
185#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000186 case TCSETSF:
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +0000187#ifdef TCSETSF2
188 case TCSETSF2:
189#endif
190 case TIOCSLCKTRMIOS:
191 decode_termios(tcp, arg);
192 break;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000193
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +0000194 /* struct termio */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000195 case TCGETA:
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +0000196 if (entering(tcp))
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000197 return 0;
198 case TCSETA:
199 case TCSETAW:
200 case TCSETAF:
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +0000201 decode_termio(tcp, arg);
202 break;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000203
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +0000204 /* struct winsize */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000205 case TIOCGWINSZ:
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +0000206 if (entering(tcp))
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000207 return 0;
208 case TIOCSWINSZ:
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +0000209 decode_winsize(tcp, arg);
210 break;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000211
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +0000212 /* struct ttysize */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000213#ifdef TIOCGSIZE
214 case TIOCGSIZE:
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +0000215 if (entering(tcp))
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000216 return 0;
217 case TIOCSSIZE:
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +0000218 decode_ttysize(tcp, arg);
219 break;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000220#endif
221
222 /* ioctls with a direct decodable arg */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000223 case TCXONC:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200224 tprints(", ");
Dmitry V. Levin9b8ca232016-05-16 23:36:14 +0000225 printxval_long(tcxonc_options, arg, "TC???");
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +0000226 break;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000227 case TCFLSH:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200228 tprints(", ");
Dmitry V. Levin9b8ca232016-05-16 23:36:14 +0000229 printxval_long(tcflsh_options, arg, "TC???");
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +0000230 break;
231 case TCSBRK:
232 case TCSBRKP:
Denys Vlasenko6a4ac6c2011-10-22 04:52:18 +0200233 case TIOCSCTTY:
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +0000234 tprintf(", %d", (int) arg);
235 break;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000236
237 /* ioctls with an indirect parameter displayed as modem flags */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000238 case TIOCMGET:
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +0000239 if (entering(tcp))
240 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000241 case TIOCMBIS:
242 case TIOCMBIC:
243 case TIOCMSET:
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +0000244 decode_modem_flags(tcp, arg);
245 break;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000246
247 /* ioctls with an indirect parameter displayed in decimal */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000248 case TIOCGPGRP:
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +0000249 case TIOCGSID:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000250 case TIOCGETD:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000251 case TIOCGSOFTCAR:
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000252 case TIOCGPTN:
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +0000253 case FIONREAD:
254 case TIOCOUTQ:
255#ifdef TIOCGEXCL
256 case TIOCGEXCL:
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000257#endif
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +0000258#ifdef TIOCGDEV
259 case TIOCGDEV:
260#endif
261 if (entering(tcp))
262 return 0;
263 case TIOCSPGRP:
264 case TIOCSETD:
265 case FIONBIO:
266 case FIOASYNC:
267 case TIOCPKT:
268 case TIOCSSOFTCAR:
269 case TIOCSPTLCK:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200270 tprints(", ");
Roland McGrathbcd2c952008-07-22 00:21:43 +0000271 printnum_int(tcp, arg, "%d");
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +0000272 break;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000273
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000274 /* ioctls with an indirect parameter displayed as a char */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000275 case TIOCSTI:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200276 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000277 printstr(tcp, arg, 1);
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +0000278 break;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000279
280 /* ioctls with no parameters */
281
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +0000282 case TIOCSBRK:
283 case TIOCCBRK:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000284 case TIOCCONS:
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +0000285 case TIOCNOTTY:
286 case TIOCEXCL:
287 case TIOCNXCL:
288 case FIOCLEX:
289 case FIONCLEX:
290#ifdef TIOCVHANGUP
291 case TIOCVHANGUP:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000292#endif
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +0000293#ifdef TIOCSSERIAL
294 case TIOCSSERIAL:
295#endif
296 break;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000297
298 /* ioctls which are unknown */
299
300 default:
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +0000301 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000302 }
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +0000303
304 return RVAL_DECODED | 1;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000305}