Annotation of Net2/kern/tty_compat.c, revision 1.1.1.2

1.1       root        1: /*-
                      2:  * Copyright (c) 1982, 1986, 1991 The Regents of the University of California.
                      3:  * All rights reserved.
                      4:  *
                      5:  * Redistribution and use in source and binary forms, with or without
                      6:  * modification, are permitted provided that the following conditions
                      7:  * are met:
                      8:  * 1. Redistributions of source code must retain the above copyright
                      9:  *    notice, this list of conditions and the following disclaimer.
                     10:  * 2. Redistributions in binary form must reproduce the above copyright
                     11:  *    notice, this list of conditions and the following disclaimer in the
                     12:  *    documentation and/or other materials provided with the distribution.
                     13:  * 3. All advertising materials mentioning features or use of this software
                     14:  *    must display the following acknowledgement:
                     15:  *     This product includes software developed by the University of
                     16:  *     California, Berkeley and its contributors.
                     17:  * 4. Neither the name of the University nor the names of its contributors
                     18:  *    may be used to endorse or promote products derived from this software
                     19:  *    without specific prior written permission.
                     20:  *
                     21:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     22:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     23:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     24:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     25:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     26:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     27:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     28:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     29:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     30:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     31:  * SUCH DAMAGE.
                     32:  *
1.1.1.2 ! root       33:  *     from: @(#)tty_compat.c  7.10 (Berkeley) 5/9/91
        !            34:  *     tty_compat.c,v 1.6 1993/06/27 06:01:57 andrew Exp
1.1       root       35:  */
                     36: 
                     37: /* 
                     38:  * mapping routines for old line discipline (yuck)
                     39:  */
                     40: #ifdef COMPAT_43
                     41: 
                     42: #include "param.h"
                     43: #include "systm.h"
                     44: #include "ioctl.h"
                     45: #include "tty.h"
                     46: #include "termios.h"
                     47: #include "proc.h"
                     48: #include "file.h"
                     49: #include "conf.h"
                     50: #include "dkstat.h"
                     51: #include "kernel.h"
                     52: #include "syslog.h"
                     53: 
                     54: int ttydebug = 0;
                     55: 
                     56: static struct speedtab compatspeeds[] = {
1.1.1.2 ! root       57: #define MAX_SPEED      17
        !            58:        115200, 17,
        !            59:        57600,  16,
1.1       root       60:        38400,  15,
                     61:        19200,  14,
                     62:        9600,   13,
                     63:        4800,   12,
                     64:        2400,   11,
                     65:        1800,   10,
                     66:        1200,   9,
                     67:        600,    8,
                     68:        300,    7,
                     69:        200,    6,
                     70:        150,    5,
                     71:        134,    4,
                     72:        110,    3,
                     73:        75,     2,
                     74:        50,     1,
                     75:        0,      0,
                     76:        -1,     -1,
                     77: };
1.1.1.2 ! root       78: static int compatspcodes[] = { 
1.1       root       79:        0, 50, 75, 110, 134, 150, 200, 300, 600, 1200,
1.1.1.2 ! root       80:        1800, 2400, 4800, 9600, 19200, 38400, 57600, 115200
1.1       root       81: };
                     82: 
1.1.1.2 ! root       83: int ttcompatgetflags __P((struct tty *tp));
        !            84: void ttcompatsetflags __P((struct tty *tp, struct termios *t));
        !            85: void ttcompatsetlflags __P((struct tty *tp, struct termios *t));
        !            86: 
1.1       root       87: /*ARGSUSED*/
1.1.1.2 ! root       88: int
1.1       root       89: ttcompat(tp, com, data, flag)
                     90:        register struct tty *tp;
