new template
[unix-history] / usr / src / usr.bin / tip / aculib / biz22.c
CommitLineData
d0aeaf5a
DF
1/*
2 * Copyright (c) 1983 Regents of the University of California.
3 * All rights reserved. The Berkeley software License Agreement
4 * specifies the terms and conditions for redistribution.
5 */
6
05862919 7#ifndef lint
d0aeaf5a
DF
8static char sccsid[] = "@(#)biz22.c 5.1 (Berkeley) %G%";
9#endif not lint
05862919 10
cabb8583
SL
11#include "tip.h"
12
05862919 13#define DISCONNECT_CMD "\20\04" /* disconnection string */
cabb8583 14
05862919
SL
15static int sigALRM();
16static int timeout = 0;
17static jmp_buf timeoutbuf;
cabb8583
SL
18
19/*
20 * Dial up on a BIZCOMP Model 1022 with either
21 * tone dialing (mod = "V")
22 * pulse dialing (mod = "W")
23 */
24static int
25biz_dialer(num, mod)
26 char *num, *mod;
27{
28 register int connected = 0;
29 char cbuf[40];
30
31 if (boolean(value(VERBOSE)))
32 printf("\nstarting call...");
33 /*
34 * Disable auto-answer and configure for tone/pulse
35 * dialing
36 */
37 if (cmd("\02K\r")) {
38 printf("can't initialize bizcomp...");
39 return (0);
40 }
41 strcpy(cbuf, "\02.\r");
42 cbuf[1] = *mod;
43 if (cmd(cbuf)) {
44 printf("can't set dialing mode...");
45 return (0);
46 }
47 strcpy(cbuf, "\02D");
48 strcat(cbuf, num);
49 strcat(cbuf, "\r");
50 write(FD, cbuf, strlen(cbuf));
51 if (!detect("7\r")) {
52 printf("can't get dial tone...");
53 return (0);
54 }
55 if (boolean(value(VERBOSE)))
56 printf("ringing...");
57 /*
58 * The reply from the BIZCOMP should be:
59 * 2 \r or 7 \r failure
60 * 1 \r success
61 */
62 connected = detect("1\r");
63#ifdef ACULOG
64 if (timeout) {
65 char line[80];
66
67 sprintf(line, "%d second dial timeout",
68 number(value(DIALTIMEOUT)));
69 logent(value(HOST), num, "biz1022", line);
70 }
71#endif
72 if (timeout)
73 biz22_disconnect(); /* insurance */
74 return (connected);
75}
76
77biz22w_dialer(num, acu)
78 char *num, *acu;
79{
05862919 80
cabb8583
SL
81 return (biz_dialer(num, "W"));
82}
83
84biz22f_dialer(num, acu)
85 char *num, *acu;
86{
05862919 87
cabb8583
SL
88 return (biz_dialer(num, "V"));
89}
90
91biz22_disconnect()
92{
05862919
SL
93 int rw = 2;
94
95 write(FD, DISCONNECT_CMD, 4);
cabb8583 96 sleep(2);
05862919 97 ioctl(FD, TIOCFLUSH, &rw);
cabb8583
SL
98}
99
100biz22_abort()
101{
05862919 102
cabb8583 103 write(FD, "\02", 1);
cabb8583
SL
104}
105
106static int
107sigALRM()
108{
05862919 109
cabb8583 110 timeout = 1;
05862919 111 longjmp(timeoutbuf, 1);
cabb8583
SL
112}
113
114static int
115cmd(s)
116 register char *s;
117{
118 char c;
05862919 119 int (*f)();
cabb8583
SL
120
121 write(FD, s, strlen(s));
05862919
SL
122 f = signal(SIGALRM, sigALRM);
123 if (setjmp(timeoutbuf)) {
124 biz22_abort();
125 signal(SIGALRM, f);
126 return (1);
127 }
cabb8583
SL
128 alarm(number(value(DIALTIMEOUT)));
129 read(FD, &c, 1);
130 alarm(0);
05862919 131 signal(SIGALRM, f);
cabb8583
SL
132 c &= 0177;
133 return (c != '\r');
134}
135
136static int
137detect(s)
138 register char *s;
139{
140 char c;
05862919 141 int (*f)();
cabb8583 142
05862919 143 f = signal(SIGALRM, sigALRM);
cabb8583
SL
144 timeout = 0;
145 while (*s) {
05862919
SL
146 if (setjmp(timeoutbuf)) {
147 biz22_abort();
148 break;
149 }
cabb8583
SL
150 alarm(number(value(DIALTIMEOUT)));
151 read(FD, &c, 1);
152 alarm(0);
cabb8583
SL
153 c &= 0177;
154 if (c != *s++)
155 return (0);
156 }
05862919
SL
157 signal(SIGALRM, f);
158 return (timeout == 0);
cabb8583 159}