1 /* $OpenBSD: t3000.c,v 1.14 2006/03/17 19:17:13 moritz Exp $ */
2 /* $NetBSD: t3000.c,v 1.5 1997/02/11 09:24:18 mrg Exp $ */
5 * SPDX-License-Identifier: BSD-3-Clause
7 * Copyright (c) 1992, 1993
8 * The Regents of the University of California. All rights reserved.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 #include <sys/cdefs.h>
36 __FBSDID("$FreeBSD$");
40 static char sccsid[] = "@(#)t3000.c 8.1 (Berkeley) 6/6/93";
41 static const char rcsid[] = "$OpenBSD: t3000.c,v 1.14 2006/03/17 19:17:13 moritz Exp $";
46 * Routines for calling up on a Telebit T3000 modem.
47 * Derived from Courier driver.
51 #include <sys/ioctl.h>
56 static int dialtimeout = 0;
57 static int connected = 0;
58 static jmp_buf timeoutbuf;
60 static void sigALRM(int);
61 static int t3000_swallow(char *);
62 static int t3000_connect(void);
63 static int t3000_sync(void);
64 static void t3000_write(int, char *, int);
65 static void t3000_nap(void);
67 static void t3000_verbose_read(void);
71 t3000_dialer(char *num, char *acu)
79 if (boolean(value(VERBOSE)))
80 printf("Using \"%s\"\n", acu);
82 tcgetattr(FD, &cntrl);
83 cntrl.c_cflag |= HUPCL;
84 tcsetattr(FD, TCSANOW, &cntrl);
90 printf("can't synchronize with t3000\n");
92 logent(value(HOST), num, "t3000", "can't synch up");
96 t3000_write(FD, "AT E0\r", 6); /* turn off echoing */
99 if (boolean(value(VERBOSE)))
100 t3000_verbose_read();
102 tcflush(FD, TCIOFLUSH);
103 t3000_write(FD, "AT E0 H0 Q0 X4 V1\r", 18);
104 if (!t3000_swallow("\r\nOK\r\n"))
107 t3000_write(FD, "AT D", 4);
108 for (cp = num; *cp; cp++)
111 t3000_write(FD, num, strlen(num));
112 t3000_write(FD, "\r", 1);
113 connected = t3000_connect();
116 (void)snprintf(line, sizeof line, "%ld second dial timeout",
117 number(value(DIALTIMEOUT)));
118 logent(value(HOST), num, "t3000", line);
127 t3000_disconnect(void)
129 /* first hang up the modem*/
130 ioctl(FD, TIOCCDTR, 0);
132 ioctl(FD, TIOCSDTR, 0);
133 t3000_sync(); /* reset */
140 t3000_write(FD, "\r", 1); /* send anything to abort the call */
148 printf("\07timeout waiting for reply\n");
150 longjmp(timeoutbuf, 1);
154 t3000_swallow(char *match)
159 f = signal(SIGALRM, sigALRM);
166 if (setjmp(timeoutbuf)) {
170 alarm(number(value(DIALTIMEOUT)));
175 if (boolean(value(VERBOSE)))
178 } while (c == *match++);
180 if (boolean(value(VERBOSE)))
183 signal(SIGALRM, SIG_DFL);
187 #ifndef B19200 /* XXX */
198 { " 1200", B1200, 0 },
199 { " 2400", B2400, 0 },
200 { " 4800", B4800, 0 },
201 { " 9600", B9600, 0 },
202 { " 14400", B19200, B9600 },
203 { " 19200", B19200, B9600 },
204 { " 38400", B38400, B9600 },
205 { " 57600", B38400, B9600 },
206 { " 7512", B9600, 0 },
207 { " 1275", B2400, 0 },
208 { " 7200", B9600, 0 },
209 { " 12000", B19200, B9600 },
219 struct tbaud_msg *bm;
222 if (t3000_swallow("\r\n") == 0)
224 f = signal(SIGALRM, sigALRM);
226 nc = 0; nl = sizeof(dialer_buf)-1;
227 bzero(dialer_buf, sizeof(dialer_buf));
229 for (nc = 0, nl = sizeof(dialer_buf)-1 ; nl > 0 ; nc++, nl--) {
230 if (setjmp(timeoutbuf))
232 alarm(number(value(DIALTIMEOUT)));
239 if (t3000_swallow("\n") == 0)
243 if (strcmp(dialer_buf, "RINGING") == 0 &&
244 boolean(value(VERBOSE))) {
246 printf("%s\r\n", dialer_buf);
250 if (strncmp(dialer_buf, "CONNECT",
251 sizeof("CONNECT")-1) != 0)
253 for (bm = tbaud_msg ; bm->msg ; bm++)
255 dialer_buf+sizeof("CONNECT")-1) == 0) {
256 struct termios cntrl;
258 tcgetattr(FD, &cntrl);
259 cfsetospeed(&cntrl, bm->baud);
260 cfsetispeed(&cntrl, bm->baud);
261 tcsetattr(FD, TCSAFLUSH, &cntrl);
264 if (boolean(value(VERBOSE)))
265 printf("%s\r\n", dialer_buf);
273 if (boolean(value(VERBOSE)))
277 printf("%s\r\n", dialer_buf);
283 * This convoluted piece of code attempts to get
293 while (already++ < MAXRETRY) {
294 tcflush(FD, TCIOFLUSH);
295 t3000_write(FD, "\rAT Z\r", 6); /* reset modem */
296 bzero(buf, sizeof(buf));
298 ioctl(FD, FIONREAD, &len);
300 if (len == 0) len = 1;
303 len = read(FD, buf, sizeof(buf));
306 printf("t3000_sync: (\"%s\")\n\r", buf);
308 if (strchr(buf, '0') ||
309 (strchr(buf, 'O') && strchr(buf, 'K')))
313 * If not strapped for DTR control,
314 * try to get command mode.
317 t3000_write(FD, "+++", 3);
320 * Toggle DTR to force anyone off that might have left
321 * the modem connected.
323 ioctl(FD, TIOCCDTR, 0);
325 ioctl(FD, TIOCSDTR, 0);
327 t3000_write(FD, "\rAT Z\r", 6);
332 t3000_write(int fd, char *cp, int n)
335 if (boolean(value(VERBOSE)))
340 for ( ; n-- ; cp++) {
349 t3000_verbose_read(void)
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);