1*13186Ssam /* v831.c 4.3 83/06/18 */ 213130Sralph 313153Sralph #ifdef V831 413130Sralph /* 513130Sralph * Routines for dialing up on Vadic 831 613130Sralph */ 713153Sralph #include <sys/file.h> 813153Sralph #include <sys/time.h> 913153Sralph 1013130Sralph #include <setjmp.h> 1113130Sralph #include <errno.h> 1213130Sralph #include <sgtty.h> 1313130Sralph 1413153Sralph #include "tip.h" 1513130Sralph 16*13186Ssam static char *sccsid = "@(#)v831.c 4.3 06/18/83"; 1713130Sralph 1813153Sralph int v831_abort(); 19*13186Ssam static int alarmtr(); 2013153Sralph extern errno; 2113130Sralph 2213130Sralph static jmp_buf jmpbuf; 2313130Sralph static int child = -1; 2413130Sralph 2513130Sralph v831_dialer(num, acu) 2613153Sralph char *num, *acu; 2713130Sralph { 2813153Sralph int status, pid, connected = 1; 2913153Sralph register int timelim; 3013130Sralph 3113153Sralph if (boolean(value(VERBOSE))) 3213153Sralph printf("\nstarting call..."); 3313130Sralph #ifdef DEBUG 3413153Sralph printf ("(acu=%s)\n", acu); 3513130Sralph #endif 36*13186Ssam if ((AC = open(acu, O_RDWR)) < 0) { 3713153Sralph if (errno == EBUSY) 3813153Sralph printf("line busy..."); 3913153Sralph else 4013153Sralph printf("acu open error..."); 4113153Sralph return (0); 4213153Sralph } 4313153Sralph if (setjmp(jmpbuf)) { 4413153Sralph kill(child, SIGKILL); 4513153Sralph close(AC); 4613153Sralph return (0); 4713153Sralph } 4813153Sralph signal(SIGALRM, alarmtr); 4913153Sralph timelim = 5 * strlen(num); 5013153Sralph alarm(timelim < 30 ? 30 : timelim); 5113153Sralph if ((child = fork()) == 0) { 5213153Sralph /* 5313153Sralph * ignore this stuff for aborts 5413153Sralph */ 5513153Sralph signal(SIGALRM, SIG_IGN); 5613130Sralph signal(SIGINT, SIG_IGN); 5713153Sralph signal(SIGQUIT, SIG_IGN); 5813153Sralph sleep(2); 5913153Sralph exit(dialit(num, acu) != 'A'); 6013153Sralph } 6113153Sralph /* 6213153Sralph * open line - will return on carrier 6313153Sralph */ 64*13186Ssam if ((FD = open(DV, O_RDWR)) < 0) { 6513130Sralph #ifdef DEBUG 6613153Sralph printf("(after open, errno=%d)\n", errno); 6713130Sralph #endif 6813153Sralph if (errno == EIO) 6913153Sralph printf("lost carrier..."); 7013153Sralph else 7113153Sralph printf("dialup line open failed..."); 7213153Sralph alarm(0); 7313153Sralph kill(child, SIGKILL); 7413153Sralph close(AC); 7513153Sralph return (0); 7613153Sralph } 7713153Sralph alarm(0); 7813153Sralph #ifdef notdef 7913153Sralph ioctl(AC, TIOCHPCL, 0); 8013153Sralph #endif 8113153Sralph signal(SIGALRM, SIG_DFL); 8213153Sralph while ((pid = wait(&status)) != child && pid != -1) 8313153Sralph ; 8413153Sralph if (status) { 8513153Sralph close(AC); 8613153Sralph return (0); 8713153Sralph } 8813153Sralph return (1); 8913130Sralph } 9013130Sralph 91*13186Ssam static 9213130Sralph alarmtr() 9313130Sralph { 94*13186Ssam 9513153Sralph alarm(0); 9613153Sralph longjmp(jmpbuf, 1); 9713130Sralph } 9813130Sralph 9913130Sralph /* 10013130Sralph * Insurance, for some reason we don't seem to be 10113130Sralph * hanging up... 10213130Sralph */ 10313130Sralph v831_disconnect() 10413130Sralph { 10513153Sralph struct sgttyb cntrl; 10613153Sralph 10713153Sralph sleep(2); 10813130Sralph #ifdef VMUNIX 10913130Sralph #ifdef DEBUG 11013153Sralph printf("[disconnect: FD=%d]\n", FD); 11113130Sralph #endif 11213153Sralph if (FD > 0) { 11313153Sralph ioctl(FD, TIOCCDTR, 0); 11413153Sralph ioctl(FD, TIOCGETP, &cntrl); 11513153Sralph cntrl.sg_ispeed = cntrl.sg_ospeed = 0; 11613153Sralph ioctl(FD, TIOCSETP, &cntrl); 11713153Sralph ioctl(FD, TIOCNXCL, (struct sgttyb *)NULL); 11813153Sralph } 11913130Sralph #endif 12013153Sralph close(FD); 12113130Sralph } 12213130Sralph 12313130Sralph v831_abort() 12413130Sralph { 125*13186Ssam 12613130Sralph #ifdef DEBUG 12713153Sralph printf("[abort: AC=%d]\n", AC); 12813130Sralph #endif 12913153Sralph sleep(2); 13013153Sralph if (child > 0) 13113153Sralph kill(child, SIGKILL); 13213153Sralph if (AC > 0) 13313153Sralph ioctl(FD, TIOCNXCL, (struct sgttyb *)NULL); 13413153Sralph close(AC); 13513130Sralph #ifdef VMUNIX 13613153Sralph if (FD > 0) 13713153Sralph ioctl(FD, TIOCCDTR, 0); 13813130Sralph #endif 13913153Sralph close(FD); 14013130Sralph } 14113130Sralph #endif 14213130Sralph 14313153Sralph /* 14413153Sralph * Sigh, this probably must be changed at each site. 14513153Sralph */ 14613153Sralph struct vaconfig { 14713153Sralph char *vc_name; 14813153Sralph char vc_rack; 14913153Sralph char vc_modem; 15013153Sralph } vaconfig[] = { 15113153Sralph { "/dev/cua0",'4','0' }, 15213153Sralph { "/dev/cua1",'4','1' }, 15313153Sralph { 0 } 15413153Sralph }; 15513153Sralph 15613153Sralph #define pc(x) (c = x, write(AC,&c,1)) 15713153Sralph #define ABORT 01 15813153Sralph #define SI 017 15913153Sralph #define STX 02 16013153Sralph #define ETX 03 16113153Sralph 162*13186Ssam static 16313153Sralph dialit(phonenum, acu) 16413153Sralph register char *phonenum; 16513153Sralph char *acu; 16613130Sralph { 16713153Sralph register struct vaconfig *vp; 16813153Sralph struct sgttyb cntrl; 16913153Sralph char c, *sanitize(); 17013153Sralph int i, two = 2; 17113130Sralph 17213153Sralph phonenum = sanitize(phonenum); 17313130Sralph #ifdef DEBUG 17413153Sralph printf ("(dial phonenum=%s)\n", phonenum); 17513130Sralph #endif 17613153Sralph if (*phonenum == '<' && phonenum[1] == 0) 17713153Sralph return ('Z'); 17813153Sralph for (vp = vaconfig; vp->vc_name; vp++) 17913153Sralph if (strcmp(vp->vc_name, acu) == 0) 18013153Sralph break; 18113153Sralph if (vp->vc_name == 0) { 18213130Sralph printf("Unable to locate dialer (%s)\n", acu); 18313153Sralph return ('K'); 18413130Sralph } 18513153Sralph ioctl(AC, TIOCGETP, &cntrl); 18613153Sralph cntrl.sg_ispeed = cntrl.sg_ospeed = B2400; 18713153Sralph cntrl.sg_flags = RAW | EVENP | ODDP; 18813153Sralph ioctl(AC, TIOCSETP, &cntrl); 18913153Sralph ioctl(AC, TIOCFLUSH, &two); 19013153Sralph pc(STX); 19113153Sralph pc(vp->vc_rack); 19213153Sralph pc(vp->vc_modem); 19313153Sralph while (*phonenum && *phonenum != '<') 19413153Sralph pc(*phonenum++); 19513153Sralph pc(SI); 19613153Sralph pc(ETX); 19713153Sralph sleep(1); 19813153Sralph i = read(AC, &c, 1); 19913130Sralph #ifdef DEBUG 20013153Sralph printf("read %d chars, char=%c, errno %d\n", i, c, errno); 20113130Sralph #endif 20213153Sralph if (i != 1) 20313153Sralph c = 'M'; 20413153Sralph if (c == 'B' || c == 'G') { 20513153Sralph char cc, oc = c; 20613130Sralph 20713153Sralph pc(ABORT); 20813153Sralph read(AC, &cc, 1); 20913130Sralph #ifdef DEBUG 21013153Sralph printf("abort response=%c\n", cc); 21113130Sralph #endif 21213153Sralph c = oc; 21313153Sralph v831_disconnect(); 21413153Sralph } 21513153Sralph close(AC); 21613130Sralph #ifdef DEBUG 21713153Sralph printf("dialit: returns %c\n", c); 21813130Sralph #endif 21913153Sralph return (c); 22013130Sralph } 22113153Sralph 22213153Sralph static char * 22313153Sralph sanitize(s) 22413153Sralph register char *s; 22513130Sralph { 22613153Sralph static char buf[128]; 22713153Sralph register char *cp; 22813153Sralph 22913153Sralph for (cp = buf; *s; s++) { 23013153Sralph if (!isdigit(*s) && *s == '<' && *s != '_') 23113153Sralph continue; 23213153Sralph if (*s == '_') 23313153Sralph *s = '='; 23413153Sralph *cp++ = *s; 23513130Sralph } 23613153Sralph *cp++ = 0; 23713153Sralph return (buf); 23813130Sralph } 239