1*ffe34450Schristos /* $NetBSD: dn11.c,v 1.10 2006/12/14 17:09:43 christos Exp $ */
239801cccSjtc
361f28255Scgd /*
439801cccSjtc * Copyright (c) 1983, 1993
539801cccSjtc * The Regents of the University of California. All rights reserved.
661f28255Scgd *
761f28255Scgd * Redistribution and use in source and binary forms, with or without
861f28255Scgd * modification, are permitted provided that the following conditions
961f28255Scgd * are met:
1061f28255Scgd * 1. Redistributions of source code must retain the above copyright
1161f28255Scgd * notice, this list of conditions and the following disclaimer.
1261f28255Scgd * 2. Redistributions in binary form must reproduce the above copyright
1361f28255Scgd * notice, this list of conditions and the following disclaimer in the
1461f28255Scgd * documentation and/or other materials provided with the distribution.
1589aaa1bbSagc * 3. Neither the name of the University nor the names of its contributors
1661f28255Scgd * may be used to endorse or promote products derived from this software
1761f28255Scgd * without specific prior written permission.
1861f28255Scgd *
1961f28255Scgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2061f28255Scgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2161f28255Scgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2261f28255Scgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2361f28255Scgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2461f28255Scgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2561f28255Scgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2661f28255Scgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2761f28255Scgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2861f28255Scgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2961f28255Scgd * SUCH DAMAGE.
3061f28255Scgd */
3161f28255Scgd
32e37283e1Slukem #include <sys/cdefs.h>
3361f28255Scgd #ifndef lint
3439801cccSjtc #if 0
3539801cccSjtc static char sccsid[] = "@(#)dn11.c 8.1 (Berkeley) 6/6/93";
3639801cccSjtc #endif
37*ffe34450Schristos __RCSID("$NetBSD: dn11.c,v 1.10 2006/12/14 17:09:43 christos Exp $");
3861f28255Scgd #endif /* not lint */
3961f28255Scgd
4061f28255Scgd /*
4161f28255Scgd * Routines for dialing up on DN-11
4261f28255Scgd */
4361f28255Scgd #include "tip.h"
4461f28255Scgd
4561f28255Scgd static jmp_buf jmpbuf;
4661f28255Scgd static int child = -1, dn;
4761f28255Scgd
4858c2151fSperry static void alarmtr(int);
49e37283e1Slukem
50e37283e1Slukem int
dn_dialer(char * num,char * acu)5158c2151fSperry dn_dialer(char *num, char *acu)
5261f28255Scgd {
53e37283e1Slukem int lt, nw;
54e37283e1Slukem int timelim;
55258108ceSpk struct termios cntrl;
5661f28255Scgd
5761f28255Scgd if (boolean(value(VERBOSE)))
58*ffe34450Schristos (void)printf("\nstarting call...");
597f507fd2Suebayasi if ((dn = open(acu, O_WRONLY)) < 0) {
6061f28255Scgd if (errno == EBUSY)
61*ffe34450Schristos (void)printf("line busy...");
6261f28255Scgd else
63*ffe34450Schristos (void)printf("acu open error...");
6461f28255Scgd return (0);
6561f28255Scgd }
6661f28255Scgd if (setjmp(jmpbuf)) {
67*ffe34450Schristos (void)kill(child, SIGKILL);
68*ffe34450Schristos (void)close(dn);
6961f28255Scgd return (0);
7061f28255Scgd }
71*ffe34450Schristos (void)signal(SIGALRM, alarmtr);
7261f28255Scgd timelim = 5 * strlen(num);
73*ffe34450Schristos (void)alarm((unsigned)(timelim < 30 ? 30 : timelim));
7461f28255Scgd if ((child = fork()) == 0) {
7561f28255Scgd /*
7661f28255Scgd * ignore this stuff for aborts
7761f28255Scgd */
78*ffe34450Schristos (void)signal(SIGALRM, SIG_IGN);
79*ffe34450Schristos (void)signal(SIGINT, SIG_IGN);
80*ffe34450Schristos (void)signal(SIGQUIT, SIG_IGN);
81*ffe34450Schristos (void)sleep(2);
82*ffe34450Schristos nw = write(dn, num, (size_t)(lt = strlen(num)));
8361f28255Scgd exit(nw != lt);
8461f28255Scgd }
8561f28255Scgd /*
8661f28255Scgd * open line - will return on carrier
8761f28255Scgd */
887f507fd2Suebayasi if ((FD = open(DV, O_RDWR)) < 0) {
8961f28255Scgd if (errno == EIO)
90*ffe34450Schristos (void)printf("lost carrier...");
9161f28255Scgd else
92*ffe34450Schristos (void)printf("dialup line open failed...");
93*ffe34450Schristos (void)alarm(0);
94*ffe34450Schristos (void)kill(child, SIGKILL);
95*ffe34450Schristos (void)close(dn);
9661f28255Scgd return (0);
9761f28255Scgd }
98*ffe34450Schristos (void)alarm(0);
99*ffe34450Schristos (void)tcgetattr(dn, &cntrl);
100258108ceSpk cntrl.c_cflag |= HUPCL;
101*ffe34450Schristos (void)tcsetattr(dn, TCSANOW, &cntrl);
102*ffe34450Schristos (void)signal(SIGALRM, SIG_DFL);
10361f28255Scgd while ((nw = wait(<)) != child && nw != -1)
10461f28255Scgd ;
105*ffe34450Schristos (void)fflush(stdout);
106*ffe34450Schristos (void)close(dn);
10761f28255Scgd if (lt != 0) {
108*ffe34450Schristos (void)close(FD);
10961f28255Scgd return (0);
11061f28255Scgd }
11161f28255Scgd return (1);
11261f28255Scgd }
11361f28255Scgd
114e37283e1Slukem static void
115*ffe34450Schristos /*ARGSUSED*/
alarmtr(int dummy __unused)116*ffe34450Schristos alarmtr(int dummy __unused)
11761f28255Scgd {
11897eafd50Smrg
119*ffe34450Schristos (void)alarm(0);
12061f28255Scgd longjmp(jmpbuf, 1);
12161f28255Scgd }
12261f28255Scgd
12361f28255Scgd /*
12461f28255Scgd * Insurance, for some reason we don't seem to be
12561f28255Scgd * hanging up...
12661f28255Scgd */
127e37283e1Slukem void
dn_disconnect(void)12858c2151fSperry dn_disconnect(void)
12961f28255Scgd {
13061f28255Scgd
131*ffe34450Schristos (void)sleep(2);
13261f28255Scgd if (FD > 0)
133*ffe34450Schristos (void)ioctl(FD, TIOCCDTR, 0);
134*ffe34450Schristos (void)close(FD);
13561f28255Scgd }
13661f28255Scgd
137e37283e1Slukem void
dn_abort(void)13858c2151fSperry dn_abort(void)
13961f28255Scgd {
14061f28255Scgd
141*ffe34450Schristos (void)sleep(2);
14261f28255Scgd if (child > 0)
143*ffe34450Schristos (void)kill(child, SIGKILL);
14461f28255Scgd if (dn > 0)
145*ffe34450Schristos (void)close(dn);
14661f28255Scgd if (FD > 0)
147*ffe34450Schristos (void)ioctl(FD, TIOCCDTR, 0);
148*ffe34450Schristos (void)close(FD);
14961f28255Scgd }
150