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

📄 swipmtb.c

📁 vt6528芯片交换机API函数和文档运行程序
💻 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:    swipmtb.c
 *
 * Purpose: IP multicast table operation functions
 *
 * Author:  Henry Lin
 *
 * Date:    May 02, 2005
 *
 * Functions:
 *
 * Revision History:
 *
 */


#if !defined(__STR_H__)
#include "str.h"
#endif
#if !defined(__SWIPMTB_H__)
#include "swipmtb.h"
#endif
#if !defined(__SWGMRPTB_H__)
#include "swgmrptb.h"
#endif




/*---------------------  Static Definitions -------------------------*/

/*---------------------  Static Types  ------------------------------*/

/*---------------------  Static Macros  -----------------------------*/

/*---------------------  Static Classes  ----------------------------*/

/*---------------------  Static Variables  --------------------------*/

/*---------------------  Static Functions  --------------------------*/
static void s_vSetDefaultValue(SGMRPEntry  *pSGmrp);

/*---------------------  Export Variables  --------------------------*/


/*
 * Input : u16Indx: if PMAC entry, vaule between 0 and 8191.
 *                  if BCAM entry, vaule between 8192 and 8447.
 */
BOOL SWIPMTB_bGetEntry(UINT16 u16Indx, SIpmEntry *pSEntry)
{
    SGMRPEntry  SGmrp;
    UINT8   ii;
    

    // If invalid entry, return
    if (SWIPMTB_bIsEntryEmpty(u16Indx))
        return FALSE;

    STR_pvMemset((PUINT8)pSEntry, 0, sizeof(SIpmEntry));
    SWGMRPTB_bGetEntry(u16Indx, &SGmrp);

    // Get IP field
    for (ii = 2 ; ii < 6; ii++){
        pSEntry->dwIpAddr <<= 8;
        pSEntry->dwIpAddr |= (SGmrp.sMacEntry.abyMacAddr[ii]);
    }
    // Get FID field
    pSEntry->u16Vid = SGmrp.sMacEntry.u16Fid;
    // Get port mask field
    pSEntry->u32MbrPortMsk = SGmrp.u32PortMask;
    // Get static field
    pSEntry->bStatic = TRUE;    //if IGMP create, the value apply by protocol
    // Get Binding ID
    pSEntry->byBindId = SGmrp.sMacEntry.byBindId;
    // Get Option
    pSEntry->bSecDropExcp = SGmrp.sMacEntry.bSecDropExcp;
    pSEntry->bNotRedirDmac = SGmrp.sMacEntry.bNotRedirDmac;
    
    return TRUE;
}


UINT16  SWIPMTB_wSearchEntry(UINT32 dwIPKey, UINT16 wVidKey)
{
    UINT8 abyMacAddr[6];
    INT8        i8Cnt;

    
    abyMacAddr[5] = 0x01;
    abyMacAddr[4] = 0x00;
    //Fill Ip address to Mac[0~3]
    for (i8Cnt = 3 ; i8Cnt >= 0; i8Cnt--)
        abyMacAddr[i8Cnt] = (UINT8)(dwIPKey >> (8*i8Cnt));
    
    return (SWGMRPTB_wSearchEntry(abyMacAddr, wVidKey));
}


BOOL SWIPMTB_bInsEntry(SIpmEntry *pSInsEntry, BOOL bIsOverWrite)
{
    SGMRPEntry  SGmrp;
    INT8        i8Cnt;

    STR_pvMemset((PUINT8)&SGmrp, 0, sizeof(SGMRPEntry));
    s_vSetDefaultValue(&SGmrp);
    
    //
    // Use B-CAM ,SMAC and MPM.
    //
    
    SGmrp.u32PortMask = pSInsEntry->u32MbrPortMsk;
    //Fill Ip address to abyMacAddr[0~3]
    for (i8Cnt = 3 ; i8Cnt >= 0; i8Cnt--)
        SGmrp.sMacEntry.abyMacAddr[i8Cnt] = (UINT8)(pSInsEntry->dwIpAddr >> (8*i8Cnt));
    SGmrp.sMacEntry.u16Fid  = pSInsEntry->u16Vid;
    SGmrp.sMacEntry.byBindId= pSInsEntry->byBindId;
    SGmrp.sMacEntry.bSecDropExcp    = pSInsEntry->bSecDropExcp;
    SGmrp.sMacEntry.bNotRedirDmac   = pSInsEntry->bNotRedirDmac;

    if (pSInsEntry->bBindIdValid)
        SWGMRPTB_bInsEntryInSMT(&SGmrp, bIsOverWrite);
    else{
        SGmrp.sMacEntry.byBindId= 0;
        SWGMRPTB_bInsEntry(&SGmrp, bIsOverWrite);
    }

    return TRUE;
}


BOOL SWIPMTB_bDelEntry(UINT32 dwIpKey, UINT16 wVidKey)
{
    UINT8 abyMacAddr[6];
    INT8        i8Cnt;


    abyMacAddr[5] = 0x01;
    abyMacAddr[4] = 0x00;
    //Fill Ip address to Mac[0~3]
    for (i8Cnt = 3 ; i8Cnt >= 0; i8Cnt--)
        abyMacAddr[i8Cnt] = (UINT8)(dwIpKey >> (8*i8Cnt));
    
    return (SWGMRPTB_bDelEntry(abyMacAddr, wVidKey));
}


static void s_vSetDefaultValue(SGMRPEntry  *pSGmrp)
{
    pSGmrp->sMacEntry.abyMacAddr[5] = 0x01;
    pSGmrp->sMacEntry.abyMacAddr[4] = 0x00;
    pSGmrp->sMacEntry.bIpMcst       = TRUE;
    pSGmrp->sMacEntry.bTypeMcst     = TRUE;
    pSGmrp->sMacEntry.bStatic       = TRUE;
    
    //for PMAC
    pSGmrp->sMacEntry.bPriDmac      = 1;    //IP multicast address
}


/*
 * Input : u16Indx: if PMAC entry, vaule between 0 and 8191.
 *                  if BCAM entry, vaule between 8192 and 8447.
 */
BOOL SWIPMTB_bIsEntryEmpty(UINT16 u16Indx)
{

    if (IS_PMAC_ENTRY(u16Indx) ){
        // this is a pmac index
        return (SWMACTB_bIsEntryEmpty(u16Indx));
    }
    else{
        // this is a bcam index
        u16Indx -= PMAC_SLOT_NUM;
        return (SWSMACBCAM_bIsEntryEmpty(u16Indx));
    }
}

⌨️ 快捷键说明

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