📄 tclcmd.c
字号:
/*
* Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
* All rights reserved.
*
* This software is copyrighted by and is the sole property of
* VIA Networking Technologies, Inc. This software may only be used
* in accordance with the corresponding license agreement. Any unauthorized
* use, duplication, transmission, distribution, or disclosure of this
* software is expressly forbidden.
*
* This software is provided by VIA Networking Technologies, Inc. "as is"
* and any express or implied warranties, including, but not limited to, the
* implied warranties of merchantability and fitness for a particular purpose
* are disclaimed. In no event shall VIA Networking Technologies, Inc.
* be liable for any direct, indirect, incidental, special, exemplary, or
* consequential damages.
*
*
* File: tclcmd.c
*
* Purpose: TCL commands interpreter
*
* Author: Wango Wei
*
* Date: July 09, 2004
*
* Functions:
*
* Revision History:
* 2005-07-11 LucasLin Change return string seperater from ',' to ' '
*
* 2005-07-20 LucasLin Add "ver" cmd
*
* 2005-08-22 HenryLin Mask "ver" cmd
* Mask "sendpkt" cmd
*
*/
#if !defined(__SPRINT_F__)
//#include "sprintf.h"
#endif
#if !defined(__SWAPI_VERSION_H__)
#include "version.h"
#endif
#if !defined(__SWITCH_H__)
#include "switch.h"
#endif
#if !defined(__STR_H__)
#include "str.h"
#endif
#if !defined(__SWGMRPTB_H__)
#include "swgmrptb.h"
#endif
#if !defined(__SWIPMTB_H__)
#include "swipmtb.h"
#endif
#if !defined(__SWIPMTB_H__)
#include "swipmtb.h"
#endif
#if !defined(__SWL2PTB_H__)
#include "swl2ptb.h"
#endif
#if !defined(__SWLOGTB_H__)
#include "swlogtb.h"
#endif
#if !defined(__SWMIBTB_H__)
#include "swmibtb.h"
#endif
#if !defined(__SWMII_H__)
#include "swmii.h"
#endif
#if !defined(__SWMPMTB_H__)
#include "swmpmtb.h"
#endif
#if !defined(__SWMSTTB_H__)
#include "swmsttb.h"
#endif
#if !defined(__NVRAM_H__)
#include "nvram.h"
#endif
#if !defined(__SWREG_H__)
#include "swreg.h"
#endif
#if !defined(__SWSRAM_H__)
#include "swsram.h"
#endif
#if !defined(__SWPKT_H__)
#include "swpkt.h"
#endif
#if !defined(__SWPRIMTB_H__)
#include "swprimtb.h"
#endif
#if !defined(__SWPRVTB_H__)
#include "swprvtb.h"
#endif
#if !defined(__SWPMACTB_H__)
#include "swpmactb.h"
#endif
#if !defined(__SWPRVTB_H__)
#include "swprvtb.h"
#endif
#if !defined(__SWQOS_H__)
#include "swqos.h"
#endif
#if !defined(__SWRATE_H__)
#include "swrate.h"
#endif
#if !defined(__SWSECU_H__)
#include "swsecu.h"
#endif
#if !defined(__SWSTP_H__)
#include "swstp.h"
#endif
#if !defined(__SWTRK_H__)
#include "swtrk.h"
#endif
#if !defined(__SWSYS_H__)
#include "swsys.h"
#endif
#if !defined(__SWVLANTB_H__)
#include "swvlantb.h"
#endif
#if !defined(__TBLMAIN_H__)
//#include "tblmain.h"
#endif
#if !defined(__TCLCMDENG_H__)
#include "tclcmd.h"
#endif
#if !defined(__TTY_H__)
#include "tty.h"
#endif
#if !defined(__TTYPE_H__)
#include "ttype.h"
#endif
#if !defined(__SWLOGTB_H__)
#include "swlogtb.h"
#endif
#if !defined(__SWMPMTB_H__)
#include "swmpmtb.h"
#endif
/*--------------------- Static Definitions -------------------------*/
//#define __TEST_API 1
#define DEBUG_TCL 0 /* 1 = Enable Debugging message */
#define NEW_TCAM_CMD 1 /* 1 = Use new TCAM Cmd */
#ifdef __TCL_UART1
#define TTY_vGetStr TTY_vGetStr1
#define TTY_vPutStr TTY_vPutStr1
#else
#define TTY_vGetStr TTY_vGetStr
#define TTY_vPutStr TTY_vPutStr
#endif
#if (DEBUG_TCL)
#define PRINT(X) { TTY_vPrintf X; }
#else
#define PRINT(X)
#endif
#define MAX_BUF_SIZE 255
#define ARGU_CNT 32
#define ARGU_SIZE 16
typedef struct tagSCmdMap {
PSTR szCmd;
void (*pfnCmd)(char aszArgus[][ARGU_SIZE]);
} SCmdMap;
#define APPEND_SPACE(x) do { *x = ' '; x++; } while (0)
/*--------------------- Static Classes ----------------------------*/
/*--------------------- Static Functions --------------------------*/
static void s_vRegOp(char aszArgus[][ARGU_SIZE]);
static void s_vPhyOp(char aszArgus[][ARGU_SIZE]);
static void s_vSramOp(char aszArgus[][ARGU_SIZE]);
static void s_vLogTb(char aszArgus[][ARGU_SIZE]);
static void s_vPMacTb(char aszArgus[][ARGU_SIZE]);
static void s_vSMacTb(char aszArgus[][ARGU_SIZE]);
static void s_vVLANTb(char aszArgus[][ARGU_SIZE]);
static void s_vL2pTb(char aszArgus[][ARGU_SIZE]);
#if (NEW_TCAM_CMD)
static void s_vTcam(char aszArgus[][ARGU_SIZE]);
static void s_vTcamMask(char aszArgus[][ARGU_SIZE]);
#else
static void s_vTcamTb(char aszArgus[][ARGU_SIZE]);
#endif
static void s_vTcamTbNonIpv4(char aszArgus[][ARGU_SIZE]);
static void s_vL2pHitTb(char aszArgus[][ARGU_SIZE]);
static void s_vMPMTb(char aszArgus[][ARGU_SIZE]);
static void s_vMSTSTb(char aszArgus[][ARGU_SIZE]);
static void s_vPriMapTb(char aszArgus[][ARGU_SIZE]);
static void s_vMibCntTb(char aszArgus[][ARGU_SIZE]);
static void s_vQosPrec(char aszArgus[][ARGU_SIZE]);
static void s_vQosAdjProf (char aszArgus[][ARGU_SIZE]);
static void s_vSecuGblCfg (char aszArgus[][ARGU_SIZE]);
static void s_vRateOverHeadCfg (char aszArgus[][ARGU_SIZE]);
static void s_vRateEgrsCfg (char aszArgus[][ARGU_SIZE]);
static void s_vRateCfg (char aszArgus[][ARGU_SIZE]);
static void s_vTrkCfg (char aszArgus[][ARGU_SIZE]);
static void s_vSTPCfg (char aszArgus[][ARGU_SIZE]);
static void s_vMSTPCfg(char aszArgus[][ARGU_SIZE]);
static void s_vGMRPTb(char aszArgus[][ARGU_SIZE]);
static void s_vIGMPTb(char aszArgus[][ARGU_SIZE]);
static void s_vProVlanTb (char aszArgus[][ARGU_SIZE]);
static void s_vTest (char aszArgus[][ARGU_SIZE]);
static void s_vVerGet(char aszArgus[][ARGU_SIZE]);
static void s_vSendPkt(char aszArgus[][ARGU_SIZE]);
static void s_vSwInit(char aszArgus[][ARGU_SIZE]);
static void s_bClearTblNonStaticEntry(char aszArgus[][ARGU_SIZE]);
//static void s_vShowMacAddr(char aszArgus[][ARGU_SIZE]);
void s_vShowMacAddr(char aszArgus[][ARGU_SIZE]);
static void s_vShowBusType(char aszArgus[][ARGU_SIZE]);
static void s_vDumpPmac(char aszArgus[][ARGU_SIZE]);
/*--------------------- Static Variables --------------------------*/
// command table.
static SCmdMap s_aSCmdTbl[] =
{
{ "reg", s_vRegOp },
{ "phy", s_vPhyOp },
{ "sram", s_vSramOp },
{ "mac_log", s_vLogTb },
{ "mac_pri", s_vPMacTb },
{ "mac_sec", s_vSMacTb },
{ "vlan", s_vVLANTb },
{ "l2p", s_vL2pTb },
#if (NEW_TCAM_CMD)
{ "tcam", s_vTcam },
{ "tcam_mask", s_vTcamMask },
#else
{ "tcam", s_vTcamTb },
#endif
{ "tcam1", s_vTcamTbNonIpv4 },
{ "l2p_hit", s_vL2pHitTb },
{ "mpmt", s_vMPMTb },
{ "mstst", s_vMSTSTb }, //test SWMSTTB_bInsEntry
{ "primap", s_vPriMapTb },
{ "mib", s_vMibCntTb },
{ "ver", s_vVerGet },
{ "sendpkt", s_vSendPkt },
{ "swinit", s_vSwInit },
/*
* Use for debug API only
*/
{ "qos_prec", s_vQosPrec },
{ "qos_adjprof",s_vQosAdjProf },
{ "secu_gbl", s_vSecuGblCfg },
{ "rate_oh", s_vRateOverHeadCfg },
{ "rate_egrs", s_vRateEgrsCfg },
{ "rate", s_vRateCfg },
{ "trk", s_vTrkCfg },
{ "stp", s_vSTPCfg },
{ "mstp", s_vMSTPCfg }, //test SWPROTO_vMstpSetStpState
{ "gmrp", s_vGMRPTb },
{ "igmp", s_vIGMPTb },
{ "provlan", s_vProVlanTb },
{ "line_clr", s_vTest },
{ "mac_clr", s_bClearTblNonStaticEntry },
{ "show_mac", s_vShowMacAddr },
{ "show_bus", s_vShowBusType },
{ "dump_pmac", s_vDumpPmac },
//end
{ 0, 0 }
};
/*--------------------- Export Variables --------------------------*/
/*--------------------- Export Functions --------------------------*/
static void s_vCvtMacValtoStr (char* pszMacStr, char* pzMacVal)
{
INT8 i8u;
// for (si = 0; si < 6; si++) {
for (i8u = 5; i8u >= 0; i8u--) {
STR_iU32ToStrHexPad(pszMacStr+(5-i8u)*2, pzMacVal[i8u], 2);
}
pszMacStr[MAC_STRING_LEN] = 0;
}
static void s_vCvtMacStrtoVal (char* pszMacStr, char* pszMacVal)
{
UINT8 ii;
INT8 i8u;
STR_pvMemset(pszMacVal, 0 , 6);
// for (uu = 0; uu < 6; uu++) {
for (i8u = 5; i8u >= 0; i8u--) {
for (ii = 0; ii < 2; ii++) {
pszMacVal[i8u] = (pszMacVal[i8u] * 16) + STR_cToInt(STR_cToUpper(*pszMacStr));
pszMacStr++;
}
}
}
/************************************************************************
* Check if there are u8ArguNum arguments in aszArgus
************************************************************************/
static BOOL s_bCheckArgus(char aszArgus[][ARGU_SIZE], UINT8 u8ArguNum)
{
UINT8 uu;
for (uu = 0; uu < u8ArguNum; uu++)
{
if (aszArgus[uu][0] == 0)
{
TTY_vPrintf("fail: param[%u] = NULL\n", uu + 1);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -