xref: /csrg-svn/usr.bin/tip/aculib/v3451.c (revision 35492)
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[] = "@(#)v3451.c	5.2 (Berkeley) 09/13/88";
20*35492Sbostic #endif /* not lint */
2113131Sralph 
2213131Sralph /*
2313131Sralph  * Routines for calling up on a Vadic 3451 Modem
2413131Sralph  */
2513131Sralph #include "tip.h"
2613131Sralph 
2713276Ssam static	jmp_buf Sjbuf;
2813131Sralph 
2913280Ssam v3451_dialer(num, acu)
3013131Sralph 	register char *num;
3113131Sralph 	char *acu;
3213131Sralph {
3313276Ssam 	int ok, (*func)();
3413276Ssam 	int slow = number(value(BAUDRATE)) < 1200, rw = 2;
3513131Sralph 	char phone[50];
3613131Sralph #ifdef ACULOG
3713131Sralph 	char line[80];
3813131Sralph #endif
3913131Sralph 
4013131Sralph 	/*
4113131Sralph 	 * Get in synch
4213131Sralph 	 */
4313276Ssam 	vawrite("I\r", 1 + slow);
4413276Ssam 	vawrite("I\r", 1 + slow);
4513276Ssam 	vawrite("I\r", 1 + slow);
4613276Ssam 	vawrite("\005\r", 2 + slow);
4713276Ssam 	if (!expect("READY")) {
4813131Sralph 		printf("can't synchronize with vadic 3451\n");
4913131Sralph #ifdef ACULOG
5013131Sralph 		logent(value(HOST), num, "vadic", "can't synch up");
5113131Sralph #endif
5213131Sralph 		return (0);
5313131Sralph 	}
5413131Sralph 	ioctl(FD, TIOCHPCL, 0);
5513131Sralph 	sleep(1);
5613276Ssam 	vawrite("D\r", 2 + slow);
5713276Ssam 	if (!expect("NUMBER?")) {
5813131Sralph 		printf("Vadic will not accept dial command\n");
5913131Sralph #ifdef ACULOG
6013131Sralph 		logent(value(HOST), num, "vadic", "will not accept dial");
6113131Sralph #endif
6213131Sralph 		return (0);
6313131Sralph 	}
6413276Ssam 	strcpy(phone, num);
6513276Ssam 	strcat(phone, "\r");
6613276Ssam 	vawrite(phone, 1 + slow);
6713276Ssam 	if (!expect(phone)) {
6813131Sralph 		printf("Vadic will not accept phone number\n");
6913131Sralph #ifdef ACULOG
7013131Sralph 		logent(value(HOST), num, "vadic", "will not accept number");
7113131Sralph #endif
7213131Sralph 		return (0);
7313131Sralph 	}
7413131Sralph 	func = signal(SIGINT,SIG_IGN);
7513276Ssam 	/*
7613276Ssam 	 * You cannot interrupt the Vadic when its dialing;
7713276Ssam 	 * even dropping DTR does not work (definitely a
7813276Ssam 	 * brain damaged design).
7913276Ssam 	 */
8013276Ssam 	vawrite("\r", 1 + slow);
8113276Ssam 	vawrite("\r", 1 + slow);
8213276Ssam 	if (!expect("DIALING:")) {
8313131Sralph 		printf("Vadic failed to dial\n");
8413131Sralph #ifdef ACULOG
8513131Sralph 		logent(value(HOST), num, "vadic", "failed to dial");
8613131Sralph #endif
8713131Sralph 		return (0);
8813276Ssam 	}
8913276Ssam 	if (boolean(value(VERBOSE)))
9013276Ssam 		printf("\ndialing...");
9113131Sralph 	ok = expect("ON LINE");
9213276Ssam 	signal(SIGINT, func);
9313276Ssam 	if (!ok) {
9413131Sralph 		printf("call failed\n");
9513131Sralph #ifdef ACULOG
9613131Sralph 		logent(value(HOST), num, "vadic", "call failed");
9713131Sralph #endif
9813131Sralph 		return (0);
9913131Sralph 	}
10013276Ssam 	ioctl(FD, TIOCFLUSH, &rw);
10113131Sralph 	return (1);
10213131Sralph }
10313131Sralph 
10413280Ssam v3451_disconnect()
10513131Sralph {
10613276Ssam 
10713131Sralph 	close(FD);
10813131Sralph }
10913131Sralph 
11013280Ssam v3451_abort()
11113131Sralph {
11213276Ssam 
11313276Ssam 	close(FD);
11413131Sralph }
11513131Sralph 
11613276Ssam static
11713276Ssam vawrite(cp, delay)
11813276Ssam 	register char *cp;
11913276Ssam 	int delay;
12013131Sralph {
12113276Ssam 
12213276Ssam 	for (; *cp; sleep(delay), cp++)
12313276Ssam 		write(FD, cp, 1);
12413131Sralph }
12513131Sralph 
12613276Ssam static
12713276Ssam expect(cp)
12813276Ssam 	register char *cp;
12913131Sralph {
13013276Ssam 	char buf[300];
13113276Ssam 	register char *rp = buf;
13213276Ssam 	int alarmtr(), timeout = 30, online = 0;
13313131Sralph 
13413276Ssam 	if (strcmp(cp, "\"\"") == 0)
13513276Ssam 		return (1);
13613131Sralph 	*rp = 0;
13713131Sralph 	/*
13813131Sralph 	 * If we are waiting for the Vadic to complete
13913131Sralph 	 * dialing and get a connection, allow more time
14013131Sralph 	 * Unfortunately, the Vadic times out 24 seconds after
14113131Sralph 	 * the last digit is dialed
14213131Sralph 	 */
14313276Ssam 	online = strcmp(cp, "ON LINE") == 0;
14413276Ssam 	if (online)
14513276Ssam 		timeout = number(value(DIALTIMEOUT));
14613131Sralph 	signal(SIGALRM, alarmtr);
14713276Ssam 	if (setjmp(Sjbuf))
14813276Ssam 		return (0);
14913276Ssam 	alarm(timeout);
15013276Ssam 	while (notin(cp, buf) && rp < buf + sizeof (buf) - 1) {
15113276Ssam 		if (online && notin("FAILED CALL", buf) == 0)
15213276Ssam 			return (0);
15313276Ssam 		if (read(FD, rp, 1) < 0) {
15413131Sralph 			alarm(0);
15513276Ssam 			return (0);
15613131Sralph 		}
15713276Ssam 		if (*rp &= 0177)
15813131Sralph 			rp++;
15913131Sralph 		*rp = '\0';
16013131Sralph 	}
16113131Sralph 	alarm(0);
16213276Ssam 	return (1);
16313131Sralph }
16413131Sralph 
16513276Ssam static
16613131Sralph alarmtr()
16713131Sralph {
16813276Ssam 
16913131Sralph 	longjmp(Sjbuf, 1);
17013131Sralph }
17113131Sralph 
17213276Ssam static
17313131Sralph notin(sh, lg)
17413276Ssam 	char *sh, *lg;
17513131Sralph {
17613276Ssam 
17713276Ssam 	for (; *lg; lg++)
17813131Sralph 		if (prefix(sh, lg))
17913276Ssam 			return (0);
18013276Ssam 	return (1);
18113131Sralph }
18213131Sralph 
18313276Ssam static
18413131Sralph prefix(s1, s2)
18513276Ssam 	register char *s1, *s2;
18613131Sralph {
18713276Ssam 	register char c;
18813131Sralph 
18913131Sralph 	while ((c = *s1++) == *s2++)
19013131Sralph 		if (c == '\0')
19113276Ssam 			return (1);
19213276Ssam 	return (c == '\0');
19313131Sralph }
194