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

📄 pimacfltmd.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:    pimacflt.c
 *
 * Purpose: mac table filter module UI definitions
 *
 * Author:  Tim Feng
 *
 * Date:    Jan 13, 2006
 *
 * Functions:
 *
 * Revision History:
 *
 */


#include "str.h"
#include "swsys.h"

#if !defined(__SWPMACTB_H__)
#include "swpmactb.h"
#endif

#if !defined(__SWSMACTB_H__)
#include "swsmactb.h"
#endif

#if !defined(__SWSECU_H__)
#include "swsecu.h"
#endif

#if !defined(__SWMACTBLSCAN_H__)
#include "swmactblscan.h"
#endif

#include "piportmp.h"

#include "pimacfltmd.h"
#include "pimacfltep.h"
/*---------------------  Static Definitions -------------------------*/
// Definitions to reduce statement length
#define pSCurGrp            (&pSPageBuf->SCurGrp)

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

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

/*---------------------  Static Functions  --------------------------*/
void s_vSetEepDefault (SMacFltPageCfg *pSPageBuf, BOOL bWriteDefault);

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

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

/*---------------------  Export Functions  --------------------------*/

// Get config from EEPROM and set into page buf
void PIMACFLT_vInitPage (SMacFltPageCfg *pSPageBuf)
{
    STR_pvMemset(pSPageBuf, 0, sizeof(SMacFltPageCfg));

    PIMACFLTEP_vStatisTblInfo(pSPageBuf);
}


// Get config from EEPROM and set into hardware
void PIMACFLT_vSetHwFromEep (SMacFltPageCfg *pSPageBuf)
{
    UINT16          si;
    SMacEntry      sTblEntry; 
    UINT8            abyMacBuff[MAC_ADDR_SIZE];   
    UINT16          wTblPtr;
    UINT16          u16Indx;
    UINT8           bySMACMode;
    UINT8           bIsOperOk = TRUE;

    PIMACFLT_vGetSMacFltMode(&bySMACMode);

    // Initialize page and get all groups
    PIMACFLT_vInitPage(pSPageBuf);
    //Set all groups into hardware
    for (si = 0; si < pSPageBuf->wValidEntryNum; si ++) {
        STR_pvMemset(&sTblEntry, 0, sizeof(SMacEntry));
        
        STR_vCvtMacStrtoVal(pSPageBuf->astrGrpMacList + si*(MAC_STRING_LEN + 1), (char*)abyMacBuff);
        
        if ((wTblPtr = PIMACFLTEP_wSearchEntry(abyMacBuff, pSPageBuf->awValidGrpFidList[si])) != UINT16_MAX) {    
            PIMACFLTEP_vGetEntry(wTblPtr,&sTblEntry);
            //set into HW  
            //If 2 slot in Primary MAC Table is full, Insert in Secondary MAC Table
            if ((bIsOperOk = SWMACTB_bInsEntry(&sTblEntry, FALSE)) == FALSE) {
                //First check whether exist the same entry but act as dynamic entry, If yes, delete the entry
                if ((u16Indx = SWSMACBCAM_wSearchEntryInHw(abyMacBuff, pSPageBuf->awValidGrpFidList[si])) != UINT16_MAX)
                    SWSMACTB_vDelEntryByIndx(u16Indx);
                //If no space for this entry in BCAM,Delete the entry
                if ((bIsOperOk = SWSMACTB_bInsEntry(&sTblEntry, TRUE)) == FALSE)
                    PIMACFLTEP_vDelEntry(wTblPtr);
            }       
            if (bySMACMode == MACFLT_MODE_SMAC_PERMIT) {
                PIMACFLT_vSetPortSecurity(sTblEntry.u8SrcId, TRUE);
            }             
        }
    }  
    //In SMAC permit mode handle security related config
    if (pSPageBuf->bySMACFltMode == MACFLT_MODE_SMAC_PERMIT) {
        SGlobSecuCfg sSecuCfg;

        STR_pvMemset(&sSecuCfg, 0, sizeof(SGlobSecuCfg)); 

        SWSECU_vGetGlobalCfg(&sSecuCfg);
        sSecuCfg.bySVFwdOpt = SV_FWD_DROP;
        SWSECU_bSetGlobalCfg(sSecuCfg);
    }
}