1.1.1.2 ! root       91:        int com, flag;
1.1       root       92:        caddr_t data;
                     93: {
                     94: 
                     95:        switch (com) {
                     96:        case TIOCGETP: {
                     97:                register struct sgttyb *sg = (struct sgttyb *)data;
                     98:                register u_char *cc = tp->t_cc;
                     99:                register speed;
                    100: 
                    101:                speed = ttspeedtab(tp->t_ospeed, compatspeeds);
1.1.1.2 ! root      102:                sg->sg_ospeed = (speed == -1) ? MAX_SPEED : speed;
1.1       root      103:                if (tp->t_ispeed == 0)
                    104:                        sg->sg_ispeed = sg->sg_ospeed;
                    105:                else {
                    106:                        speed = ttspeedtab(tp->t_ispeed, compatspeeds);
1.1.1.2 ! root      107:                        sg->sg_ispeed = (speed == -1) ? MAX_SPEED : speed;
1.1       root      108:                }
                    109:                sg->sg_erase = cc[VERASE];
                    110:                sg->sg_kill = cc[VKILL];
1.1.1.2 ! root      111:                sg->sg_flags = tp->t_flags = ttcompatgetflags(tp);
1.1       root      112:                break;
                    113:        }
                    114: 
                    115:        case TIOCSETP:
                    116:        case TIOCSETN: {
                    117:                register struct sgttyb *sg = (struct sgttyb *)data;
                    118:                struct termios term;
                    119:                int speed;
                    120: 
                    121:                term = tp->t_termios;
1.1.1.2 ! root      122:                if ((speed = sg->sg_ispeed) > MAX_SPEED || speed < 0)
1.1       root      123:                        term.c_ispeed = speed;
                    124:                else
                    125:                        term.c_ispeed = compatspcodes[speed];
1.1.1.2 ! root      126:                if ((speed = sg->sg_ospeed) > MAX_SPEED || speed < 0)
1.1       root      127:                        term.c_ospeed = speed;
                    128:                else
                    129:                        term.c_ospeed = compatspcodes[speed];
                    130:                term.c_cc[VERASE] = sg->sg_erase;
                    131:                term.c_cc[VKILL] = sg->sg_kill;
1.1.1.2 ! root      132:                tp->t_flags = ttcompatgetflags(tp)&0xffff0000 | sg->sg_flags&0xffff;
1.1       root      133:                ttcompatsetflags(tp, &term);
                    134:                return (ttioctl(tp, com == TIOCSETP ? TIOCSETAF : TIOCSETA, 
1.1.1.2 ! root      135:                        (caddr_t)&term, flag));
1.1       root      136:        }
                    137: 
                    138:        case TIOCGETC: {
                    139:                struct tchars *tc = (struct tchars *)data;
                    140:                register u_char *cc = tp->t_cc;
                    141: 
                    142:                tc->t_intrc = cc[VINTR];
                    143:                tc->t_quitc = cc[VQUIT];
                    144:                tc->t_startc = cc[VSTART];
                    145:                tc->t_stopc = cc[VSTOP];
                    146:                tc->t_eofc = cc[VEOF];
                    147:                tc->t_brkc = cc[VEOL];
                    148:                break;
                    149:        }
                    150:        case TIOCSETC: {
                    151:                struct tchars *tc = (struct tchars *)data;
                    152:                register u_char *cc = tp->t_cc;
                    153: 
                    154:                cc[VINTR] = tc->t_intrc;
                    155:                cc[VQUIT] = tc->t_quitc;
                    156:                cc[VSTART] = tc->t_startc;
                    157:                cc[VSTOP] = tc->t_stopc;
                    158:                cc[VEOF] = tc->t_eofc;
                    159:                cc[VEOL] = tc->t_brkc;
                    160:                if (tc->t_brkc == -1)
                    161:                        cc[VEOL2] = _POSIX_VDISABLE;
                    162:                break;
                    163:        }
                    164:        case TIOCSLTC: {
                    165:                struct ltchars *ltc = (struct ltchars *)data;
                    166:                register u_char *cc = tp->t_cc;
                    167: 
                    168:                cc[VSUSP] = ltc->t_suspc;
                    169:                cc[VDSUSP] = ltc->t_dsuspc;
                    170:                cc[VREPRINT] = ltc->t_rprntc;
                    171:                cc[VDISCARD] = ltc->t_flushc;
                    172:                cc[VWERASE] = ltc->t_werasc;
                    173:                cc[VLNEXT] = ltc->t_lnextc;
                    174:                break;
                    175:        }
                    176:        case TIOCGLTC: {
                    177:                struct ltchars *ltc = (struct ltchars *)data;
                    178:                register u_char *cc = tp->t_cc;
                    179: 
                    180:                ltc->t_suspc = cc[VSUSP];
                    181:                ltc->t_dsuspc = cc[VDSUSP];
                    182:                ltc->t_rprntc = cc[VREPRINT];
                    183:                ltc->t_flushc = cc[VDISCARD];
                    184:                ltc->t_werasc = cc[VWERASE];
                    185:                ltc->t_lnextc = cc[VLNEXT];
                    186:                break;
                    187:        }
                    188:        case TIOCLBIS:
                    189:        case TIOCLBIC:
                    190:        case TIOCLSET: {
                    191:                struct termios term;
                    192: 
                    193:                term = tp->t_termios;
                    194:                if (com == TIOCLSET)
1.1.1.2 ! root      195:                        tp->t_flags = (ttcompatgetflags(tp)&0xffff) | *(int *)data<<16;
1.1       root      196:                else {
1.1.1.2 ! root      197:                        tp->t_flags = ttcompatgetflags(tp);
1.1       root      198:                        if (com == TIOCLBIS)
                    199:                                tp->t_flags |= *(int *)data<<16;
                    200:                        else
                    201:                                tp->t_flags &= ~(*(int *)data<<16);
                    202:                }
                    203:                ttcompatsetlflags(tp, &term);
1.1.1.2 ! root      204:                return (ttioctl(tp, TIOCSETA, (caddr_t)&term, flag));
1.1       root      205:        }
                    206:        case TIOCLGET:
1.1.1.2 ! root      207:                tp->t_flags =
        !           208:                 (ttcompatgetflags(tp)&0xffff0000)|(tp->t_flags&0xffff);
        !           209:                *(int *)data = tp->t_flags>>16;
1.1       root      210:                if (ttydebug)
                    211:                        printf("CLGET: returning %x\n", *(int *)data);
                    212:                break;
                    213: 
                    214:        case OTIOCGETD:
                    215:                *(int *)data = tp->t_line ? tp->t_line : 2;
                    216:                break;
                    217: 
                    218:        case OTIOCSETD: {
                    219:                int ldisczero = 0;
                    220: 
                    221:                return (ttioctl(tp, TIOCSETD, 
                    222:                        *(int *)data == 2 ? (caddr_t)&ldisczero : data, flag));
                    223:            }
                    224: 
                    225:        case OTIOCCONS:
                    226:                *(int *)data = 1;
                    227:                return (ttioctl(tp, TIOCCONS, data, flag));
                    228: 
                    229:        default:
                    230:                return (-1);
                    231:        }
                    232:        return (0);
                    233: }
                    234: 
