1 /* 2 * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 3 * Use is subject to license terms. 4 */ 5 6 /* 7 * Copyright (c) 1983 Regents of the University of California. 8 * All rights reserved. The Berkeley software License Agreement 9 * specifies the terms and conditions for redistribution. 10 */ 11 12 /* 13 * Dial the DF02-AC or DF03-AC 14 */ 15 16 #include "tip.h" 17 18 static sigjmp_buf Sjbuf; 19 static void timeout(void); 20 21 void df_disconnect(void); 22 int df_dialer(char *, char *, int); 23 24 int 25 df02_dialer(char *num, char *acu) 26 { 27 28 return (df_dialer(num, acu, 0)); 29 } 30 31 int 32 df03_dialer(char *num, char *acu) 33 { 34 35 return (df_dialer(num, acu, 1)); 36 } 37 38 /* ARGSUSED */ 39 int 40 df_dialer(char *num, char *acu, int df03) 41 { 42 int f = FD; 43 struct termios buf; 44 int speed = 0; 45 char c = '\0'; 46 47 (void) ioctl(f, TCGETS, &buf); 48 buf.c_cflag |= HUPCL; 49 (void) ioctl(f, TCSETS, &buf); 50 if (sigsetjmp(Sjbuf, 1)) { 51 (void) printf("connection timed out\r\n"); 52 df_disconnect(); 53 return (0); 54 } 55 if (boolean(value(VERBOSE))) 56 (void) printf("\ndialing..."); 57 (void) fflush(stdout); 58 #ifdef TIOCMSET 59 if (df03) { 60 int st = TIOCM_ST; /* secondary Transmit flag */ 61 62 (void) ioctl(f, TCGETS, &buf); 63 if (cfgetospeed(&buf) != B1200) { /* must dial at 1200 baud */ 64 speed = cfgetospeed(&buf); 65 (void) cfsetospeed(&buf, B0); 66 (void) cfsetispeed(&buf, B0); 67 (void) cfsetospeed(&buf, B1200); 68 (void) ioctl(f, TCSETSW, &buf); 69 /* clear ST for 300 baud */ 70 (void) ioctl(f, TIOCMBIC, &st); 71 } else 72 /* set ST for 1200 baud */ 73 (void) ioctl(f, TIOCMBIS, &st); 74 } 75 #endif 76 (void) signal(SIGALRM, (sig_handler_t)timeout); 77 (void) alarm(5 * strlen(num) + 10); 78 (void) ioctl(f, TCFLSH, TCOFLUSH); 79 (void) write(f, "\001", 1); 80 (void) sleep(1); 81 (void) write(f, "\002", 1); 82 (void) write(f, num, strlen(num)); 83 (void) read(f, &c, 1); 84 #ifdef TIOCMSET 85 if (df03 && speed) { 86 (void) cfsetospeed(&buf, B0); 87 (void) cfsetispeed(&buf, B0); 88 (void) cfsetospeed(&buf, speed); 89 (void) ioctl(f, TCSETSW, &buf); 90 } 91 #endif 92 return (c == 'A'); 93 } 94 95 void 96 df_disconnect(void) 97 { 98 99 (void) write(FD, "\001", 1); 100 (void) sleep(1); 101 (void) ioctl(FD, TCFLSH, TCOFLUSH); 102 } 103 104 void 105 df_abort(void) 106 { 107 108 df_disconnect(); 109 } 110 111 112 static void 113 timeout(void) 114 { 115 116 siglongjmp(Sjbuf, 1); 117 } 118