void PIMACFLT_vSetSMACFltMode (SMacFltPageCfg *pSPageBuf)
{
    SMacEntry sTblEntry;
    UINT8   byOldMode;
    UINT16  si;

    PIMACFLT_vGetSMacFltMode(&byOldMode);
    
    if (byOldMode != pSPageBuf->bySMACFltMode) {            
        for (si = 0; si < pSPageBuf->wValidEntryNum; si++) {
            PIMACFLTEP_vGetEntry(si, &sTblEntry);         
            //clear entry in hw table, If entry not in Primary Mac Table, clear entry in Secondary Mac Table
            if (!SWMACTB_bDelEntry(sTblEntry.abyMacAddr, sTblEntry.u16Fid)) 
                SWSMACTB_bDelEntry(sTblEntry.abyMacAddr, sTblEntry.u16Fid);
            }

        //In SMAC permit mode handle security related config
        if (pSPageBuf->bySMACFltMode == MACFLT_MODE_SMAC_PERMIT) {
            SGlobSecuCfg sSecuCfg;

            STR_pvMemset(&sSecuCfg, 0, sizeof(SGlobSecuCfg));

            SWSECU_vGetGlobalCfg(&sSecuCfg);
            sSecuCfg.bySVFwdOpt = SV_FWD_DROP;
            SWSECU_bSetGlobalCfg(sSecuCfg);
        }
        else {
            //Clear all the port's security
            for (si = 0; si < SWITCH_PORT_NUM; si++)      
                PIMACFLT_vSetPortSecurity(si, FALSE);
        }
        //clear groups in flash
        s_vSetEepDefault(pSPageBuf, FALSE);
    }
}


void PIMACFLT_vSetPortSecurity(UINT8 byPhyPID, BOOL bSecuEn)
{
    SWSECU_vSetLearnEn(byPhyPID, !bSecuEn);
    SWSECU_vSetSecuDetectEn(byPhyPID,bSecuEn);  

    if (bSecuEn) {
        //clean port's dynamic address
        SMacTblScanCfg sScanCfg;

        STR_pvMemset(&sScanCfg, 0, sizeof(SMacTblScanCfg));

        SWMACTBLSCAN_vGetScanCfg(&sScanCfg);
        sScanCfg.bMvFrmFidEn = FALSE;
        sScanCfg.byMvFrmPortId = byPhyPID;
        sScanCfg.bMvFrmTrunk = FALSE;
        sScanCfg.bMvFrmPortEn = TRUE;
        sScanCfg.byCmd = SCAN_CMD_SELECT_CLR;
        SWMACTBLSCAN_vSetScanCfg(sScanCfg);
    }
}

// Set default into EEPROM
void PIMACFLT_vSetEepDefault (SMacFltPageCfg *pSPageBuf, BOOL bWriteDefault)
{
    PIMACFLT_vGetSMacFltMode(&pSPageBuf->bySMACFltMode);   
    if (bWriteDefault)
        pSPageBuf->bySMACFltMode = MACFLT_MODE_SMAC_DISABLE;
    
    s_vSetEepDefault(pSPageBuf, bWriteDefault);
}

// Set default into EEPROM
void s_vSetEepDefault (SMacFltPageCfg *pSPageBuf, BOOL bWriteDefault)
{
    // Set value to nvram software cache
    STR_pvMemset(g_pu8NVRSwCache + (EEP_ADDR_SMACFLT_MODE - NVR_ADDR_DATA_AREA_START), pSPageBuf->bySMACFltMode, EEP_SIZE_SMACFLT_MODE);       
    STR_pvMemset(g_pu8NVRSwCache + (EEP_ADDR_MACFLT_GROUP_CFG - NVR_ADDR_DATA_AREA_START), 0, EEP_SIZE_MACFLT_GROUP_CFG);       
    if (!bWriteDefault) {
        // Not write default operation     
        // Write cache data into flash             
        NVRAM_bWriteBlock(EEP_ADDR_MACFLT_CFG, g_pu8NVRSwCache + (EEP_ADDR_MACFLT_CFG - NVR_ADDR_DATA_AREA_START), EEP_SIZE_MACFLT_CFG, FALSE);
        // Update checksum and return
        NVRAM_vUpdateChecksum(EEP_SIZE_DATA_AREA);
    }
}

⌨️ 快捷键说明

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