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