xref: /illumos-gate/usr/src/cmd/tip/aculib/df.c (revision 8d489c7a)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
37c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
47c478bd9Sstevel@tonic-gate  */
5*8d489c7aSmuffin 
67c478bd9Sstevel@tonic-gate /*
77c478bd9Sstevel@tonic-gate  * Copyright (c) 1983 Regents of the University of California.
87c478bd9Sstevel@tonic-gate  * All rights reserved. The Berkeley software License Agreement
97c478bd9Sstevel@tonic-gate  * specifies the terms and conditions for redistribution.
107c478bd9Sstevel@tonic-gate  */
11*8d489c7aSmuffin 
12*8d489c7aSmuffin #pragma ident	"%Z%%M%	%I%	%E% SMI"
137c478bd9Sstevel@tonic-gate 
147c478bd9Sstevel@tonic-gate /*
157c478bd9Sstevel@tonic-gate  * Dial the DF02-AC or DF03-AC
167c478bd9Sstevel@tonic-gate  */
177c478bd9Sstevel@tonic-gate 
187c478bd9Sstevel@tonic-gate #include "tip.h"
197c478bd9Sstevel@tonic-gate 
20*8d489c7aSmuffin static sigjmp_buf	Sjbuf;
21*8d489c7aSmuffin static void	timeout(void);
227c478bd9Sstevel@tonic-gate 
23*8d489c7aSmuffin void	df_disconnect(void);
24*8d489c7aSmuffin int	df_dialer(char *, char *, int);
25*8d489c7aSmuffin 
26*8d489c7aSmuffin int
df02_dialer(char * num,char * acu)27*8d489c7aSmuffin df02_dialer(char *num, char *acu)
287c478bd9Sstevel@tonic-gate {
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate 	return (df_dialer(num, acu, 0));
317c478bd9Sstevel@tonic-gate }
327c478bd9Sstevel@tonic-gate 
33*8d489c7aSmuffin int
df03_dialer(char * num,char * acu)34*8d489c7aSmuffin df03_dialer(char *num, char *acu)
357c478bd9Sstevel@tonic-gate {
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate 	return (df_dialer(num, acu, 1));
387c478bd9Sstevel@tonic-gate }
397c478bd9Sstevel@tonic-gate 
40*8d489c7aSmuffin /* ARGSUSED */
41*8d489c7aSmuffin int
df_dialer(char * num,char * acu,int df03)42*8d489c7aSmuffin df_dialer(char *num, char *acu, int df03)
437c478bd9Sstevel@tonic-gate {
44*8d489c7aSmuffin 	int f = FD;
457c478bd9Sstevel@tonic-gate 	struct termios buf;
467c478bd9Sstevel@tonic-gate 	int speed = 0;
477c478bd9Sstevel@tonic-gate 	char c = '\0';
487c478bd9Sstevel@tonic-gate 
49*8d489c7aSmuffin 	(void) ioctl(f, TCGETS, &buf);
507c478bd9Sstevel@tonic-gate 	buf.c_cflag |= HUPCL;
51*8d489c7aSmuffin 	(void) ioctl(f, TCSETS, &buf);
527c478bd9Sstevel@tonic-gate 	if (sigsetjmp(Sjbuf, 1)) {
53*8d489c7aSmuffin 		(void) printf("connection timed out\r\n");
547c478bd9Sstevel@tonic-gate 		df_disconnect();
557c478bd9Sstevel@tonic-gate 		return (0);
567c478bd9Sstevel@tonic-gate 	}
577c478bd9Sstevel@tonic-gate 	if (boolean(value(VERBOSE)))
58*8d489c7aSmuffin 		(void) printf("\ndialing...");
59*8d489c7aSmuffin 	(void) fflush(stdout);
607c478bd9Sstevel@tonic-gate #ifdef TIOCMSET
617c478bd9Sstevel@tonic-gate 	if (df03) {
627c478bd9Sstevel@tonic-gate 		int st = TIOCM_ST;	/* secondary Transmit flag */
637c478bd9Sstevel@tonic-gate 
64*8d489c7aSmuffin 		(void) ioctl(f, TCGETS, &buf);
657c478bd9Sstevel@tonic-gate 		if (cfgetospeed(&buf) != B1200) { /* must dial at 1200 baud */
667c478bd9Sstevel@tonic-gate 			speed = cfgetospeed(&buf);
67*8d489c7aSmuffin 			(void) cfsetospeed(&buf, B0);
68*8d489c7aSmuffin 			(void) cfsetispeed(&buf, B0);
69*8d489c7aSmuffin 			(void) cfsetospeed(&buf, B1200);
70*8d489c7aSmuffin 			(void) ioctl(f, TCSETSW, &buf);
71*8d489c7aSmuffin 			/* clear ST for 300 baud */
72*8d489c7aSmuffin 			(void) ioctl(f, TIOCMBIC, &st);
737c478bd9Sstevel@tonic-gate 		} else
74*8d489c7aSmuffin 			/* set ST for 1200 baud */
75*8d489c7aSmuffin 			(void) ioctl(f, TIOCMBIS, &st);
767c478bd9Sstevel@tonic-gate 	}
777c478bd9Sstevel@tonic-gate #endif
78*8d489c7aSmuffin 	(void) signal(SIGALRM, (sig_handler_t)timeout);
79*8d489c7aSmuffin 	(void) alarm(5 * strlen(num) + 10);
80*8d489c7aSmuffin 	(void) ioctl(f, TCFLSH, TCOFLUSH);
81*8d489c7aSmuffin 	(void) write(f, "\001", 1);
82*8d489c7aSmuffin 	(void) sleep(1);
83*8d489c7aSmuffin 	(void) write(f, "\002", 1);
84*8d489c7aSmuffin 	(void) write(f, num, strlen(num));
85*8d489c7aSmuffin 	(void) read(f, &c, 1);
867c478bd9Sstevel@tonic-gate #ifdef TIOCMSET
877c478bd9Sstevel@tonic-gate 	if (df03 && speed) {
88*8d489c7aSmuffin 		(void) cfsetospeed(&buf, B0);
89*8d489c7aSmuffin 		(void) cfsetispeed(&buf, B0);
90*8d489c7aSmuffin 		(void) cfsetospeed(&buf, speed);
91*8d489c7aSmuffin 		(void) ioctl(f, TCSETSW, &buf);
927c478bd9Sstevel@tonic-gate 	}
937c478bd9Sstevel@tonic-gate #endif
947c478bd9Sstevel@tonic-gate 	return (c == 'A');
957c478bd9Sstevel@tonic-gate }
967c478bd9Sstevel@tonic-gate 
97*8d489c7aSmuffin void
df_disconnect(void)98*8d489c7aSmuffin df_disconnect(void)
997c478bd9Sstevel@tonic-gate {
1007c478bd9Sstevel@tonic-gate 
101*8d489c7aSmuffin 	(void) write(FD, "\001", 1);
102*8d489c7aSmuffin 	(void) sleep(1);
103*8d489c7aSmuffin 	(void) ioctl(FD, TCFLSH, TCOFLUSH);
1047c478bd9Sstevel@tonic-gate }
1057c478bd9Sstevel@tonic-gate 
106*8d489c7aSmuffin void
df_abort(void)107*8d489c7aSmuffin df_abort(void)
1087c478bd9Sstevel@tonic-gate {
1097c478bd9Sstevel@tonic-gate 
1107c478bd9Sstevel@tonic-gate 	df_disconnect();
1117c478bd9Sstevel@tonic-gate }
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate 
1147c478bd9Sstevel@tonic-gate static void
timeout(void)115*8d489c7aSmuffin timeout(void)
1167c478bd9Sstevel@tonic-gate {
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate 	siglongjmp(Sjbuf, 1);
1197c478bd9Sstevel@tonic-gate }
120