Home | History | Annotate | Line # | Download | only in aculib
      1 /*	$NetBSD: df.c,v 1.10 2006/12/14 17:09:43 christos 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. Neither the name of the University nor the names of its contributors
     16  *    may be used to endorse or promote products derived from this software
     17  *    without specific prior written permission.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29  * SUCH DAMAGE.
     30  */
     31 
     32 #include <sys/cdefs.h>
     33 #ifndef lint
     34 #if 0
     35 static char sccsid[] = "@(#)df.c	8.1 (Berkeley) 6/6/93";
     36 #endif
     37 __RCSID("$NetBSD: df.c,v 1.10 2006/12/14 17:09:43 christos Exp $");
     38 #endif /* not lint */
     39 
     40 /*
     41  * Dial the DF02-AC or DF03-AC
     42  */
     43 
     44 #include "tip.h"
     45 
     46 static jmp_buf Sjbuf;
     47 
     48 static	int	df_dialer(char *, char *, int);
     49 static	void	timeout(int);
     50 
     51 int
     52 df02_dialer(char *num, char *acu)
     53 {
     54 
     55 	return (df_dialer(num, acu, 0));
     56 }
     57 
     58 int
     59 df03_dialer(char *num, char *acu)
     60 {
     61 
     62 	return (df_dialer(num, acu, 1));
     63 }
     64 
     65 static int
     66 /*ARGSUSED*/
     67 df_dialer(char *num, char *acu __unused, int df03)
     68 {
     69 	int f = FD;
     70 	struct termios cntrl;
     71 	speed_t volatile spd;
     72 	char c;
     73 
     74 	spd = 0;
     75 	c = '\0';
     76 	(void)tcgetattr(f, &cntrl);
     77 	cntrl.c_cflag |= HUPCL;
     78 	(void)tcsetattr(f, TCSANOW, &cntrl);
     79 	if (setjmp(Sjbuf)) {
     80 		(void)printf("connection timed out\r\n");
     81 		df_disconnect();
     82 		return (0);
     83 	}
     84 	if (boolean(value(VERBOSE)))
     85 		(void)printf("\ndialing...");
     86 	(void)fflush(stdout);
     87 #ifdef TIOCMSET
     88 	if (df03) {
     89 		int st = TIOCM_ST;	/* secondary Transmit flag */
     90 
     91 		(void)tcgetattr(f, &cntrl);
     92 		spd = cfgetospeed(&cntrl);
     93 		if (spd != B1200) {	/* must dial at 1200 baud */
     94 			(void)cfsetospeed(&cntrl, B1200);
     95 			(void)cfsetispeed(&cntrl, B1200);
     96 			(void)tcsetattr(f, TCSAFLUSH, &cntrl);
     97 			(void)ioctl(f, TIOCMBIC, &st); /* clear ST for 300 baud */
     98 		} else
     99 			(void)ioctl(f, TIOCMBIS, &st); /* set ST for 1200 baud */
    100 	}
    101 #endif
    102 	(void)signal(SIGALRM, timeout);
    103 	(void)alarm(5 * strlen(num) + 10);
    104 	(void)tcflush(f, TCIOFLUSH);
    105 	(void)write(f, "\001", 1);
    106 	(void)sleep(1);
    107 	(void)write(f, "\002", 1);
    108 	(void)write(f, num, strlen(num));
    109 	(void)read(f, &c, 1);
    110 #ifdef TIOCMSET
    111 	if (df03 && spd != B1200) {
    112 		(void)cfsetospeed(&cntrl, spd);
    113 		(void)cfsetispeed(&cntrl, spd);
    114 		(void)tcsetattr(f, TCSAFLUSH, &cntrl);
    115 	}
    116 #endif
    117 	return (c == 'A');
    118 }
    119 
    120 void
    121 df_disconnect(void)
    122 {
    123 
    124 	(void)write(FD, "\001", 1);
    125 	(void)sleep(1);
    126 	(void)tcflush(FD, TCIOFLUSH);
    127 }
    128 
    129 
    130 void
    131 df_abort(void)
    132 {
    133 
    134 	df_disconnect();
    135 }
    136 
    137 
    138 static void
    139 /*ARGSUSED*/
    140 timeout(int dummy __unused)
    141 {
    142 
    143 	longjmp(Sjbuf, 1);
    144 }
    145