4.4BSD snapshot (revision 8.1); add 1993 to copyright
[unix-history] / usr / src / usr.bin / uucp / libacu / mic.c
CommitLineData
f49909f5 1/*-
17e8cbca
KB
2 * Copyright (c) 1985, 1993
3 * The Regents of the University of California. All rights reserved.
f49909f5
KB
4 *
5 * %sccs.include.proprietary.c%
6 */
7
1f59c325 8#ifndef lint
17e8cbca 9static char sccsid[] = "@(#)mic.c 8.1 (Berkeley) %G%";
f49909f5 10#endif /* not lint */
1f59c325 11
ddf4e66c 12#include "condevs.h"
1f59c325
RC
13#ifdef MICOM
14
15/*
16 * micopn: establish connection through a micom.
17 * Returns descriptor open to tty for reading and writing.
18 * Negative values (-1...-7) denote errors in connmsg.
19 * Be sure to disconnect tty when done, via HUPCL or stty 0.
20 */
21micopn(flds)
22register char *flds[];
23{
24 extern errno;
25 char *rindex(), *fdig(), dcname[20];
26 int dh, ok = 0, speed;
27 register struct condev *cd;
28 register FILE *dfp;
29 struct Devices dev;
30
31 dfp = fopen(DEVFILE, "r");
32 ASSERT(dfp != NULL, "Can't open", DEVFILE, 0);
33
34 signal(SIGALRM, alarmtr);
35 dh = -1;
36 for(cd = condevs; ((cd->CU_meth != NULL)&&(dh < 0)); cd++) {
37 if (snccmp(flds[F_LINE], cd->CU_meth) == SAME) {
38 fseek(dfp, (off_t)0, 0);
39 while(rddev(dfp, &dev) != FAIL) {
40 if (strcmp(flds[F_CLASS], dev.D_class) != SAME)
41 continue;
42 if (snccmp(flds[F_LINE], dev.D_type) != SAME)
43 continue;
44 if (mlock(dev.D_line) == FAIL)
45 continue;
46
47 sprintf(dcname, "/dev/%s", dev.D_line);
48 getnextfd();
49 alarm(10);
50 if (setjmp(Sjbuf)) {
51 delock(dev.D_line);
52 logent(dev.D_line,"micom open TIMEOUT");
53 dh = -1;
54 break;
55 }
56 dh = open(dcname, 2);
57 alarm(0);
58 next_fd = -1;
59 if (dh > 0) {
60 break;
61 }
62 devSel[0] = '\0';
63 delock(dev.D_line);
64 }
65 }
66 }
67 fclose(dfp);
68 if (dh < 0)
69 return CF_NODEV;
70
71 speed = atoi(fdig(flds[F_CLASS]));
72 fixline(dh, speed);
73 sleep(1);
74
75 /* negotiate with micom */
76 if (speed != 4800) /* damn their eyes! */
77 write(dh, "\r", 1);
78 else
79 write(dh, " ", 1);
80
81 DEBUG(4, "wanted %s ", "SELECTION");
82 ok = expect("SELECTION", dh);
83 DEBUG(4, "got %s\n", ok ? "?" : "that");
84 if (ok == 0) {
85 write(dh, flds[F_PHONE], strlen(flds[F_PHONE]));
86 sleep(1);
87 write(dh, "\r", 1);
88 DEBUG(4, "wanted %s ", "GO");
89 ok = expect("GO", dh);
90 DEBUG(4, "got %s\n", ok ? "?" : "that");
91 }
92
93 if (ok != 0) {
94 if (dh > 2)
95 close(dh);
96 DEBUG(4, "micom failed\n", "");
97 delock(dev.D_line);
98 return(CF_DIAL);
99 }
100 else
101 DEBUG(4, "micom ok\n", "");
102
103 CU_end = cd->CU_clos;
104 strcat(devSel, dev.D_line); /* for later unlock */
105 return dh;
106}
107
108miccls(fd)
109register int fd;
110{
111
112 if (fd > 0) {
113 close(fd);
114 delock(devSel);
115 }
116}
117#endif MICOM