1 /* $OpenBSD: v831.c,v 1.11 2006/03/17 19:17:13 moritz Exp $ */
2 /* $NetBSD: v831.c,v 1.5 1996/12/29 10:42:01 cgd Exp $ */
5 * SPDX-License-Identifier: BSD-3-Clause
7 * Copyright (c) 1983, 1993
8 * The Regents of the University of California. All rights reserved.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 #include <sys/cdefs.h>
36 __FBSDID("$FreeBSD$");
40 static char sccsid[] = "@(#)v831.c 8.1 (Berkeley) 6/6/93";
41 static const char rcsid[] = "$OpenBSD: v831.c,v 1.11 2006/03/17 19:17:13 moritz Exp $";
46 * Routines for dialing up on Vadic 831
51 static jmp_buf jmpbuf;
52 static pid_t child = -1;
54 static void alarmtr(int);
55 static int dialit(char *, char *);
56 static char * sanitize(char *);
59 v831_dialer(char *num, char *acu)
65 if (boolean(value(VERBOSE)))
66 printf("\nstarting call...");
68 printf ("(acu=%s)\n", acu);
70 if ((AC = open(acu, O_RDWR)) < 0) {
72 printf("line busy...");
74 printf("acu open error...");
82 signal(SIGALRM, alarmtr);
83 timelim = 5 * strlen(num);
84 alarm(timelim < 30 ? 30 : timelim);
85 if ((child = fork()) == 0) {
87 * ignore this stuff for aborts
89 signal(SIGALRM, SIG_IGN);
90 signal(SIGINT, SIG_IGN);
91 signal(SIGQUIT, SIG_IGN);
93 exit(dialit(num, acu) != 'A');
96 * open line - will return on carrier
98 if ((FD = open(DV, O_RDWR)) < 0) {
100 printf("(after open, errno=%d)\n", errno);
103 printf("lost carrier...");
105 printf("dialup line open failed...");
107 kill(child, SIGKILL);
112 signal(SIGALRM, SIG_DFL);
113 while ((pid = wait(&status)) != child && pid != -1)
131 * Insurance, for some reason we don't seem to be
135 v831_disconnect(void)
137 struct termios cntrl;
141 printf("[disconnect: FD=%d]\n", FD);
144 ioctl(FD, TIOCCDTR, 0);
145 tcgetattr(FD, &cntrl);
146 cfsetospeed(&cntrl, 0);
147 cfsetispeed(&cntrl, 0);
148 tcsetattr(FD, TCSAFLUSH, &cntrl);
149 ioctl(FD, TIOCNXCL, NULL);
158 printf("[abort: AC=%d]\n", AC);
162 kill(child, SIGKILL);
164 ioctl(FD, TIOCNXCL, NULL);
167 ioctl(FD, TIOCCDTR, 0);
172 * Sigh, this probably must be changed at each site.
179 { "/dev/cua0",'4','0' },
180 { "/dev/cua1",'4','1' },
184 #define pc(x) (c = x, write(AC,&c,1))
191 dialit(char *phonenum, char *acu)
194 struct termios cntrl;
198 phonenum = sanitize(phonenum);
200 printf ("(dial phonenum=%s)\n", phonenum);
202 if (*phonenum == '<' && phonenum[1] == 0)
204 for (vp = vaconfig; vp->vc_name; vp++)
205 if (strcmp(vp->vc_name, acu) == 0)
207 if (vp->vc_name == 0) {
208 printf("Unable to locate dialer (%s)\n", acu);
211 tcgetattr(AC, &cntrl);
212 cfsetospeed(&cntrl, B2400);
213 cfsetispeed(&cntrl, B2400);
214 cntrl.c_cflag |= PARODD | PARENB;
215 cntrl.c_lflag &= ~(ISIG | ICANON);
216 tcsetattr(AC, TCSANOW, &cntrl);
217 tcflush(AC, TCIOFLUSH);
221 while (*phonenum && *phonenum != '<')
228 printf("read %d chars, char=%c, errno %d\n", i, c, errno);
232 if (c == 'B' || c == 'G') {
238 printf("abort response=%c\n", cc);
245 printf("dialit: returns %c\n", c);
253 static char buf[128];
256 for (cp = buf; *s; s++) {
257 if (!isdigit(*s) && *s == '<' && *s != '_')