biz22.c revision 549:9e644232f978
1214152Sed/* 2214152Sed * Copyright 2000 Sun Microsystems, Inc. All rights reserved. 3214152Sed * Use is subject to license terms. 4214152Sed */ 5214152Sed 6214152Sed/* 7214152Sed * Copyright (c) 1983 Regents of the University of California. 8214152Sed * All rights reserved. The Berkeley software License Agreement 9214152Sed * specifies the terms and conditions for redistribution. 10214152Sed */ 11214152Sed 12214152Sed#pragma ident "%Z%%M% %I% %E% SMI" 13214152Sed 14214152Sed#include "tip.h" 15214152Sed 16214152Sed#define DISCONNECT_CMD "\20\04" /* disconnection string */ 17214152Sed 18214152Sedstatic void sigALRM(void); 19214152Sedstatic int cmd(char *); 20214152Sedstatic int detect(char *); 21214152Sed 22214152Sedstatic int timeout = 0; 23214152Sedstatic sigjmp_buf timeoutbuf; 24214152Sed 25214152Sedvoid biz22_disconnect(void); 26214152Sed 27214152Sed/* 28214152Sed * Dial up on a BIZCOMP Model 1022 with either 29214152Sed * tone dialing (mod = "V") 30214152Sed * pulse dialing (mod = "W") 31214152Sed */ 32214152Sedstatic int 33214152Sedbiz_dialer(char *num, char *mod) 34214152Sed{ 35214152Sed int connected = 0; 36214152Sed char cbuf[40]; 37214152Sed 38214152Sed if (boolean(value(VERBOSE))) 39214152Sed (void) printf("\nstarting call..."); 40214152Sed /* 41214152Sed * Disable auto-answer and configure for tone/pulse 42214152Sed * dialing 43214152Sed */ 44214152Sed if (cmd("\02K\r")) { 45214152Sed (void) printf("can't initialize bizcomp..."); 46214152Sed return (0); 47214152Sed } 48214152Sed (void) strcpy(cbuf, "\02.\r"); 49214152Sed cbuf[1] = *mod; 50214152Sed if (cmd(cbuf)) { 51214152Sed (void) printf("can't set dialing mode..."); 52214152Sed return (0); 53214152Sed } 54214152Sed (void) strcpy(cbuf, "\02D"); 55214152Sed (void) strlcat(cbuf, num, sizeof (cbuf)); 56214152Sed (void) strlcat(cbuf, "\r", sizeof (cbuf)); 57214152Sed (void) write(FD, cbuf, strlen(cbuf)); 58214152Sed if (!detect("7\r")) { 59 (void) printf("can't get dial tone..."); 60 return (0); 61 } 62 if (boolean(value(VERBOSE))) 63 (void) printf("ringing..."); 64 /* 65 * The reply from the BIZCOMP should be: 66 * 2 \r or 7 \r failure 67 * 1 \r success 68 */ 69 connected = detect("1\r"); 70#ifdef ACULOG 71 if (timeout) { 72 char line[80]; 73 74 (void) sprintf(line, "%d second dial timeout", 75 number(value(DIALTIMEOUT))); 76 logent(value(HOST), num, "biz1022", line); 77 } 78#endif 79 if (timeout) 80 biz22_disconnect(); /* insurance */ 81 return (connected); 82} 83 84/* ARGSUSED */ 85int 86biz22w_dialer(char *num, char *acu) 87{ 88 89 return (biz_dialer(num, "W")); 90} 91 92/* ARGSUSED */ 93int 94biz22f_dialer(char *num, char *acu) 95{ 96 97 return (biz_dialer(num, "V")); 98} 99 100void 101biz22_disconnect(void) 102{ 103 104 (void) write(FD, DISCONNECT_CMD, 4); 105 (void) sleep(2); 106 (void) ioctl(FD, TCFLSH, TCOFLUSH); 107} 108 109void 110biz22_abort(void) 111{ 112 113 (void) write(FD, "\02", 1); 114} 115 116static void 117sigALRM(void) 118{ 119 120 timeout = 1; 121 siglongjmp(timeoutbuf, 1); 122} 123 124static int 125cmd(char *s) 126{ 127 char c; 128 sig_handler_t f; 129 130 (void) write(FD, s, strlen(s)); 131 f = signal(SIGALRM, (sig_handler_t)sigALRM); 132 if (sigsetjmp(timeoutbuf, 1)) { 133 biz22_abort(); 134 (void) signal(SIGALRM, f); 135 return (1); 136 } 137 (void) alarm(number(value(DIALTIMEOUT))); 138 (void) read(FD, &c, 1); 139 (void) alarm(0); 140 (void) signal(SIGALRM, f); 141 c &= 0177; 142 return (c != '\r'); 143} 144 145static int 146detect(char *s) 147{ 148 char c; 149 sig_handler_t f; 150 151 f = signal(SIGALRM, (sig_handler_t)sigALRM); 152 timeout = 0; 153 while (*s) { 154 if (sigsetjmp(timeoutbuf, 1)) { 155 biz22_abort(); 156 break; 157 } 158 (void) alarm(number(value(DIALTIMEOUT))); 159 (void) read(FD, &c, 1); 160 (void) alarm(0); 161 c &= 0177; 162 if (c != *s++) 163 return (0); 164 } 165 (void) signal(SIGALRM, f); 166 return (timeout == 0); 167} 168