biz22.c revision 7527
17527Sjkh/*
27527Sjkh * Copyright (c) 1983, 1993
37527Sjkh *	The Regents of the University of California.  All rights reserved.
47527Sjkh *
57527Sjkh * Redistribution and use in source and binary forms, with or without
67527Sjkh * modification, are permitted provided that the following conditions
77527Sjkh * are met:
87527Sjkh * 1. Redistributions of source code must retain the above copyright
97527Sjkh *    notice, this list of conditions and the following disclaimer.
107527Sjkh * 2. Redistributions in binary form must reproduce the above copyright
117527Sjkh *    notice, this list of conditions and the following disclaimer in the
127527Sjkh *    documentation and/or other materials provided with the distribution.
137527Sjkh * 3. All advertising materials mentioning features or use of this software
147527Sjkh *    must display the following acknowledgement:
157527Sjkh *	This product includes software developed by the University of
167527Sjkh *	California, Berkeley and its contributors.
177527Sjkh * 4. Neither the name of the University nor the names of its contributors
187527Sjkh *    may be used to endorse or promote products derived from this software
197527Sjkh *    without specific prior written permission.
207527Sjkh *
217527Sjkh * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
227527Sjkh * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
237527Sjkh * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
247527Sjkh * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
257527Sjkh * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
267527Sjkh * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
277527Sjkh * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
287527Sjkh * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
297527Sjkh * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
307527Sjkh * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
317527Sjkh * SUCH DAMAGE.
327527Sjkh */
337527Sjkh
347527Sjkh#ifndef lint
357527Sjkhstatic char sccsid[] = "@(#)biz22.c	8.1 (Berkeley) 6/6/93";
367527Sjkh#endif /* not lint */
377527Sjkh
387527Sjkh#include "tipconf.h"
397527Sjkh#include "tip.h"
407527Sjkh
417527Sjkh#define DISCONNECT_CMD	"\20\04"	/* disconnection string */
427527Sjkh
437527Sjkhstatic	void sigALRM();
447527Sjkhstatic	int timeout = 0;
457527Sjkhstatic	jmp_buf timeoutbuf;
467527Sjkh
477527Sjkh/*
487527Sjkh * Dial up on a BIZCOMP Model 1022 with either
497527Sjkh * 	tone dialing (mod = "V")
507527Sjkh *	pulse dialing (mod = "W")
517527Sjkh */
527527Sjkhstatic int
537527Sjkhbiz_dialer(num, mod)
547527Sjkh	char *num, *mod;
557527Sjkh{
567527Sjkh	register int connected = 0;
577527Sjkh	char cbuf[40];
587527Sjkh	static int cmd(), detect();
597527Sjkh
607527Sjkh	if (boolean(value(VERBOSE)))
617527Sjkh		printf("\nstarting call...");
627527Sjkh	/*
637527Sjkh	 * Disable auto-answer and configure for tone/pulse
647527Sjkh	 *  dialing
657527Sjkh	 */
667527Sjkh	if (cmd("\02K\r")) {
677527Sjkh		printf("can't initialize bizcomp...");
687527Sjkh		return (0);
697527Sjkh	}
707527Sjkh	strcpy(cbuf, "\02.\r");
717527Sjkh	cbuf[1] = *mod;
727527Sjkh	if (cmd(cbuf)) {
737527Sjkh		printf("can't set dialing mode...");
747527Sjkh		return (0);
757527Sjkh	}
767527Sjkh	strcpy(cbuf, "\02D");
777527Sjkh	strcat(cbuf, num);
787527Sjkh	strcat(cbuf, "\r");
797527Sjkh	write(FD, cbuf, strlen(cbuf));
807527Sjkh	if (!detect("7\r")) {
817527Sjkh		printf("can't get dial tone...");
827527Sjkh		return (0);
837527Sjkh	}
847527Sjkh	if (boolean(value(VERBOSE)))
857527Sjkh		printf("ringing...");
867527Sjkh	/*
877527Sjkh	 * The reply from the BIZCOMP should be:
887527Sjkh	 *	2 \r or 7 \r	failure
897527Sjkh	 *	1 \r		success
907527Sjkh	 */
917527Sjkh	connected = detect("1\r");
927527Sjkh#if ACULOG
937527Sjkh	if (timeout) {
947527Sjkh		char line[80];
957527Sjkh
967527Sjkh		sprintf(line, "%d second dial timeout",
977527Sjkh			number(value(DIALTIMEOUT)));
987527Sjkh		logent(value(HOST), num, "biz1022", line);
997527Sjkh	}
1007527Sjkh#endif
1017527Sjkh	if (timeout)
1027527Sjkh		biz22_disconnect();	/* insurance */
1037527Sjkh	return (connected);
1047527Sjkh}
1057527Sjkh
1067527Sjkhbiz22w_dialer(num, acu)
1077527Sjkh	char *num, *acu;
1087527Sjkh{
1097527Sjkh
1107527Sjkh	return (biz_dialer(num, "W"));
1117527Sjkh}
1127527Sjkh
1137527Sjkhbiz22f_dialer(num, acu)
1147527Sjkh	char *num, *acu;
1157527Sjkh{
1167527Sjkh
1177527Sjkh	return (biz_dialer(num, "V"));
1187527Sjkh}
1197527Sjkh
1207527Sjkhbiz22_disconnect()
1217527Sjkh{
1227527Sjkh	int rw = 2;
1237527Sjkh
1247527Sjkh	write(FD, DISCONNECT_CMD, 4);
1257527Sjkh	sleep(2);
1267527Sjkh	ioctl(FD, TIOCFLUSH, &rw);
1277527Sjkh}
1287527Sjkh
1297527Sjkhbiz22_abort()
1307527Sjkh{
1317527Sjkh
1327527Sjkh	write(FD, "\02", 1);
1337527Sjkh}
1347527Sjkh
1357527Sjkhstatic void
1367527SjkhsigALRM()
1377527Sjkh{
1387527Sjkh
1397527Sjkh	timeout = 1;
1407527Sjkh	longjmp(timeoutbuf, 1);
1417527Sjkh}
1427527Sjkh
1437527Sjkhstatic int
1447527Sjkhcmd(s)
1457527Sjkh	register char *s;
1467527Sjkh{
1477527Sjkh	sig_t f;
1487527Sjkh	char c;
1497527Sjkh
1507527Sjkh	write(FD, s, strlen(s));
1517527Sjkh	f = signal(SIGALRM, sigALRM);
1527527Sjkh	if (setjmp(timeoutbuf)) {
1537527Sjkh		biz22_abort();
1547527Sjkh		signal(SIGALRM, f);
1557527Sjkh		return (1);
1567527Sjkh	}
1577527Sjkh	alarm(number(value(DIALTIMEOUT)));
1587527Sjkh	read(FD, &c, 1);
1597527Sjkh	alarm(0);
1607527Sjkh	signal(SIGALRM, f);
1617527Sjkh	c &= 0177;
1627527Sjkh	return (c != '\r');
1637527Sjkh}
1647527Sjkh
1657527Sjkhstatic int
1667527Sjkhdetect(s)
1677527Sjkh	register char *s;
1687527Sjkh{
1697527Sjkh	sig_t f;
1707527Sjkh	char c;
1717527Sjkh
1727527Sjkh	f = signal(SIGALRM, sigALRM);
1737527Sjkh	timeout = 0;
1747527Sjkh	while (*s) {
1757527Sjkh		if (setjmp(timeoutbuf)) {
1767527Sjkh			biz22_abort();
1777527Sjkh			break;
1787527Sjkh		}
1797527Sjkh		alarm(number(value(DIALTIMEOUT)));
1807527Sjkh		read(FD, &c, 1);
1817527Sjkh		alarm(0);
1827527Sjkh		c &= 0177;
1837527Sjkh		if (c != *s++)
1847527Sjkh			return (0);
1857527Sjkh	}
1867527Sjkh	signal(SIGALRM, f);
1877527Sjkh	return (timeout == 0);
1887527Sjkh}
189