xref: /csrg-svn/usr.bin/uucp/libacu/vad.c (revision 46875)
117785Sralph #ifndef lint
2*46875Sbostic static char sccsid[] = "@(#)vad.c	4.4 (Berkeley) 03/02/91";
317785Sralph #endif
417785Sralph 
5*46875Sbostic #include "condevs.h"
617785Sralph 
717785Sralph /*
817785Sralph  *	vadopn: establish dial-out connection through a Racal-Vadic 3450.
917785Sralph  *	Returns descriptor open to tty for reading and writing.
1017785Sralph  *	Negative values (-1...-7) denote errors in connmsg.
1117785Sralph  *	Be sure to disconnect tty when done, via HUPCL or stty 0.
1217785Sralph  */
1317785Sralph 
1417785Sralph vadopn(telno, flds, dev)
1517785Sralph char *telno;
1617785Sralph char *flds[];
1717785Sralph struct Devices *dev;
1817785Sralph {
1917785Sralph 	int	dh = -1;
2017785Sralph 	int	i, ok, er = 0, delay;
2117785Sralph 	extern errno;
2217785Sralph 	char dcname[20];
2317785Sralph 
2417785Sralph 	sprintf(dcname, "/dev/%s", dev->D_line);
2517785Sralph 	if (setjmp(Sjbuf)) {
2617785Sralph 		DEBUG(1, "timeout vadic open\n", "");
2717785Sralph 		logent("vadic open", "TIMEOUT");
2817785Sralph 		if (dh >= 0)
2917785Sralph 			close(dh);
3017785Sralph 		delock(dev->D_line);
3117785Sralph 		return CF_NODEV;
3217785Sralph 	}
3317785Sralph 	signal(SIGALRM, alarmtr);
3417785Sralph 	getnextfd();
3517785Sralph 	alarm(10);
3617785Sralph 	dh = open(dcname, 2);
3717785Sralph 	alarm(0);
3817785Sralph 
3917785Sralph 	/* modem is open */
4017785Sralph 	next_fd = -1;
4117785Sralph 	if (dh < 0) {
4217785Sralph 		delock(dev->D_line);
4317785Sralph 		return CF_NODEV;
4417785Sralph 	}
4517785Sralph 	fixline(dh, dev->D_speed);
4617785Sralph 
4717785Sralph 	DEBUG(4, "calling %s -> ", telno);
4817785Sralph 	if (dochat(dev, flds, dh)) {
4917785Sralph 		logent(dcname, "CHAT FAILED");
5017785Sralph 		close(dh);
5117785Sralph 		return CF_DIAL;
5217785Sralph 	}
5317785Sralph 	delay = 0;
5417785Sralph 	for (i = 0; i < strlen(telno); ++i) {
5517785Sralph 		switch(telno[i]) {
5617785Sralph 		case '=':	/* await dial tone */
5717785Sralph 		case '-':
5817785Sralph 		case ',':
5917785Sralph 		case '<':
6017785Sralph 		case 'K':
6117785Sralph 			telno[i] = 'K';
6217785Sralph 			delay += 5;
6317785Sralph 			break;
6417785Sralph 		}
6517785Sralph 	}
6617785Sralph 	DEBUG(4, "%s\n", telno);
6717785Sralph 	for(i = 0; i < 5; ++i) {	/* make 5 tries */
6817785Sralph 		/* wake up Vadic */
6925159Sbloom 		write(dh, "\005", 1);
7025159Sbloom 		sleep(1);
7125159Sbloom 		write(dh, "\r", 1);
7217785Sralph 		DEBUG(4, "wanted * ", CNULL);
7325159Sbloom 		ok = expect("*~5", dh);
7417785Sralph 		DEBUG(4, "got %s\n", ok ? "?" : "that");
7517785Sralph 		if (ok != 0)
7617785Sralph 			continue;
7717785Sralph 
7817785Sralph 		write(dh, "D\r", 2); /* "D" (enter number) command */
7917785Sralph 		DEBUG(4, "wanted NUMBER?\\r\\n ", CNULL);
8025159Sbloom 		ok = expect("NUMBER?\r\n~5", dh);
8117785Sralph 		DEBUG(4, "got %s\n", ok ? "?" : "that");
8217785Sralph 		if (ok != 0)
8317785Sralph 			continue;
8417785Sralph 
8517785Sralph 		/* send telno, send \r */
8617785Sralph 		write(dh, telno, strlen(telno));
8717785Sralph 		sleep(1);
8817785Sralph 		write(dh, "\r", 1);
8917785Sralph 		DEBUG(4, "wanted %s ", telno);
9017785Sralph 		ok = expect(telno, dh);
9117785Sralph 		if (ok == 0)
9217785Sralph 			ok = expect("\r\n", dh);
9317785Sralph 		DEBUG(4, "got %s\n", ok ? "?" : "that");
9417785Sralph 		if (ok != 0)
9517785Sralph 			continue;
9617785Sralph 
9717785Sralph 		write(dh, "\r", 1); /* confirm number */
9817785Sralph 		DEBUG(4, "wanted DIALING: ", CNULL);
9917785Sralph 		ok = expect("DIALING: ", dh);
10017785Sralph 		DEBUG(4, "got %s\n", ok ? "?" : "that");
10117785Sralph 		if (ok == 0)
10217785Sralph 			break;
10317785Sralph 	}
10417785Sralph 
10517785Sralph 	if (ok == 0) {
10617785Sralph 		sleep(10 + delay);	/* give vadic some time */
10717785Sralph 		DEBUG(4, "wanted ON LINE\\r\\n ", CNULL);
10817785Sralph 		ok = expect("ON LINE\r\n", dh);
10917785Sralph 		DEBUG(4, "got %s\n", ok ? "?" : "that");
11017785Sralph 	}
11117785Sralph 
11217785Sralph 	if (ok != 0) {
11317785Sralph 		if (dh > 2)
11417785Sralph 			close(dh);
11517785Sralph 		DEBUG(4, "vadDial failed\n", CNULL);
11617785Sralph 		delock(dev->D_line);
11717785Sralph 		return CF_DIAL;
11817785Sralph 	}
11917785Sralph 	DEBUG(4, "vadic ok\n", CNULL);
12017785Sralph 	return dh;
12117785Sralph }
12217785Sralph 
12325159Sbloom vadcls(fd)
12425159Sbloom {
12517785Sralph 	if (fd > 0) {
12617785Sralph 		close(fd);
12717785Sralph 		sleep(5);
12817785Sralph 		delock(devSel);
12917785Sralph 	}
13017785Sralph }
131