1*13280Ssam #ifndef lint 2*13280Ssam static char sccsid[] = "@(#)v831.c 4.4 (Berkeley) 06/25/83"; 3*13280Ssam #endif 413130Sralph 513153Sralph #ifdef V831 613130Sralph /* 713130Sralph * Routines for dialing up on Vadic 831 813130Sralph */ 913153Sralph #include <sys/time.h> 1013153Sralph 1113153Sralph #include "tip.h" 1213130Sralph 1313153Sralph int v831_abort(); 1413186Ssam static int alarmtr(); 1513153Sralph extern errno; 1613130Sralph 1713130Sralph static jmp_buf jmpbuf; 1813130Sralph static int child = -1; 1913130Sralph 2013130Sralph v831_dialer(num, acu) 2113153Sralph char *num, *acu; 2213130Sralph { 2313153Sralph int status, pid, connected = 1; 2413153Sralph register int timelim; 2513130Sralph 2613153Sralph if (boolean(value(VERBOSE))) 2713153Sralph printf("\nstarting call..."); 2813130Sralph #ifdef DEBUG 2913153Sralph printf ("(acu=%s)\n", acu); 3013130Sralph #endif 3113186Ssam if ((AC = open(acu, O_RDWR)) < 0) { 3213153Sralph if (errno == EBUSY) 3313153Sralph printf("line busy..."); 3413153Sralph else 3513153Sralph printf("acu open error..."); 3613153Sralph return (0); 3713153Sralph } 3813153Sralph if (setjmp(jmpbuf)) { 3913153Sralph kill(child, SIGKILL); 4013153Sralph close(AC); 4113153Sralph return (0); 4213153Sralph } 4313153Sralph signal(SIGALRM, alarmtr); 4413153Sralph timelim = 5 * strlen(num); 4513153Sralph alarm(timelim < 30 ? 30 : timelim); 4613153Sralph if ((child = fork()) == 0) { 4713153Sralph /* 4813153Sralph * ignore this stuff for aborts 4913153Sralph */ 5013153Sralph signal(SIGALRM, SIG_IGN); 5113130Sralph signal(SIGINT, SIG_IGN); 5213153Sralph signal(SIGQUIT, SIG_IGN); 5313153Sralph sleep(2); 5413153Sralph exit(dialit(num, acu) != 'A'); 5513153Sralph } 5613153Sralph /* 5713153Sralph * open line - will return on carrier 5813153Sralph */ 5913186Ssam if ((FD = open(DV, O_RDWR)) < 0) { 6013130Sralph #ifdef DEBUG 6113153Sralph printf("(after open, errno=%d)\n", errno); 6213130Sralph #endif 6313153Sralph if (errno == EIO) 6413153Sralph printf("lost carrier..."); 6513153Sralph else 6613153Sralph printf("dialup line open failed..."); 6713153Sralph alarm(0); 6813153Sralph kill(child, SIGKILL); 6913153Sralph close(AC); 7013153Sralph return (0); 7113153Sralph } 7213153Sralph alarm(0); 7313153Sralph #ifdef notdef 7413153Sralph ioctl(AC, TIOCHPCL, 0); 7513153Sralph #endif 7613153Sralph signal(SIGALRM, SIG_DFL); 7713153Sralph while ((pid = wait(&status)) != child && pid != -1) 7813153Sralph ; 7913153Sralph if (status) { 8013153Sralph close(AC); 8113153Sralph return (0); 8213153Sralph } 8313153Sralph return (1); 8413130Sralph } 8513130Sralph 8613186Ssam static 8713130Sralph alarmtr() 8813130Sralph { 8913186Ssam 9013153Sralph alarm(0); 9113153Sralph longjmp(jmpbuf, 1); 9213130Sralph } 9313130Sralph 9413130Sralph /* 9513130Sralph * Insurance, for some reason we don't seem to be 9613130Sralph * hanging up... 9713130Sralph */ 9813130Sralph v831_disconnect() 9913130Sralph { 10013153Sralph struct sgttyb cntrl; 10113153Sralph 10213153Sralph sleep(2); 10313130Sralph #ifdef DEBUG 10413153Sralph printf("[disconnect: FD=%d]\n", FD); 10513130Sralph #endif 10613153Sralph if (FD > 0) { 10713153Sralph ioctl(FD, TIOCCDTR, 0); 10813153Sralph ioctl(FD, TIOCGETP, &cntrl); 10913153Sralph cntrl.sg_ispeed = cntrl.sg_ospeed = 0; 11013153Sralph ioctl(FD, TIOCSETP, &cntrl); 11113153Sralph ioctl(FD, TIOCNXCL, (struct sgttyb *)NULL); 11213153Sralph } 11313153Sralph close(FD); 11413130Sralph } 11513130Sralph 11613130Sralph v831_abort() 11713130Sralph { 11813186Ssam 11913130Sralph #ifdef DEBUG 12013153Sralph printf("[abort: AC=%d]\n", AC); 12113130Sralph #endif 12213153Sralph sleep(2); 12313153Sralph if (child > 0) 12413153Sralph kill(child, SIGKILL); 12513153Sralph if (AC > 0) 12613153Sralph ioctl(FD, TIOCNXCL, (struct sgttyb *)NULL); 12713153Sralph close(AC); 12813153Sralph if (FD > 0) 12913153Sralph ioctl(FD, TIOCCDTR, 0); 13013153Sralph close(FD); 13113130Sralph } 13213130Sralph #endif 13313130Sralph 13413153Sralph /* 13513153Sralph * Sigh, this probably must be changed at each site. 13613153Sralph */ 13713153Sralph struct vaconfig { 13813153Sralph char *vc_name; 13913153Sralph char vc_rack; 14013153Sralph char vc_modem; 14113153Sralph } vaconfig[] = { 14213153Sralph { "/dev/cua0",'4','0' }, 14313153Sralph { "/dev/cua1",'4','1' }, 14413153Sralph { 0 } 14513153Sralph }; 14613153Sralph 14713153Sralph #define pc(x) (c = x, write(AC,&c,1)) 14813153Sralph #define ABORT 01 14913153Sralph #define SI 017 15013153Sralph #define STX 02 15113153Sralph #define ETX 03 15213153Sralph 15313186Ssam static 15413153Sralph dialit(phonenum, acu) 15513153Sralph register char *phonenum; 15613153Sralph char *acu; 15713130Sralph { 15813153Sralph register struct vaconfig *vp; 15913153Sralph struct sgttyb cntrl; 16013153Sralph char c, *sanitize(); 16113153Sralph int i, two = 2; 16213130Sralph 16313153Sralph phonenum = sanitize(phonenum); 16413130Sralph #ifdef DEBUG 16513153Sralph printf ("(dial phonenum=%s)\n", phonenum); 16613130Sralph #endif 16713153Sralph if (*phonenum == '<' && phonenum[1] == 0) 16813153Sralph return ('Z'); 16913153Sralph for (vp = vaconfig; vp->vc_name; vp++) 17013153Sralph if (strcmp(vp->vc_name, acu) == 0) 17113153Sralph break; 17213153Sralph if (vp->vc_name == 0) { 17313130Sralph printf("Unable to locate dialer (%s)\n", acu); 17413153Sralph return ('K'); 17513130Sralph } 17613153Sralph ioctl(AC, TIOCGETP, &cntrl); 17713153Sralph cntrl.sg_ispeed = cntrl.sg_ospeed = B2400; 17813153Sralph cntrl.sg_flags = RAW | EVENP | ODDP; 17913153Sralph ioctl(AC, TIOCSETP, &cntrl); 18013153Sralph ioctl(AC, TIOCFLUSH, &two); 18113153Sralph pc(STX); 18213153Sralph pc(vp->vc_rack); 18313153Sralph pc(vp->vc_modem); 18413153Sralph while (*phonenum && *phonenum != '<') 18513153Sralph pc(*phonenum++); 18613153Sralph pc(SI); 18713153Sralph pc(ETX); 18813153Sralph sleep(1); 18913153Sralph i = read(AC, &c, 1); 19013130Sralph #ifdef DEBUG 19113153Sralph printf("read %d chars, char=%c, errno %d\n", i, c, errno); 19213130Sralph #endif 19313153Sralph if (i != 1) 19413153Sralph c = 'M'; 19513153Sralph if (c == 'B' || c == 'G') { 19613153Sralph char cc, oc = c; 19713130Sralph 19813153Sralph pc(ABORT); 19913153Sralph read(AC, &cc, 1); 20013130Sralph #ifdef DEBUG 20113153Sralph printf("abort response=%c\n", cc); 20213130Sralph #endif 20313153Sralph c = oc; 20413153Sralph v831_disconnect(); 20513153Sralph } 20613153Sralph close(AC); 20713130Sralph #ifdef DEBUG 20813153Sralph printf("dialit: returns %c\n", c); 20913130Sralph #endif 21013153Sralph return (c); 21113130Sralph } 21213153Sralph 21313153Sralph static char * 21413153Sralph sanitize(s) 21513153Sralph register char *s; 21613130Sralph { 21713153Sralph static char buf[128]; 21813153Sralph register char *cp; 21913153Sralph 22013153Sralph for (cp = buf; *s; s++) { 22113153Sralph if (!isdigit(*s) && *s == '<' && *s != '_') 22213153Sralph continue; 22313153Sralph if (*s == '_') 22413153Sralph *s = '='; 22513153Sralph *cp++ = *s; 22613130Sralph } 22713153Sralph *cp++ = 0; 22813153Sralph return (buf); 22913130Sralph } 230