119817Sdist /*
2*62317Sbostic * Copyright (c) 1983, 1993
3*62317Sbostic * The Regents of the University of California. All rights reserved.
435492Sbostic *
542770Sbostic * %sccs.include.redist.c%
619817Sdist */
719817Sdist
813280Ssam #ifndef lint
9*62317Sbostic static char sccsid[] = "@(#)v3451.c 8.1 (Berkeley) 06/06/93";
1035492Sbostic #endif /* not lint */
1113131Sralph
1213131Sralph /*
1313131Sralph * Routines for calling up on a Vadic 3451 Modem
1413131Sralph */
1513131Sralph #include "tip.h"
1613131Sralph
1713276Ssam static jmp_buf Sjbuf;
1813131Sralph
v3451_dialer(num,acu)1913280Ssam v3451_dialer(num, acu)
2013131Sralph register char *num;
2113131Sralph char *acu;
2213131Sralph {
2339253Sbostic sig_t func;
2439253Sbostic int ok;
2513276Ssam int slow = number(value(BAUDRATE)) < 1200, rw = 2;
2613131Sralph char phone[50];
2713131Sralph #ifdef ACULOG
2813131Sralph char line[80];
2913131Sralph #endif
3046867Sbostic static int expect();
3146867Sbostic static void vawrite();
3213131Sralph
3313131Sralph /*
3413131Sralph * Get in synch
3513131Sralph */
3613276Ssam vawrite("I\r", 1 + slow);
3713276Ssam vawrite("I\r", 1 + slow);
3813276Ssam vawrite("I\r", 1 + slow);
3913276Ssam vawrite("\005\r", 2 + slow);
4013276Ssam if (!expect("READY")) {
4113131Sralph printf("can't synchronize with vadic 3451\n");
4213131Sralph #ifdef ACULOG
4313131Sralph logent(value(HOST), num, "vadic", "can't synch up");
4413131Sralph #endif
4513131Sralph return (0);
4613131Sralph }
4713131Sralph ioctl(FD, TIOCHPCL, 0);
4813131Sralph sleep(1);
4913276Ssam vawrite("D\r", 2 + slow);
5013276Ssam if (!expect("NUMBER?")) {
5113131Sralph printf("Vadic will not accept dial command\n");
5213131Sralph #ifdef ACULOG
5313131Sralph logent(value(HOST), num, "vadic", "will not accept dial");
5413131Sralph #endif
5513131Sralph return (0);
5613131Sralph }
5713276Ssam strcpy(phone, num);
5813276Ssam strcat(phone, "\r");
5913276Ssam vawrite(phone, 1 + slow);
6013276Ssam if (!expect(phone)) {
6113131Sralph printf("Vadic will not accept phone number\n");
6213131Sralph #ifdef ACULOG
6313131Sralph logent(value(HOST), num, "vadic", "will not accept number");
6413131Sralph #endif
6513131Sralph return (0);
6613131Sralph }
6713131Sralph func = signal(SIGINT,SIG_IGN);
6813276Ssam /*
6913276Ssam * You cannot interrupt the Vadic when its dialing;
7013276Ssam * even dropping DTR does not work (definitely a
7113276Ssam * brain damaged design).
7213276Ssam */
7313276Ssam vawrite("\r", 1 + slow);
7413276Ssam vawrite("\r", 1 + slow);
7513276Ssam if (!expect("DIALING:")) {
7613131Sralph printf("Vadic failed to dial\n");
7713131Sralph #ifdef ACULOG
7813131Sralph logent(value(HOST), num, "vadic", "failed to dial");
7913131Sralph #endif
8013131Sralph return (0);
8113276Ssam }
8213276Ssam if (boolean(value(VERBOSE)))
8313276Ssam printf("\ndialing...");
8413131Sralph ok = expect("ON LINE");
8513276Ssam signal(SIGINT, func);
8613276Ssam if (!ok) {
8713131Sralph printf("call failed\n");
8813131Sralph #ifdef ACULOG
8913131Sralph logent(value(HOST), num, "vadic", "call failed");
9013131Sralph #endif
9113131Sralph return (0);
9213131Sralph }
9313276Ssam ioctl(FD, TIOCFLUSH, &rw);
9413131Sralph return (1);
9513131Sralph }
9613131Sralph
v3451_disconnect()9713280Ssam v3451_disconnect()
9813131Sralph {
9913276Ssam
10013131Sralph close(FD);
10113131Sralph }
10213131Sralph
v3451_abort()10313280Ssam v3451_abort()
10413131Sralph {
10513276Ssam
10613276Ssam close(FD);
10713131Sralph }
10813131Sralph
10946867Sbostic static void
vawrite(cp,delay)11013276Ssam vawrite(cp, delay)
11113276Ssam register char *cp;
11213276Ssam int delay;
11313131Sralph {
11413276Ssam
11513276Ssam for (; *cp; sleep(delay), cp++)
11613276Ssam write(FD, cp, 1);
11713131Sralph }
11813131Sralph
11913276Ssam static
expect(cp)12013276Ssam expect(cp)
12113276Ssam register char *cp;
12213131Sralph {
12313276Ssam char buf[300];
12413276Ssam register char *rp = buf;
12546867Sbostic int timeout = 30, online = 0;
12646867Sbostic static int notin();
12746867Sbostic static void alarmtr();
12813131Sralph
12913276Ssam if (strcmp(cp, "\"\"") == 0)
13013276Ssam return (1);
13113131Sralph *rp = 0;
13213131Sralph /*
13313131Sralph * If we are waiting for the Vadic to complete
13413131Sralph * dialing and get a connection, allow more time
13513131Sralph * Unfortunately, the Vadic times out 24 seconds after
13613131Sralph * the last digit is dialed
13713131Sralph */
13813276Ssam online = strcmp(cp, "ON LINE") == 0;
13913276Ssam if (online)
14013276Ssam timeout = number(value(DIALTIMEOUT));
14113131Sralph signal(SIGALRM, alarmtr);
14213276Ssam if (setjmp(Sjbuf))
14313276Ssam return (0);
14413276Ssam alarm(timeout);
14513276Ssam while (notin(cp, buf) && rp < buf + sizeof (buf) - 1) {
14613276Ssam if (online && notin("FAILED CALL", buf) == 0)
14713276Ssam return (0);
14813276Ssam if (read(FD, rp, 1) < 0) {
14913131Sralph alarm(0);
15013276Ssam return (0);
15113131Sralph }
15213276Ssam if (*rp &= 0177)
15313131Sralph rp++;
15413131Sralph *rp = '\0';
15513131Sralph }
15613131Sralph alarm(0);
15713276Ssam return (1);
15813131Sralph }
15913131Sralph
16046867Sbostic static void
alarmtr()16113131Sralph alarmtr()
16213131Sralph {
16313131Sralph longjmp(Sjbuf, 1);
16413131Sralph }
16513131Sralph
16646867Sbostic static int
notin(sh,lg)16713131Sralph notin(sh, lg)
16813276Ssam char *sh, *lg;
16913131Sralph {
17046867Sbostic static int prefix();
17113276Ssam
17213276Ssam for (; *lg; lg++)
17313131Sralph if (prefix(sh, lg))
17413276Ssam return (0);
17513276Ssam return (1);
17613131Sralph }
17713131Sralph
17813276Ssam static
prefix(s1,s2)17913131Sralph prefix(s1, s2)
18013276Ssam register char *s1, *s2;
18113131Sralph {
18213276Ssam register char c;
18313131Sralph
18413131Sralph while ((c = *s1++) == *s2++)
18513131Sralph if (c == '\0')
18613276Ssam return (1);
18713276Ssam return (c == '\0');
18813131Sralph }
189