⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tclcmd.c

📁 vt6528芯片交换机API函数和文档运行程序
💻 C
📖 第 1 页 / 共 5 页
字号:
 * param[14] (write): priority adjustment enable   (dec, Bit[30])
 * param[15] (write): jumbo packet pass enable     (dec, Bit[29])
 * param[16] (write): egress membership            (hex, Bit[26:0])
*************************************************************************/
static void s_vVLANTb (char aszArgus[][ARGU_SIZE])
{
    char        aszOutBuf[MAX_BUF_SIZE];
    char        *pszOp, *pszBuf = aszOutBuf;
    UINT16      u16Vid = 0;
    SVlanEntry  SEntry;
    UINT32      dwAddr;

    // check arguments
    if (!s_bCheckArgus(&aszArgus[1], 2)) {
        return;
    }  

    pszOp  = aszArgus[1];
    u16Vid = STR_u32StrDecToU32(aszArgus[2]);

    if (0 == STR_iStrcmp("read", pszOp)) {
        //TTY_vPutStr("1,0,0,0,0,1,0,1,000011FF,00,000000FF,0,0,1,000000FF\r");

        dwAddr = SWVLANTB_dwVidToSramAddr(u16Vid);
        if (dwAddr == UINT32_MAX){
            TTY_vPutStr("fail: vid out of range.\r");
            return ;
        }

        if (FALSE == SWVLANTB_bGetEntry(u16Vid, &SEntry)) {
            TTY_vPutStr("fail: entry invalid.\r");
            return;
        }
        else {
            STR_pvMemset(pszBuf, 0, MAX_BUF_SIZE);
            pszBuf += STR_iU32ToStrDec(pszBuf, SEntry.u16Vid);                  APPEND_SPACE(pszBuf);
            pszBuf += STR_iU32ToStrDec(pszBuf, SEntry.bMstIdVld);               APPEND_SPACE(pszBuf); // bit 126
            pszBuf += STR_iU32ToStrDec(pszBuf, SEntry.u8MstId);                 APPEND_SPACE(pszBuf); // bit 125~120
            pszBuf += STR_iU32ToStrDec(pszBuf, SEntry.bLocTagRule);             APPEND_SPACE(pszBuf); // bit 110
            pszBuf += STR_iU32ToStrDec(pszBuf, SEntry.bVerbMode);               APPEND_SPACE(pszBuf); // bit 109
            pszBuf += STR_iU32ToStrDec(pszBuf, SEntry.u16Fid);                  APPEND_SPACE(pszBuf); // bit 108~96
            pszBuf += STR_iU32ToStrDec(pszBuf, SEntry.bPerVlanPriVld);          APPEND_SPACE(pszBuf); // bit 95
            pszBuf += STR_iU32ToStrDec(pszBuf, SEntry.u8PerVlanPri);            APPEND_SPACE(pszBuf); // bit 94~92
            pszBuf += STR_iU32ToStrHexPad(pszBuf, SEntry.u32TagPortMsk, 8);     APPEND_SPACE(pszBuf);  // bit 89~64
            pszBuf += STR_iU32ToStrHexPad(pszBuf, SEntry.u8CpuFwd, 2);          APPEND_SPACE(pszBuf);  // bit 63~60
            pszBuf += STR_iU32ToStrHexPad(pszBuf, SEntry.u32IngrsMbrPortMsk, 8);APPEND_SPACE(pszBuf);  // bit 57~32
            pszBuf += STR_iU32ToStrDec(pszBuf, SEntry.bTosTo8021p);             APPEND_SPACE(pszBuf);   // bit 31
            pszBuf += STR_iU32ToStrDec(pszBuf, SEntry.bPriAdj);                 APPEND_SPACE(pszBuf);   // bit 30
            pszBuf += STR_iU32ToStrDec(pszBuf, SEntry.bJumboPass);              APPEND_SPACE(pszBuf);   // bit 29
            pszBuf += STR_iU32ToStrHexPad(pszBuf, SEntry.u32EgrsMbrPortMsk, 8);             // bit 26~0

            TTY_vPutStr(STR_pszStrcatchr(aszOutBuf, '\r'));
        }

    }
    else if (0 == STR_iStrcmp("write", pszOp)) {
        // check arguments
        if (!s_bCheckArgus(&aszArgus[3], 14)) {
            return;
        }
        STR_pvMemset(&SEntry, 0, sizeof(SVlanEntry));
        SEntry.u16Vid             = u16Vid;
        SEntry.bMstIdVld          = STR_u32StrDecToU32(aszArgus[3]);
        SEntry.u8MstId            = STR_u32StrDecToU32(aszArgus[4]);
        SEntry.bLocTagRule        = STR_u32StrDecToU32(aszArgus[5]);
        SEntry.bVerbMode          = STR_u32StrDecToU32(aszArgus[6]);
        SEntry.u16Fid             = STR_u32StrDecToU32(aszArgus[7]);
        SEntry.bPerVlanPriVld     = STR_u32StrDecToU32(aszArgus[8]);
        SEntry.u8PerVlanPri       = STR_u32StrDecToU32(aszArgus[9]);
        SEntry.u32TagPortMsk      = STR_u32StrHexToU32(aszArgus[10]);
        SEntry.u8CpuFwd           = STR_u32StrHexToU32(aszArgus[11]);
        SEntry.u32IngrsMbrPortMsk = STR_u32StrHexToU32(aszArgus[12]);
        SEntry.bTosTo8021p        = STR_u32StrDecToU32(aszArgus[13]);
        SEntry.bPriAdj            = STR_u32StrDecToU32(aszArgus[14]);
        SEntry.bJumboPass         = STR_u32StrDecToU32(aszArgus[15]);
        SEntry.u32EgrsMbrPortMsk  = STR_u32StrHexToU32(aszArgus[16]);

        s_bVlanSetEntry(&SEntry);

        TTY_vPutStr("success.\r");

    }
    else if (0 == STR_iStrcmp("del", pszOp)) {
        dwAddr = SWVLANTB_dwVidToSramAddr(u16Vid);
        if (dwAddr == UINT32_MAX){
            TTY_vPutStr("fail: vid out of range.\r");
            return ;
        }
        if (!SWVLANTB_bDelEntry(u16Vid)) {
            TTY_vPutStr("fail: del fail.\r");
            return;
        }

        TTY_vPutStr("success.\r");
    }
}


