1 /* $NetBSD: df.c,v 1.5 1997/11/22 07:28:54 lukem Exp $ */ 2 3 /* 4 * Copyright (c) 1983, 1993 5 * The Regents of the University of California. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 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. All advertising materials mentioning features or use of this software 16 * must display the following acknowledgement: 17 * This product includes software developed by the University of 18 * California, Berkeley and its contributors. 19 * 4. Neither the name of the University nor the names of its contributors 20 * may be used to endorse or promote products derived from this software 21 * without specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * SUCH DAMAGE. 34 */ 35 36 #include <sys/cdefs.h> 37 #ifndef lint 38 #if 0 39 static char sccsid[] = "@(#)df.c 8.1 (Berkeley) 6/6/93"; 40 #endif 41 __RCSID("$NetBSD: df.c,v 1.5 1997/11/22 07:28:54 lukem Exp $"); 42 #endif /* not lint */ 43 44 /* 45 * Dial the DF02-AC or DF03-AC 46 */ 47 48 #include "tip.h" 49 50 static jmp_buf Sjbuf; 51 52 static int df_dialer __P((char *, char *, int)); 53 static void timeout __P((int)); 54 55 int 56 df02_dialer(num, acu) 57 char *num, *acu; 58 { 59 60 return (df_dialer(num, acu, 0)); 61 } 62 63 int 64 df03_dialer(num, acu) 65 char *num, *acu; 66 { 67 68 return (df_dialer(num, acu, 1)); 69 } 70 71 static int 72 df_dialer(num, acu, df03) 73 char *num, *acu; 74 int df03; 75 { 76 int f = FD; 77 struct termios cntrl; 78 int speed = 0; 79 char c = '\0'; 80 81 #if __GNUC__ /* XXX pacify gcc */ 82 (void)&speed; 83 #endif 84 85 tcgetattr(f, &cntrl); 86 cntrl.c_cflag |= HUPCL; 87 tcsetattr(f, TCSANOW, &cntrl); 88 if (setjmp(Sjbuf)) { 89 printf("connection timed out\r\n"); 90 df_disconnect(); 91 return (0); 92 } 93 if (boolean(value(VERBOSE))) 94 printf("\ndialing..."); 95 fflush(stdout); 96 #ifdef TIOCMSET 97 if (df03) { 98 int st = TIOCM_ST; /* secondary Transmit flag */ 99 100 tcgetattr(f, &cntrl); 101 speed = cfgetospeed(&cntrl); 102 if (speed != B1200) { /* must dial at 1200 baud */ 103 cfsetospeed(&cntrl, B1200); 104 cfsetispeed(&cntrl, B1200); 105 tcsetattr(f, TCSAFLUSH, &cntrl); 106 ioctl(f, TIOCMBIC, &st); /* clear ST for 300 baud */ 107 } else 108 ioctl(f, TIOCMBIS, &st); /* set ST for 1200 baud */ 109 } 110 #endif 111 signal(SIGALRM, timeout); 112 alarm(5 * strlen(num) + 10); 113 tcflush(f, TCIOFLUSH); 114 write(f, "\001", 1); 115 sleep(1); 116 write(f, "\002", 1); 117 write(f, num, strlen(num)); 118 read(f, &c, 1); 119 #ifdef TIOCMSET 120 if (df03 && speed != B1200) { 121 cfsetospeed(&cntrl, speed); 122 cfsetispeed(&cntrl, speed); 123 tcsetattr(f, TCSAFLUSH, &cntrl); 124 } 125 #endif 126 return (c == 'A'); 127 } 128 129 void 130 df_disconnect() 131 { 132 133 write(FD, "\001", 1); 134 sleep(1); 135 tcflush(FD, TCIOFLUSH); 136 } 137 138 139 void 140 df_abort() 141 { 142 143 df_disconnect(); 144 } 145 146 147 static void 148 timeout(dummy) 149 int dummy; 150 { 151 152 longjmp(Sjbuf, 1); 153 } 154