1 /* $NetBSD: linux_termios.h,v 1.19 2009/03/15 15:55:51 cegger 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 53 struct 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 */ 64 struct 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 73 struct 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 140 static 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 145 static 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 153 struct linux32_termio; 154 struct linux32_termios; 155 static void linux32_termio_to_bsd_termios(struct linux32_termio *, 156 struct termios *); 157 static void bsd_termios_to_linux32_termio(struct termios *, 158 struct linux32_termio *); 159 static void linux32_termios_to_bsd_termios(struct linux32_termios *, 160 struct termios *); 161 static void bsd_termios_to_linux32_termios(struct termios *, 162 struct linux32_termios *); 163 #else 164 struct linux_termio; 165 struct linux_termios; 166 static void linux_termio_to_bsd_termios(struct linux_termio *, 167 struct termios *); 168 static void bsd_termios_to_linux_termio(struct termios *, 169 struct linux_termio *); 170 static void linux_termios_to_bsd_termios(struct linux_termios *, 171 struct termios *); 172 static 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 186 static void 187 #ifdef COMPAT_LINUX32 188 linux32_termio_to_bsd_termios(struct linux32_termio *lt, struct termios *bts) 189 #else 190 linux_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 bts->c_cc[VEOF] = lt->c_cc[LINUX_OLD_VEOF]; 267 bts->c_cc[VTIME] = lt->c_cc[LINUX_OLD_VTIME]; 268 bts->c_cc[VMIN] = lt->c_cc[LINUX_OLD_VMIN]; 269 } 270 271 static void 272 #ifdef COMPAT_LINUX32 273 bsd_termios_to_linux32_termio(struct termios *bts, struct linux32_termio *lt) 274 #else 275 bsd_termios_to_linux_termio(struct termios *bts, struct linux_termio *lt) 276 #endif 277 { 278 int i, mask; 279 280 lt->c_iflag = 0; 281 lt->c_iflag |= cvtto_linux_mask(bts->c_iflag, IGNBRK, LINUX_IGNBRK); 282 lt->c_iflag |= cvtto_linux_mask(bts->c_iflag, BRKINT, LINUX_BRKINT); 283 lt->c_iflag |= cvtto_linux_mask(bts->c_iflag, IGNPAR, LINUX_IGNPAR); 284 lt->c_iflag |= cvtto_linux_mask(bts->c_iflag, INPCK, LINUX_INPCK); 285 lt->c_iflag |= cvtto_linux_mask(bts->c_iflag, ISTRIP, LINUX_ISTRIP); 286 lt->c_iflag |= cvtto_linux_mask(bts->c_iflag, INLCR, LINUX_INLCR); 287 lt->c_iflag |= cvtto_linux_mask(bts->c_iflag, IGNCR, LINUX_IGNCR); 288 lt->c_iflag |= cvtto_linux_mask(bts->c_iflag, ICRNL, LINUX_ICRNL); 289 lt->c_iflag |= cvtto_linux_mask(bts->c_iflag, IXON, LINUX_IXON); 290 lt->c_iflag |= cvtto_linux_mask(bts->c_iflag, IXANY, LINUX_IXANY); 291 lt->c_iflag |= cvtto_linux_mask(bts->c_iflag, IXOFF, LINUX_IXOFF); 292 lt->c_iflag |= cvtto_linux_mask(bts->c_iflag, IMAXBEL, LINUX_IMAXBEL); 293 294 lt->c_oflag = 0; 295 lt->c_oflag |= cvtto_linux_mask(bts->c_oflag, OPOST, LINUX_OPOST); 296 lt->c_oflag |= cvtto_linux_mask(bts->c_oflag, ONLCR, LINUX_ONLCR); 297 lt->c_oflag |= cvtto_linux_mask(bts->c_oflag, OXTABS, LINUX_XTABS); 298 299 switch (bts->c_cflag & CSIZE) { 300 case CS5: 301 lt->c_cflag = LINUX_CS5; 302 break; 303 case CS6: 304 lt->c_cflag = LINUX_CS6; 305 break; 306 case CS7: 307 lt->c_cflag = LINUX_CS7; 308 break; 309 case CS8: 310 lt->c_cflag = LINUX_CS8; 311 break; 312 } 313 lt->c_cflag |= cvtto_linux_mask(bts->c_cflag, CSTOPB, LINUX_CSTOPB); 314 lt->c_cflag |= cvtto_linux_mask(bts->c_cflag, CREAD, LINUX_CREAD); 315 lt->c_cflag |= cvtto_linux_mask(bts->c_cflag, PARENB, LINUX_PARENB); 316 lt->c_cflag |= cvtto_linux_mask(bts->c_cflag, PARODD, LINUX_PARODD); 317 lt->c_cflag |= cvtto_linux_mask(bts->c_cflag, HUPCL, LINUX_HUPCL); 318 lt->c_cflag |= cvtto_linux_mask(bts->c_cflag, CLOCAL, LINUX_CLOCAL); 319 lt->c_cflag |= cvtto_linux_mask(bts->c_cflag, CRTSCTS, LINUX_CRTSCTS); 320 321 lt->c_lflag = 0; 322 lt->c_lflag |= cvtto_linux_mask(bts->c_lflag, ISIG, LINUX_ISIG); 323 lt->c_lflag |= cvtto_linux_mask(bts->c_lflag, ICANON, LINUX_ICANON); 324 lt->c_lflag |= cvtto_linux_mask(bts->c_lflag, ECHO, LINUX_ECHO); 325 lt->c_lflag |= cvtto_linux_mask(bts->c_lflag, ECHOE, LINUX_ECHOE); 326 lt->c_lflag |= cvtto_linux_mask(bts->c_lflag, ECHOK, LINUX_ECHOK); 327 lt->c_lflag |= cvtto_linux_mask(bts->c_lflag, ECHONL, LINUX_ECHONL); 328 lt->c_lflag |= cvtto_linux_mask(bts->c_lflag, NOFLSH, LINUX_NOFLSH); 329 lt->c_lflag |= cvtto_linux_mask(bts->c_lflag, TOSTOP, LINUX_TOSTOP); 330 lt->c_lflag |= cvtto_linux_mask(bts->c_lflag, ECHOCTL, LINUX_ECHOCTL); 331 lt->c_lflag |= cvtto_linux_mask(bts->c_lflag, ECHOPRT, LINUX_ECHOPRT); 332 lt->c_lflag |= cvtto_linux_mask(bts->c_lflag, ECHOKE, LINUX_ECHOKE); 333 lt->c_lflag |= cvtto_linux_mask(bts->c_lflag, FLUSHO, LINUX_FLUSHO); 334 lt->c_lflag |= cvtto_linux_mask(bts->c_lflag, PENDIN, LINUX_PENDIN); 335 lt->c_lflag |= cvtto_linux_mask(bts->c_lflag, IEXTEN, LINUX_IEXTEN); 336 337 mask = LINUX_B9600; /* XXX default value should this be 0? */ 338 for (i = 0; i < sizeof (linux_speeds) / sizeof (linux_speed_t); i++) { 339 if (bts->c_ospeed == linux_speeds[i]) { 340 mask = linux_spmasks[i]; 341 break; 342 } 343 } 344 lt->c_cflag |= mask; 345 346 lt->c_cc[LINUX_VINTR] = bts->c_cc[VINTR]; 347 lt->c_cc[LINUX_VQUIT] = bts->c_cc[VQUIT]; 348 lt->c_cc[LINUX_VERASE] = bts->c_cc[VERASE]; 349 lt->c_cc[LINUX_VKILL] = bts->c_cc[VKILL]; 350 lt->c_cc[LINUX_VEOF] = bts->c_cc[VEOF]; 351 lt->c_cc[LINUX_VTIME] = bts->c_cc[VTIME]; 352 lt->c_cc[LINUX_VMIN] = bts->c_cc[VMIN]; 353 lt->c_cc[LINUX_VSWTC] = 0; 354 355 /* XXX should be fixed someday */ 356 lt->c_line = 0; 357 } 358 359 static void 360 #ifdef COMPAT_LINUX32 361 linux32_termios_to_bsd_termios(struct linux32_termios *lts, struct termios *bts) 362 #else 363 linux_termios_to_bsd_termios(struct linux_termios *lts, struct termios *bts) 364 #endif 365 { 366 int index; 367 368 bts->c_iflag = 0; 369 bts->c_iflag |= cvtto_bsd_mask(lts->c_iflag, LINUX_IGNBRK, IGNBRK); 370 bts->c_iflag |= cvtto_bsd_mask(lts->c_iflag, LINUX_BRKINT, BRKINT); 371 bts->c_iflag |= cvtto_bsd_mask(lts->c_iflag, LINUX_IGNPAR, IGNPAR); 372 bts->c_iflag |= cvtto_bsd_mask(lts->c_iflag, LINUX_INPCK, INPCK); 373 bts->c_iflag |= cvtto_bsd_mask(lts->c_iflag, LINUX_ISTRIP, ISTRIP); 374 bts->c_iflag |= cvtto_bsd_mask(lts->c_iflag, LINUX_INLCR, INLCR); 375 bts->c_iflag |= cvtto_bsd_mask(lts->c_iflag, LINUX_IGNCR, IGNCR); 376 bts->c_iflag |= cvtto_bsd_mask(lts->c_iflag, LINUX_ICRNL, ICRNL); 377 bts->c_iflag |= cvtto_bsd_mask(lts->c_iflag, LINUX_IXON, IXON); 378 bts->c_iflag |= cvtto_bsd_mask(lts->c_iflag, LINUX_IXANY, IXANY); 379 bts->c_iflag |= cvtto_bsd_mask(lts->c_iflag, LINUX_IXOFF, IXOFF); 380 bts->c_iflag |= cvtto_bsd_mask(lts->c_iflag, LINUX_IMAXBEL, IMAXBEL); 381 382 bts->c_oflag = 0; 383 bts->c_oflag |= cvtto_bsd_mask(lts->c_oflag, LINUX_OPOST, OPOST); 384 bts->c_oflag |= cvtto_bsd_mask(lts->c_oflag, LINUX_ONLCR, ONLCR); 385 bts->c_oflag |= cvtto_bsd_mask(lts->c_oflag, LINUX_XTABS, OXTABS); 386 387 bts->c_cflag = 0; 388 switch (lts->c_cflag & LINUX_CSIZE) { 389 case LINUX_CS5: 390 bts->c_cflag = CS5; 391 break; 392 case LINUX_CS6: 393 bts->c_cflag = CS6; 394 break; 395 case LINUX_CS7: 396 bts->c_cflag = CS7; 397 break; 398 case LINUX_CS8: 399 bts->c_cflag = CS8; 400 break; 401 } 402 bts->c_cflag |= cvtto_bsd_mask(lts->c_cflag, LINUX_CSTOPB, CSTOPB); 403 bts->c_cflag |= cvtto_bsd_mask(lts->c_cflag, LINUX_CREAD, CREAD); 404 bts->c_cflag |= cvtto_bsd_mask(lts->c_cflag, LINUX_PARENB, PARENB); 405 bts->c_cflag |= cvtto_bsd_mask(lts->c_cflag, LINUX_PARODD, PARODD); 406 bts->c_cflag |= cvtto_bsd_mask(lts->c_cflag, LINUX_HUPCL, HUPCL); 407 bts->c_cflag |= cvtto_bsd_mask(lts->c_cflag, LINUX_CLOCAL, CLOCAL); 408 bts->c_cflag |= cvtto_bsd_mask(lts->c_cflag, LINUX_CRTSCTS, CRTSCTS); 409 410 bts->c_lflag = 0; 411 bts->c_lflag |= cvtto_bsd_mask(lts->c_lflag, LINUX_ISIG, ISIG); 412 bts->c_lflag |= cvtto_bsd_mask(lts->c_lflag, LINUX_ICANON, ICANON); 413 bts->c_lflag |= cvtto_bsd_mask(lts->c_lflag, LINUX_ECHO, ECHO); 414 bts->c_lflag |= cvtto_bsd_mask(lts->c_lflag, LINUX_ECHOE, ECHOE); 415 bts->c_lflag |= cvtto_bsd_mask(lts->c_lflag, LINUX_ECHOK, ECHOK); 416 bts->c_lflag |= cvtto_bsd_mask(lts->c_lflag, LINUX_ECHONL, ECHONL); 417 bts->c_lflag |= cvtto_bsd_mask(lts->c_lflag, LINUX_NOFLSH, NOFLSH); 418 bts->c_lflag |= cvtto_bsd_mask(lts->c_lflag, LINUX_TOSTOP, TOSTOP); 419 bts->c_lflag |= cvtto_bsd_mask(lts->c_lflag, LINUX_ECHOCTL, ECHOCTL); 420 bts->c_lflag |= cvtto_bsd_mask(lts->c_lflag, LINUX_ECHOPRT, ECHOPRT); 421 bts->c_lflag |= cvtto_bsd_mask(lts->c_lflag, LINUX_ECHOKE, ECHOKE); 422 bts->c_lflag |= cvtto_bsd_mask(lts->c_lflag, LINUX_FLUSHO, FLUSHO); 423 bts->c_lflag |= cvtto_bsd_mask(lts->c_lflag, LINUX_PENDIN, PENDIN); 424 bts->c_lflag |= cvtto_bsd_mask(lts->c_lflag, LINUX_IEXTEN, IEXTEN); 425 426 index = lts->c_cflag & LINUX_CBAUD; 427 if (index & LINUX_CBAUDEX) 428 index = (index & ~LINUX_CBAUDEX) + LINUX_NSPEEDS - 1; 429 bts->c_ispeed = bts->c_ospeed = linux_speeds[index]; 430 /* 431 * A null c_ospeed causes NetBSD to hangup the terminal. 432 * Linux does not do this, and it sets c_ospeed to zero 433 * sometimes. If it is null, we store -1 in the kernel 434 */ 435 if (bts->c_ospeed == 0) 436 bts->c_ospeed = -1; 437 438 bts->c_cc[VINTR] = lts->c_cc[LINUX_VINTR]; 439 bts->c_cc[VQUIT] = lts->c_cc[LINUX_VQUIT]; 440 bts->c_cc[VERASE] = lts->c_cc[LINUX_VERASE]; 441 bts->c_cc[VKILL] = lts->c_cc[LINUX_VKILL]; 442 bts->c_cc[VEOF] = lts->c_cc[LINUX_VEOF]; 443 bts->c_cc[VTIME] = lts->c_cc[LINUX_VTIME]; 444 bts->c_cc[VMIN] = lts->c_cc[LINUX_VMIN]; 445 bts->c_cc[VEOL] = lts->c_cc[LINUX_VEOL]; 446 bts->c_cc[VEOL2] = lts->c_cc[LINUX_VEOL2]; 447 bts->c_cc[VWERASE] = lts->c_cc[LINUX_VWERASE]; 448 bts->c_cc[VSUSP] = lts->c_cc[LINUX_VSUSP]; 449 bts->c_cc[VSTART] = lts->c_cc[LINUX_VSTART]; 450 bts->c_cc[VSTOP] = lts->c_cc[LINUX_VSTOP]; 451 bts->c_cc[VLNEXT] = lts->c_cc[LINUX_VLNEXT]; 452 bts->c_cc[VDISCARD] = lts->c_cc[LINUX_VDISCARD]; 453 bts->c_cc[VREPRINT] = lts->c_cc[LINUX_VREPRINT]; 454 } 455 456 static void 457 #ifdef COMPAT_LINUX32 458 bsd_termios_to_linux32_termios(struct termios *bts, struct linux32_termios *lts) 459 #else 460 bsd_termios_to_linux_termios(struct termios *bts, struct linux_termios *lts) 461 #endif 462 { 463 int i, mask; 464 465 lts->c_iflag = 0; 466 lts->c_iflag |= cvtto_linux_mask(bts->c_iflag, IGNBRK, LINUX_IGNBRK); 467 lts->c_iflag |= cvtto_linux_mask(bts->c_iflag, BRKINT, LINUX_BRKINT); 468 lts->c_iflag |= cvtto_linux_mask(bts->c_iflag, IGNPAR, LINUX_IGNPAR); 469 lts->c_iflag |= cvtto_linux_mask(bts->c_iflag, INPCK, LINUX_INPCK); 470 lts->c_iflag |= cvtto_linux_mask(bts->c_iflag, ISTRIP, LINUX_ISTRIP); 471 lts->c_iflag |= cvtto_linux_mask(bts->c_iflag, INLCR, LINUX_INLCR); 472 lts->c_iflag |= cvtto_linux_mask(bts->c_iflag, IGNCR, LINUX_IGNCR); 473 lts->c_iflag |= cvtto_linux_mask(bts->c_iflag, ICRNL, LINUX_ICRNL); 474 lts->c_iflag |= cvtto_linux_mask(bts->c_iflag, IXON, LINUX_IXON); 475 lts->c_iflag |= cvtto_linux_mask(bts->c_iflag, IXANY, LINUX_IXANY); 476 lts->c_iflag |= cvtto_linux_mask(bts->c_iflag, IXOFF, LINUX_IXOFF); 477 lts->c_iflag |= cvtto_linux_mask(bts->c_iflag, IMAXBEL, LINUX_IMAXBEL); 478 479 lts->c_oflag = 0; 480 lts->c_oflag |= cvtto_linux_mask(bts->c_oflag, OPOST, LINUX_OPOST); 481 lts->c_oflag |= cvtto_linux_mask(bts->c_oflag, ONLCR, LINUX_ONLCR); 482 lts->c_oflag |= cvtto_linux_mask(bts->c_oflag, OXTABS, LINUX_XTABS); 483 484 switch (bts->c_cflag & CSIZE) { 485 case CS5: 486 lts->c_cflag = LINUX_CS5; 487 break; 488 case CS6: 489 lts->c_cflag = LINUX_CS6; 490 break; 491 case CS7: 492 lts->c_cflag = LINUX_CS7; 493 break; 494 case CS8: 495 lts->c_cflag = LINUX_CS8; 496 break; 497 } 498 lts->c_cflag |= cvtto_linux_mask(bts->c_cflag, CS5, LINUX_CS5); 499 lts->c_cflag |= cvtto_linux_mask(bts->c_cflag, CS6, LINUX_CS6); 500 lts->c_cflag |= cvtto_linux_mask(bts->c_cflag, CS7, LINUX_CS7); 501 lts->c_cflag |= cvtto_linux_mask(bts->c_cflag, CS8, LINUX_CS8); 502 lts->c_cflag |= cvtto_linux_mask(bts->c_cflag, CSTOPB, LINUX_CSTOPB); 503 lts->c_cflag |= cvtto_linux_mask(bts->c_cflag, CREAD, LINUX_CREAD); 504 lts->c_cflag |= cvtto_linux_mask(bts->c_cflag, PARENB, LINUX_PARENB); 505 lts->c_cflag |= cvtto_linux_mask(bts->c_cflag, PARODD, LINUX_PARODD); 506 lts->c_cflag |= cvtto_linux_mask(bts->c_cflag, HUPCL, LINUX_HUPCL); 507 lts->c_cflag |= cvtto_linux_mask(bts->c_cflag, CLOCAL, LINUX_CLOCAL); 508 lts->c_cflag |= cvtto_linux_mask(bts->c_cflag, CRTSCTS, LINUX_CRTSCTS); 509 510 lts->c_lflag = 0; 511 lts->c_lflag |= cvtto_linux_mask(bts->c_lflag, ISIG, LINUX_ISIG); 512 lts->c_lflag |= cvtto_linux_mask(bts->c_lflag, ICANON, LINUX_ICANON); 513 lts->c_lflag |= cvtto_linux_mask(bts->c_lflag, ECHO, LINUX_ECHO); 514 lts->c_lflag |= cvtto_linux_mask(bts->c_lflag, ECHOE, LINUX_ECHOE); 515 lts->c_lflag |= cvtto_linux_mask(bts->c_lflag, ECHOK, LINUX_ECHOK); 516 lts->c_lflag |= cvtto_linux_mask(bts->c_lflag, ECHONL, LINUX_ECHONL); 517 lts->c_lflag |= cvtto_linux_mask(bts->c_lflag, NOFLSH, LINUX_NOFLSH); 518 lts->c_lflag |= cvtto_linux_mask(bts->c_lflag, TOSTOP, LINUX_TOSTOP); 519 lts->c_lflag |= cvtto_linux_mask(bts->c_lflag, ECHOCTL, LINUX_ECHOCTL); 520 lts->c_lflag |= cvtto_linux_mask(bts->c_lflag, ECHOPRT, LINUX_ECHOPRT); 521 lts->c_lflag |= cvtto_linux_mask(bts->c_lflag, ECHOKE, LINUX_ECHOKE); 522 lts->c_lflag |= cvtto_linux_mask(bts->c_lflag, FLUSHO, LINUX_FLUSHO); 523 lts->c_lflag |= cvtto_linux_mask(bts->c_lflag, PENDIN, LINUX_PENDIN); 524 lts->c_lflag |= cvtto_linux_mask(bts->c_lflag, IEXTEN, LINUX_IEXTEN); 525 526 mask = LINUX_B9600; /* XXX default value */ 527 for (i = 0; i < sizeof (linux_speeds) / sizeof (linux_speed_t); i++) { 528 if (bts->c_ospeed == linux_speeds[i]) { 529 mask = linux_spmasks[i]; 530 break; 531 } 532 } 533 /* 534 * A null c_ospeed causes NetBSD to hangup the terminal. 535 * Linux does not do this, and it sets c_ospeed to zero 536 * sometimes. If it is null, we store -1 in the kernel 537 */ 538 if (bts->c_ospeed == -1) 539 bts->c_ospeed = 0; 540 lts->c_cflag |= mask; 541 542 lts->c_cc[LINUX_VINTR] = bts->c_cc[VINTR]; 543 lts->c_cc[LINUX_VQUIT] = bts->c_cc[VQUIT]; 544 lts->c_cc[LINUX_VERASE] = bts->c_cc[VERASE]; 545 lts->c_cc[LINUX_VKILL] = bts->c_cc[VKILL]; 546 lts->c_cc[LINUX_VEOF] = bts->c_cc[VEOF]; 547 lts->c_cc[LINUX_VTIME] = bts->c_cc[VTIME]; 548 lts->c_cc[LINUX_VMIN] = bts->c_cc[VMIN]; 549 lts->c_cc[LINUX_VEOL] = bts->c_cc[VEOL]; 550 lts->c_cc[LINUX_VEOL2] = bts->c_cc[VEOL2]; 551 lts->c_cc[LINUX_VWERASE] = bts->c_cc[VWERASE]; 552 lts->c_cc[LINUX_VSUSP] = bts->c_cc[VSUSP]; 553 lts->c_cc[LINUX_VSTART] = bts->c_cc[VSTART]; 554 lts->c_cc[LINUX_VSTOP] = bts->c_cc[VSTOP]; 555 lts->c_cc[LINUX_VLNEXT] = bts->c_cc[VLNEXT]; 556 lts->c_cc[LINUX_VDISCARD] = bts->c_cc[VDISCARD]; 557 lts->c_cc[LINUX_VREPRINT] = bts->c_cc[VREPRINT]; 558 lts->c_cc[LINUX_VSWTC] = 0; 559 560 /* XXX should be fixed someday */ 561 lts->c_line = 0; 562 } 563 #endif /* !_LINUX_TERMIOS_H */ 564