// protocol vlan table command.(provlan)
//  1st param        : read/write/del
//  2nd param        : type     (hex, 2bytes)
//  3rd param        : vid      (dec)
//  4th param        : frame format idex ( 0:FRAME_FRMT_ETHER2_IPV4, 1:FRAME_FRMT_ETHER2, 2:FRAME_FRMT_RFC1042, 3:FRAME_FRMT_802_1H, 4:FRAME_FRMT_SANP_OTHERS, 5:FRAME_FRMT_LLC)
//  5th param (write): VLAN-tag type ( 0:not VLAN-tagged, 1:VLAN-tagged packet)
//  6th param        : OUI0     (hex, 1bytes)   //only use when frame format == FRAME_FRMT_SANP_OTHERS
//  7th param        : OUI1     (hex, 1bytes)   //only use when frame format == FRAME_FRMT_SANP_OTHERS
//  8th param        : OUI2     (hex, 1bytes)   //only use when frame format == FRAME_FRMT_SANP_OTHERS
static void s_vProVlanTb (char aszArgus[][ARGU_SIZE])
{
    char    aszOutBuf[MAX_BUF_SIZE];
    char    *pszOp, *pszBuf = aszOutBuf;
    UINT16  u16EntryIdx;
    UINT16  u16Type, u16Vid;
    UINT8    byFormat;
    BOOL    bIsOverWrite;
    SProVlanEntry SEntry;


    // check arguments
    if (!s_bCheckArgus(&aszArgus[1], 4))
        return;

    pszOp    = aszArgus[1];
    u16Type  = STR_u32StrHexToU32(aszArgus[2]);
    u16Vid   = STR_u32StrDecToU32(aszArgus[3]);
    byFormat = STR_u32StrDecToU32(aszArgus[4]);


    if (0 == STR_iStrcmp("read", pszOp)) {
        //TTY_vPutStr("Type,vid,format,TagPkt\r");
        //TTY_vPutStr("0806,100,1,0\r");
        
        u16EntryIdx = SWPRVTB_u16SearchEntry(u16Type, u16Vid, byFormat);
        if (u16EntryIdx == UINT16_MAX){
            TTY_vPutStr("fail: entry not exist.\r");return ;
        }
        
        STR_pvMemset(&SEntry, 0, sizeof(SProVlanEntry));
        SWPRVTB_bGetEntry(u16EntryIdx, &SEntry);
    
        STR_pvMemset(pszBuf, 0, MAX_BUF_SIZE);
        pszBuf += STR_iU32ToStrHexPad(pszBuf, SEntry.u16Type, 4);   APPEND_SPACE(pszBuf);
        pszBuf += STR_iU32ToStrDec(pszBuf, SEntry.u16Vid);          APPEND_SPACE(pszBuf);
        pszBuf += STR_iU32ToStrDec(pszBuf, SEntry.byFrameFormat);   APPEND_SPACE(pszBuf);
        pszBuf += STR_iU32ToStrDec(pszBuf, SEntry.bTagPkt);
        TTY_vPutStr(STR_pszStrcatchr(aszOutBuf, '\r'));

    }
    else if (0 == STR_iStrcmp("write", pszOp)) {
        // check arguments
        if (!s_bCheckArgus(&aszArgus[5], 1)) {
            return;
        }

        STR_pvMemset(&SEntry, 0, sizeof(SProVlanEntry));
        SEntry.u16Type              = u16Type;
        SEntry.u16Vid               = u16Vid;
        SEntry.byFrameFormat        = byFormat;
        SEntry.bTagPkt              = STR_u32StrDecToU32(aszArgus[5]);
        if (byFormat >= FRAME_FRMT_SANP_OTHERS)
        {
            SEntry.abyOUI[0]            = STR_u32StrHexToU32(aszArgus[6]);
            SEntry.abyOUI[1]            = STR_u32StrHexToU32(aszArgus[7]);
            SEntry.abyOUI[2]            = STR_u32StrHexToU32(aszArgus[8]);
        }
        bIsOverWrite                = TRUE;

        if (!SWPRVTB_bInsEntry(&SEntry, bIsOverWrite)){
            TTY_vPutStr("fail: Insert fail.\r");return ;
        }
        TTY_vPutStr("success.\r");
    }
    else if (0 == STR_iStrcmp("del", pszOp)) {
        if (!SWPRVTB_bDelEntry(u16Type, u16Vid, byFormat)){
            TTY_vPutStr("fail: del fail.\r");return;
        }
        TTY_vPutStr("success.\r");
    }
}



