122414Sdist /*
2*62317Sbostic * Copyright (c) 1983, 1993
3*62317Sbostic * The Regents of the University of California. All rights reserved.
435492Sbostic *
542770Sbostic * %sccs.include.redist.c%
622414Sdist */
722414Sdist
813277Ssam #ifndef lint
9*62317Sbostic static char sccsid[] = "@(#)biz22.c 8.1 (Berkeley) 06/06/93";
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
biz_dialer(num,mod)265130Ssam biz_dialer(num, mod)
275130Ssam char *num, *mod;
285130Ssam {
295130Ssam register int connected = 0;
305130Ssam char cbuf[40];
3146865Sbostic static int cmd(), detect();
325130Ssam
335130Ssam if (boolean(value(VERBOSE)))
345130Ssam printf("\nstarting call...");
355130Ssam /*
365130Ssam * Disable auto-answer and configure for tone/pulse
375130Ssam * dialing
385130Ssam */
395130Ssam if (cmd("\02K\r")) {
405130Ssam printf("can't initialize bizcomp...");
415130Ssam return (0);
425130Ssam }
435130Ssam strcpy(cbuf, "\02.\r");
445130Ssam cbuf[1] = *mod;
455130Ssam if (cmd(cbuf)) {
465130Ssam printf("can't set dialing mode...");
475130Ssam return (0);
485130Ssam }
495130Ssam strcpy(cbuf, "\02D");
505130Ssam strcat(cbuf, num);
515130Ssam strcat(cbuf, "\r");
525130Ssam write(FD, cbuf, strlen(cbuf));
535130Ssam if (!detect("7\r")) {
545130Ssam printf("can't get dial tone...");
555130Ssam return (0);
565130Ssam }
575130Ssam if (boolean(value(VERBOSE)))
585130Ssam printf("ringing...");
595130Ssam /*
605130Ssam * The reply from the BIZCOMP should be:
615130Ssam * 2 \r or 7 \r failure
625130Ssam * 1 \r success
635130Ssam */
645130Ssam connected = detect("1\r");
655130Ssam #ifdef ACULOG
665130Ssam if (timeout) {
675130Ssam char line[80];
685130Ssam
695130Ssam sprintf(line, "%d second dial timeout",
705130Ssam number(value(DIALTIMEOUT)));
715130Ssam logent(value(HOST), num, "biz1022", line);
725130Ssam }
735130Ssam #endif
745130Ssam if (timeout)
755130Ssam biz22_disconnect(); /* insurance */
765130Ssam return (connected);
775130Ssam }
785130Ssam
biz22w_dialer(num,acu)795130Ssam biz22w_dialer(num, acu)
805130Ssam char *num, *acu;
815130Ssam {
8213277Ssam
835130Ssam return (biz_dialer(num, "W"));
845130Ssam }
855130Ssam
biz22f_dialer(num,acu)865130Ssam biz22f_dialer(num, acu)
875130Ssam char *num, *acu;
885130Ssam {
8913277Ssam
905130Ssam return (biz_dialer(num, "V"));
915130Ssam }
925130Ssam
biz22_disconnect()935130Ssam biz22_disconnect()
945130Ssam {
9513277Ssam int rw = 2;
9613277Ssam
9713277Ssam write(FD, DISCONNECT_CMD, 4);
985130Ssam sleep(2);
9913277Ssam ioctl(FD, TIOCFLUSH, &rw);
1005130Ssam }
1015130Ssam
biz22_abort()1025130Ssam biz22_abort()
1035130Ssam {
10413277Ssam
1055130Ssam write(FD, "\02", 1);
1065130Ssam }
1075130Ssam
10839253Sbostic static void
sigALRM()1095130Ssam sigALRM()
1105130Ssam {
11113277Ssam
1125130Ssam timeout = 1;
11313277Ssam longjmp(timeoutbuf, 1);
1145130Ssam }
1155130Ssam
1165130Ssam static int
cmd(s)1175130Ssam cmd(s)
1185130Ssam register char *s;
1195130Ssam {
12039253Sbostic sig_t f;
1215130Ssam char c;
1225130Ssam
1235130Ssam write(FD, s, strlen(s));
12413277Ssam f = signal(SIGALRM, sigALRM);
12513277Ssam if (setjmp(timeoutbuf)) {
12613277Ssam biz22_abort();
12713277Ssam signal(SIGALRM, f);
12813277Ssam return (1);
12913277Ssam }
1305130Ssam alarm(number(value(DIALTIMEOUT)));
1315130Ssam read(FD, &c, 1);
1325130Ssam alarm(0);
13313277Ssam signal(SIGALRM, f);
1345130Ssam c &= 0177;
1355130Ssam return (c != '\r');
1365130Ssam }
1375130Ssam
1385130Ssam static int
detect(s)1395130Ssam detect(s)
1405130Ssam register char *s;
1415130Ssam {
14239253Sbostic sig_t f;
1435130Ssam char c;
1445130Ssam
14513277Ssam f = signal(SIGALRM, sigALRM);
1465130Ssam timeout = 0;
1475130Ssam while (*s) {
14813277Ssam if (setjmp(timeoutbuf)) {
14913277Ssam biz22_abort();
15013277Ssam break;
15113277Ssam }
1525130Ssam alarm(number(value(DIALTIMEOUT)));
1535130Ssam read(FD, &c, 1);
1545130Ssam alarm(0);
1555130Ssam c &= 0177;
1565130Ssam if (c != *s++)
1575130Ssam return (0);
1585130Ssam }
15913277Ssam signal(SIGALRM, f);
16013277Ssam return (timeout == 0);
1615130Ssam }
162