xref: /netbsd-src/usr.bin/tip/aculib/df.c (revision 76dfffe33547c37f8bdd446e3e4ab0f3c16cea4b)
1 /*	$NetBSD: df.c,v 1.4 1995/10/29 00:49:51 pk 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[] = "@(#)df.c	8.1 (Berkeley) 6/6/93";
39 #endif
40 static char rcsid[] = "$NetBSD: df.c,v 1.4 1995/10/29 00:49:51 pk Exp $";
41 #endif /* not lint */
42 
43 /*
44  * Dial the DF02-AC or DF03-AC
45  */
46 
47 #include "tip.h"
48 
49 static jmp_buf Sjbuf;
50 static void timeout();
51 
52 df02_dialer(num, acu)
53 	char *num, *acu;
54 {
55 
56 	return (df_dialer(num, acu, 0));
57 }
58 
59 df03_dialer(num, acu)
60 	char *num, *acu;
61 {
62 
63 	return (df_dialer(num, acu, 1));
64 }
65 
66 df_dialer(num, acu, df03)
67 	char *num, *acu;
68 	int df03;
69 {
70 	register int f = FD;
71 	struct termios cntrl;
72 	int speed = 0, rw = 2;
73 	char c = '\0';
74 
75 	tcgetattr(f, &cntrl);
76 	cntrl.c_cflag |= HUPCL;
77 	tcsetattr(f, TCSANOW, &cntrl);
78 	if (setjmp(Sjbuf)) {
79 		printf("connection timed out\r\n");
80 		df_disconnect();
81 		return (0);
82 	}
83 	if (boolean(value(VERBOSE)))
84 		printf("\ndialing...");
85 	fflush(stdout);
86 #ifdef TIOCMSET
87 	if (df03) {
88 		int st = TIOCM_ST;	/* secondary Transmit flag */
89 
90 		tcgetattr(f, &cntrl);
91 		speed = cfgetospeed(&cntrl);
92 		if (speed != B1200) {	/* must dial at 1200 baud */
93 			cfsetospeed(&cntrl, B1200);
94 			cfsetispeed(&cntrl, B1200);
95 			tcsetattr(f, TCSAFLUSH, &cntrl);
96 			ioctl(f, TIOCMBIC, &st); /* clear ST for 300 baud */
97 		} else
98 			ioctl(f, TIOCMBIS, &st); /* set ST for 1200 baud */
99 	}
100 #endif
101 	signal(SIGALRM, timeout);
102 	alarm(5 * strlen(num) + 10);
103 	tcflush(f, TCIOFLUSH);
104 	write(f, "\001", 1);
105 	sleep(1);
106 	write(f, "\002", 1);
107 	write(f, num, strlen(num));
108 	read(f, &c, 1);
109 #ifdef TIOCMSET
110 	if (df03 && speed != B1200) {
111 		cfsetospeed(&cntrl, speed);
112 		cfsetispeed(&cntrl, speed);
113 		tcsetattr(f, TCSAFLUSH, &cntrl);
114 	}
115 #endif
116 	return (c == 'A');
117 }
118 
119 df_disconnect()
120 {
121 	int rw = 2;
122 
123 	write(FD, "\001", 1);
124 	sleep(1);
125 	tcflush(FD, TCIOFLUSH);
126 }
127 
128 
129 df_abort()
130 {
131 
132 	df_disconnect();
133 }
134 
135 
136 static void
137 timeout()
138 {
139 
140 	longjmp(Sjbuf, 1);
141 }
142