sitara_depot/components/free_rtos/ethernet_ip/eth_arp.hpp

81 lines
1.8 KiB
C++
Raw 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_arp.hpp
*
* Created on: 13 мар. 2023 г.
* Author: sychev
*/
#ifndef FREE_RTOS_ETHERNET_IP_ETH_ARP_HPP_
#define FREE_RTOS_ETHERNET_IP_ETH_ARP_HPP_
#include <map>
#include <cstdint>
#include "free_rtos/ethernet_ip/eth_arp_iface.hpp"
#include "free_rtos/ethernet_ip/eth_stack_iface.hpp"
#include "free_rtos/handler_store/handler.hpp"
#include "free_rtos/clock/clock.hpp"
#include "free_rtos/timer_sw/timer_sw.hpp"
namespace free_rtos {
class EthArp : public Handler, public EthArpIface {
public:
EthArp(EthStackIface& eth_stack);
bool init(TEthMacPorts eth_port_id, uint64_t self_mac, uint32_t self_ip);
bool getIpAddr(uint64_t mac, uint32_t& ip);
virtual bool getMacAddr(uint32_t ip, uint64_t& mac) override;
bool try_request(uint32_t ip);
virtual int32_t Process(uint8_t * p_data, uint32_t len) override;
virtual uint16_t Sender(HandlerArgs& handlerArgs, size_t scatter_segment) override;
private:
bool request(uint32_t ip);
void add(uint64_t mac, uint32_t ip);
void init_request_pkt(uint64_t self_mac, uint32_t self_ip);
friend void clock_timeout(ClockP_Object * obj, void * arg);
private:
enum Operations {
e_oprRequest,
e_oprReply,
e_oprTotal
};
struct ArpIpReqData {
uint64_t mac = 0;
uint32_t attemps = 0;
TimerSw tmr;
};
static const uint32_t pkt_len = 42;
const uint16_t arp_opr_be_[e_oprTotal] = {0x0100, 0x0200};
const uint32_t max_attemps_ = 8;
TEthPkt request_pkt_;
std::map<uint64_t, uint32_t> table_mac_;
std::map<uint32_t, ArpIpReqData> table_ip_;
uint64_t self_mac_;
uint32_t self_ip_;
TEthMacPorts eth_port_id_;
EthStackIface& eth_stack_;
Clock clock_;
TimerSw tmrGratuitous_;
};
}
#endif /* FREE_RTOS_ETHERNET_IP_ETH_ARP_HPP_ */