xref: /csrg-svn/usr.bin/uucp/libacu/rvmacs.c (revision 25161)
117779Sralph #ifndef lint
2*25161Sbloom static char sccsid[] = "@(#)rvmacs.c	4.2 (Berkeley) 10/10/85";
317779Sralph #endif
417779Sralph 
517779Sralph #include "../condevs.h"
617779Sralph #ifdef	RVMACS
717779Sralph 
817779Sralph /*
917779Sralph  * Racal-Vadic 'RV820' MACS system with 831 adaptor.
1017779Sralph  * A typical 300 baud L-devices entry is
1117779Sralph  *	ACU tty10 tty11,48 300 rvmacs
1217779Sralph  * where tty10 is the communication line (D_Line),
1317779Sralph  * tty11 is the dialer line (D_calldev),
1417779Sralph  * the '4' is the dialer address + modem type (viz. dialer 0, Bell 103),
1517779Sralph  * the '8' is the communication port,
16*25161Sbloom  * We assume the dialer speed is 1200 baud unless MULTISPEED is defined.
17*25161Sbloom  * We extended the semantics of the L-devices entry to allow you
18*25161Sbloom  * to set the speed at which the computer talks to the dialer:
19*25161Sbloom  *	ACU cul0 cua0,0<,2400 1200 rvmacs
20*25161Sbloom  * This is interpreted as above, except that the number following the second
21*25161Sbloom  * comma in the third field is taken to be the speed at which the computer
22*25161Sbloom  * must communicate with the dialer.  (If omitted, it defaults to the value
23*25161Sbloom  * in the fourth field.)  Note -- just after the call completes and you get
24*25161Sbloom  * carrier, the line speed is reset to the speed indicated in the fourth field.
25*25161Sbloom  * To get this ability, define "MULTISPEED", as below.
26*25161Sbloom  *
2717779Sralph  */
28*25161Sbloom #define MULTISPEED		/* for dialers which work at various speeds */
2917779Sralph 
3017779Sralph #define	STX	02	/* Access Adaptor */
3117779Sralph #define	ETX	03	/* Transfer to Dialer */
3217779Sralph #define	SI	017	/* Buffer Empty (end of phone number) */
3317779Sralph #define	ABORT	01	/* Abort */
3417779Sralph 
3517779Sralph #define	pc(fd, x)	(c = x, write(fd, &c, 1))
3617779Sralph 
3717779Sralph rvmacsopn(ph, flds, dev)
3817779Sralph char *ph, *flds[];
3917779Sralph struct Devices *dev;
4017779Sralph {
4117779Sralph 	register int va, i, child;
4217779Sralph 	register char *p;
4317779Sralph 	char *q;
4417779Sralph 	char c, acu[20], com[20];
4517779Sralph 	int baudrate;
4617779Sralph 	int timelim;
4717779Sralph 	int pid, status;
4817779Sralph 	int zero = 0;
4917779Sralph 	struct sgttyb sg;
5017779Sralph 
5117779Sralph 	child = -1;
5217779Sralph 	sprintf(com, "/dev/%s", dev->D_line);
5317779Sralph 	sprintf(acu, "/dev/%s", dev->D_calldev);
5417779Sralph 	if ((p = index(acu, ',')) == NULL) {
5517779Sralph 		DEBUG(2, "No dialer/modem specification\n", 0);
5617779Sralph 		return CF_DIAL;
5717779Sralph 	}
5817779Sralph 	*p++ = '\0';
59*25161Sbloom #ifdef MULTISPEED
60*25161Sbloom 	baudrate = dev->D_speed;
61*25161Sbloom 	if ((pp = index(p, ',')) != NULL){
62*25161Sbloom 		baudrate = atoi(pp+1);
63*25161Sbloom 		DEBUG(5, "Using speed %d baud\n", baudrate);
64*25161Sbloom 	}
65*25161Sbloom #endif MULTISPEED
6617779Sralph 	if (setjmp(Sjbuf)) {
6717779Sralph 		logent("rvmacsopn", "TIMEOUT");
6817779Sralph 		goto failret;
6917779Sralph 	}
7017779Sralph 	DEBUG(4, "STARTING CALL\n", 0);
7117779Sralph 	getnextfd();
7217779Sralph 	signal(SIGALRM, alarmtr);
7317779Sralph 	timelim = 5 * strlen(ph);
7417779Sralph 	alarm(timelim < 45 ? 45 : timelim);
7517779Sralph 
7617779Sralph 	if ((va = open(acu, 2)) < 0) {
7717779Sralph 		logent(acu, "CAN'T OPEN");
7817779Sralph 		alarm(0);
7917779Sralph 		return CF_DIAL;
8017779Sralph 	}
8117779Sralph 
8217779Sralph 	/* rti!trt: avoid passing acu file descriptor to children */
8317779Sralph 	next_fd = -1;
8417779Sralph 	fioclex(va);
8517779Sralph 
8617779Sralph 	if ((child = fork()) == 0) {
8717779Sralph 		/* create child to do dialing */
8817779Sralph 		sleep(2);
8917779Sralph 		fclose(stdin);
9017779Sralph 		fclose(stdout);
91*25161Sbloom #ifdef MULTISPEED
92*25161Sbloom 		fixline(va, baudrate);
93*25161Sbloom #else !MULTISPEED
9417779Sralph 		sg.sg_flags = RAW|ANYP;
9517779Sralph 		sg.sg_ispeed = sg.sg_ospeed = B1200;
9617779Sralph 		ioctl(va, TIOCSETP, &sg);
97*25161Sbloom #endif MULTISPEED
9817779Sralph 		pc(va, ABORT);
9917779Sralph 		sleep(1);
10017779Sralph 		ioctl(va, TIOCFLUSH, &zero);
10117779Sralph 		pc(va, STX);	/* access adaptor */
10217779Sralph 		pc(va, *p++);	/* Send Dialer Address Digit */
10317779Sralph 		pc(va, *p);	/* Send Modem Address Digit */
10417779Sralph 		while (*ph && *ph != '<') {
10517779Sralph 			switch (*ph) {
10617779Sralph 			case '_':
10717779Sralph 			case '-':
10817779Sralph 			case '=':
10917779Sralph 				pc(va, '=');
11017779Sralph 				break;
11117779Sralph 			default:
11217779Sralph 				if (*ph >= '0' && *ph <= '9')
11317779Sralph 					pc(va, *ph);
11417779Sralph 				break;
11517779Sralph 			}
11617779Sralph 			ph++;
11717779Sralph 		}
11817779Sralph 		pc(va, '<');	/* Transfer Control to Modem (sigh) */
11917779Sralph 		pc(va, SI);	/* Send Buffer Empty */
12017779Sralph 		pc(va, ETX);	/* Initiate Call */
12117779Sralph 		sleep(1);
12217779Sralph 
12317779Sralph 		if (read(va, &c, 1) != 1) {
12417779Sralph 			close(va);
12517779Sralph 			logent("ACU READ", _FAILED);
12617779Sralph 			exit(1);
12717779Sralph 		}
12817779Sralph 		if (c == 'B' || c == 'G') {
12917779Sralph 			char cc;
13017779Sralph 			pc(va, ABORT);
13117779Sralph 			read(va, &cc, 1);
13217779Sralph 		}
13317779Sralph 		DEBUG(4, "Dialer returned %c\n", c);
13417779Sralph 		close(va);
13517779Sralph 		exit(c != 'A');
13617779Sralph 	}
13717779Sralph 	/*
13817779Sralph 	 * open line - will return on carrier
13917779Sralph 	 */
14017779Sralph 	if ((i = open(com, 2)) < 0) {
14117779Sralph 		if (errno == EIO)
14217779Sralph 			logent("carrier", "LOST");
14317779Sralph 		else
14417779Sralph 			logent("dialup open", _FAILED);
14517779Sralph 		goto failret;
14617779Sralph 	}
14717779Sralph 	while ((pid = wait(&status)) != child && pid != -1)
14817779Sralph 		;
14917779Sralph 	alarm(0);
15017779Sralph 	if (status) {
15117779Sralph 		close(i);
15217779Sralph 		close(va);		/* XXX */
15317779Sralph 		return CF_DIAL;
15417779Sralph 	}
15517779Sralph 	fixline(i, dev->D_speed);
15617779Sralph 	return i;
15717779Sralph 
15817779Sralph failret:
15917779Sralph 	alarm(0);
16017779Sralph 	close(va);
16117779Sralph 	if (child != -1)
16217779Sralph 		kill(child, SIGKILL);
16317779Sralph 	return CF_DIAL;
16417779Sralph }
16517779Sralph 
16617779Sralph rvmacscls(fd)
16717779Sralph register int fd;
16817779Sralph {
16917779Sralph 	if (fd > 0) {
17017779Sralph 		ioctl(fd, TIOCCDTR, STBNULL);
17117779Sralph 		sleep(1);
17217779Sralph 		ioctl(fd, TIOCNXCL, STBNULL);
17317779Sralph 		close(fd);
17417779Sralph 		delock(devSel);
17517779Sralph 	}
17617779Sralph }
17717779Sralph #endif
178