1 #ifndef lint 2 static char sccsid[] = "@(#)hys24.c 1.1 (Berkeley) 01/13/86"; 3 #endif !lint 4 5 #include "../condevs.h" 6 7 #ifdef HAYES2400 8 /* 9 * hyspopn24(telno, flds, dev) connect to hayes smartmodem (pulse call) 10 * hystopn24(telno, flds, dev) connect to hayes smartmodem (tone call) 11 * char *flds[], *dev[]; 12 * 13 * return codes: 14 * >0 - file number - ok 15 * CF_DIAL,CF_DEVICE - failed 16 */ 17 18 hyspopn24(telno, flds, dev) 19 char *telno, *flds[]; 20 struct Devices *dev; 21 { 22 return hysopn24(telno, flds, dev, 0); 23 } 24 25 hystopn24(telno, flds, dev) 26 char *telno, *flds[]; 27 struct Devices *dev; 28 { 29 return hysopn24(telno, flds, dev, 1); 30 } 31 32 /* ARGSUSED */ 33 hysopn24(telno, flds, dev, toneflag) 34 char *telno; 35 char *flds[]; 36 struct Devices *dev; 37 int toneflag; 38 { 39 int dh = -1; 40 char *ii; 41 extern errno; 42 char dcname[20]; 43 44 sprintf(dcname, "/dev/%s", dev->D_line); 45 DEBUG(4, "dc - %s\n", dcname); 46 if (setjmp(Sjbuf)) { 47 logent(dcname, "TIMEOUT"); 48 if (dh >= 0) 49 hyscls24(dh); 50 return CF_DIAL; 51 } 52 signal(SIGALRM, alarmtr); 53 getnextfd(); 54 alarm(10); 55 dh = open(dcname, 2); /* read/write */ 56 alarm(0); 57 58 for (ii = telno; *ii; ii++) 59 if (*ii == '=') 60 *ii = ','; 61 62 /* modem is open */ 63 next_fd = -1; 64 if (dh >= 0) { 65 fixline(dh, dev->D_speed); 66 write(dh, "\rATZH\r", 6); 67 sleep(2); 68 if (dochat(dev, flds, dh)) { 69 logent(dcname, "CHAT FAILED"); 70 hyscls24(dh); 71 return CF_DIAL; 72 } 73 write(dh, "AT&F&D3&C1E0X1\r", 15); 74 if (expect("OK\r\n", dh) != 0) { 75 logent(dcname, "HSM not responding OK"); 76 hyscls24(dh); 77 return CF_DIAL; 78 } 79 if (toneflag) 80 write(dh, "\rATDT", 5); 81 else 82 write(dh, "\rATDP", 5); 83 write(dh, telno, strlen(telno)); 84 write(dh, "\r", 1); 85 86 if (expect("CONNECT", dh) != 0) { 87 logent("HSM no carrier", _FAILED); 88 strcpy(devSel, dev->D_line); 89 hyscls24(dh); 90 return CF_DIAL; 91 } 92 93 } 94 if (dh < 0) { 95 logent(dcname, "CAN'T OPEN"); 96 return dh; 97 } 98 DEBUG(4, "hayes ok\n", CNULL); 99 return dh; 100 } 101 102 hyscls24(fd) 103 int fd; 104 { 105 char dcname[20]; 106 107 if (fd > 0) { 108 sprintf(dcname, "/dev/%s", devSel); 109 DEBUG(4, "Hanging up fd = %d\n", fd); 110 sleep(1); 111 /* 112 * Since we have a getty sleeping on this line, when it wakes up it sends 113 * all kinds of garbage to the modem. Unfortunatly, the modem likes to 114 * execute the previous command when it sees the garbage. The previous 115 * command was to dial the phone, so let's make the last command reset 116 * the modem. 117 */ 118 write(fd, "\r+++", 4); 119 sleep(2); 120 write(fd, "\rATH\rATZ\r", 9); 121 sleep(2); 122 close(fd); 123 delock(devSel); 124 } 125 } 126 #endif HAYES2400 127