|
|
1.1 ! root 1: #ifndef lint ! 2: static char sccsid[] = "@(#)vad.c 4.3 (Berkeley) 2/24/88"; ! 3: #endif ! 4: ! 5: #include "../condevs.h" ! 6: ! 7: /* ! 8: * vadopn: establish dial-out connection through a Racal-Vadic 3450. ! 9: * Returns descriptor open to tty for reading and writing. ! 10: * Negative values (-1...-7) denote errors in connmsg. ! 11: * Be sure to disconnect tty when done, via HUPCL or stty 0. ! 12: */ ! 13: ! 14: vadopn(telno, flds, dev) ! 15: char *telno; ! 16: char *flds[]; ! 17: struct Devices *dev; ! 18: { ! 19: int dh = -1; ! 20: int i, ok, er = 0, delay; ! 21: extern errno; ! 22: char dcname[20]; ! 23: ! 24: sprintf(dcname, "/dev/%s", dev->D_line); ! 25: if (setjmp(Sjbuf)) { ! 26: DEBUG(1, "timeout vadic open\n", ""); ! 27: logent("vadic open", "TIMEOUT"); ! 28: if (dh >= 0) ! 29: close(dh); ! 30: delock(dev->D_line); ! 31: return CF_NODEV; ! 32: } ! 33: signal(SIGALRM, alarmtr); ! 34: getnextfd(); ! 35: alarm(10); ! 36: dh = open(dcname, 2); ! 37: alarm(0); ! 38: ! 39: /* modem is open */ ! 40: next_fd = -1; ! 41: if (dh < 0) { ! 42: delock(dev->D_line); ! 43: return CF_NODEV; ! 44: } ! 45: fixline(dh, dev->D_speed); ! 46: ! 47: DEBUG(4, "calling %s -> ", telno); ! 48: if (dochat(dev, flds, dh)) { ! 49: logent(dcname, "CHAT FAILED"); ! 50: close(dh); ! 51: return CF_DIAL; ! 52: } ! 53: delay = 0; ! 54: for (i = 0; i < strlen(telno); ++i) { ! 55: switch(telno[i]) { ! 56: case '=': /* await dial tone */ ! 57: case '-': ! 58: case ',': ! 59: case '<': ! 60: case 'K': ! 61: telno[i] = 'K'; ! 62: delay += 5; ! 63: break; ! 64: } ! 65: } ! 66: DEBUG(4, "%s\n", telno); ! 67: for(i = 0; i < 5; ++i) { /* make 5 tries */ ! 68: /* wake up Vadic */ ! 69: write(dh, "\005", 1); ! 70: sleep(1); ! 71: write(dh, "\r", 1); ! 72: DEBUG(4, "wanted * ", CNULL); ! 73: ok = expect("*~5", dh); ! 74: DEBUG(4, "got %s\n", ok ? "?" : "that"); ! 75: if (ok != 0) ! 76: continue; ! 77: ! 78: write(dh, "D\r", 2); /* "D" (enter number) command */ ! 79: DEBUG(4, "wanted NUMBER?\\r\\n ", CNULL); ! 80: ok = expect("NUMBER?\r\n~5", dh); ! 81: DEBUG(4, "got %s\n", ok ? "?" : "that"); ! 82: if (ok != 0) ! 83: continue; ! 84: ! 85: /* send telno, send \r */ ! 86: write(dh, telno, strlen(telno)); ! 87: sleep(1); ! 88: write(dh, "\r", 1); ! 89: DEBUG(4, "wanted %s ", telno); ! 90: ok = expect(telno, dh); ! 91: if (ok == 0) ! 92: ok = expect("\r\n", dh); ! 93: DEBUG(4, "got %s\n", ok ? "?" : "that"); ! 94: if (ok != 0) ! 95: continue; ! 96: ! 97: write(dh, "\r", 1); /* confirm number */ ! 98: DEBUG(4, "wanted DIALING: ", CNULL); ! 99: ok = expect("DIALING: ", dh); ! 100: DEBUG(4, "got %s\n", ok ? "?" : "that"); ! 101: if (ok == 0) ! 102: break; ! 103: } ! 104: ! 105: if (ok == 0) { ! 106: sleep(10 + delay); /* give vadic some time */ ! 107: DEBUG(4, "wanted ON LINE\\r\\n ", CNULL); ! 108: ok = expect("ON LINE\r\n", dh); ! 109: DEBUG(4, "got %s\n", ok ? "?" : "that"); ! 110: } ! 111: ! 112: if (ok != 0) { ! 113: if (dh > 2) ! 114: close(dh); ! 115: DEBUG(4, "vadDial failed\n", CNULL); ! 116: delock(dev->D_line); ! 117: return CF_DIAL; ! 118: } ! 119: DEBUG(4, "vadic ok\n", CNULL); ! 120: return dh; ! 121: } ! 122: ! 123: vadcls(fd) ! 124: { ! 125: if (fd > 0) { ! 126: close(fd); ! 127: sleep(5); ! 128: delock(devSel); ! 129: } ! 130: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.