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