17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
59d5056eaSjv227347 * Common Development and Distribution License (the "License").
69d5056eaSjv227347 * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
217c478bd9Sstevel@tonic-gate /*
229d5056eaSjv227347 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
237c478bd9Sstevel@tonic-gate * Use is subject to license terms.
246cfa0a70SAndy Fiddaman * Copyright 2018 OmniOS Community Edition (OmniOSce) Association.
257c478bd9Sstevel@tonic-gate */
267c478bd9Sstevel@tonic-gate
277c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
287c478bd9Sstevel@tonic-gate /* All Rights Reserved */
297c478bd9Sstevel@tonic-gate
307c478bd9Sstevel@tonic-gate /*
317c478bd9Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988
327c478bd9Sstevel@tonic-gate * The Regents of the University of California
337c478bd9Sstevel@tonic-gate * All Rights Reserved
347c478bd9Sstevel@tonic-gate *
357c478bd9Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from
367c478bd9Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its
377c478bd9Sstevel@tonic-gate * contributors.
387c478bd9Sstevel@tonic-gate */
397c478bd9Sstevel@tonic-gate
407c478bd9Sstevel@tonic-gate /*
417c478bd9Sstevel@tonic-gate * Module to intercept old V7 and 4BSD "ioctl" calls.
427c478bd9Sstevel@tonic-gate */
437c478bd9Sstevel@tonic-gate
447c478bd9Sstevel@tonic-gate #include <sys/types.h>
457c478bd9Sstevel@tonic-gate #include <sys/param.h>
467c478bd9Sstevel@tonic-gate #include <sys/signal.h>
477c478bd9Sstevel@tonic-gate #include <sys/file.h>
487c478bd9Sstevel@tonic-gate #include <sys/termios.h>
497c478bd9Sstevel@tonic-gate #include <sys/ttold.h>
507c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
517c478bd9Sstevel@tonic-gate #include <sys/stream.h>
527c478bd9Sstevel@tonic-gate #include <sys/stropts.h>
539d5056eaSjv227347 #include <sys/strsubr.h>
547c478bd9Sstevel@tonic-gate #include <sys/strsun.h>
557c478bd9Sstevel@tonic-gate #include <sys/errno.h>
567c478bd9Sstevel@tonic-gate #include <sys/debug.h>
577c478bd9Sstevel@tonic-gate #include <sys/ttcompat.h>
587c478bd9Sstevel@tonic-gate #include <sys/ddi.h>
597c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
607c478bd9Sstevel@tonic-gate #include <sys/kmem.h>
617c478bd9Sstevel@tonic-gate #include <sys/policy.h>
627c478bd9Sstevel@tonic-gate
637c478bd9Sstevel@tonic-gate /*
647c478bd9Sstevel@tonic-gate * This is the loadable module wrapper.
657c478bd9Sstevel@tonic-gate */
667c478bd9Sstevel@tonic-gate #include <sys/conf.h>
677c478bd9Sstevel@tonic-gate #include <sys/modctl.h>
687c478bd9Sstevel@tonic-gate
697c478bd9Sstevel@tonic-gate /* See os/streamio.c */
707c478bd9Sstevel@tonic-gate extern int sgttyb_handling;
717c478bd9Sstevel@tonic-gate
727c478bd9Sstevel@tonic-gate static struct streamtab ttcoinfo;
737c478bd9Sstevel@tonic-gate
747c478bd9Sstevel@tonic-gate static struct fmodsw fsw = {
757c478bd9Sstevel@tonic-gate "ttcompat",
767c478bd9Sstevel@tonic-gate &ttcoinfo,
776cfa0a70SAndy Fiddaman D_MTQPAIR | D_MP | _D_SINGLE_INSTANCE
787c478bd9Sstevel@tonic-gate };
797c478bd9Sstevel@tonic-gate
807c478bd9Sstevel@tonic-gate /*
817c478bd9Sstevel@tonic-gate * Module linkage information for the kernel.
827c478bd9Sstevel@tonic-gate */
837c478bd9Sstevel@tonic-gate
847c478bd9Sstevel@tonic-gate static struct modlstrmod modlstrmod = {
857c478bd9Sstevel@tonic-gate &mod_strmodops,
867c478bd9Sstevel@tonic-gate "alt ioctl calls",
877c478bd9Sstevel@tonic-gate &fsw
887c478bd9Sstevel@tonic-gate };
897c478bd9Sstevel@tonic-gate
907c478bd9Sstevel@tonic-gate static struct modlinkage modlinkage = {
917c478bd9Sstevel@tonic-gate MODREV_1, &modlstrmod, NULL
927c478bd9Sstevel@tonic-gate };
937c478bd9Sstevel@tonic-gate
947c478bd9Sstevel@tonic-gate int
_init(void)957c478bd9Sstevel@tonic-gate _init(void)
967c478bd9Sstevel@tonic-gate {
977c478bd9Sstevel@tonic-gate return (mod_install(&modlinkage));
987c478bd9Sstevel@tonic-gate }
997c478bd9Sstevel@tonic-gate
1007c478bd9Sstevel@tonic-gate int
_fini(void)1017c478bd9Sstevel@tonic-gate _fini(void)
1027c478bd9Sstevel@tonic-gate {
1037c478bd9Sstevel@tonic-gate return (mod_remove(&modlinkage));
1047c478bd9Sstevel@tonic-gate }
1057c478bd9Sstevel@tonic-gate
1067c478bd9Sstevel@tonic-gate int
_info(struct modinfo * modinfop)1077c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop)
1087c478bd9Sstevel@tonic-gate {
1097c478bd9Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop));
1107c478bd9Sstevel@tonic-gate }
1117c478bd9Sstevel@tonic-gate
1127c478bd9Sstevel@tonic-gate static int ttcompatopen(queue_t *, dev_t *, int, int, cred_t *);
1137c478bd9Sstevel@tonic-gate static int ttcompatclose(queue_t *, int, cred_t *);
114*457cb919SToomas Soome static int ttcompatrput(queue_t *, mblk_t *);
115*457cb919SToomas Soome static int ttcompatwput(queue_t *, mblk_t *);
1167c478bd9Sstevel@tonic-gate
1177c478bd9Sstevel@tonic-gate static struct module_info ttycompatmiinfo = {
1187c478bd9Sstevel@tonic-gate 0,
1197c478bd9Sstevel@tonic-gate "ttcompat",
1207c478bd9Sstevel@tonic-gate 0,
1217c478bd9Sstevel@tonic-gate INFPSZ,
1227c478bd9Sstevel@tonic-gate 2048,
1237c478bd9Sstevel@tonic-gate 128
1247c478bd9Sstevel@tonic-gate };
1257c478bd9Sstevel@tonic-gate
1267c478bd9Sstevel@tonic-gate static struct qinit ttycompatrinit = {
127*457cb919SToomas Soome ttcompatrput,
1287c478bd9Sstevel@tonic-gate NULL,
1297c478bd9Sstevel@tonic-gate ttcompatopen,
1307c478bd9Sstevel@tonic-gate ttcompatclose,
1317c478bd9Sstevel@tonic-gate NULL,
1327c478bd9Sstevel@tonic-gate &ttycompatmiinfo
1337c478bd9Sstevel@tonic-gate };
1347c478bd9Sstevel@tonic-gate
1357c478bd9Sstevel@tonic-gate static struct module_info ttycompatmoinfo = {
1367c478bd9Sstevel@tonic-gate 42,
1377c478bd9Sstevel@tonic-gate "ttcompat",
1387c478bd9Sstevel@tonic-gate 0,
1397c478bd9Sstevel@tonic-gate INFPSZ,
1407c478bd9Sstevel@tonic-gate 300,
1417c478bd9Sstevel@tonic-gate 200
1427c478bd9Sstevel@tonic-gate };
1437c478bd9Sstevel@tonic-gate
1447c478bd9Sstevel@tonic-gate static struct qinit ttycompatwinit = {
145*457cb919SToomas Soome ttcompatwput,
1467c478bd9Sstevel@tonic-gate NULL,
1477c478bd9Sstevel@tonic-gate ttcompatopen,
1487c478bd9Sstevel@tonic-gate ttcompatclose,
1497c478bd9Sstevel@tonic-gate NULL,
1507c478bd9Sstevel@tonic-gate &ttycompatmoinfo
1517c478bd9Sstevel@tonic-gate };
1527c478bd9Sstevel@tonic-gate
1537c478bd9Sstevel@tonic-gate static struct streamtab ttcoinfo = {
1547c478bd9Sstevel@tonic-gate &ttycompatrinit,
1557c478bd9Sstevel@tonic-gate &ttycompatwinit,
1567c478bd9Sstevel@tonic-gate NULL,
1577c478bd9Sstevel@tonic-gate NULL
1587c478bd9Sstevel@tonic-gate };
1597c478bd9Sstevel@tonic-gate
1607c478bd9Sstevel@tonic-gate static void ttcompat_do_ioctl(ttcompat_state_t *, queue_t *, mblk_t *);
1617c478bd9Sstevel@tonic-gate static void ttcompat_ioctl_ack(queue_t *, mblk_t *);
1627c478bd9Sstevel@tonic-gate static void ttcopyout(queue_t *, mblk_t *);
1637c478bd9Sstevel@tonic-gate static void ttcompat_ioctl_nak(queue_t *, mblk_t *);
1647c478bd9Sstevel@tonic-gate static void from_compat(compat_state_t *, struct termios *);
1657c478bd9Sstevel@tonic-gate static void to_compat(struct termios *, compat_state_t *);
1667c478bd9Sstevel@tonic-gate
1677c478bd9Sstevel@tonic-gate /*
1687c478bd9Sstevel@tonic-gate * Open - get the current modes and translate them to the V7/4BSD equivalent.
1697c478bd9Sstevel@tonic-gate */
1707c478bd9Sstevel@tonic-gate /*ARGSUSED*/
1717c478bd9Sstevel@tonic-gate static int
ttcompatopen(queue_t * q,dev_t * devp,int oflag,int sflag,cred_t * crp)1727c478bd9Sstevel@tonic-gate ttcompatopen(queue_t *q, dev_t *devp, int oflag, int sflag, cred_t *crp)
1737c478bd9Sstevel@tonic-gate {
1747c478bd9Sstevel@tonic-gate ttcompat_state_t *tp;
1757c478bd9Sstevel@tonic-gate
1767c478bd9Sstevel@tonic-gate if (q->q_ptr != NULL) {
1777c478bd9Sstevel@tonic-gate tp = (ttcompat_state_t *)q->q_ptr;
1787c478bd9Sstevel@tonic-gate /* fail open if TIOCEXCL was done and its not privileged */
1797c478bd9Sstevel@tonic-gate if ((tp->t_new_lflags & XCLUDE) &&
1807c478bd9Sstevel@tonic-gate secpolicy_excl_open(crp) != 0) {
1817c478bd9Sstevel@tonic-gate return (EBUSY);
1827c478bd9Sstevel@tonic-gate }
1837c478bd9Sstevel@tonic-gate return (0); /* already attached */
1847c478bd9Sstevel@tonic-gate }
1857c478bd9Sstevel@tonic-gate tp = kmem_zalloc(sizeof (ttcompat_state_t), KM_SLEEP);
1867c478bd9Sstevel@tonic-gate q->q_ptr = tp;
1877c478bd9Sstevel@tonic-gate WR(q)->q_ptr = tp;
1887c478bd9Sstevel@tonic-gate qprocson(q);
1899d5056eaSjv227347
1907c478bd9Sstevel@tonic-gate return (0);
1917c478bd9Sstevel@tonic-gate }
1927c478bd9Sstevel@tonic-gate
1937c478bd9Sstevel@tonic-gate /* ARGSUSED1 */
1947c478bd9Sstevel@tonic-gate static int
ttcompatclose(queue_t * q,int flag,cred_t * crp)1957c478bd9Sstevel@tonic-gate ttcompatclose(queue_t *q, int flag, cred_t *crp)
1967c478bd9Sstevel@tonic-gate {
1977c478bd9Sstevel@tonic-gate ttcompat_state_t *tp = (ttcompat_state_t *)q->q_ptr;
1987c478bd9Sstevel@tonic-gate mblk_t *mp;
1997c478bd9Sstevel@tonic-gate
2007c478bd9Sstevel@tonic-gate /* Dump the state structure, then unlink it */
2017c478bd9Sstevel@tonic-gate qprocsoff(q);
2027c478bd9Sstevel@tonic-gate if (tp->t_bufcallid != 0) {
2037c478bd9Sstevel@tonic-gate qunbufcall(q, tp->t_bufcallid);
2047c478bd9Sstevel@tonic-gate tp->t_bufcallid = 0;
2057c478bd9Sstevel@tonic-gate }
2067c478bd9Sstevel@tonic-gate if ((mp = tp->t_iocpending) != NULL)
2077c478bd9Sstevel@tonic-gate freemsg(mp);
2087c478bd9Sstevel@tonic-gate kmem_free(tp, sizeof (ttcompat_state_t));
2097c478bd9Sstevel@tonic-gate q->q_ptr = NULL;
2107c478bd9Sstevel@tonic-gate
2117c478bd9Sstevel@tonic-gate return (0);
2127c478bd9Sstevel@tonic-gate }
2137c478bd9Sstevel@tonic-gate
2147c478bd9Sstevel@tonic-gate /*
2157c478bd9Sstevel@tonic-gate * Put procedure for input from driver end of stream (read queue).
2167c478bd9Sstevel@tonic-gate * Most messages just get passed to the next guy up; we intercept
2177c478bd9Sstevel@tonic-gate * "ioctl" replies, and if it's an "ioctl" whose reply we plan to do
2187c478bd9Sstevel@tonic-gate * something with, we do it.
2197c478bd9Sstevel@tonic-gate */
220*457cb919SToomas Soome static int
ttcompatrput(queue_t * q,mblk_t * mp)2217c478bd9Sstevel@tonic-gate ttcompatrput(queue_t *q, mblk_t *mp)
2227c478bd9Sstevel@tonic-gate {
2237c478bd9Sstevel@tonic-gate switch (mp->b_datap->db_type) {
2247c478bd9Sstevel@tonic-gate
2257c478bd9Sstevel@tonic-gate case M_IOCACK:
2267c478bd9Sstevel@tonic-gate ttcompat_ioctl_ack(q, mp);
2277c478bd9Sstevel@tonic-gate break;
2287c478bd9Sstevel@tonic-gate
2297c478bd9Sstevel@tonic-gate case M_IOCNAK:
2307c478bd9Sstevel@tonic-gate ttcompat_ioctl_nak(q, mp);
2317c478bd9Sstevel@tonic-gate break;
2327c478bd9Sstevel@tonic-gate
2337c478bd9Sstevel@tonic-gate default:
2347c478bd9Sstevel@tonic-gate putnext(q, mp);
2357c478bd9Sstevel@tonic-gate break;
2367c478bd9Sstevel@tonic-gate }
237*457cb919SToomas Soome return (0);
2387c478bd9Sstevel@tonic-gate }
2397c478bd9Sstevel@tonic-gate
2407c478bd9Sstevel@tonic-gate /*
2417c478bd9Sstevel@tonic-gate * Line discipline output queue put procedure: speeds M_IOCTL
2427c478bd9Sstevel@tonic-gate * messages.
2437c478bd9Sstevel@tonic-gate */
244*457cb919SToomas Soome static int
ttcompatwput(queue_t * q,mblk_t * mp)2457c478bd9Sstevel@tonic-gate ttcompatwput(queue_t *q, mblk_t *mp)
2467c478bd9Sstevel@tonic-gate {
2477c478bd9Sstevel@tonic-gate ttcompat_state_t *tp;
2487c478bd9Sstevel@tonic-gate struct copyreq *cqp;
2497c478bd9Sstevel@tonic-gate struct copyresp *csp;
2507c478bd9Sstevel@tonic-gate struct iocblk *iocbp;
2517c478bd9Sstevel@tonic-gate
2527c478bd9Sstevel@tonic-gate tp = (ttcompat_state_t *)q->q_ptr;
2537c478bd9Sstevel@tonic-gate
2547c478bd9Sstevel@tonic-gate /*
2557c478bd9Sstevel@tonic-gate * Process some M_IOCTL messages here; pass everything else down.
2567c478bd9Sstevel@tonic-gate */
2577c478bd9Sstevel@tonic-gate switch (mp->b_datap->db_type) {
2587c478bd9Sstevel@tonic-gate
2597c478bd9Sstevel@tonic-gate default:
2607c478bd9Sstevel@tonic-gate putnext(q, mp);
261*457cb919SToomas Soome return (0);
2627c478bd9Sstevel@tonic-gate
2637c478bd9Sstevel@tonic-gate case M_IOCTL:
2647c478bd9Sstevel@tonic-gate iocbp = (struct iocblk *)mp->b_rptr;
2657c478bd9Sstevel@tonic-gate
2667c478bd9Sstevel@tonic-gate switch (iocbp->ioc_cmd) {
2677c478bd9Sstevel@tonic-gate
2687c478bd9Sstevel@tonic-gate default:
2697c478bd9Sstevel@tonic-gate /* these are ioctls with no arguments or are known to stream head */
2707c478bd9Sstevel@tonic-gate /* process them right away */
2717c478bd9Sstevel@tonic-gate ttcompat_do_ioctl(tp, q, mp);
272*457cb919SToomas Soome return (0);
2737c478bd9Sstevel@tonic-gate case TIOCSETN:
2747c478bd9Sstevel@tonic-gate case TIOCSLTC:
2757c478bd9Sstevel@tonic-gate case TIOCSETC:
2767c478bd9Sstevel@tonic-gate case TIOCLBIS:
2777c478bd9Sstevel@tonic-gate case TIOCLBIC:
2787c478bd9Sstevel@tonic-gate case TIOCLSET:
2797c478bd9Sstevel@tonic-gate case TIOCFLUSH:
2807c478bd9Sstevel@tonic-gate if (iocbp->ioc_count != TRANSPARENT) {
2817c478bd9Sstevel@tonic-gate putnext(q, mp);
282*457cb919SToomas Soome return (0);
2837c478bd9Sstevel@tonic-gate }
2847c478bd9Sstevel@tonic-gate
2857c478bd9Sstevel@tonic-gate mp->b_datap->db_type = M_COPYIN;
2867c478bd9Sstevel@tonic-gate cqp = (struct copyreq *)mp->b_rptr;
2877c478bd9Sstevel@tonic-gate cqp->cq_addr = (caddr_t)*(intptr_t *)mp->b_cont->b_rptr;
2887c478bd9Sstevel@tonic-gate switch (iocbp->ioc_cmd) {
2897c478bd9Sstevel@tonic-gate case TIOCSETN:
2907c478bd9Sstevel@tonic-gate cqp->cq_size = sizeof (struct sgttyb);
2917c478bd9Sstevel@tonic-gate break;
2927c478bd9Sstevel@tonic-gate case TIOCSLTC:
2937c478bd9Sstevel@tonic-gate cqp->cq_size = sizeof (struct ltchars);
2947c478bd9Sstevel@tonic-gate break;
2957c478bd9Sstevel@tonic-gate case TIOCSETC:
2967c478bd9Sstevel@tonic-gate cqp->cq_size = sizeof (struct tchars);
2977c478bd9Sstevel@tonic-gate break;
2987c478bd9Sstevel@tonic-gate case TIOCLBIS:
2997c478bd9Sstevel@tonic-gate case TIOCLBIC:
3007c478bd9Sstevel@tonic-gate case TIOCLSET:
3017c478bd9Sstevel@tonic-gate case TIOCFLUSH:
3027c478bd9Sstevel@tonic-gate cqp->cq_size = sizeof (int);
3037c478bd9Sstevel@tonic-gate break;
3047c478bd9Sstevel@tonic-gate default:
3057c478bd9Sstevel@tonic-gate break;
3067c478bd9Sstevel@tonic-gate }
3077c478bd9Sstevel@tonic-gate cqp->cq_flag = 0;
3087c478bd9Sstevel@tonic-gate cqp->cq_private = NULL;
3097c478bd9Sstevel@tonic-gate freemsg(mp->b_cont);
3107c478bd9Sstevel@tonic-gate mp->b_cont = NULL;
3117c478bd9Sstevel@tonic-gate mp->b_wptr = mp->b_rptr + sizeof (struct copyreq);
3127c478bd9Sstevel@tonic-gate tp->t_ioccmd = iocbp->ioc_cmd;
3137c478bd9Sstevel@tonic-gate tp->t_state |= TS_W_IN;
3147c478bd9Sstevel@tonic-gate qreply(q, mp);
315*457cb919SToomas Soome return (0);
3167c478bd9Sstevel@tonic-gate
3177c478bd9Sstevel@tonic-gate } /* switch ioc_cmd */
3187c478bd9Sstevel@tonic-gate case M_IOCDATA:
3197c478bd9Sstevel@tonic-gate csp = (struct copyresp *)mp->b_rptr;
3207c478bd9Sstevel@tonic-gate
3217c478bd9Sstevel@tonic-gate switch (csp->cp_cmd) {
3227c478bd9Sstevel@tonic-gate
3237c478bd9Sstevel@tonic-gate default:
3247c478bd9Sstevel@tonic-gate putnext(q, mp);
325*457cb919SToomas Soome return (0);
3267c478bd9Sstevel@tonic-gate
3277c478bd9Sstevel@tonic-gate case TIOCSETN:
3287c478bd9Sstevel@tonic-gate case TIOCSLTC:
3297c478bd9Sstevel@tonic-gate case TIOCSETC:
3307c478bd9Sstevel@tonic-gate case TIOCLBIS:
3317c478bd9Sstevel@tonic-gate case TIOCLBIC:
3327c478bd9Sstevel@tonic-gate case TIOCLSET:
3337c478bd9Sstevel@tonic-gate case TIOCFLUSH:
3347c478bd9Sstevel@tonic-gate tp->t_state &= ~TS_W_IN;
3357c478bd9Sstevel@tonic-gate if (csp->cp_rval != 0) { /* failure */
3367c478bd9Sstevel@tonic-gate freemsg(mp);
337*457cb919SToomas Soome return (0);
3387c478bd9Sstevel@tonic-gate }
3397c478bd9Sstevel@tonic-gate
3407c478bd9Sstevel@tonic-gate /* make it look like an ioctl */
3417c478bd9Sstevel@tonic-gate mp->b_datap->db_type = M_IOCTL;
3427c478bd9Sstevel@tonic-gate mp->b_wptr = mp->b_rptr + sizeof (struct iocblk);
3437c478bd9Sstevel@tonic-gate iocbp = (struct iocblk *)mp->b_rptr;
3447c478bd9Sstevel@tonic-gate iocbp->ioc_count = MBLKL(mp->b_cont);
3457c478bd9Sstevel@tonic-gate iocbp->ioc_error = 0;
3467c478bd9Sstevel@tonic-gate iocbp->ioc_rval = 0;
3477c478bd9Sstevel@tonic-gate ttcompat_do_ioctl(tp, q, mp);
348*457cb919SToomas Soome return (0);
3497c478bd9Sstevel@tonic-gate
3507c478bd9Sstevel@tonic-gate case TIOCGLTC:
3517c478bd9Sstevel@tonic-gate case TIOCLGET:
3527c478bd9Sstevel@tonic-gate case TIOCGETC:
3537c478bd9Sstevel@tonic-gate tp->t_state &= ~TS_W_OUT;
3547c478bd9Sstevel@tonic-gate if (csp->cp_rval != 0) { /* failure */
3557c478bd9Sstevel@tonic-gate freemsg(mp);
356*457cb919SToomas Soome return (0);
3577c478bd9Sstevel@tonic-gate }
3587c478bd9Sstevel@tonic-gate
3597c478bd9Sstevel@tonic-gate iocbp = (struct iocblk *)mp->b_rptr;
3607c478bd9Sstevel@tonic-gate iocbp->ioc_count = 0;
3617c478bd9Sstevel@tonic-gate iocbp->ioc_error = 0;
3627c478bd9Sstevel@tonic-gate iocbp->ioc_rval = 0;
3637c478bd9Sstevel@tonic-gate mp->b_datap->db_type = M_IOCACK;
3647c478bd9Sstevel@tonic-gate qreply(q, mp);
365*457cb919SToomas Soome return (0);
3667c478bd9Sstevel@tonic-gate
3677c478bd9Sstevel@tonic-gate } /* switch cp_cmd */
3687c478bd9Sstevel@tonic-gate } /* end message switch */
369*457cb919SToomas Soome return (0);
3707c478bd9Sstevel@tonic-gate }
3717c478bd9Sstevel@tonic-gate
3727c478bd9Sstevel@tonic-gate /*
3737c478bd9Sstevel@tonic-gate * Retry an "ioctl", now that "bufcall" claims we may be able to allocate
3747c478bd9Sstevel@tonic-gate * the buffer we need.
3757c478bd9Sstevel@tonic-gate */
3767c478bd9Sstevel@tonic-gate static void
ttcompat_reioctl(void * arg)3777c478bd9Sstevel@tonic-gate ttcompat_reioctl(void *arg)
3787c478bd9Sstevel@tonic-gate {
3797c478bd9Sstevel@tonic-gate queue_t *q = arg;
3807c478bd9Sstevel@tonic-gate ttcompat_state_t *tp;
3817c478bd9Sstevel@tonic-gate mblk_t *mp;
3827c478bd9Sstevel@tonic-gate
3837c478bd9Sstevel@tonic-gate tp = (ttcompat_state_t *)q->q_ptr;
3847c478bd9Sstevel@tonic-gate tp->t_bufcallid = 0;
3857c478bd9Sstevel@tonic-gate
3867c478bd9Sstevel@tonic-gate if ((mp = tp->t_iocpending) != NULL) {
3877c478bd9Sstevel@tonic-gate tp->t_iocpending = NULL; /* not pending any more */
3887c478bd9Sstevel@tonic-gate ttcompat_do_ioctl(tp, q, mp);
3897c478bd9Sstevel@tonic-gate }
3907c478bd9Sstevel@tonic-gate }
3917c478bd9Sstevel@tonic-gate
3927c478bd9Sstevel@tonic-gate /*
3937c478bd9Sstevel@tonic-gate * Handle old-style "ioctl" messages; pass the rest down unmolested.
3947c478bd9Sstevel@tonic-gate */
3957c478bd9Sstevel@tonic-gate static void
ttcompat_do_ioctl(ttcompat_state_t * tp,queue_t * q,mblk_t * mp)3967c478bd9Sstevel@tonic-gate ttcompat_do_ioctl(ttcompat_state_t *tp, queue_t *q, mblk_t *mp)
3977c478bd9Sstevel@tonic-gate {
3987c478bd9Sstevel@tonic-gate struct iocblk *iocp;
3997c478bd9Sstevel@tonic-gate int error;
4007c478bd9Sstevel@tonic-gate
4017c478bd9Sstevel@tonic-gate /*
4027c478bd9Sstevel@tonic-gate * Most of the miocpullup()'s below aren't needed because the
4037c478bd9Sstevel@tonic-gate * ioctls in question are actually transparent M_IOCDATA messages
4047c478bd9Sstevel@tonic-gate * dummied to look like M_IOCTL messages. However, for clarity and
4057c478bd9Sstevel@tonic-gate * robustness against future changes, we've included them anyway.
4067c478bd9Sstevel@tonic-gate */
4077c478bd9Sstevel@tonic-gate
4087c478bd9Sstevel@tonic-gate iocp = (struct iocblk *)mp->b_rptr;
4097c478bd9Sstevel@tonic-gate switch (iocp->ioc_cmd) {
4107c478bd9Sstevel@tonic-gate
4117c478bd9Sstevel@tonic-gate /*
4127c478bd9Sstevel@tonic-gate * "get"-style calls that get translated data from the "termios"
4137c478bd9Sstevel@tonic-gate * structure. Save the existing code and pass it down as a TCGETS.
4147c478bd9Sstevel@tonic-gate */
4157c478bd9Sstevel@tonic-gate case TIOCGETC:
4167c478bd9Sstevel@tonic-gate case TIOCLGET:
4177c478bd9Sstevel@tonic-gate case TIOCGLTC:
4187c478bd9Sstevel@tonic-gate if (iocp->ioc_count != TRANSPARENT) {
4197c478bd9Sstevel@tonic-gate miocnak(q, mp, 0, EINVAL);
4207c478bd9Sstevel@tonic-gate return;
4217c478bd9Sstevel@tonic-gate }
4227c478bd9Sstevel@tonic-gate
4237c478bd9Sstevel@tonic-gate /*
4247c478bd9Sstevel@tonic-gate * We can get here with t_arg != 0, iff the stream head
4257c478bd9Sstevel@tonic-gate * has for some reason given up on the ioctl in progress.
4267c478bd9Sstevel@tonic-gate * The most likely cause is an interrupted ioctl syscall.
4277c478bd9Sstevel@tonic-gate * We will behave robustly because (given our perimeter)
4287c478bd9Sstevel@tonic-gate * the ttcompat_state_t will get set up for the new ioctl,
4297c478bd9Sstevel@tonic-gate * and when the response we were waiting for appears it
4307c478bd9Sstevel@tonic-gate * will be passed on to the stream head which will discard
4317c478bd9Sstevel@tonic-gate * it as non-current.
4327c478bd9Sstevel@tonic-gate */
4337c478bd9Sstevel@tonic-gate ASSERT(mp->b_cont != NULL);
4347c478bd9Sstevel@tonic-gate tp->t_arg = *(intptr_t *)mp->b_cont->b_rptr;
4357c478bd9Sstevel@tonic-gate /* free the data buffer - it might not be sufficient */
4367c478bd9Sstevel@tonic-gate /* driver will allocate one for termios size */
4377c478bd9Sstevel@tonic-gate freemsg(mp->b_cont);
4387c478bd9Sstevel@tonic-gate mp->b_cont = NULL;
4397c478bd9Sstevel@tonic-gate iocp->ioc_count = 0;
4407c478bd9Sstevel@tonic-gate /* FALLTHRU */
4417c478bd9Sstevel@tonic-gate case TIOCGETP:
4427c478bd9Sstevel@tonic-gate goto dogets;
4437c478bd9Sstevel@tonic-gate
4447c478bd9Sstevel@tonic-gate /*
4457c478bd9Sstevel@tonic-gate * "set"-style calls that set translated data into a "termios"
4467c478bd9Sstevel@tonic-gate * structure. Set our idea of the new state from the value
4477c478bd9Sstevel@tonic-gate * given to us. We then have to get the current state, so we
4487c478bd9Sstevel@tonic-gate * turn this guy into a TCGETS and pass it down. When the
4497c478bd9Sstevel@tonic-gate * ACK comes back, we modify the state we got back and shove it
4507c478bd9Sstevel@tonic-gate * back down as the appropriate type of TCSETS.
4517c478bd9Sstevel@tonic-gate */
4527c478bd9Sstevel@tonic-gate case TIOCSETP:
4537c478bd9Sstevel@tonic-gate case TIOCSETN:
4547c478bd9Sstevel@tonic-gate error = miocpullup(mp, sizeof (struct sgttyb));
4557c478bd9Sstevel@tonic-gate if (error != 0) {
4567c478bd9Sstevel@tonic-gate miocnak(q, mp, 0, error);
4577c478bd9Sstevel@tonic-gate return;
4587c478bd9Sstevel@tonic-gate }
4597c478bd9Sstevel@tonic-gate tp->t_new_sgttyb = *((struct sgttyb *)mp->b_cont->b_rptr);
4607c478bd9Sstevel@tonic-gate goto dogets;
4617c478bd9Sstevel@tonic-gate
4627c478bd9Sstevel@tonic-gate case TIOCSETC:
4637c478bd9Sstevel@tonic-gate error = miocpullup(mp, sizeof (struct tchars));
4647c478bd9Sstevel@tonic-gate if (error != 0) {
4657c478bd9Sstevel@tonic-gate miocnak(q, mp, 0, error);
4667c478bd9Sstevel@tonic-gate return;
4677c478bd9Sstevel@tonic-gate }
4687c478bd9Sstevel@tonic-gate tp->t_new_tchars = *((struct tchars *)mp->b_cont->b_rptr);
4697c478bd9Sstevel@tonic-gate goto dogets;
4707c478bd9Sstevel@tonic-gate
4717c478bd9Sstevel@tonic-gate case TIOCSLTC:
4727c478bd9Sstevel@tonic-gate error = miocpullup(mp, sizeof (struct ltchars));
4737c478bd9Sstevel@tonic-gate if (error != 0) {
4747c478bd9Sstevel@tonic-gate miocnak(q, mp, 0, error);
4757c478bd9Sstevel@tonic-gate return;
4767c478bd9Sstevel@tonic-gate }
4777c478bd9Sstevel@tonic-gate tp->t_new_ltchars = *((struct ltchars *)mp->b_cont->b_rptr);
4787c478bd9Sstevel@tonic-gate goto dogets;
4797c478bd9Sstevel@tonic-gate
4807c478bd9Sstevel@tonic-gate case TIOCLBIS:
4817c478bd9Sstevel@tonic-gate case TIOCLBIC:
4827c478bd9Sstevel@tonic-gate case TIOCLSET:
4837c478bd9Sstevel@tonic-gate error = miocpullup(mp, sizeof (int));
4847c478bd9Sstevel@tonic-gate if (error != 0) {
4857c478bd9Sstevel@tonic-gate miocnak(q, mp, 0, error);
4867c478bd9Sstevel@tonic-gate return;
4877c478bd9Sstevel@tonic-gate }
4887c478bd9Sstevel@tonic-gate tp->t_new_lflags = *(int *)mp->b_cont->b_rptr;
4897c478bd9Sstevel@tonic-gate goto dogets;
4907c478bd9Sstevel@tonic-gate
4917c478bd9Sstevel@tonic-gate /*
4927c478bd9Sstevel@tonic-gate * "set"-style call that sets a particular bit in a "termios"
4937c478bd9Sstevel@tonic-gate * structure. We then have to get the current state, so we
4947c478bd9Sstevel@tonic-gate * turn this guy into a TCGETS and pass it down. When the
4957c478bd9Sstevel@tonic-gate * ACK comes back, we modify the state we got back and shove it
4967c478bd9Sstevel@tonic-gate * back down as the appropriate type of TCSETS.
4977c478bd9Sstevel@tonic-gate */
4987c478bd9Sstevel@tonic-gate case TIOCHPCL:
4997c478bd9Sstevel@tonic-gate dogets:
5007c478bd9Sstevel@tonic-gate tp->t_ioccmd = iocp->ioc_cmd;
5017c478bd9Sstevel@tonic-gate tp->t_iocid = iocp->ioc_id;
5027c478bd9Sstevel@tonic-gate tp->t_state |= TS_IOCWAIT;
5037c478bd9Sstevel@tonic-gate iocp->ioc_cmd = TCGETS;
5047c478bd9Sstevel@tonic-gate iocp->ioc_count = 0; /* no data returned unless we say so */
5057c478bd9Sstevel@tonic-gate break;
5067c478bd9Sstevel@tonic-gate
5077c478bd9Sstevel@tonic-gate /*
5087c478bd9Sstevel@tonic-gate * "set"-style call that sets DTR. Pretend that it was a TIOCMBIS
5097c478bd9Sstevel@tonic-gate * with TIOCM_DTR set.
5107c478bd9Sstevel@tonic-gate */
5117c478bd9Sstevel@tonic-gate case TIOCSDTR: {
5127c478bd9Sstevel@tonic-gate mblk_t *datap;
5137c478bd9Sstevel@tonic-gate
5147c478bd9Sstevel@tonic-gate if ((datap = allocb(sizeof (int), BPRI_HI)) == NULL)
5157c478bd9Sstevel@tonic-gate goto allocfailure;
5167c478bd9Sstevel@tonic-gate *(int *)datap->b_wptr = TIOCM_DTR;
5177c478bd9Sstevel@tonic-gate datap->b_wptr += sizeof (int);
5187c478bd9Sstevel@tonic-gate iocp->ioc_cmd = TIOCMBIS; /* turn it into a TIOCMBIS */
5197c478bd9Sstevel@tonic-gate if (mp->b_cont != NULL)
5207c478bd9Sstevel@tonic-gate freemsg(mp->b_cont);
5217c478bd9Sstevel@tonic-gate mp->b_cont = datap; /* attach the data */
5227c478bd9Sstevel@tonic-gate iocp->ioc_count = sizeof (int); /* in case driver checks */
5237c478bd9Sstevel@tonic-gate break;
5247c478bd9Sstevel@tonic-gate }
5257c478bd9Sstevel@tonic-gate
5267c478bd9Sstevel@tonic-gate /*
5277c478bd9Sstevel@tonic-gate * "set"-style call that clears DTR. Pretend that it was a TIOCMBIC
5287c478bd9Sstevel@tonic-gate * with TIOCM_DTR set.
5297c478bd9Sstevel@tonic-gate */
5307c478bd9Sstevel@tonic-gate case TIOCCDTR: {
5317c478bd9Sstevel@tonic-gate mblk_t *datap;
5327c478bd9Sstevel@tonic-gate
5337c478bd9Sstevel@tonic-gate if ((datap = allocb(sizeof (int), BPRI_HI)) == NULL)
5347c478bd9Sstevel@tonic-gate goto allocfailure;
5357c478bd9Sstevel@tonic-gate *(int *)datap->b_wptr = TIOCM_DTR;
5367c478bd9Sstevel@tonic-gate datap->b_wptr += sizeof (int);
5377c478bd9Sstevel@tonic-gate iocp->ioc_cmd = TIOCMBIC; /* turn it into a TIOCMBIC */
5387c478bd9Sstevel@tonic-gate if (mp->b_cont != NULL)
5397c478bd9Sstevel@tonic-gate freemsg(mp->b_cont);
5407c478bd9Sstevel@tonic-gate mp->b_cont = datap; /* attach the data */
5417c478bd9Sstevel@tonic-gate iocp->ioc_count = sizeof (int); /* in case driver checks */
5427c478bd9Sstevel@tonic-gate break;
5437c478bd9Sstevel@tonic-gate }
5447c478bd9Sstevel@tonic-gate
5457c478bd9Sstevel@tonic-gate /*
5467c478bd9Sstevel@tonic-gate * Translate into the S5 form of TCFLSH.
5477c478bd9Sstevel@tonic-gate */
5487c478bd9Sstevel@tonic-gate case TIOCFLUSH: {
5497c478bd9Sstevel@tonic-gate int flags;
5507c478bd9Sstevel@tonic-gate
5517c478bd9Sstevel@tonic-gate error = miocpullup(mp, sizeof (int));
5527c478bd9Sstevel@tonic-gate if (error != 0) {
5537c478bd9Sstevel@tonic-gate miocnak(q, mp, 0, error);
5547c478bd9Sstevel@tonic-gate return;
5557c478bd9Sstevel@tonic-gate }
5567c478bd9Sstevel@tonic-gate flags = *(int *)mp->b_cont->b_rptr;
5577c478bd9Sstevel@tonic-gate
5587c478bd9Sstevel@tonic-gate switch (flags&(FREAD|FWRITE)) {
5597c478bd9Sstevel@tonic-gate
5607c478bd9Sstevel@tonic-gate case 0:
5617c478bd9Sstevel@tonic-gate case FREAD|FWRITE:
5627c478bd9Sstevel@tonic-gate flags = 2; /* flush 'em both */
5637c478bd9Sstevel@tonic-gate break;
5647c478bd9Sstevel@tonic-gate
5657c478bd9Sstevel@tonic-gate case FREAD:
5667c478bd9Sstevel@tonic-gate flags = 0; /* flush read */
5677c478bd9Sstevel@tonic-gate break;
5687c478bd9Sstevel@tonic-gate
5697c478bd9Sstevel@tonic-gate case FWRITE:
5707c478bd9Sstevel@tonic-gate flags = 1; /* flush write */
5717c478bd9Sstevel@tonic-gate break;
5727c478bd9Sstevel@tonic-gate }
5737c478bd9Sstevel@tonic-gate iocp->ioc_cmd = TCFLSH; /* turn it into a TCFLSH */
5747c478bd9Sstevel@tonic-gate *(int *)mp->b_cont->b_rptr = flags; /* fiddle the arg */
5757c478bd9Sstevel@tonic-gate break;
5767c478bd9Sstevel@tonic-gate }
5777c478bd9Sstevel@tonic-gate
5787c478bd9Sstevel@tonic-gate /*
5797c478bd9Sstevel@tonic-gate * Turn into a TCXONC.
5807c478bd9Sstevel@tonic-gate */
5817c478bd9Sstevel@tonic-gate case TIOCSTOP: {
5827c478bd9Sstevel@tonic-gate mblk_t *datap;
5837c478bd9Sstevel@tonic-gate
5847c478bd9Sstevel@tonic-gate if ((datap = allocb(sizeof (int), BPRI_HI)) == NULL)
5857c478bd9Sstevel@tonic-gate goto allocfailure;
5867c478bd9Sstevel@tonic-gate *(int *)datap->b_wptr = 0; /* stop */
5877c478bd9Sstevel@tonic-gate datap->b_wptr += sizeof (int);
5887c478bd9Sstevel@tonic-gate iocp->ioc_cmd = TCXONC; /* turn it into a XONC */
5897c478bd9Sstevel@tonic-gate iocp->ioc_count = sizeof (int);
5907c478bd9Sstevel@tonic-gate if (mp->b_cont != NULL)
5917c478bd9Sstevel@tonic-gate freemsg(mp->b_cont);
5927c478bd9Sstevel@tonic-gate mp->b_cont = datap; /* attach the data */
5937c478bd9Sstevel@tonic-gate break;
5947c478bd9Sstevel@tonic-gate }
5957c478bd9Sstevel@tonic-gate
5967c478bd9Sstevel@tonic-gate case TIOCSTART: {
5977c478bd9Sstevel@tonic-gate mblk_t *datap;
5987c478bd9Sstevel@tonic-gate
5997c478bd9Sstevel@tonic-gate if ((datap = allocb(sizeof (int), BPRI_HI)) == NULL)
6007c478bd9Sstevel@tonic-gate goto allocfailure;
6017c478bd9Sstevel@tonic-gate *(int *)datap->b_wptr = 1; /* start */
6027c478bd9Sstevel@tonic-gate datap->b_wptr += sizeof (int);
6037c478bd9Sstevel@tonic-gate iocp->ioc_cmd = TCXONC; /* turn it into a XONC */
6047c478bd9Sstevel@tonic-gate iocp->ioc_count = sizeof (int);
6057c478bd9Sstevel@tonic-gate if (mp->b_cont != NULL)
6067c478bd9Sstevel@tonic-gate freemsg(mp->b_cont);
6077c478bd9Sstevel@tonic-gate mp->b_cont = datap; /* attach the data */
6087c478bd9Sstevel@tonic-gate break;
6097c478bd9Sstevel@tonic-gate }
6107c478bd9Sstevel@tonic-gate case TIOCSETD:
6117c478bd9Sstevel@tonic-gate case TIOCGETD:
6127c478bd9Sstevel@tonic-gate case DIOCSETP:
6137c478bd9Sstevel@tonic-gate case DIOCGETP:
6147c478bd9Sstevel@tonic-gate case LDOPEN:
6157c478bd9Sstevel@tonic-gate case LDCLOSE:
6167c478bd9Sstevel@tonic-gate case LDCHG:
6177c478bd9Sstevel@tonic-gate case LDSETT:
6187c478bd9Sstevel@tonic-gate case LDGETT:
6197c478bd9Sstevel@tonic-gate /*
6207c478bd9Sstevel@tonic-gate * All of these ioctls are just ACK'd, except for
6217c478bd9Sstevel@tonic-gate * TIOCSETD, which must be for line discipline zero.
6227c478bd9Sstevel@tonic-gate */
6237c478bd9Sstevel@tonic-gate mp->b_datap->db_type = M_IOCACK;
6247c478bd9Sstevel@tonic-gate if (iocp->ioc_cmd == TIOCSETD) {
6257c478bd9Sstevel@tonic-gate iocp->ioc_error = miocpullup(mp, sizeof (uchar_t));
6267c478bd9Sstevel@tonic-gate if (iocp->ioc_error == 0 && (*mp->b_cont->b_rptr != 0))
6277c478bd9Sstevel@tonic-gate mp->b_datap->db_type = M_IOCNAK;
6287c478bd9Sstevel@tonic-gate }
6297c478bd9Sstevel@tonic-gate
6307c478bd9Sstevel@tonic-gate iocp->ioc_error = 0;
6317c478bd9Sstevel@tonic-gate iocp->ioc_count = 0;
6327c478bd9Sstevel@tonic-gate iocp->ioc_rval = 0;
6337c478bd9Sstevel@tonic-gate qreply(q, mp);
6347c478bd9Sstevel@tonic-gate return;
6357c478bd9Sstevel@tonic-gate case IOCTYPE:
6367c478bd9Sstevel@tonic-gate mp->b_datap->db_type = M_IOCACK;
6377c478bd9Sstevel@tonic-gate iocp->ioc_error = 0;
6387c478bd9Sstevel@tonic-gate iocp->ioc_count = 0;
6397c478bd9Sstevel@tonic-gate iocp->ioc_rval = TIOC;
6407c478bd9Sstevel@tonic-gate qreply(q, mp);
6417c478bd9Sstevel@tonic-gate return;
6427c478bd9Sstevel@tonic-gate case TIOCEXCL:
6437c478bd9Sstevel@tonic-gate /* check for binary value of XCLUDE flag ???? */
6447c478bd9Sstevel@tonic-gate tp->t_new_lflags |= XCLUDE;
6457c478bd9Sstevel@tonic-gate mp->b_datap->db_type = M_IOCACK;
6467c478bd9Sstevel@tonic-gate iocp->ioc_error = 0;
6477c478bd9Sstevel@tonic-gate iocp->ioc_count = 0;
6487c478bd9Sstevel@tonic-gate iocp->ioc_rval = 0;
6497c478bd9Sstevel@tonic-gate qreply(q, mp);
6507c478bd9Sstevel@tonic-gate return;
6517c478bd9Sstevel@tonic-gate case TIOCNXCL:
6527c478bd9Sstevel@tonic-gate tp->t_new_lflags &= ~XCLUDE;
6537c478bd9Sstevel@tonic-gate mp->b_datap->db_type = M_IOCACK;
6547c478bd9Sstevel@tonic-gate iocp->ioc_error = 0;
6557c478bd9Sstevel@tonic-gate iocp->ioc_count = 0;
6567c478bd9Sstevel@tonic-gate iocp->ioc_rval = 0;
6577c478bd9Sstevel@tonic-gate qreply(q, mp);
6587c478bd9Sstevel@tonic-gate return;
6597c478bd9Sstevel@tonic-gate }
6607c478bd9Sstevel@tonic-gate
6617c478bd9Sstevel@tonic-gate /*
6627c478bd9Sstevel@tonic-gate * We don't reply to most calls, we just pass them down,
6637c478bd9Sstevel@tonic-gate * possibly after modifying the arguments.
6647c478bd9Sstevel@tonic-gate */
6657c478bd9Sstevel@tonic-gate putnext(q, mp);
6667c478bd9Sstevel@tonic-gate return;
6677c478bd9Sstevel@tonic-gate
6687c478bd9Sstevel@tonic-gate allocfailure:
6697c478bd9Sstevel@tonic-gate /*
6707c478bd9Sstevel@tonic-gate * We needed to allocate something to handle this "ioctl", but
6717c478bd9Sstevel@tonic-gate * couldn't; save this "ioctl" and arrange to get called back when
6727c478bd9Sstevel@tonic-gate * it's more likely that we can get what we need.
6737c478bd9Sstevel@tonic-gate * If there's already one being saved, throw it out, since it
6747c478bd9Sstevel@tonic-gate * must have timed out.
6757c478bd9Sstevel@tonic-gate */
6767c478bd9Sstevel@tonic-gate if (tp->t_iocpending != NULL)
6777c478bd9Sstevel@tonic-gate freemsg(tp->t_iocpending);
6787c478bd9Sstevel@tonic-gate tp->t_iocpending = mp; /* hold this ioctl */
6797c478bd9Sstevel@tonic-gate if (tp->t_bufcallid != 0)
6807c478bd9Sstevel@tonic-gate qunbufcall(q, tp->t_bufcallid);
6817c478bd9Sstevel@tonic-gate
6827c478bd9Sstevel@tonic-gate tp->t_bufcallid = qbufcall(q, sizeof (struct iocblk), BPRI_HI,
6837c478bd9Sstevel@tonic-gate ttcompat_reioctl, q);
6847c478bd9Sstevel@tonic-gate }
6857c478bd9Sstevel@tonic-gate
6867c478bd9Sstevel@tonic-gate /*
6877c478bd9Sstevel@tonic-gate * Called when an M_IOCACK message is seen on the read queue; if this
6887c478bd9Sstevel@tonic-gate * is the response we were waiting for, we either:
6897c478bd9Sstevel@tonic-gate * modify the data going up (if the "ioctl" read data); since in all
6907c478bd9Sstevel@tonic-gate * cases, the old-style returned information is smaller than or the same
6917c478bd9Sstevel@tonic-gate * size as the new-style returned information, we just overwrite the old
6927c478bd9Sstevel@tonic-gate * stuff with the new stuff (beware of changing structure sizes, in case
6937c478bd9Sstevel@tonic-gate * you invalidate this)
6947c478bd9Sstevel@tonic-gate * or
6957c478bd9Sstevel@tonic-gate * take this data, modify it appropriately, and send it back down (if
6967c478bd9Sstevel@tonic-gate * the "ioctl" wrote data).
6977c478bd9Sstevel@tonic-gate * In either case, we cancel the "wait"; the final response to a "write"
6987c478bd9Sstevel@tonic-gate * ioctl goes back up to the user.
6997c478bd9Sstevel@tonic-gate * If this wasn't the response we were waiting for, just pass it up.
7007c478bd9Sstevel@tonic-gate */
7017c478bd9Sstevel@tonic-gate static void
ttcompat_ioctl_ack(queue_t * q,mblk_t * mp)7027c478bd9Sstevel@tonic-gate ttcompat_ioctl_ack(queue_t *q, mblk_t *mp)
7037c478bd9Sstevel@tonic-gate {
7047c478bd9Sstevel@tonic-gate ttcompat_state_t *tp;
7057c478bd9Sstevel@tonic-gate struct iocblk *iocp;
7067c478bd9Sstevel@tonic-gate mblk_t *datap;
7077c478bd9Sstevel@tonic-gate
7087c478bd9Sstevel@tonic-gate tp = (ttcompat_state_t *)q->q_ptr;
7097c478bd9Sstevel@tonic-gate iocp = (struct iocblk *)mp->b_rptr;
7107c478bd9Sstevel@tonic-gate
7117c478bd9Sstevel@tonic-gate if (!(tp->t_state&TS_IOCWAIT) || iocp->ioc_id != tp->t_iocid) {
7127c478bd9Sstevel@tonic-gate /*
7137c478bd9Sstevel@tonic-gate * This isn't the reply we're looking for. Move along.
7147c478bd9Sstevel@tonic-gate */
7157c478bd9Sstevel@tonic-gate putnext(q, mp);
7167c478bd9Sstevel@tonic-gate return;
7177c478bd9Sstevel@tonic-gate }
7187c478bd9Sstevel@tonic-gate
7197c478bd9Sstevel@tonic-gate datap = mp->b_cont; /* mblk containing data going up */
7207c478bd9Sstevel@tonic-gate
7217c478bd9Sstevel@tonic-gate switch (tp->t_ioccmd) {
7227c478bd9Sstevel@tonic-gate
7237c478bd9Sstevel@tonic-gate case TIOCGETP: {
7247c478bd9Sstevel@tonic-gate struct sgttyb *cb;
7257c478bd9Sstevel@tonic-gate
7267c478bd9Sstevel@tonic-gate to_compat((struct termios *)datap->b_rptr, &tp->t_curstate);
7277c478bd9Sstevel@tonic-gate datap->b_rptr = datap->b_wptr = datap->b_datap->db_base;
7287c478bd9Sstevel@tonic-gate /* recycle the reply's buffer */
7297c478bd9Sstevel@tonic-gate cb = (struct sgttyb *)datap->b_wptr;
7307c478bd9Sstevel@tonic-gate /*
7317c478bd9Sstevel@tonic-gate * This is used for TIOCGETP handling of sg_ispeed and
7327c478bd9Sstevel@tonic-gate * sg_ospeed. If the current speed is over 38400 (the
7337c478bd9Sstevel@tonic-gate * sgttyb limit), then we report 38400. Note that
7347c478bd9Sstevel@tonic-gate * when "compatibility with old releases" is enabled
7357c478bd9Sstevel@tonic-gate * (sgttyb_handling == 0), then t_[io]speed will have
7367c478bd9Sstevel@tonic-gate * garbled nonsense, as in prior releases. (See
7377c478bd9Sstevel@tonic-gate * to_compat() below).
7387c478bd9Sstevel@tonic-gate */
7397c478bd9Sstevel@tonic-gate cb->sg_ispeed = tp->t_curstate.t_ispeed > B38400 ? B38400 :
7407c478bd9Sstevel@tonic-gate tp->t_curstate.t_ispeed;
7417c478bd9Sstevel@tonic-gate cb->sg_ospeed = tp->t_curstate.t_ospeed > B38400 ? B38400 :
7427c478bd9Sstevel@tonic-gate tp->t_curstate.t_ospeed;
7437c478bd9Sstevel@tonic-gate cb->sg_erase = tp->t_curstate.t_erase;
7447c478bd9Sstevel@tonic-gate cb->sg_kill = tp->t_curstate.t_kill;
7457c478bd9Sstevel@tonic-gate cb->sg_flags = tp->t_curstate.t_flags;
7467c478bd9Sstevel@tonic-gate datap->b_wptr += sizeof (struct sgttyb);
7477c478bd9Sstevel@tonic-gate iocp->ioc_count = sizeof (struct sgttyb);
7487c478bd9Sstevel@tonic-gate
7497c478bd9Sstevel@tonic-gate /* you are lucky - stream head knows how to copy you out */
7507c478bd9Sstevel@tonic-gate
7517c478bd9Sstevel@tonic-gate tp->t_state &= ~TS_IOCWAIT; /* we got what we wanted */
7527c478bd9Sstevel@tonic-gate iocp->ioc_rval = 0;
7537c478bd9Sstevel@tonic-gate iocp->ioc_cmd = tp->t_ioccmd;
7547c478bd9Sstevel@tonic-gate putnext(q, mp);
7557c478bd9Sstevel@tonic-gate return;
7567c478bd9Sstevel@tonic-gate }
7577c478bd9Sstevel@tonic-gate
7587c478bd9Sstevel@tonic-gate case TIOCGETC:
7597c478bd9Sstevel@tonic-gate to_compat((struct termios *)datap->b_rptr, &tp->t_curstate);
7607c478bd9Sstevel@tonic-gate datap->b_rptr = datap->b_wptr = datap->b_datap->db_base;
7617c478bd9Sstevel@tonic-gate /* recycle the reply's buffer */
7627c478bd9Sstevel@tonic-gate bcopy(&tp->t_curstate.t_intrc, datap->b_wptr,
7637c478bd9Sstevel@tonic-gate sizeof (struct tchars));
7647c478bd9Sstevel@tonic-gate datap->b_wptr += sizeof (struct tchars);
7657c478bd9Sstevel@tonic-gate break;
7667c478bd9Sstevel@tonic-gate
7677c478bd9Sstevel@tonic-gate case TIOCGLTC:
7687c478bd9Sstevel@tonic-gate to_compat((struct termios *)datap->b_rptr, &tp->t_curstate);
7697c478bd9Sstevel@tonic-gate datap->b_rptr = datap->b_wptr = datap->b_datap->db_base;
7707c478bd9Sstevel@tonic-gate /* recycle the reply's buffer */
7717c478bd9Sstevel@tonic-gate bcopy(&tp->t_curstate.t_suspc, datap->b_wptr,
7727c478bd9Sstevel@tonic-gate sizeof (struct ltchars));
7737c478bd9Sstevel@tonic-gate datap->b_wptr += sizeof (struct ltchars);
7747c478bd9Sstevel@tonic-gate break;
7757c478bd9Sstevel@tonic-gate
7767c478bd9Sstevel@tonic-gate case TIOCLGET:
7777c478bd9Sstevel@tonic-gate to_compat((struct termios *)datap->b_rptr, &tp->t_curstate);
7787c478bd9Sstevel@tonic-gate datap->b_rptr = datap->b_wptr = datap->b_datap->db_base;
7797c478bd9Sstevel@tonic-gate /* recycle the reply's buffer */
7807c478bd9Sstevel@tonic-gate *(int *)datap->b_wptr =
7817c478bd9Sstevel@tonic-gate ((unsigned)tp->t_curstate.t_flags) >> 16;
7827c478bd9Sstevel@tonic-gate datap->b_wptr += sizeof (int);
7837c478bd9Sstevel@tonic-gate break;
7847c478bd9Sstevel@tonic-gate
7857c478bd9Sstevel@tonic-gate case TIOCSETP:
7867c478bd9Sstevel@tonic-gate case TIOCSETN:
7877c478bd9Sstevel@tonic-gate /*
7887c478bd9Sstevel@tonic-gate * Get the current state from the GETS data, and
7897c478bd9Sstevel@tonic-gate * update it.
7907c478bd9Sstevel@tonic-gate */
7917c478bd9Sstevel@tonic-gate to_compat((struct termios *)datap->b_rptr, &tp->t_curstate);
7927c478bd9Sstevel@tonic-gate tp->t_curstate.t_erase = tp->t_new_sgttyb.sg_erase;
7937c478bd9Sstevel@tonic-gate tp->t_curstate.t_kill = tp->t_new_sgttyb.sg_kill;
7947c478bd9Sstevel@tonic-gate /*
7957c478bd9Sstevel@tonic-gate * For new-style handling, we ignore requests to set
7967c478bd9Sstevel@tonic-gate * B38400 when the current speed is over B38400. This
7977c478bd9Sstevel@tonic-gate * means that we change the speed as requested if:
7987c478bd9Sstevel@tonic-gate * old style (sgttyb_handling == 0) is requested
7997c478bd9Sstevel@tonic-gate * the requested new speed isn't B38400
8007c478bd9Sstevel@tonic-gate * the current speed is at or below B38400
8017c478bd9Sstevel@tonic-gate * Note that when old style is requested, both speeds
8027c478bd9Sstevel@tonic-gate * in t_curstate are set to <= B38400 by to_compat, so
8037c478bd9Sstevel@tonic-gate * the first test isn't needed here.
8047c478bd9Sstevel@tonic-gate * Also note that we silently allow the user to set
8057c478bd9Sstevel@tonic-gate * speeds above B38400 through this interface,
8067c478bd9Sstevel@tonic-gate * regardless of the style setting. This allows
8077c478bd9Sstevel@tonic-gate * greater compatibility with current BSD releases.
8087c478bd9Sstevel@tonic-gate */
8097c478bd9Sstevel@tonic-gate if (tp->t_new_sgttyb.sg_ispeed != B38400 ||
8107c478bd9Sstevel@tonic-gate tp->t_curstate.t_ispeed <= B38400)
8117c478bd9Sstevel@tonic-gate tp->t_curstate.t_ispeed = tp->t_new_sgttyb.sg_ispeed;
8127c478bd9Sstevel@tonic-gate if (tp->t_new_sgttyb.sg_ospeed != B38400 ||
8137c478bd9Sstevel@tonic-gate tp->t_curstate.t_ospeed <= B38400)
8147c478bd9Sstevel@tonic-gate tp->t_curstate.t_ospeed = tp->t_new_sgttyb.sg_ospeed;
8157c478bd9Sstevel@tonic-gate tp->t_curstate.t_flags =
8167c478bd9Sstevel@tonic-gate (tp->t_curstate.t_flags & 0xffff0000) |
8177c478bd9Sstevel@tonic-gate (tp->t_new_sgttyb.sg_flags & 0xffff);
8187c478bd9Sstevel@tonic-gate
8197c478bd9Sstevel@tonic-gate /*
8207c478bd9Sstevel@tonic-gate * Replace the data that came up with the updated data.
8217c478bd9Sstevel@tonic-gate */
8227c478bd9Sstevel@tonic-gate from_compat(&tp->t_curstate, (struct termios *)datap->b_rptr);
8237c478bd9Sstevel@tonic-gate
8247c478bd9Sstevel@tonic-gate /*
8257c478bd9Sstevel@tonic-gate * Send it back down as a TCSETS or TCSETSF.
8267c478bd9Sstevel@tonic-gate */
8277c478bd9Sstevel@tonic-gate iocp->ioc_cmd = (tp->t_ioccmd == TIOCSETP) ? TCSETSF : TCSETS;
8287c478bd9Sstevel@tonic-gate goto senddown;
8297c478bd9Sstevel@tonic-gate
8307c478bd9Sstevel@tonic-gate case TIOCSETC:
8317c478bd9Sstevel@tonic-gate /*
8327c478bd9Sstevel@tonic-gate * Get the current state from the GETS data, and
8337c478bd9Sstevel@tonic-gate * update it.
8347c478bd9Sstevel@tonic-gate */
8357c478bd9Sstevel@tonic-gate to_compat((struct termios *)datap->b_rptr, &tp->t_curstate);
8367c478bd9Sstevel@tonic-gate bcopy(&tp->t_new_tchars,
8377c478bd9Sstevel@tonic-gate &tp->t_curstate.t_intrc, sizeof (struct tchars));
8387c478bd9Sstevel@tonic-gate
8397c478bd9Sstevel@tonic-gate /*
8407c478bd9Sstevel@tonic-gate * Replace the data that came up with the updated data.
8417c478bd9Sstevel@tonic-gate */
8427c478bd9Sstevel@tonic-gate from_compat(&tp->t_curstate, (struct termios *)datap->b_rptr);
8437c478bd9Sstevel@tonic-gate
8447c478bd9Sstevel@tonic-gate /*
8457c478bd9Sstevel@tonic-gate * Send it back down as a TCSETS.
8467c478bd9Sstevel@tonic-gate */
8477c478bd9Sstevel@tonic-gate iocp->ioc_cmd = TCSETS;
8487c478bd9Sstevel@tonic-gate goto senddown;
8497c478bd9Sstevel@tonic-gate
8507c478bd9Sstevel@tonic-gate case TIOCSLTC:
8517c478bd9Sstevel@tonic-gate /*
8527c478bd9Sstevel@tonic-gate * Get the current state from the GETS data, and
8537c478bd9Sstevel@tonic-gate * update it.
8547c478bd9Sstevel@tonic-gate */
8557c478bd9Sstevel@tonic-gate to_compat((struct termios *)datap->b_rptr, &tp->t_curstate);
8567c478bd9Sstevel@tonic-gate bcopy(&tp->t_new_ltchars,
8577c478bd9Sstevel@tonic-gate &tp->t_curstate.t_suspc, sizeof (struct ltchars));
8587c478bd9Sstevel@tonic-gate
8597c478bd9Sstevel@tonic-gate /*
8607c478bd9Sstevel@tonic-gate * Replace the data that came up with the updated data.
8617c478bd9Sstevel@tonic-gate */
8627c478bd9Sstevel@tonic-gate from_compat(&tp->t_curstate, (struct termios *)datap->b_rptr);
8637c478bd9Sstevel@tonic-gate
8647c478bd9Sstevel@tonic-gate /*
8657c478bd9Sstevel@tonic-gate * Send it back down as a TCSETS.
8667c478bd9Sstevel@tonic-gate */
8677c478bd9Sstevel@tonic-gate iocp->ioc_cmd = TCSETS;
8687c478bd9Sstevel@tonic-gate goto senddown;
8697c478bd9Sstevel@tonic-gate
8707c478bd9Sstevel@tonic-gate case TIOCLBIS:
8717c478bd9Sstevel@tonic-gate /*
8727c478bd9Sstevel@tonic-gate * Get the current state from the GETS data, and
8737c478bd9Sstevel@tonic-gate * update it.
8747c478bd9Sstevel@tonic-gate */
8757c478bd9Sstevel@tonic-gate to_compat((struct termios *)datap->b_rptr, &tp->t_curstate);
8767c478bd9Sstevel@tonic-gate tp->t_curstate.t_flags |= (tp->t_new_lflags << 16);
8777c478bd9Sstevel@tonic-gate
8787c478bd9Sstevel@tonic-gate /*
8797c478bd9Sstevel@tonic-gate * Replace the data that came up with the updated data.
8807c478bd9Sstevel@tonic-gate */
8817c478bd9Sstevel@tonic-gate from_compat(&tp->t_curstate, (struct termios *)datap->b_rptr);
8827c478bd9Sstevel@tonic-gate
8837c478bd9Sstevel@tonic-gate /*
8847c478bd9Sstevel@tonic-gate * Send it back down as a TCSETS.
8857c478bd9Sstevel@tonic-gate */
8867c478bd9Sstevel@tonic-gate iocp->ioc_cmd = TCSETS;
8877c478bd9Sstevel@tonic-gate goto senddown;
8887c478bd9Sstevel@tonic-gate
8897c478bd9Sstevel@tonic-gate case TIOCLBIC:
8907c478bd9Sstevel@tonic-gate /*
8917c478bd9Sstevel@tonic-gate * Get the current state from the GETS data, and
8927c478bd9Sstevel@tonic-gate * update it.
8937c478bd9Sstevel@tonic-gate */
8947c478bd9Sstevel@tonic-gate to_compat((struct termios *)datap->b_rptr, &tp->t_curstate);
8957c478bd9Sstevel@tonic-gate tp->t_curstate.t_flags &= ~(tp->t_new_lflags << 16);
8967c478bd9Sstevel@tonic-gate
8977c478bd9Sstevel@tonic-gate /*
8987c478bd9Sstevel@tonic-gate * Replace the data that came up with the updated data.
8997c478bd9Sstevel@tonic-gate */
9007c478bd9Sstevel@tonic-gate from_compat(&tp->t_curstate, (struct termios *)datap->b_rptr);
9017c478bd9Sstevel@tonic-gate
9027c478bd9Sstevel@tonic-gate /*
9037c478bd9Sstevel@tonic-gate * Send it back down as a TCSETS.
9047c478bd9Sstevel@tonic-gate */
9057c478bd9Sstevel@tonic-gate iocp->ioc_cmd = TCSETS;
9067c478bd9Sstevel@tonic-gate goto senddown;
9077c478bd9Sstevel@tonic-gate
9087c478bd9Sstevel@tonic-gate case TIOCLSET:
9097c478bd9Sstevel@tonic-gate /*
9107c478bd9Sstevel@tonic-gate * Get the current state from the GETS data, and
9117c478bd9Sstevel@tonic-gate * update it.
9127c478bd9Sstevel@tonic-gate */
9137c478bd9Sstevel@tonic-gate to_compat((struct termios *)datap->b_rptr, &tp->t_curstate);
9147c478bd9Sstevel@tonic-gate tp->t_curstate.t_flags &= 0xffff;
9157c478bd9Sstevel@tonic-gate tp->t_curstate.t_flags |= (tp->t_new_lflags << 16);
9167c478bd9Sstevel@tonic-gate
9177c478bd9Sstevel@tonic-gate /*
9187c478bd9Sstevel@tonic-gate * Replace the data that came up with the updated data.
9197c478bd9Sstevel@tonic-gate */
9207c478bd9Sstevel@tonic-gate from_compat(&tp->t_curstate, (struct termios *)datap->b_rptr);
9217c478bd9Sstevel@tonic-gate
9227c478bd9Sstevel@tonic-gate /*
9237c478bd9Sstevel@tonic-gate * Send it back down as a TCSETS.
9247c478bd9Sstevel@tonic-gate */
9257c478bd9Sstevel@tonic-gate iocp->ioc_cmd = TCSETS;
9267c478bd9Sstevel@tonic-gate goto senddown;
9277c478bd9Sstevel@tonic-gate
9287c478bd9Sstevel@tonic-gate case TIOCHPCL:
9297c478bd9Sstevel@tonic-gate /*
9307c478bd9Sstevel@tonic-gate * Replace the data that came up with the updated data.
9317c478bd9Sstevel@tonic-gate */
9327c478bd9Sstevel@tonic-gate ((struct termios *)datap->b_rptr)->c_cflag |= HUPCL;
9337c478bd9Sstevel@tonic-gate
9347c478bd9Sstevel@tonic-gate /*
9357c478bd9Sstevel@tonic-gate * Send it back down as a TCSETS.
9367c478bd9Sstevel@tonic-gate */
9377c478bd9Sstevel@tonic-gate iocp->ioc_cmd = TCSETS;
9387c478bd9Sstevel@tonic-gate goto senddown;
9397c478bd9Sstevel@tonic-gate
9409d5056eaSjv227347 case TCSETSF:
9419d5056eaSjv227347 /*
9429d5056eaSjv227347 * We're acknowledging the terminal reset ioctl that we sent
9439d5056eaSjv227347 * when the module was opened.
9449d5056eaSjv227347 */
9459d5056eaSjv227347 tp->t_state &= ~(TS_IOCWAIT | TS_TIOCNAK);
9469d5056eaSjv227347 freemsg(mp);
9479d5056eaSjv227347 return;
9489d5056eaSjv227347
9497c478bd9Sstevel@tonic-gate default:
9507c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "ttcompat: Unexpected ioctl acknowledgment\n");
9517c478bd9Sstevel@tonic-gate }
9527c478bd9Sstevel@tonic-gate
9537c478bd9Sstevel@tonic-gate /*
9547c478bd9Sstevel@tonic-gate * All the calls that return something return 0.
9557c478bd9Sstevel@tonic-gate */
9567c478bd9Sstevel@tonic-gate tp->t_state &= ~TS_IOCWAIT; /* we got what we wanted */
9577c478bd9Sstevel@tonic-gate iocp->ioc_rval = 0;
9587c478bd9Sstevel@tonic-gate
9597c478bd9Sstevel@tonic-gate /* copy out the data - ioctl transparency */
9607c478bd9Sstevel@tonic-gate iocp->ioc_cmd = tp->t_ioccmd;
9617c478bd9Sstevel@tonic-gate ttcopyout(q, mp);
9627c478bd9Sstevel@tonic-gate return;
9637c478bd9Sstevel@tonic-gate
9647c478bd9Sstevel@tonic-gate senddown:
9657c478bd9Sstevel@tonic-gate /*
9667c478bd9Sstevel@tonic-gate * Send a "get state" reply back down, with suitably-modified
9677c478bd9Sstevel@tonic-gate * state, as a "set state" "ioctl".
9687c478bd9Sstevel@tonic-gate */
9697c478bd9Sstevel@tonic-gate tp->t_state &= ~TS_IOCWAIT;
9707c478bd9Sstevel@tonic-gate mp->b_datap->db_type = M_IOCTL;
9717c478bd9Sstevel@tonic-gate mp->b_wptr = mp->b_rptr + sizeof (struct iocblk);
9727c478bd9Sstevel@tonic-gate putnext(WR(q), mp);
9737c478bd9Sstevel@tonic-gate }
9747c478bd9Sstevel@tonic-gate /* Called from ttcompatrput M_IOCACK processing. */
9757c478bd9Sstevel@tonic-gate /* Copies out the data using M_COPYOUT messages */
9767c478bd9Sstevel@tonic-gate
9777c478bd9Sstevel@tonic-gate static void
ttcopyout(queue_t * q,mblk_t * mp)9787c478bd9Sstevel@tonic-gate ttcopyout(queue_t *q, mblk_t *mp)
9797c478bd9Sstevel@tonic-gate {
9807c478bd9Sstevel@tonic-gate struct copyreq *cqp;
9817c478bd9Sstevel@tonic-gate ttcompat_state_t *tp;
9827c478bd9Sstevel@tonic-gate
9837c478bd9Sstevel@tonic-gate tp = (ttcompat_state_t *)q->q_ptr;
9847c478bd9Sstevel@tonic-gate
9857c478bd9Sstevel@tonic-gate mp->b_datap->db_type = M_COPYOUT;
9867c478bd9Sstevel@tonic-gate cqp = (struct copyreq *)mp->b_rptr;
9877c478bd9Sstevel@tonic-gate cqp->cq_addr = (caddr_t)tp->t_arg; /* retrieve the 3rd argument */
9887c478bd9Sstevel@tonic-gate tp->t_arg = 0; /* clear it since we don't need it anymore */
9897c478bd9Sstevel@tonic-gate switch (tp->t_ioccmd) {
9907c478bd9Sstevel@tonic-gate case TIOCGLTC:
9917c478bd9Sstevel@tonic-gate cqp->cq_size = sizeof (struct ltchars);
9927c478bd9Sstevel@tonic-gate break;
9937c478bd9Sstevel@tonic-gate case TIOCGETC:
9947c478bd9Sstevel@tonic-gate cqp->cq_size = sizeof (struct tchars);
9957c478bd9Sstevel@tonic-gate break;
9967c478bd9Sstevel@tonic-gate case TIOCLGET:
9977c478bd9Sstevel@tonic-gate cqp->cq_size = sizeof (int);
9987c478bd9Sstevel@tonic-gate break;
9997c478bd9Sstevel@tonic-gate default:
10007c478bd9Sstevel@tonic-gate cmn_err(CE_WARN,
10017c478bd9Sstevel@tonic-gate "ttcompat: Unknown ioctl to copyout\n");
10027c478bd9Sstevel@tonic-gate break;
10037c478bd9Sstevel@tonic-gate }
10047c478bd9Sstevel@tonic-gate cqp->cq_flag = 0;
10057c478bd9Sstevel@tonic-gate cqp->cq_private = NULL;
10067c478bd9Sstevel@tonic-gate tp->t_state |= TS_W_OUT;
10077c478bd9Sstevel@tonic-gate putnext(q, mp);
10087c478bd9Sstevel@tonic-gate }
10097c478bd9Sstevel@tonic-gate
10107c478bd9Sstevel@tonic-gate
10117c478bd9Sstevel@tonic-gate /*
10127c478bd9Sstevel@tonic-gate * Called when an M_IOCNAK message is seen on the read queue; if this is
10137c478bd9Sstevel@tonic-gate * the response we were waiting for, cancel the wait. Pass the reply up;
10147c478bd9Sstevel@tonic-gate * if we were waiting for this response, we can't complete the "ioctl" and
10157c478bd9Sstevel@tonic-gate * the NAK will tell that to the guy above us.
10167c478bd9Sstevel@tonic-gate * If this wasn't the response we were waiting for, just pass it up.
10177c478bd9Sstevel@tonic-gate */
10187c478bd9Sstevel@tonic-gate static void
ttcompat_ioctl_nak(queue_t * q,mblk_t * mp)10197c478bd9Sstevel@tonic-gate ttcompat_ioctl_nak(queue_t *q, mblk_t *mp)
10207c478bd9Sstevel@tonic-gate {
10217c478bd9Sstevel@tonic-gate ttcompat_state_t *tp;
10227c478bd9Sstevel@tonic-gate struct iocblk *iocp;
10237c478bd9Sstevel@tonic-gate
10247c478bd9Sstevel@tonic-gate iocp = (struct iocblk *)mp->b_rptr;
10257c478bd9Sstevel@tonic-gate tp = (ttcompat_state_t *)q->q_ptr;
10267c478bd9Sstevel@tonic-gate
10277c478bd9Sstevel@tonic-gate if (tp->t_state&TS_IOCWAIT && iocp->ioc_id == tp->t_iocid) {
10287c478bd9Sstevel@tonic-gate tp->t_state &= ~TS_IOCWAIT; /* this call isn't going through */
10297c478bd9Sstevel@tonic-gate tp->t_arg = 0; /* we may have stashed the 3rd argument */
10307c478bd9Sstevel@tonic-gate }
10317c478bd9Sstevel@tonic-gate putnext(q, mp);
10327c478bd9Sstevel@tonic-gate }
10337c478bd9Sstevel@tonic-gate
10347c478bd9Sstevel@tonic-gate #define FROM_COMPAT_CHAR(to, from) { if ((to = from) == 0377) to = 0; }
10357c478bd9Sstevel@tonic-gate
10367c478bd9Sstevel@tonic-gate static void
from_compat(compat_state_t * csp,struct termios * termiosp)10377c478bd9Sstevel@tonic-gate from_compat(compat_state_t *csp, struct termios *termiosp)
10387c478bd9Sstevel@tonic-gate {
10397c478bd9Sstevel@tonic-gate termiosp->c_iflag = 0;
10407c478bd9Sstevel@tonic-gate termiosp->c_oflag &= (ONLRET|ONOCR);
10417c478bd9Sstevel@tonic-gate
10427c478bd9Sstevel@tonic-gate termiosp->c_cflag = (termiosp->c_cflag &
10437c478bd9Sstevel@tonic-gate (CRTSCTS|CRTSXOFF|PAREXT|LOBLK|HUPCL)) | CREAD;
10447c478bd9Sstevel@tonic-gate
10457c478bd9Sstevel@tonic-gate if (csp->t_ospeed > CBAUD) {
10467c478bd9Sstevel@tonic-gate termiosp->c_cflag |= ((csp->t_ospeed - CBAUD - 1) & CBAUD) |
10477c478bd9Sstevel@tonic-gate CBAUDEXT;
10487c478bd9Sstevel@tonic-gate } else {
10497c478bd9Sstevel@tonic-gate termiosp->c_cflag |= csp->t_ospeed & CBAUD;
10507c478bd9Sstevel@tonic-gate }
10517c478bd9Sstevel@tonic-gate
10527c478bd9Sstevel@tonic-gate if (csp->t_ospeed != csp->t_ispeed) {
10537c478bd9Sstevel@tonic-gate if (csp->t_ispeed > (CIBAUD >> IBSHIFT)) {
10547c478bd9Sstevel@tonic-gate termiosp->c_cflag |= CIBAUDEXT |
10557c478bd9Sstevel@tonic-gate (((csp->t_ispeed - (CIBAUD >> IBSHIFT) - 1) <<
10567c478bd9Sstevel@tonic-gate IBSHIFT) & CIBAUD);
10577c478bd9Sstevel@tonic-gate } else {
10587c478bd9Sstevel@tonic-gate termiosp->c_cflag |= (csp->t_ispeed << IBSHIFT) &
10597c478bd9Sstevel@tonic-gate CIBAUD;
10607c478bd9Sstevel@tonic-gate }
10617c478bd9Sstevel@tonic-gate /* hang up if ispeed=0 */
10627c478bd9Sstevel@tonic-gate if (csp->t_ispeed == 0)
10637c478bd9Sstevel@tonic-gate termiosp->c_cflag &= ~CBAUD & ~CBAUDEXT;
10647c478bd9Sstevel@tonic-gate }
10657c478bd9Sstevel@tonic-gate if (csp->t_ispeed == B110 || csp->t_xflags & STOPB)
10667c478bd9Sstevel@tonic-gate termiosp->c_cflag |= CSTOPB;
10677c478bd9Sstevel@tonic-gate termiosp->c_lflag = ECHOK;
10687c478bd9Sstevel@tonic-gate FROM_COMPAT_CHAR(termiosp->c_cc[VERASE], csp->t_erase);
10697c478bd9Sstevel@tonic-gate FROM_COMPAT_CHAR(termiosp->c_cc[VKILL], csp->t_kill);
10707c478bd9Sstevel@tonic-gate FROM_COMPAT_CHAR(termiosp->c_cc[VINTR], csp->t_intrc);
10717c478bd9Sstevel@tonic-gate FROM_COMPAT_CHAR(termiosp->c_cc[VQUIT], csp->t_quitc);
10727c478bd9Sstevel@tonic-gate FROM_COMPAT_CHAR(termiosp->c_cc[VSTART], csp->t_startc);
10737c478bd9Sstevel@tonic-gate FROM_COMPAT_CHAR(termiosp->c_cc[VSTOP], csp->t_stopc);
10747c478bd9Sstevel@tonic-gate termiosp->c_cc[VEOL2] = 0;
10757c478bd9Sstevel@tonic-gate FROM_COMPAT_CHAR(termiosp->c_cc[VSUSP], csp->t_suspc);
10767c478bd9Sstevel@tonic-gate /* is this useful? */
10777c478bd9Sstevel@tonic-gate FROM_COMPAT_CHAR(termiosp->c_cc[VDSUSP], csp->t_dsuspc);
10787c478bd9Sstevel@tonic-gate FROM_COMPAT_CHAR(termiosp->c_cc[VREPRINT], csp->t_rprntc);
10797c478bd9Sstevel@tonic-gate FROM_COMPAT_CHAR(termiosp->c_cc[VDISCARD], csp->t_flushc);
10807c478bd9Sstevel@tonic-gate FROM_COMPAT_CHAR(termiosp->c_cc[VWERASE], csp->t_werasc);
10817c478bd9Sstevel@tonic-gate FROM_COMPAT_CHAR(termiosp->c_cc[VLNEXT], csp->t_lnextc);
108219d32b9aSRobert Mustacchi termiosp->c_cc[VSTATUS] = 0;
10837c478bd9Sstevel@tonic-gate if (csp->t_flags & O_TANDEM)
10847c478bd9Sstevel@tonic-gate termiosp->c_iflag |= IXOFF;
10857c478bd9Sstevel@tonic-gate if (csp->t_flags & O_LCASE) {
10867c478bd9Sstevel@tonic-gate termiosp->c_iflag |= IUCLC;
10877c478bd9Sstevel@tonic-gate termiosp->c_oflag |= OLCUC;
10887c478bd9Sstevel@tonic-gate termiosp->c_lflag |= XCASE;
10897c478bd9Sstevel@tonic-gate }
10907c478bd9Sstevel@tonic-gate if (csp->t_flags & O_ECHO)
10917c478bd9Sstevel@tonic-gate termiosp->c_lflag |= ECHO;
10927c478bd9Sstevel@tonic-gate if (csp->t_flags & O_CRMOD) {
10937c478bd9Sstevel@tonic-gate termiosp->c_iflag |= ICRNL;
10947c478bd9Sstevel@tonic-gate termiosp->c_oflag |= ONLCR;
10957c478bd9Sstevel@tonic-gate switch (csp->t_flags & O_CRDELAY) {
10967c478bd9Sstevel@tonic-gate
10977c478bd9Sstevel@tonic-gate case O_CR1:
10987c478bd9Sstevel@tonic-gate termiosp->c_oflag |= CR2;
10997c478bd9Sstevel@tonic-gate break;
11007c478bd9Sstevel@tonic-gate
11017c478bd9Sstevel@tonic-gate case O_CR2:
11027c478bd9Sstevel@tonic-gate termiosp->c_oflag |= CR3;
11037c478bd9Sstevel@tonic-gate break;
11047c478bd9Sstevel@tonic-gate }
11057c478bd9Sstevel@tonic-gate } else {
11067c478bd9Sstevel@tonic-gate if ((csp->t_flags & O_NLDELAY) == O_NL1)
11077c478bd9Sstevel@tonic-gate termiosp->c_oflag |= ONLRET|CR1; /* tty37 */
11087c478bd9Sstevel@tonic-gate }
11097c478bd9Sstevel@tonic-gate if ((csp->t_flags & O_NLDELAY) == O_NL2)
11107c478bd9Sstevel@tonic-gate termiosp->c_oflag |= NL1;
11117c478bd9Sstevel@tonic-gate /*
11127c478bd9Sstevel@tonic-gate * When going into RAW mode, the special characters controlled by the
11137c478bd9Sstevel@tonic-gate * POSIX IEXTEN bit no longer apply; when leaving, they do.
11147c478bd9Sstevel@tonic-gate */
11157c478bd9Sstevel@tonic-gate if (csp->t_flags & O_RAW) {
11167c478bd9Sstevel@tonic-gate termiosp->c_cflag |= CS8;
11177c478bd9Sstevel@tonic-gate termiosp->c_iflag &= ~(ICRNL|IUCLC);
11187c478bd9Sstevel@tonic-gate termiosp->c_lflag &= ~(XCASE|IEXTEN);
11197c478bd9Sstevel@tonic-gate } else {
11207c478bd9Sstevel@tonic-gate termiosp->c_iflag |= IMAXBEL|BRKINT|IGNPAR;
11217c478bd9Sstevel@tonic-gate if (termiosp->c_cc[VSTOP] != 0 && termiosp->c_cc[VSTART] != 0)
11227c478bd9Sstevel@tonic-gate termiosp->c_iflag |= IXON;
11237c478bd9Sstevel@tonic-gate if (csp->t_flags & O_LITOUT)
11247c478bd9Sstevel@tonic-gate termiosp->c_cflag |= CS8;
11257c478bd9Sstevel@tonic-gate else {
11267c478bd9Sstevel@tonic-gate if (csp->t_flags & O_PASS8)
11277c478bd9Sstevel@tonic-gate termiosp->c_cflag |= CS8;
11287c478bd9Sstevel@tonic-gate /* XXX - what about 8 bits plus parity? */
11297c478bd9Sstevel@tonic-gate else {
11307c478bd9Sstevel@tonic-gate switch (csp->t_flags & (O_EVENP|O_ODDP)) {
11317c478bd9Sstevel@tonic-gate
11327c478bd9Sstevel@tonic-gate case 0:
11337c478bd9Sstevel@tonic-gate termiosp->c_iflag |= ISTRIP;
11347c478bd9Sstevel@tonic-gate termiosp->c_cflag |= CS8;
11357c478bd9Sstevel@tonic-gate break;
11367c478bd9Sstevel@tonic-gate
11377c478bd9Sstevel@tonic-gate case O_EVENP:
11387c478bd9Sstevel@tonic-gate termiosp->c_iflag |= INPCK|ISTRIP;
11397c478bd9Sstevel@tonic-gate termiosp->c_cflag |= CS7|PARENB;
11407c478bd9Sstevel@tonic-gate break;
11417c478bd9Sstevel@tonic-gate
11427c478bd9Sstevel@tonic-gate case O_ODDP:
11437c478bd9Sstevel@tonic-gate termiosp->c_iflag |= INPCK|ISTRIP;
11447c478bd9Sstevel@tonic-gate termiosp->c_cflag |= CS7|PARENB|PARODD;
11457c478bd9Sstevel@tonic-gate break;
11467c478bd9Sstevel@tonic-gate
11477c478bd9Sstevel@tonic-gate case O_EVENP|O_ODDP:
11487c478bd9Sstevel@tonic-gate termiosp->c_iflag |= ISTRIP;
11497c478bd9Sstevel@tonic-gate termiosp->c_cflag |= CS7|PARENB;
11507c478bd9Sstevel@tonic-gate break;
11517c478bd9Sstevel@tonic-gate }
11527c478bd9Sstevel@tonic-gate }
11537c478bd9Sstevel@tonic-gate if (!(csp->t_xflags & NOPOST))
11547c478bd9Sstevel@tonic-gate termiosp->c_oflag |= OPOST;
11557c478bd9Sstevel@tonic-gate }
11567c478bd9Sstevel@tonic-gate termiosp->c_lflag |= IEXTEN;
11577c478bd9Sstevel@tonic-gate if (!(csp->t_xflags & NOISIG))
11587c478bd9Sstevel@tonic-gate termiosp->c_lflag |= ISIG;
11597c478bd9Sstevel@tonic-gate if (!(csp->t_flags & O_CBREAK))
11607c478bd9Sstevel@tonic-gate termiosp->c_lflag |= ICANON;
11617c478bd9Sstevel@tonic-gate if (csp->t_flags & O_CTLECH)
11627c478bd9Sstevel@tonic-gate termiosp->c_lflag |= ECHOCTL;
11637c478bd9Sstevel@tonic-gate }
11647c478bd9Sstevel@tonic-gate switch (csp->t_flags & O_TBDELAY) {
11657c478bd9Sstevel@tonic-gate
11667c478bd9Sstevel@tonic-gate case O_TAB1:
11677c478bd9Sstevel@tonic-gate termiosp->c_oflag |= TAB1;
11687c478bd9Sstevel@tonic-gate break;
11697c478bd9Sstevel@tonic-gate
11707c478bd9Sstevel@tonic-gate case O_TAB2:
11717c478bd9Sstevel@tonic-gate termiosp->c_oflag |= TAB2;
11727c478bd9Sstevel@tonic-gate break;
11737c478bd9Sstevel@tonic-gate
11747c478bd9Sstevel@tonic-gate case O_XTABS:
11757c478bd9Sstevel@tonic-gate termiosp->c_oflag |= TAB3;
11767c478bd9Sstevel@tonic-gate break;
11777c478bd9Sstevel@tonic-gate }
11787c478bd9Sstevel@tonic-gate if (csp->t_flags & O_VTDELAY)
11797c478bd9Sstevel@tonic-gate termiosp->c_oflag |= FFDLY;
11807c478bd9Sstevel@tonic-gate if (csp->t_flags & O_BSDELAY)
11817c478bd9Sstevel@tonic-gate termiosp->c_oflag |= BSDLY;
11827c478bd9Sstevel@tonic-gate if (csp->t_flags & O_PRTERA)
11837c478bd9Sstevel@tonic-gate termiosp->c_lflag |= ECHOPRT;
11847c478bd9Sstevel@tonic-gate if (csp->t_flags & O_CRTERA)
11857c478bd9Sstevel@tonic-gate termiosp->c_lflag |= ECHOE;
11867c478bd9Sstevel@tonic-gate if (csp->t_flags & O_TOSTOP)
11877c478bd9Sstevel@tonic-gate termiosp->c_lflag |= TOSTOP;
11887c478bd9Sstevel@tonic-gate if (csp->t_flags & O_FLUSHO)
11897c478bd9Sstevel@tonic-gate termiosp->c_lflag |= FLUSHO;
11907c478bd9Sstevel@tonic-gate if (csp->t_flags & O_NOHANG)
11917c478bd9Sstevel@tonic-gate termiosp->c_cflag |= CLOCAL;
11927c478bd9Sstevel@tonic-gate if (csp->t_flags & O_CRTKIL)
11937c478bd9Sstevel@tonic-gate termiosp->c_lflag |= ECHOKE;
11947c478bd9Sstevel@tonic-gate if (csp->t_flags & O_PENDIN)
11957c478bd9Sstevel@tonic-gate termiosp->c_lflag |= PENDIN;
11967c478bd9Sstevel@tonic-gate if (!(csp->t_flags & O_DECCTQ))
11977c478bd9Sstevel@tonic-gate termiosp->c_iflag |= IXANY;
11987c478bd9Sstevel@tonic-gate if (csp->t_flags & O_NOFLSH)
11997c478bd9Sstevel@tonic-gate termiosp->c_lflag |= NOFLSH;
12007c478bd9Sstevel@tonic-gate if (termiosp->c_lflag & ICANON) {
12017c478bd9Sstevel@tonic-gate FROM_COMPAT_CHAR(termiosp->c_cc[VEOF], csp->t_eofc);
12027c478bd9Sstevel@tonic-gate FROM_COMPAT_CHAR(termiosp->c_cc[VEOL], csp->t_brkc);
12037c478bd9Sstevel@tonic-gate } else {
12047c478bd9Sstevel@tonic-gate termiosp->c_cc[VMIN] = 1;
12057c478bd9Sstevel@tonic-gate termiosp->c_cc[VTIME] = 0;
12067c478bd9Sstevel@tonic-gate }
12077c478bd9Sstevel@tonic-gate }
12087c478bd9Sstevel@tonic-gate
12097c478bd9Sstevel@tonic-gate #define TO_COMPAT_CHAR(to, from) { if ((to = from) == 0) to = (uchar_t)0377; }
12107c478bd9Sstevel@tonic-gate
12117c478bd9Sstevel@tonic-gate static void
to_compat(struct termios * termiosp,compat_state_t * csp)12127c478bd9Sstevel@tonic-gate to_compat(struct termios *termiosp, compat_state_t *csp)
12137c478bd9Sstevel@tonic-gate {
12147c478bd9Sstevel@tonic-gate csp->t_xflags &= (NOISIG|NOPOST);
12157c478bd9Sstevel@tonic-gate csp->t_ospeed = termiosp->c_cflag & CBAUD;
12167c478bd9Sstevel@tonic-gate csp->t_ispeed = (termiosp->c_cflag & CIBAUD) >> IBSHIFT;
12177c478bd9Sstevel@tonic-gate if (sgttyb_handling > 0) {
12187c478bd9Sstevel@tonic-gate if (termiosp->c_cflag & CBAUDEXT)
12197c478bd9Sstevel@tonic-gate csp->t_ospeed += CBAUD + 1;
12207c478bd9Sstevel@tonic-gate if (termiosp->c_cflag & CIBAUDEXT)
12217c478bd9Sstevel@tonic-gate csp->t_ispeed += (CIBAUD >> IBSHIFT) + 1;
12227c478bd9Sstevel@tonic-gate }
12237c478bd9Sstevel@tonic-gate if (csp->t_ispeed == 0)
12247c478bd9Sstevel@tonic-gate csp->t_ispeed = csp->t_ospeed;
12257c478bd9Sstevel@tonic-gate if ((termiosp->c_cflag & CSTOPB) && csp->t_ispeed != B110)
12267c478bd9Sstevel@tonic-gate csp->t_xflags |= STOPB;
12277c478bd9Sstevel@tonic-gate TO_COMPAT_CHAR(csp->t_erase, termiosp->c_cc[VERASE]);
12287c478bd9Sstevel@tonic-gate TO_COMPAT_CHAR(csp->t_kill, termiosp->c_cc[VKILL]);
12297c478bd9Sstevel@tonic-gate TO_COMPAT_CHAR(csp->t_intrc, termiosp->c_cc[VINTR]);
12307c478bd9Sstevel@tonic-gate TO_COMPAT_CHAR(csp->t_quitc, termiosp->c_cc[VQUIT]);
12317c478bd9Sstevel@tonic-gate TO_COMPAT_CHAR(csp->t_startc, termiosp->c_cc[VSTART]);
12327c478bd9Sstevel@tonic-gate TO_COMPAT_CHAR(csp->t_stopc, termiosp->c_cc[VSTOP]);
12337c478bd9Sstevel@tonic-gate TO_COMPAT_CHAR(csp->t_suspc, termiosp->c_cc[VSUSP]);
12347c478bd9Sstevel@tonic-gate TO_COMPAT_CHAR(csp->t_dsuspc, termiosp->c_cc[VDSUSP]);
12357c478bd9Sstevel@tonic-gate TO_COMPAT_CHAR(csp->t_rprntc, termiosp->c_cc[VREPRINT]);
12367c478bd9Sstevel@tonic-gate TO_COMPAT_CHAR(csp->t_flushc, termiosp->c_cc[VDISCARD]);
12377c478bd9Sstevel@tonic-gate TO_COMPAT_CHAR(csp->t_werasc, termiosp->c_cc[VWERASE]);
12387c478bd9Sstevel@tonic-gate TO_COMPAT_CHAR(csp->t_lnextc, termiosp->c_cc[VLNEXT]);
12397c478bd9Sstevel@tonic-gate csp->t_flags &= (O_CTLECH|O_LITOUT|O_PASS8|O_ODDP|O_EVENP);
12407c478bd9Sstevel@tonic-gate if (termiosp->c_iflag & IXOFF)
12417c478bd9Sstevel@tonic-gate csp->t_flags |= O_TANDEM;
12427c478bd9Sstevel@tonic-gate if (!(termiosp->c_iflag &
12437c478bd9Sstevel@tonic-gate (IMAXBEL|BRKINT|IGNPAR|PARMRK|INPCK|ISTRIP|
12447c478bd9Sstevel@tonic-gate INLCR|IGNCR|ICRNL|IUCLC|IXON)) &&
12457c478bd9Sstevel@tonic-gate !(termiosp->c_oflag & OPOST) &&
12467c478bd9Sstevel@tonic-gate (termiosp->c_cflag & (CSIZE|PARENB)) == CS8 &&
12477c478bd9Sstevel@tonic-gate !(termiosp->c_lflag & (ISIG|ICANON|XCASE|IEXTEN)))
12487c478bd9Sstevel@tonic-gate csp->t_flags |= O_RAW;
12497c478bd9Sstevel@tonic-gate else {
12507c478bd9Sstevel@tonic-gate if (!(termiosp->c_iflag & IXON)) {
12517c478bd9Sstevel@tonic-gate csp->t_startc = (uchar_t)0377;
12527c478bd9Sstevel@tonic-gate csp->t_stopc = (uchar_t)0377;
12537c478bd9Sstevel@tonic-gate }
12547c478bd9Sstevel@tonic-gate if ((termiosp->c_cflag & (CSIZE|PARENB)) == CS8 &&
12557c478bd9Sstevel@tonic-gate !(termiosp->c_oflag & OPOST))
12567c478bd9Sstevel@tonic-gate csp->t_flags |= O_LITOUT;
12577c478bd9Sstevel@tonic-gate else {
12587c478bd9Sstevel@tonic-gate csp->t_flags &= ~O_LITOUT;
12597c478bd9Sstevel@tonic-gate if ((termiosp->c_cflag & (CSIZE|PARENB)) == CS8) {
12607c478bd9Sstevel@tonic-gate if (!(termiosp->c_iflag & ISTRIP))
12617c478bd9Sstevel@tonic-gate csp->t_flags |= O_PASS8;
12627c478bd9Sstevel@tonic-gate } else {
12637c478bd9Sstevel@tonic-gate csp->t_flags &= ~(O_ODDP|O_EVENP|O_PASS8);
12647c478bd9Sstevel@tonic-gate if (termiosp->c_cflag & PARODD)
12657c478bd9Sstevel@tonic-gate csp->t_flags |= O_ODDP;
12667c478bd9Sstevel@tonic-gate else if (termiosp->c_iflag & INPCK)
12677c478bd9Sstevel@tonic-gate csp->t_flags |= O_EVENP;
12687c478bd9Sstevel@tonic-gate else
12697c478bd9Sstevel@tonic-gate csp->t_flags |= O_ODDP|O_EVENP;
12707c478bd9Sstevel@tonic-gate }
12717c478bd9Sstevel@tonic-gate if (!(termiosp->c_oflag & OPOST))
12727c478bd9Sstevel@tonic-gate csp->t_xflags |= NOPOST;
12737c478bd9Sstevel@tonic-gate else
12747c478bd9Sstevel@tonic-gate csp->t_xflags &= ~NOPOST;
12757c478bd9Sstevel@tonic-gate }
12767c478bd9Sstevel@tonic-gate if (!(termiosp->c_lflag & ISIG))
12777c478bd9Sstevel@tonic-gate csp->t_xflags |= NOISIG;
12787c478bd9Sstevel@tonic-gate else
12797c478bd9Sstevel@tonic-gate csp->t_xflags &= ~NOISIG;
12807c478bd9Sstevel@tonic-gate if (!(termiosp->c_lflag & ICANON))
12817c478bd9Sstevel@tonic-gate csp->t_flags |= O_CBREAK;
12827c478bd9Sstevel@tonic-gate if (termiosp->c_lflag & ECHOCTL)
12837c478bd9Sstevel@tonic-gate csp->t_flags |= O_CTLECH;
12847c478bd9Sstevel@tonic-gate else
12857c478bd9Sstevel@tonic-gate csp->t_flags &= ~O_CTLECH;
12867c478bd9Sstevel@tonic-gate }
12877c478bd9Sstevel@tonic-gate if (termiosp->c_oflag & OLCUC)
12887c478bd9Sstevel@tonic-gate csp->t_flags |= O_LCASE;
12897c478bd9Sstevel@tonic-gate if (termiosp->c_lflag&ECHO)
12907c478bd9Sstevel@tonic-gate csp->t_flags |= O_ECHO;
12917c478bd9Sstevel@tonic-gate if (termiosp->c_oflag & ONLCR) {
12927c478bd9Sstevel@tonic-gate csp->t_flags |= O_CRMOD;
12937c478bd9Sstevel@tonic-gate switch (termiosp->c_oflag & CRDLY) {
12947c478bd9Sstevel@tonic-gate
12957c478bd9Sstevel@tonic-gate case CR2:
12967c478bd9Sstevel@tonic-gate csp->t_flags |= O_CR1;
12977c478bd9Sstevel@tonic-gate break;
12987c478bd9Sstevel@tonic-gate
12997c478bd9Sstevel@tonic-gate case CR3:
13007c478bd9Sstevel@tonic-gate csp->t_flags |= O_CR2;
13017c478bd9Sstevel@tonic-gate break;
13027c478bd9Sstevel@tonic-gate }
13037c478bd9Sstevel@tonic-gate } else {
13047c478bd9Sstevel@tonic-gate if ((termiosp->c_oflag & CR1) &&
13057c478bd9Sstevel@tonic-gate (termiosp->c_oflag & ONLRET))
13067c478bd9Sstevel@tonic-gate csp->t_flags |= O_NL1; /* tty37 */
13077c478bd9Sstevel@tonic-gate }
13087c478bd9Sstevel@tonic-gate if ((termiosp->c_oflag & ONLRET) && (termiosp->c_oflag & NL1))
13097c478bd9Sstevel@tonic-gate csp->t_flags |= O_NL2;
13107c478bd9Sstevel@tonic-gate switch (termiosp->c_oflag & TABDLY) {
13117c478bd9Sstevel@tonic-gate
13127c478bd9Sstevel@tonic-gate case TAB1:
13137c478bd9Sstevel@tonic-gate csp->t_flags |= O_TAB1;
13147c478bd9Sstevel@tonic-gate break;
13157c478bd9Sstevel@tonic-gate
13167c478bd9Sstevel@tonic-gate case TAB2:
13177c478bd9Sstevel@tonic-gate csp->t_flags |= O_TAB2;
13187c478bd9Sstevel@tonic-gate break;
13197c478bd9Sstevel@tonic-gate
13207c478bd9Sstevel@tonic-gate case XTABS:
13217c478bd9Sstevel@tonic-gate csp->t_flags |= O_XTABS;
13227c478bd9Sstevel@tonic-gate break;
13237c478bd9Sstevel@tonic-gate }
13247c478bd9Sstevel@tonic-gate if (termiosp->c_oflag & FFDLY)
13257c478bd9Sstevel@tonic-gate csp->t_flags |= O_VTDELAY;
13267c478bd9Sstevel@tonic-gate if (termiosp->c_oflag & BSDLY)
13277c478bd9Sstevel@tonic-gate csp->t_flags |= O_BSDELAY;
13287c478bd9Sstevel@tonic-gate if (termiosp->c_lflag & ECHOPRT)
13297c478bd9Sstevel@tonic-gate csp->t_flags |= O_PRTERA;
13307c478bd9Sstevel@tonic-gate if (termiosp->c_lflag & ECHOE)
13317c478bd9Sstevel@tonic-gate csp->t_flags |= (O_CRTERA|O_CRTBS);
13327c478bd9Sstevel@tonic-gate if (termiosp->c_lflag & TOSTOP)
13337c478bd9Sstevel@tonic-gate csp->t_flags |= O_TOSTOP;
13347c478bd9Sstevel@tonic-gate if (termiosp->c_lflag & FLUSHO)
13357c478bd9Sstevel@tonic-gate csp->t_flags |= O_FLUSHO;
13367c478bd9Sstevel@tonic-gate if (termiosp->c_cflag & CLOCAL)
13377c478bd9Sstevel@tonic-gate csp->t_flags |= O_NOHANG;
13387c478bd9Sstevel@tonic-gate if (termiosp->c_lflag & ECHOKE)
13397c478bd9Sstevel@tonic-gate csp->t_flags |= O_CRTKIL;
13407c478bd9Sstevel@tonic-gate if (termiosp->c_lflag & PENDIN)
13417c478bd9Sstevel@tonic-gate csp->t_flags |= O_PENDIN;
13427c478bd9Sstevel@tonic-gate if (!(termiosp->c_iflag & IXANY))
13437c478bd9Sstevel@tonic-gate csp->t_flags |= O_DECCTQ;
13447c478bd9Sstevel@tonic-gate if (termiosp->c_lflag & NOFLSH)
13457c478bd9Sstevel@tonic-gate csp->t_flags |= O_NOFLSH;
13467c478bd9Sstevel@tonic-gate if (termiosp->c_lflag & ICANON) {
13477c478bd9Sstevel@tonic-gate TO_COMPAT_CHAR(csp->t_eofc, termiosp->c_cc[VEOF]);
13487c478bd9Sstevel@tonic-gate TO_COMPAT_CHAR(csp->t_brkc, termiosp->c_cc[VEOL]);
13497c478bd9Sstevel@tonic-gate } else {
13507c478bd9Sstevel@tonic-gate termiosp->c_cc[VMIN] = 1;
13517c478bd9Sstevel@tonic-gate termiosp->c_cc[VTIME] = 0;
13527c478bd9Sstevel@tonic-gate }
13537c478bd9Sstevel@tonic-gate }
1354