Annotation of 43BSDReno/usr.bin/tip/aculib/v831.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 1983 The Regents of the University of California.
                      3:  * All rights reserved.
                      4:  *
                      5:  * Redistribution and use in source and binary forms are permitted
                      6:  * provided that: (1) source distributions retain this entire copyright
                      7:  * notice and comment, and (2) distributions including binaries display
                      8:  * the following acknowledgement:  ``This product includes software
                      9:  * developed by the University of California, Berkeley and its contributors''
                     10:  * in the documentation or other materials provided with the distribution
                     11:  * and in all advertising materials mentioning features or use of this
                     12:  * software. Neither the name of the University nor the names of its
                     13:  * contributors may be used to endorse or promote products derived
                     14:  * from this software without specific prior written permission.
                     15:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
                     16:  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
                     17:  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
                     18:  */
                     19: 
                     20: #ifndef lint
                     21: static char sccsid[] = "@(#)v831.c     5.3 (Berkeley) 6/1/90";
                     22: #endif /* not lint */
                     23: 
                     24: /*
                     25:  * Routines for dialing up on Vadic 831
                     26:  */
                     27: #include <sys/time.h>
                     28: 
                     29: #include "tip.h"
                     30: 
                     31: int    v831_abort();
                     32: static int alarmtr();
                     33: extern errno;
                     34: 
                     35: static jmp_buf jmpbuf;
                     36: static int child = -1;
                     37: 
                     38: v831_dialer(num, acu)
                     39:         char *num, *acu;
                     40: {
                     41:         int status, pid, connected = 1;
                     42:         register int timelim;
                     43: 
                     44:         if (boolean(value(VERBOSE)))
                     45:                 printf("\nstarting call...");
                     46: #ifdef DEBUG
                     47:         printf ("(acu=%s)\n", acu);
                     48: #endif
                     49:         if ((AC = open(acu, O_RDWR)) < 0) {
                     50:                 if (errno == EBUSY)
                     51:                         printf("line busy...");
                     52:                 else
                     53:                         printf("acu open error...");
                     54:                 return (0);
                     55:         }
                     56:         if (setjmp(jmpbuf)) {
                     57:                 kill(child, SIGKILL);
                     58:                 close(AC);
                     59:                 return (0);
                     60:         }
                     61:         signal(SIGALRM, alarmtr);
                     62:         timelim = 5 * strlen(num);
                     63:         alarm(timelim < 30 ? 30 : timelim);
                     64:         if ((child = fork()) == 0) {
                     65:                 /*
                     66:                  * ignore this stuff for aborts
                     67:                  */
                     68:                 signal(SIGALRM, SIG_IGN);
                     69:                signal(SIGINT, SIG_IGN);
                     70:                 signal(SIGQUIT, SIG_IGN);
                     71:                 sleep(2);
                     72:                 exit(dialit(num, acu) != 'A');
                     73:         }
                     74:         /*
                     75:          * open line - will return on carrier
                     76:          */
                     77:         if ((FD = open(DV, O_RDWR)) < 0) {
                     78: #ifdef DEBUG
                     79:                 printf("(after open, errno=%d)\n", errno);
                     80: #endif
                     81:                 if (errno == EIO)
                     82:                         printf("lost carrier...");
                     83:                 else
                     84:                         printf("dialup line open failed...");
                     85:                 alarm(0);
                     86:                 kill(child, SIGKILL);
                     87:                 close(AC);
                     88:                 return (0);
                     89:         }
                     90:         alarm(0);
                     91: #ifdef notdef
                     92:         ioctl(AC, TIOCHPCL, 0);
                     93: #endif
                     94:         signal(SIGALRM, SIG_DFL);
                     95:         while ((pid = wait(&status)) != child && pid != -1)
                     96:                 ;
                     97:         if (status) {
                     98:                 close(AC);
                     99:                 return (0);
                    100:         }
                    101:         return (1);
                    102: }
                    103: 
                    104: static
                    105: alarmtr()
                    106: {
                    107: 
                    108:         alarm(0);
                    109:         longjmp(jmpbuf, 1);
                    110: }
                    111: 
                    112: /*
                    113:  * Insurance, for some reason we don't seem to be
                    114:  *  hanging up...
                    115:  */
                    116: v831_disconnect()
                    117: {
                    118:         struct sgttyb cntrl;
                    119: 
                    120:         sleep(2);
                    121: #ifdef DEBUG
                    122:         printf("[disconnect: FD=%d]\n", FD);
                    123: #endif
                    124:         if (FD > 0) {
                    125:                 ioctl(FD, TIOCCDTR, 0);
                    126:                 ioctl(FD, TIOCGETP, &cntrl);
                    127:                 cntrl.sg_ispeed = cntrl.sg_ospeed = 0;
                    128:                 ioctl(FD, TIOCSETP, &cntrl);
                    129:                 ioctl(FD, TIOCNXCL, (struct sgttyb *)NULL);
                    130:         }
                    131:         close(FD);
                    132: }
                    133: 
                    134: v831_abort()
                    135: {
                    136: 
                    137: #ifdef DEBUG
                    138:         printf("[abort: AC=%d]\n", AC);
                    139: #endif
                    140:         sleep(2);
                    141:         if (child > 0)
                    142:                 kill(child, SIGKILL);
                    143:         if (AC > 0)
                    144:                 ioctl(FD, TIOCNXCL, (struct sgttyb *)NULL);
                    145:                 close(AC);
                    146:         if (FD > 0)
                    147:                 ioctl(FD, TIOCCDTR, 0);
                    148:         close(FD);
                    149: }
                    150: 
                    151: /*
                    152:  * Sigh, this probably must be changed at each site.
                    153:  */
                    154: struct vaconfig {
                    155:        char    *vc_name;
                    156:        char    vc_rack;
                    157:        char    vc_modem;
                    158: } vaconfig[] = {
                    159:        { "/dev/cua0",'4','0' },
                    160:        { "/dev/cua1",'4','1' },
                    161:        { 0 }
                    162: };
                    163: 
                    164: #define pc(x)  (c = x, write(AC,&c,1))
                    165: #define ABORT  01
                    166: #define SI     017
                    167: #define STX    02
                    168: #define ETX    03
                    169: 
                    170: static
                    171: dialit(phonenum, acu)
                    172:        register char *phonenum;
                    173:        char *acu;
                    174: {
                    175:         register struct vaconfig *vp;
                    176:        struct sgttyb cntrl;
                    177:         char c, *sanitize();
                    178:         int i, two = 2;
                    179: 
                    180:         phonenum = sanitize(phonenum);
                    181: #ifdef DEBUG
                    182:         printf ("(dial phonenum=%s)\n", phonenum);
                    183: #endif
                    184:         if (*phonenum == '<' && phonenum[1] == 0)
                    185:                 return ('Z');
                    186:        for (vp = vaconfig; vp->vc_name; vp++)
                    187:                if (strcmp(vp->vc_name, acu) == 0)
                    188:                        break;
                    189:        if (vp->vc_name == 0) {
                    190:                printf("Unable to locate dialer (%s)\n", acu);
                    191:                return ('K');
                    192:        }
                    193:         ioctl(AC, TIOCGETP, &cntrl);
                    194:         cntrl.sg_ispeed = cntrl.sg_ospeed = B2400;
                    195:         cntrl.sg_flags = RAW | EVENP | ODDP;
                    196:         ioctl(AC, TIOCSETP, &cntrl);
                    197:        ioctl(AC, TIOCFLUSH, &two);
                    198:         pc(STX);
                    199:        pc(vp->vc_rack);
                    200:        pc(vp->vc_modem);
                    201:        while (*phonenum && *phonenum != '<')
                    202:                pc(*phonenum++);
                    203:         pc(SI);
                    204:        pc(ETX);
                    205:         sleep(1);
                    206:         i = read(AC, &c, 1);
                    207: #ifdef DEBUG
                    208:         printf("read %d chars, char=%c, errno %d\n", i, c, errno);
                    209: #endif
                    210:         if (i != 1)
                    211:                c = 'M';
                    212:         if (c == 'B' || c == 'G') {
                    213:                 char cc, oc = c;
                    214: 
                    215:                 pc(ABORT);
                    216:                 read(AC, &cc, 1);
                    217: #ifdef DEBUG
                    218:                 printf("abort response=%c\n", cc);
                    219: #endif
                    220:                 c = oc;
                    221:                 v831_disconnect();
                    222:         }
                    223:         close(AC);
                    224: #ifdef DEBUG
                    225:         printf("dialit: returns %c\n", c);
                    226: #endif
                    227:         return (c);
                    228: }
                    229: 
                    230: static char *
                    231: sanitize(s)
                    232:        register char *s;
                    233: {
                    234:         static char buf[128];
                    235:         register char *cp;
                    236: 
                    237:         for (cp = buf; *s; s++) {
                    238:                if (!isdigit(*s) && *s == '<' && *s != '_')
                    239:                        continue;
                    240:                if (*s == '_')
                    241:                        *s = '=';
                    242:                *cp++ = *s;
                    243:        }
                    244:         *cp++ = 0;
                    245:         return (buf);
                    246: }

unix.superglobalmegacorp.com

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