xref: /illumos-gate/usr/src/uts/common/io/ptem.c (revision 3ade83088bf2797d3800b650040b7ea6f9fc7c14)
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
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
237c478bd9Sstevel@tonic-gate /*	  All Rights Reserved	*/
247c478bd9Sstevel@tonic-gate 
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate /*
277c478bd9Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
287c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
296cfa0a70SAndy Fiddaman  * Copyright 2018 OmniOS Community Edition (OmniOSce) Association.
307c478bd9Sstevel@tonic-gate  */
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate /*
337c478bd9Sstevel@tonic-gate  * Description:
347c478bd9Sstevel@tonic-gate  *
357c478bd9Sstevel@tonic-gate  * The PTEM streams module is used as a pseudo driver emulator.  Its purpose
367c478bd9Sstevel@tonic-gate  * is to emulate the ioctl() functions of a terminal device driver.
377c478bd9Sstevel@tonic-gate  */
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate #include <sys/types.h>
407c478bd9Sstevel@tonic-gate #include <sys/param.h>
417c478bd9Sstevel@tonic-gate #include <sys/stream.h>
427c478bd9Sstevel@tonic-gate #include <sys/stropts.h>
437c478bd9Sstevel@tonic-gate #include <sys/strsun.h>
447c478bd9Sstevel@tonic-gate #include <sys/termio.h>
457c478bd9Sstevel@tonic-gate #include <sys/pcb.h>
467c478bd9Sstevel@tonic-gate #include <sys/signal.h>
477c478bd9Sstevel@tonic-gate #include <sys/cred.h>
487c478bd9Sstevel@tonic-gate #include <sys/strtty.h>
497c478bd9Sstevel@tonic-gate #include <sys/errno.h>
507c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
517c478bd9Sstevel@tonic-gate #include <sys/jioctl.h>
527c478bd9Sstevel@tonic-gate #include <sys/ptem.h>
537c478bd9Sstevel@tonic-gate #include <sys/ptms.h>
547c478bd9Sstevel@tonic-gate #include <sys/debug.h>
557c478bd9Sstevel@tonic-gate #include <sys/kmem.h>
567c478bd9Sstevel@tonic-gate #include <sys/ddi.h>
577c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
587c478bd9Sstevel@tonic-gate #include <sys/conf.h>
597c478bd9Sstevel@tonic-gate #include <sys/modctl.h>
607c478bd9Sstevel@tonic-gate 
617c478bd9Sstevel@tonic-gate extern struct streamtab pteminfo;
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate static struct fmodsw fsw = {
647c478bd9Sstevel@tonic-gate 	"ptem",
657c478bd9Sstevel@tonic-gate 	&pteminfo,
666cfa0a70SAndy Fiddaman 	D_MTQPAIR | D_MP | _D_SINGLE_INSTANCE
677c478bd9Sstevel@tonic-gate };
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate static struct modlstrmod modlstrmod = {
707c478bd9Sstevel@tonic-gate 	&mod_strmodops, "pty hardware emulator", &fsw
717c478bd9Sstevel@tonic-gate };
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate static struct modlinkage modlinkage = {
747c478bd9Sstevel@tonic-gate 	MODREV_1, &modlstrmod, NULL
757c478bd9Sstevel@tonic-gate };
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate int
_init()787c478bd9Sstevel@tonic-gate _init()
797c478bd9Sstevel@tonic-gate {
807c478bd9Sstevel@tonic-gate 	return (mod_install(&modlinkage));
817c478bd9Sstevel@tonic-gate }
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate int
_fini()847c478bd9Sstevel@tonic-gate _fini()
857c478bd9Sstevel@tonic-gate {
867c478bd9Sstevel@tonic-gate 	return (mod_remove(&modlinkage));
877c478bd9Sstevel@tonic-gate }
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate int
_info(struct modinfo * modinfop)907c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop)
917c478bd9Sstevel@tonic-gate {
927c478bd9Sstevel@tonic-gate 	return (mod_info(&modlinkage, modinfop));
937c478bd9Sstevel@tonic-gate }
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate /*
967c478bd9Sstevel@tonic-gate  * stream data structure definitions
977c478bd9Sstevel@tonic-gate  */
987c478bd9Sstevel@tonic-gate static int ptemopen(queue_t *, dev_t  *, int, int, cred_t *);
997c478bd9Sstevel@tonic-gate static int ptemclose(queue_t *, int, cred_t *);
100fd121eb4SToomas Soome static int ptemrput(queue_t *, mblk_t *);
101fd121eb4SToomas Soome static int ptemwput(queue_t *, mblk_t *);
102fd121eb4SToomas Soome static int ptemwsrv(queue_t *);
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate static struct module_info ptem_info = {
1057c478bd9Sstevel@tonic-gate 	0xabcd,
1067c478bd9Sstevel@tonic-gate 	"ptem",
1077c478bd9Sstevel@tonic-gate 	0,
1082463e920SRichard Lowe 	_TTY_BUFSIZ,
1092463e920SRichard Lowe 	_TTY_BUFSIZ,
1107c478bd9Sstevel@tonic-gate 	128
1117c478bd9Sstevel@tonic-gate };
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate static struct qinit ptemrinit = {
114fd121eb4SToomas Soome 	ptemrput,
1157c478bd9Sstevel@tonic-gate 	NULL,
1167c478bd9Sstevel@tonic-gate 	ptemopen,
1177c478bd9Sstevel@tonic-gate 	ptemclose,
1187c478bd9Sstevel@tonic-gate 	NULL,
1197c478bd9Sstevel@tonic-gate 	&ptem_info,
1207c478bd9Sstevel@tonic-gate 	NULL
1217c478bd9Sstevel@tonic-gate };
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate static struct qinit ptemwinit = {
124fd121eb4SToomas Soome 	ptemwput,
125fd121eb4SToomas Soome 	ptemwsrv,
1267c478bd9Sstevel@tonic-gate 	ptemopen,
1277c478bd9Sstevel@tonic-gate 	ptemclose,
1287c478bd9Sstevel@tonic-gate 	nulldev,
1297c478bd9Sstevel@tonic-gate 	&ptem_info,
1307c478bd9Sstevel@tonic-gate 	NULL
1317c478bd9Sstevel@tonic-gate };
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate struct streamtab pteminfo = {
1347c478bd9Sstevel@tonic-gate 	&ptemrinit,
1357c478bd9Sstevel@tonic-gate 	&ptemwinit,
1367c478bd9Sstevel@tonic-gate 	NULL,
1377c478bd9Sstevel@tonic-gate 	NULL
1387c478bd9Sstevel@tonic-gate };
1397c478bd9Sstevel@tonic-gate 
1407c478bd9Sstevel@tonic-gate static void	ptioc(queue_t *, mblk_t *, int);
1417c478bd9Sstevel@tonic-gate static int	ptemwmsg(queue_t *, mblk_t *);
1427c478bd9Sstevel@tonic-gate 
1437c478bd9Sstevel@tonic-gate /*
1447c478bd9Sstevel@tonic-gate  * ptemopen - open routine gets called when the module gets pushed onto the
1457c478bd9Sstevel@tonic-gate  * stream.
1467c478bd9Sstevel@tonic-gate  */
1477c478bd9Sstevel@tonic-gate /* ARGSUSED */
1487c478bd9Sstevel@tonic-gate static int
ptemopen(queue_t * q,dev_t * devp,int oflag,int sflag,cred_t * credp)1497c478bd9Sstevel@tonic-gate ptemopen(
1507c478bd9Sstevel@tonic-gate 	queue_t    *q,		/* pointer to the read side queue */
1517c478bd9Sstevel@tonic-gate 	dev_t   *devp,		/* pointer to stream tail's dev */
1527c478bd9Sstevel@tonic-gate 	int	oflag,		/* the user open(2) supplied flags */
1537c478bd9Sstevel@tonic-gate 	int	sflag,		/* open state flag */
1547c478bd9Sstevel@tonic-gate 	cred_t *credp)		/* credentials */
1557c478bd9Sstevel@tonic-gate {
1567c478bd9Sstevel@tonic-gate 	struct ptem *ntp;	/* ptem entry for this PTEM module */
1577c478bd9Sstevel@tonic-gate 	mblk_t *mop;		/* an setopts mblk */
1587c478bd9Sstevel@tonic-gate 	struct stroptions *sop;
1597c478bd9Sstevel@tonic-gate 	struct termios *termiosp;
1607c478bd9Sstevel@tonic-gate 	int len;
1617c478bd9Sstevel@tonic-gate 
1627c478bd9Sstevel@tonic-gate 	if (sflag != MODOPEN)
1637c478bd9Sstevel@tonic-gate 		return (EINVAL);
1647c478bd9Sstevel@tonic-gate 
1657c478bd9Sstevel@tonic-gate 	if (q->q_ptr != NULL) {
1667c478bd9Sstevel@tonic-gate 		/* It's already attached. */
1677c478bd9Sstevel@tonic-gate 		return (0);
1687c478bd9Sstevel@tonic-gate 	}
1697c478bd9Sstevel@tonic-gate 
1707c478bd9Sstevel@tonic-gate 	/*
1717c478bd9Sstevel@tonic-gate 	 * Allocate state structure.
1727c478bd9Sstevel@tonic-gate 	 */
1737c478bd9Sstevel@tonic-gate 	ntp = kmem_alloc(sizeof (*ntp), KM_SLEEP);
1747c478bd9Sstevel@tonic-gate 
1757c478bd9Sstevel@tonic-gate 	/*
1767c478bd9Sstevel@tonic-gate 	 * Allocate a message block, used to pass the zero length message for
1777c478bd9Sstevel@tonic-gate 	 * "stty 0".
1787c478bd9Sstevel@tonic-gate 	 *
1797c478bd9Sstevel@tonic-gate 	 * NOTE: it's better to find out if such a message block can be
1807c478bd9Sstevel@tonic-gate 	 *	 allocated before it's needed than to not be able to
1817c478bd9Sstevel@tonic-gate 	 *	 deliver (for possible lack of buffers) when a hang-up
1827c478bd9Sstevel@tonic-gate 	 *	 occurs.
1837c478bd9Sstevel@tonic-gate 	 */
1847c478bd9Sstevel@tonic-gate 	if ((ntp->dack_ptr = allocb(4, BPRI_MED)) == NULL) {
1857c478bd9Sstevel@tonic-gate 		kmem_free(ntp, sizeof (*ntp));
1867c478bd9Sstevel@tonic-gate 		return (EAGAIN);
1877c478bd9Sstevel@tonic-gate 	}
1887c478bd9Sstevel@tonic-gate 
1897c478bd9Sstevel@tonic-gate 	/*
1907c478bd9Sstevel@tonic-gate 	 * Initialize an M_SETOPTS message to set up hi/lo water marks on
1917c478bd9Sstevel@tonic-gate 	 * stream head read queue and add controlling tty if not set.
1927c478bd9Sstevel@tonic-gate 	 */
1937c478bd9Sstevel@tonic-gate 	mop = allocb(sizeof (struct stroptions), BPRI_MED);
1947c478bd9Sstevel@tonic-gate 	if (mop == NULL) {
1957c478bd9Sstevel@tonic-gate 		freemsg(ntp->dack_ptr);
1967c478bd9Sstevel@tonic-gate 		kmem_free(ntp, sizeof (*ntp));
1977c478bd9Sstevel@tonic-gate 		return (EAGAIN);
1987c478bd9Sstevel@tonic-gate 	}
1997c478bd9Sstevel@tonic-gate 	mop->b_datap->db_type = M_SETOPTS;
2007c478bd9Sstevel@tonic-gate 	mop->b_wptr += sizeof (struct stroptions);
2017c478bd9Sstevel@tonic-gate 	sop = (struct stroptions *)mop->b_rptr;
2027c478bd9Sstevel@tonic-gate 	sop->so_flags = SO_HIWAT | SO_LOWAT | SO_ISTTY;
2032463e920SRichard Lowe 	sop->so_hiwat = _TTY_BUFSIZ;
2047c478bd9Sstevel@tonic-gate 	sop->so_lowat = 256;
2057c478bd9Sstevel@tonic-gate 
2067c478bd9Sstevel@tonic-gate 	/*
2077c478bd9Sstevel@tonic-gate 	 * Cross-link.
2087c478bd9Sstevel@tonic-gate 	 */
2097c478bd9Sstevel@tonic-gate 	ntp->q_ptr = q;
2107c478bd9Sstevel@tonic-gate 	q->q_ptr = ntp;
2117c478bd9Sstevel@tonic-gate 	WR(q)->q_ptr = ntp;
2127c478bd9Sstevel@tonic-gate 
2137c478bd9Sstevel@tonic-gate 	/*
2147c478bd9Sstevel@tonic-gate 	 * Get termios defaults.  These are stored as
2157c478bd9Sstevel@tonic-gate 	 * a property in the "options" node.
2167c478bd9Sstevel@tonic-gate 	 */
2177c478bd9Sstevel@tonic-gate 	if (ddi_getlongprop(DDI_DEV_T_ANY, ddi_root_node(), 0, "ttymodes",
2187c478bd9Sstevel@tonic-gate 	    (caddr_t)&termiosp, &len) == DDI_PROP_SUCCESS &&
2197c478bd9Sstevel@tonic-gate 	    len == sizeof (struct termios)) {
2207c478bd9Sstevel@tonic-gate 
2217c478bd9Sstevel@tonic-gate 		ntp->cflags = termiosp->c_cflag;
2227c478bd9Sstevel@tonic-gate 		kmem_free(termiosp, len);
2237c478bd9Sstevel@tonic-gate 	} else {
2247c478bd9Sstevel@tonic-gate 		/*
2257c478bd9Sstevel@tonic-gate 		 * Gack!  Whine about it.
2267c478bd9Sstevel@tonic-gate 		 */
2277c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN, "ptem: Couldn't get ttymodes property!");
2287c478bd9Sstevel@tonic-gate 	}
2297c478bd9Sstevel@tonic-gate 	ntp->wsz.ws_row = 0;
2307c478bd9Sstevel@tonic-gate 	ntp->wsz.ws_col = 0;
2317c478bd9Sstevel@tonic-gate 	ntp->wsz.ws_xpixel = 0;
2327c478bd9Sstevel@tonic-gate 	ntp->wsz.ws_ypixel = 0;
2337c478bd9Sstevel@tonic-gate 
2347c478bd9Sstevel@tonic-gate 	ntp->state = 0;
2357c478bd9Sstevel@tonic-gate 
2367c478bd9Sstevel@tonic-gate 	/*
2377c478bd9Sstevel@tonic-gate 	 * Commit to the open and send the M_SETOPTS off to the stream head.
2387c478bd9Sstevel@tonic-gate 	 */
2397c478bd9Sstevel@tonic-gate 	qprocson(q);
2407c478bd9Sstevel@tonic-gate 	putnext(q, mop);
2417c478bd9Sstevel@tonic-gate 
2427c478bd9Sstevel@tonic-gate 	return (0);
2437c478bd9Sstevel@tonic-gate }
2447c478bd9Sstevel@tonic-gate 
2457c478bd9Sstevel@tonic-gate 
2467c478bd9Sstevel@tonic-gate /*
2477c478bd9Sstevel@tonic-gate  * ptemclose - This routine gets called when the module gets popped off of the
2487c478bd9Sstevel@tonic-gate  * stream.
2497c478bd9Sstevel@tonic-gate  */
2507c478bd9Sstevel@tonic-gate /* ARGSUSED */
2517c478bd9Sstevel@tonic-gate static int
ptemclose(queue_t * q,int flag,cred_t * credp)2527c478bd9Sstevel@tonic-gate ptemclose(queue_t *q, int flag, cred_t *credp)
2537c478bd9Sstevel@tonic-gate {
2547c478bd9Sstevel@tonic-gate 	struct ptem *ntp;	/* ptem entry for this PTEM module */
2557c478bd9Sstevel@tonic-gate 
2567c478bd9Sstevel@tonic-gate 	qprocsoff(q);
2577c478bd9Sstevel@tonic-gate 	ntp = (struct ptem *)q->q_ptr;
2587c478bd9Sstevel@tonic-gate 	freemsg(ntp->dack_ptr);
2597c478bd9Sstevel@tonic-gate 	kmem_free(ntp, sizeof (*ntp));
2607c478bd9Sstevel@tonic-gate 	q->q_ptr = WR(q)->q_ptr = NULL;
2617c478bd9Sstevel@tonic-gate 	return (0);
2627c478bd9Sstevel@tonic-gate }
2637c478bd9Sstevel@tonic-gate 
2647c478bd9Sstevel@tonic-gate 
2657c478bd9Sstevel@tonic-gate /*
2667c478bd9Sstevel@tonic-gate  * ptemrput - Module read queue put procedure.
2677c478bd9Sstevel@tonic-gate  *
2687c478bd9Sstevel@tonic-gate  * This is called from the module or driver downstream.
2697c478bd9Sstevel@tonic-gate  */
270fd121eb4SToomas Soome static int
ptemrput(queue_t * q,mblk_t * mp)2717c478bd9Sstevel@tonic-gate ptemrput(queue_t *q, mblk_t *mp)
2727c478bd9Sstevel@tonic-gate {
2737c478bd9Sstevel@tonic-gate 	struct iocblk *iocp;	/* M_IOCTL data */
2747c478bd9Sstevel@tonic-gate 	struct copyresp *resp;	/* transparent ioctl response struct */
2757c478bd9Sstevel@tonic-gate 	int error;
2767c478bd9Sstevel@tonic-gate 
2777c478bd9Sstevel@tonic-gate 	switch (mp->b_datap->db_type) {
2787c478bd9Sstevel@tonic-gate 	case M_DELAY:
2797c478bd9Sstevel@tonic-gate 	case M_READ:
2807c478bd9Sstevel@tonic-gate 		freemsg(mp);
2817c478bd9Sstevel@tonic-gate 		break;
2827c478bd9Sstevel@tonic-gate 
2837c478bd9Sstevel@tonic-gate 	case M_IOCTL:
2847c478bd9Sstevel@tonic-gate 		iocp = (struct iocblk *)mp->b_rptr;
2857c478bd9Sstevel@tonic-gate 
2867c478bd9Sstevel@tonic-gate 		switch (iocp->ioc_cmd) {
2877c478bd9Sstevel@tonic-gate 		case TCSBRK:
2887c478bd9Sstevel@tonic-gate 			/*
2897c478bd9Sstevel@tonic-gate 			 * Send a break message upstream.
2907c478bd9Sstevel@tonic-gate 			 *
2917c478bd9Sstevel@tonic-gate 			 * XXX:	Shouldn't the argument come into play in
2927c478bd9Sstevel@tonic-gate 			 *	determining whether or not so send an M_BREAK?
2937c478bd9Sstevel@tonic-gate 			 *	It certainly does in the write-side direction.
2947c478bd9Sstevel@tonic-gate 			 */
2957c478bd9Sstevel@tonic-gate 			error = miocpullup(mp, sizeof (int));
2967c478bd9Sstevel@tonic-gate 			if (error != 0) {
2977c478bd9Sstevel@tonic-gate 				miocnak(q, mp, 0, error);
2987c478bd9Sstevel@tonic-gate 				break;
2997c478bd9Sstevel@tonic-gate 			}
3007c478bd9Sstevel@tonic-gate 			if (!(*(int *)mp->b_cont->b_rptr)) {
3017c478bd9Sstevel@tonic-gate 				if (!putnextctl(q, M_BREAK)) {
3027c478bd9Sstevel@tonic-gate 					/*
3037c478bd9Sstevel@tonic-gate 					 * Send an NAK reply back
3047c478bd9Sstevel@tonic-gate 					 */
3057c478bd9Sstevel@tonic-gate 					miocnak(q, mp, 0, EAGAIN);
3067c478bd9Sstevel@tonic-gate 					break;
3077c478bd9Sstevel@tonic-gate 				}
3087c478bd9Sstevel@tonic-gate 			}
3097c478bd9Sstevel@tonic-gate 			/*
3107c478bd9Sstevel@tonic-gate 			 * ACK it.
3117c478bd9Sstevel@tonic-gate 			 */
3127c478bd9Sstevel@tonic-gate 			mioc2ack(mp, NULL, 0, 0);
3137c478bd9Sstevel@tonic-gate 			qreply(q, mp);
3147c478bd9Sstevel@tonic-gate 			break;
3157c478bd9Sstevel@tonic-gate 
3167c478bd9Sstevel@tonic-gate 		case JWINSIZE:
3177c478bd9Sstevel@tonic-gate 		case TIOCGWINSZ:
3187c478bd9Sstevel@tonic-gate 		case TIOCSWINSZ:
3197c478bd9Sstevel@tonic-gate 			ptioc(q, mp, RDSIDE);
3207c478bd9Sstevel@tonic-gate 			break;
3217c478bd9Sstevel@tonic-gate 
3227c478bd9Sstevel@tonic-gate 		case TIOCSIGNAL:
3237c478bd9Sstevel@tonic-gate 			/*
3247c478bd9Sstevel@tonic-gate 			 * The following subtle logic is due to the fact that
3257c478bd9Sstevel@tonic-gate 			 * `mp' may be in any one of three distinct formats:
3267c478bd9Sstevel@tonic-gate 			 *
3277c478bd9Sstevel@tonic-gate 			 *	1. A transparent M_IOCTL with an intptr_t-sized
3287c478bd9Sstevel@tonic-gate 			 *	   payload containing the signal number.
3297c478bd9Sstevel@tonic-gate 			 *
3307c478bd9Sstevel@tonic-gate 			 *	2. An I_STR M_IOCTL with an int-sized payload
3317c478bd9Sstevel@tonic-gate 			 *	   containing the signal number.
3327c478bd9Sstevel@tonic-gate 			 *
3337c478bd9Sstevel@tonic-gate 			 *	3. An M_IOCDATA with an int-sized payload
3347c478bd9Sstevel@tonic-gate 			 *	   containing the signal number.
3357c478bd9Sstevel@tonic-gate 			 */
3367c478bd9Sstevel@tonic-gate 			if (iocp->ioc_count == TRANSPARENT) {
3377c478bd9Sstevel@tonic-gate 				intptr_t sig = *(intptr_t *)mp->b_cont->b_rptr;
3387c478bd9Sstevel@tonic-gate 
3397c478bd9Sstevel@tonic-gate 				if (sig < 1 || sig >= NSIG) {
3407c478bd9Sstevel@tonic-gate 					/*
3417c478bd9Sstevel@tonic-gate 					 * it's transparent with pointer
3427c478bd9Sstevel@tonic-gate 					 * to the arg
3437c478bd9Sstevel@tonic-gate 					 */
3447c478bd9Sstevel@tonic-gate 					mcopyin(mp, NULL, sizeof (int), NULL);
3457c478bd9Sstevel@tonic-gate 					qreply(q, mp);
3467c478bd9Sstevel@tonic-gate 					break;
3477c478bd9Sstevel@tonic-gate 				}
3487c478bd9Sstevel@tonic-gate 			}
3497c478bd9Sstevel@tonic-gate 			ptioc(q, mp, RDSIDE);
3507c478bd9Sstevel@tonic-gate 			break;
3517c478bd9Sstevel@tonic-gate 
3527c478bd9Sstevel@tonic-gate 		case TIOCREMOTE:
3537c478bd9Sstevel@tonic-gate 			if (iocp->ioc_count != TRANSPARENT)
3547c478bd9Sstevel@tonic-gate 				ptioc(q, mp, RDSIDE);
3557c478bd9Sstevel@tonic-gate 			else {
3567c478bd9Sstevel@tonic-gate 				mcopyin(mp, NULL, sizeof (int), NULL);
3577c478bd9Sstevel@tonic-gate 				qreply(q, mp);
3587c478bd9Sstevel@tonic-gate 			}
3597c478bd9Sstevel@tonic-gate 			break;
3607c478bd9Sstevel@tonic-gate 
3617c478bd9Sstevel@tonic-gate 		default:
3627c478bd9Sstevel@tonic-gate 			putnext(q, mp);
3637c478bd9Sstevel@tonic-gate 			break;
3647c478bd9Sstevel@tonic-gate 		}
3657c478bd9Sstevel@tonic-gate 		break;
3667c478bd9Sstevel@tonic-gate 
3677c478bd9Sstevel@tonic-gate 	case M_IOCDATA:
3687c478bd9Sstevel@tonic-gate 		resp = (struct copyresp *)mp->b_rptr;
3697c478bd9Sstevel@tonic-gate 		if (resp->cp_rval) {
3707c478bd9Sstevel@tonic-gate 			/*
3717c478bd9Sstevel@tonic-gate 			 * Just free message on failure.
3727c478bd9Sstevel@tonic-gate 			 */
3737c478bd9Sstevel@tonic-gate 			freemsg(mp);
3747c478bd9Sstevel@tonic-gate 			break;
3757c478bd9Sstevel@tonic-gate 		}
3767c478bd9Sstevel@tonic-gate 
3777c478bd9Sstevel@tonic-gate 		/*
3787c478bd9Sstevel@tonic-gate 		 * Only need to copy data for the SET case.
3797c478bd9Sstevel@tonic-gate 		 */
3807c478bd9Sstevel@tonic-gate 		switch (resp->cp_cmd) {
3817c478bd9Sstevel@tonic-gate 
3827c478bd9Sstevel@tonic-gate 		case TIOCSWINSZ:
3837c478bd9Sstevel@tonic-gate 		case TIOCSIGNAL:
3847c478bd9Sstevel@tonic-gate 		case TIOCREMOTE:
3857c478bd9Sstevel@tonic-gate 			ptioc(q, mp, RDSIDE);
3867c478bd9Sstevel@tonic-gate 			break;
3877c478bd9Sstevel@tonic-gate 
3887c478bd9Sstevel@tonic-gate 		case JWINSIZE:
3897c478bd9Sstevel@tonic-gate 		case TIOCGWINSZ:
3907c478bd9Sstevel@tonic-gate 			mp->b_datap->db_type = M_IOCACK;
3917c478bd9Sstevel@tonic-gate 			mioc2ack(mp, NULL, 0, 0);
3927c478bd9Sstevel@tonic-gate 			qreply(q, mp);
3937c478bd9Sstevel@tonic-gate 			break;
3947c478bd9Sstevel@tonic-gate 
3957c478bd9Sstevel@tonic-gate 		default:
3967c478bd9Sstevel@tonic-gate 			freemsg(mp);
3977c478bd9Sstevel@tonic-gate 			break;
3987c478bd9Sstevel@tonic-gate 	}
3997c478bd9Sstevel@tonic-gate 	break;
4007c478bd9Sstevel@tonic-gate 
4017c478bd9Sstevel@tonic-gate 	case M_IOCACK:
4027c478bd9Sstevel@tonic-gate 	case M_IOCNAK:
4037c478bd9Sstevel@tonic-gate 		/*
4041fa2a664SJoshua M. Clulow 		 * We only pass write-side ioctls through to the manager that
4057c478bd9Sstevel@tonic-gate 		 * we've already ACKed or NAKed to the stream head.  Thus, we
4067c478bd9Sstevel@tonic-gate 		 * discard ones arriving from below, since they're redundant
4077c478bd9Sstevel@tonic-gate 		 * from the point of view of modules above us.
4087c478bd9Sstevel@tonic-gate 		 */
4097c478bd9Sstevel@tonic-gate 		freemsg(mp);
4107c478bd9Sstevel@tonic-gate 		break;
4117c478bd9Sstevel@tonic-gate 
4127c478bd9Sstevel@tonic-gate 	case M_HANGUP:
4137c478bd9Sstevel@tonic-gate 		/*
4147c478bd9Sstevel@tonic-gate 		 * clear blocked state.
4157c478bd9Sstevel@tonic-gate 		 */
4167c478bd9Sstevel@tonic-gate 		{
4177c478bd9Sstevel@tonic-gate 			struct ptem *ntp = (struct ptem *)q->q_ptr;
4187c478bd9Sstevel@tonic-gate 			if (ntp->state & OFLOW_CTL) {
4197c478bd9Sstevel@tonic-gate 				ntp->state &= ~OFLOW_CTL;
4207c478bd9Sstevel@tonic-gate 				qenable(WR(q));
4217c478bd9Sstevel@tonic-gate 			}
4227c478bd9Sstevel@tonic-gate 		}
423b80bb91bSToomas Soome 		/* FALLTHROUGH */
4247c478bd9Sstevel@tonic-gate 	default:
4257c478bd9Sstevel@tonic-gate 		putnext(q, mp);
4267c478bd9Sstevel@tonic-gate 		break;
4277c478bd9Sstevel@tonic-gate 	}
428fd121eb4SToomas Soome 	return (0);
4297c478bd9Sstevel@tonic-gate }
4307c478bd9Sstevel@tonic-gate 
4317c478bd9Sstevel@tonic-gate 
4327c478bd9Sstevel@tonic-gate /*
4337c478bd9Sstevel@tonic-gate  * ptemwput - Module write queue put procedure.
4347c478bd9Sstevel@tonic-gate  *
4357c478bd9Sstevel@tonic-gate  * This is called from the module or stream head upstream.
4367c478bd9Sstevel@tonic-gate  *
4377c478bd9Sstevel@tonic-gate  * XXX:	This routine is quite lazy about handling allocation failures,
4387c478bd9Sstevel@tonic-gate  *	basically just giving up and reporting failure.  It really ought to
4397c478bd9Sstevel@tonic-gate  *	set up bufcalls and only fail when it's absolutely necessary.
4407c478bd9Sstevel@tonic-gate  */
441fd121eb4SToomas Soome static int
ptemwput(queue_t * q,mblk_t * mp)4427c478bd9Sstevel@tonic-gate ptemwput(queue_t *q, mblk_t *mp)
4437c478bd9Sstevel@tonic-gate {
4447c478bd9Sstevel@tonic-gate 	struct ptem *ntp = (struct ptem *)q->q_ptr;
4457c478bd9Sstevel@tonic-gate 	struct iocblk *iocp;	/* outgoing ioctl structure */
4467c478bd9Sstevel@tonic-gate 	struct copyresp *resp;
4477c478bd9Sstevel@tonic-gate 	unsigned char type = mp->b_datap->db_type;
4487c478bd9Sstevel@tonic-gate 
4497c478bd9Sstevel@tonic-gate 	if (type >= QPCTL) {
4507c478bd9Sstevel@tonic-gate 		switch (type) {
4517c478bd9Sstevel@tonic-gate 
4527c478bd9Sstevel@tonic-gate 		case M_IOCDATA:
4537c478bd9Sstevel@tonic-gate 			resp = (struct copyresp *)mp->b_rptr;
4547c478bd9Sstevel@tonic-gate 			if (resp->cp_rval) {
4557c478bd9Sstevel@tonic-gate 				/*
4567c478bd9Sstevel@tonic-gate 				 * Just free message on failure.
4577c478bd9Sstevel@tonic-gate 				 */
4587c478bd9Sstevel@tonic-gate 				freemsg(mp);
4597c478bd9Sstevel@tonic-gate 				break;
4607c478bd9Sstevel@tonic-gate 			}
4617c478bd9Sstevel@tonic-gate 
4627c478bd9Sstevel@tonic-gate 			/*
4637c478bd9Sstevel@tonic-gate 			 * Only need to copy data for the SET case.
4647c478bd9Sstevel@tonic-gate 			 */
4657c478bd9Sstevel@tonic-gate 			switch (resp->cp_cmd) {
4667c478bd9Sstevel@tonic-gate 
4677c478bd9Sstevel@tonic-gate 				case TIOCSWINSZ:
4687c478bd9Sstevel@tonic-gate 					ptioc(q, mp, WRSIDE);
4697c478bd9Sstevel@tonic-gate 					break;
4707c478bd9Sstevel@tonic-gate 
4717c478bd9Sstevel@tonic-gate 				case JWINSIZE:
4727c478bd9Sstevel@tonic-gate 				case TIOCGWINSZ:
4737c478bd9Sstevel@tonic-gate 					mioc2ack(mp, NULL, 0, 0);
4747c478bd9Sstevel@tonic-gate 					qreply(q, mp);
4757c478bd9Sstevel@tonic-gate 					break;
4767c478bd9Sstevel@tonic-gate 
4777c478bd9Sstevel@tonic-gate 				default:
4787c478bd9Sstevel@tonic-gate 					freemsg(mp);
4797c478bd9Sstevel@tonic-gate 			}
4807c478bd9Sstevel@tonic-gate 			break;
4817c478bd9Sstevel@tonic-gate 
4827c478bd9Sstevel@tonic-gate 		case M_FLUSH:
4837c478bd9Sstevel@tonic-gate 			if (*mp->b_rptr & FLUSHW) {
4847c478bd9Sstevel@tonic-gate 				if ((ntp->state & IS_PTSTTY) &&
4857c478bd9Sstevel@tonic-gate 				    (*mp->b_rptr & FLUSHBAND))
4862463e920SRichard Lowe 					flushband(q, *(mp->b_rptr + 1),
4872463e920SRichard Lowe 					    FLUSHDATA);
4887c478bd9Sstevel@tonic-gate 				else
4897c478bd9Sstevel@tonic-gate 					flushq(q, FLUSHDATA);
4907c478bd9Sstevel@tonic-gate 			}
4917c478bd9Sstevel@tonic-gate 			putnext(q, mp);
4927c478bd9Sstevel@tonic-gate 			break;
4937c478bd9Sstevel@tonic-gate 
4947c478bd9Sstevel@tonic-gate 		case M_READ:
4957c478bd9Sstevel@tonic-gate 			freemsg(mp);
4967c478bd9Sstevel@tonic-gate 			break;
4977c478bd9Sstevel@tonic-gate 
4987c478bd9Sstevel@tonic-gate 		case M_STOP:
4997c478bd9Sstevel@tonic-gate 			/*
5007c478bd9Sstevel@tonic-gate 			 * Set the output flow control state.
5017c478bd9Sstevel@tonic-gate 			 */
5027c478bd9Sstevel@tonic-gate 			ntp->state |= OFLOW_CTL;
5037c478bd9Sstevel@tonic-gate 			putnext(q, mp);
5047c478bd9Sstevel@tonic-gate 			break;
5057c478bd9Sstevel@tonic-gate 
5067c478bd9Sstevel@tonic-gate 		case M_START:
5077c478bd9Sstevel@tonic-gate 			/*
5087c478bd9Sstevel@tonic-gate 			 * Relieve the output flow control state.
5097c478bd9Sstevel@tonic-gate 			 */
5107c478bd9Sstevel@tonic-gate 			ntp->state &= ~OFLOW_CTL;
5117c478bd9Sstevel@tonic-gate 			putnext(q, mp);
5127c478bd9Sstevel@tonic-gate 			qenable(q);
5137c478bd9Sstevel@tonic-gate 			break;
5147c478bd9Sstevel@tonic-gate 		default:
5157c478bd9Sstevel@tonic-gate 			putnext(q, mp);
5167c478bd9Sstevel@tonic-gate 			break;
5177c478bd9Sstevel@tonic-gate 		}
518fd121eb4SToomas Soome 		return (0);
5197c478bd9Sstevel@tonic-gate 	}
5207c478bd9Sstevel@tonic-gate 	/*
5217c478bd9Sstevel@tonic-gate 	 * If our queue is nonempty or flow control persists
5227c478bd9Sstevel@tonic-gate 	 * downstream or module in stopped state, queue this message.
5237c478bd9Sstevel@tonic-gate 	 */
5247c478bd9Sstevel@tonic-gate 	if (q->q_first != NULL || !bcanputnext(q, mp->b_band)) {
5257c478bd9Sstevel@tonic-gate 		/*
5267c478bd9Sstevel@tonic-gate 		 * Exception: ioctls, except for those defined to
5277c478bd9Sstevel@tonic-gate 		 * take effect after output has drained, should be
5287c478bd9Sstevel@tonic-gate 		 * processed immediately.
5297c478bd9Sstevel@tonic-gate 		 */
5307c478bd9Sstevel@tonic-gate 		switch (type) {
5317c478bd9Sstevel@tonic-gate 
5327c478bd9Sstevel@tonic-gate 		case M_IOCTL:
5337c478bd9Sstevel@tonic-gate 			iocp = (struct iocblk *)mp->b_rptr;
5347c478bd9Sstevel@tonic-gate 			switch (iocp->ioc_cmd) {
5357c478bd9Sstevel@tonic-gate 			/*
5367c478bd9Sstevel@tonic-gate 			 * Queue these.
5377c478bd9Sstevel@tonic-gate 			 */
5387c478bd9Sstevel@tonic-gate 			case TCSETSW:
5397c478bd9Sstevel@tonic-gate 			case TCSETSF:
5407c478bd9Sstevel@tonic-gate 			case TCSETAW:
5417c478bd9Sstevel@tonic-gate 			case TCSETAF:
5427c478bd9Sstevel@tonic-gate 			case TCSBRK:
5437c478bd9Sstevel@tonic-gate 				break;
5447c478bd9Sstevel@tonic-gate 
5457c478bd9Sstevel@tonic-gate 			/*
5467c478bd9Sstevel@tonic-gate 			 * Handle all others immediately.
5477c478bd9Sstevel@tonic-gate 			 */
5487c478bd9Sstevel@tonic-gate 			default:
5497c478bd9Sstevel@tonic-gate 				(void) ptemwmsg(q, mp);
550fd121eb4SToomas Soome 				return (0);
5517c478bd9Sstevel@tonic-gate 			}
5527c478bd9Sstevel@tonic-gate 			break;
5537c478bd9Sstevel@tonic-gate 
5547c478bd9Sstevel@tonic-gate 		case M_DELAY: /* tty delays not supported */
5557c478bd9Sstevel@tonic-gate 			freemsg(mp);
556fd121eb4SToomas Soome 			return (0);
5577c478bd9Sstevel@tonic-gate 
5587c478bd9Sstevel@tonic-gate 		case M_DATA:
5597c478bd9Sstevel@tonic-gate 			if ((mp->b_wptr - mp->b_rptr) < 0) {
5607c478bd9Sstevel@tonic-gate 				/*
5617c478bd9Sstevel@tonic-gate 				 * Free all bad length messages.
5627c478bd9Sstevel@tonic-gate 				 */
5637c478bd9Sstevel@tonic-gate 				freemsg(mp);
564fd121eb4SToomas Soome 				return (0);
5657c478bd9Sstevel@tonic-gate 			} else if ((mp->b_wptr - mp->b_rptr) == 0) {
5667c478bd9Sstevel@tonic-gate 				if (!(ntp->state & IS_PTSTTY)) {
5677c478bd9Sstevel@tonic-gate 					freemsg(mp);
568fd121eb4SToomas Soome 					return (0);
5697c478bd9Sstevel@tonic-gate 				}
5707c478bd9Sstevel@tonic-gate 			}
5717c478bd9Sstevel@tonic-gate 		}
5727c478bd9Sstevel@tonic-gate 		(void) putq(q, mp);
573fd121eb4SToomas Soome 		return (0);
5747c478bd9Sstevel@tonic-gate 	}
5757c478bd9Sstevel@tonic-gate 	/*
5767c478bd9Sstevel@tonic-gate 	 * fast path into ptemwmsg to dispose of mp.
5777c478bd9Sstevel@tonic-gate 	 */
5787c478bd9Sstevel@tonic-gate 	if (!ptemwmsg(q, mp))
5797c478bd9Sstevel@tonic-gate 		(void) putq(q, mp);
580fd121eb4SToomas Soome 	return (0);
5817c478bd9Sstevel@tonic-gate }
5827c478bd9Sstevel@tonic-gate 
5837c478bd9Sstevel@tonic-gate /*
5847c478bd9Sstevel@tonic-gate  * ptem write queue service procedure.
5857c478bd9Sstevel@tonic-gate  */
586fd121eb4SToomas Soome static int
ptemwsrv(queue_t * q)5877c478bd9Sstevel@tonic-gate ptemwsrv(queue_t *q)
5887c478bd9Sstevel@tonic-gate {
5897c478bd9Sstevel@tonic-gate 	mblk_t *mp;
5907c478bd9Sstevel@tonic-gate 
5917c478bd9Sstevel@tonic-gate 	while ((mp = getq(q)) != NULL) {
5927c478bd9Sstevel@tonic-gate 		if (!bcanputnext(q, mp->b_band) || !ptemwmsg(q, mp)) {
5937c478bd9Sstevel@tonic-gate 			(void) putbq(q, mp);
5947c478bd9Sstevel@tonic-gate 			break;
5957c478bd9Sstevel@tonic-gate 		}
5967c478bd9Sstevel@tonic-gate 	}
597fd121eb4SToomas Soome 	return (0);
5987c478bd9Sstevel@tonic-gate }
5997c478bd9Sstevel@tonic-gate 
6007c478bd9Sstevel@tonic-gate 
6017c478bd9Sstevel@tonic-gate /*
6027c478bd9Sstevel@tonic-gate  * This routine is called from both ptemwput and ptemwsrv to do the
6037c478bd9Sstevel@tonic-gate  * actual work of dealing with mp.  ptmewput will have already
6047c478bd9Sstevel@tonic-gate  * dealt with high priority messages.
6057c478bd9Sstevel@tonic-gate  *
6067c478bd9Sstevel@tonic-gate  * Return 1 if the message was processed completely and 0 if not.
6077c478bd9Sstevel@tonic-gate  */
6087c478bd9Sstevel@tonic-gate static int
ptemwmsg(queue_t * q,mblk_t * mp)6097c478bd9Sstevel@tonic-gate ptemwmsg(queue_t *q, mblk_t *mp)
6107c478bd9Sstevel@tonic-gate {
6117c478bd9Sstevel@tonic-gate 	struct ptem *ntp = (struct ptem *)q->q_ptr;
6127c478bd9Sstevel@tonic-gate 	struct iocblk *iocp;	/* outgoing ioctl structure */
6137c478bd9Sstevel@tonic-gate 	struct termio *termiop;
6147c478bd9Sstevel@tonic-gate 	struct termios *termiosp;
6157c478bd9Sstevel@tonic-gate 	mblk_t *dack_ptr;		/* disconnect message ACK block */
6167c478bd9Sstevel@tonic-gate 	mblk_t *pckt_msgp;		/* message sent to the PCKT module */
6177c478bd9Sstevel@tonic-gate 	mblk_t *dp;			/* ioctl reply data */
6187c478bd9Sstevel@tonic-gate 	tcflag_t cflags;
6197c478bd9Sstevel@tonic-gate 	int error;
6207c478bd9Sstevel@tonic-gate 
6217c478bd9Sstevel@tonic-gate 	switch (mp->b_datap->db_type) {
6227c478bd9Sstevel@tonic-gate 
6237c478bd9Sstevel@tonic-gate 	case M_IOCTL:
6247c478bd9Sstevel@tonic-gate 		/*
6257c478bd9Sstevel@tonic-gate 		 * Note:  for each "set" type operation a copy
6267c478bd9Sstevel@tonic-gate 		 * of the M_IOCTL message is made and passed
6277c478bd9Sstevel@tonic-gate 		 * downstream.  Eventually the PCKT module, if
6287c478bd9Sstevel@tonic-gate 		 * it has been pushed, should pick up this message.
6291fa2a664SJoshua M. Clulow 		 * If the PCKT module has not been pushed the manager
6307c478bd9Sstevel@tonic-gate 		 * side stream head will free it.
6317c478bd9Sstevel@tonic-gate 		 */
6327c478bd9Sstevel@tonic-gate 		iocp = (struct iocblk *)mp->b_rptr;
6337c478bd9Sstevel@tonic-gate 		switch (iocp->ioc_cmd) {
6347c478bd9Sstevel@tonic-gate 
6357c478bd9Sstevel@tonic-gate 		case TCSETAF:
6367c478bd9Sstevel@tonic-gate 		case TCSETSF:
6377c478bd9Sstevel@tonic-gate 			/*
6387c478bd9Sstevel@tonic-gate 			 * Flush the read queue.
6397c478bd9Sstevel@tonic-gate 			 */
6407c478bd9Sstevel@tonic-gate 			if (putnextctl1(q, M_FLUSH, FLUSHR) == 0) {
6417c478bd9Sstevel@tonic-gate 				miocnak(q, mp, 0, EAGAIN);
6427c478bd9Sstevel@tonic-gate 				break;
6437c478bd9Sstevel@tonic-gate 			}
6447c478bd9Sstevel@tonic-gate 			/* FALLTHROUGH */
6457c478bd9Sstevel@tonic-gate 
6467c478bd9Sstevel@tonic-gate 		case TCSETA:
6477c478bd9Sstevel@tonic-gate 		case TCSETAW:
6487c478bd9Sstevel@tonic-gate 		case TCSETS:
6497c478bd9Sstevel@tonic-gate 		case TCSETSW:
6507c478bd9Sstevel@tonic-gate 
6517c478bd9Sstevel@tonic-gate 			switch (iocp->ioc_cmd) {
6527c478bd9Sstevel@tonic-gate 			case TCSETAF:
6537c478bd9Sstevel@tonic-gate 			case TCSETA:
6547c478bd9Sstevel@tonic-gate 			case TCSETAW:
6557c478bd9Sstevel@tonic-gate 				error = miocpullup(mp, sizeof (struct termio));
6567c478bd9Sstevel@tonic-gate 				if (error != 0) {
6577c478bd9Sstevel@tonic-gate 					miocnak(q, mp, 0, error);
6587c478bd9Sstevel@tonic-gate 					goto out;
6597c478bd9Sstevel@tonic-gate 				}
6607c478bd9Sstevel@tonic-gate 				cflags = ((struct termio *)
6617c478bd9Sstevel@tonic-gate 				    mp->b_cont->b_rptr)->c_cflag;
6627c478bd9Sstevel@tonic-gate 				ntp->cflags =
6637c478bd9Sstevel@tonic-gate 				    (ntp->cflags & 0xffff0000 | cflags);
6647c478bd9Sstevel@tonic-gate 				break;
6657c478bd9Sstevel@tonic-gate 
6667c478bd9Sstevel@tonic-gate 			case TCSETSF:
6677c478bd9Sstevel@tonic-gate 			case TCSETS:
6687c478bd9Sstevel@tonic-gate 			case TCSETSW:
6697c478bd9Sstevel@tonic-gate 				error = miocpullup(mp, sizeof (struct termios));
6707c478bd9Sstevel@tonic-gate 				if (error != 0) {
6717c478bd9Sstevel@tonic-gate 					miocnak(q, mp, 0, error);
6727c478bd9Sstevel@tonic-gate 					goto out;
6737c478bd9Sstevel@tonic-gate 				}
6747c478bd9Sstevel@tonic-gate 				cflags = ((struct termios *)
6757c478bd9Sstevel@tonic-gate 				    mp->b_cont->b_rptr)->c_cflag;
6767c478bd9Sstevel@tonic-gate 				ntp->cflags = cflags;
6777c478bd9Sstevel@tonic-gate 				break;
6787c478bd9Sstevel@tonic-gate 			}
6797c478bd9Sstevel@tonic-gate 
6807c478bd9Sstevel@tonic-gate 			if ((cflags & CBAUD) == B0) {
6817c478bd9Sstevel@tonic-gate 				/*
6827c478bd9Sstevel@tonic-gate 				 * Hang-up: Send a zero length message.
6837c478bd9Sstevel@tonic-gate 				 */
6847c478bd9Sstevel@tonic-gate 				dack_ptr = ntp->dack_ptr;
6857c478bd9Sstevel@tonic-gate 
6867c478bd9Sstevel@tonic-gate 				if (dack_ptr) {
6877c478bd9Sstevel@tonic-gate 					ntp->dack_ptr = NULL;
6887c478bd9Sstevel@tonic-gate 					/*
6897c478bd9Sstevel@tonic-gate 					 * Send a zero length message
6907c478bd9Sstevel@tonic-gate 					 * downstream.
6917c478bd9Sstevel@tonic-gate 					 */
6927c478bd9Sstevel@tonic-gate 					putnext(q, dack_ptr);
6937c478bd9Sstevel@tonic-gate 				}
6947c478bd9Sstevel@tonic-gate 			} else {
6957c478bd9Sstevel@tonic-gate 				/*
6967c478bd9Sstevel@tonic-gate 				 * Make a copy of this message and pass it on
6977c478bd9Sstevel@tonic-gate 				 * to the PCKT module.
6987c478bd9Sstevel@tonic-gate 				 */
6997c478bd9Sstevel@tonic-gate 				if ((pckt_msgp = copymsg(mp)) == NULL) {
7007c478bd9Sstevel@tonic-gate 					miocnak(q, mp, 0, EAGAIN);
7017c478bd9Sstevel@tonic-gate 					break;
7027c478bd9Sstevel@tonic-gate 				}
7037c478bd9Sstevel@tonic-gate 				putnext(q, pckt_msgp);
7047c478bd9Sstevel@tonic-gate 			}
7057c478bd9Sstevel@tonic-gate 			/*
7067c478bd9Sstevel@tonic-gate 			 * Send ACK upstream.
7077c478bd9Sstevel@tonic-gate 			 */
7087c478bd9Sstevel@tonic-gate 			mioc2ack(mp, NULL, 0, 0);
7097c478bd9Sstevel@tonic-gate 			qreply(q, mp);
7107c478bd9Sstevel@tonic-gate out:
7117c478bd9Sstevel@tonic-gate 			break;
7127c478bd9Sstevel@tonic-gate 
7137c478bd9Sstevel@tonic-gate 		case TCGETA:
7147c478bd9Sstevel@tonic-gate 			dp = allocb(sizeof (struct termio), BPRI_MED);
7157c478bd9Sstevel@tonic-gate 			if (dp == NULL) {
7167c478bd9Sstevel@tonic-gate 				miocnak(q, mp, 0, EAGAIN);
7177c478bd9Sstevel@tonic-gate 				break;
7187c478bd9Sstevel@tonic-gate 			}
7197c478bd9Sstevel@tonic-gate 			termiop = (struct termio *)dp->b_rptr;
7207c478bd9Sstevel@tonic-gate 			termiop->c_cflag = (ushort_t)ntp->cflags;
7217c478bd9Sstevel@tonic-gate 			mioc2ack(mp, dp, sizeof (struct termio), 0);
7227c478bd9Sstevel@tonic-gate 			qreply(q, mp);
7237c478bd9Sstevel@tonic-gate 			break;
7247c478bd9Sstevel@tonic-gate 
7257c478bd9Sstevel@tonic-gate 		case TCGETS:
7267c478bd9Sstevel@tonic-gate 			dp = allocb(sizeof (struct termios), BPRI_MED);
7277c478bd9Sstevel@tonic-gate 			if (dp == NULL) {
7287c478bd9Sstevel@tonic-gate 				miocnak(q, mp, 0, EAGAIN);
7297c478bd9Sstevel@tonic-gate 				break;
7307c478bd9Sstevel@tonic-gate 			}
7317c478bd9Sstevel@tonic-gate 			termiosp = (struct termios *)dp->b_rptr;
7327c478bd9Sstevel@tonic-gate 			termiosp->c_cflag = ntp->cflags;
7337c478bd9Sstevel@tonic-gate 			mioc2ack(mp, dp, sizeof (struct termios), 0);
7347c478bd9Sstevel@tonic-gate 			qreply(q, mp);
7357c478bd9Sstevel@tonic-gate 			break;
7367c478bd9Sstevel@tonic-gate 
7377c478bd9Sstevel@tonic-gate 		case TCSBRK:
7387c478bd9Sstevel@tonic-gate 			error = miocpullup(mp, sizeof (int));
7397c478bd9Sstevel@tonic-gate 			if (error != 0) {
7407c478bd9Sstevel@tonic-gate 				miocnak(q, mp, 0, error);
7417c478bd9Sstevel@tonic-gate 				break;
7427c478bd9Sstevel@tonic-gate 			}
7437c478bd9Sstevel@tonic-gate 
7447c478bd9Sstevel@tonic-gate 			/*
7457c478bd9Sstevel@tonic-gate 			 * Need a copy of this message to pass it on to
7467c478bd9Sstevel@tonic-gate 			 * the PCKT module.
7477c478bd9Sstevel@tonic-gate 			 */
7487c478bd9Sstevel@tonic-gate 			if ((pckt_msgp = copymsg(mp)) == NULL) {
7497c478bd9Sstevel@tonic-gate 				miocnak(q, mp, 0, EAGAIN);
7507c478bd9Sstevel@tonic-gate 				break;
7517c478bd9Sstevel@tonic-gate 			}
7527c478bd9Sstevel@tonic-gate 			/*
7537c478bd9Sstevel@tonic-gate 			 * Send a copy of the M_IOCTL to the PCKT module.
7547c478bd9Sstevel@tonic-gate 			 */
7557c478bd9Sstevel@tonic-gate 			putnext(q, pckt_msgp);
7567c478bd9Sstevel@tonic-gate 
7577c478bd9Sstevel@tonic-gate 			/*
7587c478bd9Sstevel@tonic-gate 			 * TCSBRK meaningful if data part of message is 0
759*bbf21555SRichard Lowe 			 * cf. termio(4I).
7607c478bd9Sstevel@tonic-gate 			 */
7617c478bd9Sstevel@tonic-gate 			if (!(*(int *)mp->b_cont->b_rptr))
7627c478bd9Sstevel@tonic-gate 				(void) putnextctl(q, M_BREAK);
7637c478bd9Sstevel@tonic-gate 			/*
7647c478bd9Sstevel@tonic-gate 			 * ACK the ioctl.
7657c478bd9Sstevel@tonic-gate 			 */
7667c478bd9Sstevel@tonic-gate 			mioc2ack(mp, NULL, 0, 0);
7677c478bd9Sstevel@tonic-gate 			qreply(q, mp);
7687c478bd9Sstevel@tonic-gate 			break;
7697c478bd9Sstevel@tonic-gate 
7707c478bd9Sstevel@tonic-gate 		case JWINSIZE:
7717c478bd9Sstevel@tonic-gate 		case TIOCGWINSZ:
7727c478bd9Sstevel@tonic-gate 		case TIOCSWINSZ:
7737c478bd9Sstevel@tonic-gate 			ptioc(q, mp, WRSIDE);
7747c478bd9Sstevel@tonic-gate 			break;
7757c478bd9Sstevel@tonic-gate 
7767c478bd9Sstevel@tonic-gate 		case TIOCSTI:
7777c478bd9Sstevel@tonic-gate 			/*
7787c478bd9Sstevel@tonic-gate 			 * Simulate typing of a character at the terminal.  In
7797c478bd9Sstevel@tonic-gate 			 * all cases, we acknowledge the ioctl and pass a copy
7807c478bd9Sstevel@tonic-gate 			 * of it along for the PCKT module to encapsulate.  If
7817c478bd9Sstevel@tonic-gate 			 * not in remote mode, we also process the ioctl
7827c478bd9Sstevel@tonic-gate 			 * itself, looping the character given as its argument
7837c478bd9Sstevel@tonic-gate 			 * back around to the read side.
7847c478bd9Sstevel@tonic-gate 			 */
7857c478bd9Sstevel@tonic-gate 
7867c478bd9Sstevel@tonic-gate 			/*
7877c478bd9Sstevel@tonic-gate 			 * Need a copy of this message to pass on to the PCKT
7887c478bd9Sstevel@tonic-gate 			 * module.
7897c478bd9Sstevel@tonic-gate 			 */
7907c478bd9Sstevel@tonic-gate 			if ((pckt_msgp = copymsg(mp)) == NULL) {
7917c478bd9Sstevel@tonic-gate 				miocnak(q, mp, 0, EAGAIN);
7927c478bd9Sstevel@tonic-gate 				break;
7937c478bd9Sstevel@tonic-gate 			}
7947c478bd9Sstevel@tonic-gate 			if ((ntp->state & REMOTEMODE) == 0) {
7957c478bd9Sstevel@tonic-gate 				mblk_t *bp;
7967c478bd9Sstevel@tonic-gate 
7977c478bd9Sstevel@tonic-gate 				error = miocpullup(mp, sizeof (char));
7987c478bd9Sstevel@tonic-gate 				if (error != 0) {
7997c478bd9Sstevel@tonic-gate 					freemsg(pckt_msgp);
8007c478bd9Sstevel@tonic-gate 					miocnak(q, mp, 0, error);
8017c478bd9Sstevel@tonic-gate 					break;
8027c478bd9Sstevel@tonic-gate 				}
8037c478bd9Sstevel@tonic-gate 
8047c478bd9Sstevel@tonic-gate 				/*
8057c478bd9Sstevel@tonic-gate 				 * The permission checking has already been
8067c478bd9Sstevel@tonic-gate 				 * done at the stream head, since it has to be
8077c478bd9Sstevel@tonic-gate 				 * done in the context of the process doing
8087c478bd9Sstevel@tonic-gate 				 * the call.
8097c478bd9Sstevel@tonic-gate 				 */
8107c478bd9Sstevel@tonic-gate 				if ((bp = allocb(1, BPRI_MED)) == NULL) {
8117c478bd9Sstevel@tonic-gate 					freemsg(pckt_msgp);
8127c478bd9Sstevel@tonic-gate 					miocnak(q, mp, 0, EAGAIN);
8137c478bd9Sstevel@tonic-gate 					break;
8147c478bd9Sstevel@tonic-gate 				}
8157c478bd9Sstevel@tonic-gate 				/*
8167c478bd9Sstevel@tonic-gate 				 * XXX:	Is EAGAIN really the right response to
8177c478bd9Sstevel@tonic-gate 				 *	flow control blockage?
8187c478bd9Sstevel@tonic-gate 				 */
8197c478bd9Sstevel@tonic-gate 				if (!bcanputnext(RD(q), mp->b_band)) {
8207c478bd9Sstevel@tonic-gate 					freemsg(bp);
8217c478bd9Sstevel@tonic-gate 					freemsg(pckt_msgp);
8227c478bd9Sstevel@tonic-gate 					miocnak(q, mp, 0, EAGAIN);
8237c478bd9Sstevel@tonic-gate 					break;
8247c478bd9Sstevel@tonic-gate 				}
8257c478bd9Sstevel@tonic-gate 				*bp->b_wptr++ = *mp->b_cont->b_rptr;
8267c478bd9Sstevel@tonic-gate 				qreply(q, bp);
8277c478bd9Sstevel@tonic-gate 			}
8287c478bd9Sstevel@tonic-gate 
8297c478bd9Sstevel@tonic-gate 			putnext(q, pckt_msgp);
8307c478bd9Sstevel@tonic-gate 			mioc2ack(mp, NULL, 0, 0);
8317c478bd9Sstevel@tonic-gate 			qreply(q, mp);
8327c478bd9Sstevel@tonic-gate 			break;
8337c478bd9Sstevel@tonic-gate 
8347c478bd9Sstevel@tonic-gate 		case PTSSTTY:
8357c478bd9Sstevel@tonic-gate 			if (ntp->state & IS_PTSTTY) {
8367c478bd9Sstevel@tonic-gate 				miocnak(q, mp, 0, EEXIST);
8377c478bd9Sstevel@tonic-gate 			} else {
8387c478bd9Sstevel@tonic-gate 				ntp->state |= IS_PTSTTY;
8397c478bd9Sstevel@tonic-gate 				mioc2ack(mp, NULL, 0, 0);
8407c478bd9Sstevel@tonic-gate 				qreply(q, mp);
8417c478bd9Sstevel@tonic-gate 			}
8427c478bd9Sstevel@tonic-gate 			break;
8437c478bd9Sstevel@tonic-gate 
8447c478bd9Sstevel@tonic-gate 		default:
8457c478bd9Sstevel@tonic-gate 			/*
8461fa2a664SJoshua M. Clulow 			 * End of the line.  The subsidiary driver doesn't see
8471fa2a664SJoshua M. Clulow 			 * any ioctls that we don't explicitly pass along to
8481fa2a664SJoshua M. Clulow 			 * it.
8497c478bd9Sstevel@tonic-gate 			 */
8507c478bd9Sstevel@tonic-gate 			miocnak(q, mp, 0, EINVAL);
8517c478bd9Sstevel@tonic-gate 			break;
8527c478bd9Sstevel@tonic-gate 		}
8537c478bd9Sstevel@tonic-gate 		break;
8547c478bd9Sstevel@tonic-gate 
8557c478bd9Sstevel@tonic-gate 	case M_DELAY: /* tty delays not supported */
8567c478bd9Sstevel@tonic-gate 		freemsg(mp);
8577c478bd9Sstevel@tonic-gate 		break;
8587c478bd9Sstevel@tonic-gate 
8597c478bd9Sstevel@tonic-gate 	case M_DATA:
8607c478bd9Sstevel@tonic-gate 		if ((mp->b_wptr - mp->b_rptr) < 0) {
8617c478bd9Sstevel@tonic-gate 			/*
8627c478bd9Sstevel@tonic-gate 			 * Free all bad length messages.
8637c478bd9Sstevel@tonic-gate 			 */
8647c478bd9Sstevel@tonic-gate 			freemsg(mp);
8657c478bd9Sstevel@tonic-gate 			break;
8667c478bd9Sstevel@tonic-gate 		} else if ((mp->b_wptr - mp->b_rptr) == 0) {
8677c478bd9Sstevel@tonic-gate 			if (!(ntp->state & IS_PTSTTY)) {
8687c478bd9Sstevel@tonic-gate 				freemsg(mp);
8697c478bd9Sstevel@tonic-gate 				break;
8707c478bd9Sstevel@tonic-gate 			}
8717c478bd9Sstevel@tonic-gate 		}
8727c478bd9Sstevel@tonic-gate 		if (ntp->state & OFLOW_CTL)
8737c478bd9Sstevel@tonic-gate 			return (0);
874b80bb91bSToomas Soome 		/* FALLTHROUGH */
8757c478bd9Sstevel@tonic-gate 
8767c478bd9Sstevel@tonic-gate 	default:
8777c478bd9Sstevel@tonic-gate 		putnext(q, mp);
8787c478bd9Sstevel@tonic-gate 		break;
8797c478bd9Sstevel@tonic-gate 
8807c478bd9Sstevel@tonic-gate 	}
8817c478bd9Sstevel@tonic-gate 
8827c478bd9Sstevel@tonic-gate 	return (1);
8837c478bd9Sstevel@tonic-gate }
8847c478bd9Sstevel@tonic-gate 
8857c478bd9Sstevel@tonic-gate /*
8867c478bd9Sstevel@tonic-gate  * Message must be of type M_IOCTL or M_IOCDATA for this routine to be called.
8877c478bd9Sstevel@tonic-gate  */
8887c478bd9Sstevel@tonic-gate static void
ptioc(queue_t * q,mblk_t * mp,int qside)8897c478bd9Sstevel@tonic-gate ptioc(queue_t *q, mblk_t *mp, int qside)
8907c478bd9Sstevel@tonic-gate {
8917c478bd9Sstevel@tonic-gate 	struct ptem *tp;
8927c478bd9Sstevel@tonic-gate 	struct iocblk *iocp;
8937c478bd9Sstevel@tonic-gate 	struct winsize *wb;
8947c478bd9Sstevel@tonic-gate 	struct jwinsize *jwb;
8957c478bd9Sstevel@tonic-gate 	mblk_t *tmp;
8967c478bd9Sstevel@tonic-gate 	mblk_t *pckt_msgp;	/* message sent to the PCKT module */
8977c478bd9Sstevel@tonic-gate 	int error;
8987c478bd9Sstevel@tonic-gate 
8997c478bd9Sstevel@tonic-gate 	iocp = (struct iocblk *)mp->b_rptr;
9007c478bd9Sstevel@tonic-gate 	tp = (struct ptem *)q->q_ptr;
9017c478bd9Sstevel@tonic-gate 
9027c478bd9Sstevel@tonic-gate 	switch (iocp->ioc_cmd) {
9037c478bd9Sstevel@tonic-gate 
9047c478bd9Sstevel@tonic-gate 	case JWINSIZE:
9057c478bd9Sstevel@tonic-gate 		/*
9067c478bd9Sstevel@tonic-gate 		 * For compatibility:  If all zeros, NAK the message for dumb
9077c478bd9Sstevel@tonic-gate 		 * terminals.
9087c478bd9Sstevel@tonic-gate 		 */
9097c478bd9Sstevel@tonic-gate 		if ((tp->wsz.ws_row == 0) && (tp->wsz.ws_col == 0) &&
9107c478bd9Sstevel@tonic-gate 		    (tp->wsz.ws_xpixel == 0) && (tp->wsz.ws_ypixel == 0)) {
9117c478bd9Sstevel@tonic-gate 			miocnak(q, mp, 0, EINVAL);
9127c478bd9Sstevel@tonic-gate 			return;
9137c478bd9Sstevel@tonic-gate 		}
9147c478bd9Sstevel@tonic-gate 
9157c478bd9Sstevel@tonic-gate 		tmp = allocb(sizeof (struct jwinsize), BPRI_MED);
9167c478bd9Sstevel@tonic-gate 		if (tmp == NULL) {
9177c478bd9Sstevel@tonic-gate 			miocnak(q, mp, 0, EAGAIN);
9187c478bd9Sstevel@tonic-gate 			return;
9197c478bd9Sstevel@tonic-gate 		}
9207c478bd9Sstevel@tonic-gate 
9217c478bd9Sstevel@tonic-gate 		if (iocp->ioc_count == TRANSPARENT)
9227c478bd9Sstevel@tonic-gate 			mcopyout(mp, NULL, sizeof (struct jwinsize), NULL, tmp);
9237c478bd9Sstevel@tonic-gate 		else
9247c478bd9Sstevel@tonic-gate 			mioc2ack(mp, tmp, sizeof (struct jwinsize), 0);
9257c478bd9Sstevel@tonic-gate 
9267c478bd9Sstevel@tonic-gate 		jwb = (struct jwinsize *)mp->b_cont->b_rptr;
9277c478bd9Sstevel@tonic-gate 		jwb->bytesx = tp->wsz.ws_col;
9287c478bd9Sstevel@tonic-gate 		jwb->bytesy = tp->wsz.ws_row;
9297c478bd9Sstevel@tonic-gate 		jwb->bitsx = tp->wsz.ws_xpixel;
9307c478bd9Sstevel@tonic-gate 		jwb->bitsy = tp->wsz.ws_ypixel;
9317c478bd9Sstevel@tonic-gate 
9327c478bd9Sstevel@tonic-gate 		qreply(q, mp);
9337c478bd9Sstevel@tonic-gate 		return;
9347c478bd9Sstevel@tonic-gate 
9357c478bd9Sstevel@tonic-gate 	case TIOCGWINSZ:
9367c478bd9Sstevel@tonic-gate 		tmp = allocb(sizeof (struct winsize), BPRI_MED);
9377c478bd9Sstevel@tonic-gate 		if (tmp == NULL) {
9387c478bd9Sstevel@tonic-gate 			miocnak(q, mp, 0, EAGAIN);
9397c478bd9Sstevel@tonic-gate 			return;
9407c478bd9Sstevel@tonic-gate 		}
9417c478bd9Sstevel@tonic-gate 
9427c478bd9Sstevel@tonic-gate 		mioc2ack(mp, tmp, sizeof (struct winsize), 0);
9437c478bd9Sstevel@tonic-gate 
9447c478bd9Sstevel@tonic-gate 		wb = (struct winsize *)mp->b_cont->b_rptr;
9457c478bd9Sstevel@tonic-gate 		wb->ws_row = tp->wsz.ws_row;
9467c478bd9Sstevel@tonic-gate 		wb->ws_col = tp->wsz.ws_col;
9477c478bd9Sstevel@tonic-gate 		wb->ws_xpixel = tp->wsz.ws_xpixel;
9487c478bd9Sstevel@tonic-gate 		wb->ws_ypixel = tp->wsz.ws_ypixel;
9497c478bd9Sstevel@tonic-gate 
9507c478bd9Sstevel@tonic-gate 		qreply(q, mp);
9517c478bd9Sstevel@tonic-gate 		return;
9527c478bd9Sstevel@tonic-gate 
9537c478bd9Sstevel@tonic-gate 	case TIOCSWINSZ:
9547c478bd9Sstevel@tonic-gate 		error = miocpullup(mp, sizeof (struct winsize));
9557c478bd9Sstevel@tonic-gate 		if (error != 0) {
9567c478bd9Sstevel@tonic-gate 			miocnak(q, mp, 0, error);
9577c478bd9Sstevel@tonic-gate 			return;
9587c478bd9Sstevel@tonic-gate 		}
9597c478bd9Sstevel@tonic-gate 
9607c478bd9Sstevel@tonic-gate 		wb = (struct winsize *)mp->b_cont->b_rptr;
9617c478bd9Sstevel@tonic-gate 		/*
9627c478bd9Sstevel@tonic-gate 		 * Send a SIGWINCH signal if the row/col information has
9637c478bd9Sstevel@tonic-gate 		 * changed.
9647c478bd9Sstevel@tonic-gate 		 */
9657c478bd9Sstevel@tonic-gate 		if ((tp->wsz.ws_row != wb->ws_row) ||
9667c478bd9Sstevel@tonic-gate 		    (tp->wsz.ws_col != wb->ws_col) ||
9677c478bd9Sstevel@tonic-gate 		    (tp->wsz.ws_xpixel != wb->ws_xpixel) ||
9687c478bd9Sstevel@tonic-gate 		    (tp->wsz.ws_ypixel != wb->ws_xpixel)) {
9697c478bd9Sstevel@tonic-gate 			/*
9707c478bd9Sstevel@tonic-gate 			 * SIGWINCH is always sent upstream.
9717c478bd9Sstevel@tonic-gate 			 */
9727c478bd9Sstevel@tonic-gate 			if (qside == WRSIDE)
9737c478bd9Sstevel@tonic-gate 				(void) putnextctl1(RD(q), M_SIG, SIGWINCH);
9747c478bd9Sstevel@tonic-gate 			else if (qside == RDSIDE)
9757c478bd9Sstevel@tonic-gate 				(void) putnextctl1(q, M_SIG, SIGWINCH);
9767c478bd9Sstevel@tonic-gate 			/*
9777c478bd9Sstevel@tonic-gate 			 * Message may have come in as an M_IOCDATA; pass it
9781fa2a664SJoshua M. Clulow 			 * to the manager side as an M_IOCTL.
9797c478bd9Sstevel@tonic-gate 			 */
9807c478bd9Sstevel@tonic-gate 			mp->b_datap->db_type = M_IOCTL;
9817c478bd9Sstevel@tonic-gate 			if (qside == WRSIDE) {
9827c478bd9Sstevel@tonic-gate 				/*
9837c478bd9Sstevel@tonic-gate 				 * Need a copy of this message to pass on to
9847c478bd9Sstevel@tonic-gate 				 * the PCKT module, only if the M_IOCTL
9851fa2a664SJoshua M. Clulow 				 * orginated from the subsidiary side.
9867c478bd9Sstevel@tonic-gate 				 */
9877c478bd9Sstevel@tonic-gate 				if ((pckt_msgp = copymsg(mp)) == NULL) {
9887c478bd9Sstevel@tonic-gate 					miocnak(q, mp, 0, EAGAIN);
9897c478bd9Sstevel@tonic-gate 					return;
9907c478bd9Sstevel@tonic-gate 				}
9917c478bd9Sstevel@tonic-gate 				putnext(q, pckt_msgp);
9927c478bd9Sstevel@tonic-gate 			}
9937c478bd9Sstevel@tonic-gate 			tp->wsz.ws_row = wb->ws_row;
9947c478bd9Sstevel@tonic-gate 			tp->wsz.ws_col = wb->ws_col;
9957c478bd9Sstevel@tonic-gate 			tp->wsz.ws_xpixel = wb->ws_xpixel;
9967c478bd9Sstevel@tonic-gate 			tp->wsz.ws_ypixel = wb->ws_ypixel;
9977c478bd9Sstevel@tonic-gate 		}
9987c478bd9Sstevel@tonic-gate 
9997c478bd9Sstevel@tonic-gate 		mioc2ack(mp, NULL, 0, 0);
10007c478bd9Sstevel@tonic-gate 		qreply(q, mp);
10017c478bd9Sstevel@tonic-gate 		return;
10027c478bd9Sstevel@tonic-gate 
10037c478bd9Sstevel@tonic-gate 	case TIOCSIGNAL: {
10047c478bd9Sstevel@tonic-gate 		/*
10051fa2a664SJoshua M. Clulow 		 * This ioctl can emanate from the manager side in remote
10067c478bd9Sstevel@tonic-gate 		 * mode only.
10077c478bd9Sstevel@tonic-gate 		 */
10087c478bd9Sstevel@tonic-gate 		int	sig;
10097c478bd9Sstevel@tonic-gate 
10107c478bd9Sstevel@tonic-gate 		if (DB_TYPE(mp) == M_IOCTL && iocp->ioc_count != TRANSPARENT) {
10117c478bd9Sstevel@tonic-gate 			error = miocpullup(mp, sizeof (int));
10127c478bd9Sstevel@tonic-gate 			if (error != 0) {
10137c478bd9Sstevel@tonic-gate 				miocnak(q, mp, 0, error);
10147c478bd9Sstevel@tonic-gate 				return;
10157c478bd9Sstevel@tonic-gate 			}
10167c478bd9Sstevel@tonic-gate 		}
10177c478bd9Sstevel@tonic-gate 
10187c478bd9Sstevel@tonic-gate 		if (DB_TYPE(mp) == M_IOCDATA || iocp->ioc_count != TRANSPARENT)
10197c478bd9Sstevel@tonic-gate 			sig = *(int *)mp->b_cont->b_rptr;
10207c478bd9Sstevel@tonic-gate 		else
10217c478bd9Sstevel@tonic-gate 			sig = (int)*(intptr_t *)mp->b_cont->b_rptr;
10227c478bd9Sstevel@tonic-gate 
10237c478bd9Sstevel@tonic-gate 		if (sig < 1 || sig >= NSIG) {
10247c478bd9Sstevel@tonic-gate 			miocnak(q, mp, 0, EINVAL);
10257c478bd9Sstevel@tonic-gate 			return;
10267c478bd9Sstevel@tonic-gate 		}
10277c478bd9Sstevel@tonic-gate 
10287c478bd9Sstevel@tonic-gate 		/*
10291fa2a664SJoshua M. Clulow 		 * Send an M_PCSIG message up the subsidiary's read side and
10301fa2a664SJoshua M. Clulow 		 * respond back to the manager with an ACK or NAK as
10317c478bd9Sstevel@tonic-gate 		 * appropriate.
10327c478bd9Sstevel@tonic-gate 		 */
10337c478bd9Sstevel@tonic-gate 		if (putnextctl1(q, M_PCSIG, sig) == 0) {
10347c478bd9Sstevel@tonic-gate 			miocnak(q, mp, 0, EAGAIN);
10357c478bd9Sstevel@tonic-gate 			return;
10367c478bd9Sstevel@tonic-gate 		}
10377c478bd9Sstevel@tonic-gate 
10387c478bd9Sstevel@tonic-gate 		mioc2ack(mp, NULL, 0, 0);
10397c478bd9Sstevel@tonic-gate 		qreply(q, mp);
10407c478bd9Sstevel@tonic-gate 		return;
10417c478bd9Sstevel@tonic-gate 	}
10427c478bd9Sstevel@tonic-gate 
10437c478bd9Sstevel@tonic-gate 	case TIOCREMOTE: {
10447c478bd9Sstevel@tonic-gate 		int	onoff;
10457c478bd9Sstevel@tonic-gate 		mblk_t	*mctlp;
10467c478bd9Sstevel@tonic-gate 
10477c478bd9Sstevel@tonic-gate 		if (DB_TYPE(mp) == M_IOCTL) {
10487c478bd9Sstevel@tonic-gate 			error = miocpullup(mp, sizeof (int));
10497c478bd9Sstevel@tonic-gate 			if (error != 0) {
10507c478bd9Sstevel@tonic-gate 				miocnak(q, mp, 0, error);
10517c478bd9Sstevel@tonic-gate 				return;
10527c478bd9Sstevel@tonic-gate 			}
10537c478bd9Sstevel@tonic-gate 		}
10547c478bd9Sstevel@tonic-gate 
10557c478bd9Sstevel@tonic-gate 		onoff = *(int *)mp->b_cont->b_rptr;
10567c478bd9Sstevel@tonic-gate 
10577c478bd9Sstevel@tonic-gate 		/*
10587c478bd9Sstevel@tonic-gate 		 * Send M_CTL up using the iocblk format.
10597c478bd9Sstevel@tonic-gate 		 */
10607c478bd9Sstevel@tonic-gate 		mctlp = mkiocb(onoff ? MC_NO_CANON : MC_DO_CANON);
10617c478bd9Sstevel@tonic-gate 		if (mctlp == NULL) {
10627c478bd9Sstevel@tonic-gate 			miocnak(q, mp, 0, EAGAIN);
10637c478bd9Sstevel@tonic-gate 			return;
10647c478bd9Sstevel@tonic-gate 		}
10657c478bd9Sstevel@tonic-gate 		mctlp->b_datap->db_type = M_CTL;
10667c478bd9Sstevel@tonic-gate 		putnext(q, mctlp);
10677c478bd9Sstevel@tonic-gate 
10687c478bd9Sstevel@tonic-gate 		/*
10697c478bd9Sstevel@tonic-gate 		 * ACK the ioctl.
10707c478bd9Sstevel@tonic-gate 		 */
10717c478bd9Sstevel@tonic-gate 		mioc2ack(mp, NULL, 0, 0);
10727c478bd9Sstevel@tonic-gate 		qreply(q, mp);
10737c478bd9Sstevel@tonic-gate 
10747c478bd9Sstevel@tonic-gate 		/*
10757c478bd9Sstevel@tonic-gate 		 * Record state change.
10767c478bd9Sstevel@tonic-gate 		 */
10777c478bd9Sstevel@tonic-gate 		if (onoff)
10787c478bd9Sstevel@tonic-gate 			tp->state |= REMOTEMODE;
10797c478bd9Sstevel@tonic-gate 		else
10807c478bd9Sstevel@tonic-gate 			tp->state &= ~REMOTEMODE;
10817c478bd9Sstevel@tonic-gate 		return;
10827c478bd9Sstevel@tonic-gate 	}
10837c478bd9Sstevel@tonic-gate 
10847c478bd9Sstevel@tonic-gate 	default:
10857c478bd9Sstevel@tonic-gate 		putnext(q, mp);
10867c478bd9Sstevel@tonic-gate 		return;
10877c478bd9Sstevel@tonic-gate 	}
10887c478bd9Sstevel@tonic-gate }
1089