xref: /csrg-svn/usr.bin/uucp/libacu/va811.c (revision 17783)
1*17783Sralph #ifndef lint
2*17783Sralph static char sccsid[] = "@(#)va811.c	4.1 (Berkeley) 01/22/85";
3*17783Sralph #endif
4*17783Sralph 
5*17783Sralph #include "../condevs.h"
6*17783Sralph 
7*17783Sralph #ifdef	VA811S
8*17783Sralph /*
9*17783Sralph  * Racal-Vadic VA811 dialer with 831 adaptor.
10*17783Sralph  * A typical 300 baud L-devices entry is
11*17783Sralph  *	ACU /dev/tty10 unused 300 va811s
12*17783Sralph  * where tty10 is the communication line (D_Line),
13*17783Sralph  * and 300 is the line speed.
14*17783Sralph  * This is almost identical to RVMACS except that we don't need to
15*17783Sralph  * send addresses and modem types, and don't need the fork.
16*17783Sralph  *	Joe Kelsey, fluke!joe, vax4.1526, Apr 11 1984.
17*17783Sralph  */
18*17783Sralph 
19*17783Sralph #define	STX	02	/* Access Adaptor */
20*17783Sralph #define	ETX	03	/* Transfer to Dialer */
21*17783Sralph #define	SI	017	/* Buffer Empty (end of phone number) */
22*17783Sralph #define	SOH	01	/* Abort */
23*17783Sralph 
24*17783Sralph va811opn(ph, flds, dev)
25*17783Sralph char *ph, *flds[];
26*17783Sralph struct Devices *dev;
27*17783Sralph {
28*17783Sralph 	int va;
29*17783Sralph 	register int i, tries;
30*17783Sralph 	char c, dcname[20];
31*17783Sralph 	char vabuf[35];		/* STX, 31 phone digits, SI, ETX, NUL */
32*17783Sralph 
33*17783Sralph 	va = 0;
34*17783Sralph 	sprintf(dcname, "/dev/%s", dev->D_line);
35*17783Sralph 	if (setjmp(Sjbuf)) {
36*17783Sralph 		DEBUG(1, "timeout va811 open\n", 0);
37*17783Sralph 		logent("va811opn", "TIMEOUT");
38*17783Sralph 		if (va >= 0)
39*17783Sralph 			close(va);
40*17783Sralph 		delock(dev->D_line);
41*17783Sralph 		return CF_NODEV;
42*17783Sralph 	}
43*17783Sralph 	DEBUG(4, "va811: STARTING CALL\n", 0);
44*17783Sralph 	getnextfd();
45*17783Sralph 	signal(SIGALRM, alarmtr);
46*17783Sralph 	alarm(10);
47*17783Sralph 	va = open(dcname, 2);
48*17783Sralph 	alarm(0);
49*17783Sralph 
50*17783Sralph 	/* line is open */
51*17783Sralph 	next_fd = -1;
52*17783Sralph 	if (va < 0) {
53*17783Sralph 		DEBUG(4, errno == 4 ? "%s: no carrier\n" : "%s: can't open\n",
54*17783Sralph 			dcname);
55*17783Sralph 		delock(dev->D_line);
56*17783Sralph 		logent(dcname, "CAN'T OPEN");
57*17783Sralph 		return(errno == 4 ? CF_DIAL : CF_NODEV);
58*17783Sralph 	}
59*17783Sralph 	fixline(va, dev->D_speed);
60*17783Sralph 
61*17783Sralph 	/* first, reset everything */
62*17783Sralph 	sendthem("\\01\\c", va);
63*17783Sralph 	DEBUG(4, "wanted %c ", 'B');
64*17783Sralph 	i = expect("B", va);
65*17783Sralph 	DEBUG(4, "got %s\n", i ? "?" : "that");
66*17783Sralph 	if (i != 0) {
67*17783Sralph 	    DEBUG(4, "va811: NO RESPONSE\n", 0);
68*17783Sralph 	    logent("va811 reset", "TIMEOUT");
69*17783Sralph 	    close(va);
70*17783Sralph 	    delock(dev->D_line);
71*17783Sralph 	    return CF_DIAL;
72*17783Sralph 	}
73*17783Sralph 
74*17783Sralph 	sprintf(vabuf, "%c%.31s%c%c\\c", STX, ph, SI, SOH);
75*17783Sralph 	sendthem(vabuf, va);
76*17783Sralph 	DEBUG(4, "wanted %c ", 'B');
77*17783Sralph 	i = expect("B", va);
78*17783Sralph 	DEBUG(4, "got %s\n", i ? "?" : "that");
79*17783Sralph 
80*17783Sralph 	if (i != 0) {
81*17783Sralph 	    DEBUG(4, "va811: STORE NUMBER\n", 0);
82*17783Sralph 	    logent("va811 STORE", _FAILED);
83*17783Sralph 	    close(va);
84*17783Sralph 	    delock(dev->D_line);
85*17783Sralph 	    return CF_DIAL;
86*17783Sralph 	}
87*17783Sralph 
88*17783Sralph 	for (tries = 0; tries < TRYCALLS; tries++) {
89*17783Sralph 	    sprintf(vabuf, "%c%c\\c", STX, ETX);
90*17783Sralph 	    sendthem(vabuf, va);
91*17783Sralph 	    DEBUG(4, "DIALING...", CNULL);
92*17783Sralph 	    i = expect("A", va);
93*17783Sralph 	    DEBUG(4, " %s\n", i ? _FAILED : "SUCCEEDED");
94*17783Sralph 	    if (i != 0) {
95*17783Sralph 		DEBUG(4, "va811: RESETTING\n", CNULL);
96*17783Sralph 		logent("va811 DIAL", _FAILED);
97*17783Sralph 	        sendthem("\\01\\c", va);
98*17783Sralph 	        expect("B", va);
99*17783Sralph 	    }
100*17783Sralph 	    else
101*17783Sralph 	        break;
102*17783Sralph 	}
103*17783Sralph 
104*17783Sralph 	if (tries >= TRYCALLS) {
105*17783Sralph 	    close(va);
106*17783Sralph 	    delock(dev->D_line);
107*17783Sralph 	    return CF_DIAL;
108*17783Sralph 	}
109*17783Sralph 
110*17783Sralph 	DEBUG(4, "va811 ok\n", CNULL);
111*17783Sralph 	return va;
112*17783Sralph }
113*17783Sralph 
114*17783Sralph va811cls(fd)
115*17783Sralph register int fd;
116*17783Sralph {
117*17783Sralph 	DEBUG(2, "va811 close %d\n", fd);
118*17783Sralph 	p_chwrite(fd, SOH);
119*17783Sralph /*	ioctl(fd, TIOCCDTR, NULL);*/
120*17783Sralph 	close(fd);
121*17783Sralph 	delock(devSel);
122*17783Sralph }
123*17783Sralph #endif VA811S
124