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