1 /* $NetBSD: biz22.c,v 1.7 1997/11/22 07:28:52 lukem Exp $ */ 2 3 /* 4 * Copyright (c) 1983, 1993 5 * The Regents of the University of California. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. All advertising materials mentioning features or use of this software 16 * must display the following acknowledgement: 17 * This product includes software developed by the University of 18 * California, Berkeley and its contributors. 19 * 4. Neither the name of the University nor the names of its contributors 20 * may be used to endorse or promote products derived from this software 21 * without specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * SUCH DAMAGE. 34 */ 35 36 #include <sys/cdefs.h> 37 #ifndef lint 38 #if 0 39 static char sccsid[] = "@(#)biz22.c 8.1 (Berkeley) 6/6/93"; 40 #endif 41 __RCSID("$NetBSD: biz22.c,v 1.7 1997/11/22 07:28:52 lukem Exp $"); 42 #endif /* not lint */ 43 44 #include "tip.h" 45 46 #define DISCONNECT_CMD "\20\04" /* disconnection string */ 47 48 static int btimeout = 0; 49 static jmp_buf timeoutbuf; 50 51 static int biz_dialer __P((char *, char *)); 52 static int cmd __P((char *)); 53 static int detect __P((char *)); 54 static void sigALRM __P((int)); 55 56 /* 57 * Dial up on a BIZCOMP Model 1022 with either 58 * tone dialing (mod = "V") 59 * pulse dialing (mod = "W") 60 */ 61 static int 62 biz_dialer(num, mod) 63 char *num, *mod; 64 { 65 int connected = 0; 66 char cbuf[40]; 67 68 if (boolean(value(VERBOSE))) 69 printf("\nstarting call..."); 70 /* 71 * Disable auto-answer and configure for tone/pulse 72 * dialing 73 */ 74 if (cmd("\02K\r")) { 75 printf("can't initialize bizcomp..."); 76 return (0); 77 } 78 (void)strncpy(cbuf, "\02.\r", sizeof(cbuf) - 1); 79 cbuf[1] = *mod; 80 if (cmd(cbuf)) { 81 printf("can't set dialing mode..."); 82 return (0); 83 } 84 (void)snprintf(cbuf, sizeof cbuf, "\02D%s\r", num); 85 write(FD, cbuf, strlen(cbuf)); 86 if (!detect("7\r")) { 87 printf("can't get dial tone..."); 88 return (0); 89 } 90 if (boolean(value(VERBOSE))) 91 printf("ringing..."); 92 /* 93 * The reply from the BIZCOMP should be: 94 * 2 \r or 7 \r failure 95 * 1 \r success 96 */ 97 connected = detect("1\r"); 98 #ifdef ACULOG 99 if (btimeout) { 100 char line[80]; 101 102 (void)snprintf(line, sizeof line, "%d second dial timeout", 103 (int)number(value(DIALTIMEOUT))); 104 logent(value(HOST), num, "biz1022", line); 105 } 106 #endif 107 if (btimeout) 108 biz22_disconnect(); /* insurance */ 109 return (connected); 110 } 111 112 int 113 biz22w_dialer(num, acu) 114 char *num, *acu; 115 { 116 117 return (biz_dialer(num, "W")); 118 } 119 120 int 121 biz22f_dialer(num, acu) 122 char *num, *acu; 123 { 124 125 return (biz_dialer(num, "V")); 126 } 127 128 void 129 biz22_disconnect() 130 { 131 132 write(FD, DISCONNECT_CMD, 4); 133 sleep(2); 134 tcflush(FD, TCIOFLUSH); 135 } 136 137 void 138 biz22_abort() 139 { 140 141 write(FD, "\02", 1); 142 } 143 144 static void 145 sigALRM(dummy) 146 int dummy; 147 { 148 149 btimeout = 1; 150 longjmp(timeoutbuf, 1); 151 } 152 153 static int 154 cmd(s) 155 char *s; 156 { 157 sig_t f; 158 char c; 159 160 write(FD, s, strlen(s)); 161 f = signal(SIGALRM, sigALRM); 162 if (setjmp(timeoutbuf)) { 163 biz22_abort(); 164 signal(SIGALRM, f); 165 return (1); 166 } 167 alarm(number(value(DIALTIMEOUT))); 168 read(FD, &c, 1); 169 alarm(0); 170 signal(SIGALRM, f); 171 c &= 0177; 172 return (c != '\r'); 173 } 174 175 static int 176 detect(s) 177 char *s; 178 { 179 sig_t f; 180 char c; 181 182 #if __GNUC__ /* XXX pacify gcc */ 183 (void)&s; 184 #endif 185 186 f = signal(SIGALRM, sigALRM); 187 btimeout = 0; 188 while (*s) { 189 if (setjmp(timeoutbuf)) { 190 biz22_abort(); 191 break; 192 } 193 alarm(number(value(DIALTIMEOUT))); 194 read(FD, &c, 1); 195 alarm(0); 196 c &= 0177; 197 if (c != *s++) 198 return (0); 199 } 200 signal(SIGALRM, f); 201 return (btimeout == 0); 202 } 203