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