📄 lcp.c
字号:
/****************************************Copyright (c)**************************************************
** 广州周立功单片机发展有限公司
** 研 究 所
** 产品一部
**
** http://www.zlgmcu.com
**
**--------------文件信息--------------------------------------------------------------------------------
**文 件 名: LPC.h
**创 建 人: 陈明计
**最后修改日期: 2004年4月23日
**描 述: PPP 链路质量监控协议头处理程序
**
**--------------历史版本信息----------------------------------------------------------------------------
** 创建人: 陈明计
** 版 本: 0.10b
** 日 期: 2004年4月23日
** 描 述: 原始版本
**
**--------------当前版本修订------------------------------------------------------------------------------
** 修改人:
** 日 期:
** 描 述:
**
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
#define IN_LCP
#include "config.h"
uint8 LcpCfg[] = {
PPP_FRAM_TYPE__LPC / 256, PPP_FRAM_TYPE__LPC % 256,
0x01,0x00,
0x00,0x04,
};
uint8 LcpTermReg[] = {
PPP_FRAM_TYPE__LPC / 256, PPP_FRAM_TYPE__LPC % 256,
0x05,0x00,
0x00,0x04,
};
void SendCfgFram(PppData *ThisPPP, uint8 *In)
{
uint16 NByte;
NByte= ((In[4] * 256) | In[5]) + 2;
PPPDriveWrite(ThisPPP->HardDrive, In, NByte);
}
void LCPSendCfgReq(PppData *ThisPPP)
{
LcpCfg[3] = ThisPPP->FramID++;
SendCfgFram(ThisPPP, LcpCfg);
}
void LCPSendCfgAck(PppData *ThisPPP, uint8 * DataBuf)
{
DataBuf[2] = LCP_CFG_ACK;
SendCfgFram(ThisPPP, DataBuf);
}
void LCPSendCfgNak(PppData *ThisPPP, uint8 * DataBuf)
{
SendCfgFram(ThisPPP, DataBuf);
}
void LCPSendTermReq(PppData *ThisPPP)
{
LcpTermReg[3] = ThisPPP->FramID++;
SendCfgFram(ThisPPP, LcpTermReg);
}
void LCPSendTermAck(PppData *ThisPPP, uint8 * DataBuf)
{
DataBuf[2] = LCP_TERM_ACK;
SendCfgFram(ThisPPP, DataBuf);
}
void LCPSendCodeRej(PppData *ThisPPP, uint8 * DataBuf)
{
uint16 NByte;
ThisPPP = ThisPPP;
DataBuf -= 3;
NByte = ((DataBuf[1] * 256) | DataBuf[2]) + 1;
DataBuf[0] = PPP_FRAM_TYPE__LPC / 256;
DataBuf[1] = PPP_FRAM_TYPE__LPC % 256,
DataBuf[2] = LCP_CODE_REJ;
PPPDriveWrite(ThisPPP->HardDrive, DataBuf, NByte);
}
void LCPSendEchoReply(PppData *ThisPPP, uint8 * DataBuf)
{
DataBuf[2] = LCP_ECHO_REPLY;
SendCfgFram(ThisPPP, DataBuf);
}
uint16 LCPReviceCfg(uint8 *Fram, uint8 Flag)
{
int16 FramNByte,RtNByte;
uint8 temp;
uint8 *cp;
FramNByte = Fram[0] * 256 | Fram[1] - 4;
Fram += 2;
RtNByte = 0;
cp = Fram;
while (FramNByte > 0)
{
FramNByte -= Fram[1];
temp = LCP_CFG_REJ;
switch (*Fram)
{
case 0: /* RESERVED */
//temp = LCP_CFG_REJ;
break;
case 1: /* Maximum-Receive-Unit */
//temp = LCP_CFG_REJ;
break;
case 3: /* Authentication-Protocol */
temp = CfgPAP(Fram);
break;
case 4: /* Quality-Protocol */
//temp = LCP_CFG_REJ;
break;
case 5: /* Magic-Number */
temp = LCP_CFG_ACK;
break;
case 7: /* Protocol-Field-Compression */
//temp = LCP_CFG_REJ;
break;
case 8: /* Address-and-Control-Field-Compression */
//temp = LCP_CFG_REJ;
break;
default:
#if EN_LCP_REVICE_CFG_HOOHK > 0
temp = LCPReviceCfgHooK(Fram);
#endif
break;
}
if (temp == Flag)
{
temp = Fram[1];
RtNByte += temp;
while (temp--)
{
*cp++ = *Fram++;
}
}
else
{
Fram += Fram[1];
}
}
return RtNByte;
}
uint8 LCPReviceFram(uint8 *Fram)
{
uint16 NByte;
uint8 rt;
rt = PPP_EVENT_RUC;
Fram += 2;
switch (*Fram)
{
case LCP_CFG_REQ:
*Fram = LCP_CFG_ACK;
rt = PPP_EVENT_RCR_GOOD;
NByte = LCPReviceCfg(Fram + 2, LCP_CFG_REJ);
if (NByte == 0)
{
NByte = LCPReviceCfg(Fram + 2, LCP_CFG_NAK);
if(NByte == 0)
{
break;
}
*Fram = LCP_CFG_NAK;
}
else
{
*Fram = LCP_CFG_REJ;
}
NByte += 4;
Fram += 2;
*Fram++ = NByte / 256;
*Fram = NByte & 0xff;
rt = PPP_EVENT_RCR_BAD;
break;
case LCP_CFG_ACK:
rt = PPP_EVENT_RCA;
break;
case LCP_CFG_NAK:
rt = PPP_EVENT_RCN;
break;
case LCP_CFG_REJ:
rt = PPP_EVENT_RCN;
break;
case LCP_TERM_REQ:
rt = PPP_EVENT_RTR;
break;
case LCP_TERM_ACK:
rt = PPP_EVENT_RTA;
break;
case LCP_CODE_REJ:
rt = PPP_EVENT_RXJ_p;
break;
case LCP_ECHO_REQ:
rt = PPP_EVENT_RXR;
break;
case LCP_ECHO_REPLY:
rt = PPP_EVENT_NONE;
break;
case LCP_DISCARD_REQ:
rt = PPP_EVENT_NONE;
break;
default :
#if EN_LCP_REVICE_FRAM_HOOHK > 0
rt = LCPReviceFramHook(Fram);
#endif
break;
}
return rt;
}
/*********************************************************************************************************
** End Of File
********************************************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -