xref: /csrg-svn/usr.bin/uucp/libacu/pen.c (revision 46875)
118564Sralph #ifndef lint
2*46875Sbostic static char sccsid[] = "@(#)pen.c	4.4 (Berkeley) 03/02/91";
318564Sralph #endif
418564Sralph 
518564Sralph /*
618564Sralph  *	Speaker's quick and dirty penril hack.  STA 4/1/85.
718564Sralph  */
8*46875Sbostic #include "condevs.h"
918564Sralph 
1018564Sralph penopn(telno, flds, dev)
1118564Sralph char *flds[], *telno;
1218564Sralph struct Devices *dev;
1318564Sralph {
1418564Sralph 	int	dh;
1518564Sralph 	int	i, ok = -1;
1618564Sralph 	char dcname[20];
1718564Sralph 
1818564Sralph 	sprintf(dcname, "/dev/%s", dev->D_line);
1918564Sralph 	if (setjmp(Sjbuf)) {
2018564Sralph 		DEBUG(1, "timeout penril open\n", "");
2118564Sralph 		logent("penril open", "TIMEOUT");
2218564Sralph 		if (dh >= 0)
2318564Sralph 			close(dh);
2418564Sralph 		delock(dev->D_line);
2518564Sralph 		return CF_NODEV;
2618564Sralph 	}
2718564Sralph 	signal(SIGALRM, alarmtr);
2818564Sralph 	getnextfd();
2918564Sralph 	alarm(10);
3018564Sralph 	dh = open(dcname, 2);
3125155Sbloom 	alarm(0);
3218564Sralph 	next_fd = -1;
3318564Sralph 	if (dh < 0) {
3418564Sralph 		DEBUG(4,"%s\n", errno == 4 ? "no carrier" : "can't open modem");
3518564Sralph 		delock(dev->D_line);
3618564Sralph 		return errno == 4 ? CF_DIAL : CF_NODEV;
3718564Sralph 	}
3818564Sralph 
3918564Sralph 	/* modem is open */
4018564Sralph 	fixline(dh, dev->D_speed);
4118564Sralph 
4218564Sralph 	/* translate - to P and = to W for Penril */
4318564Sralph 	DEBUG(4, "calling %s -> ", telno);
4418564Sralph 	for (i = 0; i < strlen(telno); ++i) {
4518564Sralph 		switch(telno[i]) {
4618564Sralph 		case '-':	/* delay */
4718564Sralph 			telno[i] = 'P';
4818564Sralph 			break;
4918564Sralph 		case '=':	/* await dial tone */
5018564Sralph 			telno[i] = 'W';
5118564Sralph 			break;
5218564Sralph 		case '<':
5318564Sralph 			telno[i] = 'P';
5418564Sralph 			break;
5518564Sralph 		}
5618564Sralph 	}
5718564Sralph 	DEBUG(4, "%s\n", telno);
5818564Sralph 	sleep(1);
5918564Sralph 	for(i = 0; i < 5; ++i) {	/* make up to 5 tries */
6018564Sralph 		slowrite(dh, "\r");/* awake, thou lowly Penril! */
6118564Sralph 
6218564Sralph 		DEBUG(4, "wanted %s ", ">");
6318564Sralph 		ok = expect(">", dh);
6418564Sralph 		DEBUG(4, "got %s\n", ok ? "?" : "that");
6518564Sralph 		if (ok != 0)
6618564Sralph 			continue;
6718564Sralph 		slowrite(dh, "K");	/* "K" (enter number) command */
6818564Sralph 		DEBUG(4, "wanted %s ", "NO.: ");
6918564Sralph 		ok = expect("NO.: ", dh);
7018564Sralph 		DEBUG(4, "got %s\n", ok ? "?" : "that");
7118564Sralph 		if (ok == 0)
7218564Sralph 			break;
7318564Sralph 	}
7418564Sralph 
7518564Sralph 	if (ok == 0) {
7618564Sralph 		slowrite(dh, telno); /* send telno, send \r */
7718564Sralph 		slowrite(dh, "\r");
7818564Sralph 		DEBUG(4, "wanted %s ", "OK");
7918564Sralph 		ok = expect("OK", dh);
8018564Sralph 		DEBUG(4, "got %s\n", ok ? "?" : "that");
8118564Sralph 	}
8218564Sralph 	if (ok != 0) {
8318564Sralph 		if (dh > 2)
8418564Sralph 			close(dh);
8518564Sralph 		DEBUG(4, "penDial failed\n", "");
8618564Sralph 		return CF_DIAL;
8718564Sralph 	}
8818564Sralph 	else
8918564Sralph 		DEBUG(4, "penDial ok\n", "");
9018564Sralph 	return dh;
9118564Sralph }
9218564Sralph 
9318564Sralph pencls(fd)
9418564Sralph int fd;
9518564Sralph {
9618564Sralph 	if (fd > 0) {
9718564Sralph 		close(fd);
9818564Sralph 		sleep(5);
9918564Sralph 		delock(devSel);
10018564Sralph 	}
10118564Sralph }
102