81 lines
2.0 KiB
C++
81 lines
2.0 KiB
C++
/*
|
||
* eth_arp.hpp
|
||
*
|
||
* Created on: 13 <20><><EFBFBD>. 2023 <20>.
|
||
* 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 uint32_t Sender(uint8_t * p_data, 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; /// <20><><EFBFBD>-<2D><><EFBFBD><EFBFBD><EFBFBD>
|
||
uint32_t attemps = 0; /// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
TimerSw tmr; /// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
};
|
||
|
||
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_; /// <20><><EFBFBD><EFBFBD> mac, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ip
|
||
std::map<uint32_t, ArpIpReqData> table_ip_; /// <20><><EFBFBD><EFBFBD> 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_ */
|