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
34 * $DragonFly: src/usr.bin/tip/libacu/t3000.c,v 1.3 2005/05/07 23:20:43 corecode Exp $
38 * Routines for calling up on a Telebit T3000 modem.
39 * Derived from Courier driver.
43 #include "acucommon.h"
48 static void sigALRM();
49 static int timeout
= 0;
50 static int connected
= 0;
51 static jmp_buf timeoutbuf
, intbuf
;
52 static int t3000_sync();
53 static int t3000_connect(void);
54 static int t3000_swallow(char *);
56 t3000_dialer(num
, acu
)
65 if (boolean(value(VERBOSE
)))
66 printf("Using \"%s\"\n", acu
);
74 printf("can't synchronize with t3000\n");
76 logent(value(HOST
), num
, "t3000", "can't synch up");
80 t3000_write(FD
, "AT E0\r", 6); /* turn off echoing */
83 if (boolean(value(VERBOSE
)))
86 ioctl(FD
, TIOCFLUSH
, 0); /* flush any clutter */
87 t3000_write(FD
, "AT E0 H0 Q0 X4 V1\r", 18);
88 if (!t3000_swallow("\r\nOK\r\n"))
91 t3000_write(FD
, "AT D", 4);
92 for (cp
= num
; *cp
; cp
++)
95 t3000_write(FD
, num
, strlen(num
));
96 t3000_write(FD
, "\r", 1);
97 connected
= t3000_connect();
100 sprintf(line
, "%d second dial timeout",
101 number(value(DIALTIMEOUT
)));
102 logent(value(HOST
), num
, "t3000", line
);
112 /* first hang up the modem*/
113 ioctl(FD
, TIOCCDTR
, 0);
115 ioctl(FD
, TIOCSDTR
, 0);
116 t3000_sync(); /* reset */
122 t3000_write(FD
, "\r", 1); /* send anything to abort the call */
129 printf("\07timeout waiting for reply\n");
131 longjmp(timeoutbuf
, 1);
136 register char *match
;
141 f
= signal(SIGALRM
, sigALRM
);
148 if (setjmp(timeoutbuf
)) {
152 alarm(number(value(DIALTIMEOUT
)));
157 if (boolean(value(VERBOSE
)))
160 } while (c
== *match
++);
162 if (boolean(value(VERBOSE
)))
165 signal(SIGALRM
, SIG_DFL
);
169 #ifndef B19200 /* XXX */
184 " 14400", B19200
, B9600
,
185 " 19200", B19200
, B9600
,
186 " 38400", B38400
, B9600
,
187 " 57600", B38400
, B9600
,
191 " 12000", B19200
, B9600
,
201 struct tbaud_msg
*bm
;
204 if (t3000_swallow("\r\n") == 0)
206 f
= signal(SIGALRM
, sigALRM
);
208 nc
= 0; nl
= sizeof(dialer_buf
)-1;
209 bzero(dialer_buf
, sizeof(dialer_buf
));
211 for (nc
= 0, nl
= sizeof(dialer_buf
)-1 ; nl
> 0 ; nc
++, nl
--) {
212 if (setjmp(timeoutbuf
))
214 alarm(number(value(DIALTIMEOUT
)));
221 if (t3000_swallow("\n") == 0)
225 if (strcmp(dialer_buf
, "RINGING") == 0 &&
226 boolean(value(VERBOSE
))) {
228 printf("%s\r\n", dialer_buf
);
232 if (strncmp(dialer_buf
, "CONNECT",
233 sizeof("CONNECT")-1) != 0)
235 for (bm
= tbaud_msg
; bm
->msg
; bm
++)
237 dialer_buf
+sizeof("CONNECT")-1) == 0) {
238 if (!(acu_setspeed (bm
->baud
) || (bm
->baud2
&& acu_setspeed (bm
->baud2
))))
242 if (boolean(value(VERBOSE
)))
243 printf("%s\r\n", dialer_buf
);
251 if (boolean(value(VERBOSE
)))
256 printf("%s\r\n", dialer_buf
);
263 * This convoluted piece of code attempts to get
273 while (already
++ < MAXRETRY
) {
274 ioctl(FD
, TIOCFLUSH
, 0); /* flush any clutter */
275 t3000_write(FD
, "\rAT Z\r", 6); /* reset modem */
276 bzero(buf
, sizeof(buf
));
278 ioctl(FD
, FIONREAD
, &len
);
280 if (len
== 0) len
= 1;
283 len
= read(FD
, buf
, sizeof(buf
));
286 printf("t3000_sync: (\"%s\")\n\r", buf
);
288 if (index(buf
, '0') ||
289 (index(buf
, 'O') && index(buf
, 'K')))
293 * If not strapped for DTR control,
294 * try to get command mode.
297 t3000_write(FD
, "+++", 3);
300 * Toggle DTR to force anyone off that might have left
301 * the modem connected.
303 ioctl(FD
, TIOCCDTR
, 0);
305 ioctl(FD
, TIOCSDTR
, 0);
307 t3000_write(FD
, "\rAT Z\r", 6);
311 t3000_write(fd
, cp
, n
)
317 if (boolean(value(VERBOSE
)))
322 for ( ; n
-- ; cp
++) {
335 if (ioctl(FD
, FIONREAD
, &n
) < 0)
339 if (read(FD
, buf
, n
) != n
)