xref: /netbsd-src/usr.bin/tip/aculib/df.c (revision ce0bb6e8d2e560ecacbe865a848624f94498063b)
1 /*	$NetBSD: df.c,v 1.3 1994/12/08 09:31:38 jtc 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.3 1994/12/08 09:31:38 jtc 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 sgttyb buf;
72 	int speed = 0, rw = 2;
73 	char c = '\0';
74 
75 	ioctl(f, TIOCHPCL, 0);		/* make sure it hangs up when done */
76 	if (setjmp(Sjbuf)) {
77 		printf("connection timed out\r\n");
78 		df_disconnect();
79 		return (0);
80 	}
81 	if (boolean(value(VERBOSE)))
82 		printf("\ndialing...");
83 	fflush(stdout);
84 #ifdef TIOCMSET
85 	if (df03) {
86 		int st = TIOCM_ST;	/* secondary Transmit flag */
87 
88 		ioctl(f, TIOCGETP, &buf);
89 		if (buf.sg_ospeed != B1200) {	/* must dial at 1200 baud */
90 			speed = buf.sg_ospeed;
91 			buf.sg_ospeed = buf.sg_ispeed = B1200;
92 			ioctl(f, TIOCSETP, &buf);
93 			ioctl(f, TIOCMBIC, &st); /* clear ST for 300 baud */
94 		} else
95 			ioctl(f, TIOCMBIS, &st); /* set ST for 1200 baud */
96 	}
97 #endif
98 	signal(SIGALRM, timeout);
99 	alarm(5 * strlen(num) + 10);
100 	ioctl(f, TIOCFLUSH, &rw);
101 	write(f, "\001", 1);
102 	sleep(1);
103 	write(f, "\002", 1);
104 	write(f, num, strlen(num));
105 	read(f, &c, 1);
106 #ifdef TIOCMSET
107 	if (df03 && speed) {
108 		buf.sg_ispeed = buf.sg_ospeed = speed;
109 		ioctl(f, TIOCSETP, &buf);
110 	}
111 #endif
112 	return (c == 'A');
113 }
114 
115 df_disconnect()
116 {
117 	int rw = 2;
118 
119 	write(FD, "\001", 1);
120 	sleep(1);
121 	ioctl(FD, TIOCFLUSH, &rw);
122 }
123 
124 
125 df_abort()
126 {
127 
128 	df_disconnect();
129 }
130 
131 
132 static void
133 timeout()
134 {
135 
136 	longjmp(Sjbuf, 1);
137 }
138