xref: /illumos-gate/usr/src/cmd/tip/aculib/v3451.c (revision 7c478bd9)
1 /*
2  * Copyright (c) 2000 by Sun Microsystems, Inc.
3  * All rights reserved.
4  */
5 
6 /* from UCB 4.4 6/25/83 */
7 /*
8  * Copyright (c) 1983 Regents of the University of California.
9  * All rights reserved. The Berkeley software License Agreement
10  * specifies the terms and conditions for redistribution.
11  */
12 #pragma ident	"%Z%%M%	%I%	%E% SMI"
13 
14 /*
15  * Routines for calling up on a Vadic 3451 Modem
16  */
17 #include "tip.h"
18 
19 static	sigjmp_buf Sjbuf;
20 
21 v3451_dialer(num, acu)
22 	register char *num;
23 	char *acu;
24 {
25 	int ok;
26 	void (*func)();
27 	struct termios buf;
28 	int slow = number(value(BAUDRATE)) < 1200;
29 	char phone[50];
30 #ifdef ACULOG
31 	char line[80];
32 #endif
33 
34 	/*
35 	 * Get in synch
36 	 */
37 	vawrite("I\r", 1 + slow);
38 	vawrite("I\r", 1 + slow);
39 	vawrite("I\r", 1 + slow);
40 	vawrite("\005\r", 2 + slow);
41 	if (!expect("READY")) {
42 		printf("can't synchronize with vadic 3451\n");
43 #ifdef ACULOG
44 		logent(value(HOST), num, "vadic", "can't synch up");
45 #endif
46 		return (0);
47 	}
48 	ioctl(FD, TCGETS, &buf);
49 	buf.c_cflag |= HUPCL;
50 	ioctl(FD, TCSETSF, &buf);
51 	sleep(1);
52 	vawrite("D\r", 2 + slow);
53 	if (!expect("NUMBER?")) {
54 		printf("Vadic will not accept dial command\n");
55 #ifdef ACULOG
56 		logent(value(HOST), num, "vadic", "will not accept dial");
57 #endif
58 		return (0);
59 	}
60 	strlcpy(phone, num, sizeof (phone));
61 	strlcat(phone, "\r", sizeof (phone));
62 	vawrite(phone, 1 + slow);
63 	if (!expect(phone)) {
64 		printf("Vadic will not accept phone number\n");
65 #ifdef ACULOG
66 		logent(value(HOST), num, "vadic", "will not accept number");
67 #endif
68 		return (0);
69 	}
70 	func = signal(SIGINT, SIG_IGN);
71 	/*
72 	 * You cannot interrupt the Vadic when its dialing;
73 	 * even dropping DTR does not work (definitely a
74 	 * brain damaged design).
75 	 */
76 	vawrite("\r", 1 + slow);
77 	vawrite("\r", 1 + slow);
78 	if (!expect("DIALING:")) {
79 		printf("Vadic failed to dial\n");
80 #ifdef ACULOG
81 		logent(value(HOST), num, "vadic", "failed to dial");
82 #endif
83 		return (0);
84 	}
85 	if (boolean(value(VERBOSE)))
86 		printf("\ndialing...");
87 	ok = expect("ON LINE");
88 	signal(SIGINT, func);
89 	if (!ok) {
90 		printf("call failed\n");
91 #ifdef ACULOG
92 		logent(value(HOST), num, "vadic", "call failed");
93 #endif
94 		return (0);
95 	}
96 	ioctl(FD, TCFLSH, TCOFLUSH);
97 	return (1);
98 }
99 
100 v3451_disconnect()
101 {
102 
103 	close(FD);
104 }
105 
106 v3451_abort()
107 {
108 
109 	close(FD);
110 }
111 
112 static
113 vawrite(cp, delay)
114 	register char *cp;
115 	int delay;
116 {
117 
118 	for (; *cp; sleep(delay), cp++)
119 		write(FD, cp, 1);
120 }
121 
122 static
123 expect(cp)
124 	register char *cp;
125 {
126 	char buf[300];
127 	register char *rp = buf;
128 	static void alarmtr();
129 	int timeout = 30, online = 0;
130 
131 	if (strcmp(cp, "\"\"") == 0)
132 		return (1);
133 	*rp = 0;
134 	/*
135 	 * If we are waiting for the Vadic to complete
136 	 * dialing and get a connection, allow more time
137 	 * Unfortunately, the Vadic times out 24 seconds after
138 	 * the last digit is dialed
139 	 */
140 	online = strcmp(cp, "ON LINE") == 0;
141 	if (online)
142 		timeout = number(value(DIALTIMEOUT));
143 	signal(SIGALRM, alarmtr);
144 	if (sigsetjmp(Sjbuf, 1))
145 		return (0);
146 	alarm(timeout);
147 	while (notin(cp, buf) && rp < buf + sizeof (buf) - 1) {
148 		if (online && notin("FAILED CALL", buf) == 0)
149 			return (0);
150 		if (read(FD, rp, 1) < 0) {
151 			alarm(0);
152 			return (0);
153 		}
154 		if (*rp &= 0177)
155 			rp++;
156 		*rp = '\0';
157 	}
158 	alarm(0);
159 	return (1);
160 }
161 
162 static void
163 alarmtr()
164 {
165 
166 	siglongjmp(Sjbuf, 1);
167 }
168 
169 static
170 notin(sh, lg)
171 	char *sh, *lg;
172 {
173 
174 	for (; *lg; lg++)
175 		if (prefix(sh, lg))
176 			return (0);
177 	return (1);
178 }
179 
180 static
181 prefix(s1, s2)
182 	register char *s1, *s2;
183 {
184 	register char c;
185 
186 	while ((c = *s1++) == *s2++)
187 		if (c == '\0')
188 			return (1);
189 	return (c == '\0');
190 }
191