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