1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 22 /* 23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 /* 28 * Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T 29 * All Rights Reserved 30 * 31 */ 32 33 #include <stdio.h> 34 #include <sys/types.h> 35 #include <termio.h> 36 #include <sys/stermio.h> 37 #include <sys/termiox.h> 38 #include "stty.h" 39 40 const struct speeds speeds[] = { 41 "0", B0, 0, 42 "50", B50, 50, 43 "75", B75, 75, 44 "110", B110, 110, 45 "134", B134, 134, 46 "134.5", B134, 134, 47 "150", B150, 150, 48 "200", B200, 200, 49 "300", B300, 300, 50 "600", B600, 600, 51 "1200", B1200, 1200, 52 "1800", B1800, 1800, 53 "2400", B2400, 2400, 54 "4800", B4800, 4800, 55 "9600", B9600, 9600, 56 "19200", B19200, 19200, 57 "19.2", B19200, 19200, 58 "38400", B38400, 38400, 59 "38.4", B38400, 38400, 60 "57600", B57600, 57600, 61 "57.6", B57600, 57600, 62 "76800", B76800, 76800, 63 "76.8", B76800, 76800, 64 "115200", B115200, 115200, 65 "115.2", B115200, 115200, 66 "153600", B153600, 153600, 67 "153.6", B153600, 153600, 68 "230400", B230400, 230400, 69 "230.4", B230400, 230400, 70 "307200", B307200, 307200, 71 "307.2", B307200, 307200, 72 "460800", B460800, 460800, 73 "460.8", B460800, 460800, 74 "921600", B921600, 921600, 75 "921.6", B921600, 921600, 76 "1000000", B1000000, 1000000, 77 "1152000", B1152000, 1152000, 78 "1500000", B1500000, 1500000, 79 "2000000", B2000000, 2000000, 80 "2500000", B2500000, 2500000, 81 "3000000", B3000000, 3000000, 82 "3500000", B3500000, 3500000, 83 "4000000", B4000000, 4000000, 84 0, 85 }; 86 87 const struct mds cmodes[] = { 88 "-parity", CS8, PARENB|CSIZE, 89 "-evenp", CS8, PARENB|CSIZE, 90 "-oddp", CS8, PARENB|PARODD|CSIZE, 91 "parity", PARENB|CS7, PARODD|CSIZE, 92 "evenp", PARENB|CS7, PARODD|CSIZE, 93 "oddp", PARENB|PARODD|CS7, CSIZE, 94 "parenb", PARENB, 0, 95 "-parenb", 0, PARENB, 96 "parodd", PARODD, 0, 97 "-parodd", 0, PARODD, 98 "cs8", CS8, CSIZE, 99 "cs7", CS7, CSIZE, 100 "cs6", CS6, CSIZE, 101 "cs5", CS5, CSIZE, 102 "cstopb", CSTOPB, 0, 103 "-cstopb", 0, CSTOPB, 104 "hupcl", HUPCL, 0, 105 "hup", HUPCL, 0, 106 "-hupcl", 0, HUPCL, 107 "-hup", 0, HUPCL, 108 "clocal", CLOCAL, 0, 109 "-clocal", 0, CLOCAL, 110 "loblk", LOBLK, 0, 111 "-loblk", 0, LOBLK, 112 "cread", CREAD, 0, 113 "-cread", 0, CREAD, 114 "crtscts", (long)CRTSCTS, 0, 115 "-crtscts", 0, (long)CRTSCTS, 116 "crtsxoff", CRTSXOFF, 0, 117 "-crtsxoff", 0, CRTSXOFF, 118 "raw", CS8, (CSIZE|PARENB), 119 "-raw", (CS7|PARENB), CSIZE, 120 "cooked", (CS7|PARENB), CSIZE, 121 "sane", (CS7|PARENB|CREAD), (CSIZE|PARODD|CLOCAL), 122 0 123 }; 124 125 const struct mds ncmodes[] = { 126 "parext", PAREXT, 0, 127 "-parext", 0, PAREXT, 128 "markp", (PARENB|PARODD|CS7|PAREXT), CSIZE, 129 "-markp", CS8, (PARENB|PARODD|CSIZE|PAREXT), 130 "spacep", (PARENB|CS7|PAREXT), PARODD|CSIZE, 131 "-spacep", CS8, (PARENB|CSIZE|PAREXT), 132 0 133 }; 134 135 const struct mds imodes[] = { 136 "ignbrk", IGNBRK, 0, 137 "-ignbrk", 0, IGNBRK, 138 "brkint", BRKINT, 0, 139 "-brkint", 0, BRKINT, 140 "ignpar", IGNPAR, 0, 141 "-ignpar", 0, IGNPAR, 142 "parmrk", PARMRK, 0, 143 "-parmrk", 0, PARMRK, 144 "inpck", INPCK, 0, 145 "-inpck", 0, INPCK, 146 "istrip", ISTRIP, 0, 147 "-istrip", 0, ISTRIP, 148 "inlcr", INLCR, 0, 149 "-inlcr", 0, INLCR, 150 "igncr", IGNCR, 0, 151 "-igncr", 0, IGNCR, 152 "icrnl", ICRNL, 0, 153 "-icrnl", 0, ICRNL, 154 #ifdef XPG4 155 "-nl", 0, (ICRNL|INLCR|IGNCR), 156 "nl", ICRNL, 0, 157 #else 158 "-nl", ICRNL, (INLCR|IGNCR), 159 "nl", 0, ICRNL, 160 #endif 161 "iuclc", IUCLC, 0, 162 "-iuclc", 0, IUCLC, 163 "lcase", IUCLC, 0, 164 "-lcase", 0, IUCLC, 165 "LCASE", IUCLC, 0, 166 "-LCASE", 0, IUCLC, 167 "ixon", IXON, 0, 168 "-ixon", 0, IXON, 169 "ixany", IXANY, 0, 170 "-ixany", 0, IXANY, 171 "ixoff", IXOFF, 0, 172 "-ixoff", 0, IXOFF, 173 "raw", 0, -1, 174 "-raw", (BRKINT|IGNPAR|ISTRIP|ICRNL|IXON), 0, 175 "cooked", (BRKINT|IGNPAR|ISTRIP|ICRNL|IXON), 0, 176 "sane", (BRKINT|IGNPAR|ISTRIP|ICRNL|IXON|IMAXBEL), 177 (IGNBRK|PARMRK|INPCK|INLCR|IGNCR|IUCLC|IXOFF|IXANY), 178 0 179 }; 180 181 182 const struct mds nimodes[] = { 183 "imaxbel", IMAXBEL, 0, 184 "-imaxbel", 0, IMAXBEL, 185 0 186 }; 187 188 const struct mds lmodes[] = { 189 "isig", ISIG, 0, 190 "-isig", 0, ISIG, 191 "icanon", ICANON, 0, 192 "-icanon", 0, ICANON, 193 "xcase", XCASE, 0, 194 "-xcase", 0, XCASE, 195 "lcase", XCASE, 0, 196 "-lcase", 0, XCASE, 197 "LCASE", XCASE, 0, 198 "-LCASE", 0, XCASE, 199 "echo", ECHO, 0, 200 "-echo", 0, ECHO, 201 "echoe", ECHOE, 0, 202 "-echoe", 0, ECHOE, 203 "echok", ECHOK, 0, 204 "-echok", 0, ECHOK, 205 "lfkc", ECHOK, 0, 206 "-lfkc", 0, ECHOK, 207 "echonl", ECHONL, 0, 208 "-echonl", 0, ECHONL, 209 "noflsh", NOFLSH, 0, 210 "-noflsh", 0, NOFLSH, 211 "raw", 0, (ISIG|ICANON|XCASE), 212 "-raw", (ISIG|ICANON), 0, 213 "cooked", (ISIG|ICANON), 0, 214 "sane", (ISIG|ICANON|IEXTEN|ECHO|ECHOK|ECHOE|ECHOKE|ECHOCTL), 215 (XCASE|ECHONL|NOFLSH|STFLUSH|STWRAP|STAPPL), 216 "stflush", STFLUSH, 0, 217 "-stflush", 0, STFLUSH, 218 "stwrap", STWRAP, 0, 219 "-stwrap", 0, STWRAP, 220 "stappl", STAPPL, 0, 221 "-stappl", 0, STAPPL, 222 0, 223 }; 224 225 const struct mds nlmodes[] = { 226 "tostop", TOSTOP, 0, 227 "-tostop", 0, TOSTOP, 228 "echoctl", ECHOCTL, 0, 229 "-echoctl", 0, ECHOCTL, 230 "echoprt", ECHOPRT, 0, 231 "-echoprt", 0, ECHOPRT, 232 "echoke", ECHOKE, 0, 233 "-echoke", 0, ECHOKE, 234 "defecho", DEFECHO, 0, 235 "-defecho", 0, DEFECHO, 236 "flusho", FLUSHO, 0, 237 "-flusho", 0, FLUSHO, 238 "pendin", PENDIN, 0, 239 "-pendin", 0, PENDIN, 240 "iexten", IEXTEN, 0, 241 "-iexten", 0, IEXTEN, 242 0 243 }; 244 245 const struct mds omodes[] = { 246 "opost", OPOST, 0, 247 "-opost", 0, OPOST, 248 "olcuc", OLCUC, 0, 249 "-olcuc", 0, OLCUC, 250 "lcase", OLCUC, 0, 251 "-lcase", 0, OLCUC, 252 "LCASE", OLCUC, 0, 253 "-LCASE", 0, OLCUC, 254 "onlcr", ONLCR, 0, 255 "-onlcr", 0, ONLCR, 256 "-nl", ONLCR, (OCRNL|ONLRET), 257 "nl", 0, ONLCR, 258 "ocrnl", OCRNL, 0, 259 "-ocrnl", 0, OCRNL, 260 "onocr", ONOCR, 0, 261 "-onocr", 0, ONOCR, 262 "onlret", ONLRET, 0, 263 "-onlret", 0, ONLRET, 264 "fill", OFILL, OFDEL, 265 "-fill", 0, OFILL|OFDEL, 266 "nul-fill", OFILL, OFDEL, 267 "del-fill", OFILL|OFDEL, 0, 268 "ofill", OFILL, 0, 269 "-ofill", 0, OFILL, 270 "ofdel", OFDEL, 0, 271 "-ofdel", 0, OFDEL, 272 "cr0", CR0, CRDLY, 273 "cr1", CR1, CRDLY, 274 "cr2", CR2, CRDLY, 275 "cr3", CR3, CRDLY, 276 "tab0", TAB0, TABDLY, 277 "tabs", TAB0, TABDLY, 278 "tab1", TAB1, TABDLY, 279 "tab2", TAB2, TABDLY, 280 "tab3", TAB3, TABDLY, 281 "-tabs", TAB3, TABDLY, 282 "tab8", TAB3, TABDLY, 283 "nl0", NL0, NLDLY, 284 "nl1", NL1, NLDLY, 285 "ff0", FF0, FFDLY, 286 "ff1", FF1, FFDLY, 287 "vt0", VT0, VTDLY, 288 "vt1", VT1, VTDLY, 289 "bs0", BS0, BSDLY, 290 "bs1", BS1, BSDLY, 291 "raw", 0, OPOST, 292 "-raw", OPOST, 0, 293 "cooked", OPOST, 0, 294 "tty33", CR1, (CRDLY|TABDLY|NLDLY|FFDLY|VTDLY|BSDLY), 295 "tn300", CR1, (CRDLY|TABDLY|NLDLY|FFDLY|VTDLY|BSDLY), 296 "ti700", CR2, (CRDLY|TABDLY|NLDLY|FFDLY|VTDLY|BSDLY), 297 "vt05", NL1, (CRDLY|TABDLY|NLDLY|FFDLY|VTDLY|BSDLY), 298 "tek", FF1, (CRDLY|TABDLY|NLDLY|FFDLY|VTDLY|BSDLY), 299 "tty37", (FF1|VT1|CR2|TAB1|NL1), (NLDLY|CRDLY|TABDLY|BSDLY|VTDLY|FFDLY), 300 "sane", (OPOST|ONLCR), (OLCUC|OCRNL|ONOCR|ONLRET|OFILL|OFDEL| 301 NLDLY|CRDLY|TABDLY|BSDLY|VTDLY|FFDLY), 302 0, 303 }; 304 305 const struct mds hmodes[] = { 306 "-rtsxoff", 0, RTSXOFF, 307 "rtsxoff", RTSXOFF, 0, 308 "-ctsxon", 0, CTSXON, 309 "ctsxon", CTSXON, 0, 310 "-dtrxoff", 0, DTRXOFF, 311 "dtrxoff", DTRXOFF, 0, 312 "-cdxon", 0, CDXON, 313 "cdxon", CDXON, 0, 314 "-isxoff", 0, ISXOFF, 315 "isxoff", ISXOFF, 0, 316 0, 317 }; 318 319 const struct mds clkmodes[] = { 320 "xcibrg", XCIBRG, XMTCLK, 321 "xctset", XCTSET, XMTCLK, 322 "xcrset", XCRSET, XMTCLK, 323 "rcibrg", RCIBRG, RCVCLK, 324 "rctset", RCTSET, RCVCLK, 325 "rcrset", RCRSET, RCVCLK, 326 "tsetcoff", TSETCOFF, TSETCLK, 327 "tsetcrbrg", TSETCRBRG, TSETCLK, 328 "tsetctbrg", TSETCTBRG, TSETCLK, 329 "tsetctset", TSETCTSET, TSETCLK, 330 "tsetcrset", TSETCRSET, TSETCLK, 331 "rsetcoff", RSETCOFF, RSETCLK, 332 "rsetcrbrg", RSETCRBRG, RSETCLK, 333 "rsetctbrg", RSETCTBRG, RSETCLK, 334 "rsetctset", RSETCTSET, RSETCLK, 335 "rsetcrset", RSETCRSET, RSETCLK, 336 "async", XCIBRG|RCIBRG|TSETCOFF|RSETCOFF, XMTCLK|RCVCLK|TSETCLK|RSETCLK, 337 0, 338 }; 339 340 const char *not_supported[] = { 341 "rtsxoff", 342 "ctsxon", 343 "dtrxoff", 344 "cdxon", 345 "isxoff", 346 "xcibrg", 347 "xctset", 348 "scrset", 349 "rcibrg", 350 "rctset", 351 "rcrset", 352 "tsetcoff", 353 "tsetcrbrg", 354 "rsetcbrg", 355 "rsetctbrg", 356 "rsetctset", 357 "rsetcrset", 358 0, 359 }; 360