xref: /original-bsd/usr.bin/uucp/libacu/hys24.c (revision 57530171)
1 #ifndef lint
2 static char sccsid[] = "@(#)hys24.c	1.3 (Berkeley) 04/05/88";
3 #endif !lint
4 
5 #include "../condevs.h"
6 
7 /*
8  *	hyspopn24(telno, flds, dev) connect to hayes smartmodem (pulse call)
9  *	hystopn24(telno, flds, dev) connect to hayes smartmodem (tone call)
10  *	char *flds[], *dev[];
11  *
12  *	return codes:
13  *		>0  -  file number  -  ok
14  *		CF_DIAL,CF_DEVICE  -  failed
15  */
16 
17 hyspopn24(telno, flds, dev)
18 char *telno, *flds[];
19 struct Devices *dev;
20 {
21 	return hysopn24(telno, flds, dev, 0);
22 }
23 
24 hystopn24(telno, flds, dev)
25 char *telno, *flds[];
26 struct Devices *dev;
27 {
28 	return hysopn24(telno, flds, dev, 1);
29 }
30 
31 /* ARGSUSED */
32 hysopn24(telno, flds, dev, toneflag)
33 char *telno;
34 char *flds[];
35 struct Devices *dev;
36 int toneflag;
37 {
38 	int	dh = -1;
39 	char *ii;
40 	extern errno;
41 	char dcname[20];
42 
43 	sprintf(dcname, "/dev/%s", dev->D_line);
44 	DEBUG(4, "dc - %s\n", dcname);
45 	if (setjmp(Sjbuf)) {
46 		logent(dcname, "TIMEOUT");
47 		if (dh >= 0)
48 			hyscls24(dh);
49 		return CF_DIAL;
50 	}
51 	signal(SIGALRM, alarmtr);
52 	getnextfd();
53 	alarm(10);
54 	dh = open(dcname, 2); /* read/write */
55 	alarm(0);
56 
57 	for (ii = telno; *ii; ii++)
58 		if (*ii == '=')
59 		    *ii = ',';
60 
61 	/* modem is open */
62 	next_fd = -1;
63 	if (dh >= 0) {
64 		fixline(dh, dev->D_speed);
65 		write(dh, "\rATZH\r", 6);
66 		sleep(2);
67 		if (dochat(dev, flds, dh)) {
68 			logent(dcname, "CHAT FAILED");
69 			hyscls24(dh);
70 			return CF_DIAL;
71 		}
72 		write(dh, "AT&F&D3&C1E0X1\r", 15);
73 		if (expect("OK\r\n", dh) != 0) {
74 			logent(dcname, "HSM not responding OK");
75 			hyscls24(dh);
76 			return CF_DIAL;
77 		}
78 		if (toneflag)
79 			write(dh, "\rATDT", 5);
80 		else
81 			write(dh, "\rATDP", 5);
82 		write(dh, telno, strlen(telno));
83 		write(dh, "\r", 1);
84 
85 		if (expect("CONNECT", dh) != 0) {
86 			logent("HSM no carrier", _FAILED);
87 			strcpy(devSel, dev->D_line);
88 			hyscls24(dh);
89 			return CF_DIAL;
90 		}
91 
92 	}
93 	if (dh < 0) {
94 		logent(dcname, "CAN'T OPEN");
95 		return dh;
96 	}
97 	DEBUG(4, "hayes ok\n", CNULL);
98 	return dh;
99 }
100 
101 hyscls24(fd)
102 int fd;
103 {
104 	char dcname[20];
105 
106 	if (fd > 0) {
107 		sprintf(dcname, "/dev/%s", devSel);
108 		DEBUG(4, "Hanging up fd = %d\n", fd);
109 		sleep(1);
110 /*
111  * Since we have a getty sleeping on this line, when it wakes up it sends
112  * all kinds of garbage to the modem.  Unfortunatly, the modem likes to
113  * execute the previous command when it sees the garbage.  The previous
114  * command was to dial the phone, so let's make the last command reset
115  * the modem.
116  */
117 		write(fd, "\r+++", 4);
118 		sleep(2);
119 		write(fd, "\rATH\rATZ\r", 9);
120 		sleep(2);
121 		close(fd);
122 		delock(devSel);
123 	}
124 }
125