1 /* $NetBSD: biz31.c,v 1.11 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
[] = "@(#)biz31.c 8.1 (Berkeley) 6/6/93";
37 __RCSID("$NetBSD: biz31.c,v 1.11 2006/04/03 02:25:27 perry Exp $");
42 #define MAXRETRY 3 /* sync up retry count */
43 #define DISCONNECT_CMD "\21\25\11\24" /* disconnection string */
45 static void sigALRM(int);
46 static int timeout
= 0;
47 static jmp_buf timeoutbuf
;
49 static void echo(const char *);
50 static int detect(const char *);
51 static void flush(const char *);
52 static int bizsync(int);
55 * Dial up on a BIZCOMP Model 1031 with either
56 * tone dialing (mod = "f")
57 * pulse dialing (mod = "w")
60 biz_dialer(char *num
, const char *mod
)
65 logent(value(HOST
), "", "biz", "out of sync");
66 (void)printf("bizcomp out of sync\n");
69 if (boolean(value(VERBOSE
)))
70 (void)printf("\nstarting call...");
71 echo("#\rk$\r$\n"); /* disable auto-answer */
72 echo("$>$.$ #\r"); /* tone/pulse dialing */
75 echo("$>$.$ #\re$ "); /* disconnection sequence */
78 echo("$>$.$ #\rr$ "); /* repeat dial */
81 if (boolean(value(VERBOSE
)))
82 (void)printf("ringing...");
84 * The reply from the BIZCOMP should be:
85 * `^G NO CONNECTION\r\n^G\r\n' failure
86 * ` CONNECTION\r\n^G' success
88 connected
= detect(" ");
90 flush(" NO CONNECTION\r\n\07\r\n");
92 flush("CONNECTION\r\n\07");
94 biz31_disconnect(); /* insurance */
100 biz31w_dialer(char *num
, char *acu __unused
)
103 return (biz_dialer(num
, "w"));
108 biz31f_dialer(char *num
, char *acu __unused
)
111 return (biz_dialer(num
, "f"));
115 biz31_disconnect(void)
118 (void)write(FD
, DISCONNECT_CMD
, 4);
120 (void)tcflush(FD
, TCIOFLUSH
);
127 (void)write(FD
, "\33", 1);
135 while ((c
= *s
++) != '\0')
138 (void)read(FD
, &c
, 1);
144 (void)write(FD
, &c
, 1);
148 (void)write(FD
, &c
, 1);
149 (void)read(FD
, &c
, 1);
155 sigALRM(int signo __unused
)
159 longjmp(timeoutbuf
, 1);
163 detect(const char *s
)
168 f
= signal(SIGALRM
, sigALRM
);
171 if (setjmp(timeoutbuf
)) {
172 (void)printf("\07timeout waiting for reply\n");
176 (void)alarm((unsigned)number(value(DIALTIMEOUT
)));
177 (void)read(FD
, &c
, 1);
182 (void)signal(SIGALRM
, f
);
183 return (timeout
== 0);
192 f
= signal(SIGALRM
, sigALRM
);
194 if (setjmp(timeoutbuf
))
197 (void)read(FD
, &c
, 1);
200 (void)signal(SIGALRM
, f
);
201 timeout
= 0; /* guard against disconnection */
205 * This convoluted piece of code attempts to get
206 * the bizcomp in sync. If you don't have the capacity or nread
207 * call there are gory ways to simulate this.
214 # define chars(b) ((b).cp_nbytes)
215 # define IOCTL FIOCAPACITY
219 # define chars(b) (b)
220 # define IOCTL FIONREAD
226 if (ioctl(fd
, IOCTL
, &b
) >= 0 && chars(b
) > 0)
227 (void)tcflush(FD
, TCIOFLUSH
);
228 (void)write(fd
, "\rp>\r", 4);
230 if (ioctl(fd
, IOCTL
, &b
) >= 0) {
231 if (chars(b
) != 10) {
233 if (already
> MAXRETRY
)
235 (void)write(fd
, DISCONNECT_CMD
, 4);
240 (void)read(fd
, buf
, 10);
241 if (strncmp(buf
, "p >\r\n\r\n>", 8))