2 * Copyright (c) 1982, 1986, 1991, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * @(#)tty_compat.c 8.1 (Berkeley) 6/10/93
34 * $FreeBSD: src/sys/kern/tty_compat.c,v 1.29 1999/08/28 00:46:20 peter Exp $
37 #include "opt_compat.h"
40 * mapping routines for old line discipline (yuck)
42 #if defined(COMPAT_43) || defined(COMPAT_SUNOS)
44 #include <sys/param.h>
45 #include <sys/systm.h>
46 #include <sys/ioctl_compat.h>
48 #include <sys/kernel.h>
49 #include <sys/sysctl.h>
51 static int ttcompatgetflags __P((struct tty *tp));
52 static void ttcompatsetflags __P((struct tty *tp, struct termios *t));
53 static void ttcompatsetlflags __P((struct tty *tp, struct termios *t));
54 static int ttcompatspeedtab __P((int speed, struct speedtab *table));
56 static int ttydebug = 0;
57 SYSCTL_INT(_debug, OID_AUTO, ttydebug, CTLFLAG_RW, &ttydebug, 0, "");
59 static struct speedtab compatspeeds[] = {
81 static int compatspcodes[] = {
82 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200,
83 1800, 2400, 4800, 9600, 19200, 38400, 57600, 115200,
87 ttcompatspeedtab(speed, table)
89 register struct speedtab *table;
92 return (0); /* hangup */
93 for ( ; table->sp_speed > 0; table++)
94 if (table->sp_speed <= speed) /* nearest one, rounded down */
95 return (table->sp_code);
96 return (1); /* 50, min and not hangup */
100 ttsetcompat(tp, com, data, term)
101 register struct tty *tp;
104 struct termios *term;
109 register struct sgttyb *sg = (struct sgttyb *)data;
112 if ((speed = sg->sg_ispeed) > MAX_SPEED || speed < 0)
114 else if (speed != ttcompatspeedtab(tp->t_ispeed, compatspeeds))
115 term->c_ispeed = compatspcodes[speed];
117 term->c_ispeed = tp->t_ispeed;
118 if ((speed = sg->sg_ospeed) > MAX_SPEED || speed < 0)
120 else if (speed != ttcompatspeedtab(tp->t_ospeed, compatspeeds))
121 term->c_ospeed = compatspcodes[speed];
123 term->c_ospeed = tp->t_ospeed;
124 term->c_cc[VERASE] = sg->sg_erase;
125 term->c_cc[VKILL] = sg->sg_kill;
126 tp->t_flags = (tp->t_flags&0xffff0000) | (sg->sg_flags&0xffff);
127 ttcompatsetflags(tp, term);
128 *com = (*com == TIOCSETP) ? TIOCSETAF : TIOCSETA;
132 struct tchars *tc = (struct tchars *)data;
136 cc[VINTR] = tc->t_intrc;
137 cc[VQUIT] = tc->t_quitc;
138 cc[VSTART] = tc->t_startc;
139 cc[VSTOP] = tc->t_stopc;
140 cc[VEOF] = tc->t_eofc;
141 cc[VEOL] = tc->t_brkc;
142 if (tc->t_brkc == -1)
143 cc[VEOL2] = _POSIX_VDISABLE;
148 struct ltchars *ltc = (struct ltchars *)data;
152 cc[VSUSP] = ltc->t_suspc;
153 cc[VDSUSP] = ltc->t_dsuspc;
154 cc[VREPRINT] = ltc->t_rprntc;
155 cc[VDISCARD] = ltc->t_flushc;
156 cc[VWERASE] = ltc->t_werasc;
157 cc[VLNEXT] = ltc->t_lnextc;
164 if (*com == TIOCLSET)
165 tp->t_flags = (tp->t_flags&0xffff) | *(int *)data<<16;
168 (ttcompatgetflags(tp)&0xffff0000)|(tp->t_flags&0xffff);
169 if (*com == TIOCLBIS)
170 tp->t_flags |= *(int *)data<<16;
172 tp->t_flags &= ~(*(int *)data<<16);
174 ttcompatsetlflags(tp, term);
183 ttcompat(tp, com, data, flag)
184 register struct tty *tp;
200 term = tp->t_termios;
201 if ((error = ttsetcompat(tp, &com, data, &term)) != 0)
203 return ttioctl(tp, com, &term, flag);
206 register struct sgttyb *sg = (struct sgttyb *)data;
207 register cc_t *cc = tp->t_cc;
209 sg->sg_ospeed = ttcompatspeedtab(tp->t_ospeed, compatspeeds);
210 if (tp->t_ispeed == 0)
211 sg->sg_ispeed = sg->sg_ospeed;
213 sg->sg_ispeed = ttcompatspeedtab(tp->t_ispeed, compatspeeds);
214 sg->sg_erase = cc[VERASE];
215 sg->sg_kill = cc[VKILL];
216 sg->sg_flags = tp->t_flags = ttcompatgetflags(tp);
220 struct tchars *tc = (struct tchars *)data;
221 register cc_t *cc = tp->t_cc;
223 tc->t_intrc = cc[VINTR];
224 tc->t_quitc = cc[VQUIT];
225 tc->t_startc = cc[VSTART];
226 tc->t_stopc = cc[VSTOP];
227 tc->t_eofc = cc[VEOF];
228 tc->t_brkc = cc[VEOL];
232 struct ltchars *ltc = (struct ltchars *)data;
233 register cc_t *cc = tp->t_cc;
235 ltc->t_suspc = cc[VSUSP];
236 ltc->t_dsuspc = cc[VDSUSP];
237 ltc->t_rprntc = cc[VREPRINT];
238 ltc->t_flushc = cc[VDISCARD];
239 ltc->t_werasc = cc[VWERASE];
240 ltc->t_lnextc = cc[VLNEXT];
245 (ttcompatgetflags(tp) & 0xffff0000UL)
246 | (tp->t_flags & 0xffff);
247 *(int *)data = tp->t_flags>>16;
249 printf("CLGET: returning %x\n", *(int *)data);
253 *(int *)data = tp->t_line ? tp->t_line : 2;
259 return (ttioctl(tp, TIOCSETD,
260 *(int *)data == 2 ? (caddr_t)&ldisczero : data, flag));
265 return (ttioctl(tp, TIOCCONS, data, flag));
275 register struct tty *tp;
277 register tcflag_t iflag = tp->t_iflag;
278 register tcflag_t lflag = tp->t_lflag;
279 register tcflag_t oflag = tp->t_oflag;
280 register tcflag_t cflag = tp->t_cflag;
281 register int flags = 0;
285 if (iflag&ICRNL || oflag&ONLCR)
287 if ((cflag&CSIZE) == CS8) {
292 else if (cflag&PARENB) {
299 flags |= EVENP | ODDP;
302 if ((lflag&ICANON) == 0) {
304 if (iflag&(INPCK|ISTRIP|IXON) || lflag&(IEXTEN|ISIG)
305 || (cflag&(CSIZE|PARENB)) != CS8)
310 if (!(flags&RAW) && !(oflag&OPOST) && (cflag&(CSIZE|PARENB)) == CS8)
314 if ((cflag&HUPCL) == 0)
319 flags |= CRTERA|CRTBS;
321 flags |= CRTKIL|CRTBS;
326 if ((iflag&IXANY) == 0)
328 flags |= lflag&(ECHO|TOSTOP|FLUSHO|PENDIN|NOFLSH);
330 printf("getflags: %x\n", flags);
335 ttcompatsetflags(tp, t)
336 register struct tty *tp;
337 register struct termios *t;
339 register int flags = tp->t_flags;
340 register tcflag_t iflag = t->c_iflag;
341 register tcflag_t oflag = t->c_oflag;
342 register tcflag_t lflag = t->c_lflag;
343 register tcflag_t cflag = t->c_cflag;
347 lflag &= ~(ECHOCTL|ISIG|ICANON|IEXTEN);
349 iflag &= ~(PARMRK|IGNPAR|IGNCR|INLCR);
350 iflag |= BRKINT|IXON|IMAXBEL;
351 lflag |= ISIG|IEXTEN|ECHOCTL; /* XXX was echoctl on ? */
373 cflag &= ~(CSIZE|PARENB);
374 if (flags&(RAW|LITOUT|PASS8)) {
376 if (!(flags&(RAW|PASS8))
377 || (flags&(RAW|PASS8|ANYP)) == (PASS8|ANYP))
381 if (flags&(RAW|LITOUT))
390 /* XXX don't set INPCK if RAW or PASS8? */
391 if ((flags&(EVENP|ODDP)) == EVENP) {
394 } else if ((flags&(EVENP|ODDP)) == ODDP) {
403 if ((flags&DECCTQ) == 0)
414 ttcompatsetlflags(tp, t)
415 register struct tty *tp;
416 register struct termios *t;
418 register int flags = tp->t_flags;
419 register tcflag_t iflag = t->c_iflag;
420 register tcflag_t oflag = t->c_oflag;
421 register tcflag_t lflag = t->c_lflag;
422 register tcflag_t cflag = t->c_cflag;
424 iflag &= ~(PARMRK|IGNPAR|IGNCR|INLCR);
445 if ((flags&DECCTQ) == 0)
457 lflag &= ~(TOSTOP|FLUSHO|PENDIN|NOFLSH);
458 lflag |= flags&(TOSTOP|FLUSHO|PENDIN|NOFLSH);
461 * The next if-else statement is copied from above so don't bother
462 * checking it separately. We could avoid fiddlling with the
463 * character size if the mode is already RAW or if neither the
464 * LITOUT bit or the PASS8 bit is being changed, but the delta of
465 * the change is not available here and skipping the RAW case would
466 * make the code different from above.
468 cflag &= ~(CSIZE|PARENB);
469 if (flags&(RAW|LITOUT|PASS8)) {
471 if (!(flags&(RAW|PASS8))
472 || (flags&(RAW|PASS8|ANYP)) == (PASS8|ANYP))
476 if (flags&(RAW|LITOUT))
490 #endif /* COMPAT_43 || COMPAT_SUNOS */