xref: /csrg-svn/usr.bin/uucp/libacu/nov.c (revision 46875)
117777Sralph #ifndef lint
2*46875Sbostic static char sccsid[] = "@(#)nov.c	4.3 (Berkeley) 03/02/91";
317777Sralph #endif
417777Sralph 
5*46875Sbostic #include "condevs.h"
617777Sralph 
717777Sralph /***
817777Sralph  *	novopn(telno, flds, dev) connect to novation Smart-Cat
917777Sralph  *	(similar to hayes smartmodem)
1017777Sralph  *	char *flds[], *dev[];
1117777Sralph  *
1217777Sralph  *	return codes:
1317777Sralph  *		>0  -  file number  -  ok
1417777Sralph  *		CF_DIAL,CF_DEVICE  -  failed
1517777Sralph  */
1617777Sralph 
1717777Sralph novopn(telno, flds, dev)
1817777Sralph char *telno;
1917777Sralph char *flds[];
2017777Sralph struct Devices *dev;
2117777Sralph {
2217777Sralph 	int	dh = -1;
2317777Sralph 	extern errno;
2417777Sralph 	char dcname[20];
2517777Sralph 	int pulse = 0;
2617777Sralph 
2717777Sralph 	sprintf(dcname, "/dev/%s", dev->D_line);
2817777Sralph 	DEBUG(4, "dc - %s\n", dcname);
2917777Sralph 	if (strcmp(dev->D_calldev, "pulse") == 0)
3017777Sralph 		pulse = 1;
3117777Sralph 	if (setjmp(Sjbuf)) {
3217777Sralph 		DEBUG(1, "timeout novation open %s\n", dcname);
3317777Sralph 		logent("novation open", "TIMEOUT");
3417777Sralph 		if (dh >= 0)
3517777Sralph 			close(dh);
3617777Sralph 		delock(dev->D_line);
3717777Sralph 		return CF_DIAL;
3817777Sralph 	}
3917777Sralph 	signal(SIGALRM, alarmtr);
4017777Sralph 	getnextfd();
4117777Sralph 	alarm(10);
4217777Sralph 	dh = open(dcname, 2); /* read/write */
4317777Sralph 	alarm(0);
4417777Sralph 
4517777Sralph 	/* modem is open */
4617777Sralph 	next_fd = -1;
4717777Sralph 	if (dh >= 0) {
4817777Sralph 		fixline(dh, dev->D_speed);
4917777Sralph 		/* set guard time small so line is in transparant mode */
5017777Sralph 		slowrite(dh, "\rATS12=1\r");
5117777Sralph 		if (expect("OK", dh) != 0) {
5217777Sralph 			logent("NOV no line", _FAILED);
5317777Sralph 			strcpy(devSel, dev->D_line);
5417777Sralph 			novcls(dh);
5517777Sralph 			return CF_DIAL;
5617777Sralph 		}
5717777Sralph 
5817777Sralph 		if (pulse)
5917777Sralph 			slowrite(dh, "ATDP");
6017777Sralph 		else
6117777Sralph 			slowrite(dh, "ATDT");
6217777Sralph 		slowrite(dh, telno);
6317777Sralph 		slowrite(dh, "\r");
6417777Sralph 
6517777Sralph 		if (expect("CONNECT", dh) != 0) {
6617777Sralph 			logent("NOV no carrier", _FAILED);
6717777Sralph 			strcpy(devSel, dev->D_line);
6817777Sralph 			novcls(dh);
6917777Sralph 			return CF_DIAL;
7017777Sralph 		}
7117777Sralph 
7217777Sralph 	}
7317777Sralph 	if (dh < 0) {
7417777Sralph 		DEBUG(4, "novation failed\n", CNULL);
7517777Sralph 		delock(dev->D_line);
7617777Sralph 	}
7717777Sralph 	DEBUG(4, "novation ok\n", CNULL);
7817777Sralph 	return dh;
7917777Sralph }
8017777Sralph 
8117777Sralph novcls(fd)
8217777Sralph int fd;
8317777Sralph {
8417777Sralph 	char dcname[20];
8517777Sralph 	struct sgttyb hup, sav;
8617777Sralph 
8717777Sralph 	if (fd > 0) {
8817777Sralph 		sprintf(dcname, "/dev/%s", devSel);
8917777Sralph 		DEBUG(4, "Hanging up fd = %d\n", fd);
9017777Sralph 		/*
9117777Sralph 		 * code to drop DTR -- change to 0 baud then back to default.
9217777Sralph 		 */
9317777Sralph 		gtty(fd, &hup);
9417777Sralph 		gtty(fd, &sav);
9517777Sralph 		hup.sg_ispeed = B0;
9617777Sralph 		hup.sg_ospeed = B0;
9717777Sralph 		stty(fd, &hup);
9817777Sralph 		sleep(2);
9917777Sralph 		stty(fd, &sav);
10017777Sralph 		/*
10117777Sralph 		 * now raise DTR -- close the device & open it again.
10217777Sralph 		 */
10317777Sralph 		sleep(2);
10417777Sralph 		close(fd);
10517777Sralph 		sleep(2);
10617777Sralph 		fd = open(dcname, 2);
10717777Sralph 		/*
10817777Sralph 		 * Since we have a getty sleeping on this line, when it wakes up it sends
10917777Sralph 		 * all kinds of garbage to the modem.  Unfortunatly, the modem likes to
11017777Sralph 		 * execute the previous command when it sees the garbage.  The previous
11117777Sralph 		 * command was to dial the phone, so let's make the last command reset
11217777Sralph 		 * the modem.
11317777Sralph 		 */
11417777Sralph 		sleep(2);
11517777Sralph 		slowrite(fd, "\rATZ\r");
11617777Sralph 		close(fd);
11717777Sralph 		delock(devSel);
11817777Sralph 	}
11917777Sralph }
120