1 /* v831.c 4.2 83/06/15 */ 2 3 #ifdef V831 4 /* 5 * Routines for dialing up on Vadic 831 6 */ 7 #include <sys/file.h> 8 #include <sys/time.h> 9 10 #include <setjmp.h> 11 #include <errno.h> 12 #include <sgtty.h> 13 14 #include "tip.h" 15 16 static char *sccsid = "@(#)v831.c 4.2 06/15/83"; 17 18 int v831_abort(); 19 int alarmtr(); 20 extern errno; 21 22 static jmp_buf jmpbuf; 23 static int child = -1; 24 25 v831_dialer(num, acu) 26 char *num, *acu; 27 { 28 int status, pid, connected = 1; 29 register int timelim; 30 31 if (boolean(value(VERBOSE))) 32 printf("\nstarting call..."); 33 #ifdef DEBUG 34 printf ("(acu=%s)\n", acu); 35 #endif 36 if ((AC = open(acu, FRDWR)) < 0) { 37 if (errno == EBUSY) 38 printf("line busy..."); 39 else 40 printf("acu open error..."); 41 return (0); 42 } 43 if (setjmp(jmpbuf)) { 44 kill(child, SIGKILL); 45 close(AC); 46 return (0); 47 } 48 signal(SIGALRM, alarmtr); 49 timelim = 5 * strlen(num); 50 alarm(timelim < 30 ? 30 : timelim); 51 if ((child = fork()) == 0) { 52 /* 53 * ignore this stuff for aborts 54 */ 55 signal(SIGALRM, SIG_IGN); 56 signal(SIGINT, SIG_IGN); 57 signal(SIGQUIT, SIG_IGN); 58 sleep(2); 59 exit(dialit(num, acu) != 'A'); 60 } 61 /* 62 * open line - will return on carrier 63 */ 64 if ((FD = open(DV, 2)) < 0) { 65 #ifdef DEBUG 66 printf("(after open, errno=%d)\n", errno); 67 #endif 68 if (errno == EIO) 69 printf("lost carrier..."); 70 else 71 printf("dialup line open failed..."); 72 alarm(0); 73 kill(child, SIGKILL); 74 close(AC); 75 return (0); 76 } 77 alarm(0); 78 #ifdef notdef 79 ioctl(AC, TIOCHPCL, 0); 80 #endif 81 signal(SIGALRM, SIG_DFL); 82 while ((pid = wait(&status)) != child && pid != -1) 83 ; 84 if (status) { 85 close(AC); 86 return (0); 87 } 88 return (1); 89 } 90 91 alarmtr() 92 { 93 alarm(0); 94 longjmp(jmpbuf, 1); 95 } 96 97 /* 98 * Insurance, for some reason we don't seem to be 99 * hanging up... 100 */ 101 v831_disconnect() 102 { 103 struct sgttyb cntrl; 104 105 sleep(2); 106 #ifdef VMUNIX 107 #ifdef DEBUG 108 printf("[disconnect: FD=%d]\n", FD); 109 #endif 110 if (FD > 0) { 111 ioctl(FD, TIOCCDTR, 0); 112 ioctl(FD, TIOCGETP, &cntrl); 113 cntrl.sg_ispeed = cntrl.sg_ospeed = 0; 114 ioctl(FD, TIOCSETP, &cntrl); 115 ioctl(FD, TIOCNXCL, (struct sgttyb *)NULL); 116 } 117 #endif 118 close(FD); 119 } 120 121 v831_abort() 122 { 123 #ifdef DEBUG 124 printf("[abort: AC=%d]\n", AC); 125 #endif 126 sleep(2); 127 if (child > 0) 128 kill(child, SIGKILL); 129 if (AC > 0) 130 ioctl(FD, TIOCNXCL, (struct sgttyb *)NULL); 131 close(AC); 132 #ifdef VMUNIX 133 if (FD > 0) 134 ioctl(FD, TIOCCDTR, 0); 135 #endif 136 close(FD); 137 } 138 #endif 139 140 /* 141 * Sigh, this probably must be changed at each site. 142 */ 143 struct vaconfig { 144 char *vc_name; 145 char vc_rack; 146 char vc_modem; 147 } vaconfig[] = { 148 { "/dev/cua0",'4','0' }, 149 { "/dev/cua1",'4','1' }, 150 { 0 } 151 }; 152 153 #define pc(x) (c = x, write(AC,&c,1)) 154 #define ABORT 01 155 #define SI 017 156 #define STX 02 157 #define ETX 03 158 159 dialit(phonenum, acu) 160 register char *phonenum; 161 char *acu; 162 { 163 register struct vaconfig *vp; 164 struct sgttyb cntrl; 165 char c, *sanitize(); 166 int i, two = 2; 167 168 phonenum = sanitize(phonenum); 169 #ifdef DEBUG 170 printf ("(dial phonenum=%s)\n", phonenum); 171 #endif 172 if (*phonenum == '<' && phonenum[1] == 0) 173 return ('Z'); 174 for (vp = vaconfig; vp->vc_name; vp++) 175 if (strcmp(vp->vc_name, acu) == 0) 176 break; 177 if (vp->vc_name == 0) { 178 printf("Unable to locate dialer (%s)\n", acu); 179 return ('K'); 180 } 181 ioctl(AC, TIOCGETP, &cntrl); 182 cntrl.sg_ispeed = cntrl.sg_ospeed = B2400; 183 cntrl.sg_flags = RAW | EVENP | ODDP; 184 ioctl(AC, TIOCSETP, &cntrl); 185 ioctl(AC, TIOCFLUSH, &two); 186 pc(STX); 187 pc(vp->vc_rack); 188 pc(vp->vc_modem); 189 while (*phonenum && *phonenum != '<') 190 pc(*phonenum++); 191 pc(SI); 192 pc(ETX); 193 sleep(1); 194 i = read(AC, &c, 1); 195 #ifdef DEBUG 196 printf("read %d chars, char=%c, errno %d\n", i, c, errno); 197 #endif 198 if (i != 1) 199 c = 'M'; 200 if (c == 'B' || c == 'G') { 201 char cc, oc = c; 202 203 pc(ABORT); 204 read(AC, &cc, 1); 205 #ifdef DEBUG 206 printf("abort response=%c\n", cc); 207 #endif 208 c = oc; 209 v831_disconnect(); 210 } 211 close(AC); 212 #ifdef DEBUG 213 printf("dialit: returns %c\n", c); 214 #endif 215 return (c); 216 } 217 218 static char * 219 sanitize(s) 220 register char *s; 221 { 222 static char buf[128]; 223 register char *cp; 224 225 for (cp = buf; *s; s++) { 226 if (!isdigit(*s) && *s == '<' && *s != '_') 227 continue; 228 if (*s == '_') 229 *s = '='; 230 *cp++ = *s; 231 } 232 *cp++ = 0; 233 return (buf); 234 } 235