10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*8770SJordan.Vaughan@Sun.com * Common Development and Distribution License (the "License").
6*8770SJordan.Vaughan@Sun.com * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
210Sstevel@tonic-gate /*
22*8770SJordan.Vaughan@Sun.com * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
230Sstevel@tonic-gate * Use is subject to license terms.
240Sstevel@tonic-gate */
250Sstevel@tonic-gate
260Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
270Sstevel@tonic-gate /* All Rights Reserved */
280Sstevel@tonic-gate
290Sstevel@tonic-gate /*
300Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988
310Sstevel@tonic-gate * The Regents of the University of California
320Sstevel@tonic-gate * All Rights Reserved
330Sstevel@tonic-gate *
340Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from
350Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its
360Sstevel@tonic-gate * contributors.
370Sstevel@tonic-gate */
380Sstevel@tonic-gate
390Sstevel@tonic-gate /*
400Sstevel@tonic-gate * Module to intercept old V7 and 4BSD "ioctl" calls.
410Sstevel@tonic-gate */
420Sstevel@tonic-gate
430Sstevel@tonic-gate #include <sys/types.h>
440Sstevel@tonic-gate #include <sys/param.h>
450Sstevel@tonic-gate #include <sys/signal.h>
460Sstevel@tonic-gate #include <sys/file.h>
470Sstevel@tonic-gate #include <sys/termios.h>
480Sstevel@tonic-gate #include <sys/ttold.h>
490Sstevel@tonic-gate #include <sys/cmn_err.h>
500Sstevel@tonic-gate #include <sys/stream.h>
510Sstevel@tonic-gate #include <sys/stropts.h>
52*8770SJordan.Vaughan@Sun.com #include <sys/strsubr.h>
530Sstevel@tonic-gate #include <sys/strsun.h>
540Sstevel@tonic-gate #include <sys/errno.h>
550Sstevel@tonic-gate #include <sys/debug.h>
560Sstevel@tonic-gate #include <sys/ttcompat.h>
570Sstevel@tonic-gate #include <sys/ddi.h>
580Sstevel@tonic-gate #include <sys/sunddi.h>
590Sstevel@tonic-gate #include <sys/kmem.h>
600Sstevel@tonic-gate #include <sys/policy.h>
610Sstevel@tonic-gate
620Sstevel@tonic-gate /*
630Sstevel@tonic-gate * This is the loadable module wrapper.
640Sstevel@tonic-gate */
650Sstevel@tonic-gate #include <sys/conf.h>
660Sstevel@tonic-gate #include <sys/modctl.h>
670Sstevel@tonic-gate
680Sstevel@tonic-gate /* See os/streamio.c */
690Sstevel@tonic-gate extern int sgttyb_handling;
700Sstevel@tonic-gate
710Sstevel@tonic-gate static struct streamtab ttcoinfo;
720Sstevel@tonic-gate
730Sstevel@tonic-gate static struct fmodsw fsw = {
740Sstevel@tonic-gate "ttcompat",
750Sstevel@tonic-gate &ttcoinfo,
760Sstevel@tonic-gate D_MTQPAIR | D_MP
770Sstevel@tonic-gate };
780Sstevel@tonic-gate
790Sstevel@tonic-gate /*
800Sstevel@tonic-gate * Module linkage information for the kernel.
810Sstevel@tonic-gate */
820Sstevel@tonic-gate
830Sstevel@tonic-gate static struct modlstrmod modlstrmod = {
840Sstevel@tonic-gate &mod_strmodops,
850Sstevel@tonic-gate "alt ioctl calls",
860Sstevel@tonic-gate &fsw
870Sstevel@tonic-gate };
880Sstevel@tonic-gate
890Sstevel@tonic-gate static struct modlinkage modlinkage = {
900Sstevel@tonic-gate MODREV_1, &modlstrmod, NULL
910Sstevel@tonic-gate };
920Sstevel@tonic-gate
930Sstevel@tonic-gate int
_init(void)940Sstevel@tonic-gate _init(void)
950Sstevel@tonic-gate {
960Sstevel@tonic-gate return (mod_install(&modlinkage));
970Sstevel@tonic-gate }
980Sstevel@tonic-gate
990Sstevel@tonic-gate int
_fini(void)1000Sstevel@tonic-gate _fini(void)
1010Sstevel@tonic-gate {
1020Sstevel@tonic-gate return (mod_remove(&modlinkage));
1030Sstevel@tonic-gate }
1040Sstevel@tonic-gate
1050Sstevel@tonic-gate int
_info(struct modinfo * modinfop)1060Sstevel@tonic-gate _info(struct modinfo *modinfop)
1070Sstevel@tonic-gate {
1080Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop));
1090Sstevel@tonic-gate }
1100Sstevel@tonic-gate
1110Sstevel@tonic-gate static int ttcompatopen(queue_t *, dev_t *, int, int, cred_t *);
1120Sstevel@tonic-gate static int ttcompatclose(queue_t *, int, cred_t *);
1130Sstevel@tonic-gate static void ttcompatrput(queue_t *, mblk_t *);
1140Sstevel@tonic-gate static void ttcompatwput(queue_t *, mblk_t *);
1150Sstevel@tonic-gate
1160Sstevel@tonic-gate static struct module_info ttycompatmiinfo = {
1170Sstevel@tonic-gate 0,
1180Sstevel@tonic-gate "ttcompat",
1190Sstevel@tonic-gate 0,
1200Sstevel@tonic-gate INFPSZ,
1210Sstevel@tonic-gate 2048,
1220Sstevel@tonic-gate 128
1230Sstevel@tonic-gate };
1240Sstevel@tonic-gate
1250Sstevel@tonic-gate static struct qinit ttycompatrinit = {
1260Sstevel@tonic-gate (int (*)())ttcompatrput,
1270Sstevel@tonic-gate NULL,
1280Sstevel@tonic-gate ttcompatopen,
1290Sstevel@tonic-gate ttcompatclose,
1300Sstevel@tonic-gate NULL,
1310Sstevel@tonic-gate &ttycompatmiinfo
1320Sstevel@tonic-gate };
1330Sstevel@tonic-gate
1340Sstevel@tonic-gate static struct module_info ttycompatmoinfo = {
1350Sstevel@tonic-gate 42,
1360Sstevel@tonic-gate "ttcompat",
1370Sstevel@tonic-gate 0,
1380Sstevel@tonic-gate INFPSZ,
1390Sstevel@tonic-gate 300,
1400Sstevel@tonic-gate 200
1410Sstevel@tonic-gate };
1420Sstevel@tonic-gate
1430Sstevel@tonic-gate static struct qinit ttycompatwinit = {
1440Sstevel@tonic-gate (int (*)())ttcompatwput,
1450Sstevel@tonic-gate NULL,
1460Sstevel@tonic-gate ttcompatopen,
1470Sstevel@tonic-gate ttcompatclose,
1480Sstevel@tonic-gate NULL,
1490Sstevel@tonic-gate &ttycompatmoinfo
1500Sstevel@tonic-gate };
1510Sstevel@tonic-gate
1520Sstevel@tonic-gate static struct streamtab ttcoinfo = {
1530Sstevel@tonic-gate &ttycompatrinit,
1540Sstevel@tonic-gate &ttycompatwinit,
1550Sstevel@tonic-gate NULL,
1560Sstevel@tonic-gate NULL
1570Sstevel@tonic-gate };
1580Sstevel@tonic-gate
159*8770SJordan.Vaughan@Sun.com /*
160*8770SJordan.Vaughan@Sun.com * This is the termios structure that is used to reset terminal settings
161*8770SJordan.Vaughan@Sun.com * when the underlying device is an instance of zcons. It came from
162*8770SJordan.Vaughan@Sun.com * cmd/init/init.c and should be kept in-sync with dflt_termios found therein.
163*8770SJordan.Vaughan@Sun.com */
164*8770SJordan.Vaughan@Sun.com static const struct termios base_termios = {
165*8770SJordan.Vaughan@Sun.com BRKINT|ICRNL|IXON|IMAXBEL, /* iflag */
166*8770SJordan.Vaughan@Sun.com OPOST|ONLCR|TAB3, /* oflag */
167*8770SJordan.Vaughan@Sun.com CS8|CREAD|B9600, /* cflag */
168*8770SJordan.Vaughan@Sun.com ISIG|ICANON|ECHO|ECHOE|ECHOK|ECHOCTL|ECHOKE|IEXTEN, /* lflag */
169*8770SJordan.Vaughan@Sun.com CINTR, CQUIT, CERASE, CKILL, CEOF, 0, 0, 0, 0, 0, 0, 0, /* c_cc vals */
170*8770SJordan.Vaughan@Sun.com 0, 0, 0, 0, 0, 0, 0
171*8770SJordan.Vaughan@Sun.com };
172*8770SJordan.Vaughan@Sun.com
173*8770SJordan.Vaughan@Sun.com
1740Sstevel@tonic-gate static void ttcompat_do_ioctl(ttcompat_state_t *, queue_t *, mblk_t *);
1750Sstevel@tonic-gate static void ttcompat_ioctl_ack(queue_t *, mblk_t *);
1760Sstevel@tonic-gate static void ttcopyout(queue_t *, mblk_t *);
1770Sstevel@tonic-gate static void ttcompat_ioctl_nak(queue_t *, mblk_t *);
1780Sstevel@tonic-gate static void from_compat(compat_state_t *, struct termios *);
1790Sstevel@tonic-gate static void to_compat(struct termios *, compat_state_t *);
1800Sstevel@tonic-gate
1810Sstevel@tonic-gate /*
1820Sstevel@tonic-gate * Open - get the current modes and translate them to the V7/4BSD equivalent.
1830Sstevel@tonic-gate */
1840Sstevel@tonic-gate /*ARGSUSED*/
1850Sstevel@tonic-gate static int
ttcompatopen(queue_t * q,dev_t * devp,int oflag,int sflag,cred_t * crp)1860Sstevel@tonic-gate ttcompatopen(queue_t *q, dev_t *devp, int oflag, int sflag, cred_t *crp)
1870Sstevel@tonic-gate {
1880Sstevel@tonic-gate ttcompat_state_t *tp;
189*8770SJordan.Vaughan@Sun.com mblk_t *mp;
190*8770SJordan.Vaughan@Sun.com mblk_t *datamp;
191*8770SJordan.Vaughan@Sun.com struct iocblk *iocb;
192*8770SJordan.Vaughan@Sun.com int error;
1930Sstevel@tonic-gate
1940Sstevel@tonic-gate if (q->q_ptr != NULL) {
1950Sstevel@tonic-gate tp = (ttcompat_state_t *)q->q_ptr;
1960Sstevel@tonic-gate /* fail open if TIOCEXCL was done and its not privileged */
1970Sstevel@tonic-gate if ((tp->t_new_lflags & XCLUDE) &&
1980Sstevel@tonic-gate secpolicy_excl_open(crp) != 0) {
1990Sstevel@tonic-gate return (EBUSY);
2000Sstevel@tonic-gate }
2010Sstevel@tonic-gate return (0); /* already attached */
2020Sstevel@tonic-gate }
2030Sstevel@tonic-gate tp = kmem_zalloc(sizeof (ttcompat_state_t), KM_SLEEP);
2040Sstevel@tonic-gate tp->t_iocpending = NULL;
2050Sstevel@tonic-gate tp->t_state = 0;
2060Sstevel@tonic-gate tp->t_iocid = 0;
2070Sstevel@tonic-gate tp->t_ioccmd = 0;
2080Sstevel@tonic-gate tp->t_new_lflags = 0;
2090Sstevel@tonic-gate tp->t_curstate.t_flags = 0;
2100Sstevel@tonic-gate tp->t_curstate.t_ispeed = B0;
2110Sstevel@tonic-gate tp->t_curstate.t_ospeed = B0;
2120Sstevel@tonic-gate tp->t_curstate.t_erase = '\0';
2130Sstevel@tonic-gate tp->t_curstate.t_kill = '\0';
2140Sstevel@tonic-gate tp->t_curstate.t_intrc = '\0';
2150Sstevel@tonic-gate tp->t_curstate.t_quitc = '\0';
2160Sstevel@tonic-gate tp->t_curstate.t_startc = '\0';
2170Sstevel@tonic-gate tp->t_curstate.t_stopc = '\0';
2180Sstevel@tonic-gate tp->t_curstate.t_eofc = '\0';
2190Sstevel@tonic-gate tp->t_curstate.t_brkc = '\0';
2200Sstevel@tonic-gate tp->t_curstate.t_suspc = '\0';
2210Sstevel@tonic-gate tp->t_curstate.t_dsuspc = '\0';
2220Sstevel@tonic-gate tp->t_curstate.t_rprntc = '\0';
2230Sstevel@tonic-gate tp->t_curstate.t_flushc = '\0';
2240Sstevel@tonic-gate tp->t_curstate.t_werasc = '\0';
2250Sstevel@tonic-gate tp->t_curstate.t_lnextc = '\0';
2260Sstevel@tonic-gate tp->t_curstate.t_xflags = 0;
2270Sstevel@tonic-gate tp->t_bufcallid = 0;
2280Sstevel@tonic-gate tp->t_arg = 0;
2290Sstevel@tonic-gate
2300Sstevel@tonic-gate q->q_ptr = tp;
2310Sstevel@tonic-gate WR(q)->q_ptr = tp;
2320Sstevel@tonic-gate qprocson(q);
233*8770SJordan.Vaughan@Sun.com
234*8770SJordan.Vaughan@Sun.com /*
235*8770SJordan.Vaughan@Sun.com * Determine if the underlying device is a zcons instance. If so,
236*8770SJordan.Vaughan@Sun.com * then issue a termios ioctl to reset the terminal settings.
237*8770SJordan.Vaughan@Sun.com */
238*8770SJordan.Vaughan@Sun.com if (getmajor(q->q_stream->sd_vnode->v_rdev) !=
239*8770SJordan.Vaughan@Sun.com ddi_name_to_major("zcons"))
240*8770SJordan.Vaughan@Sun.com return (0);
241*8770SJordan.Vaughan@Sun.com
242*8770SJordan.Vaughan@Sun.com /*
243*8770SJordan.Vaughan@Sun.com * Create the ioctl message.
244*8770SJordan.Vaughan@Sun.com */
245*8770SJordan.Vaughan@Sun.com if ((mp = mkiocb(TCSETSF)) == NULL) {
246*8770SJordan.Vaughan@Sun.com error = ENOMEM;
247*8770SJordan.Vaughan@Sun.com goto common_error;
248*8770SJordan.Vaughan@Sun.com }
249*8770SJordan.Vaughan@Sun.com if ((datamp = allocb(sizeof (struct termios), BPRI_HI)) == NULL) {
250*8770SJordan.Vaughan@Sun.com freemsg(mp);
251*8770SJordan.Vaughan@Sun.com error = ENOMEM;
252*8770SJordan.Vaughan@Sun.com goto common_error;
253*8770SJordan.Vaughan@Sun.com }
254*8770SJordan.Vaughan@Sun.com iocb = (struct iocblk *)mp->b_rptr;
255*8770SJordan.Vaughan@Sun.com iocb->ioc_count = sizeof (struct termios);
256*8770SJordan.Vaughan@Sun.com bcopy(&base_termios, datamp->b_rptr, sizeof (struct termios));
257*8770SJordan.Vaughan@Sun.com datamp->b_wptr += sizeof (struct termios);
258*8770SJordan.Vaughan@Sun.com mp->b_cont = datamp;
259*8770SJordan.Vaughan@Sun.com
260*8770SJordan.Vaughan@Sun.com /*
261*8770SJordan.Vaughan@Sun.com * Send the ioctl message on its merry way toward the driver.
262*8770SJordan.Vaughan@Sun.com * Set some state beforehand so we can properly wait for
263*8770SJordan.Vaughan@Sun.com * an acknowledgement.
264*8770SJordan.Vaughan@Sun.com */
265*8770SJordan.Vaughan@Sun.com tp->t_state |= TS_IOCWAIT | TS_TIOCNAK;
266*8770SJordan.Vaughan@Sun.com tp->t_iocid = iocb->ioc_id;
267*8770SJordan.Vaughan@Sun.com tp->t_ioccmd = TCSETSF;
268*8770SJordan.Vaughan@Sun.com putnext(WR(q), mp);
269*8770SJordan.Vaughan@Sun.com
270*8770SJordan.Vaughan@Sun.com /*
271*8770SJordan.Vaughan@Sun.com * Wait for an acknowledgement. A NAK is treated as an error.
272*8770SJordan.Vaughan@Sun.com * The presence of the TS_TIOCNAK flag indicates that a NAK was
273*8770SJordan.Vaughan@Sun.com * received.
274*8770SJordan.Vaughan@Sun.com */
275*8770SJordan.Vaughan@Sun.com while (tp->t_state & TS_IOCWAIT) {
276*8770SJordan.Vaughan@Sun.com if (qwait_sig(q) == 0) {
277*8770SJordan.Vaughan@Sun.com error = EINTR;
278*8770SJordan.Vaughan@Sun.com goto common_error;
279*8770SJordan.Vaughan@Sun.com }
280*8770SJordan.Vaughan@Sun.com }
281*8770SJordan.Vaughan@Sun.com if (!(tp->t_state & TS_TIOCNAK))
282*8770SJordan.Vaughan@Sun.com return (0);
283*8770SJordan.Vaughan@Sun.com error = ENOTTY;
284*8770SJordan.Vaughan@Sun.com
285*8770SJordan.Vaughan@Sun.com common_error:
286*8770SJordan.Vaughan@Sun.com qprocsoff(q);
287*8770SJordan.Vaughan@Sun.com kmem_free(tp, sizeof (ttcompat_state_t));
288*8770SJordan.Vaughan@Sun.com q->q_ptr = NULL;
289*8770SJordan.Vaughan@Sun.com WR(q)->q_ptr = NULL;
290*8770SJordan.Vaughan@Sun.com return (error);
2910Sstevel@tonic-gate }
2920Sstevel@tonic-gate
2930Sstevel@tonic-gate /* ARGSUSED1 */
2940Sstevel@tonic-gate static int
ttcompatclose(queue_t * q,int flag,cred_t * crp)2950Sstevel@tonic-gate ttcompatclose(queue_t *q, int flag, cred_t *crp)
2960Sstevel@tonic-gate {
2970Sstevel@tonic-gate ttcompat_state_t *tp = (ttcompat_state_t *)q->q_ptr;
2980Sstevel@tonic-gate mblk_t *mp;
2990Sstevel@tonic-gate
3000Sstevel@tonic-gate /* Dump the state structure, then unlink it */
3010Sstevel@tonic-gate qprocsoff(q);
3020Sstevel@tonic-gate if (tp->t_bufcallid != 0) {
3030Sstevel@tonic-gate qunbufcall(q, tp->t_bufcallid);
3040Sstevel@tonic-gate tp->t_bufcallid = 0;
3050Sstevel@tonic-gate }
3060Sstevel@tonic-gate if ((mp = tp->t_iocpending) != NULL)
3070Sstevel@tonic-gate freemsg(mp);
3080Sstevel@tonic-gate kmem_free(tp, sizeof (ttcompat_state_t));
3090Sstevel@tonic-gate q->q_ptr = NULL;
3100Sstevel@tonic-gate
3110Sstevel@tonic-gate return (0);
3120Sstevel@tonic-gate }
3130Sstevel@tonic-gate
3140Sstevel@tonic-gate /*
3150Sstevel@tonic-gate * Put procedure for input from driver end of stream (read queue).
3160Sstevel@tonic-gate * Most messages just get passed to the next guy up; we intercept
3170Sstevel@tonic-gate * "ioctl" replies, and if it's an "ioctl" whose reply we plan to do
3180Sstevel@tonic-gate * something with, we do it.
3190Sstevel@tonic-gate */
3200Sstevel@tonic-gate static void
ttcompatrput(queue_t * q,mblk_t * mp)3210Sstevel@tonic-gate ttcompatrput(queue_t *q, mblk_t *mp)
3220Sstevel@tonic-gate {
3230Sstevel@tonic-gate switch (mp->b_datap->db_type) {
3240Sstevel@tonic-gate
3250Sstevel@tonic-gate case M_IOCACK:
3260Sstevel@tonic-gate ttcompat_ioctl_ack(q, mp);
3270Sstevel@tonic-gate break;
3280Sstevel@tonic-gate
3290Sstevel@tonic-gate case M_IOCNAK:
3300Sstevel@tonic-gate ttcompat_ioctl_nak(q, mp);
3310Sstevel@tonic-gate break;
3320Sstevel@tonic-gate
3330Sstevel@tonic-gate default:
3340Sstevel@tonic-gate putnext(q, mp);
3350Sstevel@tonic-gate break;
3360Sstevel@tonic-gate }
3370Sstevel@tonic-gate }
3380Sstevel@tonic-gate
3390Sstevel@tonic-gate /*
3400Sstevel@tonic-gate * Line discipline output queue put procedure: speeds M_IOCTL
3410Sstevel@tonic-gate * messages.
3420Sstevel@tonic-gate */
3430Sstevel@tonic-gate static void
ttcompatwput(queue_t * q,mblk_t * mp)3440Sstevel@tonic-gate ttcompatwput(queue_t *q, mblk_t *mp)
3450Sstevel@tonic-gate {
3460Sstevel@tonic-gate ttcompat_state_t *tp;
3470Sstevel@tonic-gate struct copyreq *cqp;
3480Sstevel@tonic-gate struct copyresp *csp;
3490Sstevel@tonic-gate struct iocblk *iocbp;
3500Sstevel@tonic-gate
3510Sstevel@tonic-gate tp = (ttcompat_state_t *)q->q_ptr;
3520Sstevel@tonic-gate
3530Sstevel@tonic-gate /*
3540Sstevel@tonic-gate * Process some M_IOCTL messages here; pass everything else down.
3550Sstevel@tonic-gate */
3560Sstevel@tonic-gate switch (mp->b_datap->db_type) {
3570Sstevel@tonic-gate
3580Sstevel@tonic-gate default:
3590Sstevel@tonic-gate putnext(q, mp);
3600Sstevel@tonic-gate return;
3610Sstevel@tonic-gate
3620Sstevel@tonic-gate case M_IOCTL:
3630Sstevel@tonic-gate iocbp = (struct iocblk *)mp->b_rptr;
3640Sstevel@tonic-gate
3650Sstevel@tonic-gate switch (iocbp->ioc_cmd) {
3660Sstevel@tonic-gate
3670Sstevel@tonic-gate default:
3680Sstevel@tonic-gate /* these are ioctls with no arguments or are known to stream head */
3690Sstevel@tonic-gate /* process them right away */
3700Sstevel@tonic-gate ttcompat_do_ioctl(tp, q, mp);
3710Sstevel@tonic-gate return;
3720Sstevel@tonic-gate case TIOCSETN:
3730Sstevel@tonic-gate case TIOCSLTC:
3740Sstevel@tonic-gate case TIOCSETC:
3750Sstevel@tonic-gate case TIOCLBIS:
3760Sstevel@tonic-gate case TIOCLBIC:
3770Sstevel@tonic-gate case TIOCLSET:
3780Sstevel@tonic-gate case TIOCFLUSH:
3790Sstevel@tonic-gate if (iocbp->ioc_count != TRANSPARENT) {
3800Sstevel@tonic-gate putnext(q, mp);
3810Sstevel@tonic-gate return;
3820Sstevel@tonic-gate }
3830Sstevel@tonic-gate
3840Sstevel@tonic-gate mp->b_datap->db_type = M_COPYIN;
3850Sstevel@tonic-gate cqp = (struct copyreq *)mp->b_rptr;
3860Sstevel@tonic-gate cqp->cq_addr = (caddr_t)*(intptr_t *)mp->b_cont->b_rptr;
3870Sstevel@tonic-gate switch (iocbp->ioc_cmd) {
3880Sstevel@tonic-gate case TIOCSETN:
3890Sstevel@tonic-gate cqp->cq_size = sizeof (struct sgttyb);
3900Sstevel@tonic-gate break;
3910Sstevel@tonic-gate case TIOCSLTC:
3920Sstevel@tonic-gate cqp->cq_size = sizeof (struct ltchars);
3930Sstevel@tonic-gate break;
3940Sstevel@tonic-gate case TIOCSETC:
3950Sstevel@tonic-gate cqp->cq_size = sizeof (struct tchars);
3960Sstevel@tonic-gate break;
3970Sstevel@tonic-gate case TIOCLBIS:
3980Sstevel@tonic-gate case TIOCLBIC:
3990Sstevel@tonic-gate case TIOCLSET:
4000Sstevel@tonic-gate case TIOCFLUSH:
4010Sstevel@tonic-gate cqp->cq_size = sizeof (int);
4020Sstevel@tonic-gate break;
4030Sstevel@tonic-gate default:
4040Sstevel@tonic-gate break;
4050Sstevel@tonic-gate }
4060Sstevel@tonic-gate cqp->cq_flag = 0;
4070Sstevel@tonic-gate cqp->cq_private = NULL;
4080Sstevel@tonic-gate freemsg(mp->b_cont);
4090Sstevel@tonic-gate mp->b_cont = NULL;
4100Sstevel@tonic-gate mp->b_wptr = mp->b_rptr + sizeof (struct copyreq);
4110Sstevel@tonic-gate tp->t_ioccmd = iocbp->ioc_cmd;
4120Sstevel@tonic-gate tp->t_state |= TS_W_IN;
4130Sstevel@tonic-gate qreply(q, mp);
4140Sstevel@tonic-gate return;
4150Sstevel@tonic-gate
4160Sstevel@tonic-gate } /* switch ioc_cmd */
4170Sstevel@tonic-gate case M_IOCDATA:
4180Sstevel@tonic-gate csp = (struct copyresp *)mp->b_rptr;
4190Sstevel@tonic-gate
4200Sstevel@tonic-gate switch (csp->cp_cmd) {
4210Sstevel@tonic-gate
4220Sstevel@tonic-gate default:
4230Sstevel@tonic-gate putnext(q, mp);
4240Sstevel@tonic-gate return;
4250Sstevel@tonic-gate
4260Sstevel@tonic-gate case TIOCSETN:
4270Sstevel@tonic-gate case TIOCSLTC:
4280Sstevel@tonic-gate case TIOCSETC:
4290Sstevel@tonic-gate case TIOCLBIS:
4300Sstevel@tonic-gate case TIOCLBIC:
4310Sstevel@tonic-gate case TIOCLSET:
4320Sstevel@tonic-gate case TIOCFLUSH:
4330Sstevel@tonic-gate tp->t_state &= ~TS_W_IN;
4340Sstevel@tonic-gate if (csp->cp_rval != 0) { /* failure */
4350Sstevel@tonic-gate freemsg(mp);
4360Sstevel@tonic-gate return;
4370Sstevel@tonic-gate }
4380Sstevel@tonic-gate
4390Sstevel@tonic-gate /* make it look like an ioctl */
4400Sstevel@tonic-gate mp->b_datap->db_type = M_IOCTL;
4410Sstevel@tonic-gate mp->b_wptr = mp->b_rptr + sizeof (struct iocblk);
4420Sstevel@tonic-gate iocbp = (struct iocblk *)mp->b_rptr;
4430Sstevel@tonic-gate iocbp->ioc_count = MBLKL(mp->b_cont);
4440Sstevel@tonic-gate iocbp->ioc_error = 0;
4450Sstevel@tonic-gate iocbp->ioc_rval = 0;
4460Sstevel@tonic-gate ttcompat_do_ioctl(tp, q, mp);
4470Sstevel@tonic-gate return;
4480Sstevel@tonic-gate
4490Sstevel@tonic-gate case TIOCGLTC:
4500Sstevel@tonic-gate case TIOCLGET:
4510Sstevel@tonic-gate case TIOCGETC:
4520Sstevel@tonic-gate tp->t_state &= ~TS_W_OUT;
4530Sstevel@tonic-gate if (csp->cp_rval != 0) { /* failure */
4540Sstevel@tonic-gate freemsg(mp);
4550Sstevel@tonic-gate return;
4560Sstevel@tonic-gate }
4570Sstevel@tonic-gate
4580Sstevel@tonic-gate iocbp = (struct iocblk *)mp->b_rptr;
4590Sstevel@tonic-gate iocbp->ioc_count = 0;
4600Sstevel@tonic-gate iocbp->ioc_error = 0;
4610Sstevel@tonic-gate iocbp->ioc_rval = 0;
4620Sstevel@tonic-gate mp->b_datap->db_type = M_IOCACK;
4630Sstevel@tonic-gate qreply(q, mp);
4640Sstevel@tonic-gate return;
4650Sstevel@tonic-gate
4660Sstevel@tonic-gate } /* switch cp_cmd */
4670Sstevel@tonic-gate } /* end message switch */
4680Sstevel@tonic-gate }
4690Sstevel@tonic-gate
4700Sstevel@tonic-gate /*
4710Sstevel@tonic-gate * Retry an "ioctl", now that "bufcall" claims we may be able to allocate
4720Sstevel@tonic-gate * the buffer we need.
4730Sstevel@tonic-gate */
4740Sstevel@tonic-gate static void
ttcompat_reioctl(void * arg)4750Sstevel@tonic-gate ttcompat_reioctl(void *arg)
4760Sstevel@tonic-gate {
4770Sstevel@tonic-gate queue_t *q = arg;
4780Sstevel@tonic-gate ttcompat_state_t *tp;
4790Sstevel@tonic-gate mblk_t *mp;
4800Sstevel@tonic-gate
4810Sstevel@tonic-gate tp = (ttcompat_state_t *)q->q_ptr;
4820Sstevel@tonic-gate tp->t_bufcallid = 0;
4830Sstevel@tonic-gate
4840Sstevel@tonic-gate if ((mp = tp->t_iocpending) != NULL) {
4850Sstevel@tonic-gate tp->t_iocpending = NULL; /* not pending any more */
4860Sstevel@tonic-gate ttcompat_do_ioctl(tp, q, mp);
4870Sstevel@tonic-gate }
4880Sstevel@tonic-gate }
4890Sstevel@tonic-gate
4900Sstevel@tonic-gate /*
4910Sstevel@tonic-gate * Handle old-style "ioctl" messages; pass the rest down unmolested.
4920Sstevel@tonic-gate */
4930Sstevel@tonic-gate static void
ttcompat_do_ioctl(ttcompat_state_t * tp,queue_t * q,mblk_t * mp)4940Sstevel@tonic-gate ttcompat_do_ioctl(ttcompat_state_t *tp, queue_t *q, mblk_t *mp)
4950Sstevel@tonic-gate {
4960Sstevel@tonic-gate struct iocblk *iocp;
4970Sstevel@tonic-gate int error;
4980Sstevel@tonic-gate
4990Sstevel@tonic-gate /*
5000Sstevel@tonic-gate * Most of the miocpullup()'s below aren't needed because the
5010Sstevel@tonic-gate * ioctls in question are actually transparent M_IOCDATA messages
5020Sstevel@tonic-gate * dummied to look like M_IOCTL messages. However, for clarity and
5030Sstevel@tonic-gate * robustness against future changes, we've included them anyway.
5040Sstevel@tonic-gate */
5050Sstevel@tonic-gate
5060Sstevel@tonic-gate iocp = (struct iocblk *)mp->b_rptr;
5070Sstevel@tonic-gate switch (iocp->ioc_cmd) {
5080Sstevel@tonic-gate
5090Sstevel@tonic-gate /*
5100Sstevel@tonic-gate * "get"-style calls that get translated data from the "termios"
5110Sstevel@tonic-gate * structure. Save the existing code and pass it down as a TCGETS.
5120Sstevel@tonic-gate */
5130Sstevel@tonic-gate case TIOCGETC:
5140Sstevel@tonic-gate case TIOCLGET:
5150Sstevel@tonic-gate case TIOCGLTC:
5160Sstevel@tonic-gate if (iocp->ioc_count != TRANSPARENT) {
5170Sstevel@tonic-gate miocnak(q, mp, 0, EINVAL);
5180Sstevel@tonic-gate return;
5190Sstevel@tonic-gate }
5200Sstevel@tonic-gate
5210Sstevel@tonic-gate /*
5220Sstevel@tonic-gate * We can get here with t_arg != 0, iff the stream head
5230Sstevel@tonic-gate * has for some reason given up on the ioctl in progress.
5240Sstevel@tonic-gate * The most likely cause is an interrupted ioctl syscall.
5250Sstevel@tonic-gate * We will behave robustly because (given our perimeter)
5260Sstevel@tonic-gate * the ttcompat_state_t will get set up for the new ioctl,
5270Sstevel@tonic-gate * and when the response we were waiting for appears it
5280Sstevel@tonic-gate * will be passed on to the stream head which will discard
5290Sstevel@tonic-gate * it as non-current.
5300Sstevel@tonic-gate */
5310Sstevel@tonic-gate ASSERT(mp->b_cont != NULL);
5320Sstevel@tonic-gate tp->t_arg = *(intptr_t *)mp->b_cont->b_rptr;
5330Sstevel@tonic-gate /* free the data buffer - it might not be sufficient */
5340Sstevel@tonic-gate /* driver will allocate one for termios size */
5350Sstevel@tonic-gate freemsg(mp->b_cont);
5360Sstevel@tonic-gate mp->b_cont = NULL;
5370Sstevel@tonic-gate iocp->ioc_count = 0;
5380Sstevel@tonic-gate /* FALLTHRU */
5390Sstevel@tonic-gate case TIOCGETP:
5400Sstevel@tonic-gate goto dogets;
5410Sstevel@tonic-gate
5420Sstevel@tonic-gate /*
5430Sstevel@tonic-gate * "set"-style calls that set translated data into a "termios"
5440Sstevel@tonic-gate * structure. Set our idea of the new state from the value
5450Sstevel@tonic-gate * given to us. We then have to get the current state, so we
5460Sstevel@tonic-gate * turn this guy into a TCGETS and pass it down. When the
5470Sstevel@tonic-gate * ACK comes back, we modify the state we got back and shove it
5480Sstevel@tonic-gate * back down as the appropriate type of TCSETS.
5490Sstevel@tonic-gate */
5500Sstevel@tonic-gate case TIOCSETP:
5510Sstevel@tonic-gate case TIOCSETN:
5520Sstevel@tonic-gate error = miocpullup(mp, sizeof (struct sgttyb));
5530Sstevel@tonic-gate if (error != 0) {
5540Sstevel@tonic-gate miocnak(q, mp, 0, error);
5550Sstevel@tonic-gate return;
5560Sstevel@tonic-gate }
5570Sstevel@tonic-gate tp->t_new_sgttyb = *((struct sgttyb *)mp->b_cont->b_rptr);
5580Sstevel@tonic-gate goto dogets;
5590Sstevel@tonic-gate
5600Sstevel@tonic-gate case TIOCSETC:
5610Sstevel@tonic-gate error = miocpullup(mp, sizeof (struct tchars));
5620Sstevel@tonic-gate if (error != 0) {
5630Sstevel@tonic-gate miocnak(q, mp, 0, error);
5640Sstevel@tonic-gate return;
5650Sstevel@tonic-gate }
5660Sstevel@tonic-gate tp->t_new_tchars = *((struct tchars *)mp->b_cont->b_rptr);
5670Sstevel@tonic-gate goto dogets;
5680Sstevel@tonic-gate
5690Sstevel@tonic-gate case TIOCSLTC:
5700Sstevel@tonic-gate error = miocpullup(mp, sizeof (struct ltchars));
5710Sstevel@tonic-gate if (error != 0) {
5720Sstevel@tonic-gate miocnak(q, mp, 0, error);
5730Sstevel@tonic-gate return;
5740Sstevel@tonic-gate }
5750Sstevel@tonic-gate tp->t_new_ltchars = *((struct ltchars *)mp->b_cont->b_rptr);
5760Sstevel@tonic-gate goto dogets;
5770Sstevel@tonic-gate
5780Sstevel@tonic-gate case TIOCLBIS:
5790Sstevel@tonic-gate case TIOCLBIC:
5800Sstevel@tonic-gate case TIOCLSET:
5810Sstevel@tonic-gate error = miocpullup(mp, sizeof (int));
5820Sstevel@tonic-gate if (error != 0) {
5830Sstevel@tonic-gate miocnak(q, mp, 0, error);
5840Sstevel@tonic-gate return;
5850Sstevel@tonic-gate }
5860Sstevel@tonic-gate tp->t_new_lflags = *(int *)mp->b_cont->b_rptr;
5870Sstevel@tonic-gate goto dogets;
5880Sstevel@tonic-gate
5890Sstevel@tonic-gate /*
5900Sstevel@tonic-gate * "set"-style call that sets a particular bit in a "termios"
5910Sstevel@tonic-gate * structure. We then have to get the current state, so we
5920Sstevel@tonic-gate * turn this guy into a TCGETS and pass it down. When the
5930Sstevel@tonic-gate * ACK comes back, we modify the state we got back and shove it
5940Sstevel@tonic-gate * back down as the appropriate type of TCSETS.
5950Sstevel@tonic-gate */
5960Sstevel@tonic-gate case TIOCHPCL:
5970Sstevel@tonic-gate dogets:
5980Sstevel@tonic-gate tp->t_ioccmd = iocp->ioc_cmd;
5990Sstevel@tonic-gate tp->t_iocid = iocp->ioc_id;
6000Sstevel@tonic-gate tp->t_state |= TS_IOCWAIT;
6010Sstevel@tonic-gate iocp->ioc_cmd = TCGETS;
6020Sstevel@tonic-gate iocp->ioc_count = 0; /* no data returned unless we say so */
6030Sstevel@tonic-gate break;
6040Sstevel@tonic-gate
6050Sstevel@tonic-gate /*
6060Sstevel@tonic-gate * "set"-style call that sets DTR. Pretend that it was a TIOCMBIS
6070Sstevel@tonic-gate * with TIOCM_DTR set.
6080Sstevel@tonic-gate */
6090Sstevel@tonic-gate case TIOCSDTR: {
6100Sstevel@tonic-gate mblk_t *datap;
6110Sstevel@tonic-gate
6120Sstevel@tonic-gate if ((datap = allocb(sizeof (int), BPRI_HI)) == NULL)
6130Sstevel@tonic-gate goto allocfailure;
6140Sstevel@tonic-gate *(int *)datap->b_wptr = TIOCM_DTR;
6150Sstevel@tonic-gate datap->b_wptr += sizeof (int);
6160Sstevel@tonic-gate iocp->ioc_cmd = TIOCMBIS; /* turn it into a TIOCMBIS */
6170Sstevel@tonic-gate if (mp->b_cont != NULL)
6180Sstevel@tonic-gate freemsg(mp->b_cont);
6190Sstevel@tonic-gate mp->b_cont = datap; /* attach the data */
6200Sstevel@tonic-gate iocp->ioc_count = sizeof (int); /* in case driver checks */
6210Sstevel@tonic-gate break;
6220Sstevel@tonic-gate }
6230Sstevel@tonic-gate
6240Sstevel@tonic-gate /*
6250Sstevel@tonic-gate * "set"-style call that clears DTR. Pretend that it was a TIOCMBIC
6260Sstevel@tonic-gate * with TIOCM_DTR set.
6270Sstevel@tonic-gate */
6280Sstevel@tonic-gate case TIOCCDTR: {
6290Sstevel@tonic-gate mblk_t *datap;
6300Sstevel@tonic-gate
6310Sstevel@tonic-gate if ((datap = allocb(sizeof (int), BPRI_HI)) == NULL)
6320Sstevel@tonic-gate goto allocfailure;
6330Sstevel@tonic-gate *(int *)datap->b_wptr = TIOCM_DTR;
6340Sstevel@tonic-gate datap->b_wptr += sizeof (int);
6350Sstevel@tonic-gate iocp->ioc_cmd = TIOCMBIC; /* turn it into a TIOCMBIC */
6360Sstevel@tonic-gate if (mp->b_cont != NULL)
6370Sstevel@tonic-gate freemsg(mp->b_cont);
6380Sstevel@tonic-gate mp->b_cont = datap; /* attach the data */
6390Sstevel@tonic-gate iocp->ioc_count = sizeof (int); /* in case driver checks */
6400Sstevel@tonic-gate break;
6410Sstevel@tonic-gate }
6420Sstevel@tonic-gate
6430Sstevel@tonic-gate /*
6440Sstevel@tonic-gate * Translate into the S5 form of TCFLSH.
6450Sstevel@tonic-gate */
6460Sstevel@tonic-gate case TIOCFLUSH: {
6470Sstevel@tonic-gate int flags;
6480Sstevel@tonic-gate
6490Sstevel@tonic-gate error = miocpullup(mp, sizeof (int));
6500Sstevel@tonic-gate if (error != 0) {
6510Sstevel@tonic-gate miocnak(q, mp, 0, error);
6520Sstevel@tonic-gate return;
6530Sstevel@tonic-gate }
6540Sstevel@tonic-gate flags = *(int *)mp->b_cont->b_rptr;
6550Sstevel@tonic-gate
6560Sstevel@tonic-gate switch (flags&(FREAD|FWRITE)) {
6570Sstevel@tonic-gate
6580Sstevel@tonic-gate case 0:
6590Sstevel@tonic-gate case FREAD|FWRITE:
6600Sstevel@tonic-gate flags = 2; /* flush 'em both */
6610Sstevel@tonic-gate break;
6620Sstevel@tonic-gate
6630Sstevel@tonic-gate case FREAD:
6640Sstevel@tonic-gate flags = 0; /* flush read */
6650Sstevel@tonic-gate break;
6660Sstevel@tonic-gate
6670Sstevel@tonic-gate case FWRITE:
6680Sstevel@tonic-gate flags = 1; /* flush write */
6690Sstevel@tonic-gate break;
6700Sstevel@tonic-gate }
6710Sstevel@tonic-gate iocp->ioc_cmd = TCFLSH; /* turn it into a TCFLSH */
6720Sstevel@tonic-gate *(int *)mp->b_cont->b_rptr = flags; /* fiddle the arg */
6730Sstevel@tonic-gate break;
6740Sstevel@tonic-gate }
6750Sstevel@tonic-gate
6760Sstevel@tonic-gate /*
6770Sstevel@tonic-gate * Turn into a TCXONC.
6780Sstevel@tonic-gate */
6790Sstevel@tonic-gate case TIOCSTOP: {
6800Sstevel@tonic-gate mblk_t *datap;
6810Sstevel@tonic-gate
6820Sstevel@tonic-gate if ((datap = allocb(sizeof (int), BPRI_HI)) == NULL)
6830Sstevel@tonic-gate goto allocfailure;
6840Sstevel@tonic-gate *(int *)datap->b_wptr = 0; /* stop */
6850Sstevel@tonic-gate datap->b_wptr += sizeof (int);
6860Sstevel@tonic-gate iocp->ioc_cmd = TCXONC; /* turn it into a XONC */
6870Sstevel@tonic-gate iocp->ioc_count = sizeof (int);
6880Sstevel@tonic-gate if (mp->b_cont != NULL)
6890Sstevel@tonic-gate freemsg(mp->b_cont);
6900Sstevel@tonic-gate mp->b_cont = datap; /* attach the data */
6910Sstevel@tonic-gate break;
6920Sstevel@tonic-gate }
6930Sstevel@tonic-gate
6940Sstevel@tonic-gate case TIOCSTART: {
6950Sstevel@tonic-gate mblk_t *datap;
6960Sstevel@tonic-gate
6970Sstevel@tonic-gate if ((datap = allocb(sizeof (int), BPRI_HI)) == NULL)
6980Sstevel@tonic-gate goto allocfailure;
6990Sstevel@tonic-gate *(int *)datap->b_wptr = 1; /* start */
7000Sstevel@tonic-gate datap->b_wptr += sizeof (int);
7010Sstevel@tonic-gate iocp->ioc_cmd = TCXONC; /* turn it into a XONC */
7020Sstevel@tonic-gate iocp->ioc_count = sizeof (int);
7030Sstevel@tonic-gate if (mp->b_cont != NULL)
7040Sstevel@tonic-gate freemsg(mp->b_cont);
7050Sstevel@tonic-gate mp->b_cont = datap; /* attach the data */
7060Sstevel@tonic-gate break;
7070Sstevel@tonic-gate }
7080Sstevel@tonic-gate case TIOCSETD:
7090Sstevel@tonic-gate case TIOCGETD:
7100Sstevel@tonic-gate case DIOCSETP:
7110Sstevel@tonic-gate case DIOCGETP:
7120Sstevel@tonic-gate case LDOPEN:
7130Sstevel@tonic-gate case LDCLOSE:
7140Sstevel@tonic-gate case LDCHG:
7150Sstevel@tonic-gate case LDSETT:
7160Sstevel@tonic-gate case LDGETT:
7170Sstevel@tonic-gate /*
7180Sstevel@tonic-gate * All of these ioctls are just ACK'd, except for
7190Sstevel@tonic-gate * TIOCSETD, which must be for line discipline zero.
7200Sstevel@tonic-gate */
7210Sstevel@tonic-gate mp->b_datap->db_type = M_IOCACK;
7220Sstevel@tonic-gate if (iocp->ioc_cmd == TIOCSETD) {
7230Sstevel@tonic-gate iocp->ioc_error = miocpullup(mp, sizeof (uchar_t));
7240Sstevel@tonic-gate if (iocp->ioc_error == 0 && (*mp->b_cont->b_rptr != 0))
7250Sstevel@tonic-gate mp->b_datap->db_type = M_IOCNAK;
7260Sstevel@tonic-gate }
7270Sstevel@tonic-gate
7280Sstevel@tonic-gate iocp->ioc_error = 0;
7290Sstevel@tonic-gate iocp->ioc_count = 0;
7300Sstevel@tonic-gate iocp->ioc_rval = 0;
7310Sstevel@tonic-gate qreply(q, mp);
7320Sstevel@tonic-gate return;
7330Sstevel@tonic-gate case IOCTYPE:
7340Sstevel@tonic-gate mp->b_datap->db_type = M_IOCACK;
7350Sstevel@tonic-gate iocp->ioc_error = 0;
7360Sstevel@tonic-gate iocp->ioc_count = 0;
7370Sstevel@tonic-gate iocp->ioc_rval = TIOC;
7380Sstevel@tonic-gate qreply(q, mp);
7390Sstevel@tonic-gate return;
7400Sstevel@tonic-gate case TIOCEXCL:
7410Sstevel@tonic-gate /* check for binary value of XCLUDE flag ???? */
7420Sstevel@tonic-gate tp->t_new_lflags |= XCLUDE;
7430Sstevel@tonic-gate mp->b_datap->db_type = M_IOCACK;
7440Sstevel@tonic-gate iocp->ioc_error = 0;
7450Sstevel@tonic-gate iocp->ioc_count = 0;
7460Sstevel@tonic-gate iocp->ioc_rval = 0;
7470Sstevel@tonic-gate qreply(q, mp);
7480Sstevel@tonic-gate return;
7490Sstevel@tonic-gate case TIOCNXCL:
7500Sstevel@tonic-gate tp->t_new_lflags &= ~XCLUDE;
7510Sstevel@tonic-gate mp->b_datap->db_type = M_IOCACK;
7520Sstevel@tonic-gate iocp->ioc_error = 0;
7530Sstevel@tonic-gate iocp->ioc_count = 0;
7540Sstevel@tonic-gate iocp->ioc_rval = 0;
7550Sstevel@tonic-gate qreply(q, mp);
7560Sstevel@tonic-gate return;
7570Sstevel@tonic-gate }
7580Sstevel@tonic-gate
7590Sstevel@tonic-gate /*
7600Sstevel@tonic-gate * We don't reply to most calls, we just pass them down,
7610Sstevel@tonic-gate * possibly after modifying the arguments.
7620Sstevel@tonic-gate */
7630Sstevel@tonic-gate putnext(q, mp);
7640Sstevel@tonic-gate return;
7650Sstevel@tonic-gate
7660Sstevel@tonic-gate allocfailure:
7670Sstevel@tonic-gate /*
7680Sstevel@tonic-gate * We needed to allocate something to handle this "ioctl", but
7690Sstevel@tonic-gate * couldn't; save this "ioctl" and arrange to get called back when
7700Sstevel@tonic-gate * it's more likely that we can get what we need.
7710Sstevel@tonic-gate * If there's already one being saved, throw it out, since it
7720Sstevel@tonic-gate * must have timed out.
7730Sstevel@tonic-gate */
7740Sstevel@tonic-gate if (tp->t_iocpending != NULL)
7750Sstevel@tonic-gate freemsg(tp->t_iocpending);
7760Sstevel@tonic-gate tp->t_iocpending = mp; /* hold this ioctl */
7770Sstevel@tonic-gate if (tp->t_bufcallid != 0)
7780Sstevel@tonic-gate qunbufcall(q, tp->t_bufcallid);
7790Sstevel@tonic-gate
7800Sstevel@tonic-gate tp->t_bufcallid = qbufcall(q, sizeof (struct iocblk), BPRI_HI,
7810Sstevel@tonic-gate ttcompat_reioctl, q);
7820Sstevel@tonic-gate }
7830Sstevel@tonic-gate
7840Sstevel@tonic-gate /*
7850Sstevel@tonic-gate * Called when an M_IOCACK message is seen on the read queue; if this
7860Sstevel@tonic-gate * is the response we were waiting for, we either:
7870Sstevel@tonic-gate * modify the data going up (if the "ioctl" read data); since in all
7880Sstevel@tonic-gate * cases, the old-style returned information is smaller than or the same
7890Sstevel@tonic-gate * size as the new-style returned information, we just overwrite the old
7900Sstevel@tonic-gate * stuff with the new stuff (beware of changing structure sizes, in case
7910Sstevel@tonic-gate * you invalidate this)
7920Sstevel@tonic-gate * or
7930Sstevel@tonic-gate * take this data, modify it appropriately, and send it back down (if
7940Sstevel@tonic-gate * the "ioctl" wrote data).
7950Sstevel@tonic-gate * In either case, we cancel the "wait"; the final response to a "write"
7960Sstevel@tonic-gate * ioctl goes back up to the user.
7970Sstevel@tonic-gate * If this wasn't the response we were waiting for, just pass it up.
7980Sstevel@tonic-gate */
7990Sstevel@tonic-gate static void
ttcompat_ioctl_ack(queue_t * q,mblk_t * mp)8000Sstevel@tonic-gate ttcompat_ioctl_ack(queue_t *q, mblk_t *mp)
8010Sstevel@tonic-gate {
8020Sstevel@tonic-gate ttcompat_state_t *tp;
8030Sstevel@tonic-gate struct iocblk *iocp;
8040Sstevel@tonic-gate mblk_t *datap;
8050Sstevel@tonic-gate
8060Sstevel@tonic-gate tp = (ttcompat_state_t *)q->q_ptr;
8070Sstevel@tonic-gate iocp = (struct iocblk *)mp->b_rptr;
8080Sstevel@tonic-gate
8090Sstevel@tonic-gate if (!(tp->t_state&TS_IOCWAIT) || iocp->ioc_id != tp->t_iocid) {
8100Sstevel@tonic-gate /*
8110Sstevel@tonic-gate * This isn't the reply we're looking for. Move along.
8120Sstevel@tonic-gate */
8130Sstevel@tonic-gate putnext(q, mp);
8140Sstevel@tonic-gate return;
8150Sstevel@tonic-gate }
8160Sstevel@tonic-gate
8170Sstevel@tonic-gate datap = mp->b_cont; /* mblk containing data going up */
8180Sstevel@tonic-gate
8190Sstevel@tonic-gate switch (tp->t_ioccmd) {
8200Sstevel@tonic-gate
8210Sstevel@tonic-gate case TIOCGETP: {
8220Sstevel@tonic-gate struct sgttyb *cb;
8230Sstevel@tonic-gate
8240Sstevel@tonic-gate to_compat((struct termios *)datap->b_rptr, &tp->t_curstate);
8250Sstevel@tonic-gate datap->b_rptr = datap->b_wptr = datap->b_datap->db_base;
8260Sstevel@tonic-gate /* recycle the reply's buffer */
8270Sstevel@tonic-gate cb = (struct sgttyb *)datap->b_wptr;
8280Sstevel@tonic-gate /*
8290Sstevel@tonic-gate * This is used for TIOCGETP handling of sg_ispeed and
8300Sstevel@tonic-gate * sg_ospeed. If the current speed is over 38400 (the
8310Sstevel@tonic-gate * sgttyb limit), then we report 38400. Note that
8320Sstevel@tonic-gate * when "compatibility with old releases" is enabled
8330Sstevel@tonic-gate * (sgttyb_handling == 0), then t_[io]speed will have
8340Sstevel@tonic-gate * garbled nonsense, as in prior releases. (See
8350Sstevel@tonic-gate * to_compat() below).
8360Sstevel@tonic-gate */
8370Sstevel@tonic-gate cb->sg_ispeed = tp->t_curstate.t_ispeed > B38400 ? B38400 :
8380Sstevel@tonic-gate tp->t_curstate.t_ispeed;
8390Sstevel@tonic-gate cb->sg_ospeed = tp->t_curstate.t_ospeed > B38400 ? B38400 :
8400Sstevel@tonic-gate tp->t_curstate.t_ospeed;
8410Sstevel@tonic-gate cb->sg_erase = tp->t_curstate.t_erase;
8420Sstevel@tonic-gate cb->sg_kill = tp->t_curstate.t_kill;
8430Sstevel@tonic-gate cb->sg_flags = tp->t_curstate.t_flags;
8440Sstevel@tonic-gate datap->b_wptr += sizeof (struct sgttyb);
8450Sstevel@tonic-gate iocp->ioc_count = sizeof (struct sgttyb);
8460Sstevel@tonic-gate
8470Sstevel@tonic-gate /* you are lucky - stream head knows how to copy you out */
8480Sstevel@tonic-gate
8490Sstevel@tonic-gate tp->t_state &= ~TS_IOCWAIT; /* we got what we wanted */
8500Sstevel@tonic-gate iocp->ioc_rval = 0;
8510Sstevel@tonic-gate iocp->ioc_cmd = tp->t_ioccmd;
8520Sstevel@tonic-gate putnext(q, mp);
8530Sstevel@tonic-gate return;
8540Sstevel@tonic-gate }
8550Sstevel@tonic-gate
8560Sstevel@tonic-gate case TIOCGETC:
8570Sstevel@tonic-gate to_compat((struct termios *)datap->b_rptr, &tp->t_curstate);
8580Sstevel@tonic-gate datap->b_rptr = datap->b_wptr = datap->b_datap->db_base;
8590Sstevel@tonic-gate /* recycle the reply's buffer */
8600Sstevel@tonic-gate bcopy(&tp->t_curstate.t_intrc, datap->b_wptr,
8610Sstevel@tonic-gate sizeof (struct tchars));
8620Sstevel@tonic-gate datap->b_wptr += sizeof (struct tchars);
8630Sstevel@tonic-gate break;
8640Sstevel@tonic-gate
8650Sstevel@tonic-gate case TIOCGLTC:
8660Sstevel@tonic-gate to_compat((struct termios *)datap->b_rptr, &tp->t_curstate);
8670Sstevel@tonic-gate datap->b_rptr = datap->b_wptr = datap->b_datap->db_base;
8680Sstevel@tonic-gate /* recycle the reply's buffer */
8690Sstevel@tonic-gate bcopy(&tp->t_curstate.t_suspc, datap->b_wptr,
8700Sstevel@tonic-gate sizeof (struct ltchars));
8710Sstevel@tonic-gate datap->b_wptr += sizeof (struct ltchars);
8720Sstevel@tonic-gate break;
8730Sstevel@tonic-gate
8740Sstevel@tonic-gate case TIOCLGET:
8750Sstevel@tonic-gate to_compat((struct termios *)datap->b_rptr, &tp->t_curstate);
8760Sstevel@tonic-gate datap->b_rptr = datap->b_wptr = datap->b_datap->db_base;
8770Sstevel@tonic-gate /* recycle the reply's buffer */
8780Sstevel@tonic-gate *(int *)datap->b_wptr =
8790Sstevel@tonic-gate ((unsigned)tp->t_curstate.t_flags) >> 16;
8800Sstevel@tonic-gate datap->b_wptr += sizeof (int);
8810Sstevel@tonic-gate break;
8820Sstevel@tonic-gate
8830Sstevel@tonic-gate case TIOCSETP:
8840Sstevel@tonic-gate case TIOCSETN:
8850Sstevel@tonic-gate /*
8860Sstevel@tonic-gate * Get the current state from the GETS data, and
8870Sstevel@tonic-gate * update it.
8880Sstevel@tonic-gate */
8890Sstevel@tonic-gate to_compat((struct termios *)datap->b_rptr, &tp->t_curstate);
8900Sstevel@tonic-gate tp->t_curstate.t_erase = tp->t_new_sgttyb.sg_erase;
8910Sstevel@tonic-gate tp->t_curstate.t_kill = tp->t_new_sgttyb.sg_kill;
8920Sstevel@tonic-gate /*
8930Sstevel@tonic-gate * For new-style handling, we ignore requests to set
8940Sstevel@tonic-gate * B38400 when the current speed is over B38400. This
8950Sstevel@tonic-gate * means that we change the speed as requested if:
8960Sstevel@tonic-gate * old style (sgttyb_handling == 0) is requested
8970Sstevel@tonic-gate * the requested new speed isn't B38400
8980Sstevel@tonic-gate * the current speed is at or below B38400
8990Sstevel@tonic-gate * Note that when old style is requested, both speeds
9000Sstevel@tonic-gate * in t_curstate are set to <= B38400 by to_compat, so
9010Sstevel@tonic-gate * the first test isn't needed here.
9020Sstevel@tonic-gate * Also note that we silently allow the user to set
9030Sstevel@tonic-gate * speeds above B38400 through this interface,
9040Sstevel@tonic-gate * regardless of the style setting. This allows
9050Sstevel@tonic-gate * greater compatibility with current BSD releases.
9060Sstevel@tonic-gate */
9070Sstevel@tonic-gate if (tp->t_new_sgttyb.sg_ispeed != B38400 ||
9080Sstevel@tonic-gate tp->t_curstate.t_ispeed <= B38400)
9090Sstevel@tonic-gate tp->t_curstate.t_ispeed = tp->t_new_sgttyb.sg_ispeed;
9100Sstevel@tonic-gate if (tp->t_new_sgttyb.sg_ospeed != B38400 ||
9110Sstevel@tonic-gate tp->t_curstate.t_ospeed <= B38400)
9120Sstevel@tonic-gate tp->t_curstate.t_ospeed = tp->t_new_sgttyb.sg_ospeed;
9130Sstevel@tonic-gate tp->t_curstate.t_flags =
9140Sstevel@tonic-gate (tp->t_curstate.t_flags & 0xffff0000) |
9150Sstevel@tonic-gate (tp->t_new_sgttyb.sg_flags & 0xffff);
9160Sstevel@tonic-gate
9170Sstevel@tonic-gate /*
9180Sstevel@tonic-gate * Replace the data that came up with the updated data.
9190Sstevel@tonic-gate */
9200Sstevel@tonic-gate from_compat(&tp->t_curstate, (struct termios *)datap->b_rptr);
9210Sstevel@tonic-gate
9220Sstevel@tonic-gate /*
9230Sstevel@tonic-gate * Send it back down as a TCSETS or TCSETSF.
9240Sstevel@tonic-gate */
9250Sstevel@tonic-gate iocp->ioc_cmd = (tp->t_ioccmd == TIOCSETP) ? TCSETSF : TCSETS;
9260Sstevel@tonic-gate goto senddown;
9270Sstevel@tonic-gate
9280Sstevel@tonic-gate case TIOCSETC:
9290Sstevel@tonic-gate /*
9300Sstevel@tonic-gate * Get the current state from the GETS data, and
9310Sstevel@tonic-gate * update it.
9320Sstevel@tonic-gate */
9330Sstevel@tonic-gate to_compat((struct termios *)datap->b_rptr, &tp->t_curstate);
9340Sstevel@tonic-gate bcopy(&tp->t_new_tchars,
9350Sstevel@tonic-gate &tp->t_curstate.t_intrc, sizeof (struct tchars));
9360Sstevel@tonic-gate
9370Sstevel@tonic-gate /*
9380Sstevel@tonic-gate * Replace the data that came up with the updated data.
9390Sstevel@tonic-gate */
9400Sstevel@tonic-gate from_compat(&tp->t_curstate, (struct termios *)datap->b_rptr);
9410Sstevel@tonic-gate
9420Sstevel@tonic-gate /*
9430Sstevel@tonic-gate * Send it back down as a TCSETS.
9440Sstevel@tonic-gate */
9450Sstevel@tonic-gate iocp->ioc_cmd = TCSETS;
9460Sstevel@tonic-gate goto senddown;
9470Sstevel@tonic-gate
9480Sstevel@tonic-gate case TIOCSLTC:
9490Sstevel@tonic-gate /*
9500Sstevel@tonic-gate * Get the current state from the GETS data, and
9510Sstevel@tonic-gate * update it.
9520Sstevel@tonic-gate */
9530Sstevel@tonic-gate to_compat((struct termios *)datap->b_rptr, &tp->t_curstate);
9540Sstevel@tonic-gate bcopy(&tp->t_new_ltchars,
9550Sstevel@tonic-gate &tp->t_curstate.t_suspc, sizeof (struct ltchars));
9560Sstevel@tonic-gate
9570Sstevel@tonic-gate /*
9580Sstevel@tonic-gate * Replace the data that came up with the updated data.
9590Sstevel@tonic-gate */
9600Sstevel@tonic-gate from_compat(&tp->t_curstate, (struct termios *)datap->b_rptr);
9610Sstevel@tonic-gate
9620Sstevel@tonic-gate /*
9630Sstevel@tonic-gate * Send it back down as a TCSETS.
9640Sstevel@tonic-gate */
9650Sstevel@tonic-gate iocp->ioc_cmd = TCSETS;
9660Sstevel@tonic-gate goto senddown;
9670Sstevel@tonic-gate
9680Sstevel@tonic-gate case TIOCLBIS:
9690Sstevel@tonic-gate /*
9700Sstevel@tonic-gate * Get the current state from the GETS data, and
9710Sstevel@tonic-gate * update it.
9720Sstevel@tonic-gate */
9730Sstevel@tonic-gate to_compat((struct termios *)datap->b_rptr, &tp->t_curstate);
9740Sstevel@tonic-gate tp->t_curstate.t_flags |= (tp->t_new_lflags << 16);
9750Sstevel@tonic-gate
9760Sstevel@tonic-gate /*
9770Sstevel@tonic-gate * Replace the data that came up with the updated data.
9780Sstevel@tonic-gate */
9790Sstevel@tonic-gate from_compat(&tp->t_curstate, (struct termios *)datap->b_rptr);
9800Sstevel@tonic-gate
9810Sstevel@tonic-gate /*
9820Sstevel@tonic-gate * Send it back down as a TCSETS.
9830Sstevel@tonic-gate */
9840Sstevel@tonic-gate iocp->ioc_cmd = TCSETS;
9850Sstevel@tonic-gate goto senddown;
9860Sstevel@tonic-gate
9870Sstevel@tonic-gate case TIOCLBIC:
9880Sstevel@tonic-gate /*
9890Sstevel@tonic-gate * Get the current state from the GETS data, and
9900Sstevel@tonic-gate * update it.
9910Sstevel@tonic-gate */
9920Sstevel@tonic-gate to_compat((struct termios *)datap->b_rptr, &tp->t_curstate);
9930Sstevel@tonic-gate tp->t_curstate.t_flags &= ~(tp->t_new_lflags << 16);
9940Sstevel@tonic-gate
9950Sstevel@tonic-gate /*
9960Sstevel@tonic-gate * Replace the data that came up with the updated data.
9970Sstevel@tonic-gate */
9980Sstevel@tonic-gate from_compat(&tp->t_curstate, (struct termios *)datap->b_rptr);
9990Sstevel@tonic-gate
10000Sstevel@tonic-gate /*
10010Sstevel@tonic-gate * Send it back down as a TCSETS.
10020Sstevel@tonic-gate */
10030Sstevel@tonic-gate iocp->ioc_cmd = TCSETS;
10040Sstevel@tonic-gate goto senddown;
10050Sstevel@tonic-gate
10060Sstevel@tonic-gate case TIOCLSET:
10070Sstevel@tonic-gate /*
10080Sstevel@tonic-gate * Get the current state from the GETS data, and
10090Sstevel@tonic-gate * update it.
10100Sstevel@tonic-gate */
10110Sstevel@tonic-gate to_compat((struct termios *)datap->b_rptr, &tp->t_curstate);
10120Sstevel@tonic-gate tp->t_curstate.t_flags &= 0xffff;
10130Sstevel@tonic-gate tp->t_curstate.t_flags |= (tp->t_new_lflags << 16);
10140Sstevel@tonic-gate
10150Sstevel@tonic-gate /*
10160Sstevel@tonic-gate * Replace the data that came up with the updated data.
10170Sstevel@tonic-gate */
10180Sstevel@tonic-gate from_compat(&tp->t_curstate, (struct termios *)datap->b_rptr);
10190Sstevel@tonic-gate
10200Sstevel@tonic-gate /*
10210Sstevel@tonic-gate * Send it back down as a TCSETS.
10220Sstevel@tonic-gate */
10230Sstevel@tonic-gate iocp->ioc_cmd = TCSETS;
10240Sstevel@tonic-gate goto senddown;
10250Sstevel@tonic-gate
10260Sstevel@tonic-gate case TIOCHPCL:
10270Sstevel@tonic-gate /*
10280Sstevel@tonic-gate * Replace the data that came up with the updated data.
10290Sstevel@tonic-gate */
10300Sstevel@tonic-gate ((struct termios *)datap->b_rptr)->c_cflag |= HUPCL;
10310Sstevel@tonic-gate
10320Sstevel@tonic-gate /*
10330Sstevel@tonic-gate * Send it back down as a TCSETS.
10340Sstevel@tonic-gate */
10350Sstevel@tonic-gate iocp->ioc_cmd = TCSETS;
10360Sstevel@tonic-gate goto senddown;
10370Sstevel@tonic-gate
1038*8770SJordan.Vaughan@Sun.com case TCSETSF:
1039*8770SJordan.Vaughan@Sun.com /*
1040*8770SJordan.Vaughan@Sun.com * We're acknowledging the terminal reset ioctl that we sent
1041*8770SJordan.Vaughan@Sun.com * when the module was opened.
1042*8770SJordan.Vaughan@Sun.com */
1043*8770SJordan.Vaughan@Sun.com tp->t_state &= ~(TS_IOCWAIT | TS_TIOCNAK);
1044*8770SJordan.Vaughan@Sun.com freemsg(mp);
1045*8770SJordan.Vaughan@Sun.com return;
1046*8770SJordan.Vaughan@Sun.com
10470Sstevel@tonic-gate default:
10480Sstevel@tonic-gate cmn_err(CE_WARN, "ttcompat: Unexpected ioctl acknowledgment\n");
10490Sstevel@tonic-gate }
10500Sstevel@tonic-gate
10510Sstevel@tonic-gate /*
10520Sstevel@tonic-gate * All the calls that return something return 0.
10530Sstevel@tonic-gate */
10540Sstevel@tonic-gate tp->t_state &= ~TS_IOCWAIT; /* we got what we wanted */
10550Sstevel@tonic-gate iocp->ioc_rval = 0;
10560Sstevel@tonic-gate
10570Sstevel@tonic-gate /* copy out the data - ioctl transparency */
10580Sstevel@tonic-gate iocp->ioc_cmd = tp->t_ioccmd;
10590Sstevel@tonic-gate ttcopyout(q, mp);
10600Sstevel@tonic-gate return;
10610Sstevel@tonic-gate
10620Sstevel@tonic-gate senddown:
10630Sstevel@tonic-gate /*
10640Sstevel@tonic-gate * Send a "get state" reply back down, with suitably-modified
10650Sstevel@tonic-gate * state, as a "set state" "ioctl".
10660Sstevel@tonic-gate */
10670Sstevel@tonic-gate tp->t_state &= ~TS_IOCWAIT;
10680Sstevel@tonic-gate mp->b_datap->db_type = M_IOCTL;
10690Sstevel@tonic-gate mp->b_wptr = mp->b_rptr + sizeof (struct iocblk);
10700Sstevel@tonic-gate putnext(WR(q), mp);
10710Sstevel@tonic-gate }
10720Sstevel@tonic-gate /* Called from ttcompatrput M_IOCACK processing. */
10730Sstevel@tonic-gate /* Copies out the data using M_COPYOUT messages */
10740Sstevel@tonic-gate
10750Sstevel@tonic-gate static void
ttcopyout(queue_t * q,mblk_t * mp)10760Sstevel@tonic-gate ttcopyout(queue_t *q, mblk_t *mp)
10770Sstevel@tonic-gate {
10780Sstevel@tonic-gate struct copyreq *cqp;
10790Sstevel@tonic-gate ttcompat_state_t *tp;
10800Sstevel@tonic-gate
10810Sstevel@tonic-gate tp = (ttcompat_state_t *)q->q_ptr;
10820Sstevel@tonic-gate
10830Sstevel@tonic-gate mp->b_datap->db_type = M_COPYOUT;
10840Sstevel@tonic-gate cqp = (struct copyreq *)mp->b_rptr;
10850Sstevel@tonic-gate cqp->cq_addr = (caddr_t)tp->t_arg; /* retrieve the 3rd argument */
10860Sstevel@tonic-gate tp->t_arg = 0; /* clear it since we don't need it anymore */
10870Sstevel@tonic-gate switch (tp->t_ioccmd) {
10880Sstevel@tonic-gate case TIOCGLTC:
10890Sstevel@tonic-gate cqp->cq_size = sizeof (struct ltchars);
10900Sstevel@tonic-gate break;
10910Sstevel@tonic-gate case TIOCGETC:
10920Sstevel@tonic-gate cqp->cq_size = sizeof (struct tchars);
10930Sstevel@tonic-gate break;
10940Sstevel@tonic-gate case TIOCLGET:
10950Sstevel@tonic-gate cqp->cq_size = sizeof (int);
10960Sstevel@tonic-gate break;
10970Sstevel@tonic-gate default:
10980Sstevel@tonic-gate cmn_err(CE_WARN,
10990Sstevel@tonic-gate "ttcompat: Unknown ioctl to copyout\n");
11000Sstevel@tonic-gate break;
11010Sstevel@tonic-gate }
11020Sstevel@tonic-gate cqp->cq_flag = 0;
11030Sstevel@tonic-gate cqp->cq_private = NULL;
11040Sstevel@tonic-gate tp->t_state |= TS_W_OUT;
11050Sstevel@tonic-gate putnext(q, mp);
11060Sstevel@tonic-gate }
11070Sstevel@tonic-gate
11080Sstevel@tonic-gate
11090Sstevel@tonic-gate /*
11100Sstevel@tonic-gate * Called when an M_IOCNAK message is seen on the read queue; if this is
11110Sstevel@tonic-gate * the response we were waiting for, cancel the wait. Pass the reply up;
11120Sstevel@tonic-gate * if we were waiting for this response, we can't complete the "ioctl" and
11130Sstevel@tonic-gate * the NAK will tell that to the guy above us.
11140Sstevel@tonic-gate * If this wasn't the response we were waiting for, just pass it up.
11150Sstevel@tonic-gate */
11160Sstevel@tonic-gate static void
ttcompat_ioctl_nak(queue_t * q,mblk_t * mp)11170Sstevel@tonic-gate ttcompat_ioctl_nak(queue_t *q, mblk_t *mp)
11180Sstevel@tonic-gate {
11190Sstevel@tonic-gate ttcompat_state_t *tp;
11200Sstevel@tonic-gate struct iocblk *iocp;
11210Sstevel@tonic-gate
11220Sstevel@tonic-gate iocp = (struct iocblk *)mp->b_rptr;
11230Sstevel@tonic-gate tp = (ttcompat_state_t *)q->q_ptr;
11240Sstevel@tonic-gate
11250Sstevel@tonic-gate if (tp->t_state&TS_IOCWAIT && iocp->ioc_id == tp->t_iocid) {
11260Sstevel@tonic-gate tp->t_state &= ~TS_IOCWAIT; /* this call isn't going through */
11270Sstevel@tonic-gate tp->t_arg = 0; /* we may have stashed the 3rd argument */
11280Sstevel@tonic-gate }
11290Sstevel@tonic-gate putnext(q, mp);
11300Sstevel@tonic-gate }
11310Sstevel@tonic-gate
11320Sstevel@tonic-gate #define FROM_COMPAT_CHAR(to, from) { if ((to = from) == 0377) to = 0; }
11330Sstevel@tonic-gate
11340Sstevel@tonic-gate static void
from_compat(compat_state_t * csp,struct termios * termiosp)11350Sstevel@tonic-gate from_compat(compat_state_t *csp, struct termios *termiosp)
11360Sstevel@tonic-gate {
11370Sstevel@tonic-gate termiosp->c_iflag = 0;
11380Sstevel@tonic-gate termiosp->c_oflag &= (ONLRET|ONOCR);
11390Sstevel@tonic-gate
11400Sstevel@tonic-gate termiosp->c_cflag = (termiosp->c_cflag &
11410Sstevel@tonic-gate (CRTSCTS|CRTSXOFF|PAREXT|LOBLK|HUPCL)) | CREAD;
11420Sstevel@tonic-gate
11430Sstevel@tonic-gate if (csp->t_ospeed > CBAUD) {
11440Sstevel@tonic-gate termiosp->c_cflag |= ((csp->t_ospeed - CBAUD - 1) & CBAUD) |
11450Sstevel@tonic-gate CBAUDEXT;
11460Sstevel@tonic-gate } else {
11470Sstevel@tonic-gate termiosp->c_cflag |= csp->t_ospeed & CBAUD;
11480Sstevel@tonic-gate }
11490Sstevel@tonic-gate
11500Sstevel@tonic-gate if (csp->t_ospeed != csp->t_ispeed) {
11510Sstevel@tonic-gate if (csp->t_ispeed > (CIBAUD >> IBSHIFT)) {
11520Sstevel@tonic-gate termiosp->c_cflag |= CIBAUDEXT |
11530Sstevel@tonic-gate (((csp->t_ispeed - (CIBAUD >> IBSHIFT) - 1) <<
1154*8770SJordan.Vaughan@Sun.com IBSHIFT) & CIBAUD);
11550Sstevel@tonic-gate } else {
11560Sstevel@tonic-gate termiosp->c_cflag |= (csp->t_ispeed << IBSHIFT) &
11570Sstevel@tonic-gate CIBAUD;
11580Sstevel@tonic-gate }
11590Sstevel@tonic-gate /* hang up if ispeed=0 */
11600Sstevel@tonic-gate if (csp->t_ispeed == 0)
11610Sstevel@tonic-gate termiosp->c_cflag &= ~CBAUD & ~CBAUDEXT;
11620Sstevel@tonic-gate }
11630Sstevel@tonic-gate if (csp->t_ispeed == B110 || csp->t_xflags & STOPB)
11640Sstevel@tonic-gate termiosp->c_cflag |= CSTOPB;
11650Sstevel@tonic-gate termiosp->c_lflag = ECHOK;
11660Sstevel@tonic-gate FROM_COMPAT_CHAR(termiosp->c_cc[VERASE], csp->t_erase);
11670Sstevel@tonic-gate FROM_COMPAT_CHAR(termiosp->c_cc[VKILL], csp->t_kill);
11680Sstevel@tonic-gate FROM_COMPAT_CHAR(termiosp->c_cc[VINTR], csp->t_intrc);
11690Sstevel@tonic-gate FROM_COMPAT_CHAR(termiosp->c_cc[VQUIT], csp->t_quitc);
11700Sstevel@tonic-gate FROM_COMPAT_CHAR(termiosp->c_cc[VSTART], csp->t_startc);
11710Sstevel@tonic-gate FROM_COMPAT_CHAR(termiosp->c_cc[VSTOP], csp->t_stopc);
11720Sstevel@tonic-gate termiosp->c_cc[VEOL2] = 0;
11730Sstevel@tonic-gate FROM_COMPAT_CHAR(termiosp->c_cc[VSUSP], csp->t_suspc);
11740Sstevel@tonic-gate /* is this useful? */
11750Sstevel@tonic-gate FROM_COMPAT_CHAR(termiosp->c_cc[VDSUSP], csp->t_dsuspc);
11760Sstevel@tonic-gate FROM_COMPAT_CHAR(termiosp->c_cc[VREPRINT], csp->t_rprntc);
11770Sstevel@tonic-gate FROM_COMPAT_CHAR(termiosp->c_cc[VDISCARD], csp->t_flushc);
11780Sstevel@tonic-gate FROM_COMPAT_CHAR(termiosp->c_cc[VWERASE], csp->t_werasc);
11790Sstevel@tonic-gate FROM_COMPAT_CHAR(termiosp->c_cc[VLNEXT], csp->t_lnextc);
11800Sstevel@tonic-gate if (csp->t_flags & O_TANDEM)
11810Sstevel@tonic-gate termiosp->c_iflag |= IXOFF;
11820Sstevel@tonic-gate if (csp->t_flags & O_LCASE) {
11830Sstevel@tonic-gate termiosp->c_iflag |= IUCLC;
11840Sstevel@tonic-gate termiosp->c_oflag |= OLCUC;
11850Sstevel@tonic-gate termiosp->c_lflag |= XCASE;
11860Sstevel@tonic-gate }
11870Sstevel@tonic-gate if (csp->t_flags & O_ECHO)
11880Sstevel@tonic-gate termiosp->c_lflag |= ECHO;
11890Sstevel@tonic-gate if (csp->t_flags & O_CRMOD) {
11900Sstevel@tonic-gate termiosp->c_iflag |= ICRNL;
11910Sstevel@tonic-gate termiosp->c_oflag |= ONLCR;
11920Sstevel@tonic-gate switch (csp->t_flags & O_CRDELAY) {
11930Sstevel@tonic-gate
11940Sstevel@tonic-gate case O_CR1:
11950Sstevel@tonic-gate termiosp->c_oflag |= CR2;
11960Sstevel@tonic-gate break;
11970Sstevel@tonic-gate
11980Sstevel@tonic-gate case O_CR2:
11990Sstevel@tonic-gate termiosp->c_oflag |= CR3;
12000Sstevel@tonic-gate break;
12010Sstevel@tonic-gate }
12020Sstevel@tonic-gate } else {
12030Sstevel@tonic-gate if ((csp->t_flags & O_NLDELAY) == O_NL1)
12040Sstevel@tonic-gate termiosp->c_oflag |= ONLRET|CR1; /* tty37 */
12050Sstevel@tonic-gate }
12060Sstevel@tonic-gate if ((csp->t_flags & O_NLDELAY) == O_NL2)
12070Sstevel@tonic-gate termiosp->c_oflag |= NL1;
12080Sstevel@tonic-gate /*
12090Sstevel@tonic-gate * When going into RAW mode, the special characters controlled by the
12100Sstevel@tonic-gate * POSIX IEXTEN bit no longer apply; when leaving, they do.
12110Sstevel@tonic-gate */
12120Sstevel@tonic-gate if (csp->t_flags & O_RAW) {
12130Sstevel@tonic-gate termiosp->c_cflag |= CS8;
12140Sstevel@tonic-gate termiosp->c_iflag &= ~(ICRNL|IUCLC);
12150Sstevel@tonic-gate termiosp->c_lflag &= ~(XCASE|IEXTEN);
12160Sstevel@tonic-gate } else {
12170Sstevel@tonic-gate termiosp->c_iflag |= IMAXBEL|BRKINT|IGNPAR;
12180Sstevel@tonic-gate if (termiosp->c_cc[VSTOP] != 0 && termiosp->c_cc[VSTART] != 0)
12190Sstevel@tonic-gate termiosp->c_iflag |= IXON;
12200Sstevel@tonic-gate if (csp->t_flags & O_LITOUT)
12210Sstevel@tonic-gate termiosp->c_cflag |= CS8;
12220Sstevel@tonic-gate else {
12230Sstevel@tonic-gate if (csp->t_flags & O_PASS8)
12240Sstevel@tonic-gate termiosp->c_cflag |= CS8;
12250Sstevel@tonic-gate /* XXX - what about 8 bits plus parity? */
12260Sstevel@tonic-gate else {
12270Sstevel@tonic-gate switch (csp->t_flags & (O_EVENP|O_ODDP)) {
12280Sstevel@tonic-gate
12290Sstevel@tonic-gate case 0:
12300Sstevel@tonic-gate termiosp->c_iflag |= ISTRIP;
12310Sstevel@tonic-gate termiosp->c_cflag |= CS8;
12320Sstevel@tonic-gate break;
12330Sstevel@tonic-gate
12340Sstevel@tonic-gate case O_EVENP:
12350Sstevel@tonic-gate termiosp->c_iflag |= INPCK|ISTRIP;
12360Sstevel@tonic-gate termiosp->c_cflag |= CS7|PARENB;
12370Sstevel@tonic-gate break;
12380Sstevel@tonic-gate
12390Sstevel@tonic-gate case O_ODDP:
12400Sstevel@tonic-gate termiosp->c_iflag |= INPCK|ISTRIP;
12410Sstevel@tonic-gate termiosp->c_cflag |= CS7|PARENB|PARODD;
12420Sstevel@tonic-gate break;
12430Sstevel@tonic-gate
12440Sstevel@tonic-gate case O_EVENP|O_ODDP:
12450Sstevel@tonic-gate termiosp->c_iflag |= ISTRIP;
12460Sstevel@tonic-gate termiosp->c_cflag |= CS7|PARENB;
12470Sstevel@tonic-gate break;
12480Sstevel@tonic-gate }
12490Sstevel@tonic-gate }
12500Sstevel@tonic-gate if (!(csp->t_xflags & NOPOST))
12510Sstevel@tonic-gate termiosp->c_oflag |= OPOST;
12520Sstevel@tonic-gate }
12530Sstevel@tonic-gate termiosp->c_lflag |= IEXTEN;
12540Sstevel@tonic-gate if (!(csp->t_xflags & NOISIG))
12550Sstevel@tonic-gate termiosp->c_lflag |= ISIG;
12560Sstevel@tonic-gate if (!(csp->t_flags & O_CBREAK))
12570Sstevel@tonic-gate termiosp->c_lflag |= ICANON;
12580Sstevel@tonic-gate if (csp->t_flags & O_CTLECH)
12590Sstevel@tonic-gate termiosp->c_lflag |= ECHOCTL;
12600Sstevel@tonic-gate }
12610Sstevel@tonic-gate switch (csp->t_flags & O_TBDELAY) {
12620Sstevel@tonic-gate
12630Sstevel@tonic-gate case O_TAB1:
12640Sstevel@tonic-gate termiosp->c_oflag |= TAB1;
12650Sstevel@tonic-gate break;
12660Sstevel@tonic-gate
12670Sstevel@tonic-gate case O_TAB2:
12680Sstevel@tonic-gate termiosp->c_oflag |= TAB2;
12690Sstevel@tonic-gate break;
12700Sstevel@tonic-gate
12710Sstevel@tonic-gate case O_XTABS:
12720Sstevel@tonic-gate termiosp->c_oflag |= TAB3;
12730Sstevel@tonic-gate break;
12740Sstevel@tonic-gate }
12750Sstevel@tonic-gate if (csp->t_flags & O_VTDELAY)
12760Sstevel@tonic-gate termiosp->c_oflag |= FFDLY;
12770Sstevel@tonic-gate if (csp->t_flags & O_BSDELAY)
12780Sstevel@tonic-gate termiosp->c_oflag |= BSDLY;
12790Sstevel@tonic-gate if (csp->t_flags & O_PRTERA)
12800Sstevel@tonic-gate termiosp->c_lflag |= ECHOPRT;
12810Sstevel@tonic-gate if (csp->t_flags & O_CRTERA)
12820Sstevel@tonic-gate termiosp->c_lflag |= ECHOE;
12830Sstevel@tonic-gate if (csp->t_flags & O_TOSTOP)
12840Sstevel@tonic-gate termiosp->c_lflag |= TOSTOP;
12850Sstevel@tonic-gate if (csp->t_flags & O_FLUSHO)
12860Sstevel@tonic-gate termiosp->c_lflag |= FLUSHO;
12870Sstevel@tonic-gate if (csp->t_flags & O_NOHANG)
12880Sstevel@tonic-gate termiosp->c_cflag |= CLOCAL;
12890Sstevel@tonic-gate if (csp->t_flags & O_CRTKIL)
12900Sstevel@tonic-gate termiosp->c_lflag |= ECHOKE;
12910Sstevel@tonic-gate if (csp->t_flags & O_PENDIN)
12920Sstevel@tonic-gate termiosp->c_lflag |= PENDIN;
12930Sstevel@tonic-gate if (!(csp->t_flags & O_DECCTQ))
12940Sstevel@tonic-gate termiosp->c_iflag |= IXANY;
12950Sstevel@tonic-gate if (csp->t_flags & O_NOFLSH)
12960Sstevel@tonic-gate termiosp->c_lflag |= NOFLSH;
12970Sstevel@tonic-gate if (termiosp->c_lflag & ICANON) {
12980Sstevel@tonic-gate FROM_COMPAT_CHAR(termiosp->c_cc[VEOF], csp->t_eofc);
12990Sstevel@tonic-gate FROM_COMPAT_CHAR(termiosp->c_cc[VEOL], csp->t_brkc);
13000Sstevel@tonic-gate } else {
13010Sstevel@tonic-gate termiosp->c_cc[VMIN] = 1;
13020Sstevel@tonic-gate termiosp->c_cc[VTIME] = 0;
13030Sstevel@tonic-gate }
13040Sstevel@tonic-gate }
13050Sstevel@tonic-gate
13060Sstevel@tonic-gate #define TO_COMPAT_CHAR(to, from) { if ((to = from) == 0) to = (uchar_t)0377; }
13070Sstevel@tonic-gate
13080Sstevel@tonic-gate static void
to_compat(struct termios * termiosp,compat_state_t * csp)13090Sstevel@tonic-gate to_compat(struct termios *termiosp, compat_state_t *csp)
13100Sstevel@tonic-gate {
13110Sstevel@tonic-gate csp->t_xflags &= (NOISIG|NOPOST);
13120Sstevel@tonic-gate csp->t_ospeed = termiosp->c_cflag & CBAUD;
13130Sstevel@tonic-gate csp->t_ispeed = (termiosp->c_cflag & CIBAUD) >> IBSHIFT;
13140Sstevel@tonic-gate if (sgttyb_handling > 0) {
13150Sstevel@tonic-gate if (termiosp->c_cflag & CBAUDEXT)
13160Sstevel@tonic-gate csp->t_ospeed += CBAUD + 1;
13170Sstevel@tonic-gate if (termiosp->c_cflag & CIBAUDEXT)
13180Sstevel@tonic-gate csp->t_ispeed += (CIBAUD >> IBSHIFT) + 1;
13190Sstevel@tonic-gate }
13200Sstevel@tonic-gate if (csp->t_ispeed == 0)
13210Sstevel@tonic-gate csp->t_ispeed = csp->t_ospeed;
13220Sstevel@tonic-gate if ((termiosp->c_cflag & CSTOPB) && csp->t_ispeed != B110)
13230Sstevel@tonic-gate csp->t_xflags |= STOPB;
13240Sstevel@tonic-gate TO_COMPAT_CHAR(csp->t_erase, termiosp->c_cc[VERASE]);
13250Sstevel@tonic-gate TO_COMPAT_CHAR(csp->t_kill, termiosp->c_cc[VKILL]);
13260Sstevel@tonic-gate TO_COMPAT_CHAR(csp->t_intrc, termiosp->c_cc[VINTR]);
13270Sstevel@tonic-gate TO_COMPAT_CHAR(csp->t_quitc, termiosp->c_cc[VQUIT]);
13280Sstevel@tonic-gate TO_COMPAT_CHAR(csp->t_startc, termiosp->c_cc[VSTART]);
13290Sstevel@tonic-gate TO_COMPAT_CHAR(csp->t_stopc, termiosp->c_cc[VSTOP]);
13300Sstevel@tonic-gate TO_COMPAT_CHAR(csp->t_suspc, termiosp->c_cc[VSUSP]);
13310Sstevel@tonic-gate TO_COMPAT_CHAR(csp->t_dsuspc, termiosp->c_cc[VDSUSP]);
13320Sstevel@tonic-gate TO_COMPAT_CHAR(csp->t_rprntc, termiosp->c_cc[VREPRINT]);
13330Sstevel@tonic-gate TO_COMPAT_CHAR(csp->t_flushc, termiosp->c_cc[VDISCARD]);
13340Sstevel@tonic-gate TO_COMPAT_CHAR(csp->t_werasc, termiosp->c_cc[VWERASE]);
13350Sstevel@tonic-gate TO_COMPAT_CHAR(csp->t_lnextc, termiosp->c_cc[VLNEXT]);
13360Sstevel@tonic-gate csp->t_flags &= (O_CTLECH|O_LITOUT|O_PASS8|O_ODDP|O_EVENP);
13370Sstevel@tonic-gate if (termiosp->c_iflag & IXOFF)
13380Sstevel@tonic-gate csp->t_flags |= O_TANDEM;
13390Sstevel@tonic-gate if (!(termiosp->c_iflag &
13400Sstevel@tonic-gate (IMAXBEL|BRKINT|IGNPAR|PARMRK|INPCK|ISTRIP|
13410Sstevel@tonic-gate INLCR|IGNCR|ICRNL|IUCLC|IXON)) &&
13420Sstevel@tonic-gate !(termiosp->c_oflag & OPOST) &&
13430Sstevel@tonic-gate (termiosp->c_cflag & (CSIZE|PARENB)) == CS8 &&
13440Sstevel@tonic-gate !(termiosp->c_lflag & (ISIG|ICANON|XCASE|IEXTEN)))
13450Sstevel@tonic-gate csp->t_flags |= O_RAW;
13460Sstevel@tonic-gate else {
13470Sstevel@tonic-gate if (!(termiosp->c_iflag & IXON)) {
13480Sstevel@tonic-gate csp->t_startc = (uchar_t)0377;
13490Sstevel@tonic-gate csp->t_stopc = (uchar_t)0377;
13500Sstevel@tonic-gate }
13510Sstevel@tonic-gate if ((termiosp->c_cflag & (CSIZE|PARENB)) == CS8 &&
13520Sstevel@tonic-gate !(termiosp->c_oflag & OPOST))
13530Sstevel@tonic-gate csp->t_flags |= O_LITOUT;
13540Sstevel@tonic-gate else {
13550Sstevel@tonic-gate csp->t_flags &= ~O_LITOUT;
13560Sstevel@tonic-gate if ((termiosp->c_cflag & (CSIZE|PARENB)) == CS8) {
13570Sstevel@tonic-gate if (!(termiosp->c_iflag & ISTRIP))
13580Sstevel@tonic-gate csp->t_flags |= O_PASS8;
13590Sstevel@tonic-gate } else {
13600Sstevel@tonic-gate csp->t_flags &= ~(O_ODDP|O_EVENP|O_PASS8);
13610Sstevel@tonic-gate if (termiosp->c_cflag & PARODD)
13620Sstevel@tonic-gate csp->t_flags |= O_ODDP;
13630Sstevel@tonic-gate else if (termiosp->c_iflag & INPCK)
13640Sstevel@tonic-gate csp->t_flags |= O_EVENP;
13650Sstevel@tonic-gate else
13660Sstevel@tonic-gate csp->t_flags |= O_ODDP|O_EVENP;
13670Sstevel@tonic-gate }
13680Sstevel@tonic-gate if (!(termiosp->c_oflag & OPOST))
13690Sstevel@tonic-gate csp->t_xflags |= NOPOST;
13700Sstevel@tonic-gate else
13710Sstevel@tonic-gate csp->t_xflags &= ~NOPOST;
13720Sstevel@tonic-gate }
13730Sstevel@tonic-gate if (!(termiosp->c_lflag & ISIG))
13740Sstevel@tonic-gate csp->t_xflags |= NOISIG;
13750Sstevel@tonic-gate else
13760Sstevel@tonic-gate csp->t_xflags &= ~NOISIG;
13770Sstevel@tonic-gate if (!(termiosp->c_lflag & ICANON))
13780Sstevel@tonic-gate csp->t_flags |= O_CBREAK;
13790Sstevel@tonic-gate if (termiosp->c_lflag & ECHOCTL)
13800Sstevel@tonic-gate csp->t_flags |= O_CTLECH;
13810Sstevel@tonic-gate else
13820Sstevel@tonic-gate csp->t_flags &= ~O_CTLECH;
13830Sstevel@tonic-gate }
13840Sstevel@tonic-gate if (termiosp->c_oflag & OLCUC)
13850Sstevel@tonic-gate csp->t_flags |= O_LCASE;
13860Sstevel@tonic-gate if (termiosp->c_lflag&ECHO)
13870Sstevel@tonic-gate csp->t_flags |= O_ECHO;
13880Sstevel@tonic-gate if (termiosp->c_oflag & ONLCR) {
13890Sstevel@tonic-gate csp->t_flags |= O_CRMOD;
13900Sstevel@tonic-gate switch (termiosp->c_oflag & CRDLY) {
13910Sstevel@tonic-gate
13920Sstevel@tonic-gate case CR2:
13930Sstevel@tonic-gate csp->t_flags |= O_CR1;
13940Sstevel@tonic-gate break;
13950Sstevel@tonic-gate
13960Sstevel@tonic-gate case CR3:
13970Sstevel@tonic-gate csp->t_flags |= O_CR2;
13980Sstevel@tonic-gate break;
13990Sstevel@tonic-gate }
14000Sstevel@tonic-gate } else {
14010Sstevel@tonic-gate if ((termiosp->c_oflag & CR1) &&
14020Sstevel@tonic-gate (termiosp->c_oflag & ONLRET))
14030Sstevel@tonic-gate csp->t_flags |= O_NL1; /* tty37 */
14040Sstevel@tonic-gate }
14050Sstevel@tonic-gate if ((termiosp->c_oflag & ONLRET) && (termiosp->c_oflag & NL1))
14060Sstevel@tonic-gate csp->t_flags |= O_NL2;
14070Sstevel@tonic-gate switch (termiosp->c_oflag & TABDLY) {
14080Sstevel@tonic-gate
14090Sstevel@tonic-gate case TAB1:
14100Sstevel@tonic-gate csp->t_flags |= O_TAB1;
14110Sstevel@tonic-gate break;
14120Sstevel@tonic-gate
14130Sstevel@tonic-gate case TAB2:
14140Sstevel@tonic-gate csp->t_flags |= O_TAB2;
14150Sstevel@tonic-gate break;
14160Sstevel@tonic-gate
14170Sstevel@tonic-gate case XTABS:
14180Sstevel@tonic-gate csp->t_flags |= O_XTABS;
14190Sstevel@tonic-gate break;
14200Sstevel@tonic-gate }
14210Sstevel@tonic-gate if (termiosp->c_oflag & FFDLY)
14220Sstevel@tonic-gate csp->t_flags |= O_VTDELAY;
14230Sstevel@tonic-gate if (termiosp->c_oflag & BSDLY)
14240Sstevel@tonic-gate csp->t_flags |= O_BSDELAY;
14250Sstevel@tonic-gate if (termiosp->c_lflag & ECHOPRT)
14260Sstevel@tonic-gate csp->t_flags |= O_PRTERA;
14270Sstevel@tonic-gate if (termiosp->c_lflag & ECHOE)
14280Sstevel@tonic-gate csp->t_flags |= (O_CRTERA|O_CRTBS);
14290Sstevel@tonic-gate if (termiosp->c_lflag & TOSTOP)
14300Sstevel@tonic-gate csp->t_flags |= O_TOSTOP;
14310Sstevel@tonic-gate if (termiosp->c_lflag & FLUSHO)
14320Sstevel@tonic-gate csp->t_flags |= O_FLUSHO;
14330Sstevel@tonic-gate if (termiosp->c_cflag & CLOCAL)
14340Sstevel@tonic-gate csp->t_flags |= O_NOHANG;
14350Sstevel@tonic-gate if (termiosp->c_lflag & ECHOKE)
14360Sstevel@tonic-gate csp->t_flags |= O_CRTKIL;
14370Sstevel@tonic-gate if (termiosp->c_lflag & PENDIN)
14380Sstevel@tonic-gate csp->t_flags |= O_PENDIN;
14390Sstevel@tonic-gate if (!(termiosp->c_iflag & IXANY))
14400Sstevel@tonic-gate csp->t_flags |= O_DECCTQ;
14410Sstevel@tonic-gate if (termiosp->c_lflag & NOFLSH)
14420Sstevel@tonic-gate csp->t_flags |= O_NOFLSH;
14430Sstevel@tonic-gate if (termiosp->c_lflag & ICANON) {
14440Sstevel@tonic-gate TO_COMPAT_CHAR(csp->t_eofc, termiosp->c_cc[VEOF]);
14450Sstevel@tonic-gate TO_COMPAT_CHAR(csp->t_brkc, termiosp->c_cc[VEOL]);
14460Sstevel@tonic-gate } else {
14470Sstevel@tonic-gate termiosp->c_cc[VMIN] = 1;
14480Sstevel@tonic-gate termiosp->c_cc[VTIME] = 0;
14490Sstevel@tonic-gate }
14500Sstevel@tonic-gate }
1451