fix(SF-60): Еще багфиксы

This commit is contained in:
algin 2023-10-26 13:47:28 +03:00
parent 87ccf2c5cc
commit 59faba1f3a
8 changed files with 35 additions and 25 deletions

View File

@ -247,10 +247,10 @@ bool free_rtos::EthTxFlow::send(TxFlowHandlerArgs& handlerArgs, uint32_t numScat
for(size_t scatter_segment = 0; scatter_segment < numScatterSegments; scatter_segment++)
{
handlerArgs.buffer = txPktInfo->sgList.list[scatter_segment].bufPtr;
txPktInfo->sgList.list[scatter_segment].segmentFilledLen = handlerArgs.stack_handler->Sender(handlerArgs, 0);
txPktInfo->sgList.list[scatter_segment].segmentFilledLen = handlerArgs.stack_handler->Sender(handlerArgs, scatter_segment);
}
txPktInfo->sgList.numScatterSegments = 1;
txPktInfo->sgList.numScatterSegments = numScatterSegments;
txPktInfo->chkSumInfo = 0U;
txPktInfo->appPriv = nullptr;
txPktInfo->tsInfo.txPktSeqId = 0;

View File

@ -129,16 +129,11 @@ bool free_rtos::EthIp::send(IpHandlerArgs& handlerArgs)
inline uint16_t free_rtos::EthIp::fillEthFrameHeader(IpHandlerArgs& ipHandlerArgs)
{
TEthFrameHeader * p_eth_hdr = (TEthFrameHeader *)ipHandlerArgs.buffer;
uint64_t mac_dst;
if (!arp_.getMacAddr(ipHandlerArgs.dest_ip, mac_dst)) {
return 0;
}
p_eth_hdr->prot_id = ETH_PROT_IP_BE;
memcpy(p_eth_hdr->mac_src, &self_mac_, ETH_FRAME_MAC_ADDR_LEN_BYTES);
memcpy(p_eth_hdr->mac_dest, &mac_dst, ETH_FRAME_MAC_ADDR_LEN_BYTES);
memcpy(p_eth_hdr->mac_dest, &ipHandlerArgs.dest_mac, ETH_FRAME_MAC_ADDR_LEN_BYTES);
return sizeof(TEthFrameHeader);
}
@ -147,10 +142,7 @@ uint16_t free_rtos::EthIp::Sender(HandlerArgs& handlerArgs, size_t scatter_segme
{
IpHandlerArgs& ipHandlerArgs = static_cast<IpHandlerArgs&>(handlerArgs); // downcasting back to derived type
if(fillEthFrameHeader(ipHandlerArgs) == 0) {
//EnetAppUtils_print("Cannot find destination mac\r\n");
}
fillEthFrameHeader(ipHandlerArgs);
TIpHeader * ip_header = (TIpHeader *)(ipHandlerArgs.buffer + sizeof(TEthFrameHeader));
*ip_header = ipHandlerArgs.ip_header;

View File

@ -18,6 +18,7 @@ struct IpHandlerArgs : public EthStackHandlerArgs {
uint16_t ip_header_len;
uint16_t ip_data_len;
uint32_t dest_ip;
uint64_t dest_mac;
uint8_t ip_prot_id;
Handler* ip_handler;
TIpHeader ip_header;

View File

@ -16,7 +16,7 @@ free_rtos::EthStack::EthStack(EthTxFlowIface& tx_flow) :
tx_flow_{tx_flow},
arp_{*this},
ip_{*this, arp_},
udp_{ip_}
udp_{ip_, arp_}
{
}

View File

@ -14,13 +14,14 @@
#include <cstring>
free_rtos::EthUpdClient::EthUpdClient(EthIpIface& ip_iface, TEthMacPorts port_id,
uint16_t port_dst_be, uint16_t port_src_be,
free_rtos::EthUpdClient::EthUpdClient(EthIpIface& ip_iface, EthArpIface& arp,
TEthMacPorts port_id, uint16_t port_dst_be, uint16_t port_src_be,
bool use_chksum) :
port_dst_be_{port_dst_be},
port_src_be_{port_src_be},
use_checksum_{use_chksum},
ip_iface_{ip_iface},
arp_{arp},
port_id_{port_id}
{ }
@ -211,9 +212,15 @@ uint16_t free_rtos::EthUpdClient::fill_udp_header(UDPHandlerArgs& udpHandlerArgs
bool free_rtos::EthUpdClient::write(uint32_t ip_dst_be, uint8_t * p_data, uint32_t len)
{
UDPHandlerArgs udpHandlerArgs;
uint64_t mac_dst{0x0000000000000000};
if (ip_dst_be == 0) {
ip_dst_be = src_ip_;
mac_dst = src_mac_;
} else {
if (arp_.getMacAddr(ip_dst_be, mac_dst) == false) {
return false;
}
}
//udpHandlerArgs.buffer = nullptr;
@ -222,6 +229,7 @@ bool free_rtos::EthUpdClient::write(uint32_t ip_dst_be, uint8_t * p_data, uint32
udpHandlerArgs.ip_header_len = sizeof(TUdpHeader);
udpHandlerArgs.ip_data_len = len;
udpHandlerArgs.dest_ip = ip_dst_be;
udpHandlerArgs.dest_mac = mac_dst;
udpHandlerArgs.ip_prot_id = IP_PROT_UDP;
udpHandlerArgs.ip_handler = this;
udpHandlerArgs.p_data = p_data;

View File

@ -19,6 +19,7 @@
#include "free_rtos/semaphore/semaphore.hpp"
#include "free_rtos/mutex/mutex.hpp"
#include "free_rtos/ethernet/eth_frame.h"
#include "free_rtos/ethernet_ip/eth_arp_iface.hpp"
#include "free_rtos/ethernet_ip/eth_ip_iface.hpp"
#include "free_rtos/ethernet/eth_types.h"
#include "free_rtos/ethernet_ip/eth_udp_types.h"
@ -42,8 +43,8 @@ class EthUpdClient : public Handler {
friend class EthUdpServer;
public:
EthUpdClient(EthIpIface& ip_iface, TEthMacPorts port_id,
uint16_t port_dst_be, uint16_t port_src_be,
EthUpdClient(EthIpIface& ip_iface, EthArpIface& arp,
TEthMacPorts port_id, uint16_t port_dst_be, uint16_t port_src_be,
bool use_chksum);
virtual int32_t Process(uint8_t * p_data, uint32_t len) override;
@ -91,12 +92,14 @@ private:
const bool use_checksum_;
EthIpIface& ip_iface_;
EthArpIface& arp_;
const TEthMacPorts port_id_;
//TEthPkt eth_pkt_;
uint32_t src_ip_;
uint32_t src_ip_{0x00000000};
uint64_t src_mac_{0x0000000000000000};
std::array<std::vector<uint8_t>, UDP_BUF_NUM> buff_;
std::atomic<UDPToggle> in_toggle_{UDPToggle::UDP_BUF_1};
@ -127,8 +130,9 @@ private:
return size;
}
void set_src_ip(uint32_t src_ip) {
void set_src_ip(uint32_t src_ip, uint64_t src_mac) {
src_ip_ = src_ip;
src_mac_ = src_mac;
}
inline uint16_t fill_udp_header(UDPHandlerArgs& udpHandlerArgs);

View File

@ -10,8 +10,9 @@
#include "free_rtos/base/swap.h"
free_rtos::EthUdpServer::EthUdpServer(EthIpIface& ip_iface) :
ip_iface_{ip_iface}
free_rtos::EthUdpServer::EthUdpServer(EthIpIface& ip_iface, EthArpIface& arp)
: ip_iface_{ip_iface}
, arp_{arp}
{
}
@ -28,7 +29,7 @@ std::shared_ptr<free_rtos::EthUpdClient> free_rtos::EthUdpServer::createClient(u
return nullptr;
}
std::shared_ptr<EthUpdClient> p_client = std::make_shared<EthUpdClient>(ip_iface_, port_id_,
std::shared_ptr<EthUpdClient> p_client = std::make_shared<EthUpdClient>(ip_iface_, arp_, port_id_,
port_dst, port_src, use_chksum);
if (p_client == nullptr) {
@ -61,13 +62,15 @@ int32_t free_rtos::EthUdpServer::Process(uint8_t * p_data, uint32_t len)
auto& client = item->second;
TEthFrameHeader * p_eth_hdr = (TEthFrameHeader *)(p_data - sizeof(TEthFrameHeader) - sizeof(TIpHeader));
TIpHeader * p_ip_hdr = (TIpHeader*)(p_data - sizeof(TIpHeader));
uint64_t src_mac;
uint32_t src_ip;
memcpy(&src_mac, p_eth_hdr->mac_src, ETH_FRAME_MAC_ADDR_LEN_BYTES);
memcpy(&src_ip, p_ip_hdr->ip_src, ETH_IP_ADDR_LEN);
client->set_src_ip(src_ip);
client->set_src_ip(src_ip, src_mac);
client->put_data(p_data + sizeof(TUdpHeader), BASE_SWAP16(hdr->Length) - sizeof(TUdpHeader));
rx_sem_.post();

View File

@ -14,6 +14,7 @@
#include "free_rtos/handler_store/handler_store.hpp"
#include "free_rtos/ethernet_ip/eth_udp_server_iface.hpp"
#include "free_rtos/ethernet_ip/eth_arp_iface.hpp"
#include "free_rtos/ethernet_ip/eth_ip_iface.hpp"
#include "free_rtos/ethernet/eth_types.h"
@ -21,7 +22,7 @@ namespace free_rtos {
class EthUdpServer : public Handler, public EthUdpServerIface {
public:
EthUdpServer(EthIpIface& ip_iface);
EthUdpServer(EthIpIface& ip_iface, EthArpIface& arp);
void setPortId(TEthMacPorts port_id) { port_id_ = port_id;};
@ -45,6 +46,7 @@ public:
private:
EthIpIface& ip_iface_;
EthArpIface& arp_;
TEthMacPorts port_id_;