1 /* $OpenBSD: ventel.c,v 1.12 2006/03/17 19:17:13 moritz Exp $ */
2 /* $NetBSD: ventel.c,v 1.6 1997/02/11 09:24:21 mrg Exp $ */
5 * Copyright (c) 1983, 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. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
38 static char sccsid[] = "@(#)ventel.c 8.1 (Berkeley) 6/6/93";
39 static const char rcsid[] = "$OpenBSD: ventel.c,v 1.12 2006/03/17 19:17:13 moritz Exp $";
44 * Routines for calling up on a Ventel Modem
45 * The Ventel is expected to be strapped for local echo (just like uucp)
49 #include <sys/ioctl.h>
53 static int dialtimeout = 0;
54 static jmp_buf timeoutbuf;
56 static void echo(char *);
57 static void sigALRM(int);
58 static int gobble(char, char *);
59 static int vensync(int);
62 * some sleep calls have been replaced by this macro
63 * because some ventel modems require two <cr>s in less than
64 * a second in order to 'wake up'... yes, it is dirty...
66 #define delay(num,denom) busyloop(CPUSPEED*num/denom)
67 #define CPUSPEED 1000000 /* VAX 780 is 1MIPS */
68 #define DELAY(n) do { long N = (n); while (--N > 0); } while (0)
69 #define busyloop(n) do { DELAY(n); } while (0)
72 ven_dialer(char *num, char *acu)
80 * Get in synch with a couple of carriage returns
83 printf("can't synchronize with ventel\n");
85 logent(value(HOST), num, "ventel", "can't synch up");
89 if (boolean(value(VERBOSE)))
90 printf("\ndialing...");
92 tcgetattr(FD, &cntrl);
93 cntrl.c_cflag |= HUPCL;
94 tcsetattr(FD, TCSANOW, &cntrl);
95 echo("#k$\r$\n$D$I$A$L$:$ ");
96 for (cp = num; *cp; cp++) {
103 if (gobble('\n', line))
104 connected = gobble('!', line);
105 tcflush(FD, TCIOFLUSH);
108 (void)snprintf(line, sizeof line, "%ld second dial timeout",
109 number(value(DIALTIMEOUT)));
110 logent(value(HOST), num, "ventel", line);
114 ven_disconnect(); /* insurance */
115 if (connected || dialtimeout || !boolean(value(VERBOSE)))
117 /* call failed, parse response for user */
118 cp = strchr(line, '\r');
121 for (cp = line; (cp = strchr(cp, ' ')) != NULL; cp++)
133 printf("%s...", msg);
156 while ((c = *s++) != '\0')
178 printf("\07timeout waiting for reply\n");
180 longjmp(timeoutbuf, 1);
184 gobble(char match, char response[])
190 f = signal(SIGALRM, sigALRM);
193 if (setjmp(timeoutbuf)) {
198 alarm(number(value(DIALTIMEOUT)));
203 if (boolean(value(VERBOSE)))
206 } while (c != '\n' && c != match);
207 signal(SIGALRM, SIG_DFL);
212 #define min(a,b) ((a)>(b)?(b):(a))
214 * This convoluted piece of code attempts to get
215 * the ventel in sync. If you don't have FIONREAD
216 * there are gory ways to simulate this.
221 int already = 0, nread;
225 * Toggle DTR to force anyone off that might have left
226 * the modem connected, and insure a consistent state
229 * If you don't have the ioctl calls to diddle directly
230 * with DTR, you can always try setting the baud rate to 0.
232 ioctl(FD, TIOCCDTR, 0);
234 ioctl(FD, TIOCSDTR, 0);
235 while (already < MAXRETRY) {
237 * After reseting the modem, send it two \r's to
238 * autobaud on. Make sure to delay between them
239 * so the modem can frame the incoming characters.
245 if (ioctl(fd, FIONREAD, (caddr_t)&nread) < 0) {
246 perror("tip: ioctl");
250 read(fd, buf, min(nread, 60));
251 if ((buf[nread - 1] & 0177) == '$')
253 nread -= min(nread, 60);