xref: /csrg-svn/usr.bin/uucp/libacu/sy.c (revision 46875)
117780Sralph #ifndef lint
2*46875Sbostic static char sccsid[] = "@(#)sy.c	4.3 (Berkeley) 03/02/91";
317780Sralph #endif
417780Sralph 
5*46875Sbostic #include "condevs.h"
617780Sralph 
717780Sralph #ifdef SYTEK
817780Sralph 
917780Sralph /*
1017780Sralph  *	sykopn: establish connection through a sytek port.
1117780Sralph  *	Returns descriptor open to tty for reading and writing.
1217780Sralph  *	Negative values (-1...-7) denote errors in connmsg.
1317780Sralph  *	Will try to change baud rate of local port to match
1417780Sralph  *	that of the remote side.
1517780Sralph  */
1617780Sralph char sykspeed[50];	/* speed to reset to on close */
1717780Sralph 
1817780Sralph sykopn(flds)
1917780Sralph register char *flds[];
2017780Sralph {
2117780Sralph 	extern errno;
2217780Sralph 	char *rindex(), *fdig(), dcname[20];
2317780Sralph 	int dh, ok = 0, speed;
2417780Sralph 	register FILE *dfp;
2517780Sralph 	struct Devices dev;
2617780Sralph 	char speedbuf[50];
2717780Sralph 
2817780Sralph 	dfp = fopen(DEVFILE, "r");
2917780Sralph 	ASSERT(dfp != NULL, "Can't open", DEVFILE, 0);
3017780Sralph 
3117780Sralph 	signal(SIGALRM, alarmtr);
3217780Sralph 	dh = -1;
3317780Sralph 	while(rddev(dfp, &dev) != FAIL) {
3417780Sralph /* we'll set our own speed; F_CLASS is how cynthia configures it every night
3517780Sralph 		if (strcmp(flds[F_CLASS], dev.D_class) != SAME)
3617780Sralph 			continue;
3717780Sralph */
3817780Sralph 		if (snccmp(flds[F_LINE], dev.D_type) != SAME)
3917780Sralph 			continue;
4017780Sralph 		if (mlock(dev.D_line) == FAIL)
4117780Sralph 			continue;
4217780Sralph 
4317780Sralph 		sprintf(dcname, "/dev/%s", dev.D_line);
4417780Sralph 		getnextfd();
4517780Sralph 		alarm(10);
4617780Sralph 		if (setjmp(Sjbuf)) {
4717780Sralph 			delock(dev.D_line);
4817780Sralph 			logent(dev.D_line,"sytek open TIMEOUT");
4917780Sralph 			dh = -1;
5017780Sralph 			break;
5117780Sralph 			}
5217780Sralph 		dh = open(dcname, 2);
5317780Sralph 		alarm(0);
5417780Sralph 		next_fd = -1;
5517780Sralph 		if (dh > 0) {
5617780Sralph 			break;
5717780Sralph 			}
5817780Sralph 		devSel[0] = '\0';
5917780Sralph 		delock(dev.D_line);
6017780Sralph 	}
6117780Sralph 	fclose(dfp);
6217780Sralph 	if (dh < 0)
6317780Sralph 		return(CF_NODEV);
6417780Sralph 
6517780Sralph 	speed = atoi(fdig(dev.D_class));
6617780Sralph 	fixline(dh, speed);
6717780Sralph 	sleep(1);
6817780Sralph 
6917780Sralph 	/* negotiate with sytek */
7017780Sralph 	genbrk(dh, 3);
7117780Sralph 
7217780Sralph 	DEBUG(4, "wanted %s ", "#");
7317780Sralph 	ok = expect("#", dh);
7417780Sralph 	DEBUG(4, "got %s\n", ok ? "?" : "that");
7517780Sralph 	if(ok != 0){
7617780Sralph 		if(atoi(fdig(dev.D_class)) == 9600){
7717780Sralph 			fixline(dh, 2400);
7817780Sralph 			speed = 2400;
7917780Sralph 		} else {
8017780Sralph 			fixline(dh, 9600);
8117780Sralph 			speed = 9600;
8217780Sralph 		}
8317780Sralph 		sleep(1);
8417780Sralph 		genbrk(dh, 3);
8517780Sralph 		ok = expect("#", dh);
8617780Sralph 		if(ok){
8717780Sralph 			close(dh);
8817780Sralph 			DEBUG(4, "sytek BREAK failed\n", "");
8917780Sralph 			delock(dev.D_line);
9017780Sralph 			return(CF_DIAL);
9117780Sralph 		}
9217780Sralph 	}
9317780Sralph 	write(dh, "done \r", 6);
9417780Sralph 	ok = expect("#", dh);
9517780Sralph 	DEBUG(4, "got %s\n", ok ? "?" : "that");
9617780Sralph 	if(speed != atoi(fdig(flds[F_CLASS]))){
9717780Sralph 		DEBUG(4, "changing speed\n", "");
9817780Sralph 		sprintf(speedbuf, "baud %s\r", fdig(flds[F_CLASS]));
9917780Sralph 		write(dh, speedbuf, strlen(speedbuf));
10017780Sralph 		sleep(1);
10117780Sralph 		speed = atoi(fdig(flds[F_CLASS]));
10217780Sralph 		fixline(dh, speed);
10317780Sralph 		genbrk(dh, 3);
10417780Sralph 		ok = expect("#", dh);
10517780Sralph 		DEBUG(4, "speed set %s\n", ok ? "failed" : flds[F_CLASS]);
10617780Sralph 	}
10717780Sralph 	strcpy(sykspeed, dev.D_class);
10817780Sralph 	write(dh, "command break\r", 14);
10917780Sralph 	ok = expect("#", dh);
11017780Sralph 	DEBUG(4, "got %s\n", ok ? "?" : "that");
11117780Sralph 	if (ok == 0) {
11217780Sralph 		write(dh, "call ", 5);
11317780Sralph 		write(dh, flds[F_PHONE], strlen(flds[F_PHONE]));
11417780Sralph 		write(dh, "\r", 1);
11517780Sralph 		DEBUG(4, "sytek dial %s\n", flds[F_PHONE]);
11617780Sralph 		DEBUG(4, "wanted %s ", "COMPLETED TO ");
11717780Sralph 		ok = expect("COMPLETED TO ", dh);
11817780Sralph 		DEBUG(4, "got %s\n", ok ? "?" : "that");
11917780Sralph 	}
12017780Sralph 
12117780Sralph 	if (ok != 0) {
12217780Sralph 		close(dh);
12317780Sralph 		DEBUG(4, "sytek failed\n", "");
12417780Sralph 		delock(dev.D_line);
12517780Sralph 		return(CF_DIAL);
12617780Sralph 	} else
12717780Sralph 		DEBUG(4, "sytek ok\n", "");
12817780Sralph 
12917780Sralph 	CU_end = sykcls;
13017780Sralph 	strcpy(devSel, dev.D_line);	/* for later unlock */
13117780Sralph 	return(dh);
13217780Sralph 
13317780Sralph }
13417780Sralph 
13517780Sralph sykcls(fd)
13617780Sralph register int fd;
13717780Sralph {
13817780Sralph 	register int ok, speed;
13917780Sralph 
14017780Sralph 
14117780Sralph 	if (fd > 0) {
14217780Sralph 		genbrk(fd, 3);
14317780Sralph 		ok = expect("#", fd);
14417780Sralph 		DEBUG(4, "got %s\n", ok ? "?" : "that");
14517780Sralph 		if(ok != 0){
14617780Sralph 			genbrk(fd, 3);
14717780Sralph 			ok = expect("#", fd);
14817780Sralph 		}
14917780Sralph 		if(ok == 0){
15017780Sralph 			write(fd, "done 1\r", 7);
15117780Sralph 			ok = expect("#", fd);
15217780Sralph 			DEBUG(4, "got %s\n", ok ? "?" : "that");
15317780Sralph 			DEBUG(4, "reset baud to %s\n", sykspeed);
15417780Sralph 			write(fd, "baud ", 5);
15517780Sralph 			write(fd, sykspeed, strlen(sykspeed));
15617780Sralph 			write(fd, "\r", 1);
15717780Sralph 			sleep(1);
15817780Sralph 		}
15917780Sralph 		close(fd);
16017780Sralph 		delock(devSel);
16117780Sralph 	}
16217780Sralph }
16317780Sralph #endif SYTEK
164