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