2020-10-10 18:59:41 +03:00
|
|
|
/* $NetBSD: tty_43.c,v 1.39 2020/10/10 15:59:41 christos Exp $ */
|
2008-04-23 17:44:46 +04:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 2008 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
1995-06-25 00:15:55 +04:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 1982, 1986, 1991, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2003-08-07 20:26:28 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1995-06-25 00:15:55 +04:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
1998-03-01 05:20:01 +03:00
|
|
|
* @(#)tty_compat.c 8.2 (Berkeley) 1/9/95
|
1995-06-25 00:15:55 +04:00
|
|
|
*/
|
|
|
|
|
1996-02-02 21:47:50 +03:00
|
|
|
/*
|
1995-06-25 00:15:55 +04:00
|
|
|
* mapping routines for old line discipline (yuck)
|
|
|
|
*/
|
2001-11-13 05:07:52 +03:00
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
2020-10-10 18:59:41 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: tty_43.c,v 1.39 2020/10/10 15:59:41 christos Exp $");
|
2019-01-27 05:08:33 +03:00
|
|
|
|
|
|
|
#if defined(_KERNEL_OPT)
|
|
|
|
#include "opt_compat_netbsd.h"
|
|
|
|
#endif
|
2001-11-13 05:07:52 +03:00
|
|
|
|
1995-06-25 00:15:55 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/proc.h>
|
2000-11-02 14:00:53 +03:00
|
|
|
#include <sys/conf.h>
|
1995-06-25 00:15:55 +04:00
|
|
|
#include <sys/tty.h>
|
|
|
|
#include <sys/termios.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/syslog.h>
|
2019-01-28 18:46:49 +03:00
|
|
|
#include <sys/compat_stub.h>
|
|
|
|
#include <sys/module_hook.h>
|
1996-02-10 03:12:44 +03:00
|
|
|
#include <sys/ioctl_compat.h>
|
1995-06-25 00:15:55 +04:00
|
|
|
|
2019-01-27 05:08:33 +03:00
|
|
|
#include <compat/common/compat_mod.h>
|
2019-01-28 18:46:49 +03:00
|
|
|
#include <compat/sys/ttycom.h>
|
2019-01-27 05:08:33 +03:00
|
|
|
|
1995-06-25 00:15:55 +04:00
|
|
|
int ttydebug = 0;
|
|
|
|
|
2004-04-25 10:23:40 +04:00
|
|
|
static const struct speedtab compatspeeds[] = {
|
1995-06-25 00:15:55 +04:00
|
|
|
#define MAX_SPEED 17
|
|
|
|
{ 115200, 17 },
|
|
|
|
{ 57600, 16 },
|
|
|
|
{ 38400, 15 },
|
|
|
|
{ 19200, 14 },
|
|
|
|
{ 9600, 13 },
|
|
|
|
{ 4800, 12 },
|
|
|
|
{ 2400, 11 },
|
|
|
|
{ 1800, 10 },
|
|
|
|
{ 1200, 9 },
|
|
|
|
{ 600, 8 },
|
|
|
|
{ 300, 7 },
|
|
|
|
{ 200, 6 },
|
|
|
|
{ 150, 5 },
|
|
|
|
{ 134, 4 },
|
|
|
|
{ 110, 3 },
|
|
|
|
{ 75, 2 },
|
|
|
|
{ 50, 1 },
|
|
|
|
{ 0, 0 },
|
|
|
|
{ -1, -1 },
|
|
|
|
};
|
2004-04-25 10:23:40 +04:00
|
|
|
static const int compatspcodes[] = {
|
1995-06-25 00:15:55 +04:00
|
|
|
0, 50, 75, 110, 134, 150, 200, 300, 600, 1200,
|
|
|
|
1800, 2400, 4800, 9600, 19200, 38400, 57600, 115200
|
|
|
|
};
|
|
|
|
|
2008-04-23 17:44:46 +04:00
|
|
|
static int ttcompatgetflags(struct tty *);
|
|
|
|
static void ttcompatsetflags(struct tty *, struct termios *);
|
|
|
|
static void ttcompatsetlflags(struct tty *, struct termios *);
|
1996-03-14 22:31:45 +03:00
|
|
|
|
1995-06-25 00:15:55 +04:00
|
|
|
/*ARGSUSED*/
|
1996-03-14 22:31:45 +03:00
|
|
|
int
|
2019-01-28 18:46:49 +03:00
|
|
|
compat_43_ttioctl(struct tty *tp, u_long com, void *data, int flag,
|
|
|
|
struct lwp *l)
|
1995-06-25 00:15:55 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
switch (com) {
|
|
|
|
case TIOCGETP: {
|
2000-03-30 15:24:16 +04:00
|
|
|
struct sgttyb *sg = (struct sgttyb *)data;
|
|
|
|
int speed;
|
1995-06-25 00:15:55 +04:00
|
|
|
|
2008-04-23 17:44:46 +04:00
|
|
|
mutex_spin_enter(&tty_lock);
|
1995-06-25 00:15:55 +04:00
|
|
|
speed = ttspeedtab(tp->t_ospeed, compatspeeds);
|
|
|
|
sg->sg_ospeed = (speed == -1) ? MAX_SPEED : speed;
|
|
|
|
if (tp->t_ispeed == 0)
|
|
|
|
sg->sg_ispeed = sg->sg_ospeed;
|
|
|
|
else {
|
|
|
|
speed = ttspeedtab(tp->t_ispeed, compatspeeds);
|
|
|
|
sg->sg_ispeed = (speed == -1) ? MAX_SPEED : speed;
|
|
|
|
}
|
2014-05-22 20:31:19 +04:00
|
|
|
sg->sg_erase = tty_getctrlchar(tp, VERASE);
|
|
|
|
sg->sg_kill = tty_getctrlchar(tp, VKILL);
|
1995-06-25 00:15:55 +04:00
|
|
|
sg->sg_flags = ttcompatgetflags(tp);
|
2008-04-23 17:44:46 +04:00
|
|
|
mutex_spin_exit(&tty_lock);
|
1995-06-25 00:15:55 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case TIOCSETP:
|
|
|
|
case TIOCSETN: {
|
2000-03-30 15:24:16 +04:00
|
|
|
struct sgttyb *sg = (struct sgttyb *)data;
|
1995-06-25 00:15:55 +04:00
|
|
|
struct termios term;
|
|
|
|
int speed;
|
|
|
|
|
2008-04-23 17:44:46 +04:00
|
|
|
mutex_spin_enter(&tty_lock);
|
1995-06-25 00:15:55 +04:00
|
|
|
term = tp->t_termios;
|
|
|
|
if ((speed = sg->sg_ispeed) > MAX_SPEED || speed < 0)
|
|
|
|
term.c_ispeed = speed;
|
|
|
|
else
|
|
|
|
term.c_ispeed = compatspcodes[speed];
|
|
|
|
if ((speed = sg->sg_ospeed) > MAX_SPEED || speed < 0)
|
|
|
|
term.c_ospeed = speed;
|
|
|
|
else
|
|
|
|
term.c_ospeed = compatspcodes[speed];
|
|
|
|
term.c_cc[VERASE] = sg->sg_erase;
|
|
|
|
term.c_cc[VKILL] = sg->sg_kill;
|
|
|
|
tp->t_flags = (ttcompatgetflags(tp)&0xffff0000) | (sg->sg_flags&0xffff);
|
|
|
|
ttcompatsetflags(tp, &term);
|
2008-04-23 17:44:46 +04:00
|
|
|
mutex_spin_exit(&tty_lock);
|
1996-02-02 21:47:50 +03:00
|
|
|
return (ttioctl(tp, com == TIOCSETP ? TIOCSETAF : TIOCSETA,
|
2007-03-04 08:59:00 +03:00
|
|
|
(void *)&term, flag, l));
|
1995-06-25 00:15:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
case TIOCGETC: {
|
|
|
|
struct tchars *tc = (struct tchars *)data;
|
|
|
|
|
2014-05-22 20:31:19 +04:00
|
|
|
tc->t_intrc = tty_getctrlchar(tp, VINTR);
|
|
|
|
tc->t_quitc = tty_getctrlchar(tp, VQUIT);
|
|
|
|
tc->t_startc = tty_getctrlchar(tp, VSTART);
|
|
|
|
tc->t_stopc = tty_getctrlchar(tp, VSTOP);
|
|
|
|
tc->t_eofc = tty_getctrlchar(tp, VEOF);
|
|
|
|
tc->t_brkc = tty_getctrlchar(tp, VEOL);
|
1995-06-25 00:15:55 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TIOCSETC: {
|
|
|
|
struct tchars *tc = (struct tchars *)data;
|
|
|
|
|
2014-05-22 20:31:19 +04:00
|
|
|
tty_setctrlchar(tp, VINTR, tc->t_intrc);
|
|
|
|
tty_setctrlchar(tp, VQUIT, tc->t_quitc);
|
|
|
|
tty_setctrlchar(tp, VSTART, tc->t_startc);
|
|
|
|
tty_setctrlchar(tp, VSTOP, tc->t_stopc);
|
|
|
|
tty_setctrlchar(tp, VEOF, tc->t_eofc);
|
|
|
|
tty_setctrlchar(tp, VEOL, tc->t_brkc);
|
1996-05-20 18:29:17 +04:00
|
|
|
if (tc->t_brkc == (char)-1)
|
2014-05-22 20:31:19 +04:00
|
|
|
tty_setctrlchar(tp, VEOL2, _POSIX_VDISABLE);
|
1995-06-25 00:15:55 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TIOCSLTC: {
|
|
|
|
struct ltchars *ltc = (struct ltchars *)data;
|
|
|
|
|
2014-05-22 20:31:19 +04:00
|
|
|
tty_setctrlchar(tp, VSUSP, ltc->t_suspc);
|
|
|
|
tty_setctrlchar(tp, VDSUSP, ltc->t_dsuspc);
|
|
|
|
tty_setctrlchar(tp, VREPRINT, ltc->t_rprntc);
|
|
|
|
tty_setctrlchar(tp, VDISCARD, ltc->t_flushc);
|
|
|
|
tty_setctrlchar(tp, VWERASE, ltc->t_werasc);
|
|
|
|
tty_setctrlchar(tp, VLNEXT, ltc->t_lnextc);
|
1995-06-25 00:15:55 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TIOCGLTC: {
|
|
|
|
struct ltchars *ltc = (struct ltchars *)data;
|
|
|
|
|
2014-05-22 20:31:19 +04:00
|
|
|
ltc->t_suspc = tty_getctrlchar(tp, VSUSP);
|
|
|
|
ltc->t_dsuspc = tty_getctrlchar(tp, VDSUSP);
|
|
|
|
ltc->t_rprntc = tty_getctrlchar(tp, VREPRINT);
|
|
|
|
ltc->t_flushc = tty_getctrlchar(tp, VDISCARD);
|
|
|
|
ltc->t_werasc = tty_getctrlchar(tp, VWERASE);
|
|
|
|
ltc->t_lnextc = tty_getctrlchar(tp, VLNEXT);
|
1995-06-25 00:15:55 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TIOCLBIS:
|
|
|
|
case TIOCLBIC:
|
|
|
|
case TIOCLSET: {
|
|
|
|
struct termios term;
|
2020-10-09 13:41:53 +03:00
|
|
|
int argbits, flags;
|
|
|
|
|
|
|
|
argbits = *(int *)data;
|
|
|
|
if (argbits < 0)
|
|
|
|
return EINVAL;
|
1995-06-25 00:15:55 +04:00
|
|
|
|
2008-04-23 17:44:46 +04:00
|
|
|
mutex_spin_enter(&tty_lock);
|
1995-06-25 00:15:55 +04:00
|
|
|
term = tp->t_termios;
|
|
|
|
flags = ttcompatgetflags(tp);
|
|
|
|
switch (com) {
|
|
|
|
case TIOCLSET:
|
2020-10-09 13:41:53 +03:00
|
|
|
tp->t_flags = (flags & 0xffff) | (argbits << 16);
|
1995-06-25 00:15:55 +04:00
|
|
|
break;
|
|
|
|
case TIOCLBIS:
|
2020-10-09 13:41:53 +03:00
|
|
|
tp->t_flags = flags | (argbits << 16);
|
1995-06-25 00:15:55 +04:00
|
|
|
break;
|
|
|
|
case TIOCLBIC:
|
2020-10-09 13:41:53 +03:00
|
|
|
tp->t_flags = flags & ~(argbits << 16);
|
1995-06-25 00:15:55 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
ttcompatsetlflags(tp, &term);
|
2008-04-23 17:44:46 +04:00
|
|
|
mutex_spin_exit(&tty_lock);
|
2007-03-04 08:59:00 +03:00
|
|
|
return (ttioctl(tp, TIOCSETA, (void *)&term, flag, l));
|
1995-06-25 00:15:55 +04:00
|
|
|
}
|
|
|
|
case TIOCLGET:
|
2008-04-23 17:44:46 +04:00
|
|
|
mutex_spin_enter(&tty_lock);
|
1995-06-25 00:15:55 +04:00
|
|
|
*(int *)data = ttcompatgetflags(tp)>>16;
|
2008-04-23 17:44:46 +04:00
|
|
|
mutex_spin_exit(&tty_lock);
|
1995-06-25 00:15:55 +04:00
|
|
|
if (ttydebug)
|
1996-10-13 04:46:49 +04:00
|
|
|
printf("CLGET: returning %x\n", *(int *)data);
|
1995-06-25 00:15:55 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OTIOCGETD:
|
2008-04-23 17:44:46 +04:00
|
|
|
mutex_spin_enter(&tty_lock);
|
2020-08-08 22:04:58 +03:00
|
|
|
*(int *)data = (tp->t_linesw == NULL || tp->t_linesw->l_no == 0)
|
|
|
|
? 2 /* XXX old NTTYDISC */ : tp->t_linesw->l_no;
|
2008-04-23 17:44:46 +04:00
|
|
|
mutex_spin_exit(&tty_lock);
|
1995-06-25 00:15:55 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OTIOCSETD: {
|
|
|
|
int ldisczero = 0;
|
|
|
|
|
1996-02-02 21:47:50 +03:00
|
|
|
return (ttioctl(tp, TIOCSETD,
|
2007-03-04 08:59:00 +03:00
|
|
|
*(int *)data == 2 ? (void *)&ldisczero : data, flag,
|
2005-12-11 15:16:03 +03:00
|
|
|
l));
|
1995-06-25 00:15:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
case OTIOCCONS:
|
|
|
|
*(int *)data = 1;
|
2005-12-11 15:16:03 +03:00
|
|
|
return (ttioctl(tp, TIOCCONS, data, flag, l));
|
1995-06-25 00:15:55 +04:00
|
|
|
|
|
|
|
case TIOCHPCL:
|
2008-04-23 17:44:46 +04:00
|
|
|
mutex_spin_enter(&tty_lock);
|
1996-02-02 21:47:50 +03:00
|
|
|
SET(tp->t_cflag, HUPCL);
|
2008-04-23 17:44:46 +04:00
|
|
|
mutex_spin_exit(&tty_lock);
|
1995-06-25 00:15:55 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2002-03-17 22:40:26 +03:00
|
|
|
return (EPASSTHROUGH);
|
1995-06-25 00:15:55 +04:00
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2008-04-23 17:44:46 +04:00
|
|
|
static int
|
2007-12-08 21:35:53 +03:00
|
|
|
ttcompatgetflags(struct tty *tp)
|
1995-06-25 00:15:55 +04:00
|
|
|
{
|
2000-03-30 15:24:16 +04:00
|
|
|
tcflag_t iflag = tp->t_iflag;
|
|
|
|
tcflag_t lflag = tp->t_lflag;
|
|
|
|
tcflag_t oflag = tp->t_oflag;
|
|
|
|
tcflag_t cflag = tp->t_cflag;
|
|
|
|
int flags = 0;
|
1996-02-02 21:47:50 +03:00
|
|
|
|
2008-04-23 17:44:46 +04:00
|
|
|
KASSERT(mutex_owned(&tty_lock));
|
|
|
|
|
1996-02-02 21:47:50 +03:00
|
|
|
if (ISSET(iflag, IXOFF))
|
|
|
|
SET(flags, TANDEM);
|
|
|
|
if (ISSET(iflag, ICRNL) || ISSET(oflag, ONLCR))
|
|
|
|
SET(flags, CRMOD);
|
|
|
|
if (ISSET(cflag, PARENB)) {
|
|
|
|
if (ISSET(iflag, INPCK)) {
|
|
|
|
if (ISSET(cflag, PARODD))
|
|
|
|
SET(flags, ODDP);
|
1995-06-25 00:15:55 +04:00
|
|
|
else
|
1996-02-02 21:47:50 +03:00
|
|
|
SET(flags, EVENP);
|
1995-06-25 00:15:55 +04:00
|
|
|
} else
|
1996-02-02 21:47:50 +03:00
|
|
|
SET(flags, ANYP);
|
1995-06-25 00:15:55 +04:00
|
|
|
}
|
1996-02-02 21:47:50 +03:00
|
|
|
|
|
|
|
if (!ISSET(lflag, ICANON)) {
|
1995-06-25 00:15:55 +04:00
|
|
|
/* fudge */
|
1996-02-02 21:47:50 +03:00
|
|
|
if (ISSET(iflag, IXON) || ISSET(lflag, ISIG|IEXTEN) ||
|
|
|
|
ISSET(cflag, PARENB))
|
|
|
|
SET(flags, CBREAK);
|
1995-06-25 00:15:55 +04:00
|
|
|
else
|
1996-02-02 21:47:50 +03:00
|
|
|
SET(flags, RAW);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ISSET(flags, RAW))
|
|
|
|
SET(flags, ISSET(tp->t_flags, LITOUT|PASS8));
|
|
|
|
else if (ISSET(cflag, CSIZE) == CS8) {
|
|
|
|
if (!ISSET(oflag, OPOST))
|
|
|
|
SET(flags, LITOUT);
|
|
|
|
if (!ISSET(iflag, ISTRIP))
|
|
|
|
SET(flags, PASS8);
|
1995-06-25 00:15:55 +04:00
|
|
|
}
|
1996-02-02 21:47:50 +03:00
|
|
|
|
|
|
|
if (ISSET(cflag, MDMBUF))
|
|
|
|
SET(flags, MDMBUF);
|
|
|
|
if (!ISSET(cflag, HUPCL))
|
|
|
|
SET(flags, NOHANG);
|
|
|
|
if (ISSET(oflag, OXTABS))
|
|
|
|
SET(flags, XTABS);
|
|
|
|
if (ISSET(lflag, ECHOE))
|
|
|
|
SET(flags, CRTERA|CRTBS);
|
|
|
|
if (ISSET(lflag, ECHOKE))
|
|
|
|
SET(flags, CRTKIL|CRTBS);
|
|
|
|
if (ISSET(lflag, ECHOPRT))
|
|
|
|
SET(flags, PRTERA);
|
|
|
|
if (ISSET(lflag, ECHOCTL))
|
|
|
|
SET(flags, CTLECH);
|
|
|
|
if (!ISSET(iflag, IXANY))
|
|
|
|
SET(flags, DECCTQ);
|
|
|
|
SET(flags, ISSET(lflag, ECHO|TOSTOP|FLUSHO|PENDIN|NOFLSH));
|
1995-06-25 00:15:55 +04:00
|
|
|
if (ttydebug)
|
1996-10-13 04:46:49 +04:00
|
|
|
printf("getflags: %x\n", flags);
|
1995-06-25 00:15:55 +04:00
|
|
|
return (flags);
|
|
|
|
}
|
|
|
|
|
2008-04-23 17:44:46 +04:00
|
|
|
static void
|
2007-12-08 21:35:53 +03:00
|
|
|
ttcompatsetflags(struct tty *tp, struct termios *t)
|
1995-06-25 00:15:55 +04:00
|
|
|
{
|
2000-03-30 15:24:16 +04:00
|
|
|
int flags = tp->t_flags;
|
2008-04-23 17:44:46 +04:00
|
|
|
|
|
|
|
KASSERT(mutex_owned(&tty_lock));
|
|
|
|
|
2000-03-30 15:24:16 +04:00
|
|
|
tcflag_t iflag = t->c_iflag;
|
|
|
|
tcflag_t oflag = t->c_oflag;
|
|
|
|
tcflag_t lflag = t->c_lflag;
|
|
|
|
tcflag_t cflag = t->c_cflag;
|
1996-02-02 21:47:50 +03:00
|
|
|
|
|
|
|
if (ISSET(flags, TANDEM))
|
|
|
|
SET(iflag, IXOFF);
|
1995-06-25 00:15:55 +04:00
|
|
|
else
|
1996-02-02 21:47:50 +03:00
|
|
|
CLR(iflag, IXOFF);
|
|
|
|
if (ISSET(flags, ECHO))
|
|
|
|
SET(lflag, ECHO);
|
1995-06-25 00:15:55 +04:00
|
|
|
else
|
1996-02-02 21:47:50 +03:00
|
|
|
CLR(lflag, ECHO);
|
|
|
|
if (ISSET(flags, CRMOD)) {
|
|
|
|
SET(iflag, ICRNL);
|
|
|
|
SET(oflag, ONLCR);
|
1995-06-25 00:15:55 +04:00
|
|
|
} else {
|
1996-02-02 21:47:50 +03:00
|
|
|
CLR(iflag, ICRNL);
|
|
|
|
CLR(oflag, ONLCR);
|
1995-06-25 00:15:55 +04:00
|
|
|
}
|
1996-02-02 21:47:50 +03:00
|
|
|
if (ISSET(flags, XTABS))
|
|
|
|
SET(oflag, OXTABS);
|
1995-06-25 00:15:55 +04:00
|
|
|
else
|
1996-02-02 21:47:50 +03:00
|
|
|
CLR(oflag, OXTABS);
|
1995-06-25 00:15:55 +04:00
|
|
|
|
|
|
|
|
1996-02-02 21:47:50 +03:00
|
|
|
if (ISSET(flags, RAW)) {
|
1995-06-25 00:15:55 +04:00
|
|
|
iflag &= IXOFF;
|
1996-02-02 21:47:50 +03:00
|
|
|
CLR(lflag, ISIG|ICANON|IEXTEN);
|
|
|
|
CLR(cflag, PARENB);
|
1995-06-25 00:15:55 +04:00
|
|
|
} else {
|
1996-02-02 21:47:50 +03:00
|
|
|
SET(iflag, BRKINT|IXON|IMAXBEL);
|
|
|
|
SET(lflag, ISIG|IEXTEN);
|
|
|
|
if (ISSET(flags, CBREAK))
|
|
|
|
CLR(lflag, ICANON);
|
1995-06-25 00:15:55 +04:00
|
|
|
else
|
1996-02-02 21:47:50 +03:00
|
|
|
SET(lflag, ICANON);
|
|
|
|
switch (ISSET(flags, ANYP)) {
|
|
|
|
case 0:
|
|
|
|
CLR(cflag, PARENB);
|
|
|
|
break;
|
|
|
|
case ANYP:
|
|
|
|
SET(cflag, PARENB);
|
|
|
|
CLR(iflag, INPCK);
|
|
|
|
break;
|
|
|
|
case EVENP:
|
|
|
|
SET(cflag, PARENB);
|
|
|
|
SET(iflag, INPCK);
|
|
|
|
CLR(cflag, PARODD);
|
|
|
|
break;
|
|
|
|
case ODDP:
|
|
|
|
SET(cflag, PARENB);
|
|
|
|
SET(iflag, INPCK);
|
|
|
|
SET(cflag, PARODD);
|
|
|
|
break;
|
|
|
|
}
|
1995-06-25 00:15:55 +04:00
|
|
|
}
|
|
|
|
|
1996-02-02 21:47:50 +03:00
|
|
|
if (ISSET(flags, RAW|LITOUT|PASS8)) {
|
|
|
|
CLR(cflag, CSIZE);
|
|
|
|
SET(cflag, CS8);
|
|
|
|
if (!ISSET(flags, RAW|PASS8))
|
|
|
|
SET(iflag, ISTRIP);
|
1995-06-25 00:15:55 +04:00
|
|
|
else
|
1996-02-02 21:47:50 +03:00
|
|
|
CLR(iflag, ISTRIP);
|
|
|
|
if (!ISSET(flags, RAW|LITOUT))
|
|
|
|
SET(oflag, OPOST);
|
1995-06-25 00:15:55 +04:00
|
|
|
else
|
1996-02-02 21:47:50 +03:00
|
|
|
CLR(oflag, OPOST);
|
1995-06-25 00:15:55 +04:00
|
|
|
} else {
|
1996-02-02 21:47:50 +03:00
|
|
|
CLR(cflag, CSIZE);
|
|
|
|
SET(cflag, CS7);
|
|
|
|
SET(iflag, ISTRIP);
|
|
|
|
SET(oflag, OPOST);
|
1995-06-25 00:15:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
t->c_iflag = iflag;
|
|
|
|
t->c_oflag = oflag;
|
|
|
|
t->c_lflag = lflag;
|
|
|
|
t->c_cflag = cflag;
|
|
|
|
}
|
|
|
|
|
2008-04-23 17:44:46 +04:00
|
|
|
static void
|
2007-12-08 21:35:53 +03:00
|
|
|
ttcompatsetlflags(struct tty *tp, struct termios *t)
|
1995-06-25 00:15:55 +04:00
|
|
|
{
|
2000-03-30 15:24:16 +04:00
|
|
|
int flags = tp->t_flags;
|
|
|
|
tcflag_t iflag = t->c_iflag;
|
|
|
|
tcflag_t oflag = t->c_oflag;
|
|
|
|
tcflag_t lflag = t->c_lflag;
|
|
|
|
tcflag_t cflag = t->c_cflag;
|
1995-06-25 00:15:55 +04:00
|
|
|
|
2008-04-23 17:44:46 +04:00
|
|
|
KASSERT(mutex_owned(&tty_lock));
|
|
|
|
|
1995-06-25 00:15:55 +04:00
|
|
|
/* Nothing we can do with CRTBS. */
|
1996-02-02 21:47:50 +03:00
|
|
|
if (ISSET(flags, PRTERA))
|
|
|
|
SET(lflag, ECHOPRT);
|
1995-06-25 00:15:55 +04:00
|
|
|
else
|
1996-02-02 21:47:50 +03:00
|
|
|
CLR(lflag, ECHOPRT);
|
|
|
|
if (ISSET(flags, CRTERA))
|
|
|
|
SET(lflag, ECHOE);
|
1995-06-25 00:15:55 +04:00
|
|
|
else
|
1996-02-02 21:47:50 +03:00
|
|
|
CLR(lflag, ECHOE);
|
1995-06-25 00:15:55 +04:00
|
|
|
/* Nothing we can do with TILDE. */
|
1996-02-02 21:47:50 +03:00
|
|
|
if (ISSET(flags, MDMBUF))
|
|
|
|
SET(cflag, MDMBUF);
|
1995-06-25 00:15:55 +04:00
|
|
|
else
|
1996-02-02 21:47:50 +03:00
|
|
|
CLR(cflag, MDMBUF);
|
|
|
|
if (ISSET(flags, NOHANG))
|
|
|
|
CLR(cflag, HUPCL);
|
1995-06-25 00:15:55 +04:00
|
|
|
else
|
1996-02-02 21:47:50 +03:00
|
|
|
SET(cflag, HUPCL);
|
|
|
|
if (ISSET(flags, CRTKIL))
|
|
|
|
SET(lflag, ECHOKE);
|
1995-06-25 00:15:55 +04:00
|
|
|
else
|
1996-02-02 21:47:50 +03:00
|
|
|
CLR(lflag, ECHOKE);
|
|
|
|
if (ISSET(flags, CTLECH))
|
|
|
|
SET(lflag, ECHOCTL);
|
1995-06-25 00:15:55 +04:00
|
|
|
else
|
1996-02-02 21:47:50 +03:00
|
|
|
CLR(lflag, ECHOCTL);
|
|
|
|
if (!ISSET(flags, DECCTQ))
|
|
|
|
SET(iflag, IXANY);
|
1995-06-25 00:15:55 +04:00
|
|
|
else
|
1996-02-02 21:47:50 +03:00
|
|
|
CLR(iflag, IXANY);
|
|
|
|
CLR(lflag, TOSTOP|FLUSHO|PENDIN|NOFLSH);
|
|
|
|
SET(lflag, ISSET(flags, TOSTOP|FLUSHO|PENDIN|NOFLSH));
|
|
|
|
|
|
|
|
if (ISSET(flags, RAW|LITOUT|PASS8)) {
|
|
|
|
CLR(cflag, CSIZE);
|
|
|
|
SET(cflag, CS8);
|
|
|
|
if (!ISSET(flags, RAW|PASS8))
|
|
|
|
SET(iflag, ISTRIP);
|
1995-06-25 00:15:55 +04:00
|
|
|
else
|
1996-02-02 21:47:50 +03:00
|
|
|
CLR(iflag, ISTRIP);
|
|
|
|
if (!ISSET(flags, RAW|LITOUT))
|
|
|
|
SET(oflag, OPOST);
|
1995-06-25 00:15:55 +04:00
|
|
|
else
|
1996-02-02 21:47:50 +03:00
|
|
|
CLR(oflag, OPOST);
|
1995-06-25 00:15:55 +04:00
|
|
|
} else {
|
1996-02-02 21:47:50 +03:00
|
|
|
CLR(cflag, CSIZE);
|
|
|
|
SET(cflag, CS7);
|
|
|
|
SET(iflag, ISTRIP);
|
|
|
|
SET(oflag, OPOST);
|
1995-06-25 00:15:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
t->c_iflag = iflag;
|
|
|
|
t->c_oflag = oflag;
|
|
|
|
t->c_lflag = lflag;
|
|
|
|
t->c_cflag = cflag;
|
|
|
|
}
|
2019-01-27 05:08:33 +03:00
|
|
|
|
|
|
|
int
|
2019-01-28 18:46:49 +03:00
|
|
|
kern_tty_43_init(void)
|
2019-01-27 05:08:33 +03:00
|
|
|
{
|
2019-12-12 05:15:42 +03:00
|
|
|
MODULE_HOOK_SET(tty_ttioctl_43_hook, compat_43_ttioctl);
|
2019-01-27 05:08:33 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2019-01-28 18:46:49 +03:00
|
|
|
kern_tty_43_fini(void)
|
2019-01-27 05:08:33 +03:00
|
|
|
{
|
2019-03-01 14:06:55 +03:00
|
|
|
MODULE_HOOK_UNSET(tty_ttioctl_43_hook);
|
2019-01-27 05:08:33 +03:00
|
|
|
return 0;
|
|
|
|
}
|