1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * Copyright (c) 2000 by Sun Microsystems, Inc. 3*7c478bd9Sstevel@tonic-gate * All rights reserved. 4*7c478bd9Sstevel@tonic-gate */ 5*7c478bd9Sstevel@tonic-gate 6*7c478bd9Sstevel@tonic-gate /* from UCB 4.4 6/25/83 */ 7*7c478bd9Sstevel@tonic-gate /* 8*7c478bd9Sstevel@tonic-gate * Copyright (c) 1983 Regents of the University of California. 9*7c478bd9Sstevel@tonic-gate * All rights reserved. The Berkeley software License Agreement 10*7c478bd9Sstevel@tonic-gate * specifies the terms and conditions for redistribution. 11*7c478bd9Sstevel@tonic-gate */ 12*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 13*7c478bd9Sstevel@tonic-gate 14*7c478bd9Sstevel@tonic-gate /* 15*7c478bd9Sstevel@tonic-gate * Routines for calling up on a Vadic 3451 Modem 16*7c478bd9Sstevel@tonic-gate */ 17*7c478bd9Sstevel@tonic-gate #include "tip.h" 18*7c478bd9Sstevel@tonic-gate 19*7c478bd9Sstevel@tonic-gate static sigjmp_buf Sjbuf; 20*7c478bd9Sstevel@tonic-gate 21*7c478bd9Sstevel@tonic-gate v3451_dialer(num, acu) 22*7c478bd9Sstevel@tonic-gate register char *num; 23*7c478bd9Sstevel@tonic-gate char *acu; 24*7c478bd9Sstevel@tonic-gate { 25*7c478bd9Sstevel@tonic-gate int ok; 26*7c478bd9Sstevel@tonic-gate void (*func)(); 27*7c478bd9Sstevel@tonic-gate struct termios buf; 28*7c478bd9Sstevel@tonic-gate int slow = number(value(BAUDRATE)) < 1200; 29*7c478bd9Sstevel@tonic-gate char phone[50]; 30*7c478bd9Sstevel@tonic-gate #ifdef ACULOG 31*7c478bd9Sstevel@tonic-gate char line[80]; 32*7c478bd9Sstevel@tonic-gate #endif 33*7c478bd9Sstevel@tonic-gate 34*7c478bd9Sstevel@tonic-gate /* 35*7c478bd9Sstevel@tonic-gate * Get in synch 36*7c478bd9Sstevel@tonic-gate */ 37*7c478bd9Sstevel@tonic-gate vawrite("I\r", 1 + slow); 38*7c478bd9Sstevel@tonic-gate vawrite("I\r", 1 + slow); 39*7c478bd9Sstevel@tonic-gate vawrite("I\r", 1 + slow); 40*7c478bd9Sstevel@tonic-gate vawrite("\005\r", 2 + slow); 41*7c478bd9Sstevel@tonic-gate if (!expect("READY")) { 42*7c478bd9Sstevel@tonic-gate printf("can't synchronize with vadic 3451\n"); 43*7c478bd9Sstevel@tonic-gate #ifdef ACULOG 44*7c478bd9Sstevel@tonic-gate logent(value(HOST), num, "vadic", "can't synch up"); 45*7c478bd9Sstevel@tonic-gate #endif 46*7c478bd9Sstevel@tonic-gate return (0); 47*7c478bd9Sstevel@tonic-gate } 48*7c478bd9Sstevel@tonic-gate ioctl(FD, TCGETS, &buf); 49*7c478bd9Sstevel@tonic-gate buf.c_cflag |= HUPCL; 50*7c478bd9Sstevel@tonic-gate ioctl(FD, TCSETSF, &buf); 51*7c478bd9Sstevel@tonic-gate sleep(1); 52*7c478bd9Sstevel@tonic-gate vawrite("D\r", 2 + slow); 53*7c478bd9Sstevel@tonic-gate if (!expect("NUMBER?")) { 54*7c478bd9Sstevel@tonic-gate printf("Vadic will not accept dial command\n"); 55*7c478bd9Sstevel@tonic-gate #ifdef ACULOG 56*7c478bd9Sstevel@tonic-gate logent(value(HOST), num, "vadic", "will not accept dial"); 57*7c478bd9Sstevel@tonic-gate #endif 58*7c478bd9Sstevel@tonic-gate return (0); 59*7c478bd9Sstevel@tonic-gate } 60*7c478bd9Sstevel@tonic-gate strlcpy(phone, num, sizeof (phone)); 61*7c478bd9Sstevel@tonic-gate strlcat(phone, "\r", sizeof (phone)); 62*7c478bd9Sstevel@tonic-gate vawrite(phone, 1 + slow); 63*7c478bd9Sstevel@tonic-gate if (!expect(phone)) { 64*7c478bd9Sstevel@tonic-gate printf("Vadic will not accept phone number\n"); 65*7c478bd9Sstevel@tonic-gate #ifdef ACULOG 66*7c478bd9Sstevel@tonic-gate logent(value(HOST), num, "vadic", "will not accept number"); 67*7c478bd9Sstevel@tonic-gate #endif 68*7c478bd9Sstevel@tonic-gate return (0); 69*7c478bd9Sstevel@tonic-gate } 70*7c478bd9Sstevel@tonic-gate func = signal(SIGINT, SIG_IGN); 71*7c478bd9Sstevel@tonic-gate /* 72*7c478bd9Sstevel@tonic-gate * You cannot interrupt the Vadic when its dialing; 73*7c478bd9Sstevel@tonic-gate * even dropping DTR does not work (definitely a 74*7c478bd9Sstevel@tonic-gate * brain damaged design). 75*7c478bd9Sstevel@tonic-gate */ 76*7c478bd9Sstevel@tonic-gate vawrite("\r", 1 + slow); 77*7c478bd9Sstevel@tonic-gate vawrite("\r", 1 + slow); 78*7c478bd9Sstevel@tonic-gate if (!expect("DIALING:")) { 79*7c478bd9Sstevel@tonic-gate printf("Vadic failed to dial\n"); 80*7c478bd9Sstevel@tonic-gate #ifdef ACULOG 81*7c478bd9Sstevel@tonic-gate logent(value(HOST), num, "vadic", "failed to dial"); 82*7c478bd9Sstevel@tonic-gate #endif 83*7c478bd9Sstevel@tonic-gate return (0); 84*7c478bd9Sstevel@tonic-gate } 85*7c478bd9Sstevel@tonic-gate if (boolean(value(VERBOSE))) 86*7c478bd9Sstevel@tonic-gate printf("\ndialing..."); 87*7c478bd9Sstevel@tonic-gate ok = expect("ON LINE"); 88*7c478bd9Sstevel@tonic-gate signal(SIGINT, func); 89*7c478bd9Sstevel@tonic-gate if (!ok) { 90*7c478bd9Sstevel@tonic-gate printf("call failed\n"); 91*7c478bd9Sstevel@tonic-gate #ifdef ACULOG 92*7c478bd9Sstevel@tonic-gate logent(value(HOST), num, "vadic", "call failed"); 93*7c478bd9Sstevel@tonic-gate #endif 94*7c478bd9Sstevel@tonic-gate return (0); 95*7c478bd9Sstevel@tonic-gate } 96*7c478bd9Sstevel@tonic-gate ioctl(FD, TCFLSH, TCOFLUSH); 97*7c478bd9Sstevel@tonic-gate return (1); 98*7c478bd9Sstevel@tonic-gate } 99*7c478bd9Sstevel@tonic-gate 100*7c478bd9Sstevel@tonic-gate v3451_disconnect() 101*7c478bd9Sstevel@tonic-gate { 102*7c478bd9Sstevel@tonic-gate 103*7c478bd9Sstevel@tonic-gate close(FD); 104*7c478bd9Sstevel@tonic-gate } 105*7c478bd9Sstevel@tonic-gate 106*7c478bd9Sstevel@tonic-gate v3451_abort() 107*7c478bd9Sstevel@tonic-gate { 108*7c478bd9Sstevel@tonic-gate 109*7c478bd9Sstevel@tonic-gate close(FD); 110*7c478bd9Sstevel@tonic-gate } 111*7c478bd9Sstevel@tonic-gate 112*7c478bd9Sstevel@tonic-gate static 113*7c478bd9Sstevel@tonic-gate vawrite(cp, delay) 114*7c478bd9Sstevel@tonic-gate register char *cp; 115*7c478bd9Sstevel@tonic-gate int delay; 116*7c478bd9Sstevel@tonic-gate { 117*7c478bd9Sstevel@tonic-gate 118*7c478bd9Sstevel@tonic-gate for (; *cp; sleep(delay), cp++) 119*7c478bd9Sstevel@tonic-gate write(FD, cp, 1); 120*7c478bd9Sstevel@tonic-gate } 121*7c478bd9Sstevel@tonic-gate 122*7c478bd9Sstevel@tonic-gate static 123*7c478bd9Sstevel@tonic-gate expect(cp) 124*7c478bd9Sstevel@tonic-gate register char *cp; 125*7c478bd9Sstevel@tonic-gate { 126*7c478bd9Sstevel@tonic-gate char buf[300]; 127*7c478bd9Sstevel@tonic-gate register char *rp = buf; 128*7c478bd9Sstevel@tonic-gate static void alarmtr(); 129*7c478bd9Sstevel@tonic-gate int timeout = 30, online = 0; 130*7c478bd9Sstevel@tonic-gate 131*7c478bd9Sstevel@tonic-gate if (strcmp(cp, "\"\"") == 0) 132*7c478bd9Sstevel@tonic-gate return (1); 133*7c478bd9Sstevel@tonic-gate *rp = 0; 134*7c478bd9Sstevel@tonic-gate /* 135*7c478bd9Sstevel@tonic-gate * If we are waiting for the Vadic to complete 136*7c478bd9Sstevel@tonic-gate * dialing and get a connection, allow more time 137*7c478bd9Sstevel@tonic-gate * Unfortunately, the Vadic times out 24 seconds after 138*7c478bd9Sstevel@tonic-gate * the last digit is dialed 139*7c478bd9Sstevel@tonic-gate */ 140*7c478bd9Sstevel@tonic-gate online = strcmp(cp, "ON LINE") == 0; 141*7c478bd9Sstevel@tonic-gate if (online) 142*7c478bd9Sstevel@tonic-gate timeout = number(value(DIALTIMEOUT)); 143*7c478bd9Sstevel@tonic-gate signal(SIGALRM, alarmtr); 144*7c478bd9Sstevel@tonic-gate if (sigsetjmp(Sjbuf, 1)) 145*7c478bd9Sstevel@tonic-gate return (0); 146*7c478bd9Sstevel@tonic-gate alarm(timeout); 147*7c478bd9Sstevel@tonic-gate while (notin(cp, buf) && rp < buf + sizeof (buf) - 1) { 148*7c478bd9Sstevel@tonic-gate if (online && notin("FAILED CALL", buf) == 0) 149*7c478bd9Sstevel@tonic-gate return (0); 150*7c478bd9Sstevel@tonic-gate if (read(FD, rp, 1) < 0) { 151*7c478bd9Sstevel@tonic-gate alarm(0); 152*7c478bd9Sstevel@tonic-gate return (0); 153*7c478bd9Sstevel@tonic-gate } 154*7c478bd9Sstevel@tonic-gate if (*rp &= 0177) 155*7c478bd9Sstevel@tonic-gate rp++; 156*7c478bd9Sstevel@tonic-gate *rp = '\0'; 157*7c478bd9Sstevel@tonic-gate } 158*7c478bd9Sstevel@tonic-gate alarm(0); 159*7c478bd9Sstevel@tonic-gate return (1); 160*7c478bd9Sstevel@tonic-gate } 161*7c478bd9Sstevel@tonic-gate 162*7c478bd9Sstevel@tonic-gate static void 163*7c478bd9Sstevel@tonic-gate alarmtr() 164*7c478bd9Sstevel@tonic-gate { 165*7c478bd9Sstevel@tonic-gate 166*7c478bd9Sstevel@tonic-gate siglongjmp(Sjbuf, 1); 167*7c478bd9Sstevel@tonic-gate } 168*7c478bd9Sstevel@tonic-gate 169*7c478bd9Sstevel@tonic-gate static 170*7c478bd9Sstevel@tonic-gate notin(sh, lg) 171*7c478bd9Sstevel@tonic-gate char *sh, *lg; 172*7c478bd9Sstevel@tonic-gate { 173*7c478bd9Sstevel@tonic-gate 174*7c478bd9Sstevel@tonic-gate for (; *lg; lg++) 175*7c478bd9Sstevel@tonic-gate if (prefix(sh, lg)) 176*7c478bd9Sstevel@tonic-gate return (0); 177*7c478bd9Sstevel@tonic-gate return (1); 178*7c478bd9Sstevel@tonic-gate } 179*7c478bd9Sstevel@tonic-gate 180*7c478bd9Sstevel@tonic-gate static 181*7c478bd9Sstevel@tonic-gate prefix(s1, s2) 182*7c478bd9Sstevel@tonic-gate register char *s1, *s2; 183*7c478bd9Sstevel@tonic-gate { 184*7c478bd9Sstevel@tonic-gate register char c; 185*7c478bd9Sstevel@tonic-gate 186*7c478bd9Sstevel@tonic-gate while ((c = *s1++) == *s2++) 187*7c478bd9Sstevel@tonic-gate if (c == '\0') 188*7c478bd9Sstevel@tonic-gate return (1); 189*7c478bd9Sstevel@tonic-gate return (c == '\0'); 190*7c478bd9Sstevel@tonic-gate } 191