47 lines
953 B
C++
47 lines
953 B
C++
/*
|
||
* eth_icmp.cpp
|
||
*
|
||
* Created on: 14 <20><><EFBFBD>. 2023 <20>.
|
||
* 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;
|
||
}
|
||
|
||
uint32_t free_rtos::EthIcmp::Sender(uint8_t * p_data, size_t scatter_segment)
|
||
{
|
||
return 0;
|
||
}
|