Annotation of 43BSD/usr.bin/uucp/aculib/hys.c, revision 1.1.1.1

1.1       root        1: #ifndef lint
                      2: static char sccsid[] = "@(#)hys.c      4.6 (Berkeley) 2/12/86";
                      3: #endif
                      4: 
                      5: #include "../condevs.h"
                      6: 
                      7: #ifdef HAYES
                      8: #ifdef USR2400
                      9: #define DROPDTR
                     10: /*
                     11:  * The "correct" switch settings for a USR Courier 2400 are
                     12:  *     Dialin/out:     0 0 1 1 0 0 0 1 0 0
                     13:  *     Dialout only:   0 0 1 1 1 1 0 1 0 0
                     14:  * where 0 = off and 1 = on
                     15:  */
                     16: #endif USR2400
                     17: 
                     18: /*
                     19:  *     hyspopn(telno, flds, dev) connect to hayes smartmodem (pulse call)
                     20:  *     hystopn(telno, flds, dev) connect to hayes smartmodem (tone call)
                     21:  *     char *flds[], *dev[];
                     22:  *
                     23:  *     return codes:
                     24:  *             >0  -  file number  -  ok
                     25:  *             CF_DIAL,CF_DEVICE  -  failed
                     26:  */
                     27: 
                     28: hyspopn(telno, flds, dev)
                     29: char *telno, *flds[];
                     30: struct Devices *dev;
                     31: {
                     32:        return hysopn(telno, flds, dev, 0);
                     33: }
                     34: 
                     35: hystopn(telno, flds, dev)
                     36: char *telno, *flds[];
                     37: struct Devices *dev;
                     38: {
                     39:        return hysopn(telno, flds, dev, 1);
                     40: }
                     41: 
                     42: /* ARGSUSED */
                     43: hysopn(telno, flds, dev, toneflag)
                     44: char *telno;
                     45: char *flds[];
                     46: struct Devices *dev;
                     47: int toneflag;
                     48: {
                     49:        extern errno;
                     50:        char dcname[20];
                     51:        char cbuf[MAXPH];
                     52:        register char *cp;
                     53:        register int i;
                     54:        int dh = -1, nrings = 0;
                     55: 
                     56:        sprintf(dcname, "/dev/%s", dev->D_line);
                     57:        DEBUG(4, "dc - %s\n", dcname);
                     58:        if (setjmp(Sjbuf)) {
                     59:                logent(dcname, "TIMEOUT");
                     60:                if (dh >= 0)
                     61:                        hyscls(dh);
                     62:                return CF_DIAL;
                     63:        }
                     64:        signal(SIGALRM, alarmtr);
                     65:        getnextfd();
                     66:        alarm(10);
                     67:        dh = open(dcname, 2); /* read/write */
                     68:        alarm(0);
                     69: 
                     70:        /* modem is open */
                     71:        next_fd = -1;
                     72:        if (dh >= 0) {
                     73:                fixline(dh, dev->D_speed);
                     74:                if (dochat(dev, flds, dh)) {
                     75:                        logent(dcname, "CHAT FAILED");
                     76:                        hyscls(dh);
                     77:                        return CF_DIAL;
                     78:                }
                     79:                write(dh, "ATV1E0H\r", 8);
                     80:                if (expect("OK\r\n", dh) != 0) {
                     81:                        logent(dcname, "HSM seems dead");
                     82:                        hyscls(dh);
                     83:                        return CF_DIAL;
                     84:                }
                     85: #ifdef USR2400
                     86:                write(dh, "ATX6S7=44\r", 10);
                     87:                if (expect("OK\r\n", dh) != 0) {
                     88:                        logent(dcname, "HSM seems dead");
                     89:                        hyscls(dh);
                     90:                        return CF_DIAL;
                     91:                }
                     92: #endif USR2400
                     93:                if (toneflag)
                     94:                        write(dh, "\rATDT", 5);
                     95:                else
                     96: #ifdef USR2400
                     97:                        write(dh, "\rATD", 4);
                     98: #else HAYES
                     99:                        write(dh, "\rATDP", 5);
                    100: #endif HAYES
                    101:                write(dh, telno, strlen(telno));
                    102:                write(dh, "\r", 1);
                    103: 
                    104:                if (setjmp(Sjbuf)) {
                    105:                        logent(dcname, "TIMEOUT");
                    106:                        strcpy(devSel, dev->D_line);
                    107:                        hyscls(dh);
                    108:                        return CF_DIAL;
                    109:                }
                    110:                signal(SIGALRM, alarmtr);
                    111:                alarm(2*MAXMSGTIME);
                    112:                do {
                    113:                        cp = cbuf;
                    114:                        while (read(dh, cp ,1) == 1)
                    115:                                if (*cp >= ' ')
                    116:                                        break;
                    117:                        while (++cp < &cbuf[MAXPH] && read(dh, cp, 1) == 1 && *cp != '\n')
                    118:                                ;
                    119:                        alarm(0);
                    120:                        *cp-- = '\0';
                    121:                        if (*cp == '\r')
                    122:                                *cp = '\0';
                    123:                        DEBUG(4,"\nGOT: %s", cbuf);
                    124:                        alarm(MAXMSGTIME);
                    125:                } while (strncmp(cbuf, "RING", 4) == 0 && nrings++ < 5);
                    126:                if (strncmp(cbuf, "CONNECT", 7) != 0) {
                    127:                        logent(cbuf, _FAILED);
                    128:                        strcpy(devSel, dev->D_line);
                    129:                        hyscls(dh);
                    130:                        return CF_DIAL;
                    131:                }
                    132:                i = atoi(&cbuf[8]);
                    133:                if (i > 0 && i != dev->D_speed) {       
                    134:                        DEBUG(4,"Baudrate reset to %d\n", i);
                    135:                        fixline(dh, i);
                    136:                }
                    137: 
                    138:        }
                    139:        if (dh < 0) {
                    140:                logent(dcname, "CAN'T OPEN");
                    141:                return dh;
                    142:        }
                    143:        DEBUG(4, "hayes ok\n", CNULL);
                    144:        return dh;
                    145: }
                    146: 
                    147: hyscls(fd)
                    148: int fd;
                    149: {
                    150:        char dcname[20];
                    151: #ifdef DROPDTR
                    152:        struct sgttyb hup, sav;
                    153: #endif
                    154: 
                    155:        if (fd > 0) {
                    156:                sprintf(dcname, "/dev/%s", devSel);
                    157:                DEBUG(4, "Hanging up fd = %d\n", fd);
                    158: #ifdef DROPDTR
                    159:                /*
                    160:                 * code to drop DTR -- change to 0 baud then back to default.
                    161:                 */
                    162:                gtty(fd, &hup);
                    163:                gtty(fd, &sav);
                    164:                hup.sg_ispeed = B0;
                    165:                hup.sg_ospeed = B0;
                    166:                stty(fd, &hup);
                    167:                sleep(2);
                    168:                stty(fd, &sav);
                    169:                /*
                    170:                 * now raise DTR -- close the device & open it again.
                    171:                 */
                    172:                sleep(2);
                    173:                close(fd);
                    174:                sleep(2);
                    175:                fd = open(dcname, 2);
                    176:                stty(fd, &sav);
                    177: #else
                    178:                sleep(3);
                    179:                write(fd, "+++", 3);
                    180: #endif
                    181:                sleep(3);
                    182:                write(fd, "ATZ\r", 4);
                    183:                if (expect("OK",fd) != 0)
                    184:                        logent(devSel, "HSM did not respond to ATZ");
                    185:                write(fd, "ATH\r", 4);
                    186:                sleep(1);
                    187:                close(fd);
                    188:                delock(devSel);
                    189:        }
                    190: }
                    191: #endif HAYES

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.