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

📄 tclcmd.c

📁 vt6528芯片交换机API函数和文档运行程序
💻 C
📖 第 1 页 / 共 5 页
字号:
    UINT16     u16Fid, u16Tmp;
    SMacEntry  SEntry;
    BOOL        bOverWrite;
    UINT16     u16Indx;


    // check arguments
    if (!s_bCheckArgus(&aszArgus[1], 3)) {
        return;
    }    
    
    pszOp  = aszArgus[1];
    pszMac = aszArgus[2];
    u16Fid = STR_u32StrHexToU32(aszArgus[3]);
    s_vCvtMacStrtoVal(pszMac, (char*)au8MacAddr);
    
    if (0 == STR_iStrcmp("read", pszOp)) {
        //TTY_vPutStr("1122334455FF,1,1,00FF,1,0,1,3\r");
        u16Indx = SWMACTB_wSearchEntry(au8MacAddr, u16Fid);

        if (u16Indx == UINT16_MAX) {
            TTY_vPutStr("fail: no such entry.\r");
            return;
        }
        else {
            STR_pvMemset(pszBuf, 0, MAX_BUF_SIZE);
            
            if (!SWMACTB_bGetEntry(u16Indx, &SEntry)){
                TTY_vPutStr("empty entry.\r");
                return;
            }
            
            s_vCvtMacValtoStr (szMacStr, (char*)SEntry.abyMacAddr);
            pszBuf += STR_iStrcpy(pszBuf, szMacStr);                APPEND_SPACE(pszBuf);  // bit 63~28
            pszBuf += STR_iU32ToStrDec(pszBuf, SEntry.bStatic);     APPEND_SPACE(pszBuf);  // bit 27
            pszBuf += STR_iU32ToStrDec(pszBuf, SEntry.bTypeMcst);   APPEND_SPACE(pszBuf);  // bit 26
            
            if (!SEntry.bTypeMcst) { // unicast                                            // bit 25~16, binary(ex:10111) and dec
                pszBuf += STR_iU32ToStrDec(pszBuf, SEntry.bFltrSmac);
                pszBuf += STR_iU32ToStrDec(pszBuf, SEntry.bNotRedirSmac);
                pszBuf += STR_iU32ToStrDec(pszBuf, SEntry.bPriSmac);
                pszBuf += STR_iU32ToStrDec(pszBuf, SEntry.bCpuInv);
                pszBuf += STR_iU32ToStrDec(pszBuf, SEntry.bTrkGrp); APPEND_SPACE(pszBuf);
                
                pszBuf += STR_iU32ToStrDec(pszBuf, SEntry.u8SrcId);
            }
            else { // multicast
                pszBuf += STR_iU32ToStrHexPad(pszBuf, SEntry.u16McstIdx, 4);
            }
            APPEND_SPACE(pszBuf);

            if (SEntry.bStatic) { // static                                            // bit 15~13, binary(ex:101)
                pszBuf += STR_iU32ToStrDec(pszBuf, SEntry.bSecDropExcp);
                pszBuf += STR_iU32ToStrDec(pszBuf, SEntry.bPriDmac);
                pszBuf += STR_iU32ToStrDec(pszBuf, SEntry.bNotRedirDmac);
            }
            else { // dynamic
                pszBuf += STR_iU32ToStrDec(pszBuf, SEntry.u8AgeCnt);
            }
            APPEND_SPACE(pszBuf);
            pszBuf += STR_iU32ToStrDec(pszBuf, SEntry.u16Fid);

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

        STR_pvMemset(&SEntry, 0, sizeof(SMacEntry));
        STR_pvMemcpy(SEntry.abyMacAddr, au8MacAddr, MAC_ADDR_SIZE);
        SEntry.u16Fid   = u16Fid;
        SEntry.bStatic  = STR_u32StrDecToU32(aszArgus[4]);
        SEntry.bTypeMcst= STR_u32StrDecToU32(aszArgus[5]);
        u16Tmp          = STR_u32StrHexToU32(aszArgus[6]);
        bOverWrite      = STR_u32StrHexToU32(aszArgus[8]);
        if (!SEntry.bTypeMcst) { // unicast
            SEntry.bFltrSmac     = (u16Tmp & 0x0200) ? TRUE : FALSE;
            SEntry.bNotRedirSmac = (u16Tmp & 0x0100) ? TRUE : FALSE;
            SEntry.bPriSmac      = (u16Tmp & 0x0080) ? TRUE : FALSE;
            SEntry.bCpuInv       = (u16Tmp & 0x0040) ? TRUE : FALSE;
            SEntry.bTrkGrp       = (u16Tmp & 0x0020) ? TRUE : FALSE;
            SEntry.u8SrcId       = (u16Tmp & 0x001F);
        }
        else { // multicast
            SEntry.u16McstIdx    = u16Tmp;
        }

        u16Tmp = STR_u32StrHexToU32(aszArgus[7]);
        if (SEntry.bStatic) { // static
            SEntry.bSecDropExcp  = (u16Tmp & 0x04) ? TRUE : FALSE;
            SEntry.bPriDmac      = (u16Tmp & 0x02) ? TRUE : FALSE;
            SEntry.bNotRedirDmac = (u16Tmp & 0x01) ? TRUE : FALSE;
        }
        else { // dynamic
            SEntry.u8AgeCnt = u16Tmp;
        }

        if (!SWMACTB_bInsEntry(&SEntry, bOverWrite)) {
            TTY_vPutStr("fail: insert conflict.\r");
            return;
        }
        TTY_vPutStr("success.\r");
    }
    else if (0 == STR_iStrcmp("del", pszOp)) {
        if (!SWMACTB_bDelEntry(au8MacAddr, u16Fid)) {
            TTY_vPutStr("fail: no such entry.\r");
            return;
        }
        TTY_vPutStr("success.\r");
    }
}

