summaryrefslogtreecommitdiffstats
path: root/usr.bin/tip/libacu
diff options
context:
space:
mode:
authormarkm <markm@FreeBSD.org>2001-12-20 14:25:46 +0000
committermarkm <markm@FreeBSD.org>2001-12-20 14:25:46 +0000
commitea00e48044b4c63ff0b00ff8afa84d9a1ac54155 (patch)
tree735e71ebf880fba90adb57f05d2821e1c63de2df /usr.bin/tip/libacu
parent3551cbb12e15475b2d7b2e33119ddd9e4f857531 (diff)
downloadFreeBSD-src-ea00e48044b4c63ff0b00ff8afa84d9a1ac54155.zip
FreeBSD-src-ea00e48044b4c63ff0b00ff8afa84d9a1ac54155.tar.gz
Fix merge conflicts, and because this still has a zillion warnings,
protect the build with a WARNS=2. Fix the build.
Diffstat (limited to 'usr.bin/tip/libacu')
-rw-r--r--usr.bin/tip/libacu/Makefile12
-rw-r--r--usr.bin/tip/libacu/acucommon.c196
-rw-r--r--usr.bin/tip/libacu/acucommon.h6
-rw-r--r--usr.bin/tip/libacu/biz22.c38
-rw-r--r--usr.bin/tip/libacu/biz31.c28
-rw-r--r--usr.bin/tip/libacu/courier.c85
-rw-r--r--usr.bin/tip/libacu/df.c45
-rw-r--r--usr.bin/tip/libacu/dn11.c39
-rw-r--r--usr.bin/tip/libacu/hayes.c78
-rw-r--r--usr.bin/tip/libacu/multitech.c404
-rw-r--r--usr.bin/tip/libacu/t3000.c83
-rw-r--r--usr.bin/tip/libacu/tod.c107
-rw-r--r--usr.bin/tip/libacu/tod.h9
-rw-r--r--usr.bin/tip/libacu/unidialer.c806
-rw-r--r--usr.bin/tip/libacu/v3451.c62
-rw-r--r--usr.bin/tip/libacu/v831.c81
-rw-r--r--usr.bin/tip/libacu/ventel.c58
17 files changed, 355 insertions, 1782 deletions
diff --git a/usr.bin/tip/libacu/Makefile b/usr.bin/tip/libacu/Makefile
deleted file mode 100644
index 77a95cd..0000000
--- a/usr.bin/tip/libacu/Makefile
+++ /dev/null
@@ -1,12 +0,0 @@
-LIB= acu
-CFLAGS+= -I${.CURDIR}/../tip
-SRCS= acucommon.c biz22.c courier.c df.c dn11.c hayes.c \
- multitech.c t3000.c tod.c unidialer.c v3451.c v831.c ventel.c
-NOPROFILE= yes
-
-$(OBJS): ${.CURDIR}/../tip/tipconf.h
-
-install:
- @echo -n
-
-.include <bsd.lib.mk>
diff --git a/usr.bin/tip/libacu/acucommon.c b/usr.bin/tip/libacu/acucommon.c
deleted file mode 100644
index efb644f..0000000
--- a/usr.bin/tip/libacu/acucommon.c
+++ /dev/null
@@ -1,196 +0,0 @@
-/*
- * Copyright (c) 1986, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)acucommon.c 8.1 (Berkeley) 6/6/93";
-#endif
-static const char rcsid[] =
- "$FreeBSD$";
-#endif /* not lint */
-
-/*
- * Routines for calling up on a Courier modem.
- * Derived from Hayes driver.
- */
-#include "tipconf.h"
-#include "tip.h"
-
-#include <err.h>
-
-#if HAVE_SELECT
-#include <sys/types.h>
-#include <sys/times.h>
-#include <unistd.h>
-
-void acu_nap (unsigned int how_long)
-{
- struct timeval t;
- t.tv_usec = (how_long % 1000) * 1000;
- t.tv_sec = how_long / 1000;
- (void) select (0, NULL, NULL, NULL, &t);
-}
-
-#elif HAVE_USLEEP
-void acu_nap (unsigned int how_long)
-{
- (void) usleep (how_long * 1000);
-}
-
-#else
-
-/*
- * Code stolen from /usr/src/lib/libc/gen/sleep.c
- */
-#define mask(s) (1<<((s)-1))
-#define setvec(vec, a) \
- vec.sv_handler = a; vec.sv_mask = vec.sv_onstack = 0
-
-static int ringring;
-
-static void acunap_napx()
-{
- ringring = 1;
-}
-
-void acu_nap (unsigned int how_long)
-{
- int omask;
- struct itimerval itv, oitv;
- register struct itimerval *itp = &itv;
- struct sigvec vec, ovec;
-
- timerclear(&itp->it_interval);
- timerclear(&itp->it_value);
- if (setitimer(ITIMER_REAL, itp, &oitv) < 0)
- return;
- setvec(ovec, SIG_DFL);
- omask = sigblock(mask(SIGALRM));
- itp->it_value.tv_sec = how_long / 1000;
- itp->it_value.tv_usec = ((how_long % 1000) * 1000);
- setvec(vec, acunap_napx);
- ringring = 0;
- (void) sigvec(SIGALRM, &vec, &ovec);
- (void) setitimer(ITIMER_REAL, itp, (struct itimerval *)0);
- while (!ringring)
- sigpause(omask &~ mask(SIGALRM));
- (void) sigvec(SIGALRM, &ovec, (struct sigvec *)0);
- (void) setitimer(ITIMER_REAL, &oitv, (struct itimerval *)0);
- (void) sigsetmask(omask);
-}
-
-#endif /* HAVE_USLEEP */
-
-void acu_hw_flow_control (hw_flow_control)
-{
-#if HAVE_TERMIOS
- struct termios t;
- if (tcgetattr (FD, &t) == 0) {
- if (hw_flow_control)
- t.c_cflag |= CRTSCTS;
- else
- t.c_cflag &= ~CRTSCTS;
- tcsetattr (FD, TCSANOW, &t);
- }
-#endif /* HAVE_TERMIOS */
-}
-
-int acu_flush ()
-{
-#ifdef TIOCFLUSH
- int flags = 0;
- return (ioctl (FD, TIOCFLUSH, &flags) == 0); /* flush any clutter */
-#elif !HAVE_TERMIOS
- struct sgttyb buf;
- return (ioctl (FD, TIOCGETP, &buf) == 0 && ioctl (FD, TIOCSETP, &buf) == 0);
-#endif
-}
-
-int acu_getspeed ()
-{
-#if HAVE_TERMIOS
- struct termios term;
- tcgetattr (FD, &term);
- return (term.c_ospeed);
-#else /* HAVE_TERMIOS */
- struct sgttyb buf;
- ioctl (FD, TIOCGETP, &buf);
- return (buf.sg_ospeed);
-#endif
-}
-
-int acu_setspeed (int speed)
-{
- int rc = 0;
-#if HAVE_TERMIOS
- struct termios term;
- if (tcgetattr (FD, &term) == 0) {
-#ifndef _POSIX_SOURCE
- cfsetspeed (&term, speed);
-#else
- cfsetispeed (&term, speed);
- cfsetospeed (&term, speed);
-#endif
- if (tcsetattr (FD, TCSANOW, &term) == 0)
- ++rc;
- }
-#else /* HAVE TERMIOS */
- struct sgttyb sb;
- if (ioctl(FD, TIOCGETP, &sb) < 0) {
- warn("TIOCGETP");
- }
- else {
- sb.sg_ispeed = sb.sg_ospeed = speed;
- if (ioctl(FD, TIOCSETP, &sb) < 0) {
- warn("TIOCSETP");
- }
- else
- ++rc;
- }
-#endif /* HAVE TERMIOS */
- return (rc);
-}
-
-void acu_hupcl ()
-{
-#if HAVE_TERMIOS
- struct termios term;
- tcgetattr (FD, &term);
- term.c_cflag |= HUPCL;
- tcsetattr (FD, TCSANOW, &term);
-#elif defined(TIOCHPCL)
- ioctl(FD, TIOCHPCL, 0);
-#endif
-}
-
-/* end of acucommon.c */
diff --git a/usr.bin/tip/libacu/acucommon.h b/usr.bin/tip/libacu/acucommon.h
deleted file mode 100644
index 50d28cd..0000000
--- a/usr.bin/tip/libacu/acucommon.h
+++ /dev/null
@@ -1,6 +0,0 @@
-void acu_nap (unsigned int how_long);
-void acu_hw_flow_control (int hw_flow_control);
-int acu_flush ();
-void acu_hupcl ();
-int acu_setspeed (int speed);
-/* end of acucommon.h */
diff --git a/usr.bin/tip/libacu/biz22.c b/usr.bin/tip/libacu/biz22.c
index 63fb11c..2794ba7 100644
--- a/usr.bin/tip/libacu/biz22.c
+++ b/usr.bin/tip/libacu/biz22.c
@@ -1,3 +1,6 @@
+/* $OpenBSD: biz22.c,v 1.7 2001/10/24 18:38:58 millert Exp $ */
+/* $NetBSD: biz22.c,v 1.6 1997/02/11 09:24:11 mrg Exp $ */
+
/*
* Copyright (c) 1983, 1993
* The Regents of the University of California. All rights reserved.
@@ -31,11 +34,16 @@
* SUCH DAMAGE.
*/
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
#ifndef lint
+#if 0
static char sccsid[] = "@(#)biz22.c 8.1 (Berkeley) 6/6/93";
+static char rcsid[] = "$OpenBSD: biz22.c,v 1.7 2001/10/24 18:38:58 millert Exp $";
+#endif
#endif /* not lint */
-#include "tipconf.h"
#include "tip.h"
#define DISCONNECT_CMD "\20\04" /* disconnection string */
@@ -44,6 +52,9 @@ static void sigALRM();
static int timeout = 0;
static jmp_buf timeoutbuf;
+static int cmd(), detect();
+void biz22_disconnect();
+
/*
* Dial up on a BIZCOMP Model 1022 with either
* tone dialing (mod = "V")
@@ -53,9 +64,8 @@ static int
biz_dialer(num, mod)
char *num, *mod;
{
- register int connected = 0;
+ int connected = 0;
char cbuf[40];
- static int cmd(), detect();
if (boolean(value(VERBOSE)))
printf("\nstarting call...");
@@ -67,15 +77,13 @@ biz_dialer(num, mod)
printf("can't initialize bizcomp...");
return (0);
}
- strcpy(cbuf, "\02.\r");
+ (void)strcpy(cbuf, "\02.\r");
cbuf[1] = *mod;
if (cmd(cbuf)) {
printf("can't set dialing mode...");
return (0);
}
- strcpy(cbuf, "\02D");
- strcat(cbuf, num);
- strcat(cbuf, "\r");
+ (void)snprintf(cbuf, sizeof(cbuf), "\02D%s\r", num);
write(FD, cbuf, strlen(cbuf));
if (!detect("7\r")) {
printf("can't get dial tone...");
@@ -89,11 +97,11 @@ biz_dialer(num, mod)
* 1 \r success
*/
connected = detect("1\r");
-#if ACULOG
+#ifdef ACULOG
if (timeout) {
char line[80];
- sprintf(line, "%d second dial timeout",
+ (void)sprintf(line, "%ld second dial timeout",
number(value(DIALTIMEOUT)));
logent(value(HOST), num, "biz1022", line);
}
@@ -103,6 +111,7 @@ biz_dialer(num, mod)
return (connected);
}
+int
biz22w_dialer(num, acu)
char *num, *acu;
{
@@ -110,6 +119,7 @@ biz22w_dialer(num, acu)
return (biz_dialer(num, "W"));
}
+int
biz22f_dialer(num, acu)
char *num, *acu;
{
@@ -117,15 +127,15 @@ biz22f_dialer(num, acu)
return (biz_dialer(num, "V"));
}
+void
biz22_disconnect()
{
- int rw = 2;
-
write(FD, DISCONNECT_CMD, 4);
sleep(2);
- ioctl(FD, TIOCFLUSH, &rw);
+ tcflush(FD, TCIOFLUSH);
}
+void
biz22_abort()
{
@@ -142,7 +152,7 @@ sigALRM()
static int
cmd(s)
- register char *s;
+ char *s;
{
sig_t f;
char c;
@@ -164,7 +174,7 @@ cmd(s)
static int
detect(s)
- register char *s;
+ char *s;
{
sig_t f;
char c;
diff --git a/usr.bin/tip/libacu/biz31.c b/usr.bin/tip/libacu/biz31.c
index 9553a6d..44b8a62 100644
--- a/usr.bin/tip/libacu/biz31.c
+++ b/usr.bin/tip/libacu/biz31.c
@@ -1,3 +1,6 @@
+/* $OpenBSD: biz31.c,v 1.6 2001/10/24 18:38:58 millert Exp $ */
+/* $NetBSD: biz31.c,v 1.5 1997/02/11 09:24:14 mrg Exp $ */
+
/*
* Copyright (c) 1983, 1993
* The Regents of the University of California. All rights reserved.
@@ -31,11 +34,16 @@
* SUCH DAMAGE.
*/
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
#ifndef lint
+#if 0
static char sccsid[] = "@(#)biz31.c 8.1 (Berkeley) 6/6/93";
+static char rcsid[] = "$OpenBSD: biz31.c,v 1.6 2001/10/24 18:38:58 millert Exp $";
+#endif
#endif /* not lint */
-#include "tipconf.h"
#include "tip.h"
#define MAXRETRY 3 /* sync up retry count */
@@ -54,7 +62,7 @@ static int
biz_dialer(num, mod)
char *num, *mod;
{
- register int connected = 0;
+ int connected = 0;
if (!bizsync(FD)) {
logent(value(HOST), "", "biz", "out of sync");
@@ -82,11 +90,11 @@ biz_dialer(num, mod)
* ` CONNECTION\r\n^G' success
*/
connected = detect(" ");
-#if ACULOG
+#ifdef ACULOG
if (timeout) {
char line[80];
- sprintf(line, "%d second dial timeout",
+ (void)sprintf(line, "%ld second dial timeout",
number(value(DIALTIMEOUT)));
logent(value(HOST), num, "biz", line);
}
@@ -119,7 +127,7 @@ biz31_disconnect()
write(FD, DISCONNECT_CMD, 4);
sleep(2);
- ioctl(FD, TIOCFLUSH);
+ tcflush(FD, TCIOFLUSH);
}
biz31_abort()
@@ -130,7 +138,7 @@ biz31_abort()
static int
echo(s)
- register char *s;
+ char *s;
{
char c;
@@ -162,7 +170,7 @@ sigALRM()
static int
detect(s)
- register char *s;
+ char *s;
{
sig_t f;
char c;
@@ -187,7 +195,7 @@ detect(s)
static int
flush(s)
- register char *s;
+ char *s;
{
sig_t f;
char c;
@@ -222,12 +230,12 @@ bizsync(fd)
# define chars(b) (b)
# define IOCTL FIONREAD
#endif
- register int already = 0;
+ int already = 0;
char buf[10];
retry:
if (ioctl(fd, IOCTL, (caddr_t)&b) >= 0 && chars(b) > 0)
- ioctl(fd, TIOCFLUSH);
+ tcflush(FD, TCIOFLUSH);
write(fd, "\rp>\r", 4);
sleep(1);
if (ioctl(fd, IOCTL, (caddr_t)&b) >= 0) {
diff --git a/usr.bin/tip/libacu/courier.c b/usr.bin/tip/libacu/courier.c
index df19573..67c7529 100644
--- a/usr.bin/tip/libacu/courier.c
+++ b/usr.bin/tip/libacu/courier.c
@@ -1,3 +1,6 @@
+/* $OpenBSD: courier.c,v 1.9 2001/10/24 18:38:58 millert Exp $ */
+/* $NetBSD: courier.c,v 1.7 1997/02/11 09:24:16 mrg Exp $ */
+
/*
* Copyright (c) 1986, 1993
* The Regents of the University of California. All rights reserved.
@@ -31,20 +34,23 @@
* SUCH DAMAGE.
*/
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
#ifndef lint
-static const char rcsid[] =
- "$FreeBSD$";
+#if 0
+static char sccsid[] = "@(#)courier.c 8.1 (Berkeley) 6/6/93";
+static char rcsid[] = "$OpenBSD: courier.c,v 1.9 2001/10/24 18:38:58 millert Exp $";
#endif
+#endif /* not lint */
/*
* Routines for calling up on a Courier modem.
* Derived from Hayes driver.
*/
-#include "tipconf.h"
#include "tip.h"
-#include "acucommon.h"
+#include <sys/ioctl.h>
#include <stdio.h>
-#include <unistd.h>
#define MAXRETRY 5
@@ -52,30 +58,35 @@ static void sigALRM();
static int timeout = 0;
static int connected = 0;
static jmp_buf timeoutbuf, intbuf;
-static int coursync();
+static int coursync(), cour_connect(), cour_swallow();
+void cour_nap();
+
+void cour_disconnect __P((void));
+int
cour_dialer(num, acu)
- register char *num;
+ char *num;
char *acu;
{
- register char *cp;
-#if ACULOG
+ char *cp;
+#ifdef ACULOG
char line[80];
#endif
- static int cour_connect(), cour_swallow();
+ struct termios cntrl;
if (boolean(value(VERBOSE)))
printf("Using \"%s\"\n", acu);
- acu_hupcl ();
-
+ tcgetattr(FD, &cntrl);
+ cntrl.c_cflag |= HUPCL;
+ tcsetattr(FD, TCSAFLUSH, &cntrl);
/*
* Get in synch.
*/
if (!coursync()) {
badsynch:
printf("can't synchronize with courier\n");
-#if ACULOG
+#ifdef ACULOG
logent(value(HOST), num, "courier", "can't synch up");
#endif
return (0);
@@ -86,7 +97,7 @@ badsynch:
if (boolean(value(VERBOSE)))
cour_verbose_read();
#endif
- ioctl(FD, TIOCFLUSH, 0); /* flush any clutter */
+ tcflush(FD, TCIOFLUSH);
cour_write(FD, "AT C1 E0 H0 Q0 X6 V1\r", 21);
if (!cour_swallow("\r\nOK\r\n"))
goto badsynch;
@@ -98,9 +109,9 @@ badsynch:
cour_write(FD, num, strlen(num));
cour_write(FD, "\r", 1);
connected = cour_connect();
-#if ACULOG
+#ifdef ACULOG
if (timeout) {
- sprintf(line, "%d second dial timeout",
+ (void)sprintf(line, "%ld second dial timeout",
number(value(DIALTIMEOUT)));
logent(value(HOST), num, "cour", line);
}
@@ -110,6 +121,7 @@ badsynch:
return (connected);
}
+void
cour_disconnect()
{
/* first hang up the modem*/
@@ -120,6 +132,7 @@ cour_disconnect()
close(FD);
}
+void
cour_abort()
{
cour_write(FD, "\r", 1); /* send anything to abort the call */
@@ -136,8 +149,8 @@ sigALRM()
static int
cour_swallow(match)
- register char *match;
- {
+ char *match;
+{
sig_t f;
char c;
@@ -224,8 +237,12 @@ again:
for (bm = baud_msg ; bm->msg ; bm++)
if (strcmp(bm->msg,
dialer_buf+sizeof("CONNECT")-1) == 0) {
- if (!acu_setspeed(bm->baud))
- goto error;
+ struct termios cntrl;
+
+ tcgetattr(FD, &cntrl);
+ cfsetospeed(&cntrl, bm->baud);
+ cfsetispeed(&cntrl, bm->baud);
+ tcsetattr(FD, TCSAFLUSH, &cntrl);
signal(SIGALRM, f);
#ifdef DEBUG
if (boolean(value(VERBOSE)))
@@ -241,9 +258,7 @@ again:
putchar(c);
#endif
}
-error1:
printf("%s\r\n", dialer_buf);
-error:
signal(SIGALRM, f);
return (0);
}
@@ -260,7 +275,7 @@ coursync()
char buf[40];
while (already++ < MAXRETRY) {
- ioctl(FD, TIOCFLUSH, 0); /* flush any clutter */
+ tcflush(FD, TCIOFLUSH);
cour_write(FD, "\rAT Z\r", 6); /* reset modem */
bzero(buf, sizeof(buf));
sleep(1);
@@ -271,8 +286,8 @@ coursync()
buf[len] = '\0';
printf("coursync: (\"%s\")\n\r", buf);
#endif
- if (index(buf, '0') ||
- (index(buf, 'O') && index(buf, 'K')))
+ if (strchr(buf, '0') ||
+ (strchr(buf, 'O') && strchr(buf, 'K')))
return(1);
}
/*
@@ -294,6 +309,7 @@ coursync()
return (0);
}
+static void
cour_write(fd, cp, n)
int fd;
char *cp;
@@ -301,13 +317,13 @@ int n;
{
#ifdef notdef
if (boolean(value(VERBOSE)))
- write(STDOUT_FILENO, cp, n);
+ write(1, cp, n);
#endif
- acu_flush ();
+ tcdrain(fd);
cour_nap();
for ( ; n-- ; cp++) {
write(fd, cp, 1);
- acu_flush ();
+ tcdrain(fd);
cour_nap();
}
}
@@ -324,13 +340,18 @@ cour_verbose_read()
return;
if (read(FD, buf, n) != n)
return;
- write(STDOUT_FILENO, buf, n);
+ write(1, buf, n);
}
#endif
+/* Give the courier 50 milliseconds between characters */
+void
cour_nap()
{
- acu_nap (50);
-}
+ struct timespec ts;
-/* end of courier.c */
+ ts.tv_sec = 0;
+ ts.tv_nsec = 50 * 1000000;
+
+ nanosleep(&ts, NULL);
+}
diff --git a/usr.bin/tip/libacu/df.c b/usr.bin/tip/libacu/df.c
index fc60ad3..1c8ee30 100644
--- a/usr.bin/tip/libacu/df.c
+++ b/usr.bin/tip/libacu/df.c
@@ -1,3 +1,6 @@
+/* $OpenBSD: df.c,v 1.5 2001/10/24 18:38:58 millert Exp $ */
+/* $NetBSD: df.c,v 1.4 1995/10/29 00:49:51 pk Exp $ */
+
/*
* Copyright (c) 1983, 1993
* The Regents of the University of California. All rights reserved.
@@ -31,20 +34,26 @@
* SUCH DAMAGE.
*/
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
#ifndef lint
+#if 0
static char sccsid[] = "@(#)df.c 8.1 (Berkeley) 6/6/93";
+static char rcsid[] = "$OpenBSD: df.c,v 1.5 2001/10/24 18:38:58 millert Exp $";
+#endif
#endif /* not lint */
/*
* Dial the DF02-AC or DF03-AC
*/
-#include "tipconf.h"
#include "tip.h"
static jmp_buf Sjbuf;
static void timeout();
+int
df02_dialer(num, acu)
char *num, *acu;
{
@@ -52,6 +61,7 @@ df02_dialer(num, acu)
return (df_dialer(num, acu, 0));
}
+int
df03_dialer(num, acu)
char *num, *acu;
{
@@ -59,16 +69,19 @@ df03_dialer(num, acu)
return (df_dialer(num, acu, 1));
}
+int
df_dialer(num, acu, df03)
char *num, *acu;
int df03;
{
- register int f = FD;
- int speed = 0, rw = 2;
+ int f = FD;
+ struct termios cntrl;
+ int speed = 0;
char c = '\0';
- acu_hupcl ();
-
+ tcgetattr(f, &cntrl);
+ cntrl.c_cflag |= HUPCL;
+ tcsetattr(f, TCSANOW, &cntrl);
if (setjmp(Sjbuf)) {
printf("connection timed out\r\n");
df_disconnect();
@@ -81,8 +94,12 @@ df_dialer(num, acu, df03)
if (df03) {
int st = TIOCM_ST; /* secondary Transmit flag */
- if ((speed = acu_getspeed ()) != B1200) { /* must dial at 1200 baud */
- acu_setspeed (B1200);
+ tcgetattr(f, &cntrl);
+ speed = cfgetospeed(&cntrl);
+ if (speed != B1200) { /* must dial at 1200 baud */
+ cfsetospeed(&cntrl, B1200);
+ cfsetispeed(&cntrl, B1200);
+ tcsetattr(f, TCSAFLUSH, &cntrl);
ioctl(f, TIOCMBIC, &st); /* clear ST for 300 baud */
} else
ioctl(f, TIOCMBIS, &st); /* set ST for 1200 baud */
@@ -90,30 +107,32 @@ df_dialer(num, acu, df03)
#endif
signal(SIGALRM, timeout);
alarm(5 * strlen(num) + 10);
- ioctl(f, TIOCFLUSH, &rw);
+ tcflush(f, TCIOFLUSH);
write(f, "\001", 1);
sleep(1);
write(f, "\002", 1);
write(f, num, strlen(num));
read(f, &c, 1);
#ifdef TIOCMSET
- if (df03 && speed) {
- acu_setspeed (speed);
+ if (df03 && speed != B1200) {
+ cfsetospeed(&cntrl, speed);
+ cfsetispeed(&cntrl, speed);
+ tcsetattr(f, TCSAFLUSH, &cntrl);
}
#endif
return (c == 'A');
}
+void
df_disconnect()
{
- int rw = 2;
-
write(FD, "\001", 1);
sleep(1);
- ioctl(FD, TIOCFLUSH, &rw);
+ tcflush(FD, TCIOFLUSH);
}
+void
df_abort()
{
diff --git a/usr.bin/tip/libacu/dn11.c b/usr.bin/tip/libacu/dn11.c
index 6a2fc3e..ea78cce 100644
--- a/usr.bin/tip/libacu/dn11.c
+++ b/usr.bin/tip/libacu/dn11.c
@@ -1,3 +1,6 @@
+/* $OpenBSD: dn11.c,v 1.5 2001/11/19 19:02:16 mpech Exp $ */
+/* $NetBSD: dn11.c,v 1.4 1995/10/29 00:49:53 pk Exp $ */
+
/*
* Copyright (c) 1983, 1993
* The Regents of the University of California. All rights reserved.
@@ -29,32 +32,35 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
- *
- * $FreeBSD$
*/
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
#ifndef lint
+#if 0
static char sccsid[] = "@(#)dn11.c 8.1 (Berkeley) 6/6/93";
+static char rcsid[] = "$OpenBSD: dn11.c,v 1.5 2001/11/19 19:02:16 mpech Exp $";
+#endif
#endif /* not lint */
/*
* Routines for dialing up on DN-11
*/
-#include "tipconf.h"
#include "tip.h"
-#include <errno.h>
-int dn_abort();
+void dn_abort();
void alarmtr();
static jmp_buf jmpbuf;
static int child = -1, dn;
+int
dn_dialer(num, acu)
char *num, *acu;
{
- char *p, *q, phone[40];
- int lt, nw, connected = 1;
- register int timelim;
+ int lt, nw;
+ int timelim;
+ struct termios cntrl;
if (boolean(value(VERBOSE)))
printf("\nstarting call...");
@@ -98,18 +104,9 @@ dn_dialer(num, acu)
return (0);
}
alarm(0);
-
-#if HAVE_TERMIOS
- {
- struct termios term;
- tcgetattr (dn, &term);
- term.c_cflag |= HUPCL;
- tcsetattr (dn, TCSANOW, &term);
- }
-#elif defined(TIOCHPCL)
- ioctl(dn, TIOCHPCL, 0);
-#endif
-
+ tcgetattr(dn, &cntrl);
+ cntrl.c_cflag |= HUPCL;
+ tcsetattr(dn, TCSANOW, &cntrl);
signal(SIGALRM, SIG_DFL);
while ((nw = wait(&lt)) != child && nw != -1)
;
@@ -133,6 +130,7 @@ alarmtr()
* Insurance, for some reason we don't seem to be
* hanging up...
*/
+void
dn_disconnect()
{
@@ -142,6 +140,7 @@ dn_disconnect()
close(FD);
}
+void
dn_abort()
{
diff --git a/usr.bin/tip/libacu/hayes.c b/usr.bin/tip/libacu/hayes.c
index dcce6a5..8210fbf 100644
--- a/usr.bin/tip/libacu/hayes.c
+++ b/usr.bin/tip/libacu/hayes.c
@@ -1,3 +1,6 @@
+/* $OpenBSD: hayes.c,v 1.8 2001/10/24 18:38:58 millert Exp $ */
+/* $NetBSD: hayes.c,v 1.6 1997/02/11 09:24:17 mrg Exp $ */
+
/*
* Copyright (c) 1983, 1993
* The Regents of the University of California. All rights reserved.
@@ -31,8 +34,14 @@
* SUCH DAMAGE.
*/
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
#ifndef lint
+#if 0
static char sccsid[] = "@(#)hayes.c 8.1 (Berkeley) 6/6/93";
+static char rcsid[] = "$OpenBSD: hayes.c,v 1.8 2001/10/24 18:38:58 millert Exp $";
+#endif
#endif /* not lint */
/*
@@ -48,19 +57,21 @@ static char sccsid[] = "@(#)hayes.c 8.1 (Berkeley) 6/6/93";
* before modem is hung up, removal of the DTR signal
* has no effect (except that it prevents the modem from
* recognizing commands).
- * (by Helge Skrivervik, Calma Company, Sunnyvale, CA. 1984)
+ * (by Helge Skrivervik, Calma Company, Sunnyvale, CA. 1984)
*/
/*
* TODO:
* It is probably not a good idea to switch the modem
* state between 'verbose' and terse (status messages).
- * This should be kicked out and we should use verbose
+ * This should be kicked out and we should use verbose
* mode only. This would make it consistent with normal
* interactive use thru the command 'tip dialer'.
*/
-#include "tipconf.h"
#include "tip.h"
+#include <termios.h>
+#include <sys/ioctl.h>
+
#define min(a,b) ((a < b) ? a : b)
static void sigALRM();
@@ -76,14 +87,16 @@ static char dumbuf[DUMBUFLEN];
#define FAILED 4
static int state = IDLE;
+int
hay_dialer(num, acu)
- register char *num;
+ char *num;
char *acu;
{
- register char *cp;
- register int connected = 0;
+ char *cp;
+ int connected = 0;
char dummy;
-#if ACULOG
+ struct termios cntrl;
+#ifdef ACULOG
char line[80];
#endif
if (hay_sync() == 0) /* make sure we can talk to the modem */
@@ -91,12 +104,17 @@ hay_dialer(num, acu)
if (boolean(value(VERBOSE)))
printf("\ndialing...");
fflush(stdout);
- acu_hupcl ();
- acu_flush ();
+ tcgetattr(FD, &cntrl);
+ cntrl.c_cflag |= HUPCL;
+ tcsetattr(FD, TCSANOW, &cntrl);
+ tcflush(FD, TCIOFLUSH);
write(FD, "ATv0\r", 5); /* tell modem to use short status codes */
gobble("\r");
gobble("\r");
write(FD, "ATTD", 4); /* send dial command */
+ for (cp = num; *cp; cp++)
+ if (*cp == '=')
+ *cp = ',';
write(FD, num, strlen(num));
state = DIALING;
write(FD, "\r", 1);
@@ -113,10 +131,10 @@ hay_dialer(num, acu)
state = FAILED;
return (connected); /* lets get out of here.. */
}
- ioctl(FD, TIOCFLUSH, 0);
-#if ACULOG
+ tcflush(FD, TCIOFLUSH);
+#ifdef ACULOG
if (timeout) {
- sprintf(line, "%d second dial timeout",
+ (void)sprintf(line, "%ld second dial timeout",
number(value(DIALTIMEOUT)));
logent(value(HOST), num, "hayes", line);
}
@@ -127,11 +145,9 @@ hay_dialer(num, acu)
}
+void
hay_disconnect()
{
- char c;
- int len, rlen;
-
/* first hang up the modem*/
#ifdef DEBUG
printf("\rdisconnecting modem....\n\r");
@@ -142,11 +158,10 @@ hay_disconnect()
goodbye();
}
+void
hay_abort()
{
- char c;
-
write(FD, "\r", 1); /* send anything to abort the call */
hay_disconnect();
}
@@ -162,7 +177,7 @@ sigALRM()
static char
gobble(match)
- register char *match;
+ char *match;
{
char c;
sig_t f;
@@ -196,8 +211,9 @@ gobble(match)
return (status);
}
+static void
error_rep(c)
- register char c;
+ char c;
{
printf("\n\r");
switch (c) {
@@ -209,23 +225,23 @@ error_rep(c)
case '1':
printf("CONNECT");
break;
-
+
case '2':
printf("RING");
break;
-
+
case '3':
printf("NO CARRIER");
break;
-
+
case '4':
printf("ERROR in input");
break;
-
+
case '5':
printf("CONNECT 1200");
break;
-
+
default:
printf("Unknown Modem error: %c (0x%x)", c, c);
}
@@ -236,16 +252,17 @@ error_rep(c)
/*
* set modem back to normal verbose status codes.
*/
+void
goodbye()
{
- int len, rlen;
+ int len;
char c;
- ioctl(FD, TIOCFLUSH, &len); /* get rid of trash */
+ tcflush(FD, TCIOFLUSH);
if (hay_sync()) {
sleep(1);
#ifndef DEBUG
- ioctl(FD, TIOCFLUSH, 0);
+ tcflush(FD, TCIOFLUSH);
#endif
write(FD, "ATH0\r", 5); /* insurance */
#ifndef DEBUG
@@ -273,13 +290,14 @@ goodbye()
printf("read (%d): %s\r\n", rlen, dumbuf);
#endif
}
- ioctl(FD, TIOCFLUSH, 0); /* clear the input buffer */
+ tcflush(FD, TCIOFLUSH);
ioctl(FD, TIOCCDTR, 0); /* clear DTR (insurance) */
close(FD);
}
#define MAXRETRY 5
+int
hay_sync()
{
int len, retry = 0;
@@ -290,8 +308,8 @@ hay_sync()
ioctl(FD, FIONREAD, &len);
if (len) {
len = read(FD, dumbuf, min(len, DUMBUFLEN));
- if (index(dumbuf, '0') ||
- (index(dumbuf, 'O') && index(dumbuf, 'K')))
+ if (strchr(dumbuf, '0') ||
+ (strchr(dumbuf, 'O') && strchr(dumbuf, 'K')))
return(1);
#ifdef DEBUG
dumbuf[len] = '\0';
diff --git a/usr.bin/tip/libacu/multitech.c b/usr.bin/tip/libacu/multitech.c
deleted file mode 100644
index 2c3b2d9..0000000
--- a/usr.bin/tip/libacu/multitech.c
+++ /dev/null
@@ -1,404 +0,0 @@
-/*
- * Copyright (c) 1986, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifndef lint
-static const char rcsid[] =
- "$FreeBSD$";
-#endif
-
-/*
- * Routines for calling up on a Courier modem.
- * Derived from Hayes driver.
- */
-#include "tipconf.h"
-#include "tip.h"
-#include "acucommon.h"
-
-#include <stdio.h>
-#include <unistd.h>
-
-/* #define DEBUG */
-#define MAXRETRY 5
-/*
- Configuration
-*/
-static CONST char *dial_command = "ATDT";
-static CONST char *hangup_command = "ATH\r";
-static CONST char *echo_off_command = "ATE0\r";
-static CONST char *reset_command = "\rATZ\r";
-static CONST char *init_string = "AT$BA0$SB38400&E1&E4&E13&E15Q0V1X4E0S0=0\r";
-static CONST char *escape_sequence = "+++"; /* return to command escape sequence */
-static CONST int lock_baud = 1;
-static CONST unsigned int intercharacter_delay = 20;
-static CONST unsigned int intercommand_delay = 250;
-static CONST unsigned int escape_guard_time = 250;
-static CONST unsigned int reset_delay = 2000;
-
-/*
- Forward declarations
-*/
-void multitech_write (int fd, CONST char *cp, int n);
-void multitech_write_str (int fd, CONST char *cp);
-void multitech_disconnect ();
-void acu_nap (unsigned int how_long);
-static void sigALRM ();
-static int multitechsync ();
-static int multitech_swallow (register char *match);
-
-/*
- Global vars
-*/
-static int timeout = 0;
-static int connected = 0;
-static jmp_buf timeoutbuf, intbuf;
-
-int multitech_dialer (register char *num, char *acu)
-{
- register char *cp;
-#if ACULOG
- char line [80];
-#endif
- static int multitech_connect(), multitech_swallow();
-
- if (lock_baud)
- {
- int i;
- if ((i = speed(number(value(BAUDRATE)))) == 0)
- return 0;
- ttysetup (i);
- }
-
- if (boolean(value(VERBOSE)))
- printf("Using \"%s\"\n", acu);
-
- acu_hupcl ();
-
- /*
- * Get in synch.
- */
- if (!multitechsync()) {
-badsynch:
- printf("can't synchronize with multitech\n");
-#if ACULOG
- logent(value(HOST), num, "multitech", "can't synch up");
-#endif
- return (0);
- }
- acu_nap (intercommand_delay);
-
- multitech_write_str (FD, echo_off_command); /* turn off echoing */
-
- sleep(1);
-
-#ifdef DEBUG
- if (boolean(value(VERBOSE)))
- multitech_verbose_read();
-#endif
-
- acu_flush ();
-
- acu_nap (intercommand_delay);
- multitech_write_str (FD, init_string);
-
- if (!multitech_swallow ("\r\nOK\r\n"))
- goto badsynch;
-
- fflush (stdout);
-
- acu_nap (intercommand_delay);
- multitech_write_str (FD, dial_command);
-
- for (cp = num; *cp; cp++)
- if (*cp == '=')
- *cp = ',';
-
- multitech_write_str (FD, num);
-
- multitech_write_str (FD, "\r");
-
- connected = multitech_connect();
-
-#if ACULOG
- if (timeout) {
- sprintf(line, "%d second dial timeout",
- number(value(DIALTIMEOUT)));
- logent(value(HOST), num, "multitech", line);
- }
-#endif
- if (timeout)
- multitech_disconnect ();
- return (connected);
-}
-
-void multitech_disconnect ()
-{
- int okay, retries;
- for (retries = okay = 0; retries < 3 && !okay; retries++)
- {
- /* first hang up the modem*/
- ioctl (FD, TIOCCDTR, 0);
- acu_nap (escape_guard_time);
- ioctl (FD, TIOCSDTR, 0);
- acu_nap (escape_guard_time);
- /*
- * If not strapped for DTR control, try to get command mode.
- */
- acu_nap (escape_guard_time);
- multitech_write_str (FD, escape_sequence);
- acu_nap (escape_guard_time);
- multitech_write_str (FD, hangup_command);
- okay = multitech_swallow ("\r\nOK\r\n");
- }
- if (!okay)
- {
- #if ACULOG
- logent(value(HOST), "", "multitech", "can't hang up modem");
- #endif
- if (boolean(value(VERBOSE)))
- printf("hang up failed\n");
- }
- close (FD);
-}
-
-void multitech_abort ()
-{
- multitech_write_str (FD, "\r"); /* send anything to abort the call */
- multitech_disconnect ();
-}
-
-static void sigALRM ()
-{
- (void) printf("\07timeout waiting for reply\n");
- timeout = 1;
- longjmp(timeoutbuf, 1);
-}
-
-static int multitech_swallow (register char *match)
- {
- sig_t f;
- char c;
-
- f = signal(SIGALRM, sigALRM);
- timeout = 0;
- do {
- if (*match =='\0') {
- signal(SIGALRM, f);
- return (1);
- }
- if (setjmp(timeoutbuf)) {
- signal(SIGALRM, f);
- return (0);
- }
- alarm(number(value(DIALTIMEOUT)));
- read(FD, &c, 1);
- alarm(0);
- c &= 0177;
-#ifdef DEBUG
- if (boolean(value(VERBOSE)))
- putchar(c);
-#endif
- } while (c == *match++);
-#ifdef DEBUG
- if (boolean(value(VERBOSE)))
- fflush (stdout);
-#endif
- signal(SIGALRM, SIG_DFL);
- return (0);
-}
-
-static struct baud_msg {
- char *msg;
- int baud;
-} baud_msg[] = {
- "", B300,
- " 1200", B1200,
- " 2400", B2400,
- " 9600", B9600,
- " 9600/ARQ", B9600,
- 0, 0,
-};
-
-static int multitech_connect ()
-{
- char c;
- int nc, nl, n;
- char dialer_buf[64];
- struct baud_msg *bm;
- sig_t f;
-
- if (multitech_swallow("\r\n") == 0)
- return (0);
- f = signal(SIGALRM, sigALRM);
-again:
- nc = 0; nl = sizeof(dialer_buf)-1;
- bzero(dialer_buf, sizeof(dialer_buf));
- timeout = 0;
- for (nc = 0, nl = sizeof(dialer_buf)-1 ; nl > 0 ; nc++, nl--) {
- if (setjmp(timeoutbuf))
- break;
- alarm(number(value(DIALTIMEOUT)));
- n = read(FD, &c, 1);
- alarm(0);
- if (n <= 0)
- break;
- c &= 0x7f;
- if (c == '\r') {
- if (multitech_swallow("\n") == 0)
- break;
- if (!dialer_buf[0])
- goto again;
- if (strcmp(dialer_buf, "RINGING") == 0 &&
- boolean(value(VERBOSE))) {
-#ifdef DEBUG
- printf("%s\r\n", dialer_buf);
-#endif
- goto again;
- }
- if (strncmp(dialer_buf, "CONNECT",
- sizeof("CONNECT")-1) != 0)
- break;
- if (lock_baud) {
- signal(SIGALRM, f);
-#ifdef DEBUG
- if (boolean(value(VERBOSE)))
- printf("%s\r\n", dialer_buf);
-#endif
- return (1);
- }
- for (bm = baud_msg ; bm->msg ; bm++)
- if (strcmp(bm->msg, dialer_buf+sizeof("CONNECT")-1) == 0) {
- if (!acu_setspeed (bm->baud))
- goto error;
- signal(SIGALRM, f);
-#ifdef DEBUG
- if (boolean(value(VERBOSE)))
- printf("%s\r\n", dialer_buf);
-#endif
- return (1);
- }
- break;
- }
- dialer_buf[nc] = c;
- }
-error1:
- printf("%s\r\n", dialer_buf);
-error:
- signal(SIGALRM, f);
- return (0);
-}
-
-/*
- * This convoluted piece of code attempts to get
- * the multitech in sync.
- */
-static int multitechsync ()
-{
- int already = 0;
- int len;
- char buf[40];
-
- while (already++ < MAXRETRY) {
- acu_nap (intercommand_delay);
- ioctl (FD, TIOCFLUSH, 0); /* flush any clutter */
- multitech_write_str (FD, reset_command); /* reset modem */
- bzero(buf, sizeof(buf));
- acu_nap (reset_delay);
- ioctl (FD, FIONREAD, &len);
- if (len) {
- len = read(FD, buf, sizeof(buf));
-#ifdef DEBUG
- buf [len] = '\0';
- printf("multitechsync: (\"%s\")\n\r", buf);
-#endif
- if (index(buf, '0') ||
- (index(buf, 'O') && index(buf, 'K')))
- return(1);
- }
- /*
- * If not strapped for DTR control,
- * try to get command mode.
- */
- acu_nap (escape_guard_time);
- multitech_write_str (FD, escape_sequence);
- acu_nap (escape_guard_time);
- multitech_write_str (FD, hangup_command);
- /*
- * Toggle DTR to force anyone off that might have left
- * the modem connected.
- */
- acu_nap (escape_guard_time);
- ioctl (FD, TIOCCDTR, 0);
- acu_nap (escape_guard_time);
- ioctl (FD, TIOCSDTR, 0);
- }
- acu_nap (intercommand_delay);
- multitech_write_str (FD, reset_command);
- return (0);
-}
-
-void multitech_write_str (int fd, const char *cp)
-{
-#ifdef DEBUG
- printf ("multitech: sending %s\n", cp);
-#endif
- multitech_write (fd, cp, strlen (cp));
-}
-
-void multitech_write (int fd, const char *cp, int n)
-{
- acu_flush ();
- acu_nap (intercharacter_delay);
- for ( ; n-- ; cp++) {
- write (fd, cp, 1);
- acu_flush ();
- acu_nap (intercharacter_delay);
- }
-}
-
-#ifdef DEBUG
-multitech_verbose_read()
-{
- int n = 0;
- char buf[BUFSIZ];
-
- if (ioctl(FD, FIONREAD, &n) < 0)
- return;
- if (n <= 0)
- return;
- if (read(FD, buf, n) != n)
- return;
- write(STDOUT_FILENO, buf, n);
-}
-#endif
-
-/* end of multitech.c */
diff --git a/usr.bin/tip/libacu/t3000.c b/usr.bin/tip/libacu/t3000.c
index b8caafe..627aae9 100644
--- a/usr.bin/tip/libacu/t3000.c
+++ b/usr.bin/tip/libacu/t3000.c
@@ -1,3 +1,6 @@
+/* $OpenBSD: t3000.c,v 1.9 2001/10/24 18:38:58 millert Exp $ */
+/* $NetBSD: t3000.c,v 1.5 1997/02/11 09:24:18 mrg Exp $ */
+
/*
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
@@ -31,20 +34,24 @@
* SUCH DAMAGE.
*/
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
#ifndef lint
-static const char rcsid[] =
- "$FreeBSD$";
+#if 0
+static char sccsid[] = "@(#)t3000.c 8.1 (Berkeley) 6/6/93";
+static char rcsid[] = "$OpenBSD: t3000.c,v 1.9 2001/10/24 18:38:58 millert Exp $";
#endif
+#endif /* not lint */
/*
* Routines for calling up on a Telebit T3000 modem.
* Derived from Courier driver.
*/
-#include "tipconf.h"
#include "tip.h"
-#include "acucommon.h"
+
+#include <sys/ioctl.h>
#include <stdio.h>
-#include <unistd.h>
#define MAXRETRY 5
@@ -52,29 +59,33 @@ static void sigALRM();
static int timeout = 0;
static int connected = 0;
static jmp_buf timeoutbuf, intbuf;
-static int t3000_sync();
+static int t3000_sync(), t3000_connect(), t3000_swallow();
+static void t3000_nap();
+int
t3000_dialer(num, acu)
- register char *num;
+ char *num;
char *acu;
{
- register char *cp;
-#if ACULOG
+ char *cp;
+ struct termios cntrl;
+#ifdef ACULOG
char line[80];
#endif
- static int t3000_connect(), t3000_swallow();
if (boolean(value(VERBOSE)))
printf("Using \"%s\"\n", acu);
- acu_hupcl ();
+ tcgetattr(FD, &cntrl);
+ cntrl.c_cflag |= HUPCL;
+ tcsetattr(FD, TCSANOW, &cntrl);
/*
* Get in synch.
*/
if (!t3000_sync()) {
badsynch:
printf("can't synchronize with t3000\n");
-#if ACULOG
+#ifdef ACULOG
logent(value(HOST), num, "t3000", "can't synch up");
#endif
return (0);
@@ -85,7 +96,7 @@ badsynch:
if (boolean(value(VERBOSE)))
t3000_verbose_read();
#endif
- ioctl(FD, TIOCFLUSH, 0); /* flush any clutter */
+ tcflush(FD, TCIOFLUSH);
t3000_write(FD, "AT E0 H0 Q0 X4 V1\r", 18);
if (!t3000_swallow("\r\nOK\r\n"))
goto badsynch;
@@ -97,9 +108,9 @@ badsynch:
t3000_write(FD, num, strlen(num));
t3000_write(FD, "\r", 1);
connected = t3000_connect();
-#if ACULOG
+#ifdef ACULOG
if (timeout) {
- sprintf(line, "%d second dial timeout",
+ (void)sprintf(line, "%ld second dial timeout",
number(value(DIALTIMEOUT)));
logent(value(HOST), num, "t3000", line);
}
@@ -109,6 +120,7 @@ badsynch:
return (connected);
}
+void
t3000_disconnect()
{
/* first hang up the modem*/
@@ -119,6 +131,7 @@ t3000_disconnect()
close(FD);
}
+void
t3000_abort()
{
t3000_write(FD, "\r", 1); /* send anything to abort the call */
@@ -135,8 +148,8 @@ sigALRM()
static int
t3000_swallow(match)
- register char *match;
- {
+ char *match;
+{
sig_t f;
char c;
@@ -237,8 +250,12 @@ again:
for (bm = tbaud_msg ; bm->msg ; bm++)
if (strcmp(bm->msg,
dialer_buf+sizeof("CONNECT")-1) == 0) {
- if (!(acu_setspeed (bm->baud) || (bm->baud2 && acu_setspeed (bm->baud2))))
- goto error;
+ struct termios cntrl;
+
+ tcgetattr(FD, &cntrl);
+ cfsetospeed(&cntrl, bm->baud);
+ cfsetispeed(&cntrl, bm->baud);
+ tcsetattr(FD, TCSAFLUSH, &cntrl);
signal(SIGALRM, f);
#ifdef DEBUG
if (boolean(value(VERBOSE)))
@@ -254,9 +271,7 @@ again:
putchar(c);
#endif
}
-error1:
printf("%s\r\n", dialer_buf);
-error:
signal(SIGALRM, f);
return (0);
}
@@ -273,7 +288,7 @@ t3000_sync()
char buf[40];
while (already++ < MAXRETRY) {
- ioctl(FD, TIOCFLUSH, 0); /* flush any clutter */
+ tcflush(FD, TCIOFLUSH);
t3000_write(FD, "\rAT Z\r", 6); /* reset modem */
bzero(buf, sizeof(buf));
sleep(2);
@@ -287,8 +302,8 @@ if (len == 0) len = 1;
buf[len] = '\0';
printf("t3000_sync: (\"%s\")\n\r", buf);
#endif
- if (index(buf, '0') ||
- (index(buf, 'O') && index(buf, 'K')))
+ if (strchr(buf, '0') ||
+ (strchr(buf, 'O') && strchr(buf, 'K')))
return(1);
}
/*
@@ -310,6 +325,7 @@ if (len == 0) len = 1;
return (0);
}
+static int
t3000_write(fd, cp, n)
int fd;
char *cp;
@@ -317,13 +333,13 @@ int n;
{
#ifdef notdef
if (boolean(value(VERBOSE)))
- write(STDOUT_FILENO, cp, n);
+ write(1, cp, n);
#endif
- acu_flush ();
+ tcdrain(fd);
t3000_nap();
for ( ; n-- ; cp++) {
write(fd, cp, 1);
- acu_flush ();
+ tcdrain(fd);
t3000_nap();
}
}
@@ -340,13 +356,18 @@ t3000_verbose_read()
return;
if (read(FD, buf, n) != n)
return;
- write(STDOUT_FILENO, buf, n);
+ write(1, buf, n);
}
#endif
+/* Give the t3000 50 milliseconds between characters */
+void
t3000_nap()
{
- acu_nap (50);
-}
+ struct timespec ts;
-/* end of t3000.c */
+ ts.tv_sec = 0;
+ ts.tv_nsec = 50 * 1000000;
+
+ nanosleep(&ts, NULL);
+}
diff --git a/usr.bin/tip/libacu/tod.c b/usr.bin/tip/libacu/tod.c
deleted file mode 100644
index f585063..0000000
--- a/usr.bin/tip/libacu/tod.c
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * tod.c -- time of day pseudo-class implementation
- *
- * Copyright (c) 1995 John H. Poplett
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice immediately at the beginning of the file, without modification,
- * this list of conditions, and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Absolutely no warranty of function or purpose is made by the author
- * John H. Poplett.
- * 4. This work was done expressly for inclusion into FreeBSD. Other use
- * is allowed if this notation is included.
- * 5. Modifications may be freely made to this file if the above conditions
- * are met.
- *
- */
-
-#include <sys/types.h>
-#include <sys/time.h>
-
-#include <assert.h>
-#include <stdio.h>
-
-#include "tod.h"
-
-#define USP 1000000
-
-int tod_cmp (const struct timeval *a, const struct timeval *b)
-{
- int rc;
- assert (a->tv_usec <= USP);
- assert (b->tv_usec <= USP);
- rc = a->tv_sec - b->tv_sec;
- if (rc == 0)
- rc = a->tv_usec - b->tv_usec;
- return rc;
-}
-
-/*
- TOD < command
-*/
-int tod_lt (const struct timeval *a, const struct timeval *b)
-{
- return tod_cmp (a, b) < 0;
-}
-
-int tod_gt (const struct timeval *a, const struct timeval *b)
-{
- return tod_cmp (a, b) > 0;
-}
-
-int tod_lte (const struct timeval *a, const struct timeval *b)
-{
- return tod_cmp (a, b) <= 0;
-}
-
-int tod_gte (const struct timeval *a, const struct timeval *b)
-{
- return tod_cmp (a, b) >= 0;
-}
-
-int tod_eq (const struct timeval *a, const struct timeval *b)
-{
- return tod_cmp (a, b) == 0;
-}
-
-/*
- TOD += command
-*/
-void tod_addto (struct timeval *a, const struct timeval *b)
-{
- a->tv_usec += b->tv_usec;
- a->tv_sec += b->tv_sec + a->tv_usec / USP;
- a->tv_usec %= USP;
-}
-
-/*
- TOD -= command
-*/
-void tod_subfrom (struct timeval *a, struct timeval b)
-{
- assert (a->tv_usec <= USP);
- assert (b.tv_usec <= USP);
- if (b.tv_usec > a->tv_usec)
- {
- a->tv_usec += USP;
- a->tv_sec -= 1;
- }
- a->tv_usec -= b.tv_usec;
- a->tv_sec -= b.tv_sec;
-}
-
-void tod_gettime (struct timeval *tp)
-{
- gettimeofday (tp, NULL);
- tp->tv_sec += tp->tv_usec / USP;
- tp->tv_usec %= USP;
-}
-
-/* end of tod.c */
diff --git a/usr.bin/tip/libacu/tod.h b/usr.bin/tip/libacu/tod.h
deleted file mode 100644
index d772230..0000000
--- a/usr.bin/tip/libacu/tod.h
+++ /dev/null
@@ -1,9 +0,0 @@
-int tod_cmp (const struct timeval *a, const struct timeval *b);
-int tod_lt (const struct timeval *a, const struct timeval *b) ;
-int tod_gt (const struct timeval *a, const struct timeval *b);
-int tod_lte (const struct timeval *a, const struct timeval *b);
-int tod_gte (const struct timeval *a, const struct timeval *b);
-int tod_eq (const struct timeval *a, const struct timeval *b);
-void tod_addto (struct timeval *a, const struct timeval *b);
-void tod_subfrom (struct timeval *a, struct timeval b);
-void tod_gettime (struct timeval *tp);
diff --git a/usr.bin/tip/libacu/unidialer.c b/usr.bin/tip/libacu/unidialer.c
deleted file mode 100644
index 6fcec2f..0000000
--- a/usr.bin/tip/libacu/unidialer.c
+++ /dev/null
@@ -1,806 +0,0 @@
-/*
- * Copyright (c) 1986, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)unidialer.c 8.1 (Berkeley) 6/6/93";
-#endif
-static const char rcsid[] =
- "$FreeBSD$";
-#endif /* not lint */
-
-/*
- * Generalized routines for calling up on a Hayes AT command set based modem.
- * Control variables are pulled out of a modem caps-style database to
- * configure the driver for a particular modem.
- */
-#include "tipconf.h"
-#include "tip.h"
-#include "pathnames.h"
-
-#include <sys/times.h>
-#include <assert.h>
-#include <err.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-
-#include "acucommon.h"
-#include "tod.h"
-
-/* #define DEBUG */
-#define MAXRETRY 5
-
-typedef enum
-{
- mpt_notype, mpt_string, mpt_number, mpt_boolean
-} modem_parm_type_t;
-
-typedef struct {
- modem_parm_type_t modem_parm_type;
- const char *name;
- union {
- char **string;
- unsigned int *number;
- } value;
- union {
- char *string;
- unsigned int number;
- } default_value;
-} modem_parm_t;
-
-/*
- Configuration
-*/
-static char modem_name [80];
-static char *dial_command;
-static char *hangup_command;
-static char *echo_off_command;
-static char *reset_command;
-static char *init_string;
-static char *escape_sequence;
-static int hw_flow_control;
-static int lock_baud;
-static unsigned int intercharacter_delay;
-static unsigned int intercommand_delay;
-static unsigned int escape_guard_time;
-static unsigned int reset_delay;
-
-static int unidialer_dialer (register char *num, char *acu);
-static void unidialer_disconnect ();
-static void unidialer_abort ();
-
-static acu_t unidialer =
-{
- modem_name,
- unidialer_dialer,
- unidialer_disconnect,
- unidialer_abort
-};
-
-/*
- Table of parameters kept in modem database
-*/
-modem_parm_t modem_parms [] = {
- { mpt_string, "dial_command", &dial_command, "ATDT%s\r" },
- { mpt_string, "hangup_command", &hangup_command, "ATH\r", },
- { mpt_string, "echo_off_command", &echo_off_command, "ATE0\r" },
- { mpt_string, "reset_command", &reset_command, "ATZ\r" },
- { mpt_string, "init_string", &init_string, "AT&F\r", },
- { mpt_string, "escape_sequence", &escape_sequence, "+++" },
- { mpt_boolean, "hw_flow_control", (char **)&hw_flow_control, NULL },
- { mpt_boolean, "lock_baud", (char **)&lock_baud, NULL },
- { mpt_number, "intercharacter_delay", (char **)&intercharacter_delay, (char *)50 },
- { mpt_number, "intercommand_delay", (char **)&intercommand_delay, (char *)300 },
- { mpt_number, "escape_guard_time", (char **)&escape_guard_time, (char *)300 },
- { mpt_number, "reset_delay", (char **)&reset_delay, (char *)3000 },
- { mpt_notype, NULL, NULL, NULL }
-};
-
-/*
- Forward declarations
-*/
-static void unidialer_verbose_read ();
-static void unidialer_modem_cmd (int fd, CONST char *cmd);
-static void unidialer_write (int fd, CONST char *cp, int n);
-static void unidialer_write_str (int fd, CONST char *cp);
-static void unidialer_disconnect ();
-static void sigALRM ();
-static int unidialersync ();
-static int unidialer_swallow (register char *match);
-
-/*
- Global vars
-*/
-static int timeout = 0;
-static int connected = 0;
-static jmp_buf timeoutbuf, intbuf;
-
-#define cgetflag(f) (cgetcap(bp, f, ':') != NULL)
-
-#ifdef DEBUG
-
-#define print_str(x) printf (#x " = %s\n", x)
-#define print_num(x) printf (#x " = %d\n", x)
-
-void dumpmodemparms (char *modem)
-{
- printf ("modem parms for %s\n", modem);
- print_str (dial_command);
- print_str (hangup_command);
- print_str (echo_off_command);
- print_str (reset_command);
- print_str (init_string);
- print_str (escape_sequence);
- print_num (lock_baud);
- print_num (intercharacter_delay);
- print_num (intercommand_delay);
- print_num (escape_guard_time);
- print_num (reset_delay);
- printf ("\n");
-}
-#endif
-
-static int getmodemparms (const char *modem)
-{
- char *bp, *db_array [3], *modempath;
- int ndx, stat;
- modem_parm_t *mpp;
-
- modempath = getenv ("MODEMS");
-
- ndx = 0;
-
- if (modempath != NULL)
- db_array [ndx++] = modempath;
-
- db_array [ndx++] = _PATH_MODEMS;
- db_array [ndx] = NULL;
-
- if ((stat = cgetent (&bp, db_array, (char *)modem)) < 0) {
- switch (stat) {
- case -1:
- warnx ("unknown modem %s", modem);
- break;
- case -2:
- warnx ("can't open modem description file");
- break;
- case -3:
- warnx ("possible reference loop in modem description file");
- break;
- }
- return 0;
- }
- for (mpp = modem_parms; mpp->name; mpp++)
- {
- switch (mpp->modem_parm_type)
- {
- case mpt_string:
- if (cgetstr (bp, (char *)mpp->name, mpp->value.string) == -1)
- *mpp->value.string = mpp->default_value.string;
- break;
-
- case mpt_number:
- {
- long l;
- if (cgetnum (bp, (char *)mpp->name, &l) == -1)
- *mpp->value.number = mpp->default_value.number;
- else
- *mpp->value.number = (unsigned int)l;
- }
- break;
-
- case mpt_boolean:
- *mpp->value.number = cgetflag ((char *)mpp->name);
- break;
- }
- }
- strncpy (modem_name, modem, sizeof (modem_name) - 1);
- modem_name [sizeof (modem_name) - 1] = '\0';
- return 1;
-}
-
-/*
-*/
-acu_t* unidialer_getmodem (const char *modem_name)
-{
- acu_t* rc = NOACU;
- if (getmodemparms (modem_name))
- rc = &unidialer;
- return rc;
-}
-
-static int unidialer_modem_ready ()
-{
-#ifdef TIOCMGET
- int state;
- ioctl (FD, TIOCMGET, &state);
- return (state & TIOCM_DSR) ? 1 : 0;
-#else
- return (1);
-#endif
-}
-
-static int unidialer_waitfor_modem_ready (int ms)
-{
-#ifdef TIOCMGET
- int count;
- for (count = 0; count < ms; count += 100)
- {
- if (unidialer_modem_ready ())
- {
-#ifdef DEBUG
- printf ("unidialer_waitfor_modem_ready: modem ready.\n");
-#endif
- break;
- }
- acu_nap (100);
- }
- return (count < ms);
-#else
- acu_nap (250);
- return (1);
-#endif
-}
-
-int unidialer_tty_clocal (int flag)
-{
-#if HAVE_TERMIOS
- struct termios t;
- tcgetattr (FD, &t);
- if (flag)
- t.c_cflag |= CLOCAL;
- else
- t.c_cflag &= ~CLOCAL;
- tcsetattr (FD, TCSANOW, &t);
-#elif defined(TIOCMSET)
- int state;
- /*
- Don't have CLOCAL so raise CD in software to
- get the same effect.
- */
- ioctl (FD, TIOCMGET, &state);
- if (flag)
- state |= TIOCM_CD;
- else
- state &= ~TIOCM_CD;
- ioctl (FD, TIOCMSET, &state);
-#endif
-}
-
-int unidialer_get_modem_response (char *buf, int bufsz, int response_timeout)
-{
- sig_t f;
- char c, *p = buf, *lid = buf + bufsz - 1;
- int state;
-
- assert (bufsz > 0);
-
- f = signal (SIGALRM, sigALRM);
-
- timeout = 0;
-
- if (setjmp (timeoutbuf)) {
- signal (SIGALRM, f);
- *p = '\0';
-#ifdef DEBUG
- printf ("get_response: timeout buf=%s, state=%d\n", buf, state);
-#endif
- return (0);
- }
-
- ualarm (response_timeout * 1000, 0);
-
- state = 0;
-
- while (1)
- {
- switch (state)
- {
- case 0:
- if (read (FD, &c, 1) == 1)
- {
- if (c == '\r')
- {
- ++state;
- }
- else
- {
-#ifdef DEBUG
- printf ("get_response: unexpected char %s.\n", ctrl (c));
-#endif
- }
- }
- break;
-
- case 1:
- if (read (FD, &c, 1) == 1)
- {
- if (c == '\n')
- {
-#ifdef DEBUG
- printf ("get_response: <CRLF> encountered.\n", buf);
-#endif
- ++state;
- }
- else
- {
- state = 0;
-#ifdef DEBUG
- printf ("get_response: unexpected char %s.\n", ctrl (c));
-#endif
- }
- }
- break;
-
- case 2:
- if (read (FD, &c, 1) == 1)
- {
- if (c == '\r')
- ++state;
- else if (c >= ' ' && p < lid)
- *p++ = c;
- }
- break;
-
- case 3:
- if (read (FD, &c, 1) == 1)
- {
- if (c == '\n')
- {
- signal (SIGALRM, f);
- /* ualarm (0, 0); */
- alarm (0);
- *p = '\0';
-#ifdef DEBUG
- printf ("get_response: %s\n", buf);
-#endif
- return (1);
- }
- else
- {
- state = 0;
- p = buf;
- }
- }
- break;
- }
- }
-}
-
-int unidialer_get_okay (int ms)
-{
- int okay;
- char buf [BUFSIZ];
- okay = unidialer_get_modem_response (buf, sizeof (buf), ms) &&
- strcmp (buf, "OK") == 0;
- return okay;
-}
-
-static int unidialer_dialer (register char *num, char *acu)
-{
- register char *cp;
- char dial_string [80];
-#if ACULOG
- char line [80];
-#endif
- static int unidialer_connect(), unidialer_swallow();
-
- #ifdef DEBUG
- dumpmodemparms (modem_name);
- #endif
-
- if (lock_baud) {
- int i;
- if ((i = speed(number(value(BAUDRATE)))) == 0)
- return 0;
- ttysetup (i);
- }
-
- if (boolean(value(VERBOSE)))
- printf("Using \"%s\"\n", acu);
-
- acu_hupcl ();
-
- /*
- * Get in synch.
- */
- if (!unidialersync()) {
-badsynch:
- printf("tip: can't synchronize with %s\n", modem_name);
-#if ACULOG
- logent(value(HOST), num, modem_name, "can't synch up");
-#endif
- return (0);
- }
-
- unidialer_modem_cmd (FD, echo_off_command); /* turn off echoing */
-
- sleep(1);
-
-#ifdef DEBUG
- if (boolean(value(VERBOSE)))
- unidialer_verbose_read();
-#endif
-
- acu_flush (); /* flush any clutter */
-
- unidialer_modem_cmd (FD, init_string);
-
- if (!unidialer_get_okay (reset_delay))
- goto badsynch;
-
- fflush (stdout);
-
- for (cp = num; *cp; cp++)
- if (*cp == '=')
- *cp = ',';
-
- (void) sprintf (dial_string, dial_command, num);
-
- unidialer_modem_cmd (FD, dial_string);
-
- connected = unidialer_connect ();
-
- if (connected && hw_flow_control) {
- acu_hw_flow_control (hw_flow_control);
- }
-
-#if ACULOG
- if (timeout) {
- sprintf(line, "%d second dial timeout",
- number(value(DIALTIMEOUT)));
- logent(value(HOST), num, modem_name, line);
- }
-#endif
-
- if (timeout)
- unidialer_disconnect ();
-
- return (connected);
-}
-
-static void unidialer_disconnect ()
-{
- int okay, retries;
-
- acu_flush (); /* flush any clutter */
-
- unidialer_tty_clocal (TRUE);
-
- /* first hang up the modem*/
- ioctl (FD, TIOCCDTR, 0);
- acu_nap (250);
- ioctl (FD, TIOCSDTR, 0);
-
- /*
- * If AT&D2, then dropping DTR *should* just hangup the modem. But
- * some modems reset anyway; also, the modem may be programmed to reset
- * anyway with AT&D3. Play it safe and wait for the full reset time before
- * proceeding.
- */
- acu_nap (reset_delay);
-
- if (!unidialer_waitfor_modem_ready (reset_delay))
- {
-#ifdef DEBUG
- printf ("unidialer_disconnect: warning CTS low.\r\n");
-#endif
- }
-
- /*
- * If not strapped for DTR control, try to get command mode.
- */
- for (retries = okay = 0; retries < MAXRETRY && !okay; retries++)
- {
- int timeout_value;
- /* flush any clutter */
- if (!acu_flush ())
- {
-#ifdef DEBUG
- printf ("unidialer_disconnect: warning flush failed.\r\n");
-#endif
- }
- timeout_value = escape_guard_time;
- timeout_value += (timeout_value * retries / MAXRETRY);
- acu_nap (timeout_value);
- acu_flush (); /* flush any clutter */
- unidialer_modem_cmd (FD, escape_sequence);
- acu_nap (timeout_value);
- unidialer_modem_cmd (FD, hangup_command);
- okay = unidialer_get_okay (reset_delay);
- }
- if (!okay)
- {
- #if ACULOG
- logent(value(HOST), "", modem_name, "can't hang up modem");
- #endif
- if (boolean(value(VERBOSE)))
- printf("hang up failed\n");
- }
- (void) acu_flush ();
- close (FD);
-}
-
-static void unidialer_abort ()
-{
- unidialer_write_str (FD, "\r"); /* send anything to abort the call */
- unidialer_disconnect ();
-}
-
-static void sigALRM ()
-{
- (void) printf("\07timeout waiting for reply\n");
- timeout = 1;
- longjmp(timeoutbuf, 1);
-}
-
-static int unidialer_swallow (register char *match)
-{
- sig_t f;
- char c;
-
- f = signal(SIGALRM, sigALRM);
-
- timeout = 0;
-
- if (setjmp(timeoutbuf)) {
- signal(SIGALRM, f);
- return (0);
- }
-
- alarm(number(value(DIALTIMEOUT)));
-
- do {
- if (*match =='\0') {
- signal(SIGALRM, f);
- alarm (0);
- return (1);
- }
- do {
- read (FD, &c, 1);
- } while (c == '\0');
- c &= 0177;
-#ifdef DEBUG
- if (boolean(value(VERBOSE)))
- {
- /* putchar(c); */
- printf (ctrl (c));
- }
-#endif
- } while (c == *match++);
- signal(SIGALRM, SIG_DFL);
- alarm(0);
-#ifdef DEBUG
- if (boolean(value(VERBOSE)))
- fflush (stdout);
-#endif
- return (0);
-}
-
-static struct baud_msg {
- char *msg;
- int baud;
-} baud_msg[] = {
- "", B300,
- " 1200", B1200,
- " 2400", B2400,
- " 9600", B9600,
- " 9600/ARQ", B9600,
- 0, 0,
-};
-
-static int unidialer_connect ()
-{
- char c;
- int nc, nl, n;
- char dialer_buf[64];
- struct baud_msg *bm;
- sig_t f;
-
- if (unidialer_swallow("\r\n") == 0)
- return (0);
- f = signal(SIGALRM, sigALRM);
-again:
- nc = 0; nl = sizeof(dialer_buf)-1;
- bzero(dialer_buf, sizeof(dialer_buf));
- timeout = 0;
- for (nc = 0, nl = sizeof(dialer_buf)-1 ; nl > 0 ; nc++, nl--) {
- if (setjmp(timeoutbuf))
- break;
- alarm(number(value(DIALTIMEOUT)));
- n = read(FD, &c, 1);
- alarm(0);
- if (n <= 0)
- break;
- c &= 0x7f;
- if (c == '\r') {
- if (unidialer_swallow("\n") == 0)
- break;
- if (!dialer_buf[0])
- goto again;
- if (strcmp(dialer_buf, "RINGING") == 0 &&
- boolean(value(VERBOSE))) {
-#ifdef DEBUG
- printf("%s\r\n", dialer_buf);
-#endif
- goto again;
- }
- if (strncmp(dialer_buf, "CONNECT",
- sizeof("CONNECT")-1) != 0)
- break;
- if (lock_baud) {
- signal(SIGALRM, f);
-#ifdef DEBUG
- if (boolean(value(VERBOSE)))
- printf("%s\r\n", dialer_buf);
-#endif
- return (1);
- }
- for (bm = baud_msg ; bm->msg ; bm++)
- if (strcmp(bm->msg, dialer_buf+sizeof("CONNECT")-1) == 0) {
- if (!acu_setspeed (bm->baud))
- goto error;
- signal(SIGALRM, f);
-#ifdef DEBUG
- if (boolean(value(VERBOSE)))
- printf("%s\r\n", dialer_buf);
-#endif
- return (1);
- }
- break;
- }
- dialer_buf[nc] = c;
- }
-error1:
- printf("%s\r\n", dialer_buf);
-error:
- signal(SIGALRM, f);
- return (0);
-}
-
-/*
- * This convoluted piece of code attempts to get
- * the unidialer in sync.
- */
-static int unidialersync ()
-{
- int already = 0;
- int len;
- char buf[40];
-
- while (already++ < MAXRETRY) {
- acu_nap (intercommand_delay);
- acu_flush (); /* flush any clutter */
- unidialer_write_str (FD, reset_command); /* reset modem */
- bzero(buf, sizeof(buf));
- acu_nap (reset_delay);
- ioctl (FD, FIONREAD, &len);
- if (len) {
- len = read(FD, buf, sizeof(buf));
-#ifdef DEBUG
- buf [len] = '\0';
- printf("unidialersync (%s): (\"%s\")\n\r", modem_name, buf);
-#endif
- if (index(buf, '0') ||
- (index(buf, 'O') && index(buf, 'K')))
- return(1);
- }
- /*
- * If not strapped for DTR control,
- * try to get command mode.
- */
- acu_nap (escape_guard_time);
- unidialer_write_str (FD, escape_sequence);
- acu_nap (escape_guard_time);
- unidialer_write_str (FD, hangup_command);
- /*
- * Toggle DTR to force anyone off that might have left
- * the modem connected.
- */
- acu_nap (escape_guard_time);
- ioctl (FD, TIOCCDTR, 0);
- acu_nap (1000);
- ioctl (FD, TIOCSDTR, 0);
- }
- acu_nap (intercommand_delay);
- unidialer_write_str (FD, reset_command);
- return (0);
-}
-
-/*
- Send commands to modem; impose delay between commands.
-*/
-static void unidialer_modem_cmd (int fd, const char *cmd)
-{
- static struct timeval oldt = { 0, 0 };
- struct timeval newt;
- tod_gettime (&newt);
- if (tod_lt (&newt, &oldt))
- {
- unsigned int naptime;
- tod_subfrom (&oldt, newt);
- naptime = oldt.tv_sec * 1000 + oldt.tv_usec / 1000;
- if (naptime > intercommand_delay)
- {
-#ifdef DEBUG
- printf ("unidialer_modem_cmd: suspicious naptime (%u ms)\r\n", naptime);
-#endif
- naptime = intercommand_delay;
- }
-#ifdef DEBUG
- printf ("unidialer_modem_cmd: delaying %u ms\r\n", naptime);
-#endif
- acu_nap (naptime);
- }
- unidialer_write_str (fd, cmd);
- tod_gettime (&oldt);
- newt.tv_sec = 0;
- newt.tv_usec = intercommand_delay;
- tod_addto (&oldt, &newt);
-}
-
-static void unidialer_write_str (int fd, const char *cp)
-{
-#ifdef DEBUG
- printf ("unidialer (%s): sending %s\n", modem_name, cp);
-#endif
- unidialer_write (fd, cp, strlen (cp));
-}
-
-static void unidialer_write (int fd, const char *cp, int n)
-{
- acu_nap (intercharacter_delay);
- for ( ; n-- ; cp++) {
- write (fd, cp, 1);
- acu_nap (intercharacter_delay);
- }
-}
-
-#ifdef DEBUG
-static void unidialer_verbose_read()
-{
- int n = 0;
- char buf[BUFSIZ];
-
- if (ioctl(FD, FIONREAD, &n) < 0)
- return;
- if (n <= 0)
- return;
- if (read(FD, buf, n) != n)
- return;
- write(STDOUT_FILENO, buf, n);
-}
-#endif
-
-/* end of unidialer.c */
diff --git a/usr.bin/tip/libacu/v3451.c b/usr.bin/tip/libacu/v3451.c
index a98c4d4..df850a5 100644
--- a/usr.bin/tip/libacu/v3451.c
+++ b/usr.bin/tip/libacu/v3451.c
@@ -1,3 +1,6 @@
+/* $OpenBSD: v3451.c,v 1.6 2001/10/24 18:38:58 millert Exp $ */
+/* $NetBSD: v3451.c,v 1.6 1997/02/11 09:24:20 mrg Exp $ */
+
/*
* Copyright (c) 1983, 1993
* The Regents of the University of California. All rights reserved.
@@ -31,31 +34,36 @@
* SUCH DAMAGE.
*/
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
#ifndef lint
+#if 0
static char sccsid[] = "@(#)v3451.c 8.1 (Berkeley) 6/6/93";
+static char rcsid[] = "$OpenBSD: v3451.c,v 1.6 2001/10/24 18:38:58 millert Exp $";
+#endif
#endif /* not lint */
/*
* Routines for calling up on a Vadic 3451 Modem
*/
-#include "tipconf.h"
#include "tip.h"
static jmp_buf Sjbuf;
+static int expect(), notin(), prefix();
+static void vawrite(), alarmtr();
+
+int
v3451_dialer(num, acu)
- register char *num;
+ char *num;
char *acu;
{
sig_t func;
int ok;
- int slow = number(value(BAUDRATE)) < 1200, rw = 2;
+ int slow = number(value(BAUDRATE)) < 1200;
char phone[50];
-#if ACULOG
- char line[80];
-#endif
- static int expect();
- static void vawrite();
+ struct termios cntrl;
/*
* Get in synch
@@ -66,27 +74,28 @@ v3451_dialer(num, acu)
vawrite("\005\r", 2 + slow);
if (!expect("READY")) {
printf("can't synchronize with vadic 3451\n");
-#if ACULOG
+#ifdef ACULOG
logent(value(HOST), num, "vadic", "can't synch up");
#endif
return (0);
}
- acu_hupcl ();
+ tcgetattr(FD, &cntrl);
+ term.c_cflag |= HUPCL;
+ tcsetattr(FD, TCSANOW, &cntrl);
sleep(1);
vawrite("D\r", 2 + slow);
if (!expect("NUMBER?")) {
printf("Vadic will not accept dial command\n");
-#if ACULOG
+#ifdef ACULOG
logent(value(HOST), num, "vadic", "will not accept dial");
#endif
return (0);
}
- strcpy(phone, num);
- strcat(phone, "\r");
+ (void)snprintf(phone, sizeof phone, "%s\r", num);
vawrite(phone, 1 + slow);
if (!expect(phone)) {
printf("Vadic will not accept phone number\n");
-#if ACULOG
+#ifdef ACULOG
logent(value(HOST), num, "vadic", "will not accept number");
#endif
return (0);
@@ -101,7 +110,7 @@ v3451_dialer(num, acu)
vawrite("\r", 1 + slow);
if (!expect("DIALING:")) {
printf("Vadic failed to dial\n");
-#if ACULOG
+#ifdef ACULOG
logent(value(HOST), num, "vadic", "failed to dial");
#endif
return (0);
@@ -112,21 +121,23 @@ v3451_dialer(num, acu)
signal(SIGINT, func);
if (!ok) {
printf("call failed\n");
-#if ACULOG
+#ifdef ACULOG
logent(value(HOST), num, "vadic", "call failed");
#endif
return (0);
}
- ioctl(FD, TIOCFLUSH, &rw);
+ tcflush(FD, TCIOFLUSH);
return (1);
}
+void
v3451_disconnect()
{
close(FD);
}
+void
v3451_abort()
{
@@ -135,7 +146,7 @@ v3451_abort()
static void
vawrite(cp, delay)
- register char *cp;
+ char *cp;
int delay;
{
@@ -143,15 +154,13 @@ vawrite(cp, delay)
write(FD, cp, 1);
}
-static
+static int
expect(cp)
- register char *cp;
+ char *cp;
{
char buf[300];
- register char *rp = buf;
+ char *rp = buf;
int timeout = 30, online = 0;
- static int notin();
- static void alarmtr();
if (strcmp(cp, "\"\"") == 0)
return (1);
@@ -194,7 +203,6 @@ static int
notin(sh, lg)
char *sh, *lg;
{
- static int prefix();
for (; *lg; lg++)
if (prefix(sh, lg))
@@ -202,11 +210,11 @@ notin(sh, lg)
return (1);
}
-static
+static int
prefix(s1, s2)
- register char *s1, *s2;
+ char *s1, *s2;
{
- register char c;
+ char c;
while ((c = *s1++) == *s2++)
if (c == '\0')
diff --git a/usr.bin/tip/libacu/v831.c b/usr.bin/tip/libacu/v831.c
index e02121c..5a6268e 100644
--- a/usr.bin/tip/libacu/v831.c
+++ b/usr.bin/tip/libacu/v831.c
@@ -1,3 +1,6 @@
+/* $OpenBSD: v831.c,v 1.6 2001/11/19 19:02:16 mpech Exp $ */
+/* $NetBSD: v831.c,v 1.5 1996/12/29 10:42:01 cgd Exp $ */
+
/*
* Copyright (c) 1983, 1993
* The Regents of the University of California. All rights reserved.
@@ -29,33 +32,38 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
- *
- * $FreeBSD$
*/
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
#ifndef lint
+#if 0
static char sccsid[] = "@(#)v831.c 8.1 (Berkeley) 6/6/93";
+static char rcsid[] = "$OpenBSD: v831.c,v 1.6 2001/11/19 19:02:16 mpech Exp $";
+#endif
#endif /* not lint */
/*
* Routines for dialing up on Vadic 831
*/
-#include "tipconf.h"
#include "tip.h"
-#include <errno.h>
+#include <termios.h>
-int v831_abort();
+void v831_abort();
static void alarmtr();
+static int dialit();
+static char *sanitize();
static jmp_buf jmpbuf;
static int child = -1;
+int
v831_dialer(num, acu)
char *num, *acu;
{
- int status, pid, connected = 1;
- register int timelim;
- static int dialit();
+ int status, pid;
+ int timelim;
if (boolean(value(VERBOSE)))
printf("\nstarting call...");
@@ -104,9 +112,6 @@ v831_dialer(num, acu)
return (0);
}
alarm(0);
-#ifdef notdef
- ioctl(AC, TIOCHPCL, 0);
-#endif
signal(SIGALRM, SIG_DFL);
while ((pid = wait(&status)) != child && pid != -1)
;
@@ -128,20 +133,27 @@ alarmtr()
* Insurance, for some reason we don't seem to be
* hanging up...
*/
+void
v831_disconnect()
{
+ struct termios cntrl;
+
sleep(2);
#ifdef DEBUG
printf("[disconnect: FD=%d]\n", FD);
#endif
if (FD > 0) {
ioctl(FD, TIOCCDTR, 0);
- acu_setspeec (0);
- ioctl(FD, TIOCNXCL, 0);
+ tcgetattr(FD, &cntrl);
+ cfsetospeed(&cntrl, 0);
+ cfsetispeed(&cntrl, 0);
+ tcsetattr(FD, TCSAFLUSH, &cntrl);
+ ioctl(FD, TIOCNXCL, NULL);
}
close(FD);
}
+void
v831_abort()
{
@@ -152,7 +164,7 @@ v831_abort()
if (child > 0)
kill(child, SIGKILL);
if (AC > 0)
- ioctl(FD, TIOCNXCL, 0);
+ ioctl(FD, TIOCNXCL, NULL);
close(AC);
if (FD > 0)
ioctl(FD, TIOCCDTR, 0);
@@ -180,13 +192,13 @@ struct vaconfig {
static int
dialit(phonenum, acu)
- register char *phonenum;
+ char *phonenum;
char *acu;
{
- register struct vaconfig *vp;
+ struct vaconfig *vp;
+ struct termios cntrl;
char c;
- int i, two = 2;
- static char *sanitize();
+ int i;
phonenum = sanitize(phonenum);
#ifdef DEBUG
@@ -201,28 +213,13 @@ dialit(phonenum, acu)
printf("Unable to locate dialer (%s)\n", acu);
return ('K');
}
- {
-#if HAVE_TERMIOS
- struct termios termios;
- tcgetattr (AC, &termios);
- termios.c_iflag = 0;
-#ifndef _POSIX_SOURCE
- termios.c_lflag = (PENDIN|ECHOKE|ECHOE);
-#else
- termios.c_lflag = (PENDIN|ECHOE);
-#endif
- termios.c_cflag = (CLOCAL|HUPCL|CREAD|CS8);
- termios.c_ispeed = termios.c_ospeed = B2400;
- tcsetattr (AC, TCSANOW, &termios);
-#else /* HAVE_TERMIOS */
- struct sgttyb cntrl;
- ioctl(AC, TIOCGETP, &cntrl);
- cntrl.sg_ispeed = cntrl.sg_ospeed = B2400;
- cntrl.sg_flags = RAW | EVENP | ODDP;
- ioctl(AC, TIOCSETP, &cntrl);
- #endif
- }
- ioctl(AC, TIOCFLUSH, &two);
+ tcgetattr(AC, &cntrl);
+ cfsetospeed(&cntrl, B2400);
+ cfsetispeed(&cntrl, B2400);
+ cntrl.c_cflag |= PARODD | PARENB;
+ cntrl.c_lflag &= ~(ISIG | ICANON);
+ tcsetattr(AC, TCSANOW, &cntrl);
+ tcflush(AC, TCIOFLUSH);
pc(STX);
pc(vp->vc_rack);
pc(vp->vc_modem);
@@ -257,10 +254,10 @@ dialit(phonenum, acu)
static char *
sanitize(s)
- register char *s;
+ char *s;
{
static char buf[128];
- register char *cp;
+ char *cp;
for (cp = buf; *s; s++) {
if (!isdigit(*s) && *s == '<' && *s != '_')
diff --git a/usr.bin/tip/libacu/ventel.c b/usr.bin/tip/libacu/ventel.c
index 08f2be5..c3b87ae 100644
--- a/usr.bin/tip/libacu/ventel.c
+++ b/usr.bin/tip/libacu/ventel.c
@@ -1,3 +1,6 @@
+/* $OpenBSD: ventel.c,v 1.7 2001/11/19 19:02:16 mpech Exp $ */
+/* $NetBSD: ventel.c,v 1.6 1997/02/11 09:24:21 mrg Exp $ */
+
/*
* Copyright (c) 1983, 1993
* The Regents of the University of California. All rights reserved.
@@ -31,21 +34,23 @@
* SUCH DAMAGE.
*/
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
#ifndef lint
#if 0
static char sccsid[] = "@(#)ventel.c 8.1 (Berkeley) 6/6/93";
+static char rcsid[] = "$OpenBSD: ventel.c,v 1.7 2001/11/19 19:02:16 mpech Exp $";
#endif
-static const char rcsid[] =
- "$FreeBSD$";
#endif /* not lint */
/*
* Routines for calling up on a Ventel Modem
* The Ventel is expected to be strapped for local echo (just like uucp)
*/
-#include "tipconf.h"
#include "tip.h"
-#include <err.h>
+#include <termios.h>
+#include <sys/ioctl.h>
#define MAXRETRY 5
@@ -53,6 +58,9 @@ static void sigALRM();
static int timeout = 0;
static jmp_buf timeoutbuf;
+static int gobble(), vensync();
+static void echo();
+
/*
* some sleep calls have been replaced by this macro
* because some ventel modems require two <cr>s in less than
@@ -60,25 +68,25 @@ static jmp_buf timeoutbuf;
*/
#define delay(num,denom) busyloop(CPUSPEED*num/denom)
#define CPUSPEED 1000000 /* VAX 780 is 1MIPS */
-#define DELAY(n) { register long N = (n); while (--N > 0); }
-busyloop(n) { DELAY(n); }
+#define DELAY(n) do { long N = (n); while (--N > 0); } while (0)
+#define busyloop(n) do { DELAY(n); } while (0)
+int
ven_dialer(num, acu)
- register char *num;
+ char *num;
char *acu;
{
- register char *cp;
- register int connected = 0;
- char *msg, *index(), line[80];
- static int gobble(), vensync();
- static void echo();
+ char *cp;
+ int connected = 0;
+ char *msg, line[80];
+ struct termios cntrl;
/*
* Get in synch with a couple of carriage returns
*/
if (!vensync(FD)) {
printf("can't synchronize with ventel\n");
-#if ACULOG
+#ifdef ACULOG
logent(value(HOST), num, "ventel", "can't synch up");
#endif
return (0);
@@ -86,7 +94,9 @@ ven_dialer(num, acu)
if (boolean(value(VERBOSE)))
printf("\ndialing...");
fflush(stdout);
- acu_hupcl ();
+ tcgetattr(FD, &cntrl);
+ cntrl.c_cflag |= HUPCL;
+ tcsetattr(FD, TCSANOW, &cntrl);
echo("#k$\r$\n$D$I$A$L$:$ ");
for (cp = num; *cp; cp++) {
delay(1, 10);
@@ -97,10 +107,10 @@ ven_dialer(num, acu)
gobble('\n', line);
if (gobble('\n', line))
connected = gobble('!', line);
- acu_flush ();
-#if ACULOG
+ tcflush(FD, TCIOFLUSH);
+#ifdef ACULOG
if (timeout) {
- sprintf(line, "%d second dial timeout",
+ (void)sprintf(line, "%ld second dial timeout",
number(value(DIALTIMEOUT)));
logent(value(HOST), num, "ventel", line);
}
@@ -110,10 +120,10 @@ ven_dialer(num, acu)
if (connected || timeout || !boolean(value(VERBOSE)))
return (connected);
/* call failed, parse response for user */
- cp = index(line, '\r');
+ cp = strchr(line, '\r');
if (cp)
*cp = '\0';
- for (cp = line; cp = index(cp, ' '); cp++)
+ for (cp = line; cp = strchr(cp, ' '); cp++)
if (cp[1] == ' ')
break;
if (cp) {
@@ -130,12 +140,14 @@ ven_dialer(num, acu)
return (connected);
}
+void
ven_disconnect()
{
close(FD);
}
+void
ven_abort()
{
@@ -145,7 +157,7 @@ ven_abort()
static void
echo(s)
- register char *s;
+ char *s;
{
char c;
@@ -177,10 +189,10 @@ sigALRM()
static int
gobble(match, response)
- register char match;
+ char match;
char response[];
{
- register char *cp = response;
+ char *cp = response;
sig_t f;
char c;
@@ -240,7 +252,7 @@ vensync(fd)
write(fd, "\r", 1);
sleep(2);
if (ioctl(fd, FIONREAD, (caddr_t)&nread) < 0) {
- warn("ioctl");
+ perror("tip: ioctl");
continue;
}
while (nread > 0) {
OpenPOWER on IntegriCloud