XilinxProcessorIPLib/drivers/emaclite/examples/xemaclite_ping_reply_example.c
static void ProcessRecvFrame(XEmacLite *InstancePtr)
{
	u16 *RxFramePtr;
	u16 *TxFramePtr;
	u16 *TempPtr;
	u16 CheckSum;
	u32 NextTxBuffBaseAddr;
	int Index;
	int PacketType = 0;

	TxFramePtr = (u16 *)TxFrame;
	RxFramePtr = (u16 *)RxFrame;

	/*
	 * Determine the next expected Tx buffer address.
	 */
	NextTxBuffBaseAddr = XEmacLite_NextTransmitAddr(InstancePtr);

	/*
	 * Check the packet type.
	 */
	Index = MAC_ADDR_LEN;
	TempPtr = (u16 *)LocalMacAddr;
	while (Index--) {
		if (Xil_Ntohs((*(RxFramePtr + Index)) == BROADCAST_ADDR) &&
					(PacketType != MAC_MATCHED_PACKET)) {
			PacketType = BROADCAST_PACKET;
		} else if (Xil_Ntohs((*(RxFramePtr + Index)) == *(TempPtr + Index)) &&
					(PacketType != BROADCAST_PACKET)) {
			PacketType = MAC_MATCHED_PACKET;
		} else {
			PacketType = 0;
			break;
		}
	}

	/*
	 * Process broadcast packet.
	 */
	if (PacketType == BROADCAST_PACKET) {

		/*
		 * Check for an ARP Packet if so generate a reply.
		 */
		if (Xil_Ntohs(*(RxFramePtr + ETHER_PROTO_TYPE_LOC)) ==
				XEL_ETHER_PROTO_TYPE_ARP) {

			/*
			 * IP address of the local machine.
			 */
			TempPtr = (u16 *)LocalIpAddr;

			/*
			 * Check destination IP address of the packet with
			 * local IP address.
			 */
			if (
			((*(RxFramePtr + ARP_REQ_DEST_IP_LOC_1)) == *TempPtr++) &&
			((*(RxFramePtr + ARP_REQ_DEST_IP_LOC_2)) == *TempPtr++)) {

				/*
				 * Check ARP packet type(request/reply).
				 */
				if (Xil_Ntohs(*(RxFramePtr + ARP_REQ_STATUS_LOC)) ==
								ARP_REQUEST) {

					/*
					 * Add destination MAC address
					 * to the reply packet (i.e) source
					 * address of the received packet.
					 */
					Index = SRC_MAC_ADDR_LOC;
					while (Index < (SRC_MAC_ADDR_LOC +
							MAC_ADDR_LEN)) {
						*TxFramePtr++ =
							*(RxFramePtr + Index);
						Index++;
					}

					/*
					 * Add source (local) MAC address
					 * to the reply packet.
					 */
					Index = 0;
					TempPtr = (u16 *)LocalMacAddr;
					while (Index < MAC_ADDR_LEN) {
						*TxFramePtr++ = *TempPtr++;
						Index++;
					}

					/*
					 * Add Ethernet proto type H/W
					 * type(10/3MBps),H/W address length and
					 * protocol address len (i.e)same as in
					 * the received packet
					 */
					Index = ETHER_PROTO_TYPE_LOC;
					while (Index < (ETHER_PROTO_TYPE_LOC +
							ETHER_PROTO_TYPE_LEN +
							ARP_HW_TYPE_LEN +
							ARP_HW_ADD_LEN
							+ ARP_PROTO_ADD_LEN)) {
						*TxFramePtr++ =
							*(RxFramePtr + Index);
						Index++;
					}

					/*
					 * Add ARP reply status to the reply
					 * packet.
					 */
					*TxFramePtr++ = Xil_Htons(ARP_REPLY);

					/*
					 * Add local MAC Address
					 * to the reply packet.
					 */
					TempPtr = (u16 *)LocalMacAddr;
					Index = 0;
					while (Index < MAC_ADDR_LEN) {
						*TxFramePtr++ = *TempPtr++;
						Index++;
					}

					/*
					 * Add local IP Address
					 * to the reply packet.
					 */
					TempPtr = (u16 *)LocalIpAddr;
					Index = 0;
					while (Index < IP_ADDR_LEN) {
						*TxFramePtr++ = *TempPtr++ ;
						Index++;
					}

					/*
					 * Add Destination MAC Address
					 * to the reply packet from the received
					 * packet.
					 */
					Index = SRC_MAC_ADDR_LOC;
					while (Index < (SRC_MAC_ADDR_LOC +
							MAC_ADDR_LEN)) {
						*TxFramePtr++ =
							*(RxFramePtr + Index);
						Index++;
					}

					/*
					 * Add Destination IP Address
					 * to the reply packet.
					 */
					Index = ARP_REQ_SRC_IP_LOC;
					while (Index < (ARP_REQ_SRC_IP_LOC +
							IP_ADDR_LEN)) {
						*TxFramePtr++ =
								*(RxFramePtr + Index);
						Index++;
					}

					/*
					 * Fill zeros as per protocol.
					 */
					Index = 0;
					while (Index < ARP_ZEROS_LEN) {
						*TxFramePtr++ = 0x0000;
						Index++;
					}

					/*
					 * Transmit the Reply Packet.
					 */
					XEmacLite_Send(InstancePtr,
							(u8 *)&TxFrame,
							ARP_PACKET_SIZE);
				}
			}
		}
	}

	/*
	 * Process packets whose MAC address is matched.
	 */
	if (PacketType == MAC_MATCHED_PACKET) {

		/*
		 * Check ICMP packet.
		 */
		if (Xil_Ntohs(*(RxFramePtr + ETHER_PROTO_TYPE_LOC)) ==
						XEL_ETHER_PROTO_TYPE_IP) {

			/*
			 * Check the IP header checksum.
			 */
			CheckSum = CheckSumCalculation(RxFramePtr,
						IP_HDR_START_LOC,
						IP_HDR_LEN);

			/*
			 * Check the Data field checksum.
			 */
			if (CheckSum == CORRECT_CKSUM_VALUE) {
				CheckSum = CheckSumCalculation(RxFramePtr,
						ICMP_DATA_START_LOC,
						ICMP_DATA_FIELD_LEN);
				if (CheckSum == CORRECT_CKSUM_VALUE) {

					/*
					 * Add destination address
					 * to the reply packet (i.e)source
					 * address of the received packet.
					 */
					Index = SRC_MAC_ADDR_LOC;
					while (Index < (SRC_MAC_ADDR_LOC +
							MAC_ADDR_LEN)) {
						*TxFramePtr++ =
							*(RxFramePtr + Index);
						Index++;
					}

					/*
					 * Add local MAC address
					 * to the reply packet.
					 */
					Index = 0;
					TempPtr = (u16 *)LocalMacAddr;
					while (Index < MAC_ADDR_LEN) {
						*TxFramePtr++ = *TempPtr++;
						Index++;
					}

					/*
					 * Add protocol type
					 * header length and, packet
					 * length(60 Bytes) to the reply packet.
					 */
					Index = ETHER_PROTO_TYPE_LOC;
					while (Index < (ETHER_PROTO_TYPE_LOC +
							ETHER_PROTO_TYPE_LEN +
							IP_VERSION_LEN +
							IP_PACKET_LEN)) {
						*TxFramePtr++ =
							*(RxFramePtr + Index);
						Index++;
					}

					/*
					 * Identification field a random number
					 * which is set to IDENT_FIELD_VALUE.
					 */
					*TxFramePtr++ = IDENT_FIELD_VALUE;

					/*
					 * Add fragment type, time to live and
					 * ICM field. It is same as in the
					 * received packet.
					 */
					Index = IP_FRAG_FIELD_LOC;
					while (Index < (IP_FRAG_FIELD_LOC +
							IP_TTL_ICM_LEN +
							IP_FRAG_FIELD_LEN)) {
						*TxFramePtr++ =
							*(RxFramePtr + Index);
						Index++;
					}

					/*
					 * Checksum first set to 0 and
					 * added in this field later.
					 */
					*TxFramePtr++ = 0x0000;

					/*
					 * Add Source IP address
					 */
					Index = 0;
					TempPtr = (u16 *)LocalIpAddr;
					while (Index < IP_ADDR_LEN) {
						*TxFramePtr++ = *TempPtr++;
						Index++;
					}

					/*
					 * Add Destination IP address.
					 */
					Index = ICMP_REQ_SRC_IP_LOC;
					while (Index < (ICMP_REQ_SRC_IP_LOC +
							IP_ADDR_LEN)) {
						*TxFramePtr++ =
							*(RxFramePtr + Index);
						Index++;
					}

					/*
					 * Calculate checksum, and
					 * add it in the appropriate field.
					 */
					CheckSum = CheckSumCalculation(
							(u16 *)TxFrame,
							IP_HDR_START_LOC,
							IP_HDR_LEN);
					CheckSum = ~CheckSum;
					*(TxFramePtr - IP_CSUM_LOC_BACK) =
								Xil_Htons(CheckSum);

					/*
					 * Echo reply status & checksum.
					 */
					Index = ICMP_ECHO_FIELD_LOC;
					while (Index < (ICMP_ECHO_FIELD_LOC +
							ICMP_ECHO_FIELD_LEN)) {
						*TxFramePtr++ = 0x0000;
						Index++;
					}

					/*
					 * Add data to buffer which was
					 * received from the packet.
					 */
					Index = ICMP_DATA_LOC;
					while (Index < (ICMP_DATA_LOC +
							ICMP_DATA_LEN)) {
						*TxFramePtr++ =
								(*(RxFramePtr + Index));
						Index++;
					}

					/*
					 * Generate checksum for the data and
					 * add it in the appropriate field.
					 */
					CheckSum = CheckSumCalculation(
							(u16 *)TxFrame,
							ICMP_DATA_START_LOC,
							ICMP_DATA_FIELD_LEN);
					CheckSum = ~CheckSum;
					*(TxFramePtr - ICMP_DATA_CSUM_LOC_BACK)
								= Xil_Htons(CheckSum);

					/*
					 * Transmit the frame.
					 */
					XEmacLite_Send(InstancePtr,
							(u8 *)&TxFrame,
							ICMP_PACKET_SIZE);

					/*
					 * Increment the number of
					 * Ping replies sent.
					 */
					NumOfPingReplies++;

				}
			}
		}
	}
}
/******************************************************************************/
/**
*
* This function processes the received packet and generates the corresponding
* reply packets.
*
* @param	InstancePtr is a pointer to the instance of the EmacLite.
*
* @return	None.
*
* @note		This function assumes MAC does not strip padding or CRC.
*
******************************************************************************/
This function processes the received packet and generates the corresponding
reply packets.
This function processes the received packet and generates the corresponding reply packets .
static void ProcessRecvFrame(XEmacLite *InstancePtr)
{
	u16 *RxFramePtr;
	u16 *TxFramePtr;
	u16 *TempPtr;
	u16 CheckSum;
	u32 NextTxBuffBaseAddr;
	int Index;
	int PacketType = 0;
	TxFramePtr = (u16 *)TxFrame;
	RxFramePtr = (u16 *)RxFrame;
	NextTxBuffBaseAddr = XEmacLite_NextTransmitAddr(InstancePtr);
	Index = MAC_ADDR_LEN;
	TempPtr = (u16 *)LocalMacAddr;
	while (Index--) {
		if (Xil_Ntohs((*(RxFramePtr + Index)) == BROADCAST_ADDR) &&
					(PacketType != MAC_MATCHED_PACKET)) {
			PacketType = BROADCAST_PACKET;
		} else if (Xil_Ntohs((*(RxFramePtr + Index)) == *(TempPtr + Index)) &&
					(PacketType != BROADCAST_PACKET)) {
			PacketType = MAC_MATCHED_PACKET;
		} else {
			PacketType = 0;
			break;
		}
	}
	if (PacketType == BROADCAST_PACKET) {
		if (Xil_Ntohs(*(RxFramePtr + ETHER_PROTO_TYPE_LOC)) ==
				XEL_ETHER_PROTO_TYPE_ARP) {
			TempPtr = (u16 *)LocalIpAddr;
			if (
			((*(RxFramePtr + ARP_REQ_DEST_IP_LOC_1)) == *TempPtr++) &&
			((*(RxFramePtr + ARP_REQ_DEST_IP_LOC_2)) == *TempPtr++)) {
				if (Xil_Ntohs(*(RxFramePtr + ARP_REQ_STATUS_LOC)) ==
								ARP_REQUEST) {
					Index = SRC_MAC_ADDR_LOC;
					while (Index < (SRC_MAC_ADDR_LOC +
							MAC_ADDR_LEN)) {
						*TxFramePtr++ =
							*(RxFramePtr + Index);
						Index++;
					}
					Index = 0;
					TempPtr = (u16 *)LocalMacAddr;
					while (Index < MAC_ADDR_LEN) {
						*TxFramePtr++ = *TempPtr++;
						Index++;
					}
					Index = ETHER_PROTO_TYPE_LOC;
					while (Index < (ETHER_PROTO_TYPE_LOC +
							ETHER_PROTO_TYPE_LEN +
							ARP_HW_TYPE_LEN +
							ARP_HW_ADD_LEN
							+ ARP_PROTO_ADD_LEN)) {
						*TxFramePtr++ =
							*(RxFramePtr + Index);
						Index++;
					}
					*TxFramePtr++ = Xil_Htons(ARP_REPLY);
					TempPtr = (u16 *)LocalMacAddr;
					Index = 0;
					while (Index < MAC_ADDR_LEN) {
						*TxFramePtr++ = *TempPtr++;
						Index++;
					}
					TempPtr = (u16 *)LocalIpAddr;
					Index = 0;
					while (Index < IP_ADDR_LEN) {
						*TxFramePtr++ = *TempPtr++ ;
						Index++;
					}
					Index = SRC_MAC_ADDR_LOC;
					while (Index < (SRC_MAC_ADDR_LOC +
							MAC_ADDR_LEN)) {
						*TxFramePtr++ =
							*(RxFramePtr + Index);
						Index++;
					}
					Index = ARP_REQ_SRC_IP_LOC;
					while (Index < (ARP_REQ_SRC_IP_LOC +
							IP_ADDR_LEN)) {
						*TxFramePtr++ =
								*(RxFramePtr + Index);
						Index++;
					}
					Index = 0;
					while (Index < ARP_ZEROS_LEN) {
						*TxFramePtr++ = 0x0000;
						Index++;
					}
					XEmacLite_Send(InstancePtr,
							(u8 *)&TxFrame,
							ARP_PACKET_SIZE);
				}
			}
		}
	}
	if (PacketType == MAC_MATCHED_PACKET) {
		if (Xil_Ntohs(*(RxFramePtr + ETHER_PROTO_TYPE_LOC)) ==
						XEL_ETHER_PROTO_TYPE_IP) {
			CheckSum = CheckSumCalculation(RxFramePtr,
						IP_HDR_START_LOC,
						IP_HDR_LEN);
			if (CheckSum == CORRECT_CKSUM_VALUE) {
				CheckSum = CheckSumCalculation(RxFramePtr,
						ICMP_DATA_START_LOC,
						ICMP_DATA_FIELD_LEN);
				if (CheckSum == CORRECT_CKSUM_VALUE) {
					Index = SRC_MAC_ADDR_LOC;
					while (Index < (SRC_MAC_ADDR_LOC +
							MAC_ADDR_LEN)) {
						*TxFramePtr++ =
							*(RxFramePtr + Index);
						Index++;
					}
					Index = 0;
					TempPtr = (u16 *)LocalMacAddr;
					while (Index < MAC_ADDR_LEN) {
						*TxFramePtr++ = *TempPtr++;
						Index++;
					}
					Index = ETHER_PROTO_TYPE_LOC;
					while (Index < (ETHER_PROTO_TYPE_LOC +
							ETHER_PROTO_TYPE_LEN +
							IP_VERSION_LEN +
							IP_PACKET_LEN)) {
						*TxFramePtr++ =
							*(RxFramePtr + Index);
						Index++;
					}
					*TxFramePtr++ = IDENT_FIELD_VALUE;
					Index = IP_FRAG_FIELD_LOC;
					while (Index < (IP_FRAG_FIELD_LOC +
							IP_TTL_ICM_LEN +
							IP_FRAG_FIELD_LEN)) {
						*TxFramePtr++ =
							*(RxFramePtr + Index);
						Index++;
					}
					*TxFramePtr++ = 0x0000;
					Index = 0;
					TempPtr = (u16 *)LocalIpAddr;
					while (Index < IP_ADDR_LEN) {
						*TxFramePtr++ = *TempPtr++;
						Index++;
					}
					Index = ICMP_REQ_SRC_IP_LOC;
					while (Index < (ICMP_REQ_SRC_IP_LOC +
							IP_ADDR_LEN)) {
						*TxFramePtr++ =
							*(RxFramePtr + Index);
						Index++;
					}
					CheckSum = CheckSumCalculation(
							(u16 *)TxFrame,
							IP_HDR_START_LOC,
							IP_HDR_LEN);
					CheckSum = ~CheckSum;
					*(TxFramePtr - IP_CSUM_LOC_BACK) =
								Xil_Htons(CheckSum);
					Index = ICMP_ECHO_FIELD_LOC;
					while (Index < (ICMP_ECHO_FIELD_LOC +
							ICMP_ECHO_FIELD_LEN)) {
						*TxFramePtr++ = 0x0000;
						Index++;
					}
					Index = ICMP_DATA_LOC;
					while (Index < (ICMP_DATA_LOC +
							ICMP_DATA_LEN)) {
						*TxFramePtr++ =
								(*(RxFramePtr + Index));
						Index++;
					}
					CheckSum = CheckSumCalculation(
							(u16 *)TxFrame,
							ICMP_DATA_START_LOC,
							ICMP_DATA_FIELD_LEN);
					CheckSum = ~CheckSum;
					*(TxFramePtr - ICMP_DATA_CSUM_LOC_BACK)
								= Xil_Htons(CheckSum);
					XEmacLite_Send(InstancePtr,
							(u8 *)&TxFrame,
							ICMP_PACKET_SIZE);
					NumOfPingReplies++;
				}
			}
		}
	}
}
static void ProcessRecvFrame ( XEmacLite * InstancePtr ) { u16 * RxFramePtr ; u16 * TxFramePtr ; u16 * TempPtr ; u16 CheckSum ; u32 NextTxBuffBaseAddr ; int Index ; int PacketType = 0 ; TxFramePtr = ( u16 * ) TxFrame ; RxFramePtr = ( u16 * ) RxFrame ; NextTxBuffBaseAddr = XEmacLite_NextTransmitAddr ( InstancePtr ) ; Index = MAC_ADDR_LEN ; TempPtr = ( u16 * ) LocalMacAddr ; while ( Index -- ) { if ( Xil_Ntohs ( ( * ( RxFramePtr + Index ) ) == BROADCAST_ADDR ) && ( PacketType != MAC_MATCHED_PACKET ) ) { PacketType = BROADCAST_PACKET ; } else if ( Xil_Ntohs ( ( * ( RxFramePtr + Index ) ) == * ( TempPtr + Index ) ) && ( PacketType != BROADCAST_PACKET ) ) { PacketType = MAC_MATCHED_PACKET ; } else { PacketType = 0 ; break ; } } if ( PacketType == BROADCAST_PACKET ) { if ( Xil_Ntohs ( * ( RxFramePtr + ETHER_PROTO_TYPE_LOC ) ) == XEL_ETHER_PROTO_TYPE_ARP ) { TempPtr = ( u16 * ) LocalIpAddr ; if ( ( ( * ( RxFramePtr + ARP_REQ_DEST_IP_LOC_1 ) ) == * TempPtr ++ ) && ( ( * ( RxFramePtr + ARP_REQ_DEST_IP_LOC_2 ) ) == * TempPtr ++ ) ) { if ( Xil_Ntohs ( * ( RxFramePtr + ARP_REQ_STATUS_LOC ) ) == ARP_REQUEST ) { Index = SRC_MAC_ADDR_LOC ; while ( Index < ( SRC_MAC_ADDR_LOC + MAC_ADDR_LEN ) ) { * TxFramePtr ++ = * ( RxFramePtr + Index ) ; Index ++ ; } Index = 0 ; TempPtr = ( u16 * ) LocalMacAddr ; while ( Index < MAC_ADDR_LEN ) { * TxFramePtr ++ = * TempPtr ++ ; Index ++ ; } Index = ETHER_PROTO_TYPE_LOC ; while ( Index < ( ETHER_PROTO_TYPE_LOC + ETHER_PROTO_TYPE_LEN + ARP_HW_TYPE_LEN + ARP_HW_ADD_LEN + ARP_PROTO_ADD_LEN ) ) { * TxFramePtr ++ = * ( RxFramePtr + Index ) ; Index ++ ; } * TxFramePtr ++ = Xil_Htons ( ARP_REPLY ) ; TempPtr = ( u16 * ) LocalMacAddr ; Index = 0 ; while ( Index < MAC_ADDR_LEN ) { * TxFramePtr ++ = * TempPtr ++ ; Index ++ ; } TempPtr = ( u16 * ) LocalIpAddr ; Index = 0 ; while ( Index < IP_ADDR_LEN ) { * TxFramePtr ++ = * TempPtr ++ ; Index ++ ; } Index = SRC_MAC_ADDR_LOC ; while ( Index < ( SRC_MAC_ADDR_LOC + MAC_ADDR_LEN ) ) { * TxFramePtr ++ = * ( RxFramePtr + Index ) ; Index ++ ; } Index = ARP_REQ_SRC_IP_LOC ; while ( Index < ( ARP_REQ_SRC_IP_LOC + IP_ADDR_LEN ) ) { * TxFramePtr ++ = * ( RxFramePtr + Index ) ; Index ++ ; } Index = 0 ; while ( Index < ARP_ZEROS_LEN ) { * TxFramePtr ++ = 0x0000 ; Index ++ ; } XEmacLite_Send ( InstancePtr , ( u8 * ) & TxFrame , ARP_PACKET_SIZE ) ; } } } } if ( PacketType == MAC_MATCHED_PACKET ) { if ( Xil_Ntohs ( * ( RxFramePtr + ETHER_PROTO_TYPE_LOC ) ) == XEL_ETHER_PROTO_TYPE_IP ) { CheckSum = CheckSumCalculation ( RxFramePtr , IP_HDR_START_LOC , IP_HDR_LEN ) ; if ( CheckSum == CORRECT_CKSUM_VALUE ) { CheckSum = CheckSumCalculation ( RxFramePtr , ICMP_DATA_START_LOC , ICMP_DATA_FIELD_LEN ) ; if ( CheckSum == CORRECT_CKSUM_VALUE ) { Index = SRC_MAC_ADDR_LOC ; while ( Index < ( SRC_MAC_ADDR_LOC + MAC_ADDR_LEN ) ) { * TxFramePtr ++ = * ( RxFramePtr + Index ) ; Index ++ ; } Index = 0 ; TempPtr = ( u16 * ) LocalMacAddr ; while ( Index < MAC_ADDR_LEN ) { * TxFramePtr ++ = * TempPtr ++ ; Index ++ ; } Index = ETHER_PROTO_TYPE_LOC ; while ( Index < ( ETHER_PROTO_TYPE_LOC + ETHER_PROTO_TYPE_LEN + IP_VERSION_LEN + IP_PACKET_LEN ) ) { * TxFramePtr ++ = * ( RxFramePtr + Index ) ; Index ++ ; } * TxFramePtr ++ = IDENT_FIELD_VALUE ; Index = IP_FRAG_FIELD_LOC ; while ( Index < ( IP_FRAG_FIELD_LOC + IP_TTL_ICM_LEN + IP_FRAG_FIELD_LEN ) ) { * TxFramePtr ++ = * ( RxFramePtr + Index ) ; Index ++ ; } * TxFramePtr ++ = 0x0000 ; Index = 0 ; TempPtr = ( u16 * ) LocalIpAddr ; while ( Index < IP_ADDR_LEN ) { * TxFramePtr ++ = * TempPtr ++ ; Index ++ ; } Index = ICMP_REQ_SRC_IP_LOC ; while ( Index < ( ICMP_REQ_SRC_IP_LOC + IP_ADDR_LEN ) ) { * TxFramePtr ++ = * ( RxFramePtr + Index ) ; Index ++ ; } CheckSum = CheckSumCalculation ( ( u16 * ) TxFrame , IP_HDR_START_LOC , IP_HDR_LEN ) ; CheckSum = ~ CheckSum ; * ( TxFramePtr - IP_CSUM_LOC_BACK ) = Xil_Htons ( CheckSum ) ; Index = ICMP_ECHO_FIELD_LOC ; while ( Index < ( ICMP_ECHO_FIELD_LOC + ICMP_ECHO_FIELD_LEN ) ) { * TxFramePtr ++ = 0x0000 ; Index ++ ; } Index = ICMP_DATA_LOC ; while ( Index < ( ICMP_DATA_LOC + ICMP_DATA_LEN ) ) { * TxFramePtr ++ = ( * ( RxFramePtr + Index ) ) ; Index ++ ; } CheckSum = CheckSumCalculation ( ( u16 * ) TxFrame , ICMP_DATA_START_LOC , ICMP_DATA_FIELD_LEN ) ; CheckSum = ~ CheckSum ; * ( TxFramePtr - ICMP_DATA_CSUM_LOC_BACK ) = Xil_Htons ( CheckSum ) ; XEmacLite_Send ( InstancePtr , ( u8 * ) & TxFrame , ICMP_PACKET_SIZE ) ; NumOfPingReplies ++ ; } } } } }
This function processes the received packet and generates the corresponding
reply packets.
This function processes the received packet and generates the corresponding reply packets .
/*
	 * Determine the next expected Tx buffer address.
	 */ /*
	 * Check the packet type.
	 */ /*
	 * Process broadcast packet.
	 */ /*
		 * Check for an ARP Packet if so generate a reply.
		 */ /*
			 * IP address of the local machine.
			 */ /*
			 * Check destination IP address of the packet with
			 * local IP address.
			 */ /*
				 * Check ARP packet type(request/reply).
				 */ /*
					 * Add destination MAC address
					 * to the reply packet (i.e) source
					 * address of the received packet.
					 */ /*
					 * Add source (local) MAC address
					 * to the reply packet.
					 */ /*
					 * Add Ethernet proto type H/W
					 * type(10/3MBps),H/W address length and
					 * protocol address len (i.e)same as in
					 * the received packet
					 */ /*
					 * Add ARP reply status to the reply
					 * packet.
					 */ /*
					 * Add local MAC Address
					 * to the reply packet.
					 */ /*
					 * Add local IP Address
					 * to the reply packet.
					 */ /*
					 * Add Destination MAC Address
					 * to the reply packet from the received
					 * packet.
					 */ /*
					 * Add Destination IP Address
					 * to the reply packet.
					 */ /*
					 * Fill zeros as per protocol.
					 */ /*
					 * Transmit the Reply Packet.
					 */ /*
	 * Process packets whose MAC address is matched.
	 */ /*
		 * Check ICMP packet.
		 */ /*
			 * Check the IP header checksum.
			 */ /*
			 * Check the Data field checksum.
			 */ /*
					 * Add destination address
					 * to the reply packet (i.e)source
					 * address of the received packet.
					 */ /*
					 * Add local MAC address
					 * to the reply packet.
					 */ /*
					 * Add protocol type
					 * header length and, packet
					 * length(60 Bytes) to the reply packet.
					 */ /*
					 * Identification field a random number
					 * which is set to IDENT_FIELD_VALUE.
					 */ /*
					 * Add fragment type, time to live and
					 * ICM field. It is same as in the
					 * received packet.
					 */ /*
					 * Checksum first set to 0 and
					 * added in this field later.
					 */ /*
					 * Add Source IP address
					 */ /*
					 * Add Destination IP address.
					 */ /*
					 * Calculate checksum, and
					 * add it in the appropriate field.
					 */ /*
					 * Echo reply status & checksum.
					 */ /*
					 * Add data to buffer which was
					 * received from the packet.
					 */ /*
					 * Generate checksum for the data and
					 * add it in the appropriate field.
					 */ /*
					 * Transmit the frame.
					 */ /*
					 * Increment the number of
					 * Ping replies sent.
					 */