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