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 /*
150Sstevel@tonic-gate * Routines for calling up on a Vadic 3451 Modem
160Sstevel@tonic-gate */
170Sstevel@tonic-gate #include "tip.h"
180Sstevel@tonic-gate
19*549Smuffin static int expect(char *);
20*549Smuffin static int notin(char *, char *);
21*549Smuffin static int prefix(char *, char *);
22*549Smuffin static void vawrite(char *, int);
23*549Smuffin static void alarmtr(void);
240Sstevel@tonic-gate
25*549Smuffin static sigjmp_buf Sjbuf;
26*549Smuffin
27*549Smuffin /* ARGSUSED */
28*549Smuffin int
v3451_dialer(char * num,char * acu)29*549Smuffin v3451_dialer(char *num, char *acu)
300Sstevel@tonic-gate {
310Sstevel@tonic-gate int ok;
32*549Smuffin sig_handler_t func;
330Sstevel@tonic-gate struct termios buf;
340Sstevel@tonic-gate int slow = number(value(BAUDRATE)) < 1200;
350Sstevel@tonic-gate char phone[50];
360Sstevel@tonic-gate #ifdef ACULOG
370Sstevel@tonic-gate char line[80];
380Sstevel@tonic-gate #endif
390Sstevel@tonic-gate
400Sstevel@tonic-gate /*
410Sstevel@tonic-gate * Get in synch
420Sstevel@tonic-gate */
430Sstevel@tonic-gate vawrite("I\r", 1 + slow);
440Sstevel@tonic-gate vawrite("I\r", 1 + slow);
450Sstevel@tonic-gate vawrite("I\r", 1 + slow);
460Sstevel@tonic-gate vawrite("\005\r", 2 + slow);
470Sstevel@tonic-gate if (!expect("READY")) {
48*549Smuffin (void) printf("can't synchronize with vadic 3451\n");
490Sstevel@tonic-gate #ifdef ACULOG
500Sstevel@tonic-gate logent(value(HOST), num, "vadic", "can't synch up");
510Sstevel@tonic-gate #endif
520Sstevel@tonic-gate return (0);
530Sstevel@tonic-gate }
54*549Smuffin (void) ioctl(FD, TCGETS, &buf);
550Sstevel@tonic-gate buf.c_cflag |= HUPCL;
56*549Smuffin (void) ioctl(FD, TCSETSF, &buf);
57*549Smuffin (void) sleep(1);
580Sstevel@tonic-gate vawrite("D\r", 2 + slow);
590Sstevel@tonic-gate if (!expect("NUMBER?")) {
60*549Smuffin (void) printf("Vadic will not accept dial command\n");
610Sstevel@tonic-gate #ifdef ACULOG
620Sstevel@tonic-gate logent(value(HOST), num, "vadic", "will not accept dial");
630Sstevel@tonic-gate #endif
640Sstevel@tonic-gate return (0);
650Sstevel@tonic-gate }
66*549Smuffin (void) strlcpy(phone, num, sizeof (phone));
67*549Smuffin (void) strlcat(phone, "\r", sizeof (phone));
680Sstevel@tonic-gate vawrite(phone, 1 + slow);
690Sstevel@tonic-gate if (!expect(phone)) {
70*549Smuffin (void) printf("Vadic will not accept phone number\n");
710Sstevel@tonic-gate #ifdef ACULOG
720Sstevel@tonic-gate logent(value(HOST), num, "vadic", "will not accept number");
730Sstevel@tonic-gate #endif
740Sstevel@tonic-gate return (0);
750Sstevel@tonic-gate }
760Sstevel@tonic-gate func = signal(SIGINT, SIG_IGN);
770Sstevel@tonic-gate /*
780Sstevel@tonic-gate * You cannot interrupt the Vadic when its dialing;
790Sstevel@tonic-gate * even dropping DTR does not work (definitely a
800Sstevel@tonic-gate * brain damaged design).
810Sstevel@tonic-gate */
820Sstevel@tonic-gate vawrite("\r", 1 + slow);
830Sstevel@tonic-gate vawrite("\r", 1 + slow);
840Sstevel@tonic-gate if (!expect("DIALING:")) {
85*549Smuffin (void) printf("Vadic failed to dial\n");
860Sstevel@tonic-gate #ifdef ACULOG
870Sstevel@tonic-gate logent(value(HOST), num, "vadic", "failed to dial");
880Sstevel@tonic-gate #endif
890Sstevel@tonic-gate return (0);
900Sstevel@tonic-gate }
910Sstevel@tonic-gate if (boolean(value(VERBOSE)))
92*549Smuffin (void) printf("\ndialing...");
930Sstevel@tonic-gate ok = expect("ON LINE");
94*549Smuffin (void) signal(SIGINT, func);
950Sstevel@tonic-gate if (!ok) {
96*549Smuffin (void) printf("call failed\n");
970Sstevel@tonic-gate #ifdef ACULOG
980Sstevel@tonic-gate logent(value(HOST), num, "vadic", "call failed");
990Sstevel@tonic-gate #endif
1000Sstevel@tonic-gate return (0);
1010Sstevel@tonic-gate }
102*549Smuffin (void) ioctl(FD, TCFLSH, TCOFLUSH);
1030Sstevel@tonic-gate return (1);
1040Sstevel@tonic-gate }
1050Sstevel@tonic-gate
106*549Smuffin void
v3451_disconnect(void)107*549Smuffin v3451_disconnect(void)
1080Sstevel@tonic-gate {
1090Sstevel@tonic-gate
110*549Smuffin (void) close(FD);
1110Sstevel@tonic-gate }
1120Sstevel@tonic-gate
113*549Smuffin void
v3451_abort(void)114*549Smuffin v3451_abort(void)
1150Sstevel@tonic-gate {
1160Sstevel@tonic-gate
117*549Smuffin (void) close(FD);
1180Sstevel@tonic-gate }
1190Sstevel@tonic-gate
120*549Smuffin static void
vawrite(char * cp,int delay)121*549Smuffin vawrite(char *cp, int delay)
1220Sstevel@tonic-gate {
1230Sstevel@tonic-gate
124*549Smuffin for (; *cp; (void) sleep(delay), cp++)
125*549Smuffin (void) write(FD, cp, 1);
1260Sstevel@tonic-gate }
1270Sstevel@tonic-gate
128*549Smuffin static int
expect(char * cp)129*549Smuffin expect(char *cp)
1300Sstevel@tonic-gate {
1310Sstevel@tonic-gate char buf[300];
132*549Smuffin char *rp = buf;
1330Sstevel@tonic-gate int timeout = 30, online = 0;
1340Sstevel@tonic-gate
1350Sstevel@tonic-gate if (strcmp(cp, "\"\"") == 0)
1360Sstevel@tonic-gate return (1);
1370Sstevel@tonic-gate *rp = 0;
1380Sstevel@tonic-gate /*
1390Sstevel@tonic-gate * If we are waiting for the Vadic to complete
1400Sstevel@tonic-gate * dialing and get a connection, allow more time
1410Sstevel@tonic-gate * Unfortunately, the Vadic times out 24 seconds after
1420Sstevel@tonic-gate * the last digit is dialed
1430Sstevel@tonic-gate */
1440Sstevel@tonic-gate online = strcmp(cp, "ON LINE") == 0;
1450Sstevel@tonic-gate if (online)
1460Sstevel@tonic-gate timeout = number(value(DIALTIMEOUT));
147*549Smuffin (void) signal(SIGALRM, (sig_handler_t)alarmtr);
1480Sstevel@tonic-gate if (sigsetjmp(Sjbuf, 1))
1490Sstevel@tonic-gate return (0);
150*549Smuffin (void) alarm(timeout);
1510Sstevel@tonic-gate while (notin(cp, buf) && rp < buf + sizeof (buf) - 1) {
1520Sstevel@tonic-gate if (online && notin("FAILED CALL", buf) == 0)
1530Sstevel@tonic-gate return (0);
1540Sstevel@tonic-gate if (read(FD, rp, 1) < 0) {
155*549Smuffin (void) alarm(0);
1560Sstevel@tonic-gate return (0);
1570Sstevel@tonic-gate }
1580Sstevel@tonic-gate if (*rp &= 0177)
1590Sstevel@tonic-gate rp++;
1600Sstevel@tonic-gate *rp = '\0';
1610Sstevel@tonic-gate }
162*549Smuffin (void) alarm(0);
1630Sstevel@tonic-gate return (1);
1640Sstevel@tonic-gate }
1650Sstevel@tonic-gate
1660Sstevel@tonic-gate static void
alarmtr(void)167*549Smuffin alarmtr(void)
1680Sstevel@tonic-gate {
1690Sstevel@tonic-gate
1700Sstevel@tonic-gate siglongjmp(Sjbuf, 1);
1710Sstevel@tonic-gate }
1720Sstevel@tonic-gate
173*549Smuffin static int
notin(char * sh,char * lg)174*549Smuffin notin(char *sh, char *lg)
1750Sstevel@tonic-gate {
1760Sstevel@tonic-gate
1770Sstevel@tonic-gate for (; *lg; lg++)
1780Sstevel@tonic-gate if (prefix(sh, lg))
1790Sstevel@tonic-gate return (0);
1800Sstevel@tonic-gate return (1);
1810Sstevel@tonic-gate }
1820Sstevel@tonic-gate
183*549Smuffin static int
prefix(char * s1,char * s2)184*549Smuffin prefix(char *s1, char *s2)
1850Sstevel@tonic-gate {
186*549Smuffin char c;
1870Sstevel@tonic-gate
1880Sstevel@tonic-gate while ((c = *s1++) == *s2++)
1890Sstevel@tonic-gate if (c == '\0')
1900Sstevel@tonic-gate return (1);
1910Sstevel@tonic-gate return (c == '\0');
1920Sstevel@tonic-gate }
193