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