xref: /csrg-svn/usr.bin/tip/aculib/v3451.c (revision 13276)
1*13276Ssam /*	v3451.c	4.2	83/06/24	*/
213131Sralph 
313131Sralph #if VADIC
413131Sralph /*
513131Sralph  * Routines for calling up on a Vadic 3451 Modem
613131Sralph  */
713131Sralph #include "tip.h"
813131Sralph #include <setjmp.h>
913131Sralph #include <errno.h>
1013131Sralph #include <signal.h>
1113131Sralph 
12*13276Ssam static	jmp_buf Sjbuf;
1313131Sralph 
1413131Sralph vadic_dialer(num, acu)
1513131Sralph 	register char *num;
1613131Sralph 	char *acu;
1713131Sralph {
18*13276Ssam 	int ok, (*func)();
19*13276Ssam 	int slow = number(value(BAUDRATE)) < 1200, rw = 2;
2013131Sralph 	char phone[50];
2113131Sralph #ifdef ACULOG
2213131Sralph 	char line[80];
2313131Sralph #endif
2413131Sralph 
2513131Sralph 	/*
2613131Sralph 	 * Get in synch
2713131Sralph 	 */
28*13276Ssam 	vawrite("I\r", 1 + slow);
29*13276Ssam 	vawrite("I\r", 1 + slow);
30*13276Ssam 	vawrite("I\r", 1 + slow);
31*13276Ssam 	vawrite("\005\r", 2 + slow);
32*13276Ssam 	if (!expect("READY")) {
3313131Sralph 		printf("can't synchronize with vadic 3451\n");
3413131Sralph #ifdef ACULOG
3513131Sralph 		logent(value(HOST), num, "vadic", "can't synch up");
3613131Sralph #endif
3713131Sralph 		return (0);
3813131Sralph 	}
3913131Sralph 	ioctl(FD, TIOCHPCL, 0);
4013131Sralph 	sleep(1);
41*13276Ssam 	vawrite("D\r", 2 + slow);
42*13276Ssam 	if (!expect("NUMBER?")) {
4313131Sralph 		printf("Vadic will not accept dial command\n");
4413131Sralph #ifdef ACULOG
4513131Sralph 		logent(value(HOST), num, "vadic", "will not accept dial");
4613131Sralph #endif
4713131Sralph 		return (0);
4813131Sralph 	}
49*13276Ssam 	strcpy(phone, num);
50*13276Ssam 	strcat(phone, "\r");
51*13276Ssam 	vawrite(phone, 1 + slow);
52*13276Ssam 	if (!expect(phone)) {
5313131Sralph 		printf("Vadic will not accept phone number\n");
5413131Sralph #ifdef ACULOG
5513131Sralph 		logent(value(HOST), num, "vadic", "will not accept number");
5613131Sralph #endif
5713131Sralph 		return (0);
5813131Sralph 	}
5913131Sralph 	func = signal(SIGINT,SIG_IGN);
60*13276Ssam 	/*
61*13276Ssam 	 * You cannot interrupt the Vadic when its dialing;
62*13276Ssam 	 * even dropping DTR does not work (definitely a
63*13276Ssam 	 * brain damaged design).
64*13276Ssam 	 */
65*13276Ssam 	vawrite("\r", 1 + slow);
66*13276Ssam 	vawrite("\r", 1 + slow);
67*13276Ssam 	if (!expect("DIALING:")) {
6813131Sralph 		printf("Vadic failed to dial\n");
6913131Sralph #ifdef ACULOG
7013131Sralph 		logent(value(HOST), num, "vadic", "failed to dial");
7113131Sralph #endif
7213131Sralph 		return (0);
73*13276Ssam 	}
74*13276Ssam 	if (boolean(value(VERBOSE)))
75*13276Ssam 		printf("\ndialing...");
7613131Sralph 	ok = expect("ON LINE");
77*13276Ssam 	signal(SIGINT, func);
78*13276Ssam 	if (!ok) {
7913131Sralph 		printf("call failed\n");
8013131Sralph #ifdef ACULOG
8113131Sralph 		logent(value(HOST), num, "vadic", "call failed");
8213131Sralph #endif
8313131Sralph 		return (0);
8413131Sralph 	}
85*13276Ssam 	ioctl(FD, TIOCFLUSH, &rw);
8613131Sralph 	return (1);
8713131Sralph }
8813131Sralph 
8913131Sralph vadic_disconnect()
9013131Sralph {
91*13276Ssam 
9213131Sralph 	close(FD);
9313131Sralph }
9413131Sralph 
9513131Sralph vadic_abort()
9613131Sralph {
97*13276Ssam 
98*13276Ssam 	close(FD);
9913131Sralph }
10013131Sralph 
101*13276Ssam static
102*13276Ssam vawrite(cp, delay)
103*13276Ssam 	register char *cp;
104*13276Ssam 	int delay;
10513131Sralph {
106*13276Ssam 
107*13276Ssam 	for (; *cp; sleep(delay), cp++)
108*13276Ssam 		write(FD, cp, 1);
10913131Sralph }
11013131Sralph 
111*13276Ssam static
112*13276Ssam expect(cp)
113*13276Ssam 	register char *cp;
11413131Sralph {
115*13276Ssam 	char buf[300];
116*13276Ssam 	register char *rp = buf;
117*13276Ssam 	int alarmtr(), timeout = 30, online = 0;
11813131Sralph 
119*13276Ssam 	if (strcmp(cp, "\"\"") == 0)
120*13276Ssam 		return (1);
12113131Sralph 	*rp = 0;
12213131Sralph 	/*
12313131Sralph 	 * If we are waiting for the Vadic to complete
12413131Sralph 	 * dialing and get a connection, allow more time
12513131Sralph 	 * Unfortunately, the Vadic times out 24 seconds after
12613131Sralph 	 * the last digit is dialed
12713131Sralph 	 */
128*13276Ssam 	online = strcmp(cp, "ON LINE") == 0;
129*13276Ssam 	if (online)
130*13276Ssam 		timeout = number(value(DIALTIMEOUT));
13113131Sralph 	signal(SIGALRM, alarmtr);
132*13276Ssam 	if (setjmp(Sjbuf))
133*13276Ssam 		return (0);
134*13276Ssam 	alarm(timeout);
135*13276Ssam 	while (notin(cp, buf) && rp < buf + sizeof (buf) - 1) {
136*13276Ssam 		if (online && notin("FAILED CALL", buf) == 0)
137*13276Ssam 			return (0);
138*13276Ssam 		if (read(FD, rp, 1) < 0) {
13913131Sralph 			alarm(0);
140*13276Ssam 			return (0);
14113131Sralph 		}
142*13276Ssam 		if (*rp &= 0177)
14313131Sralph 			rp++;
14413131Sralph 		*rp = '\0';
14513131Sralph 	}
14613131Sralph 	alarm(0);
147*13276Ssam 	return (1);
14813131Sralph }
14913131Sralph 
150*13276Ssam static
15113131Sralph alarmtr()
15213131Sralph {
153*13276Ssam 
15413131Sralph 	longjmp(Sjbuf, 1);
15513131Sralph }
15613131Sralph 
157*13276Ssam static
15813131Sralph notin(sh, lg)
159*13276Ssam 	char *sh, *lg;
16013131Sralph {
161*13276Ssam 
162*13276Ssam 	for (; *lg; lg++)
16313131Sralph 		if (prefix(sh, lg))
164*13276Ssam 			return (0);
165*13276Ssam 	return (1);
16613131Sralph }
16713131Sralph 
168*13276Ssam static
16913131Sralph prefix(s1, s2)
170*13276Ssam 	register char *s1, *s2;
17113131Sralph {
172*13276Ssam 	register char c;
17313131Sralph 
17413131Sralph 	while ((c = *s1++) == *s2++)
17513131Sralph 		if (c == '\0')
176*13276Ssam 			return (1);
177*13276Ssam 	return (c == '\0');
17813131Sralph }
179