1.1.1.2 ! root      235: int
1.1       root      236: ttcompatgetflags(tp)
                    237:        register struct tty *tp;
                    238: {
                    239:        register long iflag = tp->t_iflag;
                    240:        register long lflag = tp->t_lflag;
                    241:        register long oflag = tp->t_oflag;
                    242:        register long cflag = tp->t_cflag;
                    243:        register flags = 0;
                    244: 
                    245:        if (iflag&IXOFF)
                    246:                flags |= TANDEM;
                    247:        if (iflag&ICRNL || oflag&ONLCR)
                    248:                flags |= CRMOD;
1.1.1.2 ! root      249:        if ((cflag&CSIZE) == CS8) {
        !           250:                flags |= PASS8;
        !           251:                if (iflag&ISTRIP)
        !           252:                        flags |= ANYP;
        !           253:        }
        !           254:        else if (cflag&PARENB) {
1.1       root      255:                if (iflag&INPCK) {
                    256:                        if (cflag&PARODD)
                    257:                                flags |= ODDP;
                    258:                        else
                    259:                                flags |= EVENP;
                    260:                } else
                    261:                        flags |= EVENP | ODDP;
                    262:        }
1.1.1.2 ! root      263: 
1.1       root      264:        if ((lflag&ICANON) == 0) {      
                    265:                /* fudge */
1.1.1.2 ! root      266:                if (oflag&OPOST || iflag&ISTRIP || iflag&IXON || lflag&ISIG || lflag&IEXTEN || cflag&PARENB || iflag&INPCK || (cflag&CSIZE) != CS8)
1.1       root      267:                        flags |= CBREAK;
                    268:                else
                    269:                        flags |= RAW;
                    270:        }
1.1.1.2 ! root      271:        if (!(flags&RAW) && !(oflag&OPOST) && (!(cflag&PARENB) || (cflag&CSIZE) == CS8))
        !           272:                flags |= LITOUT;
1.1       root      273:        if (oflag&OXTABS)
                    274:                flags |= XTABS;
                    275:        if (lflag&ECHOE)
                    276:                flags |= CRTERA|CRTBS;
                    277:        if (lflag&ECHOKE)
                    278:                flags |= CRTKIL|CRTBS;
                    279:        if (lflag&ECHOPRT)
                    280:                flags |= PRTERA;
                    281:        if (lflag&ECHOCTL)
                    282:                flags |= CTLECH;
                    283:        if ((iflag&IXANY) == 0)
                    284:                flags |= DECCTQ;
                    285:        flags |= lflag&(ECHO|MDMBUF|TOSTOP|FLUSHO|NOHANG|PENDIN|NOFLSH);
                    286: if (ttydebug)
                    287:        printf("getflags: %x\n", flags);
                    288:        return (flags);
                    289: }
                    290: 
