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