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