xref: /csrg-svn/usr.bin/uucp/libacu/rvmacs.c (revision 17779)
1*17779Sralph #ifndef lint
2*17779Sralph static char sccsid[] = "@(#)rvmacs.c	4.1 (Berkeley) 01/22/85";
3*17779Sralph #endif
4*17779Sralph 
5*17779Sralph #include "../condevs.h"
6*17779Sralph #ifdef	RVMACS
7*17779Sralph 
8*17779Sralph /*
9*17779Sralph  * Racal-Vadic 'RV820' MACS system with 831 adaptor.
10*17779Sralph  * A typical 300 baud L-devices entry is
11*17779Sralph  *	ACU tty10 tty11,48 300 rvmacs
12*17779Sralph  * where tty10 is the communication line (D_Line),
13*17779Sralph  * tty11 is the dialer line (D_calldev),
14*17779Sralph  * the '4' is the dialer address + modem type (viz. dialer 0, Bell 103),
15*17779Sralph  * the '8' is the communication port,
16*17779Sralph  * We assume the dialer speed is 1200 baud.
17*17779Sralph  */
18*17779Sralph 
19*17779Sralph #define	STX	02	/* Access Adaptor */
20*17779Sralph #define	ETX	03	/* Transfer to Dialer */
21*17779Sralph #define	SI	017	/* Buffer Empty (end of phone number) */
22*17779Sralph #define	ABORT	01	/* Abort */
23*17779Sralph 
24*17779Sralph #define	pc(fd, x)	(c = x, write(fd, &c, 1))
25*17779Sralph 
26*17779Sralph rvmacsopn(ph, flds, dev)
27*17779Sralph char *ph, *flds[];
28*17779Sralph struct Devices *dev;
29*17779Sralph {
30*17779Sralph 	register int va, i, child;
31*17779Sralph 	register char *p;
32*17779Sralph 	char *q;
33*17779Sralph 	char c, acu[20], com[20];
34*17779Sralph 	int baudrate;
35*17779Sralph 	int timelim;
36*17779Sralph 	int pid, status;
37*17779Sralph 	int zero = 0;
38*17779Sralph 	struct sgttyb sg;
39*17779Sralph 
40*17779Sralph 	child = -1;
41*17779Sralph 	sprintf(com, "/dev/%s", dev->D_line);
42*17779Sralph 	sprintf(acu, "/dev/%s", dev->D_calldev);
43*17779Sralph 	if ((p = index(acu, ',')) == NULL) {
44*17779Sralph 		DEBUG(2, "No dialer/modem specification\n", 0);
45*17779Sralph 		return CF_DIAL;
46*17779Sralph 	}
47*17779Sralph 	*p++ = '\0';
48*17779Sralph 	if (setjmp(Sjbuf)) {
49*17779Sralph 		logent("rvmacsopn", "TIMEOUT");
50*17779Sralph 		goto failret;
51*17779Sralph 	}
52*17779Sralph 	DEBUG(4, "STARTING CALL\n", 0);
53*17779Sralph 	getnextfd();
54*17779Sralph 	signal(SIGALRM, alarmtr);
55*17779Sralph 	timelim = 5 * strlen(ph);
56*17779Sralph 	alarm(timelim < 45 ? 45 : timelim);
57*17779Sralph 
58*17779Sralph 	if ((va = open(acu, 2)) < 0) {
59*17779Sralph 		logent(acu, "CAN'T OPEN");
60*17779Sralph 		alarm(0);
61*17779Sralph 		return CF_DIAL;
62*17779Sralph 	}
63*17779Sralph 
64*17779Sralph 	/* rti!trt: avoid passing acu file descriptor to children */
65*17779Sralph 	next_fd = -1;
66*17779Sralph 	fioclex(va);
67*17779Sralph 
68*17779Sralph 	if ((child = fork()) == 0) {
69*17779Sralph 		/* create child to do dialing */
70*17779Sralph 		sleep(2);
71*17779Sralph 		fclose(stdin);
72*17779Sralph 		fclose(stdout);
73*17779Sralph 		sg.sg_flags = RAW|ANYP;
74*17779Sralph 		sg.sg_ispeed = sg.sg_ospeed = B1200;
75*17779Sralph 		ioctl(va, TIOCSETP, &sg);
76*17779Sralph 		pc(va, ABORT);
77*17779Sralph 		sleep(1);
78*17779Sralph 		ioctl(va, TIOCFLUSH, &zero);
79*17779Sralph 		pc(va, STX);	/* access adaptor */
80*17779Sralph 		pc(va, *p++);	/* Send Dialer Address Digit */
81*17779Sralph 		pc(va, *p);	/* Send Modem Address Digit */
82*17779Sralph 		while (*ph && *ph != '<') {
83*17779Sralph 			switch (*ph) {
84*17779Sralph 			case '_':
85*17779Sralph 			case '-':
86*17779Sralph 			case '=':
87*17779Sralph 				pc(va, '=');
88*17779Sralph 				break;
89*17779Sralph 			default:
90*17779Sralph 				if (*ph >= '0' && *ph <= '9')
91*17779Sralph 					pc(va, *ph);
92*17779Sralph 				break;
93*17779Sralph 			}
94*17779Sralph 			ph++;
95*17779Sralph 		}
96*17779Sralph 		pc(va, '<');	/* Transfer Control to Modem (sigh) */
97*17779Sralph 		pc(va, SI);	/* Send Buffer Empty */
98*17779Sralph 		pc(va, ETX);	/* Initiate Call */
99*17779Sralph 		sleep(1);
100*17779Sralph 
101*17779Sralph 		if (read(va, &c, 1) != 1) {
102*17779Sralph 			close(va);
103*17779Sralph 			logent("ACU READ", _FAILED);
104*17779Sralph 			exit(1);
105*17779Sralph 		}
106*17779Sralph 		if (c == 'B' || c == 'G') {
107*17779Sralph 			char cc;
108*17779Sralph 			pc(va, ABORT);
109*17779Sralph 			read(va, &cc, 1);
110*17779Sralph 		}
111*17779Sralph 		DEBUG(4, "Dialer returned %c\n", c);
112*17779Sralph 		close(va);
113*17779Sralph 		exit(c != 'A');
114*17779Sralph 	}
115*17779Sralph 	/*
116*17779Sralph 	 * open line - will return on carrier
117*17779Sralph 	 */
118*17779Sralph 	if ((i = open(com, 2)) < 0) {
119*17779Sralph 		if (errno == EIO)
120*17779Sralph 			logent("carrier", "LOST");
121*17779Sralph 		else
122*17779Sralph 			logent("dialup open", _FAILED);
123*17779Sralph 		goto failret;
124*17779Sralph 	}
125*17779Sralph 	while ((pid = wait(&status)) != child && pid != -1)
126*17779Sralph 		;
127*17779Sralph 	alarm(0);
128*17779Sralph 	if (status) {
129*17779Sralph 		close(i);
130*17779Sralph 		close(va);		/* XXX */
131*17779Sralph 		return CF_DIAL;
132*17779Sralph 	}
133*17779Sralph 	fixline(i, dev->D_speed);
134*17779Sralph 	return i;
135*17779Sralph 
136*17779Sralph failret:
137*17779Sralph 	alarm(0);
138*17779Sralph 	close(va);
139*17779Sralph 	if (child != -1)
140*17779Sralph 		kill(child, SIGKILL);
141*17779Sralph 	return CF_DIAL;
142*17779Sralph }
143*17779Sralph 
144*17779Sralph rvmacscls(fd)
145*17779Sralph register int fd;
146*17779Sralph {
147*17779Sralph 	if (fd > 0) {
148*17779Sralph 		ioctl(fd, TIOCCDTR, STBNULL);
149*17779Sralph 		sleep(1);
150*17779Sralph 		ioctl(fd, TIOCNXCL, STBNULL);
151*17779Sralph 		close(fd);
152*17779Sralph 		delock(devSel);
153*17779Sralph 	}
154*17779Sralph }
155*17779Sralph #endif
156