1 /* $NetBSD: v3451.c,v 1.12 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
[] = "@(#)v3451.c 8.1 (Berkeley) 6/6/93";
37 __RCSID("$NetBSD: v3451.c,v 1.12 2006/04/03 02:25:27 perry Exp $");
41 * Routines for calling up on a Vadic 3451 Modem
47 static void alarmtr(int);
48 static int expect(const char *);
49 static int notin(const char *, char *);
50 static int prefix(const char *, char *);
51 static void vawrite(const char *, int);
55 v3451_dialer(char *num
, char *acu __unused
)
59 int slow
= number(value(BAUDRATE
)) < 1200;
66 vawrite("I\r", 1 + slow
);
67 vawrite("I\r", 1 + slow
);
68 vawrite("I\r", 1 + slow
);
69 vawrite("\005\r", 2 + slow
);
70 if (!expect("READY")) {
71 (void)printf("can't synchronize with vadic 3451\n");
74 (void)tcgetattr(FD
, &cntrl
);
75 term
.c_cflag
|= HUPCL
;
76 (void)tcsetattr(FD
, TCSANOW
, &cntrl
);
78 vawrite("D\r", 2 + slow
);
79 if (!expect("NUMBER?")) {
80 (void)printf("Vadic will not accept dial command\n");
83 (void)snprintf(phone
, sizeof phone
, "%s\r", num
);
84 vawrite(phone
, 1 + slow
);
86 (void)printf("Vadic will not accept phone number\n");
89 func
= signal(SIGINT
,SIG_IGN
);
91 * You cannot interrupt the Vadic when its dialing;
92 * even dropping DTR does not work (definitely a
93 * brain damaged design).
95 vawrite("\r", 1 + slow
);
96 vawrite("\r", 1 + slow
);
97 if (!expect("DIALING:")) {
98 (void)printf("Vadic failed to dial\n");
101 if (boolean(value(VERBOSE
)))
102 (void)printf("\ndialing...");
103 ok
= expect("ON LINE");
104 (void)signal(SIGINT
, func
);
106 (void)printf("call failed\n");
109 (void)tcflush(FD
, TCIOFLUSH
);
114 v3451_disconnect(void)
128 vawrite(const char *cp
, int delay
)
131 for (/*EMPTY*/; *cp
; cp
++) {
132 (void)write(FD
, cp
, 1);
133 (void)sleep((unsigned)delay
);
138 expect(const char *cp
)
142 int volatile timeout
;
149 if (strcmp(cp
, "\"\"") == 0)
153 * If we are waiting for the Vadic to complete
154 * dialing and get a connection, allow more time
155 * Unfortunately, the Vadic times out 24 seconds after
156 * the last digit is dialed
158 online
= strcmp(cp
, "ON LINE") == 0;
160 timeout
= number(value(DIALTIMEOUT
));
161 (void)signal(SIGALRM
, alarmtr
);
164 (void)alarm((unsigned)timeout
);
165 while (notin(cp
, buf
) && rp
< buf
+ sizeof (buf
) - 1) {
166 if (online
&& notin("FAILED CALL", buf
) == 0)
168 if (read(FD
, rp
, 1) < 0) {
182 alarmtr(int dummy __unused
)
189 notin(const char *sh
, char *lg
)
199 prefix(const char *s1
, char *s2
)
203 while ((c
= *s1
++) == *s2
++)