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

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


#include "swreg.h"
#if !defined(__SWCFG_H__)
#include "swcfg.h"
#endif
#include "swmsg.h"
#include "swsys.h"

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

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

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

#include "piportmp.h"

#include "pivlneep.h"

#include "pismacep.h"

#include "pimacfltgp.h"
#include "pimacfltep.h"
#include "pimacfltmd.h"


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

// Definitions to reduce statement length
#define pSCurGrp            (&pSPageBuf->SCurGrp)

//Macro to decide whether user function s_wFixedSearchSMACEntry(), instead of
//PISMACEP_wSearchEntry() to search static mac table
//If TRUE, use s_wFixedSearchSMACEntry() to search
//If FALSE,use PISMACEP_wSearchEntry() to search
//When bugs in module static mac table are fixed, the macro should be change to FALSE
//to use function PISMACEP_wSearchEntry() to search  (Feb 05,06)
#define FIX_SEARCH_SMAC_FUNC  (TRUE)

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

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

/*---------------------  Static Functions  --------------------------*/
static UINT8 s_byCheckGrpCfg (SMacFltPageCfg *pSPageBuf);

#if (FIX_SEARCH_SMAC_FUNC)
static UINT16 s_wFixedSearchSMACEntry (UINT8 *abyMacAddr, UINT16 u16Fid);
#endif

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

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

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


//init Item(PortId) for selection
void PIMACFltGP_vInitAddOrEditGrpPage (SMacFltPageCfg *pSPageBuf)
{ 
    // for ui engine
    //pSPageBuf->SCurGrp.SStrTblMap.byListNum = g_byLogIdNum;
    pSPageBuf->SCurGrp.SStrTblMap.byListNum = g_bySingleLogIdNum;

    //STR_pvMemcpy(pSPageBuf->SCurGrp.abyDestPortList, g_abyLogIdList, g_byLogIdNum);
    STR_pvMemcpy(pSPageBuf->SCurGrp.abyDestPortList, g_abyLogIdList, g_bySingleMegaLogIdNum);
    // copy module port log id
    STR_pvMemcpy(pSPageBuf->SCurGrp.abyDestPortList + g_bySingleMegaLogIdNum,
               g_abyLogIdList + g_byMegaLogIdNum,
               g_byModuleLogIdNum);
    pSPageBuf->SCurGrp.SStrTblMap.abyListIndex = pSPageBuf->SCurGrp.abyDestPortList;

}


// Get a group
UINT8 PIMACFLTGP_byGetGrp (SMacFltPageCfg *pSPageBuf)
{
    UINT16              wTblPtr;
    SMacEntry           sTblEntry;
    UINT8                abyMacBuff[MAC_ADDR_SIZE];     


    STR_pvMemset(&sTblEntry, 0, sizeof(SMacEntry));

    STR_vCvtMacStrtoVal(pSCurGrp->azMacAddr, (char*)abyMacBuff);  
    // If group id not exist, return error code
    wTblPtr = PIMACFLTEP_wSearchEntry(abyMacBuff, pSCurGrp->u16Fid);
    if (wTblPtr == UINT16_MAX)
        return MACFLT_OP_GRP_NOT_EXIST;

    // Get entry from EEPROM and transfer into config buffer format
    PIMACFLTEP_vGetEntry(wTblPtr, &sTblEntry);
    PIMACFLTGP_vTrfrEepOrHWtoUI(pSPageBuf, &sTblEntry);
    
    return OP_OK;
}


// Insert a group
UINT8 PIMACFLTGP_byInsGrp (SMacFltPageCfg *pSPageBuf)
{

    SMacEntry      sTblEntry;   
    UINT8            abyMacBuff[MAC_ADDR_SIZE];     
    UINT16           u16Indx;
    UINT8            byErrCode;
    
    STR_pvMemset(&sTblEntry, 0, sizeof(SMacEntry)); 

    // If no empty group, return error code
    if (pSPageBuf->wValidEntryNum == SWITCH_MAC_FLT_GRP_NUM )
        return MACFLT_OP_NO_EMPTY_GRP;

    // Check group configuration
    if ((byErrCode = s_byCheckGrpCfg(pSPageBuf)) != OP_OK)
        return byErrCode;

    //transfer Mac string to abyMacBuff
    STR_vCvtMacStrtoVal(pSCurGrp->azMacAddr, (char*)abyMacBuff);    
       
    //need to trsfer logic portmsk to physical portmsk
    PIMACFLTGP_vTrfrUItoEepOrHW(pSPageBuf, &sTblEntry);
    //set insert entry as static entry
    sTblEntry.bStatic = 1;
    
    //set into HW  
    //If 2 slot in Primary MAC Table is full, Insert in Secondary MAC Table
    if (!SWMACTB_bInsEntry(&sTblEntry, FALSE)) {
        //First check whether exist the same entry but act as dynamic entry, If yes delete the entry
        if ((u16Indx = SWSMACBCAM_wSearchEntryInHw(abyMacBuff, pSCurGrp->u16Fid)) != UINT16_MAX)
            SWSMACTB_vDelEntryByIndx(u16Indx);

        if (!SWSMACTB_bInsEntry(&sTblEntry, TRUE))
            return MACFLT_OP_NO_EMPTY_SPACE_HW;
    }
    //Set config into port related HW
    if (pSPageBuf->bySMACFltMode == MACFLT_MODE_SMAC_PERMIT)
         //Use phyId to search entry in flash, check whether exist other entry with this port. If
        //no, change security of this port from normal to secure
         if (PIMACFLTEP_wSearchEntrybyPortId(sTblEntry.u8SrcId) == UINT16_MAX)
             PIMACFLT_vSetPortSecurity(sTblEntry.u8SrcId, TRUE);
        
    //set into Eep
    PIMACFLTEP_byInsEntry(&sTblEntry);

    return OP_OK;
}

