xref: /csrg-svn/usr.bin/tip/aculib/biz22.c (revision 13277)
1*13277Ssam #ifndef lint
2*13277Ssam static char sccsid[] = "@(#)biz22.c	4.3 (Berkeley) 06/25/83";
3*13277Ssam #endif
4*13277Ssam 
55130Ssam #include "tip.h"
65130Ssam 
75130Ssam #if BIZ1022
8*13277Ssam #define DISCONNECT_CMD	"\20\04"	/* disconnection string */
95130Ssam 
10*13277Ssam static	int sigALRM();
11*13277Ssam static	int timeout = 0;
12*13277Ssam static	jmp_buf timeoutbuf;
135130Ssam 
145130Ssam /*
155130Ssam  * Dial up on a BIZCOMP Model 1022 with either
165130Ssam  * 	tone dialing (mod = "V")
175130Ssam  *	pulse dialing (mod = "W")
185130Ssam  */
195130Ssam static int
205130Ssam biz_dialer(num, mod)
215130Ssam 	char *num, *mod;
225130Ssam {
235130Ssam 	register int connected = 0;
245130Ssam 	char cbuf[40];
255130Ssam 
265130Ssam 	if (boolean(value(VERBOSE)))
275130Ssam 		printf("\nstarting call...");
285130Ssam 	/*
295130Ssam 	 * Disable auto-answer and configure for tone/pulse
305130Ssam 	 *  dialing
315130Ssam 	 */
325130Ssam 	if (cmd("\02K\r")) {
335130Ssam 		printf("can't initialize bizcomp...");
345130Ssam 		return (0);
355130Ssam 	}
365130Ssam 	strcpy(cbuf, "\02.\r");
375130Ssam 	cbuf[1] = *mod;
385130Ssam 	if (cmd(cbuf)) {
395130Ssam 		printf("can't set dialing mode...");
405130Ssam 		return (0);
415130Ssam 	}
425130Ssam 	strcpy(cbuf, "\02D");
435130Ssam 	strcat(cbuf, num);
445130Ssam 	strcat(cbuf, "\r");
455130Ssam 	write(FD, cbuf, strlen(cbuf));
465130Ssam 	if (!detect("7\r")) {
475130Ssam 		printf("can't get dial tone...");
485130Ssam 		return (0);
495130Ssam 	}
505130Ssam 	if (boolean(value(VERBOSE)))
515130Ssam 		printf("ringing...");
525130Ssam 	/*
535130Ssam 	 * The reply from the BIZCOMP should be:
545130Ssam 	 *	2 \r or 7 \r	failure
555130Ssam 	 *	1 \r		success
565130Ssam 	 */
575130Ssam 	connected = detect("1\r");
585130Ssam #ifdef ACULOG
595130Ssam 	if (timeout) {
605130Ssam 		char line[80];
615130Ssam 
625130Ssam 		sprintf(line, "%d second dial timeout",
635130Ssam 			number(value(DIALTIMEOUT)));
645130Ssam 		logent(value(HOST), num, "biz1022", line);
655130Ssam 	}
665130Ssam #endif
675130Ssam 	if (timeout)
685130Ssam 		biz22_disconnect();	/* insurance */
695130Ssam 	return (connected);
705130Ssam }
715130Ssam 
725130Ssam biz22w_dialer(num, acu)
735130Ssam 	char *num, *acu;
745130Ssam {
75*13277Ssam 
765130Ssam 	return (biz_dialer(num, "W"));
775130Ssam }
785130Ssam 
795130Ssam biz22f_dialer(num, acu)
805130Ssam 	char *num, *acu;
815130Ssam {
82*13277Ssam 
835130Ssam 	return (biz_dialer(num, "V"));
845130Ssam }
855130Ssam 
865130Ssam biz22_disconnect()
875130Ssam {
88*13277Ssam 	int rw = 2;
89*13277Ssam 
90*13277Ssam 	write(FD, DISCONNECT_CMD, 4);
915130Ssam 	sleep(2);
92*13277Ssam 	ioctl(FD, TIOCFLUSH, &rw);
935130Ssam }
945130Ssam 
955130Ssam biz22_abort()
965130Ssam {
97*13277Ssam 
985130Ssam 	write(FD, "\02", 1);
995130Ssam }
1005130Ssam 
1015130Ssam static int
1025130Ssam sigALRM()
1035130Ssam {
104*13277Ssam 
1055130Ssam 	timeout = 1;
106*13277Ssam 	longjmp(timeoutbuf, 1);
1075130Ssam }
1085130Ssam 
1095130Ssam static int
1105130Ssam cmd(s)
1115130Ssam 	register char *s;
1125130Ssam {
1135130Ssam 	char c;
114*13277Ssam 	int (*f)();
1155130Ssam 
1165130Ssam 	write(FD, s, strlen(s));
117*13277Ssam 	f = signal(SIGALRM, sigALRM);
118*13277Ssam 	if (setjmp(timeoutbuf)) {
119*13277Ssam 		biz22_abort();
120*13277Ssam 		signal(SIGALRM, f);
121*13277Ssam 		return (1);
122*13277Ssam 	}
1235130Ssam 	alarm(number(value(DIALTIMEOUT)));
1245130Ssam 	read(FD, &c, 1);
1255130Ssam 	alarm(0);
126*13277Ssam 	signal(SIGALRM, f);
1275130Ssam 	c &= 0177;
1285130Ssam 	return (c != '\r');
1295130Ssam }
1305130Ssam 
1315130Ssam static int
1325130Ssam detect(s)
1335130Ssam 	register char *s;
1345130Ssam {
1355130Ssam 	char c;
136*13277Ssam 	int (*f)();
1375130Ssam 
138*13277Ssam 	f = signal(SIGALRM, sigALRM);
1395130Ssam 	timeout = 0;
1405130Ssam 	while (*s) {
141*13277Ssam 		if (setjmp(timeoutbuf)) {
142*13277Ssam 			biz22_abort();
143*13277Ssam 			break;
144*13277Ssam 		}
1455130Ssam 		alarm(number(value(DIALTIMEOUT)));
1465130Ssam 		read(FD, &c, 1);
1475130Ssam 		alarm(0);
1485130Ssam 		c &= 0177;
1495130Ssam 		if (c != *s++)
1505130Ssam 			return (0);
1515130Ssam 	}
152*13277Ssam 	signal(SIGALRM, f);
153*13277Ssam 	return (timeout == 0);
1545130Ssam }
15513135Sralph #endif
156