2 * Copyright (c) 1983, 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
36 static char sccsid[] = "@(#)ventel.c 8.1 (Berkeley) 6/6/93";
38 static const char rcsid[] =
39 "$FreeBSD: src/usr.bin/tip/libacu/ventel.c,v 1.3 1999/08/28 01:06:31 peter Exp $";
43 * Routines for calling up on a Ventel Modem
44 * The Ventel is expected to be strapped for local echo (just like uucp)
52 static void sigALRM();
53 static int timeout = 0;
54 static jmp_buf timeoutbuf;
57 * some sleep calls have been replaced by this macro
58 * because some ventel modems require two <cr>s in less than
59 * a second in order to 'wake up'... yes, it is dirty...
61 #define delay(num,denom) busyloop(CPUSPEED*num/denom)
62 #define CPUSPEED 1000000 /* VAX 780 is 1MIPS */
63 #define DELAY(n) { register long N = (n); while (--N > 0); }
64 busyloop(n) { DELAY(n); }
71 register int connected = 0;
72 char *msg, *index(), line[80];
73 static int gobble(), vensync();
77 * Get in synch with a couple of carriage returns
80 printf("can't synchronize with ventel\n");
82 logent(value(HOST), num, "ventel", "can't synch up");
86 if (boolean(value(VERBOSE)))
87 printf("\ndialing...");
90 echo("#k$\r$\n$D$I$A$L$:$ ");
91 for (cp = num; *cp; cp++) {
98 if (gobble('\n', line))
99 connected = gobble('!', line);
103 sprintf(line, "%d second dial timeout",
104 number(value(DIALTIMEOUT)));
105 logent(value(HOST), num, "ventel", line);
109 ven_disconnect(); /* insurance */
110 if (connected || timeout || !boolean(value(VERBOSE)))
112 /* call failed, parse response for user */
113 cp = index(line, '\r');
116 for (cp = line; cp = index(cp, ' '); cp++)
128 printf("%s...", msg);
152 while (c = *s++) switch (c) {
173 printf("\07timeout waiting for reply\n");
175 longjmp(timeoutbuf, 1);
179 gobble(match, response)
183 register char *cp = response;
187 f = signal(SIGALRM, sigALRM);
190 if (setjmp(timeoutbuf)) {
195 alarm(number(value(DIALTIMEOUT)));
200 if (boolean(value(VERBOSE)))
203 } while (c != '\n' && c != match);
204 signal(SIGALRM, SIG_DFL);
209 #define min(a,b) ((a)>(b)?(b):(a))
211 * This convoluted piece of code attempts to get
212 * the ventel in sync. If you don't have FIONREAD
213 * there are gory ways to simulate this.
218 int already = 0, nread;
222 * Toggle DTR to force anyone off that might have left
223 * the modem connected, and insure a consistent state
226 * If you don't have the ioctl calls to diddle directly
227 * with DTR, you can always try setting the baud rate to 0.
229 ioctl(FD, TIOCCDTR, 0);
231 ioctl(FD, TIOCSDTR, 0);
232 while (already < MAXRETRY) {
234 * After reseting the modem, send it two \r's to
235 * autobaud on. Make sure to delay between them
236 * so the modem can frame the incoming characters.
242 if (ioctl(fd, FIONREAD, (caddr_t)&nread) < 0) {
247 read(fd, buf, min(nread, 60));
248 if ((buf[nread - 1] & 0177) == '$')
250 nread -= min(nread, 60);