2016-06-30 08:56:46 +03:00
|
|
|
/* $NetBSD: v831.c,v 1.13 2016/06/30 05:56:46 dholland Exp $ */
|
1994-12-08 12:30:36 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
1994-12-08 12:30:36 +03:00
|
|
|
* Copyright (c) 1983, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
|
|
|
* 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.
|
2003-08-07 15:13:06 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1993-03-21 12:45:37 +03:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
1997-11-22 10:28:39 +03:00
|
|
|
#include <sys/cdefs.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#ifndef lint
|
1994-12-08 12:30:36 +03:00
|
|
|
#if 0
|
|
|
|
static char sccsid[] = "@(#)v831.c 8.1 (Berkeley) 6/6/93";
|
|
|
|
#endif
|
2016-06-30 08:56:46 +03:00
|
|
|
__RCSID("$NetBSD: v831.c,v 1.13 2016/06/30 05:56:46 dholland Exp $");
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Routines for dialing up on Vadic 831
|
|
|
|
*/
|
|
|
|
#include "tip.h"
|
|
|
|
|
|
|
|
static jmp_buf jmpbuf;
|
|
|
|
static int child = -1;
|
|
|
|
|
2006-04-03 04:51:13 +04:00
|
|
|
static void alarmtr(int);
|
|
|
|
static int dialit(char *, char *);
|
|
|
|
static char *sanitize(char *);
|
1997-11-22 10:28:39 +03:00
|
|
|
|
|
|
|
int
|
2006-04-03 04:51:13 +04:00
|
|
|
v831_dialer(char *num, char *acu)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2004-04-24 02:11:44 +04:00
|
|
|
int status, mypid;
|
1997-11-22 10:28:39 +03:00
|
|
|
int timelim;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
if (boolean(value(VERBOSE)))
|
2006-12-14 20:09:43 +03:00
|
|
|
(void)printf("\nstarting call...");
|
1993-03-21 12:45:37 +03:00
|
|
|
#ifdef DEBUG
|
2006-12-14 20:09:43 +03:00
|
|
|
(void)printf("(acu=%s)\n", acu);
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif
|
|
|
|
if ((AC = open(acu, O_RDWR)) < 0) {
|
|
|
|
if (errno == EBUSY)
|
2006-12-14 20:09:43 +03:00
|
|
|
(void)printf("line busy...");
|
1993-03-21 12:45:37 +03:00
|
|
|
else
|
2006-12-14 20:09:43 +03:00
|
|
|
(void)printf("acu open error...");
|
1993-03-21 12:45:37 +03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
if (setjmp(jmpbuf)) {
|
2006-12-14 20:09:43 +03:00
|
|
|
(void)kill(child, SIGKILL);
|
|
|
|
(void)close(AC);
|
1993-03-21 12:45:37 +03:00
|
|
|
return (0);
|
|
|
|
}
|
2006-12-14 20:09:43 +03:00
|
|
|
(void)signal(SIGALRM, alarmtr);
|
1993-03-21 12:45:37 +03:00
|
|
|
timelim = 5 * strlen(num);
|
2006-12-14 20:09:43 +03:00
|
|
|
(void)alarm((unsigned)(timelim < 30 ? 30 : timelim));
|
1993-03-21 12:45:37 +03:00
|
|
|
if ((child = fork()) == 0) {
|
|
|
|
/*
|
|
|
|
* ignore this stuff for aborts
|
|
|
|
*/
|
2006-12-14 20:09:43 +03:00
|
|
|
(void)signal(SIGALRM, SIG_IGN);
|
|
|
|
(void)signal(SIGINT, SIG_IGN);
|
|
|
|
(void)signal(SIGQUIT, SIG_IGN);
|
|
|
|
(void)sleep(2);
|
1993-03-21 12:45:37 +03:00
|
|
|
exit(dialit(num, acu) != 'A');
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* open line - will return on carrier
|
|
|
|
*/
|
|
|
|
if ((FD = open(DV, O_RDWR)) < 0) {
|
|
|
|
#ifdef DEBUG
|
2006-12-14 20:09:43 +03:00
|
|
|
(void)printf("(after open, errno=%d)\n", errno);
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif
|
|
|
|
if (errno == EIO)
|
2006-12-14 20:09:43 +03:00
|
|
|
(void)printf("lost carrier...");
|
1993-03-21 12:45:37 +03:00
|
|
|
else
|
2006-12-14 20:09:43 +03:00
|
|
|
(void)printf("dialup line open failed...");
|
|
|
|
(void)alarm(0);
|
|
|
|
(void)kill(child, SIGKILL);
|
|
|
|
(void)close(AC);
|
1993-03-21 12:45:37 +03:00
|
|
|
return (0);
|
|
|
|
}
|
2006-12-14 20:09:43 +03:00
|
|
|
(void)alarm(0);
|
|
|
|
(void)signal(SIGALRM, SIG_DFL);
|
2004-04-24 02:11:44 +04:00
|
|
|
while ((mypid = wait(&status)) != child && mypid != -1)
|
1993-03-21 12:45:37 +03:00
|
|
|
;
|
|
|
|
if (status) {
|
2006-12-14 20:09:43 +03:00
|
|
|
(void)close(AC);
|
1993-03-21 12:45:37 +03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-12-14 20:09:43 +03:00
|
|
|
/*ARGSUSED*/
|
|
|
|
alarmtr(int dummy __unused)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1998-07-12 13:14:19 +04:00
|
|
|
|
2006-12-14 20:09:43 +03:00
|
|
|
(void)alarm(0);
|
1993-03-21 12:45:37 +03:00
|
|
|
longjmp(jmpbuf, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Insurance, for some reason we don't seem to be
|
|
|
|
* hanging up...
|
|
|
|
*/
|
1997-11-22 10:28:39 +03:00
|
|
|
void
|
2006-04-03 04:51:13 +04:00
|
|
|
v831_disconnect(void)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1995-10-29 03:49:38 +03:00
|
|
|
struct termios cntrl;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2006-12-14 20:09:43 +03:00
|
|
|
(void)sleep(2);
|
1993-03-21 12:45:37 +03:00
|
|
|
#ifdef DEBUG
|
2006-12-14 20:09:43 +03:00
|
|
|
(void)printf("[disconnect: FD=%d]\n", FD);
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif
|
|
|
|
if (FD > 0) {
|
2006-12-14 20:09:43 +03:00
|
|
|
(void)ioctl(FD, TIOCCDTR, 0);
|
|
|
|
(void)tcgetattr(FD, &cntrl);
|
|
|
|
(void)cfsetospeed(&cntrl, 0);
|
|
|
|
(void)cfsetispeed(&cntrl, 0);
|
|
|
|
(void)tcsetattr(FD, TCSAFLUSH, &cntrl);
|
|
|
|
(void)ioctl(FD, TIOCNXCL, NULL);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
2006-12-14 20:09:43 +03:00
|
|
|
(void)close(FD);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1997-11-22 10:28:39 +03:00
|
|
|
void
|
2006-04-03 04:51:13 +04:00
|
|
|
v831_abort(void)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2006-12-14 20:09:43 +03:00
|
|
|
(void)printf("[abort: AC=%d]\n", AC);
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif
|
2006-12-14 20:09:43 +03:00
|
|
|
(void)sleep(2);
|
1993-03-21 12:45:37 +03:00
|
|
|
if (child > 0)
|
2006-12-14 20:09:43 +03:00
|
|
|
(void)kill(child, SIGKILL);
|
1993-03-21 12:45:37 +03:00
|
|
|
if (AC > 0)
|
2006-12-14 20:09:43 +03:00
|
|
|
(void)ioctl(FD, TIOCNXCL, NULL);
|
|
|
|
(void)close(AC);
|
1993-03-21 12:45:37 +03:00
|
|
|
if (FD > 0)
|
2006-12-14 20:09:43 +03:00
|
|
|
(void)ioctl(FD, TIOCCDTR, 0);
|
|
|
|
(void)close(FD);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Sigh, this probably must be changed at each site.
|
|
|
|
*/
|
|
|
|
struct vaconfig {
|
2004-04-24 02:11:44 +04:00
|
|
|
const char *vc_name;
|
1993-03-21 12:45:37 +03:00
|
|
|
char vc_rack;
|
|
|
|
char vc_modem;
|
|
|
|
} vaconfig[] = {
|
|
|
|
{ "/dev/cua0",'4','0' },
|
|
|
|
{ "/dev/cua1",'4','1' },
|
2006-12-14 20:09:43 +03:00
|
|
|
{ 0, '\0', '\0' }
|
1993-03-21 12:45:37 +03:00
|
|
|
};
|
|
|
|
|
2006-12-14 20:09:43 +03:00
|
|
|
#define pc(x) (void)(c = x, write(AC,&c,1))
|
1993-03-21 12:45:37 +03:00
|
|
|
#define ABORT 01
|
|
|
|
#define SI 017
|
|
|
|
#define STX 02
|
|
|
|
#define ETX 03
|
|
|
|
|
|
|
|
static int
|
2006-04-03 04:51:13 +04:00
|
|
|
dialit(char *phonenum, char *acu)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-11-22 10:28:39 +03:00
|
|
|
struct vaconfig *vp;
|
1995-10-29 03:49:38 +03:00
|
|
|
struct termios cntrl;
|
1993-03-21 12:45:37 +03:00
|
|
|
char c;
|
1997-11-22 10:28:39 +03:00
|
|
|
int i;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
phonenum = sanitize(phonenum);
|
|
|
|
#ifdef DEBUG
|
2006-12-14 20:09:43 +03:00
|
|
|
(void)printf("(dial phonenum=%s)\n", phonenum);
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif
|
|
|
|
if (*phonenum == '<' && phonenum[1] == 0)
|
|
|
|
return ('Z');
|
|
|
|
for (vp = vaconfig; vp->vc_name; vp++)
|
|
|
|
if (strcmp(vp->vc_name, acu) == 0)
|
|
|
|
break;
|
|
|
|
if (vp->vc_name == 0) {
|
2006-12-14 20:09:43 +03:00
|
|
|
(void)printf("Unable to locate dialer (%s)\n", acu);
|
1993-03-21 12:45:37 +03:00
|
|
|
return ('K');
|
|
|
|
}
|
2006-12-14 20:09:43 +03:00
|
|
|
(void)tcgetattr(AC, &cntrl);
|
|
|
|
(void)cfsetospeed(&cntrl, B2400);
|
|
|
|
(void)cfsetispeed(&cntrl, B2400);
|
1995-10-29 03:49:38 +03:00
|
|
|
cntrl.c_cflag |= PARODD | PARENB;
|
|
|
|
cntrl.c_lflag &= ~(ISIG | ICANON);
|
2006-12-14 20:09:43 +03:00
|
|
|
(void)tcsetattr(AC, TCSANOW, &cntrl);
|
|
|
|
(void)tcflush(AC, TCIOFLUSH);
|
1993-03-21 12:45:37 +03:00
|
|
|
pc(STX);
|
|
|
|
pc(vp->vc_rack);
|
|
|
|
pc(vp->vc_modem);
|
|
|
|
while (*phonenum && *phonenum != '<')
|
|
|
|
pc(*phonenum++);
|
|
|
|
pc(SI);
|
|
|
|
pc(ETX);
|
2006-12-14 20:09:43 +03:00
|
|
|
(void)sleep(1);
|
1993-03-21 12:45:37 +03:00
|
|
|
i = read(AC, &c, 1);
|
|
|
|
#ifdef DEBUG
|
2006-12-14 20:09:43 +03:00
|
|
|
(void)printf("read %d chars, char=%c, errno %d\n", i, c, errno);
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif
|
|
|
|
if (i != 1)
|
|
|
|
c = 'M';
|
|
|
|
if (c == 'B' || c == 'G') {
|
|
|
|
char cc, oc = c;
|
|
|
|
|
|
|
|
pc(ABORT);
|
2006-12-14 20:09:43 +03:00
|
|
|
(void)read(AC, &cc, 1);
|
1993-03-21 12:45:37 +03:00
|
|
|
#ifdef DEBUG
|
2006-12-14 20:09:43 +03:00
|
|
|
(void)printf("abort response=%c\n", cc);
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif
|
|
|
|
c = oc;
|
|
|
|
v831_disconnect();
|
|
|
|
}
|
2006-12-14 20:09:43 +03:00
|
|
|
(void)close(AC);
|
1993-03-21 12:45:37 +03:00
|
|
|
#ifdef DEBUG
|
2006-12-14 20:09:43 +03:00
|
|
|
(void)printf("dialit: returns %c\n", c);
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif
|
|
|
|
return (c);
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
2006-04-03 04:51:13 +04:00
|
|
|
sanitize(char *s)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
static char buf[128];
|
1997-11-22 10:28:39 +03:00
|
|
|
char *cp;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1998-07-12 13:14:19 +04:00
|
|
|
for (cp = buf; *s && buf + sizeof buf - cp > 1; s++) {
|
2016-06-30 08:56:46 +03:00
|
|
|
if (!isdigit((unsigned char)*s) && *s != '<' && *s != '_')
|
1993-03-21 12:45:37 +03:00
|
|
|
continue;
|
|
|
|
if (*s == '_')
|
|
|
|
*s = '=';
|
|
|
|
*cp++ = *s;
|
|
|
|
}
|
|
|
|
*cp++ = 0;
|
|
|
|
return (buf);
|
|
|
|
}
|