xref: /illumos-gate/usr/src/cmd/tip/aculib/v3451.c (revision 8d489c7a)
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 /*
157c478bd9Sstevel@tonic-gate  * Routines for calling up on a Vadic 3451 Modem
167c478bd9Sstevel@tonic-gate  */
177c478bd9Sstevel@tonic-gate #include "tip.h"
187c478bd9Sstevel@tonic-gate 
19*8d489c7aSmuffin static int	expect(char *);
20*8d489c7aSmuffin static int	notin(char *, char *);
21*8d489c7aSmuffin static int	prefix(char *, char *);
22*8d489c7aSmuffin static void	vawrite(char *, int);
23*8d489c7aSmuffin static void	alarmtr(void);
24*8d489c7aSmuffin 
25*8d489c7aSmuffin static sigjmp_buf	Sjbuf;
267c478bd9Sstevel@tonic-gate 
27*8d489c7aSmuffin /* ARGSUSED */
28*8d489c7aSmuffin int
v3451_dialer(char * num,char * acu)29*8d489c7aSmuffin v3451_dialer(char *num, char *acu)
307c478bd9Sstevel@tonic-gate {
317c478bd9Sstevel@tonic-gate 	int ok;
32*8d489c7aSmuffin 	sig_handler_t	func;
337c478bd9Sstevel@tonic-gate 	struct termios buf;
347c478bd9Sstevel@tonic-gate 	int slow = number(value(BAUDRATE)) < 1200;
357c478bd9Sstevel@tonic-gate 	char phone[50];
367c478bd9Sstevel@tonic-gate #ifdef ACULOG
377c478bd9Sstevel@tonic-gate 	char line[80];
387c478bd9Sstevel@tonic-gate #endif
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate 	/*
417c478bd9Sstevel@tonic-gate 	 * Get in synch
427c478bd9Sstevel@tonic-gate 	 */
437c478bd9Sstevel@tonic-gate 	vawrite("I\r", 1 + slow);
447c478bd9Sstevel@tonic-gate 	vawrite("I\r", 1 + slow);
457c478bd9Sstevel@tonic-gate 	vawrite("I\r", 1 + slow);
467c478bd9Sstevel@tonic-gate 	vawrite("\005\r", 2 + slow);
477c478bd9Sstevel@tonic-gate 	if (!expect("READY")) {
48*8d489c7aSmuffin 		(void) printf("can't synchronize with vadic 3451\n");
497c478bd9Sstevel@tonic-gate #ifdef ACULOG
507c478bd9Sstevel@tonic-gate 		logent(value(HOST), num, "vadic", "can't synch up");
517c478bd9Sstevel@tonic-gate #endif
527c478bd9Sstevel@tonic-gate 		return (0);
537c478bd9Sstevel@tonic-gate 	}
54*8d489c7aSmuffin 	(void) ioctl(FD, TCGETS, &buf);
557c478bd9Sstevel@tonic-gate 	buf.c_cflag |= HUPCL;
56*8d489c7aSmuffin 	(void) ioctl(FD, TCSETSF, &buf);
57*8d489c7aSmuffin 	(void) sleep(1);
587c478bd9Sstevel@tonic-gate 	vawrite("D\r", 2 + slow);
597c478bd9Sstevel@tonic-gate 	if (!expect("NUMBER?")) {
60*8d489c7aSmuffin 		(void) printf("Vadic will not accept dial command\n");
617c478bd9Sstevel@tonic-gate #ifdef ACULOG
627c478bd9Sstevel@tonic-gate 		logent(value(HOST), num, "vadic", "will not accept dial");
637c478bd9Sstevel@tonic-gate #endif
647c478bd9Sstevel@tonic-gate 		return (0);
657c478bd9Sstevel@tonic-gate 	}
66*8d489c7aSmuffin 	(void) strlcpy(phone, num, sizeof (phone));
67*8d489c7aSmuffin 	(void) strlcat(phone, "\r", sizeof (phone));
687c478bd9Sstevel@tonic-gate 	vawrite(phone, 1 + slow);
697c478bd9Sstevel@tonic-gate 	if (!expect(phone)) {
70*8d489c7aSmuffin 		(void) printf("Vadic will not accept phone number\n");
717c478bd9Sstevel@tonic-gate #ifdef ACULOG
727c478bd9Sstevel@tonic-gate 		logent(value(HOST), num, "vadic", "will not accept number");
737c478bd9Sstevel@tonic-gate #endif
747c478bd9Sstevel@tonic-gate 		return (0);
757c478bd9Sstevel@tonic-gate 	}
767c478bd9Sstevel@tonic-gate 	func = signal(SIGINT, SIG_IGN);
777c478bd9Sstevel@tonic-gate 	/*
787c478bd9Sstevel@tonic-gate 	 * You cannot interrupt the Vadic when its dialing;
797c478bd9Sstevel@tonic-gate 	 * even dropping DTR does not work (definitely a
807c478bd9Sstevel@tonic-gate 	 * brain damaged design).
817c478bd9Sstevel@tonic-gate 	 */
827c478bd9Sstevel@tonic-gate 	vawrite("\r", 1 + slow);
837c478bd9Sstevel@tonic-gate 	vawrite("\r", 1 + slow);
847c478bd9Sstevel@tonic-gate 	if (!expect("DIALING:")) {
85*8d489c7aSmuffin 		(void) printf("Vadic failed to dial\n");
867c478bd9Sstevel@tonic-gate #ifdef ACULOG
877c478bd9Sstevel@tonic-gate 		logent(value(HOST), num, "vadic", "failed to dial");
887c478bd9Sstevel@tonic-gate #endif
897c478bd9Sstevel@tonic-gate 		return (0);
907c478bd9Sstevel@tonic-gate 	}
917c478bd9Sstevel@tonic-gate 	if (boolean(value(VERBOSE)))
92*8d489c7aSmuffin 		(void) printf("\ndialing...");
937c478bd9Sstevel@tonic-gate 	ok = expect("ON LINE");
94*8d489c7aSmuffin 	(void) signal(SIGINT, func);
957c478bd9Sstevel@tonic-gate 	if (!ok) {
96*8d489c7aSmuffin 		(void) printf("call failed\n");
977c478bd9Sstevel@tonic-gate #ifdef ACULOG
987c478bd9Sstevel@tonic-gate 		logent(value(HOST), num, "vadic", "call failed");
997c478bd9Sstevel@tonic-gate #endif
1007c478bd9Sstevel@tonic-gate 		return (0);
1017c478bd9Sstevel@tonic-gate 	}
102*8d489c7aSmuffin 	(void) ioctl(FD, TCFLSH, TCOFLUSH);
1037c478bd9Sstevel@tonic-gate 	return (1);
1047c478bd9Sstevel@tonic-gate }
1057c478bd9Sstevel@tonic-gate 
106*8d489c7aSmuffin void
v3451_disconnect(void)107*8d489c7aSmuffin v3451_disconnect(void)
1087c478bd9Sstevel@tonic-gate {
1097c478bd9Sstevel@tonic-gate 
110*8d489c7aSmuffin 	(void) close(FD);
1117c478bd9Sstevel@tonic-gate }
1127c478bd9Sstevel@tonic-gate 
113*8d489c7aSmuffin void
v3451_abort(void)114*8d489c7aSmuffin v3451_abort(void)
1157c478bd9Sstevel@tonic-gate {
1167c478bd9Sstevel@tonic-gate 
117*8d489c7aSmuffin 	(void) close(FD);
1187c478bd9Sstevel@tonic-gate }
1197c478bd9Sstevel@tonic-gate 
120*8d489c7aSmuffin static void
vawrite(char * cp,int delay)121*8d489c7aSmuffin vawrite(char *cp, int delay)
1227c478bd9Sstevel@tonic-gate {
1237c478bd9Sstevel@tonic-gate 
124*8d489c7aSmuffin 	for (; *cp; (void) sleep(delay), cp++)
125*8d489c7aSmuffin 		(void) write(FD, cp, 1);
1267c478bd9Sstevel@tonic-gate }
1277c478bd9Sstevel@tonic-gate 
128*8d489c7aSmuffin static int
expect(char * cp)129*8d489c7aSmuffin expect(char *cp)
1307c478bd9Sstevel@tonic-gate {
1317c478bd9Sstevel@tonic-gate 	char buf[300];
132*8d489c7aSmuffin 	char *rp = buf;
1337c478bd9Sstevel@tonic-gate 	int timeout = 30, online = 0;
1347c478bd9Sstevel@tonic-gate 
1357c478bd9Sstevel@tonic-gate 	if (strcmp(cp, "\"\"") == 0)
1367c478bd9Sstevel@tonic-gate 		return (1);
1377c478bd9Sstevel@tonic-gate 	*rp = 0;
1387c478bd9Sstevel@tonic-gate 	/*
1397c478bd9Sstevel@tonic-gate 	 * If we are waiting for the Vadic to complete
1407c478bd9Sstevel@tonic-gate 	 * dialing and get a connection, allow more time
1417c478bd9Sstevel@tonic-gate 	 * Unfortunately, the Vadic times out 24 seconds after
1427c478bd9Sstevel@tonic-gate 	 * the last digit is dialed
1437c478bd9Sstevel@tonic-gate 	 */
1447c478bd9Sstevel@tonic-gate 	online = strcmp(cp, "ON LINE") == 0;
1457c478bd9Sstevel@tonic-gate 	if (online)
1467c478bd9Sstevel@tonic-gate 		timeout = number(value(DIALTIMEOUT));
147*8d489c7aSmuffin 	(void) signal(SIGALRM, (sig_handler_t)alarmtr);
1487c478bd9Sstevel@tonic-gate 	if (sigsetjmp(Sjbuf, 1))
1497c478bd9Sstevel@tonic-gate 		return (0);
150*8d489c7aSmuffin 	(void) alarm(timeout);
1517c478bd9Sstevel@tonic-gate 	while (notin(cp, buf) && rp < buf + sizeof (buf) - 1) {
1527c478bd9Sstevel@tonic-gate 		if (online && notin("FAILED CALL", buf) == 0)
1537c478bd9Sstevel@tonic-gate 			return (0);
1547c478bd9Sstevel@tonic-gate 		if (read(FD, rp, 1) < 0) {
155*8d489c7aSmuffin 			(void) alarm(0);
1567c478bd9Sstevel@tonic-gate 			return (0);
1577c478bd9Sstevel@tonic-gate 		}
1587c478bd9Sstevel@tonic-gate 		if (*rp &= 0177)
1597c478bd9Sstevel@tonic-gate 			rp++;
1607c478bd9Sstevel@tonic-gate 		*rp = '\0';
1617c478bd9Sstevel@tonic-gate 	}
162*8d489c7aSmuffin 	(void) alarm(0);
1637c478bd9Sstevel@tonic-gate 	return (1);
1647c478bd9Sstevel@tonic-gate }
1657c478bd9Sstevel@tonic-gate 
1667c478bd9Sstevel@tonic-gate static void
alarmtr(void)167*8d489c7aSmuffin alarmtr(void)
1687c478bd9Sstevel@tonic-gate {
1697c478bd9Sstevel@tonic-gate 
1707c478bd9Sstevel@tonic-gate 	siglongjmp(Sjbuf, 1);
1717c478bd9Sstevel@tonic-gate }
1727c478bd9Sstevel@tonic-gate 
173*8d489c7aSmuffin static int
notin(char * sh,char * lg)174*8d489c7aSmuffin notin(char *sh, char *lg)
1757c478bd9Sstevel@tonic-gate {
1767c478bd9Sstevel@tonic-gate 
1777c478bd9Sstevel@tonic-gate 	for (; *lg; lg++)
1787c478bd9Sstevel@tonic-gate 		if (prefix(sh, lg))
1797c478bd9Sstevel@tonic-gate 			return (0);
1807c478bd9Sstevel@tonic-gate 	return (1);
1817c478bd9Sstevel@tonic-gate }
1827c478bd9Sstevel@tonic-gate 
183*8d489c7aSmuffin static int
prefix(char * s1,char * s2)184*8d489c7aSmuffin prefix(char *s1, char *s2)
1857c478bd9Sstevel@tonic-gate {
186*8d489c7aSmuffin 	char c;
1877c478bd9Sstevel@tonic-gate 
1887c478bd9Sstevel@tonic-gate 	while ((c = *s1++) == *s2++)
1897c478bd9Sstevel@tonic-gate 		if (c == '\0')
1907c478bd9Sstevel@tonic-gate 			return (1);
1917c478bd9Sstevel@tonic-gate 	return (c == '\0');
1927c478bd9Sstevel@tonic-gate }
193