xref: /csrg-svn/usr.bin/uucp/libacu/va212.c (revision 46875)
117782Sralph #ifndef lint
2*46875Sbostic static char sccsid[] = "@(#)va212.c	4.4 (Berkeley) 03/02/91";
317782Sralph #endif
417782Sralph 
5*46875Sbostic #include "condevs.h"
617782Sralph 
717782Sralph va212opn(telno, flds, dev)
817782Sralph char *telno;
917782Sralph char *flds[];
1017782Sralph struct Devices *dev;
1117782Sralph {
1217782Sralph 	int	dh = -1;
1317782Sralph 	int	i, ok, er = 0, delay;
1417782Sralph 	extern errno;
1517782Sralph 	char dcname[20];
1617782Sralph 
1717782Sralph 	sprintf(dcname, "/dev/%s", dev->D_line);
1817782Sralph 	if (setjmp(Sjbuf)) {
1917782Sralph 		DEBUG(1, "timeout va212 open\n", 0);
2017782Sralph 		logent("va212 open", "TIMEOUT");
2117782Sralph 		if (dh >= 0)
2217782Sralph 			close(dh);
2317782Sralph 		delock(dev->D_line);
2417782Sralph 		return CF_NODEV;
2517782Sralph 	}
2617782Sralph 	signal(SIGALRM, alarmtr);
2717782Sralph 	getnextfd();
2817782Sralph 	alarm(10);
2917782Sralph 	dh = open(dcname, 2);
3017782Sralph 	alarm(0);
3117782Sralph 
3217782Sralph 	/* modem is open */
3317782Sralph 	next_fd = -1;
3417782Sralph 	if (dh < 0) {
3517782Sralph 		DEBUG (4, errno == 4 ? "%s: no carrier\n" : "%s: can't open\n",
3617782Sralph 		dcname);
3717782Sralph 		delock(dev->D_line);
3817782Sralph 		return errno == 4 ? CF_DIAL : CF_NODEV;
3917782Sralph 	}
4017782Sralph 	fixline(dh, dev->D_speed);
4117782Sralph 
4217782Sralph 	/* translate - to K for Vadic */
4317782Sralph 	DEBUG(4, "calling %s -> ", telno);
4417782Sralph 	delay = 0;
4517782Sralph 	for (i = 0; i < strlen(telno); ++i) {
4617782Sralph 		switch(telno[i]) {
4717782Sralph 		case '=':	/* await dial tone */
4817782Sralph 		case '-':	/* delay */
4917782Sralph 		case '<':
5017782Sralph 			telno[i] = 'K';
5117782Sralph 			delay += 5;
5217782Sralph 			break;
5317782Sralph 		}
5417782Sralph 	}
5517782Sralph 	DEBUG(4, "%s\n", telno);
5617782Sralph 	for(i = 0; i < TRYCALLS; ++i) {	/* make TRYCALLS tries */
5717782Sralph 		/* wake up Vadic */
5817782Sralph 		sendthem("\005\\d", dh);
5917782Sralph 		DEBUG(4, "wanted * ", CNULL);
6017782Sralph 		ok = expect("*", dh);
6117782Sralph 		DEBUG(4, "got %s\n", ok ? "?" : "that");
6217782Sralph 		if (ok != 0)
6317782Sralph 			continue;
6417782Sralph 
6517782Sralph 		sendthem("D\\d", dh);	/* "D" (enter number) command */
6617782Sralph 		DEBUG(4, "wanted NUMBER? ", CNULL);
6717782Sralph 		ok = expect("NUMBER?", dh);
6817782Sralph 		if (ok == 0)
6917782Sralph 			ok = expect("\n", dh);
7017782Sralph 		DEBUG(4, "got %s\n", ok ? "?" : "that");
7117782Sralph 		if (ok != 0)
7217782Sralph 			continue;
7317782Sralph 
7417782Sralph 		/* send telno, send \r */
7517782Sralph 		sendthem(telno, dh);
7617782Sralph 		DEBUG(4, "wanted %s ", telno);
7717782Sralph 		ok = expect(telno, dh);
7817782Sralph 		if (ok == 0)
7917782Sralph 			ok = expect("\n", dh);
8017782Sralph 		DEBUG(4, "got %s\n", ok ? "?" : "that");
8117782Sralph 		if (ok != 0)
8217782Sralph 			continue;
8317782Sralph 
8417782Sralph 		sendthem("", dh); /* confirm number */
8517782Sralph 		DEBUG(4, "wanted %s ", "DIALING...");
8617782Sralph 		ok = expect("DIALING...", dh);
8717782Sralph 		if (ok == 0) {
8817782Sralph 			ok = expect("\n", dh);
8917782Sralph 			DEBUG(4, "wanted ANSWER TONE", CNULL);
9017782Sralph 			ok = expect("ANSWER TONE", dh);
9117782Sralph 			if (ok == 0)
9217782Sralph 				ok = expect("\n", dh);
9317782Sralph 		}
9417782Sralph 		DEBUG(4, "got %s\n", ok ? "?" : "that");
9517782Sralph 		if (ok == 0)
9617782Sralph 			break;
9717782Sralph 	}
9817782Sralph 
9917782Sralph 	if (ok == 0) {
10023703Sbloom 		DEBUG(4, "wanted ON LINE\\r\\n ", CNULL);
10123703Sbloom 		ok = expect("ON LINE\r\n", dh);
10217782Sralph 		DEBUG(4, "got %s\n", ok ? "?" : "that");
10317782Sralph 	}
10417782Sralph 
10517782Sralph 	if (ok != 0) {
10617782Sralph 		sendthem("I\\d", dh);	/* back to idle */
10717782Sralph 		if (dh > 2)
10817782Sralph 			close(dh);
10917782Sralph 		DEBUG(4, "vadDial failed\n", CNULL);
11017782Sralph 		delock(dev->D_line);
11117782Sralph 		return CF_DIAL;
11217782Sralph 	}
11317782Sralph 	DEBUG(4, "va212 ok\n", 0);
11417782Sralph 	return dh;
11517782Sralph }
11617782Sralph 
11717782Sralph va212cls(fd)
11817782Sralph {
11917782Sralph 	if (fd > 0) {
12017782Sralph 		close(fd);
12117782Sralph 		sleep(5);
12217782Sralph 		delock(devSel);
12317782Sralph 	}
12417782Sralph }
125