⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ckudia.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 5 页
字号:
	erp = errmsg;	sprintf(erp,"Sorry, can't open %s",ttname);	perror(errmsg);	return(0);    }/* Condition console terminal and communication line */    /* Place line into "clocal" dialing state, */    /* important mainly for System V UNIX.     */    if (ttpkt(speed,FLO_DIAL,parity) < 0) {	ttclos(0);			/* If ttpkt fails do all this... */	if (ttopen(ttname,&local,mymdmtyp,0) < 0) {	    erp = errmsg;	    sprintf(erp,"Sorry, can't reopen %s",ttname);	    perror(errmsg);	    return(0);	}				/* And try again. */	if (ttpkt(speed,FLO_DIAL,parity) < 0) {	    printf("Sorry, Can't condition communication line\n");	    printf("Try 'set line %s' again\n",ttname);	    return(0);	}    }    msleep(500);    pmdminf = ptrtab[ (mymdmtyp & 0xff) -1 ]; /* set pointer to modem info */    augmdmtyp = mymdmtyp;		/* initialize "augmented" modem type */    mymdmtyp &= 0xff;			/* major modem type */    /* Interdigit waits for tone dial */    if (dialtmo < 1) {			/* Automatic computation. */	waitct = 1 * (int)strlen(telnbr) ; /* Compute worst case dial time */	waitct += pmdminf->dial_time;	/* dialtone + completion wait times */	for (s = telnbr; *s; s++) {	/* add in pause characters time */	    for (p=pmdminf->pause_chars; *p; p++)	      if (*s == *p) {		  waitct += pmdminf->pause_time;		  break;	      }	}#ifndef MINIDIAL	if (augmdmtyp == n_TBPEP || augmdmtyp == n_TBPNV) {	    waitct += 30;	/* Longer connect wait for PEP call */	}#endif /* MINIDIAL */    } else {				/* User-specified timeout */	waitct = dialtmo;    }/*  waitct is our alarm() timer.  mdmwait is how long we tell the modem to wait for carrier.  We set mdmwait to be 1 second less than waitct, to increase the  chance that we get a response from the modem before timing out.*/    if (waitct < 0) waitct = 0;    mdmwait = (waitct > 5) ? waitct - 5 : waitct;    for (m = 0; m < nmdm; m++) {	/* Look up modem type. */	if (mdmtab[m].kwval == mymdmtyp) {	    break;	}    }    if (!quiet && !backgrd) {		/* Print information messages. */	printf(" Dialing: %s\n", telnbr);	if (network) {	    printf(" Via modem server: %s, modem-dialer: %s\n",		   ttname, (m >= nmdm ? "(unknown)" : mdmtab[m].kwd) );	} else {	    printf(" Device: %s, modem-dialer: %s",		   ttname, (m >= nmdm ? "(unknown)" : mdmtab[m].kwd) );	    if (speed > -1L)	      printf(", speed: %ld\n", speed);	    else	      printf(", speed: (unknown)\n", speed);	}	printf(" Dial timeout: %d seconds\n",waitct);	printf(#ifdef MAC	       " Type Command-. to cancel dialing\n"#else#ifdef UNIX	       " To cancel: type your interrupt character (normally Ctrl-C)\n"#else	       " To cancel: type Ctrl-C\n"#endif /* UNIX */#endif /* MAC */	       );    }    debug(F111,"ckdial",ttname,(int) (speed / 10L));    debug(F101,"ckdial timeout","",waitct);/* Hang up the modem (in case it wasn't "on hook") *//* But only if SET DIAL HANGUP ON... */    if (dialhup() < 0) {	debug(F100,"ckdial dialhup failed","",0);#ifndef MINIDIAL	if (mymdmtyp == n_TELEBIT)	/* Telebit might need a BREAK */	  ttsndb();			/*  first. */#endif /* MINIDIAL */	if (dialhng) {			/* If it failed, */	    ttclos(0);			/* close and reopen the device. */            if (ttopen(ttname,&local,mymdmtyp,0) < 0) {		printf("Sorry, Can't hang up communication device\n");		printf("Try 'set line %s' again\n",ttname);		return(0);	    }	}    }#ifndef MINIDIAL    if (augmdmtyp == n_ROLM)		/* Don't start talking to Rolm */      msleep(500);			/* too soon... */#endif /* MINIDIAL *//*  Establish jump vector, or handle "failure" jumps.  longjmp() sets global failure reason, n1.*/    if (setjmp(sjbuf)) {		/* if a "failure jump" was taken... */	n = n1;	alarm(0);			/* disable timeouts */	if (setjmp(sjbuf)) {		/* failure while handling failure */	    printf ("%s failure while handling failure.\n", F_reason[n1]);	} else {			/* first (i.e., non-nested) failure */	    signal(SIGALRM, dialtime);	/* be sure to catch signals */#ifdef MAC	    signal(SIGINT, dialint);#else /* MAC */#ifdef OSK	    if (signal(SIGINT, SIG_IGN) != (SIGTYP (*)()) SIG_IGN)		signal(SIGINT, dialint);#else	    if (signal(SIGINT, SIG_IGN) != SIG_IGN)		signal(SIGINT, dialint);#endif /* OS9 */#endif /* MAC */	    alarm(10);			/* Be sure to exit this section */	}	switch (n) {			/* Type of failure */	    case F_time: {		/* Timed out */		printf ("DIAL TIMEOUT interval expired.\n");		if (mymdmtyp == n_HAYES#ifndef MINIDIAL		    || mymdmtyp == n_TELEBIT || mymdmtyp == n_HST#endif /* MINIDIAL */		    )		  ttoc('\015');		/* Send CR to interrupt dialing */  		  /* some hayes modems don't fail with BUSY on busy lines */		debug(F110,"dial","timeout",0);		break;	    }	    case F_int: {		/* Dialing interrupted */		printf ("Dialing interrupted.\n");		debug(F110,"dial","interrupted",0);		if (mymdmtyp == n_HAYES#ifndef MINIDIAL		    || mymdmtyp == n_TELEBIT || mymdmtyp == n_HST#endif /* MINIDIAL */		    )		  ttoc('\015');		/* Send CR to interrupt dialing */		break;	    }	    case F_modem: {		/* Modem detected a failure */		printf ("Call failed (\"");		for (pc = lbuf; *pc; pc++)		  if (isprint(*pc))		    putchar(*pc);	/* Display printable reason */		printf ("\").\n");		debug(F110,"dial",lbuf,0);		break;	    }	    case F_minit: {		/* Cannot initialize modem */		printf ("Can't initialize modem.\n");		debug(F110,"dial","modem init",0);		break;	    }	}	dreset();			/* reset alarms, etc. */#ifdef DYNAMIC	if (lbuf) free(lbuf);#endif /* DYNAMIC */	return(0);			/* exit with failure code */    }/* Set timer and interrupt handlers. */    alarm(0);				/* No alarms yet. */#ifdef MAC    savint = signal(SIGINT, dialint);	/* And terminal interrupt handler. */#else /* MAC */#ifdef OSK    if ((savint = signal(SIGINT,SIG_IGN)) != (SIGTYP (*)()) SIG_IGN)      signal(SIGINT,dialint);#else    if ((savint = signal(SIGINT,SIG_IGN)) != SIG_IGN )      signal(SIGINT,dialint);#endif /* OS-9 */#endif /* MAC *//* Put modem in command mode. */switch (augmdmtyp) {			/* Send the wakeup string */#ifdef ATT7300	case n_ATTUPC: {/*  For ATT7300/Unix PC's with their special internal modem.  Timeout  and user interrupts are enabled during dialing.  attdial() is in  file ckutio.c.  - jrd*/_PROTOTYP( int attdial, (char *, long, char *) );            savalrm = signal(SIGALRM,dialtime); /* Set alarm handler. */	    alarm(waitct);			/* do alarm properly */	    if (attdial(ttname,speed,telnbr)) { /* dial internal modem */		dreset();			/* reset alarms, etc. */		printf(" Call failed.\r\n");		dialhup();	        	/* Hangup the call */#ifdef DYNAMIC		if (lbuf) free(lbuf);#endif /* DYNAMIC */		return(0);			/* return failure */	    }	    dreset();				/* reset alarms, etc. */	    ttpkt(speed,FLO_DIAX,parity);	/* cancel dialing ioctl */	    if (!quiet && !backgrd) {		if (dialdpy) printf("\n");		printf(" Call complete.\07\r\n");	    }#ifdef DYNAMIC            if (lbuf) free(lbuf);#endif /* DYNAMIC */	    return(1);	 /* no conversation with modem to complete dialing */	}#endif /* ATT7300 *//*  For Hayes modem command language, figure out if modem is giving verbose  or digit result codes.*/    case n_HAYES:    case n_HAYESNV:#ifndef MINIDIAL    case n_HST:	if (augmdmtyp == n_HST)	  m = 255;	else#endif /* MINIDIAL */	  m = 60;			/* Maximum value for S7 */	ws = dialini ? dialini : HAYES.wake_str;	for (tries = 4; tries > 0; tries--) {	    ttslow(ws,pmdminf->wake_rate);	    mdmstat = getok(4,1);	    if (mdmstat > 0) break;	    sleep(1);			/* Wait before retrying */	}	if (mdmstat > 0) { 		/* Initialized OK. */	    char hbuf[10];/*  Now tell the modem about our dial timeout.  For Hayes 1200, the maximum  is 60 seconds.  For Hayes 2400 (the manual says) it is 30 seconds, but I'm  not sure I believe this (I don't have one handy to see for myself).  If you give the modem a value larger than its maximum, it sets the timeout  to its maximum.  The manual does not say what happens when the value is 0,  but experimentation shows that it allows the modem to wait forever, in  which case Kermit will time out at the desired time.*//*  Note by Kai Uwe Rommel:  This is not acceptable for general use of the hayes modem type with other  compatible modems. Most other modems allow a range of 1..255 while 0 is  invalid on several modems. Let it be the user's responsibility to make  sure a valid value is used. Higher values are desirable for users with  rotary dialing and with high speed modems, where protocol negotiation takes  quite a long time.*/#ifdef COMMENT	    if (mdmwait > m)		/* If larger than maximum, */	      mdmwait = 0;		/* make it infinite. */#else	    if (mdmwait > 255)		/* If larger than maximum, */	      mdmwait = 255;		/* make it maximum. */#endif /* COMMENT */	    sprintf(hbuf,"ATS7=%d%c",mdmwait,13); /* S7 = Carrier wait time */	    ttslow(hbuf,pmdminf->wake_rate); /* Set it. */	    mdmstat = getok(4,1);	/* Get response from modem */	    debug(F101,"S7 mdmstat","",mdmstat);	    break;			/* Errors here are not fatal */	}	/* modem-initialization failure */	n1 = (mdmstat == 0) ? F_minit : F_modem;	longjmp( sjbuf, n1 );#ifndef MINIDIAL/*  Telebit modems fall into two basic groups: old and new.  The functions and  command sets are different between the two groups, and also vary by specific  models within each group, and even by firmware ROM revision number.  Read  ckcker.bwr for details.  Commands used by C-Kermit include:    Old       New            Meaning    -------   --------       ----------------------------------------    Q0        Q0             Enable result codes.    X1        X1             Extended result codes.    X1        X1             Extended result codes + BUSY, NO DIALTONE, etc.    I         I              Model number inquiry.    I3        I3             Additional model information inquiry.    S12=50    S12=50         Escape sequence guard time (1 sec).    S2=43     S2=43          Escape character is '+'.    S7=xx     S7=xx          DIAL TIMEOUT, calculated or SET by user.    S48=0     S48=0          7-bit data (Kermit's PARITY is not NONE).    S48=1     S48=1          8-bit data (Kermit's PARITY is NONE).    S50=0     S50=0          Automatic speed & protocol determination.    S50=3     S50=3          2400/1200/300 bps.    S50=6     S50=6          V.32 (9600 bps).    S50=255   S50=255        PEP mode.    S110=1    S190=1 S191=7  Allow compression in PEP mode.    S51=?     S51=?          DTE interface speed (left alone by Kermit).    S54=3     S61=0 S63=0    Pass BREAK signal (always).    S58=2     S58=2          RTS/CTS flow control if Kermit's FLOW is RTS/CTS.    S58=?     S58=?          S58 unchanged if Kermit's FLOW is not RTS/CTS.    S68=255   S68=255        Use flow control specified by S58 (always).    S95=0     S180=0         MNP disabled (SET DIAL MNP-ENABLE OFF)    S95=2     S180=3         MNP, fallback to direct (also as V.42 fallback)    S97=1     S180=2         Enable V.42 (LAPM) error correction    S98=3                    Enable compression in both directions    S106=1                   V.42bis compression enableFor Kermit Spoof (same commands for all models that support it):    S111=0                   No Kermit spoofing    S111=10                  Kermit with no parity    S111=11                  Kermit with odd parity    S111=12                  Kermit with even parity    S111=13                  Kermit with mark parity    S111=14                  Kermit with space parity    S112=??                  Kermit's start-of-packet character (stchr).*/    case n_TELEBIT:			/* Telebits... */    case n_TBPEP:    case n_TB3:    case n_TB4:    case n_TBS:    case n_TBNV:    case n_TBPNV:    case n_TB3NV:    case n_TB4NV:    case n_TBSNV: {	int S111;			/* Telebit Kermit spoof register */	char tbcmdbuf[64];		/* Telebit modem command buffer */	char *mnpstr = "";		/* Pointer to MNP-enable string */	char *dprstr = "";		/* Pointer to dial protocol string *//*  If user defined a DIAL INIT-STRING, send that now, otherwise send built-in  Telebit string.  Try up to 4 times to get OK or 0 response from modem.  NOTE: The default init string *must* be independent of Telebit model.*/	ws = dialini ? dialini : TELEBIT.wake_str;	debug(F110,"ckdial telebit init string",ws,0);	for (tries = 4; tries > 0; tries--) {	    ttsndb();			/* Begin by sending BREAK */	    ttslow(ws,pmdminf->wake_rate); /* Send wakeup string */	    mdmstat = getok(5,0);	/* Get modem's response */	    if (mdmstat) break;		/* If response OK, done */	    msleep(300);		/* Otherwise, sleep 1/3 second */	    dialhup();			/* Hang up */	    ttflui();			/* Flush input buffer and try again */	}	if (mdmstat < 1) {		/* If we didn't get a response */	    n1 = F_minit;		/* fail, reason = can't initialize */	    longjmp( sjbuf, F_minit );	}	if (!dialini) {			/* If using built-in init strings... *//*  Try to get the model number.  It should be in the getok() response buffer,  rbuf[], because the Telebit init string asks for it with the "I" command.  If the model number is 965, we have to make another query to narrow it down.*/	    if (didweget(rbuf,"962") ||	/* Check model number */		didweget(rbuf,"961") ||		didweget(rbuf,"963")) {		tbmodel = TB_BLAZ;	/* Trailblazer */	    } else if (didweget(rbuf,"972")) {		tbmodel = TB_2500;	/* T2500 */	    } else if (didweget(rbuf,"968")) {		tbmodel = TB_1000;	/* T1000 */	    } else if (didweget(rbuf,"966") ||		       didweget(rbuf,"967") ||		       didweget(rbuf,"964")) {		tbmodel = TB_PLUS;	/* Trailblazer-Plus */	    } else if (didweget(rbuf,"969")) {		tbmodel = TB_QBLA;	/* Qblazer */	    } else if (didweget(rbuf,"965")) { /* Most new models */		tbati3(965);		/* Go find out */	    } else if (didweget(rbuf,"971")) { /* T1500 or T2500 */		tbati3(971);		/* Go find out */	    } else if (didweget(rbuf,"123") || didweget(rbuf,"960")) {		tbmodel = TB_UNK;	/* Telebit in Hayes mode */	    }	    debug(F111,"Telebit model",tb_name[tbmodel],tbmodel);	    if (dialdpy)	      printf("Telebit model: %s\n",tb_name[tbmodel]);	    ttflui();/*  Dial timeout.  S7 is set to the DIAL TIMEOUT value, or else to 255 if the  dial timeout is greater than 255, which is the maximum value for Telebits.  S7 can't be set to 0 on Telebits -- it gives an error.*/	    if (mdmwait > 255)		/* If dial timeout too big */	      mdmwait = 255;		/* make it as big as possible. *//*  Flow control.  If C-Kermit's FLOW-CONTROL is RTS/CTS, then we set this on

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -