xref: /titanic_50/usr/src/cmd/tip/aculib/biz22.c (revision 8d489c7a815fcac696803219572e95aa01532b0f)
17c478bd9Sstevel@tonic-gate /*
2*8d489c7aSmuffin  * Copyright 2000 Sun Microsystems, Inc.  All rights reserved.
3*8d489c7aSmuffin  * Use is subject to license terms.
47c478bd9Sstevel@tonic-gate  */
57c478bd9Sstevel@tonic-gate 
67c478bd9Sstevel@tonic-gate /*
77c478bd9Sstevel@tonic-gate  * Copyright (c) 1983 Regents of the University of California.
87c478bd9Sstevel@tonic-gate  * All rights reserved. The Berkeley software License Agreement
97c478bd9Sstevel@tonic-gate  * specifies the terms and conditions for redistribution.
107c478bd9Sstevel@tonic-gate  */
11*8d489c7aSmuffin 
127c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
137c478bd9Sstevel@tonic-gate 
147c478bd9Sstevel@tonic-gate #include "tip.h"
157c478bd9Sstevel@tonic-gate 
167c478bd9Sstevel@tonic-gate #define	DISCONNECT_CMD	"\20\04"	/* disconnection string */
177c478bd9Sstevel@tonic-gate 
18*8d489c7aSmuffin static void	sigALRM(void);
19*8d489c7aSmuffin static int	cmd(char *);
20*8d489c7aSmuffin static int	detect(char *);
21*8d489c7aSmuffin 
227c478bd9Sstevel@tonic-gate static	int timeout = 0;
237c478bd9Sstevel@tonic-gate static	sigjmp_buf timeoutbuf;
247c478bd9Sstevel@tonic-gate 
25*8d489c7aSmuffin void	biz22_disconnect(void);
26*8d489c7aSmuffin 
277c478bd9Sstevel@tonic-gate /*
287c478bd9Sstevel@tonic-gate  * Dial up on a BIZCOMP Model 1022 with either
297c478bd9Sstevel@tonic-gate  * 	tone dialing (mod = "V")
307c478bd9Sstevel@tonic-gate  *	pulse dialing (mod = "W")
317c478bd9Sstevel@tonic-gate  */
327c478bd9Sstevel@tonic-gate static int
biz_dialer(char * num,char * mod)33*8d489c7aSmuffin biz_dialer(char *num, char *mod)
347c478bd9Sstevel@tonic-gate {
35*8d489c7aSmuffin 	int connected = 0;
367c478bd9Sstevel@tonic-gate 	char cbuf[40];
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate 	if (boolean(value(VERBOSE)))
39*8d489c7aSmuffin 		(void) printf("\nstarting call...");
407c478bd9Sstevel@tonic-gate 	/*
417c478bd9Sstevel@tonic-gate 	 * Disable auto-answer and configure for tone/pulse
427c478bd9Sstevel@tonic-gate 	 *  dialing
437c478bd9Sstevel@tonic-gate 	 */
447c478bd9Sstevel@tonic-gate 	if (cmd("\02K\r")) {
45*8d489c7aSmuffin 		(void) printf("can't initialize bizcomp...");
467c478bd9Sstevel@tonic-gate 		return (0);
477c478bd9Sstevel@tonic-gate 	}
48*8d489c7aSmuffin 	(void) strcpy(cbuf, "\02.\r");
497c478bd9Sstevel@tonic-gate 	cbuf[1] = *mod;
507c478bd9Sstevel@tonic-gate 	if (cmd(cbuf)) {
51*8d489c7aSmuffin 		(void) printf("can't set dialing mode...");
527c478bd9Sstevel@tonic-gate 		return (0);
537c478bd9Sstevel@tonic-gate 	}
54*8d489c7aSmuffin 	(void) strcpy(cbuf, "\02D");
55*8d489c7aSmuffin 	(void) strlcat(cbuf, num, sizeof (cbuf));
56*8d489c7aSmuffin 	(void) strlcat(cbuf, "\r", sizeof (cbuf));
57*8d489c7aSmuffin 	(void) write(FD, cbuf, strlen(cbuf));
587c478bd9Sstevel@tonic-gate 	if (!detect("7\r")) {
59*8d489c7aSmuffin 		(void) printf("can't get dial tone...");
607c478bd9Sstevel@tonic-gate 		return (0);
617c478bd9Sstevel@tonic-gate 	}
627c478bd9Sstevel@tonic-gate 	if (boolean(value(VERBOSE)))
63*8d489c7aSmuffin 		(void) printf("ringing...");
647c478bd9Sstevel@tonic-gate 	/*
657c478bd9Sstevel@tonic-gate 	 * The reply from the BIZCOMP should be:
667c478bd9Sstevel@tonic-gate 	 *	2 \r or 7 \r	failure
677c478bd9Sstevel@tonic-gate 	 *	1 \r		success
687c478bd9Sstevel@tonic-gate 	 */
697c478bd9Sstevel@tonic-gate 	connected = detect("1\r");
707c478bd9Sstevel@tonic-gate #ifdef ACULOG
717c478bd9Sstevel@tonic-gate 	if (timeout) {
727c478bd9Sstevel@tonic-gate 		char line[80];
737c478bd9Sstevel@tonic-gate 
74*8d489c7aSmuffin 		(void) sprintf(line, "%d second dial timeout",
757c478bd9Sstevel@tonic-gate 		    number(value(DIALTIMEOUT)));
767c478bd9Sstevel@tonic-gate 		logent(value(HOST), num, "biz1022", line);
777c478bd9Sstevel@tonic-gate 	}
787c478bd9Sstevel@tonic-gate #endif
797c478bd9Sstevel@tonic-gate 	if (timeout)
807c478bd9Sstevel@tonic-gate 		biz22_disconnect();	/* insurance */
817c478bd9Sstevel@tonic-gate 	return (connected);
827c478bd9Sstevel@tonic-gate }
837c478bd9Sstevel@tonic-gate 
84*8d489c7aSmuffin /* ARGSUSED */
85*8d489c7aSmuffin int
biz22w_dialer(char * num,char * acu)86*8d489c7aSmuffin biz22w_dialer(char *num, char *acu)
877c478bd9Sstevel@tonic-gate {
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate 	return (biz_dialer(num, "W"));
907c478bd9Sstevel@tonic-gate }
917c478bd9Sstevel@tonic-gate 
92*8d489c7aSmuffin /* ARGSUSED */
93*8d489c7aSmuffin int
biz22f_dialer(char * num,char * acu)94*8d489c7aSmuffin biz22f_dialer(char *num, char *acu)
957c478bd9Sstevel@tonic-gate {
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate 	return (biz_dialer(num, "V"));
987c478bd9Sstevel@tonic-gate }
997c478bd9Sstevel@tonic-gate 
100*8d489c7aSmuffin void
biz22_disconnect(void)101*8d489c7aSmuffin biz22_disconnect(void)
1027c478bd9Sstevel@tonic-gate {
1037c478bd9Sstevel@tonic-gate 
104*8d489c7aSmuffin 	(void) write(FD, DISCONNECT_CMD, 4);
105*8d489c7aSmuffin 	(void) sleep(2);
106*8d489c7aSmuffin 	(void) ioctl(FD, TCFLSH, TCOFLUSH);
1077c478bd9Sstevel@tonic-gate }
1087c478bd9Sstevel@tonic-gate 
109*8d489c7aSmuffin void
biz22_abort(void)110*8d489c7aSmuffin biz22_abort(void)
1117c478bd9Sstevel@tonic-gate {
1127c478bd9Sstevel@tonic-gate 
113*8d489c7aSmuffin 	(void) write(FD, "\02", 1);
1147c478bd9Sstevel@tonic-gate }
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate static void
sigALRM(void)117*8d489c7aSmuffin sigALRM(void)
1187c478bd9Sstevel@tonic-gate {
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate 	timeout = 1;
1217c478bd9Sstevel@tonic-gate 	siglongjmp(timeoutbuf, 1);
1227c478bd9Sstevel@tonic-gate }
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate static int
cmd(char * s)125*8d489c7aSmuffin cmd(char *s)
1267c478bd9Sstevel@tonic-gate {
1277c478bd9Sstevel@tonic-gate 	char c;
1287c478bd9Sstevel@tonic-gate 	sig_handler_t f;
1297c478bd9Sstevel@tonic-gate 
130*8d489c7aSmuffin 	(void) write(FD, s, strlen(s));
1317c478bd9Sstevel@tonic-gate 	f = signal(SIGALRM, (sig_handler_t)sigALRM);
1327c478bd9Sstevel@tonic-gate 	if (sigsetjmp(timeoutbuf, 1)) {
1337c478bd9Sstevel@tonic-gate 		biz22_abort();
134*8d489c7aSmuffin 		(void) signal(SIGALRM, f);
1357c478bd9Sstevel@tonic-gate 		return (1);
1367c478bd9Sstevel@tonic-gate 	}
137*8d489c7aSmuffin 	(void) alarm(number(value(DIALTIMEOUT)));
138*8d489c7aSmuffin 	(void) read(FD, &c, 1);
139*8d489c7aSmuffin 	(void) alarm(0);
140*8d489c7aSmuffin 	(void) signal(SIGALRM, f);
1417c478bd9Sstevel@tonic-gate 	c &= 0177;
1427c478bd9Sstevel@tonic-gate 	return (c != '\r');
1437c478bd9Sstevel@tonic-gate }
1447c478bd9Sstevel@tonic-gate 
1457c478bd9Sstevel@tonic-gate static int
detect(char * s)146*8d489c7aSmuffin detect(char *s)
1477c478bd9Sstevel@tonic-gate {
1487c478bd9Sstevel@tonic-gate 	char c;
1497c478bd9Sstevel@tonic-gate 	sig_handler_t f;
1507c478bd9Sstevel@tonic-gate 
1517c478bd9Sstevel@tonic-gate 	f = signal(SIGALRM, (sig_handler_t)sigALRM);
1527c478bd9Sstevel@tonic-gate 	timeout = 0;
1537c478bd9Sstevel@tonic-gate 	while (*s) {
1547c478bd9Sstevel@tonic-gate 		if (sigsetjmp(timeoutbuf, 1)) {
1557c478bd9Sstevel@tonic-gate 			biz22_abort();
1567c478bd9Sstevel@tonic-gate 			break;
1577c478bd9Sstevel@tonic-gate 		}
158*8d489c7aSmuffin 		(void) alarm(number(value(DIALTIMEOUT)));
159*8d489c7aSmuffin 		(void) read(FD, &c, 1);
160*8d489c7aSmuffin 		(void) alarm(0);
1617c478bd9Sstevel@tonic-gate 		c &= 0177;
1627c478bd9Sstevel@tonic-gate 		if (c != *s++)
1637c478bd9Sstevel@tonic-gate 			return (0);
1647c478bd9Sstevel@tonic-gate 	}
165*8d489c7aSmuffin 	(void) signal(SIGALRM, f);
1667c478bd9Sstevel@tonic-gate 	return (timeout == 0);
1677c478bd9Sstevel@tonic-gate }
168