1*17775Sralph #ifndef lint 2*17775Sralph static char sccsid[] = "@(#)hysq.c 4.1 (Berkeley) 01/22/85"; 3*17775Sralph #endif 4*17775Sralph 5*17775Sralph #include "../condevs.h" 6*17775Sralph 7*17775Sralph #ifdef HAYESQ 8*17775Sralph /* 9*17775Sralph * New dialout routine to work with Hayes' SMART MODEM 10*17775Sralph * 13-JUL-82, Mike Mitchell 11*17775Sralph * Modified 23-MAR-83 to work with Tom Truscott's (rti!trt) 12*17775Sralph * version of UUCP (ncsu!mcm) 13*17775Sralph * 14*17775Sralph * The modem should be set to NOT send any result codes to 15*17775Sralph * the system (switch 3 up, 4 down). This end will figure out 16*17775Sralph * what is wrong. 17*17775Sralph * 18*17775Sralph * I had lots of problems with the modem sending 19*17775Sralph * result codes since I am using the same modem for both incomming and 20*17775Sralph * outgoing calls. I'd occasionally miss the result code (getty would 21*17775Sralph * grab it), and the connect would fail. Worse yet, the getty would 22*17775Sralph * think the result code was a user name, and send garbage to it while 23*17775Sralph * it was in the command state. I turned off ALL result codes, and hope 24*17775Sralph * for the best. 99% of the time the modem is in the correct state. 25*17775Sralph * Occassionally it doesn't connect, or the phone was busy, etc., and 26*17775Sralph * uucico sits there trying to log in. It eventually times out, calling 27*17775Sralph * clsacu() in the process, so it resets itself for the next attempt. 28*17775Sralph */ 29*17775Sralph 30*17775Sralph /* 31*17775Sralph * NOTE: this version is not for the faint-hearted. 32*17775Sralph * Someday it would be nice to have a single version of hayes dialer 33*17775Sralph * with a way to specify the switch settings that are on the dialer 34*17775Sralph * as well as tone/pulse. 35*17775Sralph * In the meantime, using HAYES rather than HAYESQ is probably best. 36*17775Sralph */ 37*17775Sralph 38*17775Sralph hysqpopn(telno, flds, dev) 39*17775Sralph char *telno, *flds[]; 40*17775Sralph struct Devices *dev; 41*17775Sralph { 42*17775Sralph return hysqopn(telno, flds, dev, 0); 43*17775Sralph } 44*17775Sralph 45*17775Sralph hysqtopn(telno, flds, dev) 46*17775Sralph char *telno, *flds[]; 47*17775Sralph struct Devices *dev; 48*17775Sralph { 49*17775Sralph return hysqopn(telno, flds, dev, 1); 50*17775Sralph } 51*17775Sralph 52*17775Sralph hysqopn(telno, flds, dev, toneflag) 53*17775Sralph char *telno, *flds[]; 54*17775Sralph struct Devices *dev; 55*17775Sralph int toneflag; 56*17775Sralph { 57*17775Sralph char dcname[20], phone[MAXPH+10], c = 0; 58*17775Sralph #ifdef USG 59*17775Sralph struct termio ttbuf; 60*17775Sralph #endif USG 61*17775Sralph int status, dnf; 62*17775Sralph unsigned timelim; 63*17775Sralph 64*17775Sralph signal(SIGALRM, alarmtr); 65*17775Sralph sprintf(dcname, "/dev/%s", dev->D_line); 66*17775Sralph 67*17775Sralph getnextfd(); 68*17775Sralph if (setjmp(Sjbuf)) { 69*17775Sralph logent("DEVICE", "NO"); 70*17775Sralph DEBUG(4, "Open timed out %s", dcname); 71*17775Sralph return CF_NODEV; 72*17775Sralph } 73*17775Sralph alarm(10); 74*17775Sralph 75*17775Sralph if ((dnf = open(dcname, 2)) <= 0) { 76*17775Sralph logent("DEVICE", "NO"); 77*17775Sralph DEBUG(4, "Can't open %s", dcname); 78*17775Sralph return CF_NODEV; 79*17775Sralph } 80*17775Sralph 81*17775Sralph alarm(0); 82*17775Sralph next_fd = -1; 83*17775Sralph fixline(dnf, dev->D_speed); 84*17775Sralph DEBUG(4, "Hayes port - %s, ", dcname); 85*17775Sralph 86*17775Sralph if (toneflag) 87*17775Sralph sprintf(phone, "\rATDT%s\r", telno); 88*17775Sralph else 89*17775Sralph sprintf(phone, "\rATDP%s\r", telno); 90*17775Sralph 91*17775Sralph write(dnf, phone, strlen(phone)); 92*17775Sralph 93*17775Sralph /* calculate delay time for the other system to answer the phone. 94*17775Sralph * Default is 15 seconds, add 2 seconds for each comma in the phone 95*17775Sralph * number. 96*17775Sralph */ 97*17775Sralph timelim = 150; 98*17775Sralph while(*telno) { 99*17775Sralph c = *telno++; 100*17775Sralph if (c == ',') 101*17775Sralph timelim += 20; 102*17775Sralph else if (toneflag) 103*17775Sralph timelim += 2; /* .2 seconds per tone */ 104*17775Sralph else { 105*17775Sralph if (c == '0') timelim += 10; /* .1 sec per digit */ 106*17775Sralph else if (c > '0' && c <= '9') 107*17775Sralph timelim += (c - '0'); 108*17775Sralph } 109*17775Sralph } 110*17775Sralph alarm(timelim/10 + 1); 111*17775Sralph if (setjmp(Sjbuf) == 0) { 112*17775Sralph read(dnf, &c, 1); 113*17775Sralph alarm(0); 114*17775Sralph } 115*17775Sralph 116*17775Sralph return dnf; 117*17775Sralph } 118*17775Sralph 119*17775Sralph hysqcls(fd) 120*17775Sralph int fd; 121*17775Sralph { 122*17775Sralph char dcname[20]; 123*17775Sralph struct sgttyb hup, sav; 124*17775Sralph 125*17775Sralph if (fd > 0) { 126*17775Sralph sprintf(dcname, "/dev/%s", devSel); 127*17775Sralph DEBUG(4, "Hanging up fd = %d\n", fd); 128*17775Sralph /* 129*17775Sralph * code to drop DTR -- change to 0 baud then back to default. 130*17775Sralph */ 131*17775Sralph gtty(fd, &hup); 132*17775Sralph gtty(fd, &sav); 133*17775Sralph hup.sg_ispeed = B0; 134*17775Sralph hup.sg_ospeed = B0; 135*17775Sralph stty(fd, &hup); 136*17775Sralph sleep(2); 137*17775Sralph stty(fd, &sav); 138*17775Sralph /* 139*17775Sralph * now raise DTR -- close the device & open it again. 140*17775Sralph */ 141*17775Sralph sleep(2); 142*17775Sralph close(fd); 143*17775Sralph sleep(2); 144*17775Sralph fd = open(dcname, 2); 145*17775Sralph /* 146*17775Sralph * Since we have a getty sleeping on this line, when it wakes up it sends 147*17775Sralph * all kinds of garbage to the modem. Unfortunatly, the modem likes to 148*17775Sralph * execute the previous command when it sees the garbage. The previous 149*17775Sralph * command was to dial the phone, so let's make the last command reset 150*17775Sralph * the modem. 151*17775Sralph */ 152*17775Sralph sleep(2); 153*17775Sralph write(fd, "\rATZ\r", 5); 154*17775Sralph close(fd); 155*17775Sralph delock(devSel); 156*17775Sralph } 157*17775Sralph } 158*17775Sralph 159*17775Sralph #endif HAYESQ 160