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
817780Sralph #ifndef lint
9*62384Sbostic static char sccsid[] = "@(#)sy.c 8.1 (Berkeley) 06/06/93";
1048651Sbostic #endif /* not lint */
1117780Sralph
1246875Sbostic #include "condevs.h"
1317780Sralph
1417780Sralph #ifdef SYTEK
1517780Sralph
1617780Sralph /*
1717780Sralph * sykopn: establish connection through a sytek port.
1817780Sralph * Returns descriptor open to tty for reading and writing.
1917780Sralph * Negative values (-1...-7) denote errors in connmsg.
2017780Sralph * Will try to change baud rate of local port to match
2117780Sralph * that of the remote side.
2217780Sralph */
2317780Sralph char sykspeed[50]; /* speed to reset to on close */
2417780Sralph
sykopn(flds)2517780Sralph sykopn(flds)
2617780Sralph register char *flds[];
2717780Sralph {
2817780Sralph extern errno;
2917780Sralph char *rindex(), *fdig(), dcname[20];
3017780Sralph int dh, ok = 0, speed;
3117780Sralph register FILE *dfp;
3217780Sralph struct Devices dev;
3317780Sralph char speedbuf[50];
3417780Sralph
3517780Sralph dfp = fopen(DEVFILE, "r");
3617780Sralph ASSERT(dfp != NULL, "Can't open", DEVFILE, 0);
3717780Sralph
3817780Sralph signal(SIGALRM, alarmtr);
3917780Sralph dh = -1;
4017780Sralph while(rddev(dfp, &dev) != FAIL) {
4117780Sralph /* we'll set our own speed; F_CLASS is how cynthia configures it every night
4217780Sralph if (strcmp(flds[F_CLASS], dev.D_class) != SAME)
4317780Sralph continue;
4417780Sralph */
4517780Sralph if (snccmp(flds[F_LINE], dev.D_type) != SAME)
4617780Sralph continue;
4717780Sralph if (mlock(dev.D_line) == FAIL)
4817780Sralph continue;
4917780Sralph
5017780Sralph sprintf(dcname, "/dev/%s", dev.D_line);
5117780Sralph getnextfd();
5217780Sralph alarm(10);
5317780Sralph if (setjmp(Sjbuf)) {
5417780Sralph delock(dev.D_line);
5517780Sralph logent(dev.D_line,"sytek open TIMEOUT");
5617780Sralph dh = -1;
5717780Sralph break;
5817780Sralph }
5917780Sralph dh = open(dcname, 2);
6017780Sralph alarm(0);
6117780Sralph next_fd = -1;
6217780Sralph if (dh > 0) {
6317780Sralph break;
6417780Sralph }
6517780Sralph devSel[0] = '\0';
6617780Sralph delock(dev.D_line);
6717780Sralph }
6817780Sralph fclose(dfp);
6917780Sralph if (dh < 0)
7017780Sralph return(CF_NODEV);
7117780Sralph
7217780Sralph speed = atoi(fdig(dev.D_class));
7317780Sralph fixline(dh, speed);
7417780Sralph sleep(1);
7517780Sralph
7617780Sralph /* negotiate with sytek */
7717780Sralph genbrk(dh, 3);
7817780Sralph
7917780Sralph DEBUG(4, "wanted %s ", "#");
8017780Sralph ok = expect("#", dh);
8117780Sralph DEBUG(4, "got %s\n", ok ? "?" : "that");
8217780Sralph if(ok != 0){
8317780Sralph if(atoi(fdig(dev.D_class)) == 9600){
8417780Sralph fixline(dh, 2400);
8517780Sralph speed = 2400;
8617780Sralph } else {
8717780Sralph fixline(dh, 9600);
8817780Sralph speed = 9600;
8917780Sralph }
9017780Sralph sleep(1);
9117780Sralph genbrk(dh, 3);
9217780Sralph ok = expect("#", dh);
9317780Sralph if(ok){
9417780Sralph close(dh);
9517780Sralph DEBUG(4, "sytek BREAK failed\n", "");
9617780Sralph delock(dev.D_line);
9717780Sralph return(CF_DIAL);
9817780Sralph }
9917780Sralph }
10017780Sralph write(dh, "done \r", 6);
10117780Sralph ok = expect("#", dh);
10217780Sralph DEBUG(4, "got %s\n", ok ? "?" : "that");
10317780Sralph if(speed != atoi(fdig(flds[F_CLASS]))){
10417780Sralph DEBUG(4, "changing speed\n", "");
10517780Sralph sprintf(speedbuf, "baud %s\r", fdig(flds[F_CLASS]));
10617780Sralph write(dh, speedbuf, strlen(speedbuf));
10717780Sralph sleep(1);
10817780Sralph speed = atoi(fdig(flds[F_CLASS]));
10917780Sralph fixline(dh, speed);
11017780Sralph genbrk(dh, 3);
11117780Sralph ok = expect("#", dh);
11217780Sralph DEBUG(4, "speed set %s\n", ok ? "failed" : flds[F_CLASS]);
11317780Sralph }
11417780Sralph strcpy(sykspeed, dev.D_class);
11517780Sralph write(dh, "command break\r", 14);
11617780Sralph ok = expect("#", dh);
11717780Sralph DEBUG(4, "got %s\n", ok ? "?" : "that");
11817780Sralph if (ok == 0) {
11917780Sralph write(dh, "call ", 5);
12017780Sralph write(dh, flds[F_PHONE], strlen(flds[F_PHONE]));
12117780Sralph write(dh, "\r", 1);
12217780Sralph DEBUG(4, "sytek dial %s\n", flds[F_PHONE]);
12317780Sralph DEBUG(4, "wanted %s ", "COMPLETED TO ");
12417780Sralph ok = expect("COMPLETED TO ", dh);
12517780Sralph DEBUG(4, "got %s\n", ok ? "?" : "that");
12617780Sralph }
12717780Sralph
12817780Sralph if (ok != 0) {
12917780Sralph close(dh);
13017780Sralph DEBUG(4, "sytek failed\n", "");
13117780Sralph delock(dev.D_line);
13217780Sralph return(CF_DIAL);
13317780Sralph } else
13417780Sralph DEBUG(4, "sytek ok\n", "");
13517780Sralph
13617780Sralph CU_end = sykcls;
13717780Sralph strcpy(devSel, dev.D_line); /* for later unlock */
13817780Sralph return(dh);
13917780Sralph
14017780Sralph }
14117780Sralph
sykcls(fd)14217780Sralph sykcls(fd)
14317780Sralph register int fd;
14417780Sralph {
14517780Sralph register int ok, speed;
14617780Sralph
14717780Sralph
14817780Sralph if (fd > 0) {
14917780Sralph genbrk(fd, 3);
15017780Sralph ok = expect("#", fd);
15117780Sralph DEBUG(4, "got %s\n", ok ? "?" : "that");
15217780Sralph if(ok != 0){
15317780Sralph genbrk(fd, 3);
15417780Sralph ok = expect("#", fd);
15517780Sralph }
15617780Sralph if(ok == 0){
15717780Sralph write(fd, "done 1\r", 7);
15817780Sralph ok = expect("#", fd);
15917780Sralph DEBUG(4, "got %s\n", ok ? "?" : "that");
16017780Sralph DEBUG(4, "reset baud to %s\n", sykspeed);
16117780Sralph write(fd, "baud ", 5);
16217780Sralph write(fd, sykspeed, strlen(sykspeed));
16317780Sralph write(fd, "\r", 1);
16417780Sralph sleep(1);
16517780Sralph }
16617780Sralph close(fd);
16717780Sralph delock(devSel);
16817780Sralph }
16917780Sralph }
17017780Sralph #endif SYTEK
171