XilinxProcessorIPLib/drivers/axiethernet/examples/xaxiethernet_example_util.c
int AxiEthernetUtilFrameVerify(EthernetFrame * CheckFrame,
			 EthernetFrame * ActualFrame)
{
	unsigned char *CheckPtr = (unsigned char *) CheckFrame;
	unsigned char *ActualPtr = (unsigned char *) ActualFrame;
	u16 BytesLeft;
	u16 Counter;
	int Index;

	CheckPtr = CheckPtr + Padding;
	ActualPtr = ActualPtr + Padding;

	/*
	 * Compare the headers
	 */
	for (Index = 0; Index < XAE_HDR_SIZE; Index++) {
		if (CheckPtr[Index] != ActualPtr[Index]) {
			return XST_FAILURE;
		}
	}

	Index = 0;

	BytesLeft = *(u16 *) &ActualPtr[12];
	BytesLeft = Xil_Ntohs(BytesLeft);
	/*
	 * Get the length of the payload, do not use VLAN TPID here.
	 * TPID needs to be verified.
	 */
	while ((0x8100 == BytesLeft) || (0x88A8 == BytesLeft) ||
	       (0x9100 == BytesLeft) || (0x9200 == BytesLeft)) {
		Index++;
		BytesLeft = *(u16 *) &ActualPtr[12+(4*Index)];
		BytesLeft = Xil_Ntohs(BytesLeft);
	}

	/*
	 * Validate the payload
	 */
	Counter = 0;
	ActualPtr = &ActualPtr[14+(4*Index)];

	/*
	 * Check 8 bit incrementing pattern
	 */
	while (BytesLeft && (Counter < 256)) {
		if (*ActualPtr++ != (u8) Counter++) {

			return XST_FAILURE;
		}
		BytesLeft--;
	}

	/*
	 * Check 16 bit incrementing pattern
	 */
	while (BytesLeft) {
		if (*ActualPtr++ != (u8) (Counter >> 8)) {	/* high */
			return XST_FAILURE;
		}

		BytesLeft--;

		if (!BytesLeft)
			break;

		if (*ActualPtr++ != (u8) Counter++) {	/* low */
			return XST_FAILURE;
		}

		BytesLeft--;
	}

	return XST_SUCCESS;
}
/******************************************************************************/
/**
* This function verifies the frame data against a CheckFrame.
*
* Validation occurs by comparing the ActualFrame to the header of the
* CheckFrame. If the headers match, then the payload of ActualFrame is
* verified for the same pattern Util_FrameSetPayloadData() generates.
*
* @param	CheckFrame is a pointer to a frame containing the 14 byte header
*		that should be present in the ActualFrame parameter.
* @param	ActualFrame is a pointer to a frame to validate.
*
* @return
*		- XST_SUCCESS if successful.
*		- XST_FAILURE in case of failure.
*
* @note		None.
*
******************************************************************************/
This function verifies the frame data against a CheckFrame.
Validation occurs by comparing the ActualFrame to the header of the
CheckFrame. If the headers match, then the payload of ActualFrame is
verified for the same pattern Util_FrameSetPayloadData() generates.
This function verifies the frame data against a CheckFrame . Validation occurs by comparing the ActualFrame to the header of the CheckFrame . If the headers match then the payload of ActualFrame is verified for the same pattern Util_FrameSetPayloadData () generates .
int AxiEthernetUtilFrameVerify(EthernetFrame * CheckFrame,
			 EthernetFrame * ActualFrame)
{
	unsigned char *CheckPtr = (unsigned char *) CheckFrame;
	unsigned char *ActualPtr = (unsigned char *) ActualFrame;
	u16 BytesLeft;
	u16 Counter;
	int Index;
	CheckPtr = CheckPtr + Padding;
	ActualPtr = ActualPtr + Padding;
	for (Index = 0; Index < XAE_HDR_SIZE; Index++) {
		if (CheckPtr[Index] != ActualPtr[Index]) {
			return XST_FAILURE;
		}
	}
	Index = 0;
	BytesLeft = *(u16 *) &ActualPtr[12];
	BytesLeft = Xil_Ntohs(BytesLeft);
	while ((0x8100 == BytesLeft) || (0x88A8 == BytesLeft) ||
	       (0x9100 == BytesLeft) || (0x9200 == BytesLeft)) {
		Index++;
		BytesLeft = *(u16 *) &ActualPtr[12+(4*Index)];
		BytesLeft = Xil_Ntohs(BytesLeft);
	}
	Counter = 0;
	ActualPtr = &ActualPtr[14+(4*Index)];
	while (BytesLeft && (Counter < 256)) {
		if (*ActualPtr++ != (u8) Counter++) {
			return XST_FAILURE;
		}
		BytesLeft--;
	}
	while (BytesLeft) {
		if (*ActualPtr++ != (u8) (Counter >> 8)) {	
			return XST_FAILURE;
		}
		BytesLeft--;
		if (!BytesLeft)
			break;
		if (*ActualPtr++ != (u8) Counter++) {	
			return XST_FAILURE;
		}
		BytesLeft--;
	}
	return XST_SUCCESS;
}
int AxiEthernetUtilFrameVerify ( EthernetFrame * CheckFrame , EthernetFrame * ActualFrame ) { unsigned char * CheckPtr = ( unsigned char * ) CheckFrame ; unsigned char * ActualPtr = ( unsigned char * ) ActualFrame ; u16 BytesLeft ; u16 Counter ; int Index ; CheckPtr = CheckPtr + Padding ; ActualPtr = ActualPtr + Padding ; for ( Index = 0 ; Index < XAE_HDR_SIZE ; Index ++ ) { if ( CheckPtr [ Index ] != ActualPtr [ Index ] ) { return XST_FAILURE ; } } Index = 0 ; BytesLeft = * ( u16 * ) & ActualPtr [ 12 ] ; BytesLeft = Xil_Ntohs ( BytesLeft ) ; while ( ( 0x8100 == BytesLeft ) || ( 0x88A8 == BytesLeft ) || ( 0x9100 == BytesLeft ) || ( 0x9200 == BytesLeft ) ) { Index ++ ; BytesLeft = * ( u16 * ) & ActualPtr [ 12 + ( 4 * Index ) ] ; BytesLeft = Xil_Ntohs ( BytesLeft ) ; } Counter = 0 ; ActualPtr = & ActualPtr [ 14 + ( 4 * Index ) ] ; while ( BytesLeft && ( Counter < 256 ) ) { if ( * ActualPtr ++ != ( u8 ) Counter ++ ) { return XST_FAILURE ; } BytesLeft -- ; } while ( BytesLeft ) { if ( * ActualPtr ++ != ( u8 ) ( Counter >> 8 ) ) { return XST_FAILURE ; } BytesLeft -- ; if ( ! BytesLeft ) break ; if ( * ActualPtr ++ != ( u8 ) Counter ++ ) { return XST_FAILURE ; } BytesLeft -- ; } return XST_SUCCESS ; }
This function verifies the frame data against a CheckFrame.
This function verifies the frame data against a CheckFrame .
/*
	 * Compare the headers
	 */ /*
	 * Get the length of the payload, do not use VLAN TPID here.
	 * TPID needs to be verified.
	 */ /*
	 * Validate the payload
	 */ /*
	 * Check 8 bit incrementing pattern
	 */ /*
	 * Check 16 bit incrementing pattern
	 */ /* high */ /* low */