xref: /csrg-svn/usr.bin/tip/aculib/biz22.c (revision 22414)
1*22414Sdist /*
2*22414Sdist  * Copyright (c) 1983 Regents of the University of California.
3*22414Sdist  * All rights reserved.  The Berkeley software License Agreement
4*22414Sdist  * specifies the terms and conditions for redistribution.
5*22414Sdist  */
6*22414Sdist 
713277Ssam #ifndef lint
8*22414Sdist static char sccsid[] = "@(#)biz22.c	5.1 (Berkeley) 06/06/85";
9*22414Sdist #endif not lint
1013277Ssam 
115130Ssam #include "tip.h"
125130Ssam 
1313277Ssam #define DISCONNECT_CMD	"\20\04"	/* disconnection string */
145130Ssam 
1513277Ssam static	int sigALRM();
1613277Ssam static	int timeout = 0;
1713277Ssam static	jmp_buf timeoutbuf;
185130Ssam 
195130Ssam /*
205130Ssam  * Dial up on a BIZCOMP Model 1022 with either
215130Ssam  * 	tone dialing (mod = "V")
225130Ssam  *	pulse dialing (mod = "W")
235130Ssam  */
245130Ssam static int
255130Ssam biz_dialer(num, mod)
265130Ssam 	char *num, *mod;
275130Ssam {
285130Ssam 	register int connected = 0;
295130Ssam 	char cbuf[40];
305130Ssam 
315130Ssam 	if (boolean(value(VERBOSE)))
325130Ssam 		printf("\nstarting call...");
335130Ssam 	/*
345130Ssam 	 * Disable auto-answer and configure for tone/pulse
355130Ssam 	 *  dialing
365130Ssam 	 */
375130Ssam 	if (cmd("\02K\r")) {
385130Ssam 		printf("can't initialize bizcomp...");
395130Ssam 		return (0);
405130Ssam 	}
415130Ssam 	strcpy(cbuf, "\02.\r");
425130Ssam 	cbuf[1] = *mod;
435130Ssam 	if (cmd(cbuf)) {
445130Ssam 		printf("can't set dialing mode...");
455130Ssam 		return (0);
465130Ssam 	}
475130Ssam 	strcpy(cbuf, "\02D");
485130Ssam 	strcat(cbuf, num);
495130Ssam 	strcat(cbuf, "\r");
505130Ssam 	write(FD, cbuf, strlen(cbuf));
515130Ssam 	if (!detect("7\r")) {
525130Ssam 		printf("can't get dial tone...");
535130Ssam 		return (0);
545130Ssam 	}
555130Ssam 	if (boolean(value(VERBOSE)))
565130Ssam 		printf("ringing...");
575130Ssam 	/*
585130Ssam 	 * The reply from the BIZCOMP should be:
595130Ssam 	 *	2 \r or 7 \r	failure
605130Ssam 	 *	1 \r		success
615130Ssam 	 */
625130Ssam 	connected = detect("1\r");
635130Ssam #ifdef ACULOG
645130Ssam 	if (timeout) {
655130Ssam 		char line[80];
665130Ssam 
675130Ssam 		sprintf(line, "%d second dial timeout",
685130Ssam 			number(value(DIALTIMEOUT)));
695130Ssam 		logent(value(HOST), num, "biz1022", line);
705130Ssam 	}
715130Ssam #endif
725130Ssam 	if (timeout)
735130Ssam 		biz22_disconnect();	/* insurance */
745130Ssam 	return (connected);
755130Ssam }
765130Ssam 
775130Ssam biz22w_dialer(num, acu)
785130Ssam 	char *num, *acu;
795130Ssam {
8013277Ssam 
815130Ssam 	return (biz_dialer(num, "W"));
825130Ssam }
835130Ssam 
845130Ssam biz22f_dialer(num, acu)
855130Ssam 	char *num, *acu;
865130Ssam {
8713277Ssam 
885130Ssam 	return (biz_dialer(num, "V"));
895130Ssam }
905130Ssam 
915130Ssam biz22_disconnect()
925130Ssam {
9313277Ssam 	int rw = 2;
9413277Ssam 
9513277Ssam 	write(FD, DISCONNECT_CMD, 4);
965130Ssam 	sleep(2);
9713277Ssam 	ioctl(FD, TIOCFLUSH, &rw);
985130Ssam }
995130Ssam 
1005130Ssam biz22_abort()
1015130Ssam {
10213277Ssam 
1035130Ssam 	write(FD, "\02", 1);
1045130Ssam }
1055130Ssam 
1065130Ssam static int
1075130Ssam sigALRM()
1085130Ssam {
10913277Ssam 
1105130Ssam 	timeout = 1;
11113277Ssam 	longjmp(timeoutbuf, 1);
1125130Ssam }
1135130Ssam 
1145130Ssam static int
1155130Ssam cmd(s)
1165130Ssam 	register char *s;
1175130Ssam {
1185130Ssam 	char c;
11913277Ssam 	int (*f)();
1205130Ssam 
1215130Ssam 	write(FD, s, strlen(s));
12213277Ssam 	f = signal(SIGALRM, sigALRM);
12313277Ssam 	if (setjmp(timeoutbuf)) {
12413277Ssam 		biz22_abort();
12513277Ssam 		signal(SIGALRM, f);
12613277Ssam 		return (1);
12713277Ssam 	}
1285130Ssam 	alarm(number(value(DIALTIMEOUT)));
1295130Ssam 	read(FD, &c, 1);
1305130Ssam 	alarm(0);
13113277Ssam 	signal(SIGALRM, f);
1325130Ssam 	c &= 0177;
1335130Ssam 	return (c != '\r');
1345130Ssam }
1355130Ssam 
1365130Ssam static int
1375130Ssam detect(s)
1385130Ssam 	register char *s;
1395130Ssam {
1405130Ssam 	char c;
14113277Ssam 	int (*f)();
1425130Ssam 
14313277Ssam 	f = signal(SIGALRM, sigALRM);
1445130Ssam 	timeout = 0;
1455130Ssam 	while (*s) {
14613277Ssam 		if (setjmp(timeoutbuf)) {
14713277Ssam 			biz22_abort();
14813277Ssam 			break;
14913277Ssam 		}
1505130Ssam 		alarm(number(value(DIALTIMEOUT)));
1515130Ssam 		read(FD, &c, 1);
1525130Ssam 		alarm(0);
1535130Ssam 		c &= 0177;
1545130Ssam 		if (c != *s++)
1555130Ssam 			return (0);
1565130Ssam 	}
15713277Ssam 	signal(SIGALRM, f);
15813277Ssam 	return (timeout == 0);
1595130Ssam }
160