📄 pisniff.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: pisniff.c
*
* Purpose: Sniffer module UI callback functions
*
* Author: Tevin Chen
*
* Date: Jan 08, 2002
*
* Functions:
*
* Revision History:
*
*/
#include "str.h"
#include "swsnf.h"
#include "swmsg.h"
#include "pigencfg.h"
#include "pisniff.h"
#include "piportmp.h"
/*--------------------- Static Definitions -------------------------*/
/*--------------------- Static Classes ----------------------------*/
/*--------------------- Static Variables --------------------------*/
/*--------------------- Static Functions --------------------------*/
static UINT8 s_bySetCfgToHW(SSniffPageCfg* pSPageCfg_Sniff);
/*--------------------- Export Variables --------------------------*/
/*--------------------- Export Macros -----------------------------*/
/*--------------------- Export Functions --------------------------*/
void PISNF_vInitPage(SSniffPageCfg* pSPageCfg_Sniff)
{
PIEEP_vGetCfgFromEep(EEP_ADDR_SNIFF_CFG, EEP_SIZE_SNIFF_CFG, (PUINT8)pSPageCfg_Sniff);
// If sniffer disabled, show first non-trunked port as destination port
if (pSPageCfg_Sniff->f2Mode == SNIFF_MODE_DISABLE)
pSPageCfg_Sniff->f6DestPort = 0;
// If sniffer enabled, show EEPROM stored config
else
pSPageCfg_Sniff->f6DestPort = PIPORTMP_byPhyIdToLogPtr(pSPageCfg_Sniff->f6DestPort);
if (pSPageCfg_Sniff->f6DestPort >= g_bySingleMegaLogIdNum)
pSPageCfg_Sniff->f6DestPort -= g_byTrunkLogIdNum; // skip trunk ports
PICFGMP_v4BPhyMskTo1bLogPtrMsk(pSPageCfg_Sniff->abySrcPortMsk);
// for ui engine
pSPageCfg_Sniff->SStrTblMap.byListNum = g_bySingleLogIdNum;
STR_pvMemcpy(pSPageCfg_Sniff->abyDestPortList, g_abyLogIdList, g_bySingleMegaLogIdNum);
// copy module port log id
STR_pvMemcpy(pSPageCfg_Sniff->abyDestPortList + g_bySingleMegaLogIdNum,
g_abyLogIdList + g_byMegaLogIdNum,
g_byModuleLogIdNum);
pSPageCfg_Sniff->SStrTblMap.abyListIndex = pSPageCfg_Sniff->abyDestPortList;
}
void PISNF_vSetEepDefault(SSniffPageCfg* pSPageCfg_Sniff, BOOL bWriteDefault)
{
STR_pvMemset(pSPageCfg_Sniff, 0, EEP_SIZE_SNIFF_CFG);
if (bWriteDefault) {
// Set value to nvram software cache
STR_pvMemcpy(g_pu8NVRSwCache + (EEP_ADDR_SNIFF_CFG - NVR_ADDR_DATA_AREA_START), (PUINT8)pSPageCfg_Sniff, EEP_SIZE_SNIFF_CFG);
}
else {
PIEEP_vSetCfgIntoEep((PUINT8)pSPageCfg_Sniff, EEP_ADDR_SNIFF_CFG, EEP_SIZE_SNIFF_CFG);
NVRAM_vUpdateChecksum(EEP_SIZE_DATA_AREA);
}
}
void PISNF_vSetHwFromEep(SSniffPageCfg* pSPageCfg_Sniff)
{
PIEEP_vGetCfgFromEep(EEP_ADDR_SNIFF_CFG, EEP_SIZE_SNIFF_CFG, (PUINT8)pSPageCfg_Sniff);
s_bySetCfgToHW(pSPageCfg_Sniff);
}
UINT8 PISNF_bySavePage(SSniffPageCfg* pSPageCfg_Sniff)
{
SSniffPageCfg SCfgBuf;
UINT8 byRes;
STR_pvMemcpy(&SCfgBuf, pSPageCfg_Sniff, EEP_SIZE_SNIFF_CFG);
// Transfer from config to physical format
if (SCfgBuf.f6DestPort >= g_bySingleMegaLogIdNum)
SCfgBuf.f6DestPort += g_byTrunkLogIdNum;
SCfgBuf.f6DestPort = PIPORTMP_byLogPtrToPhyId(SCfgBuf.f6DestPort);
PICFGMP_v1bLogPtrMskTo4BPhyMsk(SCfgBuf.abySrcPortMsk);
// Set config into HW
byRes = s_bySetCfgToHW(&SCfgBuf);
if (byRes != OP_OK)
return byRes;
// Set config into EEPROM and return
PIEEP_vSetCfgIntoEep((PUINT8)&SCfgBuf, EEP_ADDR_SNIFF_CFG, EEP_SIZE_SNIFF_CFG);
NVRAM_vUpdateChecksum(EEP_SIZE_DATA_AREA);
return byRes;
}
static UINT8 s_bySetCfgToHW(SSniffPageCfg* pSPageCfg_Sniff)
{
SSniffCfg SSniffBuf;
UINT8 byIndex, byNum = 1;
UINT32 dwSrcPortMsk = 0;
SSniffBuf.byMode = pSPageCfg_Sniff->f2Mode;
SSniffBuf.byDestPort = pSPageCfg_Sniff->f6DestPort; // it's phy port id
SSniffBuf.bySrcPort = 0;
STR_pvMemcpy( (PUINT8)(&dwSrcPortMsk)+BYTE_OFFSET_IN_DWORD_OF_CFGMASK,
pSPageCfg_Sniff->abySrcPortMsk, BYTE_NUM_OF_CFGBUF_BIT_MASK );
// If sniffer enabled, check config valid
if (pSPageCfg_Sniff->f2Mode != SNIFF_MODE_DISABLE)
{
// (dest != source)
if (((dwSrcPortMsk >> SSniffBuf.byDestPort) & 0x00000001) )
return SNIFF_OP_DEST_AND_SRC_OVERLAP;
// only one port can be monitored port
for (byIndex=0; byIndex<SWITCH_PORT_NUM; byIndex++ ) {
if ((dwSrcPortMsk>>byIndex) & 0x00000001 ) {
if (byNum != 1)
return SNIFF_OP_MORE_THAN_ONE_PORT;
byNum --;
}
}
// no any port be monitored port
if (byNum == 1 )
return SNIFF_OP_NO_MONITORED_PORT;
}
// Set config into HW
for (byIndex=0; byIndex<SWITCH_PORT_NUM; byIndex++ ) {
if ((dwSrcPortMsk>>byIndex) & 0x00000001 ) {
SSniffBuf.bySrcPort = byIndex;
SWSNF_vSetSniffCfg(&SSniffBuf);
break;
}
}
return OP_OK;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -