Home | History | Annotate | Line # | Download | only in aculib
v3451.c revision 1.5
      1 /*	$NetBSD: v3451.c,v 1.5 1996/12/29 10:42:00 cgd 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 #ifndef lint
     37 #if 0
     38 static char sccsid[] = "@(#)v3451.c	8.1 (Berkeley) 6/6/93";
     39 #endif
     40 static char rcsid[] = "$NetBSD: v3451.c,v 1.5 1996/12/29 10:42:00 cgd Exp $";
     41 #endif /* not lint */
     42 
     43 /*
     44  * Routines for calling up on a Vadic 3451 Modem
     45  */
     46 #include "tip.h"
     47 
     48 static	jmp_buf Sjbuf;
     49 
     50 static	int expect(), notin(), prefix();
     51 static	void vawrite(), alarmtr();
     52 
     53 v3451_dialer(num, acu)
     54 	register char *num;
     55 	char *acu;
     56 {
     57 	sig_t func;
     58 	int ok;
     59 	int slow = number(value(BAUDRATE)) < 1200, rw = 2;
     60 	char phone[50];
     61 	struct termios cntrl;
     62 #ifdef ACULOG
     63 	char line[80];
     64 #endif
     65 
     66 	/*
     67 	 * Get in synch
     68 	 */
     69 	vawrite("I\r", 1 + slow);
     70 	vawrite("I\r", 1 + slow);
     71 	vawrite("I\r", 1 + slow);
     72 	vawrite("\005\r", 2 + slow);
     73 	if (!expect("READY")) {
     74 		printf("can't synchronize with vadic 3451\n");
     75 #ifdef ACULOG
     76 		logent(value(HOST), num, "vadic", "can't synch up");
     77 #endif
     78 		return (0);
     79 	}
     80 	tcgetattr(FD, &cntrl);
     81 	term.c_cflag |= HUPCL;
     82 	tcsetattr(FD, TCSANOW, &cntrl);
     83 	sleep(1);
     84 	vawrite("D\r", 2 + slow);
     85 	if (!expect("NUMBER?")) {
     86 		printf("Vadic will not accept dial command\n");
     87 #ifdef ACULOG
     88 		logent(value(HOST), num, "vadic", "will not accept dial");
     89 #endif
     90 		return (0);
     91 	}
     92 	strcpy(phone, num);
     93 	strcat(phone, "\r");
     94 	vawrite(phone, 1 + slow);
     95 	if (!expect(phone)) {
     96 		printf("Vadic will not accept phone number\n");
     97 #ifdef ACULOG
     98 		logent(value(HOST), num, "vadic", "will not accept number");
     99 #endif
    100 		return (0);
    101 	}
    102 	func = signal(SIGINT,SIG_IGN);
    103 	/*
    104 	 * You cannot interrupt the Vadic when its dialing;
    105 	 * even dropping DTR does not work (definitely a
    106 	 * brain damaged design).
    107 	 */
    108 	vawrite("\r", 1 + slow);
    109 	vawrite("\r", 1 + slow);
    110 	if (!expect("DIALING:")) {
    111 		printf("Vadic failed to dial\n");
    112 #ifdef ACULOG
    113 		logent(value(HOST), num, "vadic", "failed to dial");
    114 #endif
    115 		return (0);
    116 	}
    117 	if (boolean(value(VERBOSE)))
    118 		printf("\ndialing...");
    119 	ok = expect("ON LINE");
    120 	signal(SIGINT, func);
    121 	if (!ok) {
    122 		printf("call failed\n");
    123 #ifdef ACULOG
    124 		logent(value(HOST), num, "vadic", "call failed");
    125 #endif
    126 		return (0);
    127 	}
    128 	tcflush(FD, TCIOFLUSH);
    129 	return (1);
    130 }
    131 
    132 v3451_disconnect()
    133 {
    134 
    135 	close(FD);
    136 }
    137 
    138 v3451_abort()
    139 {
    140 
    141 	close(FD);
    142 }
    143 
    144 static void
    145 vawrite(cp, delay)
    146 	register char *cp;
    147 	int delay;
    148 {
    149 
    150 	for (; *cp; sleep(delay), cp++)
    151 		write(FD, cp, 1);
    152 }
    153 
    154 static
    155 expect(cp)
    156 	register char *cp;
    157 {
    158 	char buf[300];
    159 	register char *rp = buf;
    160 	int timeout = 30, online = 0;
    161 
    162 	if (strcmp(cp, "\"\"") == 0)
    163 		return (1);
    164 	*rp = 0;
    165 	/*
    166 	 * If we are waiting for the Vadic to complete
    167 	 * dialing and get a connection, allow more time
    168 	 * Unfortunately, the Vadic times out 24 seconds after
    169 	 * the last digit is dialed
    170 	 */
    171 	online = strcmp(cp, "ON LINE") == 0;
    172 	if (online)
    173 		timeout = number(value(DIALTIMEOUT));
    174 	signal(SIGALRM, alarmtr);
    175 	if (setjmp(Sjbuf))
    176 		return (0);
    177 	alarm(timeout);
    178 	while (notin(cp, buf) && rp < buf + sizeof (buf) - 1) {
    179 		if (online && notin("FAILED CALL", buf) == 0)
    180 			return (0);
    181 		if (read(FD, rp, 1) < 0) {
    182 			alarm(0);
    183 			return (0);
    184 		}
    185 		if (*rp &= 0177)
    186 			rp++;
    187 		*rp = '\0';
    188 	}
    189 	alarm(0);
    190 	return (1);
    191 }
    192 
    193 static void
    194 alarmtr()
    195 {
    196 	longjmp(Sjbuf, 1);
    197 }
    198 
    199 static int
    200 notin(sh, lg)
    201 	char *sh, *lg;
    202 {
    203 
    204 	for (; *lg; lg++)
    205 		if (prefix(sh, lg))
    206 			return (0);
    207 	return (1);
    208 }
    209 
    210 static
    211 prefix(s1, s2)
    212 	register char *s1, *s2;
    213 {
    214 	register char c;
    215 
    216 	while ((c = *s1++) == *s2++)
    217 		if (c == '\0')
    218 			return (1);
    219 	return (c == '\0');
    220 }
    221