?? diald.c
字號:
#include "net.h"
#include "local.h"
#include "support.h"
#include "driver.h"
#include "ppp.h"
#include "script.h"
extern unsigned int clocks_per_sec;
/* This is used to save network specific information. */
static struct SAVINS {
void (*comec)(int, struct NET *);
int (*goingc)(struct NET *);
#if NTRACE >= 3
char *name;
#endif
MESS *mp;
int logid;
unsigned char *logp;
} _sv[NNETS];
static void format(struct NET *netp, MESS *mess);
static int getDialInt(unsigned char **sp);
static void expect(struct NET *netp, MESS *mess);
static int isSubString(char *a, char *b);
static int isIgnore(char c);
/*
** * * * * * *
** modemout() Return the next modem character to transmit
**
** static int modemout(struct NET *netp);
**
** PARAMETERS:
** (in/out) struct NET *netp link-layer structure pointer
**
** RETURNS:
** a character The next character to send
** -1 No more characters to send
**
** DESCRIPTION:
** This function will provide the driver with the characters it needs
** to send out at a transmit interrupt.
*/
static int modemout(struct NET *netp)
{
MESS *mess;
int i1 = -1;
(void)mess;
if (netp->hw.chsout == 2) { /* If transmitting now */
transmit:
i1 = *netp->hw.bufout++; /* Grab next character */
if (i1 == 0) {
netp->hw.chsout = 0; /* No more data to send */
netp->hw.st = ussDialStateNextE; /* Ready for next command */
netp->hw.idle_time = 0; /* Stop waiting */
/* Start expect immediately after SEND if possible */
if (*++netp->hw.sp == ussDialXcmdExpectE) {
netp->hw.sp++;
expect(netp, _sv[netp->netno].mp);
}
return -1;
}
}
else if (netp->hw.chsout == 1) { /* If just starting */
netp->hw.chsout = 2; /* Start transmitting */
QUEUE_OUT(netp, depart, mess); /* Grab fake TX buffer */
goto transmit; /* Send character */
}
return i1;
}
/*
** * * * * * *
** modemin() Place an arrived character in the in-buffer.
**
** static void modemin(int cc, struct NET *netp);
**
** PARAMETERS:
** (in) int cc character that arrived
** (in/out) struct NET *netp link-layer structure pointer
**
** DESCRIPTION:
** If this layer is expecting data (in the RECV state), paste characters
** to the in-buffer and force a comparison with the expected data.
*/
static void modemin(int cc, struct NET *netp)
{
int i1, i2;
/* If we're in receive mode, append data and force check */
if ((netp->hw.st & ussDialStateRecvE) == ussDialStateRecvE) {
*netp->hw.bufin++ = (char)cc; /* Grab next character */
*netp->hw.bufin = 0; /* Terminate string */
netp->hw.st = ussDialStateRecvE|ussDialStateBChckE;
/* If we are currently logging incoming data, try to log it */
if ((i1 = _sv[netp->netno].logid) >= 0) {
i2 = _sv[netp->netno].logp - ussDialLogTable[i1];
i2 -= ussDialLogLenTable[i1];
/* If there's room left in the array, add a log character */
if (i2 < 0) {
*_sv[netp->netno].logp++ = (char)cc;
*_sv[netp->netno].logp = 0;
}
else {
/* Stop logging */
_sv[netp->netno].logp = 0;
_sv[netp->netno].logid = -1;
}
}
}
return;
}
/*
** * * * * * *
** dialUp() Set up for non-network terminal mode.
**
** static void dialUp(int netno);
**
** PARAMETERS:
** (in) int netno a yfnet network number
**
** DESCRIPTION:
** This function will install new high-level I/O interrupt handlers
** to enable terminal mode for interactions with a modem.
*/
static void dialUp(int netno)
{
struct NET *netp;
netp = &nets[netno];
_sv[netno].comec = netp->hw.comec;
_sv[netno].goingc = netp->hw.goingc;
#if NTRACE >= 3
_sv[netno].name = 0;
#endif
_sv[netno].mp->id = bWACK; /* Don't De-allocate */
_sv[netno].mp->netno = netno; /* Network for driver */
_sv[netno].logid = -1; /* No logging yet */
_sv[netno].logp = 0; /* No log pointer */
netp->hw.idle_time = 0; /* No wait time */
DISABLE();
netp->hw.comec = modemin;
netp->hw.goingc = modemout;
ENABLE();
}
/*
** * * * * * *
** dialDown() Set up link layer network I/O mode (end terminal mode)
**
** static void dialDown(int netno);
**
** PARAMETERS:
** (in) int netno a yfnet network number
**
** DESCRIPTION:
** This function will reinstall the old high-level I/O interrupt handlers
** to enable PPP.
*/
static void dialDown(int netno)
{
struct NET *netp;
MESS *mess;
char *cp;
int i1;
(void)mess;
netp = &nets[netno];
/* Remove buffer from depart queue if not done so yet */
if ((netp->hw.st == (ussDialStateSendE|ussDialStateBWaitE)) && !QUEUE_EMPTY(netp, depart)) {
QUEUE_OUT(netp, depart, mess);
}
_sv[netno].mp->id = bALLOC; /* Ready buffer for de-allocation */
Nrelbuf(_sv[netno].mp); /* De-allocate buffer */
_sv[netno].mp = 0;
netp->hw.chsout = 0;
netp->hw.opt1 = 0;
netp->hw.bufin = 0;
DISABLE();
netp->hw.comec = _sv[netno].comec;
netp->hw.goingc = _sv[netno].goingc;
ENABLE();
}
/*
** * * * * * *
** ussScriptTimeout() Perform non-blocked script operations
**
** int ussScriptTimeout(int netno);
**
** PARAMETERS:
** (in) int netno a yfnet network number
**
** RETURNS:
** -1 Finished with failure
** 0 Still working
** 1 Finished with success
**
** DESCRIPTION:
** This function will drive a script's execution without blocking.
*/
int ussScriptTimeout(int netno)
{
register struct NET *netp;
int i1, i2;
char c1, *cp, *cp2;
unsigned long ul1;
netp = &nets[netno];
/* If the wait (but not the check) bit is set, check the time. */
if ((netp->hw.st & (ussDialStateBWaitE|ussDialStateBChckE)) == ussDialStateBWaitE) {
if (TimeMS() < netp->hw.idle_time)
return 0;
netp->hw.st &= ~ussDialStateBWaitE;
}
switch (netp->hw.st) {
default: /* Unknown state */
case ussDialStateNoneE: /* Script not ready */
goto term;
case ussDialStateNextE: /* Ready for next command */
next_command:
switch (*netp->hw.sp++ & 0xff) {
case ussDialXcmdInitE: /* type */
netp->hw.opt1 = 1; /* Status flag is good */
break;
case ussDialXcmdSendE: /* type {string|int|var} 0x00 */
if (netp->hw.opt1) {
netp->hw.st = ussDialStateSendE|ussDialStateBWaitE;
netp->hw.idle_time = 3000 + TimeMS(); /* Wait time */
format(netp, _sv[netno].mp);
netp->hw.chsout = 1;
if (netp->protoc[1]->writE(netno, _sv[netno].mp) != -1)
{
break; /* break if success */
}
netp->hw.chsout = 0;
netp->hw.opt1 = 0;
netp->hw.st = ussDialStateNextE;
}
until_0:
/* Find the end of send/expect */
while ((c1 = *netp->hw.sp++) != 0)
if (c1 == USS_DIAL_RCMD_VAR || c1 == USS_DIAL_RCMD_INT)
netp->hw.sp++;
break;
case ussDialXcmdExpectE:/* type string|var 0x00 */
if (netp->hw.opt1)
expect(netp, _sv[netno].mp);
else {
netp->hw.sp += 2;
goto until_0;
}
break;
case ussDialXcmdPauseE: /* type 1-octet-value */
netp->hw.st = ussDialStatePausE|ussDialStateBWaitE;
ul1 = getDialInt(&netp->hw.sp);
/* Convert Seconds -> milliseconds */
netp->hw.idle_time = 1000 * ul1 + TimeMS();
break;
case ussDialXcmdTagE: /* type tag-name */
netp->hw.sp++;
break;
case ussDialXcmdCheckE: /* type tag-name1 tag-name2 */
/* If status is bad, goto tag-name2 */
if (!netp->hw.opt1) {
bad_goto:
netp->hw.sp++;
}
case ussDialXcmdGotoE: /* type tag-name */
good_goto:
/* Tag value */
c1 = *netp->hw.sp & 0xff;
for (cp=(char *)netp->hw.script; *cp!=(char)USS_DIAL_SFLAG; cp++) {
if (*cp == ussDialXcmdTagE)
if (cp[1] == c1)
break;
}
if (*cp == (char)USS_DIAL_SFLAG)
goto term;
netp->hw.sp = (unsigned char *)cp;
break;
case ussDialXcmdIntE: /* type index initial-value(two bytes) */
i1 = *netp->hw.sp++;
i2 = ((int)*netp->hw.sp++ << 8) & 0xff00;
i2 += *netp->hw.sp++ & 0xff;
ussDialIntTable[i1] = i2;
break;
case ussDialXcmdKillE: /* type */
term:
#if NTRACE >= 3
Nprintf("DIALD: Terminating script (bad) %s\n",
_sv[netp->netno].name);
#endif
netp->hw.st = ussDialStateNoneE;
dialDown(netno);
return -1;
case ussDialXcmdDbgsE: /* type trace-level {string|int|var} 0x00 */
netp->hw.sp++; /* Skip NTRACE level for now */
while (*netp->hw.sp) {
#if PPP_DEBUG && NTRACE
if (*netp->hw.sp == USS_DIAL_RCMD_VAR)
Nprintf("%s", *ussDialVarTable[*++netp->hw.sp]);
else if (*netp->hw.sp == USS_DIAL_RCMD_INT)
Nprintf("%d", ussDialIntTable[*++netp->hw.sp]);
else
Nputchr(*netp->hw.sp);
#else
if (*netp->hw.sp == USS_DIAL_RCMD_VAR || *netp->hw.sp == USS_DIAL_RCMD_INT)
netp->hw.sp++;
#endif
netp->hw.sp++;
}
netp->hw.sp++;
return 0; /* Don't do another command */
case ussDialXcmdFileE: /* type string 0x00 */
#if NTRACE >= 3
_sv[netp->netno].name = (char *)netp->hw.sp;
#endif
goto until_0;
case ussDialXcmdMinusE: /* type int-index */
netp->hw.sp++;
ussDialIntTable[*netp->hw.sp++]--;
break;
case ussDialXcmdPlusE: /* type int-index */
netp->hw.sp++;
ussDialIntTable[*netp->hw.sp++]++;
break;
/* type int-index|value >|<|= [=] int-index|value tag-name1 tag-name2 */
case ussDialXcmdIfE:
/* Value 1 */
i1 = getDialInt(&netp->hw.sp);
/* Condition (>|<|=)[=]*/
c1 = 3;
if (*netp->hw.sp == '>') c1 += 2, netp->hw.sp++;
if (*netp->hw.sp == '<') c1 -= 2, netp->hw.sp++;
if (*netp->hw.sp == '=') c1++, netp->hw.sp++;
if (*netp->hw.sp == '=') c1--, netp->hw.sp++;
/* Value 2 */
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -