biz22.c revision 1.5 1 /* $NetBSD: biz22.c,v 1.5 1996/12/29 10:41:55 cgd Exp $ */
2
3 /*
4 * Copyright (c) 1983, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
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. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the University of
18 * California, Berkeley and its contributors.
19 * 4. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 */
35
36 #ifndef lint
37 #if 0
38 static char sccsid[] = "@(#)biz22.c 8.1 (Berkeley) 6/6/93";
39 #endif
40 static char rcsid[] = "$NetBSD: biz22.c,v 1.5 1996/12/29 10:41:55 cgd Exp $";
41 #endif /* not lint */
42
43 #include "tip.h"
44
45 #define DISCONNECT_CMD "\20\04" /* disconnection string */
46
47 static void sigALRM();
48 static int timeout = 0;
49 static jmp_buf timeoutbuf;
50
51 static int cmd(), detect();
52
53 /*
54 * Dial up on a BIZCOMP Model 1022 with either
55 * tone dialing (mod = "V")
56 * pulse dialing (mod = "W")
57 */
58 static int
59 biz_dialer(num, mod)
60 char *num, *mod;
61 {
62 register int connected = 0;
63 char cbuf[40];
64
65 if (boolean(value(VERBOSE)))
66 printf("\nstarting call...");
67 /*
68 * Disable auto-answer and configure for tone/pulse
69 * dialing
70 */
71 if (cmd("\02K\r")) {
72 printf("can't initialize bizcomp...");
73 return (0);
74 }
75 strcpy(cbuf, "\02.\r");
76 cbuf[1] = *mod;
77 if (cmd(cbuf)) {
78 printf("can't set dialing mode...");
79 return (0);
80 }
81 strcpy(cbuf, "\02D");
82 strcat(cbuf, num);
83 strcat(cbuf, "\r");
84 write(FD, cbuf, strlen(cbuf));
85 if (!detect("7\r")) {
86 printf("can't get dial tone...");
87 return (0);
88 }
89 if (boolean(value(VERBOSE)))
90 printf("ringing...");
91 /*
92 * The reply from the BIZCOMP should be:
93 * 2 \r or 7 \r failure
94 * 1 \r success
95 */
96 connected = detect("1\r");
97 #ifdef ACULOG
98 if (timeout) {
99 char line[80];
100
101 sprintf(line, "%d second dial timeout",
102 number(value(DIALTIMEOUT)));
103 logent(value(HOST), num, "biz1022", line);
104 }
105 #endif
106 if (timeout)
107 biz22_disconnect(); /* insurance */
108 return (connected);
109 }
110
111 biz22w_dialer(num, acu)
112 char *num, *acu;
113 {
114
115 return (biz_dialer(num, "W"));
116 }
117
118 biz22f_dialer(num, acu)
119 char *num, *acu;
120 {
121
122 return (biz_dialer(num, "V"));
123 }
124
125 biz22_disconnect()
126 {
127 int rw = 2;
128
129 write(FD, DISCONNECT_CMD, 4);
130 sleep(2);
131 tcflush(FD, TCIOFLUSH);
132 }
133
134 biz22_abort()
135 {
136
137 write(FD, "\02", 1);
138 }
139
140 static void
141 sigALRM()
142 {
143
144 timeout = 1;
145 longjmp(timeoutbuf, 1);
146 }
147
148 static int
149 cmd(s)
150 register char *s;
151 {
152 sig_t f;
153 char c;
154
155 write(FD, s, strlen(s));
156 f = signal(SIGALRM, sigALRM);
157 if (setjmp(timeoutbuf)) {
158 biz22_abort();
159 signal(SIGALRM, f);
160 return (1);
161 }
162 alarm(number(value(DIALTIMEOUT)));
163 read(FD, &c, 1);
164 alarm(0);
165 signal(SIGALRM, f);
166 c &= 0177;
167 return (c != '\r');
168 }
169
170 static int
171 detect(s)
172 register char *s;
173 {
174 sig_t f;
175 char c;
176
177 f = signal(SIGALRM, sigALRM);
178 timeout = 0;
179 while (*s) {
180 if (setjmp(timeoutbuf)) {
181 biz22_abort();
182 break;
183 }
184 alarm(number(value(DIALTIMEOUT)));
185 read(FD, &c, 1);
186 alarm(0);
187 c &= 0177;
188 if (c != *s++)
189 return (0);
190 }
191 signal(SIGALRM, f);
192 return (timeout == 0);
193 }
194