xref: /illumos-gate/usr/src/cmd/tip/aculib/dn11.c (revision 7c478bd9)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
3*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
4*7c478bd9Sstevel@tonic-gate  */
5*7c478bd9Sstevel@tonic-gate /*
6*7c478bd9Sstevel@tonic-gate  * Copyright (c) 1983 Regents of the University of California.
7*7c478bd9Sstevel@tonic-gate  * All rights reserved. The Berkeley software License Agreement
8*7c478bd9Sstevel@tonic-gate  * specifies the terms and conditions for redistribution.
9*7c478bd9Sstevel@tonic-gate  */
10*7c478bd9Sstevel@tonic-gate #ident	"%Z%%M%	%I%	%E% SMI"	/* from UCB 4.14 6/25/83 */
11*7c478bd9Sstevel@tonic-gate 
12*7c478bd9Sstevel@tonic-gate /*
13*7c478bd9Sstevel@tonic-gate  * Routines for dialing up on DN-11
14*7c478bd9Sstevel@tonic-gate  */
15*7c478bd9Sstevel@tonic-gate #include "tip.h"
16*7c478bd9Sstevel@tonic-gate 
17*7c478bd9Sstevel@tonic-gate int dn_abort();
18*7c478bd9Sstevel@tonic-gate void alarmtr();
19*7c478bd9Sstevel@tonic-gate static sigjmp_buf jmpbuf;
20*7c478bd9Sstevel@tonic-gate static int child = -1, dn;
21*7c478bd9Sstevel@tonic-gate 
22*7c478bd9Sstevel@tonic-gate dn_dialer(num, acu)
23*7c478bd9Sstevel@tonic-gate 	char *num, *acu;
24*7c478bd9Sstevel@tonic-gate {
25*7c478bd9Sstevel@tonic-gate 	extern errno;
26*7c478bd9Sstevel@tonic-gate 	char *p, *q, phone[40];
27*7c478bd9Sstevel@tonic-gate 	int lt, nw, connected = 1;
28*7c478bd9Sstevel@tonic-gate 	register int timelim;
29*7c478bd9Sstevel@tonic-gate 	struct termios buf;
30*7c478bd9Sstevel@tonic-gate 
31*7c478bd9Sstevel@tonic-gate 	if (boolean(value(VERBOSE)))
32*7c478bd9Sstevel@tonic-gate 		printf("\nstarting call...");
33*7c478bd9Sstevel@tonic-gate 	if ((dn = open(acu, 1)) < 0) {
34*7c478bd9Sstevel@tonic-gate 		if (errno == EBUSY)
35*7c478bd9Sstevel@tonic-gate 			printf("line busy...");
36*7c478bd9Sstevel@tonic-gate 		else
37*7c478bd9Sstevel@tonic-gate 			printf("acu open error...");
38*7c478bd9Sstevel@tonic-gate 		return (0);
39*7c478bd9Sstevel@tonic-gate 	}
40*7c478bd9Sstevel@tonic-gate 	if (sigsetjmp(jmpbuf, 1)) {
41*7c478bd9Sstevel@tonic-gate 		kill(child, SIGKILL);
42*7c478bd9Sstevel@tonic-gate 		close(dn);
43*7c478bd9Sstevel@tonic-gate 		return (0);
44*7c478bd9Sstevel@tonic-gate 	}
45*7c478bd9Sstevel@tonic-gate 	signal(SIGALRM, alarmtr);
46*7c478bd9Sstevel@tonic-gate 	timelim = 5 * strlen(num);
47*7c478bd9Sstevel@tonic-gate 	alarm(timelim < 30 ? 30 : timelim);
48*7c478bd9Sstevel@tonic-gate 	if ((child = fork()) == 0) {
49*7c478bd9Sstevel@tonic-gate 		/*
50*7c478bd9Sstevel@tonic-gate 		 * ignore this stuff for aborts
51*7c478bd9Sstevel@tonic-gate 		 */
52*7c478bd9Sstevel@tonic-gate 		signal(SIGALRM, SIG_IGN);
53*7c478bd9Sstevel@tonic-gate 		signal(SIGINT, SIG_IGN);
54*7c478bd9Sstevel@tonic-gate 		signal(SIGQUIT, SIG_IGN);
55*7c478bd9Sstevel@tonic-gate 		sleep(2);
56*7c478bd9Sstevel@tonic-gate 		nw = write(dn, num, lt = strlen(num));
57*7c478bd9Sstevel@tonic-gate 		exit(nw != lt);
58*7c478bd9Sstevel@tonic-gate 	}
59*7c478bd9Sstevel@tonic-gate 	/*
60*7c478bd9Sstevel@tonic-gate 	 * open line - will return on carrier
61*7c478bd9Sstevel@tonic-gate 	 */
62*7c478bd9Sstevel@tonic-gate 	if ((FD = open(DV, 2)) < 0) {
63*7c478bd9Sstevel@tonic-gate 		if (errno == EIO)
64*7c478bd9Sstevel@tonic-gate 			printf("lost carrier...");
65*7c478bd9Sstevel@tonic-gate 		else
66*7c478bd9Sstevel@tonic-gate 			printf("dialup line open failed...");
67*7c478bd9Sstevel@tonic-gate 		alarm(0);
68*7c478bd9Sstevel@tonic-gate 		kill(child, SIGKILL);
69*7c478bd9Sstevel@tonic-gate 		close(dn);
70*7c478bd9Sstevel@tonic-gate 		return (0);
71*7c478bd9Sstevel@tonic-gate 	}
72*7c478bd9Sstevel@tonic-gate 	alarm(0);
73*7c478bd9Sstevel@tonic-gate 	ioctl(dn, TCGETS, &buf);
74*7c478bd9Sstevel@tonic-gate 	buf.c_cflag |= HUPCL;
75*7c478bd9Sstevel@tonic-gate 	ioctl(dn, TCSETSF, &buf);
76*7c478bd9Sstevel@tonic-gate 	signal(SIGALRM, SIG_DFL);
77*7c478bd9Sstevel@tonic-gate 	while ((nw = wait(&lt)) != child && nw != -1)
78*7c478bd9Sstevel@tonic-gate 		;
79*7c478bd9Sstevel@tonic-gate 	fflush(stdout);
80*7c478bd9Sstevel@tonic-gate 	close(dn);
81*7c478bd9Sstevel@tonic-gate 	if (lt != 0) {
82*7c478bd9Sstevel@tonic-gate 		close(FD);
83*7c478bd9Sstevel@tonic-gate 		return (0);
84*7c478bd9Sstevel@tonic-gate 	}
85*7c478bd9Sstevel@tonic-gate 	return (1);
86*7c478bd9Sstevel@tonic-gate }
87*7c478bd9Sstevel@tonic-gate 
88*7c478bd9Sstevel@tonic-gate void
89*7c478bd9Sstevel@tonic-gate alarmtr()
90*7c478bd9Sstevel@tonic-gate {
91*7c478bd9Sstevel@tonic-gate 
92*7c478bd9Sstevel@tonic-gate 	alarm(0);
93*7c478bd9Sstevel@tonic-gate 	siglongjmp(jmpbuf, 1);
94*7c478bd9Sstevel@tonic-gate }
95*7c478bd9Sstevel@tonic-gate 
96*7c478bd9Sstevel@tonic-gate /*
97*7c478bd9Sstevel@tonic-gate  * Insurance, for some reason we don't seem to be
98*7c478bd9Sstevel@tonic-gate  *  hanging up...
99*7c478bd9Sstevel@tonic-gate  */
100*7c478bd9Sstevel@tonic-gate dn_disconnect()
101*7c478bd9Sstevel@tonic-gate {
102*7c478bd9Sstevel@tonic-gate 	int dtr = TIOCM_DTR;
103*7c478bd9Sstevel@tonic-gate 
104*7c478bd9Sstevel@tonic-gate 	sleep(2);
105*7c478bd9Sstevel@tonic-gate 	if (FD > 0)
106*7c478bd9Sstevel@tonic-gate 		ioctl(FD, TIOCMBIC, &dtr);
107*7c478bd9Sstevel@tonic-gate 	close(FD);
108*7c478bd9Sstevel@tonic-gate }
109*7c478bd9Sstevel@tonic-gate 
110*7c478bd9Sstevel@tonic-gate dn_abort()
111*7c478bd9Sstevel@tonic-gate {
112*7c478bd9Sstevel@tonic-gate 	int dtr = TIOCM_DTR;
113*7c478bd9Sstevel@tonic-gate 
114*7c478bd9Sstevel@tonic-gate 	sleep(2);
115*7c478bd9Sstevel@tonic-gate 	if (child > 0)
116*7c478bd9Sstevel@tonic-gate 		kill(child, SIGKILL);
117*7c478bd9Sstevel@tonic-gate 	if (dn > 0)
118*7c478bd9Sstevel@tonic-gate 		close(dn);
119*7c478bd9Sstevel@tonic-gate 	if (FD > 0)
120*7c478bd9Sstevel@tonic-gate 		ioctl(FD, TIOCMBIC, &dtr);
121*7c478bd9Sstevel@tonic-gate 	close(FD);
122*7c478bd9Sstevel@tonic-gate }
123