1 /* v3451.c 4.1 83/06/15 */ 2 3 #if VADIC 4 /* 5 * Routines for calling up on a Vadic 3451 Modem 6 */ 7 #include "tip.h" 8 #include <setjmp.h> 9 #include <errno.h> 10 #include <signal.h> 11 12 static char *sccsid = "@(#)v3451.c 4.1 06/15/83"; 13 14 int va_delay; 15 static int fudge=0; /* for sleep in vawrite */ 16 jmp_buf Sjbuf; 17 18 vadic_dialer(num, acu) 19 register char *num; 20 char *acu; 21 { 22 int lt; 23 int ok; 24 char phone[50]; 25 #ifdef ACULOG 26 char line[80]; 27 #endif 28 int (*func) (); 29 30 if(number(value(BAUDRATE)) < 1200) 31 fudge = 1; 32 /* 33 * Get in synch 34 */ 35 lt = strlen(num); 36 va_delay = 15 + 3*lt; 37 vawrite("I\r",1); 38 vawrite("I\r",1); 39 vawrite("I\r",1); 40 vawrite("\005\r",2); 41 ok = expect("READY"); 42 43 if ( ok ) { 44 printf("can't synchronize with vadic 3451\n"); 45 #ifdef ACULOG 46 logent(value(HOST), num, "vadic", "can't synch up"); 47 #endif 48 return (0); 49 } 50 ioctl(FD, TIOCHPCL, 0); 51 sleep(1); 52 vawrite("D\r",2); 53 ok = expect("NUMBER?"); 54 if ( ok ) { 55 printf("Vadic will not accept dial command\n"); 56 #ifdef ACULOG 57 logent(value(HOST), num, "vadic", "will not accept dial"); 58 #endif 59 return (0); 60 } 61 strcpy(phone,num); 62 strcat(phone,"\r"); 63 vawrite(phone,1); 64 ok = expect(phone); 65 if ( ok ) { 66 printf("Vadic will not accept phone number\n"); 67 #ifdef ACULOG 68 logent(value(HOST), num, "vadic", "will not accept number"); 69 #endif 70 return (0); 71 } 72 func = signal(SIGINT,SIG_IGN); 73 /* You cannot interrupt the Vadic when its dialing */ 74 /* Even dropping DTR does not work /* 75 /* Definitely a Brain Damaged Design */ 76 vawrite("\r",1); 77 vawrite("\r",1); 78 ok = expect("DIALING:"); 79 if ( ok ) { 80 printf("Vadic failed to dial\n"); 81 #ifdef ACULOG 82 logent(value(HOST), num, "vadic", "failed to dial"); 83 #endif 84 return (0); 85 } else 86 printf("dialing...\n"); 87 ok = expect("ON LINE"); 88 signal(SIGINT,func); 89 if ( ok ) { 90 printf("call failed\n"); 91 #ifdef ACULOG 92 logent(value(HOST), num, "vadic", "call failed"); 93 #endif 94 return (0); 95 } 96 ioctl(FD, TIOCFLUSH); 97 return (1); 98 } 99 100 vadic_disconnect() 101 { 102 char string[100]; 103 close(FD); 104 sleep(5); /* insure that the phone line is dropped */ 105 sprintf(string,"/usr/lib/uucp/enable %s\n",rindex(DV,'/')+1); 106 system(string); 107 } 108 109 vadic_abort() 110 { 111 vadic_disconnect(); 112 } 113 114 vawrite(str,delay) 115 char *str; 116 int delay; 117 { 118 while(*str) 119 { 120 write(FD,str,1); 121 sleep(delay+fudge); 122 str++; 123 } 124 return; 125 } 126 127 128 #define MR 300 129 130 int Error = 0; 131 132 /*** 133 * expect(str) look for expected string 134 * char *str; 135 * 136 * return codes: 137 * 0 - found 138 * FAIL - lost line or too many characters read 139 * some character - timed out 140 */ 141 142 expect(str) 143 char *str; 144 { 145 static char rdvec[MR]; 146 extern alarmtr(); 147 char *rp = rdvec; 148 int nextch = 0, kr; 149 int alarm_tm; 150 int expect_online = 0; 151 152 if (strcmp(str, "\"\"") == 0) 153 return(0); 154 *rp = 0; 155 /* 156 * If we are waiting for the Vadic to complete 157 * dialing and get a connection, allow more time 158 * Unfortunately, the Vadic times out 24 seconds after 159 * the last digit is dialed 160 */ 161 if(strcmp(str, "ON LINE") == 0){ 162 alarm_tm = number(value(DIALTIMEOUT)); 163 expect_online++; 164 } 165 else 166 alarm_tm = 30; 167 if (setjmp(Sjbuf)) { 168 return(1); 169 } 170 signal(SIGALRM, alarmtr); 171 alarm(alarm_tm); 172 while (notin(str, rdvec)) { 173 if(expect_online) 174 if(notin("FAILED CALL", rdvec) == 0) 175 return(1); 176 kr = read(FD, &nextch, 1); 177 if (kr <= 0) { 178 alarm(0); 179 return(1); 180 } 181 { 182 int c; 183 c = nextch & 0177; 184 } 185 if ((*rp = nextch & 0177) != '\0') 186 rp++; 187 *rp = '\0'; 188 if (rp >= rdvec + MR) 189 return(1); 190 } 191 alarm(0); 192 return(0); 193 } 194 195 /*** 196 * alarmtr() - catch alarm routine for "expect". 197 */ 198 199 alarmtr() 200 { 201 longjmp(Sjbuf, 1); 202 } 203 204 /*** 205 * notin(sh, lg) check for occurrence of substring "sh" 206 * char *sh, *lg; 207 * 208 * return codes: 209 * 0 - found the string 210 * 1 - not in the string 211 */ 212 213 notin(sh, lg) 214 char *sh, *lg; 215 { 216 while (*lg != '\0') { 217 if (prefix(sh, lg)) 218 return(0); 219 else 220 lg++; 221 } 222 return(1); 223 } 224 225 /******* 226 * prefix(s1, s2) check s2 for prefix s1 227 * char *s1, *s2; 228 * 229 * return 0 - != 230 * return 1 - == 231 */ 232 233 prefix(s1, s2) 234 char *s1, *s2; 235 { 236 char c; 237 238 while ((c = *s1++) == *s2++) 239 if (c == '\0') 240 return(1); 241 return(c == '\0'); 242 } 243