xref: /csrg-svn/usr.bin/uucp/libacu/rvmacs.c (revision 25254)
117779Sralph #ifndef lint
2*25254Sbloom static char sccsid[] = "@(#)rvmacs.c	4.3 (Berkeley) 10/23/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,
1625161Sbloom  * We assume the dialer speed is 1200 baud unless MULTISPEED is defined.
1725161Sbloom  * We extended the semantics of the L-devices entry to allow you
1825161Sbloom  * to set the speed at which the computer talks to the dialer:
1925161Sbloom  *	ACU cul0 cua0,0<,2400 1200 rvmacs
2025161Sbloom  * This is interpreted as above, except that the number following the second
2125161Sbloom  * comma in the third field is taken to be the speed at which the computer
2225161Sbloom  * must communicate with the dialer.  (If omitted, it defaults to the value
2325161Sbloom  * in the fourth field.)  Note -- just after the call completes and you get
2425161Sbloom  * carrier, the line speed is reset to the speed indicated in the fourth field.
2525161Sbloom  * To get this ability, define "MULTISPEED", as below.
2625161Sbloom  *
2717779Sralph  */
2825161Sbloom #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 c, acu[20], com[20];
4417779Sralph 	int baudrate;
4517779Sralph 	int timelim;
4617779Sralph 	int pid, status;
4717779Sralph 	int zero = 0;
48*25254Sbloom #ifdef MULTISPEED
49*25254Sbloom 	char *pp;
50*25254Sbloom #else !MULTISPEED
5117779Sralph 	struct sgttyb sg;
52*25254Sbloom #endif MULTISPEED
5317779Sralph 
5417779Sralph 	child = -1;
5517779Sralph 	sprintf(com, "/dev/%s", dev->D_line);
5617779Sralph 	sprintf(acu, "/dev/%s", dev->D_calldev);
5717779Sralph 	if ((p = index(acu, ',')) == NULL) {
5817779Sralph 		DEBUG(2, "No dialer/modem specification\n", 0);
5917779Sralph 		return CF_DIAL;
6017779Sralph 	}
6117779Sralph 	*p++ = '\0';
6225161Sbloom #ifdef MULTISPEED
6325161Sbloom 	baudrate = dev->D_speed;
6425161Sbloom 	if ((pp = index(p, ',')) != NULL){
6525161Sbloom 		baudrate = atoi(pp+1);
6625161Sbloom 		DEBUG(5, "Using speed %d baud\n", baudrate);
6725161Sbloom 	}
6825161Sbloom #endif MULTISPEED
6917779Sralph 	if (setjmp(Sjbuf)) {
7017779Sralph 		logent("rvmacsopn", "TIMEOUT");
7117779Sralph 		goto failret;
7217779Sralph 	}
7317779Sralph 	DEBUG(4, "STARTING CALL\n", 0);
7417779Sralph 	getnextfd();
7517779Sralph 	signal(SIGALRM, alarmtr);
7617779Sralph 	timelim = 5 * strlen(ph);
7717779Sralph 	alarm(timelim < 45 ? 45 : timelim);
7817779Sralph 
7917779Sralph 	if ((va = open(acu, 2)) < 0) {
8017779Sralph 		logent(acu, "CAN'T OPEN");
8117779Sralph 		alarm(0);
8217779Sralph 		return CF_DIAL;
8317779Sralph 	}
8417779Sralph 
8517779Sralph 	/* rti!trt: avoid passing acu file descriptor to children */
8617779Sralph 	next_fd = -1;
8717779Sralph 	fioclex(va);
8817779Sralph 
8917779Sralph 	if ((child = fork()) == 0) {
9017779Sralph 		/* create child to do dialing */
9117779Sralph 		sleep(2);
9217779Sralph 		fclose(stdin);
9317779Sralph 		fclose(stdout);
9425161Sbloom #ifdef MULTISPEED
9525161Sbloom 		fixline(va, baudrate);
9625161Sbloom #else !MULTISPEED
9717779Sralph 		sg.sg_flags = RAW|ANYP;
9817779Sralph 		sg.sg_ispeed = sg.sg_ospeed = B1200;
9917779Sralph 		ioctl(va, TIOCSETP, &sg);
10025161Sbloom #endif MULTISPEED
10117779Sralph 		pc(va, ABORT);
10217779Sralph 		sleep(1);
10317779Sralph 		ioctl(va, TIOCFLUSH, &zero);
10417779Sralph 		pc(va, STX);	/* access adaptor */
10517779Sralph 		pc(va, *p++);	/* Send Dialer Address Digit */
10617779Sralph 		pc(va, *p);	/* Send Modem Address Digit */
10717779Sralph 		while (*ph && *ph != '<') {
10817779Sralph 			switch (*ph) {
10917779Sralph 			case '_':
11017779Sralph 			case '-':
11117779Sralph 			case '=':
11217779Sralph 				pc(va, '=');
11317779Sralph 				break;
11417779Sralph 			default:
11517779Sralph 				if (*ph >= '0' && *ph <= '9')
11617779Sralph 					pc(va, *ph);
11717779Sralph 				break;
11817779Sralph 			}
11917779Sralph 			ph++;
12017779Sralph 		}
12117779Sralph 		pc(va, '<');	/* Transfer Control to Modem (sigh) */
12217779Sralph 		pc(va, SI);	/* Send Buffer Empty */
12317779Sralph 		pc(va, ETX);	/* Initiate Call */
12417779Sralph 		sleep(1);
12517779Sralph 
12617779Sralph 		if (read(va, &c, 1) != 1) {
12717779Sralph 			close(va);
12817779Sralph 			logent("ACU READ", _FAILED);
12917779Sralph 			exit(1);
13017779Sralph 		}
13117779Sralph 		if (c == 'B' || c == 'G') {
13217779Sralph 			char cc;
13317779Sralph 			pc(va, ABORT);
13417779Sralph 			read(va, &cc, 1);
13517779Sralph 		}
13617779Sralph 		DEBUG(4, "Dialer returned %c\n", c);
13717779Sralph 		close(va);
13817779Sralph 		exit(c != 'A');
13917779Sralph 	}
14017779Sralph 	/*
14117779Sralph 	 * open line - will return on carrier
14217779Sralph 	 */
14317779Sralph 	if ((i = open(com, 2)) < 0) {
14417779Sralph 		if (errno == EIO)
14517779Sralph 			logent("carrier", "LOST");
14617779Sralph 		else
14717779Sralph 			logent("dialup open", _FAILED);
14817779Sralph 		goto failret;
14917779Sralph 	}
15017779Sralph 	while ((pid = wait(&status)) != child && pid != -1)
15117779Sralph 		;
15217779Sralph 	alarm(0);
15317779Sralph 	if (status) {
15417779Sralph 		close(i);
15517779Sralph 		close(va);		/* XXX */
15617779Sralph 		return CF_DIAL;
15717779Sralph 	}
15817779Sralph 	fixline(i, dev->D_speed);
15917779Sralph 	return i;
16017779Sralph 
16117779Sralph failret:
16217779Sralph 	alarm(0);
16317779Sralph 	close(va);
16417779Sralph 	if (child != -1)
16517779Sralph 		kill(child, SIGKILL);
16617779Sralph 	return CF_DIAL;
16717779Sralph }
16817779Sralph 
16917779Sralph rvmacscls(fd)
17017779Sralph register int fd;
17117779Sralph {
17217779Sralph 	if (fd > 0) {
17317779Sralph 		ioctl(fd, TIOCCDTR, STBNULL);
17417779Sralph 		sleep(1);
17517779Sralph 		ioctl(fd, TIOCNXCL, STBNULL);
17617779Sralph 		close(fd);
17717779Sralph 		delock(devSel);
17817779Sralph 	}
17917779Sralph }
18017779Sralph #endif
181