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