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
817776Sralph #ifndef lint
9*62384Sbostic static char sccsid[] = "@(#)mic.c 8.1 (Berkeley) 06/06/93";
1048651Sbostic #endif /* not lint */
1117776Sralph
1246875Sbostic #include "condevs.h"
1317776Sralph #ifdef MICOM
1417776Sralph
1517776Sralph /*
1617776Sralph * micopn: establish connection through a micom.
1717776Sralph * Returns descriptor open to tty for reading and writing.
1817776Sralph * Negative values (-1...-7) denote errors in connmsg.
1917776Sralph * Be sure to disconnect tty when done, via HUPCL or stty 0.
2017776Sralph */
micopn(flds)2117776Sralph micopn(flds)
2217776Sralph register char *flds[];
2317776Sralph {
2417776Sralph extern errno;
2517776Sralph char *rindex(), *fdig(), dcname[20];
2617776Sralph int dh, ok = 0, speed;
2717776Sralph register struct condev *cd;
2817776Sralph register FILE *dfp;
2917776Sralph struct Devices dev;
3017776Sralph
3117776Sralph dfp = fopen(DEVFILE, "r");
3217776Sralph ASSERT(dfp != NULL, "Can't open", DEVFILE, 0);
3317776Sralph
3417776Sralph signal(SIGALRM, alarmtr);
3517776Sralph dh = -1;
3617776Sralph for(cd = condevs; ((cd->CU_meth != NULL)&&(dh < 0)); cd++) {
3717776Sralph if (snccmp(flds[F_LINE], cd->CU_meth) == SAME) {
3817776Sralph fseek(dfp, (off_t)0, 0);
3917776Sralph while(rddev(dfp, &dev) != FAIL) {
4017776Sralph if (strcmp(flds[F_CLASS], dev.D_class) != SAME)
4117776Sralph continue;
4217776Sralph if (snccmp(flds[F_LINE], dev.D_type) != SAME)
4317776Sralph continue;
4417776Sralph if (mlock(dev.D_line) == FAIL)
4517776Sralph continue;
4617776Sralph
4717776Sralph sprintf(dcname, "/dev/%s", dev.D_line);
4817776Sralph getnextfd();
4917776Sralph alarm(10);
5017776Sralph if (setjmp(Sjbuf)) {
5117776Sralph delock(dev.D_line);
5217776Sralph logent(dev.D_line,"micom open TIMEOUT");
5317776Sralph dh = -1;
5417776Sralph break;
5517776Sralph }
5617776Sralph dh = open(dcname, 2);
5717776Sralph alarm(0);
5817776Sralph next_fd = -1;
5917776Sralph if (dh > 0) {
6017776Sralph break;
6117776Sralph }
6217776Sralph devSel[0] = '\0';
6317776Sralph delock(dev.D_line);
6417776Sralph }
6517776Sralph }
6617776Sralph }
6717776Sralph fclose(dfp);
6817776Sralph if (dh < 0)
6917776Sralph return CF_NODEV;
7017776Sralph
7117776Sralph speed = atoi(fdig(flds[F_CLASS]));
7217776Sralph fixline(dh, speed);
7317776Sralph sleep(1);
7417776Sralph
7517776Sralph /* negotiate with micom */
7617776Sralph if (speed != 4800) /* damn their eyes! */
7717776Sralph write(dh, "\r", 1);
7817776Sralph else
7917776Sralph write(dh, " ", 1);
8017776Sralph
8117776Sralph DEBUG(4, "wanted %s ", "SELECTION");
8217776Sralph ok = expect("SELECTION", dh);
8317776Sralph DEBUG(4, "got %s\n", ok ? "?" : "that");
8417776Sralph if (ok == 0) {
8517776Sralph write(dh, flds[F_PHONE], strlen(flds[F_PHONE]));
8617776Sralph sleep(1);
8717776Sralph write(dh, "\r", 1);
8817776Sralph DEBUG(4, "wanted %s ", "GO");
8917776Sralph ok = expect("GO", dh);
9017776Sralph DEBUG(4, "got %s\n", ok ? "?" : "that");
9117776Sralph }
9217776Sralph
9317776Sralph if (ok != 0) {
9417776Sralph if (dh > 2)
9517776Sralph close(dh);
9617776Sralph DEBUG(4, "micom failed\n", "");
9717776Sralph delock(dev.D_line);
9817776Sralph return(CF_DIAL);
9917776Sralph }
10017776Sralph else
10117776Sralph DEBUG(4, "micom ok\n", "");
10217776Sralph
10317776Sralph CU_end = cd->CU_clos;
10417776Sralph strcat(devSel, dev.D_line); /* for later unlock */
10517776Sralph return dh;
10617776Sralph }
10717776Sralph
miccls(fd)10817776Sralph miccls(fd)
10917776Sralph register int fd;
11017776Sralph {
11117776Sralph
11217776Sralph if (fd > 0) {
11317776Sralph close(fd);
11417776Sralph delock(devSel);
11517776Sralph }
11617776Sralph }
11717776Sralph #endif MICOM
118