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 /*
137c478bd9Sstevel@tonic-gate * Routines for calling up on a Vadic 3451 Modem
147c478bd9Sstevel@tonic-gate */
157c478bd9Sstevel@tonic-gate #include "tip.h"
167c478bd9Sstevel@tonic-gate
17*8d489c7aSmuffin static int expect(char *);
18*8d489c7aSmuffin static int notin(char *, char *);
19*8d489c7aSmuffin static int prefix(char *, char *);
20*8d489c7aSmuffin static void vawrite(char *, int);
21*8d489c7aSmuffin static void alarmtr(void);
22*8d489c7aSmuffin
23*8d489c7aSmuffin static sigjmp_buf Sjbuf;
247c478bd9Sstevel@tonic-gate
25*8d489c7aSmuffin /* ARGSUSED */
26*8d489c7aSmuffin int
v3451_dialer(char * num,char * acu)27*8d489c7aSmuffin v3451_dialer(char *num, char *acu)
287c478bd9Sstevel@tonic-gate {
297c478bd9Sstevel@tonic-gate int ok;
30*8d489c7aSmuffin sig_handler_t func;
317c478bd9Sstevel@tonic-gate struct termios buf;
327c478bd9Sstevel@tonic-gate int slow = number(value(BAUDRATE)) < 1200;
337c478bd9Sstevel@tonic-gate char phone[50];
347c478bd9Sstevel@tonic-gate #ifdef ACULOG
357c478bd9Sstevel@tonic-gate char line[80];
367c478bd9Sstevel@tonic-gate #endif
377c478bd9Sstevel@tonic-gate
387c478bd9Sstevel@tonic-gate /*
397c478bd9Sstevel@tonic-gate * Get in synch
407c478bd9Sstevel@tonic-gate */
417c478bd9Sstevel@tonic-gate vawrite("I\r", 1 + slow);
427c478bd9Sstevel@tonic-gate vawrite("I\r", 1 + slow);
437c478bd9Sstevel@tonic-gate vawrite("I\r", 1 + slow);
447c478bd9Sstevel@tonic-gate vawrite("\005\r", 2 + slow);
457c478bd9Sstevel@tonic-gate if (!expect("READY")) {
46*8d489c7aSmuffin (void) printf("can't synchronize with vadic 3451\n");
477c478bd9Sstevel@tonic-gate #ifdef ACULOG
487c478bd9Sstevel@tonic-gate logent(value(HOST), num, "vadic", "can't synch up");
497c478bd9Sstevel@tonic-gate #endif
507c478bd9Sstevel@tonic-gate return (0);
517c478bd9Sstevel@tonic-gate }
52*8d489c7aSmuffin (void) ioctl(FD, TCGETS, &buf);
537c478bd9Sstevel@tonic-gate buf.c_cflag |= HUPCL;
54*8d489c7aSmuffin (void) ioctl(FD, TCSETSF, &buf);
55*8d489c7aSmuffin (void) sleep(1);
567c478bd9Sstevel@tonic-gate vawrite("D\r", 2 + slow);
577c478bd9Sstevel@tonic-gate if (!expect("NUMBER?")) {
58*8d489c7aSmuffin (void) printf("Vadic will not accept dial command\n");
597c478bd9Sstevel@tonic-gate #ifdef ACULOG
607c478bd9Sstevel@tonic-gate logent(value(HOST), num, "vadic", "will not accept dial");
617c478bd9Sstevel@tonic-gate #endif
627c478bd9Sstevel@tonic-gate return (0);
637c478bd9Sstevel@tonic-gate }
64*8d489c7aSmuffin (void) strlcpy(phone, num, sizeof (phone));
65*8d489c7aSmuffin (void) strlcat(phone, "\r", sizeof (phone));
667c478bd9Sstevel@tonic-gate vawrite(phone, 1 + slow);
677c478bd9Sstevel@tonic-gate if (!expect(phone)) {
68*8d489c7aSmuffin (void) printf("Vadic will not accept phone number\n");
697c478bd9Sstevel@tonic-gate #ifdef ACULOG
707c478bd9Sstevel@tonic-gate logent(value(HOST), num, "vadic", "will not accept number");
717c478bd9Sstevel@tonic-gate #endif
727c478bd9Sstevel@tonic-gate return (0);
737c478bd9Sstevel@tonic-gate }
747c478bd9Sstevel@tonic-gate func = signal(SIGINT, SIG_IGN);
757c478bd9Sstevel@tonic-gate /*
767c478bd9Sstevel@tonic-gate * You cannot interrupt the Vadic when its dialing;
777c478bd9Sstevel@tonic-gate * even dropping DTR does not work (definitely a
787c478bd9Sstevel@tonic-gate * brain damaged design).
797c478bd9Sstevel@tonic-gate */
807c478bd9Sstevel@tonic-gate vawrite("\r", 1 + slow);
817c478bd9Sstevel@tonic-gate vawrite("\r", 1 + slow);
827c478bd9Sstevel@tonic-gate if (!expect("DIALING:")) {
83*8d489c7aSmuffin (void) printf("Vadic failed to dial\n");
847c478bd9Sstevel@tonic-gate #ifdef ACULOG
857c478bd9Sstevel@tonic-gate logent(value(HOST), num, "vadic", "failed to dial");
867c478bd9Sstevel@tonic-gate #endif
877c478bd9Sstevel@tonic-gate return (0);
887c478bd9Sstevel@tonic-gate }
897c478bd9Sstevel@tonic-gate if (boolean(value(VERBOSE)))
90*8d489c7aSmuffin (void) printf("\ndialing...");
917c478bd9Sstevel@tonic-gate ok = expect("ON LINE");
92*8d489c7aSmuffin (void) signal(SIGINT, func);
937c478bd9Sstevel@tonic-gate if (!ok) {
94*8d489c7aSmuffin (void) printf("call failed\n");
957c478bd9Sstevel@tonic-gate #ifdef ACULOG
967c478bd9Sstevel@tonic-gate logent(value(HOST), num, "vadic", "call failed");
977c478bd9Sstevel@tonic-gate #endif
987c478bd9Sstevel@tonic-gate return (0);
997c478bd9Sstevel@tonic-gate }
100*8d489c7aSmuffin (void) ioctl(FD, TCFLSH, TCOFLUSH);
1017c478bd9Sstevel@tonic-gate return (1);
1027c478bd9Sstevel@tonic-gate }
1037c478bd9Sstevel@tonic-gate
104*8d489c7aSmuffin void
v3451_disconnect(void)105*8d489c7aSmuffin v3451_disconnect(void)
1067c478bd9Sstevel@tonic-gate {
1077c478bd9Sstevel@tonic-gate
108*8d489c7aSmuffin (void) close(FD);
1097c478bd9Sstevel@tonic-gate }
1107c478bd9Sstevel@tonic-gate
111*8d489c7aSmuffin void
v3451_abort(void)112*8d489c7aSmuffin v3451_abort(void)
1137c478bd9Sstevel@tonic-gate {
1147c478bd9Sstevel@tonic-gate
115*8d489c7aSmuffin (void) close(FD);
1167c478bd9Sstevel@tonic-gate }
1177c478bd9Sstevel@tonic-gate
118*8d489c7aSmuffin static void
vawrite(char * cp,int delay)119*8d489c7aSmuffin vawrite(char *cp, int delay)
1207c478bd9Sstevel@tonic-gate {
1217c478bd9Sstevel@tonic-gate
122*8d489c7aSmuffin for (; *cp; (void) sleep(delay), cp++)
123*8d489c7aSmuffin (void) write(FD, cp, 1);
1247c478bd9Sstevel@tonic-gate }
1257c478bd9Sstevel@tonic-gate
126*8d489c7aSmuffin static int
expect(char * cp)127*8d489c7aSmuffin expect(char *cp)
1287c478bd9Sstevel@tonic-gate {
1297c478bd9Sstevel@tonic-gate char buf[300];
130*8d489c7aSmuffin char *rp = buf;
1317c478bd9Sstevel@tonic-gate int timeout = 30, online = 0;
1327c478bd9Sstevel@tonic-gate
1337c478bd9Sstevel@tonic-gate if (strcmp(cp, "\"\"") == 0)
1347c478bd9Sstevel@tonic-gate return (1);
1357c478bd9Sstevel@tonic-gate *rp = 0;
1367c478bd9Sstevel@tonic-gate /*
1377c478bd9Sstevel@tonic-gate * If we are waiting for the Vadic to complete
1387c478bd9Sstevel@tonic-gate * dialing and get a connection, allow more time
1397c478bd9Sstevel@tonic-gate * Unfortunately, the Vadic times out 24 seconds after
1407c478bd9Sstevel@tonic-gate * the last digit is dialed
1417c478bd9Sstevel@tonic-gate */
1427c478bd9Sstevel@tonic-gate online = strcmp(cp, "ON LINE") == 0;
1437c478bd9Sstevel@tonic-gate if (online)
1447c478bd9Sstevel@tonic-gate timeout = number(value(DIALTIMEOUT));
145*8d489c7aSmuffin (void) signal(SIGALRM, (sig_handler_t)alarmtr);
1467c478bd9Sstevel@tonic-gate if (sigsetjmp(Sjbuf, 1))
1477c478bd9Sstevel@tonic-gate return (0);
148*8d489c7aSmuffin (void) alarm(timeout);
1497c478bd9Sstevel@tonic-gate while (notin(cp, buf) && rp < buf + sizeof (buf) - 1) {
1507c478bd9Sstevel@tonic-gate if (online && notin("FAILED CALL", buf) == 0)
1517c478bd9Sstevel@tonic-gate return (0);
1527c478bd9Sstevel@tonic-gate if (read(FD, rp, 1) < 0) {
153*8d489c7aSmuffin (void) alarm(0);
1547c478bd9Sstevel@tonic-gate return (0);
1557c478bd9Sstevel@tonic-gate }
1567c478bd9Sstevel@tonic-gate if (*rp &= 0177)
1577c478bd9Sstevel@tonic-gate rp++;
1587c478bd9Sstevel@tonic-gate *rp = '\0';
1597c478bd9Sstevel@tonic-gate }
160*8d489c7aSmuffin (void) alarm(0);
1617c478bd9Sstevel@tonic-gate return (1);
1627c478bd9Sstevel@tonic-gate }
1637c478bd9Sstevel@tonic-gate
1647c478bd9Sstevel@tonic-gate static void
alarmtr(void)165*8d489c7aSmuffin alarmtr(void)
1667c478bd9Sstevel@tonic-gate {
1677c478bd9Sstevel@tonic-gate
1687c478bd9Sstevel@tonic-gate siglongjmp(Sjbuf, 1);
1697c478bd9Sstevel@tonic-gate }
1707c478bd9Sstevel@tonic-gate
171*8d489c7aSmuffin static int
notin(char * sh,char * lg)172*8d489c7aSmuffin notin(char *sh, char *lg)
1737c478bd9Sstevel@tonic-gate {
1747c478bd9Sstevel@tonic-gate
1757c478bd9Sstevel@tonic-gate for (; *lg; lg++)
1767c478bd9Sstevel@tonic-gate if (prefix(sh, lg))
1777c478bd9Sstevel@tonic-gate return (0);
1787c478bd9Sstevel@tonic-gate return (1);
1797c478bd9Sstevel@tonic-gate }
1807c478bd9Sstevel@tonic-gate
181*8d489c7aSmuffin static int
prefix(char * s1,char * s2)182*8d489c7aSmuffin prefix(char *s1, char *s2)
1837c478bd9Sstevel@tonic-gate {
184*8d489c7aSmuffin char c;
1857c478bd9Sstevel@tonic-gate
1867c478bd9Sstevel@tonic-gate while ((c = *s1++) == *s2++)
1877c478bd9Sstevel@tonic-gate if (c == '\0')
1887c478bd9Sstevel@tonic-gate return (1);
1897c478bd9Sstevel@tonic-gate return (c == '\0');
1907c478bd9Sstevel@tonic-gate }
191