1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 3*0Sstevel@tonic-gate * Use is subject to license terms. 4*0Sstevel@tonic-gate */ 5*0Sstevel@tonic-gate /* 6*0Sstevel@tonic-gate * Copyright (c) 1983 Regents of the University of California. 7*0Sstevel@tonic-gate * All rights reserved. The Berkeley software License Agreement 8*0Sstevel@tonic-gate * specifies the terms and conditions for redistribution. 9*0Sstevel@tonic-gate */ 10*0Sstevel@tonic-gate #ident "%Z%%M% %I% %E% SMI" /* from UCB 4.7 6/25/83 */ 11*0Sstevel@tonic-gate 12*0Sstevel@tonic-gate #include "tip.h" 13*0Sstevel@tonic-gate 14*0Sstevel@tonic-gate #define MAXRETRY 3 /* sync up retry count */ 15*0Sstevel@tonic-gate #define DISCONNECT_CMD "\21\25\11\24" /* disconnection string */ 16*0Sstevel@tonic-gate 17*0Sstevel@tonic-gate static void sigALRM(); 18*0Sstevel@tonic-gate static int timeout = 0; 19*0Sstevel@tonic-gate static sigjmp_buf timeoutbuf; 20*0Sstevel@tonic-gate 21*0Sstevel@tonic-gate /* 22*0Sstevel@tonic-gate * Dial up on a BIZCOMP Model 1031 with either 23*0Sstevel@tonic-gate * tone dialing (mod = "f") 24*0Sstevel@tonic-gate * pulse dialing (mod = "w") 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate static int 27*0Sstevel@tonic-gate biz_dialer(num, mod) 28*0Sstevel@tonic-gate char *num, *mod; 29*0Sstevel@tonic-gate { 30*0Sstevel@tonic-gate register int connected = 0; 31*0Sstevel@tonic-gate 32*0Sstevel@tonic-gate if (!bizsync(FD)) { 33*0Sstevel@tonic-gate logent(value(HOST), "", "biz", "out of sync"); 34*0Sstevel@tonic-gate printf("bizcomp out of sync\n"); 35*0Sstevel@tonic-gate delock(uucplock); 36*0Sstevel@tonic-gate exit(0); 37*0Sstevel@tonic-gate } 38*0Sstevel@tonic-gate if (boolean(value(VERBOSE))) 39*0Sstevel@tonic-gate printf("\nstarting call..."); 40*0Sstevel@tonic-gate echo("#\rk$\r$\n"); /* disable auto-answer */ 41*0Sstevel@tonic-gate echo("$>$.$ #\r"); /* tone/pulse dialing */ 42*0Sstevel@tonic-gate echo(mod); 43*0Sstevel@tonic-gate echo("$\r$\n"); 44*0Sstevel@tonic-gate echo("$>$.$ #\re$ "); /* disconnection sequence */ 45*0Sstevel@tonic-gate echo(DISCONNECT_CMD); 46*0Sstevel@tonic-gate echo("\r$\n$\r$\n"); 47*0Sstevel@tonic-gate echo("$>$.$ #\rr$ "); /* repeat dial */ 48*0Sstevel@tonic-gate echo(num); 49*0Sstevel@tonic-gate echo("\r$\n"); 50*0Sstevel@tonic-gate if (boolean(value(VERBOSE))) 51*0Sstevel@tonic-gate printf("ringing..."); 52*0Sstevel@tonic-gate /* 53*0Sstevel@tonic-gate * The reply from the BIZCOMP should be: 54*0Sstevel@tonic-gate * `^G NO CONNECTION\r\n^G\r\n' failure 55*0Sstevel@tonic-gate * ` CONNECTION\r\n^G' success 56*0Sstevel@tonic-gate */ 57*0Sstevel@tonic-gate connected = detect(" "); 58*0Sstevel@tonic-gate #ifdef ACULOG 59*0Sstevel@tonic-gate if (timeout) { 60*0Sstevel@tonic-gate char line[80]; 61*0Sstevel@tonic-gate 62*0Sstevel@tonic-gate sprintf(line, "%d second dial timeout", 63*0Sstevel@tonic-gate number(value(DIALTIMEOUT))); 64*0Sstevel@tonic-gate logent(value(HOST), num, "biz", line); 65*0Sstevel@tonic-gate } 66*0Sstevel@tonic-gate #endif 67*0Sstevel@tonic-gate if (!connected) 68*0Sstevel@tonic-gate flush(" NO CONNECTION\r\n\07\r\n"); 69*0Sstevel@tonic-gate else 70*0Sstevel@tonic-gate flush("CONNECTION\r\n\07"); 71*0Sstevel@tonic-gate if (timeout) 72*0Sstevel@tonic-gate biz31_disconnect(); /* insurance */ 73*0Sstevel@tonic-gate return (connected); 74*0Sstevel@tonic-gate } 75*0Sstevel@tonic-gate 76*0Sstevel@tonic-gate biz31w_dialer(num, acu) 77*0Sstevel@tonic-gate char *num, *acu; 78*0Sstevel@tonic-gate { 79*0Sstevel@tonic-gate 80*0Sstevel@tonic-gate return (biz_dialer(num, "w")); 81*0Sstevel@tonic-gate } 82*0Sstevel@tonic-gate 83*0Sstevel@tonic-gate biz31f_dialer(num, acu) 84*0Sstevel@tonic-gate char *num, *acu; 85*0Sstevel@tonic-gate { 86*0Sstevel@tonic-gate 87*0Sstevel@tonic-gate return (biz_dialer(num, "f")); 88*0Sstevel@tonic-gate } 89*0Sstevel@tonic-gate 90*0Sstevel@tonic-gate biz31_disconnect() 91*0Sstevel@tonic-gate { 92*0Sstevel@tonic-gate 93*0Sstevel@tonic-gate write(FD, DISCONNECT_CMD, 4); 94*0Sstevel@tonic-gate sleep(2); 95*0Sstevel@tonic-gate ioctl(FD, TCFLSH, TCOFLUSH); 96*0Sstevel@tonic-gate } 97*0Sstevel@tonic-gate 98*0Sstevel@tonic-gate biz31_abort() 99*0Sstevel@tonic-gate { 100*0Sstevel@tonic-gate 101*0Sstevel@tonic-gate write(FD, "\33", 1); 102*0Sstevel@tonic-gate } 103*0Sstevel@tonic-gate 104*0Sstevel@tonic-gate static int 105*0Sstevel@tonic-gate echo(s) 106*0Sstevel@tonic-gate register char *s; 107*0Sstevel@tonic-gate { 108*0Sstevel@tonic-gate char c; 109*0Sstevel@tonic-gate 110*0Sstevel@tonic-gate while (c = *s++) { 111*0Sstevel@tonic-gate switch (c) { 112*0Sstevel@tonic-gate case '$': 113*0Sstevel@tonic-gate read(FD, &c, 1); 114*0Sstevel@tonic-gate s++; 115*0Sstevel@tonic-gate break; 116*0Sstevel@tonic-gate 117*0Sstevel@tonic-gate case '#': 118*0Sstevel@tonic-gate c = *s++; 119*0Sstevel@tonic-gate write(FD, &c, 1); 120*0Sstevel@tonic-gate break; 121*0Sstevel@tonic-gate 122*0Sstevel@tonic-gate default: 123*0Sstevel@tonic-gate write(FD, &c, 1); 124*0Sstevel@tonic-gate read(FD, &c, 1); 125*0Sstevel@tonic-gate } 126*0Sstevel@tonic-gate } 127*0Sstevel@tonic-gate } 128*0Sstevel@tonic-gate 129*0Sstevel@tonic-gate static void 130*0Sstevel@tonic-gate sigALRM() 131*0Sstevel@tonic-gate { 132*0Sstevel@tonic-gate 133*0Sstevel@tonic-gate timeout = 1; 134*0Sstevel@tonic-gate siglongjmp(timeoutbuf, 1); 135*0Sstevel@tonic-gate } 136*0Sstevel@tonic-gate 137*0Sstevel@tonic-gate static int 138*0Sstevel@tonic-gate detect(s) 139*0Sstevel@tonic-gate register char *s; 140*0Sstevel@tonic-gate { 141*0Sstevel@tonic-gate char c; 142*0Sstevel@tonic-gate sig_handler_t f; 143*0Sstevel@tonic-gate 144*0Sstevel@tonic-gate f = signal(SIGALRM, (sig_handler_t)sigALRM); 145*0Sstevel@tonic-gate timeout = 0; 146*0Sstevel@tonic-gate while (*s) { 147*0Sstevel@tonic-gate if (sigsetjmp(timeoutbuf, 1)) { 148*0Sstevel@tonic-gate printf("\07timeout waiting for reply\n"); 149*0Sstevel@tonic-gate biz31_abort(); 150*0Sstevel@tonic-gate break; 151*0Sstevel@tonic-gate } 152*0Sstevel@tonic-gate alarm(number(value(DIALTIMEOUT))); 153*0Sstevel@tonic-gate read(FD, &c, 1); 154*0Sstevel@tonic-gate alarm(0); 155*0Sstevel@tonic-gate if (c != *s++) 156*0Sstevel@tonic-gate break; 157*0Sstevel@tonic-gate } 158*0Sstevel@tonic-gate signal(SIGALRM, f); 159*0Sstevel@tonic-gate return (timeout == 0); 160*0Sstevel@tonic-gate } 161*0Sstevel@tonic-gate 162*0Sstevel@tonic-gate static int 163*0Sstevel@tonic-gate flush(s) 164*0Sstevel@tonic-gate register char *s; 165*0Sstevel@tonic-gate { 166*0Sstevel@tonic-gate char c; 167*0Sstevel@tonic-gate sig_handler_t f; 168*0Sstevel@tonic-gate 169*0Sstevel@tonic-gate f = signal(SIGALRM, (sig_handler_t)sigALRM); 170*0Sstevel@tonic-gate while (*s++) { 171*0Sstevel@tonic-gate if (sigsetjmp(timeoutbuf, 1)) 172*0Sstevel@tonic-gate break; 173*0Sstevel@tonic-gate alarm(10); 174*0Sstevel@tonic-gate read(FD, &c, 1); 175*0Sstevel@tonic-gate alarm(0); 176*0Sstevel@tonic-gate } 177*0Sstevel@tonic-gate signal(SIGALRM, f); 178*0Sstevel@tonic-gate timeout = 0; /* guard against disconnection */ 179*0Sstevel@tonic-gate } 180*0Sstevel@tonic-gate 181*0Sstevel@tonic-gate /* 182*0Sstevel@tonic-gate * This convoluted piece of code attempts to get 183*0Sstevel@tonic-gate * the bizcomp in sync. If you don't have the capacity or nread 184*0Sstevel@tonic-gate * call there are gory ways to simulate this. 185*0Sstevel@tonic-gate */ 186*0Sstevel@tonic-gate static int 187*0Sstevel@tonic-gate bizsync(fd) 188*0Sstevel@tonic-gate { 189*0Sstevel@tonic-gate #ifdef FIOCAPACITY 190*0Sstevel@tonic-gate struct capacity b; 191*0Sstevel@tonic-gate #define chars(b) ((b).cp_nbytes) 192*0Sstevel@tonic-gate #define IOCTL FIOCAPACITY 193*0Sstevel@tonic-gate #endif 194*0Sstevel@tonic-gate #ifdef FIONREAD 195*0Sstevel@tonic-gate long b; 196*0Sstevel@tonic-gate #define chars(b) (b) 197*0Sstevel@tonic-gate #define IOCTL FIONREAD 198*0Sstevel@tonic-gate #endif 199*0Sstevel@tonic-gate register int already = 0; 200*0Sstevel@tonic-gate char buf[10]; 201*0Sstevel@tonic-gate 202*0Sstevel@tonic-gate retry: 203*0Sstevel@tonic-gate if (ioctl(fd, IOCTL, (caddr_t)&b) >= 0 && chars(b) > 0) 204*0Sstevel@tonic-gate ioctl(fd, TCFLSH, TCIOFLUSH); 205*0Sstevel@tonic-gate write(fd, "\rp>\r", 4); 206*0Sstevel@tonic-gate sleep(1); 207*0Sstevel@tonic-gate if (ioctl(fd, IOCTL, (caddr_t)&b) >= 0) { 208*0Sstevel@tonic-gate if (chars(b) != 10) { 209*0Sstevel@tonic-gate nono: 210*0Sstevel@tonic-gate if (already > MAXRETRY) 211*0Sstevel@tonic-gate return (0); 212*0Sstevel@tonic-gate write(fd, DISCONNECT_CMD, 4); 213*0Sstevel@tonic-gate sleep(2); 214*0Sstevel@tonic-gate already++; 215*0Sstevel@tonic-gate goto retry; 216*0Sstevel@tonic-gate } else { 217*0Sstevel@tonic-gate read(fd, buf, 10); 218*0Sstevel@tonic-gate if (strncmp(buf, "p >\r\n\r\n>", 8)) 219*0Sstevel@tonic-gate goto nono; 220*0Sstevel@tonic-gate } 221*0Sstevel@tonic-gate } 222*0Sstevel@tonic-gate return (1); 223*0Sstevel@tonic-gate } 224