1 #ifndef lint 2 static char sccsid[] = "@(#)cds224.c 1.1 (Berkeley) 01/13/86"; 3 #endif !lint 4 5 #include "../condevs.h" 6 #ifdef CDS224 7 8 /* 9 * conopn: establish dial-out connection through a Concord CDS 224. 10 * Returns descriptor open to tty for reading and writing. 11 * Negative values (-1...-7) denote errors in connmsg. 12 * Be sure to disconnect tty when done, via HUPCL or stty 0. 13 */ 14 #define TRYS 5 /* number of trys */ 15 16 cdsopn224(telno, flds, dev) 17 char *telno; 18 char *flds[]; 19 struct Devices *dev; 20 { 21 int dh = -1; 22 int i, ok, er = 0, delay; 23 extern errno; 24 char dcname[20]; 25 char *tempbuf[20]; 26 27 sprintf(dcname, "/dev/%s", dev->D_line); 28 if (setjmp(Sjbuf)) { 29 DEBUG(1, "timeout concord open\n", ""); 30 logent("concord open", "TIMEOUT"); 31 if (dh >= 0) 32 cdscls224(dh); 33 delock(dev->D_line); 34 return CF_NODEV; 35 } 36 signal(SIGALRM, alarmtr); 37 getnextfd(); 38 alarm(10); 39 dh = open(dcname, 2); 40 alarm(0); 41 42 /* modem is open */ 43 next_fd = -1; 44 if (dh < 0) { 45 delock(dev->D_line); 46 return CF_NODEV; 47 } 48 fixline(dh, dev->D_speed); 49 50 DEBUG(4, "calling %s -> ", telno); 51 if (dochat(dev, flds, dh)) { 52 logent(dcname, "CHAT FAILED"); 53 cdscls224(dh); 54 return CF_DIAL; 55 } 56 for(i = 0; i < TRYS; ++i) { 57 /* wake up Concord */ 58 write(dh, "\r\r", 2); 59 DEBUG(4, "wanted CDS >", CNULL); 60 ok = expect("CDS >", dh); 61 DEBUG(4, "got %s\n", ok ? "?" : "that"); 62 if (ok != 0) 63 continue; 64 65 write(dh, "\r", 2); 66 DEBUG(4, "wanted CDS >", CNULL); 67 ok = expect("CDS >", dh); 68 DEBUG(4, "got %s\n", ok ? "?" : "that"); 69 if (ok != 0) 70 continue; 71 72 /* send telno \r */ 73 sprintf(tempbuf,"D%s\r",telno); 74 write(dh, tempbuf, strlen(tempbuf)); 75 76 DEBUG(4, "wanted DIALING ", CNULL); 77 ok = expect("DIALING ", dh); 78 DEBUG(4, "got %s\n", ok ? "?" : "that"); 79 if (ok == 0) 80 break; 81 } 82 83 if (ok == 0) { 84 sleep(10); /* give concord some time */ 85 DEBUG(4, "wanted INITIATING " , CNULL); 86 ok = expect("INITIATING", dh); 87 DEBUG(4, "got %s\n", ok ? "?" : "that"); 88 } 89 90 if (ok != 0) { 91 if (dh > 2) 92 close(dh); 93 DEBUG(4, "conDial failed\n", CNULL); 94 delock(dev->D_line); 95 return CF_DIAL; 96 } 97 DEBUG(4, "concord ok\n", CNULL); 98 return dh; 99 } 100 101 cdscls224(fd) 102 { 103 104 if (fd > 0) { 105 close(fd); 106 sleep(5); 107 delock(devSel); 108 } 109 } 110 #endif CDS224 111