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 $
35 * $DragonFly: src/sys/kern/tty_compat.c,v 1.4 2003/08/26 21:09:02 rob Exp $
38 #include "opt_compat.h"
41 * mapping routines for old line discipline (yuck)
43 #if defined(COMPAT_43) || defined(COMPAT_SUNOS)
45 #include <sys/param.h>
46 #include <sys/systm.h>
47 #include <sys/ioctl_compat.h>
49 #include <sys/kernel.h>
50 #include <sys/sysctl.h>
52 static int ttcompatgetflags (struct tty *tp);
53 static void ttcompatsetflags (struct tty *tp, struct termios *t);
54 static void ttcompatsetlflags (struct tty *tp, struct termios *t);
55 static int ttcompatspeedtab (int speed, struct speedtab *table);
57 static int ttydebug = 0;
58 SYSCTL_INT(_debug, OID_AUTO, ttydebug, CTLFLAG_RW, &ttydebug, 0, "");
60 static struct speedtab compatspeeds[] = {
82 static int compatspcodes[] = {
83 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200,
84 1800, 2400, 4800, 9600, 19200, 38400, 57600, 115200,
88 ttcompatspeedtab(speed, table)
90 struct speedtab *table;
93 return (0); /* hangup */
94 for ( ; table->sp_speed > 0; table++)
95 if (table->sp_speed <= speed) /* nearest one, rounded down */
96 return (table->sp_code);
97 return (1); /* 50, min and not hangup */
101 ttsetcompat(tp, com, data, term)
105 struct termios *term;
110 struct sgttyb *sg = (struct sgttyb *)data;
113 if ((speed = sg->sg_ispeed) > MAX_SPEED || speed < 0)
115 else if (speed != ttcompatspeedtab(tp->t_ispeed, compatspeeds))
116 term->c_ispeed = compatspcodes[speed];
118 term->c_ispeed = tp->t_ispeed;
119 if ((speed = sg->sg_ospeed) > MAX_SPEED || speed < 0)
121 else if (speed != ttcompatspeedtab(tp->t_ospeed, compatspeeds))
122 term->c_ospeed = compatspcodes[speed];
124 term->c_ospeed = tp->t_ospeed;
125 term->c_cc[VERASE] = sg->sg_erase;
126 term->c_cc[VKILL] = sg->sg_kill;
127 tp->t_flags = (tp->t_flags&0xffff0000) | (sg->sg_flags&0xffff);
128 ttcompatsetflags(tp, term);
129 *com = (*com == TIOCSETP) ? TIOCSETAF : TIOCSETA;
133 struct tchars *tc = (struct tchars *)data;
137 cc[VINTR] = tc->t_intrc;
138 cc[VQUIT] = tc->t_quitc;
139 cc[VSTART] = tc->t_startc;
140 cc[VSTOP] = tc->t_stopc;
141 cc[VEOF] = tc->t_eofc;
142 cc[VEOL] = tc->t_brkc;
143 if (tc->t_brkc == -1)
144 cc[VEOL2] = _POSIX_VDISABLE;
149 struct ltchars *ltc = (struct ltchars *)data;
153 cc[VSUSP] = ltc->t_suspc;
154 cc[VDSUSP] = ltc->t_dsuspc;
155 cc[VREPRINT] = ltc->t_rprntc;
156 cc[VDISCARD] = ltc->t_flushc;
157 cc[VWERASE] = ltc->t_werasc;
158 cc[VLNEXT] = ltc->t_lnextc;
165 if (*com == TIOCLSET)
166 tp->t_flags = (tp->t_flags&0xffff) | *(int *)data<<16;
169 (ttcompatgetflags(tp)&0xffff0000)|(tp->t_flags&0xffff);
170 if (*com == TIOCLBIS)
171 tp->t_flags |= *(int *)data<<16;
173 tp->t_flags &= ~(*(int *)data<<16);
175 ttcompatsetlflags(tp, term);
184 ttcompat(tp, com, data, flag)
201 term = tp->t_termios;
202 if ((error = ttsetcompat(tp, &com, data, &term)) != 0)
204 return ttioctl(tp, com, &term, flag);
207 struct sgttyb *sg = (struct sgttyb *)data;
210 sg->sg_ospeed = ttcompatspeedtab(tp->t_ospeed, compatspeeds);
211 if (tp->t_ispeed == 0)
212 sg->sg_ispeed = sg->sg_ospeed;
214 sg->sg_ispeed = ttcompatspeedtab(tp->t_ispeed, compatspeeds);
215 sg->sg_erase = cc[VERASE];
216 sg->sg_kill = cc[VKILL];
217 sg->sg_flags = tp->t_flags = ttcompatgetflags(tp);
221 struct tchars *tc = (struct tchars *)data;
224 tc->t_intrc = cc[VINTR];
225 tc->t_quitc = cc[VQUIT];
226 tc->t_startc = cc[VSTART];
227 tc->t_stopc = cc[VSTOP];
228 tc->t_eofc = cc[VEOF];
229 tc->t_brkc = cc[VEOL];
233 struct ltchars *ltc = (struct ltchars *)data;
236 ltc->t_suspc = cc[VSUSP];
237 ltc->t_dsuspc = cc[VDSUSP];
238 ltc->t_rprntc = cc[VREPRINT];
239 ltc->t_flushc = cc[VDISCARD];
240 ltc->t_werasc = cc[VWERASE];
241 ltc->t_lnextc = cc[VLNEXT];
246 (ttcompatgetflags(tp) & 0xffff0000UL)
247 | (tp->t_flags & 0xffff);
248 *(int *)data = tp->t_flags>>16;
250 printf("CLGET: returning %x\n", *(int *)data);
254 *(int *)data = tp->t_line ? tp->t_line : 2;
260 return (ttioctl(tp, TIOCSETD,
261 *(int *)data == 2 ? (caddr_t)&ldisczero : data, flag));
266 return (ttioctl(tp, TIOCCONS, data, flag));
278 tcflag_t iflag = tp->t_iflag;
279 tcflag_t lflag = tp->t_lflag;
280 tcflag_t oflag = tp->t_oflag;
281 tcflag_t cflag = tp->t_cflag;
286 if (iflag&ICRNL || oflag&ONLCR)
288 if ((cflag&CSIZE) == CS8) {
293 else if (cflag&PARENB) {
300 flags |= EVENP | ODDP;
303 if ((lflag&ICANON) == 0) {
305 if (iflag&(INPCK|ISTRIP|IXON) || lflag&(IEXTEN|ISIG)
306 || (cflag&(CSIZE|PARENB)) != CS8)
311 if (!(flags&RAW) && !(oflag&OPOST) && (cflag&(CSIZE|PARENB)) == CS8)
315 if ((cflag&HUPCL) == 0)
320 flags |= CRTERA|CRTBS;
322 flags |= CRTKIL|CRTBS;
327 if ((iflag&IXANY) == 0)
329 flags |= lflag&(ECHO|TOSTOP|FLUSHO|PENDIN|NOFLSH);
331 printf("getflags: %x\n", flags);
336 ttcompatsetflags(tp, t)
340 int flags = tp->t_flags;
341 tcflag_t iflag = t->c_iflag;
342 tcflag_t oflag = t->c_oflag;
343 tcflag_t lflag = t->c_lflag;
344 tcflag_t cflag = t->c_cflag;
348 lflag &= ~(ECHOCTL|ISIG|ICANON|IEXTEN);
350 iflag &= ~(PARMRK|IGNPAR|IGNCR|INLCR);
351 iflag |= BRKINT|IXON|IMAXBEL;
352 lflag |= ISIG|IEXTEN|ECHOCTL; /* XXX was echoctl on ? */
374 cflag &= ~(CSIZE|PARENB);
375 if (flags&(RAW|LITOUT|PASS8)) {
377 if (!(flags&(RAW|PASS8))
378 || (flags&(RAW|PASS8|ANYP)) == (PASS8|ANYP))
382 if (flags&(RAW|LITOUT))
391 /* XXX don't set INPCK if RAW or PASS8? */
392 if ((flags&(EVENP|ODDP)) == EVENP) {
395 } else if ((flags&(EVENP|ODDP)) == ODDP) {
404 if ((flags&DECCTQ) == 0)
415 ttcompatsetlflags(tp, t)
419 int flags = tp->t_flags;
420 tcflag_t iflag = t->c_iflag;
421 tcflag_t oflag = t->c_oflag;
422 tcflag_t lflag = t->c_lflag;
423 tcflag_t cflag = t->c_cflag;
425 iflag &= ~(PARMRK|IGNPAR|IGNCR|INLCR);
446 if ((flags&DECCTQ) == 0)
458 lflag &= ~(TOSTOP|FLUSHO|PENDIN|NOFLSH);
459 lflag |= flags&(TOSTOP|FLUSHO|PENDIN|NOFLSH);
462 * The next if-else statement is copied from above so don't bother
463 * checking it separately. We could avoid fiddlling with the
464 * character size if the mode is already RAW or if neither the
465 * LITOUT bit or the PASS8 bit is being changed, but the delta of
466 * the change is not available here and skipping the RAW case would
467 * make the code different from above.
469 cflag &= ~(CSIZE|PARENB);
470 if (flags&(RAW|LITOUT|PASS8)) {
472 if (!(flags&(RAW|PASS8))
473 || (flags&(RAW|PASS8|ANYP)) == (PASS8|ANYP))
477 if (flags&(RAW|LITOUT))
491 #endif /* COMPAT_43 || COMPAT_SUNOS */