1 /* $OpenBSD: v3451.c,v 1.9 2006/03/17 19:17:13 moritz Exp $ */
2 /* $NetBSD: v3451.c,v 1.6 1997/02/11 09:24:20 mrg Exp $ */
5 * Copyright (c) 1983, 1993
6 * The Regents of the University of California. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
38 static char sccsid[] = "@(#)v3451.c 8.1 (Berkeley) 6/6/93";
39 static const char rcsid[] = "$OpenBSD: v3451.c,v 1.9 2006/03/17 19:17:13 moritz Exp $";
44 * Routines for calling up on a Vadic 3451 Modem
50 static void vawrite(char *, int);
51 static int expect(char *);
52 static void alarmtr(int);
53 static int notin(char *, char *);
54 static int prefix(char *, char *);
57 v3451_dialer(char *num, char *acu)
61 int slow = number(value(BAUDRATE)) < 1200;
68 vawrite("I\r", 1 + slow);
69 vawrite("I\r", 1 + slow);
70 vawrite("I\r", 1 + slow);
71 vawrite("\005\r", 2 + slow);
72 if (!expect("READY")) {
73 printf("can't synchronize with vadic 3451\n");
75 logent(value(HOST), num, "vadic", "can't synch up");
79 tcgetattr(FD, &cntrl);
80 term.c_cflag |= HUPCL;
81 tcsetattr(FD, TCSANOW, &cntrl);
83 vawrite("D\r", 2 + slow);
84 if (!expect("NUMBER?")) {
85 printf("Vadic will not accept dial command\n");
87 logent(value(HOST), num, "vadic", "will not accept dial");
91 (void)snprintf(phone, sizeof phone, "%s\r", num);
92 vawrite(phone, 1 + slow);
94 printf("Vadic will not accept phone number\n");
96 logent(value(HOST), num, "vadic", "will not accept number");
100 func = signal(SIGINT,SIG_IGN);
102 * You cannot interrupt the Vadic when its dialing;
103 * even dropping DTR does not work (definitely a
104 * brain damaged design).
106 vawrite("\r", 1 + slow);
107 vawrite("\r", 1 + slow);
108 if (!expect("DIALING:")) {
109 printf("Vadic failed to dial\n");
111 logent(value(HOST), num, "vadic", "failed to dial");
115 if (boolean(value(VERBOSE)))
116 printf("\ndialing...");
117 ok = expect("ON LINE");
118 signal(SIGINT, func);
120 printf("call failed\n");
122 logent(value(HOST), num, "vadic", "call failed");
126 tcflush(FD, TCIOFLUSH);
131 v3451_disconnect(void)
143 vawrite(char *cp, int delay)
145 for (; *cp; sleep(delay), cp++)
154 int timeout = 30, online = 0;
156 if (strcmp(cp, "\"\"") == 0)
160 * If we are waiting for the Vadic to complete
161 * dialing and get a connection, allow more time
162 * Unfortunately, the Vadic times out 24 seconds after
163 * the last digit is dialed
165 online = strcmp(cp, "ON LINE") == 0;
167 timeout = number(value(DIALTIMEOUT));
168 signal(SIGALRM, alarmtr);
172 while (notin(cp, buf) && rp < buf + sizeof (buf) - 1) {
173 if (online && notin("FAILED CALL", buf) == 0)
175 if (read(FD, rp, 1) < 0) {
195 notin(char *sh, char *lg)
204 prefix(char *s1, char *s2)
208 while ((c = *s1++) == *s2++)