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