// secondary mac table command.
//  1st param :  read/write/del
//  2nd param :  mac address
//  3rd param :  fid
//  4th param (write): match address type (dec, BCAM, Bit[15])
//  5th parma (write): binding ID         (dec, SMAC, Bit[23:16])
//  6th param (write): option             (hex,       Bit[15:13])
//  7th param (write): static             (dec,       Bit[11])
//  8th param (write): port index type    (dec,       Bit[10])
//  9th param (write): port index         (hex,       Bit[9:0])
static void s_vSMacTb (char aszArgus[][ARGU_SIZE])
{
    char       aszOutBuf[MAX_BUF_SIZE];
    char       *pszOp, *pszMac, *pszBuf = aszOutBuf;
    UINT8      au8MacAddr[MAC_ADDR_SIZE];
    UINT16     u16Fid = 0, u16Tmp;
    SMacEntry  SEntry;
    UINT16     u16Indx;
    

    // check arguments
    if (!s_bCheckArgus(&aszArgus[1], 3)) {
        return;
    }  
          
    pszOp  = aszArgus[1];
    pszMac = aszArgus[2];
    u16Fid = STR_u32StrHexToU32(aszArgus[3]);
    s_vCvtMacStrtoVal(pszMac, (char*)au8MacAddr);
    
    if (0 == STR_iStrcmp("read", pszOp)) {
        //TTY_vPutStr("1122334455FF,0,3,1,1,1,1,1,1,00FF\r");
        u16Indx = SWSMACBCAM_wSearchEntry(au8MacAddr, u16Fid);
        if (u16Indx == UINT16_MAX) {
            TTY_vPutStr("fail: no such entry.\r");
            return;
        }
        else {
            if (FALSE == SWSMACTB_bGetEntry(u16Indx, &SEntry)) {
                TTY_vPutStr("fail: no such entry.\r");
                return;
            }

            STR_pvMemset(pszBuf, 0, MAX_BUF_SIZE);
            pszBuf += STR_iStrcpy(pszBuf, pszMac);              APPEND_SPACE(pszBuf);  // Bcam, bit 63~16
            pszBuf += STR_iU32ToStrDec(pszBuf, SEntry.bIpMcst); APPEND_SPACE(pszBuf);  // bit 15
            pszBuf += STR_iU32ToStrDec(pszBuf, u16Fid);         APPEND_SPACE(pszBuf);  // bit 12~0

            pszBuf += STR_iU32ToStrDec(pszBuf, SEntry.byBindId); APPEND_SPACE(pszBuf);  // Smac, bit 23~16                                                                                        
            if (SEntry.bStatic) { // static                                             // bit 15~13, binary(ex:101)
                pszBuf += STR_iU32ToStrDec(pszBuf, SEntry.bSecDropExcp);
                pszBuf += STR_iU32ToStrDec(pszBuf, SEntry.bPriDmac);
                pszBuf += STR_iU32ToStrDec(pszBuf, SEntry.bNotRedirDmac);
            }
            else { // dynamic
                pszBuf += STR_iU32ToStrDec(pszBuf, SEntry.u8AgeCnt);
            }
            APPEND_SPACE(pszBuf);
            pszBuf += STR_iU32ToStrDec(pszBuf, SEntry.bStatic);     APPEND_SPACE(pszBuf);  // bit 11
            pszBuf += STR_iU32ToStrDec(pszBuf, SEntry.bTypeMcst);   APPEND_SPACE(pszBuf);  // bit 10                                                                                        
            if (!SEntry.bTypeMcst) { // unicast                                            // bit 9~0, binary(ex:10111) and dec
                pszBuf += STR_iU32ToStrDec(pszBuf, SEntry.bFltrSmac);
                pszBuf += STR_iU32ToStrDec(pszBuf, SEntry.bNotRedirSmac);
                pszBuf += STR_iU32ToStrDec(pszBuf, SEntry.bPriSmac);
                pszBuf += STR_iU32ToStrDec(pszBuf, SEntry.bCpuInv);
                pszBuf += STR_iU32ToStrDec(pszBuf, SEntry.bTrkGrp); APPEND_SPACE(pszBuf);
                
                pszBuf += STR_iU32ToStrDec(pszBuf, SEntry.u8SrcId);
            }
            else { // multicast
                pszBuf += STR_iU32ToStrHexPad(pszBuf, SEntry.u16McstIdx, 4);
            }

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

        STR_pvMemset(&SEntry, 0, sizeof(SMacEntry));
        STR_pvMemcpy(SEntry.abyMacAddr, au8MacAddr, MAC_ADDR_SIZE);
        SEntry.u16Fid   = u16Fid;
        SEntry.bIpMcst  = STR_u32StrDecToU32(aszArgus[4]);
        SEntry.byBindId = STR_u32StrDecToU32(aszArgus[5]);
        SEntry.bStatic  = STR_u32StrDecToU32(aszArgus[7]);
        SEntry.bTypeMcst= STR_u32StrDecToU32(aszArgus[8]);

        u16Tmp = STR_u32StrHexToU32(aszArgus[6]);
        if (TRUE == SEntry.bStatic) { // static
            SEntry.bSecDropExcp  = (u16Tmp & 0x04);
            SEntry.bPriDmac      = (u16Tmp & 0x02);
            SEntry.bNotRedirDmac = (u16Tmp & 0x01);
        }
        else { // dynamic
            SEntry.u8AgeCnt = u16Tmp;
        }

        u16Tmp = STR_u32StrHexToU32(aszArgus[9]);
        if (FALSE == SEntry.bTypeMcst) { // unicast
            SEntry.bFltrSmac     = (u16Tmp & 0x0200) ? TRUE : FALSE;
            SEntry.bNotRedirSmac = (u16Tmp & 0x0100) ? TRUE : FALSE;
            SEntry.bPriSmac      = (u16Tmp & 0x0080) ? TRUE : FALSE;
            SEntry.bCpuInv       = (u16Tmp & 0x0040) ? TRUE : FALSE;
            SEntry.bTrkGrp       = (u16Tmp & 0x0020) ? TRUE : FALSE;
            SEntry.u8SrcId       = (u16Tmp & 0x001F);
        }
        else { // multicast
            SEntry.u16McstIdx    = u16Tmp;
        }

        if (!SWSMACTB_bInsEntry(&SEntry, TRUE)) {
            TTY_vPutStr("fail: insert conflict.\r");
            return;
        }
        TTY_vPutStr("success.\r");
    }
    else if (0 == STR_iStrcmp("del", pszOp)) {
        if (!SWSMACTB_bDelEntry(au8MacAddr, u16Fid)) {
            TTY_vPutStr("fail: no such entry.\r");
            return;
        }
        TTY_vPutStr("success.\r");
    }
}

/************************************************************************
 * Raw edition of VLAN Ins Entry
 * Do not insert CPU port into Egress Member
 ************************************************************************/
static BOOL 
s_bVlanSetEntry (SVlanEntry* pSEntry)
{
    
#define VID_NUM_8021Q               4096
#define VLAN_ENTRY_SIZE             SRAM_ENTRY_SIZE_16Byte

    UINT8   au8EntryBuf[VLAN_ENTRY_SIZE];
    UINT32  dwAddr;


    //Internal VLAN Enable?
    if (pSEntry->u16Vid >= VID_NUM_8021Q){
        if (!SWVLANTB_bIsIntEntryValid(pSEntry->u16Vid))
            return FALSE;
    }
    
    //insert entry to VLAN or PMAC table
    dwAddr = SWVLANTB_dwVidToSramAddr(pSEntry->u16Vid);
    if (dwAddr == UINT32_MAX)
        return FALSE;   //vid out of range

    // Set entry content and write into sram
    STR_pvMemset(au8EntryBuf, 0, VLAN_ENTRY_SIZE);
    // Set fid field
    SWSRAM_vModifyBits(au8EntryBuf, VLAN_BIT_FID_S, VLAN_BIT_FID_E, (PUINT8)&pSEntry->u16Fid);
#if (0)
    // Set egress membership field, CPU port MUST be all of the vlan member
    pSEntry->u32EgrsMbrPortMsk |= BIT_MASK_PORT_CPU;
#endif
    SWSRAM_vModifyBits(au8EntryBuf, VLAN_BIT_EGRS_MEMBER_S, VLAN_BIT_EGRS_MEMBER_E, (PUINT8)&pSEntry->u32EgrsMbrPortMsk);
    // Set ingress membership field
    SWSRAM_vModifyBits(au8EntryBuf, VLAN_BIT_INGRS_MEMBER_S, VLAN_BIT_INGRS_MEMBER_E, (PUINT8)&pSEntry->u32IngrsMbrPortMsk);
    // Set tag-rule field
    SWSRAM_vModifyBits(au8EntryBuf, VLAN_BIT_TAG_S, VLAN_BIT_TAG_E, (PUINT8)&pSEntry->u32TagPortMsk);

    // Set VLAN valid field
    au8EntryBuf[15] |= VLAN_BPTN_VALID_VLAN;

    // Set jumbo field
    SWSRAM_vModifyBitsByBool(au8EntryBuf, VLAN_BIT_JUMBO_PASS_S, VLAN_BIT_JUMBO_PASS_E, &pSEntry->bJumboPass);
    // Set priority adjustment field
    SWSRAM_vModifyBitsByBool(au8EntryBuf, VLAN_BIT_PRI_ADJ_S, VLAN_BIT_PRI_ADJ_E, &pSEntry->bPriAdj);
    // Set ToS/DSCP-to-802.1p field
    SWSRAM_vModifyBitsByBool(au8EntryBuf, VLAN_BIT_TOS_MAP_1P_S, VLAN_BIT_TOS_MAP_1P_E, &pSEntry->bTosTo8021p);
    // Set cpu forward cfg field
    SWSRAM_vModifyBitsByByte(au8EntryBuf, VLAN_BIT_CPU_FWD_S, VLAN_BIT_CPU_FWD_E,  &pSEntry->u8CpuFwd);
    // Set per-VLAN priority field
    SWSRAM_vModifyBitsByByte(au8EntryBuf, VLAN_BIT_PER_VLAN_PRI_S, VLAN_BIT_PER_VLAN_PRI_E,  &pSEntry->u8PerVlanPri);
    // Set per-VLAN priority valid field
    SWSRAM_vModifyBitsByBool(au8EntryBuf, VLAN_BIT_PER_VLAN_VALID_S, VLAN_BIT_PER_VLAN_VALID_E, &pSEntry->bPerVlanPriVld);

    // Set verbatim mode field
    SWSRAM_vModifyBitsByBool(au8EntryBuf, VLAN_BIT_VERBATIM_MODE_S, VLAN_BIT_VERBATIM_MODE_E, &pSEntry->bVerbMode);
    // Set local tag rule field
    SWSRAM_vModifyBitsByBool(au8EntryBuf, VLAN_BIT_LOCAL_TAG_S, VLAN_BIT_LOCAL_TAG_E, &pSEntry->bLocTagRule);
    // Set MSTID field
    SWSRAM_vModifyBitsByByte(au8EntryBuf, VLAN_BIT_MSTID_S, VLAN_BIT_MSTID_E,  &pSEntry->u8MstId);
    // Set MSTID valid field
    SWSRAM_vModifyBitsByBool(au8EntryBuf, VLAN_BIT_MSTID_VALID_S, VLAN_BIT_MSTID_VALID_E, &pSEntry->bMstIdVld);

    SWSRAM_bWriteEntry(dwAddr, au8EntryBuf);

    return TRUE;
    
} /* end s_bVlanSetEntry */


/************************************************************************
 * vlan table command.
 * param[1]         : read/write/del
 * param[2]         : vid                          (dec)
 * param[3]  (write): mst valid                    (dec, Bit[126])
 * param[4]  (write): mst id                       (dec, Bit[125:120])
 * param[5]  (write): local tag rule enable        (dec, Bit[110])
 * param[6]  (write): verbatim mode                (dec, Bit[109])
 * param[7]  (write): fid                          (dec, Bit[108:96])
 * param[8]  (write): per-vlan priority valid      (dec, Bit[95])
 * param[9]  (write): per-vlan priority            (dec, Bit[94:92])
 * param[10] (write): egress tag rule              (hex, Bit[89:64])
 * param[11] (write): cpu forward config.          (hex, Bit[63:60])
 * param[12] (write): ingress membership           (hex, Bit[57:32])
 * param[13] (write): tos/dscp-to-802.1p mapping   (dec, Bit[31])

⌨️ 快捷键说明

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