1 /* $NetBSD: ventel.c,v 1.14 2006/04/03 02:25:27 perry Exp $ */
4 * Copyright (c) 1983, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <sys/cdefs.h>
35 static char sccsid
[] = "@(#)ventel.c 8.1 (Berkeley) 6/6/93";
37 __RCSID("$NetBSD: ventel.c,v 1.14 2006/04/03 02:25:27 perry Exp $");
41 * Routines for calling up on a Ventel Modem
42 * The Ventel is expected to be strapped for local echo (just like uucp)
48 static int timeout
= 0;
49 static jmp_buf timeoutbuf
;
51 static void echo(const char *);
52 static int gobble(char, char *);
53 static void sigALRM(int);
54 static int vensync(int);
57 * some sleep calls have been replaced by usleep(DELAYUS)
58 * because some ventel modems require two <cr>s in less than
59 * a second in order to 'wake up'
61 #define DELAYUS 100000 /* delay in microseconds */
65 ven_dialer(char *num
, char *acu __unused
)
73 * Get in synch with a couple of carriage returns
76 (void)printf("can't synchronize with ventel\n");
79 if (boolean(value(VERBOSE
)))
80 (void)printf("\ndialing...");
82 (void)tcgetattr(FD
, &cntrl
);
83 cntrl
.c_cflag
|= HUPCL
;
84 (void)tcsetattr(FD
, TCSANOW
, &cntrl
);
85 echo("#k$\r$\n$D$I$A$L$:$ ");
86 for (cp
= num
; *cp
; cp
++) {
87 (void)usleep(DELAYUS
);
88 (void)write(FD
, cp
, 1);
90 (void)usleep(DELAYUS
);
91 (void)write(FD
, "\r", 1);
92 (void)gobble('\n', line
);
93 if (gobble('\n', line
))
94 connected
= gobble('!', line
);
95 (void)tcflush(FD
, TCIOFLUSH
);
97 ven_disconnect(); /* insurance */
98 if (connected
|| timeout
|| !boolean(value(VERBOSE
)))
100 /* call failed, parse response for user */
101 cp
= strchr(line
, '\r');
104 for (cp
= line
; (cp
= strchr(cp
, ' ')) != NULL
; cp
++)
112 if (isupper((unsigned char)*cp
))
113 *cp
= tolower((unsigned char)*cp
);
116 (void)printf("%s...", msg
);
132 (void)write(FD
, "\03", 1);
141 while ((c
= *s
++) != 0) switch (c
) {
144 (void)read(FD
, &c
, 1);
150 (void)write(FD
, &c
, 1);
154 (void)write(FD
, &c
, 1);
155 (void)read(FD
, &c
, 1);
161 sigALRM(int dummy __unused
)
164 (void)printf("\07timeout waiting for reply\n");
166 longjmp(timeoutbuf
, 1);
170 gobble(char match
, char response
[])
177 f
= signal(SIGALRM
, sigALRM
);
180 if (setjmp(timeoutbuf
)) {
181 (void)signal(SIGALRM
, f
);
185 (void)alarm((unsigned)number(value(DIALTIMEOUT
)));
186 (void)read(FD
, cp
, 1);
190 if (boolean(value(VERBOSE
)))
193 } while (c
!= '\n' && c
!= match
);
194 (void)signal(SIGALRM
, SIG_DFL
);
199 #define min(a,b) ((a)>(b)?(b):(a))
201 * This convoluted piece of code attempts to get
202 * the ventel in sync. If you don't have FIONREAD
203 * there are gory ways to simulate this.
208 int already
= 0, nread
;
212 * Toggle DTR to force anyone off that might have left
213 * the modem connected, and insure a consistent state
216 * If you don't have the ioctl calls to diddle directly
217 * with DTR, you can always try setting the baud rate to 0.
219 (void)ioctl(FD
, TIOCCDTR
, 0);
221 (void)ioctl(FD
, TIOCSDTR
, 0);
222 while (already
< MAXRETRY
) {
224 * After reseting the modem, send it two \r's to
225 * autobaud on. Make sure to delay between them
226 * so the modem can frame the incoming characters.
228 (void)write(fd
, "\r", 1);
229 (void)usleep(DELAYUS
);
230 (void)write(fd
, "\r", 1);
232 if (ioctl(fd
, FIONREAD
, &nread
) < 0) {
233 perror("tip: ioctl");
237 (void)read(fd
, buf
, min(nread
, sizeof buf
));
238 if ((buf
[min(nread
, sizeof buf
) - 1] & 0177) == '$')
240 nread
-= min(nread
, 60);