date and time created 85/03/22 09:03:14 by ralph
[unix-history] / usr / src / usr.bin / uucp / libacu / vad.c
CommitLineData
1429dd8a
RC
1#ifndef lint
2static char sccsid[] = "@(#)vad.c 4.1 (Berkeley) %G%";
3#endif
4
5#include "../condevs.h"
6#ifdef VADIC
7
8/*
9 * vadopn: establish dial-out connection through a Racal-Vadic 3450.
10 * Returns descriptor open to tty for reading and writing.
11 * Negative values (-1...-7) denote errors in connmsg.
12 * Be sure to disconnect tty when done, via HUPCL or stty 0.
13 */
14
15vadopn(telno, flds, dev)
16char *telno;
17char *flds[];
18struct Devices *dev;
19{
20 int dh = -1;
21 int i, ok, er = 0, delay;
22 extern errno;
23 char dcname[20];
24
25 sprintf(dcname, "/dev/%s", dev->D_line);
26 if (setjmp(Sjbuf)) {
27 DEBUG(1, "timeout vadic open\n", "");
28 logent("vadic open", "TIMEOUT");
29 if (dh >= 0)
30 close(dh);
31 delock(dev->D_line);
32 return CF_NODEV;
33 }
34 signal(SIGALRM, alarmtr);
35 getnextfd();
36 alarm(10);
37 dh = open(dcname, 2);
38 alarm(0);
39
40 /* modem is open */
41 next_fd = -1;
42 if (dh < 0) {
43 delock(dev->D_line);
44 return CF_NODEV;
45 }
46 fixline(dh, dev->D_speed);
47
48 DEBUG(4, "calling %s -> ", telno);
49 if (dochat(dev, flds, dh)) {
50 logent(dcname, "CHAT FAILED");
51 close(dh);
52 return CF_DIAL;
53 }
54 delay = 0;
55 for (i = 0; i < strlen(telno); ++i) {
56 switch(telno[i]) {
57 case '=': /* await dial tone */
58 case '-':
59 case ',':
60 case '<':
61 case 'K':
62 telno[i] = 'K';
63 delay += 5;
64 break;
65 }
66 }
67 DEBUG(4, "%s\n", telno);
68 for(i = 0; i < 5; ++i) { /* make 5 tries */
69 /* wake up Vadic */
70 write(dh, "\005\r", 2);
71 DEBUG(4, "wanted * ", CNULL);
72 ok = expect("*", dh);
73 DEBUG(4, "got %s\n", ok ? "?" : "that");
74 if (ok != 0)
75 continue;
76
77 write(dh, "D\r", 2); /* "D" (enter number) command */
78 DEBUG(4, "wanted NUMBER?\\r\\n ", CNULL);
79 ok = expect("NUMBER?\r\n", dh);
80 DEBUG(4, "got %s\n", ok ? "?" : "that");
81 if (ok != 0)
82 continue;
83
84 /* send telno, send \r */
85 write(dh, telno, strlen(telno));
86 sleep(1);
87 write(dh, "\r", 1);
88 DEBUG(4, "wanted %s ", telno);
89 ok = expect(telno, dh);
90 if (ok == 0)
91 ok = expect("\r\n", dh);
92 DEBUG(4, "got %s\n", ok ? "?" : "that");
93 if (ok != 0)
94 continue;
95
96 write(dh, "\r", 1); /* confirm number */
97 DEBUG(4, "wanted DIALING: ", CNULL);
98 ok = expect("DIALING: ", dh);
99 DEBUG(4, "got %s\n", ok ? "?" : "that");
100 if (ok == 0)
101 break;
102 }
103
104 if (ok == 0) {
105 sleep(10 + delay); /* give vadic some time */
106 DEBUG(4, "wanted ON LINE\\r\\n ", CNULL);
107 ok = expect("ON LINE\r\n", dh);
108 DEBUG(4, "got %s\n", ok ? "?" : "that");
109 }
110
111 if (ok != 0) {
112 if (dh > 2)
113 close(dh);
114 DEBUG(4, "vadDial failed\n", CNULL);
115 delock(dev->D_line);
116 return CF_DIAL;
117 }
118 DEBUG(4, "vadic ok\n", CNULL);
119 return dh;
120}
121
122vadcls(fd) {
123
124 if (fd > 0) {
125 close(fd);
126 sleep(5);
127 delock(devSel);
128 }
129}
130#endif VADIC