ckudia.c
资源名称:cku197.tar.Z [点击查看]
上传用户:dufan58
上传日期:2007-01-05
资源大小:3407k
文件大小:217k
源码类别:
通讯/手机编程
开发平台:
Windows_Unix
- &SUPRAX /* 69 Diamond Supra Express V.90 */
- #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
- "3com-usr-megahertz-56k", n_USRX2, 0,
- "atlas-newcom-33600ifxC", n_ATLAS, 0,
- "att-1900-stu-iii", n_ATT1900, 0,
- "att-1910-stu-iii", n_ATT1910, 0,
- "att-7300", n_ATTUPC, 0,
- "att-dataport", n_DATAPORT, 0,
- "att-dtdm", n_ATTDTDM, 0,
- "att-isn", n_ATTISN, 0,
- "att-keepintouch", n_KEEPINTOUCH, 0,
- "att-switched-net", n_ATTMODEM, 0,
- "att7300", n_ATTUPC, CM_INV, /* old name */
- "attdtdm", n_ATTDTDM, CM_INV, /* old name */
- "attisn", n_ATTISN, CM_INV, /* old name */
- "attmodem", n_ATTMODEM, CM_INV, /* old name */
- "bestdata", n_BESTDATA, 0,
- "boca", n_BOCA, 0,
- #endif /* MINIDIAL */
- "ccitt-v25bis", n_CCITT, CM_INV, /* Name changed to ITU-T */
- #ifndef MINIDIAL
- "cardinal", n_CARDINAL, 0,
- #ifdef OLDMODEMS
- "cermetek", n_CERMETEK, M_OLD,
- #endif /* OLDMODEMS */
- "compaq", n_COMPAQ, 0,
- #ifdef OLDMODEMS
- "concord", n_CONCORD, M_OLD,
- #endif /* OLDMODEMS */
- "courier", n_USR, CM_INV,
- "dataport", n_DATAPORT, CM_INV, /* == att-dataport */
- #ifdef OLDMODEMS
- "df03-ac", n_DF03, M_OLD,
- "df100-series", n_DF100, M_OLD,
- "df200-series", n_DF200, M_OLD,
- #endif /* OLDMODEMS */
- "digitel-dt22", n_DIGITEL, 0,
- #endif /* MINIDIAL */
- "direct", 0, CM_INV, /* Synonym for NONE */
- #ifndef MINIDIAL
- "fujitsu", n_FUJITSU, 0,
- "gateway-telepath", n_TELEPATH, 0,
- #ifdef OLDMODEMS
- "gdc-212a/ed", n_GDC, M_OLD,
- "ge", n_GENERIC, CM_INV|CM_ABR,
- "gen", n_GENERIC, CM_INV|CM_ABR,
- "gendatacomm", n_GDC, CM_INV, /* Synonym for GDC */
- #endif /* OLDMODEMS */
- #endif /* MINIDIAL */
- "generic-high-speed", n_GENERIC, 0,
- "h", n_HAYES, CM_INV|CM_ABR,
- "ha", n_HAYES, CM_INV|CM_ABR,
- "hay", n_HAYES, CM_INV|CM_ABR,
- "haye", n_HAYES, CM_INV|CM_ABR,
- "hayes", n_HAYES, CM_INV|CM_ABR, /* Hayes 2400 */
- #ifndef MINIDIAL
- "hayes-1200", n_H_1200, 0,
- #endif /* MINIDIAL */
- "hayes-2400", n_HAYES, 0,
- #ifndef MINIDIAL
- "hayes-high-speed", n_H_ACCURA, 0,
- "hayes-accura", n_H_ACCURA, CM_INV,
- "hayes-optima", n_H_ACCURA, CM_INV,
- "hayes-ultra", n_H_ULTRA, CM_INV,
- "hst-courier", n_USR, CM_INV, /* Synonym for COURIER */
- "intel", n_INTEL, 0,
- #endif /* MINIDIAL */
- "itu-t-v250", n_ITUTV250, CM_INV,
- "itu-t-v25ter/v250",n_ITUTV250, 0,
- "itu-t-v25bis", n_CCITT, 0, /* New name for CCITT */
- #ifndef MINIDIAL
- "maxtech", n_MAXTECH, 0,
- "megahertz-att-v34", n_MHZATT, 0, /* Megahertzes */
- "megahertz-xjack", n_XJACK, CM_INV|CM_ABR,
- "megahertz-xjack-33.6", n_XJACK, 0,
- "megahertz-xjack-56k", n_USRX2, 0, /* 3COM/USR/Megahertz 33.6 PC Card */
- "mi", n_MICROCOM, CM_INV|CM_ABR,
- "mic", n_MICROCOM, CM_INV|CM_ABR,
- "micr", n_MICROCOM, CM_INV|CM_ABR,
- "micro", n_MICROCOM, CM_INV|CM_ABR,
- "microc", n_MICROCOM, CM_INV|CM_ABR,
- "microco", n_MICROCOM, CM_INV|CM_ABR,
- "microcom", n_MICROCOM, CM_INV|CM_ABR,
- "microcom-at-mode", n_UCOM_AT, 0, /* Microcom DeskPorte, etc */
- "microcom-sx-mode", n_MICROCOM, 0, /* Microcom AX,QX,SX, native mode */
- "microlink", n_MICROLINK, 0,
- "microlink-v250", n_ULINKV250, 0,
- "motorola-codex", n_CODEX, 0,
- "motorola-fastalk", n_MOTOROLA, 0,
- "motorola-lifestyle",n_MOTOROLA, 0,
- "motorola-montana", n_MONTANA, 0,
- "mt5634zpx", n_MT5634ZPX, 0,
- "multitech", n_MULTI, 0,
- "mwave", n_MWAVE, 0,
- #endif /* MINIDIAL */
- "none", 0, 0,
- #ifndef MINIDIAL
- #ifndef OLDTBCODE
- "old-telebit", n_TELEBIT, 0,
- #endif /* OLDTBCODE */
- #ifdef OLDMODEMS
- "penril", n_PENRIL, M_OLD,
- #endif /* OLDMODEMS */
- "ppi", n_PPI, 0,
- #ifdef OLDMODEMS
- "racalvadic", n_RACAL, M_OLD,
- #endif /* OLDMODEMS */
- "rockwell-v32", n_RWV32, 0,
- "rockwell-v32bis", n_RWV32B, 0,
- "rockwell-v34", n_RWV34, 0,
- "rockwell-v90", n_RWV90, 0,
- "rolm", n_ROLM, CM_INV|CM_ABR,
- "rolm-244pc", n_ROLMAT, 0,
- "rolm-600-series", n_ROLMAT, 0,
- "rolm-dcm", n_ROLM, 0,
- "spirit-ii", n_SPIRITII, 0,
- "sportster", n_USR, CM_INV,
- "sup", n_SUPRA, CM_INV|CM_ABR,
- "supr", n_SUPRA, CM_INV|CM_ABR,
- "supra", n_SUPRA, CM_INV|CM_ABR,
- "supra-express-v90",n_SUPRAX, 0,
- "suprafaxmodem", n_SUPRA, 0,
- "suprasonic", n_SUPRASON, 0,
- #ifdef CK_TAPI
- "tapi", n_TAPI, 0,
- #endif /* CK_TAPI */
- "te", n_TBNEW, CM_INV|CM_ABR,
- "tel", n_TBNEW, CM_INV|CM_ABR,
- "telebit", n_TBNEW, 0,
- "telepath", n_TELEPATH, CM_INV,
- #endif /* MINIDIAL */
- "unknown", n_UNKNOWN, 0,
- "user-defined", n_UDEF, 0,
- #ifndef MINIDIAL
- "usr", n_USR, CM_INV|CM_ABR,
- "usr-212a", n_HAYES, CM_INV,
- "usr-courier", n_USR, CM_INV,
- "usr-megahertz-56k", n_USRX2, 0,
- "usr-sportster", n_USR, CM_INV,
- "usr-xj1560-x2", n_USRX2, CM_INV,
- "usrobotics", n_USR, 0,
- "v25bis", n_CCITT, CM_INV, /* Name changed to ITU-T */
- #ifdef OLDMODEMS
- "ventel", n_VENTEL, M_OLD,
- #endif /* OLDMODEMS */
- "zoltrix", n_ZOLTRIX, 0,
- "zoom", n_ZOOM, 0,
- "zyxel", n_ZYXEL, 0,
- #endif /* MINIDIAL */
- "", 0, 0
- };
- int nmdm = (sizeof(mdmtab) / sizeof(struct keytab)) - 1; /* Number of modems */
- #define CONNECTED 1 /* For completion status */
- #define D_FAILED 2
- #define D_PARTIAL 3
- static int tries = 0;
- static int mdmecho = 0; /* Assume modem does not echo */
- static char *p; /* For command strings & messages */
- #define LBUFL 200
- static char lbuf[LBUFL+4];
- #ifdef DYNAMIC
- #define RBUFL 256
- static char *rbuf = NULL;
- #else
- #define RBUFL 63
- static char rbuf[RBUFL+1];
- #endif /* DYNAMIC */
- #ifdef DYNAMIC
- #define FULLNUML 256
- char *fbuf = NULL; /* For full (prefixed) phone number */
- #else
- #define FULLNUML 100
- char fbuf[FULLNUML];
- #endif /* DYNAMIC */
- static ckjmpbuf sjbuf;
- #ifdef CK_ANSIC
- static SIGTYP (*savalrm)(int); /* For saving alarm handler */
- static SIGTYP (*savint)(int); /* For saving interrupt handler */
- #else
- static SIGTYP (*savalrm)(); /* For saving alarm handler */
- static SIGTYP (*savint)(); /* For saving interrupt handler */
- #endif /* CK_ANSIC */
- #ifdef CKLOGDIAL
- static VOID
- dologdial(s) char *s; {
- char buf2[16];
- char * r = NULL;
- int x, m, n;
- extern char cxlogbuf[], uidbuf[], myhost[];
- if (!s) s = "";
- if ((x = strlen(s)) > 0) { /* Replace spaces by underscores */
- r = (char *)malloc(x+1);
- if (r) {
- int i;
- for (i = 0; i <= x; i++) {
- if (s[i] != 0 && s[i] <= SP)
- r[i] = '_';
- else
- r[i] = s[i];
- }
- s = r;
- }
- }
- p = ckdate();
- n = ckstrncpy(cxlogbuf,p,CXLOGBUFL);
- m = strlen(uidbuf)+strlen(myhost)+strlen(ttname)+strlen(s)+strlen(buf2)+32;
- if (n+m < CXLOGBUFL-1) {
- p = cxlogbuf+n;
- if (diallcc && diallac)
- sprintf(buf2,"+%s(%s)",diallcc,diallac);
- else
- strcpy(buf2,"Unknown");
- sprintf(p," %s %s T=DIAL H=%s D=%s N=%s O=%s ",
- uidbuf,
- ckgetpid(),
- myhost,
- ttname,
- s,
- buf2
- );
- debug(F110,"dologdial cxlogbuf",cxlogbuf,0);
- } else
- sprintf(p,"LOGDIAL BUFFER OVERFLOW");
- if (r) free(r);
- }
- #endif /* CKLOGDIAL */
- #ifndef MINIDIAL
- #ifdef COMMENT
- static VOID
- xcpy(to,from,len) /* Copy the given number of bytes */
- register char *to, *from;
- register unsigned int len; {
- while (len--) *to++ = *from++;
- }
- #endif /* COMMENT */
- #endif /* MINIDIAL */
- static SIGTYP
- #ifdef CK_ANSIC
- dialtime(int foo) /* Timer interrupt handler */
- #else
- dialtime(foo) int foo; /* Timer interrupt handler */
- #endif /* CK_ANSIC */
- /* dialtime */ {
- fail_code = F_TIME; /* Failure reason = timeout */
- debug(F100,"dialtime caught SIGALRM","",0);
- #ifdef BEBOX
- #ifdef BE_DR_7
- alarm_expired();
- #endif /* BE_DR_7 */
- #endif /* BEBOX */
- #ifdef OS2
- signal(SIGALRM, dialtime);
- #endif /* OS2 */
- #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 */
- #ifdef NTSIG
- if (foo == SIGALRM)
- PostAlarmSigSem();
- else
- PostCtrlCSem();
- #else /* NTSIG */
- #ifdef NT
- cklongjmp(ckjaddr(sjbuf),1);
- #else /* NT */
- cklongjmp(sjbuf,1);
- #endif /* NT */
- #endif /* NTSIG */
- /* NOTREACHED */
- SIGRETURN;
- }
- static SIGTYP
- #ifdef CK_ANSIC
- dialint(int foo) /* Keyboard interrupt handler */
- #else
- dialint(foo) int foo; /* Keyboard interrupt handler */
- #endif /* CK_ANSIC */
- /* dialint */ {
- fail_code = F_INT;
- debug(F100,"dialint caught SIGINT","",0);
- #ifdef OS2
- signal(SIGINT, dialint);
- debug(F100,"dialint() SIGINT caught -- dialint restored","",0) ;
- #endif /* OS2 */
- #ifdef __EMX__
- signal(SIGINT, SIG_ACK); /* Needed for OS/2 */
- #endif /* __EMX__ */
- #ifdef OSK /* OS-9, see comment in dialtime() */
- sigmask(-1);
- #endif /* OSK */
- #ifdef NTSIG
- PostCtrlCSem() ;
- #ifdef CK_TAPI
- PostTAPIConnectSem();
- PostTAPIAnswerSem();
- #endif /* CK_TAPI */
- #else /* NTSIG */
- #ifdef NT
- cklongjmp(ckjaddr(sjbuf),1);
- #else /* NT */
- cklongjmp(sjbuf,1);
- #endif /* NT */
- #endif /* NT */
- SIGRETURN;
- }
- /*
- 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 int
- ddinc(n) int n; {
- #ifdef TNCODE
- int c = 0;
- int done = 0;
- debug(F101,"ddinc entry n","",n);
- while (!done) {
- c = ttinc(n);
- debug(F000,"ddinc","",c);
- if (c < 0) return(c);
- #ifndef OS2
- 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;
- #else /* OS2 */
- done = !(c == IAC && network && ttnproto == NP_TELNET);
- scriptwrtbuf(c); /* TELNET negotiations handled by emulator */
- #endif /* OS2 */
- }
- return(c & 0xff);
- #else /* TNCODE */
- debug(F101,"ddinc entry n","",n);
- return(ttinc(n));
- #endif /* TNCODE */
- }
- static VOID
- ttslow(s,millisec) char *s; int millisec; { /* Output s-l-o-w-l-y */
- #ifdef TCPSOCKET
- extern int tn_nlm, tn_b_nlm;
- #endif /* TCPSOCKET */
- debug(F111,"ttslow",s,millisec);
- if (dialdpy && (duplex || !mdmecho)) { /* Echo the command in case modem */
- printf("%sn",s); /* isn't echoing commands. */
- #ifdef OS2
- {
- char *s2 = s; /* Echo to emulator */
- while (*s2) {
- scriptwrtbuf((USHORT)*s2++);
- }
- scriptwrtbuf((USHORT)CR);
- scriptwrtbuf((USHORT)LF);
- }
- #endif /* OS2 */
- }
- for (; *s; s++) {
- ttoc(*s);
- #ifdef TCPSOCKET
- if (*s == CR && network && ttnproto == NP_TELNET) {
- if (!TELOPT_ME(TELOPT_BINARY) && tn_nlm != TNL_CR)
- ttoc((char)((tn_nlm == TNL_CRLF) ? LF : NUL));
- else if (TELOPT_ME(TELOPT_BINARY) &&
- (tn_b_nlm == TNL_CRLF || tn_b_nlm == TNL_CRNUL))
- ttoc((char)((tn_b_nlm == TNL_CRLF) ? LF : NUL));
- }
- #endif /* TCPSOCKET */
- if (millisec > 0)
- 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 VOID
- waitfor(s) char *s; {
- CHAR c, x;
- while ( c = *s++ ) { /* while more characters remain... */
- do { /* wait for the character */
- x = (CHAR) (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 int
- didweget(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 VOID
- dreset() {
- debug(F100,"dreset resetting alarm and signal handlers","",0);
- alarm(0);
- signal(SIGALRM,savalrm); /* restore alarm handler */
- signal(SIGINT,savint); /* restore interrupt handler */
- debug(F100,"dreset alarm and signal handlers reset","",0);
- }
- /*
- 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_ANSIC
- spdchg(long s)
- #else
- spdchg(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.rn",s);
- } else {
- printf(" Speed changed to %ld.rn",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_ANSIC
- dialoc(char c)
- #else
- dialoc(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 */
- }
- }
- char *
- getdm(x) int x; { /* Return dial modifier */
- MDMINF * mp;
- int m;
- int ishayes = 0;
- m = mdmtyp;
- if (m < 1)
- if (mdmsav > -1)
- m = mdmsav;
- if (m < 1)
- return("");
- #ifndef MINIDIAL
- if (m == n_TAPI)
- m = n_HAYES;
- #endif /* MINIDIAL */
- mp = modemp[m];
- ishayes = mp->capas & CKD_AT;
- switch (x) {
- case VN_DM_LP:
- return(ishayes ? "," : "");
- case VN_DM_SP:
- #ifdef MINIDIAL
- return("");
- #else
- return(m == n_USR ? "/" : "");
- #endif /* MINIDIAL */
- case VN_DM_PD:
- return(ishayes ? "P" : "");
- case VN_DM_TD:
- return(ishayes ? "T" : "");
- case VN_DM_WA:
- return(ishayes ? "@" : "");
- case VN_DM_WD:
- return(ishayes ? "W" : "");
- case VN_DM_RC:
- return(ishayes ? ";" : "");
- }
- return("");
- }
- static VOID
- getdialmth() {
- if (dialmauto && diallcc) { /* If DIAL METHOD AUTO... */
- int i; /* and we know our area code... */
- for (i = 0; i < ndialtocc; i++) { /* First check Tone countries list */
- if (!strcmp(dialtocc[i],diallcc)) {
- dialmth = XYDM_T;
- break;
- }
- }
- for (i = 0; i < ndialpucc; i++) { /* Then Pulse countries list */
- if (!strcmp(dialpucc[i],diallcc)) {
- dialmth = XYDM_P;
- break;
- }
- }
- }
- }
- VOID /* Get dialing defaults from environment */
- getdialenv() {
- char *p = NULL;
- int i, x;
- makestr(&p,getenv("K_DIAL_DIRECTORY"));
- if (p) {
- int i;
- xwords(p,(MAXDDIR - 2),dialdir,0);
- for (i = 0; i < (MAXDDIR - 1); i++) {
- if (!dialdir[i+1])
- break;
- else
- dialdir[i] = dialdir[i+1];
- }
- ndialdir = i;
- }
- xmakestr(&diallcc,getenv("K_COUNTRYCODE")); /* My country code */
- xmakestr(&dialixp,getenv("K_LD_PREFIX")); /* My long-distance prefix */
- xmakestr(&dialldp,getenv("K_INTL_PREFIX")); /* My international prefix */
- xmakestr(&dialldp,getenv("K_TF_PREFIX")); /* Ny Toll-free prefix */
- #ifndef NOICP
- p = getenv("K_DIAL_METHOD"); /* Local dial method */
- if (p) if (*p) {
- extern struct keytab dial_m[];
- extern int ndial_m;
- i = lookup(dial_m,p,ndial_m,&x);
- if (i > -1) {
- if (i == XYDM_A) {
- dialmauto = 1;
- dialmth = XYDM_D;
- } else {
- dialmauto = 0;
- dialmth = i;
- }
- }
- }
- #endif /* NOICP */
- p = NULL;
- xmakestr(&p,getenv("K_TF_AREACODE")); /* Toll-free areacodes */
- if (p) {
- int i;
- xwords(p,7,dialtfc,0);
- for (i = 0; i < 8; i++) {
- if (!dialtfc[i+1])
- break;
- else
- dialtfc[i] = dialtfc[i+1];
- }
- ntollfree = i;
- free(p);
- }
- for (i = 0; i < MAXTPCC; i++) { /* Clear Tone/Pulse country lists */
- dialtocc[i] = NULL;
- dialpucc[i] = NULL;
- }
- for (i = 0; i < MAXTPCC; i++) { /* Init Tone country list */
- if (tonecc[i])
- makestr(&(dialtocc[i]),tonecc[i]);
- else
- break;
- }
- ndialtocc = i;
- for (i = 0; i < MAXTPCC; i++) { /* Init Pulse country list */
- if (pulsecc[i])
- makestr(&(dialpucc[i]),pulsecc[i]);
- else
- break;
- }
- ndialpucc = i;
- if (diallcc) { /* Have country code */
- if (!strcmp(diallcc,"1")) { /* If it's 1 */
- if (!dialldp) /* Set these prefixes... */
- makestr(&dialldp,"1");
- if (!dialtfp)
- makestr(&dialtfp,"1");
- if (!dialixp)
- makestr(&dialixp,"011");
- if (ntollfree == 0) { /* Toll-free area codes */
- if (dialtfc[0] = malloc(4)) {
- strcpy(dialtfc[0],"800"); /* 1970-something */
- ntollfree++;
- if (dialtfc[1] = malloc(4)) {
- strcpy(dialtfc[1],"888"); /* 1996 */
- ntollfree++;
- if (dialtfc[2] = malloc(4)) {
- strcpy(dialtfc[2],"877"); /* 5 April 1998 */
- ntollfree++;
- if (dialtfc[3] = malloc(4)) {
- strcpy(dialtfc[3],"866"); /* Soon */
- ntollfree++;
- }
- }
- }
- }
- }
- } else if (!strcmp(diallcc,"358") &&
- ((int) strcmp(zzndate(),"19961011") > 0)
- ) { /* Finland */
- if (!dialldp) /* Long-distance prefix */
- makestr(&dialldp,"9");
- if (!dialixp) /* International dialing prefix */
- makestr(&dialixp,"990");
- } else { /* Not NANP or Finland */
- if (!dialldp)
- makestr(&dialldp,"0");
- if (!dialixp)
- makestr(&dialixp,"00");
- }
- }
- xmakestr(&diallac,getenv("K_AREACODE"));
- xmakestr(&dialpxo,getenv("K_PBX_OCP"));
- xmakestr(&dialpxi,getenv("K_PBX_ICP"));
- p = getenv("K_PBX_XCH");
- #ifdef COMMENT
- xmakestr(&dialpxx,p);
- #else
- if (p) if (*p) {
- int x;
- char * s = NULL;
- char * pp[MAXPBXEXCH+1];
- makestr(&s,p); /* Make a copy for poking */
- if (s) {
- xwords(s,MAXPBXEXCH+1,pp,0); /* Note: pp[] is 1-based. */
- for (i = 0; i <= MAXPBXEXCH; i++) {
- if (!pp[i+1]) break;
- makestr(&(dialpxx[i]),pp[i+1]);
- ndialpxx++;
- }
- makestr(&s,NULL); /* Free poked copy */
- }
- }
- #endif /* COMMENT */
- }
- static int
- dialfail(x) int x; {
- char * s;
- fail_code = x;
- debug(F101,"ckudial dialfail","",x);
- dreset(); /* Reset alarm and signal handlers */
- printf("%s Failure: ", func_code == 0 ? "DIAL" : "ANSWER");
- if (dialdpy) { /* If showing progress */
- debug(F100,"dial display is on","",0);
- p = ck_time(); /* get current time; */
- if (*p) printf("%s: ",p);
- }
- switch (fail_code) { /* Type of failure */
- case F_TIME: /* Timeout */
- if (dial_what == DW_INIT)
- printf ("Timed out while trying to initialize modem.n");
- else if (dial_what == DW_DIAL)
- printf ("%s interval expired.n",
- func_code == 0 ? "DIAL TIMEOUT" : "ANSWER timeout");
- else
- printf("Timeout.n");
- fflush(stdout);
- if (mp->capas & CKD_AT)
- ttoc(' 15'); /* Send CR to interrupt dialing */
- /* Some Hayes modems don't fail with BUSY on busy lines */
- dialsta = DIA_TIMO;
- debug(F110,"dial","timeout",0);
- break;
- case F_INT: /* Dialing interrupted */
- printf ("Interrupted.n");
- fflush(stdout);
- debug(F110,"dial","interrupted",0);
- if (mp->capas & CKD_AT)
- ttoc(' 15'); /* Send CR to interrupt dialing */
- dialsta = DIA_INTR;
- break;
- case F_MODEM: /* Modem detected a failure */
- debug(F111,"dialfail()","lbuf",lbuf);
- if (lbuf && *lbuf) {
- printf(" "");
- for (s = lbuf; *s; s++)
- if (isprint(*s))
- putchar(*s); /* Display printable reason */
- printf (""");
- } else printf(func_code == 0 ?
- " Call not completed." :
- " Call did not come in."
- );
- printf("n");
- debug(F110,"dial",lbuf,0);
- if (dialsta < 0) dialsta = DIA_UNSP;
- break;
- case F_MINIT: /* Failure to initialize modem */
- printf ("Error initializing modem.n");
- debug(F110,"dial","modem init",0);
- dialsta = DIA_NOIN;
- break;
- default:
- printf("unknownn");
- debug(F110,"dial","unknown",0);
- fflush(stdout);
- if (mp->capas & CKD_AT)
- ttoc(' 15'); /* Send CR to interrupt dialing */
- dialsta = DIA_INTR;
- }
- #ifdef DYNAMIC
- if (rbuf) free(rbuf); rbuf = NULL;
- if (fbuf) free(fbuf); fbuf = NULL;
- #endif /* DYNAMIC */
- if (dialsta < 0) dialsta = DIA_UERR; /* Set failure code */
- return(0); /* Return zero (important) */
- }
- /* C K D I A L -- Dial up the remote system */
- /* Returns 1 if call completed, 0 otherwise */
- static int mdmwait, mdmstat = 0;
- #ifndef CK_TAPI
- static
- #endif /* CK_TAPI */
- int waitct;
- int mdmwaitd = 10 ; /* dialtmo / mdmwait difference */
- static char c;
- static char *telnbr;
- static int wr = 0; /* wr = wake rate */
- static char * ws; /* ws = wake string */
- static char * xnum = NULL;
- static int inited = 0;
- static SIGTYP
- #ifdef CK_ANSIC
- _dodial(void * threadinfo)
- #else /* CK_ANSIC */
- _dodial(threadinfo) VOID * threadinfo;
- #endif /* CK_ANSIC */
- /* _dodial */ {
- char c2;
- char *dcmd, *s, *flocmd = NULL;
- int x = 0, n = F_TIME;
- #ifdef NTSIG
- signal( SIGINT, dialint );
- if (threadinfo) { /* Thread local storage... */
- TlsSetValue(TlsIndex,threadinfo);
- }
- #endif /* NTSIG */
- dcmd = dialcmd ? dialcmd : mp->dial_str;
- if ((int)strlen(dcmd) + (int)strlen(telnbr) > (LBUFL - 2)) {
- printf("DIAL command + phone number too long!n");
- dreset();
- #ifdef DYNAMIC
- if (rbuf) free(rbuf); rbuf = NULL;
- if (fbuf) free(fbuf); fbuf = NULL;
- #endif /* DYNAMIC */
- #ifdef NTSIG
- ckThreadEnd(threadinfo);
- #endif /* NTSIG */
- SIGRETURN; /* No conversation with modem to complete dialing */
- }
- makestr(&xnum,telnbr);
- getdialmth(); /* Get dial method */
- #ifdef CK_ATDT
- /* Combine the SET DIAL METHOD command with the DIAL command string */
- if (!dialcmd && /* Using default DIAL command */
- (mdmcapas & CKD_AT) && /* AT command set only */
- ((dialmth == XYDM_T && !dialtone) || /* and using default */
- (dialmth == XYDM_P && !dialpulse))) { /* modem commands... */
- char c;
- debug(F110,"dial atdt xnum 1",xnum,0);
- s = dcmd;
- debug(F110,"dial atdt s",s,0);
- if (*telnbr != 'T' &&
- *telnbr != 'P' &&
- *telnbr != 't' &&
- *telnbr != 'p' &&
- !ckstrcmp(s,"atd",3,0) &&
- s[3] != 'T' &&
- s[3] != 'P' &&
- s[3] != 't' &&
- s[3] != 'p') {
- char xbuf[200];
- c = (dialmth == XYDM_T) ? 'T' : 'P';
- if (islower(s[0]))
- c = tolower(c);
- if ((int)strlen(telnbr) < 199) {
- sprintf(xbuf,"%c%s",c,telnbr);
- makestr(&xnum,xbuf);
- }
- }
- }
- #endif /* CK_ATDT */
- debug(F111,"ckdial",xnum,xredial);
- /* Hang up the modem (in case it wasn't "on hook") */
- /* But only if SET DIAL HANGUP ON... */
- if (!xredial) { /* Modem not initalized yet. */
- inited = 0;
- }
- if (!xredial || !inited) {
- if (dialhup() < 0) { /* Hangup first */
- debug(F100,"ckdial dialhup failed","",0);
- #ifndef MINIDIAL
- if (mdmcapas & CKD_TB) /* Telebits might need a BREAK */
- ttsndb(); /* first. */
- #endif /* MINIDIAL */
- if (dialhng && dialsta != DIA_PART) { /* If hangup 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);
- dialsta = DIA_HANG;
- #ifdef DYNAMIC
- if (rbuf) free(rbuf); rbuf = NULL;
- if (fbuf) free(fbuf); fbuf = NULL;
- #endif /* DYNAMIC */
- dreset();
- #ifdef NTSIG
- ckThreadEnd(threadinfo);
- #endif /* NTSIG */
- SIGRETURN;
- }
- }
- }
- inited = 0; /* We hung up so must reinit */
- }
- #ifndef MINIDIAL
- /* Don't start talking to Rolm too soon */
- if (mymdmtyp == n_ROLM && dialsta != DIA_PART)
- msleep(500);
- #endif /* MINIDIAL */
- if (dialsta != DIA_PART /* Some initial setups. */
- #ifndef MINIDIAL
- && mymdmtyp != n_ATTUPC
- #endif /* MINIDIAL */
- ) {
- fail_code = F_MINIT; /* Default failure code */
- dial_what = DW_INIT; /* What I'm Doing Now */
- if (dialdpy) { /* If showing progress, */
- p = ck_time(); /* get timestamp. */
- if (!inited)
- if (*p)
- printf(" Initializing: %s...n",p);
- }
- }
- #ifndef MINIDIAL
- #ifdef ATT7300
- if (mymdmtyp == n_ATTUPC) {
- /*
- For ATT7300/Unix PC's with their special internal modem. Whole dialing
- process is handled right here, an exception to the normal structure.
- Timeout and user interrupts are enabled during dialing. attdial() is in
- file ckutio.c. - jrd
- */
- _PROTOTYP( int attdial, (char *, long, char *) );
- fail_code = F_MODEM; /* Default failure code */
- dial_what = DW_DIAL;
- if (dialdpy) { /* If showing progress */
- p = ck_time(); /* get current time; */
- if (*p)
- printf(" Dialing: %s...n",p);
- }
- alarm(waitct); /* Set alarm */
- if (attdial(ttname,speed,telnbr)) { /* dial internal modem */
- dreset(); /* reset alarms, etc. */
- printf(" Call failed.rn");
- dialhup(); /* Hangup the call */
- #ifdef DYNAMIC
- if (rbuf) free(rbuf); rbuf = NULL;
- if (fbuf) free(fbuf); fbuf = NULL;
- #endif /* DYNAMIC */
- dialsta = DIA_UERR;
- #ifdef NTSIG
- ckThreadEnd(threadinfo);
- #endif /* NTSIG */
- SIGRETURN; /* return failure */
- }
- dreset(); /* reset alarms, etc. */
- ttpkt(speed,FLO_DIAX,parity); /* cancel dialing ioctl */
- if (!quiet && !backgrd) {
- if (dialdpy) {
- printf("n");
- printf(" Call complete.rn");
- } else if (modemmsg[0])
- printf(" Call complete: "%s".rn",(char *)modemmsg);
- else
- printf(" Call complete.rn");
- }
- #ifdef CKLOGDIAL
- dologdial(telnbr);
- #endif /* CKLOGDIAL */
- dialsta = DIA_OK;
- #ifdef DYNAMIC
- if (rbuf) free(rbuf); rbuf = NULL;
- if (fbuf) free(fbuf); fbuf = NULL;
- #endif /* DYNAMIC */
- #ifdef NTSIG
- ckThreadEnd(threadinfo);
- #endif /* NTSIG */
- SIGRETURN; /* No conversation with modem to complete dialing */
- } else
- #endif /* ATT7300 */
- #ifdef CK_TAPI
- if (tttapi && !tapipass) { /* TAPI Dialing */
- switch (func_code) {
- case 0: /* Dial */
- if (cktapidial(telnbr)) {
- fail_code = 0;
- if (partial) {
- dialsta = DIA_PART;
- } else {
- dialsta = DIA_OK;
- speed = ttgspd();
- }
- } else {
- if (dialsta == DIA_PART)
- cktapihangup();
- if (!fail_code)
- fail_code = F_MODEM;
- dialsta = DIA_TAPI;
- }
- break;
- case 1: { /* Answer */
- long strttime = time((long *)NULL);
- long diff = 0;
- do {
- if (dialatmo) {
- strttime += diff;
- waitct -= diff;
- }
- fail_code = 0;
- if (cktapianswer()) { /* SUCCESS */
- dialsta = DIA_OK;
- speed = ttgspd();
- break;
- } else { /* FAILURE */
- if (fail_code) {
- dialsta = DIA_TAPI;
- break;
- } else {
- fail_code = F_MODEM;
- dialsta = DIA_TAPI;
- }
- }
- if (dialatmo) {
- diff = time((long *)NULL) - strttime;
- }
- } while (dialatmo ? (diff < waitct) : 1);
- break;
- }
- }
- #ifdef NTSIG
- ckThreadEnd(threadinfo);
- #endif /* NTSIG */
- SIGRETURN;
- } else
- #endif /* CK_TAPI */
- #endif /* MINIDIAL */
- /* Modems with AT command set... */
- if ((mdmcapas & CKD_AT) && dialsta != DIA_PART) {
- if (dialpace > -1) /* Set intercharacter pacing */
- wr = dialpace;
- else
- wr = mp->wake_rate;
- if (dialini) /* Get wakeup/init string */
- ws = dialini;
- else
- ws = mp->wake_str;
- if (!ws) ws = "