1 /* $NetBSD: v831.c,v 1.11 2006/04/03 00:51:14 perry Exp $ */
4 * Copyright (c) 1983, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <sys/cdefs.h>
35 static char sccsid
[] = "@(#)v831.c 8.1 (Berkeley) 6/6/93";
37 __RCSID("$NetBSD: v831.c,v 1.11 2006/04/03 00:51:14 perry Exp $");
41 * Routines for dialing up on Vadic 831
45 static jmp_buf jmpbuf
;
46 static int child
= -1;
48 static void alarmtr(int);
49 static int dialit(char *, char *);
50 static char *sanitize(char *);
53 v831_dialer(char *num
, char *acu
)
58 if (boolean(value(VERBOSE
)))
59 (void)printf("\nstarting call...");
61 (void)printf("(acu=%s)\n", acu
);
63 if ((AC
= open(acu
, O_RDWR
)) < 0) {
65 (void)printf("line busy...");
67 (void)printf("acu open error...");
71 (void)kill(child
, SIGKILL
);
75 (void)signal(SIGALRM
, alarmtr
);
76 timelim
= 5 * strlen(num
);
77 (void)alarm((unsigned)(timelim
< 30 ? 30 : timelim
));
78 if ((child
= fork()) == 0) {
80 * ignore this stuff for aborts
82 (void)signal(SIGALRM
, SIG_IGN
);
83 (void)signal(SIGINT
, SIG_IGN
);
84 (void)signal(SIGQUIT
, SIG_IGN
);
86 exit(dialit(num
, acu
) != 'A');
89 * open line - will return on carrier
91 if ((FD
= open(DV
, O_RDWR
)) < 0) {
93 (void)printf("(after open, errno=%d)\n", errno
);
96 (void)printf("lost carrier...");
98 (void)printf("dialup line open failed...");
100 (void)kill(child
, SIGKILL
);
105 (void)signal(SIGALRM
, SIG_DFL
);
106 while ((mypid
= wait(&status
)) != child
&& mypid
!= -1)
117 alarmtr(int dummy __unused
)
125 * Insurance, for some reason we don't seem to be
129 v831_disconnect(void)
131 struct termios cntrl
;
135 (void)printf("[disconnect: FD=%d]\n", FD
);
138 (void)ioctl(FD
, TIOCCDTR
, 0);
139 (void)tcgetattr(FD
, &cntrl
);
140 (void)cfsetospeed(&cntrl
, 0);
141 (void)cfsetispeed(&cntrl
, 0);
142 (void)tcsetattr(FD
, TCSAFLUSH
, &cntrl
);
143 (void)ioctl(FD
, TIOCNXCL
, NULL
);
153 (void)printf("[abort: AC=%d]\n", AC
);
157 (void)kill(child
, SIGKILL
);
159 (void)ioctl(FD
, TIOCNXCL
, NULL
);
162 (void)ioctl(FD
, TIOCCDTR
, 0);
167 * Sigh, this probably must be changed at each site.
174 { "/dev/cua0",'4','0' },
175 { "/dev/cua1",'4','1' },
179 #define pc(x) (void)(c = x, write(AC,&c,1))
186 dialit(char *phonenum
, char *acu
)
189 struct termios cntrl
;
193 phonenum
= sanitize(phonenum
);
195 (void)printf("(dial phonenum=%s)\n", phonenum
);
197 if (*phonenum
== '<' && phonenum
[1] == 0)
199 for (vp
= vaconfig
; vp
->vc_name
; vp
++)
200 if (strcmp(vp
->vc_name
, acu
) == 0)
202 if (vp
->vc_name
== 0) {
203 (void)printf("Unable to locate dialer (%s)\n", acu
);
206 (void)tcgetattr(AC
, &cntrl
);
207 (void)cfsetospeed(&cntrl
, B2400
);
208 (void)cfsetispeed(&cntrl
, B2400
);
209 cntrl
.c_cflag
|= PARODD
| PARENB
;
210 cntrl
.c_lflag
&= ~(ISIG
| ICANON
);
211 (void)tcsetattr(AC
, TCSANOW
, &cntrl
);
212 (void)tcflush(AC
, TCIOFLUSH
);
216 while (*phonenum
&& *phonenum
!= '<')
223 (void)printf("read %d chars, char=%c, errno %d\n", i
, c
, errno
);
227 if (c
== 'B' || c
== 'G') {
231 (void)read(AC
, &cc
, 1);
233 (void)printf("abort response=%c\n", cc
);
240 (void)printf("dialit: returns %c\n", c
);
248 static char buf
[128];
251 for (cp
= buf
; *s
&& buf
+ sizeof buf
- cp
> 1; s
++) {
252 if (!isdigit((unsigned char)*s
) && *s
== '<' && *s
!= '_')