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