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