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
33 * @(#)ventel.c 8.1 (Berkeley) 6/6/93
34 * $FreeBSD: src/usr.bin/tip/libacu/ventel.c,v 1.3 1999/08/28 01:06:31 peter Exp $
38 * Routines for calling up on a Ventel Modem
39 * The Ventel is expected to be strapped for local echo (just like uucp)
47 static void sigALRM();
48 static int gobble(char, char[]);
49 static int vensync(int);
50 static void echo(char *);
51 static int timeout = 0;
52 static jmp_buf timeoutbuf;
55 * some sleep calls have been replaced by this macro
56 * because some ventel modems require two <cr>s in less than
57 * a second in order to 'wake up'... yes, it is dirty...
59 #define delay(num,denom) busyloop(CPUSPEED*num/denom)
60 #define CPUSPEED 1000000 /* VAX 780 is 1MIPS */
61 #define DELAY(n) { long N = (n); while (--N > 0); }
62 busyloop(n) { DELAY(n); }
70 char *msg, *index(), line[80];
73 * Get in synch with a couple of carriage returns
76 printf("can't synchronize with ventel\n");
78 logent(value(HOST), num, "ventel", "can't synch up");
82 if (boolean(value(VERBOSE)))
83 printf("\ndialing...");
86 echo("#k$\r$\n$D$I$A$L$:$ ");
87 for (cp = num; *cp; cp++) {
94 if (gobble('\n', line))
95 connected = gobble('!', line);
99 sprintf(line, "%d second dial timeout",
100 number(value(DIALTIMEOUT)));
101 logent(value(HOST), num, "ventel", line);
105 ven_disconnect(); /* insurance */
106 if (connected || timeout || !boolean(value(VERBOSE)))
108 /* call failed, parse response for user */
109 cp = index(line, '\r');
112 for (cp = line; cp = index(cp, ' '); cp++)
124 printf("%s...", msg);
148 while (c = *s++) switch (c) {
169 printf("\07timeout waiting for reply\n");
171 longjmp(timeoutbuf, 1);
175 gobble(match, response)
183 f = signal(SIGALRM, sigALRM);
186 if (setjmp(timeoutbuf)) {
191 alarm(number(value(DIALTIMEOUT)));
196 if (boolean(value(VERBOSE)))
199 } while (c != '\n' && c != match);
200 signal(SIGALRM, SIG_DFL);
205 #define min(a,b) ((a)>(b)?(b):(a))
207 * This convoluted piece of code attempts to get
208 * the ventel in sync. If you don't have FIONREAD
209 * there are gory ways to simulate this.
214 int already = 0, nread;
218 * Toggle DTR to force anyone off that might have left
219 * the modem connected, and insure a consistent state
222 * If you don't have the ioctl calls to diddle directly
223 * with DTR, you can always try setting the baud rate to 0.
225 ioctl(FD, TIOCCDTR, 0);
227 ioctl(FD, TIOCSDTR, 0);
228 while (already < MAXRETRY) {
230 * After reseting the modem, send it two \r's to
231 * autobaud on. Make sure to delay between them
232 * so the modem can frame the incoming characters.
238 if (ioctl(fd, FIONREAD, (caddr_t)&nread) < 0) {
243 read(fd, buf, min(nread, 60));
244 if ((buf[nread - 1] & 0177) == '$')
246 nread -= min(nread, 60);