119817Sdist /* 2*35492Sbostic * Copyright (c) 1983 The Regents of the University of California. 3*35492Sbostic * All rights reserved. 4*35492Sbostic * 5*35492Sbostic * Redistribution and use in source and binary forms are permitted 6*35492Sbostic * provided that the above copyright notice and this paragraph are 7*35492Sbostic * duplicated in all such forms and that any documentation, 8*35492Sbostic * advertising materials, and other materials related to such 9*35492Sbostic * distribution and use acknowledge that the software was developed 10*35492Sbostic * by the University of California, Berkeley. The name of the 11*35492Sbostic * University may not be used to endorse or promote products derived 12*35492Sbostic * from this software without specific prior written permission. 13*35492Sbostic * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 14*35492Sbostic * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 15*35492Sbostic * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 1619817Sdist */ 1719817Sdist 1813280Ssam #ifndef lint 19*35492Sbostic static char sccsid[] = "@(#)v831.c 5.2 (Berkeley) 09/13/88"; 20*35492Sbostic #endif /* not lint */ 2113130Sralph 2213130Sralph /* 2313130Sralph * Routines for dialing up on Vadic 831 2413130Sralph */ 2513153Sralph #include <sys/time.h> 2613153Sralph 2713153Sralph #include "tip.h" 2813130Sralph 2913153Sralph int v831_abort(); 3013186Ssam static int alarmtr(); 3113153Sralph extern errno; 3213130Sralph 3313130Sralph static jmp_buf jmpbuf; 3413130Sralph static int child = -1; 3513130Sralph 3613130Sralph v831_dialer(num, acu) 3713153Sralph char *num, *acu; 3813130Sralph { 3913153Sralph int status, pid, connected = 1; 4013153Sralph register int timelim; 4113130Sralph 4213153Sralph if (boolean(value(VERBOSE))) 4313153Sralph printf("\nstarting call..."); 4413130Sralph #ifdef DEBUG 4513153Sralph printf ("(acu=%s)\n", acu); 4613130Sralph #endif 4713186Ssam if ((AC = open(acu, O_RDWR)) < 0) { 4813153Sralph if (errno == EBUSY) 4913153Sralph printf("line busy..."); 5013153Sralph else 5113153Sralph printf("acu open error..."); 5213153Sralph return (0); 5313153Sralph } 5413153Sralph if (setjmp(jmpbuf)) { 5513153Sralph kill(child, SIGKILL); 5613153Sralph close(AC); 5713153Sralph return (0); 5813153Sralph } 5913153Sralph signal(SIGALRM, alarmtr); 6013153Sralph timelim = 5 * strlen(num); 6113153Sralph alarm(timelim < 30 ? 30 : timelim); 6213153Sralph if ((child = fork()) == 0) { 6313153Sralph /* 6413153Sralph * ignore this stuff for aborts 6513153Sralph */ 6613153Sralph signal(SIGALRM, SIG_IGN); 6713130Sralph signal(SIGINT, SIG_IGN); 6813153Sralph signal(SIGQUIT, SIG_IGN); 6913153Sralph sleep(2); 7013153Sralph exit(dialit(num, acu) != 'A'); 7113153Sralph } 7213153Sralph /* 7313153Sralph * open line - will return on carrier 7413153Sralph */ 7513186Ssam if ((FD = open(DV, O_RDWR)) < 0) { 7613130Sralph #ifdef DEBUG 7713153Sralph printf("(after open, errno=%d)\n", errno); 7813130Sralph #endif 7913153Sralph if (errno == EIO) 8013153Sralph printf("lost carrier..."); 8113153Sralph else 8213153Sralph printf("dialup line open failed..."); 8313153Sralph alarm(0); 8413153Sralph kill(child, SIGKILL); 8513153Sralph close(AC); 8613153Sralph return (0); 8713153Sralph } 8813153Sralph alarm(0); 8913153Sralph #ifdef notdef 9013153Sralph ioctl(AC, TIOCHPCL, 0); 9113153Sralph #endif 9213153Sralph signal(SIGALRM, SIG_DFL); 9313153Sralph while ((pid = wait(&status)) != child && pid != -1) 9413153Sralph ; 9513153Sralph if (status) { 9613153Sralph close(AC); 9713153Sralph return (0); 9813153Sralph } 9913153Sralph return (1); 10013130Sralph } 10113130Sralph 10213186Ssam static 10313130Sralph alarmtr() 10413130Sralph { 10513186Ssam 10613153Sralph alarm(0); 10713153Sralph longjmp(jmpbuf, 1); 10813130Sralph } 10913130Sralph 11013130Sralph /* 11113130Sralph * Insurance, for some reason we don't seem to be 11213130Sralph * hanging up... 11313130Sralph */ 11413130Sralph v831_disconnect() 11513130Sralph { 11613153Sralph struct sgttyb cntrl; 11713153Sralph 11813153Sralph sleep(2); 11913130Sralph #ifdef DEBUG 12013153Sralph printf("[disconnect: FD=%d]\n", FD); 12113130Sralph #endif 12213153Sralph if (FD > 0) { 12313153Sralph ioctl(FD, TIOCCDTR, 0); 12413153Sralph ioctl(FD, TIOCGETP, &cntrl); 12513153Sralph cntrl.sg_ispeed = cntrl.sg_ospeed = 0; 12613153Sralph ioctl(FD, TIOCSETP, &cntrl); 12713153Sralph ioctl(FD, TIOCNXCL, (struct sgttyb *)NULL); 12813153Sralph } 12913153Sralph close(FD); 13013130Sralph } 13113130Sralph 13213130Sralph v831_abort() 13313130Sralph { 13413186Ssam 13513130Sralph #ifdef DEBUG 13613153Sralph printf("[abort: AC=%d]\n", AC); 13713130Sralph #endif 13813153Sralph sleep(2); 13913153Sralph if (child > 0) 14013153Sralph kill(child, SIGKILL); 14113153Sralph if (AC > 0) 14213153Sralph ioctl(FD, TIOCNXCL, (struct sgttyb *)NULL); 14313153Sralph close(AC); 14413153Sralph if (FD > 0) 14513153Sralph ioctl(FD, TIOCCDTR, 0); 14613153Sralph close(FD); 14713130Sralph } 14813130Sralph 14913153Sralph /* 15013153Sralph * Sigh, this probably must be changed at each site. 15113153Sralph */ 15213153Sralph struct vaconfig { 15313153Sralph char *vc_name; 15413153Sralph char vc_rack; 15513153Sralph char vc_modem; 15613153Sralph } vaconfig[] = { 15713153Sralph { "/dev/cua0",'4','0' }, 15813153Sralph { "/dev/cua1",'4','1' }, 15913153Sralph { 0 } 16013153Sralph }; 16113153Sralph 16213153Sralph #define pc(x) (c = x, write(AC,&c,1)) 16313153Sralph #define ABORT 01 16413153Sralph #define SI 017 16513153Sralph #define STX 02 16613153Sralph #define ETX 03 16713153Sralph 16813186Ssam static 16913153Sralph dialit(phonenum, acu) 17013153Sralph register char *phonenum; 17113153Sralph char *acu; 17213130Sralph { 17313153Sralph register struct vaconfig *vp; 17413153Sralph struct sgttyb cntrl; 17513153Sralph char c, *sanitize(); 17613153Sralph int i, two = 2; 17713130Sralph 17813153Sralph phonenum = sanitize(phonenum); 17913130Sralph #ifdef DEBUG 18013153Sralph printf ("(dial phonenum=%s)\n", phonenum); 18113130Sralph #endif 18213153Sralph if (*phonenum == '<' && phonenum[1] == 0) 18313153Sralph return ('Z'); 18413153Sralph for (vp = vaconfig; vp->vc_name; vp++) 18513153Sralph if (strcmp(vp->vc_name, acu) == 0) 18613153Sralph break; 18713153Sralph if (vp->vc_name == 0) { 18813130Sralph printf("Unable to locate dialer (%s)\n", acu); 18913153Sralph return ('K'); 19013130Sralph } 19113153Sralph ioctl(AC, TIOCGETP, &cntrl); 19213153Sralph cntrl.sg_ispeed = cntrl.sg_ospeed = B2400; 19313153Sralph cntrl.sg_flags = RAW | EVENP | ODDP; 19413153Sralph ioctl(AC, TIOCSETP, &cntrl); 19513153Sralph ioctl(AC, TIOCFLUSH, &two); 19613153Sralph pc(STX); 19713153Sralph pc(vp->vc_rack); 19813153Sralph pc(vp->vc_modem); 19913153Sralph while (*phonenum && *phonenum != '<') 20013153Sralph pc(*phonenum++); 20113153Sralph pc(SI); 20213153Sralph pc(ETX); 20313153Sralph sleep(1); 20413153Sralph i = read(AC, &c, 1); 20513130Sralph #ifdef DEBUG 20613153Sralph printf("read %d chars, char=%c, errno %d\n", i, c, errno); 20713130Sralph #endif 20813153Sralph if (i != 1) 20913153Sralph c = 'M'; 21013153Sralph if (c == 'B' || c == 'G') { 21113153Sralph char cc, oc = c; 21213130Sralph 21313153Sralph pc(ABORT); 21413153Sralph read(AC, &cc, 1); 21513130Sralph #ifdef DEBUG 21613153Sralph printf("abort response=%c\n", cc); 21713130Sralph #endif 21813153Sralph c = oc; 21913153Sralph v831_disconnect(); 22013153Sralph } 22113153Sralph close(AC); 22213130Sralph #ifdef DEBUG 22313153Sralph printf("dialit: returns %c\n", c); 22413130Sralph #endif 22513153Sralph return (c); 22613130Sralph } 22713153Sralph 22813153Sralph static char * 22913153Sralph sanitize(s) 23013153Sralph register char *s; 23113130Sralph { 23213153Sralph static char buf[128]; 23313153Sralph register char *cp; 23413153Sralph 23513153Sralph for (cp = buf; *s; s++) { 23613153Sralph if (!isdigit(*s) && *s == '<' && *s != '_') 23713153Sralph continue; 23813153Sralph if (*s == '_') 23913153Sralph *s = '='; 24013153Sralph *cp++ = *s; 24113130Sralph } 24213153Sralph *cp++ = 0; 24313153Sralph return (buf); 24413130Sralph } 245