122414Sdist /* 235492Sbostic * Copyright (c) 1983 The Regents of the University of California. 335492Sbostic * All rights reserved. 435492Sbostic * 5*42770Sbostic * %sccs.include.redist.c% 622414Sdist */ 722414Sdist 813277Ssam #ifndef lint 9*42770Sbostic static char sccsid[] = "@(#)biz22.c 5.4 (Berkeley) 06/01/90"; 1035492Sbostic #endif /* not lint */ 1113277Ssam 125130Ssam #include "tip.h" 135130Ssam 1413277Ssam #define DISCONNECT_CMD "\20\04" /* disconnection string */ 155130Ssam 1639253Sbostic static void sigALRM(); 1713277Ssam static int timeout = 0; 1813277Ssam static jmp_buf timeoutbuf; 195130Ssam 205130Ssam /* 215130Ssam * Dial up on a BIZCOMP Model 1022 with either 225130Ssam * tone dialing (mod = "V") 235130Ssam * pulse dialing (mod = "W") 245130Ssam */ 255130Ssam static int 265130Ssam biz_dialer(num, mod) 275130Ssam char *num, *mod; 285130Ssam { 295130Ssam register int connected = 0; 305130Ssam char cbuf[40]; 315130Ssam 325130Ssam if (boolean(value(VERBOSE))) 335130Ssam printf("\nstarting call..."); 345130Ssam /* 355130Ssam * Disable auto-answer and configure for tone/pulse 365130Ssam * dialing 375130Ssam */ 385130Ssam if (cmd("\02K\r")) { 395130Ssam printf("can't initialize bizcomp..."); 405130Ssam return (0); 415130Ssam } 425130Ssam strcpy(cbuf, "\02.\r"); 435130Ssam cbuf[1] = *mod; 445130Ssam if (cmd(cbuf)) { 455130Ssam printf("can't set dialing mode..."); 465130Ssam return (0); 475130Ssam } 485130Ssam strcpy(cbuf, "\02D"); 495130Ssam strcat(cbuf, num); 505130Ssam strcat(cbuf, "\r"); 515130Ssam write(FD, cbuf, strlen(cbuf)); 525130Ssam if (!detect("7\r")) { 535130Ssam printf("can't get dial tone..."); 545130Ssam return (0); 555130Ssam } 565130Ssam if (boolean(value(VERBOSE))) 575130Ssam printf("ringing..."); 585130Ssam /* 595130Ssam * The reply from the BIZCOMP should be: 605130Ssam * 2 \r or 7 \r failure 615130Ssam * 1 \r success 625130Ssam */ 635130Ssam connected = detect("1\r"); 645130Ssam #ifdef ACULOG 655130Ssam if (timeout) { 665130Ssam char line[80]; 675130Ssam 685130Ssam sprintf(line, "%d second dial timeout", 695130Ssam number(value(DIALTIMEOUT))); 705130Ssam logent(value(HOST), num, "biz1022", line); 715130Ssam } 725130Ssam #endif 735130Ssam if (timeout) 745130Ssam biz22_disconnect(); /* insurance */ 755130Ssam return (connected); 765130Ssam } 775130Ssam 785130Ssam biz22w_dialer(num, acu) 795130Ssam char *num, *acu; 805130Ssam { 8113277Ssam 825130Ssam return (biz_dialer(num, "W")); 835130Ssam } 845130Ssam 855130Ssam biz22f_dialer(num, acu) 865130Ssam char *num, *acu; 875130Ssam { 8813277Ssam 895130Ssam return (biz_dialer(num, "V")); 905130Ssam } 915130Ssam 925130Ssam biz22_disconnect() 935130Ssam { 9413277Ssam int rw = 2; 9513277Ssam 9613277Ssam write(FD, DISCONNECT_CMD, 4); 975130Ssam sleep(2); 9813277Ssam ioctl(FD, TIOCFLUSH, &rw); 995130Ssam } 1005130Ssam 1015130Ssam biz22_abort() 1025130Ssam { 10313277Ssam 1045130Ssam write(FD, "\02", 1); 1055130Ssam } 1065130Ssam 10739253Sbostic static void 1085130Ssam sigALRM() 1095130Ssam { 11013277Ssam 1115130Ssam timeout = 1; 11213277Ssam longjmp(timeoutbuf, 1); 1135130Ssam } 1145130Ssam 1155130Ssam static int 1165130Ssam cmd(s) 1175130Ssam register char *s; 1185130Ssam { 11939253Sbostic sig_t f; 1205130Ssam char c; 1215130Ssam 1225130Ssam write(FD, s, strlen(s)); 12313277Ssam f = signal(SIGALRM, sigALRM); 12413277Ssam if (setjmp(timeoutbuf)) { 12513277Ssam biz22_abort(); 12613277Ssam signal(SIGALRM, f); 12713277Ssam return (1); 12813277Ssam } 1295130Ssam alarm(number(value(DIALTIMEOUT))); 1305130Ssam read(FD, &c, 1); 1315130Ssam alarm(0); 13213277Ssam signal(SIGALRM, f); 1335130Ssam c &= 0177; 1345130Ssam return (c != '\r'); 1355130Ssam } 1365130Ssam 1375130Ssam static int 1385130Ssam detect(s) 1395130Ssam register char *s; 1405130Ssam { 14139253Sbostic sig_t f; 1425130Ssam char c; 1435130Ssam 14413277Ssam f = signal(SIGALRM, sigALRM); 1455130Ssam timeout = 0; 1465130Ssam while (*s) { 14713277Ssam if (setjmp(timeoutbuf)) { 14813277Ssam biz22_abort(); 14913277Ssam break; 15013277Ssam } 1515130Ssam alarm(number(value(DIALTIMEOUT))); 1525130Ssam read(FD, &c, 1); 1535130Ssam alarm(0); 1545130Ssam c &= 0177; 1555130Ssam if (c != *s++) 1565130Ssam return (0); 1575130Ssam } 15813277Ssam signal(SIGALRM, f); 15913277Ssam return (timeout == 0); 1605130Ssam } 161