2023-05-03 14:01:32 +03:00
|
|
|
|
/*
|
|
|
|
|
* eth_icmp.cpp
|
|
|
|
|
*
|
2023-06-08 12:27:49 +03:00
|
|
|
|
* Created on: 14 <EFBFBD><EFBFBD><EFBFBD>. 2023 <EFBFBD>.
|
2023-05-03 14:01:32 +03:00
|
|
|
|
* Author: sychev
|
|
|
|
|
*/
|
|
|
|
|
#include "ethernet_ip/eth_icmp.hpp"
|
|
|
|
|
#include "ethernet_ip/eth_icmp_types.h"
|
|
|
|
|
#include "ethernet_ip/eth_ip_checksum.h"
|
|
|
|
|
#include "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;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-08 12:27:49 +03:00
|
|
|
|
uint32_t free_rtos::EthIcmp::Sender(uint8_t * p_data, size_t scatter_segment)
|
|
|
|
|
{
|
2023-06-08 14:46:25 +03:00
|
|
|
|
return 0;
|
2023-06-08 12:27:49 +03:00
|
|
|
|
}
|