?? zl5011xpkcpreclassify.c
字號:
if (status == ZL5011X_OK)
{
status = zl5011xWriteAssembledBitFields(zl5011xParams, tempWord,
index, tempPos, address);
}
return status;
}
/*******************************************************************************
Function:
zl5011xPkcProtocolSetMaskField
Description:
Sets the masck bytes in the pre classifier. These are used to control which
of the bits in the match bytes are compared.
Inputs:
zl5011xParams Pointer to the structure for this device instance
maskNum the number of the entry to set
maskIndex array of bytes to be used for masking
Outputs:
None
Returns:
zlStatusE
Remarks:
None
*******************************************************************************/
zlStatusE zl5011xPkcProtocolSetMaskField(zl5011xParamsS *zl5011xParams,
Uint32T maskNum, Uint8T *maskIndex)
{
Uint32T tempWord[(ZL5011X_PKC_PROTOCOL_MASK_SIZE / 4) + 1];
Uint8T tempPos = 0;
Uint8T index = 0;
Uint32T address;
Uint32T loop;
zlStatusE status = ZL5011X_OK;
ZL5011X_TRACE(ZL5011X_PKC_FN_ID,
"zl5011xPkcProtocolSetMaskField: match %3d",
maskNum, 0, 0, 0, 0, 0);
address = ZL5011X_PKC_PROTOCOL_MASK +
((maskNum*2) * ZL5011X_PKC_PROTOCOL_MASK_SIZE);
/* assemble the classify match entries into 32 bit words and
then write them to the device */
for (loop = 0; loop < ZL5011X_PKC_PROTOCOL_NUM_MATCH_FIELDS; loop++)
{
if (status != ZL5011X_OK)
break;
status = zl5011xAssembleBitFields(tempWord, &index, &tempPos,
maskIndex[loop], ZL5011X_PKC_PROTOCOL_SIZE_MASK_FIELD);
}
if (status == ZL5011X_OK)
{
status = zl5011xWriteAssembledBitFields(zl5011xParams, tempWord,
index, tempPos, address);
}
return status;
}
/*******************************************************************************
Function:
zl5011xPkcProtocolConflictCheck
Description:
Checks for a protocol matching conflict.
Inputs:
zl5011xParams Pointer to the structure for this device instance
matchNum the number of the entry to disable
newMatch structure containing the pre classifier match settings
outputs:
None
Returns:
zlStatusE
Remarks:
None
*******************************************************************************/
zlStatusE zl5011xPkcProtocolConflictCheck(zl5011xParamsS *zl5011xParams,
Uint32T *matchNum, zl5011xPacketProtocolMatchS *newMatch, zl5011xBooleanE extraCheck )
{
zlStatusE status = ZL5011X_OK;
zl5011xPacketProtocolMatchS *firstMatch;
zl5011xPacketProtocolMatchS *secndMatch;
Uint32T mNum,num,ndx;
zl5011xBooleanE sameCommonMatch;
zl5011xBooleanE overridingMask;
zl5011xBooleanE identicalMatch;
Uint8T tmp;
ZL5011X_TRACE(ZL5011X_PKC_FN_ID, "zl5011xPkcProtocolConflictCheck: match %3ld",
*matchNum, 0, 0, 0, 0, 0);
if ( *matchNum >= ZL5011X_PKC_NUM_PROTOCOL_ENTRIES )
{
/* With the matchNum as invalid we assume the calling function does not know
* which entry will be used. It should turn out to be the next free one
* Does not matter if there are no free entries, as this will be dealt with elsewhere. */
mNum = 0;
while ( (mNum < ZL5011X_PKC_NUM_PROTOCOL_ENTRIES)
&& (zl5011xParams->packetIf.packetRx.pkcProtocol[mNum].protocolReserved) )
{
mNum++;
}
}
else
{
mNum = *matchNum;
}
for( num = 0; (num < ZL5011X_PKC_NUM_PROTOCOL_ENTRIES) && (status == ZL5011X_OK); num++)
{
if ( (num != mNum)
&& (zl5011xParams->packetIf.packetRx.pkcProtocol[num].protocolReserved) )
{
if ( num < mNum )
{
firstMatch = &zl5011xParams->packetIf.packetRx.pkcProtocol[num].protocolMatch;
secndMatch = newMatch;
}
else
{
firstMatch = newMatch;
secndMatch = &zl5011xParams->packetIf.packetRx.pkcProtocol[num].protocolMatch;
}
sameCommonMatch = ZL5011X_TRUE;
overridingMask = ZL5011X_TRUE;
identicalMatch = extraCheck; /* only interested if the calling function says so */
/* make comparison between new match and the current match rule given by 'num' */
for( ndx = 0; (ndx < ZL5011X_PKC_PROTOCOL_NUM_MATCH_FIELDS) && sameCommonMatch; ndx++)
{
/* assign to tmp, the mask for the common matching bits
* (note: invert as 0xff means don't care) */
tmp = ~(firstMatch->protocolMaskBytes[ndx] | secndMatch->protocolMaskBytes[ndx]);
/* see if the match values are the same using the mask above */
if ( (tmp & firstMatch->protocolMatchBytes[ndx]) != (tmp & secndMatch->protocolMatchBytes[ndx]) )
{
sameCommonMatch = ZL5011X_FALSE;
}
else
{
if ( overridingMask &&
(~firstMatch->protocolMaskBytes[ndx] & secndMatch->protocolMaskBytes[ndx]) )
{
overridingMask = ZL5011X_FALSE;
}
if ( identicalMatch &&
(firstMatch->protocolMaskBytes[ndx] != secndMatch->protocolMaskBytes[ndx]) )
{
identicalMatch = ZL5011X_FALSE;
}
}
}
/* analyse the comparison */
if ( sameCommonMatch )
{
if ( identicalMatch )
{
/* let calling function know about existing rule */
status = ZL5011X_PROTOCOL_MATCH_IN_USE;
*matchNum = num;
}
else if ( overridingMask )
{
ZL5011X_TRACE(ZL5011X_PKC_FN_ID, "Conflict: a protocol match would be hidden",0,0,0,0,0,0);
/* the proposed and the existing rules are conflicting, because the first rule will
* always over-ride the second */
status = ZL5011X_PKT_INCOMPATIBLE_HEADER_ERROR;
}
else if ( extraCheck )
{
ZL5011X_TRACE(ZL5011X_PKC_FN_ID, "Conflict: protocol match not exclusive: common with %3d",num,0,0,0,0,0);
/* not identical and not always over-riding, but the two rules do overlap
* i.e. some (or all) packets could match either rule
* Return error as the calling function cares about this */
status = ZL5011X_NO_AVAIL_PROTOCOL_MATCH;
*matchNum = num;
}
}
}
}
return status;
}
/*******************************************************************************
Function:
zl5011xPkcProtocolSetMatch
Description:
This function is used to setup a pre classifier match.
Inputs:
zl5011xParams Pointer to the structure for this device instance
matchNum the number of the entry to disable
match structure containing the pre classifier match settings
output structure containing the pre classifier output settings.
Outputs:
None
Returns:
zlStatusE
Remarks:
None
*******************************************************************************/
zlStatusE zl5011xPkcProtocolSetMatch(zl5011xParamsS *zl5011xParams,
Uint32T matchNum, zl5011xPacketProtocolMatchS *match,
zl5011xPacketProtocolOutputS *output)
{
Uint32T tempWord[(ZL5011X_PKC_PROTOCOL_OUTPUT_RAM_SIZE / 4) + 1];
Uint8T tempPos = 0;
Uint8T index = 0;
Uint32T address;
Uint32T loop;
Uint32T bits;
zlStatusE status = ZL5011X_OK;
ZL5011X_TRACE(ZL5011X_PKC_FN_ID,
"zl5011xPkcProtocolSetMatch: match %3d",
matchNum, 0, 0, 0, 0, 0);
/* check that the parameters are okay */
if ((matchNum >= ZL5011X_PKC_NUM_PROTOCOL_ENTRIES) ||
(match == NULL) ||
(output == NULL))
{
status = ZL5011X_PARAMETER_INVALID;
}
/* check that the output parameters are okay */
if (status == ZL5011X_OK)
{
status = ZL5011X_CHECK_BOOLEAN(output->discardUdpCheckFails);
}
if (status == ZL5011X_OK)
{
status = ZL5011X_CHECK_BOOLEAN(output->protocolIpv4);
}
if (status == ZL5011X_OK)
{
status = ZL5011X_CHECK_BOOLEAN(output->protocolVlan);
}
if (status == ZL5011X_OK)
{
status = ZL5011X_CHECK_BOOLEAN(output->protocolTwoByteSeq);
}
if ((status == ZL5011X_OK) &&
((output->timestampShift & ~ZL5011X_PKC_PROTOCOL_TIMESTAMP_SHIFT_MASK) != 0))
{
status = ZL5011X_PARAMETER_INVALID;
}
if (status == ZL5011X_OK)
{
loop = matchNum; /* use loop as a temporary variable */
status = zl5011xPkcProtocolConflictCheck( zl5011xParams, &loop, match, ZL5011X_FALSE );
}
/* setup the match, mask and check fields for the recognition
stage of the classifier */
if (status == ZL5011X_OK)
{
status = zl5011xPkcProtocolSetMatchField(zl5011xParams, matchNum,
match->protocolMatchBytes);
}
if (status == ZL5011X_OK)
{
status = zl5011xPkcProtocolSetMaskField(zl5011xParams,
matchNum, match->protocolMaskBytes);
}
/* set up the output Ram */
address = ZL5011X_PKC_PROTOCOL_OUTPUT_RAM +
((matchNum*2) * ZL5011X_PKC_PROTOCOL_OUTPUT_RAM_SIZE);
/* initialise the temporary buffer to 0 */
(void)memset(tempWord, 0, sizeof(tempWord));
/* write the classifier byte index'es to the output RAM */
for (loop = 0; loop < ZL5011X_PKC_CLASSIFY_NUM_MATCH_FIELDS; loop++)
{
if (status != ZL5011X_OK)
break;
status = zl5011xAssembleBitFields(tempWord, &index, &tempPos,
output->extractClassifyBytes[loop],
ZL5011X_PKC_PROTOCOL_SIZE_CLASSIFY_FIELD);
}
/* write the check byte index'es to the output RAM */
for (loop = 0; loop < ZL5011X_PKC_CLASSIFY_NUM_CHECK_FIELDS; loop++)
{
if (status != ZL5011X_OK)
break;
status = zl5011xAssembleBitFields(tempWord, &index, &tempPos,
output->extractCheckBytes[loop],
ZL5011X_PKC_PROTOCOL_SIZE_CHECK_FIELD);
}
/* write the PW status byte to the output RAM */
if (status == ZL5011X_OK)
{
status = zl5011xAssembleBitFields(tempWord, &index, &tempPos,
output->extractPwByte,
ZL5011X_PKC_PROTOCOL_SIZE_PW_FIELD);
}
/* write the sequence number bytes to the output RAM */
for (loop = 0; loop < ZL5011X_PKC_PROTOCOL_MAX_SEQ_BYTES; loop++)
{
if (status != ZL5011X_OK)
break;
status = zl5011xAssembleBitFields(tempWord, &index, &tempPos,
output->extractSequenceBytes[loop],
ZL5011X_PKC_PROTOCOL_SIZE_SEQ_FIELD);
}
/* write the timestamp bytes to the output RAM */
for (loop = 0; loop < ZL5011X_PKC_PROTOCOL_MAX_TIMESTAMP_BYTES; loop++)
{
if (status != ZL5011X_OK)
break;
status = zl5011xAssembleBitFields(tempWord, &index, &tempPos,
output->extractTimestampBytes[loop],
ZL5011X_PKC_PROTOCOL_SIZE_TIMESTAMP_FIELD);
}
/* write the length bytes to the output RAM */
for (loop = 0; loop < ZL5011X_PKC_PROTOCOL_MAX_LENGTH_BYTES; loop++)
{
if (status != ZL5011X_OK)
break;
status = zl5011xAssembleBitFields(tempWord, &index, &tempPos,
output->extractLengthBytes[loop],
ZL5011X_PKC_PROTOCOL_SIZE_LENGTH_FIELD);
}
/* write the action on UDP checksum failure bit to the output RAM */
if (status == ZL5011X_OK)
{
if (output->discardUdpCheckFails == ZL5011X_TRUE)
{
bits = 0x1;
}
else
{
bits = 0x0;
}
status = zl5011xAssembleBitFields(tempWord, &index, &tempPos,
bits,
ZL5011X_PKC_PROTOCOL_SIZE_UDP_CHECK_FIELD);
}
/* write the IP protocol bit */
if (status == ZL5011X_OK)
{
if (output->protocolIpv4 == ZL5011X_TRUE)
{
bits = 0x0;
}
else
{
bits = 0x1;
}
status = zl5011xAssembleBitFields(tempWord, &index, &tempPos,
bits,
ZL5011X_PKC_PROTOCOL_SIZE_IP_FIELD);
}
/* write the VLAN bit */
if (status == ZL5011X_OK)
{
if (output->protocolVlan == ZL5011X_TRUE)
{
bits = 0x1;
}
else
{
bits = 0x0;
}
status = zl5011xAssembleBitFields(tempWord, &index, &tempPos,
bits,
ZL5011X_PKC_PROTOCOL_SIZE_VLAN_FIELD);
}
/* write the check mask bytes to the output RAM */
for (loop = 0; loop < ZL5011X_PKC_CLASSIFY_NUM_CHECK_FIELDS; loop++)
{
if (status != ZL5011X_OK)
break;
status = zl5011xAssembleBitFields(tempWord, &index, &tempPos,
output->checkMask[loop],
ZL5011X_PKC_PROTOCOL_SIZE_CHECK_MASK_FIELD);
}
/* write the sequence length control bit to the output RAM */
if (status == ZL5011X_OK)
{
if (output->protocolTwoByteSeq == ZL5011X_TRUE)
{
bits = 0x1;
}
else
{
bits = 0x0;
}
status = zl5011xAssembleBitFields(tempWord, &index, &tempPos,
bits,
ZL5011X_PKC_PROTOCOL_SIZE_SEQ_SIZE_FIELD);
}
/* write the timestamp shift bits to the output RAM */
if (status == ZL5011X_OK)
{
status = zl5011xAssembleBitFields(tempWord, &index, &tempPos,
output->timestampShift,
ZL5011X_PKC_PROTOCOL_SIZE_TIMESTAMP_SHIFT_FIELD);
}
if (status == ZL5011X_OK)
{
status = zl5011xWriteAssembledBitFields(zl5011xParams, tempWord,
index, tempPos, address);
}
/* need to store all of these settings into the device structure */
if (status == ZL5011X_OK)
{
memcpy(&zl5011xParams->packetIf.packetRx.pkcProtocol[matchNum].protocolMatch,
match, sizeof(zl5011xPacketProtocolMatchS));
memcpy(&zl5011xParams->packetIf.packetRx.pkcProtocol[matchNum].protocolOutput,
output, sizeof(zl5011xPacketProtocolOutputS));
}
return status;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -