xref: /original-bsd/usr.bin/tip/aculib/df.c (revision abd50c55)
1 /*
2  * Copyright (c) 1983 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms are permitted
6  * provided that the above copyright notice and this paragraph are
7  * duplicated in all such forms and that any documentation,
8  * advertising materials, and other materials related to such
9  * distribution and use acknowledge that the software was developed
10  * by the University of California, Berkeley.  The name of the
11  * University may not be used to endorse or promote products derived
12  * from this software without specific prior written permission.
13  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16  */
17 
18 #ifndef lint
19 static char sccsid[] = "@(#)df.c	5.2 (Berkeley) 09/13/88";
20 #endif /* not lint */
21 
22 /*
23  * Dial the DF02-AC or DF03-AC
24  */
25 
26 #include "tip.h"
27 
28 static jmp_buf Sjbuf;
29 static timeout();
30 
31 df02_dialer(num, acu)
32 	char *num, *acu;
33 {
34 
35 	return (df_dialer(num, acu, 0));
36 }
37 
38 df03_dialer(num, acu)
39 	char *num, *acu;
40 {
41 
42 	return (df_dialer(num, acu, 1));
43 }
44 
45 df_dialer(num, acu, df03)
46 	char *num, *acu;
47 	int df03;
48 {
49 	register int f = FD;
50 	struct sgttyb buf;
51 	int speed = 0, rw = 2;
52 	char c = '\0';
53 
54 	ioctl(f, TIOCHPCL, 0);		/* make sure it hangs up when done */
55 	if (setjmp(Sjbuf)) {
56 		printf("connection timed out\r\n");
57 		df_disconnect();
58 		return (0);
59 	}
60 	if (boolean(value(VERBOSE)))
61 		printf("\ndialing...");
62 	fflush(stdout);
63 #ifdef TIOCMSET
64 	if (df03) {
65 		int st = TIOCM_ST;	/* secondary Transmit flag */
66 
67 		ioctl(f, TIOCGETP, &buf);
68 		if (buf.sg_ospeed != B1200) {	/* must dial at 1200 baud */
69 			speed = buf.sg_ospeed;
70 			buf.sg_ospeed = buf.sg_ispeed = B1200;
71 			ioctl(f, TIOCSETP, &buf);
72 			ioctl(f, TIOCMBIC, &st); /* clear ST for 300 baud */
73 		} else
74 			ioctl(f, TIOCMBIS, &st); /* set ST for 1200 baud */
75 	}
76 #endif
77 	signal(SIGALRM, timeout);
78 	alarm(5 * strlen(num) + 10);
79 	ioctl(f, TIOCFLUSH, &rw);
80 	write(f, "\001", 1);
81 	sleep(1);
82 	write(f, "\002", 1);
83 	write(f, num, strlen(num));
84 	read(f, &c, 1);
85 #ifdef TIOCMSET
86 	if (df03 && speed) {
87 		buf.sg_ispeed = buf.sg_ospeed = speed;
88 		ioctl(f, TIOCSETP, &buf);
89 	}
90 #endif
91 	return (c == 'A');
92 }
93 
94 df_disconnect()
95 {
96 	int rw = 2;
97 
98 	write(FD, "\001", 1);
99 	sleep(1);
100 	ioctl(FD, TIOCFLUSH, &rw);
101 }
102 
103 
104 df_abort()
105 {
106 
107 	df_disconnect();
108 }
109 
110 
111 static
112 timeout()
113 {
114 
115 	longjmp(Sjbuf, 1);
116 }
117