参照这种方式:
/*!Copyright(c) 2008-2014 Shenzhen TP-LINK Technologies Co.Ltd.
*
*\file cliPpppoeCircuitIdHandlers.c
*\brief Cli source file of PPPoE Circuit ID module.
*
*\author Songyuhang
*\version 1.0.0
*\date 02/19/2025
*
*\history arg 1.0.0 02/19/2025, Songyuhang, create the file
*/
/**************************************************************************************************/
/* INCLUDE_FILES */
/**************************************************************************************************/
#define HAS_DEBUG
#define DBG_ON 1
#define DBG_VRBS_ON 1
#define DBG_MAJOR_ON 1
#define __DBG_MOD_SET__ "PPPOE"
#include "tpDbg/tpdebug.h"
/* libc header */
#include <stdio.h>
/* syscall header */
/* common header */
#include "fepDefs.h"
/* platform header */
#include "midware/tpConfig.h"
#include "midware/tpState.h"
#include "userPort/user_port.h"
#include "userPort/up_str.h"
#include "common/applError.h"
#include "cliPppoeCircuitIdHandlers.h"
/**************************************************************************************************/
/* DEFINES */
/**************************************************************************************************/
#ifdef MODULE_NAME
#undef MODULE_NAME
#endif
#define MODULE_NAME "pppoeCircuitId"
/**************************************************************************************************/
/* TYPES */
/**************************************************************************************************/
/**************************************************************************************************/
/* EXTERN_PROTOTYPES */
/**************************************************************************************************/
/**************************************************************************************************/
/* LOCAL_PROTOTYPES */
/**************************************************************************************************/
/**************************************************************************************************/
/* VARIABLES */
/**************************************************************************************************/
/**************************************************************************************************/
/* LOCAL_FUNCTIONS */
/**************************************************************************************************/
/**************************************************************************************************/
/* PUBLIC_FUNCTIONS */
/**************************************************************************************************/
int cli_pppoeSysState(int state)
{
APPL_IF_ERR_RET(pppoeSysStateSet(state));
return ERR_NO_ERROR;
}
int cli_pppoeCirEther(char *portListStr, int state, int type, char *udfVal)
{
APPL_IF_ERR_RET(pppoeCirEtherSet(portListStr, state, type, udfVal));
return ERR_NO_ERROR;
}
int cli_pppoeRemEther(char *portListStr, int state, char *udfVal)
{
APPL_IF_ERR_RET(pppoeRemEtherSet(portListStr, state, udfVal));
return ERR_NO_ERROR;
}
int cli_showPppoeGlobal(cli_env *pCliEnv)
{
int ret = ERR_NO_ERROR;
char buf[TPCONFIG_BUFFER_LEN] = {};
int oldState = DISABLE_PPPOE_CIRCUIT;
char *state[2] = {"Disable", "Enable"};
APPL_IF_ERR_DONE_RET(ret, pppoeGetGlobalConfig(&oldState), ERR_BAD_PARAM);
snprintf(buf, sizeof(buf), "PPPoE ID Insertion State:%-10s%s\r\n", " ", state[oldState]);
cliPrintf(pCliEnv, buf);
done:
return ret;
}
int cli_pppoePortCfgShowByInterface(cli_env *pCliEnv, int portMode, char *portListStr)
{
int ret = ERR_NO_ERROR;
user_port up = {};
CP_PARSE_OPTION opt = {};
char strPort[UP_LIST_STR_LEN_MIN] = {};
char emptyVal[] = "---";
char tUdfVal[MAX_PPPOE_ID_LENGTH + 1] = {};
char tRemoteVal[MAX_PPPOE_ID_LENGTH + 1] = {};
char buf[TPCONFIG_CLI_BUFFER_LEN] = {};
const char *state[2] = {"Disable", "Enable"};
const char *type[4] = {"IP", "MAC", "UDF", "UDF-ONLY"};
ret = usStr2Up(UP_MODE_INTF_INVALID, (const char *)portListStr, &up, &opt);
if (!UP_IS_AVAILABLE(up) || !UP_IS_SWP_PORT(up))
{
ret = ERR_BAD_PARAM;
goto done;
}
int upIdx = UP_INDEX(up);
PPPOE_CIRCUIT_PORT_CFG_T portCfg = {};
APPL_IF_ERR_DONE_RET(ret, pppoeGetEthernetConfig(upIdx, &portCfg), ERR_BAD_PARAM);
if (0 == strlen(portCfg.udfValue))
{
memcpy(tUdfVal, emptyVal, 4);
}
else
{
memcpy(tUdfVal, portCfg.udfValue, strlen(portCfg.udfValue));
}
memset(tRemoteVal, 0, MAX_PPPOE_ID_LENGTH + 1);
if (0 == strlen(portCfg.remoteId))
{
memcpy(tRemoteVal, emptyVal, 4);
}
else
{
memcpy(tRemoteVal, portCfg.remoteId, strlen(portCfg.remoteId));
}
snprintf(buf, sizeof(buf), "%-12s%-14s%-14s%-41s%-14s%-41s\r\n", " Port ", "Circuit-ID", "C-ID Type", "C-ID Value(UDF)", "Remote-ID", "R-ID Value");
cliPrintf(pCliEnv, buf);
snprintf(buf, sizeof(buf), "%-12s%-14s%-14s%-41s%-14s%-41s\r\n", "-------", "-----------", "-----------", "--------------------------------", "-----------", "--------------------------------");
cliPrintf(pCliEnv, buf);
usUp2Str(up, strPort, 1);
snprintf(buf, sizeof(buf), "%-12s%-14s%-14s%-41s%-14s%-41s\r\n", strPort, state[(portCfg.state & 0x1)], type[portCfg.type], tUdfVal, state[(portCfg.state >> 1)], tRemoteVal);
cliPrintf(pCliEnv, buf);
done:
return ret;
}
int cliPppoeDisplayInterface(cli_env *pCliEnv, user_port up)
{
int ret = ERR_NO_ERROR;
char strPort[UP_LIST_STR_LEN_MIN] = {};
char emptyVal[] = "---";
char tUdfVal[MAX_PPPOE_ID_LENGTH + 1] = {};
char tRemoteVal[MAX_PPPOE_ID_LENGTH + 1] = {};
char buf[TPCONFIG_CLI_BUFFER_LEN] = {};
const char *state[2] = {"Disable", "Enable"};
const char *type[4] = {"IP", "MAC", "UDF", "UDF-ONLY"};
if (!UP_IS_AVAILABLE(up) || !UP_IS_SWP_PORT(up))
{
ret = ERR_BAD_PARAM;
goto done;
}
int upIdx = UP_INDEX(up);
PPPOE_CIRCUIT_PORT_CFG_T portCfg = {};
APPL_IF_ERR_DONE_RET(ret, pppoeGetEthernetConfig(upIdx, &portCfg), ERR_BAD_PARAM);
if (0 == strlen(portCfg.udfValue))
{
memcpy(tUdfVal, emptyVal, 4);
}
else
{
memcpy(tUdfVal, portCfg.udfValue, strlen(portCfg.udfValue));
}
memset(tRemoteVal, 0, MAX_PPPOE_ID_LENGTH + 1);
if (0 == strlen(portCfg.remoteId))
{
memcpy(tRemoteVal, emptyVal, 4);
}
else
{
memcpy(tRemoteVal, portCfg.remoteId, strlen(portCfg.remoteId));
}
usUp2Str(up, strPort, 1);
snprintf(buf, sizeof(buf), "%-12s%-14s%-14s%-41s%-14s%-41s\r\n", strPort, state[(portCfg.state & 0x1)], type[portCfg.type], tUdfVal, state[(portCfg.state >> 1)], tRemoteVal);
cliPrintf(pCliEnv, buf);
done:
return ret;
}
int cli_pppoePortCfgShow(cli_env *pCliEnv)
{
int ret = ERR_NO_ERROR;
int idx = 0;
user_port up = {};
valid_uplist valid_uplist = NULL;
char buf[TPCONFIG_CLI_BUFFER_LEN] = {};
snprintf(buf, sizeof(buf), "%-12s%-14s%-14s%-41s%-14s%-41s\r\n", " Port ", "Circuit-ID", "C-ID Type", "C-ID Value(UDF)", "Remote-ID", "R-ID Value");
cliPrintf(pCliEnv, buf);
snprintf(buf, sizeof(buf), "%-12s%-14s%-14s%-41s%-14s%-41s\r\n", "-------", "-----------", "-----------", "--------------------------------", "-----------", "--------------------------------");
cliPrintf(pCliEnv, buf);
PFM_IF_FAIL_DONE(ret, valid_uplist_init(&valid_uplist, 0));
PFM_IF_FAIL_DONE(ret, valid_uplist_get(&valid_uplist, 0));
UP_ITER_AVL_SWP(valid_uplist, idx, up)
{
cliPppoeDisplayInterface(pCliEnv, up);
}
done:
valid_uplist_free(&valid_uplist);
return ret;
}
最新发布