1.1.1.2 ! root      291: void
1.1       root      292: ttcompatsetflags(tp, t)
                    293:        register struct tty *tp;
                    294:        register struct termios *t;
                    295: {
                    296:        register flags = tp->t_flags;
                    297:        register long iflag = t->c_iflag;
                    298:        register long oflag = t->c_oflag;
                    299:        register long lflag = t->c_lflag;
                    300:        register long cflag = t->c_cflag;
                    301: 
                    302:        if (flags & RAW) {
1.1.1.2 ! root      303:                iflag &= (IXOFF|IXANY);
1.1       root      304:                oflag &= ~OPOST;
                    305:                lflag &= ~(ECHOCTL|ISIG|ICANON|IEXTEN);
                    306:        } else {
                    307:                iflag |= BRKINT|IXON|IMAXBEL;
                    308:                oflag |= OPOST;
                    309:                lflag |= ISIG|IEXTEN|ECHOCTL;   /* XXX was echoctl on ? */
                    310:                if (flags & XTABS)
                    311:                        oflag |= OXTABS;
                    312:                else
                    313:                        oflag &= ~OXTABS;
                    314:                if (flags & CBREAK)
                    315:                        lflag &= ~ICANON;
                    316:                else
                    317:                        lflag |= ICANON;
                    318:                if (flags&CRMOD) {
                    319:                        iflag |= ICRNL;
                    320:                        oflag |= ONLCR;
                    321:                } else {
                    322:                        iflag &= ~ICRNL;
                    323:                        oflag &= ~ONLCR;
                    324:                }
                    325:        }
                    326:        if (flags&ECHO)
                    327:                lflag |= ECHO;
                    328:        else
                    329:                lflag &= ~ECHO;
                    330:                
1.1.1.2 ! root      331:        cflag &= ~(CSIZE|PARENB);
1.1       root      332:        if (flags&(RAW|LITOUT|PASS8)) {
                    333:                cflag |= CS8;
1.1.1.2 ! root      334:                if (!(flags&(RAW|PASS8)) || (flags&(RAW|PASS8|ANYP)) == (PASS8|ANYP))
1.1       root      335:                        iflag |= ISTRIP;
                    336:                else
                    337:                        iflag &= ~ISTRIP;
                    338:        } else {
1.1.1.2 ! root      339:                cflag |= CS7;
        !           340:                if ((flags&(EVENP|ODDP)) && (flags&ANYP) != ANYP)
        !           341:                        cflag |= PARENB;
1.1       root      342:                iflag |= ISTRIP;
                    343:        }
                    344:        if ((flags&(EVENP|ODDP)) == EVENP) {
                    345:                iflag |= INPCK;
                    346:                cflag &= ~PARODD;
                    347:        } else if ((flags&(EVENP|ODDP)) == ODDP) {
                    348:                iflag |= INPCK;
                    349:                cflag |= PARODD;
                    350:        } else 
                    351:                iflag &= ~INPCK;
                    352:        if (flags&LITOUT)
                    353:                oflag &= ~OPOST;        /* move earlier ? */
                    354:        if (flags&TANDEM)
                    355:                iflag |= IXOFF;
                    356:        else
                    357:                iflag &= ~IXOFF;
                    358:        t->c_iflag = iflag;
                    359:        t->c_oflag = oflag;
                    360:        t->c_lflag = lflag;
                    361:        t->c_cflag = cflag;
                    362: }
                    363: 
