2023-05-03 14:01:32 +03:00
|
|
|
|
/*
|
|
|
|
|
|
* eth_arp.hpp
|
|
|
|
|
|
*
|
2024-02-21 10:41:56 +03:00
|
|
|
|
* Created on: 13 мар. 2023 г.
|
2023-05-03 14:01:32 +03:00
|
|
|
|
* Author: sychev
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef FREE_RTOS_ETHERNET_IP_ETH_ARP_HPP_
|
|
|
|
|
|
#define FREE_RTOS_ETHERNET_IP_ETH_ARP_HPP_
|
|
|
|
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
|
|
#include <cstdint>
|
2023-06-26 18:22:30 +03:00
|
|
|
|
#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"
|
2023-05-03 14:01:32 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
2023-10-26 10:21:41 +03:00
|
|
|
|
virtual uint16_t Sender(HandlerArgs& handlerArgs, size_t scatter_segment) override;
|
2023-05-03 14:01:32 +03:00
|
|
|
|
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 {
|
2024-02-21 10:41:56 +03:00
|
|
|
|
uint64_t mac = 0;
|
|
|
|
|
|
uint32_t attemps = 0;
|
|
|
|
|
|
TimerSw tmr;
|
2023-05-03 14:01:32 +03:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
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_;
|
|
|
|
|
|
|
2024-02-21 10:41:56 +03:00
|
|
|
|
std::map<uint64_t, uint32_t> table_mac_;
|
|
|
|
|
|
std::map<uint32_t, ArpIpReqData> table_ip_;
|
2023-05-03 14:01:32 +03:00
|
|
|
|
|
|
|
|
|
|
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_ */
|