sunos_ioctl.c revision 1.1 1 /*
2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This software was developed by the Computer Systems Engineering group
6 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
7 * contributed to Berkeley.
8 *
9 * All advertising materials mentioning features or use of this software
10 * must display the following acknowledgement:
11 * This product includes software developed by the University of
12 * California, Lawrence Berkeley Laboratory.
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
16 * are met:
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution.
22 * 3. All advertising materials mentioning features or use of this software
23 * must display the following acknowledgement:
24 * This product includes software developed by the University of
25 * California, Berkeley and its contributors.
26 * 4. Neither the name of the University nor the names of its contributors
27 * may be used to endorse or promote products derived from this software
28 * without specific prior written permission.
29 *
30 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
31 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
32 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
34 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
35 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
36 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
37 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
38 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
39 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40 * SUCH DAMAGE.
41 *
42 * @(#)sun_ioctl.c 8.1 (Berkeley) 6/11/93
43 *
44 * from: Header: sun_ioctl.c,v 1.7 93/05/28 04:40:43 torek Exp
45 * $Id: sunos_ioctl.c,v 1.1 1993/10/02 10:24:39 deraadt Exp $
46 */
47
48 #include <sys/param.h>
49 #include <sys/proc.h>
50 #include <sys/file.h>
51 #include <sys/filedesc.h>
52 #include <sys/ioctl.h>
53 #include <sys/termios.h>
54 #include <sys/tty.h>
55
56 /*
57 * SunOS ioctl calls.
58 * This file is something of a hodge-podge.
59 * Support gets added as things turn up....
60 */
61
62 struct sun_ttysize {
63 int ts_row;
64 int ts_col;
65 };
66
67 struct sun_termio {
68 u_short c_iflag;
69 u_short c_oflag;
70 u_short c_cflag;
71 u_short c_lflag;
72 char c_line;
73 unsigned char c_cc[8];
74 };
75
76 struct sun_ioctl_args {
77 int fd;
78 int cmd;
79 caddr_t data;
80 };
81 sun_ioctl(p, uap, retval)
82 register struct proc *p;
83 register struct sun_ioctl_args *uap;
84 int *retval;
85 {
86 register struct filedesc *fdp = p->p_fd;
87 register struct file *fp;
88 register int (*ctl)();
89 int error;
90
91 if ((unsigned)uap->fd >= fdp->fd_nfiles ||
92 (fp = fdp->fd_ofiles[uap->fd]) == NULL)
93 return (EBADF);
94 if ((fp->f_flag & (FREAD|FWRITE)) == 0)
95 return (EBADF);
96 ctl = fp->f_ops->fo_ioctl;
97
98 switch (uap->cmd) {
99
100 case _IOR('t', 0, int):
101 uap->cmd = TIOCGETD;
102 break;
103
104 case _IOW('t', 1, int):
105 uap->cmd = TIOCSETD;
106 break;
107
108 case _IO('t', 36): { /* sun TIOCCONS, no parameters */
109 int on = 1;
110 return ((*ctl)(fp, TIOCCONS, (caddr_t)&on, p));
111 }
112
113 case _IOW('t', 37, struct sun_ttysize): {
114 struct winsize ws;
115 if ((error = (*ctl)(fp, TIOCGWINSZ, (caddr_t)&ws, p)) != 0)
116 return (error);
117 ws.ws_row = ((struct sun_ttysize *)uap->data)->ts_row;
118 ws.ws_col = ((struct sun_ttysize *)uap->data)->ts_col;
119 return ((*ctl)(fp, TIOCSWINSZ, (caddr_t)&ws, p));
120 }
121
122 case _IOW('t', 38, struct sun_ttysize): {
123 struct winsize ws;
124 if ((error = (*ctl)(fp, TIOCGWINSZ, (caddr_t)&ws, p)) != 0)
125 return (error);
126 ((struct sun_ttysize *)uap->data)->ts_row = ws.ws_row;
127 ((struct sun_ttysize *)uap->data)->ts_col = ws.ws_col;
128 return (0);
129 }
130
131 case _IOR('t', 130, int):
132 uap->cmd = TIOCSPGRP;
133 break;
134
135 case _IOR('t', 131, int):
136 uap->cmd = TIOCGPGRP;
137 break;
138
139 case _IO('t', 132):
140 uap->cmd = TIOCSCTTY;
141 break;
142
143 case _IOR('T', 1, struct sun_termio): {
144 struct termios bt;
145 struct sun_termio st;
146 int speed;
147 static struct speedtab sptab[] = {
148 { 0, 0 }, { 50, 1 }, { 75, 2 }, { 110, 3 },
149 { 134, 4 }, { 135, 4 }, { 150, 5 }, { 200, 6 },
150 { 300, 7 }, { 600, 8 }, { 1200, 9 }, { 1800, 10 },
151 { 2400, 11 }, { 4800, 12 }, { 9600, 13 },
152 { 19200, 14 }, { 38400, 15 }, { -1, -1 }
153 };
154
155 if ((error = (*ctl)(fp, TIOCGETA, (caddr_t)&bt, p)) != 0)
156 return (error);
157 /* most bits match */
158 st.c_iflag = bt.c_iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK|
159 ISTRIP|INLCR|IGNCR|ICRNL|IXANY|IMAXBEL);
160 if (bt.c_iflag & IXON)
161 st.c_iflag |= 0x0400;
162 if (bt.c_iflag & IXOFF)
163 st.c_iflag |= 0x1000;
164 st.c_oflag = bt.c_oflag & OPOST;
165 if (bt.c_oflag & ONLCR)
166 st.c_oflag |= 0x0004;
167 if (bt.c_oflag & OXTABS)
168 st.c_oflag |= 0x1800;
169 speed = ttspeedtab(bt.c_ospeed, sptab);
170 st.c_cflag = speed >= 0 ? speed : 0;
171 st.c_cflag |= (bt.c_cflag & CSIZE) >> 4;
172 if (bt.c_cflag & CSTOPB)
173 st.c_cflag |= 0x40;
174 if (bt.c_cflag & PARENB)
175 st.c_cflag |= 0x100;
176 if (bt.c_cflag & PARODD)
177 st.c_cflag |= 0x200;
178 if (bt.c_cflag & HUPCL)
179 st.c_cflag |= 0x400;
180 if (bt.c_cflag & CLOCAL)
181 st.c_cflag |= 0x800;
182 st.c_lflag = 0;
183 if (bt.c_lflag & (ECHOKE|ECHOE|ECHOK))
184 st.c_lflag |= 0x0800;
185 if (bt.c_lflag & ECHO)
186 st.c_lflag |= 0x0008;
187 if (bt.c_lflag & ECHONL)
188 st.c_lflag |= 0x0040;
189 if (bt.c_lflag & ECHOPRT)
190 st.c_lflag |= 0x0400;
191 if (bt.c_lflag & ECHOCTL)
192 st.c_lflag |= 0x0200;
193 if (bt.c_lflag & ISIG)
194 st.c_lflag |= 0x0001;
195 if (bt.c_lflag & ICANON)
196 st.c_lflag |= 0x0002;
197 if (bt.c_lflag & IEXTEN)
198 st.c_lflag |= 0x8000;
199 if (bt.c_lflag & NOFLSH)
200 st.c_lflag |= 0x0080;
201 #define mapcc(x) ((x) == _POSIX_VDISABLE ? 0 : (x))
202 st.c_cc[0] = mapcc(bt.c_cc[VINTR]);
203 st.c_cc[1] = mapcc(bt.c_cc[VQUIT]);
204 st.c_cc[2] = mapcc(bt.c_cc[VERASE]);
205 st.c_cc[3] = mapcc(bt.c_cc[VKILL]);
206 st.c_cc[4] = mapcc(bt.c_cc[VEOF]);
207 st.c_cc[5] = mapcc(bt.c_cc[VEOL]);
208 st.c_cc[6] = mapcc(bt.c_cc[VEOL2]);
209 st.c_cc[7] = 0;
210 return (copyout((caddr_t)&st, uap->data, sizeof(st)));
211 }
212 }
213 return (ioctl(p, uap, retval));
214 }
215