1 /* $NetBSD: v3451.c,v 1.8 1998/07/12 09:14:20 mrg Exp $ */ 2 3 /* 4 * Copyright (c) 1983, 1993 5 * The Regents of the University of California. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. All advertising materials mentioning features or use of this software 16 * must display the following acknowledgement: 17 * This product includes software developed by the University of 18 * California, Berkeley and its contributors. 19 * 4. Neither the name of the University nor the names of its contributors 20 * may be used to endorse or promote products derived from this software 21 * without specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * SUCH DAMAGE. 34 */ 35 36 #include <sys/cdefs.h> 37 #ifndef lint 38 #if 0 39 static char sccsid[] = "@(#)v3451.c 8.1 (Berkeley) 6/6/93"; 40 #endif 41 __RCSID("$NetBSD: v3451.c,v 1.8 1998/07/12 09:14:20 mrg Exp $"); 42 #endif /* not lint */ 43 44 /* 45 * Routines for calling up on a Vadic 3451 Modem 46 */ 47 #include "tip.h" 48 49 static jmp_buf Sjbuf; 50 51 static void alarmtr __P((int)); 52 static int expect __P((char *)); 53 static int notin __P((char *, char *)); 54 static int prefix __P((char *, char *)); 55 static void vawrite __P((char *, int)); 56 57 int 58 v3451_dialer(num, acu) 59 char *num; 60 char *acu; 61 { 62 sig_t func; 63 int ok; 64 int slow = number(value(BAUDRATE)) < 1200; 65 char phone[50]; 66 struct termios cntrl; 67 68 /* 69 * Get in synch 70 */ 71 vawrite("I\r", 1 + slow); 72 vawrite("I\r", 1 + slow); 73 vawrite("I\r", 1 + slow); 74 vawrite("\005\r", 2 + slow); 75 if (!expect("READY")) { 76 printf("can't synchronize with vadic 3451\n"); 77 #ifdef ACULOG 78 logent(value(HOST), num, "vadic", "can't synch up"); 79 #endif 80 return (0); 81 } 82 tcgetattr(FD, &cntrl); 83 term.c_cflag |= HUPCL; 84 tcsetattr(FD, TCSANOW, &cntrl); 85 sleep(1); 86 vawrite("D\r", 2 + slow); 87 if (!expect("NUMBER?")) { 88 printf("Vadic will not accept dial command\n"); 89 #ifdef ACULOG 90 logent(value(HOST), num, "vadic", "will not accept dial"); 91 #endif 92 return (0); 93 } 94 snprintf(phone, sizeof phone, "%s\r", num); 95 vawrite(phone, 1 + slow); 96 if (!expect(phone)) { 97 printf("Vadic will not accept phone number\n"); 98 #ifdef ACULOG 99 logent(value(HOST), num, "vadic", "will not accept number"); 100 #endif 101 return (0); 102 } 103 func = signal(SIGINT,SIG_IGN); 104 /* 105 * You cannot interrupt the Vadic when its dialing; 106 * even dropping DTR does not work (definitely a 107 * brain damaged design). 108 */ 109 vawrite("\r", 1 + slow); 110 vawrite("\r", 1 + slow); 111 if (!expect("DIALING:")) { 112 printf("Vadic failed to dial\n"); 113 #ifdef ACULOG 114 logent(value(HOST), num, "vadic", "failed to dial"); 115 #endif 116 return (0); 117 } 118 if (boolean(value(VERBOSE))) 119 printf("\ndialing..."); 120 ok = expect("ON LINE"); 121 signal(SIGINT, func); 122 if (!ok) { 123 printf("call failed\n"); 124 #ifdef ACULOG 125 logent(value(HOST), num, "vadic", "call failed"); 126 #endif 127 return (0); 128 } 129 tcflush(FD, TCIOFLUSH); 130 return (1); 131 } 132 133 void 134 v3451_disconnect() 135 { 136 137 close(FD); 138 } 139 140 void 141 v3451_abort() 142 { 143 144 close(FD); 145 } 146 147 static void 148 vawrite(cp, delay) 149 char *cp; 150 int delay; 151 { 152 153 for (; *cp; sleep(delay), cp++) 154 write(FD, cp, 1); 155 } 156 157 static int 158 expect(cp) 159 char *cp; 160 { 161 char buf[300]; 162 char *rp = buf; 163 int timeout = 30, online = 0; 164 165 #if __GNUC__ /* XXX pacify gcc */ 166 (void)&online; 167 (void)&rp; 168 (void)&timeout; 169 #endif 170 171 if (strcmp(cp, "\"\"") == 0) 172 return (1); 173 *rp = 0; 174 /* 175 * If we are waiting for the Vadic to complete 176 * dialing and get a connection, allow more time 177 * Unfortunately, the Vadic times out 24 seconds after 178 * the last digit is dialed 179 */ 180 online = strcmp(cp, "ON LINE") == 0; 181 if (online) 182 timeout = number(value(DIALTIMEOUT)); 183 signal(SIGALRM, alarmtr); 184 if (setjmp(Sjbuf)) 185 return (0); 186 alarm(timeout); 187 while (notin(cp, buf) && rp < buf + sizeof (buf) - 1) { 188 if (online && notin("FAILED CALL", buf) == 0) 189 return (0); 190 if (read(FD, rp, 1) < 0) { 191 alarm(0); 192 return (0); 193 } 194 if (*rp &= 0177) 195 rp++; 196 *rp = '\0'; 197 } 198 alarm(0); 199 return (1); 200 } 201 202 static void 203 alarmtr(dummy) 204 int dummy; 205 { 206 207 longjmp(Sjbuf, 1); 208 } 209 210 static int 211 notin(sh, lg) 212 char *sh, *lg; 213 { 214 215 for (; *lg; lg++) 216 if (prefix(sh, lg)) 217 return (0); 218 return (1); 219 } 220 221 static int 222 prefix(s1, s2) 223 char *s1, *s2; 224 { 225 char c; 226 227 while ((c = *s1++) == *s2++) 228 if (c == '\0') 229 return (1); 230 return (c == '\0'); 231 } 232