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 * 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[] = "@(#)biz31.c 8.1 (Berkeley) 6/6/93";
39 static char rcsid[] = "$OpenBSD: biz31.c,v 1.10 2006/03/17 19:17:13 moritz Exp $";
45 #define MAXRETRY 3 /* sync up retry count */
46 #define DISCONNECT_CMD "\21\25\11\24" /* disconnection string */
48 static int biz_dialer(char *, char *);
49 static int bizsync(int);
50 static int echo(char *);
51 static void sigALRM(int);
52 static int detect(char *);
53 static int flush(char *);
54 static int bizsync(int);
56 static int timeout = 0;
57 static jmp_buf timeoutbuf;
60 * Dial up on a BIZCOMP Model 1031 with either
61 * tone dialing (mod = "f")
62 * pulse dialing (mod = "w")
65 biz_dialer(char *num, char *mod)
70 logent(value(HOST), "", "biz", "out of sync");
71 printf("bizcomp out of sync\n");
75 if (boolean(value(VERBOSE)))
76 printf("\nstarting call...");
77 echo("#\rk$\r$\n"); /* disable auto-answer */
78 echo("$>$.$ #\r"); /* tone/pulse dialing */
81 echo("$>$.$ #\re$ "); /* disconnection sequence */
84 echo("$>$.$ #\rr$ "); /* repeat dial */
87 if (boolean(value(VERBOSE)))
90 * The reply from the BIZCOMP should be:
91 * `^G NO CONNECTION\r\n^G\r\n' failure
92 * ` CONNECTION\r\n^G' success
94 connected = detect(" ");
99 (void)snprintf(line, sizeof line, "%ld second dial timeout",
100 number(value(DIALTIMEOUT)));
101 logent(value(HOST), num, "biz", line);
105 flush(" NO CONNECTION\r\n\07\r\n");
107 flush("CONNECTION\r\n\07");
109 biz31_disconnect(); /* insurance */
114 biz31w_dialer(char *num, char *acu)
116 return (biz_dialer(num, "w"));
120 biz31f_dialer(char *num, char *acu)
122 return (biz_dialer(num, "f"));
126 biz31_disconnect(void)
128 write(FD, DISCONNECT_CMD, sizeof(DISCONNECT_CMD)-1);
130 tcflush(FD, TCIOFLUSH);
144 while (c = *s++) switch (c) {
167 longjmp(timeoutbuf, 1);
176 f = signal(SIGALRM, sigALRM);
179 if (setjmp(timeoutbuf)) {
180 printf("\07timeout waiting for reply\n");
184 alarm(number(value(DIALTIMEOUT)));
191 return (timeout == 0);
200 f = signal(SIGALRM, sigALRM);
202 if (setjmp(timeoutbuf))
209 timeout = 0; /* guard against disconnection */
213 * This convoluted piece of code attempts to get
214 * the bizcomp in sync. If you don't have the capacity or nread
215 * call there are gory ways to simulate this.
222 # define chars(b) ((b).cp_nbytes)
223 # define IOCTL FIOCAPACITY
227 # define chars(b) (b)
228 # define IOCTL FIONREAD
234 if (ioctl(fd, IOCTL, (caddr_t)&b) >= 0 && chars(b) > 0)
235 tcflush(FD, TCIOFLUSH);
236 write(fd, "\rp>\r", 4);
238 if (ioctl(fd, IOCTL, (caddr_t)&b) >= 0) {
239 if (chars(b) != 10) {
241 if (already > MAXRETRY)
243 write(fd, DISCONNECT_CMD, 4);
249 if (strncmp(buf, "p >\r\n\r\n>", 8))