|
|
1.1 root 1: #ifndef lint
2: static char sccsid[] = "@(#)v831.c 4.5 (Berkeley) 6/25/83";
3: #endif
4:
5: /*
6: * Routines for dialing up on Vadic 831
7: */
8: #include <sys/time.h>
9:
10: #include "tip.h"
11:
12: int v831_abort();
13: static int alarmtr();
14: extern errno;
15:
16: static jmp_buf jmpbuf;
17: static int child = -1;
18:
19: v831_dialer(num, acu)
20: char *num, *acu;
21: {
22: int status, pid, connected = 1;
23: register int timelim;
24:
25: if (boolean(value(VERBOSE)))
26: printf("\nstarting call...");
27: #ifdef DEBUG
28: printf ("(acu=%s)\n", acu);
29: #endif
30: if ((AC = open(acu, O_RDWR)) < 0) {
31: if (errno == EBUSY)
32: printf("line busy...");
33: else
34: printf("acu open error...");
35: return (0);
36: }
37: if (setjmp(jmpbuf)) {
38: kill(child, SIGKILL);
39: close(AC);
40: return (0);
41: }
42: signal(SIGALRM, alarmtr);
43: timelim = 5 * strlen(num);
44: alarm(timelim < 30 ? 30 : timelim);
45: if ((child = fork()) == 0) {
46: /*
47: * ignore this stuff for aborts
48: */
49: signal(SIGALRM, SIG_IGN);
50: signal(SIGINT, SIG_IGN);
51: signal(SIGQUIT, SIG_IGN);
52: sleep(2);
53: exit(dialit(num, acu) != 'A');
54: }
55: /*
56: * open line - will return on carrier
57: */
58: if ((FD = open(DV, O_RDWR)) < 0) {
59: #ifdef DEBUG
60: printf("(after open, errno=%d)\n", errno);
61: #endif
62: if (errno == EIO)
63: printf("lost carrier...");
64: else
65: printf("dialup line open failed...");
66: alarm(0);
67: kill(child, SIGKILL);
68: close(AC);
69: return (0);
70: }
71: alarm(0);
72: #ifdef notdef
73: ioctl(AC, TIOCHPCL, 0);
74: #endif
75: signal(SIGALRM, SIG_DFL);
76: while ((pid = wait(&status)) != child && pid != -1)
77: ;
78: if (status) {
79: close(AC);
80: return (0);
81: }
82: return (1);
83: }
84:
85: static
86: alarmtr()
87: {
88:
89: alarm(0);
90: longjmp(jmpbuf, 1);
91: }
92:
93: /*
94: * Insurance, for some reason we don't seem to be
95: * hanging up...
96: */
97: v831_disconnect()
98: {
99: struct sgttyb cntrl;
100:
101: sleep(2);
102: #ifdef DEBUG
103: printf("[disconnect: FD=%d]\n", FD);
104: #endif
105: if (FD > 0) {
106: ioctl(FD, TIOCCDTR, 0);
107: ioctl(FD, TIOCGETP, &cntrl);
108: cntrl.sg_ispeed = cntrl.sg_ospeed = 0;
109: ioctl(FD, TIOCSETP, &cntrl);
110: ioctl(FD, TIOCNXCL, (struct sgttyb *)NULL);
111: }
112: close(FD);
113: }
114:
115: v831_abort()
116: {
117:
118: #ifdef DEBUG
119: printf("[abort: AC=%d]\n", AC);
120: #endif
121: sleep(2);
122: if (child > 0)
123: kill(child, SIGKILL);
124: if (AC > 0)
125: ioctl(FD, TIOCNXCL, (struct sgttyb *)NULL);
126: close(AC);
127: if (FD > 0)
128: ioctl(FD, TIOCCDTR, 0);
129: close(FD);
130: }
131:
132: /*
133: * Sigh, this probably must be changed at each site.
134: */
135: struct vaconfig {
136: char *vc_name;
137: char vc_rack;
138: char vc_modem;
139: } vaconfig[] = {
140: { "/dev/cua0",'4','0' },
141: { "/dev/cua1",'4','1' },
142: { 0 }
143: };
144:
145: #define pc(x) (c = x, write(AC,&c,1))
146: #define ABORT 01
147: #define SI 017
148: #define STX 02
149: #define ETX 03
150:
151: static
152: dialit(phonenum, acu)
153: register char *phonenum;
154: char *acu;
155: {
156: register struct vaconfig *vp;
157: struct sgttyb cntrl;
158: char c, *sanitize();
159: int i, two = 2;
160:
161: phonenum = sanitize(phonenum);
162: #ifdef DEBUG
163: printf ("(dial phonenum=%s)\n", phonenum);
164: #endif
165: if (*phonenum == '<' && phonenum[1] == 0)
166: return ('Z');
167: for (vp = vaconfig; vp->vc_name; vp++)
168: if (strcmp(vp->vc_name, acu) == 0)
169: break;
170: if (vp->vc_name == 0) {
171: printf("Unable to locate dialer (%s)\n", acu);
172: return ('K');
173: }
174: ioctl(AC, TIOCGETP, &cntrl);
175: cntrl.sg_ispeed = cntrl.sg_ospeed = B2400;
176: cntrl.sg_flags = RAW | EVENP | ODDP;
177: ioctl(AC, TIOCSETP, &cntrl);
178: ioctl(AC, TIOCFLUSH, &two);
179: pc(STX);
180: pc(vp->vc_rack);
181: pc(vp->vc_modem);
182: while (*phonenum && *phonenum != '<')
183: pc(*phonenum++);
184: pc(SI);
185: pc(ETX);
186: sleep(1);
187: i = read(AC, &c, 1);
188: #ifdef DEBUG
189: printf("read %d chars, char=%c, errno %d\n", i, c, errno);
190: #endif
191: if (i != 1)
192: c = 'M';
193: if (c == 'B' || c == 'G') {
194: char cc, oc = c;
195:
196: pc(ABORT);
197: read(AC, &cc, 1);
198: #ifdef DEBUG
199: printf("abort response=%c\n", cc);
200: #endif
201: c = oc;
202: v831_disconnect();
203: }
204: close(AC);
205: #ifdef DEBUG
206: printf("dialit: returns %c\n", c);
207: #endif
208: return (c);
209: }
210:
211: static char *
212: sanitize(s)
213: register char *s;
214: {
215: static char buf[128];
216: register char *cp;
217:
218: for (cp = buf; *s; s++) {
219: if (!isdigit(*s) && *s == '<' && *s != '_')
220: continue;
221: if (*s == '_')
222: *s = '=';
223: *cp++ = *s;
224: }
225: *cp++ = 0;
226: return (buf);
227: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.