xref: /csrg-svn/usr.bin/uucp/libacu/va820.c (revision 17784)
1*17784Sralph #ifndef lint
2*17784Sralph static char sccsid[] = "@(#)va820.c	4.1 (Berkeley) 01/22/85";
3*17784Sralph #endif
4*17784Sralph 
5*17784Sralph #include "../condevs.h"
6*17784Sralph #ifdef	VA820
7*17784Sralph 
8*17784Sralph /*
9*17784Sralph  * Racal-Vadic 'RV820' with 831 adaptor.
10*17784Sralph  * BUGS:
11*17784Sralph  * dialer baud rate is hardcoded
12*17784Sralph  */
13*17784Sralph #define	MAXDIG 30	/* set by switches inside adapter */
14*17784Sralph char	c_abort	= '\001';
15*17784Sralph char	c_start	= '\002';
16*17784Sralph char	c_empty	= '\017';
17*17784Sralph char	c_end	= '\003';
18*17784Sralph 
19*17784Sralph va820opn(ph, flds, dev)
20*17784Sralph char *ph, *flds[];
21*17784Sralph struct Devices *dev;
22*17784Sralph {
23*17784Sralph 	register int va, i, child;
24*17784Sralph 	char c, acu[20], com[20];
25*17784Sralph 	char vadbuf[MAXDIG+2];
26*17784Sralph 	int nw, lt;
27*17784Sralph 	unsigned timelim;
28*17784Sralph 	struct sgttyb sg;
29*17784Sralph 
30*17784Sralph 	child = -1;
31*17784Sralph 	if (strlen(ph) > MAXDIG) {
32*17784Sralph 		DEBUG(4, "BAD PHONE NUMBER %s\n", ph);
33*17784Sralph 		logent("rvadopn", "BAD PHONE NUMBER");
34*17784Sralph 		i = CF_DIAL;
35*17784Sralph 		goto ret;
36*17784Sralph 	}
37*17784Sralph 
38*17784Sralph 	if (setjmp(Sjbuf)) {
39*17784Sralph 		logent("rvadopn", "TIMEOUT");
40*17784Sralph 		i = CF_DIAL;
41*17784Sralph 		goto ret;
42*17784Sralph 	}
43*17784Sralph 	DEBUG(4, "ACU %s\n", dev->D_calldev);
44*17784Sralph 	DEBUG(4, "LINE %s\n", dev->D_line);
45*17784Sralph 	sprintf(acu, "/dev/%s", dev->D_calldev);
46*17784Sralph 	getnextfd();
47*17784Sralph 	signal(SIGALRM, alarmtr);
48*17784Sralph 	alarm(10);
49*17784Sralph 	if ((va = open(acu, 2)) < 0) {
50*17784Sralph 		DEBUG(4, "ACU OPEN FAIL %d\n", errno);
51*17784Sralph 		logent(acu, "CAN'T OPEN");
52*17784Sralph 		i = CF_NODEV;
53*17784Sralph 		goto ret;
54*17784Sralph 	}
55*17784Sralph 	alarm(0);
56*17784Sralph 	next_fd = -1;
57*17784Sralph 	/*
58*17784Sralph 	 * Set speed and modes on dialer and clear any
59*17784Sralph 	 * previous requests
60*17784Sralph 	 */
61*17784Sralph 	DEBUG(4, "SETTING UP VA831 (%d)\n", va);
62*17784Sralph 	ioctl(va, TIOCGETP, &sg);
63*17784Sralph 	sg.sg_ispeed = sg.sg_ospeed = B1200;
64*17784Sralph 	sg.sg_flags |= RAW;
65*17784Sralph 	sg.sg_flags &= ~ECHO;
66*17784Sralph 	ioctl(va, TIOCSETP, &sg);
67*17784Sralph 	DEBUG(4, "CLEARING VA831\n", 0);
68*17784Sralph 	if ( write(va, &c_abort, 1) != 1) {
69*17784Sralph 		DEBUG(4,"BAD VA831 WRITE %d\n", errno);
70*17784Sralph 		logent(acu, "CAN'T CLEAR");
71*17784Sralph 		i = CF_DIAL;
72*17784Sralph 		goto ret;
73*17784Sralph 	}
74*17784Sralph 	sleep(1);			/* XXX */
75*17784Sralph 	read(va, &c, 1);
76*17784Sralph 	if (c != 'B') {
77*17784Sralph 		DEBUG(4,"BAD VA831 RESPONSE %c\n", c);
78*17784Sralph 		logent(acu, "CAN'T CLEAR");
79*17784Sralph 		i = CF_DIAL;
80*17784Sralph 		goto ret;
81*17784Sralph 	}
82*17784Sralph 	/*
83*17784Sralph 	 * Build the dialing sequence for the adapter
84*17784Sralph 	 * It appears that this needs to go in one
85*17784Sralph 	 * write for some obscure reason...
86*17784Sralph 	 */
87*17784Sralph 	DEBUG(4, "DIALING %s\n", ph);
88*17784Sralph 	sprintf(vadbuf, "%c%s%c%c", c_start, ph, c_empty, c_end);
89*17784Sralph 	timelim = 5 * strlen(ph);
90*17784Sralph 	alarm(timelim < 30 ? 30 : timelim);
91*17784Sralph 	nw = write(va, vadbuf, strlen(vadbuf));	/* Send Phone Number */
92*17784Sralph 	if (nw != strlen(vadbuf)) {
93*17784Sralph 		DEBUG(4,"BAD VA831 WRITE %d\n", nw);
94*17784Sralph 		logent(acu, "BAD WRITE");
95*17784Sralph 		goto failret;
96*17784Sralph 	}
97*17784Sralph 
98*17784Sralph 	sprintf(com, "/dev/%s", dev->D_line);
99*17784Sralph 
100*17784Sralph 	/* create child to open comm line */
101*17784Sralph 	if ((child = fork()) == 0) {
102*17784Sralph 		signal(SIGINT, SIG_DFL);
103*17784Sralph 		open(com, 0);
104*17784Sralph 		sleep(5);
105*17784Sralph 		_exit(1);
106*17784Sralph 	}
107*17784Sralph 
108*17784Sralph 	DEBUG(4, "WAITING FOR ANSWER\n", 0);
109*17784Sralph 	if (read(va, &c, 1) != 1) {
110*17784Sralph 		logent("ACU READ", _FAILED);
111*17784Sralph 		goto failret;
112*17784Sralph 	}
113*17784Sralph 	switch(c) {
114*17784Sralph 	case 'A':
115*17784Sralph 		/* Fine! */
116*17784Sralph 		break;
117*17784Sralph 	case 'B':
118*17784Sralph 		DEBUG(2, "Line Busy / No Answer\n", 0);
119*17784Sralph 		goto failret;
120*17784Sralph 	case 'D':
121*17784Sralph 		DEBUG(2, "Dialer format error\n", 0);
122*17784Sralph 		goto failret;
123*17784Sralph 	case 'E':
124*17784Sralph 		DEBUG(2, "Dialer parity error\n", 0);
125*17784Sralph 		goto failret;
126*17784Sralph 	case 'F':
127*17784Sralph 		DEBUG(2, "Phone number too long\n", 0);
128*17784Sralph 		goto failret;
129*17784Sralph 	case 'G':
130*17784Sralph 		DEBUG(2, "Modem Busy\n", 0);
131*17784Sralph 		goto failret;
132*17784Sralph 	default:
133*17784Sralph 		DEBUG(2, "Unknown MACS return code '%c'\n", c&0177);
134*17784Sralph 		goto failret;
135*17784Sralph 	}
136*17784Sralph 	/*
137*17784Sralph 	 * open line - will return on carrier
138*17784Sralph 	 */
139*17784Sralph 	if ((i = open(com, 2)) < 0) {
140*17784Sralph 		if (errno == EIO)
141*17784Sralph 			logent("carrier", "LOST");
142*17784Sralph 		else
143*17784Sralph 			logent("dialup open", _FAILED);
144*17784Sralph 		goto failret;
145*17784Sralph 	}
146*17784Sralph 	DEBUG(2, "RVADIC opened %d\n", i);
147*17784Sralph 	fixline(i, dev->D_speed);
148*17784Sralph 	goto ret;
149*17784Sralph failret:
150*17784Sralph 	i = CF_DIAL;
151*17784Sralph ret:
152*17784Sralph 	alarm(0);
153*17784Sralph 	if (child != -1)
154*17784Sralph 		kill(child, SIGKILL);
155*17784Sralph 	close(va);
156*17784Sralph 	while ((nw = wait(&lt)) != child && nw != -1)
157*17784Sralph 		;
158*17784Sralph 	return i;
159*17784Sralph }
160*17784Sralph 
161*17784Sralph va820cls(fd)
162*17784Sralph register int fd;
163*17784Sralph {
164*17784Sralph 
165*17784Sralph 	DEBUG(2, "RVADIC close %d\n", fd);
166*17784Sralph 	close(fd);
167*17784Sralph }
168*17784Sralph #endif VA820
169