// L2+ action table command.
//  1st param         : read/write/del
//  2nd param         : entry index (hex)
//  3rd param  (write): l2p vid valid
//  4th param  (write): override vlan tag rule
//  5th param  (write): smac/sip binding id
//  6th param  (write): security drop exception
//  7th param  (write): filter
//  8th param  (write): mirror
//  9th param  (write): rule priority valid
// 10th param  (write): redirect
// 11th param  (write): redirect port index type
// 12th param  (write): redirect port index
// 13th param  (write): rule priority config (dec)
// 14th param  (write): l2+ vid
static void s_vL2pTb (char aszArgus[][ARGU_SIZE])
{
    char       aszOutBuf[MAX_BUF_SIZE];
    char       *pszOp, *pszBuf = aszOutBuf;
    UINT8      u8EntryIdx;
    SL2pACEntry  SEntry;


    // check arguments
    if (!s_bCheckArgus(&aszArgus[1], 2)) {
        return;
    }  
    
    pszOp      = aszArgus[1];
    u8EntryIdx = STR_u32StrHexToU32(aszArgus[2]);

    if (0 == STR_iStrcmp("read", pszOp)) {
        //TTY_vPutStr("1,0,1,0,1,1,1,1,1,00FF,1,1\r");
        if (FALSE == SWL2PAC_bGetEntry(u8EntryIdx, &SEntry)) {
            TTY_vPutStr("fail: entry invalid.\r");
            return;
        }
        else {
            STR_pvMemset(pszBuf, 0, MAX_BUF_SIZE);
            pszBuf += STR_iU32ToStrDec(pszBuf, SEntry.bL2pVidValid); APPEND_SPACE(pszBuf);  // bit 42
            pszBuf += STR_iU32ToStrDec(pszBuf, SEntry.u8OverTag);    APPEND_SPACE(pszBuf);  // bit 41~40
            pszBuf += STR_iU32ToStrDec(pszBuf, SEntry.u8BindId);     APPEND_SPACE(pszBuf);  // bit 39~32
            pszBuf += STR_iU32ToStrDec(pszBuf, SEntry.bSecDrop);     APPEND_SPACE(pszBuf);  // bit 31
            pszBuf += STR_iU32ToStrDec(pszBuf, SEntry.bFilter);      APPEND_SPACE(pszBuf);  // bit 30
            pszBuf += STR_iU32ToStrDec(pszBuf, SEntry.bMirror);      APPEND_SPACE(pszBuf);  // bit 29
            pszBuf += STR_iU32ToStrDec(pszBuf, SEntry.bPriValid);    APPEND_SPACE(pszBuf);  // bit 28
            pszBuf += STR_iU32ToStrDec(pszBuf, SEntry.bRedirEn);     APPEND_SPACE(pszBuf);  // bit 27
            pszBuf += STR_iU32ToStrDec(pszBuf, SEntry.bRedirType);   APPEND_SPACE(pszBuf);  // bit 26
            pszBuf += STR_iU32ToStrHexPad(pszBuf, SEntry.u16RedirPortIndx, 4) ;APPEND_SPACE(pszBuf);// bit 25~16
            pszBuf += STR_iU32ToStrDec(pszBuf, SEntry.u8Pri);              APPEND_SPACE(pszBuf);  // bit 15~13
            pszBuf += STR_iU32ToStrDec(pszBuf, SEntry.u16L2pVid);                                 // bit 12~0
            TTY_vPutStr(STR_pszStrcatchr(aszOutBuf, '\r'));
        }
    }
    else if (0 == STR_iStrcmp("write", pszOp)) {
        // check arguments
        if (!s_bCheckArgus(&aszArgus[3], 12)) {
            return;
        }
        STR_pvMemset(&SEntry, 0, sizeof(SVlanEntry));
        SEntry.bL2pVidValid  = STR_u32StrDecToU32(aszArgus[3]);  // bit 42
        SEntry.u8OverTag     = STR_u32StrDecToU32(aszArgus[4]);  // bit 41~40
        SEntry.u8BindId      = STR_u32StrDecToU32(aszArgus[5]);  // bit 39~32
        SEntry.bSecDrop      = STR_u32StrDecToU32(aszArgus[6]);  // bit 31
        SEntry.bFilter       = STR_u32StrDecToU32(aszArgus[7]);  // bit 30
        SEntry.bMirror       = STR_u32StrDecToU32(aszArgus[8]);  // bit 29
        SEntry.bPriValid     = STR_u32StrDecToU32(aszArgus[9]);  // bit 28
        SEntry.bRedirEn      = STR_u32StrDecToU32(aszArgus[10]); // bit 27
        SEntry.bRedirType    = STR_u32StrDecToU32(aszArgus[11]); // bit 26
        SEntry.u16RedirPortIndx = STR_u32StrHexToU32(aszArgus[12]); // bit 25 ~ 16
        SEntry.u8Pri         = STR_u32StrDecToU32(aszArgus[13]); // bit 15~13
        SEntry.u16L2pVid     = STR_u32StrDecToU32(aszArgus[14]); // bit 12~0

        SWL2PAC_bInsEntry(u8EntryIdx, &SEntry);
        TTY_vPutStr("success.\r");
    }
    else if (0 == STR_iStrcmp("del", pszOp)) {
        SWTCAM_bDelEntry(u8EntryIdx);
        TTY_vPutStr("success.\r");
    }
}

