xref: /illumos-gate/usr/src/cmd/tip/aculib/dn11.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  * Routines for dialing up on DN-11
147c478bd9Sstevel@tonic-gate  */
157c478bd9Sstevel@tonic-gate #include "tip.h"
167c478bd9Sstevel@tonic-gate 
17*8d489c7aSmuffin void	alarmtr(void);
18*8d489c7aSmuffin 
19*8d489c7aSmuffin static sigjmp_buf	jmpbuf;
20*8d489c7aSmuffin static int	child = -1, dn;
217c478bd9Sstevel@tonic-gate 
22*8d489c7aSmuffin int
dn_dialer(char * num,char * acu)23*8d489c7aSmuffin dn_dialer(char *num, char *acu)
247c478bd9Sstevel@tonic-gate {
25*8d489c7aSmuffin 	int lt, nw;
26*8d489c7aSmuffin 	int timelim;
277c478bd9Sstevel@tonic-gate 	struct termios buf;
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate 	if (boolean(value(VERBOSE)))
30*8d489c7aSmuffin 		(void) printf("\nstarting call...");
317c478bd9Sstevel@tonic-gate 	if ((dn = open(acu, 1)) < 0) {
327c478bd9Sstevel@tonic-gate 		if (errno == EBUSY)
33*8d489c7aSmuffin 			(void) printf("line busy...");
347c478bd9Sstevel@tonic-gate 		else
35*8d489c7aSmuffin 			(void) printf("acu open error...");
367c478bd9Sstevel@tonic-gate 		return (0);
377c478bd9Sstevel@tonic-gate 	}
387c478bd9Sstevel@tonic-gate 	if (sigsetjmp(jmpbuf, 1)) {
39*8d489c7aSmuffin 		(void) kill(child, SIGKILL);
40*8d489c7aSmuffin 		(void) close(dn);
417c478bd9Sstevel@tonic-gate 		return (0);
427c478bd9Sstevel@tonic-gate 	}
43*8d489c7aSmuffin 	(void) signal(SIGALRM, (sig_handler_t)alarmtr);
447c478bd9Sstevel@tonic-gate 	timelim = 5 * strlen(num);
45*8d489c7aSmuffin 	(void) alarm(timelim < 30 ? 30 : timelim);
467c478bd9Sstevel@tonic-gate 	if ((child = fork()) == 0) {
477c478bd9Sstevel@tonic-gate 		/*
487c478bd9Sstevel@tonic-gate 		 * ignore this stuff for aborts
497c478bd9Sstevel@tonic-gate 		 */
50*8d489c7aSmuffin 		(void) signal(SIGALRM, SIG_IGN);
51*8d489c7aSmuffin 		(void) signal(SIGINT, SIG_IGN);
52*8d489c7aSmuffin 		(void) signal(SIGQUIT, SIG_IGN);
53*8d489c7aSmuffin 		(void) sleep(2);
547c478bd9Sstevel@tonic-gate 		nw = write(dn, num, lt = strlen(num));
557c478bd9Sstevel@tonic-gate 		exit(nw != lt);
567c478bd9Sstevel@tonic-gate 	}
577c478bd9Sstevel@tonic-gate 	/*
587c478bd9Sstevel@tonic-gate 	 * open line - will return on carrier
597c478bd9Sstevel@tonic-gate 	 */
607c478bd9Sstevel@tonic-gate 	if ((FD = open(DV, 2)) < 0) {
617c478bd9Sstevel@tonic-gate 		if (errno == EIO)
62*8d489c7aSmuffin 			(void) printf("lost carrier...");
637c478bd9Sstevel@tonic-gate 		else
64*8d489c7aSmuffin 			(void) printf("dialup line open failed...");
65*8d489c7aSmuffin 		(void) alarm(0);
66*8d489c7aSmuffin 		(void) kill(child, SIGKILL);
67*8d489c7aSmuffin 		(void) close(dn);
687c478bd9Sstevel@tonic-gate 		return (0);
697c478bd9Sstevel@tonic-gate 	}
70*8d489c7aSmuffin 	(void) alarm(0);
71*8d489c7aSmuffin 	(void) ioctl(dn, TCGETS, &buf);
727c478bd9Sstevel@tonic-gate 	buf.c_cflag |= HUPCL;
73*8d489c7aSmuffin 	(void) ioctl(dn, TCSETSF, &buf);
74*8d489c7aSmuffin 	(void) signal(SIGALRM, SIG_DFL);
757c478bd9Sstevel@tonic-gate 	while ((nw = wait(&lt)) != child && nw != -1)
767c478bd9Sstevel@tonic-gate 		;
77*8d489c7aSmuffin 	(void) fflush(stdout);
78*8d489c7aSmuffin 	(void) close(dn);
797c478bd9Sstevel@tonic-gate 	if (lt != 0) {
80*8d489c7aSmuffin 		(void) close(FD);
817c478bd9Sstevel@tonic-gate 		return (0);
827c478bd9Sstevel@tonic-gate 	}
837c478bd9Sstevel@tonic-gate 	return (1);
847c478bd9Sstevel@tonic-gate }
857c478bd9Sstevel@tonic-gate 
867c478bd9Sstevel@tonic-gate void
alarmtr(void)87*8d489c7aSmuffin alarmtr(void)
887c478bd9Sstevel@tonic-gate {
897c478bd9Sstevel@tonic-gate 
90*8d489c7aSmuffin 	(void) alarm(0);
917c478bd9Sstevel@tonic-gate 	siglongjmp(jmpbuf, 1);
927c478bd9Sstevel@tonic-gate }
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate /*
957c478bd9Sstevel@tonic-gate  * Insurance, for some reason we don't seem to be
967c478bd9Sstevel@tonic-gate  *  hanging up...
977c478bd9Sstevel@tonic-gate  */
98*8d489c7aSmuffin void
dn_disconnect(void)99*8d489c7aSmuffin dn_disconnect(void)
1007c478bd9Sstevel@tonic-gate {
1017c478bd9Sstevel@tonic-gate 	int dtr = TIOCM_DTR;
1027c478bd9Sstevel@tonic-gate 
103*8d489c7aSmuffin 	(void) sleep(2);
1047c478bd9Sstevel@tonic-gate 	if (FD > 0)
105*8d489c7aSmuffin 		(void) ioctl(FD, TIOCMBIC, &dtr);
106*8d489c7aSmuffin 	(void) close(FD);
1077c478bd9Sstevel@tonic-gate }
1087c478bd9Sstevel@tonic-gate 
109*8d489c7aSmuffin void
dn_abort(void)110*8d489c7aSmuffin dn_abort(void)
1117c478bd9Sstevel@tonic-gate {
1127c478bd9Sstevel@tonic-gate 	int dtr = TIOCM_DTR;
1137c478bd9Sstevel@tonic-gate 
114*8d489c7aSmuffin 	(void) sleep(2);
1157c478bd9Sstevel@tonic-gate 	if (child > 0)
116*8d489c7aSmuffin 		(void) kill(child, SIGKILL);
1177c478bd9Sstevel@tonic-gate 	if (dn > 0)
118*8d489c7aSmuffin 		(void) close(dn);
1197c478bd9Sstevel@tonic-gate 	if (FD > 0)
120*8d489c7aSmuffin 		(void) ioctl(FD, TIOCMBIC, &dtr);
121*8d489c7aSmuffin 	(void) close(FD);
1227c478bd9Sstevel@tonic-gate }
123