1*19817Sdist /* 2*19817Sdist * Copyright (c) 1983 Regents of the University of California. 3*19817Sdist * All rights reserved. The Berkeley software License Agreement 4*19817Sdist * specifies the terms and conditions for redistribution. 5*19817Sdist */ 6*19817Sdist 713280Ssam #ifndef lint 8*19817Sdist static char sccsid[] = "@(#)v831.c 5.1 (Berkeley) 04/30/85"; 9*19817Sdist #endif not lint 1013130Sralph 1113130Sralph /* 1213130Sralph * Routines for dialing up on Vadic 831 1313130Sralph */ 1413153Sralph #include <sys/time.h> 1513153Sralph 1613153Sralph #include "tip.h" 1713130Sralph 1813153Sralph int v831_abort(); 1913186Ssam 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 3613186Ssam 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 */ 6413186Ssam 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 9113186Ssam static 9213130Sralph alarmtr() 9313130Sralph { 9413186Ssam 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 DEBUG 10913153Sralph printf("[disconnect: FD=%d]\n", FD); 11013130Sralph #endif 11113153Sralph if (FD > 0) { 11213153Sralph ioctl(FD, TIOCCDTR, 0); 11313153Sralph ioctl(FD, TIOCGETP, &cntrl); 11413153Sralph cntrl.sg_ispeed = cntrl.sg_ospeed = 0; 11513153Sralph ioctl(FD, TIOCSETP, &cntrl); 11613153Sralph ioctl(FD, TIOCNXCL, (struct sgttyb *)NULL); 11713153Sralph } 11813153Sralph close(FD); 11913130Sralph } 12013130Sralph 12113130Sralph v831_abort() 12213130Sralph { 12313186Ssam 12413130Sralph #ifdef DEBUG 12513153Sralph printf("[abort: AC=%d]\n", AC); 12613130Sralph #endif 12713153Sralph sleep(2); 12813153Sralph if (child > 0) 12913153Sralph kill(child, SIGKILL); 13013153Sralph if (AC > 0) 13113153Sralph ioctl(FD, TIOCNXCL, (struct sgttyb *)NULL); 13213153Sralph close(AC); 13313153Sralph if (FD > 0) 13413153Sralph ioctl(FD, TIOCCDTR, 0); 13513153Sralph close(FD); 13613130Sralph } 13713130Sralph 13813153Sralph /* 13913153Sralph * Sigh, this probably must be changed at each site. 14013153Sralph */ 14113153Sralph struct vaconfig { 14213153Sralph char *vc_name; 14313153Sralph char vc_rack; 14413153Sralph char vc_modem; 14513153Sralph } vaconfig[] = { 14613153Sralph { "/dev/cua0",'4','0' }, 14713153Sralph { "/dev/cua1",'4','1' }, 14813153Sralph { 0 } 14913153Sralph }; 15013153Sralph 15113153Sralph #define pc(x) (c = x, write(AC,&c,1)) 15213153Sralph #define ABORT 01 15313153Sralph #define SI 017 15413153Sralph #define STX 02 15513153Sralph #define ETX 03 15613153Sralph 15713186Ssam static 15813153Sralph dialit(phonenum, acu) 15913153Sralph register char *phonenum; 16013153Sralph char *acu; 16113130Sralph { 16213153Sralph register struct vaconfig *vp; 16313153Sralph struct sgttyb cntrl; 16413153Sralph char c, *sanitize(); 16513153Sralph int i, two = 2; 16613130Sralph 16713153Sralph phonenum = sanitize(phonenum); 16813130Sralph #ifdef DEBUG 16913153Sralph printf ("(dial phonenum=%s)\n", phonenum); 17013130Sralph #endif 17113153Sralph if (*phonenum == '<' && phonenum[1] == 0) 17213153Sralph return ('Z'); 17313153Sralph for (vp = vaconfig; vp->vc_name; vp++) 17413153Sralph if (strcmp(vp->vc_name, acu) == 0) 17513153Sralph break; 17613153Sralph if (vp->vc_name == 0) { 17713130Sralph printf("Unable to locate dialer (%s)\n", acu); 17813153Sralph return ('K'); 17913130Sralph } 18013153Sralph ioctl(AC, TIOCGETP, &cntrl); 18113153Sralph cntrl.sg_ispeed = cntrl.sg_ospeed = B2400; 18213153Sralph cntrl.sg_flags = RAW | EVENP | ODDP; 18313153Sralph ioctl(AC, TIOCSETP, &cntrl); 18413153Sralph ioctl(AC, TIOCFLUSH, &two); 18513153Sralph pc(STX); 18613153Sralph pc(vp->vc_rack); 18713153Sralph pc(vp->vc_modem); 18813153Sralph while (*phonenum && *phonenum != '<') 18913153Sralph pc(*phonenum++); 19013153Sralph pc(SI); 19113153Sralph pc(ETX); 19213153Sralph sleep(1); 19313153Sralph i = read(AC, &c, 1); 19413130Sralph #ifdef DEBUG 19513153Sralph printf("read %d chars, char=%c, errno %d\n", i, c, errno); 19613130Sralph #endif 19713153Sralph if (i != 1) 19813153Sralph c = 'M'; 19913153Sralph if (c == 'B' || c == 'G') { 20013153Sralph char cc, oc = c; 20113130Sralph 20213153Sralph pc(ABORT); 20313153Sralph read(AC, &cc, 1); 20413130Sralph #ifdef DEBUG 20513153Sralph printf("abort response=%c\n", cc); 20613130Sralph #endif 20713153Sralph c = oc; 20813153Sralph v831_disconnect(); 20913153Sralph } 21013153Sralph close(AC); 21113130Sralph #ifdef DEBUG 21213153Sralph printf("dialit: returns %c\n", c); 21313130Sralph #endif 21413153Sralph return (c); 21513130Sralph } 21613153Sralph 21713153Sralph static char * 21813153Sralph sanitize(s) 21913153Sralph register char *s; 22013130Sralph { 22113153Sralph static char buf[128]; 22213153Sralph register char *cp; 22313153Sralph 22413153Sralph for (cp = buf; *s; s++) { 22513153Sralph if (!isdigit(*s) && *s == '<' && *s != '_') 22613153Sralph continue; 22713153Sralph if (*s == '_') 22813153Sralph *s = '='; 22913153Sralph *cp++ = *s; 23013130Sralph } 23113153Sralph *cp++ = 0; 23213153Sralph return (buf); 23313130Sralph } 234