117785Sralph #ifndef lint 2*25159Sbloom static char sccsid[] = "@(#)vad.c 4.2 (Berkeley) 10/10/85"; 317785Sralph #endif 417785Sralph 517785Sralph #include "../condevs.h" 617785Sralph #ifdef VADIC 717785Sralph 817785Sralph /* 917785Sralph * vadopn: establish dial-out connection through a Racal-Vadic 3450. 1017785Sralph * Returns descriptor open to tty for reading and writing. 1117785Sralph * Negative values (-1...-7) denote errors in connmsg. 1217785Sralph * Be sure to disconnect tty when done, via HUPCL or stty 0. 1317785Sralph */ 1417785Sralph 1517785Sralph vadopn(telno, flds, dev) 1617785Sralph char *telno; 1717785Sralph char *flds[]; 1817785Sralph struct Devices *dev; 1917785Sralph { 2017785Sralph int dh = -1; 2117785Sralph int i, ok, er = 0, delay; 2217785Sralph extern errno; 2317785Sralph char dcname[20]; 2417785Sralph 2517785Sralph sprintf(dcname, "/dev/%s", dev->D_line); 2617785Sralph if (setjmp(Sjbuf)) { 2717785Sralph DEBUG(1, "timeout vadic open\n", ""); 2817785Sralph logent("vadic open", "TIMEOUT"); 2917785Sralph if (dh >= 0) 3017785Sralph close(dh); 3117785Sralph delock(dev->D_line); 3217785Sralph return CF_NODEV; 3317785Sralph } 3417785Sralph signal(SIGALRM, alarmtr); 3517785Sralph getnextfd(); 3617785Sralph alarm(10); 3717785Sralph dh = open(dcname, 2); 3817785Sralph alarm(0); 3917785Sralph 4017785Sralph /* modem is open */ 4117785Sralph next_fd = -1; 4217785Sralph if (dh < 0) { 4317785Sralph delock(dev->D_line); 4417785Sralph return CF_NODEV; 4517785Sralph } 4617785Sralph fixline(dh, dev->D_speed); 4717785Sralph 4817785Sralph DEBUG(4, "calling %s -> ", telno); 4917785Sralph if (dochat(dev, flds, dh)) { 5017785Sralph logent(dcname, "CHAT FAILED"); 5117785Sralph close(dh); 5217785Sralph return CF_DIAL; 5317785Sralph } 5417785Sralph delay = 0; 5517785Sralph for (i = 0; i < strlen(telno); ++i) { 5617785Sralph switch(telno[i]) { 5717785Sralph case '=': /* await dial tone */ 5817785Sralph case '-': 5917785Sralph case ',': 6017785Sralph case '<': 6117785Sralph case 'K': 6217785Sralph telno[i] = 'K'; 6317785Sralph delay += 5; 6417785Sralph break; 6517785Sralph } 6617785Sralph } 6717785Sralph DEBUG(4, "%s\n", telno); 6817785Sralph for(i = 0; i < 5; ++i) { /* make 5 tries */ 6917785Sralph /* wake up Vadic */ 70*25159Sbloom write(dh, "\005", 1); 71*25159Sbloom sleep(1); 72*25159Sbloom write(dh, "\r", 1); 7317785Sralph DEBUG(4, "wanted * ", CNULL); 74*25159Sbloom ok = expect("*~5", dh); 7517785Sralph DEBUG(4, "got %s\n", ok ? "?" : "that"); 7617785Sralph if (ok != 0) 7717785Sralph continue; 7817785Sralph 7917785Sralph write(dh, "D\r", 2); /* "D" (enter number) command */ 8017785Sralph DEBUG(4, "wanted NUMBER?\\r\\n ", CNULL); 81*25159Sbloom ok = expect("NUMBER?\r\n~5", dh); 8217785Sralph DEBUG(4, "got %s\n", ok ? "?" : "that"); 8317785Sralph if (ok != 0) 8417785Sralph continue; 8517785Sralph 8617785Sralph /* send telno, send \r */ 8717785Sralph write(dh, telno, strlen(telno)); 8817785Sralph sleep(1); 8917785Sralph write(dh, "\r", 1); 9017785Sralph DEBUG(4, "wanted %s ", telno); 9117785Sralph ok = expect(telno, dh); 9217785Sralph if (ok == 0) 9317785Sralph ok = expect("\r\n", dh); 9417785Sralph DEBUG(4, "got %s\n", ok ? "?" : "that"); 9517785Sralph if (ok != 0) 9617785Sralph continue; 9717785Sralph 9817785Sralph write(dh, "\r", 1); /* confirm number */ 9917785Sralph DEBUG(4, "wanted DIALING: ", CNULL); 10017785Sralph ok = expect("DIALING: ", dh); 10117785Sralph DEBUG(4, "got %s\n", ok ? "?" : "that"); 10217785Sralph if (ok == 0) 10317785Sralph break; 10417785Sralph } 10517785Sralph 10617785Sralph if (ok == 0) { 10717785Sralph sleep(10 + delay); /* give vadic some time */ 10817785Sralph DEBUG(4, "wanted ON LINE\\r\\n ", CNULL); 10917785Sralph ok = expect("ON LINE\r\n", dh); 11017785Sralph DEBUG(4, "got %s\n", ok ? "?" : "that"); 11117785Sralph } 11217785Sralph 11317785Sralph if (ok != 0) { 11417785Sralph if (dh > 2) 11517785Sralph close(dh); 11617785Sralph DEBUG(4, "vadDial failed\n", CNULL); 11717785Sralph delock(dev->D_line); 11817785Sralph return CF_DIAL; 11917785Sralph } 12017785Sralph DEBUG(4, "vadic ok\n", CNULL); 12117785Sralph return dh; 12217785Sralph } 12317785Sralph 124*25159Sbloom vadcls(fd) 125*25159Sbloom { 12617785Sralph if (fd > 0) { 12717785Sralph close(fd); 12817785Sralph sleep(5); 12917785Sralph delock(devSel); 13017785Sralph } 13117785Sralph } 13217785Sralph #endif VADIC 133