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