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