📄 kscmds.c
字号:
printf ( "\nRegister (0x%02x) = 0x%02x", igRRegNdx, ReadData ( (BYTE) igRRegNdx ) );
return SUCCESS;
}
//--------------------------------------------------------------------------
//
// int ReadReg
//
// Description:
// Command:
//
// rr Read content of the register elem1.
//
//
// Parameters:
// int elem1 Register number
// int elem2 NOPARAMETER
// int elem3 NOPARAMETER
//
// Return Vlaue:
// SUCCESS or PARMERROR
//
//--------------------------------------------------------------------------
int ReadReg ( int elem1, int elem2, int elem3 )
{
if ( elem1 == NOPARAMETER || elem2 != NOPARAMETER || elem3 != NOPARAMETER )
return PARMERROR;
if ( elem1 > 127 )
return PARMERROR;
printf ( "\nRegister (0x%02x) = 0x%02x", elem1, ReadData ( (BYTE) elem1 ) );
igRRegNdx = elem1;
return SUCCESS;
}
//--------------------------------------------------------------------------
//
// int ReadCnt
//
// Description:
// command:
//
// rcnt Read the counter of dynamic MAC address table entry
//
// Parameters:
// int elem1 NOPARAMETER
// int elem2 NOPARAMETER
// int elem3 NOPARAMETER
//
// Return Vlaue:
// SUCCESS or PARMERROR
//
//--------------------------------------------------------------------------
int ReadCnt ( int elem1, int elem2, int elem3 )
{
if ( elem1 != NOPARAMETER || elem2 != NOPARAMETER || elem3 != NOPARAMETER )
return PARMERROR;
printf ( "\nDynamic MAC entry count = %x", GetDynaMACEntryCnt ());
return SUCCESS;
}
//--------------------------------------------------------------------------
//
// int WriteToNextReg
//
// Description:
// command:
//
// wn Data Write Data to next register. Glocal igWRegNdx points
// to the current register.
//
// Parameters:
// elem1 Byte to be written
// elem2 NOPARAMETER
// elem3 NOPARAMETER
//
// Return Vlaue:
// SUCCESS or PARMERROR
//
//--------------------------------------------------------------------------
int WriteToNextReg ( int elem1, int elem2, int elem3 )
{
if ( elem1 == NOPARAMETER || elem2 != NOPARAMETER || elem3 != NOPARAMETER )
return PARMERROR;
igWRegNdx++;
if ( igWRegNdx == REGISTERTOTAL )
igWRegNdx = 0;
WriteData ( (BYTE) igWRegNdx, (BYTE) elem2 );
return SUCCESS;
}
//--------------------------------------------------------------------------
//
// int WriteToReg
//
// Description:
// command:
//
// wr Reg Data Write Data to register Reg.
//
// Parameters:
// elem1 Register index
// elem2 Byte to be written
// elem3 NOPARAMETER
//
// Return Vlaue:
//
//--------------------------------------------------------------------------
int WriteToReg ( int elem1, int elem2, int elem3 )
{
if ( elem3 != NOPARAMETER )
return PARMERROR;
if ( elem1 >= REGISTERTOTAL )
return PARMERROR;
WriteData ( (BYTE) elem1, (BYTE) elem2 );
igWRegNdx = elem1;
return SUCCESS;
}
//--------------------------------------------------------------------------
//
// int WriteToStaticMACTable
//
// Description:
// command:
//
// wstab n MAC Data Write to the nth entry of the static MAC address table
//
// Parameters:
// elem1 Register index
// elem2 The LSB 4 bytes of MAC address
// elem3 The rest of 2 bytes of MAC address plus the rest of bits.
//
// Return Vlaue:
// SUCCESS and PARMERROR
//
//--------------------------------------------------------------------------
int WriteToStaticMACTable ( int elem1, int elem2, int elem3 )
{
if ( elem1 == NOPARAMETER || elem3 == NOPARAMETER )
return PARMERROR;
if ( elem1 > STATICMACTOTAL )
return PARMERROR;
WriteDataBegin ( INDIRECTDATABASE + 1, (BYTE) (elem3 >> 24 ));
WriteDataContinue ( (BYTE) (elem3 >> 16 ) );
WriteDataContinue ( (BYTE) (elem3 >> 8 ) );
WriteDataContinue ( (BYTE) (elem3 ) );
WriteDataContinue ( (BYTE) (elem2 >> 24) );
WriteDataContinue ( (BYTE) (elem2 >> 16) );
WriteDataContinue ( (BYTE) (elem2 >> 8 ) );
WriteDataEnd ( (BYTE) (elem2 ) );
WriteData ( INDIRECTCTL1, INDIRECTWRITE | INDIRECTSMACTAB );
WriteData ( INDIRECTCTL2, (BYTE) elem1 );
return SUCCESS;
}
//--------------------------------------------------------------------------
//
// int WriteToVLANTable
//
// Description:
// command:
//
// wvtab n, Data Write "Data" to the nth entry of the VLAN table.
//
// Parameters:
// elem1 Register index
// elem2 0-22 VLAN bits
// elem3 NOPARAMETER
//
// Return Vlaue:
// SUCCESS and PARMERROR
//
//--------------------------------------------------------------------------
int WriteToVLANTable ( int elem1, int elem2, int elem3 )
{
if ( elem1 == NOPARAMETER || elem2 == NOPARAMETER || elem3 != NOPARAMETER )
return PARMERROR;
if ( elem1 > VLANTABTOTAL )
return PARMERROR;
WriteDataBegin ( INDIRECTDATABASE + 6, (BYTE) (elem2 >> 16 ));
WriteDataContinue ( (BYTE) (elem2 >> 8 ) );
WriteDataEnd ( (BYTE) elem2 );
WriteData ( INDIRECTCTL1, INDIRECTWRITE | INDIRECTVLANTAB );
WriteData ( INDIRECTCTL2, (BYTE) elem1 );
return SUCCESS;
}
//--------------------------------------------------------------------------
//
// int UpdateVLANTab
//
// Description:
// command:
//
// uvtab n fid= vid= mbr= on= Update VLAN table entry n
//
// prompts:
// fid= 4-bit FID
// vid= 12-bit VID
// mbr= 5-bit Portmembership bit map
// on= 1-bit Valid bit
//
// Call ParseParameter() to get the values. Assemble the bytes and call
// WriteToVLANTable () to write the bytes to the hardware.
//
//
// Parameters:
// char *sCmdBuf Pointer to the command string read in from console
// or script file.
//
//
// Return Vlaue:
// SUCCESS and PARMERROR
//
//--------------------------------------------------------------------------
int UpdateVLANTab ( char *sCmdBuf )
{
unsigned int uVid;
unsigned int uVidValue;
unsigned int uFid;
unsigned int uFidValue;
unsigned int uMbr;
unsigned int uMbrValue;
unsigned int uValid;
unsigned int uValidValue;
BYTE bByte0;
BYTE bByte1;
BYTE bByte2;
int iEntry;
// It should find the entry value and returns a pointer to next "value"
if ( !GetValue ( sCmdBuf, &iEntry ) )
return PARMERROR;
if ( iEntry < 0 || iEntry >= VLANENTRIES )
return PARMERROR;
if ( ( uVid = ParseParameters ( sCmdBuf, VID, &uVidValue ) ) == PARMERROR )
return PARMERROR;
if ( ( uFid = ParseParameters ( sCmdBuf, FID, &uFidValue ) ) == PARMERROR )
return PARMERROR;
if ( ( uMbr = ParseParameters ( sCmdBuf, MEMBERSHIP, &uMbrValue ) ) == PARMERROR )
return PARMERROR;
if ( ( uValid = ParseParameters ( sCmdBuf, VALID, &uValidValue ) ) == PARMERROR )
return PARMERROR;
GetVLANBytes ( (BYTE)iEntry, &bByte0, &bByte1, &bByte2 );
if ( uVid == SUCCESS )
{
if ( uVidValue > 0xfff ) // 12-bit length
return PARMERROR;
bByte0 = uVidValue & VID1MASK;
bByte1 &= ~VID2MASK;
bByte1 |= (uVidValue >> VID1SHIFT);
}
if ( uFid == SUCCESS )
{
if (uFidValue > 0x0f) // 4-bit length
return PARMERROR;
bByte1 &= ~VTABFIDMASK;
bByte1 |= ( uFidValue << FIDSHIFT );
}
if ( uMbr == SUCCESS )
{
if ( uMbrValue > 0x1f ) // 5-bit length
return PARMERROR;
bByte2 &= ~MBRMASK;
bByte2 |= uMbrValue;
}
if ( uValid == SUCCESS )
{
if ( uValidValue > 0x1 )
return PARMERROR;
bByte2 &= ~VALIDMASK;
bByte2 |= (uValidValue << VALIDSHIFT);
}
//
// If there is no parameter, then just return SUCCESS
//
if ( uValid && uFid && uVid && uMbr )
return SUCCESS;
return ( WriteToVLANTable ( iEntry, (int) ( bByte2 << 16 | bByte1 << 8 | bByte0 ), NOPARAMETER) );
}
//--------------------------------------------------------------------------
//
// int UpdateSMACTab
//
// Description:
// command:
//
// uvtab n fid= ufid= over= on= port= mac= Update Static MAC address table entry n
//
// prompts:
// fid= 4-bit FID
// ufid= 1-bit Use FID flag
// over= 1-bit Override flag
// on= 1-bit Valid bit
// port= 5-bit Forwarding port bit map
// mac= 48-bit MAC address
//
// Call ParseParameter() to get the values. Assemble the bytes and call
// WriteToStaticMACTable () to write the bytes to the hardware.
//
//
// Parameters:
// char *sCmdBuf Pointer to the command string read in from console
// or script file.
//
//
// Return Vlaue:
// SUCCESS and PARMERROR
//
//--------------------------------------------------------------------------
int UpdateSMACTab ( char *sCmdBuf )
{
unsigned int uFid;
unsigned int uFidValue;
unsigned int uUFid;
unsigned int uUFidValue;
unsigned int uOverride;
unsigned int uOverrideValue;
unsigned int uValid;
unsigned int uValidValue;
unsigned int uFports;
unsigned int uFportsValue;
unsigned int uMAC;
unsigned long uMACHigh;
unsigned long uMACLow;
BYTE bByte7;
BYTE bByte8;
BYTE bMACByte1;
BYTE bMACByte2;
BYTE bMACByte3;
BYTE bMACByte4;
BYTE bMACByte5;
BYTE bMACByte6;
int iEntry;
// It should find the entry value and returns a pointer to next "value"
if ( !GetValue ( sCmdBuf, &iEntry ) )
return PARMERROR;
if ( iEntry < 0 || iEntry >= SMACTABTOTAL )
return PARMERROR;
if ( ( uFid = ParseParameters ( sCmdBuf, FID, &uFidValue ) ) == PARMERROR )
return PARMERROR;
if ( ( uUFid = ParseParameters ( sCmdBuf, UFID, &uUFidValue ) ) == PARMERROR )
return PARMERROR;
if ( ( uOverride = ParseParameters ( sCmdBuf, OVERRIDE, &uOverrideValue ) ) == PARMERROR )
return PARMERROR;
if ( ( uValid = ParseParameters ( sCmdBuf, VALID, &uValidValue ) ) == PARMERROR )
return PARMERROR;
if ( ( uFports = ParseParameters ( sCmdBuf, FORWARDINGPORT, &uFportsValue ) ) == PARMERROR )
return PARMERROR;
//
// uMACLow holds the low 4 bytes of the MAC address. hh:hh:ll:ll:ll:ll
// uMACHigh holds the high 2 bytes of the MAC address.
//
if ( ( uMAC = ParseMACAddress ( sCmdBuf, MAC, &uMACLow, &uMACHigh ) ) == PARMERROR )
return PARMERROR;
GetStaticMACBytes ( (BYTE)iEntry, &bByte7, &bByte8 );
//
// Check to see if need to update MAC address
//
if ( uMAC )
{
bMACByte6 = ReadData ( INDIRECTDATABASE + 3);
bMACByte5 = ReadData ( INDIRECTDATABASE + 4);
bMACByte4 = ReadData ( INDIRECTDATABASE + 5);
bMACByte3 = ReadData ( INDIRECTDATABASE + 6);
bMACByte2 = ReadData ( INDIRECTDATABASE + 7);
bMACByte1 = ReadData ( INDIRECTDATABASE + 8);
uMACLow = bMACByte4 << 24 | bMACByte3 << 16 | bMACByte2 << 8 | bMACByte1;
uMACHigh = bMACByte5 << 8 | bMACByte6;
}
//
// Shift bit 56, and above, right one bit. The hardware is designed this way.
//
if ( bByte8 & 0x01 == 1 )
bByte7 |= 0x80;
else
bByte7 &= 0x7f;
bByte8 >>= 1;
if ( uFid == SUCCESS )
{
if (uFidValue > 0x0f) // 4-bit length
return PARMERROR;
bByte8 &= ~FIDMASK;
bByte8 |= uFidValue;
}
if ( uUFid == SUCCESS )
{
if ( uUFidValue > 0x1 ) // 1-bit length
return PARMERROR;
bByte7 &= ~UFIDMASK;
bByte7 |= ( uUFidValue << UFIDSHIFT );
}
if ( uOverride == SUCCESS )
{
if ( uOverrideValue > 0x1 ) // 1-bit length
return PARMERROR;
bByte7 &= ~OVERRIDEMASK;
bByte7 |= ( uOverrideValue << OVERRIDESHIFT );
}
if ( uValid == SUCCESS )
{
if ( uValidValue > 0x1 )
return PARMERROR;
bByte7 &= ~VALIDMASK;
bByte7 |= (uValidValue << VALIDSHIFT );
}
if ( uFports == SUCCESS )
{
if ( uFportsValue > 0x1f )
return PARMERROR;
bByte7 &= ~FPORTSMASK;
bByte7 |= uFportsValue;
}
//
// If there is no parameter, then just return SUCCESS
//
if ( uFid && uUFid && uOverride && uFports && uMAC && uValid )
return SUCCESS;
return ( WriteToStaticMACTable ( iEntry, (int) uMACLow, (int) ( bByte8 << 24 | bByte7 << 16 | uMACHigh ) ) );
}
//--------------------------------------------------------------------------
//
// int DisplayChipID
//
// Description:
// command:
//
// id Display KS8995M ID information including Family ID,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -