linux_termios.h revision 1.16 1 1.16 dsl /* $NetBSD: linux_termios.h,v 1.16 2007/12/04 18:40:17 dsl Exp $ */
2 1.1 mycroft
3 1.3 erh /*-
4 1.3 erh * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 1.3 erh * All rights reserved.
6 1.3 erh *
7 1.3 erh * This code is derived from software contributed to The NetBSD Foundation
8 1.3 erh * by Eric Haszlakiewicz.
9 1.3 erh *
10 1.3 erh * Redistribution and use in source and binary forms, with or without
11 1.3 erh * modification, are permitted provided that the following conditions
12 1.3 erh * are met:
13 1.3 erh * 1. Redistributions of source code must retain the above copyright
14 1.3 erh * notice, this list of conditions and the following disclaimer.
15 1.3 erh * 2. Redistributions in binary form must reproduce the above copyright
16 1.3 erh * notice, this list of conditions and the following disclaimer in the
17 1.3 erh * documentation and/or other materials provided with the distribution.
18 1.3 erh * 3. All advertising materials mentioning features or use of this software
19 1.3 erh * must display the following acknowledgement:
20 1.3 erh * This product includes software developed by the NetBSD
21 1.3 erh * Foundation, Inc. and its contributors.
22 1.3 erh * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.3 erh * contributors may be used to endorse or promote products derived
24 1.3 erh * from this software without specific prior written permission.
25 1.3 erh *
26 1.3 erh * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.3 erh * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.3 erh * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.3 erh * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.3 erh * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.3 erh * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.3 erh * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.3 erh * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.3 erh * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.3 erh * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.3 erh * POSSIBILITY OF SUCH DAMAGE.
37 1.3 erh */
38 1.3 erh
39 1.4 christos #ifndef _LINUX_TERMIOS_H
40 1.4 christos #define _LINUX_TERMIOS_H
41 1.3 erh
42 1.8 manu #if defined(__i386__)
43 1.8 manu #include <compat/linux/arch/i386/linux_termios.h>
44 1.8 manu #elif defined(__m68k__)
45 1.8 manu #include <compat/linux/arch/m68k/linux_termios.h>
46 1.8 manu #elif defined(__alpha__)
47 1.8 manu #include <compat/linux/arch/alpha/linux_termios.h>
48 1.8 manu #elif defined(__powerpc__)
49 1.8 manu #include <compat/linux/arch/powerpc/linux_termios.h>
50 1.10 manu #elif defined(__mips__)
51 1.10 manu #include <compat/linux/arch/mips/linux_termios.h>
52 1.11 bjh21 #elif defined(__arm__)
53 1.11 bjh21 #include <compat/linux/arch/arm/linux_termios.h>
54 1.13 manu #elif defined(__amd64__)
55 1.13 manu #include <compat/linux/arch/amd64/linux_termios.h>
56 1.8 manu #else
57 1.8 manu #error Undefined linux_termios.h machine type.
58 1.8 manu #endif
59 1.8 manu
60 1.3 erh struct linux_winsize {
61 1.3 erh unsigned short ws_row;
62 1.3 erh unsigned short ws_col;
63 1.3 erh unsigned short ws_xpixel;
64 1.3 erh unsigned short ws_ypixel;
65 1.3 erh };
66 1.1 mycroft
67 1.8 manu /*
68 1.12 perry * LINUX_NCC is architecture dependent. It is now
69 1.8 manu * defined in sys/compat/linux/<arch>/linux_termios.h
70 1.8 manu */
71 1.1 mycroft struct linux_termio {
72 1.1 mycroft unsigned short c_iflag;
73 1.1 mycroft unsigned short c_oflag;
74 1.1 mycroft unsigned short c_cflag;
75 1.1 mycroft unsigned short c_lflag;
76 1.1 mycroft unsigned char c_line;
77 1.1 mycroft unsigned char c_cc[LINUX_NCC];
78 1.1 mycroft };
79 1.1 mycroft
80 1.1 mycroft struct linux_termios {
81 1.3 erh linux_tcflag_t c_iflag;
82 1.3 erh linux_tcflag_t c_oflag;
83 1.3 erh linux_tcflag_t c_cflag;
84 1.3 erh linux_tcflag_t c_lflag;
85 1.3 erh linux_cc_t c_line;
86 1.3 erh linux_cc_t c_cc[LINUX_NCCS];
87 1.8 manu #ifdef LINUX_LARGE_STRUCT_TERMIOS
88 1.12 perry /*
89 1.12 perry * Present on some linux ports but unused:
90 1.12 perry * However we must enable it, else it breaks ioctl
91 1.8 manu * definitions (the size does not match anymore)
92 1.8 manu */
93 1.3 erh linux_speed_t c_ispeed;
94 1.3 erh linux_speed_t c_ospeed;
95 1.3 erh #endif
96 1.1 mycroft };
97 1.1 mycroft
98 1.1 mycroft /* Linux modem line defines.. not sure if they'll be used */
99 1.1 mycroft #define LINUX_TIOCM_LE 0x0001
100 1.1 mycroft #define LINUX_TIOCM_DTR 0x0002
101 1.1 mycroft #define LINUX_TIOCM_RTS 0x0004
102 1.1 mycroft #define LINUX_TIOCM_ST 0x0008
103 1.1 mycroft #define LINUX_TIOCM_SR 0x0010
104 1.1 mycroft #define LINUX_TIOCM_CTS 0x0020
105 1.1 mycroft #define LINUX_TIOCM_CAR 0x0040
106 1.1 mycroft #define LINUX_TIOCM_RNG 0x0080
107 1.1 mycroft #define LINUX_TIOCM_DSR 0x0100
108 1.1 mycroft #define LINUX_TIOCM_CD LINUX_TIOCM_CAR
109 1.1 mycroft #define LINUX_TIOCM_RI LINUX_TIOCM_RNG
110 1.1 mycroft
111 1.1 mycroft #define LINUX_TCIFLUSH 0
112 1.1 mycroft #define LINUX_TCOFLUSH 1
113 1.1 mycroft #define LINUX_TCIOFLUSH 2
114 1.1 mycroft
115 1.1 mycroft #define LINUX_TCOOFF 0
116 1.1 mycroft #define LINUX_TCOON 1
117 1.1 mycroft #define LINUX_TCIOFF 2
118 1.1 mycroft #define LINUX_TCION 3
119 1.1 mycroft
120 1.1 mycroft #define LINUX_TCSANOW 0
121 1.1 mycroft #define LINUX_TCSADRAIN 1
122 1.1 mycroft #define LINUX_TCSAFLUSH 2
123 1.1 mycroft
124 1.1 mycroft /* Linux line disciplines */
125 1.1 mycroft #define LINUX_N_TTY 0
126 1.1 mycroft #define LINUX_N_SLIP 1
127 1.1 mycroft #define LINUX_N_MOUSE 2
128 1.1 mycroft #define LINUX_N_PPP 3
129 1.3 erh #define LINUX_N_STRIP 4
130 1.3 erh
131 1.3 erh /* currently unused: */
132 1.3 erh #define LINUX_N_AX25 5
133 1.3 erh #define LINUX_N_X25 6
134 1.3 erh #define LINUX_N_6PACK 7
135 1.6 fvdl
136 1.6 fvdl /* values passed to TIOCLINUX ioctl */
137 1.6 fvdl #define LINUX_TIOCLINUX_COPY 2
138 1.6 fvdl #define LINUX_TIOCLINUX_PASTE 3
139 1.6 fvdl #define LINUX_TIOCLINUX_UNBLANK 4
140 1.6 fvdl #define LINUX_TIOCLINUX_LOADLUT 5
141 1.6 fvdl #define LINUX_TIOCLINUX_READSHIFT 6
142 1.6 fvdl #define LINUX_TIOCLINUX_READMOUSE 7
143 1.6 fvdl #define LINUX_TIOCLINUX_VESABLANK 10
144 1.6 fvdl #define LINUX_TIOCLINUX_KERNMSG 11
145 1.6 fvdl #define LINUX_TIOCLINUX_CURCONS 12
146 1.3 erh
147 1.15 manu static speed_t linux_speeds[] = {
148 1.15 manu 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
149 1.15 manu 9600, 19200, 38400, 57600, 115200, 230400
150 1.15 manu };
151 1.15 manu
152 1.15 manu static const int linux_spmasks[] = {
153 1.15 manu LINUX_B0, LINUX_B50, LINUX_B75, LINUX_B110, LINUX_B134, LINUX_B150,
154 1.15 manu LINUX_B200, LINUX_B300, LINUX_B600, LINUX_B1200, LINUX_B1800,
155 1.15 manu LINUX_B2400, LINUX_B4800, LINUX_B9600, LINUX_B19200, LINUX_B38400,
156 1.15 manu LINUX_B57600, LINUX_B115200, LINUX_B230400
157 1.15 manu };
158 1.15 manu
159 1.15 manu #ifdef COMPAT_LINUX32
160 1.15 manu struct linux32_termio;
161 1.15 manu struct linux32_termios;
162 1.16 dsl static void linux32_termio_to_bsd_termios(struct linux32_termio *,
163 1.16 dsl struct termios *);
164 1.16 dsl static void bsd_termios_to_linux32_termio(struct termios *,
165 1.16 dsl struct linux32_termio *);
166 1.16 dsl static void linux32_termios_to_bsd_termios(struct linux32_termios *,
167 1.16 dsl struct termios *);
168 1.16 dsl static void bsd_termios_to_linux32_termios(struct termios *,
169 1.16 dsl struct linux32_termios *);
170 1.15 manu #else
171 1.15 manu struct linux_termio;
172 1.15 manu struct linux_termios;
173 1.16 dsl static void linux_termio_to_bsd_termios(struct linux_termio *,
174 1.16 dsl struct termios *);
175 1.16 dsl static void bsd_termios_to_linux_termio(struct termios *,
176 1.16 dsl struct linux_termio *);
177 1.16 dsl static void linux_termios_to_bsd_termios(struct linux_termios *,
178 1.16 dsl struct termios *);
179 1.16 dsl static void bsd_termios_to_linux_termios(struct termios *,
180 1.16 dsl struct linux_termios *);
181 1.15 manu #endif
182 1.15 manu
183 1.15 manu /*
184 1.15 manu * Deal with termio ioctl cruft. This doesn't look very good..
185 1.15 manu * XXX too much code duplication, obviously..
186 1.15 manu *
187 1.15 manu * The conversion routines between Linux and BSD structures assume
188 1.15 manu * that the fields are already filled with the current values,
189 1.15 manu * so that fields present in BSD but not in Linux keep their current
190 1.15 manu * values.
191 1.15 manu */
192 1.15 manu
193 1.15 manu static void
194 1.15 manu #ifdef COMPAT_LINUX32
195 1.15 manu linux32_termio_to_bsd_termios(lt, bts)
196 1.15 manu struct linux32_termio *lt;
197 1.15 manu struct termios *bts;
198 1.15 manu #else
199 1.15 manu linux_termio_to_bsd_termios(lt, bts)
200 1.15 manu struct linux_termio *lt;
201 1.15 manu struct termios *bts;
202 1.15 manu #endif
203 1.15 manu {
204 1.15 manu int index;
205 1.15 manu
206 1.15 manu bts->c_iflag = 0;
207 1.15 manu bts->c_iflag |= cvtto_bsd_mask(lt->c_iflag, LINUX_IGNBRK, IGNBRK);
208 1.15 manu bts->c_iflag |= cvtto_bsd_mask(lt->c_iflag, LINUX_BRKINT, BRKINT);
209 1.15 manu bts->c_iflag |= cvtto_bsd_mask(lt->c_iflag, LINUX_IGNPAR, IGNPAR);
210 1.15 manu bts->c_iflag |= cvtto_bsd_mask(lt->c_iflag, LINUX_INPCK, INPCK);
211 1.15 manu bts->c_iflag |= cvtto_bsd_mask(lt->c_iflag, LINUX_ISTRIP, ISTRIP);
212 1.15 manu bts->c_iflag |= cvtto_bsd_mask(lt->c_iflag, LINUX_INLCR, INLCR);
213 1.15 manu bts->c_iflag |= cvtto_bsd_mask(lt->c_iflag, LINUX_IGNCR, IGNCR);
214 1.15 manu bts->c_iflag |= cvtto_bsd_mask(lt->c_iflag, LINUX_ICRNL, ICRNL);
215 1.15 manu bts->c_iflag |= cvtto_bsd_mask(lt->c_iflag, LINUX_IXON, IXON);
216 1.15 manu bts->c_iflag |= cvtto_bsd_mask(lt->c_iflag, LINUX_IXANY, IXANY);
217 1.15 manu bts->c_iflag |= cvtto_bsd_mask(lt->c_iflag, LINUX_IXOFF, IXOFF);
218 1.15 manu bts->c_iflag |= cvtto_bsd_mask(lt->c_iflag, LINUX_IMAXBEL, IMAXBEL);
219 1.15 manu
220 1.15 manu bts->c_oflag = 0;
221 1.15 manu bts->c_oflag |= cvtto_bsd_mask(lt->c_oflag, LINUX_OPOST, OPOST);
222 1.15 manu bts->c_oflag |= cvtto_bsd_mask(lt->c_oflag, LINUX_ONLCR, ONLCR);
223 1.15 manu bts->c_oflag |= cvtto_bsd_mask(lt->c_oflag, LINUX_XTABS, OXTABS);
224 1.15 manu
225 1.15 manu /*
226 1.15 manu * This could have been:
227 1.15 manu * bts->c_cflag = (lt->c_flag & LINUX_CSIZE) << 4
228 1.15 manu * But who knows, those values might perhaps change one day.
229 1.15 manu */
230 1.15 manu switch (lt->c_cflag & LINUX_CSIZE) {
231 1.15 manu case LINUX_CS5:
232 1.15 manu bts->c_cflag = CS5;
233 1.15 manu break;
234 1.15 manu case LINUX_CS6:
235 1.15 manu bts->c_cflag = CS6;
236 1.15 manu break;
237 1.15 manu case LINUX_CS7:
238 1.15 manu bts->c_cflag = CS7;
239 1.15 manu break;
240 1.15 manu case LINUX_CS8:
241 1.15 manu bts->c_cflag = CS8;
242 1.15 manu break;
243 1.15 manu }
244 1.15 manu bts->c_cflag |= cvtto_bsd_mask(lt->c_cflag, LINUX_CSTOPB, CSTOPB);
245 1.15 manu bts->c_cflag |= cvtto_bsd_mask(lt->c_cflag, LINUX_CREAD, CREAD);
246 1.15 manu bts->c_cflag |= cvtto_bsd_mask(lt->c_cflag, LINUX_PARENB, PARENB);
247 1.15 manu bts->c_cflag |= cvtto_bsd_mask(lt->c_cflag, LINUX_PARODD, PARODD);
248 1.15 manu bts->c_cflag |= cvtto_bsd_mask(lt->c_cflag, LINUX_HUPCL, HUPCL);
249 1.15 manu bts->c_cflag |= cvtto_bsd_mask(lt->c_cflag, LINUX_CLOCAL, CLOCAL);
250 1.15 manu bts->c_cflag |= cvtto_bsd_mask(lt->c_cflag, LINUX_CRTSCTS, CRTSCTS);
251 1.15 manu
252 1.15 manu bts->c_lflag = 0;
253 1.15 manu bts->c_lflag |= cvtto_bsd_mask(lt->c_lflag, LINUX_ISIG, ISIG);
254 1.15 manu bts->c_lflag |= cvtto_bsd_mask(lt->c_lflag, LINUX_ICANON, ICANON);
255 1.15 manu bts->c_lflag |= cvtto_bsd_mask(lt->c_lflag, LINUX_ECHO, ECHO);
256 1.15 manu bts->c_lflag |= cvtto_bsd_mask(lt->c_lflag, LINUX_ECHOE, ECHOE);
257 1.15 manu bts->c_lflag |= cvtto_bsd_mask(lt->c_lflag, LINUX_ECHOK, ECHOK);
258 1.15 manu bts->c_lflag |= cvtto_bsd_mask(lt->c_lflag, LINUX_ECHONL, ECHONL);
259 1.15 manu bts->c_lflag |= cvtto_bsd_mask(lt->c_lflag, LINUX_NOFLSH, NOFLSH);
260 1.15 manu bts->c_lflag |= cvtto_bsd_mask(lt->c_lflag, LINUX_TOSTOP, TOSTOP);
261 1.15 manu bts->c_lflag |= cvtto_bsd_mask(lt->c_lflag, LINUX_ECHOCTL, ECHOCTL);
262 1.15 manu bts->c_lflag |= cvtto_bsd_mask(lt->c_lflag, LINUX_ECHOPRT, ECHOPRT);
263 1.15 manu bts->c_lflag |= cvtto_bsd_mask(lt->c_lflag, LINUX_ECHOKE, ECHOKE);
264 1.15 manu bts->c_lflag |= cvtto_bsd_mask(lt->c_lflag, LINUX_FLUSHO, FLUSHO);
265 1.15 manu bts->c_lflag |= cvtto_bsd_mask(lt->c_lflag, LINUX_PENDIN, PENDIN);
266 1.15 manu bts->c_lflag |= cvtto_bsd_mask(lt->c_lflag, LINUX_IEXTEN, IEXTEN);
267 1.15 manu
268 1.15 manu index = lt->c_cflag & LINUX_CBAUD;
269 1.15 manu if (index & LINUX_CBAUDEX)
270 1.15 manu index = (index & ~LINUX_CBAUDEX) + LINUX_NSPEEDS - 1;
271 1.15 manu bts->c_ispeed = bts->c_ospeed = linux_speeds[index];
272 1.15 manu
273 1.15 manu bts->c_cc[VINTR] = lt->c_cc[LINUX_OLD_VINTR];
274 1.15 manu bts->c_cc[VQUIT] = lt->c_cc[LINUX_OLD_VQUIT];
275 1.15 manu bts->c_cc[VERASE] = lt->c_cc[LINUX_OLD_VERASE];
276 1.15 manu bts->c_cc[VKILL] = lt->c_cc[LINUX_OLD_VKILL];
277 1.15 manu bts->c_cc[VEOF] = lt->c_cc[LINUX_OLD_VEOF];
278 1.15 manu bts->c_cc[VTIME] = lt->c_cc[LINUX_OLD_VTIME];
279 1.15 manu bts->c_cc[VMIN] = lt->c_cc[LINUX_OLD_VMIN];
280 1.15 manu }
281 1.15 manu
282 1.15 manu static void
283 1.15 manu #ifdef COMPAT_LINUX32
284 1.15 manu bsd_termios_to_linux32_termio(bts, lt)
285 1.15 manu struct termios *bts;
286 1.15 manu struct linux32_termio *lt;
287 1.15 manu #else
288 1.15 manu bsd_termios_to_linux_termio(bts, lt)
289 1.15 manu struct termios *bts;
290 1.15 manu struct linux_termio *lt;
291 1.15 manu #endif
292 1.15 manu {
293 1.15 manu int i, mask;
294 1.15 manu
295 1.15 manu lt->c_iflag = 0;
296 1.15 manu lt->c_iflag |= cvtto_linux_mask(bts->c_iflag, IGNBRK, LINUX_IGNBRK);
297 1.15 manu lt->c_iflag |= cvtto_linux_mask(bts->c_iflag, BRKINT, LINUX_BRKINT);
298 1.15 manu lt->c_iflag |= cvtto_linux_mask(bts->c_iflag, IGNPAR, LINUX_IGNPAR);
299 1.15 manu lt->c_iflag |= cvtto_linux_mask(bts->c_iflag, INPCK, LINUX_INPCK);
300 1.15 manu lt->c_iflag |= cvtto_linux_mask(bts->c_iflag, ISTRIP, LINUX_ISTRIP);
301 1.15 manu lt->c_iflag |= cvtto_linux_mask(bts->c_iflag, INLCR, LINUX_INLCR);
302 1.15 manu lt->c_iflag |= cvtto_linux_mask(bts->c_iflag, IGNCR, LINUX_IGNCR);
303 1.15 manu lt->c_iflag |= cvtto_linux_mask(bts->c_iflag, ICRNL, LINUX_ICRNL);
304 1.15 manu lt->c_iflag |= cvtto_linux_mask(bts->c_iflag, IXON, LINUX_IXON);
305 1.15 manu lt->c_iflag |= cvtto_linux_mask(bts->c_iflag, IXANY, LINUX_IXANY);
306 1.15 manu lt->c_iflag |= cvtto_linux_mask(bts->c_iflag, IXOFF, LINUX_IXOFF);
307 1.15 manu lt->c_iflag |= cvtto_linux_mask(bts->c_iflag, IMAXBEL, LINUX_IMAXBEL);
308 1.15 manu
309 1.15 manu lt->c_oflag = 0;
310 1.15 manu lt->c_oflag |= cvtto_linux_mask(bts->c_oflag, OPOST, LINUX_OPOST);
311 1.15 manu lt->c_oflag |= cvtto_linux_mask(bts->c_oflag, ONLCR, LINUX_ONLCR);
312 1.15 manu lt->c_oflag |= cvtto_linux_mask(bts->c_oflag, OXTABS, LINUX_XTABS);
313 1.15 manu
314 1.15 manu switch (bts->c_cflag & CSIZE) {
315 1.15 manu case CS5:
316 1.15 manu lt->c_cflag = LINUX_CS5;
317 1.15 manu break;
318 1.15 manu case CS6:
319 1.15 manu lt->c_cflag = LINUX_CS6;
320 1.15 manu break;
321 1.15 manu case CS7:
322 1.15 manu lt->c_cflag = LINUX_CS7;
323 1.15 manu break;
324 1.15 manu case CS8:
325 1.15 manu lt->c_cflag = LINUX_CS8;
326 1.15 manu break;
327 1.15 manu }
328 1.15 manu lt->c_cflag |= cvtto_linux_mask(bts->c_cflag, CSTOPB, LINUX_CSTOPB);
329 1.15 manu lt->c_cflag |= cvtto_linux_mask(bts->c_cflag, CREAD, LINUX_CREAD);
330 1.15 manu lt->c_cflag |= cvtto_linux_mask(bts->c_cflag, PARENB, LINUX_PARENB);
331 1.15 manu lt->c_cflag |= cvtto_linux_mask(bts->c_cflag, PARODD, LINUX_PARODD);
332 1.15 manu lt->c_cflag |= cvtto_linux_mask(bts->c_cflag, HUPCL, LINUX_HUPCL);
333 1.15 manu lt->c_cflag |= cvtto_linux_mask(bts->c_cflag, CLOCAL, LINUX_CLOCAL);
334 1.15 manu lt->c_cflag |= cvtto_linux_mask(bts->c_cflag, CRTSCTS, LINUX_CRTSCTS);
335 1.15 manu
336 1.15 manu lt->c_lflag = 0;
337 1.15 manu lt->c_lflag |= cvtto_linux_mask(bts->c_lflag, ISIG, LINUX_ISIG);
338 1.15 manu lt->c_lflag |= cvtto_linux_mask(bts->c_lflag, ICANON, LINUX_ICANON);
339 1.15 manu lt->c_lflag |= cvtto_linux_mask(bts->c_lflag, ECHO, LINUX_ECHO);
340 1.15 manu lt->c_lflag |= cvtto_linux_mask(bts->c_lflag, ECHOE, LINUX_ECHOE);
341 1.15 manu lt->c_lflag |= cvtto_linux_mask(bts->c_lflag, ECHOK, LINUX_ECHOK);
342 1.15 manu lt->c_lflag |= cvtto_linux_mask(bts->c_lflag, ECHONL, LINUX_ECHONL);
343 1.15 manu lt->c_lflag |= cvtto_linux_mask(bts->c_lflag, NOFLSH, LINUX_NOFLSH);
344 1.15 manu lt->c_lflag |= cvtto_linux_mask(bts->c_lflag, TOSTOP, LINUX_TOSTOP);
345 1.15 manu lt->c_lflag |= cvtto_linux_mask(bts->c_lflag, ECHOCTL, LINUX_ECHOCTL);
346 1.15 manu lt->c_lflag |= cvtto_linux_mask(bts->c_lflag, ECHOPRT, LINUX_ECHOPRT);
347 1.15 manu lt->c_lflag |= cvtto_linux_mask(bts->c_lflag, ECHOKE, LINUX_ECHOKE);
348 1.15 manu lt->c_lflag |= cvtto_linux_mask(bts->c_lflag, FLUSHO, LINUX_FLUSHO);
349 1.15 manu lt->c_lflag |= cvtto_linux_mask(bts->c_lflag, PENDIN, LINUX_PENDIN);
350 1.15 manu lt->c_lflag |= cvtto_linux_mask(bts->c_lflag, IEXTEN, LINUX_IEXTEN);
351 1.15 manu
352 1.15 manu mask = LINUX_B9600; /* XXX default value should this be 0? */
353 1.15 manu for (i = 0; i < sizeof (linux_speeds) / sizeof (speed_t); i++) {
354 1.15 manu if (bts->c_ospeed == linux_speeds[i]) {
355 1.15 manu mask = linux_spmasks[i];
356 1.15 manu break;
357 1.15 manu }
358 1.15 manu }
359 1.15 manu lt->c_cflag |= mask;
360 1.15 manu
361 1.15 manu lt->c_cc[LINUX_VINTR] = bts->c_cc[VINTR];
362 1.15 manu lt->c_cc[LINUX_VQUIT] = bts->c_cc[VQUIT];
363 1.15 manu lt->c_cc[LINUX_VERASE] = bts->c_cc[VERASE];
364 1.15 manu lt->c_cc[LINUX_VKILL] = bts->c_cc[VKILL];
365 1.15 manu lt->c_cc[LINUX_VEOF] = bts->c_cc[VEOF];
366 1.15 manu lt->c_cc[LINUX_VTIME] = bts->c_cc[VTIME];
367 1.15 manu lt->c_cc[LINUX_VMIN] = bts->c_cc[VMIN];
368 1.15 manu lt->c_cc[LINUX_VSWTC] = 0;
369 1.15 manu
370 1.15 manu /* XXX should be fixed someday */
371 1.15 manu lt->c_line = 0;
372 1.15 manu }
373 1.15 manu
374 1.15 manu static void
375 1.15 manu #ifdef COMPAT_LINUX32
376 1.15 manu linux32_termios_to_bsd_termios(lts, bts)
377 1.15 manu struct linux32_termios *lts;
378 1.15 manu struct termios *bts;
379 1.15 manu #else
380 1.15 manu linux_termios_to_bsd_termios(lts, bts)
381 1.15 manu struct linux_termios *lts;
382 1.15 manu struct termios *bts;
383 1.15 manu #endif
384 1.15 manu {
385 1.15 manu int index;
386 1.15 manu
387 1.15 manu bts->c_iflag = 0;
388 1.15 manu bts->c_iflag |= cvtto_bsd_mask(lts->c_iflag, LINUX_IGNBRK, IGNBRK);
389 1.15 manu bts->c_iflag |= cvtto_bsd_mask(lts->c_iflag, LINUX_BRKINT, BRKINT);
390 1.15 manu bts->c_iflag |= cvtto_bsd_mask(lts->c_iflag, LINUX_IGNPAR, IGNPAR);
391 1.15 manu bts->c_iflag |= cvtto_bsd_mask(lts->c_iflag, LINUX_INPCK, INPCK);
392 1.15 manu bts->c_iflag |= cvtto_bsd_mask(lts->c_iflag, LINUX_ISTRIP, ISTRIP);
393 1.15 manu bts->c_iflag |= cvtto_bsd_mask(lts->c_iflag, LINUX_INLCR, INLCR);
394 1.15 manu bts->c_iflag |= cvtto_bsd_mask(lts->c_iflag, LINUX_IGNCR, IGNCR);
395 1.15 manu bts->c_iflag |= cvtto_bsd_mask(lts->c_iflag, LINUX_ICRNL, ICRNL);
396 1.15 manu bts->c_iflag |= cvtto_bsd_mask(lts->c_iflag, LINUX_IXON, IXON);
397 1.15 manu bts->c_iflag |= cvtto_bsd_mask(lts->c_iflag, LINUX_IXANY, IXANY);
398 1.15 manu bts->c_iflag |= cvtto_bsd_mask(lts->c_iflag, LINUX_IXOFF, IXOFF);
399 1.15 manu bts->c_iflag |= cvtto_bsd_mask(lts->c_iflag, LINUX_IMAXBEL, IMAXBEL);
400 1.15 manu
401 1.15 manu bts->c_oflag = 0;
402 1.15 manu bts->c_oflag |= cvtto_bsd_mask(lts->c_oflag, LINUX_OPOST, OPOST);
403 1.15 manu bts->c_oflag |= cvtto_bsd_mask(lts->c_oflag, LINUX_ONLCR, ONLCR);
404 1.15 manu bts->c_oflag |= cvtto_bsd_mask(lts->c_oflag, LINUX_XTABS, OXTABS);
405 1.15 manu
406 1.15 manu bts->c_cflag = 0;
407 1.15 manu switch (lts->c_cflag & LINUX_CSIZE) {
408 1.15 manu case LINUX_CS5:
409 1.15 manu bts->c_cflag = CS5;
410 1.15 manu break;
411 1.15 manu case LINUX_CS6:
412 1.15 manu bts->c_cflag = CS6;
413 1.15 manu break;
414 1.15 manu case LINUX_CS7:
415 1.15 manu bts->c_cflag = CS7;
416 1.15 manu break;
417 1.15 manu case LINUX_CS8:
418 1.15 manu bts->c_cflag = CS8;
419 1.15 manu break;
420 1.15 manu }
421 1.15 manu bts->c_cflag |= cvtto_bsd_mask(lts->c_cflag, LINUX_CSTOPB, CSTOPB);
422 1.15 manu bts->c_cflag |= cvtto_bsd_mask(lts->c_cflag, LINUX_CREAD, CREAD);
423 1.15 manu bts->c_cflag |= cvtto_bsd_mask(lts->c_cflag, LINUX_PARENB, PARENB);
424 1.15 manu bts->c_cflag |= cvtto_bsd_mask(lts->c_cflag, LINUX_PARODD, PARODD);
425 1.15 manu bts->c_cflag |= cvtto_bsd_mask(lts->c_cflag, LINUX_HUPCL, HUPCL);
426 1.15 manu bts->c_cflag |= cvtto_bsd_mask(lts->c_cflag, LINUX_CLOCAL, CLOCAL);
427 1.15 manu bts->c_cflag |= cvtto_bsd_mask(lts->c_cflag, LINUX_CRTSCTS, CRTSCTS);
428 1.15 manu
429 1.15 manu bts->c_lflag = 0;
430 1.15 manu bts->c_lflag |= cvtto_bsd_mask(lts->c_lflag, LINUX_ISIG, ISIG);
431 1.15 manu bts->c_lflag |= cvtto_bsd_mask(lts->c_lflag, LINUX_ICANON, ICANON);
432 1.15 manu bts->c_lflag |= cvtto_bsd_mask(lts->c_lflag, LINUX_ECHO, ECHO);
433 1.15 manu bts->c_lflag |= cvtto_bsd_mask(lts->c_lflag, LINUX_ECHOE, ECHOE);
434 1.15 manu bts->c_lflag |= cvtto_bsd_mask(lts->c_lflag, LINUX_ECHOK, ECHOK);
435 1.15 manu bts->c_lflag |= cvtto_bsd_mask(lts->c_lflag, LINUX_ECHONL, ECHONL);
436 1.15 manu bts->c_lflag |= cvtto_bsd_mask(lts->c_lflag, LINUX_NOFLSH, NOFLSH);
437 1.15 manu bts->c_lflag |= cvtto_bsd_mask(lts->c_lflag, LINUX_TOSTOP, TOSTOP);
438 1.15 manu bts->c_lflag |= cvtto_bsd_mask(lts->c_lflag, LINUX_ECHOCTL, ECHOCTL);
439 1.15 manu bts->c_lflag |= cvtto_bsd_mask(lts->c_lflag, LINUX_ECHOPRT, ECHOPRT);
440 1.15 manu bts->c_lflag |= cvtto_bsd_mask(lts->c_lflag, LINUX_ECHOKE, ECHOKE);
441 1.15 manu bts->c_lflag |= cvtto_bsd_mask(lts->c_lflag, LINUX_FLUSHO, FLUSHO);
442 1.15 manu bts->c_lflag |= cvtto_bsd_mask(lts->c_lflag, LINUX_PENDIN, PENDIN);
443 1.15 manu bts->c_lflag |= cvtto_bsd_mask(lts->c_lflag, LINUX_IEXTEN, IEXTEN);
444 1.15 manu
445 1.15 manu index = lts->c_cflag & LINUX_CBAUD;
446 1.15 manu if (index & LINUX_CBAUDEX)
447 1.15 manu index = (index & ~LINUX_CBAUDEX) + LINUX_NSPEEDS - 1;
448 1.15 manu bts->c_ispeed = bts->c_ospeed = linux_speeds[index];
449 1.15 manu /*
450 1.15 manu * A null c_ospeed causes NetBSD to hangup the terminal.
451 1.15 manu * Linux does not do this, and it sets c_ospeed to zero
452 1.15 manu * sometimes. If it is null, we store -1 in the kernel
453 1.15 manu */
454 1.15 manu if (bts->c_ospeed == 0)
455 1.15 manu bts->c_ospeed = -1;
456 1.15 manu
457 1.15 manu bts->c_cc[VINTR] = lts->c_cc[LINUX_VINTR];
458 1.15 manu bts->c_cc[VQUIT] = lts->c_cc[LINUX_VQUIT];
459 1.15 manu bts->c_cc[VERASE] = lts->c_cc[LINUX_VERASE];
460 1.15 manu bts->c_cc[VKILL] = lts->c_cc[LINUX_VKILL];
461 1.15 manu bts->c_cc[VEOF] = lts->c_cc[LINUX_VEOF];
462 1.15 manu bts->c_cc[VTIME] = lts->c_cc[LINUX_VTIME];
463 1.15 manu bts->c_cc[VMIN] = lts->c_cc[LINUX_VMIN];
464 1.15 manu bts->c_cc[VEOL] = lts->c_cc[LINUX_VEOL];
465 1.15 manu bts->c_cc[VEOL2] = lts->c_cc[LINUX_VEOL2];
466 1.15 manu bts->c_cc[VWERASE] = lts->c_cc[LINUX_VWERASE];
467 1.15 manu bts->c_cc[VSUSP] = lts->c_cc[LINUX_VSUSP];
468 1.15 manu bts->c_cc[VSTART] = lts->c_cc[LINUX_VSTART];
469 1.15 manu bts->c_cc[VSTOP] = lts->c_cc[LINUX_VSTOP];
470 1.15 manu bts->c_cc[VLNEXT] = lts->c_cc[LINUX_VLNEXT];
471 1.15 manu bts->c_cc[VDISCARD] = lts->c_cc[LINUX_VDISCARD];
472 1.15 manu bts->c_cc[VREPRINT] = lts->c_cc[LINUX_VREPRINT];
473 1.15 manu }
474 1.15 manu
475 1.15 manu static void
476 1.15 manu #ifdef COMPAT_LINUX32
477 1.15 manu bsd_termios_to_linux32_termios(bts, lts)
478 1.15 manu struct termios *bts;
479 1.15 manu struct linux32_termios *lts;
480 1.15 manu #else
481 1.15 manu bsd_termios_to_linux_termios(bts, lts)
482 1.15 manu struct termios *bts;
483 1.15 manu struct linux_termios *lts;
484 1.15 manu #endif
485 1.15 manu {
486 1.15 manu int i, mask;
487 1.15 manu
488 1.15 manu lts->c_iflag = 0;
489 1.15 manu lts->c_iflag |= cvtto_linux_mask(bts->c_iflag, IGNBRK, LINUX_IGNBRK);
490 1.15 manu lts->c_iflag |= cvtto_linux_mask(bts->c_iflag, BRKINT, LINUX_BRKINT);
491 1.15 manu lts->c_iflag |= cvtto_linux_mask(bts->c_iflag, IGNPAR, LINUX_IGNPAR);
492 1.15 manu lts->c_iflag |= cvtto_linux_mask(bts->c_iflag, INPCK, LINUX_INPCK);
493 1.15 manu lts->c_iflag |= cvtto_linux_mask(bts->c_iflag, ISTRIP, LINUX_ISTRIP);
494 1.15 manu lts->c_iflag |= cvtto_linux_mask(bts->c_iflag, INLCR, LINUX_INLCR);
495 1.15 manu lts->c_iflag |= cvtto_linux_mask(bts->c_iflag, IGNCR, LINUX_IGNCR);
496 1.15 manu lts->c_iflag |= cvtto_linux_mask(bts->c_iflag, ICRNL, LINUX_ICRNL);
497 1.15 manu lts->c_iflag |= cvtto_linux_mask(bts->c_iflag, IXON, LINUX_IXON);
498 1.15 manu lts->c_iflag |= cvtto_linux_mask(bts->c_iflag, IXANY, LINUX_IXANY);
499 1.15 manu lts->c_iflag |= cvtto_linux_mask(bts->c_iflag, IXOFF, LINUX_IXOFF);
500 1.15 manu lts->c_iflag |= cvtto_linux_mask(bts->c_iflag, IMAXBEL, LINUX_IMAXBEL);
501 1.15 manu
502 1.15 manu lts->c_oflag = 0;
503 1.15 manu lts->c_oflag |= cvtto_linux_mask(bts->c_oflag, OPOST, LINUX_OPOST);
504 1.15 manu lts->c_oflag |= cvtto_linux_mask(bts->c_oflag, ONLCR, LINUX_ONLCR);
505 1.15 manu lts->c_oflag |= cvtto_linux_mask(bts->c_oflag, OXTABS, LINUX_XTABS);
506 1.15 manu
507 1.15 manu switch (bts->c_cflag & CSIZE) {
508 1.15 manu case CS5:
509 1.15 manu lts->c_cflag = LINUX_CS5;
510 1.15 manu break;
511 1.15 manu case CS6:
512 1.15 manu lts->c_cflag = LINUX_CS6;
513 1.15 manu break;
514 1.15 manu case CS7:
515 1.15 manu lts->c_cflag = LINUX_CS7;
516 1.15 manu break;
517 1.15 manu case CS8:
518 1.15 manu lts->c_cflag = LINUX_CS8;
519 1.15 manu break;
520 1.15 manu }
521 1.15 manu lts->c_cflag |= cvtto_linux_mask(bts->c_cflag, CS5, LINUX_CS5);
522 1.15 manu lts->c_cflag |= cvtto_linux_mask(bts->c_cflag, CS6, LINUX_CS6);
523 1.15 manu lts->c_cflag |= cvtto_linux_mask(bts->c_cflag, CS7, LINUX_CS7);
524 1.15 manu lts->c_cflag |= cvtto_linux_mask(bts->c_cflag, CS8, LINUX_CS8);
525 1.15 manu lts->c_cflag |= cvtto_linux_mask(bts->c_cflag, CSTOPB, LINUX_CSTOPB);
526 1.15 manu lts->c_cflag |= cvtto_linux_mask(bts->c_cflag, CREAD, LINUX_CREAD);
527 1.15 manu lts->c_cflag |= cvtto_linux_mask(bts->c_cflag, PARENB, LINUX_PARENB);
528 1.15 manu lts->c_cflag |= cvtto_linux_mask(bts->c_cflag, PARODD, LINUX_PARODD);
529 1.15 manu lts->c_cflag |= cvtto_linux_mask(bts->c_cflag, HUPCL, LINUX_HUPCL);
530 1.15 manu lts->c_cflag |= cvtto_linux_mask(bts->c_cflag, CLOCAL, LINUX_CLOCAL);
531 1.15 manu lts->c_cflag |= cvtto_linux_mask(bts->c_cflag, CRTSCTS, LINUX_CRTSCTS);
532 1.15 manu
533 1.15 manu lts->c_lflag = 0;
534 1.15 manu lts->c_lflag |= cvtto_linux_mask(bts->c_lflag, ISIG, LINUX_ISIG);
535 1.15 manu lts->c_lflag |= cvtto_linux_mask(bts->c_lflag, ICANON, LINUX_ICANON);
536 1.15 manu lts->c_lflag |= cvtto_linux_mask(bts->c_lflag, ECHO, LINUX_ECHO);
537 1.15 manu lts->c_lflag |= cvtto_linux_mask(bts->c_lflag, ECHOE, LINUX_ECHOE);
538 1.15 manu lts->c_lflag |= cvtto_linux_mask(bts->c_lflag, ECHOK, LINUX_ECHOK);
539 1.15 manu lts->c_lflag |= cvtto_linux_mask(bts->c_lflag, ECHONL, LINUX_ECHONL);
540 1.15 manu lts->c_lflag |= cvtto_linux_mask(bts->c_lflag, NOFLSH, LINUX_NOFLSH);
541 1.15 manu lts->c_lflag |= cvtto_linux_mask(bts->c_lflag, TOSTOP, LINUX_TOSTOP);
542 1.15 manu lts->c_lflag |= cvtto_linux_mask(bts->c_lflag, ECHOCTL, LINUX_ECHOCTL);
543 1.15 manu lts->c_lflag |= cvtto_linux_mask(bts->c_lflag, ECHOPRT, LINUX_ECHOPRT);
544 1.15 manu lts->c_lflag |= cvtto_linux_mask(bts->c_lflag, ECHOKE, LINUX_ECHOKE);
545 1.15 manu lts->c_lflag |= cvtto_linux_mask(bts->c_lflag, FLUSHO, LINUX_FLUSHO);
546 1.15 manu lts->c_lflag |= cvtto_linux_mask(bts->c_lflag, PENDIN, LINUX_PENDIN);
547 1.15 manu lts->c_lflag |= cvtto_linux_mask(bts->c_lflag, IEXTEN, LINUX_IEXTEN);
548 1.15 manu
549 1.15 manu mask = LINUX_B9600; /* XXX default value */
550 1.15 manu for (i = 0; i < sizeof (linux_speeds) / sizeof (speed_t); i++) {
551 1.15 manu if (bts->c_ospeed == linux_speeds[i]) {
552 1.15 manu mask = linux_spmasks[i];
553 1.15 manu break;
554 1.15 manu }
555 1.15 manu }
556 1.15 manu /*
557 1.15 manu * A null c_ospeed causes NetBSD to hangup the terminal.
558 1.15 manu * Linux does not do this, and it sets c_ospeed to zero
559 1.15 manu * sometimes. If it is null, we store -1 in the kernel
560 1.15 manu */
561 1.15 manu if (bts->c_ospeed == -1)
562 1.15 manu bts->c_ospeed = 0;
563 1.15 manu lts->c_cflag |= mask;
564 1.15 manu
565 1.15 manu lts->c_cc[LINUX_VINTR] = bts->c_cc[VINTR];
566 1.15 manu lts->c_cc[LINUX_VQUIT] = bts->c_cc[VQUIT];
567 1.15 manu lts->c_cc[LINUX_VERASE] = bts->c_cc[VERASE];
568 1.15 manu lts->c_cc[LINUX_VKILL] = bts->c_cc[VKILL];
569 1.15 manu lts->c_cc[LINUX_VEOF] = bts->c_cc[VEOF];
570 1.15 manu lts->c_cc[LINUX_VTIME] = bts->c_cc[VTIME];
571 1.15 manu lts->c_cc[LINUX_VMIN] = bts->c_cc[VMIN];
572 1.15 manu lts->c_cc[LINUX_VEOL] = bts->c_cc[VEOL];
573 1.15 manu lts->c_cc[LINUX_VEOL2] = bts->c_cc[VEOL2];
574 1.15 manu lts->c_cc[LINUX_VWERASE] = bts->c_cc[VWERASE];
575 1.15 manu lts->c_cc[LINUX_VSUSP] = bts->c_cc[VSUSP];
576 1.15 manu lts->c_cc[LINUX_VSTART] = bts->c_cc[VSTART];
577 1.15 manu lts->c_cc[LINUX_VSTOP] = bts->c_cc[VSTOP];
578 1.15 manu lts->c_cc[LINUX_VLNEXT] = bts->c_cc[VLNEXT];
579 1.15 manu lts->c_cc[LINUX_VDISCARD] = bts->c_cc[VDISCARD];
580 1.15 manu lts->c_cc[LINUX_VREPRINT] = bts->c_cc[VREPRINT];
581 1.15 manu lts->c_cc[LINUX_VSWTC] = 0;
582 1.15 manu
583 1.15 manu /* XXX should be fixed someday */
584 1.15 manu lts->c_line = 0;
585 1.15 manu }
586 1.4 christos #endif /* !_LINUX_TERMIOS_H */
587