xref: /csrg-svn/usr.bin/uucp/libacu/nov.c (revision 17777)
1*17777Sralph #ifndef lint
2*17777Sralph static char sccsid[] = "@(#)nov.c	4.1 (Berkeley) 01/22/85";
3*17777Sralph #endif
4*17777Sralph 
5*17777Sralph #include "../condevs.h"
6*17777Sralph #ifdef NOVATION
7*17777Sralph 
8*17777Sralph /***
9*17777Sralph  *	novopn(telno, flds, dev) connect to novation Smart-Cat
10*17777Sralph  *	(similar to hayes smartmodem)
11*17777Sralph  *	char *flds[], *dev[];
12*17777Sralph  *
13*17777Sralph  *	return codes:
14*17777Sralph  *		>0  -  file number  -  ok
15*17777Sralph  *		CF_DIAL,CF_DEVICE  -  failed
16*17777Sralph  */
17*17777Sralph 
18*17777Sralph novopn(telno, flds, dev)
19*17777Sralph char *telno;
20*17777Sralph char *flds[];
21*17777Sralph struct Devices *dev;
22*17777Sralph {
23*17777Sralph 	int	dh = -1;
24*17777Sralph 	extern errno;
25*17777Sralph 	char dcname[20];
26*17777Sralph 	int pulse = 0;
27*17777Sralph 
28*17777Sralph 	sprintf(dcname, "/dev/%s", dev->D_line);
29*17777Sralph 	DEBUG(4, "dc - %s\n", dcname);
30*17777Sralph 	if (strcmp(dev->D_calldev, "pulse") == 0)
31*17777Sralph 		pulse = 1;
32*17777Sralph 	if (setjmp(Sjbuf)) {
33*17777Sralph 		DEBUG(1, "timeout novation open %s\n", dcname);
34*17777Sralph 		logent("novation open", "TIMEOUT");
35*17777Sralph 		if (dh >= 0)
36*17777Sralph 			close(dh);
37*17777Sralph 		delock(dev->D_line);
38*17777Sralph 		return CF_DIAL;
39*17777Sralph 	}
40*17777Sralph 	signal(SIGALRM, alarmtr);
41*17777Sralph 	getnextfd();
42*17777Sralph 	alarm(10);
43*17777Sralph 	dh = open(dcname, 2); /* read/write */
44*17777Sralph 	alarm(0);
45*17777Sralph 
46*17777Sralph 	/* modem is open */
47*17777Sralph 	next_fd = -1;
48*17777Sralph 	if (dh >= 0) {
49*17777Sralph 		fixline(dh, dev->D_speed);
50*17777Sralph 		/* set guard time small so line is in transparant mode */
51*17777Sralph 		slowrite(dh, "\rATS12=1\r");
52*17777Sralph 		if (expect("OK", dh) != 0) {
53*17777Sralph 			logent("NOV no line", _FAILED);
54*17777Sralph 			strcpy(devSel, dev->D_line);
55*17777Sralph 			novcls(dh);
56*17777Sralph 			return CF_DIAL;
57*17777Sralph 		}
58*17777Sralph 
59*17777Sralph 		if (pulse)
60*17777Sralph 			slowrite(dh, "ATDP");
61*17777Sralph 		else
62*17777Sralph 			slowrite(dh, "ATDT");
63*17777Sralph 		slowrite(dh, telno);
64*17777Sralph 		slowrite(dh, "\r");
65*17777Sralph 
66*17777Sralph 		if (expect("CONNECT", dh) != 0) {
67*17777Sralph 			logent("NOV no carrier", _FAILED);
68*17777Sralph 			strcpy(devSel, dev->D_line);
69*17777Sralph 			novcls(dh);
70*17777Sralph 			return CF_DIAL;
71*17777Sralph 		}
72*17777Sralph 
73*17777Sralph 	}
74*17777Sralph 	if (dh < 0) {
75*17777Sralph 		DEBUG(4, "novation failed\n", CNULL);
76*17777Sralph 		delock(dev->D_line);
77*17777Sralph 	}
78*17777Sralph 	DEBUG(4, "novation ok\n", CNULL);
79*17777Sralph 	return dh;
80*17777Sralph }
81*17777Sralph 
82*17777Sralph novcls(fd)
83*17777Sralph int fd;
84*17777Sralph {
85*17777Sralph 	char dcname[20];
86*17777Sralph 	struct sgttyb hup, sav;
87*17777Sralph 
88*17777Sralph 	if (fd > 0) {
89*17777Sralph 		sprintf(dcname, "/dev/%s", devSel);
90*17777Sralph 		DEBUG(4, "Hanging up fd = %d\n", fd);
91*17777Sralph 		/*
92*17777Sralph 		 * code to drop DTR -- change to 0 baud then back to default.
93*17777Sralph 		 */
94*17777Sralph 		gtty(fd, &hup);
95*17777Sralph 		gtty(fd, &sav);
96*17777Sralph 		hup.sg_ispeed = B0;
97*17777Sralph 		hup.sg_ospeed = B0;
98*17777Sralph 		stty(fd, &hup);
99*17777Sralph 		sleep(2);
100*17777Sralph 		stty(fd, &sav);
101*17777Sralph 		/*
102*17777Sralph 		 * now raise DTR -- close the device & open it again.
103*17777Sralph 		 */
104*17777Sralph 		sleep(2);
105*17777Sralph 		close(fd);
106*17777Sralph 		sleep(2);
107*17777Sralph 		fd = open(dcname, 2);
108*17777Sralph 		/*
109*17777Sralph 		 * Since we have a getty sleeping on this line, when it wakes up it sends
110*17777Sralph 		 * all kinds of garbage to the modem.  Unfortunatly, the modem likes to
111*17777Sralph 		 * execute the previous command when it sees the garbage.  The previous
112*17777Sralph 		 * command was to dial the phone, so let's make the last command reset
113*17777Sralph 		 * the modem.
114*17777Sralph 		 */
115*17777Sralph 		sleep(2);
116*17777Sralph 		slowrite(fd, "\rATZ\r");
117*17777Sralph 		close(fd);
118*17777Sralph 		delock(devSel);
119*17777Sralph 	}
120*17777Sralph }
121*17777Sralph 
122*17777Sralph #endif NOVATION
123