1 /* v3451.c 4.2 83/06/24 */ 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 jmp_buf Sjbuf; 13 14 vadic_dialer(num, acu) 15 register char *num; 16 char *acu; 17 { 18 int ok, (*func)(); 19 int slow = number(value(BAUDRATE)) < 1200, rw = 2; 20 char phone[50]; 21 #ifdef ACULOG 22 char line[80]; 23 #endif 24 25 /* 26 * Get in synch 27 */ 28 vawrite("I\r", 1 + slow); 29 vawrite("I\r", 1 + slow); 30 vawrite("I\r", 1 + slow); 31 vawrite("\005\r", 2 + slow); 32 if (!expect("READY")) { 33 printf("can't synchronize with vadic 3451\n"); 34 #ifdef ACULOG 35 logent(value(HOST), num, "vadic", "can't synch up"); 36 #endif 37 return (0); 38 } 39 ioctl(FD, TIOCHPCL, 0); 40 sleep(1); 41 vawrite("D\r", 2 + slow); 42 if (!expect("NUMBER?")) { 43 printf("Vadic will not accept dial command\n"); 44 #ifdef ACULOG 45 logent(value(HOST), num, "vadic", "will not accept dial"); 46 #endif 47 return (0); 48 } 49 strcpy(phone, num); 50 strcat(phone, "\r"); 51 vawrite(phone, 1 + slow); 52 if (!expect(phone)) { 53 printf("Vadic will not accept phone number\n"); 54 #ifdef ACULOG 55 logent(value(HOST), num, "vadic", "will not accept number"); 56 #endif 57 return (0); 58 } 59 func = signal(SIGINT,SIG_IGN); 60 /* 61 * You cannot interrupt the Vadic when its dialing; 62 * even dropping DTR does not work (definitely a 63 * brain damaged design). 64 */ 65 vawrite("\r", 1 + slow); 66 vawrite("\r", 1 + slow); 67 if (!expect("DIALING:")) { 68 printf("Vadic failed to dial\n"); 69 #ifdef ACULOG 70 logent(value(HOST), num, "vadic", "failed to dial"); 71 #endif 72 return (0); 73 } 74 if (boolean(value(VERBOSE))) 75 printf("\ndialing..."); 76 ok = expect("ON LINE"); 77 signal(SIGINT, func); 78 if (!ok) { 79 printf("call failed\n"); 80 #ifdef ACULOG 81 logent(value(HOST), num, "vadic", "call failed"); 82 #endif 83 return (0); 84 } 85 ioctl(FD, TIOCFLUSH, &rw); 86 return (1); 87 } 88 89 vadic_disconnect() 90 { 91 92 close(FD); 93 } 94 95 vadic_abort() 96 { 97 98 close(FD); 99 } 100 101 static 102 vawrite(cp, delay) 103 register char *cp; 104 int delay; 105 { 106 107 for (; *cp; sleep(delay), cp++) 108 write(FD, cp, 1); 109 } 110 111 static 112 expect(cp) 113 register char *cp; 114 { 115 char buf[300]; 116 register char *rp = buf; 117 int alarmtr(), timeout = 30, online = 0; 118 119 if (strcmp(cp, "\"\"") == 0) 120 return (1); 121 *rp = 0; 122 /* 123 * If we are waiting for the Vadic to complete 124 * dialing and get a connection, allow more time 125 * Unfortunately, the Vadic times out 24 seconds after 126 * the last digit is dialed 127 */ 128 online = strcmp(cp, "ON LINE") == 0; 129 if (online) 130 timeout = number(value(DIALTIMEOUT)); 131 signal(SIGALRM, alarmtr); 132 if (setjmp(Sjbuf)) 133 return (0); 134 alarm(timeout); 135 while (notin(cp, buf) && rp < buf + sizeof (buf) - 1) { 136 if (online && notin("FAILED CALL", buf) == 0) 137 return (0); 138 if (read(FD, rp, 1) < 0) { 139 alarm(0); 140 return (0); 141 } 142 if (*rp &= 0177) 143 rp++; 144 *rp = '\0'; 145 } 146 alarm(0); 147 return (1); 148 } 149 150 static 151 alarmtr() 152 { 153 154 longjmp(Sjbuf, 1); 155 } 156 157 static 158 notin(sh, lg) 159 char *sh, *lg; 160 { 161 162 for (; *lg; lg++) 163 if (prefix(sh, lg)) 164 return (0); 165 return (1); 166 } 167 168 static 169 prefix(s1, s2) 170 register char *s1, *s2; 171 { 172 register char c; 173 174 while ((c = *s1++) == *s2++) 175 if (c == '\0') 176 return (1); 177 return (c == '\0'); 178 } 179