1 /* 2 * Copyright (c) 2000 by Sun Microsystems, Inc. 3 * All rights reserved. 4 */ 5 6 /* from UCB 4.4 6/25/83 */ 7 /* 8 * Copyright (c) 1983 Regents of the University of California. 9 * All rights reserved. The Berkeley software License Agreement 10 * specifies the terms and conditions for redistribution. 11 */ 12 #pragma ident "%Z%%M% %I% %E% SMI" 13 14 #include "tip.h" 15 16 #define DISCONNECT_CMD "\20\04" /* disconnection string */ 17 18 static void sigALRM(); 19 static int timeout = 0; 20 static sigjmp_buf timeoutbuf; 21 22 /* 23 * Dial up on a BIZCOMP Model 1022 with either 24 * tone dialing (mod = "V") 25 * pulse dialing (mod = "W") 26 */ 27 static int 28 biz_dialer(num, mod) 29 char *num, *mod; 30 { 31 register int connected = 0; 32 char cbuf[40]; 33 34 if (boolean(value(VERBOSE))) 35 printf("\nstarting call..."); 36 /* 37 * Disable auto-answer and configure for tone/pulse 38 * dialing 39 */ 40 if (cmd("\02K\r")) { 41 printf("can't initialize bizcomp..."); 42 return (0); 43 } 44 strcpy(cbuf, "\02.\r"); 45 cbuf[1] = *mod; 46 if (cmd(cbuf)) { 47 printf("can't set dialing mode..."); 48 return (0); 49 } 50 strcpy(cbuf, "\02D"); 51 strlcat(cbuf, num, sizeof (cbuf)); 52 strlcat(cbuf, "\r", sizeof (cbuf)); 53 write(FD, cbuf, strlen(cbuf)); 54 if (!detect("7\r")) { 55 printf("can't get dial tone..."); 56 return (0); 57 } 58 if (boolean(value(VERBOSE))) 59 printf("ringing..."); 60 /* 61 * The reply from the BIZCOMP should be: 62 * 2 \r or 7 \r failure 63 * 1 \r success 64 */ 65 connected = detect("1\r"); 66 #ifdef ACULOG 67 if (timeout) { 68 char line[80]; 69 70 sprintf(line, "%d second dial timeout", 71 number(value(DIALTIMEOUT))); 72 logent(value(HOST), num, "biz1022", line); 73 } 74 #endif 75 if (timeout) 76 biz22_disconnect(); /* insurance */ 77 return (connected); 78 } 79 80 biz22w_dialer(num, acu) 81 char *num, *acu; 82 { 83 84 return (biz_dialer(num, "W")); 85 } 86 87 biz22f_dialer(num, acu) 88 char *num, *acu; 89 { 90 91 return (biz_dialer(num, "V")); 92 } 93 94 biz22_disconnect() 95 { 96 97 write(FD, DISCONNECT_CMD, 4); 98 sleep(2); 99 ioctl(FD, TCFLSH, TCOFLUSH); 100 } 101 102 biz22_abort() 103 { 104 105 write(FD, "\02", 1); 106 } 107 108 static void 109 sigALRM() 110 { 111 112 timeout = 1; 113 siglongjmp(timeoutbuf, 1); 114 } 115 116 static int 117 cmd(s) 118 register char *s; 119 { 120 char c; 121 sig_handler_t f; 122 123 write(FD, s, strlen(s)); 124 f = signal(SIGALRM, (sig_handler_t)sigALRM); 125 if (sigsetjmp(timeoutbuf, 1)) { 126 biz22_abort(); 127 signal(SIGALRM, f); 128 return (1); 129 } 130 alarm(number(value(DIALTIMEOUT))); 131 read(FD, &c, 1); 132 alarm(0); 133 signal(SIGALRM, f); 134 c &= 0177; 135 return (c != '\r'); 136 } 137 138 static int 139 detect(s) 140 register char *s; 141 { 142 char c; 143 sig_handler_t f; 144 145 f = signal(SIGALRM, (sig_handler_t)sigALRM); 146 timeout = 0; 147 while (*s) { 148 if (sigsetjmp(timeoutbuf, 1)) { 149 biz22_abort(); 150 break; 151 } 152 alarm(number(value(DIALTIMEOUT))); 153 read(FD, &c, 1); 154 alarm(0); 155 c &= 0177; 156 if (c != *s++) 157 return (0); 158 } 159 signal(SIGALRM, f); 160 return (timeout == 0); 161 } 162