1 /* $NetBSD: biz22.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
[] = "@(#)biz22.c 8.1 (Berkeley) 6/6/93";
37 __RCSID("$NetBSD: biz22.c,v 1.11 2006/04/03 02:25:27 perry Exp $");
42 #define DISCONNECT_CMD "\20\04" /* disconnection string */
44 static int btimeout
= 0;
45 static jmp_buf timeoutbuf
;
47 static int biz_dialer(char *, const char *);
48 static int cmd(const char *);
49 static int detect(const char *);
50 static void sigALRM(int);
53 * Dial up on a BIZCOMP Model 1022 with either
54 * tone dialing (mod = "V")
55 * pulse dialing (mod = "W")
58 biz_dialer(char *num
, const char *mod
)
63 if (boolean(value(VERBOSE
)))
64 (void)printf("\nstarting call...");
66 * Disable auto-answer and configure for tone/pulse
70 (void)printf("can't initialize bizcomp...");
73 (void)strncpy(cbuf
, "\02.\r", sizeof(cbuf
) - 1);
76 (void)printf("can't set dialing mode...");
79 (void)snprintf(cbuf
, sizeof cbuf
, "\02D%s\r", num
);
80 (void)write(FD
, cbuf
, strlen(cbuf
));
82 (void)printf("can't get dial tone...");
85 if (boolean(value(VERBOSE
)))
86 (void)printf("ringing...");
88 * The reply from the BIZCOMP should be:
89 * 2 \r or 7 \r failure
92 connected
= detect("1\r");
94 biz22_disconnect(); /* insurance */
100 biz22w_dialer(char *num
, char *acu __unused
)
103 return (biz_dialer(num
, "W"));
108 biz22f_dialer(char *num
, char *acu __unused
)
111 return (biz_dialer(num
, "V"));
115 biz22_disconnect(void)
118 (void)write(FD
, DISCONNECT_CMD
, 4);
120 (void)tcflush(FD
, TCIOFLUSH
);
127 (void)write(FD
, "\02", 1);
132 sigALRM(int dummy __unused
)
136 longjmp(timeoutbuf
, 1);
145 (void)write(FD
, s
, strlen(s
));
146 f
= signal(SIGALRM
, sigALRM
);
147 if (setjmp(timeoutbuf
)) {
149 (void)signal(SIGALRM
, f
);
152 (void)alarm((unsigned)number(value(DIALTIMEOUT
)));
153 (void)read(FD
, &c
, 1);
155 (void)signal(SIGALRM
, f
);
161 detect(const char * volatile s
)
166 f
= signal(SIGALRM
, sigALRM
);
169 if (setjmp(timeoutbuf
)) {
173 (void)alarm((unsigned)number(value(DIALTIMEOUT
)));
174 (void)read(FD
, &c
, 1);
180 (void)signal(SIGALRM
, f
);
181 return (btimeout
== 0);