📄 ppp.c
字号:
/****************************************Copyright (c)**************************************************
** 广州周立功单片机发展有限公司
** 研 究 所
** 产品一部
**
** http://www.zlgmcu.com
**
**--------------文件信息--------------------------------------------------------------------------------
**文 件 名: ppp.c
**创 建 人: 陈明计
**最后修改日期: 2004年4月23日
**描 述: PPP协议核心处理程序
**
**--------------历史版本信息----------------------------------------------------------------------------
** 创建人: 陈明计
** 版 本: 0.10b
** 日 期: 2004年4月23日
** 描 述: 原始版本
**
**--------------当前版本修订------------------------------------------------------------------------------
** 修改人:
** 日 期:
** 描 述:
**
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
#define IN_PPP
#include "config.h"
static OS_STK Stk[2][PPP_DRIVER_TASK_STK_SIZE]; /* 任务堆栈 */
static PppData PPPData;
/* ppp状态态转换表 */
uint8 PPPStateTransitionTable[MAX_PPP_EVENT][MAX_PPP_STATE] =
{
/* Initial Starting Closed Stopped Closing Stopping Req-Sent Ack-Rcvd Ack-Sent Opened */
{ PPP_STATE_CLOSED, PPP_STATE_REQ_SENT, PPP_STATE_ERR, PPP_STATE_ERR, PPP_STATE_ERR, PPP_STATE_ERR, PPP_STATE_ERR, PPP_STATE_ERR, PPP_STATE_ERR, PPP_STATE_ERR}, /* UP */
{ PPP_STATE_ERR, PPP_STATE_ERR, PPP_STATE_INITIAL, PPP_STATE_STARTING, PPP_STATE_INITIAL, PPP_STATE_STARTING, PPP_STATE_STARTING, PPP_STATE_STARTING, PPP_STATE_STARTING, PPP_STATE_STARTING}, /* DOWN */
{ PPP_STATE_STARTING, PPP_STATE_STARTING, PPP_STATE_REQ_SENT, PPP_STATE_STOPED, PPP_STATE_STOPPING, PPP_STATE_STOPPING, PPP_STATE_REQ_SENT, PPP_STATE_ACK_REVD, PPP_STATE_ACK_SEND, PPP_STATE_OPEN}, /* OPEN */
{ PPP_STATE_INITIAL, PPP_STATE_INITIAL, PPP_STATE_CLOSED, PPP_STATE_CLOSED, PPP_STATE_CLOSING, PPP_STATE_CLOSING, PPP_STATE_CLOSING, PPP_STATE_CLOSING, PPP_STATE_CLOSING, PPP_STATE_CLOSING}, /* CLOSE */
{ PPP_STATE_ERR, PPP_STATE_ERR, PPP_STATE_ERR, PPP_STATE_ERR, PPP_STATE_CLOSING, PPP_STATE_STOPPING, PPP_STATE_REQ_SENT, PPP_STATE_REQ_SENT, PPP_STATE_ACK_SEND, PPP_STATE_ERR}, /* TO+ */
{ PPP_STATE_ERR, PPP_STATE_ERR, PPP_STATE_ERR, PPP_STATE_ERR, PPP_STATE_CLOSED, PPP_STATE_STOPED, PPP_STATE_STOPED, PPP_STATE_STOPED, PPP_STATE_STOPED, PPP_STATE_ERR}, /* TO- */
{ PPP_STATE_ERR, PPP_STATE_ERR, PPP_STATE_CLOSED, PPP_STATE_ACK_SEND, PPP_STATE_CLOSING, PPP_STATE_STOPPING, PPP_STATE_ACK_SEND, PPP_STATE_OPEN, PPP_STATE_ACK_SEND, PPP_STATE_ACK_SEND}, /* RCR+ */
{ PPP_STATE_ERR, PPP_STATE_ERR, PPP_STATE_CLOSED, PPP_STATE_ACK_SEND, PPP_STATE_CLOSING, PPP_STATE_STOPPING, PPP_STATE_REQ_SENT, PPP_STATE_ACK_REVD, PPP_STATE_REQ_SENT, PPP_STATE_REQ_SENT}, /* RCR- */
{ PPP_STATE_ERR, PPP_STATE_ERR, PPP_STATE_CLOSED, PPP_STATE_STOPED, PPP_STATE_CLOSING, PPP_STATE_STOPPING, PPP_STATE_ACK_REVD, PPP_STATE_REQ_SENT, PPP_STATE_OPEN, PPP_STATE_REQ_SENT}, /* RCA */
{ PPP_STATE_ERR, PPP_STATE_ERR, PPP_STATE_CLOSED, PPP_STATE_STOPED, PPP_STATE_CLOSING, PPP_STATE_STOPPING, PPP_STATE_REQ_SENT, PPP_STATE_REQ_SENT, PPP_STATE_ACK_SEND, PPP_STATE_REQ_SENT}, /* RCN */
{ PPP_STATE_ERR, PPP_STATE_ERR, PPP_STATE_CLOSED, PPP_STATE_STOPED, PPP_STATE_CLOSING, PPP_STATE_STOPPING, PPP_STATE_REQ_SENT, PPP_STATE_REQ_SENT, PPP_STATE_REQ_SENT, PPP_STATE_STOPPING}, /* RTR */
{ PPP_STATE_ERR, PPP_STATE_ERR, PPP_STATE_CLOSED, PPP_STATE_STOPED, PPP_STATE_CLOSED, PPP_STATE_STOPED, PPP_STATE_REQ_SENT, PPP_STATE_REQ_SENT, PPP_STATE_ACK_SEND, PPP_STATE_REQ_SENT}, /* RTA */
{ PPP_STATE_ERR, PPP_STATE_ERR, PPP_STATE_CLOSED, PPP_STATE_STOPED, PPP_STATE_CLOSING, PPP_STATE_STOPPING, PPP_STATE_REQ_SENT, PPP_STATE_ACK_REVD, PPP_STATE_ACK_SEND, PPP_STATE_OPEN}, /* RUC */
{ PPP_STATE_ERR, PPP_STATE_ERR, PPP_STATE_CLOSED, PPP_STATE_STOPED, PPP_STATE_CLOSING, PPP_STATE_STOPPING, PPP_STATE_REQ_SENT, PPP_STATE_ACK_REVD, PPP_STATE_ACK_SEND, PPP_STATE_OPEN}, /* RXJ+ */
{ PPP_STATE_ERR, PPP_STATE_ERR, PPP_STATE_CLOSED, PPP_STATE_STOPED, PPP_STATE_CLOSED, PPP_STATE_STOPED, PPP_STATE_STOPED, PPP_STATE_STOPED, PPP_STATE_STOPED, PPP_STATE_STOPPING}, /* RXJ- */
{ PPP_STATE_ERR, PPP_STATE_ERR, PPP_STATE_CLOSED, PPP_STATE_STOPED, PPP_STATE_CLOSING, PPP_STATE_STOPPING, PPP_STATE_REQ_SENT, PPP_STATE_ACK_REVD, PPP_STATE_ACK_SEND, PPP_STATE_OPEN}, /* RXR */
{ PPP_STATE_INITIAL, PPP_STATE_STARTING, PPP_STATE_CLOSED, PPP_STATE_STOPED, PPP_STATE_CLOSING, PPP_STATE_STOPPING, PPP_STATE_REQ_SENT, PPP_STATE_ACK_REVD, PPP_STATE_ACK_SEND, PPP_STATE_OPEN} /* 进入高层 */
};
/* ppp动作表 */
uint8 PPPActionsTable[MAX_PPP_EVENT][MAX_PPP_STATE] =
{
/* Initial Starting Closed Stopped Closing Stopping Req-Sent Ack-Rcvd Ack-Sent Opened */
{ none, irc_scr, none, none, none, none, none, none, none, none}, /* UP */
{ none, none, none, tls, none, none, none, none, none, tld}, /* DOWN */
{ tls, none, irc_scr, reset, reset, reset, none, none, none, reset}, /* OPEN */
{ none, tlf, none, none, none, none, irc_str, irc_str, irc_str, tld_irc_str}, /* CLOSE */
{ none, none, none, none, str, str, scr, scr, scr, Uplayer}, /* TO+ */
{ none, none, none, none, tlf, tlf, tlf, tlf, tlf, Uplayer}, /* TO- */
{ none, none, sta, irc_scr_sca, none, none, sca, sca_tlu, sca, tld_scr_sca}, /* RCR+ */
{ none, none, sta, irc_scr_scn, none, none, scn, scn, scn, tld_scr_scn}, /* RCR- */
{ none, none, sta, sta, none, none, irc, scr, irc_tlu, tld_scr}, /* RCA */
{ none, none, sta, sta, none, none, irc_scr, scr, irc_sca, tld_scr}, /* RCN */
{ none, none, sta, sta, sta, sta, sta, sta, sta, tld_zrc_sta}, /* RTR */
{ none, none, none, none, tlf, tlf, none, none, none, tld_scr}, /* RTA */
{ none, none, scj, scj, scj, scj, scj, scj, scj, scj}, /* RUC */
{ none, none, none, none, none, none, none, none, none, none}, /* RXJ+ */
{ none, none, tlf, tlf, tlf, tlf, tlf, tlf, tlf, tld_irc_str}, /* RXJ- */
{ none, none, none, none, none, none, none, none, none, ser}, /* RXR */
{ none, none, none, none, none, none, none, none, none, Uplayer} /* 进入高层 */
};
void PPPDriverTask(void *Pdata);
void PPPReviceTask(void *Pdata);
uint16 PPPFcs16(uint16 Fcs, uint8 *cp, int16 Length);
/*********************************************************************************************************
** 函数名称: PPPGetState
** 功能描述: 获取ppp状态
** 输 入: 无
**
** 输 出: 状态
** 全局变量: 无
** 调用模块: 无
**
** 作 者: 陈明计
** 日 期: 2004年4月23日
**-------------------------------------------------------------------------------------------------------
** 修改人:
** 日 期:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
uint8 PPPGetState(void)
{
return PPPData.State;
}
/*********************************************************************************************************
** 函数名称: PPP_tlu()
** 功能描述: This-Layer-Up
** 动作给自动进入打开阶段的上边的层做指示。
** 典型的,该动作被LCP用于对一个NCP发送向上的事件信号,
** 或者链路质量协议,或者可以被一个NCP用于显示该链路可用于它的网络层往来。
** 输 入: DataBuf :接收到的数据包(本函数没有用到)
** Q :接收到的消息(本函数没有用到)
** 输 出: 无
** 全局变量: 无
** 调用模块: 无
**
** 作 者: 陈明计
** 日 期: 2004年4月23日
**-------------------------------------------------------------------------------------------------------
** 修改人:
** 日 期:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
void PPP_tlu(uint8 *DataBuf, uint8 Q)
{
DataBuf = DataBuf;
Q = Q;
NCPOpen(&PPPData);
}
/*********************************************************************************************************
** 函数名称: PPP_tld()
** 功能描述: This-Layer-Down
** 该动作给自动留下打开的阶段的上边的层做指示。
** 典型地,该动作被LCP用于向一个NCP发送向下的事件,证实协议,
** 或者可以被一个NCP用于显示该链路对它的网络层传输不再可用。
** 输 入: DataBuf :接收到的数据包(本函数没有用到)
** Q :接收到的消息(本函数没有用到)
** 输 出: 无
** 全局变量: 无
** 调用模块: 无
**
** 作 者: 陈明计
** 日 期: 2004年4月23日
**-------------------------------------------------------------------------------------------------------
** 修改人:
** 日 期:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
void PPP_tld(uint8 *DataBuf, uint8 Q)
{
DataBuf = DataBuf;
Q = Q;
NCPClose(&PPPData);
}
/*********************************************************************************************************
** 函数名称: PPP_tls()
** 功能描述: This-Layer-Started
** 该动作对自动进入开始状态的更低的层做指示,并且需要更低的层用于该链路。
** 当更低的层可用的时候,更低的层应该用一个向上的事件响应。
** 该动作的结果是高度的依赖动作的执行的。
** 输 入: DataBuf :接收到的数据包(本函数没有用到)
** Q :接收到的消息(本函数没有用到)
** 输 出: 无
** 全局变量: 无
** 调用模块: 无
**
** 作 者: 陈明计
** 日 期: 2004年4月23日
**-------------------------------------------------------------------------------------------------------
** 修改人:
** 日 期:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
void PPP_tls(uint8 *DataBuf, uint8 Q)
{
DataBuf = DataBuf;
Q = Q;
if (PPPData.HardDrive != NULL)
{
if (PPPData.HardDrive->Open != NULL)
{
PPPData.HardDrive->Open();
}
}
}
/*********************************************************************************************************
** 函数名称: PPP_tlf()
** 功能描述: This-Layer-Finished
** 该动作给自动进入最初,关闭了或者停止的阶段的更低的层做指示,并且,在链路上不再需要更低的层。
** 当更低的层终止的时候,更低的层应该用一个向下的事件应答。
** 典型地,该动作可以被LCP用于前进到链路死掉的状态,或者可以被一个NCP
** 用于给当没有其他的NCPs打开时链路可以被终止的LCP做指示。
** 输 入: DataBuf :接收到的数据包(本函数没有用到)
** Q :接收到的消息(本函数没有用到)
** 输 出: 无
** 全局变量: 无
** 调用模块: 无
**
** 作 者: 陈明计
** 日 期: 2004年4月23日
**-------------------------------------------------------------------------------------------------------
** 修改人:
** 日 期:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
void PPP_tlf(uint8 *DataBuf, uint8 Q)
{
DataBuf = DataBuf;
Q = Q;
if (PPPData.HardDrive != NULL)
{
if (PPPData.HardDrive->Close != NULL)
{
PPPData.HardDrive->Close();
}
}
OSTaskDel(PPP_DRIVER_TASK_PRIO + 1);
}
/**************************************************************************/
/*********************************************************************************************************
** 函数名称: PPP_irc()
** 功能描述: Initialize-Restart-Count
** 该动作对Restart计数器设置适当的值(Max-Terminate 或 Max-Configure)。
** 每次传输,包括第一次传输,计数器自减。
** 输 入: DataBuf :接收到的数据包(本函数没有用到)
** Q :接收到的消息(本函数没有用到)
** 输 出: 无
** 全局变量: 无
** 调用模块: 无
**
** 作 者: 陈明计
** 日 期: 2004年4月23日
**-------------------------------------------------------------------------------------------------------
** 修改人:
** 日 期:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
void PPP_irc(uint8 *DataBuf, uint8 Q)
{
uint8 temp;
DataBuf = DataBuf;
Q = Q;
PPPData.OverTimeSum = PPPData.MaxFailure;
temp = PPPData.State;
if (temp == PPP_STATE_CLOSING || temp == PPP_STATE_STOPPING)
{
PPPData.DelayTime = PPPData.MaxTerminate;
}
else
{
PPPData.DelayTime = PPPData.MaxConfigure;
}
}
/*********************************************************************************************************
** 函数名称: PPP_zrc()
** 功能描述: Zero-Restart-Count
** 该动作对Restart计数器清零。
** 输 入: DataBuf :接收到的数据包(本函数没有用到)
** Q :接收到的消息(本函数没有用到)
** 输 出: 无
** 全局变量: 无
** 调用模块: 无
**
** 作 者: 陈明计
** 日 期: 2004年4月23日
**-------------------------------------------------------------------------------------------------------
** 修改人:
** 日 期:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
void PPP_zrc(uint8 *DataBuf, uint8 Q)
{
DataBuf = DataBuf;
Q = Q;
PPPData.DelayTime = 0;
PPPData.OverTimeSum = 0;
}
/*********************************************************************************************************
** 函数名称: PPP_scr()
** 功能描述: Send-Configure-Request
** 一个Configure-Request的包被传送。
** 这表明要用指定的一套特殊的配置选项打开一个连接。
** 为了防止包丢失,Restart计时器在Configure-Request包被传送的时候打开。
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -