1*17774Sralph #ifndef lint 2*17774Sralph static char sccsid[] = "@(#)hys.c 4.1 (Berkeley) 01/22/85"; 3*17774Sralph #endif 4*17774Sralph 5*17774Sralph #include "../condevs.h" 6*17774Sralph 7*17774Sralph #ifdef HAYES 8*17774Sralph /*** 9*17774Sralph * hyspopn(telno, flds, dev) connect to hayes smartmodem (pulse call) 10*17774Sralph * hystopn(telno, flds, dev) connect to hayes smartmodem (tone call) 11*17774Sralph * char *flds[], *dev[]; 12*17774Sralph * 13*17774Sralph * return codes: 14*17774Sralph * >0 - file number - ok 15*17774Sralph * CF_DIAL,CF_DEVICE - failed 16*17774Sralph */ 17*17774Sralph 18*17774Sralph hyspopn(telno, flds, dev) 19*17774Sralph char *telno, *flds[]; 20*17774Sralph struct Devices *dev; 21*17774Sralph { 22*17774Sralph return hysopn(telno, flds, dev, 0); 23*17774Sralph } 24*17774Sralph 25*17774Sralph hystopn(telno, flds, dev) 26*17774Sralph char *telno, *flds[]; 27*17774Sralph struct Devices *dev; 28*17774Sralph { 29*17774Sralph return hysopn(telno, flds, dev, 1); 30*17774Sralph } 31*17774Sralph 32*17774Sralph /* ARGSUSED */ 33*17774Sralph hysopn(telno, flds, dev, toneflag) 34*17774Sralph char *telno; 35*17774Sralph char *flds[]; 36*17774Sralph struct Devices *dev; 37*17774Sralph int toneflag; 38*17774Sralph { 39*17774Sralph int dh = -1; 40*17774Sralph extern errno; 41*17774Sralph char dcname[20]; 42*17774Sralph 43*17774Sralph sprintf(dcname, "/dev/%s", dev->D_line); 44*17774Sralph DEBUG(4, "dc - %s\n", dcname); 45*17774Sralph if (setjmp(Sjbuf)) { 46*17774Sralph logent(dcname, "TIMEOUT"); 47*17774Sralph if (dh >= 0) 48*17774Sralph close(dh); 49*17774Sralph return CF_DIAL; 50*17774Sralph } 51*17774Sralph signal(SIGALRM, alarmtr); 52*17774Sralph getnextfd(); 53*17774Sralph alarm(10); 54*17774Sralph dh = open(dcname, 2); /* read/write */ 55*17774Sralph alarm(0); 56*17774Sralph 57*17774Sralph /* modem is open */ 58*17774Sralph next_fd = -1; 59*17774Sralph if (dh >= 0) { 60*17774Sralph fixline(dh, dev->D_speed); 61*17774Sralph if (dochat(dev, flds, dh)) { 62*17774Sralph logent(dcname, "CHAT FAILED"); 63*17774Sralph close(dh); 64*17774Sralph return CF_DIAL; 65*17774Sralph } 66*17774Sralph write(dh, "ATH\r", 4); 67*17774Sralph if (expect("OK\r\n", dh) != 0) { 68*17774Sralph logent(dcname, "HSM seems dead"); 69*17774Sralph close(dh); 70*17774Sralph return CF_DIAL; 71*17774Sralph } 72*17774Sralph if (toneflag) 73*17774Sralph write(dh, "\rATDT", 5); 74*17774Sralph else 75*17774Sralph write(dh, "\rATDP", 5); 76*17774Sralph write(dh, telno, strlen(telno)); 77*17774Sralph write(dh, "\r", 1); 78*17774Sralph 79*17774Sralph if (expect("CONNECT", dh) != 0) { 80*17774Sralph logent("HSM no carrier", _FAILED); 81*17774Sralph strcpy(devSel, dev->D_line); 82*17774Sralph hyscls(dh); 83*17774Sralph return CF_DIAL; 84*17774Sralph } 85*17774Sralph 86*17774Sralph } 87*17774Sralph if (dh < 0) { 88*17774Sralph logent(dcname, "CAN'T OPEN"); 89*17774Sralph return dh; 90*17774Sralph } 91*17774Sralph DEBUG(4, "hayes ok\n", CNULL); 92*17774Sralph return dh; 93*17774Sralph } 94*17774Sralph 95*17774Sralph hyscls(fd) 96*17774Sralph int fd; 97*17774Sralph { 98*17774Sralph char dcname[20]; 99*17774Sralph #ifdef DROPDTR 100*17774Sralph struct sgttyb hup, sav; 101*17774Sralph #endif 102*17774Sralph 103*17774Sralph if (fd > 0) { 104*17774Sralph sprintf(dcname, "/dev/%s", devSel); 105*17774Sralph DEBUG(4, "Hanging up fd = %d\n", fd); 106*17774Sralph #ifdef DROPDTR 107*17774Sralph /* 108*17774Sralph * code to drop DTR -- change to 0 baud then back to default. 109*17774Sralph */ 110*17774Sralph gtty(fd, &hup); 111*17774Sralph gtty(fd, &sav); 112*17774Sralph hup.sg_ispeed = B0; 113*17774Sralph hup.sg_ospeed = B0; 114*17774Sralph stty(fd, &hup); 115*17774Sralph sleep(2); 116*17774Sralph stty(fd, &sav); 117*17774Sralph /* 118*17774Sralph * now raise DTR -- close the device & open it again. 119*17774Sralph */ 120*17774Sralph sleep(2); 121*17774Sralph close(fd); 122*17774Sralph sleep(2); 123*17774Sralph fd = open(dcname, 2); 124*17774Sralph /* 125*17774Sralph * Since we have a getty sleeping on this line, when it wakes up it sends 126*17774Sralph * all kinds of garbage to the modem. Unfortunatly, the modem likes to 127*17774Sralph * execute the previous command when it sees the garbage. The previous 128*17774Sralph * command was to dial the phone, so let's make the last command reset 129*17774Sralph * the modem. 130*17774Sralph */ 131*17774Sralph #else 132*17774Sralph sleep(3); 133*17774Sralph write(fd, "+++", 3); 134*17774Sralph #endif 135*17774Sralph sleep(3); 136*17774Sralph write(fd, "ATH\r", 4); 137*17774Sralph if (expect("ATH", fd) || expect("OK\r\n", fd)) 138*17774Sralph logent(devSel, "HSM did not respond to ATH"); 139*17774Sralph write(fd, "ATZ\r", 4); 140*17774Sralph if (expect("ATZ", fd) || expect("OK\r\n", fd)) 141*17774Sralph logent(devSel, "HSM did not respond to ATZ"); 142*17774Sralph sleep(1); 143*17774Sralph close(fd); 144*17774Sralph delock(devSel); 145*17774Sralph } 146*17774Sralph } 147*17774Sralph 148*17774Sralph #endif HAYES 149