// Delete a group
UINT8 PIMACFLTGP_byDelGrp (SMacFltPageCfg *pSPageBuf)
{
    UINT16  wTblPtr;
    UINT8    abyMacBuff[MAC_ADDR_SIZE];     
    SMacEntry           sTblEntry;
        
    STR_vCvtMacStrtoVal(pSCurGrp->azMacAddr, (char*)abyMacBuff);    
    wTblPtr = PIMACFLTEP_wSearchEntry(abyMacBuff, pSCurGrp->u16Fid);
    if (wTblPtr == UINT16_MAX)
        return MACFLT_OP_GRP_NOT_EXIST;

    //clear entry in hw table, If entry not in Primary Mac Table, check Secondary Mac Table
    if (!SWMACTB_bDelEntry(abyMacBuff, pSCurGrp->u16Fid)) 
        SWSMACTB_bDelEntry(abyMacBuff, pSCurGrp->u16Fid);

    //Backup entry cfg        
    PIMACFLTEP_vGetEntry(wTblPtr, &sTblEntry);
        
    // Delete group from EEPROM and return
    PIMACFLTEP_vDelEntry(wTblPtr);

    //Set config into port related HW
    if (pSPageBuf->bySMACFltMode == MACFLT_MODE_SMAC_PERMIT) {        
        //Use phyId to search entry in flash, check whether exist other entry with this port. If
        //not, change security of this port from secure to normal
        if (PIMACFLTEP_wSearchEntrybyPortId(sTblEntry.u8SrcId) == UINT16_MAX) 
            PIMACFLT_vSetPortSecurity(sTblEntry.u8SrcId, FALSE);    
    }
    
    //PIMACFLTEP_vStatisTblInfo(pSPageBuf);

    return OP_OK;
}

void PIMACFLTGP_vTrfrUItoEepOrHW (SMacFltPageCfg *pSPageBuf, SMacEntry *pSTblEntry) 
{    

    STR_vCvtMacStrtoVal(pSCurGrp->azMacAddr, (char*)pSTblEntry->abyMacAddr);    
        
    pSTblEntry->u16Fid = pSCurGrp->u16Fid;
        
        if (pSPageBuf->bySMACFltMode == MACFLT_MODE_SMAC_PERMIT) {
            if (pSCurGrp->bySrcId >= g_bySingleMegaLogIdNum)
                pSCurGrp->bySrcId += g_byTrunkLogIdNum;

            //Trunk group wouldn't appear here
            pSTblEntry->bTrkGrp = FALSE;
            pSTblEntry->u8SrcId = PIPORTMP_byLogPtrToPhyId(pSCurGrp->bySrcId);
        }
        else {
            pSTblEntry->bFltrSmac = TRUE;  //Filter smac
            pSTblEntry->u8SrcId = SWITCH_FILTER_PORT;   
        }
}

void PIMACFLTGP_vTrfrEepOrHWtoUI (SMacFltPageCfg *pSPageBuf, SMacEntry *pSTblEntry) 
{

    STR_vCvtMacValtoStr(pSCurGrp->azMacAddr, (char*)pSTblEntry->abyMacAddr);

    pSCurGrp->u16Fid = pSTblEntry->u16Fid; 

    if(pSPageBuf->bySMACFltMode == MACFLT_MODE_SMAC_PERMIT) {
        pSCurGrp->bySrcId = PIPORTMP_byPhyIdToLogPtr(pSTblEntry->u8SrcId);

        if (pSCurGrp->bySrcId >= g_bySingleMegaLogIdNum)
            pSCurGrp->bySrcId -= g_byTrunkLogIdNum;   // skip trunk ports

    }
}


///////////////////////////////////////////////////////////////////////////////

