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