xref: /csrg-svn/usr.bin/tip/aculib/v3451.c (revision 13280)
1*13280Ssam #ifndef lint
2*13280Ssam static char sccsid[] = "@(#)v3451.c	4.3 (Berkeley) 06/25/83";
3*13280Ssam #endif
413131Sralph 
5*13280Ssam #ifdef V3451
613131Sralph /*
713131Sralph  * Routines for calling up on a Vadic 3451 Modem
813131Sralph  */
913131Sralph #include "tip.h"
1013131Sralph 
1113276Ssam static	jmp_buf Sjbuf;
1213131Sralph 
13*13280Ssam v3451_dialer(num, acu)
1413131Sralph 	register char *num;
1513131Sralph 	char *acu;
1613131Sralph {
1713276Ssam 	int ok, (*func)();
1813276Ssam 	int slow = number(value(BAUDRATE)) < 1200, rw = 2;
1913131Sralph 	char phone[50];
2013131Sralph #ifdef ACULOG
2113131Sralph 	char line[80];
2213131Sralph #endif
2313131Sralph 
2413131Sralph 	/*
2513131Sralph 	 * Get in synch
2613131Sralph 	 */
2713276Ssam 	vawrite("I\r", 1 + slow);
2813276Ssam 	vawrite("I\r", 1 + slow);
2913276Ssam 	vawrite("I\r", 1 + slow);
3013276Ssam 	vawrite("\005\r", 2 + slow);
3113276Ssam 	if (!expect("READY")) {
3213131Sralph 		printf("can't synchronize with vadic 3451\n");
3313131Sralph #ifdef ACULOG
3413131Sralph 		logent(value(HOST), num, "vadic", "can't synch up");
3513131Sralph #endif
3613131Sralph 		return (0);
3713131Sralph 	}
3813131Sralph 	ioctl(FD, TIOCHPCL, 0);
3913131Sralph 	sleep(1);
4013276Ssam 	vawrite("D\r", 2 + slow);
4113276Ssam 	if (!expect("NUMBER?")) {
4213131Sralph 		printf("Vadic will not accept dial command\n");
4313131Sralph #ifdef ACULOG
4413131Sralph 		logent(value(HOST), num, "vadic", "will not accept dial");
4513131Sralph #endif
4613131Sralph 		return (0);
4713131Sralph 	}
4813276Ssam 	strcpy(phone, num);
4913276Ssam 	strcat(phone, "\r");
5013276Ssam 	vawrite(phone, 1 + slow);
5113276Ssam 	if (!expect(phone)) {
5213131Sralph 		printf("Vadic will not accept phone number\n");
5313131Sralph #ifdef ACULOG
5413131Sralph 		logent(value(HOST), num, "vadic", "will not accept number");
5513131Sralph #endif
5613131Sralph 		return (0);
5713131Sralph 	}
5813131Sralph 	func = signal(SIGINT,SIG_IGN);
5913276Ssam 	/*
6013276Ssam 	 * You cannot interrupt the Vadic when its dialing;
6113276Ssam 	 * even dropping DTR does not work (definitely a
6213276Ssam 	 * brain damaged design).
6313276Ssam 	 */
6413276Ssam 	vawrite("\r", 1 + slow);
6513276Ssam 	vawrite("\r", 1 + slow);
6613276Ssam 	if (!expect("DIALING:")) {
6713131Sralph 		printf("Vadic failed to dial\n");
6813131Sralph #ifdef ACULOG
6913131Sralph 		logent(value(HOST), num, "vadic", "failed to dial");
7013131Sralph #endif
7113131Sralph 		return (0);
7213276Ssam 	}
7313276Ssam 	if (boolean(value(VERBOSE)))
7413276Ssam 		printf("\ndialing...");
7513131Sralph 	ok = expect("ON LINE");
7613276Ssam 	signal(SIGINT, func);
7713276Ssam 	if (!ok) {
7813131Sralph 		printf("call failed\n");
7913131Sralph #ifdef ACULOG
8013131Sralph 		logent(value(HOST), num, "vadic", "call failed");
8113131Sralph #endif
8213131Sralph 		return (0);
8313131Sralph 	}
8413276Ssam 	ioctl(FD, TIOCFLUSH, &rw);
8513131Sralph 	return (1);
8613131Sralph }
8713131Sralph 
88*13280Ssam v3451_disconnect()
8913131Sralph {
9013276Ssam 
9113131Sralph 	close(FD);
9213131Sralph }
9313131Sralph 
94*13280Ssam v3451_abort()
9513131Sralph {
9613276Ssam 
9713276Ssam 	close(FD);
9813131Sralph }
9913131Sralph 
10013276Ssam static
10113276Ssam vawrite(cp, delay)
10213276Ssam 	register char *cp;
10313276Ssam 	int delay;
10413131Sralph {
10513276Ssam 
10613276Ssam 	for (; *cp; sleep(delay), cp++)
10713276Ssam 		write(FD, cp, 1);
10813131Sralph }
10913131Sralph 
11013276Ssam static
11113276Ssam expect(cp)
11213276Ssam 	register char *cp;
11313131Sralph {
11413276Ssam 	char buf[300];
11513276Ssam 	register char *rp = buf;
11613276Ssam 	int alarmtr(), timeout = 30, online = 0;
11713131Sralph 
11813276Ssam 	if (strcmp(cp, "\"\"") == 0)
11913276Ssam 		return (1);
12013131Sralph 	*rp = 0;
12113131Sralph 	/*
12213131Sralph 	 * If we are waiting for the Vadic to complete
12313131Sralph 	 * dialing and get a connection, allow more time
12413131Sralph 	 * Unfortunately, the Vadic times out 24 seconds after
12513131Sralph 	 * the last digit is dialed
12613131Sralph 	 */
12713276Ssam 	online = strcmp(cp, "ON LINE") == 0;
12813276Ssam 	if (online)
12913276Ssam 		timeout = number(value(DIALTIMEOUT));
13013131Sralph 	signal(SIGALRM, alarmtr);
13113276Ssam 	if (setjmp(Sjbuf))
13213276Ssam 		return (0);
13313276Ssam 	alarm(timeout);
13413276Ssam 	while (notin(cp, buf) && rp < buf + sizeof (buf) - 1) {
13513276Ssam 		if (online && notin("FAILED CALL", buf) == 0)
13613276Ssam 			return (0);
13713276Ssam 		if (read(FD, rp, 1) < 0) {
13813131Sralph 			alarm(0);
13913276Ssam 			return (0);
14013131Sralph 		}
14113276Ssam 		if (*rp &= 0177)
14213131Sralph 			rp++;
14313131Sralph 		*rp = '\0';
14413131Sralph 	}
14513131Sralph 	alarm(0);
14613276Ssam 	return (1);
14713131Sralph }
14813131Sralph 
14913276Ssam static
15013131Sralph alarmtr()
15113131Sralph {
15213276Ssam 
15313131Sralph 	longjmp(Sjbuf, 1);
15413131Sralph }
15513131Sralph 
15613276Ssam static
15713131Sralph notin(sh, lg)
15813276Ssam 	char *sh, *lg;
15913131Sralph {
16013276Ssam 
16113276Ssam 	for (; *lg; lg++)
16213131Sralph 		if (prefix(sh, lg))
16313276Ssam 			return (0);
16413276Ssam 	return (1);
16513131Sralph }
16613131Sralph 
16713276Ssam static
16813131Sralph prefix(s1, s2)
16913276Ssam 	register char *s1, *s2;
17013131Sralph {
17113276Ssam 	register char c;
17213131Sralph 
17313131Sralph 	while ((c = *s1++) == *s2++)
17413131Sralph 		if (c == '\0')
17513276Ssam 			return (1);
17613276Ssam 	return (c == '\0');
17713131Sralph }
178*13280Ssam #endif
179