xref: /original-bsd/usr.bin/uucp/libacu/hysq.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[] = "@(#)hysq.c	8.1 (Berkeley) 06/06/93";
10 #endif /* not lint */
11 
12 #include "condevs.h"
13 
14 /*
15  * New dialout routine to work with Hayes' SMART MODEM
16  * 13-JUL-82, Mike Mitchell
17  * Modified 23-MAR-83 to work with Tom Truscott's (rti!trt)
18  * version of UUCP	(ncsu!mcm)
19  *
20  * The modem should be set to NOT send any result codes to
21  * the system (switch 3 up, 4 down). This end will figure out
22  * what is wrong.
23  *
24  * I had lots of problems with the modem sending
25  * result codes since I am using the same modem for both incomming and
26  * outgoing calls.  I'd occasionally miss the result code (getty would
27  * grab it), and the connect would fail.  Worse yet, the getty would
28  * think the result code was a user name, and send garbage to it while
29  * it was in the command state.  I turned off ALL result codes, and hope
30  * for the best.  99% of the time the modem is in the correct state.
31  * Occassionally it doesn't connect, or the phone was busy, etc., and
32  * uucico sits there trying to log in.  It eventually times out, calling
33  * clsacu() in the process, so it resets itself for the next attempt.
34  */
35 
36 /*
37  * NOTE: this version is not for the faint-hearted.
38  * Someday it would be nice to have a single version of hayes dialer
39  * with a way to specify the switch settings that are on the dialer
40  * as well as tone/pulse.
41  * In the meantime, using HAYES rather than HAYESQ is probably best.
42  */
43 
44 hysqpopn(telno, flds, dev)
45 char *telno, *flds[];
46 struct Devices *dev;
47 {
48 	return hysqopn(telno, flds, dev, 0);
49 }
50 
51 hysqtopn(telno, flds, dev)
52 char *telno, *flds[];
53 struct Devices *dev;
54 {
55 	return hysqopn(telno, flds, dev, 1);
56 }
57 
58 hysqopn(telno, flds, dev, toneflag)
59 char *telno, *flds[];
60 struct Devices *dev;
61 int toneflag;
62 {
63 	char dcname[20], phone[MAXPH+10], c = 0;
64 #ifdef	USG
65 	struct termio ttbuf;
66 #endif USG
67 	int status, dnf;
68 	unsigned timelim;
69 
70 	signal(SIGALRM, alarmtr);
71 	sprintf(dcname, "/dev/%s", dev->D_line);
72 
73 	getnextfd();
74 	if (setjmp(Sjbuf)) {
75 		logent("DEVICE", "NO");
76 		DEBUG(4, "Open timed out %s", dcname);
77 		return CF_NODEV;
78 	}
79 	alarm(10);
80 
81 	if ((dnf = open(dcname, 2)) <= 0) {
82 		logent("DEVICE", "NO");
83 		DEBUG(4, "Can't open %s", dcname);
84 		return CF_NODEV;
85 	}
86 
87 	alarm(0);
88 	next_fd = -1;
89 	fixline(dnf, dev->D_speed);
90 	DEBUG(4, "Hayes port - %s, ", dcname);
91 
92 	if (toneflag)
93 		sprintf(phone, "\rATDT%s\r", telno);
94 	else
95 		sprintf(phone, "\rATDP%s\r", telno);
96 
97 	write(dnf, phone, strlen(phone));
98 
99 	/* calculate delay time for the other system to answer the phone.
100 	 * Default is 15 seconds, add 2 seconds for each comma in the phone
101 	 * number.
102 	 */
103 	timelim = 150;
104 	while(*telno) {
105 		c = *telno++;
106 		if (c == ',')
107 			timelim += 20;
108 		else if (toneflag)
109 			timelim += 2;	/* .2 seconds per tone */
110 		else {
111 			if (c == '0') timelim += 10;   /* .1 sec per digit */
112 			else if (c > '0' && c <= '9')
113 				timelim += (c - '0');
114 		}
115 	}
116 	alarm(timelim/10 + 1);
117 	if (setjmp(Sjbuf) == 0) {
118 		read(dnf, &c, 1);
119 		alarm(0);
120 	}
121 
122 	return dnf;
123 }
124 
125 hysqcls(fd)
126 int fd;
127 {
128 	char dcname[20];
129 	struct sgttyb hup, sav;
130 
131 	if (fd > 0) {
132 		sprintf(dcname, "/dev/%s", devSel);
133 		DEBUG(4, "Hanging up fd = %d\n", fd);
134 		/*
135 		 * code to drop DTR -- change to 0 baud then back to default.
136 		 */
137 		gtty(fd, &hup);
138 		gtty(fd, &sav);
139 		hup.sg_ispeed = B0;
140 		hup.sg_ospeed = B0;
141 		stty(fd, &hup);
142 		sleep(2);
143 		stty(fd, &sav);
144 		/*
145 		 * now raise DTR -- close the device & open it again.
146 		 */
147 		sleep(2);
148 		close(fd);
149 		sleep(2);
150 		fd = open(dcname, 2);
151 		/*
152 		 * Since we have a getty sleeping on this line, when it wakes up it sends
153 		 * all kinds of garbage to the modem.  Unfortunatly, the modem likes to
154 		 * execute the previous command when it sees the garbage.  The previous
155 		 * command was to dial the phone, so let's make the last command reset
156 		 * the modem.
157 		 */
158 		sleep(2);
159 		write(fd, "\rATZ\r", 5);
160 		close(fd);
161 		delock(devSel);
162 	}
163 }
164