119817Sdist /* 235492Sbostic * Copyright (c) 1983 The Regents of the University of California. 335492Sbostic * All rights reserved. 435492Sbostic * 5*42770Sbostic * %sccs.include.redist.c% 619817Sdist */ 719817Sdist 813280Ssam #ifndef lint 9*42770Sbostic static char sccsid[] = "@(#)v3451.c 5.4 (Berkeley) 06/01/90"; 1035492Sbostic #endif /* not lint */ 1113131Sralph 1213131Sralph /* 1313131Sralph * Routines for calling up on a Vadic 3451 Modem 1413131Sralph */ 1513131Sralph #include "tip.h" 1613131Sralph 1713276Ssam static jmp_buf Sjbuf; 1813131Sralph 1913280Ssam v3451_dialer(num, acu) 2013131Sralph register char *num; 2113131Sralph char *acu; 2213131Sralph { 2339253Sbostic sig_t func; 2439253Sbostic int ok; 2513276Ssam int slow = number(value(BAUDRATE)) < 1200, rw = 2; 2613131Sralph char phone[50]; 2713131Sralph #ifdef ACULOG 2813131Sralph char line[80]; 2913131Sralph #endif 3013131Sralph 3113131Sralph /* 3213131Sralph * Get in synch 3313131Sralph */ 3413276Ssam vawrite("I\r", 1 + slow); 3513276Ssam vawrite("I\r", 1 + slow); 3613276Ssam vawrite("I\r", 1 + slow); 3713276Ssam vawrite("\005\r", 2 + slow); 3813276Ssam if (!expect("READY")) { 3913131Sralph printf("can't synchronize with vadic 3451\n"); 4013131Sralph #ifdef ACULOG 4113131Sralph logent(value(HOST), num, "vadic", "can't synch up"); 4213131Sralph #endif 4313131Sralph return (0); 4413131Sralph } 4513131Sralph ioctl(FD, TIOCHPCL, 0); 4613131Sralph sleep(1); 4713276Ssam vawrite("D\r", 2 + slow); 4813276Ssam if (!expect("NUMBER?")) { 4913131Sralph printf("Vadic will not accept dial command\n"); 5013131Sralph #ifdef ACULOG 5113131Sralph logent(value(HOST), num, "vadic", "will not accept dial"); 5213131Sralph #endif 5313131Sralph return (0); 5413131Sralph } 5513276Ssam strcpy(phone, num); 5613276Ssam strcat(phone, "\r"); 5713276Ssam vawrite(phone, 1 + slow); 5813276Ssam if (!expect(phone)) { 5913131Sralph printf("Vadic will not accept phone number\n"); 6013131Sralph #ifdef ACULOG 6113131Sralph logent(value(HOST), num, "vadic", "will not accept number"); 6213131Sralph #endif 6313131Sralph return (0); 6413131Sralph } 6513131Sralph func = signal(SIGINT,SIG_IGN); 6613276Ssam /* 6713276Ssam * You cannot interrupt the Vadic when its dialing; 6813276Ssam * even dropping DTR does not work (definitely a 6913276Ssam * brain damaged design). 7013276Ssam */ 7113276Ssam vawrite("\r", 1 + slow); 7213276Ssam vawrite("\r", 1 + slow); 7313276Ssam if (!expect("DIALING:")) { 7413131Sralph printf("Vadic failed to dial\n"); 7513131Sralph #ifdef ACULOG 7613131Sralph logent(value(HOST), num, "vadic", "failed to dial"); 7713131Sralph #endif 7813131Sralph return (0); 7913276Ssam } 8013276Ssam if (boolean(value(VERBOSE))) 8113276Ssam printf("\ndialing..."); 8213131Sralph ok = expect("ON LINE"); 8313276Ssam signal(SIGINT, func); 8413276Ssam if (!ok) { 8513131Sralph printf("call failed\n"); 8613131Sralph #ifdef ACULOG 8713131Sralph logent(value(HOST), num, "vadic", "call failed"); 8813131Sralph #endif 8913131Sralph return (0); 9013131Sralph } 9113276Ssam ioctl(FD, TIOCFLUSH, &rw); 9213131Sralph return (1); 9313131Sralph } 9413131Sralph 9513280Ssam v3451_disconnect() 9613131Sralph { 9713276Ssam 9813131Sralph close(FD); 9913131Sralph } 10013131Sralph 10113280Ssam v3451_abort() 10213131Sralph { 10313276Ssam 10413276Ssam close(FD); 10513131Sralph } 10613131Sralph 10713276Ssam static 10813276Ssam vawrite(cp, delay) 10913276Ssam register char *cp; 11013276Ssam int delay; 11113131Sralph { 11213276Ssam 11313276Ssam for (; *cp; sleep(delay), cp++) 11413276Ssam write(FD, cp, 1); 11513131Sralph } 11613131Sralph 11713276Ssam static 11813276Ssam expect(cp) 11913276Ssam register char *cp; 12013131Sralph { 12113276Ssam char buf[300]; 12213276Ssam register char *rp = buf; 12313276Ssam int alarmtr(), timeout = 30, online = 0; 12413131Sralph 12513276Ssam if (strcmp(cp, "\"\"") == 0) 12613276Ssam return (1); 12713131Sralph *rp = 0; 12813131Sralph /* 12913131Sralph * If we are waiting for the Vadic to complete 13013131Sralph * dialing and get a connection, allow more time 13113131Sralph * Unfortunately, the Vadic times out 24 seconds after 13213131Sralph * the last digit is dialed 13313131Sralph */ 13413276Ssam online = strcmp(cp, "ON LINE") == 0; 13513276Ssam if (online) 13613276Ssam timeout = number(value(DIALTIMEOUT)); 13713131Sralph signal(SIGALRM, alarmtr); 13813276Ssam if (setjmp(Sjbuf)) 13913276Ssam return (0); 14013276Ssam alarm(timeout); 14113276Ssam while (notin(cp, buf) && rp < buf + sizeof (buf) - 1) { 14213276Ssam if (online && notin("FAILED CALL", buf) == 0) 14313276Ssam return (0); 14413276Ssam if (read(FD, rp, 1) < 0) { 14513131Sralph alarm(0); 14613276Ssam return (0); 14713131Sralph } 14813276Ssam if (*rp &= 0177) 14913131Sralph rp++; 15013131Sralph *rp = '\0'; 15113131Sralph } 15213131Sralph alarm(0); 15313276Ssam return (1); 15413131Sralph } 15513131Sralph 15613276Ssam static 15713131Sralph alarmtr() 15813131Sralph { 15913276Ssam 16013131Sralph longjmp(Sjbuf, 1); 16113131Sralph } 16213131Sralph 16313276Ssam static 16413131Sralph notin(sh, lg) 16513276Ssam char *sh, *lg; 16613131Sralph { 16713276Ssam 16813276Ssam for (; *lg; lg++) 16913131Sralph if (prefix(sh, lg)) 17013276Ssam return (0); 17113276Ssam return (1); 17213131Sralph } 17313131Sralph 17413276Ssam static 17513131Sralph prefix(s1, s2) 17613276Ssam register char *s1, *s2; 17713131Sralph { 17813276Ssam register char c; 17913131Sralph 18013131Sralph while ((c = *s1++) == *s2++) 18113131Sralph if (c == '\0') 18213276Ssam return (1); 18313276Ssam return (c == '\0'); 18413131Sralph } 185