Home | History | Annotate | Line # | Download | only in aculib
      1  1.13  christos /*	$NetBSD: v3451.c,v 1.14 2006/12/14 17:09:43 christos Exp $	*/
      2   1.3       jtc 
      3   1.1       cgd /*
      4   1.3       jtc  * Copyright (c) 1983, 1993
      5   1.3       jtc  *	The Regents of the University of California.  All rights reserved.
      6   1.1       cgd  *
      7   1.1       cgd  * Redistribution and use in source and binary forms, with or without
      8   1.1       cgd  * modification, are permitted provided that the following conditions
      9   1.1       cgd  * are met:
     10   1.1       cgd  * 1. Redistributions of source code must retain the above copyright
     11   1.1       cgd  *    notice, this list of conditions and the following disclaimer.
     12   1.1       cgd  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.1       cgd  *    notice, this list of conditions and the following disclaimer in the
     14   1.1       cgd  *    documentation and/or other materials provided with the distribution.
     15   1.9       agc  * 3. Neither the name of the University nor the names of its contributors
     16   1.1       cgd  *    may be used to endorse or promote products derived from this software
     17   1.1       cgd  *    without specific prior written permission.
     18   1.1       cgd  *
     19   1.1       cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     20   1.1       cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     21   1.1       cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     22   1.1       cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     23   1.1       cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24   1.1       cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     25   1.1       cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26   1.1       cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27   1.1       cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28   1.1       cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29   1.1       cgd  * SUCH DAMAGE.
     30   1.1       cgd  */
     31   1.1       cgd 
     32   1.7     lukem #include <sys/cdefs.h>
     33   1.1       cgd #ifndef lint
     34   1.3       jtc #if 0
     35   1.3       jtc static char sccsid[] = "@(#)v3451.c	8.1 (Berkeley) 6/6/93";
     36   1.3       jtc #endif
     37  1.13  christos __RCSID("$NetBSD: v3451.c,v 1.14 2006/12/14 17:09:43 christos Exp $");
     38   1.1       cgd #endif /* not lint */
     39   1.1       cgd 
     40   1.1       cgd /*
     41   1.1       cgd  * Routines for calling up on a Vadic 3451 Modem
     42   1.1       cgd  */
     43   1.1       cgd #include "tip.h"
     44   1.1       cgd 
     45   1.1       cgd static	jmp_buf Sjbuf;
     46   1.1       cgd 
     47  1.11     perry static	void	alarmtr(int);
     48  1.11     perry static	int	expect(const char *);
     49  1.11     perry static	int	notin(const char *, char *);
     50  1.11     perry static	int	prefix(const char *, char *);
     51  1.11     perry static	void	vawrite(const char *, int);
     52   1.5       cgd 
     53   1.7     lukem int
     54  1.14  christos /*ARGSUSED*/
     55  1.14  christos v3451_dialer(char *num, char *acu __unused)
     56   1.1       cgd {
     57   1.1       cgd 	sig_t func;
     58   1.1       cgd 	int ok;
     59   1.7     lukem 	int slow = number(value(BAUDRATE)) < 1200;
     60   1.1       cgd 	char phone[50];
     61   1.4        pk 	struct termios cntrl;
     62   1.1       cgd 
     63   1.1       cgd 	/*
     64   1.1       cgd 	 * Get in synch
     65   1.1       cgd 	 */
     66   1.1       cgd 	vawrite("I\r", 1 + slow);
     67   1.1       cgd 	vawrite("I\r", 1 + slow);
     68   1.1       cgd 	vawrite("I\r", 1 + slow);
     69   1.1       cgd 	vawrite("\005\r", 2 + slow);
     70   1.1       cgd 	if (!expect("READY")) {
     71  1.14  christos 		(void)printf("can't synchronize with vadic 3451\n");
     72   1.1       cgd 		return (0);
     73   1.1       cgd 	}
     74  1.14  christos 	(void)tcgetattr(FD, &cntrl);
     75   1.4        pk 	term.c_cflag |= HUPCL;
     76  1.14  christos 	(void)tcsetattr(FD, TCSANOW, &cntrl);
     77  1.14  christos 	(void)sleep(1);
     78   1.1       cgd 	vawrite("D\r", 2 + slow);
     79   1.1       cgd 	if (!expect("NUMBER?")) {
     80  1.14  christos 		(void)printf("Vadic will not accept dial command\n");
     81   1.1       cgd 		return (0);
     82   1.1       cgd 	}
     83  1.14  christos 	(void)snprintf(phone, sizeof phone, "%s\r", num);
     84   1.1       cgd 	vawrite(phone, 1 + slow);
     85   1.1       cgd 	if (!expect(phone)) {
     86  1.14  christos 		(void)printf("Vadic will not accept phone number\n");
     87   1.1       cgd 		return (0);
     88   1.1       cgd 	}
     89   1.1       cgd 	func = signal(SIGINT,SIG_IGN);
     90   1.1       cgd 	/*
     91   1.1       cgd 	 * You cannot interrupt the Vadic when its dialing;
     92   1.1       cgd 	 * even dropping DTR does not work (definitely a
     93   1.1       cgd 	 * brain damaged design).
     94   1.1       cgd 	 */
     95   1.1       cgd 	vawrite("\r", 1 + slow);
     96   1.1       cgd 	vawrite("\r", 1 + slow);
     97   1.1       cgd 	if (!expect("DIALING:")) {
     98  1.14  christos 		(void)printf("Vadic failed to dial\n");
     99   1.1       cgd 		return (0);
    100   1.1       cgd 	}
    101   1.1       cgd 	if (boolean(value(VERBOSE)))
    102  1.14  christos 		(void)printf("\ndialing...");
    103   1.1       cgd 	ok = expect("ON LINE");
    104  1.14  christos 	(void)signal(SIGINT, func);
    105   1.1       cgd 	if (!ok) {
    106  1.14  christos 		(void)printf("call failed\n");
    107   1.1       cgd 		return (0);
    108   1.1       cgd 	}
    109  1.14  christos 	(void)tcflush(FD, TCIOFLUSH);
    110   1.1       cgd 	return (1);
    111   1.1       cgd }
    112   1.1       cgd 
    113   1.7     lukem void
    114  1.11     perry v3451_disconnect(void)
    115   1.1       cgd {
    116   1.1       cgd 
    117  1.14  christos 	(void)close(FD);
    118   1.1       cgd }
    119   1.1       cgd 
    120   1.7     lukem void
    121  1.11     perry v3451_abort(void)
    122   1.1       cgd {
    123   1.1       cgd 
    124  1.14  christos 	(void)close(FD);
    125   1.1       cgd }
    126   1.1       cgd 
    127   1.1       cgd static void
    128  1.11     perry vawrite(const char *cp, int delay)
    129   1.1       cgd {
    130   1.1       cgd 
    131  1.14  christos 	for (/*EMPTY*/; *cp; cp++) {
    132  1.14  christos 		(void)write(FD, cp, 1);
    133  1.14  christos 		(void)sleep((unsigned)delay);
    134  1.14  christos 	}
    135   1.1       cgd }
    136   1.1       cgd 
    137   1.7     lukem static int
    138  1.11     perry expect(const char *cp)
    139   1.1       cgd {
    140   1.1       cgd 	char buf[300];
    141  1.13  christos 	char * volatile rp;
    142  1.13  christos 	int volatile timeout;
    143  1.13  christos 	int volatile online;
    144  1.13  christos 
    145  1.13  christos 	rp = buf;
    146  1.13  christos 	timeout = 30;
    147  1.13  christos 	online = 0;
    148   1.7     lukem 
    149   1.1       cgd 	if (strcmp(cp, "\"\"") == 0)
    150   1.1       cgd 		return (1);
    151   1.1       cgd 	*rp = 0;
    152   1.1       cgd 	/*
    153   1.1       cgd 	 * If we are waiting for the Vadic to complete
    154   1.1       cgd 	 * dialing and get a connection, allow more time
    155   1.1       cgd 	 * Unfortunately, the Vadic times out 24 seconds after
    156   1.1       cgd 	 * the last digit is dialed
    157   1.1       cgd 	 */
    158   1.1       cgd 	online = strcmp(cp, "ON LINE") == 0;
    159   1.1       cgd 	if (online)
    160   1.1       cgd 		timeout = number(value(DIALTIMEOUT));
    161  1.14  christos 	(void)signal(SIGALRM, alarmtr);
    162   1.1       cgd 	if (setjmp(Sjbuf))
    163   1.1       cgd 		return (0);
    164  1.14  christos 	(void)alarm((unsigned)timeout);
    165   1.1       cgd 	while (notin(cp, buf) && rp < buf + sizeof (buf) - 1) {
    166   1.1       cgd 		if (online && notin("FAILED CALL", buf) == 0)
    167   1.1       cgd 			return (0);
    168   1.1       cgd 		if (read(FD, rp, 1) < 0) {
    169  1.14  christos 			(void)alarm(0);
    170   1.1       cgd 			return (0);
    171   1.1       cgd 		}
    172   1.1       cgd 		if (*rp &= 0177)
    173   1.1       cgd 			rp++;
    174   1.1       cgd 		*rp = '\0';
    175   1.1       cgd 	}
    176  1.14  christos 	(void)alarm(0);
    177   1.1       cgd 	return (1);
    178   1.1       cgd }
    179   1.1       cgd 
    180   1.1       cgd static void
    181  1.14  christos /*ARGSUSED*/
    182  1.14  christos alarmtr(int dummy __unused)
    183   1.1       cgd {
    184   1.8       mrg 
    185   1.1       cgd 	longjmp(Sjbuf, 1);
    186   1.1       cgd }
    187   1.1       cgd 
    188   1.1       cgd static int
    189  1.11     perry notin(const char *sh, char *lg)
    190   1.1       cgd {
    191   1.1       cgd 
    192   1.1       cgd 	for (; *lg; lg++)
    193   1.1       cgd 		if (prefix(sh, lg))
    194   1.1       cgd 			return (0);
    195   1.1       cgd 	return (1);
    196   1.1       cgd }
    197   1.1       cgd 
    198   1.7     lukem static int
    199  1.11     perry prefix(const char *s1, char *s2)
    200   1.1       cgd {
    201   1.7     lukem 	char c;
    202   1.1       cgd 
    203   1.1       cgd 	while ((c = *s1++) == *s2++)
    204   1.1       cgd 		if (c == '\0')
    205   1.1       cgd 			return (1);
    206   1.1       cgd 	return (c == '\0');
    207   1.1       cgd }
    208