Home | History | Annotate | Line # | Download | only in aculib
v831.c revision 1.3
      1  1.3  jtc /*	$NetBSD: v831.c,v 1.3 1994/12/08 09:31:50 jtc Exp $	*/
      2  1.3  jtc 
      3  1.1  cgd /*
      4  1.3  jtc  * Copyright (c) 1983, 1993
      5  1.3  jtc  *	The Regents of the University of California.  All rights reserved.
      6  1.1  cgd  *
      7  1.1  cgd  * Redistribution and use in source and binary forms, with or without
      8  1.1  cgd  * modification, are permitted provided that the following conditions
      9  1.1  cgd  * are met:
     10  1.1  cgd  * 1. Redistributions of source code must retain the above copyright
     11  1.1  cgd  *    notice, this list of conditions and the following disclaimer.
     12  1.1  cgd  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1  cgd  *    notice, this list of conditions and the following disclaimer in the
     14  1.1  cgd  *    documentation and/or other materials provided with the distribution.
     15  1.1  cgd  * 3. All advertising materials mentioning features or use of this software
     16  1.1  cgd  *    must display the following acknowledgement:
     17  1.1  cgd  *	This product includes software developed by the University of
     18  1.1  cgd  *	California, Berkeley and its contributors.
     19  1.1  cgd  * 4. Neither the name of the University nor the names of its contributors
     20  1.1  cgd  *    may be used to endorse or promote products derived from this software
     21  1.1  cgd  *    without specific prior written permission.
     22  1.1  cgd  *
     23  1.1  cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24  1.1  cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25  1.1  cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26  1.1  cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27  1.1  cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28  1.1  cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29  1.1  cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30  1.1  cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31  1.1  cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32  1.1  cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33  1.1  cgd  * SUCH DAMAGE.
     34  1.1  cgd  */
     35  1.1  cgd 
     36  1.1  cgd #ifndef lint
     37  1.3  jtc #if 0
     38  1.3  jtc static char sccsid[] = "@(#)v831.c	8.1 (Berkeley) 6/6/93";
     39  1.3  jtc #endif
     40  1.3  jtc static char rcsid[] = "$NetBSD: v831.c,v 1.3 1994/12/08 09:31:50 jtc Exp $";
     41  1.1  cgd #endif /* not lint */
     42  1.1  cgd 
     43  1.1  cgd /*
     44  1.1  cgd  * Routines for dialing up on Vadic 831
     45  1.1  cgd  */
     46  1.1  cgd #include "tip.h"
     47  1.1  cgd 
     48  1.1  cgd int	v831_abort();
     49  1.1  cgd static	void alarmtr();
     50  1.1  cgd extern	int errno;
     51  1.1  cgd 
     52  1.1  cgd static jmp_buf jmpbuf;
     53  1.1  cgd static int child = -1;
     54  1.1  cgd 
     55  1.1  cgd v831_dialer(num, acu)
     56  1.1  cgd         char *num, *acu;
     57  1.1  cgd {
     58  1.1  cgd         int status, pid, connected = 1;
     59  1.1  cgd         register int timelim;
     60  1.1  cgd 	static int dialit();
     61  1.1  cgd 
     62  1.1  cgd         if (boolean(value(VERBOSE)))
     63  1.1  cgd                 printf("\nstarting call...");
     64  1.1  cgd #ifdef DEBUG
     65  1.1  cgd         printf ("(acu=%s)\n", acu);
     66  1.1  cgd #endif
     67  1.1  cgd         if ((AC = open(acu, O_RDWR)) < 0) {
     68  1.1  cgd                 if (errno == EBUSY)
     69  1.1  cgd                         printf("line busy...");
     70  1.1  cgd                 else
     71  1.1  cgd                         printf("acu open error...");
     72  1.1  cgd                 return (0);
     73  1.1  cgd         }
     74  1.1  cgd         if (setjmp(jmpbuf)) {
     75  1.1  cgd                 kill(child, SIGKILL);
     76  1.1  cgd                 close(AC);
     77  1.1  cgd                 return (0);
     78  1.1  cgd         }
     79  1.1  cgd         signal(SIGALRM, alarmtr);
     80  1.1  cgd         timelim = 5 * strlen(num);
     81  1.1  cgd         alarm(timelim < 30 ? 30 : timelim);
     82  1.1  cgd         if ((child = fork()) == 0) {
     83  1.1  cgd                 /*
     84  1.1  cgd                  * ignore this stuff for aborts
     85  1.1  cgd                  */
     86  1.1  cgd                 signal(SIGALRM, SIG_IGN);
     87  1.1  cgd 		signal(SIGINT, SIG_IGN);
     88  1.1  cgd                 signal(SIGQUIT, SIG_IGN);
     89  1.1  cgd                 sleep(2);
     90  1.1  cgd                 exit(dialit(num, acu) != 'A');
     91  1.1  cgd         }
     92  1.1  cgd         /*
     93  1.1  cgd          * open line - will return on carrier
     94  1.1  cgd          */
     95  1.1  cgd         if ((FD = open(DV, O_RDWR)) < 0) {
     96  1.1  cgd #ifdef DEBUG
     97  1.1  cgd                 printf("(after open, errno=%d)\n", errno);
     98  1.1  cgd #endif
     99  1.1  cgd                 if (errno == EIO)
    100  1.1  cgd                         printf("lost carrier...");
    101  1.1  cgd                 else
    102  1.1  cgd                         printf("dialup line open failed...");
    103  1.1  cgd                 alarm(0);
    104  1.1  cgd                 kill(child, SIGKILL);
    105  1.1  cgd                 close(AC);
    106  1.1  cgd                 return (0);
    107  1.1  cgd         }
    108  1.1  cgd         alarm(0);
    109  1.1  cgd #ifdef notdef
    110  1.1  cgd         ioctl(AC, TIOCHPCL, 0);
    111  1.1  cgd #endif
    112  1.1  cgd         signal(SIGALRM, SIG_DFL);
    113  1.1  cgd         while ((pid = wait(&status)) != child && pid != -1)
    114  1.1  cgd                 ;
    115  1.1  cgd         if (status) {
    116  1.1  cgd                 close(AC);
    117  1.1  cgd                 return (0);
    118  1.1  cgd         }
    119  1.1  cgd         return (1);
    120  1.1  cgd }
    121  1.1  cgd 
    122  1.1  cgd static void
    123  1.1  cgd alarmtr()
    124  1.1  cgd {
    125  1.1  cgd         alarm(0);
    126  1.1  cgd         longjmp(jmpbuf, 1);
    127  1.1  cgd }
    128  1.1  cgd 
    129  1.1  cgd /*
    130  1.1  cgd  * Insurance, for some reason we don't seem to be
    131  1.1  cgd  *  hanging up...
    132  1.1  cgd  */
    133  1.1  cgd v831_disconnect()
    134  1.1  cgd {
    135  1.1  cgd         struct sgttyb cntrl;
    136  1.1  cgd 
    137  1.1  cgd         sleep(2);
    138  1.1  cgd #ifdef DEBUG
    139  1.1  cgd         printf("[disconnect: FD=%d]\n", FD);
    140  1.1  cgd #endif
    141  1.1  cgd         if (FD > 0) {
    142  1.1  cgd                 ioctl(FD, TIOCCDTR, 0);
    143  1.1  cgd                 ioctl(FD, TIOCGETP, &cntrl);
    144  1.1  cgd                 cntrl.sg_ispeed = cntrl.sg_ospeed = 0;
    145  1.1  cgd                 ioctl(FD, TIOCSETP, &cntrl);
    146  1.1  cgd                 ioctl(FD, TIOCNXCL, (struct sgttyb *)NULL);
    147  1.1  cgd         }
    148  1.1  cgd         close(FD);
    149  1.1  cgd }
    150  1.1  cgd 
    151  1.1  cgd v831_abort()
    152  1.1  cgd {
    153  1.1  cgd 
    154  1.1  cgd #ifdef DEBUG
    155  1.1  cgd         printf("[abort: AC=%d]\n", AC);
    156  1.1  cgd #endif
    157  1.1  cgd         sleep(2);
    158  1.1  cgd         if (child > 0)
    159  1.1  cgd                 kill(child, SIGKILL);
    160  1.1  cgd         if (AC > 0)
    161  1.1  cgd                 ioctl(FD, TIOCNXCL, (struct sgttyb *)NULL);
    162  1.1  cgd                 close(AC);
    163  1.1  cgd         if (FD > 0)
    164  1.1  cgd                 ioctl(FD, TIOCCDTR, 0);
    165  1.1  cgd         close(FD);
    166  1.1  cgd }
    167  1.1  cgd 
    168  1.1  cgd /*
    169  1.1  cgd  * Sigh, this probably must be changed at each site.
    170  1.1  cgd  */
    171  1.1  cgd struct vaconfig {
    172  1.1  cgd 	char	*vc_name;
    173  1.1  cgd 	char	vc_rack;
    174  1.1  cgd 	char	vc_modem;
    175  1.1  cgd } vaconfig[] = {
    176  1.1  cgd 	{ "/dev/cua0",'4','0' },
    177  1.1  cgd 	{ "/dev/cua1",'4','1' },
    178  1.1  cgd 	{ 0 }
    179  1.1  cgd };
    180  1.1  cgd 
    181  1.1  cgd #define pc(x)	(c = x, write(AC,&c,1))
    182  1.1  cgd #define ABORT	01
    183  1.1  cgd #define SI	017
    184  1.1  cgd #define STX	02
    185  1.1  cgd #define ETX	03
    186  1.1  cgd 
    187  1.1  cgd static int
    188  1.1  cgd dialit(phonenum, acu)
    189  1.1  cgd 	register char *phonenum;
    190  1.1  cgd 	char *acu;
    191  1.1  cgd {
    192  1.1  cgd         register struct vaconfig *vp;
    193  1.1  cgd 	struct sgttyb cntrl;
    194  1.1  cgd         char c;
    195  1.1  cgd         int i, two = 2;
    196  1.1  cgd 	static char *sanitize();
    197  1.1  cgd 
    198  1.1  cgd         phonenum = sanitize(phonenum);
    199  1.1  cgd #ifdef DEBUG
    200  1.1  cgd         printf ("(dial phonenum=%s)\n", phonenum);
    201  1.1  cgd #endif
    202  1.1  cgd         if (*phonenum == '<' && phonenum[1] == 0)
    203  1.1  cgd                 return ('Z');
    204  1.1  cgd 	for (vp = vaconfig; vp->vc_name; vp++)
    205  1.1  cgd 		if (strcmp(vp->vc_name, acu) == 0)
    206  1.1  cgd 			break;
    207  1.1  cgd 	if (vp->vc_name == 0) {
    208  1.1  cgd 		printf("Unable to locate dialer (%s)\n", acu);
    209  1.1  cgd 		return ('K');
    210  1.1  cgd 	}
    211  1.1  cgd         ioctl(AC, TIOCGETP, &cntrl);
    212  1.1  cgd         cntrl.sg_ispeed = cntrl.sg_ospeed = B2400;
    213  1.1  cgd         cntrl.sg_flags = RAW | EVENP | ODDP;
    214  1.1  cgd         ioctl(AC, TIOCSETP, &cntrl);
    215  1.1  cgd 	ioctl(AC, TIOCFLUSH, &two);
    216  1.1  cgd         pc(STX);
    217  1.1  cgd 	pc(vp->vc_rack);
    218  1.1  cgd 	pc(vp->vc_modem);
    219  1.1  cgd 	while (*phonenum && *phonenum != '<')
    220  1.1  cgd 		pc(*phonenum++);
    221  1.1  cgd         pc(SI);
    222  1.1  cgd 	pc(ETX);
    223  1.1  cgd         sleep(1);
    224  1.1  cgd         i = read(AC, &c, 1);
    225  1.1  cgd #ifdef DEBUG
    226  1.1  cgd         printf("read %d chars, char=%c, errno %d\n", i, c, errno);
    227  1.1  cgd #endif
    228  1.1  cgd         if (i != 1)
    229  1.1  cgd 		c = 'M';
    230  1.1  cgd         if (c == 'B' || c == 'G') {
    231  1.1  cgd                 char cc, oc = c;
    232  1.1  cgd 
    233  1.1  cgd                 pc(ABORT);
    234  1.1  cgd                 read(AC, &cc, 1);
    235  1.1  cgd #ifdef DEBUG
    236  1.1  cgd                 printf("abort response=%c\n", cc);
    237  1.1  cgd #endif
    238  1.1  cgd                 c = oc;
    239  1.1  cgd                 v831_disconnect();
    240  1.1  cgd         }
    241  1.1  cgd         close(AC);
    242  1.1  cgd #ifdef DEBUG
    243  1.1  cgd         printf("dialit: returns %c\n", c);
    244  1.1  cgd #endif
    245  1.1  cgd         return (c);
    246  1.1  cgd }
    247  1.1  cgd 
    248  1.1  cgd static char *
    249  1.1  cgd sanitize(s)
    250  1.1  cgd 	register char *s;
    251  1.1  cgd {
    252  1.1  cgd         static char buf[128];
    253  1.1  cgd         register char *cp;
    254  1.1  cgd 
    255  1.1  cgd         for (cp = buf; *s; s++) {
    256  1.1  cgd 		if (!isdigit(*s) && *s == '<' && *s != '_')
    257  1.1  cgd 			continue;
    258  1.1  cgd 		if (*s == '_')
    259  1.1  cgd 			*s = '=';
    260  1.1  cgd 		*cp++ = *s;
    261  1.1  cgd 	}
    262  1.1  cgd         *cp++ = 0;
    263  1.1  cgd         return (buf);
    264  1.1  cgd }
    265