2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * @(#)t3000.c 8.1 (Berkeley) 6/6/93
37 * Routines for calling up on a Telebit T3000 modem.
38 * Derived from Courier driver.
42 #include "acucommon.h"
47 static void sigALRM();
48 static int timeout = 0;
49 static int connected = 0;
50 static jmp_buf timeoutbuf, intbuf;
51 static int t3000_sync();
53 t3000_dialer(num, acu)
61 static int t3000_connect(), t3000_swallow();
63 if (boolean(value(VERBOSE)))
64 printf("Using \"%s\"\n", acu);
72 printf("can't synchronize with t3000\n");
74 logent(value(HOST), num, "t3000", "can't synch up");
78 t3000_write(FD, "AT E0\r", 6); /* turn off echoing */
81 if (boolean(value(VERBOSE)))
84 ioctl(FD, TIOCFLUSH, 0); /* flush any clutter */
85 t3000_write(FD, "AT E0 H0 Q0 X4 V1\r", 18);
86 if (!t3000_swallow("\r\nOK\r\n"))
89 t3000_write(FD, "AT D", 4);
90 for (cp = num; *cp; cp++)
93 t3000_write(FD, num, strlen(num));
94 t3000_write(FD, "\r", 1);
95 connected = t3000_connect();
98 sprintf(line, "%d second dial timeout",
99 number(value(DIALTIMEOUT)));
100 logent(value(HOST), num, "t3000", line);
110 /* first hang up the modem*/
111 ioctl(FD, TIOCCDTR, 0);
113 ioctl(FD, TIOCSDTR, 0);
114 t3000_sync(); /* reset */
120 t3000_write(FD, "\r", 1); /* send anything to abort the call */
127 printf("\07timeout waiting for reply\n");
129 longjmp(timeoutbuf, 1);
134 register char *match;
139 f = signal(SIGALRM, sigALRM);
146 if (setjmp(timeoutbuf)) {
150 alarm(number(value(DIALTIMEOUT)));
155 if (boolean(value(VERBOSE)))
158 } while (c == *match++);
160 if (boolean(value(VERBOSE)))
163 signal(SIGALRM, SIG_DFL);
167 #ifndef B19200 /* XXX */
182 " 14400", B19200, B9600,
183 " 19200", B19200, B9600,
184 " 38400", B38400, B9600,
185 " 57600", B38400, B9600,
189 " 12000", B19200, B9600,
199 struct tbaud_msg *bm;
202 if (t3000_swallow("\r\n") == 0)
204 f = signal(SIGALRM, sigALRM);
206 nc = 0; nl = sizeof(dialer_buf)-1;
207 bzero(dialer_buf, sizeof(dialer_buf));
209 for (nc = 0, nl = sizeof(dialer_buf)-1 ; nl > 0 ; nc++, nl--) {
210 if (setjmp(timeoutbuf))
212 alarm(number(value(DIALTIMEOUT)));
219 if (t3000_swallow("\n") == 0)
223 if (strcmp(dialer_buf, "RINGING") == 0 &&
224 boolean(value(VERBOSE))) {
226 printf("%s\r\n", dialer_buf);
230 if (strncmp(dialer_buf, "CONNECT",
231 sizeof("CONNECT")-1) != 0)
233 for (bm = tbaud_msg ; bm->msg ; bm++)
235 dialer_buf+sizeof("CONNECT")-1) == 0) {
236 if (!(acu_setspeed (bm->baud) || (bm->baud2 && acu_setspeed (bm->baud2))))
240 if (boolean(value(VERBOSE)))
241 printf("%s\r\n", dialer_buf);
249 if (boolean(value(VERBOSE)))
254 printf("%s\r\n", dialer_buf);
261 * This convoluted piece of code attempts to get
271 while (already++ < MAXRETRY) {
272 ioctl(FD, TIOCFLUSH, 0); /* flush any clutter */
273 t3000_write(FD, "\rAT Z\r", 6); /* reset modem */
274 bzero(buf, sizeof(buf));
276 ioctl(FD, FIONREAD, &len);
278 if (len == 0) len = 1;
281 len = read(FD, buf, sizeof(buf));
284 printf("t3000_sync: (\"%s\")\n\r", buf);
286 if (index(buf, '0') ||
287 (index(buf, 'O') && index(buf, 'K')))
291 * If not strapped for DTR control,
292 * try to get command mode.
295 t3000_write(FD, "+++", 3);
298 * Toggle DTR to force anyone off that might have left
299 * the modem connected.
301 ioctl(FD, TIOCCDTR, 0);
303 ioctl(FD, TIOCSDTR, 0);
305 t3000_write(FD, "\rAT Z\r", 6);
309 t3000_write(fd, cp, n)
315 if (boolean(value(VERBOSE)))
320 for ( ; n-- ; cp++) {
333 if (ioctl(FD, FIONREAD, &n) < 0)
337 if (read(FD, buf, n) != n)