1*ffe34450Schristos /* $NetBSD: df.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[] = "@(#)df.c 8.1 (Berkeley) 6/6/93";
3639801cccSjtc #endif
37*ffe34450Schristos __RCSID("$NetBSD: df.c,v 1.10 2006/12/14 17:09:43 christos Exp $");
3861f28255Scgd #endif /* not lint */
3961f28255Scgd
4061f28255Scgd /*
4161f28255Scgd * Dial the DF02-AC or DF03-AC
4261f28255Scgd */
4361f28255Scgd
4461f28255Scgd #include "tip.h"
4561f28255Scgd
4661f28255Scgd static jmp_buf Sjbuf;
4761f28255Scgd
4858c2151fSperry static int df_dialer(char *, char *, int);
4958c2151fSperry static void timeout(int);
50e37283e1Slukem
51e37283e1Slukem int
df02_dialer(char * num,char * acu)5258c2151fSperry df02_dialer(char *num, char *acu)
5361f28255Scgd {
5461f28255Scgd
5561f28255Scgd return (df_dialer(num, acu, 0));
5661f28255Scgd }
5761f28255Scgd
58e37283e1Slukem int
df03_dialer(char * num,char * acu)5958c2151fSperry df03_dialer(char *num, char *acu)
6061f28255Scgd {
6161f28255Scgd
6261f28255Scgd return (df_dialer(num, acu, 1));
6361f28255Scgd }
6461f28255Scgd
65e37283e1Slukem static int
66*ffe34450Schristos /*ARGSUSED*/
df_dialer(char * num,char * acu __unused,int df03)67*ffe34450Schristos df_dialer(char *num, char *acu __unused, int df03)
6861f28255Scgd {
69e37283e1Slukem int f = FD;
70258108ceSpk struct termios cntrl;
71*ffe34450Schristos speed_t volatile spd;
72239d1ed1Schristos char c;
7361f28255Scgd
74239d1ed1Schristos spd = 0;
75239d1ed1Schristos c = '\0';
76*ffe34450Schristos (void)tcgetattr(f, &cntrl);
77258108ceSpk cntrl.c_cflag |= HUPCL;
78*ffe34450Schristos (void)tcsetattr(f, TCSANOW, &cntrl);
7961f28255Scgd if (setjmp(Sjbuf)) {
80*ffe34450Schristos (void)printf("connection timed out\r\n");
8161f28255Scgd df_disconnect();
8261f28255Scgd return (0);
8361f28255Scgd }
8461f28255Scgd if (boolean(value(VERBOSE)))
85*ffe34450Schristos (void)printf("\ndialing...");
86*ffe34450Schristos (void)fflush(stdout);
8761f28255Scgd #ifdef TIOCMSET
8861f28255Scgd if (df03) {
8961f28255Scgd int st = TIOCM_ST; /* secondary Transmit flag */
9061f28255Scgd
91*ffe34450Schristos (void)tcgetattr(f, &cntrl);
924f6045fcSchristos spd = cfgetospeed(&cntrl);
934f6045fcSchristos if (spd != B1200) { /* must dial at 1200 baud */
94*ffe34450Schristos (void)cfsetospeed(&cntrl, B1200);
95*ffe34450Schristos (void)cfsetispeed(&cntrl, B1200);
96*ffe34450Schristos (void)tcsetattr(f, TCSAFLUSH, &cntrl);
97*ffe34450Schristos (void)ioctl(f, TIOCMBIC, &st); /* clear ST for 300 baud */
9861f28255Scgd } else
99*ffe34450Schristos (void)ioctl(f, TIOCMBIS, &st); /* set ST for 1200 baud */
10061f28255Scgd }
10161f28255Scgd #endif
102*ffe34450Schristos (void)signal(SIGALRM, timeout);
103*ffe34450Schristos (void)alarm(5 * strlen(num) + 10);
104*ffe34450Schristos (void)tcflush(f, TCIOFLUSH);
105*ffe34450Schristos (void)write(f, "\001", 1);
106*ffe34450Schristos (void)sleep(1);
107*ffe34450Schristos (void)write(f, "\002", 1);
108*ffe34450Schristos (void)write(f, num, strlen(num));
109*ffe34450Schristos (void)read(f, &c, 1);
11061f28255Scgd #ifdef TIOCMSET
1114f6045fcSchristos if (df03 && spd != B1200) {
112*ffe34450Schristos (void)cfsetospeed(&cntrl, spd);
113*ffe34450Schristos (void)cfsetispeed(&cntrl, spd);
114*ffe34450Schristos (void)tcsetattr(f, TCSAFLUSH, &cntrl);
11561f28255Scgd }
11661f28255Scgd #endif
11761f28255Scgd return (c == 'A');
11861f28255Scgd }
11961f28255Scgd
120e37283e1Slukem void
df_disconnect(void)12158c2151fSperry df_disconnect(void)
12261f28255Scgd {
12361f28255Scgd
124*ffe34450Schristos (void)write(FD, "\001", 1);
125*ffe34450Schristos (void)sleep(1);
126*ffe34450Schristos (void)tcflush(FD, TCIOFLUSH);
12761f28255Scgd }
12861f28255Scgd
12961f28255Scgd
130e37283e1Slukem void
df_abort(void)13158c2151fSperry df_abort(void)
13261f28255Scgd {
13361f28255Scgd
13461f28255Scgd df_disconnect();
13561f28255Scgd }
13661f28255Scgd
13761f28255Scgd
13861f28255Scgd static void
139*ffe34450Schristos /*ARGSUSED*/
timeout(int dummy __unused)140*ffe34450Schristos timeout(int dummy __unused)
14161f28255Scgd {
14261f28255Scgd
14361f28255Scgd longjmp(Sjbuf, 1);
14461f28255Scgd }
145