1 /* $NetBSD: df.c,v 1.8 2006/04/03 00:51:14 perry 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. 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. 18 * 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 29 * SUCH DAMAGE. 30 */ 31 32 #include <sys/cdefs.h> 33 #ifndef lint 34 #if 0 35 static char sccsid[] = "@(#)df.c 8.1 (Berkeley) 6/6/93"; 36 #endif 37 __RCSID("$NetBSD: df.c,v 1.8 2006/04/03 00:51:14 perry Exp $"); 38 #endif /* not lint */ 39 40 /* 41 * Dial the DF02-AC or DF03-AC 42 */ 43 44 #include "tip.h" 45 46 static jmp_buf Sjbuf; 47 48 static int df_dialer(char *, char *, int); 49 static void timeout(int); 50 51 int 52 df02_dialer(char *num, char *acu) 53 { 54 55 return (df_dialer(num, acu, 0)); 56 } 57 58 int 59 df03_dialer(char *num, char *acu) 60 { 61 62 return (df_dialer(num, acu, 1)); 63 } 64 65 static int 66 df_dialer(char *num, char *acu, int df03) 67 { 68 int f = FD; 69 struct termios cntrl; 70 int spd = 0; 71 char c = '\0'; 72 73 #if __GNUC__ /* XXX pacify gcc */ 74 (void)&spd; 75 #endif 76 77 tcgetattr(f, &cntrl); 78 cntrl.c_cflag |= HUPCL; 79 tcsetattr(f, TCSANOW, &cntrl); 80 if (setjmp(Sjbuf)) { 81 printf("connection timed out\r\n"); 82 df_disconnect(); 83 return (0); 84 } 85 if (boolean(value(VERBOSE))) 86 printf("\ndialing..."); 87 fflush(stdout); 88 #ifdef TIOCMSET 89 if (df03) { 90 int st = TIOCM_ST; /* secondary Transmit flag */ 91 92 tcgetattr(f, &cntrl); 93 spd = cfgetospeed(&cntrl); 94 if (spd != B1200) { /* must dial at 1200 baud */ 95 cfsetospeed(&cntrl, B1200); 96 cfsetispeed(&cntrl, B1200); 97 tcsetattr(f, TCSAFLUSH, &cntrl); 98 ioctl(f, TIOCMBIC, &st); /* clear ST for 300 baud */ 99 } else 100 ioctl(f, TIOCMBIS, &st); /* set ST for 1200 baud */ 101 } 102 #endif 103 signal(SIGALRM, timeout); 104 alarm(5 * strlen(num) + 10); 105 tcflush(f, TCIOFLUSH); 106 write(f, "\001", 1); 107 sleep(1); 108 write(f, "\002", 1); 109 write(f, num, strlen(num)); 110 read(f, &c, 1); 111 #ifdef TIOCMSET 112 if (df03 && spd != B1200) { 113 cfsetospeed(&cntrl, spd); 114 cfsetispeed(&cntrl, spd); 115 tcsetattr(f, TCSAFLUSH, &cntrl); 116 } 117 #endif 118 return (c == 'A'); 119 } 120 121 void 122 df_disconnect(void) 123 { 124 125 write(FD, "\001", 1); 126 sleep(1); 127 tcflush(FD, TCIOFLUSH); 128 } 129 130 131 void 132 df_abort(void) 133 { 134 135 df_disconnect(); 136 } 137 138 139 static void 140 timeout(int dummy) 141 { 142 143 longjmp(Sjbuf, 1); 144 } 145