v3451.c revision 1.1 1 1.1 cgd /*
2 1.1 cgd * Copyright (c) 1983 The Regents of the University of California.
3 1.1 cgd * All rights reserved.
4 1.1 cgd *
5 1.1 cgd * Redistribution and use in source and binary forms, with or without
6 1.1 cgd * modification, are permitted provided that the following conditions
7 1.1 cgd * are met:
8 1.1 cgd * 1. Redistributions of source code must retain the above copyright
9 1.1 cgd * notice, this list of conditions and the following disclaimer.
10 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
11 1.1 cgd * notice, this list of conditions and the following disclaimer in the
12 1.1 cgd * documentation and/or other materials provided with the distribution.
13 1.1 cgd * 3. All advertising materials mentioning features or use of this software
14 1.1 cgd * must display the following acknowledgement:
15 1.1 cgd * This product includes software developed by the University of
16 1.1 cgd * California, Berkeley and its contributors.
17 1.1 cgd * 4. Neither the name of the University nor the names of its contributors
18 1.1 cgd * may be used to endorse or promote products derived from this software
19 1.1 cgd * without specific prior written permission.
20 1.1 cgd *
21 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 1.1 cgd * SUCH DAMAGE.
32 1.1 cgd */
33 1.1 cgd
34 1.1 cgd #ifndef lint
35 1.1 cgd static char sccsid[] = "@(#)v3451.c 5.5 (Berkeley) 3/2/91";
36 1.1 cgd #endif /* not lint */
37 1.1 cgd
38 1.1 cgd /*
39 1.1 cgd * Routines for calling up on a Vadic 3451 Modem
40 1.1 cgd */
41 1.1 cgd #include "tip.h"
42 1.1 cgd
43 1.1 cgd static jmp_buf Sjbuf;
44 1.1 cgd
45 1.1 cgd v3451_dialer(num, acu)
46 1.1 cgd register char *num;
47 1.1 cgd char *acu;
48 1.1 cgd {
49 1.1 cgd sig_t func;
50 1.1 cgd int ok;
51 1.1 cgd int slow = number(value(BAUDRATE)) < 1200, rw = 2;
52 1.1 cgd char phone[50];
53 1.1 cgd #ifdef ACULOG
54 1.1 cgd char line[80];
55 1.1 cgd #endif
56 1.1 cgd static int expect();
57 1.1 cgd static void vawrite();
58 1.1 cgd
59 1.1 cgd /*
60 1.1 cgd * Get in synch
61 1.1 cgd */
62 1.1 cgd vawrite("I\r", 1 + slow);
63 1.1 cgd vawrite("I\r", 1 + slow);
64 1.1 cgd vawrite("I\r", 1 + slow);
65 1.1 cgd vawrite("\005\r", 2 + slow);
66 1.1 cgd if (!expect("READY")) {
67 1.1 cgd printf("can't synchronize with vadic 3451\n");
68 1.1 cgd #ifdef ACULOG
69 1.1 cgd logent(value(HOST), num, "vadic", "can't synch up");
70 1.1 cgd #endif
71 1.1 cgd return (0);
72 1.1 cgd }
73 1.1 cgd ioctl(FD, TIOCHPCL, 0);
74 1.1 cgd sleep(1);
75 1.1 cgd vawrite("D\r", 2 + slow);
76 1.1 cgd if (!expect("NUMBER?")) {
77 1.1 cgd printf("Vadic will not accept dial command\n");
78 1.1 cgd #ifdef ACULOG
79 1.1 cgd logent(value(HOST), num, "vadic", "will not accept dial");
80 1.1 cgd #endif
81 1.1 cgd return (0);
82 1.1 cgd }
83 1.1 cgd strcpy(phone, num);
84 1.1 cgd strcat(phone, "\r");
85 1.1 cgd vawrite(phone, 1 + slow);
86 1.1 cgd if (!expect(phone)) {
87 1.1 cgd printf("Vadic will not accept phone number\n");
88 1.1 cgd #ifdef ACULOG
89 1.1 cgd logent(value(HOST), num, "vadic", "will not accept number");
90 1.1 cgd #endif
91 1.1 cgd return (0);
92 1.1 cgd }
93 1.1 cgd func = signal(SIGINT,SIG_IGN);
94 1.1 cgd /*
95 1.1 cgd * You cannot interrupt the Vadic when its dialing;
96 1.1 cgd * even dropping DTR does not work (definitely a
97 1.1 cgd * brain damaged design).
98 1.1 cgd */
99 1.1 cgd vawrite("\r", 1 + slow);
100 1.1 cgd vawrite("\r", 1 + slow);
101 1.1 cgd if (!expect("DIALING:")) {
102 1.1 cgd printf("Vadic failed to dial\n");
103 1.1 cgd #ifdef ACULOG
104 1.1 cgd logent(value(HOST), num, "vadic", "failed to dial");
105 1.1 cgd #endif
106 1.1 cgd return (0);
107 1.1 cgd }
108 1.1 cgd if (boolean(value(VERBOSE)))
109 1.1 cgd printf("\ndialing...");
110 1.1 cgd ok = expect("ON LINE");
111 1.1 cgd signal(SIGINT, func);
112 1.1 cgd if (!ok) {
113 1.1 cgd printf("call failed\n");
114 1.1 cgd #ifdef ACULOG
115 1.1 cgd logent(value(HOST), num, "vadic", "call failed");
116 1.1 cgd #endif
117 1.1 cgd return (0);
118 1.1 cgd }
119 1.1 cgd ioctl(FD, TIOCFLUSH, &rw);
120 1.1 cgd return (1);
121 1.1 cgd }
122 1.1 cgd
123 1.1 cgd v3451_disconnect()
124 1.1 cgd {
125 1.1 cgd
126 1.1 cgd close(FD);
127 1.1 cgd }
128 1.1 cgd
129 1.1 cgd v3451_abort()
130 1.1 cgd {
131 1.1 cgd
132 1.1 cgd close(FD);
133 1.1 cgd }
134 1.1 cgd
135 1.1 cgd static void
136 1.1 cgd vawrite(cp, delay)
137 1.1 cgd register char *cp;
138 1.1 cgd int delay;
139 1.1 cgd {
140 1.1 cgd
141 1.1 cgd for (; *cp; sleep(delay), cp++)
142 1.1 cgd write(FD, cp, 1);
143 1.1 cgd }
144 1.1 cgd
145 1.1 cgd static
146 1.1 cgd expect(cp)
147 1.1 cgd register char *cp;
148 1.1 cgd {
149 1.1 cgd char buf[300];
150 1.1 cgd register char *rp = buf;
151 1.1 cgd int timeout = 30, online = 0;
152 1.1 cgd static int notin();
153 1.1 cgd static void alarmtr();
154 1.1 cgd
155 1.1 cgd if (strcmp(cp, "\"\"") == 0)
156 1.1 cgd return (1);
157 1.1 cgd *rp = 0;
158 1.1 cgd /*
159 1.1 cgd * If we are waiting for the Vadic to complete
160 1.1 cgd * dialing and get a connection, allow more time
161 1.1 cgd * Unfortunately, the Vadic times out 24 seconds after
162 1.1 cgd * the last digit is dialed
163 1.1 cgd */
164 1.1 cgd online = strcmp(cp, "ON LINE") == 0;
165 1.1 cgd if (online)
166 1.1 cgd timeout = number(value(DIALTIMEOUT));
167 1.1 cgd signal(SIGALRM, alarmtr);
168 1.1 cgd if (setjmp(Sjbuf))
169 1.1 cgd return (0);
170 1.1 cgd alarm(timeout);
171 1.1 cgd while (notin(cp, buf) && rp < buf + sizeof (buf) - 1) {
172 1.1 cgd if (online && notin("FAILED CALL", buf) == 0)
173 1.1 cgd return (0);
174 1.1 cgd if (read(FD, rp, 1) < 0) {
175 1.1 cgd alarm(0);
176 1.1 cgd return (0);
177 1.1 cgd }
178 1.1 cgd if (*rp &= 0177)
179 1.1 cgd rp++;
180 1.1 cgd *rp = '\0';
181 1.1 cgd }
182 1.1 cgd alarm(0);
183 1.1 cgd return (1);
184 1.1 cgd }
185 1.1 cgd
186 1.1 cgd static void
187 1.1 cgd alarmtr()
188 1.1 cgd {
189 1.1 cgd longjmp(Sjbuf, 1);
190 1.1 cgd }
191 1.1 cgd
192 1.1 cgd static int
193 1.1 cgd notin(sh, lg)
194 1.1 cgd char *sh, *lg;
195 1.1 cgd {
196 1.1 cgd static int prefix();
197 1.1 cgd
198 1.1 cgd for (; *lg; lg++)
199 1.1 cgd if (prefix(sh, lg))
200 1.1 cgd return (0);
201 1.1 cgd return (1);
202 1.1 cgd }
203 1.1 cgd
204 1.1 cgd static
205 1.1 cgd prefix(s1, s2)
206 1.1 cgd register char *s1, *s2;
207 1.1 cgd {
208 1.1 cgd register char c;
209 1.1 cgd
210 1.1 cgd while ((c = *s1++) == *s2++)
211 1.1 cgd if (c == '\0')
212 1.1 cgd return (1);
213 1.1 cgd return (c == '\0');
214 1.1 cgd }
215