📄 cli_telnet.c
字号:
/* 输入参数 :PTerm_Data_S pTermStruct 任务数据 */
/* _U8 c 接收到的输入字符 */
/* 输出参数 :PTerm_Data_S pTermStruct 任务数据 */
/* 返回值 :_U32 1:成功 */
/* 调用函数 :CLI_DebugOutString ( ) */
/* 被调函数 : */
/*==================================================================*/
_U32 CLI_SubOpt ( PTerm_Data_S pTermStruct, _U8 c )
{
struct Fsm_Trans_S * lpTab ;
_U32 ulState ;
_S8 szFSMInfoEn[1024] = "";
_S8 szFSMInfoCh[1024] = "";
/*--------------------------------------------------------------*/
/* 调用选项子协商FSM来处理输入数据 */
/* 1. 根据当前子状态及输入数据选择对应的表 */
/* 2. 处理输入数据 */
/* 3. 状态转换 */
/*--------------------------------------------------------------*/
if(pTermStruct == G_NULL)
{
return 1;
}
ulState = c ;
ulState = SubFsm[ pTermStruct->TelnetParam.SubState ] [ ulState ] ;
lpTab = &SubStab [ ulState ] ;
( lpTab->Ft_Action ) ( pTermStruct, c ) ;
pTermStruct->TelnetParam.SubState = lpTab->Ft_Next ;
if ( G_TRUE == m_bCliTelnetDebugOn )
{
if ( pTermStruct->iRecvLen == 1 )
{
switch ( pTermStruct->TelnetParam.TTState )
{
case TSSUBNEG :
strcat(szFSMInfoEn, "\r\n The telnet NVT FSM :");
strcat(szFSMInfoCh, "\r\n Telnet 网络虚拟终端状态机 :");
strcat(szFSMInfoEn, "\r\n the current state : TSSUBNEG");
strcat(szFSMInfoCh, "\r\n 当前状态 : TSSUBNEG");
if ( c == TCIAC )
{
strcat(szFSMInfoEn, "\r\n the input character : IAC ( Interrupt As Command )");
strcat(szFSMInfoCh, "\r\n 输入字符 : IAC ( Interrupt As Command )");
strcat(szFSMInfoEn, "\r\n the next state : TSSUBIAC \r\n");
strcat(szFSMInfoCh, "\r\n 下一状态 : TSSUBIAC \r\n");
}
else
{
strcat(szFSMInfoEn, "\r\n the input character : 0x");
strcat(szFSMInfoCh, "\r\n 输入字符 : 0x");
EOS_Sprintf ( szInputChar, "%2x", c ) ;
strcat(szFSMInfoEn, szInputChar);
strcat(szFSMInfoCh, szInputChar);
strcat(szFSMInfoEn, "\r\n the next state : TSSUBNEG \r\n");
strcat(szFSMInfoCh, "\r\n 下一状态 : TSSUBNEG \r\n");
}
strcat(szFSMInfoEn, "\r\n the action : pass the character to SubNeg FSM ");
strcat(szFSMInfoCh, "\r\n 执行动作 : pass the character to SubNeg FSM ");
break ;
case TSSUBIAC :
strcat(szFSMInfoEn, "\r\n The telnet NVT FSM :");
strcat(szFSMInfoCh, "\r\n Telnet 网络虚拟终端状态机 :");
strcat(szFSMInfoEn, "\r\n the current state : TSSUBIAC");
strcat(szFSMInfoCh, "\r\n 当前状态 : TSSUBIAC");
strcat(szFSMInfoEn, "\r\n the input character : 0x");
strcat(szFSMInfoCh, "\r\n 输入字符 : 0x");
EOS_Sprintf ( szInputChar, "%2x", c ) ;
strcat(szFSMInfoEn, szInputChar);
strcat(szFSMInfoCh, szInputChar);
strcat(szFSMInfoEn, "\r\n the next state : TSSUBNEG \r\n");
strcat(szFSMInfoCh, "\r\n 下一状态 : TSSUBNEG \r\n");
strcat(szFSMInfoEn, "\r\n the action : pass the character to SubNeg FSM ");
strcat(szFSMInfoCh, "\r\n 执行动作 : pass the character to SubNeg FSM ");
break ;
default :
break ;
}
}
CLI_TelFSMDegOut(szFSMInfoEn, szFSMInfoCh);
}
return 1 ;
}
/*==================================================================*/
/* 函数名 :CLI_SubEnd */
/* 函数功能 :结束选项子协商FSM状态装换 */
/* 输入参数 :PTerm_Data_S pTermStruct 任务数据 */
/* _U8 c 接收到的输入字符 */
/* 输出参数 :PTerm_Data_S pTermStruct 任务数据 */
/* 返回值 :_U32 1:成功 */
/* 调用函数 :CLI_DebugOutString ( ) */
/* 被调函数 : */
/*==================================================================*/
_U32 CLI_SubEnd ( PTerm_Data_S pTermStruct, _U8 c )
{
_S8 szFSMInfoEn[] =
"\r\n\r\n The telnet NVT FSM : \r\n \
\r\n the current state : TSSSUBIAC \
\r\n the input character : SE ( Subnegotiate End ) \
\r\n the next state : TSDATA \
\r\n the action : reset the SubNeg FSM ";
_S8 szFSMInfoCh[] =
"\r\n\r\n Telnet 网络虚拟终端状态机 : \r\n \
\r\n 当前状态 : TSSSUBIAC \
\r\n 输入字符 : SE ( Subnegotiate End ) \
\r\n 下一状态 : TSDATA \
\r\n 执行动作 : reset the SubNeg FSM ";
(_VOID)c ; /* for lint */
if(pTermStruct == G_NULL)
{
return 1;
}
/*--------------------------------------------------------------*/
/*选项子协商结束,将状态置为SS_START */
/*--------------------------------------------------------------*/
pTermStruct->TelnetParam.SubState = SS_START ;
if ( G_TRUE == m_bCliTelnetDebugOn )
{
if ( pTermStruct->iRecvLen == 1 )
{
CLI_TelFSMDegOut(szFSMInfoEn, szFSMInfoCh);
}
}
return 1 ;
}
/*==================================================================*/
/* 函数名 :CLI_Abort */
/* 函数功能 :对输入字符不做处理 */
/* 输入参数 :PTerm_Data_S pTermStruct 任务数据 */
/* _U8 c 接收到的输入字符 */
/* 输出参数 :PTerm_Data_S pTermStruct 任务数据 */
/* 返回值 :_U32 1:成功 */
/* 调用函数 : */
/* 被调函数 : */
/*==================================================================*/
_U32 CLI_Abort ( PTerm_Data_S pTermStruct, _U8 c )
{
(_VOID)pTermStruct ; /* for lint */
(_VOID)c ; /* for lint */
return 1 ;
}
/*==================================================================*/
/* 函数名 :CLI_DoNotSup */
/* 函数功能 :处理不支持的telnet "will/won't" 选项 */
/* 输入参数 :PTerm_Data_S pTermStruct 任务数据 */
/* _U8 c 接收到的输入字符 */
/* 输出参数 :PTerm_Data_S pTermStruct 任务数据 */
/* 返回值 :_U32 1:成功 */
/* 调用函数 :CLI_DebugOutString ( ) */
/* 被调函数 : */
/*==================================================================*/
_U32 CLI_DoNotSup ( PTerm_Data_S pTermStruct, _U8 c )
{
_S8 szFSMInfoEn[1024] = "";
_S8 szFSMInfoCh[1024] = "";
if(pTermStruct == G_NULL)
{
return 1;
}
/*--------------------------------------------------------------*/
/* 接收到 "IAC WILL/WONT option", 但不支持此选项 */
/* 则发送 "IAC DONT option" */
/*--------------------------------------------------------------*/
pTermStruct->szSendBuf [ pTermStruct->iSendLen++ ] = (_S8)TCIAC ;
pTermStruct->szSendBuf [ pTermStruct->iSendLen++ ] = (_S8)TCDONT ;
pTermStruct->szSendBuf [ pTermStruct->iSendLen++ ] = (_S8)c ;
pTermStruct->szSendBuf [ pTermStruct->iSendLen ] = '\0' ;
CLI_SendToTerm ( pTermStruct ) ;
if ( G_TRUE == m_bCliTelnetDebugOn )
{
if ( pTermStruct->iRecvLen == 1 )
{
strcat(szFSMInfoEn, "\r\n The telnet NVT FSM :");
strcat(szFSMInfoCh, "\r\n Telnet 网络虚拟终端状态机 :");
strcat(szFSMInfoEn, "\r\n the current state : TSWOPT");
strcat(szFSMInfoCh, "\r\n 当前状态 : TSWOPT");
if ( pTermStruct->TelnetParam.OptionCmd == TCWILL )
{
strcat(szFSMInfoEn, "\r\n the option negotiate command is : WILL");
strcat(szFSMInfoCh, "\r\n 选项协商命令: WILL");
}
else
{
strcat(szFSMInfoEn, "\r\n the option negotiate command is : WONT");
strcat(szFSMInfoCh, "\r\n 当前状态 : WONT");
}
strcat(szFSMInfoEn, "\r\n the input character : 0x");
strcat(szFSMInfoCh, "\r\n 输入字符 : 0x");
EOS_Sprintf ( szInputChar, "%2x", c ) ;
strcat(szFSMInfoEn, szInputChar);
strcat(szFSMInfoCh, szInputChar);
strcat(szFSMInfoEn, "\r\n the next state : TSDATA \r\n");
strcat(szFSMInfoCh, "\r\n 下一状态 : TSDATA \r\n");
strcat(szFSMInfoEn, "\r\n the action : send \"IAC DONT 0x");
strcat(szFSMInfoCh, "\r\n 执行动作 : send \"IAC DONT 0x");
strcat(szFSMInfoEn, szInputChar);
strcat(szFSMInfoCh, szInputChar);
strcat(szFSMInfoEn, "\" ");
strcat(szFSMInfoCh, "\" ");
}
CLI_TelFSMDegOut(szFSMInfoEn, szFSMInfoCh);
}
return 1 ;
}
/*==================================================================*/
/* 函数名 :CLI_WillNotSup */
/* 函数功能 :处理不支持的telnet "do/don't" 选项 */
/* 输入参数 :PTerm_Data_S pTermStruct 任务数据 */
/* _U8 c 接收到的输入字符 */
/* 输出参数 :PTerm_Data_S pTermStruct 任务数据 */
/* 返回值 :_U32 1:成功 */
/* 调用函数 :CLI_DebugOutString ( ) */
/* 被调函数 : */
/*==================================================================*/
_U32 CLI_WillNotSup ( PTerm_Data_S pTermStruct, _U8 c )
{
_S8 szFSMInfoEn[1024] = "";
_S8 szFSMInfoCh[1024] = "";
if(pTermStruct == G_NULL)
{
return 1;
}
/*--------------------------------------------------------------*/
/* 接收到 "IAC DO/DONT option", 但不支持此选项 */
/* 则发送 "IAC WONT option" */
/*--------------------------------------------------------------*/
pTermStruct->szSendBuf [ pTermStruct->iSendLen++ ] = (_S8)TCIAC ;
pTermStruct->szSendBuf [ pTermStruct->iSendLen++ ] = (_S8)TCWONT ;
pTermStruct->szSendBuf [ pTermStruct->iSendLen++ ] = (_S8)c ;
pTermStruct->szSendBuf [ pTermStruct->iSendLen ] = '\0' ;
CLI_SendToTerm ( pTermStruct ) ;
if ( G_TRUE == m_bCliTelnetDebugOn )
{
if ( pTermStruct->iRecvLen == 1 )
{
strcat(szFSMInfoEn, "\r\n The telnet NVT FSM :");
strcat(szFSMInfoCh, "\r\n Telnet 网络虚拟终端状态机 :");
strcat(szFSMInfoEn, "\r\n the current state : TSDOPT");
strcat(szFSMInfoCh, "\r\n 当前状态 : TSDOPT");
if ( pTermStruct->TelnetParam.OptionCmd == TCDO )
{
strcat(szFSMInfoEn, "\r\n the option negotiate command is : DO");
strcat(szFSMInfoCh, "\r\n 选项协商命令: DO");
}
else
{
strcat(szFSMInfoEn, "\r\n the option negotiate command is : DONT");
strcat(szFSMInfoCh, "\r\n 当前状态 : DONT");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -