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