📄 pivlnmod.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: pivlnmod.c
*
* Purpose: VLAN mode setting UI callback functions
*
* Author: Tevin Chen
*
* Date: Jan 08, 2002
*
* Functions:
*
* Revision History:
*
*/
#include "str.h"
#include "swvlantb.h"
#include "swsys.h"
#include "piportmp.h"
#include "picfgmp.h"
#include "pivlnmod.h"
#include "pivlngrp.h"
#include "pivlneep.h"
#include "pidef.h"
#ifdef __PROV_MENU
#include "pigmrpmd.h"
#include "piipmmod.h"
#endif
#include "pimacfltmd.h"
/*--------------------- Static Definitions -------------------------*/
// Definitions to reduce statement length
#define pSCurGrp (&pSPageBuf->SCurGrp)
/*--------------------- Static Classes ----------------------------*/
/*--------------------- Static Variables --------------------------*/
/*--------------------- Static Functions --------------------------*/
static void s_vSetEepDefault (SVlanPageCfg *pSPageBuf, BOOL bWriteDefault);
/*--------------------- Static Macros -----------------------------*/
/*--------------------- Export Variables --------------------------*/
/*--------------------- Export Functions --------------------------*/
// Get config from EEPROM and set into page buf
void PIVLAN_vInitPage (SVlanPageCfg *pSPageBuf)
{
PIVLAN_vGetVlanMode(&pSPageBuf->byVlanMode);
PIVLNEEP_vStatisTblInfo(pSPageBuf);
// decide max vid by chip type
pSPageBuf->wMaxVid = VLAN_MAX_VALID_VID_3268;
}
// Get config from EEPROM and set into hardware
void PIVLAN_vSetHwFromEep (SVlanPageCfg *pSPageBuf)
{
UINT16 si;
// Initialize page and set vlan mode into hardware
PIVLAN_vInitPage(pSPageBuf);
SWVLANTB_vSetVlanMode(pSPageBuf->byVlanMode);
// Clear system PVID setting
if ((pSPageBuf->byVlanMode == VLAN_MODE_8021Q) || (pSPageBuf->byVlanMode == VLAN_MODE_PROTOBASE) ) {
for (si = 0; si < SWITCH_PORT_NUM; si++)
SWVLANTB_vPvidSet(si, 0);
}
// If vlan enabled, add groups into hardware
for (si = 0; si < pSPageBuf->wValidEntryNum; si++) {
pSCurGrp->u16Vid = pSPageBuf->awValidGrpIdList[si];
PIVLAN_byGetGrp(pSPageBuf);
// Add portbase group
if (pSPageBuf->byVlanMode == VLAN_MODE_PORTBASE)
VLANvPortBaseInsGrp(pSCurGrp);
// Add 802.1Q group
else {
VLANv8021QInsEntry(pSPageBuf);
//(u8ProtoIndx == none) => only need to set entry into "vlan table"
//(u8ProtoIndx != none) => set entry into "vlan table" and "protocol vlan table"
if ((pSPageBuf->byVlanMode == VLAN_MODE_PROTOBASE) && (pSCurGrp->u8ProtoIndx != 0) )
VLANvPrvInsEntry(pSPageBuf);
}
}
//update default grp and pvid
if (pSPageBuf->byVlanMode == VLAN_MODE_PROTOBASE)
PIVLAN_vUpdateDefaultGrp(pSPageBuf);
// Finish port base table setting
if (pSPageBuf->byVlanMode == VLAN_MODE_PORTBASE)
SWVLANTB_vPortBaseSetCfgForAllGrp();
}
// Set default vlan mode into EEPROM
void PIVLAN_vSetEepDefault (SVlanPageCfg *pSPageBuf, BOOL bWriteDefault)
{
PIVLAN_vInitPage(pSPageBuf);
pSPageBuf->byVlanMode = DEFAULT_VLAN_MODE;
if (bWriteDefault)
s_vSetEepDefault(pSPageBuf, TRUE);
else
PIVLAN_vSetVlanMode(pSPageBuf);
}
// Set vlan mode function
// Jenda 0502: write default vlan ingress filtering setting after change vlan mode from 802.1Q
void PIVLAN_vSetVlanMode (SVlanPageCfg *pSPageBuf)
{
UINT8 byOldVlanMode;
UINT16 si;
SMacFltPageCfg sMacFltPageBuf;
#ifdef __PROV_MENU
SSMacPageCfg sSMacPageBuf;
SGMRPPageCfg sGMRPPageBuf;
SIGMPPageCfg sIGMPPageBuf;
#endif
// Clear VLAN table according to the original vlan mode
PIVLAN_vGetVlanMode(&byOldVlanMode);
if ((byOldVlanMode == VLAN_MODE_8021Q) || (byOldVlanMode == VLAN_MODE_PROTOBASE) ) {
for (si = 0; si < pSPageBuf->wValidEntryNum; si++) {
pSCurGrp->u16Vid = pSPageBuf->awValidGrpIdList[si];
SWVLANTB_bDelEntry( pSCurGrp->u16Vid );
PIVLAN_byGetGrp(pSPageBuf);
//(u8ProtoIndx == none) => only need to delete entry into "vlan table"
//(u8ProtoIndx != none) => delete entry into "vlan table" and "protocol vlan table"
if ((byOldVlanMode == VLAN_MODE_PROTOBASE) && (pSCurGrp->u8ProtoIndx != 0) )
VLANvPrvDelEntry(pSPageBuf);
}
}
else if (byOldVlanMode == VLAN_MODE_PORTBASE)
SWVLANTB_vPortBaseClearAllGrp();
// Set EEPROM content to default value of new vlan mode
s_vSetEepDefault(pSPageBuf, FALSE);
// Get config from EEPROM and set into hardware
PIVLAN_vSetHwFromEep(pSPageBuf);
// Set default vlan ingress filtering setting
if ((byOldVlanMode == VLAN_MODE_8021Q) || (byOldVlanMode == VLAN_MODE_PROTOBASE) ) {
PIVLNFLT_vSetEepDefault((SVlanIngrFilterPageCfg*)pSCurGrp, FALSE);
PIVLNFLT_vSetHwFromEep((SVlanIngrFilterPageCfg*)pSCurGrp);
}
// Clear MAC table to prevent lookup problems
//SWFWD_vClearMacTable(); //TOCHECK
//clear MAC FILTER ENTRY in MAC table when vlan mode changed
PIMACFLT_vSetEepDefault(&sMacFltPageBuf, FALSE);
#ifdef __PROV_MENU
//clear entries in MAC table and ipm table when vlan mode changed
PISMAC_vSetEepDefault(&sSMacPageBuf, FALSE);
PIGMRP_vClrAllEepGrp(&sGMRPPageBuf, FALSE);
PIIGMP_vClrAllEepGrp(&sIGMPPageBuf, FALSE);
#endif
}
// Set EEPROM default value of each vlan mode
static void s_vSetEepDefault (SVlanPageCfg *pSPageBuf, BOOL bWriteDefault)
{
// Set value to nvram software cache
STR_pvMemcpy(g_pu8NVRSwCache + (EEP_ADDR_VLAN_CFG - NVR_ADDR_DATA_AREA_START), &pSPageBuf->byVlanMode, EEP_SIZE_VLAN_MODE);
// Clear each entry buffer
STR_pvMemset(g_pu8NVRSwCache + (EEP_ADDR_VLAN_GROUP - NVR_ADDR_DATA_AREA_START), 0, EEP_SIZE_VLAN_TBL_ENTRY*SWITCH_VLAN_GRP_NUM);
// If 802.1Q => Add default group into EEPROM
if ((pSPageBuf->byVlanMode == VLAN_MODE_8021Q) || (pSPageBuf->byVlanMode == VLAN_MODE_PROTOBASE) ) {
STR_pvMemset(pSCurGrp, 0, sizeof(SVlanGrp));
pSCurGrp->u16Vid = VLAN_DEFAULT_GROUP_VID;
STR_pvMemset( pSCurGrp->abyMbrMsk, 0xFF, BYTE_NUM_OF_CFGBUF_BIT_MASK ); // Untagged member => all ports
STR_pvMemset( pSCurGrp->abyMbrMsk + BYTE_NUM_OF_CFGBUF_BIT_MASK, // Tagged member => 0
0, BYTE_NUM_OF_CFGBUF_BIT_MASK );
STR_pvMemcpy(g_pu8NVRSwCache + (EEP_ADDR_VLAN_GROUP - NVR_ADDR_DATA_AREA_START), pSCurGrp, EEP_SIZE_VLAN_TBL_ENTRY);
}
if (!bWriteDefault) {
// Not write default operation
// Write cache data into flash
NVRAM_bWriteBlock(EEP_ADDR_VLAN_CFG, g_pu8NVRSwCache + (EEP_ADDR_VLAN_CFG - NVR_ADDR_DATA_AREA_START), EEP_SIZE_VLAN_MODE + EEP_SIZE_VLAN_TBL_ENTRY*SWITCH_VLAN_GRP_NUM, FALSE);
// Update checksum and return
NVRAM_vUpdateChecksum(EEP_SIZE_DATA_AREA);
// If 802.1Q => Add default group into EEPROM
if ((pSPageBuf->byVlanMode == VLAN_MODE_8021Q) || (pSPageBuf->byVlanMode == VLAN_MODE_PROTOBASE) ) {
STR_pvMemset(pSCurGrp, 0, sizeof(SVlanGrp));
pSCurGrp->u16Vid = VLAN_DEFAULT_GROUP_VID;
STR_pvMemset( pSCurGrp->abyMbrMsk, 0xFF, BYTE_NUM_OF_CFGBUF_BIT_MASK ); // Untagged member => all ports
STR_pvMemset( pSCurGrp->abyMbrMsk + BYTE_NUM_OF_CFGBUF_BIT_MASK, // Tagged member => 0
0, BYTE_NUM_OF_CFGBUF_BIT_MASK );
PIVLNEEP_vEditEntry(0, pSCurGrp);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -