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[] = "@(#)vent.c 8.1 (Berkeley) 06/06/93"; 10 #endif /* not lint */ 11 12 #include "condevs.h" 13 14 ventopn(telno, flds, dev) 15 char *flds[], *telno; 16 struct Devices *dev; 17 { 18 int dh; 19 int i, ok = -1; 20 char dcname[20]; 21 22 sprintf(dcname, "/dev/%s", dev->D_line); 23 if (setjmp(Sjbuf)) { 24 DEBUG(1, "timeout ventel open\n", ""); 25 logent("ventel open", "TIMEOUT"); 26 if (dh >= 0) 27 close(dh); 28 delock(dev->D_line); 29 return CF_NODEV; 30 } 31 signal(SIGALRM, alarmtr); 32 getnextfd(); 33 alarm(10); 34 dh = open(dcname, 2); 35 next_fd = -1; 36 alarm(0); 37 if (dh < 0) { 38 DEBUG(4,"%s\n", errno == 4 ? "no carrier" : "can't open modem"); 39 delock(dev->D_line); 40 return errno == 4 ? CF_DIAL : CF_NODEV; 41 } 42 43 /* modem is open */ 44 fixline(dh, dev->D_speed); 45 46 /* translate - to % and = to & for VenTel */ 47 DEBUG(4, "calling %s -> ", telno); 48 for (i = 0; i < strlen(telno); ++i) { 49 switch(telno[i]) { 50 case '-': /* delay */ 51 telno[i] = '%'; 52 break; 53 case '=': /* await dial tone */ 54 telno[i] = '&'; 55 break; 56 case '<': 57 telno[i] = '%'; 58 break; 59 } 60 } 61 DEBUG(4, "%s\n", telno); 62 sleep(1); 63 for(i = 0; i < 5; ++i) { /* make up to 5 tries */ 64 slowrite(dh, "\r\r");/* awake, thou lowly VenTel! */ 65 66 DEBUG(4, "wanted %s ", "$"); 67 ok = expect("$", dh); 68 DEBUG(4, "got %s\n", ok ? "?" : "that"); 69 if (ok != 0) 70 continue; 71 slowrite(dh, "K"); /* "K" (enter number) command */ 72 DEBUG(4, "wanted %s ", "DIAL: "); 73 ok = expect("DIAL: ", dh); 74 DEBUG(4, "got %s\n", ok ? "?" : "that"); 75 if (ok == 0) 76 break; 77 } 78 79 if (ok == 0) { 80 slowrite(dh, telno); /* send telno, send \r */ 81 slowrite(dh, "\r"); 82 DEBUG(4, "wanted %s ", "ONLINE"); 83 ok = expect("ONLINE!", dh); 84 DEBUG(4, "got %s\n", ok ? "?" : "that"); 85 } 86 if (ok != 0) { 87 if (dh > 2) 88 close(dh); 89 DEBUG(4, "venDial failed\n", ""); 90 return CF_DIAL; 91 } 92 else 93 DEBUG(4, "venDial ok\n", ""); 94 return dh; 95 } 96 97 ventcls(fd) 98 int fd; 99 { 100 if (fd > 0) { 101 close(fd); 102 sleep(5); 103 delock(devSel); 104 } 105 } 106