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