#if (NEW_TCAM_CMD)
/************************************************************************
 * TCAM table command.
 * param[01]         : read/write/del
 * param[02]         : entry index (hex)
 * param[03]  (write): dmac type
 * param[04]  (write): tcp syn
 * param[05]  (write): vlan tag
 * param[06]  (write): vid (dec)
 * param[07]  (write): ipv4
 * param[08]  (write): ipv4 length
 * param[09]  (write): ip fragment
 * param[10]  (write): port id (dec)
 * param[11]  (write): ip protocol (hex)
 * param[12]  (write): source ip
 * param[13]  (write): destination ip
 * param[14]  (write): ip option
 ************************************************************************/
static void
s_vTcam (char aszArgus[][ARGU_SIZE])
{
    char        aszOutBuf[MAX_BUF_SIZE];
    char        *pszOp, *pszBuf = aszOutBuf;
    UINT8       u8EntryIdx;
    STcamEntry  SEntry;
    //BOOL        bIsIpv4 = TRUE;

    // check arguments
    if (!s_bCheckArgus(&aszArgus[1], 2)) {
        return;
    }

    pszOp        = aszArgus[1];
    u8EntryIdx   = STR_u32StrHexToU32(aszArgus[2]);

    if (0 == STR_iStrcmp("read", pszOp)) {
        if (FALSE == SWTCAM_bGetEntry(u8EntryIdx, &SEntry, 0))
        {
            TTY_vPutStr("fail: entry invalid.\r");
            return;
        }
        else {
            STR_pvMemset(pszBuf, 0, MAX_BUF_SIZE);
            pszBuf += STR_iU32ToStrDec(pszBuf, SEntry.u8DmacType); APPEND_SPACE(pszBuf);  // bit 127~126
            pszBuf += STR_iU32ToStrDec(pszBuf, SEntry.bTcpSynBit); APPEND_SPACE(pszBuf);  // bit 125
            pszBuf += STR_iU32ToStrDec(pszBuf, SEntry.bVlanTag);   APPEND_SPACE(pszBuf);  // bit 124
            pszBuf += STR_iU32ToStrDec(pszBuf, SEntry.u16Vid);     APPEND_SPACE(pszBuf);  // bit 123~112
            pszBuf += STR_iU32ToStrDec(pszBuf, SEntry.bIpv4);      APPEND_SPACE(pszBuf);  // bit 111
            pszBuf += STR_iU32ToStrDec(pszBuf, SEntry.bIpHd20Oct); APPEND_SPACE(pszBuf);  // bit 110
            pszBuf += STR_iU32ToStrDec(pszBuf, SEntry.bIpFrag);    APPEND_SPACE(pszBuf);  // bit 109
            pszBuf += STR_iU32ToStrDec(pszBuf, SEntry.u8PortId);   APPEND_SPACE(pszBuf);  // bit 108~104
            
            pszBuf += STR_iU32ToStrHexPad(pszBuf, SEntry.UCfg13B.SIpv4Fld.u8IpProto, 2);APPEND_SPACE(pszBuf);  // bit 103~96
            pszBuf += STR_iU32ToStrHexPad(pszBuf, SEntry.UCfg13B.SIpv4Fld.u32SrcIp, 8); APPEND_SPACE(pszBuf);  // bit 95~64
            pszBuf += STR_iU32ToStrHexPad(pszBuf, SEntry.UCfg13B.SIpv4Fld.u32DstIp, 8); APPEND_SPACE(pszBuf);  // bit 63~32
            pszBuf += STR_iU32ToStrHexPad(pszBuf, SEntry.UCfg13B.SIpv4Fld.u32IpOption, 8);                     // bit 31~0

            TTY_vPutStr(STR_pszStrcatchr(aszOutBuf, '\r'));
        }
    }
    else if (0 == STR_iStrcmp("write", pszOp)) {
        // check arguments
        if (!s_bCheckArgus(&aszArgus[1], 14)) {
            return;
        }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -