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