xref: /illumos-gate/usr/src/cmd/tip/aculib/biz22.c (revision 2a8bcb4efb45d99ac41c94a75c396b362c414f7f)
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 #include "tip.h"
137c478bd9Sstevel@tonic-gate 
147c478bd9Sstevel@tonic-gate #define	DISCONNECT_CMD	"\20\04"	/* disconnection string */
157c478bd9Sstevel@tonic-gate 
16*8d489c7aSmuffin static void	sigALRM(void);
17*8d489c7aSmuffin static int	cmd(char *);
18*8d489c7aSmuffin static int	detect(char *);
19*8d489c7aSmuffin 
207c478bd9Sstevel@tonic-gate static	int timeout = 0;
217c478bd9Sstevel@tonic-gate static	sigjmp_buf timeoutbuf;
227c478bd9Sstevel@tonic-gate 
23*8d489c7aSmuffin void	biz22_disconnect(void);
24*8d489c7aSmuffin 
257c478bd9Sstevel@tonic-gate /*
267c478bd9Sstevel@tonic-gate  * Dial up on a BIZCOMP Model 1022 with either
277c478bd9Sstevel@tonic-gate  * 	tone dialing (mod = "V")
287c478bd9Sstevel@tonic-gate  *	pulse dialing (mod = "W")
297c478bd9Sstevel@tonic-gate  */
307c478bd9Sstevel@tonic-gate static int
biz_dialer(char * num,char * mod)31*8d489c7aSmuffin biz_dialer(char *num, char *mod)
327c478bd9Sstevel@tonic-gate {
33*8d489c7aSmuffin 	int connected = 0;
347c478bd9Sstevel@tonic-gate 	char cbuf[40];
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate 	if (boolean(value(VERBOSE)))
37*8d489c7aSmuffin 		(void) printf("\nstarting call...");
387c478bd9Sstevel@tonic-gate 	/*
397c478bd9Sstevel@tonic-gate 	 * Disable auto-answer and configure for tone/pulse
407c478bd9Sstevel@tonic-gate 	 *  dialing
417c478bd9Sstevel@tonic-gate 	 */
427c478bd9Sstevel@tonic-gate 	if (cmd("\02K\r")) {
43*8d489c7aSmuffin 		(void) printf("can't initialize bizcomp...");
447c478bd9Sstevel@tonic-gate 		return (0);
457c478bd9Sstevel@tonic-gate 	}
46*8d489c7aSmuffin 	(void) strcpy(cbuf, "\02.\r");
477c478bd9Sstevel@tonic-gate 	cbuf[1] = *mod;
487c478bd9Sstevel@tonic-gate 	if (cmd(cbuf)) {
49*8d489c7aSmuffin 		(void) printf("can't set dialing mode...");
507c478bd9Sstevel@tonic-gate 		return (0);
517c478bd9Sstevel@tonic-gate 	}
52*8d489c7aSmuffin 	(void) strcpy(cbuf, "\02D");
53*8d489c7aSmuffin 	(void) strlcat(cbuf, num, sizeof (cbuf));
54*8d489c7aSmuffin 	(void) strlcat(cbuf, "\r", sizeof (cbuf));
55*8d489c7aSmuffin 	(void) write(FD, cbuf, strlen(cbuf));
567c478bd9Sstevel@tonic-gate 	if (!detect("7\r")) {
57*8d489c7aSmuffin 		(void) printf("can't get dial tone...");
587c478bd9Sstevel@tonic-gate 		return (0);
597c478bd9Sstevel@tonic-gate 	}
607c478bd9Sstevel@tonic-gate 	if (boolean(value(VERBOSE)))
61*8d489c7aSmuffin 		(void) printf("ringing...");
627c478bd9Sstevel@tonic-gate 	/*
637c478bd9Sstevel@tonic-gate 	 * The reply from the BIZCOMP should be:
647c478bd9Sstevel@tonic-gate 	 *	2 \r or 7 \r	failure
657c478bd9Sstevel@tonic-gate 	 *	1 \r		success
667c478bd9Sstevel@tonic-gate 	 */
677c478bd9Sstevel@tonic-gate 	connected = detect("1\r");
687c478bd9Sstevel@tonic-gate #ifdef ACULOG
697c478bd9Sstevel@tonic-gate 	if (timeout) {
707c478bd9Sstevel@tonic-gate 		char line[80];
717c478bd9Sstevel@tonic-gate 
72*8d489c7aSmuffin 		(void) sprintf(line, "%d second dial timeout",
737c478bd9Sstevel@tonic-gate 		    number(value(DIALTIMEOUT)));
747c478bd9Sstevel@tonic-gate 		logent(value(HOST), num, "biz1022", line);
757c478bd9Sstevel@tonic-gate 	}
767c478bd9Sstevel@tonic-gate #endif
777c478bd9Sstevel@tonic-gate 	if (timeout)
787c478bd9Sstevel@tonic-gate 		biz22_disconnect();	/* insurance */
797c478bd9Sstevel@tonic-gate 	return (connected);
807c478bd9Sstevel@tonic-gate }
817c478bd9Sstevel@tonic-gate 
82*8d489c7aSmuffin /* ARGSUSED */
83*8d489c7aSmuffin int
biz22w_dialer(char * num,char * acu)84*8d489c7aSmuffin biz22w_dialer(char *num, char *acu)
857c478bd9Sstevel@tonic-gate {
867c478bd9Sstevel@tonic-gate 
877c478bd9Sstevel@tonic-gate 	return (biz_dialer(num, "W"));
887c478bd9Sstevel@tonic-gate }
897c478bd9Sstevel@tonic-gate 
90*8d489c7aSmuffin /* ARGSUSED */
91*8d489c7aSmuffin int
biz22f_dialer(char * num,char * acu)92*8d489c7aSmuffin biz22f_dialer(char *num, char *acu)
937c478bd9Sstevel@tonic-gate {
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate 	return (biz_dialer(num, "V"));
967c478bd9Sstevel@tonic-gate }
977c478bd9Sstevel@tonic-gate 
98*8d489c7aSmuffin void
biz22_disconnect(void)99*8d489c7aSmuffin biz22_disconnect(void)
1007c478bd9Sstevel@tonic-gate {
1017c478bd9Sstevel@tonic-gate 
102*8d489c7aSmuffin 	(void) write(FD, DISCONNECT_CMD, 4);
103*8d489c7aSmuffin 	(void) sleep(2);
104*8d489c7aSmuffin 	(void) ioctl(FD, TCFLSH, TCOFLUSH);
1057c478bd9Sstevel@tonic-gate }
1067c478bd9Sstevel@tonic-gate 
107*8d489c7aSmuffin void
biz22_abort(void)108*8d489c7aSmuffin biz22_abort(void)
1097c478bd9Sstevel@tonic-gate {
1107c478bd9Sstevel@tonic-gate 
111*8d489c7aSmuffin 	(void) write(FD, "\02", 1);
1127c478bd9Sstevel@tonic-gate }
1137c478bd9Sstevel@tonic-gate 
1147c478bd9Sstevel@tonic-gate static void
sigALRM(void)115*8d489c7aSmuffin sigALRM(void)
1167c478bd9Sstevel@tonic-gate {
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate 	timeout = 1;
1197c478bd9Sstevel@tonic-gate 	siglongjmp(timeoutbuf, 1);
1207c478bd9Sstevel@tonic-gate }
1217c478bd9Sstevel@tonic-gate 
1227c478bd9Sstevel@tonic-gate static int
cmd(char * s)123*8d489c7aSmuffin cmd(char *s)
1247c478bd9Sstevel@tonic-gate {
1257c478bd9Sstevel@tonic-gate 	char c;
1267c478bd9Sstevel@tonic-gate 	sig_handler_t f;
1277c478bd9Sstevel@tonic-gate 
128*8d489c7aSmuffin 	(void) write(FD, s, strlen(s));
1297c478bd9Sstevel@tonic-gate 	f = signal(SIGALRM, (sig_handler_t)sigALRM);
1307c478bd9Sstevel@tonic-gate 	if (sigsetjmp(timeoutbuf, 1)) {
1317c478bd9Sstevel@tonic-gate 		biz22_abort();
132*8d489c7aSmuffin 		(void) signal(SIGALRM, f);
1337c478bd9Sstevel@tonic-gate 		return (1);
1347c478bd9Sstevel@tonic-gate 	}
135*8d489c7aSmuffin 	(void) alarm(number(value(DIALTIMEOUT)));
136*8d489c7aSmuffin 	(void) read(FD, &c, 1);
137*8d489c7aSmuffin 	(void) alarm(0);
138*8d489c7aSmuffin 	(void) signal(SIGALRM, f);
1397c478bd9Sstevel@tonic-gate 	c &= 0177;
1407c478bd9Sstevel@tonic-gate 	return (c != '\r');
1417c478bd9Sstevel@tonic-gate }
1427c478bd9Sstevel@tonic-gate 
1437c478bd9Sstevel@tonic-gate static int
detect(char * s)144*8d489c7aSmuffin detect(char *s)
1457c478bd9Sstevel@tonic-gate {
1467c478bd9Sstevel@tonic-gate 	char c;
1477c478bd9Sstevel@tonic-gate 	sig_handler_t f;
1487c478bd9Sstevel@tonic-gate 
1497c478bd9Sstevel@tonic-gate 	f = signal(SIGALRM, (sig_handler_t)sigALRM);
1507c478bd9Sstevel@tonic-gate 	timeout = 0;
1517c478bd9Sstevel@tonic-gate 	while (*s) {
1527c478bd9Sstevel@tonic-gate 		if (sigsetjmp(timeoutbuf, 1)) {
1537c478bd9Sstevel@tonic-gate 			biz22_abort();
1547c478bd9Sstevel@tonic-gate 			break;
1557c478bd9Sstevel@tonic-gate 		}
156*8d489c7aSmuffin 		(void) alarm(number(value(DIALTIMEOUT)));
157*8d489c7aSmuffin 		(void) read(FD, &c, 1);
158*8d489c7aSmuffin 		(void) alarm(0);
1597c478bd9Sstevel@tonic-gate 		c &= 0177;
1607c478bd9Sstevel@tonic-gate 		if (c != *s++)
1617c478bd9Sstevel@tonic-gate 			return (0);
1627c478bd9Sstevel@tonic-gate 	}
163*8d489c7aSmuffin 	(void) signal(SIGALRM, f);
1647c478bd9Sstevel@tonic-gate 	return (timeout == 0);
1657c478bd9Sstevel@tonic-gate }
166