xref: /illumos-gate/usr/src/cmd/tip/aculib/df.c (revision 2a8bcb4e)
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 
127c478bd9Sstevel@tonic-gate /*
137c478bd9Sstevel@tonic-gate  * Dial the DF02-AC or DF03-AC
147c478bd9Sstevel@tonic-gate  */
157c478bd9Sstevel@tonic-gate 
167c478bd9Sstevel@tonic-gate #include "tip.h"
177c478bd9Sstevel@tonic-gate 
18*8d489c7aSmuffin static sigjmp_buf	Sjbuf;
19*8d489c7aSmuffin static void	timeout(void);
207c478bd9Sstevel@tonic-gate 
21*8d489c7aSmuffin void	df_disconnect(void);
22*8d489c7aSmuffin int	df_dialer(char *, char *, int);
23*8d489c7aSmuffin 
24*8d489c7aSmuffin int
df02_dialer(char * num,char * acu)25*8d489c7aSmuffin df02_dialer(char *num, char *acu)
267c478bd9Sstevel@tonic-gate {
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate 	return (df_dialer(num, acu, 0));
297c478bd9Sstevel@tonic-gate }
307c478bd9Sstevel@tonic-gate 
31*8d489c7aSmuffin int
df03_dialer(char * num,char * acu)32*8d489c7aSmuffin df03_dialer(char *num, char *acu)
337c478bd9Sstevel@tonic-gate {
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate 	return (df_dialer(num, acu, 1));
367c478bd9Sstevel@tonic-gate }
377c478bd9Sstevel@tonic-gate 
38*8d489c7aSmuffin /* ARGSUSED */
39*8d489c7aSmuffin int
df_dialer(char * num,char * acu,int df03)40*8d489c7aSmuffin df_dialer(char *num, char *acu, int df03)
417c478bd9Sstevel@tonic-gate {
42*8d489c7aSmuffin 	int f = FD;
437c478bd9Sstevel@tonic-gate 	struct termios buf;
447c478bd9Sstevel@tonic-gate 	int speed = 0;
457c478bd9Sstevel@tonic-gate 	char c = '\0';
467c478bd9Sstevel@tonic-gate 
47*8d489c7aSmuffin 	(void) ioctl(f, TCGETS, &buf);
487c478bd9Sstevel@tonic-gate 	buf.c_cflag |= HUPCL;
49*8d489c7aSmuffin 	(void) ioctl(f, TCSETS, &buf);
507c478bd9Sstevel@tonic-gate 	if (sigsetjmp(Sjbuf, 1)) {
51*8d489c7aSmuffin 		(void) printf("connection timed out\r\n");
527c478bd9Sstevel@tonic-gate 		df_disconnect();
537c478bd9Sstevel@tonic-gate 		return (0);
547c478bd9Sstevel@tonic-gate 	}
557c478bd9Sstevel@tonic-gate 	if (boolean(value(VERBOSE)))
56*8d489c7aSmuffin 		(void) printf("\ndialing...");
57*8d489c7aSmuffin 	(void) fflush(stdout);
587c478bd9Sstevel@tonic-gate #ifdef TIOCMSET
597c478bd9Sstevel@tonic-gate 	if (df03) {
607c478bd9Sstevel@tonic-gate 		int st = TIOCM_ST;	/* secondary Transmit flag */
617c478bd9Sstevel@tonic-gate 
62*8d489c7aSmuffin 		(void) ioctl(f, TCGETS, &buf);
637c478bd9Sstevel@tonic-gate 		if (cfgetospeed(&buf) != B1200) { /* must dial at 1200 baud */
647c478bd9Sstevel@tonic-gate 			speed = cfgetospeed(&buf);
65*8d489c7aSmuffin 			(void) cfsetospeed(&buf, B0);
66*8d489c7aSmuffin 			(void) cfsetispeed(&buf, B0);
67*8d489c7aSmuffin 			(void) cfsetospeed(&buf, B1200);
68*8d489c7aSmuffin 			(void) ioctl(f, TCSETSW, &buf);
69*8d489c7aSmuffin 			/* clear ST for 300 baud */
70*8d489c7aSmuffin 			(void) ioctl(f, TIOCMBIC, &st);
717c478bd9Sstevel@tonic-gate 		} else
72*8d489c7aSmuffin 			/* set ST for 1200 baud */
73*8d489c7aSmuffin 			(void) ioctl(f, TIOCMBIS, &st);
747c478bd9Sstevel@tonic-gate 	}
757c478bd9Sstevel@tonic-gate #endif
76*8d489c7aSmuffin 	(void) signal(SIGALRM, (sig_handler_t)timeout);
77*8d489c7aSmuffin 	(void) alarm(5 * strlen(num) + 10);
78*8d489c7aSmuffin 	(void) ioctl(f, TCFLSH, TCOFLUSH);
79*8d489c7aSmuffin 	(void) write(f, "\001", 1);
80*8d489c7aSmuffin 	(void) sleep(1);
81*8d489c7aSmuffin 	(void) write(f, "\002", 1);
82*8d489c7aSmuffin 	(void) write(f, num, strlen(num));
83*8d489c7aSmuffin 	(void) read(f, &c, 1);
847c478bd9Sstevel@tonic-gate #ifdef TIOCMSET
857c478bd9Sstevel@tonic-gate 	if (df03 && speed) {
86*8d489c7aSmuffin 		(void) cfsetospeed(&buf, B0);
87*8d489c7aSmuffin 		(void) cfsetispeed(&buf, B0);
88*8d489c7aSmuffin 		(void) cfsetospeed(&buf, speed);
89*8d489c7aSmuffin 		(void) ioctl(f, TCSETSW, &buf);
907c478bd9Sstevel@tonic-gate 	}
917c478bd9Sstevel@tonic-gate #endif
927c478bd9Sstevel@tonic-gate 	return (c == 'A');
937c478bd9Sstevel@tonic-gate }
947c478bd9Sstevel@tonic-gate 
95*8d489c7aSmuffin void
df_disconnect(void)96*8d489c7aSmuffin df_disconnect(void)
977c478bd9Sstevel@tonic-gate {
987c478bd9Sstevel@tonic-gate 
99*8d489c7aSmuffin 	(void) write(FD, "\001", 1);
100*8d489c7aSmuffin 	(void) sleep(1);
101*8d489c7aSmuffin 	(void) ioctl(FD, TCFLSH, TCOFLUSH);
1027c478bd9Sstevel@tonic-gate }
1037c478bd9Sstevel@tonic-gate 
104*8d489c7aSmuffin void
df_abort(void)105*8d489c7aSmuffin df_abort(void)
1067c478bd9Sstevel@tonic-gate {
1077c478bd9Sstevel@tonic-gate 
1087c478bd9Sstevel@tonic-gate 	df_disconnect();
1097c478bd9Sstevel@tonic-gate }
1107c478bd9Sstevel@tonic-gate 
1117c478bd9Sstevel@tonic-gate 
1127c478bd9Sstevel@tonic-gate static void
timeout(void)113*8d489c7aSmuffin timeout(void)
1147c478bd9Sstevel@tonic-gate {
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate 	siglongjmp(Sjbuf, 1);
1177c478bd9Sstevel@tonic-gate }
118