Home | History | Annotate | Line # | Download | only in sunos
sunos_ioctl.c revision 1.2
      1  1.1  deraadt /*
      2  1.2  deraadt /*
      3  1.2  deraadt  * Copyright (c) 1993 Markus Wild.
      4  1.2  deraadt  * All rights reserved.
      5  1.1  deraadt  *
      6  1.1  deraadt  * Redistribution and use in source and binary forms, with or without
      7  1.1  deraadt  * modification, are permitted provided that the following conditions
      8  1.1  deraadt  * are met:
      9  1.1  deraadt  * 1. Redistributions of source code must retain the above copyright
     10  1.1  deraadt  *    notice, this list of conditions and the following disclaimer.
     11  1.2  deraadt  * 2. The name of the author may not be used to endorse or promote products
     12  1.2  deraadt  *    derived from this software withough specific prior written permission
     13  1.1  deraadt  *
     14  1.2  deraadt  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     15  1.2  deraadt  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     16  1.2  deraadt  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     17  1.2  deraadt  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     18  1.2  deraadt  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     19  1.2  deraadt  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     20  1.2  deraadt  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     21  1.2  deraadt  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     22  1.2  deraadt  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     23  1.2  deraadt  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     24  1.1  deraadt  *
     25  1.2  deraadt  * loosely from: Header: sun_ioctl.c,v 1.7 93/05/28 04:40:43 torek Exp
     26  1.2  deraadt  * $Id: sunos_ioctl.c,v 1.2 1993/11/10 15:03:33 deraadt Exp $
     27  1.1  deraadt  */
     28  1.1  deraadt 
     29  1.1  deraadt #include <sys/param.h>
     30  1.1  deraadt #include <sys/proc.h>
     31  1.1  deraadt #include <sys/file.h>
     32  1.1  deraadt #include <sys/filedesc.h>
     33  1.1  deraadt #include <sys/ioctl.h>
     34  1.1  deraadt #include <sys/termios.h>
     35  1.1  deraadt #include <sys/tty.h>
     36  1.1  deraadt 
     37  1.1  deraadt /*
     38  1.1  deraadt  * SunOS ioctl calls.
     39  1.1  deraadt  * This file is something of a hodge-podge.
     40  1.1  deraadt  * Support gets added as things turn up....
     41  1.1  deraadt  */
     42  1.1  deraadt 
     43  1.1  deraadt struct sun_ttysize {
     44  1.1  deraadt 	int	ts_row;
     45  1.1  deraadt 	int	ts_col;
     46  1.1  deraadt };
     47  1.1  deraadt 
     48  1.1  deraadt struct sun_termio {
     49  1.1  deraadt 	u_short	c_iflag;
     50  1.1  deraadt 	u_short	c_oflag;
     51  1.1  deraadt 	u_short	c_cflag;
     52  1.1  deraadt 	u_short	c_lflag;
     53  1.1  deraadt 	char	c_line;
     54  1.1  deraadt 	unsigned char c_cc[8];
     55  1.1  deraadt };
     56  1.2  deraadt #define SUN_TCGETA	_IOR('T', 1, struct sun_termio)
     57  1.2  deraadt #define SUN_TCSETA	_IOW('T', 2, struct sun_termio)
     58  1.2  deraadt #define SUN_TCSETAW	_IOW('T', 3, struct sun_termio)
     59  1.2  deraadt #define SUN_TCSETAF	_IOW('T', 4, struct sun_termio)
     60  1.2  deraadt #define SUN_TCSBRK	_IO('T', 5)
     61  1.2  deraadt 
     62  1.2  deraadt struct sun_termios {
     63  1.2  deraadt 	u_long	c_iflag;
     64  1.2  deraadt 	u_long	c_oflag;
     65  1.2  deraadt 	u_long	c_cflag;
     66  1.2  deraadt 	u_long	c_lflag;
     67  1.2  deraadt 	char	c_line;
     68  1.2  deraadt 	u_char	c_cc[17];
     69  1.2  deraadt };
     70  1.2  deraadt #define SUN_TCXONC	_IO('T', 6)
     71  1.2  deraadt #define SUN_TCFLSH	_IO('T', 7)
     72  1.2  deraadt #define SUN_TCGETS	_IOR('T', 8, struct sun_termios)
     73  1.2  deraadt #define SUN_TCSETS	_IOW('T', 9, struct sun_termios)
     74  1.2  deraadt #define SUN_TCSETSW	_IOW('T', 10, struct sun_termios)
     75  1.2  deraadt #define SUN_TCSETSF	_IOW('T', 11, struct sun_termios)
     76  1.2  deraadt #define SUN_TCSNDBRK	_IO('T', 12)
     77  1.2  deraadt #define SUN_TCDRAIN	_IO('T', 13)
     78  1.2  deraadt 
     79  1.2  deraadt static struct speedtab sptab[] = {
     80  1.2  deraadt 	{ 0, 0 },
     81  1.2  deraadt 	{ 50, 1 },
     82  1.2  deraadt 	{ 75, 2 },
     83  1.2  deraadt 	{ 110, 3 },
     84  1.2  deraadt 	{ 134, 4 },
     85  1.2  deraadt 	{ 135, 4 },
     86  1.2  deraadt 	{ 150, 5 },
     87  1.2  deraadt 	{ 200, 6 },
     88  1.2  deraadt 	{ 300, 7 },
     89  1.2  deraadt 	{ 600, 8 },
     90  1.2  deraadt 	{ 1200, 9 },
     91  1.2  deraadt 	{ 1800, 10 },
     92  1.2  deraadt 	{ 2400, 11 },
     93  1.2  deraadt 	{ 4800, 12 },
     94  1.2  deraadt 	{ 9600, 13 },
     95  1.2  deraadt 	{ 19200, 14 },
     96  1.2  deraadt 	{ 38400, 15 },
     97  1.2  deraadt 	{ -1, -1 }
     98  1.2  deraadt };
     99  1.2  deraadt 
    100  1.2  deraadt static u_long s2btab[] = {
    101  1.2  deraadt 	0,
    102  1.2  deraadt 	50,
    103  1.2  deraadt 	75,
    104  1.2  deraadt 	110,
    105  1.2  deraadt 	134,
    106  1.2  deraadt 	150,
    107  1.2  deraadt 	200,
    108  1.2  deraadt 	300,
    109  1.2  deraadt 	600,
    110  1.2  deraadt 	1200,
    111  1.2  deraadt 	1800,
    112  1.2  deraadt 	2400,
    113  1.2  deraadt 	4800,
    114  1.2  deraadt 	9600,
    115  1.2  deraadt 	19200,
    116  1.2  deraadt 	38400,
    117  1.2  deraadt };
    118  1.2  deraadt 
    119  1.2  deraadt /*
    120  1.2  deraadt  * these two conversion functions have mostly been done
    121  1.2  deraadt  * with some perl cut&paste, then handedited to comment
    122  1.2  deraadt  * out what doesn't exist under NetBSD.
    123  1.2  deraadt  * A note from Markus's code:
    124  1.2  deraadt  *	(l & BITMASK1) / BITMASK1 * BITMASK2  is translated
    125  1.2  deraadt  *	optimally by gcc m68k, much better than any ?: stuff.
    126  1.2  deraadt  *	Code may vary with different architectures of course.
    127  1.2  deraadt  *
    128  1.2  deraadt  * I don't know what optimizer you used, but seeing divu's and
    129  1.2  deraadt  * bfextu's in the m68k assembly output did not encourage me...
    130  1.2  deraadt  * as well, gcc on the sparc definately generates much better
    131  1.2  deraadt  * code with ?:.
    132  1.2  deraadt  */
    133  1.2  deraadt 
    134  1.2  deraadt static void
    135  1.2  deraadt stios2btios(st, bt)
    136  1.2  deraadt 	struct sun_termios *st;
    137  1.2  deraadt 	struct termios *bt;
    138  1.2  deraadt {
    139  1.2  deraadt 	register u_long l, r;
    140  1.2  deraadt 
    141  1.2  deraadt 	l = st->c_iflag;
    142  1.2  deraadt 	r = (	((l & 0x00000001) ? IGNBRK	: 0) |
    143  1.2  deraadt 		((l & 0x00000002) ? BRKINT	: 0) |
    144  1.2  deraadt 		((l & 0x00000004) ? IGNPAR	: 0) |
    145  1.2  deraadt 		((l & 0x00000008) ? PARMRK	: 0) |
    146  1.2  deraadt 		((l & 0x00000010) ? INPCK	: 0) |
    147  1.2  deraadt 		((l & 0x00000020) ? ISTRIP	: 0) |
    148  1.2  deraadt 		((l & 0x00000040) ? INLCR	: 0) |
    149  1.2  deraadt 		((l & 0x00000080) ? IGNCR	: 0) |
    150  1.2  deraadt 		((l & 0x00000100) ? ICRNL	: 0) |
    151  1.2  deraadt 	/*	((l & 0x00000200) ? IUCLC	: 0) |	*/
    152  1.2  deraadt 		((l & 0x00000400) ? IXON	: 0) |
    153  1.2  deraadt 		((l & 0x00000800) ? IXANY	: 0) |
    154  1.2  deraadt 		((l & 0x00001000) ? IXOFF	: 0) |
    155  1.2  deraadt 		((l & 0x00002000) ? IMAXBEL	: 0));
    156  1.2  deraadt 	bt->c_iflag = r;
    157  1.2  deraadt 
    158  1.2  deraadt 	l = st->c_oflag;
    159  1.2  deraadt 	r = (	((l & 0x00000001) ? OPOST	: 0) |
    160  1.2  deraadt 	/*	((l & 0x00000002) ? OLCUC	: 0) | */
    161  1.2  deraadt 		((l & 0x00000004) ? ONLCR	: 0) |
    162  1.2  deraadt 	/*	((l & 0x00000008) ? OCRNL	: 0) | */
    163  1.2  deraadt 	/*	((l & 0x00000010) ? ONOCR	: 0) | */
    164  1.2  deraadt 	/*	((l & 0x00000020) ? ONLRET	: 0) | */
    165  1.2  deraadt 	/*	((l & 0x00000040) ? OFILL	: 0) | */
    166  1.2  deraadt 	/*	((l & 0x00000080) ? OFDEL	: 0) | */
    167  1.2  deraadt 	/*	((l & 0x00000100) ? NLDLY	: 0) | */
    168  1.2  deraadt 	/*	((l & 0x00000100) ? NL1		: 0) | */
    169  1.2  deraadt 	/*	((l & 0x00000600) ? CRDLY	: 0) | */
    170  1.2  deraadt 	/*	((l & 0x00000200) ? CR1		: 0) | */
    171  1.2  deraadt 	/*	((l & 0x00000400) ? CR2		: 0) | */
    172  1.2  deraadt 	/*	((l & 0x00000600) ? CR3		: 0) | */
    173  1.2  deraadt 	/*	((l & 0x00001800) ? TABDLY	: 0) | */
    174  1.2  deraadt 	/*	((l & 0x00000800) ? TAB1	: 0) | */
    175  1.2  deraadt 	/*	((l & 0x00001000) ? TAB2	: 0) | */
    176  1.2  deraadt 		((l & 0x00001800) ? OXTABS	: 0)
    177  1.2  deraadt 	/*	((l & 0x00002000) ? BSDLY	: 0) | */
    178  1.2  deraadt 	/*	((l & 0x00002000) ? BS1		: 0) | */
    179  1.2  deraadt 	/*	((l & 0x00004000) ? VTDLY	: 0) | */
    180  1.2  deraadt 	/*	((l & 0x00004000) ? VT1		: 0) | */
    181  1.2  deraadt 	/*	((l & 0x00008000) ? FFDLY	: 0) | */
    182  1.2  deraadt 	/*	((l & 0x00008000) ? FF1		: 0) | */
    183  1.2  deraadt 	/*	((l & 0x00010000) ? PAGEOUT	: 0) | */
    184  1.2  deraadt 	/*	((l & 0x00020000) ? WRAP	: 0) */ );
    185  1.2  deraadt 	bt->c_oflag = r;
    186  1.2  deraadt 
    187  1.2  deraadt 	l = st->c_cflag;
    188  1.2  deraadt 	r = (	((l & 0x00000010) ? CS6		: 0) |
    189  1.2  deraadt 		((l & 0x00000020) ? CS7		: 0) |
    190  1.2  deraadt 		((l & 0x00000030) ? CS8		: 0) |
    191  1.2  deraadt 		((l & 0x00000040) ? CSTOPB	: 0) |
    192  1.2  deraadt 		((l & 0x00000080) ? CREAD	: 0) |
    193  1.2  deraadt 		((l & 0x00000100) ? PARENB	: 0) |
    194  1.2  deraadt 		((l & 0x00000200) ? PARODD	: 0) |
    195  1.2  deraadt 		((l & 0x00000400) ? HUPCL	: 0) |
    196  1.2  deraadt 		((l & 0x00000800) ? CLOCAL	: 0) |
    197  1.2  deraadt 	/*	((l & 0x00001000) ? LOBLK	: 0) | */
    198  1.2  deraadt 		((l & 0x80000000) ? (CRTS_IFLOW|CCTS_OFLOW) : 0) );
    199  1.2  deraadt 	bt->c_cflag = r;
    200  1.2  deraadt 
    201  1.2  deraadt 	bt->c_ispeed = bt->c_ospeed = s2btab[l & 0x0000000f];
    202  1.2  deraadt 
    203  1.2  deraadt 	l = st->c_lflag;
    204  1.2  deraadt 	r = (	((l & 0x00000001) ? ISIG	: 0) |
    205  1.2  deraadt 		((l & 0x00000002) ? ICANON	: 0) |
    206  1.2  deraadt 	/*	((l & 0x00000004) ? XCASE	: 0) | */
    207  1.2  deraadt 		((l & 0x00000008) ? ECHO	: 0) |
    208  1.2  deraadt 		((l & 0x00000010) ? ECHOE	: 0) |
    209  1.2  deraadt 		((l & 0x00000020) ? ECHOK	: 0) |
    210  1.2  deraadt 		((l & 0x00000040) ? ECHONL	: 0) |
    211  1.2  deraadt 		((l & 0x00000080) ? NOFLSH	: 0) |
    212  1.2  deraadt 		((l & 0x00000100) ? TOSTOP	: 0) |
    213  1.2  deraadt 		((l & 0x00000200) ? ECHOCTL	: 0) |
    214  1.2  deraadt 		((l & 0x00000400) ? ECHOPRT	: 0) |
    215  1.2  deraadt 		((l & 0x00000800) ? ECHOKE	: 0) |
    216  1.2  deraadt 	/*	((l & 0x00001000) ? DEFECHO	: 0) | */
    217  1.2  deraadt 		((l & 0x00002000) ? FLUSHO	: 0) |
    218  1.2  deraadt 		((l & 0x00004000) ? PENDIN	: 0) );
    219  1.2  deraadt 	bt->c_lflag = r;
    220  1.2  deraadt 
    221  1.2  deraadt 	bt->c_cc[VINTR]    = st->c_cc[0]  ? st->c_cc[0]  : _POSIX_VDISABLE;
    222  1.2  deraadt 	bt->c_cc[VQUIT]    = st->c_cc[1]  ? st->c_cc[1]  : _POSIX_VDISABLE;
    223  1.2  deraadt 	bt->c_cc[VERASE]   = st->c_cc[2]  ? st->c_cc[2]  : _POSIX_VDISABLE;
    224  1.2  deraadt 	bt->c_cc[VKILL]    = st->c_cc[3]  ? st->c_cc[3]  : _POSIX_VDISABLE;
    225  1.2  deraadt 	bt->c_cc[VEOF]     = st->c_cc[4]  ? st->c_cc[4]  : _POSIX_VDISABLE;
    226  1.2  deraadt 	bt->c_cc[VEOL]     = st->c_cc[5]  ? st->c_cc[5]  : _POSIX_VDISABLE;
    227  1.2  deraadt 	bt->c_cc[VEOL2]    = st->c_cc[6]  ? st->c_cc[6]  : _POSIX_VDISABLE;
    228  1.2  deraadt     /*	bt->c_cc[VSWTCH]   = st->c_cc[7]  ? st->c_cc[7]  : _POSIX_VDISABLE; */
    229  1.2  deraadt 	bt->c_cc[VSTART]   = st->c_cc[8]  ? st->c_cc[8]  : _POSIX_VDISABLE;
    230  1.2  deraadt 	bt->c_cc[VSTOP]    = st->c_cc[9]  ? st->c_cc[9]  : _POSIX_VDISABLE;
    231  1.2  deraadt 	bt->c_cc[VSUSP]    = st->c_cc[10] ? st->c_cc[10] : _POSIX_VDISABLE;
    232  1.2  deraadt 	bt->c_cc[VDSUSP]   = st->c_cc[11] ? st->c_cc[11] : _POSIX_VDISABLE;
    233  1.2  deraadt 	bt->c_cc[VREPRINT] = st->c_cc[12] ? st->c_cc[12] : _POSIX_VDISABLE;
    234  1.2  deraadt 	bt->c_cc[VDISCARD] = st->c_cc[13] ? st->c_cc[13] : _POSIX_VDISABLE;
    235  1.2  deraadt 	bt->c_cc[VWERASE]  = st->c_cc[14] ? st->c_cc[14] : _POSIX_VDISABLE;
    236  1.2  deraadt 	bt->c_cc[VLNEXT]   = st->c_cc[15] ? st->c_cc[15] : _POSIX_VDISABLE;
    237  1.2  deraadt 	bt->c_cc[VSTATUS]  = st->c_cc[16] ? st->c_cc[16] : _POSIX_VDISABLE;
    238  1.2  deraadt }
    239  1.2  deraadt 
    240  1.2  deraadt 
    241  1.2  deraadt static void
    242  1.2  deraadt btios2stios(bt, st)
    243  1.2  deraadt 	struct termios *bt;
    244  1.2  deraadt 	struct sun_termios *st;
    245  1.2  deraadt {
    246  1.2  deraadt 	register u_long l, r;
    247  1.2  deraadt 
    248  1.2  deraadt 	l = bt->c_iflag;
    249  1.2  deraadt 	r = (	((l &  IGNBRK) ? 0x00000001	: 0) |
    250  1.2  deraadt 		((l &  BRKINT) ? 0x00000002	: 0) |
    251  1.2  deraadt 		((l &  IGNPAR) ? 0x00000004	: 0) |
    252  1.2  deraadt 		((l &  PARMRK) ? 0x00000008	: 0) |
    253  1.2  deraadt 		((l &   INPCK) ? 0x00000010	: 0) |
    254  1.2  deraadt 		((l &  ISTRIP) ? 0x00000020	: 0) |
    255  1.2  deraadt 		((l &   INLCR) ? 0x00000040	: 0) |
    256  1.2  deraadt 		((l &   IGNCR) ? 0x00000080	: 0) |
    257  1.2  deraadt 		((l &   ICRNL) ? 0x00000100	: 0) |
    258  1.2  deraadt 	/*	((l &   IUCLC) ? 0x00000200	: 0) |	*/
    259  1.2  deraadt 		((l &    IXON) ? 0x00000400	: 0) |
    260  1.2  deraadt 		((l &   IXANY) ? 0x00000800	: 0) |
    261  1.2  deraadt 		((l &   IXOFF) ? 0x00001000	: 0) |
    262  1.2  deraadt 		((l & IMAXBEL) ? 0x00002000	: 0) );
    263  1.2  deraadt 	st->c_iflag = r;
    264  1.2  deraadt 
    265  1.2  deraadt 	l = bt->c_oflag;
    266  1.2  deraadt 	r = (	((l &   OPOST) ? 0x00000001	: 0) |
    267  1.2  deraadt 	/*	((l &   OLCUC) ? 0x00000002	: 0) |*/
    268  1.2  deraadt 		((l &   ONLCR) ? 0x00000004	: 0) |
    269  1.2  deraadt 	/*	((l &   OCRNL) ? 0x00000008	: 0) |*/
    270  1.2  deraadt 	/*	((l &   ONOCR) ? 0x00000010	: 0) |*/
    271  1.2  deraadt 	/*	((l &  ONLRET) ? 0x00000020	: 0) |*/
    272  1.2  deraadt 	/*	((l &   OFILL) ? 0x00000040	: 0) |*/
    273  1.2  deraadt 	/*	((l &   OFDEL) ? 0x00000080	: 0) |*/
    274  1.2  deraadt 	/*	((l &   NLDLY) ? 0x00000100	: 0) |*/
    275  1.2  deraadt 	/*	((l &     NL1) ? 0x00000100	: 0) |*/
    276  1.2  deraadt 	/*	((l &   CRDLY) ? 0x00000600	: 0) |*/
    277  1.2  deraadt 	/*	((l &     CR1) ? 0x00000200	: 0) |*/
    278  1.2  deraadt 	/*	((l &     CR2) ? 0x00000400	: 0) |*/
    279  1.2  deraadt 	/*	((l &     CR3) ? 0x00000600	: 0) |*/
    280  1.2  deraadt 	/*	((l &  TABDLY) ? 0x00001800	: 0) |*/
    281  1.2  deraadt 	/*	((l &    TAB1) ? 0x00000800	: 0) |*/
    282  1.2  deraadt 	/*	((l &    TAB2) ? 0x00001000	: 0) |*/
    283  1.2  deraadt 		((l &  OXTABS) ? 0x00001800	: 0)
    284  1.2  deraadt 	/*	((l &   BSDLY) ? 0x00002000	: 0) |*/
    285  1.2  deraadt 	/*	((l &     BS1) ? 0x00002000	: 0) |*/
    286  1.2  deraadt 	/*	((l &   VTDLY) ? 0x00004000	: 0) |*/
    287  1.2  deraadt 	/*	((l &     VT1) ? 0x00004000	: 0) |*/
    288  1.2  deraadt 	/*	((l &   FFDLY) ? 0x00008000	: 0) |*/
    289  1.2  deraadt 	/*	((l &     FF1) ? 0x00008000	: 0) |*/
    290  1.2  deraadt 	/*	((l & PAGEOUT) ? 0x00010000	: 0) |*/
    291  1.2  deraadt 	/*	((l &    WRAP) ? 0x00020000	: 0)  */  );
    292  1.2  deraadt 	st->c_oflag = r;
    293  1.2  deraadt 
    294  1.2  deraadt 	l = bt->c_cflag;
    295  1.2  deraadt 	r = (	((l &     CS6) ? 0x00000010	: 0) |
    296  1.2  deraadt 		((l &     CS7) ? 0x00000020	: 0) |
    297  1.2  deraadt 		((l &     CS8) ? 0x00000030	: 0) |
    298  1.2  deraadt 		((l &  CSTOPB) ? 0x00000040	: 0) |
    299  1.2  deraadt 		((l &   CREAD) ? 0x00000080	: 0) |
    300  1.2  deraadt 		((l &  PARENB) ? 0x00000100	: 0) |
    301  1.2  deraadt 		((l &  PARODD) ? 0x00000200	: 0) |
    302  1.2  deraadt 		((l &   HUPCL) ? 0x00000400	: 0) |
    303  1.2  deraadt 		((l &  CLOCAL) ? 0x00000800	: 0) |
    304  1.2  deraadt 	/*	((l &   LOBLK) ? 0x00001000	: 0) |	*/
    305  1.2  deraadt 		((l & (CRTS_IFLOW|CCTS_OFLOW)) ? 0x80000000 : 0) );
    306  1.2  deraadt 	st->c_cflag = r;
    307  1.2  deraadt 
    308  1.2  deraadt 	l = bt->c_lflag;
    309  1.2  deraadt 	r = (	((l &    ISIG) ? 0x00000001	: 0) |
    310  1.2  deraadt 		((l &  ICANON) ? 0x00000002	: 0) |
    311  1.2  deraadt 	/*	((l &   XCASE) ? 0x00000004	: 0) |	*/
    312  1.2  deraadt 		((l &    ECHO) ? 0x00000008	: 0) |
    313  1.2  deraadt 		((l &   ECHOE) ? 0x00000010	: 0) |
    314  1.2  deraadt 		((l &   ECHOK) ? 0x00000020	: 0) |
    315  1.2  deraadt 		((l &  ECHONL) ? 0x00000040	: 0) |
    316  1.2  deraadt 		((l &  NOFLSH) ? 0x00000080	: 0) |
    317  1.2  deraadt 		((l &  TOSTOP) ? 0x00000100	: 0) |
    318  1.2  deraadt 		((l & ECHOCTL) ? 0x00000200	: 0) |
    319  1.2  deraadt 		((l & ECHOPRT) ? 0x00000400	: 0) |
    320  1.2  deraadt 		((l &  ECHOKE) ? 0x00000800	: 0) |
    321  1.2  deraadt 	/*	((l & DEFECHO) ? 0x00001000	: 0) |	*/
    322  1.2  deraadt 		((l &  FLUSHO) ? 0x00002000	: 0) |
    323  1.2  deraadt 		((l &  PENDIN) ? 0x00004000	: 0) );
    324  1.2  deraadt 	st->c_lflag = r;
    325  1.2  deraadt 
    326  1.2  deraadt 	l = ttspeedtab(bt->c_ospeed, sptab);
    327  1.2  deraadt 	if (l >= 0)
    328  1.2  deraadt 		st->c_cflag |= l;
    329  1.2  deraadt 
    330  1.2  deraadt 	st->c_cc[0] = bt->c_cc[VINTR]   != _POSIX_VDISABLE? bt->c_cc[VINTR]:0;
    331  1.2  deraadt 	st->c_cc[1] = bt->c_cc[VQUIT]   != _POSIX_VDISABLE? bt->c_cc[VQUIT]:0;
    332  1.2  deraadt 	st->c_cc[2] = bt->c_cc[VERASE]  != _POSIX_VDISABLE? bt->c_cc[VERASE]:0;
    333  1.2  deraadt 	st->c_cc[3] = bt->c_cc[VKILL]   != _POSIX_VDISABLE? bt->c_cc[VKILL]:0;
    334  1.2  deraadt 	st->c_cc[4] = bt->c_cc[VEOF]    != _POSIX_VDISABLE? bt->c_cc[VEOF]:0;
    335  1.2  deraadt 	st->c_cc[5] = bt->c_cc[VEOL]    != _POSIX_VDISABLE? bt->c_cc[VEOL]:0;
    336  1.2  deraadt 	st->c_cc[6] = bt->c_cc[VEOL2]   != _POSIX_VDISABLE? bt->c_cc[VEOL2]:0;
    337  1.2  deraadt 	st->c_cc[7] = 0;
    338  1.2  deraadt 		/*    bt->c_cc[VSWTCH]  != _POSIX_VDISABLE? bt->c_cc[VSWTCH]: */
    339  1.2  deraadt 	st->c_cc[8] = bt->c_cc[VSTART]  != _POSIX_VDISABLE? bt->c_cc[VSTART]:0;
    340  1.2  deraadt 	st->c_cc[9] = bt->c_cc[VSTOP]   != _POSIX_VDISABLE? bt->c_cc[VSTOP]:0;
    341  1.2  deraadt 	st->c_cc[10]= bt->c_cc[VSUSP]   != _POSIX_VDISABLE? bt->c_cc[VSUSP]:0;
    342  1.2  deraadt 	st->c_cc[11]= bt->c_cc[VDSUSP]  != _POSIX_VDISABLE? bt->c_cc[VDSUSP]:0;
    343  1.2  deraadt 	st->c_cc[12]= bt->c_cc[VREPRINT]!= _POSIX_VDISABLE? bt->c_cc[VREPRINT]:0;
    344  1.2  deraadt 	st->c_cc[13]= bt->c_cc[VDISCARD]!= _POSIX_VDISABLE? bt->c_cc[VDISCARD]:0;
    345  1.2  deraadt 	st->c_cc[14]= bt->c_cc[VWERASE] != _POSIX_VDISABLE? bt->c_cc[VWERASE]:0;
    346  1.2  deraadt 	st->c_cc[15]= bt->c_cc[VLNEXT]  != _POSIX_VDISABLE? bt->c_cc[VLNEXT]:0;
    347  1.2  deraadt 	st->c_cc[16]= bt->c_cc[VSTATUS] != _POSIX_VDISABLE? bt->c_cc[VSTATUS]:0;
    348  1.2  deraadt 
    349  1.2  deraadt 	st->c_line = 0;
    350  1.2  deraadt }
    351  1.2  deraadt 
    352  1.2  deraadt static void
    353  1.2  deraadt stios2stio(ts, t)
    354  1.2  deraadt 	struct sun_termios *ts;
    355  1.2  deraadt 	struct sun_termio *t;
    356  1.2  deraadt {
    357  1.2  deraadt 	t->c_iflag = ts->c_iflag;
    358  1.2  deraadt 	t->c_oflag = ts->c_oflag;
    359  1.2  deraadt 	t->c_cflag = ts->c_cflag;
    360  1.2  deraadt 	t->c_lflag = ts->c_lflag;
    361  1.2  deraadt 	t->c_line  = ts->c_line;
    362  1.2  deraadt 	bcopy(ts->c_cc, t->c_cc, 8);
    363  1.2  deraadt }
    364  1.2  deraadt 
    365  1.2  deraadt static void
    366  1.2  deraadt stio2stios(t, ts)
    367  1.2  deraadt 	struct sun_termio *t;
    368  1.2  deraadt 	struct sun_termios *ts;
    369  1.2  deraadt {
    370  1.2  deraadt 	ts->c_iflag = t->c_iflag;
    371  1.2  deraadt 	ts->c_oflag = t->c_oflag;
    372  1.2  deraadt 	ts->c_cflag = t->c_cflag;
    373  1.2  deraadt 	ts->c_lflag = t->c_lflag;
    374  1.2  deraadt 	ts->c_line  = t->c_line;
    375  1.2  deraadt 	bcopy(t->c_cc, ts->c_cc, 8); /* don't touch the upper fields! */
    376  1.2  deraadt }
    377  1.1  deraadt 
    378  1.1  deraadt struct sun_ioctl_args {
    379  1.1  deraadt 	int	fd;
    380  1.1  deraadt 	int	cmd;
    381  1.1  deraadt 	caddr_t	data;
    382  1.1  deraadt };
    383  1.2  deraadt 
    384  1.2  deraadt int
    385  1.1  deraadt sun_ioctl(p, uap, retval)
    386  1.1  deraadt 	register struct proc *p;
    387  1.1  deraadt 	register struct sun_ioctl_args *uap;
    388  1.1  deraadt 	int *retval;
    389  1.1  deraadt {
    390  1.1  deraadt 	register struct filedesc *fdp = p->p_fd;
    391  1.1  deraadt 	register struct file *fp;
    392  1.1  deraadt 	register int (*ctl)();
    393  1.1  deraadt 	int error;
    394  1.1  deraadt 
    395  1.2  deraadt 	if ( (unsigned)uap->fd >= fdp->fd_nfiles ||
    396  1.1  deraadt 	    (fp = fdp->fd_ofiles[uap->fd]) == NULL)
    397  1.2  deraadt 		return EBADF;
    398  1.2  deraadt 
    399  1.1  deraadt 	if ((fp->f_flag & (FREAD|FWRITE)) == 0)
    400  1.2  deraadt 		return EBADF;
    401  1.2  deraadt 
    402  1.1  deraadt 	ctl = fp->f_ops->fo_ioctl;
    403  1.1  deraadt 
    404  1.1  deraadt 	switch (uap->cmd) {
    405  1.1  deraadt 	case _IOR('t', 0, int):
    406  1.1  deraadt 		uap->cmd = TIOCGETD;
    407  1.1  deraadt 		break;
    408  1.2  deraadt 	case _IOW('t', 1, int):
    409  1.2  deraadt 	    {
    410  1.2  deraadt 		int disc;
    411  1.1  deraadt 
    412  1.2  deraadt 		if ((error = copyin(uap->data, (caddr_t)&disc,
    413  1.2  deraadt 		    sizeof disc)) != 0)
    414  1.2  deraadt 			return error;
    415  1.2  deraadt 
    416  1.2  deraadt 		/* map SunOS NTTYDISC into our termios discipline */
    417  1.2  deraadt 		if (disc == 2)
    418  1.2  deraadt 			disc = 0;
    419  1.2  deraadt 		/* all other disciplines are not supported by NetBSD */
    420  1.2  deraadt 		if (disc)
    421  1.2  deraadt 			return ENXIO;
    422  1.1  deraadt 
    423  1.2  deraadt 		return (*ctl)(fp, TIOCSETD, (caddr_t)&disc, p);
    424  1.2  deraadt 	    }
    425  1.2  deraadt 	case _IO('t', 36): 		/* sun TIOCCONS, no parameters */
    426  1.2  deraadt 	    {
    427  1.1  deraadt 		int on = 1;
    428  1.2  deraadt 		return (*ctl)(fp, TIOCCONS, (caddr_t)&on, p);
    429  1.1  deraadt 	    }
    430  1.2  deraadt 	case _IOW('t', 37, struct sun_ttysize):
    431  1.2  deraadt 	    {
    432  1.2  deraadt 		struct winsize ws;
    433  1.2  deraadt 		struct sun_ttysize ss;
    434  1.1  deraadt 
    435  1.1  deraadt 		if ((error = (*ctl)(fp, TIOCGWINSZ, (caddr_t)&ws, p)) != 0)
    436  1.1  deraadt 			return (error);
    437  1.2  deraadt 
    438  1.2  deraadt 		if ((error = copyin (uap->data, &ss, sizeof (ss))) != 0)
    439  1.2  deraadt 			return error;
    440  1.2  deraadt 
    441  1.2  deraadt 		ws.ws_row = ss.ts_row;
    442  1.2  deraadt 		ws.ws_col = ss.ts_col;
    443  1.2  deraadt 
    444  1.1  deraadt 		return ((*ctl)(fp, TIOCSWINSZ, (caddr_t)&ws, p));
    445  1.1  deraadt 	    }
    446  1.2  deraadt 	case _IOW('t', 38, struct sun_ttysize):
    447  1.2  deraadt 	    {
    448  1.2  deraadt 		struct winsize ws;
    449  1.2  deraadt 		struct sun_ttysize ss;
    450  1.1  deraadt 
    451  1.1  deraadt 		if ((error = (*ctl)(fp, TIOCGWINSZ, (caddr_t)&ws, p)) != 0)
    452  1.1  deraadt 			return (error);
    453  1.2  deraadt 
    454  1.2  deraadt 		ss.ts_row = ws.ws_row;
    455  1.2  deraadt 		ss.ts_col = ws.ws_col;
    456  1.2  deraadt 
    457  1.2  deraadt 		return copyout ((caddr_t)&ss, uap->data, sizeof (ss));
    458  1.1  deraadt 	    }
    459  1.1  deraadt 	case _IOR('t', 130, int):
    460  1.1  deraadt 		uap->cmd = TIOCSPGRP;
    461  1.1  deraadt 		break;
    462  1.1  deraadt 	case _IOR('t', 131, int):
    463  1.1  deraadt 		uap->cmd = TIOCGPGRP;
    464  1.1  deraadt 		break;
    465  1.1  deraadt 	case _IO('t', 132):
    466  1.1  deraadt 		uap->cmd = TIOCSCTTY;
    467  1.1  deraadt 		break;
    468  1.2  deraadt 	case SUN_TCGETA:
    469  1.2  deraadt 	case SUN_TCGETS:
    470  1.2  deraadt 	    {
    471  1.2  deraadt 		struct termios bts;
    472  1.2  deraadt 		struct sun_termios sts;
    473  1.2  deraadt 		struct sun_termio st;
    474  1.2  deraadt 
    475  1.2  deraadt 		if ((error = (*ctl)(fp, TIOCGETA, (caddr_t)&bts, p)) != 0)
    476  1.2  deraadt 			return error;
    477  1.2  deraadt 
    478  1.2  deraadt 		btios2stios (&bts, &sts);
    479  1.2  deraadt 		if (uap->cmd == SUN_TCGETA) {
    480  1.2  deraadt 			stios2stio (&sts, &st);
    481  1.2  deraadt 			return copyout((caddr_t)&st, uap->data, sizeof (st));
    482  1.2  deraadt 		} else
    483  1.2  deraadt 			return copyout((caddr_t)&sts, uap->data, sizeof (sts));
    484  1.2  deraadt 		/*NOTREACHED*/
    485  1.2  deraadt 	    }
    486  1.2  deraadt 	case SUN_TCSETA:
    487  1.2  deraadt 	case SUN_TCSETAW:
    488  1.2  deraadt 	case SUN_TCSETAF:
    489  1.2  deraadt 	    {
    490  1.2  deraadt 		struct termios bts;
    491  1.2  deraadt 		struct sun_termios sts;
    492  1.2  deraadt 		struct sun_termio st;
    493  1.1  deraadt 
    494  1.2  deraadt 		if ((error = copyin(uap->data, (caddr_t)&st,
    495  1.2  deraadt 		    sizeof (st))) != 0)
    496  1.2  deraadt 			return error;
    497  1.2  deraadt 
    498  1.2  deraadt 		/* get full BSD termios so we don't lose information */
    499  1.2  deraadt 		if ((error = (*ctl)(fp, TIOCGETA, (caddr_t)&bts, p)) != 0)
    500  1.2  deraadt 			return error;
    501  1.2  deraadt 
    502  1.2  deraadt 		/*
    503  1.2  deraadt 		 * convert to sun termios, copy in information from
    504  1.2  deraadt 		 * termio, and convert back, then set new values.
    505  1.2  deraadt 		 */
    506  1.2  deraadt 		btios2stios(&bts, &sts);
    507  1.2  deraadt 		stio2stios(&st, &sts);
    508  1.2  deraadt 		stios2btios(&sts, &bts);
    509  1.1  deraadt 
    510  1.2  deraadt 		return (*ctl)(fp, uap->cmd - SUN_TCSETA + TIOCSETA,
    511  1.2  deraadt 		    (caddr_t)&bts, p);
    512  1.2  deraadt 	    }
    513  1.2  deraadt 	case SUN_TCSETS:
    514  1.2  deraadt 	case SUN_TCSETSW:
    515  1.2  deraadt 	case SUN_TCSETSF:
    516  1.2  deraadt 	    {
    517  1.2  deraadt 		struct termios bts;
    518  1.2  deraadt 		struct sun_termios sts;
    519  1.2  deraadt 
    520  1.2  deraadt 		if ((error = copyin (uap->data, (caddr_t)&sts,
    521  1.2  deraadt 		    sizeof (sts))) != 0)
    522  1.2  deraadt 			return error;
    523  1.2  deraadt 		stios2btios (&sts, &bts);
    524  1.2  deraadt 		return (*ctl)(fp, uap->cmd - SUN_TCSETS + TIOCSETA,
    525  1.2  deraadt 		    (caddr_t)&bts, p);
    526  1.1  deraadt 	    }
    527  1.1  deraadt 	}
    528  1.1  deraadt 	return (ioctl(p, uap, retval));
    529  1.1  deraadt }
    530