xref: /onnv-gate/usr/src/cmd/tip/aculib/biz22.c (revision 549:9e644232f978)
10Sstevel@tonic-gate /*
2*549Smuffin  * Copyright 2000 Sun Microsystems, Inc.  All rights reserved.
3*549Smuffin  * Use is subject to license terms.
40Sstevel@tonic-gate  */
50Sstevel@tonic-gate 
60Sstevel@tonic-gate /*
70Sstevel@tonic-gate  * Copyright (c) 1983 Regents of the University of California.
80Sstevel@tonic-gate  * All rights reserved. The Berkeley software License Agreement
90Sstevel@tonic-gate  * specifies the terms and conditions for redistribution.
100Sstevel@tonic-gate  */
11*549Smuffin 
120Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
130Sstevel@tonic-gate 
140Sstevel@tonic-gate #include "tip.h"
150Sstevel@tonic-gate 
160Sstevel@tonic-gate #define	DISCONNECT_CMD	"\20\04"	/* disconnection string */
170Sstevel@tonic-gate 
18*549Smuffin static void	sigALRM(void);
19*549Smuffin static int	cmd(char *);
20*549Smuffin static int	detect(char *);
21*549Smuffin 
220Sstevel@tonic-gate static	int timeout = 0;
230Sstevel@tonic-gate static	sigjmp_buf timeoutbuf;
240Sstevel@tonic-gate 
25*549Smuffin void	biz22_disconnect(void);
26*549Smuffin 
270Sstevel@tonic-gate /*
280Sstevel@tonic-gate  * Dial up on a BIZCOMP Model 1022 with either
290Sstevel@tonic-gate  * 	tone dialing (mod = "V")
300Sstevel@tonic-gate  *	pulse dialing (mod = "W")
310Sstevel@tonic-gate  */
320Sstevel@tonic-gate static int
biz_dialer(char * num,char * mod)33*549Smuffin biz_dialer(char *num, char *mod)
340Sstevel@tonic-gate {
35*549Smuffin 	int connected = 0;
360Sstevel@tonic-gate 	char cbuf[40];
370Sstevel@tonic-gate 
380Sstevel@tonic-gate 	if (boolean(value(VERBOSE)))
39*549Smuffin 		(void) printf("\nstarting call...");
400Sstevel@tonic-gate 	/*
410Sstevel@tonic-gate 	 * Disable auto-answer and configure for tone/pulse
420Sstevel@tonic-gate 	 *  dialing
430Sstevel@tonic-gate 	 */
440Sstevel@tonic-gate 	if (cmd("\02K\r")) {
45*549Smuffin 		(void) printf("can't initialize bizcomp...");
460Sstevel@tonic-gate 		return (0);
470Sstevel@tonic-gate 	}
48*549Smuffin 	(void) strcpy(cbuf, "\02.\r");
490Sstevel@tonic-gate 	cbuf[1] = *mod;
500Sstevel@tonic-gate 	if (cmd(cbuf)) {
51*549Smuffin 		(void) printf("can't set dialing mode...");
520Sstevel@tonic-gate 		return (0);
530Sstevel@tonic-gate 	}
54*549Smuffin 	(void) strcpy(cbuf, "\02D");
55*549Smuffin 	(void) strlcat(cbuf, num, sizeof (cbuf));
56*549Smuffin 	(void) strlcat(cbuf, "\r", sizeof (cbuf));
57*549Smuffin 	(void) write(FD, cbuf, strlen(cbuf));
580Sstevel@tonic-gate 	if (!detect("7\r")) {
59*549Smuffin 		(void) printf("can't get dial tone...");
600Sstevel@tonic-gate 		return (0);
610Sstevel@tonic-gate 	}
620Sstevel@tonic-gate 	if (boolean(value(VERBOSE)))
63*549Smuffin 		(void) printf("ringing...");
640Sstevel@tonic-gate 	/*
650Sstevel@tonic-gate 	 * The reply from the BIZCOMP should be:
660Sstevel@tonic-gate 	 *	2 \r or 7 \r	failure
670Sstevel@tonic-gate 	 *	1 \r		success
680Sstevel@tonic-gate 	 */
690Sstevel@tonic-gate 	connected = detect("1\r");
700Sstevel@tonic-gate #ifdef ACULOG
710Sstevel@tonic-gate 	if (timeout) {
720Sstevel@tonic-gate 		char line[80];
730Sstevel@tonic-gate 
74*549Smuffin 		(void) sprintf(line, "%d second dial timeout",
75*549Smuffin 		    number(value(DIALTIMEOUT)));
760Sstevel@tonic-gate 		logent(value(HOST), num, "biz1022", line);
770Sstevel@tonic-gate 	}
780Sstevel@tonic-gate #endif
790Sstevel@tonic-gate 	if (timeout)
800Sstevel@tonic-gate 		biz22_disconnect();	/* insurance */
810Sstevel@tonic-gate 	return (connected);
820Sstevel@tonic-gate }
830Sstevel@tonic-gate 
84*549Smuffin /* ARGSUSED */
85*549Smuffin int
biz22w_dialer(char * num,char * acu)86*549Smuffin biz22w_dialer(char *num, char *acu)
870Sstevel@tonic-gate {
880Sstevel@tonic-gate 
890Sstevel@tonic-gate 	return (biz_dialer(num, "W"));
900Sstevel@tonic-gate }
910Sstevel@tonic-gate 
92*549Smuffin /* ARGSUSED */
93*549Smuffin int
biz22f_dialer(char * num,char * acu)94*549Smuffin biz22f_dialer(char *num, char *acu)
950Sstevel@tonic-gate {
960Sstevel@tonic-gate 
970Sstevel@tonic-gate 	return (biz_dialer(num, "V"));
980Sstevel@tonic-gate }
990Sstevel@tonic-gate 
100*549Smuffin void
biz22_disconnect(void)101*549Smuffin biz22_disconnect(void)
1020Sstevel@tonic-gate {
1030Sstevel@tonic-gate 
104*549Smuffin 	(void) write(FD, DISCONNECT_CMD, 4);
105*549Smuffin 	(void) sleep(2);
106*549Smuffin 	(void) ioctl(FD, TCFLSH, TCOFLUSH);
1070Sstevel@tonic-gate }
1080Sstevel@tonic-gate 
109*549Smuffin void
biz22_abort(void)110*549Smuffin biz22_abort(void)
1110Sstevel@tonic-gate {
1120Sstevel@tonic-gate 
113*549Smuffin 	(void) write(FD, "\02", 1);
1140Sstevel@tonic-gate }
1150Sstevel@tonic-gate 
1160Sstevel@tonic-gate static void
sigALRM(void)117*549Smuffin sigALRM(void)
1180Sstevel@tonic-gate {
1190Sstevel@tonic-gate 
1200Sstevel@tonic-gate 	timeout = 1;
1210Sstevel@tonic-gate 	siglongjmp(timeoutbuf, 1);
1220Sstevel@tonic-gate }
1230Sstevel@tonic-gate 
1240Sstevel@tonic-gate static int
cmd(char * s)125*549Smuffin cmd(char *s)
1260Sstevel@tonic-gate {
1270Sstevel@tonic-gate 	char c;
1280Sstevel@tonic-gate 	sig_handler_t f;
1290Sstevel@tonic-gate 
130*549Smuffin 	(void) write(FD, s, strlen(s));
1310Sstevel@tonic-gate 	f = signal(SIGALRM, (sig_handler_t)sigALRM);
1320Sstevel@tonic-gate 	if (sigsetjmp(timeoutbuf, 1)) {
1330Sstevel@tonic-gate 		biz22_abort();
134*549Smuffin 		(void) signal(SIGALRM, f);
1350Sstevel@tonic-gate 		return (1);
1360Sstevel@tonic-gate 	}
137*549Smuffin 	(void) alarm(number(value(DIALTIMEOUT)));
138*549Smuffin 	(void) read(FD, &c, 1);
139*549Smuffin 	(void) alarm(0);
140*549Smuffin 	(void) signal(SIGALRM, f);
1410Sstevel@tonic-gate 	c &= 0177;
1420Sstevel@tonic-gate 	return (c != '\r');
1430Sstevel@tonic-gate }
1440Sstevel@tonic-gate 
1450Sstevel@tonic-gate static int
detect(char * s)146*549Smuffin detect(char *s)
1470Sstevel@tonic-gate {
1480Sstevel@tonic-gate 	char c;
1490Sstevel@tonic-gate 	sig_handler_t f;
1500Sstevel@tonic-gate 
1510Sstevel@tonic-gate 	f = signal(SIGALRM, (sig_handler_t)sigALRM);
1520Sstevel@tonic-gate 	timeout = 0;
1530Sstevel@tonic-gate 	while (*s) {
1540Sstevel@tonic-gate 		if (sigsetjmp(timeoutbuf, 1)) {
1550Sstevel@tonic-gate 			biz22_abort();
1560Sstevel@tonic-gate 			break;
1570Sstevel@tonic-gate 		}
158*549Smuffin 		(void) alarm(number(value(DIALTIMEOUT)));
159*549Smuffin 		(void) read(FD, &c, 1);
160*549Smuffin 		(void) alarm(0);
1610Sstevel@tonic-gate 		c &= 0177;
1620Sstevel@tonic-gate 		if (c != *s++)
1630Sstevel@tonic-gate 			return (0);
1640Sstevel@tonic-gate 	}
165*549Smuffin 	(void) signal(SIGALRM, f);
1660Sstevel@tonic-gate 	return (timeout == 0);
1670Sstevel@tonic-gate }
168