?? 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 + -