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 $
35 * $DragonFly: src/usr.bin/tip/libacu/ventel.c,v 1.3 2005/05/07 23:20:43 corecode Exp $
39 * Routines for calling up on a Ventel Modem
40 * The Ventel is expected to be strapped for local echo (just like uucp)
48 static void sigALRM();
49 static int gobble(char, char[]);
50 static int vensync(int);
51 static void echo(char *);
52 static int timeout
= 0;
53 static jmp_buf timeoutbuf
;
56 * some sleep calls have been replaced by this macro
57 * because some ventel modems require two <cr>s in less than
58 * a second in order to 'wake up'... yes, it is dirty...
60 #define delay(num,denom) busyloop(CPUSPEED*num/denom)
61 #define CPUSPEED 1000000 /* VAX 780 is 1MIPS */
62 #define DELAY(n) { register long N = (n); while (--N > 0); }
63 busyloop(n
) { DELAY(n
); }
70 register int connected
= 0;
71 char *msg
, *index(), line
[80];
74 * Get in synch with a couple of carriage returns
77 printf("can't synchronize with ventel\n");
79 logent(value(HOST
), num
, "ventel", "can't synch up");
83 if (boolean(value(VERBOSE
)))
84 printf("\ndialing...");
87 echo("#k$\r$\n$D$I$A$L$:$ ");
88 for (cp
= num
; *cp
; cp
++) {
95 if (gobble('\n', line
))
96 connected
= gobble('!', line
);
100 sprintf(line
, "%d second dial timeout",
101 number(value(DIALTIMEOUT
)));
102 logent(value(HOST
), num
, "ventel", line
);
106 ven_disconnect(); /* insurance */
107 if (connected
|| timeout
|| !boolean(value(VERBOSE
)))
109 /* call failed, parse response for user */
110 cp
= index(line
, '\r');
113 for (cp
= line
; cp
= index(cp
, ' '); cp
++)
125 printf("%s...", msg
);
149 while (c
= *s
++) switch (c
) {
170 printf("\07timeout waiting for reply\n");
172 longjmp(timeoutbuf
, 1);
176 gobble(match
, response
)
180 register char *cp
= response
;
184 f
= signal(SIGALRM
, sigALRM
);
187 if (setjmp(timeoutbuf
)) {
192 alarm(number(value(DIALTIMEOUT
)));
197 if (boolean(value(VERBOSE
)))
200 } while (c
!= '\n' && c
!= match
);
201 signal(SIGALRM
, SIG_DFL
);
206 #define min(a,b) ((a)>(b)?(b):(a))
208 * This convoluted piece of code attempts to get
209 * the ventel in sync. If you don't have FIONREAD
210 * there are gory ways to simulate this.
215 int already
= 0, nread
;
219 * Toggle DTR to force anyone off that might have left
220 * the modem connected, and insure a consistent state
223 * If you don't have the ioctl calls to diddle directly
224 * with DTR, you can always try setting the baud rate to 0.
226 ioctl(FD
, TIOCCDTR
, 0);
228 ioctl(FD
, TIOCSDTR
, 0);
229 while (already
< MAXRETRY
) {
231 * After reseting the modem, send it two \r's to
232 * autobaud on. Make sure to delay between them
233 * so the modem can frame the incoming characters.
239 if (ioctl(fd
, FIONREAD
, (caddr_t
)&nread
) < 0) {
244 read(fd
, buf
, min(nread
, 60));
245 if ((buf
[nread
- 1] & 0177) == '$')
247 nread
-= min(nread
, 60);