Commit | Line | Data |
---|---|---|
0088db67 | 1 | #ifndef lint |
74040d36 | 2 | static char sccsid[] = "@(#)cds224.c 1.2 (Berkeley) %G%"; |
0088db67 JB |
3 | #endif !lint |
4 | ||
5 | #include "../condevs.h" | |
0088db67 JB |
6 | |
7 | /* | |
8 | * conopn: establish dial-out connection through a Concord CDS 224. | |
9 | * Returns descriptor open to tty for reading and writing. | |
10 | * Negative values (-1...-7) denote errors in connmsg. | |
11 | * Be sure to disconnect tty when done, via HUPCL or stty 0. | |
12 | */ | |
13 | #define TRYS 5 /* number of trys */ | |
14 | ||
15 | cdsopn224(telno, flds, dev) | |
16 | char *telno; | |
17 | char *flds[]; | |
18 | struct Devices *dev; | |
19 | { | |
20 | int dh = -1; | |
21 | int i, ok, er = 0, delay; | |
22 | extern errno; | |
23 | char dcname[20]; | |
24 | char *tempbuf[20]; | |
25 | ||
26 | sprintf(dcname, "/dev/%s", dev->D_line); | |
27 | if (setjmp(Sjbuf)) { | |
28 | DEBUG(1, "timeout concord open\n", ""); | |
29 | logent("concord open", "TIMEOUT"); | |
30 | if (dh >= 0) | |
31 | cdscls224(dh); | |
32 | delock(dev->D_line); | |
33 | return CF_NODEV; | |
34 | } | |
35 | signal(SIGALRM, alarmtr); | |
36 | getnextfd(); | |
37 | alarm(10); | |
38 | dh = open(dcname, 2); | |
39 | alarm(0); | |
40 | ||
41 | /* modem is open */ | |
42 | next_fd = -1; | |
43 | if (dh < 0) { | |
44 | delock(dev->D_line); | |
45 | return CF_NODEV; | |
46 | } | |
47 | fixline(dh, dev->D_speed); | |
48 | ||
49 | DEBUG(4, "calling %s -> ", telno); | |
50 | if (dochat(dev, flds, dh)) { | |
51 | logent(dcname, "CHAT FAILED"); | |
52 | cdscls224(dh); | |
53 | return CF_DIAL; | |
54 | } | |
55 | for(i = 0; i < TRYS; ++i) { | |
56 | /* wake up Concord */ | |
57 | write(dh, "\r\r", 2); | |
58 | DEBUG(4, "wanted CDS >", CNULL); | |
59 | ok = expect("CDS >", dh); | |
60 | DEBUG(4, "got %s\n", ok ? "?" : "that"); | |
61 | if (ok != 0) | |
62 | continue; | |
63 | ||
64 | write(dh, "\r", 2); | |
65 | DEBUG(4, "wanted CDS >", CNULL); | |
66 | ok = expect("CDS >", dh); | |
67 | DEBUG(4, "got %s\n", ok ? "?" : "that"); | |
68 | if (ok != 0) | |
69 | continue; | |
70 | ||
71 | /* send telno \r */ | |
72 | sprintf(tempbuf,"D%s\r",telno); | |
73 | write(dh, tempbuf, strlen(tempbuf)); | |
74 | ||
75 | DEBUG(4, "wanted DIALING ", CNULL); | |
76 | ok = expect("DIALING ", dh); | |
77 | DEBUG(4, "got %s\n", ok ? "?" : "that"); | |
78 | if (ok == 0) | |
79 | break; | |
80 | } | |
81 | ||
82 | if (ok == 0) { | |
83 | sleep(10); /* give concord some time */ | |
84 | DEBUG(4, "wanted INITIATING " , CNULL); | |
85 | ok = expect("INITIATING", dh); | |
86 | DEBUG(4, "got %s\n", ok ? "?" : "that"); | |
87 | } | |
88 | ||
89 | if (ok != 0) { | |
90 | if (dh > 2) | |
91 | close(dh); | |
92 | DEBUG(4, "conDial failed\n", CNULL); | |
93 | delock(dev->D_line); | |
94 | return CF_DIAL; | |
95 | } | |
96 | DEBUG(4, "concord ok\n", CNULL); | |
97 | return dh; | |
98 | } | |
99 | ||
100 | cdscls224(fd) | |
101 | { | |
102 | ||
103 | if (fd > 0) { | |
104 | close(fd); | |
105 | sleep(5); | |
106 | delock(devSel); | |
107 | } | |
108 | } |