date and time created 86/04/03 16:50:58 by donn
[unix-history] / usr / src / usr.bin / tip / aculib / v3451.c
CommitLineData
051b1e55
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
051b1e55
DF
8static char sccsid[] = "@(#)v3451.c 5.1 (Berkeley) %G%";
9#endif not lint
5e071e26 10
5e071e26
RC
11/*
12 * Routines for calling up on a Vadic 3451 Modem
13 */
14#include "tip.h"
5e071e26 15
6f2a0ce9 16static jmp_buf Sjbuf;
5e071e26 17
05862919 18v3451_dialer(num, acu)
5e071e26
RC
19 register char *num;
20 char *acu;
21{
6f2a0ce9
SL
22 int ok, (*func)();
23 int slow = number(value(BAUDRATE)) < 1200, rw = 2;
5e071e26
RC
24 char phone[50];
25#ifdef ACULOG
26 char line[80];
27#endif
5e071e26 28
5e071e26
RC
29 /*
30 * Get in synch
31 */
6f2a0ce9
SL
32 vawrite("I\r", 1 + slow);
33 vawrite("I\r", 1 + slow);
34 vawrite("I\r", 1 + slow);
35 vawrite("\005\r", 2 + slow);
36 if (!expect("READY")) {
5e071e26
RC
37 printf("can't synchronize with vadic 3451\n");
38#ifdef ACULOG
39 logent(value(HOST), num, "vadic", "can't synch up");
40#endif
41 return (0);
42 }
43 ioctl(FD, TIOCHPCL, 0);
44 sleep(1);
6f2a0ce9
SL
45 vawrite("D\r", 2 + slow);
46 if (!expect("NUMBER?")) {
5e071e26
RC
47 printf("Vadic will not accept dial command\n");
48#ifdef ACULOG
49 logent(value(HOST), num, "vadic", "will not accept dial");
50#endif
51 return (0);
52 }
6f2a0ce9
SL
53 strcpy(phone, num);
54 strcat(phone, "\r");
55 vawrite(phone, 1 + slow);
56 if (!expect(phone)) {
5e071e26
RC
57 printf("Vadic will not accept phone number\n");
58#ifdef ACULOG
59 logent(value(HOST), num, "vadic", "will not accept number");
60#endif
61 return (0);
62 }
63 func = signal(SIGINT,SIG_IGN);
6f2a0ce9
SL
64 /*
65 * You cannot interrupt the Vadic when its dialing;
66 * even dropping DTR does not work (definitely a
67 * brain damaged design).
68 */
69 vawrite("\r", 1 + slow);
70 vawrite("\r", 1 + slow);
71 if (!expect("DIALING:")) {
5e071e26
RC
72 printf("Vadic failed to dial\n");
73#ifdef ACULOG
74 logent(value(HOST), num, "vadic", "failed to dial");
75#endif
76 return (0);
6f2a0ce9
SL
77 }
78 if (boolean(value(VERBOSE)))
79 printf("\ndialing...");
5e071e26 80 ok = expect("ON LINE");
6f2a0ce9
SL
81 signal(SIGINT, func);
82 if (!ok) {
5e071e26
RC
83 printf("call failed\n");
84#ifdef ACULOG
85 logent(value(HOST), num, "vadic", "call failed");
86#endif
87 return (0);
88 }
6f2a0ce9 89 ioctl(FD, TIOCFLUSH, &rw);
5e071e26
RC
90 return (1);
91}
92
05862919 93v3451_disconnect()
5e071e26 94{
6f2a0ce9 95
5e071e26 96 close(FD);
5e071e26
RC
97}
98
05862919 99v3451_abort()
5e071e26 100{
5e071e26 101
6f2a0ce9 102 close(FD);
5e071e26
RC
103}
104
6f2a0ce9
SL
105static
106vawrite(cp, delay)
107 register char *cp;
108 int delay;
109{
5e071e26 110
6f2a0ce9
SL
111 for (; *cp; sleep(delay), cp++)
112 write(FD, cp, 1);
113}
5e071e26 114
6f2a0ce9
SL
115static
116expect(cp)
117 register char *cp;
5e071e26 118{
6f2a0ce9
SL
119 char buf[300];
120 register char *rp = buf;
121 int alarmtr(), timeout = 30, online = 0;
122
123 if (strcmp(cp, "\"\"") == 0)
124 return (1);
5e071e26
RC
125 *rp = 0;
126 /*
127 * If we are waiting for the Vadic to complete
128 * dialing and get a connection, allow more time
129 * Unfortunately, the Vadic times out 24 seconds after
130 * the last digit is dialed
131 */
6f2a0ce9
SL
132 online = strcmp(cp, "ON LINE") == 0;
133 if (online)
134 timeout = number(value(DIALTIMEOUT));
5e071e26 135 signal(SIGALRM, alarmtr);
6f2a0ce9
SL
136 if (setjmp(Sjbuf))
137 return (0);
138 alarm(timeout);
139 while (notin(cp, buf) && rp < buf + sizeof (buf) - 1) {
140 if (online && notin("FAILED CALL", buf) == 0)
141 return (0);
142 if (read(FD, rp, 1) < 0) {
5e071e26 143 alarm(0);
6f2a0ce9 144 return (0);
5e071e26 145 }
6f2a0ce9 146 if (*rp &= 0177)
5e071e26
RC
147 rp++;
148 *rp = '\0';
5e071e26
RC
149 }
150 alarm(0);
6f2a0ce9 151 return (1);
5e071e26
RC
152}
153
6f2a0ce9 154static
5e071e26
RC
155alarmtr()
156{
6f2a0ce9 157
5e071e26
RC
158 longjmp(Sjbuf, 1);
159}
160
6f2a0ce9 161static
5e071e26 162notin(sh, lg)
6f2a0ce9 163 char *sh, *lg;
5e071e26 164{
6f2a0ce9
SL
165
166 for (; *lg; lg++)
5e071e26 167 if (prefix(sh, lg))
6f2a0ce9
SL
168 return (0);
169 return (1);
5e071e26
RC
170}
171
6f2a0ce9 172static
5e071e26 173prefix(s1, s2)
6f2a0ce9 174 register char *s1, *s2;
5e071e26 175{
6f2a0ce9 176 register char c;
5e071e26
RC
177
178 while ((c = *s1++) == *s2++)
179 if (c == '\0')
6f2a0ce9
SL
180 return (1);
181 return (c == '\0');
5e071e26 182}