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

📄 ckudia.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 5 页
字号:
  result codes are returned (Q0), and ask for extended result codes (X1), and  ensure that the escape sequence is +++ and it is enabled.  And also, make  sure the final character is not a digit (whose echo might be mistaken for a  result code).  The Ctrl-Q and multiple A's are recommended by Telebit.*/    "\021AAAATQ0X1S12=50 S2=43 I\015", /* wake_str. */    100,		/* wake_rate = 100 msec */    "OK\015",		/* wake_prompt */    "",		        /* dmode_str */    "",		        /* dmode_prompt */    "ATD%s\015",	/* dial_str, Note: no T or P */    80,			/* dial_rate */    1100,		/* esc_time (guard time) */    "+++",		/* esc_str */    "ATQ0H0\015",	/* hup_str */    getok		/* ok_fn */    };#endif /* MINIDIAL *//* * Declare table for converting modem numbers to information pointers. * * The entries MUST be in ascending order by modem number, without any * "gaps" in the numbers, and starting from one (1). * * This table should NOT include entries for the "variant" modem numbers, * since they share the same information as the normal value. */staticMDMINF *ptrtab[] = {#ifdef MINIDIAL    &CCITT,    &HAYES,    &UNKNOWN#else    &ATTDTDM,    &ATTISN,    &ATTMODEM,    &CCITT,    &CERMETEK,    &DF03,    &DF100,    &DF200,    &GDC,    &HAYES,    &PENRIL,    &RACAL,    &UNKNOWN,    &USROBOT,    &VENTEL,    &CONCORD,    &ATTUPC,    &ROLM,    &MICROCOM,    &HST,    &TELEBIT,    &DIGITEL#endif /* MINIDIAL */};/* * Declare modem names and associated numbers for command parsing, * and also for doing number-to-name translation. * * The entries must be in alphabetical order by modem name. */struct keytab mdmtab[] = {#ifndef MINIDIAL    "attdtdm",		n_ATTDTDM,	0,    "attisn",           n_ATTISN,       0,    "attmodem",		n_ATTMODEM,	0,    "att7300",		n_ATTUPC,	0,#endif /* MINIDIAL */    "ccitt-v25bis",	n_CCITT,	0,#ifndef MINIDIAL    "cermetek",		n_CERMETEK,	0,    "concord",		n_CONCORD,	0,    "df03-ac",		n_DF03,		0,    "df100-series",	n_DF100,	0,    "df200-series",	n_DF200,	0,    "digitel-dt22",	n_DIGITEL,	0,#endif /* MINIDIAL */    "direct",		0,		CM_INV,	/* Synonym for NONE */#ifndef MINIDIAL    "gdc-212a/ed",	n_GDC,		0,    "gendatacomm",	n_GDC,		CM_INV,	/* Synonym for GDC */#endif /* MINIDIAL */    "hayes",		n_HAYES,	0,#ifndef MINIDIAL    "hst-courier",      n_HST,          0,    "microcom",		n_MICROCOM,	0,#endif /* MINIDIAL */    "none",             0,              0,#ifndef MINIDIAL    "penril",		n_PENRIL,	0,    "pep-telebit",      n_TBPEP,        0,    "racalvadic",	n_RACAL,	0,    "rolm",		n_ROLM,		0,    "slow-telebit",     n_TBS,		0,    "telebit",          n_TELEBIT,      0,#endif /* MINIDIAL */    "unknown",		n_UNKNOWN,	0,#ifndef MINIDIAL    "usrobotics-212a",	n_USROBOT,	0,    "v32-telebit",      n_TB3,		0,    "v42-telebit",      n_TB4,		0,    "ventel",		n_VENTEL,	0#endif /* MINIDIAL */};int nmdm = (sizeof(mdmtab) / sizeof(struct keytab)); /* Number of modems */#define CONNECTED 1			/* For completion status */#define FAILED	  2staticchar *F_reason[5] = {			/* Failure reasons for message */    "Unknown",	"Timeout", "Interrupt", "Modem", "Initialize" };static int tries = 0;static int mdmecho = 0;	/* assume modem does not echo */static int augmdmtyp;	/* "augmented" modem type, to handle modem modes */static char *p;		/* For command strings & messages */#define LBUFL 100#ifdef DYNAMICstatic char *lbuf = NULL;#elsestatic char lbuf[LBUFL];#endif /* DYNAMIC */#define RBUFL 63static char rbuf[RBUFL+1];	/* Modem response buffer */static jmp_buf sjbuf;static SIGTYP (*savalrm)();	/* For saving alarm handler */static SIGTYP (*savint)();	/* For saving interrupt handler */#ifndef MINIDIALint tbmodel = 0;		/* Telebit modem model */char *gtbmodel() {			/* Function to return name of Telebit model */    if (tbmodel < 0 || tbmodel > TB__MAX) tbmodel = TB_UNK;    return(tb_name[tbmodel]);}VOIDxcpy(to,from,len)		/* Copy the given number of bytes */    register char *to, *from;    register unsigned len; {	while (len--) *to++ = *from++;}#endif /* MINIDIAL */SIGTYPdialtime(foo) int foo; {		/* Timer interrupt handler */    n1 = F_time;			/* Failure reason = timeout */#ifdef __EMX__    signal(SIGALRM, SIG_ACK);		/* Needed for OS/2 */#endif /* __EMX__ */#ifdef OSK				/* OS-9 *//*  We are in an intercept routine but do not perform a F$RTE (done implicitly  by RTS), so we have to decrement the sigmask as F$RTE does.  Warning:  longjump only restores the CPU registers, NOT the FPU registers.  So, don't  use FPU at all or at least don't use common FPU (double or float) register  variables.*/    sigmask(-1);#endif /* OSK */    longjmp( sjbuf, F_time );}SIGTYPdialint(foo) int foo; {			/* Keyboard interrupt handler */    n1 = F_int;#ifdef __EMX__    signal(SIGINT, SIG_ACK);		/* Needed for OS/2 */#endif /* __EMX__ */#ifdef OSK				/* OS-9, see comment in dialtime() */    sigmask(-1);#endif /* OSK */    longjmp( sjbuf, F_int );}/*  Routine to read a character from communication device, handling TELNET  protocol negotiations in case we're connected to the modem through a  TCP/IP TELNET modem server.*/static intddinc(n) int n; {    int c;#ifdef TNCODE    int done = 0;    while (!done) {	c = ttinc(n);	debug(F000,"ddinc","",c);	if (c < 0) return(c);	if (c == IAC && network && ttnproto == NP_TELNET) {	    switch (tn_doop((CHAR)(c & 0xff),duplex,ttinc)) {	      case 2: duplex = 0; continue;	      case 1: duplex = 1;	      default: continue;	    }	} else done = 1;    }    return(c & 0xff);#else    return(ttinc(n));#endif /* TNCODE */}static VOIDttslow(s,millisec) char *s; int millisec; { /* Output s-l-o-w-l-y */    for (; *s; s++) {	ttoc(*s);	msleep(millisec);    }}/* * Wait for a string of characters. * * The characters are waited for individually, and other characters may * be received "in between".  This merely guarantees that the characters * ARE received, and in the order specified. */static VOIDwaitfor(s) char *s; {    CHAR c, x;    while ( c = *s++ ) {		/* while more characters remain... */	do {				/* wait for the character */	    x = ddinc(0) & 0177;	    debug(F000,"dial waitfor got","",x);	    if (dialdpy) {		if (x != LF) conoc(x);		if (x == CR) conoc(LF);	    }	} while ( x != c);    }}static intdidweget(s,r) char *s, *r; {	/* Looks in string s for response r */    int lr = (int)strlen(r);	/*  0 means not found, 1 means found it */    int i;    debug(F110,"didweget",r,0);    debug(F110," in",s,0);    for (i = (int)strlen(s)-lr; i >= 0; i--)	if ( s[i] == r[0] ) if ( !strncmp(s+i,r,lr) ) return( 1 );    return( 0 );}/* R E S E T -- Reset alarms, etc. on exit. */static VOIDdreset() {    alarm(0);    signal(SIGALRM,savalrm);		/* restore alarm handler */    signal(SIGINT,savint);		/* restore interrupt handler */}/*  Call this routine when the modem reports that it has connected at a certain  speed, giving that speed as the argument.  If the connection speed is not  the same as Kermit's current communication speed, AND the modem interface  speed is not locked (i.e. DIAL SPEED-MATCHING is not ON), then change the  device speed to the one given.*/static VOID#ifdef CK_ANSICspdchg(long s)#elsespdchg(s) long s;#endif /* CK_ANSIC *//* spdchg */ {    int s2;    if (!mdmspd)			/* If modem interface speed locked, */      return;				/*  don't do this. */    if (speed != s) {			/* Speeds differ? */	s2 = s / 10L;			/* Convert to cps expressed as int */	if (ttsspd(s2) < 0) {		/* Change speed. */	    printf(" Warning: speed change to %ld failed.\r\n",s);	} else {	    printf(" Speed changed to %ld.\r\n",s);	    speed = s;			/* Update global speed variable */	}    }}/*  Display all characters received from modem dialer through this routine,  for consistent handling of carriage returns and linefeeds.*/static VOID#ifdef CK_ANSICdialoc(char c)#elsedialoc(c) char c;#endif /* CK_ANSIC */{ /* dialoc */			/* Dial Output Character */    if (dialdpy) {	if (c != LF) conoc(c);		/* Don't echo LF */	if (c == CR) conoc(LF);		/* Echo CR as CRLF */    }}#ifndef MINIDIAL/*  tbati3() -- Routine to find out Telebit model when ATI reports "965"  or "971". This routine sends another query, ATI3, to get further info  to narrow down the model number.  Argument is ATI response as integer.  Result: sets tbmodel variable to Telebit model.*/static VOIDtbati3(n) int n; {    int status;    ttflui();				/* Flush input buffer */    ttslow("ATI3\015",100);		/* Send ATI3<CR> */    status = getok(5,0);		/* Get OK response, nonstrict */    if (status < 1) {			/* ERROR or timeout */	tbmodel = TB_UNK;	debug(F111,"tbati3 fails",rbuf,status);	return;    }    debug(F110,"tbati3 rbuf",rbuf,0);/* Got a good response, check the model info */    if (n == 965) {			/* "965" - various models. */	if (didweget(rbuf,"T1600")) {	    tbmodel = TB_1600;			/* T1600 */	} else if (didweget(rbuf,"T3000")) {	    tbmodel = TB_3000;			/* T3000 */	} else if (didweget(rbuf,"World")) {	    tbmodel = TB_WBLA;			/* WorldBlazer */	} else if (didweget(rbuf,"Version B") || /* TrailBlazer-Plus models */		   didweget(rbuf,"TBSA") ||		   didweget(rbuf,"TBRM") ||		   didweget(rbuf,"DC")) { 	/* Ven-Tel EC18K */	    tbmodel = TB_PLUS;	} else tbmodel = TB_UNK;		/* Others: Unknown */    } else if (n == 971) {		/* "971" could be T1500 or T1600. */	if (didweget(rbuf,"T1500"))	  tbmodel = TB_1500;	else tbmodel = TB_2500;    }					/* Other, don't change tbmodel. */}#endif /* MINIDIAL *//*  C K D I A L	 --  Dial up the remote system *//* Returns 1 if call completed, 0 otherwise */static int waitct, mdmwait, mdmstat = 0;intckdial(telnbr) char *telnbr; {    char c, c2;    char errmsg[50], *erp;		/* for error messages */    char fullnum[100];			/* for full (prefixed) phone number */    MDMINF *pmdminf;			/* pointer to modem-specific info */    int x, m, n = F_time;    char *s, *pc, *ws;    long conspd;    char *cptr;    mymdmtyp = mdmtyp;			/* Make local copy of modem type */#ifndef MINIDIAL    tbmodel = TB_UNK;			/* Initialize Telebit model */#endif /* MINIDIAL */    if (mymdmtyp < 1) {	if (network)	  printf("Please SET HOST first, and then SET MODEM\n");	else	  printf("Sorry, you must SET MODEM first\n");	return(0);    }    if (!local) {	printf("Sorry, you must SET LINE or SET HOST first\n");	return(0);    }    if (!network && speed < 0L) {	printf("Sorry, you must SET SPEED first\n");	return(0);    }    debug(F110,"dial number",telnbr,0);    debug(F110,"dial prefix",(dialnpr ? dialnpr : ""), 0);/* Add prefix to phone number */    if (dialnpr && *dialnpr) {	sprintf(fullnum,"%s%s",(dialnpr ? dialnpr : ""),telnbr);	telnbr = fullnum;    }    debug(F110,"prefixed number", telnbr, 0);#ifdef DYNAMIC    if (!(lbuf = malloc(LBUFL+1))) {    /* Allocate input line buffer */	printf("Sorry, DIAL memory buffer can't be allocated\n");	return(0);    }#endif /* DYNAMIC */    if (ttopen(ttname,&local,mymdmtyp,0) < 0) { /* Open, no carrier wait */

⌨️ 快捷键说明

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