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 * Copyright (c) 1983, 1993
6 * The Regents of the University of California. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
38 static char sccsid[] = "@(#)v831.c 8.1 (Berkeley) 6/6/93";
39 static const char rcsid[] = "$OpenBSD: v831.c,v 1.11 2006/03/17 19:17:13 moritz Exp $";
44 * Routines for dialing up on Vadic 831
49 static jmp_buf jmpbuf;
50 static pid_t child = -1;
52 static void alarmtr(int);
53 static int dialit(char *, char *);
54 static char * sanitize(char *);
57 v831_dialer(char *num, char *acu)
63 if (boolean(value(VERBOSE)))
64 printf("\nstarting call...");
66 printf ("(acu=%s)\n", acu);
68 if ((AC = open(acu, O_RDWR)) < 0) {
70 printf("line busy...");
72 printf("acu open error...");
80 signal(SIGALRM, alarmtr);
81 timelim = 5 * strlen(num);
82 alarm(timelim < 30 ? 30 : timelim);
83 if ((child = fork()) == 0) {
85 * ignore this stuff for aborts
87 signal(SIGALRM, SIG_IGN);
88 signal(SIGINT, SIG_IGN);
89 signal(SIGQUIT, SIG_IGN);
91 exit(dialit(num, acu) != 'A');
94 * open line - will return on carrier
96 if ((FD = open(DV, O_RDWR)) < 0) {
98 printf("(after open, errno=%d)\n", errno);
101 printf("lost carrier...");
103 printf("dialup line open failed...");
105 kill(child, SIGKILL);
110 signal(SIGALRM, SIG_DFL);
111 while ((pid = wait(&status)) != child && pid != -1)
129 * Insurance, for some reason we don't seem to be
133 v831_disconnect(void)
135 struct termios cntrl;
139 printf("[disconnect: FD=%d]\n", FD);
142 ioctl(FD, TIOCCDTR, 0);
143 tcgetattr(FD, &cntrl);
144 cfsetospeed(&cntrl, 0);
145 cfsetispeed(&cntrl, 0);
146 tcsetattr(FD, TCSAFLUSH, &cntrl);
147 ioctl(FD, TIOCNXCL, NULL);
156 printf("[abort: AC=%d]\n", AC);
160 kill(child, SIGKILL);
162 ioctl(FD, TIOCNXCL, NULL);
165 ioctl(FD, TIOCCDTR, 0);
170 * Sigh, this probably must be changed at each site.
177 { "/dev/cua0",'4','0' },
178 { "/dev/cua1",'4','1' },
182 #define pc(x) (c = x, write(AC,&c,1))
189 dialit(char *phonenum, char *acu)
192 struct termios cntrl;
196 phonenum = sanitize(phonenum);
198 printf ("(dial phonenum=%s)\n", phonenum);
200 if (*phonenum == '<' && phonenum[1] == 0)
202 for (vp = vaconfig; vp->vc_name; vp++)
203 if (strcmp(vp->vc_name, acu) == 0)
205 if (vp->vc_name == 0) {
206 printf("Unable to locate dialer (%s)\n", acu);
209 tcgetattr(AC, &cntrl);
210 cfsetospeed(&cntrl, B2400);
211 cfsetispeed(&cntrl, B2400);
212 cntrl.c_cflag |= PARODD | PARENB;
213 cntrl.c_lflag &= ~(ISIG | ICANON);
214 tcsetattr(AC, TCSANOW, &cntrl);
215 tcflush(AC, TCIOFLUSH);
219 while (*phonenum && *phonenum != '<')
226 printf("read %d chars, char=%c, errno %d\n", i, c, errno);
230 if (c == 'B' || c == 'G') {
236 printf("abort response=%c\n", cc);
243 printf("dialit: returns %c\n", c);
251 static char buf[128];
254 for (cp = buf; *s; s++) {
255 if (!isdigit(*s) && *s == '<' && *s != '_')