xref: /csrg-svn/usr.bin/uucp/libacu/va820.c (revision 25160)
117784Sralph #ifndef lint
2*25160Sbloom static char sccsid[] = "@(#)va820.c	4.3 (Berkeley) 10/10/85";
317784Sralph #endif
417784Sralph 
517784Sralph #include "../condevs.h"
617784Sralph #ifdef	VA820
717784Sralph 
817784Sralph /*
917784Sralph  * Racal-Vadic 'RV820' with 831 adaptor.
1017784Sralph  * BUGS:
1117784Sralph  * dialer baud rate is hardcoded
1217784Sralph  */
1317784Sralph #define	MAXDIG 30	/* set by switches inside adapter */
1417784Sralph char	c_abort	= '\001';
1517784Sralph char	c_start	= '\002';
1617784Sralph char	c_empty	= '\017';
1717784Sralph char	c_end	= '\003';
1817784Sralph 
1917784Sralph va820opn(ph, flds, dev)
2017784Sralph char *ph, *flds[];
2117784Sralph struct Devices *dev;
2217784Sralph {
2317784Sralph 	register int va, i, child;
2417784Sralph 	char c, acu[20], com[20];
2517784Sralph 	char vadbuf[MAXDIG+2];
2617784Sralph 	int nw, lt;
2717784Sralph 	unsigned timelim;
2817784Sralph 	struct sgttyb sg;
2917784Sralph 
3017784Sralph 	child = -1;
3117784Sralph 	if (strlen(ph) > MAXDIG) {
3217784Sralph 		DEBUG(4, "BAD PHONE NUMBER %s\n", ph);
3317784Sralph 		logent("rvadopn", "BAD PHONE NUMBER");
3417784Sralph 		i = CF_DIAL;
3517784Sralph 		goto ret;
3617784Sralph 	}
3717784Sralph 
3817784Sralph 	if (setjmp(Sjbuf)) {
3917784Sralph 		logent("rvadopn", "TIMEOUT");
4017784Sralph 		i = CF_DIAL;
4117784Sralph 		goto ret;
4217784Sralph 	}
4317784Sralph 	DEBUG(4, "ACU %s\n", dev->D_calldev);
4417784Sralph 	DEBUG(4, "LINE %s\n", dev->D_line);
4517784Sralph 	sprintf(acu, "/dev/%s", dev->D_calldev);
4617784Sralph 	getnextfd();
4717784Sralph 	signal(SIGALRM, alarmtr);
4817784Sralph 	alarm(10);
49*25160Sbloom 	va = open(acu, 2);
50*25160Sbloom 	alarm(0);
51*25160Sbloom 	next_fd = -1;
52*25160Sbloom 	if (va < 0) {
5317784Sralph 		DEBUG(4, "ACU OPEN FAIL %d\n", errno);
5417784Sralph 		logent(acu, "CAN'T OPEN");
5517784Sralph 		i = CF_NODEV;
5617784Sralph 		goto ret;
5717784Sralph 	}
5817784Sralph 	/*
5917784Sralph 	 * Set speed and modes on dialer and clear any
6017784Sralph 	 * previous requests
6117784Sralph 	 */
6217784Sralph 	DEBUG(4, "SETTING UP VA831 (%d)\n", va);
6317784Sralph 	ioctl(va, TIOCGETP, &sg);
6417784Sralph 	sg.sg_ispeed = sg.sg_ospeed = B1200;
6517784Sralph 	sg.sg_flags |= RAW;
6617784Sralph 	sg.sg_flags &= ~ECHO;
6717784Sralph 	ioctl(va, TIOCSETP, &sg);
6817784Sralph 	DEBUG(4, "CLEARING VA831\n", 0);
6917784Sralph 	if ( write(va, &c_abort, 1) != 1) {
7017784Sralph 		DEBUG(4,"BAD VA831 WRITE %d\n", errno);
7117784Sralph 		logent(acu, "CAN'T CLEAR");
7217784Sralph 		i = CF_DIAL;
7317784Sralph 		goto ret;
7417784Sralph 	}
7517784Sralph 	sleep(1);			/* XXX */
7617784Sralph 	read(va, &c, 1);
7717784Sralph 	if (c != 'B') {
7817784Sralph 		DEBUG(4,"BAD VA831 RESPONSE %c\n", c);
7917784Sralph 		logent(acu, "CAN'T CLEAR");
8017784Sralph 		i = CF_DIAL;
8117784Sralph 		goto ret;
8217784Sralph 	}
8317784Sralph 	/*
8417784Sralph 	 * Build the dialing sequence for the adapter
8517784Sralph 	 */
8617784Sralph 	DEBUG(4, "DIALING %s\n", ph);
8723704Sbloom 	sprintf(vadbuf, "%c%s<%c%c", c_start, ph, c_empty, c_end);
8817784Sralph 	timelim = 5 * strlen(ph);
8917784Sralph 	alarm(timelim < 30 ? 30 : timelim);
9017784Sralph 	nw = write(va, vadbuf, strlen(vadbuf));	/* Send Phone Number */
9117784Sralph 	if (nw != strlen(vadbuf)) {
9217784Sralph 		DEBUG(4,"BAD VA831 WRITE %d\n", nw);
9317784Sralph 		logent(acu, "BAD WRITE");
9417784Sralph 		goto failret;
9517784Sralph 	}
9617784Sralph 
9717784Sralph 	sprintf(com, "/dev/%s", dev->D_line);
9817784Sralph 
9917784Sralph 	/* create child to open comm line */
10017784Sralph 	if ((child = fork()) == 0) {
10117784Sralph 		signal(SIGINT, SIG_DFL);
10217784Sralph 		open(com, 0);
10317784Sralph 		sleep(5);
10417784Sralph 		_exit(1);
10517784Sralph 	}
10617784Sralph 
10717784Sralph 	DEBUG(4, "WAITING FOR ANSWER\n", 0);
10817784Sralph 	if (read(va, &c, 1) != 1) {
10917784Sralph 		logent("ACU READ", _FAILED);
11017784Sralph 		goto failret;
11117784Sralph 	}
11217784Sralph 	switch(c) {
11317784Sralph 	case 'A':
11417784Sralph 		/* Fine! */
11517784Sralph 		break;
11617784Sralph 	case 'B':
11717784Sralph 		DEBUG(2, "Line Busy / No Answer\n", 0);
11817784Sralph 		goto failret;
11917784Sralph 	case 'D':
12017784Sralph 		DEBUG(2, "Dialer format error\n", 0);
12117784Sralph 		goto failret;
12217784Sralph 	case 'E':
12317784Sralph 		DEBUG(2, "Dialer parity error\n", 0);
12417784Sralph 		goto failret;
12517784Sralph 	case 'F':
12617784Sralph 		DEBUG(2, "Phone number too long\n", 0);
12717784Sralph 		goto failret;
12817784Sralph 	case 'G':
12917784Sralph 		DEBUG(2, "Modem Busy\n", 0);
13017784Sralph 		goto failret;
13117784Sralph 	default:
13217784Sralph 		DEBUG(2, "Unknown MACS return code '%c'\n", c&0177);
13317784Sralph 		goto failret;
13417784Sralph 	}
13517784Sralph 	/*
13617784Sralph 	 * open line - will return on carrier
13717784Sralph 	 */
13817784Sralph 	if ((i = open(com, 2)) < 0) {
13917784Sralph 		if (errno == EIO)
14017784Sralph 			logent("carrier", "LOST");
14117784Sralph 		else
14217784Sralph 			logent("dialup open", _FAILED);
14317784Sralph 		goto failret;
14417784Sralph 	}
14517784Sralph 	DEBUG(2, "RVADIC opened %d\n", i);
14617784Sralph 	fixline(i, dev->D_speed);
14717784Sralph 	goto ret;
14817784Sralph failret:
14917784Sralph 	i = CF_DIAL;
15017784Sralph ret:
15117784Sralph 	alarm(0);
15217784Sralph 	if (child != -1)
15317784Sralph 		kill(child, SIGKILL);
15417784Sralph 	close(va);
15517784Sralph 	while ((nw = wait(&lt)) != child && nw != -1)
15617784Sralph 		;
15717784Sralph 	return i;
15817784Sralph }
15917784Sralph 
16017784Sralph va820cls(fd)
16117784Sralph register int fd;
16217784Sralph {
16317784Sralph 
16417784Sralph 	DEBUG(2, "RVADIC close %d\n", fd);
16517784Sralph 	close(fd);
16617784Sralph }
16717784Sralph #endif VA820
168