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