1*22415Sdist /* 2*22415Sdist * Copyright (c) 1983 Regents of the University of California. 3*22415Sdist * All rights reserved. The Berkeley software License Agreement 4*22415Sdist * specifies the terms and conditions for redistribution. 5*22415Sdist */ 6*22415Sdist 713277Ssam #ifndef lint 8*22415Sdist static char sccsid[] = "@(#)biz31.c 5.1 (Berkeley) 06/06/85"; 9*22415Sdist #endif not lint 1013277Ssam 113687Sroot #include "tip.h" 123687Sroot 133687Sroot #define MAXRETRY 3 /* sync up retry count */ 1413277Ssam #define DISCONNECT_CMD "\21\25\11\24" /* disconnection string */ 153687Sroot 1613277Ssam static int sigALRM(); 1713277Ssam static int timeout = 0; 1813277Ssam static jmp_buf timeoutbuf; 193687Sroot 203687Sroot /* 214408Ssam * Dial up on a BIZCOMP Model 1031 with either 223687Sroot * tone dialing (mod = "f") 233687Sroot * pulse dialing (mod = "w") 243687Sroot */ 253687Sroot static int 263687Sroot biz_dialer(num, mod) 274962Ssam char *num, *mod; 283687Sroot { 293687Sroot register int connected = 0; 303687Sroot 313687Sroot if (!bizsync(FD)) { 323687Sroot logent(value(HOST), "", "biz", "out of sync"); 333687Sroot printf("bizcomp out of sync\n"); 343687Sroot delock(uucplock); 353687Sroot exit(0); 363687Sroot } 373687Sroot if (boolean(value(VERBOSE))) 383687Sroot printf("\nstarting call..."); 393687Sroot echo("#\rk$\r$\n"); /* disable auto-answer */ 403687Sroot echo("$>$.$ #\r"); /* tone/pulse dialing */ 413687Sroot echo(mod); 423687Sroot echo("$\r$\n"); 433687Sroot echo("$>$.$ #\re$ "); /* disconnection sequence */ 4413277Ssam echo(DISCONNECT_CMD); 453687Sroot echo("\r$\n$\r$\n"); 463687Sroot echo("$>$.$ #\rr$ "); /* repeat dial */ 473687Sroot echo(num); 483687Sroot echo("\r$\n"); 493687Sroot if (boolean(value(VERBOSE))) 503687Sroot printf("ringing..."); 513687Sroot /* 523687Sroot * The reply from the BIZCOMP should be: 533687Sroot * `^G NO CONNECTION\r\n^G\r\n' failure 543687Sroot * ` CONNECTION\r\n^G' success 553687Sroot */ 563687Sroot connected = detect(" "); 573687Sroot #ifdef ACULOG 583687Sroot if (timeout) { 593687Sroot char line[80]; 603687Sroot 613687Sroot sprintf(line, "%d second dial timeout", 623687Sroot number(value(DIALTIMEOUT))); 633687Sroot logent(value(HOST), num, "biz", line); 643687Sroot } 653687Sroot #endif 663687Sroot if (!connected) 673687Sroot flush(" NO CONNECTION\r\n\07\r\n"); 683687Sroot else 693687Sroot flush("CONNECTION\r\n\07"); 703687Sroot if (timeout) 714408Ssam biz31_disconnect(); /* insurance */ 725132Ssam return (connected); 733687Sroot } 743687Sroot 754408Ssam biz31w_dialer(num, acu) 764962Ssam char *num, *acu; 773687Sroot { 7813277Ssam 795132Ssam return (biz_dialer(num, "w")); 803687Sroot } 813687Sroot 824408Ssam biz31f_dialer(num, acu) 834962Ssam char *num, *acu; 843687Sroot { 8513277Ssam 865132Ssam return (biz_dialer(num, "f")); 873687Sroot } 883687Sroot 894408Ssam biz31_disconnect() 903687Sroot { 9113277Ssam 9213277Ssam write(FD, DISCONNECT_CMD, 4); 933687Sroot sleep(2); 943687Sroot ioctl(FD, TIOCFLUSH); 953687Sroot } 963687Sroot 974408Ssam biz31_abort() 983687Sroot { 9913277Ssam 1003687Sroot write(FD, "\33", 1); 1013687Sroot } 1023687Sroot 1033687Sroot static int 1043687Sroot echo(s) 1054962Ssam register char *s; 1063687Sroot { 1073687Sroot char c; 1083687Sroot 1095132Ssam while (c = *s++) switch (c) { 1105132Ssam 1115132Ssam case '$': 1125132Ssam read(FD, &c, 1); 1135132Ssam s++; 1145132Ssam break; 1155132Ssam 1165132Ssam case '#': 1175132Ssam c = *s++; 1185132Ssam write(FD, &c, 1); 1195132Ssam break; 1205132Ssam 1215132Ssam default: 1225132Ssam write(FD, &c, 1); 1235132Ssam read(FD, &c, 1); 1245132Ssam } 1253687Sroot } 1263687Sroot 1273687Sroot static int 1283687Sroot sigALRM() 1293687Sroot { 13013277Ssam 1313687Sroot timeout = 1; 13213277Ssam longjmp(timeoutbuf, 1); 1333687Sroot } 1343687Sroot 1353687Sroot static int 1363687Sroot detect(s) 1374962Ssam register char *s; 1383687Sroot { 1393687Sroot char c; 14013277Ssam int (*f)(); 1413687Sroot 14213277Ssam f = signal(SIGALRM, sigALRM); 1433687Sroot timeout = 0; 1445132Ssam while (*s) { 14513277Ssam if (setjmp(timeoutbuf)) { 14613277Ssam printf("\07timeout waiting for reply\n"); 14713277Ssam biz31_abort(); 14813277Ssam break; 14913277Ssam } 1503687Sroot alarm(number(value(DIALTIMEOUT))); 1513687Sroot read(FD, &c, 1); 1523687Sroot alarm(0); 1533687Sroot if (c != *s++) 15413277Ssam break; 1553687Sroot } 15613277Ssam signal(SIGALRM, f); 15713277Ssam return (timeout == 0); 1583687Sroot } 1593687Sroot 1603687Sroot static int 1613687Sroot flush(s) 1624962Ssam register char *s; 1633687Sroot { 1643687Sroot char c; 16513277Ssam int (*f)(); 1663687Sroot 16713277Ssam f = signal(SIGALRM, sigALRM); 1685132Ssam while (*s++) { 16913277Ssam if (setjmp(timeoutbuf)) 17013277Ssam break; 1713687Sroot alarm(10); 1723687Sroot read(FD, &c, 1); 1733687Sroot alarm(0); 1743687Sroot } 17513277Ssam signal(SIGALRM, f); 1763687Sroot timeout = 0; /* guard against disconnection */ 1773687Sroot } 1783687Sroot 1793687Sroot /* 1803687Sroot * This convoluted piece of code attempts to get 1813687Sroot * the bizcomp in sync. If you don't have the capacity or nread 1823687Sroot * call there are gory ways to simulate this. 1833687Sroot */ 1843687Sroot static int 1853687Sroot bizsync(fd) 1863687Sroot { 1873687Sroot #ifdef FIOCAPACITY 1883687Sroot struct capacity b; 1893687Sroot # define chars(b) ((b).cp_nbytes) 1903687Sroot # define IOCTL FIOCAPACITY 1913687Sroot #endif 1923687Sroot #ifdef FIONREAD 1933687Sroot long b; 1943687Sroot # define chars(b) (b) 1953687Sroot # define IOCTL FIONREAD 1963687Sroot #endif 1973687Sroot register int already = 0; 1983687Sroot char buf[10]; 1993687Sroot 2003687Sroot retry: 2013687Sroot if (ioctl(fd, IOCTL, (caddr_t)&b) >= 0 && chars(b) > 0) 2023687Sroot ioctl(fd, TIOCFLUSH); 2033687Sroot write(fd, "\rp>\r", 4); 2043687Sroot sleep(1); 2053687Sroot if (ioctl(fd, IOCTL, (caddr_t)&b) >= 0) { 2063687Sroot if (chars(b) != 10) { 2073687Sroot nono: 2083687Sroot if (already > MAXRETRY) 2095132Ssam return (0); 21013277Ssam write(fd, DISCONNECT_CMD, 4); 2113687Sroot sleep(2); 2123687Sroot already++; 2133687Sroot goto retry; 2143687Sroot } else { 2153687Sroot read(fd, buf, 10); 2163687Sroot if (strncmp(buf, "p >\r\n\r\n>", 8)) 2173687Sroot goto nono; 2183687Sroot } 2193687Sroot } 2205132Ssam return (1); 2213687Sroot } 222