Annotation of 43BSDReno/usr.bin/uucp/aculib/df12.c, revision 1.1.1.1

1.1       root        1: #ifndef lint
                      2: static char sccsid[] = "@(#)df12.c     4.2 (Berkeley) 2/24/88";
                      3: #endif
                      4: 
                      5: #include "../condevs.h"
                      6: 
                      7: /*
                      8:  *     df12popn(telno, flds, dev) connect to df12 modem (pulse call)
                      9:  *     df12topn(telno, flds, dev) connect to df12 modem (tone call)
                     10:  *     char *flds[], *dev[];
                     11:  *
                     12:  *     return codes:
                     13:  *             >0  -  file number  -  ok
                     14:  *             CF_DIAL,CF_NODEV  -  failed
                     15:  */
                     16: 
                     17: df12popn (telno, flds, dev)
                     18: char   *telno,
                     19:        *flds[];
                     20: struct Devices *dev;
                     21: {
                     22:     return df12opn (telno, flds, dev, 0);
                     23: }
                     24: 
                     25: df12topn (telno, flds, dev)
                     26: char   *telno,
                     27:        *flds[];
                     28: struct Devices *dev;
                     29: {
                     30:     return df12opn (telno, flds, dev, 1);
                     31: }
                     32: 
                     33: /* ARGSUSED */
                     34: df12opn (telno, flds, dev, toneflag)
                     35: char   *telno;
                     36: char   *flds[];
                     37: struct Devices *dev;
                     38: int     toneflag;
                     39: {
                     40:     int     phindex, dh = -1;
                     41:     extern  errno;
                     42:     char    dcname[20], newphone[64];
                     43: 
                     44:     sprintf (dcname, "/dev/%s", dev -> D_line);
                     45:     DEBUG (4, "dc - %s\n", dcname);
                     46:     if (setjmp (Sjbuf))
                     47:     {
                     48:        logent (dcname, "TIMEOUT");
                     49:        if (dh >= 0)
                     50:            close (dh);
                     51:        return CF_DIAL;
                     52:     }
                     53:     signal (SIGALRM, alarmtr);
                     54:     getnextfd ();
                     55:     alarm (10);
                     56:     dh = open (dcname, 2);/* read/write */
                     57:     alarm (0);
                     58: 
                     59:  /* modem is open */
                     60: 
                     61:  /* First, adjust our phone number string.  These modems don't 
                     62:   * like any characters but digits and "=" signs (for delay)
                     63:   */
                     64:     for (phindex = 0; *telno; telno++)
                     65:     {
                     66:        if (*telno == '=' || (*telno >= '0' && *telno <= '9'))
                     67:            newphone[phindex++] = *telno;
                     68:        if (phindex == 64)
                     69:        {
                     70:            logent (dcname, "Phone number too long");
                     71:            close (dh);
                     72:            return CF_DIAL;
                     73:        }
                     74:     }
                     75:     newphone[phindex] = '\0';
                     76:     next_fd = -1;
                     77:     if (dh >= 0)
                     78:     {
                     79:        fixline (dh, dev -> D_speed);
                     80:        if (dochat (dev, flds, dh))
                     81:        {
                     82:            logent (dcname, "CHAT FAILED");
                     83:            close (dh);
                     84:            return CF_DIAL;
                     85:        }
                     86:        slowrite (dh, "\02");
                     87:        if (expect ("Ready\r\n", dh) != 0)
                     88:        {
                     89:            DEBUG (4, "Didn't get 'Ready' response.\n", NULL);
                     90:            logent (dcname, "Modem not responding");
                     91:            close (dh);
                     92:            return CF_DIAL;
                     93:        }
                     94:        DEBUG (4, "Got 'Ready' response\n", NULL);
                     95:        DEBUG (7, "Writing control select flag %c\n", toneflag ? 'T' : 'P');
                     96:        slowrite (dh, toneflag ? "T" : "P");
                     97:        DEBUG (4, "Writing telephone number %s\n", newphone);
                     98:        slowrite (dh, newphone);
                     99:        DEBUG (7, "Telephone number written\n", NULL);
                    100:        slowrite (dh, "#");
                    101:        DEBUG (7, "Writing # sign\n", NULL);
                    102: 
                    103:        if (expect ("Attached\r\n", dh) != 0)
                    104:        {
                    105:            logent (dcname, "No carrier");
                    106:            strcpy (devSel, dev -> D_line);
                    107:            df12cls (dh);
                    108:            return CF_DIAL;
                    109:        }
                    110: 
                    111:     }
                    112:     if (dh < 0)
                    113:     {
                    114:        logent (dcname, "CAN'T OPEN");
                    115:        return CF_NODEV;
                    116:     }
                    117:     else
                    118:     {
                    119:        DEBUG (4, "df12 ok\n", CNULL);
                    120:        return dh;
                    121:     }
                    122: }
                    123: 
                    124: df12cls (fd)
                    125: int     fd;
                    126: {
                    127:     char    dcname[20];
                    128:     struct sgttyb   hup,
                    129:                     sav;
                    130: 
                    131:     if (fd > 0)
                    132:     {
                    133:        sprintf (dcname, "/dev/%s", devSel);
                    134:        DEBUG (4, "Hanging up fd = %d\n", fd);
                    135:     /* 
                    136:      * code to drop DTR -- change to 0 baud then back to default.
                    137:      */
                    138:        gtty (fd, &hup);
                    139:        gtty (fd, &sav);
                    140:        hup.sg_ispeed = B0;
                    141:        hup.sg_ospeed = B0;
                    142:        stty (fd, &hup);
                    143:        sleep (2);
                    144:        stty (fd, &sav);
                    145:     /* 
                    146:      * now raise DTR -- close the device & open it again.
                    147:      */
                    148:        sleep (2);
                    149:        close (fd);
                    150:        sleep (2);
                    151:        delock (devSel);
                    152:     }
                    153: }

unix.superglobalmegacorp.com

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