xref: /onnv-gate/usr/src/cmd/tip/aculib/df.c (revision 0)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
3*0Sstevel@tonic-gate  * Use is subject to license terms.
4*0Sstevel@tonic-gate  */
5*0Sstevel@tonic-gate /*
6*0Sstevel@tonic-gate  * Copyright (c) 1983 Regents of the University of California.
7*0Sstevel@tonic-gate  * All rights reserved. The Berkeley software License Agreement
8*0Sstevel@tonic-gate  * specifies the terms and conditions for redistribution.
9*0Sstevel@tonic-gate  */
10*0Sstevel@tonic-gate #ident	"%Z%%M%	%I%	%E% SMI"	/* from UCB 4.8 6/25/83 */
11*0Sstevel@tonic-gate 
12*0Sstevel@tonic-gate /*
13*0Sstevel@tonic-gate  * Dial the DF02-AC or DF03-AC
14*0Sstevel@tonic-gate  */
15*0Sstevel@tonic-gate 
16*0Sstevel@tonic-gate #include "tip.h"
17*0Sstevel@tonic-gate 
18*0Sstevel@tonic-gate static sigjmp_buf Sjbuf;
19*0Sstevel@tonic-gate static void timeout();
20*0Sstevel@tonic-gate 
21*0Sstevel@tonic-gate df02_dialer(num, acu)
22*0Sstevel@tonic-gate 	char *num, *acu;
23*0Sstevel@tonic-gate {
24*0Sstevel@tonic-gate 
25*0Sstevel@tonic-gate 	return (df_dialer(num, acu, 0));
26*0Sstevel@tonic-gate }
27*0Sstevel@tonic-gate 
28*0Sstevel@tonic-gate df03_dialer(num, acu)
29*0Sstevel@tonic-gate 	char *num, *acu;
30*0Sstevel@tonic-gate {
31*0Sstevel@tonic-gate 
32*0Sstevel@tonic-gate 	return (df_dialer(num, acu, 1));
33*0Sstevel@tonic-gate }
34*0Sstevel@tonic-gate 
35*0Sstevel@tonic-gate df_dialer(num, acu, df03)
36*0Sstevel@tonic-gate 	char *num, *acu;
37*0Sstevel@tonic-gate 	int df03;
38*0Sstevel@tonic-gate {
39*0Sstevel@tonic-gate 	register int f = FD;
40*0Sstevel@tonic-gate 	struct termios buf;
41*0Sstevel@tonic-gate 	int speed = 0;
42*0Sstevel@tonic-gate 	char c = '\0';
43*0Sstevel@tonic-gate 
44*0Sstevel@tonic-gate 	ioctl(f, TCGETS, &buf);
45*0Sstevel@tonic-gate 	buf.c_cflag |= HUPCL;
46*0Sstevel@tonic-gate 	ioctl(f, TCSETS, &buf);
47*0Sstevel@tonic-gate 	if (sigsetjmp(Sjbuf, 1)) {
48*0Sstevel@tonic-gate 		printf("connection timed out\r\n");
49*0Sstevel@tonic-gate 		df_disconnect();
50*0Sstevel@tonic-gate 		return (0);
51*0Sstevel@tonic-gate 	}
52*0Sstevel@tonic-gate 	if (boolean(value(VERBOSE)))
53*0Sstevel@tonic-gate 		printf("\ndialing...");
54*0Sstevel@tonic-gate 	fflush(stdout);
55*0Sstevel@tonic-gate #ifdef TIOCMSET
56*0Sstevel@tonic-gate 	if (df03) {
57*0Sstevel@tonic-gate 		int st = TIOCM_ST;	/* secondary Transmit flag */
58*0Sstevel@tonic-gate 
59*0Sstevel@tonic-gate 		ioctl(f, TCGETS, &buf);
60*0Sstevel@tonic-gate 		if (cfgetospeed(&buf) != B1200) { /* must dial at 1200 baud */
61*0Sstevel@tonic-gate 			speed = cfgetospeed(&buf);
62*0Sstevel@tonic-gate 			cfsetospeed(&buf, B0);
63*0Sstevel@tonic-gate 			cfsetispeed(&buf, B0);
64*0Sstevel@tonic-gate 			cfsetospeed(&buf, B1200);
65*0Sstevel@tonic-gate 			ioctl(f, TCSETSW, &buf);
66*0Sstevel@tonic-gate 			ioctl(f, TIOCMBIC, &st); /* clear ST for 300 baud */
67*0Sstevel@tonic-gate 		} else
68*0Sstevel@tonic-gate 			ioctl(f, TIOCMBIS, &st); /* set ST for 1200 baud */
69*0Sstevel@tonic-gate 	}
70*0Sstevel@tonic-gate #endif
71*0Sstevel@tonic-gate 	signal(SIGALRM, timeout);
72*0Sstevel@tonic-gate 	alarm(5 * strlen(num) + 10);
73*0Sstevel@tonic-gate 	ioctl(f, TCFLSH, TCOFLUSH);
74*0Sstevel@tonic-gate 	write(f, "\001", 1);
75*0Sstevel@tonic-gate 	sleep(1);
76*0Sstevel@tonic-gate 	write(f, "\002", 1);
77*0Sstevel@tonic-gate 	write(f, num, strlen(num));
78*0Sstevel@tonic-gate 	read(f, &c, 1);
79*0Sstevel@tonic-gate #ifdef TIOCMSET
80*0Sstevel@tonic-gate 	if (df03 && speed) {
81*0Sstevel@tonic-gate 		cfsetospeed(&buf, B0);
82*0Sstevel@tonic-gate 		cfsetispeed(&buf, B0);
83*0Sstevel@tonic-gate 		cfsetospeed(&buf, speed);
84*0Sstevel@tonic-gate 		ioctl(f, TCSETSW, &buf);
85*0Sstevel@tonic-gate 	}
86*0Sstevel@tonic-gate #endif
87*0Sstevel@tonic-gate 	return (c == 'A');
88*0Sstevel@tonic-gate }
89*0Sstevel@tonic-gate 
90*0Sstevel@tonic-gate df_disconnect()
91*0Sstevel@tonic-gate {
92*0Sstevel@tonic-gate 
93*0Sstevel@tonic-gate 	write(FD, "\001", 1);
94*0Sstevel@tonic-gate 	sleep(1);
95*0Sstevel@tonic-gate 	ioctl(FD, TCFLSH, TCOFLUSH);
96*0Sstevel@tonic-gate }
97*0Sstevel@tonic-gate 
98*0Sstevel@tonic-gate 
99*0Sstevel@tonic-gate df_abort()
100*0Sstevel@tonic-gate {
101*0Sstevel@tonic-gate 
102*0Sstevel@tonic-gate 	df_disconnect();
103*0Sstevel@tonic-gate }
104*0Sstevel@tonic-gate 
105*0Sstevel@tonic-gate 
106*0Sstevel@tonic-gate static void
107*0Sstevel@tonic-gate timeout()
108*0Sstevel@tonic-gate {
109*0Sstevel@tonic-gate 
110*0Sstevel@tonic-gate 	siglongjmp(Sjbuf, 1);
111*0Sstevel@tonic-gate }
112