1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * Copyright (c) 2000 by Sun Microsystems, Inc. 3*7c478bd9Sstevel@tonic-gate * All rights reserved. 4*7c478bd9Sstevel@tonic-gate */ 5*7c478bd9Sstevel@tonic-gate 6*7c478bd9Sstevel@tonic-gate /* from UCB 4.4 6/25/83 */ 7*7c478bd9Sstevel@tonic-gate /* 8*7c478bd9Sstevel@tonic-gate * Copyright (c) 1983 Regents of the University of California. 9*7c478bd9Sstevel@tonic-gate * All rights reserved. The Berkeley software License Agreement 10*7c478bd9Sstevel@tonic-gate * specifies the terms and conditions for redistribution. 11*7c478bd9Sstevel@tonic-gate */ 12*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 13*7c478bd9Sstevel@tonic-gate 14*7c478bd9Sstevel@tonic-gate #include "tip.h" 15*7c478bd9Sstevel@tonic-gate 16*7c478bd9Sstevel@tonic-gate #define DISCONNECT_CMD "\20\04" /* disconnection string */ 17*7c478bd9Sstevel@tonic-gate 18*7c478bd9Sstevel@tonic-gate static void sigALRM(); 19*7c478bd9Sstevel@tonic-gate static int timeout = 0; 20*7c478bd9Sstevel@tonic-gate static sigjmp_buf timeoutbuf; 21*7c478bd9Sstevel@tonic-gate 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Dial up on a BIZCOMP Model 1022 with either 24*7c478bd9Sstevel@tonic-gate * tone dialing (mod = "V") 25*7c478bd9Sstevel@tonic-gate * pulse dialing (mod = "W") 26*7c478bd9Sstevel@tonic-gate */ 27*7c478bd9Sstevel@tonic-gate static int 28*7c478bd9Sstevel@tonic-gate biz_dialer(num, mod) 29*7c478bd9Sstevel@tonic-gate char *num, *mod; 30*7c478bd9Sstevel@tonic-gate { 31*7c478bd9Sstevel@tonic-gate register int connected = 0; 32*7c478bd9Sstevel@tonic-gate char cbuf[40]; 33*7c478bd9Sstevel@tonic-gate 34*7c478bd9Sstevel@tonic-gate if (boolean(value(VERBOSE))) 35*7c478bd9Sstevel@tonic-gate printf("\nstarting call..."); 36*7c478bd9Sstevel@tonic-gate /* 37*7c478bd9Sstevel@tonic-gate * Disable auto-answer and configure for tone/pulse 38*7c478bd9Sstevel@tonic-gate * dialing 39*7c478bd9Sstevel@tonic-gate */ 40*7c478bd9Sstevel@tonic-gate if (cmd("\02K\r")) { 41*7c478bd9Sstevel@tonic-gate printf("can't initialize bizcomp..."); 42*7c478bd9Sstevel@tonic-gate return (0); 43*7c478bd9Sstevel@tonic-gate } 44*7c478bd9Sstevel@tonic-gate strcpy(cbuf, "\02.\r"); 45*7c478bd9Sstevel@tonic-gate cbuf[1] = *mod; 46*7c478bd9Sstevel@tonic-gate if (cmd(cbuf)) { 47*7c478bd9Sstevel@tonic-gate printf("can't set dialing mode..."); 48*7c478bd9Sstevel@tonic-gate return (0); 49*7c478bd9Sstevel@tonic-gate } 50*7c478bd9Sstevel@tonic-gate strcpy(cbuf, "\02D"); 51*7c478bd9Sstevel@tonic-gate strlcat(cbuf, num, sizeof (cbuf)); 52*7c478bd9Sstevel@tonic-gate strlcat(cbuf, "\r", sizeof (cbuf)); 53*7c478bd9Sstevel@tonic-gate write(FD, cbuf, strlen(cbuf)); 54*7c478bd9Sstevel@tonic-gate if (!detect("7\r")) { 55*7c478bd9Sstevel@tonic-gate printf("can't get dial tone..."); 56*7c478bd9Sstevel@tonic-gate return (0); 57*7c478bd9Sstevel@tonic-gate } 58*7c478bd9Sstevel@tonic-gate if (boolean(value(VERBOSE))) 59*7c478bd9Sstevel@tonic-gate printf("ringing..."); 60*7c478bd9Sstevel@tonic-gate /* 61*7c478bd9Sstevel@tonic-gate * The reply from the BIZCOMP should be: 62*7c478bd9Sstevel@tonic-gate * 2 \r or 7 \r failure 63*7c478bd9Sstevel@tonic-gate * 1 \r success 64*7c478bd9Sstevel@tonic-gate */ 65*7c478bd9Sstevel@tonic-gate connected = detect("1\r"); 66*7c478bd9Sstevel@tonic-gate #ifdef ACULOG 67*7c478bd9Sstevel@tonic-gate if (timeout) { 68*7c478bd9Sstevel@tonic-gate char line[80]; 69*7c478bd9Sstevel@tonic-gate 70*7c478bd9Sstevel@tonic-gate sprintf(line, "%d second dial timeout", 71*7c478bd9Sstevel@tonic-gate number(value(DIALTIMEOUT))); 72*7c478bd9Sstevel@tonic-gate logent(value(HOST), num, "biz1022", line); 73*7c478bd9Sstevel@tonic-gate } 74*7c478bd9Sstevel@tonic-gate #endif 75*7c478bd9Sstevel@tonic-gate if (timeout) 76*7c478bd9Sstevel@tonic-gate biz22_disconnect(); /* insurance */ 77*7c478bd9Sstevel@tonic-gate return (connected); 78*7c478bd9Sstevel@tonic-gate } 79*7c478bd9Sstevel@tonic-gate 80*7c478bd9Sstevel@tonic-gate biz22w_dialer(num, acu) 81*7c478bd9Sstevel@tonic-gate char *num, *acu; 82*7c478bd9Sstevel@tonic-gate { 83*7c478bd9Sstevel@tonic-gate 84*7c478bd9Sstevel@tonic-gate return (biz_dialer(num, "W")); 85*7c478bd9Sstevel@tonic-gate } 86*7c478bd9Sstevel@tonic-gate 87*7c478bd9Sstevel@tonic-gate biz22f_dialer(num, acu) 88*7c478bd9Sstevel@tonic-gate char *num, *acu; 89*7c478bd9Sstevel@tonic-gate { 90*7c478bd9Sstevel@tonic-gate 91*7c478bd9Sstevel@tonic-gate return (biz_dialer(num, "V")); 92*7c478bd9Sstevel@tonic-gate } 93*7c478bd9Sstevel@tonic-gate 94*7c478bd9Sstevel@tonic-gate biz22_disconnect() 95*7c478bd9Sstevel@tonic-gate { 96*7c478bd9Sstevel@tonic-gate 97*7c478bd9Sstevel@tonic-gate write(FD, DISCONNECT_CMD, 4); 98*7c478bd9Sstevel@tonic-gate sleep(2); 99*7c478bd9Sstevel@tonic-gate ioctl(FD, TCFLSH, TCOFLUSH); 100*7c478bd9Sstevel@tonic-gate } 101*7c478bd9Sstevel@tonic-gate 102*7c478bd9Sstevel@tonic-gate biz22_abort() 103*7c478bd9Sstevel@tonic-gate { 104*7c478bd9Sstevel@tonic-gate 105*7c478bd9Sstevel@tonic-gate write(FD, "\02", 1); 106*7c478bd9Sstevel@tonic-gate } 107*7c478bd9Sstevel@tonic-gate 108*7c478bd9Sstevel@tonic-gate static void 109*7c478bd9Sstevel@tonic-gate sigALRM() 110*7c478bd9Sstevel@tonic-gate { 111*7c478bd9Sstevel@tonic-gate 112*7c478bd9Sstevel@tonic-gate timeout = 1; 113*7c478bd9Sstevel@tonic-gate siglongjmp(timeoutbuf, 1); 114*7c478bd9Sstevel@tonic-gate } 115*7c478bd9Sstevel@tonic-gate 116*7c478bd9Sstevel@tonic-gate static int 117*7c478bd9Sstevel@tonic-gate cmd(s) 118*7c478bd9Sstevel@tonic-gate register char *s; 119*7c478bd9Sstevel@tonic-gate { 120*7c478bd9Sstevel@tonic-gate char c; 121*7c478bd9Sstevel@tonic-gate sig_handler_t f; 122*7c478bd9Sstevel@tonic-gate 123*7c478bd9Sstevel@tonic-gate write(FD, s, strlen(s)); 124*7c478bd9Sstevel@tonic-gate f = signal(SIGALRM, (sig_handler_t)sigALRM); 125*7c478bd9Sstevel@tonic-gate if (sigsetjmp(timeoutbuf, 1)) { 126*7c478bd9Sstevel@tonic-gate biz22_abort(); 127*7c478bd9Sstevel@tonic-gate signal(SIGALRM, f); 128*7c478bd9Sstevel@tonic-gate return (1); 129*7c478bd9Sstevel@tonic-gate } 130*7c478bd9Sstevel@tonic-gate alarm(number(value(DIALTIMEOUT))); 131*7c478bd9Sstevel@tonic-gate read(FD, &c, 1); 132*7c478bd9Sstevel@tonic-gate alarm(0); 133*7c478bd9Sstevel@tonic-gate signal(SIGALRM, f); 134*7c478bd9Sstevel@tonic-gate c &= 0177; 135*7c478bd9Sstevel@tonic-gate return (c != '\r'); 136*7c478bd9Sstevel@tonic-gate } 137*7c478bd9Sstevel@tonic-gate 138*7c478bd9Sstevel@tonic-gate static int 139*7c478bd9Sstevel@tonic-gate detect(s) 140*7c478bd9Sstevel@tonic-gate register char *s; 141*7c478bd9Sstevel@tonic-gate { 142*7c478bd9Sstevel@tonic-gate char c; 143*7c478bd9Sstevel@tonic-gate sig_handler_t f; 144*7c478bd9Sstevel@tonic-gate 145*7c478bd9Sstevel@tonic-gate f = signal(SIGALRM, (sig_handler_t)sigALRM); 146*7c478bd9Sstevel@tonic-gate timeout = 0; 147*7c478bd9Sstevel@tonic-gate while (*s) { 148*7c478bd9Sstevel@tonic-gate if (sigsetjmp(timeoutbuf, 1)) { 149*7c478bd9Sstevel@tonic-gate biz22_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 c &= 0177; 156*7c478bd9Sstevel@tonic-gate if (c != *s++) 157*7c478bd9Sstevel@tonic-gate return (0); 158*7c478bd9Sstevel@tonic-gate } 159*7c478bd9Sstevel@tonic-gate signal(SIGALRM, f); 160*7c478bd9Sstevel@tonic-gate return (timeout == 0); 161*7c478bd9Sstevel@tonic-gate } 162