BSD 4_1c_2 release
[unix-history] / usr / src / usr.bin / tip / biz22.c
CommitLineData
a0c21c7b
C
1/* biz22.c 4.1 81/11/29 */
2#include "tip.h"
3
4#if BIZ1022
5#define DISCONNECT "\20\04" /* disconnection string */
6
7static int sigALRM();
8static int timeout = 0;
9
10/*
11 * Dial up on a BIZCOMP Model 1022 with either
12 * tone dialing (mod = "V")
13 * pulse dialing (mod = "W")
14 */
15static int
16biz_dialer(num, mod)
17 char *num, *mod;
18{
19 register int connected = 0;
20 char cbuf[40];
21
22 if (boolean(value(VERBOSE)))
23 printf("\nstarting call...");
24 /*
25 * Disable auto-answer and configure for tone/pulse
26 * dialing
27 */
28 if (cmd("\02K\r")) {
29 printf("can't initialize bizcomp...");
30 return (0);
31 }
32 strcpy(cbuf, "\02.\r");
33 cbuf[1] = *mod;
34 if (cmd(cbuf)) {
35 printf("can't set dialing mode...");
36 return (0);
37 }
38 strcpy(cbuf, "\02D");
39 strcat(cbuf, num);
40 strcat(cbuf, "\r");
41 write(FD, cbuf, strlen(cbuf));
42 if (!detect("7\r")) {
43 printf("can't get dial tone...");
44 return (0);
45 }
46 if (boolean(value(VERBOSE)))
47 printf("ringing...");
48 /*
49 * The reply from the BIZCOMP should be:
50 * 2 \r or 7 \r failure
51 * 1 \r success
52 */
53 connected = detect("1\r");
54#ifdef ACULOG
55 if (timeout) {
56 char line[80];
57
58 sprintf(line, "%d second dial timeout",
59 number(value(DIALTIMEOUT)));
60 logent(value(HOST), num, "biz1022", line);
61 }
62#endif
63 if (timeout)
64 biz22_disconnect(); /* insurance */
65 return (connected);
66}
67
68biz22w_dialer(num, acu)
69 char *num, *acu;
70{
71 return (biz_dialer(num, "W"));
72}
73
74biz22f_dialer(num, acu)
75 char *num, *acu;
76{
77 return (biz_dialer(num, "V"));
78}
79
80biz22_disconnect()
81{
82 write(FD, DISCONNECT, 4);
83 sleep(2);
84 ioctl(FD, TIOCFLUSH);
85}
86
87biz22_abort()
88{
89 write(FD, "\02", 1);
90 timeout = 1;
91}
92
93static int
94sigALRM()
95{
96 signal(SIGALRM, SIG_IGN);
97 printf("\07timeout waiting for reply\n");
98 timeout = 1;
99}
100
101static int
102cmd(s)
103 register char *s;
104{
105 char c;
106
107 write(FD, s, strlen(s));
108 timeout = 0;
109 signal(SIGALRM, biz22_abort);
110 alarm(number(value(DIALTIMEOUT)));
111 read(FD, &c, 1);
112 alarm(0);
113 signal(SIGALRM, SIG_DFL);
114 if (timeout)
115 return (1);
116 c &= 0177;
117 return (c != '\r');
118}
119
120static int
121detect(s)
122 register char *s;
123{
124 char c;
125
126 signal(SIGALRM, biz22_abort);
127 timeout = 0;
128 while (*s) {
129 alarm(number(value(DIALTIMEOUT)));
130 read(FD, &c, 1);
131 alarm(0);
132 if (timeout)
133 return (0);
134 c &= 0177;
135 if (c != *s++)
136 return (0);
137 }
138 signal(SIGALRM, SIG_DFL);
139 return (1);
140}