119817Sdist /* 235492Sbostic * Copyright (c) 1983 The Regents of the University of California. 335492Sbostic * All rights reserved. 435492Sbostic * 535492Sbostic * Redistribution and use in source and binary forms are permitted 635492Sbostic * provided that the above copyright notice and this paragraph are 735492Sbostic * duplicated in all such forms and that any documentation, 835492Sbostic * advertising materials, and other materials related to such 935492Sbostic * distribution and use acknowledge that the software was developed 1035492Sbostic * by the University of California, Berkeley. The name of the 1135492Sbostic * University may not be used to endorse or promote products derived 1235492Sbostic * from this software without specific prior written permission. 1335492Sbostic * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 1435492Sbostic * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 1535492Sbostic * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 1619817Sdist */ 1719817Sdist 1813280Ssam #ifndef lint 19*39253Sbostic static char sccsid[] = "@(#)v3451.c 5.3 (Berkeley) 10/03/89"; 2035492Sbostic #endif /* not lint */ 2113131Sralph 2213131Sralph /* 2313131Sralph * Routines for calling up on a Vadic 3451 Modem 2413131Sralph */ 2513131Sralph #include "tip.h" 2613131Sralph 2713276Ssam static jmp_buf Sjbuf; 2813131Sralph 2913280Ssam v3451_dialer(num, acu) 3013131Sralph register char *num; 3113131Sralph char *acu; 3213131Sralph { 33*39253Sbostic sig_t func; 34*39253Sbostic int ok; 3513276Ssam int slow = number(value(BAUDRATE)) < 1200, rw = 2; 3613131Sralph char phone[50]; 3713131Sralph #ifdef ACULOG 3813131Sralph char line[80]; 3913131Sralph #endif 4013131Sralph 4113131Sralph /* 4213131Sralph * Get in synch 4313131Sralph */ 4413276Ssam vawrite("I\r", 1 + slow); 4513276Ssam vawrite("I\r", 1 + slow); 4613276Ssam vawrite("I\r", 1 + slow); 4713276Ssam vawrite("\005\r", 2 + slow); 4813276Ssam if (!expect("READY")) { 4913131Sralph printf("can't synchronize with vadic 3451\n"); 5013131Sralph #ifdef ACULOG 5113131Sralph logent(value(HOST), num, "vadic", "can't synch up"); 5213131Sralph #endif 5313131Sralph return (0); 5413131Sralph } 5513131Sralph ioctl(FD, TIOCHPCL, 0); 5613131Sralph sleep(1); 5713276Ssam vawrite("D\r", 2 + slow); 5813276Ssam if (!expect("NUMBER?")) { 5913131Sralph printf("Vadic will not accept dial command\n"); 6013131Sralph #ifdef ACULOG 6113131Sralph logent(value(HOST), num, "vadic", "will not accept dial"); 6213131Sralph #endif 6313131Sralph return (0); 6413131Sralph } 6513276Ssam strcpy(phone, num); 6613276Ssam strcat(phone, "\r"); 6713276Ssam vawrite(phone, 1 + slow); 6813276Ssam if (!expect(phone)) { 6913131Sralph printf("Vadic will not accept phone number\n"); 7013131Sralph #ifdef ACULOG 7113131Sralph logent(value(HOST), num, "vadic", "will not accept number"); 7213131Sralph #endif 7313131Sralph return (0); 7413131Sralph } 7513131Sralph func = signal(SIGINT,SIG_IGN); 7613276Ssam /* 7713276Ssam * You cannot interrupt the Vadic when its dialing; 7813276Ssam * even dropping DTR does not work (definitely a 7913276Ssam * brain damaged design). 8013276Ssam */ 8113276Ssam vawrite("\r", 1 + slow); 8213276Ssam vawrite("\r", 1 + slow); 8313276Ssam if (!expect("DIALING:")) { 8413131Sralph printf("Vadic failed to dial\n"); 8513131Sralph #ifdef ACULOG 8613131Sralph logent(value(HOST), num, "vadic", "failed to dial"); 8713131Sralph #endif 8813131Sralph return (0); 8913276Ssam } 9013276Ssam if (boolean(value(VERBOSE))) 9113276Ssam printf("\ndialing..."); 9213131Sralph ok = expect("ON LINE"); 9313276Ssam signal(SIGINT, func); 9413276Ssam if (!ok) { 9513131Sralph printf("call failed\n"); 9613131Sralph #ifdef ACULOG 9713131Sralph logent(value(HOST), num, "vadic", "call failed"); 9813131Sralph #endif 9913131Sralph return (0); 10013131Sralph } 10113276Ssam ioctl(FD, TIOCFLUSH, &rw); 10213131Sralph return (1); 10313131Sralph } 10413131Sralph 10513280Ssam v3451_disconnect() 10613131Sralph { 10713276Ssam 10813131Sralph close(FD); 10913131Sralph } 11013131Sralph 11113280Ssam v3451_abort() 11213131Sralph { 11313276Ssam 11413276Ssam close(FD); 11513131Sralph } 11613131Sralph 11713276Ssam static 11813276Ssam vawrite(cp, delay) 11913276Ssam register char *cp; 12013276Ssam int delay; 12113131Sralph { 12213276Ssam 12313276Ssam for (; *cp; sleep(delay), cp++) 12413276Ssam write(FD, cp, 1); 12513131Sralph } 12613131Sralph 12713276Ssam static 12813276Ssam expect(cp) 12913276Ssam register char *cp; 13013131Sralph { 13113276Ssam char buf[300]; 13213276Ssam register char *rp = buf; 13313276Ssam int alarmtr(), timeout = 30, online = 0; 13413131Sralph 13513276Ssam if (strcmp(cp, "\"\"") == 0) 13613276Ssam return (1); 13713131Sralph *rp = 0; 13813131Sralph /* 13913131Sralph * If we are waiting for the Vadic to complete 14013131Sralph * dialing and get a connection, allow more time 14113131Sralph * Unfortunately, the Vadic times out 24 seconds after 14213131Sralph * the last digit is dialed 14313131Sralph */ 14413276Ssam online = strcmp(cp, "ON LINE") == 0; 14513276Ssam if (online) 14613276Ssam timeout = number(value(DIALTIMEOUT)); 14713131Sralph signal(SIGALRM, alarmtr); 14813276Ssam if (setjmp(Sjbuf)) 14913276Ssam return (0); 15013276Ssam alarm(timeout); 15113276Ssam while (notin(cp, buf) && rp < buf + sizeof (buf) - 1) { 15213276Ssam if (online && notin("FAILED CALL", buf) == 0) 15313276Ssam return (0); 15413276Ssam if (read(FD, rp, 1) < 0) { 15513131Sralph alarm(0); 15613276Ssam return (0); 15713131Sralph } 15813276Ssam if (*rp &= 0177) 15913131Sralph rp++; 16013131Sralph *rp = '\0'; 16113131Sralph } 16213131Sralph alarm(0); 16313276Ssam return (1); 16413131Sralph } 16513131Sralph 16613276Ssam static 16713131Sralph alarmtr() 16813131Sralph { 16913276Ssam 17013131Sralph longjmp(Sjbuf, 1); 17113131Sralph } 17213131Sralph 17313276Ssam static 17413131Sralph notin(sh, lg) 17513276Ssam char *sh, *lg; 17613131Sralph { 17713276Ssam 17813276Ssam for (; *lg; lg++) 17913131Sralph if (prefix(sh, lg)) 18013276Ssam return (0); 18113276Ssam return (1); 18213131Sralph } 18313131Sralph 18413276Ssam static 18513131Sralph prefix(s1, s2) 18613276Ssam register char *s1, *s2; 18713131Sralph { 18813276Ssam register char c; 18913131Sralph 19013131Sralph while ((c = *s1++) == *s2++) 19113131Sralph if (c == '\0') 19213276Ssam return (1); 19313276Ssam return (c == '\0'); 19413131Sralph } 195