xref: /csrg-svn/usr.bin/uucp/libacu/va212.c (revision 17782)
1*17782Sralph #ifndef lint
2*17782Sralph static char sccsid[] = "@(#)va212.c	4.1 (Berkeley) 01/22/85";
3*17782Sralph #endif
4*17782Sralph 
5*17782Sralph #include "../condevs.h"
6*17782Sralph 
7*17782Sralph #ifdef VA212
8*17782Sralph va212opn(telno, flds, dev)
9*17782Sralph char *telno;
10*17782Sralph char *flds[];
11*17782Sralph struct Devices *dev;
12*17782Sralph {
13*17782Sralph 	int	dh = -1;
14*17782Sralph 	int	i, ok, er = 0, delay;
15*17782Sralph 	extern errno;
16*17782Sralph 	char dcname[20];
17*17782Sralph 
18*17782Sralph 	sprintf(dcname, "/dev/%s", dev->D_line);
19*17782Sralph 	if (setjmp(Sjbuf)) {
20*17782Sralph 		DEBUG(1, "timeout va212 open\n", 0);
21*17782Sralph 		logent("va212 open", "TIMEOUT");
22*17782Sralph 		if (dh >= 0)
23*17782Sralph 			close(dh);
24*17782Sralph 		delock(dev->D_line);
25*17782Sralph 		return CF_NODEV;
26*17782Sralph 	}
27*17782Sralph 	signal(SIGALRM, alarmtr);
28*17782Sralph 	getnextfd();
29*17782Sralph 	alarm(10);
30*17782Sralph 	dh = open(dcname, 2);
31*17782Sralph 	alarm(0);
32*17782Sralph 
33*17782Sralph 	/* modem is open */
34*17782Sralph 	next_fd = -1;
35*17782Sralph 	if (dh < 0) {
36*17782Sralph 		DEBUG (4, errno == 4 ? "%s: no carrier\n" : "%s: can't open\n",
37*17782Sralph 		dcname);
38*17782Sralph 		delock(dev->D_line);
39*17782Sralph 		return errno == 4 ? CF_DIAL : CF_NODEV;
40*17782Sralph 	}
41*17782Sralph 	fixline(dh, dev->D_speed);
42*17782Sralph 
43*17782Sralph 	/* translate - to K for Vadic */
44*17782Sralph 	DEBUG(4, "calling %s -> ", telno);
45*17782Sralph 	delay = 0;
46*17782Sralph 	for (i = 0; i < strlen(telno); ++i) {
47*17782Sralph 		switch(telno[i]) {
48*17782Sralph 		case '=':	/* await dial tone */
49*17782Sralph 		case '-':	/* delay */
50*17782Sralph 		case '<':
51*17782Sralph 			telno[i] = 'K';
52*17782Sralph 			delay += 5;
53*17782Sralph 			break;
54*17782Sralph 		}
55*17782Sralph 	}
56*17782Sralph 	DEBUG(4, "%s\n", telno);
57*17782Sralph 	for(i = 0; i < TRYCALLS; ++i) {	/* make TRYCALLS tries */
58*17782Sralph 		/* wake up Vadic */
59*17782Sralph 		sendthem("\005\\d", dh);
60*17782Sralph 		DEBUG(4, "wanted * ", CNULL);
61*17782Sralph 		ok = expect("*", dh);
62*17782Sralph 		DEBUG(4, "got %s\n", ok ? "?" : "that");
63*17782Sralph 		if (ok != 0)
64*17782Sralph 			continue;
65*17782Sralph 
66*17782Sralph 		sendthem("D\\d", dh);	/* "D" (enter number) command */
67*17782Sralph 		DEBUG(4, "wanted NUMBER? ", CNULL);
68*17782Sralph 		ok = expect("NUMBER?", dh);
69*17782Sralph 		if (ok == 0)
70*17782Sralph 			ok = expect("\n", dh);
71*17782Sralph 		DEBUG(4, "got %s\n", ok ? "?" : "that");
72*17782Sralph 		if (ok != 0)
73*17782Sralph 			continue;
74*17782Sralph 
75*17782Sralph 		/* send telno, send \r */
76*17782Sralph 		sendthem(telno, dh);
77*17782Sralph 		DEBUG(4, "wanted %s ", telno);
78*17782Sralph 		ok = expect(telno, dh);
79*17782Sralph 		if (ok == 0)
80*17782Sralph 			ok = expect("\n", dh);
81*17782Sralph 		DEBUG(4, "got %s\n", ok ? "?" : "that");
82*17782Sralph 		if (ok != 0)
83*17782Sralph 			continue;
84*17782Sralph 
85*17782Sralph 		sendthem("", dh); /* confirm number */
86*17782Sralph 		DEBUG(4, "wanted %s ", "DIALING...");
87*17782Sralph 		ok = expect("DIALING...", dh);
88*17782Sralph 		if (ok == 0) {
89*17782Sralph 			ok = expect("\n", dh);
90*17782Sralph 			DEBUG(4, "wanted ANSWER TONE", CNULL);
91*17782Sralph 			ok = expect("ANSWER TONE", dh);
92*17782Sralph 			if (ok == 0)
93*17782Sralph 				ok = expect("\n", dh);
94*17782Sralph 		}
95*17782Sralph 		DEBUG(4, "got %s\n", ok ? "?" : "that");
96*17782Sralph 		if (ok == 0)
97*17782Sralph 			break;
98*17782Sralph 	}
99*17782Sralph 
100*17782Sralph 	if (ok == 0) {
101*17782Sralph 		DEBUG(4, "wanted ON LINE \\r\\n ", CNULL);
102*17782Sralph 		ok = expect("ON LINE \r\n", dh);
103*17782Sralph 		DEBUG(4, "got %s\n", ok ? "?" : "that");
104*17782Sralph 	}
105*17782Sralph 
106*17782Sralph 	if (ok != 0) {
107*17782Sralph 		sendthem("I\\d", dh);	/* back to idle */
108*17782Sralph 		if (dh > 2)
109*17782Sralph 			close(dh);
110*17782Sralph 		DEBUG(4, "vadDial failed\n", CNULL);
111*17782Sralph 		delock(dev->D_line);
112*17782Sralph 		return CF_DIAL;
113*17782Sralph 	}
114*17782Sralph 	DEBUG(4, "va212 ok\n", 0);
115*17782Sralph 	return dh;
116*17782Sralph }
117*17782Sralph 
118*17782Sralph va212cls(fd)
119*17782Sralph {
120*17782Sralph 	if (fd > 0) {
121*17782Sralph 		close(fd);
122*17782Sralph 		sleep(5);
123*17782Sralph 		delock(devSel);
124*17782Sralph 	}
125*17782Sralph }
126*17782Sralph #endif VA212
127