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