1: /*
   2:  * static char sccsid[] = "@(#)dial.c	4.1	(Berkeley)	9/11/82";
   3:  */
   4: 
   5: /***********************************************************************
   6: * dial: do the stuff for the various autodiallers                            *
   7: ***********************************************************************/
   8: 
   9: #include "uucp.h"
  10: #include <signal.h>
  11: #include <sgtty.h>
  12: #include <setjmp.h>
  13: #include <ctype.h>
  14: #include <utmp.h>
  15: #include <sys/types.h>
  16: #include <sys/timeb.h>
  17: 
  18: /*
  19:  * static char SiD[] = "@(#)dial  1.0";
  20:  */
  21: 
  22: #define MODEMWAIT   5
  23: 
  24: int alarmtr();
  25: 
  26: /*****************************************************************************
  27: * decdial: dial a DEC DF-03                                                  *
  28: *****************************************************************************/
  29: 
  30: decdial(dev, phone, speed)
  31: char *dev, *phone;
  32: int speed;
  33: {
  34:     printf("DECDIAL %s on %s at %d\n", phone, dev, speed);
  35:     return(-1);
  36: }
  37: 
  38: /*
  39:  * Code to handle Vadic AD3451P's
  40:  * Note: this assumes sendthem() terminates messages with CR, not NL
  41:  */
  42: 
  43: vad3451P(dev, phone, speed, line)
  44: char *dev, *phone, *line;
  45: {
  46:     int dcf, i;
  47:     int nw, ng;
  48:     extern errno;
  49:     register char *p;
  50:     int delay, bad;
  51:     char sendnum[32];
  52:     char *strcat(), *strcpy();
  53: 
  54:     /* check phone number, calculate dialing time */
  55:     delay = 5+10;   /* 5 sec dial tone delay, 10 sec for carrier det. */
  56:     bad = 0;
  57:     for (p = phone; *p != '\0'; ++p)
  58:         switch (*p) {
  59:         case '0': case '1': case '2': case '3': case '4':
  60:         case '5': case '6': case '7': case '8': case '9':
  61:             delay += 2; /* up to 1 sec for digit, 3/4 sec */
  62:             break;      /* interdigit space */
  63:         case 'k':
  64:         case 'K':
  65:             delay += 5; /* 5 sec additional delay */
  66:             break;
  67:         case ' ':
  68:         case '-':
  69:             break;
  70:         default:
  71:             ++bad;
  72:         }
  73: 
  74:     if (bad || strlen(phone) > sizeof(sendnum)-3) {
  75:         logent(phone, "BAD PHONE NUMBER");
  76:         DEBUG(4, "BAD PHONE NUMBER %s\n", phone);
  77:         return(FAIL);
  78:     }
  79: 
  80:     if ((dcf = open(dev, 2)) < 0) {
  81:         logent(dev, "OPEN FAILED");
  82:         DEBUG(4, "OPEN FAILED, errno=%d\n", errno);
  83:         return(FAIL);
  84:     }
  85:     fixline(dcf, speed);
  86: 
  87:     /* get the modem's attention and set its speed */
  88:     sendthem("\005\\d", dcf);
  89:     if (expect("HELLO: I'M READY\r\n*", dcf, MODEMWAIT))
  90:         goto fail;
  91: 
  92:     sendthem("D\\d", dcf);
  93:     if (expect("NUMBER?\r\n", dcf, MODEMWAIT))
  94:         goto fail;
  95: 
  96:     /* build phone number sent to the modem */
  97:     strcpy(sendnum, phone);
  98:     for (p = sendnum; *p != '\0'; ++p)
  99:         if (*p == 'k')
 100:             *p = 'K';       /* echo is upper case */
 101:     sendthem(sendnum, dcf);
 102:     strcat(sendnum, "\r\n");
 103:     if (expect(sendnum, dcf, MODEMWAIT))
 104:         goto fail;
 105:     sendthem("", dcf);
 106:     if (expect("DIALING:  ", dcf, MODEMWAIT))
 107:         goto fail;
 108:     if (expect("ON LINE\r\n", dcf, delay)) {
 109:         logent(dev, "DIAL FAILED");
 110:         DEBUG(4, "%s DIAL FAILED\n", dev);
 111:         sendthem("I", dcf);
 112:         close(dcf);
 113:         return(FAIL);
 114:     }
 115:     return(dcf);
 116: 
 117: fail:
 118:     logent(dev, "DIALER PROBLEM");
 119:     DEBUG(4, "%s DIALER PROBLEM\n", dev);
 120:     sendthem("I", dcf);
 121:     close(dcf);
 122:     return(FAIL);
 123: }
 124: 
 125: ven212(dev, phone, speed)
 126: char *dev, *phone;
 127: int speed;
 128: {
 129:     int dcf;
 130:     int realflags;
 131:     struct sgttyb ttbuf;
 132:  /*     static struct TTY_delays vtdelays = { 0, 0205, 0, 0 };  */
 133:  /*     static struct TTY_delays nodelays = { 0, 0, 0, 0 };     */
 134:     static struct timeb loctime;
 135:         char *erc = "error code %d\n";
 136:     extern errno;
 137: 
 138:     dcf = open(dev, 2);
 139:     if(dcf < 0) {
 140:         logent(dev, "OPEN FAILED");
 141:         DEBUG(4, "OPEN %d FAILED\n", errno);
 142:         return(FAIL);
 143:     }
 144:     /* set speeds, etc. */
 145:     fixline(dcf, speed);
 146:     /* now doctor the speeds */
 147:     ASSERT(!ioctl(dcf, TIOCGETP, &ttbuf), erc, errno);
 148:     realflags = ttbuf.sg_flags;
 149:     ttbuf.sg_flags = ODDP|EVENP|CBREAK;
 150:     ASSERT(!ioctl(dcf, TIOCSETN, &ttbuf), erc, errno);
 151:     /* IS-1 crockola
 152: 	ASSERT(!ioctl(dcf, TIOCSDEL, &vtdelays), erc, errno);
 153: 	*/
 154: 
 155:     /* now try to get its attention */
 156:     DEBUG(4, "POKE VENTEL, ", 0);
 157: 
 158:     /* IS-1 way
 159: 	write(dcf, "\r\r", 2);
 160: 	*/
 161:     /* Yale way */
 162:     ftime(&loctime);
 163:     write(dcf, "\r",1);
 164:     {register i = loctime.millitm;
 165:        while (abs(loctime.millitm - i)<250) ftime(&loctime);
 166:     }
 167:         write(dcf, "\r",1);
 168: 
 169:         DEBUG(4, "IS VENTEL THERE?\n", 0);
 170:     if(expect("\r\n$", dcf, MODEMWAIT)) {
 171: dead:
 172:         DEBUG(4, "DIAL DEAD %s\n", dev);
 173:         logent(dev, "DIALLER DEAD");
 174:         close(dcf);
 175:         return(FAIL);
 176:     }
 177: 
 178:     /* now dial the number */
 179:     ioctl(dcf, TIOCSETP, &ttbuf);    /* discard buffered stuff */
 180:     write(dcf, "K", 1);
 181:     if(expect("DIAL: ", dcf, MODEMWAIT))
 182:         goto dead;
 183: 
 184:     write(dcf, phone, strlen(phone));
 185:     write(dcf, "\r", 1);
 186:     if(expect("ONLINE!", dcf, 60))  /* should be calculated delay */
 187:         goto dead;
 188: 
 189:     /* have connection */
 190:     ttbuf.sg_flags = realflags;
 191:     ioctl(dcf, TIOCSETN, &ttbuf);
 192:     /*      IS-1
 193: 	ioctl(dcf, TIOCSDEL, &nodelays);
 194: 	*/
 195:         return(dcf);
 196: }
 197: 
 198: /*****************************************************************************
 199: * disable and reenable:   allow a single line to be turned around so as to   *
 200: * work both for dialin and dialout.                                          *
 201: *****************************************************************************/
 202: 
 203: /* Yale: Disable this crock for now */
 204: 
 205: char enbdev[30];        /* disabled device */
 206: 
 207: disable(dev)
 208: char *dev;
 209: {
 210:     int i;
 211:     struct utmp u;
 212: 
 213:     return;                 /* Yale */
 214: /*      DEBUG(4, "Disable %s\n", dev);
 215: /*        i = open("/etc/utmp", 0);
 216: /*        if(i < 0)
 217: /*                return;         /* tough */
 218: /*        while(read(i, &u, sizeof(u)) == sizeof(u)) {
 219: /*                if(strcmp(u.ut_line, dev))
 220: /*                        continue;
 221: /*                if(u.ut_stat == ENABLE) {
 222: /*                        DEBUG(4, "Was enabled: %s\n", dev);
 223: /*                          enbcall("disable", dev);
 224: /*                        logent(dev, "DISABLED LOGIN");
 225: /*                        strcpy(enbdev, dev);
 226: /*                        break;
 227: /*                }
 228: /*        }
 229: /*        close(i);
 230: */
 231: }
 232: 
 233: reenable()
 234: {
 235:     return;                 /* Yale */
 236: /*        if(!enbdev[0])
 237: /*                return;         /* nothing to reenable */
 238: /*        DEBUG(4, "Reenable %s\n", enbdev);
 239: /*        enbcall("enable", enbdev);
 240: /*        logent(enbdev, "REENABLED LOGIN");
 241: /*        enbdev[0] = 0;
 242: */
 243: }
 244: 
 245: /* enbcall(type, dev)
 246: /* char *type;
 247: /* char *dev;
 248: /* {
 249: /*	int pid;
 250: /*
 251: /*	if((pid = fork()) == 0) {
 252: /*		execl("/priv/enable", type, dev, 0);
 253: /*		exit(99);
 254: /*	}
 255: /*	while(wait(0) != pid);
 256: /*}
 257: */

Defined functions

decdial defined in line 30; never used
disable defined in line 207; never used
reenable defined in line 233; never used
vad3451P defined in line 43; never used
ven212 defined in line 125; never used

Defined variables

enbdev defined in line 205; never used

Defined macros

MODEMWAIT defined in line 22; used 6 times
Last modified: 1983-03-26
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 978
Valid CSS Valid XHTML 1.0 Strict