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