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