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