148651Sbostic /*-
2*62384Sbostic * Copyright (c) 1985, 1993
3*62384Sbostic * The Regents of the University of California. All rights reserved.
448651Sbostic *
548651Sbostic * %sccs.include.proprietary.c%
648651Sbostic */
748651Sbostic
817785Sralph #ifndef lint
9*62384Sbostic static char sccsid[] = "@(#)vad.c 8.1 (Berkeley) 06/06/93";
1048651Sbostic #endif /* not lint */
1117785Sralph
1246875Sbostic #include "condevs.h"
1317785Sralph
1417785Sralph /*
1517785Sralph * vadopn: establish dial-out connection through a Racal-Vadic 3450.
1617785Sralph * Returns descriptor open to tty for reading and writing.
1717785Sralph * Negative values (-1...-7) denote errors in connmsg.
1817785Sralph * Be sure to disconnect tty when done, via HUPCL or stty 0.
1917785Sralph */
2017785Sralph
vadopn(telno,flds,dev)2117785Sralph vadopn(telno, flds, dev)
2217785Sralph char *telno;
2317785Sralph char *flds[];
2417785Sralph struct Devices *dev;
2517785Sralph {
2617785Sralph int dh = -1;
2717785Sralph int i, ok, er = 0, delay;
2817785Sralph extern errno;
2917785Sralph char dcname[20];
3017785Sralph
3117785Sralph sprintf(dcname, "/dev/%s", dev->D_line);
3217785Sralph if (setjmp(Sjbuf)) {
3317785Sralph DEBUG(1, "timeout vadic open\n", "");
3417785Sralph logent("vadic open", "TIMEOUT");
3517785Sralph if (dh >= 0)
3617785Sralph close(dh);
3717785Sralph delock(dev->D_line);
3817785Sralph return CF_NODEV;
3917785Sralph }
4017785Sralph signal(SIGALRM, alarmtr);
4117785Sralph getnextfd();
4217785Sralph alarm(10);
4317785Sralph dh = open(dcname, 2);
4417785Sralph alarm(0);
4517785Sralph
4617785Sralph /* modem is open */
4717785Sralph next_fd = -1;
4817785Sralph if (dh < 0) {
4917785Sralph delock(dev->D_line);
5017785Sralph return CF_NODEV;
5117785Sralph }
5217785Sralph fixline(dh, dev->D_speed);
5317785Sralph
5417785Sralph DEBUG(4, "calling %s -> ", telno);
5517785Sralph if (dochat(dev, flds, dh)) {
5617785Sralph logent(dcname, "CHAT FAILED");
5717785Sralph close(dh);
5817785Sralph return CF_DIAL;
5917785Sralph }
6017785Sralph delay = 0;
6117785Sralph for (i = 0; i < strlen(telno); ++i) {
6217785Sralph switch(telno[i]) {
6317785Sralph case '=': /* await dial tone */
6417785Sralph case '-':
6517785Sralph case ',':
6617785Sralph case '<':
6717785Sralph case 'K':
6817785Sralph telno[i] = 'K';
6917785Sralph delay += 5;
7017785Sralph break;
7117785Sralph }
7217785Sralph }
7317785Sralph DEBUG(4, "%s\n", telno);
7417785Sralph for(i = 0; i < 5; ++i) { /* make 5 tries */
7517785Sralph /* wake up Vadic */
7625159Sbloom write(dh, "\005", 1);
7725159Sbloom sleep(1);
7825159Sbloom write(dh, "\r", 1);
7917785Sralph DEBUG(4, "wanted * ", CNULL);
8025159Sbloom ok = expect("*~5", dh);
8117785Sralph DEBUG(4, "got %s\n", ok ? "?" : "that");
8217785Sralph if (ok != 0)
8317785Sralph continue;
8417785Sralph
8517785Sralph write(dh, "D\r", 2); /* "D" (enter number) command */
8617785Sralph DEBUG(4, "wanted NUMBER?\\r\\n ", CNULL);
8725159Sbloom ok = expect("NUMBER?\r\n~5", dh);
8817785Sralph DEBUG(4, "got %s\n", ok ? "?" : "that");
8917785Sralph if (ok != 0)
9017785Sralph continue;
9117785Sralph
9217785Sralph /* send telno, send \r */
9317785Sralph write(dh, telno, strlen(telno));
9417785Sralph sleep(1);
9517785Sralph write(dh, "\r", 1);
9617785Sralph DEBUG(4, "wanted %s ", telno);
9717785Sralph ok = expect(telno, dh);
9817785Sralph if (ok == 0)
9917785Sralph ok = expect("\r\n", dh);
10017785Sralph DEBUG(4, "got %s\n", ok ? "?" : "that");
10117785Sralph if (ok != 0)
10217785Sralph continue;
10317785Sralph
10417785Sralph write(dh, "\r", 1); /* confirm number */
10517785Sralph DEBUG(4, "wanted DIALING: ", CNULL);
10617785Sralph ok = expect("DIALING: ", dh);
10717785Sralph DEBUG(4, "got %s\n", ok ? "?" : "that");
10817785Sralph if (ok == 0)
10917785Sralph break;
11017785Sralph }
11117785Sralph
11217785Sralph if (ok == 0) {
11317785Sralph sleep(10 + delay); /* give vadic some time */
11417785Sralph DEBUG(4, "wanted ON LINE\\r\\n ", CNULL);
11517785Sralph ok = expect("ON LINE\r\n", dh);
11617785Sralph DEBUG(4, "got %s\n", ok ? "?" : "that");
11717785Sralph }
11817785Sralph
11917785Sralph if (ok != 0) {
12017785Sralph if (dh > 2)
12117785Sralph close(dh);
12217785Sralph DEBUG(4, "vadDial failed\n", CNULL);
12317785Sralph delock(dev->D_line);
12417785Sralph return CF_DIAL;
12517785Sralph }
12617785Sralph DEBUG(4, "vadic ok\n", CNULL);
12717785Sralph return dh;
12817785Sralph }
12917785Sralph
vadcls(fd)13025159Sbloom vadcls(fd)
13125159Sbloom {
13217785Sralph if (fd > 0) {
13317785Sralph close(fd);
13417785Sralph sleep(5);
13517785Sralph delock(devSel);
13617785Sralph }
13717785Sralph }
138