1.1.1.2 ! root      364: void
1.1       root      365: ttcompatsetlflags(tp, t)
                    366:        register struct tty *tp;
                    367:        register struct termios *t;
                    368: {
                    369:        register flags = tp->t_flags;
                    370:        register long iflag = t->c_iflag;
                    371:        register long oflag = t->c_oflag;
                    372:        register long lflag = t->c_lflag;
                    373:        register long cflag = t->c_cflag;
                    374: 
                    375:        if (flags&CRTERA)
                    376:                lflag |= ECHOE;
                    377:        else
                    378:                lflag &= ~ECHOE;
                    379:        if (flags&CRTKIL)
                    380:                lflag |= ECHOKE;
                    381:        else
                    382:                lflag &= ~ECHOKE;
                    383:        if (flags&PRTERA)
                    384:                lflag |= ECHOPRT;
                    385:        else
                    386:                lflag &= ~ECHOPRT;
                    387:        if (flags&CTLECH)
                    388:                lflag |= ECHOCTL;
                    389:        else
                    390:                lflag &= ~ECHOCTL;
                    391:        if ((flags&DECCTQ) == 0)
                    392:                lflag |= IXANY;
                    393:        else
                    394:                lflag &= ~IXANY;
                    395:        lflag &= ~(MDMBUF|TOSTOP|FLUSHO|NOHANG|PENDIN|NOFLSH);
                    396:        lflag |= flags&(MDMBUF|TOSTOP|FLUSHO|NOHANG|PENDIN|NOFLSH);
1.1.1.2 ! root      397:        cflag &= ~(CSIZE|PARENB);
1.1       root      398:        if (flags&(LITOUT|PASS8)) {
                    399:                cflag |= CS8;
1.1.1.2 ! root      400:                if (flags&(LITOUT|RAW))
1.1       root      401:                        oflag &= ~OPOST;
1.1.1.2 ! root      402:                else
        !           403:                        oflag |= OPOST;
        !           404:                if (!(flags&(RAW|PASS8)) || (flags&(RAW|PASS8|ANYP)) == (PASS8|ANYP))
        !           405:                        iflag |= ISTRIP;
        !           406:                else
        !           407:                        iflag &= ~ISTRIP;
1.1       root      408:        } else if ((flags&RAW) == 0) {
1.1.1.2 ! root      409:                cflag |= CS7;
        !           410:                if ((flags&(EVENP|ODDP)) && (flags&ANYP) != ANYP)
        !           411:                        cflag |= PARENB;
        !           412:                oflag |= ISTRIP|OPOST;
1.1       root      413:        }
                    414:        t->c_iflag = iflag;
                    415:        t->c_oflag = oflag;
                    416:        t->c_lflag = lflag;
                    417:        t->c_cflag = cflag;
                    418: }
                    419: #endif /* COMPAT_43 */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.