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