1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright 2003 Sun Microsystems, Inc. All rights reserved. 24*0Sstevel@tonic-gate * Use is subject to license terms. 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 28*0Sstevel@tonic-gate /* All Rights Reserved */ 29*0Sstevel@tonic-gate 30*0Sstevel@tonic-gate /* 31*0Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988 32*0Sstevel@tonic-gate * The Regents of the University of California 33*0Sstevel@tonic-gate * All Rights Reserved 34*0Sstevel@tonic-gate * 35*0Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from 36*0Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its 37*0Sstevel@tonic-gate * contributors. 38*0Sstevel@tonic-gate */ 39*0Sstevel@tonic-gate 40*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 41*0Sstevel@tonic-gate 42*0Sstevel@tonic-gate /* 43*0Sstevel@tonic-gate * Module to intercept old V7 and 4BSD "ioctl" calls. 44*0Sstevel@tonic-gate */ 45*0Sstevel@tonic-gate 46*0Sstevel@tonic-gate #include <sys/types.h> 47*0Sstevel@tonic-gate #include <sys/param.h> 48*0Sstevel@tonic-gate #include <sys/signal.h> 49*0Sstevel@tonic-gate #include <sys/file.h> 50*0Sstevel@tonic-gate #include <sys/termios.h> 51*0Sstevel@tonic-gate #include <sys/ttold.h> 52*0Sstevel@tonic-gate #include <sys/cmn_err.h> 53*0Sstevel@tonic-gate #include <sys/stream.h> 54*0Sstevel@tonic-gate #include <sys/stropts.h> 55*0Sstevel@tonic-gate #include <sys/strsun.h> 56*0Sstevel@tonic-gate #include <sys/errno.h> 57*0Sstevel@tonic-gate #include <sys/debug.h> 58*0Sstevel@tonic-gate #include <sys/ttcompat.h> 59*0Sstevel@tonic-gate #include <sys/ddi.h> 60*0Sstevel@tonic-gate #include <sys/sunddi.h> 61*0Sstevel@tonic-gate #include <sys/kmem.h> 62*0Sstevel@tonic-gate #include <sys/policy.h> 63*0Sstevel@tonic-gate 64*0Sstevel@tonic-gate /* 65*0Sstevel@tonic-gate * This is the loadable module wrapper. 66*0Sstevel@tonic-gate */ 67*0Sstevel@tonic-gate #include <sys/conf.h> 68*0Sstevel@tonic-gate #include <sys/modctl.h> 69*0Sstevel@tonic-gate 70*0Sstevel@tonic-gate /* See os/streamio.c */ 71*0Sstevel@tonic-gate extern int sgttyb_handling; 72*0Sstevel@tonic-gate 73*0Sstevel@tonic-gate static struct streamtab ttcoinfo; 74*0Sstevel@tonic-gate 75*0Sstevel@tonic-gate static struct fmodsw fsw = { 76*0Sstevel@tonic-gate "ttcompat", 77*0Sstevel@tonic-gate &ttcoinfo, 78*0Sstevel@tonic-gate D_MTQPAIR | D_MP 79*0Sstevel@tonic-gate }; 80*0Sstevel@tonic-gate 81*0Sstevel@tonic-gate /* 82*0Sstevel@tonic-gate * Module linkage information for the kernel. 83*0Sstevel@tonic-gate */ 84*0Sstevel@tonic-gate 85*0Sstevel@tonic-gate static struct modlstrmod modlstrmod = { 86*0Sstevel@tonic-gate &mod_strmodops, 87*0Sstevel@tonic-gate "alt ioctl calls", 88*0Sstevel@tonic-gate &fsw 89*0Sstevel@tonic-gate }; 90*0Sstevel@tonic-gate 91*0Sstevel@tonic-gate static struct modlinkage modlinkage = { 92*0Sstevel@tonic-gate MODREV_1, &modlstrmod, NULL 93*0Sstevel@tonic-gate }; 94*0Sstevel@tonic-gate 95*0Sstevel@tonic-gate int 96*0Sstevel@tonic-gate _init(void) 97*0Sstevel@tonic-gate { 98*0Sstevel@tonic-gate return (mod_install(&modlinkage)); 99*0Sstevel@tonic-gate } 100*0Sstevel@tonic-gate 101*0Sstevel@tonic-gate int 102*0Sstevel@tonic-gate _fini(void) 103*0Sstevel@tonic-gate { 104*0Sstevel@tonic-gate return (mod_remove(&modlinkage)); 105*0Sstevel@tonic-gate } 106*0Sstevel@tonic-gate 107*0Sstevel@tonic-gate int 108*0Sstevel@tonic-gate _info(struct modinfo *modinfop) 109*0Sstevel@tonic-gate { 110*0Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop)); 111*0Sstevel@tonic-gate } 112*0Sstevel@tonic-gate 113*0Sstevel@tonic-gate static int ttcompatopen(queue_t *, dev_t *, int, int, cred_t *); 114*0Sstevel@tonic-gate static int ttcompatclose(queue_t *, int, cred_t *); 115*0Sstevel@tonic-gate static void ttcompatrput(queue_t *, mblk_t *); 116*0Sstevel@tonic-gate static void ttcompatwput(queue_t *, mblk_t *); 117*0Sstevel@tonic-gate 118*0Sstevel@tonic-gate static struct module_info ttycompatmiinfo = { 119*0Sstevel@tonic-gate 0, 120*0Sstevel@tonic-gate "ttcompat", 121*0Sstevel@tonic-gate 0, 122*0Sstevel@tonic-gate INFPSZ, 123*0Sstevel@tonic-gate 2048, 124*0Sstevel@tonic-gate 128 125*0Sstevel@tonic-gate }; 126*0Sstevel@tonic-gate 127*0Sstevel@tonic-gate static struct qinit ttycompatrinit = { 128*0Sstevel@tonic-gate (int (*)())ttcompatrput, 129*0Sstevel@tonic-gate NULL, 130*0Sstevel@tonic-gate ttcompatopen, 131*0Sstevel@tonic-gate ttcompatclose, 132*0Sstevel@tonic-gate NULL, 133*0Sstevel@tonic-gate &ttycompatmiinfo 134*0Sstevel@tonic-gate }; 135*0Sstevel@tonic-gate 136*0Sstevel@tonic-gate static struct module_info ttycompatmoinfo = { 137*0Sstevel@tonic-gate 42, 138*0Sstevel@tonic-gate "ttcompat", 139*0Sstevel@tonic-gate 0, 140*0Sstevel@tonic-gate INFPSZ, 141*0Sstevel@tonic-gate 300, 142*0Sstevel@tonic-gate 200 143*0Sstevel@tonic-gate }; 144*0Sstevel@tonic-gate 145*0Sstevel@tonic-gate static struct qinit ttycompatwinit = { 146*0Sstevel@tonic-gate (int (*)())ttcompatwput, 147*0Sstevel@tonic-gate NULL, 148*0Sstevel@tonic-gate ttcompatopen, 149*0Sstevel@tonic-gate ttcompatclose, 150*0Sstevel@tonic-gate NULL, 151*0Sstevel@tonic-gate &ttycompatmoinfo 152*0Sstevel@tonic-gate }; 153*0Sstevel@tonic-gate 154*0Sstevel@tonic-gate static struct streamtab ttcoinfo = { 155*0Sstevel@tonic-gate &ttycompatrinit, 156*0Sstevel@tonic-gate &ttycompatwinit, 157*0Sstevel@tonic-gate NULL, 158*0Sstevel@tonic-gate NULL 159*0Sstevel@tonic-gate }; 160*0Sstevel@tonic-gate 161*0Sstevel@tonic-gate static void ttcompat_do_ioctl(ttcompat_state_t *, queue_t *, mblk_t *); 162*0Sstevel@tonic-gate static void ttcompat_ioctl_ack(queue_t *, mblk_t *); 163*0Sstevel@tonic-gate static void ttcopyout(queue_t *, mblk_t *); 164*0Sstevel@tonic-gate static void ttcompat_ioctl_nak(queue_t *, mblk_t *); 165*0Sstevel@tonic-gate static void from_compat(compat_state_t *, struct termios *); 166*0Sstevel@tonic-gate static void to_compat(struct termios *, compat_state_t *); 167*0Sstevel@tonic-gate 168*0Sstevel@tonic-gate /* 169*0Sstevel@tonic-gate * Open - get the current modes and translate them to the V7/4BSD equivalent. 170*0Sstevel@tonic-gate */ 171*0Sstevel@tonic-gate /*ARGSUSED*/ 172*0Sstevel@tonic-gate static int 173*0Sstevel@tonic-gate ttcompatopen(queue_t *q, dev_t *devp, int oflag, int sflag, cred_t *crp) 174*0Sstevel@tonic-gate { 175*0Sstevel@tonic-gate ttcompat_state_t *tp; 176*0Sstevel@tonic-gate 177*0Sstevel@tonic-gate if (q->q_ptr != NULL) { 178*0Sstevel@tonic-gate tp = (ttcompat_state_t *)q->q_ptr; 179*0Sstevel@tonic-gate /* fail open if TIOCEXCL was done and its not privileged */ 180*0Sstevel@tonic-gate if ((tp->t_new_lflags & XCLUDE) && 181*0Sstevel@tonic-gate secpolicy_excl_open(crp) != 0) { 182*0Sstevel@tonic-gate return (EBUSY); 183*0Sstevel@tonic-gate } 184*0Sstevel@tonic-gate return (0); /* already attached */ 185*0Sstevel@tonic-gate } 186*0Sstevel@tonic-gate tp = kmem_zalloc(sizeof (ttcompat_state_t), KM_SLEEP); 187*0Sstevel@tonic-gate tp->t_iocpending = NULL; 188*0Sstevel@tonic-gate tp->t_state = 0; 189*0Sstevel@tonic-gate tp->t_iocid = 0; 190*0Sstevel@tonic-gate tp->t_ioccmd = 0; 191*0Sstevel@tonic-gate tp->t_new_lflags = 0; 192*0Sstevel@tonic-gate tp->t_curstate.t_flags = 0; 193*0Sstevel@tonic-gate tp->t_curstate.t_ispeed = B0; 194*0Sstevel@tonic-gate tp->t_curstate.t_ospeed = B0; 195*0Sstevel@tonic-gate tp->t_curstate.t_erase = '\0'; 196*0Sstevel@tonic-gate tp->t_curstate.t_kill = '\0'; 197*0Sstevel@tonic-gate tp->t_curstate.t_intrc = '\0'; 198*0Sstevel@tonic-gate tp->t_curstate.t_quitc = '\0'; 199*0Sstevel@tonic-gate tp->t_curstate.t_startc = '\0'; 200*0Sstevel@tonic-gate tp->t_curstate.t_stopc = '\0'; 201*0Sstevel@tonic-gate tp->t_curstate.t_eofc = '\0'; 202*0Sstevel@tonic-gate tp->t_curstate.t_brkc = '\0'; 203*0Sstevel@tonic-gate tp->t_curstate.t_suspc = '\0'; 204*0Sstevel@tonic-gate tp->t_curstate.t_dsuspc = '\0'; 205*0Sstevel@tonic-gate tp->t_curstate.t_rprntc = '\0'; 206*0Sstevel@tonic-gate tp->t_curstate.t_flushc = '\0'; 207*0Sstevel@tonic-gate tp->t_curstate.t_werasc = '\0'; 208*0Sstevel@tonic-gate tp->t_curstate.t_lnextc = '\0'; 209*0Sstevel@tonic-gate tp->t_curstate.t_xflags = 0; 210*0Sstevel@tonic-gate tp->t_bufcallid = 0; 211*0Sstevel@tonic-gate tp->t_arg = 0; 212*0Sstevel@tonic-gate 213*0Sstevel@tonic-gate q->q_ptr = tp; 214*0Sstevel@tonic-gate WR(q)->q_ptr = tp; 215*0Sstevel@tonic-gate qprocson(q); 216*0Sstevel@tonic-gate return (0); 217*0Sstevel@tonic-gate } 218*0Sstevel@tonic-gate 219*0Sstevel@tonic-gate /* ARGSUSED1 */ 220*0Sstevel@tonic-gate static int 221*0Sstevel@tonic-gate ttcompatclose(queue_t *q, int flag, cred_t *crp) 222*0Sstevel@tonic-gate { 223*0Sstevel@tonic-gate ttcompat_state_t *tp = (ttcompat_state_t *)q->q_ptr; 224*0Sstevel@tonic-gate mblk_t *mp; 225*0Sstevel@tonic-gate 226*0Sstevel@tonic-gate /* Dump the state structure, then unlink it */ 227*0Sstevel@tonic-gate qprocsoff(q); 228*0Sstevel@tonic-gate if (tp->t_bufcallid != 0) { 229*0Sstevel@tonic-gate qunbufcall(q, tp->t_bufcallid); 230*0Sstevel@tonic-gate tp->t_bufcallid = 0; 231*0Sstevel@tonic-gate } 232*0Sstevel@tonic-gate if ((mp = tp->t_iocpending) != NULL) 233*0Sstevel@tonic-gate freemsg(mp); 234*0Sstevel@tonic-gate kmem_free(tp, sizeof (ttcompat_state_t)); 235*0Sstevel@tonic-gate q->q_ptr = NULL; 236*0Sstevel@tonic-gate 237*0Sstevel@tonic-gate return (0); 238*0Sstevel@tonic-gate } 239*0Sstevel@tonic-gate 240*0Sstevel@tonic-gate /* 241*0Sstevel@tonic-gate * Put procedure for input from driver end of stream (read queue). 242*0Sstevel@tonic-gate * Most messages just get passed to the next guy up; we intercept 243*0Sstevel@tonic-gate * "ioctl" replies, and if it's an "ioctl" whose reply we plan to do 244*0Sstevel@tonic-gate * something with, we do it. 245*0Sstevel@tonic-gate */ 246*0Sstevel@tonic-gate static void 247*0Sstevel@tonic-gate ttcompatrput(queue_t *q, mblk_t *mp) 248*0Sstevel@tonic-gate { 249*0Sstevel@tonic-gate switch (mp->b_datap->db_type) { 250*0Sstevel@tonic-gate 251*0Sstevel@tonic-gate case M_IOCACK: 252*0Sstevel@tonic-gate ttcompat_ioctl_ack(q, mp); 253*0Sstevel@tonic-gate break; 254*0Sstevel@tonic-gate 255*0Sstevel@tonic-gate case M_IOCNAK: 256*0Sstevel@tonic-gate ttcompat_ioctl_nak(q, mp); 257*0Sstevel@tonic-gate break; 258*0Sstevel@tonic-gate 259*0Sstevel@tonic-gate default: 260*0Sstevel@tonic-gate putnext(q, mp); 261*0Sstevel@tonic-gate break; 262*0Sstevel@tonic-gate } 263*0Sstevel@tonic-gate } 264*0Sstevel@tonic-gate 265*0Sstevel@tonic-gate /* 266*0Sstevel@tonic-gate * Line discipline output queue put procedure: speeds M_IOCTL 267*0Sstevel@tonic-gate * messages. 268*0Sstevel@tonic-gate */ 269*0Sstevel@tonic-gate static void 270*0Sstevel@tonic-gate ttcompatwput(queue_t *q, mblk_t *mp) 271*0Sstevel@tonic-gate { 272*0Sstevel@tonic-gate ttcompat_state_t *tp; 273*0Sstevel@tonic-gate struct copyreq *cqp; 274*0Sstevel@tonic-gate struct copyresp *csp; 275*0Sstevel@tonic-gate struct iocblk *iocbp; 276*0Sstevel@tonic-gate 277*0Sstevel@tonic-gate tp = (ttcompat_state_t *)q->q_ptr; 278*0Sstevel@tonic-gate 279*0Sstevel@tonic-gate /* 280*0Sstevel@tonic-gate * Process some M_IOCTL messages here; pass everything else down. 281*0Sstevel@tonic-gate */ 282*0Sstevel@tonic-gate switch (mp->b_datap->db_type) { 283*0Sstevel@tonic-gate 284*0Sstevel@tonic-gate default: 285*0Sstevel@tonic-gate putnext(q, mp); 286*0Sstevel@tonic-gate return; 287*0Sstevel@tonic-gate 288*0Sstevel@tonic-gate case M_IOCTL: 289*0Sstevel@tonic-gate iocbp = (struct iocblk *)mp->b_rptr; 290*0Sstevel@tonic-gate 291*0Sstevel@tonic-gate switch (iocbp->ioc_cmd) { 292*0Sstevel@tonic-gate 293*0Sstevel@tonic-gate default: 294*0Sstevel@tonic-gate /* these are ioctls with no arguments or are known to stream head */ 295*0Sstevel@tonic-gate /* process them right away */ 296*0Sstevel@tonic-gate ttcompat_do_ioctl(tp, q, mp); 297*0Sstevel@tonic-gate return; 298*0Sstevel@tonic-gate case TIOCSETN: 299*0Sstevel@tonic-gate case TIOCSLTC: 300*0Sstevel@tonic-gate case TIOCSETC: 301*0Sstevel@tonic-gate case TIOCLBIS: 302*0Sstevel@tonic-gate case TIOCLBIC: 303*0Sstevel@tonic-gate case TIOCLSET: 304*0Sstevel@tonic-gate case TIOCFLUSH: 305*0Sstevel@tonic-gate if (iocbp->ioc_count != TRANSPARENT) { 306*0Sstevel@tonic-gate putnext(q, mp); 307*0Sstevel@tonic-gate return; 308*0Sstevel@tonic-gate } 309*0Sstevel@tonic-gate 310*0Sstevel@tonic-gate mp->b_datap->db_type = M_COPYIN; 311*0Sstevel@tonic-gate cqp = (struct copyreq *)mp->b_rptr; 312*0Sstevel@tonic-gate cqp->cq_addr = (caddr_t)*(intptr_t *)mp->b_cont->b_rptr; 313*0Sstevel@tonic-gate switch (iocbp->ioc_cmd) { 314*0Sstevel@tonic-gate case TIOCSETN: 315*0Sstevel@tonic-gate cqp->cq_size = sizeof (struct sgttyb); 316*0Sstevel@tonic-gate break; 317*0Sstevel@tonic-gate case TIOCSLTC: 318*0Sstevel@tonic-gate cqp->cq_size = sizeof (struct ltchars); 319*0Sstevel@tonic-gate break; 320*0Sstevel@tonic-gate case TIOCSETC: 321*0Sstevel@tonic-gate cqp->cq_size = sizeof (struct tchars); 322*0Sstevel@tonic-gate break; 323*0Sstevel@tonic-gate case TIOCLBIS: 324*0Sstevel@tonic-gate case TIOCLBIC: 325*0Sstevel@tonic-gate case TIOCLSET: 326*0Sstevel@tonic-gate case TIOCFLUSH: 327*0Sstevel@tonic-gate cqp->cq_size = sizeof (int); 328*0Sstevel@tonic-gate break; 329*0Sstevel@tonic-gate default: 330*0Sstevel@tonic-gate break; 331*0Sstevel@tonic-gate } 332*0Sstevel@tonic-gate cqp->cq_flag = 0; 333*0Sstevel@tonic-gate cqp->cq_private = NULL; 334*0Sstevel@tonic-gate freemsg(mp->b_cont); 335*0Sstevel@tonic-gate mp->b_cont = NULL; 336*0Sstevel@tonic-gate mp->b_wptr = mp->b_rptr + sizeof (struct copyreq); 337*0Sstevel@tonic-gate tp->t_ioccmd = iocbp->ioc_cmd; 338*0Sstevel@tonic-gate tp->t_state |= TS_W_IN; 339*0Sstevel@tonic-gate qreply(q, mp); 340*0Sstevel@tonic-gate return; 341*0Sstevel@tonic-gate 342*0Sstevel@tonic-gate } /* switch ioc_cmd */ 343*0Sstevel@tonic-gate case M_IOCDATA: 344*0Sstevel@tonic-gate csp = (struct copyresp *)mp->b_rptr; 345*0Sstevel@tonic-gate 346*0Sstevel@tonic-gate switch (csp->cp_cmd) { 347*0Sstevel@tonic-gate 348*0Sstevel@tonic-gate default: 349*0Sstevel@tonic-gate putnext(q, mp); 350*0Sstevel@tonic-gate return; 351*0Sstevel@tonic-gate 352*0Sstevel@tonic-gate case TIOCSETN: 353*0Sstevel@tonic-gate case TIOCSLTC: 354*0Sstevel@tonic-gate case TIOCSETC: 355*0Sstevel@tonic-gate case TIOCLBIS: 356*0Sstevel@tonic-gate case TIOCLBIC: 357*0Sstevel@tonic-gate case TIOCLSET: 358*0Sstevel@tonic-gate case TIOCFLUSH: 359*0Sstevel@tonic-gate tp->t_state &= ~TS_W_IN; 360*0Sstevel@tonic-gate if (csp->cp_rval != 0) { /* failure */ 361*0Sstevel@tonic-gate freemsg(mp); 362*0Sstevel@tonic-gate return; 363*0Sstevel@tonic-gate } 364*0Sstevel@tonic-gate 365*0Sstevel@tonic-gate /* make it look like an ioctl */ 366*0Sstevel@tonic-gate mp->b_datap->db_type = M_IOCTL; 367*0Sstevel@tonic-gate mp->b_wptr = mp->b_rptr + sizeof (struct iocblk); 368*0Sstevel@tonic-gate iocbp = (struct iocblk *)mp->b_rptr; 369*0Sstevel@tonic-gate iocbp->ioc_count = MBLKL(mp->b_cont); 370*0Sstevel@tonic-gate iocbp->ioc_error = 0; 371*0Sstevel@tonic-gate iocbp->ioc_rval = 0; 372*0Sstevel@tonic-gate ttcompat_do_ioctl(tp, q, mp); 373*0Sstevel@tonic-gate return; 374*0Sstevel@tonic-gate 375*0Sstevel@tonic-gate case TIOCGLTC: 376*0Sstevel@tonic-gate case TIOCLGET: 377*0Sstevel@tonic-gate case TIOCGETC: 378*0Sstevel@tonic-gate tp->t_state &= ~TS_W_OUT; 379*0Sstevel@tonic-gate if (csp->cp_rval != 0) { /* failure */ 380*0Sstevel@tonic-gate freemsg(mp); 381*0Sstevel@tonic-gate return; 382*0Sstevel@tonic-gate } 383*0Sstevel@tonic-gate 384*0Sstevel@tonic-gate iocbp = (struct iocblk *)mp->b_rptr; 385*0Sstevel@tonic-gate iocbp->ioc_count = 0; 386*0Sstevel@tonic-gate iocbp->ioc_error = 0; 387*0Sstevel@tonic-gate iocbp->ioc_rval = 0; 388*0Sstevel@tonic-gate mp->b_datap->db_type = M_IOCACK; 389*0Sstevel@tonic-gate qreply(q, mp); 390*0Sstevel@tonic-gate return; 391*0Sstevel@tonic-gate 392*0Sstevel@tonic-gate } /* switch cp_cmd */ 393*0Sstevel@tonic-gate } /* end message switch */ 394*0Sstevel@tonic-gate } 395*0Sstevel@tonic-gate 396*0Sstevel@tonic-gate /* 397*0Sstevel@tonic-gate * Retry an "ioctl", now that "bufcall" claims we may be able to allocate 398*0Sstevel@tonic-gate * the buffer we need. 399*0Sstevel@tonic-gate */ 400*0Sstevel@tonic-gate static void 401*0Sstevel@tonic-gate ttcompat_reioctl(void *arg) 402*0Sstevel@tonic-gate { 403*0Sstevel@tonic-gate queue_t *q = arg; 404*0Sstevel@tonic-gate ttcompat_state_t *tp; 405*0Sstevel@tonic-gate mblk_t *mp; 406*0Sstevel@tonic-gate 407*0Sstevel@tonic-gate tp = (ttcompat_state_t *)q->q_ptr; 408*0Sstevel@tonic-gate tp->t_bufcallid = 0; 409*0Sstevel@tonic-gate 410*0Sstevel@tonic-gate if ((mp = tp->t_iocpending) != NULL) { 411*0Sstevel@tonic-gate tp->t_iocpending = NULL; /* not pending any more */ 412*0Sstevel@tonic-gate ttcompat_do_ioctl(tp, q, mp); 413*0Sstevel@tonic-gate } 414*0Sstevel@tonic-gate } 415*0Sstevel@tonic-gate 416*0Sstevel@tonic-gate /* 417*0Sstevel@tonic-gate * Handle old-style "ioctl" messages; pass the rest down unmolested. 418*0Sstevel@tonic-gate */ 419*0Sstevel@tonic-gate static void 420*0Sstevel@tonic-gate ttcompat_do_ioctl(ttcompat_state_t *tp, queue_t *q, mblk_t *mp) 421*0Sstevel@tonic-gate { 422*0Sstevel@tonic-gate struct iocblk *iocp; 423*0Sstevel@tonic-gate int error; 424*0Sstevel@tonic-gate 425*0Sstevel@tonic-gate /* 426*0Sstevel@tonic-gate * Most of the miocpullup()'s below aren't needed because the 427*0Sstevel@tonic-gate * ioctls in question are actually transparent M_IOCDATA messages 428*0Sstevel@tonic-gate * dummied to look like M_IOCTL messages. However, for clarity and 429*0Sstevel@tonic-gate * robustness against future changes, we've included them anyway. 430*0Sstevel@tonic-gate */ 431*0Sstevel@tonic-gate 432*0Sstevel@tonic-gate iocp = (struct iocblk *)mp->b_rptr; 433*0Sstevel@tonic-gate switch (iocp->ioc_cmd) { 434*0Sstevel@tonic-gate 435*0Sstevel@tonic-gate /* 436*0Sstevel@tonic-gate * "get"-style calls that get translated data from the "termios" 437*0Sstevel@tonic-gate * structure. Save the existing code and pass it down as a TCGETS. 438*0Sstevel@tonic-gate */ 439*0Sstevel@tonic-gate case TIOCGETC: 440*0Sstevel@tonic-gate case TIOCLGET: 441*0Sstevel@tonic-gate case TIOCGLTC: 442*0Sstevel@tonic-gate if (iocp->ioc_count != TRANSPARENT) { 443*0Sstevel@tonic-gate miocnak(q, mp, 0, EINVAL); 444*0Sstevel@tonic-gate return; 445*0Sstevel@tonic-gate } 446*0Sstevel@tonic-gate 447*0Sstevel@tonic-gate /* 448*0Sstevel@tonic-gate * We can get here with t_arg != 0, iff the stream head 449*0Sstevel@tonic-gate * has for some reason given up on the ioctl in progress. 450*0Sstevel@tonic-gate * The most likely cause is an interrupted ioctl syscall. 451*0Sstevel@tonic-gate * We will behave robustly because (given our perimeter) 452*0Sstevel@tonic-gate * the ttcompat_state_t will get set up for the new ioctl, 453*0Sstevel@tonic-gate * and when the response we were waiting for appears it 454*0Sstevel@tonic-gate * will be passed on to the stream head which will discard 455*0Sstevel@tonic-gate * it as non-current. 456*0Sstevel@tonic-gate */ 457*0Sstevel@tonic-gate ASSERT(mp->b_cont != NULL); 458*0Sstevel@tonic-gate tp->t_arg = *(intptr_t *)mp->b_cont->b_rptr; 459*0Sstevel@tonic-gate /* free the data buffer - it might not be sufficient */ 460*0Sstevel@tonic-gate /* driver will allocate one for termios size */ 461*0Sstevel@tonic-gate freemsg(mp->b_cont); 462*0Sstevel@tonic-gate mp->b_cont = NULL; 463*0Sstevel@tonic-gate iocp->ioc_count = 0; 464*0Sstevel@tonic-gate /* FALLTHRU */ 465*0Sstevel@tonic-gate case TIOCGETP: 466*0Sstevel@tonic-gate goto dogets; 467*0Sstevel@tonic-gate 468*0Sstevel@tonic-gate /* 469*0Sstevel@tonic-gate * "set"-style calls that set translated data into a "termios" 470*0Sstevel@tonic-gate * structure. Set our idea of the new state from the value 471*0Sstevel@tonic-gate * given to us. We then have to get the current state, so we 472*0Sstevel@tonic-gate * turn this guy into a TCGETS and pass it down. When the 473*0Sstevel@tonic-gate * ACK comes back, we modify the state we got back and shove it 474*0Sstevel@tonic-gate * back down as the appropriate type of TCSETS. 475*0Sstevel@tonic-gate */ 476*0Sstevel@tonic-gate case TIOCSETP: 477*0Sstevel@tonic-gate case TIOCSETN: 478*0Sstevel@tonic-gate error = miocpullup(mp, sizeof (struct sgttyb)); 479*0Sstevel@tonic-gate if (error != 0) { 480*0Sstevel@tonic-gate miocnak(q, mp, 0, error); 481*0Sstevel@tonic-gate return; 482*0Sstevel@tonic-gate } 483*0Sstevel@tonic-gate tp->t_new_sgttyb = *((struct sgttyb *)mp->b_cont->b_rptr); 484*0Sstevel@tonic-gate goto dogets; 485*0Sstevel@tonic-gate 486*0Sstevel@tonic-gate case TIOCSETC: 487*0Sstevel@tonic-gate error = miocpullup(mp, sizeof (struct tchars)); 488*0Sstevel@tonic-gate if (error != 0) { 489*0Sstevel@tonic-gate miocnak(q, mp, 0, error); 490*0Sstevel@tonic-gate return; 491*0Sstevel@tonic-gate } 492*0Sstevel@tonic-gate tp->t_new_tchars = *((struct tchars *)mp->b_cont->b_rptr); 493*0Sstevel@tonic-gate goto dogets; 494*0Sstevel@tonic-gate 495*0Sstevel@tonic-gate case TIOCSLTC: 496*0Sstevel@tonic-gate error = miocpullup(mp, sizeof (struct ltchars)); 497*0Sstevel@tonic-gate if (error != 0) { 498*0Sstevel@tonic-gate miocnak(q, mp, 0, error); 499*0Sstevel@tonic-gate return; 500*0Sstevel@tonic-gate } 501*0Sstevel@tonic-gate tp->t_new_ltchars = *((struct ltchars *)mp->b_cont->b_rptr); 502*0Sstevel@tonic-gate goto dogets; 503*0Sstevel@tonic-gate 504*0Sstevel@tonic-gate case TIOCLBIS: 505*0Sstevel@tonic-gate case TIOCLBIC: 506*0Sstevel@tonic-gate case TIOCLSET: 507*0Sstevel@tonic-gate error = miocpullup(mp, sizeof (int)); 508*0Sstevel@tonic-gate if (error != 0) { 509*0Sstevel@tonic-gate miocnak(q, mp, 0, error); 510*0Sstevel@tonic-gate return; 511*0Sstevel@tonic-gate } 512*0Sstevel@tonic-gate tp->t_new_lflags = *(int *)mp->b_cont->b_rptr; 513*0Sstevel@tonic-gate goto dogets; 514*0Sstevel@tonic-gate 515*0Sstevel@tonic-gate /* 516*0Sstevel@tonic-gate * "set"-style call that sets a particular bit in a "termios" 517*0Sstevel@tonic-gate * structure. We then have to get the current state, so we 518*0Sstevel@tonic-gate * turn this guy into a TCGETS and pass it down. When the 519*0Sstevel@tonic-gate * ACK comes back, we modify the state we got back and shove it 520*0Sstevel@tonic-gate * back down as the appropriate type of TCSETS. 521*0Sstevel@tonic-gate */ 522*0Sstevel@tonic-gate case TIOCHPCL: 523*0Sstevel@tonic-gate dogets: 524*0Sstevel@tonic-gate tp->t_ioccmd = iocp->ioc_cmd; 525*0Sstevel@tonic-gate tp->t_iocid = iocp->ioc_id; 526*0Sstevel@tonic-gate tp->t_state |= TS_IOCWAIT; 527*0Sstevel@tonic-gate iocp->ioc_cmd = TCGETS; 528*0Sstevel@tonic-gate iocp->ioc_count = 0; /* no data returned unless we say so */ 529*0Sstevel@tonic-gate break; 530*0Sstevel@tonic-gate 531*0Sstevel@tonic-gate /* 532*0Sstevel@tonic-gate * "set"-style call that sets DTR. Pretend that it was a TIOCMBIS 533*0Sstevel@tonic-gate * with TIOCM_DTR set. 534*0Sstevel@tonic-gate */ 535*0Sstevel@tonic-gate case TIOCSDTR: { 536*0Sstevel@tonic-gate mblk_t *datap; 537*0Sstevel@tonic-gate 538*0Sstevel@tonic-gate if ((datap = allocb(sizeof (int), BPRI_HI)) == NULL) 539*0Sstevel@tonic-gate goto allocfailure; 540*0Sstevel@tonic-gate *(int *)datap->b_wptr = TIOCM_DTR; 541*0Sstevel@tonic-gate datap->b_wptr += sizeof (int); 542*0Sstevel@tonic-gate iocp->ioc_cmd = TIOCMBIS; /* turn it into a TIOCMBIS */ 543*0Sstevel@tonic-gate if (mp->b_cont != NULL) 544*0Sstevel@tonic-gate freemsg(mp->b_cont); 545*0Sstevel@tonic-gate mp->b_cont = datap; /* attach the data */ 546*0Sstevel@tonic-gate iocp->ioc_count = sizeof (int); /* in case driver checks */ 547*0Sstevel@tonic-gate break; 548*0Sstevel@tonic-gate } 549*0Sstevel@tonic-gate 550*0Sstevel@tonic-gate /* 551*0Sstevel@tonic-gate * "set"-style call that clears DTR. Pretend that it was a TIOCMBIC 552*0Sstevel@tonic-gate * with TIOCM_DTR set. 553*0Sstevel@tonic-gate */ 554*0Sstevel@tonic-gate case TIOCCDTR: { 555*0Sstevel@tonic-gate mblk_t *datap; 556*0Sstevel@tonic-gate 557*0Sstevel@tonic-gate if ((datap = allocb(sizeof (int), BPRI_HI)) == NULL) 558*0Sstevel@tonic-gate goto allocfailure; 559*0Sstevel@tonic-gate *(int *)datap->b_wptr = TIOCM_DTR; 560*0Sstevel@tonic-gate datap->b_wptr += sizeof (int); 561*0Sstevel@tonic-gate iocp->ioc_cmd = TIOCMBIC; /* turn it into a TIOCMBIC */ 562*0Sstevel@tonic-gate if (mp->b_cont != NULL) 563*0Sstevel@tonic-gate freemsg(mp->b_cont); 564*0Sstevel@tonic-gate mp->b_cont = datap; /* attach the data */ 565*0Sstevel@tonic-gate iocp->ioc_count = sizeof (int); /* in case driver checks */ 566*0Sstevel@tonic-gate break; 567*0Sstevel@tonic-gate } 568*0Sstevel@tonic-gate 569*0Sstevel@tonic-gate /* 570*0Sstevel@tonic-gate * Translate into the S5 form of TCFLSH. 571*0Sstevel@tonic-gate */ 572*0Sstevel@tonic-gate case TIOCFLUSH: { 573*0Sstevel@tonic-gate int flags; 574*0Sstevel@tonic-gate 575*0Sstevel@tonic-gate error = miocpullup(mp, sizeof (int)); 576*0Sstevel@tonic-gate if (error != 0) { 577*0Sstevel@tonic-gate miocnak(q, mp, 0, error); 578*0Sstevel@tonic-gate return; 579*0Sstevel@tonic-gate } 580*0Sstevel@tonic-gate flags = *(int *)mp->b_cont->b_rptr; 581*0Sstevel@tonic-gate 582*0Sstevel@tonic-gate switch (flags&(FREAD|FWRITE)) { 583*0Sstevel@tonic-gate 584*0Sstevel@tonic-gate case 0: 585*0Sstevel@tonic-gate case FREAD|FWRITE: 586*0Sstevel@tonic-gate flags = 2; /* flush 'em both */ 587*0Sstevel@tonic-gate break; 588*0Sstevel@tonic-gate 589*0Sstevel@tonic-gate case FREAD: 590*0Sstevel@tonic-gate flags = 0; /* flush read */ 591*0Sstevel@tonic-gate break; 592*0Sstevel@tonic-gate 593*0Sstevel@tonic-gate case FWRITE: 594*0Sstevel@tonic-gate flags = 1; /* flush write */ 595*0Sstevel@tonic-gate break; 596*0Sstevel@tonic-gate } 597*0Sstevel@tonic-gate iocp->ioc_cmd = TCFLSH; /* turn it into a TCFLSH */ 598*0Sstevel@tonic-gate *(int *)mp->b_cont->b_rptr = flags; /* fiddle the arg */ 599*0Sstevel@tonic-gate break; 600*0Sstevel@tonic-gate } 601*0Sstevel@tonic-gate 602*0Sstevel@tonic-gate /* 603*0Sstevel@tonic-gate * Turn into a TCXONC. 604*0Sstevel@tonic-gate */ 605*0Sstevel@tonic-gate case TIOCSTOP: { 606*0Sstevel@tonic-gate mblk_t *datap; 607*0Sstevel@tonic-gate 608*0Sstevel@tonic-gate if ((datap = allocb(sizeof (int), BPRI_HI)) == NULL) 609*0Sstevel@tonic-gate goto allocfailure; 610*0Sstevel@tonic-gate *(int *)datap->b_wptr = 0; /* stop */ 611*0Sstevel@tonic-gate datap->b_wptr += sizeof (int); 612*0Sstevel@tonic-gate iocp->ioc_cmd = TCXONC; /* turn it into a XONC */ 613*0Sstevel@tonic-gate iocp->ioc_count = sizeof (int); 614*0Sstevel@tonic-gate if (mp->b_cont != NULL) 615*0Sstevel@tonic-gate freemsg(mp->b_cont); 616*0Sstevel@tonic-gate mp->b_cont = datap; /* attach the data */ 617*0Sstevel@tonic-gate break; 618*0Sstevel@tonic-gate } 619*0Sstevel@tonic-gate 620*0Sstevel@tonic-gate case TIOCSTART: { 621*0Sstevel@tonic-gate mblk_t *datap; 622*0Sstevel@tonic-gate 623*0Sstevel@tonic-gate if ((datap = allocb(sizeof (int), BPRI_HI)) == NULL) 624*0Sstevel@tonic-gate goto allocfailure; 625*0Sstevel@tonic-gate *(int *)datap->b_wptr = 1; /* start */ 626*0Sstevel@tonic-gate datap->b_wptr += sizeof (int); 627*0Sstevel@tonic-gate iocp->ioc_cmd = TCXONC; /* turn it into a XONC */ 628*0Sstevel@tonic-gate iocp->ioc_count = sizeof (int); 629*0Sstevel@tonic-gate if (mp->b_cont != NULL) 630*0Sstevel@tonic-gate freemsg(mp->b_cont); 631*0Sstevel@tonic-gate mp->b_cont = datap; /* attach the data */ 632*0Sstevel@tonic-gate break; 633*0Sstevel@tonic-gate } 634*0Sstevel@tonic-gate case TIOCSETD: 635*0Sstevel@tonic-gate case TIOCGETD: 636*0Sstevel@tonic-gate case DIOCSETP: 637*0Sstevel@tonic-gate case DIOCGETP: 638*0Sstevel@tonic-gate case LDOPEN: 639*0Sstevel@tonic-gate case LDCLOSE: 640*0Sstevel@tonic-gate case LDCHG: 641*0Sstevel@tonic-gate case LDSETT: 642*0Sstevel@tonic-gate case LDGETT: 643*0Sstevel@tonic-gate /* 644*0Sstevel@tonic-gate * All of these ioctls are just ACK'd, except for 645*0Sstevel@tonic-gate * TIOCSETD, which must be for line discipline zero. 646*0Sstevel@tonic-gate */ 647*0Sstevel@tonic-gate mp->b_datap->db_type = M_IOCACK; 648*0Sstevel@tonic-gate if (iocp->ioc_cmd == TIOCSETD) { 649*0Sstevel@tonic-gate iocp->ioc_error = miocpullup(mp, sizeof (uchar_t)); 650*0Sstevel@tonic-gate if (iocp->ioc_error == 0 && (*mp->b_cont->b_rptr != 0)) 651*0Sstevel@tonic-gate mp->b_datap->db_type = M_IOCNAK; 652*0Sstevel@tonic-gate } 653*0Sstevel@tonic-gate 654*0Sstevel@tonic-gate iocp->ioc_error = 0; 655*0Sstevel@tonic-gate iocp->ioc_count = 0; 656*0Sstevel@tonic-gate iocp->ioc_rval = 0; 657*0Sstevel@tonic-gate qreply(q, mp); 658*0Sstevel@tonic-gate return; 659*0Sstevel@tonic-gate case IOCTYPE: 660*0Sstevel@tonic-gate mp->b_datap->db_type = M_IOCACK; 661*0Sstevel@tonic-gate iocp->ioc_error = 0; 662*0Sstevel@tonic-gate iocp->ioc_count = 0; 663*0Sstevel@tonic-gate iocp->ioc_rval = TIOC; 664*0Sstevel@tonic-gate qreply(q, mp); 665*0Sstevel@tonic-gate return; 666*0Sstevel@tonic-gate case TIOCEXCL: 667*0Sstevel@tonic-gate /* check for binary value of XCLUDE flag ???? */ 668*0Sstevel@tonic-gate tp->t_new_lflags |= XCLUDE; 669*0Sstevel@tonic-gate mp->b_datap->db_type = M_IOCACK; 670*0Sstevel@tonic-gate iocp->ioc_error = 0; 671*0Sstevel@tonic-gate iocp->ioc_count = 0; 672*0Sstevel@tonic-gate iocp->ioc_rval = 0; 673*0Sstevel@tonic-gate qreply(q, mp); 674*0Sstevel@tonic-gate return; 675*0Sstevel@tonic-gate case TIOCNXCL: 676*0Sstevel@tonic-gate tp->t_new_lflags &= ~XCLUDE; 677*0Sstevel@tonic-gate mp->b_datap->db_type = M_IOCACK; 678*0Sstevel@tonic-gate iocp->ioc_error = 0; 679*0Sstevel@tonic-gate iocp->ioc_count = 0; 680*0Sstevel@tonic-gate iocp->ioc_rval = 0; 681*0Sstevel@tonic-gate qreply(q, mp); 682*0Sstevel@tonic-gate return; 683*0Sstevel@tonic-gate } 684*0Sstevel@tonic-gate 685*0Sstevel@tonic-gate /* 686*0Sstevel@tonic-gate * We don't reply to most calls, we just pass them down, 687*0Sstevel@tonic-gate * possibly after modifying the arguments. 688*0Sstevel@tonic-gate */ 689*0Sstevel@tonic-gate putnext(q, mp); 690*0Sstevel@tonic-gate return; 691*0Sstevel@tonic-gate 692*0Sstevel@tonic-gate allocfailure: 693*0Sstevel@tonic-gate /* 694*0Sstevel@tonic-gate * We needed to allocate something to handle this "ioctl", but 695*0Sstevel@tonic-gate * couldn't; save this "ioctl" and arrange to get called back when 696*0Sstevel@tonic-gate * it's more likely that we can get what we need. 697*0Sstevel@tonic-gate * If there's already one being saved, throw it out, since it 698*0Sstevel@tonic-gate * must have timed out. 699*0Sstevel@tonic-gate */ 700*0Sstevel@tonic-gate if (tp->t_iocpending != NULL) 701*0Sstevel@tonic-gate freemsg(tp->t_iocpending); 702*0Sstevel@tonic-gate tp->t_iocpending = mp; /* hold this ioctl */ 703*0Sstevel@tonic-gate if (tp->t_bufcallid != 0) 704*0Sstevel@tonic-gate qunbufcall(q, tp->t_bufcallid); 705*0Sstevel@tonic-gate 706*0Sstevel@tonic-gate tp->t_bufcallid = qbufcall(q, sizeof (struct iocblk), BPRI_HI, 707*0Sstevel@tonic-gate ttcompat_reioctl, q); 708*0Sstevel@tonic-gate } 709*0Sstevel@tonic-gate 710*0Sstevel@tonic-gate /* 711*0Sstevel@tonic-gate * Called when an M_IOCACK message is seen on the read queue; if this 712*0Sstevel@tonic-gate * is the response we were waiting for, we either: 713*0Sstevel@tonic-gate * modify the data going up (if the "ioctl" read data); since in all 714*0Sstevel@tonic-gate * cases, the old-style returned information is smaller than or the same 715*0Sstevel@tonic-gate * size as the new-style returned information, we just overwrite the old 716*0Sstevel@tonic-gate * stuff with the new stuff (beware of changing structure sizes, in case 717*0Sstevel@tonic-gate * you invalidate this) 718*0Sstevel@tonic-gate * or 719*0Sstevel@tonic-gate * take this data, modify it appropriately, and send it back down (if 720*0Sstevel@tonic-gate * the "ioctl" wrote data). 721*0Sstevel@tonic-gate * In either case, we cancel the "wait"; the final response to a "write" 722*0Sstevel@tonic-gate * ioctl goes back up to the user. 723*0Sstevel@tonic-gate * If this wasn't the response we were waiting for, just pass it up. 724*0Sstevel@tonic-gate */ 725*0Sstevel@tonic-gate static void 726*0Sstevel@tonic-gate ttcompat_ioctl_ack(queue_t *q, mblk_t *mp) 727*0Sstevel@tonic-gate { 728*0Sstevel@tonic-gate ttcompat_state_t *tp; 729*0Sstevel@tonic-gate struct iocblk *iocp; 730*0Sstevel@tonic-gate mblk_t *datap; 731*0Sstevel@tonic-gate 732*0Sstevel@tonic-gate tp = (ttcompat_state_t *)q->q_ptr; 733*0Sstevel@tonic-gate iocp = (struct iocblk *)mp->b_rptr; 734*0Sstevel@tonic-gate 735*0Sstevel@tonic-gate if (!(tp->t_state&TS_IOCWAIT) || iocp->ioc_id != tp->t_iocid) { 736*0Sstevel@tonic-gate /* 737*0Sstevel@tonic-gate * This isn't the reply we're looking for. Move along. 738*0Sstevel@tonic-gate */ 739*0Sstevel@tonic-gate putnext(q, mp); 740*0Sstevel@tonic-gate return; 741*0Sstevel@tonic-gate } 742*0Sstevel@tonic-gate 743*0Sstevel@tonic-gate datap = mp->b_cont; /* mblk containing data going up */ 744*0Sstevel@tonic-gate 745*0Sstevel@tonic-gate switch (tp->t_ioccmd) { 746*0Sstevel@tonic-gate 747*0Sstevel@tonic-gate case TIOCGETP: { 748*0Sstevel@tonic-gate struct sgttyb *cb; 749*0Sstevel@tonic-gate 750*0Sstevel@tonic-gate to_compat((struct termios *)datap->b_rptr, &tp->t_curstate); 751*0Sstevel@tonic-gate datap->b_rptr = datap->b_wptr = datap->b_datap->db_base; 752*0Sstevel@tonic-gate /* recycle the reply's buffer */ 753*0Sstevel@tonic-gate cb = (struct sgttyb *)datap->b_wptr; 754*0Sstevel@tonic-gate /* 755*0Sstevel@tonic-gate * This is used for TIOCGETP handling of sg_ispeed and 756*0Sstevel@tonic-gate * sg_ospeed. If the current speed is over 38400 (the 757*0Sstevel@tonic-gate * sgttyb limit), then we report 38400. Note that 758*0Sstevel@tonic-gate * when "compatibility with old releases" is enabled 759*0Sstevel@tonic-gate * (sgttyb_handling == 0), then t_[io]speed will have 760*0Sstevel@tonic-gate * garbled nonsense, as in prior releases. (See 761*0Sstevel@tonic-gate * to_compat() below). 762*0Sstevel@tonic-gate */ 763*0Sstevel@tonic-gate cb->sg_ispeed = tp->t_curstate.t_ispeed > B38400 ? B38400 : 764*0Sstevel@tonic-gate tp->t_curstate.t_ispeed; 765*0Sstevel@tonic-gate cb->sg_ospeed = tp->t_curstate.t_ospeed > B38400 ? B38400 : 766*0Sstevel@tonic-gate tp->t_curstate.t_ospeed; 767*0Sstevel@tonic-gate cb->sg_erase = tp->t_curstate.t_erase; 768*0Sstevel@tonic-gate cb->sg_kill = tp->t_curstate.t_kill; 769*0Sstevel@tonic-gate cb->sg_flags = tp->t_curstate.t_flags; 770*0Sstevel@tonic-gate datap->b_wptr += sizeof (struct sgttyb); 771*0Sstevel@tonic-gate iocp->ioc_count = sizeof (struct sgttyb); 772*0Sstevel@tonic-gate 773*0Sstevel@tonic-gate /* you are lucky - stream head knows how to copy you out */ 774*0Sstevel@tonic-gate 775*0Sstevel@tonic-gate tp->t_state &= ~TS_IOCWAIT; /* we got what we wanted */ 776*0Sstevel@tonic-gate iocp->ioc_rval = 0; 777*0Sstevel@tonic-gate iocp->ioc_cmd = tp->t_ioccmd; 778*0Sstevel@tonic-gate putnext(q, mp); 779*0Sstevel@tonic-gate return; 780*0Sstevel@tonic-gate } 781*0Sstevel@tonic-gate 782*0Sstevel@tonic-gate case TIOCGETC: 783*0Sstevel@tonic-gate to_compat((struct termios *)datap->b_rptr, &tp->t_curstate); 784*0Sstevel@tonic-gate datap->b_rptr = datap->b_wptr = datap->b_datap->db_base; 785*0Sstevel@tonic-gate /* recycle the reply's buffer */ 786*0Sstevel@tonic-gate bcopy(&tp->t_curstate.t_intrc, datap->b_wptr, 787*0Sstevel@tonic-gate sizeof (struct tchars)); 788*0Sstevel@tonic-gate datap->b_wptr += sizeof (struct tchars); 789*0Sstevel@tonic-gate break; 790*0Sstevel@tonic-gate 791*0Sstevel@tonic-gate case TIOCGLTC: 792*0Sstevel@tonic-gate to_compat((struct termios *)datap->b_rptr, &tp->t_curstate); 793*0Sstevel@tonic-gate datap->b_rptr = datap->b_wptr = datap->b_datap->db_base; 794*0Sstevel@tonic-gate /* recycle the reply's buffer */ 795*0Sstevel@tonic-gate bcopy(&tp->t_curstate.t_suspc, datap->b_wptr, 796*0Sstevel@tonic-gate sizeof (struct ltchars)); 797*0Sstevel@tonic-gate datap->b_wptr += sizeof (struct ltchars); 798*0Sstevel@tonic-gate break; 799*0Sstevel@tonic-gate 800*0Sstevel@tonic-gate case TIOCLGET: 801*0Sstevel@tonic-gate to_compat((struct termios *)datap->b_rptr, &tp->t_curstate); 802*0Sstevel@tonic-gate datap->b_rptr = datap->b_wptr = datap->b_datap->db_base; 803*0Sstevel@tonic-gate /* recycle the reply's buffer */ 804*0Sstevel@tonic-gate *(int *)datap->b_wptr = 805*0Sstevel@tonic-gate ((unsigned)tp->t_curstate.t_flags) >> 16; 806*0Sstevel@tonic-gate datap->b_wptr += sizeof (int); 807*0Sstevel@tonic-gate break; 808*0Sstevel@tonic-gate 809*0Sstevel@tonic-gate case TIOCSETP: 810*0Sstevel@tonic-gate case TIOCSETN: 811*0Sstevel@tonic-gate /* 812*0Sstevel@tonic-gate * Get the current state from the GETS data, and 813*0Sstevel@tonic-gate * update it. 814*0Sstevel@tonic-gate */ 815*0Sstevel@tonic-gate to_compat((struct termios *)datap->b_rptr, &tp->t_curstate); 816*0Sstevel@tonic-gate tp->t_curstate.t_erase = tp->t_new_sgttyb.sg_erase; 817*0Sstevel@tonic-gate tp->t_curstate.t_kill = tp->t_new_sgttyb.sg_kill; 818*0Sstevel@tonic-gate /* 819*0Sstevel@tonic-gate * For new-style handling, we ignore requests to set 820*0Sstevel@tonic-gate * B38400 when the current speed is over B38400. This 821*0Sstevel@tonic-gate * means that we change the speed as requested if: 822*0Sstevel@tonic-gate * old style (sgttyb_handling == 0) is requested 823*0Sstevel@tonic-gate * the requested new speed isn't B38400 824*0Sstevel@tonic-gate * the current speed is at or below B38400 825*0Sstevel@tonic-gate * Note that when old style is requested, both speeds 826*0Sstevel@tonic-gate * in t_curstate are set to <= B38400 by to_compat, so 827*0Sstevel@tonic-gate * the first test isn't needed here. 828*0Sstevel@tonic-gate * Also note that we silently allow the user to set 829*0Sstevel@tonic-gate * speeds above B38400 through this interface, 830*0Sstevel@tonic-gate * regardless of the style setting. This allows 831*0Sstevel@tonic-gate * greater compatibility with current BSD releases. 832*0Sstevel@tonic-gate */ 833*0Sstevel@tonic-gate if (tp->t_new_sgttyb.sg_ispeed != B38400 || 834*0Sstevel@tonic-gate tp->t_curstate.t_ispeed <= B38400) 835*0Sstevel@tonic-gate tp->t_curstate.t_ispeed = tp->t_new_sgttyb.sg_ispeed; 836*0Sstevel@tonic-gate if (tp->t_new_sgttyb.sg_ospeed != B38400 || 837*0Sstevel@tonic-gate tp->t_curstate.t_ospeed <= B38400) 838*0Sstevel@tonic-gate tp->t_curstate.t_ospeed = tp->t_new_sgttyb.sg_ospeed; 839*0Sstevel@tonic-gate tp->t_curstate.t_flags = 840*0Sstevel@tonic-gate (tp->t_curstate.t_flags & 0xffff0000) | 841*0Sstevel@tonic-gate (tp->t_new_sgttyb.sg_flags & 0xffff); 842*0Sstevel@tonic-gate 843*0Sstevel@tonic-gate /* 844*0Sstevel@tonic-gate * Replace the data that came up with the updated data. 845*0Sstevel@tonic-gate */ 846*0Sstevel@tonic-gate from_compat(&tp->t_curstate, (struct termios *)datap->b_rptr); 847*0Sstevel@tonic-gate 848*0Sstevel@tonic-gate /* 849*0Sstevel@tonic-gate * Send it back down as a TCSETS or TCSETSF. 850*0Sstevel@tonic-gate */ 851*0Sstevel@tonic-gate iocp->ioc_cmd = (tp->t_ioccmd == TIOCSETP) ? TCSETSF : TCSETS; 852*0Sstevel@tonic-gate goto senddown; 853*0Sstevel@tonic-gate 854*0Sstevel@tonic-gate case TIOCSETC: 855*0Sstevel@tonic-gate /* 856*0Sstevel@tonic-gate * Get the current state from the GETS data, and 857*0Sstevel@tonic-gate * update it. 858*0Sstevel@tonic-gate */ 859*0Sstevel@tonic-gate to_compat((struct termios *)datap->b_rptr, &tp->t_curstate); 860*0Sstevel@tonic-gate bcopy(&tp->t_new_tchars, 861*0Sstevel@tonic-gate &tp->t_curstate.t_intrc, sizeof (struct tchars)); 862*0Sstevel@tonic-gate 863*0Sstevel@tonic-gate /* 864*0Sstevel@tonic-gate * Replace the data that came up with the updated data. 865*0Sstevel@tonic-gate */ 866*0Sstevel@tonic-gate from_compat(&tp->t_curstate, (struct termios *)datap->b_rptr); 867*0Sstevel@tonic-gate 868*0Sstevel@tonic-gate /* 869*0Sstevel@tonic-gate * Send it back down as a TCSETS. 870*0Sstevel@tonic-gate */ 871*0Sstevel@tonic-gate iocp->ioc_cmd = TCSETS; 872*0Sstevel@tonic-gate goto senddown; 873*0Sstevel@tonic-gate 874*0Sstevel@tonic-gate case TIOCSLTC: 875*0Sstevel@tonic-gate /* 876*0Sstevel@tonic-gate * Get the current state from the GETS data, and 877*0Sstevel@tonic-gate * update it. 878*0Sstevel@tonic-gate */ 879*0Sstevel@tonic-gate to_compat((struct termios *)datap->b_rptr, &tp->t_curstate); 880*0Sstevel@tonic-gate bcopy(&tp->t_new_ltchars, 881*0Sstevel@tonic-gate &tp->t_curstate.t_suspc, sizeof (struct ltchars)); 882*0Sstevel@tonic-gate 883*0Sstevel@tonic-gate /* 884*0Sstevel@tonic-gate * Replace the data that came up with the updated data. 885*0Sstevel@tonic-gate */ 886*0Sstevel@tonic-gate from_compat(&tp->t_curstate, (struct termios *)datap->b_rptr); 887*0Sstevel@tonic-gate 888*0Sstevel@tonic-gate /* 889*0Sstevel@tonic-gate * Send it back down as a TCSETS. 890*0Sstevel@tonic-gate */ 891*0Sstevel@tonic-gate iocp->ioc_cmd = TCSETS; 892*0Sstevel@tonic-gate goto senddown; 893*0Sstevel@tonic-gate 894*0Sstevel@tonic-gate case TIOCLBIS: 895*0Sstevel@tonic-gate /* 896*0Sstevel@tonic-gate * Get the current state from the GETS data, and 897*0Sstevel@tonic-gate * update it. 898*0Sstevel@tonic-gate */ 899*0Sstevel@tonic-gate to_compat((struct termios *)datap->b_rptr, &tp->t_curstate); 900*0Sstevel@tonic-gate tp->t_curstate.t_flags |= (tp->t_new_lflags << 16); 901*0Sstevel@tonic-gate 902*0Sstevel@tonic-gate /* 903*0Sstevel@tonic-gate * Replace the data that came up with the updated data. 904*0Sstevel@tonic-gate */ 905*0Sstevel@tonic-gate from_compat(&tp->t_curstate, (struct termios *)datap->b_rptr); 906*0Sstevel@tonic-gate 907*0Sstevel@tonic-gate /* 908*0Sstevel@tonic-gate * Send it back down as a TCSETS. 909*0Sstevel@tonic-gate */ 910*0Sstevel@tonic-gate iocp->ioc_cmd = TCSETS; 911*0Sstevel@tonic-gate goto senddown; 912*0Sstevel@tonic-gate 913*0Sstevel@tonic-gate case TIOCLBIC: 914*0Sstevel@tonic-gate /* 915*0Sstevel@tonic-gate * Get the current state from the GETS data, and 916*0Sstevel@tonic-gate * update it. 917*0Sstevel@tonic-gate */ 918*0Sstevel@tonic-gate to_compat((struct termios *)datap->b_rptr, &tp->t_curstate); 919*0Sstevel@tonic-gate tp->t_curstate.t_flags &= ~(tp->t_new_lflags << 16); 920*0Sstevel@tonic-gate 921*0Sstevel@tonic-gate /* 922*0Sstevel@tonic-gate * Replace the data that came up with the updated data. 923*0Sstevel@tonic-gate */ 924*0Sstevel@tonic-gate from_compat(&tp->t_curstate, (struct termios *)datap->b_rptr); 925*0Sstevel@tonic-gate 926*0Sstevel@tonic-gate /* 927*0Sstevel@tonic-gate * Send it back down as a TCSETS. 928*0Sstevel@tonic-gate */ 929*0Sstevel@tonic-gate iocp->ioc_cmd = TCSETS; 930*0Sstevel@tonic-gate goto senddown; 931*0Sstevel@tonic-gate 932*0Sstevel@tonic-gate case TIOCLSET: 933*0Sstevel@tonic-gate /* 934*0Sstevel@tonic-gate * Get the current state from the GETS data, and 935*0Sstevel@tonic-gate * update it. 936*0Sstevel@tonic-gate */ 937*0Sstevel@tonic-gate to_compat((struct termios *)datap->b_rptr, &tp->t_curstate); 938*0Sstevel@tonic-gate tp->t_curstate.t_flags &= 0xffff; 939*0Sstevel@tonic-gate tp->t_curstate.t_flags |= (tp->t_new_lflags << 16); 940*0Sstevel@tonic-gate 941*0Sstevel@tonic-gate /* 942*0Sstevel@tonic-gate * Replace the data that came up with the updated data. 943*0Sstevel@tonic-gate */ 944*0Sstevel@tonic-gate from_compat(&tp->t_curstate, (struct termios *)datap->b_rptr); 945*0Sstevel@tonic-gate 946*0Sstevel@tonic-gate /* 947*0Sstevel@tonic-gate * Send it back down as a TCSETS. 948*0Sstevel@tonic-gate */ 949*0Sstevel@tonic-gate iocp->ioc_cmd = TCSETS; 950*0Sstevel@tonic-gate goto senddown; 951*0Sstevel@tonic-gate 952*0Sstevel@tonic-gate case TIOCHPCL: 953*0Sstevel@tonic-gate /* 954*0Sstevel@tonic-gate * Replace the data that came up with the updated data. 955*0Sstevel@tonic-gate */ 956*0Sstevel@tonic-gate ((struct termios *)datap->b_rptr)->c_cflag |= HUPCL; 957*0Sstevel@tonic-gate 958*0Sstevel@tonic-gate /* 959*0Sstevel@tonic-gate * Send it back down as a TCSETS. 960*0Sstevel@tonic-gate */ 961*0Sstevel@tonic-gate iocp->ioc_cmd = TCSETS; 962*0Sstevel@tonic-gate goto senddown; 963*0Sstevel@tonic-gate 964*0Sstevel@tonic-gate default: 965*0Sstevel@tonic-gate cmn_err(CE_WARN, "ttcompat: Unexpected ioctl acknowledgment\n"); 966*0Sstevel@tonic-gate } 967*0Sstevel@tonic-gate 968*0Sstevel@tonic-gate /* 969*0Sstevel@tonic-gate * All the calls that return something return 0. 970*0Sstevel@tonic-gate */ 971*0Sstevel@tonic-gate tp->t_state &= ~TS_IOCWAIT; /* we got what we wanted */ 972*0Sstevel@tonic-gate iocp->ioc_rval = 0; 973*0Sstevel@tonic-gate 974*0Sstevel@tonic-gate /* copy out the data - ioctl transparency */ 975*0Sstevel@tonic-gate iocp->ioc_cmd = tp->t_ioccmd; 976*0Sstevel@tonic-gate ttcopyout(q, mp); 977*0Sstevel@tonic-gate return; 978*0Sstevel@tonic-gate 979*0Sstevel@tonic-gate senddown: 980*0Sstevel@tonic-gate /* 981*0Sstevel@tonic-gate * Send a "get state" reply back down, with suitably-modified 982*0Sstevel@tonic-gate * state, as a "set state" "ioctl". 983*0Sstevel@tonic-gate */ 984*0Sstevel@tonic-gate tp->t_state &= ~TS_IOCWAIT; 985*0Sstevel@tonic-gate mp->b_datap->db_type = M_IOCTL; 986*0Sstevel@tonic-gate mp->b_wptr = mp->b_rptr + sizeof (struct iocblk); 987*0Sstevel@tonic-gate putnext(WR(q), mp); 988*0Sstevel@tonic-gate } 989*0Sstevel@tonic-gate /* Called from ttcompatrput M_IOCACK processing. */ 990*0Sstevel@tonic-gate /* Copies out the data using M_COPYOUT messages */ 991*0Sstevel@tonic-gate 992*0Sstevel@tonic-gate static void 993*0Sstevel@tonic-gate ttcopyout(queue_t *q, mblk_t *mp) 994*0Sstevel@tonic-gate { 995*0Sstevel@tonic-gate struct copyreq *cqp; 996*0Sstevel@tonic-gate ttcompat_state_t *tp; 997*0Sstevel@tonic-gate 998*0Sstevel@tonic-gate tp = (ttcompat_state_t *)q->q_ptr; 999*0Sstevel@tonic-gate 1000*0Sstevel@tonic-gate mp->b_datap->db_type = M_COPYOUT; 1001*0Sstevel@tonic-gate cqp = (struct copyreq *)mp->b_rptr; 1002*0Sstevel@tonic-gate cqp->cq_addr = (caddr_t)tp->t_arg; /* retrieve the 3rd argument */ 1003*0Sstevel@tonic-gate tp->t_arg = 0; /* clear it since we don't need it anymore */ 1004*0Sstevel@tonic-gate switch (tp->t_ioccmd) { 1005*0Sstevel@tonic-gate case TIOCGLTC: 1006*0Sstevel@tonic-gate cqp->cq_size = sizeof (struct ltchars); 1007*0Sstevel@tonic-gate break; 1008*0Sstevel@tonic-gate case TIOCGETC: 1009*0Sstevel@tonic-gate cqp->cq_size = sizeof (struct tchars); 1010*0Sstevel@tonic-gate break; 1011*0Sstevel@tonic-gate case TIOCLGET: 1012*0Sstevel@tonic-gate cqp->cq_size = sizeof (int); 1013*0Sstevel@tonic-gate break; 1014*0Sstevel@tonic-gate default: 1015*0Sstevel@tonic-gate cmn_err(CE_WARN, 1016*0Sstevel@tonic-gate "ttcompat: Unknown ioctl to copyout\n"); 1017*0Sstevel@tonic-gate break; 1018*0Sstevel@tonic-gate } 1019*0Sstevel@tonic-gate cqp->cq_flag = 0; 1020*0Sstevel@tonic-gate cqp->cq_private = NULL; 1021*0Sstevel@tonic-gate tp->t_state |= TS_W_OUT; 1022*0Sstevel@tonic-gate putnext(q, mp); 1023*0Sstevel@tonic-gate } 1024*0Sstevel@tonic-gate 1025*0Sstevel@tonic-gate 1026*0Sstevel@tonic-gate /* 1027*0Sstevel@tonic-gate * Called when an M_IOCNAK message is seen on the read queue; if this is 1028*0Sstevel@tonic-gate * the response we were waiting for, cancel the wait. Pass the reply up; 1029*0Sstevel@tonic-gate * if we were waiting for this response, we can't complete the "ioctl" and 1030*0Sstevel@tonic-gate * the NAK will tell that to the guy above us. 1031*0Sstevel@tonic-gate * If this wasn't the response we were waiting for, just pass it up. 1032*0Sstevel@tonic-gate */ 1033*0Sstevel@tonic-gate static void 1034*0Sstevel@tonic-gate ttcompat_ioctl_nak(queue_t *q, mblk_t *mp) 1035*0Sstevel@tonic-gate { 1036*0Sstevel@tonic-gate ttcompat_state_t *tp; 1037*0Sstevel@tonic-gate struct iocblk *iocp; 1038*0Sstevel@tonic-gate 1039*0Sstevel@tonic-gate iocp = (struct iocblk *)mp->b_rptr; 1040*0Sstevel@tonic-gate tp = (ttcompat_state_t *)q->q_ptr; 1041*0Sstevel@tonic-gate 1042*0Sstevel@tonic-gate if (tp->t_state&TS_IOCWAIT && iocp->ioc_id == tp->t_iocid) { 1043*0Sstevel@tonic-gate tp->t_state &= ~TS_IOCWAIT; /* this call isn't going through */ 1044*0Sstevel@tonic-gate tp->t_arg = 0; /* we may have stashed the 3rd argument */ 1045*0Sstevel@tonic-gate } 1046*0Sstevel@tonic-gate putnext(q, mp); 1047*0Sstevel@tonic-gate } 1048*0Sstevel@tonic-gate 1049*0Sstevel@tonic-gate #define FROM_COMPAT_CHAR(to, from) { if ((to = from) == 0377) to = 0; } 1050*0Sstevel@tonic-gate 1051*0Sstevel@tonic-gate static void 1052*0Sstevel@tonic-gate from_compat(compat_state_t *csp, struct termios *termiosp) 1053*0Sstevel@tonic-gate { 1054*0Sstevel@tonic-gate termiosp->c_iflag = 0; 1055*0Sstevel@tonic-gate termiosp->c_oflag &= (ONLRET|ONOCR); 1056*0Sstevel@tonic-gate 1057*0Sstevel@tonic-gate termiosp->c_cflag = (termiosp->c_cflag & 1058*0Sstevel@tonic-gate (CRTSCTS|CRTSXOFF|PAREXT|LOBLK|HUPCL)) | CREAD; 1059*0Sstevel@tonic-gate 1060*0Sstevel@tonic-gate if (csp->t_ospeed > CBAUD) { 1061*0Sstevel@tonic-gate termiosp->c_cflag |= ((csp->t_ospeed - CBAUD - 1) & CBAUD) | 1062*0Sstevel@tonic-gate CBAUDEXT; 1063*0Sstevel@tonic-gate } else { 1064*0Sstevel@tonic-gate termiosp->c_cflag |= csp->t_ospeed & CBAUD; 1065*0Sstevel@tonic-gate } 1066*0Sstevel@tonic-gate 1067*0Sstevel@tonic-gate if (csp->t_ospeed != csp->t_ispeed) { 1068*0Sstevel@tonic-gate if (csp->t_ispeed > (CIBAUD >> IBSHIFT)) { 1069*0Sstevel@tonic-gate termiosp->c_cflag |= CIBAUDEXT | 1070*0Sstevel@tonic-gate (((csp->t_ispeed - (CIBAUD >> IBSHIFT) - 1) << 1071*0Sstevel@tonic-gate IBSHIFT) & CIBAUD); 1072*0Sstevel@tonic-gate } else { 1073*0Sstevel@tonic-gate termiosp->c_cflag |= (csp->t_ispeed << IBSHIFT) & 1074*0Sstevel@tonic-gate CIBAUD; 1075*0Sstevel@tonic-gate } 1076*0Sstevel@tonic-gate /* hang up if ispeed=0 */ 1077*0Sstevel@tonic-gate if (csp->t_ispeed == 0) 1078*0Sstevel@tonic-gate termiosp->c_cflag &= ~CBAUD & ~CBAUDEXT; 1079*0Sstevel@tonic-gate } 1080*0Sstevel@tonic-gate if (csp->t_ispeed == B110 || csp->t_xflags & STOPB) 1081*0Sstevel@tonic-gate termiosp->c_cflag |= CSTOPB; 1082*0Sstevel@tonic-gate termiosp->c_lflag = ECHOK; 1083*0Sstevel@tonic-gate FROM_COMPAT_CHAR(termiosp->c_cc[VERASE], csp->t_erase); 1084*0Sstevel@tonic-gate FROM_COMPAT_CHAR(termiosp->c_cc[VKILL], csp->t_kill); 1085*0Sstevel@tonic-gate FROM_COMPAT_CHAR(termiosp->c_cc[VINTR], csp->t_intrc); 1086*0Sstevel@tonic-gate FROM_COMPAT_CHAR(termiosp->c_cc[VQUIT], csp->t_quitc); 1087*0Sstevel@tonic-gate FROM_COMPAT_CHAR(termiosp->c_cc[VSTART], csp->t_startc); 1088*0Sstevel@tonic-gate FROM_COMPAT_CHAR(termiosp->c_cc[VSTOP], csp->t_stopc); 1089*0Sstevel@tonic-gate termiosp->c_cc[VEOL2] = 0; 1090*0Sstevel@tonic-gate FROM_COMPAT_CHAR(termiosp->c_cc[VSUSP], csp->t_suspc); 1091*0Sstevel@tonic-gate /* is this useful? */ 1092*0Sstevel@tonic-gate FROM_COMPAT_CHAR(termiosp->c_cc[VDSUSP], csp->t_dsuspc); 1093*0Sstevel@tonic-gate FROM_COMPAT_CHAR(termiosp->c_cc[VREPRINT], csp->t_rprntc); 1094*0Sstevel@tonic-gate FROM_COMPAT_CHAR(termiosp->c_cc[VDISCARD], csp->t_flushc); 1095*0Sstevel@tonic-gate FROM_COMPAT_CHAR(termiosp->c_cc[VWERASE], csp->t_werasc); 1096*0Sstevel@tonic-gate FROM_COMPAT_CHAR(termiosp->c_cc[VLNEXT], csp->t_lnextc); 1097*0Sstevel@tonic-gate if (csp->t_flags & O_TANDEM) 1098*0Sstevel@tonic-gate termiosp->c_iflag |= IXOFF; 1099*0Sstevel@tonic-gate if (csp->t_flags & O_LCASE) { 1100*0Sstevel@tonic-gate termiosp->c_iflag |= IUCLC; 1101*0Sstevel@tonic-gate termiosp->c_oflag |= OLCUC; 1102*0Sstevel@tonic-gate termiosp->c_lflag |= XCASE; 1103*0Sstevel@tonic-gate } 1104*0Sstevel@tonic-gate if (csp->t_flags & O_ECHO) 1105*0Sstevel@tonic-gate termiosp->c_lflag |= ECHO; 1106*0Sstevel@tonic-gate if (csp->t_flags & O_CRMOD) { 1107*0Sstevel@tonic-gate termiosp->c_iflag |= ICRNL; 1108*0Sstevel@tonic-gate termiosp->c_oflag |= ONLCR; 1109*0Sstevel@tonic-gate switch (csp->t_flags & O_CRDELAY) { 1110*0Sstevel@tonic-gate 1111*0Sstevel@tonic-gate case O_CR1: 1112*0Sstevel@tonic-gate termiosp->c_oflag |= CR2; 1113*0Sstevel@tonic-gate break; 1114*0Sstevel@tonic-gate 1115*0Sstevel@tonic-gate case O_CR2: 1116*0Sstevel@tonic-gate termiosp->c_oflag |= CR3; 1117*0Sstevel@tonic-gate break; 1118*0Sstevel@tonic-gate } 1119*0Sstevel@tonic-gate } else { 1120*0Sstevel@tonic-gate if ((csp->t_flags & O_NLDELAY) == O_NL1) 1121*0Sstevel@tonic-gate termiosp->c_oflag |= ONLRET|CR1; /* tty37 */ 1122*0Sstevel@tonic-gate } 1123*0Sstevel@tonic-gate if ((csp->t_flags & O_NLDELAY) == O_NL2) 1124*0Sstevel@tonic-gate termiosp->c_oflag |= NL1; 1125*0Sstevel@tonic-gate /* 1126*0Sstevel@tonic-gate * When going into RAW mode, the special characters controlled by the 1127*0Sstevel@tonic-gate * POSIX IEXTEN bit no longer apply; when leaving, they do. 1128*0Sstevel@tonic-gate */ 1129*0Sstevel@tonic-gate if (csp->t_flags & O_RAW) { 1130*0Sstevel@tonic-gate termiosp->c_cflag |= CS8; 1131*0Sstevel@tonic-gate termiosp->c_iflag &= ~(ICRNL|IUCLC); 1132*0Sstevel@tonic-gate termiosp->c_lflag &= ~(XCASE|IEXTEN); 1133*0Sstevel@tonic-gate } else { 1134*0Sstevel@tonic-gate termiosp->c_iflag |= IMAXBEL|BRKINT|IGNPAR; 1135*0Sstevel@tonic-gate if (termiosp->c_cc[VSTOP] != 0 && termiosp->c_cc[VSTART] != 0) 1136*0Sstevel@tonic-gate termiosp->c_iflag |= IXON; 1137*0Sstevel@tonic-gate if (csp->t_flags & O_LITOUT) 1138*0Sstevel@tonic-gate termiosp->c_cflag |= CS8; 1139*0Sstevel@tonic-gate else { 1140*0Sstevel@tonic-gate if (csp->t_flags & O_PASS8) 1141*0Sstevel@tonic-gate termiosp->c_cflag |= CS8; 1142*0Sstevel@tonic-gate /* XXX - what about 8 bits plus parity? */ 1143*0Sstevel@tonic-gate else { 1144*0Sstevel@tonic-gate switch (csp->t_flags & (O_EVENP|O_ODDP)) { 1145*0Sstevel@tonic-gate 1146*0Sstevel@tonic-gate case 0: 1147*0Sstevel@tonic-gate termiosp->c_iflag |= ISTRIP; 1148*0Sstevel@tonic-gate termiosp->c_cflag |= CS8; 1149*0Sstevel@tonic-gate break; 1150*0Sstevel@tonic-gate 1151*0Sstevel@tonic-gate case O_EVENP: 1152*0Sstevel@tonic-gate termiosp->c_iflag |= INPCK|ISTRIP; 1153*0Sstevel@tonic-gate termiosp->c_cflag |= CS7|PARENB; 1154*0Sstevel@tonic-gate break; 1155*0Sstevel@tonic-gate 1156*0Sstevel@tonic-gate case O_ODDP: 1157*0Sstevel@tonic-gate termiosp->c_iflag |= INPCK|ISTRIP; 1158*0Sstevel@tonic-gate termiosp->c_cflag |= CS7|PARENB|PARODD; 1159*0Sstevel@tonic-gate break; 1160*0Sstevel@tonic-gate 1161*0Sstevel@tonic-gate case O_EVENP|O_ODDP: 1162*0Sstevel@tonic-gate termiosp->c_iflag |= ISTRIP; 1163*0Sstevel@tonic-gate termiosp->c_cflag |= CS7|PARENB; 1164*0Sstevel@tonic-gate break; 1165*0Sstevel@tonic-gate } 1166*0Sstevel@tonic-gate } 1167*0Sstevel@tonic-gate if (!(csp->t_xflags & NOPOST)) 1168*0Sstevel@tonic-gate termiosp->c_oflag |= OPOST; 1169*0Sstevel@tonic-gate } 1170*0Sstevel@tonic-gate termiosp->c_lflag |= IEXTEN; 1171*0Sstevel@tonic-gate if (!(csp->t_xflags & NOISIG)) 1172*0Sstevel@tonic-gate termiosp->c_lflag |= ISIG; 1173*0Sstevel@tonic-gate if (!(csp->t_flags & O_CBREAK)) 1174*0Sstevel@tonic-gate termiosp->c_lflag |= ICANON; 1175*0Sstevel@tonic-gate if (csp->t_flags & O_CTLECH) 1176*0Sstevel@tonic-gate termiosp->c_lflag |= ECHOCTL; 1177*0Sstevel@tonic-gate } 1178*0Sstevel@tonic-gate switch (csp->t_flags & O_TBDELAY) { 1179*0Sstevel@tonic-gate 1180*0Sstevel@tonic-gate case O_TAB1: 1181*0Sstevel@tonic-gate termiosp->c_oflag |= TAB1; 1182*0Sstevel@tonic-gate break; 1183*0Sstevel@tonic-gate 1184*0Sstevel@tonic-gate case O_TAB2: 1185*0Sstevel@tonic-gate termiosp->c_oflag |= TAB2; 1186*0Sstevel@tonic-gate break; 1187*0Sstevel@tonic-gate 1188*0Sstevel@tonic-gate case O_XTABS: 1189*0Sstevel@tonic-gate termiosp->c_oflag |= TAB3; 1190*0Sstevel@tonic-gate break; 1191*0Sstevel@tonic-gate } 1192*0Sstevel@tonic-gate if (csp->t_flags & O_VTDELAY) 1193*0Sstevel@tonic-gate termiosp->c_oflag |= FFDLY; 1194*0Sstevel@tonic-gate if (csp->t_flags & O_BSDELAY) 1195*0Sstevel@tonic-gate termiosp->c_oflag |= BSDLY; 1196*0Sstevel@tonic-gate if (csp->t_flags & O_PRTERA) 1197*0Sstevel@tonic-gate termiosp->c_lflag |= ECHOPRT; 1198*0Sstevel@tonic-gate if (csp->t_flags & O_CRTERA) 1199*0Sstevel@tonic-gate termiosp->c_lflag |= ECHOE; 1200*0Sstevel@tonic-gate if (csp->t_flags & O_TOSTOP) 1201*0Sstevel@tonic-gate termiosp->c_lflag |= TOSTOP; 1202*0Sstevel@tonic-gate if (csp->t_flags & O_FLUSHO) 1203*0Sstevel@tonic-gate termiosp->c_lflag |= FLUSHO; 1204*0Sstevel@tonic-gate if (csp->t_flags & O_NOHANG) 1205*0Sstevel@tonic-gate termiosp->c_cflag |= CLOCAL; 1206*0Sstevel@tonic-gate if (csp->t_flags & O_CRTKIL) 1207*0Sstevel@tonic-gate termiosp->c_lflag |= ECHOKE; 1208*0Sstevel@tonic-gate if (csp->t_flags & O_PENDIN) 1209*0Sstevel@tonic-gate termiosp->c_lflag |= PENDIN; 1210*0Sstevel@tonic-gate if (!(csp->t_flags & O_DECCTQ)) 1211*0Sstevel@tonic-gate termiosp->c_iflag |= IXANY; 1212*0Sstevel@tonic-gate if (csp->t_flags & O_NOFLSH) 1213*0Sstevel@tonic-gate termiosp->c_lflag |= NOFLSH; 1214*0Sstevel@tonic-gate if (termiosp->c_lflag & ICANON) { 1215*0Sstevel@tonic-gate FROM_COMPAT_CHAR(termiosp->c_cc[VEOF], csp->t_eofc); 1216*0Sstevel@tonic-gate FROM_COMPAT_CHAR(termiosp->c_cc[VEOL], csp->t_brkc); 1217*0Sstevel@tonic-gate } else { 1218*0Sstevel@tonic-gate termiosp->c_cc[VMIN] = 1; 1219*0Sstevel@tonic-gate termiosp->c_cc[VTIME] = 0; 1220*0Sstevel@tonic-gate } 1221*0Sstevel@tonic-gate } 1222*0Sstevel@tonic-gate 1223*0Sstevel@tonic-gate #define TO_COMPAT_CHAR(to, from) { if ((to = from) == 0) to = (uchar_t)0377; } 1224*0Sstevel@tonic-gate 1225*0Sstevel@tonic-gate static void 1226*0Sstevel@tonic-gate to_compat(struct termios *termiosp, compat_state_t *csp) 1227*0Sstevel@tonic-gate { 1228*0Sstevel@tonic-gate csp->t_xflags &= (NOISIG|NOPOST); 1229*0Sstevel@tonic-gate csp->t_ospeed = termiosp->c_cflag & CBAUD; 1230*0Sstevel@tonic-gate csp->t_ispeed = (termiosp->c_cflag & CIBAUD) >> IBSHIFT; 1231*0Sstevel@tonic-gate if (sgttyb_handling > 0) { 1232*0Sstevel@tonic-gate if (termiosp->c_cflag & CBAUDEXT) 1233*0Sstevel@tonic-gate csp->t_ospeed += CBAUD + 1; 1234*0Sstevel@tonic-gate if (termiosp->c_cflag & CIBAUDEXT) 1235*0Sstevel@tonic-gate csp->t_ispeed += (CIBAUD >> IBSHIFT) + 1; 1236*0Sstevel@tonic-gate } 1237*0Sstevel@tonic-gate if (csp->t_ispeed == 0) 1238*0Sstevel@tonic-gate csp->t_ispeed = csp->t_ospeed; 1239*0Sstevel@tonic-gate if ((termiosp->c_cflag & CSTOPB) && csp->t_ispeed != B110) 1240*0Sstevel@tonic-gate csp->t_xflags |= STOPB; 1241*0Sstevel@tonic-gate TO_COMPAT_CHAR(csp->t_erase, termiosp->c_cc[VERASE]); 1242*0Sstevel@tonic-gate TO_COMPAT_CHAR(csp->t_kill, termiosp->c_cc[VKILL]); 1243*0Sstevel@tonic-gate TO_COMPAT_CHAR(csp->t_intrc, termiosp->c_cc[VINTR]); 1244*0Sstevel@tonic-gate TO_COMPAT_CHAR(csp->t_quitc, termiosp->c_cc[VQUIT]); 1245*0Sstevel@tonic-gate TO_COMPAT_CHAR(csp->t_startc, termiosp->c_cc[VSTART]); 1246*0Sstevel@tonic-gate TO_COMPAT_CHAR(csp->t_stopc, termiosp->c_cc[VSTOP]); 1247*0Sstevel@tonic-gate TO_COMPAT_CHAR(csp->t_suspc, termiosp->c_cc[VSUSP]); 1248*0Sstevel@tonic-gate TO_COMPAT_CHAR(csp->t_dsuspc, termiosp->c_cc[VDSUSP]); 1249*0Sstevel@tonic-gate TO_COMPAT_CHAR(csp->t_rprntc, termiosp->c_cc[VREPRINT]); 1250*0Sstevel@tonic-gate TO_COMPAT_CHAR(csp->t_flushc, termiosp->c_cc[VDISCARD]); 1251*0Sstevel@tonic-gate TO_COMPAT_CHAR(csp->t_werasc, termiosp->c_cc[VWERASE]); 1252*0Sstevel@tonic-gate TO_COMPAT_CHAR(csp->t_lnextc, termiosp->c_cc[VLNEXT]); 1253*0Sstevel@tonic-gate csp->t_flags &= (O_CTLECH|O_LITOUT|O_PASS8|O_ODDP|O_EVENP); 1254*0Sstevel@tonic-gate if (termiosp->c_iflag & IXOFF) 1255*0Sstevel@tonic-gate csp->t_flags |= O_TANDEM; 1256*0Sstevel@tonic-gate if (!(termiosp->c_iflag & 1257*0Sstevel@tonic-gate (IMAXBEL|BRKINT|IGNPAR|PARMRK|INPCK|ISTRIP| 1258*0Sstevel@tonic-gate INLCR|IGNCR|ICRNL|IUCLC|IXON)) && 1259*0Sstevel@tonic-gate !(termiosp->c_oflag & OPOST) && 1260*0Sstevel@tonic-gate (termiosp->c_cflag & (CSIZE|PARENB)) == CS8 && 1261*0Sstevel@tonic-gate !(termiosp->c_lflag & (ISIG|ICANON|XCASE|IEXTEN))) 1262*0Sstevel@tonic-gate csp->t_flags |= O_RAW; 1263*0Sstevel@tonic-gate else { 1264*0Sstevel@tonic-gate if (!(termiosp->c_iflag & IXON)) { 1265*0Sstevel@tonic-gate csp->t_startc = (uchar_t)0377; 1266*0Sstevel@tonic-gate csp->t_stopc = (uchar_t)0377; 1267*0Sstevel@tonic-gate } 1268*0Sstevel@tonic-gate if ((termiosp->c_cflag & (CSIZE|PARENB)) == CS8 && 1269*0Sstevel@tonic-gate !(termiosp->c_oflag & OPOST)) 1270*0Sstevel@tonic-gate csp->t_flags |= O_LITOUT; 1271*0Sstevel@tonic-gate else { 1272*0Sstevel@tonic-gate csp->t_flags &= ~O_LITOUT; 1273*0Sstevel@tonic-gate if ((termiosp->c_cflag & (CSIZE|PARENB)) == CS8) { 1274*0Sstevel@tonic-gate if (!(termiosp->c_iflag & ISTRIP)) 1275*0Sstevel@tonic-gate csp->t_flags |= O_PASS8; 1276*0Sstevel@tonic-gate } else { 1277*0Sstevel@tonic-gate csp->t_flags &= ~(O_ODDP|O_EVENP|O_PASS8); 1278*0Sstevel@tonic-gate if (termiosp->c_cflag & PARODD) 1279*0Sstevel@tonic-gate csp->t_flags |= O_ODDP; 1280*0Sstevel@tonic-gate else if (termiosp->c_iflag & INPCK) 1281*0Sstevel@tonic-gate csp->t_flags |= O_EVENP; 1282*0Sstevel@tonic-gate else 1283*0Sstevel@tonic-gate csp->t_flags |= O_ODDP|O_EVENP; 1284*0Sstevel@tonic-gate } 1285*0Sstevel@tonic-gate if (!(termiosp->c_oflag & OPOST)) 1286*0Sstevel@tonic-gate csp->t_xflags |= NOPOST; 1287*0Sstevel@tonic-gate else 1288*0Sstevel@tonic-gate csp->t_xflags &= ~NOPOST; 1289*0Sstevel@tonic-gate } 1290*0Sstevel@tonic-gate if (!(termiosp->c_lflag & ISIG)) 1291*0Sstevel@tonic-gate csp->t_xflags |= NOISIG; 1292*0Sstevel@tonic-gate else 1293*0Sstevel@tonic-gate csp->t_xflags &= ~NOISIG; 1294*0Sstevel@tonic-gate if (!(termiosp->c_lflag & ICANON)) 1295*0Sstevel@tonic-gate csp->t_flags |= O_CBREAK; 1296*0Sstevel@tonic-gate if (termiosp->c_lflag & ECHOCTL) 1297*0Sstevel@tonic-gate csp->t_flags |= O_CTLECH; 1298*0Sstevel@tonic-gate else 1299*0Sstevel@tonic-gate csp->t_flags &= ~O_CTLECH; 1300*0Sstevel@tonic-gate } 1301*0Sstevel@tonic-gate if (termiosp->c_oflag & OLCUC) 1302*0Sstevel@tonic-gate csp->t_flags |= O_LCASE; 1303*0Sstevel@tonic-gate if (termiosp->c_lflag&ECHO) 1304*0Sstevel@tonic-gate csp->t_flags |= O_ECHO; 1305*0Sstevel@tonic-gate if (termiosp->c_oflag & ONLCR) { 1306*0Sstevel@tonic-gate csp->t_flags |= O_CRMOD; 1307*0Sstevel@tonic-gate switch (termiosp->c_oflag & CRDLY) { 1308*0Sstevel@tonic-gate 1309*0Sstevel@tonic-gate case CR2: 1310*0Sstevel@tonic-gate csp->t_flags |= O_CR1; 1311*0Sstevel@tonic-gate break; 1312*0Sstevel@tonic-gate 1313*0Sstevel@tonic-gate case CR3: 1314*0Sstevel@tonic-gate csp->t_flags |= O_CR2; 1315*0Sstevel@tonic-gate break; 1316*0Sstevel@tonic-gate } 1317*0Sstevel@tonic-gate } else { 1318*0Sstevel@tonic-gate if ((termiosp->c_oflag & CR1) && 1319*0Sstevel@tonic-gate (termiosp->c_oflag & ONLRET)) 1320*0Sstevel@tonic-gate csp->t_flags |= O_NL1; /* tty37 */ 1321*0Sstevel@tonic-gate } 1322*0Sstevel@tonic-gate if ((termiosp->c_oflag & ONLRET) && (termiosp->c_oflag & NL1)) 1323*0Sstevel@tonic-gate csp->t_flags |= O_NL2; 1324*0Sstevel@tonic-gate switch (termiosp->c_oflag & TABDLY) { 1325*0Sstevel@tonic-gate 1326*0Sstevel@tonic-gate case TAB1: 1327*0Sstevel@tonic-gate csp->t_flags |= O_TAB1; 1328*0Sstevel@tonic-gate break; 1329*0Sstevel@tonic-gate 1330*0Sstevel@tonic-gate case TAB2: 1331*0Sstevel@tonic-gate csp->t_flags |= O_TAB2; 1332*0Sstevel@tonic-gate break; 1333*0Sstevel@tonic-gate 1334*0Sstevel@tonic-gate case XTABS: 1335*0Sstevel@tonic-gate csp->t_flags |= O_XTABS; 1336*0Sstevel@tonic-gate break; 1337*0Sstevel@tonic-gate } 1338*0Sstevel@tonic-gate if (termiosp->c_oflag & FFDLY) 1339*0Sstevel@tonic-gate csp->t_flags |= O_VTDELAY; 1340*0Sstevel@tonic-gate if (termiosp->c_oflag & BSDLY) 1341*0Sstevel@tonic-gate csp->t_flags |= O_BSDELAY; 1342*0Sstevel@tonic-gate if (termiosp->c_lflag & ECHOPRT) 1343*0Sstevel@tonic-gate csp->t_flags |= O_PRTERA; 1344*0Sstevel@tonic-gate if (termiosp->c_lflag & ECHOE) 1345*0Sstevel@tonic-gate csp->t_flags |= (O_CRTERA|O_CRTBS); 1346*0Sstevel@tonic-gate if (termiosp->c_lflag & TOSTOP) 1347*0Sstevel@tonic-gate csp->t_flags |= O_TOSTOP; 1348*0Sstevel@tonic-gate if (termiosp->c_lflag & FLUSHO) 1349*0Sstevel@tonic-gate csp->t_flags |= O_FLUSHO; 1350*0Sstevel@tonic-gate if (termiosp->c_cflag & CLOCAL) 1351*0Sstevel@tonic-gate csp->t_flags |= O_NOHANG; 1352*0Sstevel@tonic-gate if (termiosp->c_lflag & ECHOKE) 1353*0Sstevel@tonic-gate csp->t_flags |= O_CRTKIL; 1354*0Sstevel@tonic-gate if (termiosp->c_lflag & PENDIN) 1355*0Sstevel@tonic-gate csp->t_flags |= O_PENDIN; 1356*0Sstevel@tonic-gate if (!(termiosp->c_iflag & IXANY)) 1357*0Sstevel@tonic-gate csp->t_flags |= O_DECCTQ; 1358*0Sstevel@tonic-gate if (termiosp->c_lflag & NOFLSH) 1359*0Sstevel@tonic-gate csp->t_flags |= O_NOFLSH; 1360*0Sstevel@tonic-gate if (termiosp->c_lflag & ICANON) { 1361*0Sstevel@tonic-gate TO_COMPAT_CHAR(csp->t_eofc, termiosp->c_cc[VEOF]); 1362*0Sstevel@tonic-gate TO_COMPAT_CHAR(csp->t_brkc, termiosp->c_cc[VEOL]); 1363*0Sstevel@tonic-gate } else { 1364*0Sstevel@tonic-gate termiosp->c_cc[VMIN] = 1; 1365*0Sstevel@tonic-gate termiosp->c_cc[VTIME] = 0; 1366*0Sstevel@tonic-gate } 1367*0Sstevel@tonic-gate } 1368