blob: d083cdd541b57ae97fbed6ee4983148cc90ef93f [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
Elliott Hughesd35df492017-02-15 15:19:05 -080041decode_termios(struct tcb *const tcp, const kernel_ulong_t 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 tprints(", ");
47 if (umove_or_printaddr(tcp, addr, &tios))
48 return;
49 if (abbrev(tcp)) {
50 tprints("{");
51 printxval(baud_options, tios.c_cflag & CBAUD, "B???");
52 tprintf(" %sopost %sisig %sicanon %secho ...}",
53 (tios.c_oflag & OPOST) ? "" : "-",
54 (tios.c_lflag & ISIG) ? "" : "-",
55 (tios.c_lflag & ICANON) ? "" : "-",
56 (tios.c_lflag & ECHO) ? "" : "-");
57 return;
58 }
59 tprintf("{c_iflags=%#lx, c_oflags=%#lx, ",
60 (long) tios.c_iflag, (long) tios.c_oflag);
61 tprintf("c_cflags=%#lx, c_lflags=%#lx, ",
62 (long) tios.c_cflag, (long) tios.c_lflag);
63 tprintf("c_line=%u, ", tios.c_line);
64 if (!(tios.c_lflag & ICANON))
65 tprintf("c_cc[VMIN]=%d, c_cc[VTIME]=%d, ",
66 tios.c_cc[VMIN], tios.c_cc[VTIME]);
Dmitry V. Levincce5aae2016-10-02 16:20:05 +000067 tprints("c_cc=\"");
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +000068 for (i = 0; i < NCCS; i++)
69 tprintf("\\x%02x", tios.c_cc[i]);
Dmitry V. Levincce5aae2016-10-02 16:20:05 +000070 tprints("\"}");
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +000071}
72
73static void
Elliott Hughesd35df492017-02-15 15:19:05 -080074decode_termio(struct tcb *const tcp, const kernel_ulong_t addr)
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +000075{
76 struct termio tio;
77 int i;
78
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +000079 tprints(", ");
80 if (umove_or_printaddr(tcp, addr, &tio))
81 return;
82 if (abbrev(tcp)) {
83 tprints("{");
84 printxval(baud_options, tio.c_cflag & CBAUD, "B???");
85 tprintf(" %sopost %sisig %sicanon %secho ...}",
86 (tio.c_oflag & OPOST) ? "" : "-",
87 (tio.c_lflag & ISIG) ? "" : "-",
88 (tio.c_lflag & ICANON) ? "" : "-",
89 (tio.c_lflag & ECHO) ? "" : "-");
90 return;
91 }
92 tprintf("{c_iflags=%#lx, c_oflags=%#lx, ",
93 (long) tio.c_iflag, (long) tio.c_oflag);
94 tprintf("c_cflags=%#lx, c_lflags=%#lx, ",
95 (long) tio.c_cflag, (long) tio.c_lflag);
96 tprintf("c_line=%u, ", tio.c_line);
97#ifdef _VMIN
98 if (!(tio.c_lflag & ICANON))
99 tprintf("c_cc[_VMIN]=%d, c_cc[_VTIME]=%d, ",
100 tio.c_cc[_VMIN], tio.c_cc[_VTIME]);
101#else /* !_VMIN */
102 if (!(tio.c_lflag & ICANON))
103 tprintf("c_cc[VMIN]=%d, c_cc[VTIME]=%d, ",
104 tio.c_cc[VMIN], tio.c_cc[VTIME]);
105#endif /* !_VMIN */
Dmitry V. Levincce5aae2016-10-02 16:20:05 +0000106 tprints("c_cc=\"");
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +0000107 for (i = 0; i < NCC; i++)
108 tprintf("\\x%02x", tio.c_cc[i]);
Dmitry V. Levincce5aae2016-10-02 16:20:05 +0000109 tprints("\"}");
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +0000110}
111
112static void
Elliott Hughesd35df492017-02-15 15:19:05 -0800113decode_winsize(struct tcb *const tcp, const kernel_ulong_t addr)
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +0000114{
115 struct winsize ws;
116
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +0000117 tprints(", ");
118 if (umove_or_printaddr(tcp, addr, &ws))
119 return;
120 tprintf("{ws_row=%d, ws_col=%d, ws_xpixel=%d, ws_ypixel=%d}",
121 ws.ws_row, ws.ws_col, ws.ws_xpixel, ws.ws_ypixel);
122}
123
124#ifdef TIOCGSIZE
125static void
Elliott Hughesd35df492017-02-15 15:19:05 -0800126decode_ttysize(struct tcb *const tcp, const kernel_ulong_t addr)
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +0000127{
128 struct ttysize ts;
129
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +0000130 tprints(", ");
131 if (umove_or_printaddr(tcp, addr, &ts))
132 return;
133 tprintf("{ts_lines=%d, ts_cols=%d}",
134 ts.ts_lines, ts.ts_cols);
135}
136#endif
137
138static void
Elliott Hughesd35df492017-02-15 15:19:05 -0800139decode_modem_flags(struct tcb *const tcp, const kernel_ulong_t addr)
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +0000140{
141 int i;
142
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +0000143 tprints(", ");
144 if (umove_or_printaddr(tcp, addr, &i))
145 return;
146 tprints("[");
147 printflags(modem_flags, i, "TIOCM_???");
148 tprints("]");
149}
150
151int
Elliott Hughesd35df492017-02-15 15:19:05 -0800152term_ioctl(struct tcb *const tcp, const unsigned int code,
153 const kernel_ulong_t arg)
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +0000154{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000155 switch (code) {
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +0000156 /* struct termios */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000157 case TCGETS:
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +0000158#ifdef TCGETS2
159 case TCGETS2:
160#endif
161 case TIOCGLCKTRMIOS:
162 if (entering(tcp))
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000163 return 0;
164 case TCSETS:
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +0000165#ifdef TCSETS2
166 case TCSETS2:
167#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000168 case TCSETSW:
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +0000169#ifdef TCSETSW2
170 case TCSETSW2:
171#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000172 case TCSETSF:
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +0000173#ifdef TCSETSF2
174 case TCSETSF2:
175#endif
176 case TIOCSLCKTRMIOS:
177 decode_termios(tcp, arg);
178 break;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000179
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +0000180 /* struct termio */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000181 case TCGETA:
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +0000182 if (entering(tcp))
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000183 return 0;
184 case TCSETA:
185 case TCSETAW:
186 case TCSETAF:
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +0000187 decode_termio(tcp, arg);
188 break;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000189
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +0000190 /* struct winsize */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000191 case TIOCGWINSZ:
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +0000192 if (entering(tcp))
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000193 return 0;
194 case TIOCSWINSZ:
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +0000195 decode_winsize(tcp, arg);
196 break;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000197
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +0000198 /* struct ttysize */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000199#ifdef TIOCGSIZE
200 case TIOCGSIZE:
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +0000201 if (entering(tcp))
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000202 return 0;
203 case TIOCSSIZE:
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +0000204 decode_ttysize(tcp, arg);
205 break;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000206#endif
207
208 /* ioctls with a direct decodable arg */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000209 case TCXONC:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200210 tprints(", ");
Elliott Hughesd35df492017-02-15 15:19:05 -0800211 printxval64(tcxonc_options, arg, "TC???");
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +0000212 break;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000213 case TCFLSH:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200214 tprints(", ");
Elliott Hughesd35df492017-02-15 15:19:05 -0800215 printxval64(tcflsh_options, arg, "TC???");
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +0000216 break;
217 case TCSBRK:
218 case TCSBRKP:
Denys Vlasenko6a4ac6c2011-10-22 04:52:18 +0200219 case TIOCSCTTY:
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +0000220 tprintf(", %d", (int) arg);
221 break;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000222
223 /* ioctls with an indirect parameter displayed as modem flags */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000224 case TIOCMGET:
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +0000225 if (entering(tcp))
226 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000227 case TIOCMBIS:
228 case TIOCMBIC:
229 case TIOCMSET:
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +0000230 decode_modem_flags(tcp, arg);
231 break;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000232
233 /* ioctls with an indirect parameter displayed in decimal */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000234 case TIOCGPGRP:
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +0000235 case TIOCGSID:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000236 case TIOCGETD:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000237 case TIOCGSOFTCAR:
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000238 case TIOCGPTN:
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +0000239 case FIONREAD:
240 case TIOCOUTQ:
241#ifdef TIOCGEXCL
242 case TIOCGEXCL:
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000243#endif
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +0000244#ifdef TIOCGDEV
245 case TIOCGDEV:
246#endif
247 if (entering(tcp))
248 return 0;
249 case TIOCSPGRP:
250 case TIOCSETD:
251 case FIONBIO:
252 case FIOASYNC:
253 case TIOCPKT:
254 case TIOCSSOFTCAR:
255 case TIOCSPTLCK:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200256 tprints(", ");
Roland McGrathbcd2c952008-07-22 00:21:43 +0000257 printnum_int(tcp, arg, "%d");
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +0000258 break;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000259
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000260 /* ioctls with an indirect parameter displayed as a char */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000261 case TIOCSTI:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200262 tprints(", ");
Elliott Hughesd35df492017-02-15 15:19:05 -0800263 printstrn(tcp, arg, 1);
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +0000264 break;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000265
266 /* ioctls with no parameters */
267
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +0000268 case TIOCSBRK:
269 case TIOCCBRK:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000270 case TIOCCONS:
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +0000271 case TIOCNOTTY:
272 case TIOCEXCL:
273 case TIOCNXCL:
274 case FIOCLEX:
275 case FIONCLEX:
276#ifdef TIOCVHANGUP
277 case TIOCVHANGUP:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000278#endif
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +0000279#ifdef TIOCSSERIAL
280 case TIOCSSERIAL:
281#endif
282 break;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000283
284 /* ioctls which are unknown */
285
286 default:
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +0000287 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000288 }
Dmitry V. Levinfd3cdc02015-07-13 20:10:20 +0000289
290 return RVAL_DECODED | 1;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000291}