1 /*-
2 * Copyright (c) 1985, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * %sccs.include.proprietary.c%
6 */
7
8 #ifndef lint
9 static char sccsid[] = "@(#)va811.c 8.1 (Berkeley) 06/06/93";
10 #endif /* not lint */
11
12 #include "condevs.h"
13
14 /*
15 * Racal-Vadic VA811 dialer with 831 adaptor.
16 * A typical 300 baud L-devices entry is
17 * ACU /dev/tty10 unused 300 va811s
18 * where tty10 is the communication line (D_Line),
19 * and 300 is the line speed.
20 * This is almost identical to RVMACS except that we don't need to
21 * send addresses and modem types, and don't need the fork.
22 * Joe Kelsey, fluke!joe, vax4.1526, Apr 11 1984.
23 */
24
25 #define STX 02 /* Access Adaptor */
26 #define ETX 03 /* Transfer to Dialer */
27 #define SI 017 /* Buffer Empty (end of phone number) */
28 #define SOH 01 /* Abort */
29
va811opn(ph,flds,dev)30 va811opn(ph, flds, dev)
31 char *ph, *flds[];
32 struct Devices *dev;
33 {
34 int va;
35 register int i, tries;
36 char c, dcname[20];
37 char vabuf[35]; /* STX, 31 phone digits, SI, ETX, NUL */
38
39 va = 0;
40 sprintf(dcname, "/dev/%s", dev->D_line);
41 if (setjmp(Sjbuf)) {
42 DEBUG(1, "timeout va811 open\n", 0);
43 logent("va811opn", "TIMEOUT");
44 if (va >= 0)
45 close(va);
46 delock(dev->D_line);
47 return CF_NODEV;
48 }
49 DEBUG(4, "va811: STARTING CALL\n", 0);
50 getnextfd();
51 signal(SIGALRM, alarmtr);
52 alarm(10);
53 va = open(dcname, 2);
54 alarm(0);
55
56 /* line is open */
57 next_fd = -1;
58 if (va < 0) {
59 DEBUG(4, errno == 4 ? "%s: no carrier\n" : "%s: can't open\n",
60 dcname);
61 delock(dev->D_line);
62 logent(dcname, "CAN'T OPEN");
63 return(errno == 4 ? CF_DIAL : CF_NODEV);
64 }
65 fixline(va, dev->D_speed);
66
67 /* first, reset everything */
68 sendthem("\\01\\c", va);
69 DEBUG(4, "wanted %c ", 'B');
70 i = expect("B", va);
71 DEBUG(4, "got %s\n", i ? "?" : "that");
72 if (i != 0) {
73 DEBUG(4, "va811: NO RESPONSE\n", 0);
74 logent("va811 reset", "TIMEOUT");
75 close(va);
76 delock(dev->D_line);
77 return CF_DIAL;
78 }
79
80 sprintf(vabuf, "%c%.31s%c%c\\c", STX, ph, SI, SOH);
81 sendthem(vabuf, va);
82 DEBUG(4, "wanted %c ", 'B');
83 i = expect("B", va);
84 DEBUG(4, "got %s\n", i ? "?" : "that");
85
86 if (i != 0) {
87 DEBUG(4, "va811: STORE NUMBER\n", 0);
88 logent("va811 STORE", _FAILED);
89 close(va);
90 delock(dev->D_line);
91 return CF_DIAL;
92 }
93
94 for (tries = 0; tries < TRYCALLS; tries++) {
95 sprintf(vabuf, "%c%c\\c", STX, ETX);
96 sendthem(vabuf, va);
97 DEBUG(4, "DIALING...", CNULL);
98 i = expect("A", va);
99 DEBUG(4, " %s\n", i ? _FAILED : "SUCCEEDED");
100 if (i != 0) {
101 DEBUG(4, "va811: RESETTING\n", CNULL);
102 logent("va811 DIAL", _FAILED);
103 sendthem("\\01\\c", va);
104 expect("B", va);
105 }
106 else
107 break;
108 }
109
110 if (tries >= TRYCALLS) {
111 close(va);
112 delock(dev->D_line);
113 return CF_DIAL;
114 }
115
116 DEBUG(4, "va811 ok\n", CNULL);
117 return va;
118 }
119
va811cls(fd)120 va811cls(fd)
121 register int fd;
122 {
123 DEBUG(2, "va811 close %d\n", fd);
124 p_chwrite(fd, SOH);
125 /* ioctl(fd, TIOCCDTR, NULL);*/
126 close(fd);
127 delock(devSel);
128 }
129