1 /* $OpenBSD: t3000.c,v 1.9 2001/10/24 18:38:58 millert Exp $ */
2 /* $NetBSD: t3000.c,v 1.5 1997/02/11 09:24:18 mrg Exp $ */
5 * Copyright (c) 1992, 1993
6 * The Regents of the University of California. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 #include <sys/cdefs.h>
38 __FBSDID("$FreeBSD$");
42 static char sccsid[] = "@(#)t3000.c 8.1 (Berkeley) 6/6/93";
43 static char rcsid[] = "$OpenBSD: t3000.c,v 1.9 2001/10/24 18:38:58 millert Exp $";
48 * Routines for calling up on a Telebit T3000 modem.
49 * Derived from Courier driver.
53 #include <sys/ioctl.h>
58 static void sigALRM();
59 static int timeout = 0;
60 static int connected = 0;
61 static jmp_buf timeoutbuf, intbuf;
62 static int t3000_sync(), t3000_connect(), t3000_swallow();
63 static void t3000_nap();
64 static int t3000_write(int fd, char *cp, int n);
67 t3000_dialer(num, acu)
77 if (boolean(value(VERBOSE)))
78 printf("Using \"%s\"\n", acu);
80 tcgetattr(FD, &cntrl);
81 cntrl.c_cflag |= HUPCL;
82 tcsetattr(FD, TCSANOW, &cntrl);
88 printf("can't synchronize with t3000\n");
90 logent(value(HOST), num, "t3000", "can't synch up");
94 t3000_write(FD, "AT E0\r", 6); /* turn off echoing */
97 if (boolean(value(VERBOSE)))
100 tcflush(FD, TCIOFLUSH);
101 t3000_write(FD, "AT E0 H0 Q0 X4 V1\r", 18);
102 if (!t3000_swallow("\r\nOK\r\n"))
105 t3000_write(FD, "AT D", 4);
106 for (cp = num; *cp; cp++)
109 t3000_write(FD, num, strlen(num));
110 t3000_write(FD, "\r", 1);
111 connected = t3000_connect();
114 (void)sprintf(line, "%ld second dial timeout",
115 number(value(DIALTIMEOUT)));
116 logent(value(HOST), num, "t3000", line);
127 /* first hang up the modem*/
128 ioctl(FD, TIOCCDTR, 0);
130 ioctl(FD, TIOCSDTR, 0);
131 t3000_sync(); /* reset */
138 t3000_write(FD, "\r", 1); /* send anything to abort the call */
145 printf("\07timeout waiting for reply\n");
147 longjmp(timeoutbuf, 1);
157 f = signal(SIGALRM, sigALRM);
164 if (setjmp(timeoutbuf)) {
168 alarm(number(value(DIALTIMEOUT)));
173 if (boolean(value(VERBOSE)))
176 } while (c == *match++);
178 if (boolean(value(VERBOSE)))
181 signal(SIGALRM, SIG_DFL);
185 #ifndef B19200 /* XXX */
200 " 14400", B19200, B9600,
201 " 19200", B19200, B9600,
202 " 38400", B38400, B9600,
203 " 57600", B38400, B9600,
207 " 12000", B19200, B9600,
217 struct tbaud_msg *bm;
220 if (t3000_swallow("\r\n") == 0)
222 f = signal(SIGALRM, sigALRM);
224 nc = 0; nl = sizeof(dialer_buf)-1;
225 bzero(dialer_buf, sizeof(dialer_buf));
227 for (nc = 0, nl = sizeof(dialer_buf)-1 ; nl > 0 ; nc++, nl--) {
228 if (setjmp(timeoutbuf))
230 alarm(number(value(DIALTIMEOUT)));
237 if (t3000_swallow("\n") == 0)
241 if (strcmp(dialer_buf, "RINGING") == 0 &&
242 boolean(value(VERBOSE))) {
244 printf("%s\r\n", dialer_buf);
248 if (strncmp(dialer_buf, "CONNECT",
249 sizeof("CONNECT")-1) != 0)
251 for (bm = tbaud_msg ; bm->msg ; bm++)
253 dialer_buf+sizeof("CONNECT")-1) == 0) {
254 struct termios cntrl;
256 tcgetattr(FD, &cntrl);
257 cfsetospeed(&cntrl, bm->baud);
258 cfsetispeed(&cntrl, bm->baud);
259 tcsetattr(FD, TCSAFLUSH, &cntrl);
262 if (boolean(value(VERBOSE)))
263 printf("%s\r\n", dialer_buf);
271 if (boolean(value(VERBOSE)))
275 printf("%s\r\n", dialer_buf);
281 * This convoluted piece of code attempts to get
291 while (already++ < MAXRETRY) {
292 tcflush(FD, TCIOFLUSH);
293 t3000_write(FD, "\rAT Z\r", 6); /* reset modem */
294 bzero(buf, sizeof(buf));
296 ioctl(FD, FIONREAD, &len);
298 if (len == 0) len = 1;
301 len = read(FD, buf, sizeof(buf));
304 printf("t3000_sync: (\"%s\")\n\r", buf);
306 if (strchr(buf, '0') ||
307 (strchr(buf, 'O') && strchr(buf, 'K')))
311 * If not strapped for DTR control,
312 * try to get command mode.
315 t3000_write(FD, "+++", 3);
318 * Toggle DTR to force anyone off that might have left
319 * the modem connected.
321 ioctl(FD, TIOCCDTR, 0);
323 ioctl(FD, TIOCSDTR, 0);
325 t3000_write(FD, "\rAT Z\r", 6);
330 t3000_write(fd, cp, n)
336 if (boolean(value(VERBOSE)))
341 for ( ; n-- ; cp++) {
354 if (ioctl(FD, FIONREAD, &n) < 0)
358 if (read(FD, buf, n) != n)
364 /* Give the t3000 50 milliseconds between characters */
371 ts.tv_nsec = 50 * 1000000;
373 nanosleep(&ts, NULL);