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