1*19817Sdist /* 2*19817Sdist * Copyright (c) 1983 Regents of the University of California. 3*19817Sdist * All rights reserved. The Berkeley software License Agreement 4*19817Sdist * specifies the terms and conditions for redistribution. 5*19817Sdist */ 6*19817Sdist 713280Ssam #ifndef lint 8*19817Sdist static char sccsid[] = "@(#)v3451.c 5.1 (Berkeley) 04/30/85"; 9*19817Sdist #endif not lint 1013131Sralph 1113131Sralph /* 1213131Sralph * Routines for calling up on a Vadic 3451 Modem 1313131Sralph */ 1413131Sralph #include "tip.h" 1513131Sralph 1613276Ssam static jmp_buf Sjbuf; 1713131Sralph 1813280Ssam v3451_dialer(num, acu) 1913131Sralph register char *num; 2013131Sralph char *acu; 2113131Sralph { 2213276Ssam int ok, (*func)(); 2313276Ssam int slow = number(value(BAUDRATE)) < 1200, rw = 2; 2413131Sralph char phone[50]; 2513131Sralph #ifdef ACULOG 2613131Sralph char line[80]; 2713131Sralph #endif 2813131Sralph 2913131Sralph /* 3013131Sralph * Get in synch 3113131Sralph */ 3213276Ssam vawrite("I\r", 1 + slow); 3313276Ssam vawrite("I\r", 1 + slow); 3413276Ssam vawrite("I\r", 1 + slow); 3513276Ssam vawrite("\005\r", 2 + slow); 3613276Ssam if (!expect("READY")) { 3713131Sralph printf("can't synchronize with vadic 3451\n"); 3813131Sralph #ifdef ACULOG 3913131Sralph logent(value(HOST), num, "vadic", "can't synch up"); 4013131Sralph #endif 4113131Sralph return (0); 4213131Sralph } 4313131Sralph ioctl(FD, TIOCHPCL, 0); 4413131Sralph sleep(1); 4513276Ssam vawrite("D\r", 2 + slow); 4613276Ssam if (!expect("NUMBER?")) { 4713131Sralph printf("Vadic will not accept dial command\n"); 4813131Sralph #ifdef ACULOG 4913131Sralph logent(value(HOST), num, "vadic", "will not accept dial"); 5013131Sralph #endif 5113131Sralph return (0); 5213131Sralph } 5313276Ssam strcpy(phone, num); 5413276Ssam strcat(phone, "\r"); 5513276Ssam vawrite(phone, 1 + slow); 5613276Ssam if (!expect(phone)) { 5713131Sralph printf("Vadic will not accept phone number\n"); 5813131Sralph #ifdef ACULOG 5913131Sralph logent(value(HOST), num, "vadic", "will not accept number"); 6013131Sralph #endif 6113131Sralph return (0); 6213131Sralph } 6313131Sralph func = signal(SIGINT,SIG_IGN); 6413276Ssam /* 6513276Ssam * You cannot interrupt the Vadic when its dialing; 6613276Ssam * even dropping DTR does not work (definitely a 6713276Ssam * brain damaged design). 6813276Ssam */ 6913276Ssam vawrite("\r", 1 + slow); 7013276Ssam vawrite("\r", 1 + slow); 7113276Ssam if (!expect("DIALING:")) { 7213131Sralph printf("Vadic failed to dial\n"); 7313131Sralph #ifdef ACULOG 7413131Sralph logent(value(HOST), num, "vadic", "failed to dial"); 7513131Sralph #endif 7613131Sralph return (0); 7713276Ssam } 7813276Ssam if (boolean(value(VERBOSE))) 7913276Ssam printf("\ndialing..."); 8013131Sralph ok = expect("ON LINE"); 8113276Ssam signal(SIGINT, func); 8213276Ssam if (!ok) { 8313131Sralph printf("call failed\n"); 8413131Sralph #ifdef ACULOG 8513131Sralph logent(value(HOST), num, "vadic", "call failed"); 8613131Sralph #endif 8713131Sralph return (0); 8813131Sralph } 8913276Ssam ioctl(FD, TIOCFLUSH, &rw); 9013131Sralph return (1); 9113131Sralph } 9213131Sralph 9313280Ssam v3451_disconnect() 9413131Sralph { 9513276Ssam 9613131Sralph close(FD); 9713131Sralph } 9813131Sralph 9913280Ssam v3451_abort() 10013131Sralph { 10113276Ssam 10213276Ssam close(FD); 10313131Sralph } 10413131Sralph 10513276Ssam static 10613276Ssam vawrite(cp, delay) 10713276Ssam register char *cp; 10813276Ssam int delay; 10913131Sralph { 11013276Ssam 11113276Ssam for (; *cp; sleep(delay), cp++) 11213276Ssam write(FD, cp, 1); 11313131Sralph } 11413131Sralph 11513276Ssam static 11613276Ssam expect(cp) 11713276Ssam register char *cp; 11813131Sralph { 11913276Ssam char buf[300]; 12013276Ssam register char *rp = buf; 12113276Ssam int alarmtr(), timeout = 30, online = 0; 12213131Sralph 12313276Ssam if (strcmp(cp, "\"\"") == 0) 12413276Ssam return (1); 12513131Sralph *rp = 0; 12613131Sralph /* 12713131Sralph * If we are waiting for the Vadic to complete 12813131Sralph * dialing and get a connection, allow more time 12913131Sralph * Unfortunately, the Vadic times out 24 seconds after 13013131Sralph * the last digit is dialed 13113131Sralph */ 13213276Ssam online = strcmp(cp, "ON LINE") == 0; 13313276Ssam if (online) 13413276Ssam timeout = number(value(DIALTIMEOUT)); 13513131Sralph signal(SIGALRM, alarmtr); 13613276Ssam if (setjmp(Sjbuf)) 13713276Ssam return (0); 13813276Ssam alarm(timeout); 13913276Ssam while (notin(cp, buf) && rp < buf + sizeof (buf) - 1) { 14013276Ssam if (online && notin("FAILED CALL", buf) == 0) 14113276Ssam return (0); 14213276Ssam if (read(FD, rp, 1) < 0) { 14313131Sralph alarm(0); 14413276Ssam return (0); 14513131Sralph } 14613276Ssam if (*rp &= 0177) 14713131Sralph rp++; 14813131Sralph *rp = '\0'; 14913131Sralph } 15013131Sralph alarm(0); 15113276Ssam return (1); 15213131Sralph } 15313131Sralph 15413276Ssam static 15513131Sralph alarmtr() 15613131Sralph { 15713276Ssam 15813131Sralph longjmp(Sjbuf, 1); 15913131Sralph } 16013131Sralph 16113276Ssam static 16213131Sralph notin(sh, lg) 16313276Ssam char *sh, *lg; 16413131Sralph { 16513276Ssam 16613276Ssam for (; *lg; lg++) 16713131Sralph if (prefix(sh, lg)) 16813276Ssam return (0); 16913276Ssam return (1); 17013131Sralph } 17113131Sralph 17213276Ssam static 17313131Sralph prefix(s1, s2) 17413276Ssam register char *s1, *s2; 17513131Sralph { 17613276Ssam register char c; 17713131Sralph 17813131Sralph while ((c = *s1++) == *s2++) 17913131Sralph if (c == '\0') 18013276Ssam return (1); 18113276Ssam return (c == '\0'); 18213131Sralph } 183