sitara_depot/components/free_rtos/ethernet_ip/eth_icmp.cpp

47 lines
997 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* eth_icmp.cpp
*
* Created on: 14 мар. 2023 г.
* Author: sychev
*/
#include "free_rtos/ethernet_ip/eth_icmp.hpp"
#include "free_rtos/ethernet_ip/eth_icmp_types.h"
#include "free_rtos/ethernet_ip/eth_ip_checksum.h"
#include "free_rtos/base/swap.h"
int32_t free_rtos::EthIcmp::Process(uint8_t * p_data, uint32_t len)
{
TIcmpEchoHeader * hdr = (TIcmpEchoHeader*)p_data;
uint32_t ul_icmp_len = len;
if (hdr->type != ICMP_ECHO_REQUEST) {
return 0;
}
hdr->type = ICMP_ECHO_REPLY;
hdr->code = 0;
hdr->cksum = 0;
/* Checksum of the ICMP message */
if (ul_icmp_len % 2)
{
*(((uint8_t *) hdr) + ul_icmp_len) = 0;
++ul_icmp_len;
}
ul_icmp_len = ul_icmp_len / 2;
uint16_t chsum = eth_ip_calcChecksum((uint16_t *)hdr, ul_icmp_len);
hdr->cksum = BASE_SWAP16(chsum);
++rx_cnt_;
return len;
}
uint16_t free_rtos::EthIcmp::Sender(HandlerArgs& handlerArgs, size_t scatter_segment)
{
return 0;
}