1 /* 2 * Copyright (c) 1983 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms are permitted 6 * provided that the above copyright notice and this paragraph are 7 * duplicated in all such forms and that any documentation, 8 * advertising materials, and other materials related to such 9 * distribution and use acknowledge that the software was developed 10 * by the University of California, Berkeley. The name of the 11 * University may not be used to endorse or promote products derived 12 * from this software without specific prior written permission. 13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 15 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 16 */ 17 18 #ifndef lint 19 static char sccsid[] = "@(#)v3451.c 5.2 (Berkeley) 09/13/88"; 20 #endif /* not lint */ 21 22 /* 23 * Routines for calling up on a Vadic 3451 Modem 24 */ 25 #include "tip.h" 26 27 static jmp_buf Sjbuf; 28 29 v3451_dialer(num, acu) 30 register char *num; 31 char *acu; 32 { 33 int ok, (*func)(); 34 int slow = number(value(BAUDRATE)) < 1200, rw = 2; 35 char phone[50]; 36 #ifdef ACULOG 37 char line[80]; 38 #endif 39 40 /* 41 * Get in synch 42 */ 43 vawrite("I\r", 1 + slow); 44 vawrite("I\r", 1 + slow); 45 vawrite("I\r", 1 + slow); 46 vawrite("\005\r", 2 + slow); 47 if (!expect("READY")) { 48 printf("can't synchronize with vadic 3451\n"); 49 #ifdef ACULOG 50 logent(value(HOST), num, "vadic", "can't synch up"); 51 #endif 52 return (0); 53 } 54 ioctl(FD, TIOCHPCL, 0); 55 sleep(1); 56 vawrite("D\r", 2 + slow); 57 if (!expect("NUMBER?")) { 58 printf("Vadic will not accept dial command\n"); 59 #ifdef ACULOG 60 logent(value(HOST), num, "vadic", "will not accept dial"); 61 #endif 62 return (0); 63 } 64 strcpy(phone, num); 65 strcat(phone, "\r"); 66 vawrite(phone, 1 + slow); 67 if (!expect(phone)) { 68 printf("Vadic will not accept phone number\n"); 69 #ifdef ACULOG 70 logent(value(HOST), num, "vadic", "will not accept number"); 71 #endif 72 return (0); 73 } 74 func = signal(SIGINT,SIG_IGN); 75 /* 76 * You cannot interrupt the Vadic when its dialing; 77 * even dropping DTR does not work (definitely a 78 * brain damaged design). 79 */ 80 vawrite("\r", 1 + slow); 81 vawrite("\r", 1 + slow); 82 if (!expect("DIALING:")) { 83 printf("Vadic failed to dial\n"); 84 #ifdef ACULOG 85 logent(value(HOST), num, "vadic", "failed to dial"); 86 #endif 87 return (0); 88 } 89 if (boolean(value(VERBOSE))) 90 printf("\ndialing..."); 91 ok = expect("ON LINE"); 92 signal(SIGINT, func); 93 if (!ok) { 94 printf("call failed\n"); 95 #ifdef ACULOG 96 logent(value(HOST), num, "vadic", "call failed"); 97 #endif 98 return (0); 99 } 100 ioctl(FD, TIOCFLUSH, &rw); 101 return (1); 102 } 103 104 v3451_disconnect() 105 { 106 107 close(FD); 108 } 109 110 v3451_abort() 111 { 112 113 close(FD); 114 } 115 116 static 117 vawrite(cp, delay) 118 register char *cp; 119 int delay; 120 { 121 122 for (; *cp; sleep(delay), cp++) 123 write(FD, cp, 1); 124 } 125 126 static 127 expect(cp) 128 register char *cp; 129 { 130 char buf[300]; 131 register char *rp = buf; 132 int alarmtr(), timeout = 30, online = 0; 133 134 if (strcmp(cp, "\"\"") == 0) 135 return (1); 136 *rp = 0; 137 /* 138 * If we are waiting for the Vadic to complete 139 * dialing and get a connection, allow more time 140 * Unfortunately, the Vadic times out 24 seconds after 141 * the last digit is dialed 142 */ 143 online = strcmp(cp, "ON LINE") == 0; 144 if (online) 145 timeout = number(value(DIALTIMEOUT)); 146 signal(SIGALRM, alarmtr); 147 if (setjmp(Sjbuf)) 148 return (0); 149 alarm(timeout); 150 while (notin(cp, buf) && rp < buf + sizeof (buf) - 1) { 151 if (online && notin("FAILED CALL", buf) == 0) 152 return (0); 153 if (read(FD, rp, 1) < 0) { 154 alarm(0); 155 return (0); 156 } 157 if (*rp &= 0177) 158 rp++; 159 *rp = '\0'; 160 } 161 alarm(0); 162 return (1); 163 } 164 165 static 166 alarmtr() 167 { 168 169 longjmp(Sjbuf, 1); 170 } 171 172 static 173 notin(sh, lg) 174 char *sh, *lg; 175 { 176 177 for (; *lg; lg++) 178 if (prefix(sh, lg)) 179 return (0); 180 return (1); 181 } 182 183 static 184 prefix(s1, s2) 185 register char *s1, *s2; 186 { 187 register char c; 188 189 while ((c = *s1++) == *s2++) 190 if (c == '\0') 191 return (1); 192 return (c == '\0'); 193 } 194