static UINT8 s_byCheckGrpCfg (SMacFltPageCfg *pSPageBuf)
{
    UINT8    byVlanMode;
    UINT8    abyMacBuff[MAC_ADDR_SIZE];     
    char      *pazMacAddr = pSCurGrp->azMacAddr;

    //Check whether not HEX Digit exist in MAC address string buffer, If exist, return error code 
    while (*pazMacAddr) {
        if (!STR_bIsXDigit(*pazMacAddr) && (*pazMacAddr != ':'))
            return MACFLT_OP_MAC_ADDR_INVALID;

        pazMacAddr ++;
    }

    //transfer Mac string to abyMacBuff
    STR_vCvtMacStrtoVal(pSCurGrp->azMacAddr, (char*)abyMacBuff); 

    // If group already exist, return error code
    if (PIMACFLTEP_wSearchEntry(abyMacBuff, pSCurGrp->u16Fid) != UINT16_MAX )
        return MACFLT_OP_GRP_EXIST;

    //BroadCast address can not be added     
    if ((abyMacBuff[0] == 0xFF) && (abyMacBuff[1] ==0xFF )&& (abyMacBuff[2] == 0xFF) 
        &&(abyMacBuff[0] == 0xFF) && (abyMacBuff[1] ==0xFF )&& (abyMacBuff[2] == 0xFF) )
        return MACFLT_OP_MAC_ADDR_BCST;

    //Multicast address can not be added  
    if (abyMacBuff[5] == 0x01)
        return MACFLT_OP_MAC_ADDR_MCST;

    //Check VID by VLAN mode
#if 0
/*
    To check Fid base on VLAN mode
    If 802.1q VLAN or ProtocolBase VLAN, Fid should between  VLAN_MIN_VALID_VID~VLAN_MAX_VALID_VID_3268
    If VLAN disabled, Fid should be 0
    If PortBase VLAN, Fid should be 128
*/
    PIVLAN_vGetVlanMode(&byVlanMode);
    if ((byVlanMode == VLAN_MODE_8021Q) || (byVlanMode == VLAN_MODE_PROTOBASE) ) {
        if (pSCurGrp->u16Fid < VLAN_MIN_VALID_VID || pSCurGrp->u16Fid > VLAN_MAX_VALID_VID_3268)
            return MACFLT_OP_FID_INVALID;
    }    
    else if ((byVlanMode == VLAN_MODE_DISABLE) && pSCurGrp->u16Fid != 0)    
        return MACFLT_OP_FID_INVALID;

    else if ((byVlanMode == VLAN_MODE_PORTBASE) && pSCurGrp->u16Fid != PORTBASE_VLAN_FID)    
        return MACFLT_OP_FID_INVALID;
#endif
    PIVLAN_vGetVlanMode(&byVlanMode);
    if ((byVlanMode == VLAN_MODE_8021Q) || (byVlanMode == VLAN_MODE_PROTOBASE) ) {
        if (pSCurGrp->u16Fid < VLAN_MIN_VALID_VID || pSCurGrp->u16Fid > VLAN_MAX_VALID_VID_3268)
            return MACFLT_OP_FID_INVALID;
    }     

    //Check whether the filtered MAC exist at Static MAC Binding
#if (FIX_SEARCH_SMAC_FUNC)  
    if (s_wFixedSearchSMACEntry(abyMacBuff, pSCurGrp->u16Fid) != UINT16_MAX)
#else
    if (PISMACEP_wSearchEntry(abyMacBuff, pSCurGrp->u16Fid) != UINT16_MAX)
#endif
        return MACFLT_OP_GRP_EXIST_AS_SMAC;

    return OP_OK;
}

#if (FIX_SEARCH_SMAC_FUNC)
// Search entry in static mac table
// If search successed, return EEPROM table entry id; else return ENTRY_END_FLAG
UINT16 s_wFixedSearchSMACEntry (UINT8 *abyMacAddr, UINT16 u16Fid)
{
    SMacEntry sTblEntry;
    PUINT8   pabyMacAddrTmp;
    UINT8 si;
        
        
    STR_pvMemset(&sTblEntry, 0, sizeof(SMacEntry)); 
    pabyMacAddrTmp = sTblEntry.abyMacAddr;
    
    // Find where in EEPROM the current entry is
    for (si = 0; si < SWITCH_SMAC_GRP_NUM; si ++ ) {        
        PISMACEP_vGetEntry(si, &sTblEntry);

        //If not static group, It means that the group invalid
        if (sTblEntry.bStatic)         
            // If HIT => return current location
            if ( (abyMacAddr[0] == pabyMacAddrTmp[0]) && (abyMacAddr[1] == pabyMacAddrTmp[1]) && (abyMacAddr[2] == pabyMacAddrTmp[2])
                && (abyMacAddr[3] == pabyMacAddrTmp[3]) && (abyMacAddr[4] == pabyMacAddrTmp[4]) && (abyMacAddr[5] == pabyMacAddrTmp[5])
                && (u16Fid == sTblEntry.u16Fid) )
                return si;
        }

    // If entry not exist, return UINT16_MAX
    return UINT16_MAX;

}
#endif

⌨️ 快捷键说明

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