XilinxProcessorIPLib/drivers/axiethernet/examples/xaxiethernet_mcdma_ping_req_example.c
int ProcessRecvFrame(XAxiEthernet *AxiEthernetInstancePtr,
	             XMcdma *DmaInstancePtr, u8 ChanId)
{
	u16 *RxFramePtr;
	u16 *TempPtr;
	u16 CheckSum;
	int Index;
	int Match = 0;
	int DataWrong = 0;


	RxFramePtr = (u16 *)(UINTPTR)GetRxBufAddr();
	TempPtr = (u16 *)LocalMacAddr;

	/*
	 * Check Dest Mac address of the packet with the LocalMac address.
	 */
	Match = CompareData(RxFramePtr, TempPtr, 0, 0, MAC_ADDR_LEN);
	if (Padding) {
		RxFramePtr += 4;
		Match = CompareData(RxFramePtr, TempPtr, 0, 0, MAC_ADDR_LEN);
	}
	if (Match == XST_SUCCESS) {
		/*
		 * Check ARP type.
		 */
		if (Xil_Ntohs(*(RxFramePtr + ETHER_PROTO_TYPE_LOC)) ==
				XAE_ETHER_PROTO_TYPE_ARP ) {

			/*
			 * Check ARP status.
			 */
			if (Xil_Ntohs(*(RxFramePtr + ARP_REQ_STATUS_LOC)) == ARP_REPLY) {

				/*
				 * Check destination IP address with
				 * packet's source IP address.
				 */
				TempPtr = (u16 *)DestIpAddress;
				Match = CompareData(RxFramePtr,
						TempPtr, ARP_REQ_SRC_IP_LOC,
						0, IP_ADDR_LEN);
				if (Match == XST_SUCCESS) {

					/*
					 * Copy src Mac address of the received
					 * packet.
					 */
					Index = MAC_ADDR_LEN;
					TempPtr = (u16 *)DestMacAddr;
					while (Index--) {
						*(TempPtr + Index) =
							*(RxFramePtr +
							(SRC_MAC_ADDR_LOC +
								Index));
					}

					/*
					 * Send Echo request packet.
					 */
					SendEchoReqFrame(AxiEthernetInstancePtr, DmaInstancePtr, ChanId);
				}
			}
		}

		/*
		 * Check for IP type.
		 */
		else if (Xil_Ntohs(*(RxFramePtr + ETHER_PROTO_TYPE_LOC)) ==
						XAE_ETHER_PROTO_TYPE_IP) {

			/*
			 * Calculate checksum.
			 */
			CheckSum = CheckSumCalculation(RxFramePtr,
							ICMP_DATA_START_LOC,
							ICMP_DATA_FIELD_LEN);

			/*
			 * Verify checksum, echo reply, identifier number and
			 * sequence number of the received packet.
			 */
			if ((CheckSum == CORRECT_CHECKSUM_VALUE) &&
			(Xil_Ntohs(*(RxFramePtr + ICMP_ECHO_FIELD_LOC)) == ECHO_REPLY) &&
			(Xil_Ntohs(*(RxFramePtr + ICMP_IDEN_FIELD_LOC)) == IDEN_NUM) &&
			(Xil_Ntohs(*(RxFramePtr + (ICMP_SEQ_NO_LOC))) == SeqNum)) {

				/*
				 * Verify data in the received packet with known
				 * data.
				 */
				TempPtr = IcmpData;
				Match = CompareData(RxFramePtr,
						TempPtr, ICMP_KNOWN_DATA_LOC,
							0, ICMP_KNOWN_DATA_LEN);
				if (Match == XST_FAILURE) {
					DataWrong = 1;
				}
			}
			if (DataWrong != 1) {
				xil_printf("Packet No: %d ",
				NUM_OF_PING_REQ_PKTS - NumOfPingReqPkts);
				xil_printf("Seq NO %d Echo Packet received\r\n",
								SeqNum);
				return XST_SUCCESS;
			}
		}
	}
	return XST_FAILURE;
}
/*****************************************************************************/
/**
*
* This function will process the received packet. This function sends
* the echo request packet based on the ARP reply packet.
*
* @param	AxiEthernetInstancePtr is a pointer to the instance of the
*		Axi Ethernet component.
* @param	DmaInstancePtr is a pointer to the instance of the Dma
*		component.
* @param	ChanId is the MCDMA Channel number to be operate on.
*
* @return	XST_SUCCESS is returned when an echo reply is received.
*		Otherwise, XST_FAILURE is returned.
*
* @note		This assumes MAC does not strip padding or CRC.
*
******************************************************************************/
This function will process the received packet. This function sends
the echo request packet based on the ARP reply packet.
This function will process the received packet . This function sends the echo request packet based on the ARP reply packet .
int ProcessRecvFrame(XAxiEthernet *AxiEthernetInstancePtr,
	             XMcdma *DmaInstancePtr, u8 ChanId)
{
	u16 *RxFramePtr;
	u16 *TempPtr;
	u16 CheckSum;
	int Index;
	int Match = 0;
	int DataWrong = 0;
	RxFramePtr = (u16 *)(UINTPTR)GetRxBufAddr();
	TempPtr = (u16 *)LocalMacAddr;
	Match = CompareData(RxFramePtr, TempPtr, 0, 0, MAC_ADDR_LEN);
	if (Padding) {
		RxFramePtr += 4;
		Match = CompareData(RxFramePtr, TempPtr, 0, 0, MAC_ADDR_LEN);
	}
	if (Match == XST_SUCCESS) {
		if (Xil_Ntohs(*(RxFramePtr + ETHER_PROTO_TYPE_LOC)) ==
				XAE_ETHER_PROTO_TYPE_ARP ) {
			if (Xil_Ntohs(*(RxFramePtr + ARP_REQ_STATUS_LOC)) == ARP_REPLY) {
				TempPtr = (u16 *)DestIpAddress;
				Match = CompareData(RxFramePtr,
						TempPtr, ARP_REQ_SRC_IP_LOC,
						0, IP_ADDR_LEN);
				if (Match == XST_SUCCESS) {
					Index = MAC_ADDR_LEN;
					TempPtr = (u16 *)DestMacAddr;
					while (Index--) {
						*(TempPtr + Index) =
							*(RxFramePtr +
							(SRC_MAC_ADDR_LOC +
								Index));
					}
					SendEchoReqFrame(AxiEthernetInstancePtr, DmaInstancePtr, ChanId);
				}
			}
		}
		else if (Xil_Ntohs(*(RxFramePtr + ETHER_PROTO_TYPE_LOC)) ==
						XAE_ETHER_PROTO_TYPE_IP) {
			CheckSum = CheckSumCalculation(RxFramePtr,
							ICMP_DATA_START_LOC,
							ICMP_DATA_FIELD_LEN);
			if ((CheckSum == CORRECT_CHECKSUM_VALUE) &&
			(Xil_Ntohs(*(RxFramePtr + ICMP_ECHO_FIELD_LOC)) == ECHO_REPLY) &&
			(Xil_Ntohs(*(RxFramePtr + ICMP_IDEN_FIELD_LOC)) == IDEN_NUM) &&
			(Xil_Ntohs(*(RxFramePtr + (ICMP_SEQ_NO_LOC))) == SeqNum)) {
				TempPtr = IcmpData;
				Match = CompareData(RxFramePtr,
						TempPtr, ICMP_KNOWN_DATA_LOC,
							0, ICMP_KNOWN_DATA_LEN);
				if (Match == XST_FAILURE) {
					DataWrong = 1;
				}
			}
			if (DataWrong != 1) {
				xil_printf("Packet No: %d ",
				NUM_OF_PING_REQ_PKTS - NumOfPingReqPkts);
				xil_printf("Seq NO %d Echo Packet received\r\n",
								SeqNum);
				return XST_SUCCESS;
			}
		}
	}
	return XST_FAILURE;
}
int ProcessRecvFrame ( XAxiEthernet * AxiEthernetInstancePtr , XMcdma * DmaInstancePtr , u8 ChanId ) { u16 * RxFramePtr ; u16 * TempPtr ; u16 CheckSum ; int Index ; int Match = 0 ; int DataWrong = 0 ; RxFramePtr = ( u16 * ) ( UINTPTR ) GetRxBufAddr ( ) ; TempPtr = ( u16 * ) LocalMacAddr ; Match = CompareData ( RxFramePtr , TempPtr , 0 , 0 , MAC_ADDR_LEN ) ; if ( Padding ) { RxFramePtr += 4 ; Match = CompareData ( RxFramePtr , TempPtr , 0 , 0 , MAC_ADDR_LEN ) ; } if ( Match == XST_SUCCESS ) { if ( Xil_Ntohs ( * ( RxFramePtr + ETHER_PROTO_TYPE_LOC ) ) == XAE_ETHER_PROTO_TYPE_ARP ) { if ( Xil_Ntohs ( * ( RxFramePtr + ARP_REQ_STATUS_LOC ) ) == ARP_REPLY ) { TempPtr = ( u16 * ) DestIpAddress ; Match = CompareData ( RxFramePtr , TempPtr , ARP_REQ_SRC_IP_LOC , 0 , IP_ADDR_LEN ) ; if ( Match == XST_SUCCESS ) { Index = MAC_ADDR_LEN ; TempPtr = ( u16 * ) DestMacAddr ; while ( Index -- ) { * ( TempPtr + Index ) = * ( RxFramePtr + ( SRC_MAC_ADDR_LOC + Index ) ) ; } SendEchoReqFrame ( AxiEthernetInstancePtr , DmaInstancePtr , ChanId ) ; } } } else if ( Xil_Ntohs ( * ( RxFramePtr + ETHER_PROTO_TYPE_LOC ) ) == XAE_ETHER_PROTO_TYPE_IP ) { CheckSum = CheckSumCalculation ( RxFramePtr , ICMP_DATA_START_LOC , ICMP_DATA_FIELD_LEN ) ; if ( ( CheckSum == CORRECT_CHECKSUM_VALUE ) && ( Xil_Ntohs ( * ( RxFramePtr + ICMP_ECHO_FIELD_LOC ) ) == ECHO_REPLY ) && ( Xil_Ntohs ( * ( RxFramePtr + ICMP_IDEN_FIELD_LOC ) ) == IDEN_NUM ) && ( Xil_Ntohs ( * ( RxFramePtr + ( ICMP_SEQ_NO_LOC ) ) ) == SeqNum ) ) { TempPtr = IcmpData ; Match = CompareData ( RxFramePtr , TempPtr , ICMP_KNOWN_DATA_LOC , 0 , ICMP_KNOWN_DATA_LEN ) ; if ( Match == XST_FAILURE ) { DataWrong = 1 ; } } if ( DataWrong != 1 ) { xil_printf ( " " , NUM_OF_PING_REQ_PKTS - NumOfPingReqPkts ) ; xil_printf ( " \r \n " , SeqNum ) ; return XST_SUCCESS ; } } } return XST_FAILURE ; }
This function will process the received packet.
This function will process the received packet .
/*
	 * Check Dest Mac address of the packet with the LocalMac address.
	 */ /*
		 * Check ARP type.
		 */ /*
			 * Check ARP status.
			 */ /*
				 * Check destination IP address with
				 * packet's source IP address.
				 */ /*
					 * Copy src Mac address of the received
					 * packet.
					 */ /*
					 * Send Echo request packet.
					 */ /*
		 * Check for IP type.
		 */ /*
			 * Calculate checksum.
			 */ /*
			 * Verify checksum, echo reply, identifier number and
			 * sequence number of the received packet.
			 */ /*
				 * Verify data in the received packet with known
				 * data.
				 */