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