1*48651Sbostic /*- 2*48651Sbostic * Copyright (c) 1985 The Regents of the University of California. 3*48651Sbostic * All rights reserved. 4*48651Sbostic * 5*48651Sbostic * %sccs.include.proprietary.c% 6*48651Sbostic */ 7*48651Sbostic 818564Sralph #ifndef lint 9*48651Sbostic static char sccsid[] = "@(#)pen.c 4.5 (Berkeley) 04/24/91"; 10*48651Sbostic #endif /* not lint */ 1118564Sralph 1218564Sralph /* 1318564Sralph * Speaker's quick and dirty penril hack. STA 4/1/85. 1418564Sralph */ 1546875Sbostic #include "condevs.h" 1618564Sralph 1718564Sralph penopn(telno, flds, dev) 1818564Sralph char *flds[], *telno; 1918564Sralph struct Devices *dev; 2018564Sralph { 2118564Sralph int dh; 2218564Sralph int i, ok = -1; 2318564Sralph char dcname[20]; 2418564Sralph 2518564Sralph sprintf(dcname, "/dev/%s", dev->D_line); 2618564Sralph if (setjmp(Sjbuf)) { 2718564Sralph DEBUG(1, "timeout penril open\n", ""); 2818564Sralph logent("penril open", "TIMEOUT"); 2918564Sralph if (dh >= 0) 3018564Sralph close(dh); 3118564Sralph delock(dev->D_line); 3218564Sralph return CF_NODEV; 3318564Sralph } 3418564Sralph signal(SIGALRM, alarmtr); 3518564Sralph getnextfd(); 3618564Sralph alarm(10); 3718564Sralph dh = open(dcname, 2); 3825155Sbloom alarm(0); 3918564Sralph next_fd = -1; 4018564Sralph if (dh < 0) { 4118564Sralph DEBUG(4,"%s\n", errno == 4 ? "no carrier" : "can't open modem"); 4218564Sralph delock(dev->D_line); 4318564Sralph return errno == 4 ? CF_DIAL : CF_NODEV; 4418564Sralph } 4518564Sralph 4618564Sralph /* modem is open */ 4718564Sralph fixline(dh, dev->D_speed); 4818564Sralph 4918564Sralph /* translate - to P and = to W for Penril */ 5018564Sralph DEBUG(4, "calling %s -> ", telno); 5118564Sralph for (i = 0; i < strlen(telno); ++i) { 5218564Sralph switch(telno[i]) { 5318564Sralph case '-': /* delay */ 5418564Sralph telno[i] = 'P'; 5518564Sralph break; 5618564Sralph case '=': /* await dial tone */ 5718564Sralph telno[i] = 'W'; 5818564Sralph break; 5918564Sralph case '<': 6018564Sralph telno[i] = 'P'; 6118564Sralph break; 6218564Sralph } 6318564Sralph } 6418564Sralph DEBUG(4, "%s\n", telno); 6518564Sralph sleep(1); 6618564Sralph for(i = 0; i < 5; ++i) { /* make up to 5 tries */ 6718564Sralph slowrite(dh, "\r");/* awake, thou lowly Penril! */ 6818564Sralph 6918564Sralph DEBUG(4, "wanted %s ", ">"); 7018564Sralph ok = expect(">", dh); 7118564Sralph DEBUG(4, "got %s\n", ok ? "?" : "that"); 7218564Sralph if (ok != 0) 7318564Sralph continue; 7418564Sralph slowrite(dh, "K"); /* "K" (enter number) command */ 7518564Sralph DEBUG(4, "wanted %s ", "NO.: "); 7618564Sralph ok = expect("NO.: ", dh); 7718564Sralph DEBUG(4, "got %s\n", ok ? "?" : "that"); 7818564Sralph if (ok == 0) 7918564Sralph break; 8018564Sralph } 8118564Sralph 8218564Sralph if (ok == 0) { 8318564Sralph slowrite(dh, telno); /* send telno, send \r */ 8418564Sralph slowrite(dh, "\r"); 8518564Sralph DEBUG(4, "wanted %s ", "OK"); 8618564Sralph ok = expect("OK", dh); 8718564Sralph DEBUG(4, "got %s\n", ok ? "?" : "that"); 8818564Sralph } 8918564Sralph if (ok != 0) { 9018564Sralph if (dh > 2) 9118564Sralph close(dh); 9218564Sralph DEBUG(4, "penDial failed\n", ""); 9318564Sralph return CF_DIAL; 9418564Sralph } 9518564Sralph else 9618564Sralph DEBUG(4, "penDial ok\n", ""); 9718564Sralph return dh; 9818564Sralph } 9918564Sralph 10018564Sralph pencls(fd) 10118564Sralph int fd; 10218564Sralph { 10318564Sralph if (fd > 0) { 10418564Sralph close(fd); 10518564Sralph sleep(5); 10618564Sralph delock(devSel); 10718564Sralph } 10818564Sralph } 109