1 /* $NetBSD: v3451.c,v 1.6 1997/02/11 09:24: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 #ifndef lint 37 #if 0 38 static char sccsid[] = "@(#)v3451.c 8.1 (Berkeley) 6/6/93"; 39 #endif 40 static char rcsid[] = "$NetBSD: v3451.c,v 1.6 1997/02/11 09:24:20 mrg Exp $"; 41 #endif /* not lint */ 42 43 /* 44 * Routines for calling up on a Vadic 3451 Modem 45 */ 46 #include "tip.h" 47 48 static jmp_buf Sjbuf; 49 50 static int expect(), notin(), prefix(); 51 static void vawrite(), alarmtr(); 52 53 v3451_dialer(num, acu) 54 register char *num; 55 char *acu; 56 { 57 sig_t func; 58 int ok; 59 int slow = number(value(BAUDRATE)) < 1200, rw = 2; 60 char phone[50]; 61 struct termios cntrl; 62 #ifdef ACULOG 63 char line[80]; 64 #endif 65 66 /* 67 * Get in synch 68 */ 69 vawrite("I\r", 1 + slow); 70 vawrite("I\r", 1 + slow); 71 vawrite("I\r", 1 + slow); 72 vawrite("\005\r", 2 + slow); 73 if (!expect("READY")) { 74 printf("can't synchronize with vadic 3451\n"); 75 #ifdef ACULOG 76 logent(value(HOST), num, "vadic", "can't synch up"); 77 #endif 78 return (0); 79 } 80 tcgetattr(FD, &cntrl); 81 term.c_cflag |= HUPCL; 82 tcsetattr(FD, TCSANOW, &cntrl); 83 sleep(1); 84 vawrite("D\r", 2 + slow); 85 if (!expect("NUMBER?")) { 86 printf("Vadic will not accept dial command\n"); 87 #ifdef ACULOG 88 logent(value(HOST), num, "vadic", "will not accept dial"); 89 #endif 90 return (0); 91 } 92 snprintf(phone, sizeof phone, "%s\r", num); 93 vawrite(phone, 1 + slow); 94 if (!expect(phone)) { 95 printf("Vadic will not accept phone number\n"); 96 #ifdef ACULOG 97 logent(value(HOST), num, "vadic", "will not accept number"); 98 #endif 99 return (0); 100 } 101 func = signal(SIGINT,SIG_IGN); 102 /* 103 * You cannot interrupt the Vadic when its dialing; 104 * even dropping DTR does not work (definitely a 105 * brain damaged design). 106 */ 107 vawrite("\r", 1 + slow); 108 vawrite("\r", 1 + slow); 109 if (!expect("DIALING:")) { 110 printf("Vadic failed to dial\n"); 111 #ifdef ACULOG 112 logent(value(HOST), num, "vadic", "failed to dial"); 113 #endif 114 return (0); 115 } 116 if (boolean(value(VERBOSE))) 117 printf("\ndialing..."); 118 ok = expect("ON LINE"); 119 signal(SIGINT, func); 120 if (!ok) { 121 printf("call failed\n"); 122 #ifdef ACULOG 123 logent(value(HOST), num, "vadic", "call failed"); 124 #endif 125 return (0); 126 } 127 tcflush(FD, TCIOFLUSH); 128 return (1); 129 } 130 131 v3451_disconnect() 132 { 133 134 close(FD); 135 } 136 137 v3451_abort() 138 { 139 140 close(FD); 141 } 142 143 static void 144 vawrite(cp, delay) 145 register char *cp; 146 int delay; 147 { 148 149 for (; *cp; sleep(delay), cp++) 150 write(FD, cp, 1); 151 } 152 153 static 154 expect(cp) 155 register char *cp; 156 { 157 char buf[300]; 158 register char *rp = buf; 159 int timeout = 30, online = 0; 160 161 if (strcmp(cp, "\"\"") == 0) 162 return (1); 163 *rp = 0; 164 /* 165 * If we are waiting for the Vadic to complete 166 * dialing and get a connection, allow more time 167 * Unfortunately, the Vadic times out 24 seconds after 168 * the last digit is dialed 169 */ 170 online = strcmp(cp, "ON LINE") == 0; 171 if (online) 172 timeout = number(value(DIALTIMEOUT)); 173 signal(SIGALRM, alarmtr); 174 if (setjmp(Sjbuf)) 175 return (0); 176 alarm(timeout); 177 while (notin(cp, buf) && rp < buf + sizeof (buf) - 1) { 178 if (online && notin("FAILED CALL", buf) == 0) 179 return (0); 180 if (read(FD, rp, 1) < 0) { 181 alarm(0); 182 return (0); 183 } 184 if (*rp &= 0177) 185 rp++; 186 *rp = '\0'; 187 } 188 alarm(0); 189 return (1); 190 } 191 192 static void 193 alarmtr() 194 { 195 longjmp(Sjbuf, 1); 196 } 197 198 static int 199 notin(sh, lg) 200 char *sh, *lg; 201 { 202 203 for (; *lg; lg++) 204 if (prefix(sh, lg)) 205 return (0); 206 return (1); 207 } 208 209 static 210 prefix(s1, s2) 211 register char *s1, *s2; 212 { 213 register char c; 214 215 while ((c = *s1++) == *s2++) 216 if (c == '\0') 217 return (1); 218 return (c == '\0'); 219 } 220