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