xref: /csrg-svn/usr.bin/uucp/libacu/sy.c (revision 17780)
1*17780Sralph #ifndef lint
2*17780Sralph static char sccsid[] = "@(#)sy.c	4.1 (Berkeley) 01/22/85";
3*17780Sralph #endif
4*17780Sralph 
5*17780Sralph #include "../condevs.h"
6*17780Sralph 
7*17780Sralph #ifdef SYTEK
8*17780Sralph 
9*17780Sralph /*
10*17780Sralph  *	sykopn: establish connection through a sytek port.
11*17780Sralph  *	Returns descriptor open to tty for reading and writing.
12*17780Sralph  *	Negative values (-1...-7) denote errors in connmsg.
13*17780Sralph  *	Will try to change baud rate of local port to match
14*17780Sralph  *	that of the remote side.
15*17780Sralph  */
16*17780Sralph char sykspeed[50];	/* speed to reset to on close */
17*17780Sralph 
18*17780Sralph sykopn(flds)
19*17780Sralph register char *flds[];
20*17780Sralph {
21*17780Sralph 	extern errno;
22*17780Sralph 	char *rindex(), *fdig(), dcname[20];
23*17780Sralph 	int dh, ok = 0, speed;
24*17780Sralph 	register FILE *dfp;
25*17780Sralph 	struct Devices dev;
26*17780Sralph 	char speedbuf[50];
27*17780Sralph 
28*17780Sralph 	dfp = fopen(DEVFILE, "r");
29*17780Sralph 	ASSERT(dfp != NULL, "Can't open", DEVFILE, 0);
30*17780Sralph 
31*17780Sralph 	signal(SIGALRM, alarmtr);
32*17780Sralph 	dh = -1;
33*17780Sralph 	while(rddev(dfp, &dev) != FAIL) {
34*17780Sralph /* we'll set our own speed; F_CLASS is how cynthia configures it every night
35*17780Sralph 		if (strcmp(flds[F_CLASS], dev.D_class) != SAME)
36*17780Sralph 			continue;
37*17780Sralph */
38*17780Sralph 		if (snccmp(flds[F_LINE], dev.D_type) != SAME)
39*17780Sralph 			continue;
40*17780Sralph 		if (mlock(dev.D_line) == FAIL)
41*17780Sralph 			continue;
42*17780Sralph 
43*17780Sralph 		sprintf(dcname, "/dev/%s", dev.D_line);
44*17780Sralph 		getnextfd();
45*17780Sralph 		alarm(10);
46*17780Sralph 		if (setjmp(Sjbuf)) {
47*17780Sralph 			delock(dev.D_line);
48*17780Sralph 			logent(dev.D_line,"sytek open TIMEOUT");
49*17780Sralph 			dh = -1;
50*17780Sralph 			break;
51*17780Sralph 			}
52*17780Sralph 		dh = open(dcname, 2);
53*17780Sralph 		alarm(0);
54*17780Sralph 		next_fd = -1;
55*17780Sralph 		if (dh > 0) {
56*17780Sralph 			break;
57*17780Sralph 			}
58*17780Sralph 		devSel[0] = '\0';
59*17780Sralph 		delock(dev.D_line);
60*17780Sralph 	}
61*17780Sralph 	fclose(dfp);
62*17780Sralph 	if (dh < 0)
63*17780Sralph 		return(CF_NODEV);
64*17780Sralph 
65*17780Sralph 	speed = atoi(fdig(dev.D_class));
66*17780Sralph 	fixline(dh, speed);
67*17780Sralph 	sleep(1);
68*17780Sralph 
69*17780Sralph 	/* negotiate with sytek */
70*17780Sralph 	genbrk(dh, 3);
71*17780Sralph 
72*17780Sralph 	DEBUG(4, "wanted %s ", "#");
73*17780Sralph 	ok = expect("#", dh);
74*17780Sralph 	DEBUG(4, "got %s\n", ok ? "?" : "that");
75*17780Sralph 	if(ok != 0){
76*17780Sralph 		if(atoi(fdig(dev.D_class)) == 9600){
77*17780Sralph 			fixline(dh, 2400);
78*17780Sralph 			speed = 2400;
79*17780Sralph 		} else {
80*17780Sralph 			fixline(dh, 9600);
81*17780Sralph 			speed = 9600;
82*17780Sralph 		}
83*17780Sralph 		sleep(1);
84*17780Sralph 		genbrk(dh, 3);
85*17780Sralph 		ok = expect("#", dh);
86*17780Sralph 		if(ok){
87*17780Sralph 			close(dh);
88*17780Sralph 			DEBUG(4, "sytek BREAK failed\n", "");
89*17780Sralph 			delock(dev.D_line);
90*17780Sralph 			return(CF_DIAL);
91*17780Sralph 		}
92*17780Sralph 	}
93*17780Sralph 	write(dh, "done \r", 6);
94*17780Sralph 	ok = expect("#", dh);
95*17780Sralph 	DEBUG(4, "got %s\n", ok ? "?" : "that");
96*17780Sralph 	if(speed != atoi(fdig(flds[F_CLASS]))){
97*17780Sralph 		DEBUG(4, "changing speed\n", "");
98*17780Sralph 		sprintf(speedbuf, "baud %s\r", fdig(flds[F_CLASS]));
99*17780Sralph 		write(dh, speedbuf, strlen(speedbuf));
100*17780Sralph 		sleep(1);
101*17780Sralph 		speed = atoi(fdig(flds[F_CLASS]));
102*17780Sralph 		fixline(dh, speed);
103*17780Sralph 		genbrk(dh, 3);
104*17780Sralph 		ok = expect("#", dh);
105*17780Sralph 		DEBUG(4, "speed set %s\n", ok ? "failed" : flds[F_CLASS]);
106*17780Sralph 	}
107*17780Sralph 	strcpy(sykspeed, dev.D_class);
108*17780Sralph 	write(dh, "command break\r", 14);
109*17780Sralph 	ok = expect("#", dh);
110*17780Sralph 	DEBUG(4, "got %s\n", ok ? "?" : "that");
111*17780Sralph 	if (ok == 0) {
112*17780Sralph 		write(dh, "call ", 5);
113*17780Sralph 		write(dh, flds[F_PHONE], strlen(flds[F_PHONE]));
114*17780Sralph 		write(dh, "\r", 1);
115*17780Sralph 		DEBUG(4, "sytek dial %s\n", flds[F_PHONE]);
116*17780Sralph 		DEBUG(4, "wanted %s ", "COMPLETED TO ");
117*17780Sralph 		ok = expect("COMPLETED TO ", dh);
118*17780Sralph 		DEBUG(4, "got %s\n", ok ? "?" : "that");
119*17780Sralph 	}
120*17780Sralph 
121*17780Sralph 	if (ok != 0) {
122*17780Sralph 		close(dh);
123*17780Sralph 		DEBUG(4, "sytek failed\n", "");
124*17780Sralph 		delock(dev.D_line);
125*17780Sralph 		return(CF_DIAL);
126*17780Sralph 	} else
127*17780Sralph 		DEBUG(4, "sytek ok\n", "");
128*17780Sralph 
129*17780Sralph 	CU_end = sykcls;
130*17780Sralph 	strcpy(devSel, dev.D_line);	/* for later unlock */
131*17780Sralph 	return(dh);
132*17780Sralph 
133*17780Sralph }
134*17780Sralph 
135*17780Sralph sykcls(fd)
136*17780Sralph register int fd;
137*17780Sralph {
138*17780Sralph 	register int ok, speed;
139*17780Sralph 
140*17780Sralph 
141*17780Sralph 	if (fd > 0) {
142*17780Sralph 		genbrk(fd, 3);
143*17780Sralph 		ok = expect("#", fd);
144*17780Sralph 		DEBUG(4, "got %s\n", ok ? "?" : "that");
145*17780Sralph 		if(ok != 0){
146*17780Sralph 			genbrk(fd, 3);
147*17780Sralph 			ok = expect("#", fd);
148*17780Sralph 		}
149*17780Sralph 		if(ok == 0){
150*17780Sralph 			write(fd, "done 1\r", 7);
151*17780Sralph 			ok = expect("#", fd);
152*17780Sralph 			DEBUG(4, "got %s\n", ok ? "?" : "that");
153*17780Sralph 			DEBUG(4, "reset baud to %s\n", sykspeed);
154*17780Sralph 			write(fd, "baud ", 5);
155*17780Sralph 			write(fd, sykspeed, strlen(sykspeed));
156*17780Sralph 			write(fd, "\r", 1);
157*17780Sralph 			sleep(1);
158*17780Sralph 		}
159*17780Sralph 		close(fd);
160*17780Sralph 		delock(devSel);
161*17780Sralph 	}
162*17780Sralph }
163*17780Sralph #endif SYTEK
164