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