1 /* $OpenBSD: biz31.c,v 1.10 2006/03/17 19:17:13 moritz Exp $ */
2 /* $NetBSD: biz31.c,v 1.5 1997/02/11 09:24:14 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[] = "@(#)biz31.c 8.1 (Berkeley) 6/6/93";
41 static char rcsid[] = "$OpenBSD: biz31.c,v 1.10 2006/03/17 19:17:13 moritz Exp $";
47 #define MAXRETRY 3 /* sync up retry count */
48 #define DISCONNECT_CMD "\21\25\11\24" /* disconnection string */
50 static int biz_dialer(char *, char *);
51 static int bizsync(int);
52 static int echo(char *);
53 static void sigALRM(int);
54 static int detect(char *);
55 static int flush(char *);
56 static int bizsync(int);
58 static int timeout = 0;
59 static jmp_buf timeoutbuf;
62 * Dial up on a BIZCOMP Model 1031 with either
63 * tone dialing (mod = "f")
64 * pulse dialing (mod = "w")
67 biz_dialer(char *num, char *mod)
72 logent(value(HOST), "", "biz", "out of sync");
73 printf("bizcomp out of sync\n");
77 if (boolean(value(VERBOSE)))
78 printf("\nstarting call...");
79 echo("#\rk$\r$\n"); /* disable auto-answer */
80 echo("$>$.$ #\r"); /* tone/pulse dialing */
83 echo("$>$.$ #\re$ "); /* disconnection sequence */
86 echo("$>$.$ #\rr$ "); /* repeat dial */
89 if (boolean(value(VERBOSE)))
92 * The reply from the BIZCOMP should be:
93 * `^G NO CONNECTION\r\n^G\r\n' failure
94 * ` CONNECTION\r\n^G' success
96 connected = detect(" ");
101 (void)snprintf(line, sizeof line, "%ld second dial timeout",
102 number(value(DIALTIMEOUT)));
103 logent(value(HOST), num, "biz", line);
107 flush(" NO CONNECTION\r\n\07\r\n");
109 flush("CONNECTION\r\n\07");
111 biz31_disconnect(); /* insurance */
116 biz31w_dialer(char *num, char *acu)
118 return (biz_dialer(num, "w"));
122 biz31f_dialer(char *num, char *acu)
124 return (biz_dialer(num, "f"));
128 biz31_disconnect(void)
130 write(FD, DISCONNECT_CMD, sizeof(DISCONNECT_CMD)-1);
132 tcflush(FD, TCIOFLUSH);
146 while (c = *s++) switch (c) {
169 longjmp(timeoutbuf, 1);
178 f = signal(SIGALRM, sigALRM);
181 if (setjmp(timeoutbuf)) {
182 printf("\07timeout waiting for reply\n");
186 alarm(number(value(DIALTIMEOUT)));
193 return (timeout == 0);
202 f = signal(SIGALRM, sigALRM);
204 if (setjmp(timeoutbuf))
211 timeout = 0; /* guard against disconnection */
215 * This convoluted piece of code attempts to get
216 * the bizcomp in sync. If you don't have the capacity or nread
217 * call there are gory ways to simulate this.
224 # define chars(b) ((b).cp_nbytes)
225 # define IOCTL FIOCAPACITY
229 # define chars(b) (b)
230 # define IOCTL FIONREAD
236 if (ioctl(fd, IOCTL, (caddr_t)&b) >= 0 && chars(b) > 0)
237 tcflush(FD, TCIOFLUSH);
238 write(fd, "\rp>\r", 4);
240 if (ioctl(fd, IOCTL, (caddr_t)&b) >= 0) {
241 if (chars(b) != 10) {
243 if (already > MAXRETRY)
245 write(fd, DISCONNECT_CMD, 4);
251 if (strncmp(buf, "p >\r\n\r\n>", 8))