2023-05-03 14:01:32 +03:00
|
|
|
|
/*
|
|
|
|
|
|
* eth_udp.cpp
|
|
|
|
|
|
*
|
2023-06-08 12:27:49 +03:00
|
|
|
|
* Created on: 15 <EFBFBD><EFBFBD><EFBFBD>. 2023 <EFBFBD>.
|
2023-05-03 14:01:32 +03:00
|
|
|
|
* Author: sychev
|
|
|
|
|
|
*/
|
2023-06-26 18:22:30 +03:00
|
|
|
|
#include "free_rtos/ethernet_ip/eth_udp_server.hpp"
|
|
|
|
|
|
#include "free_rtos/ethernet_ip/eth_udp_types.h"
|
|
|
|
|
|
#include "free_rtos/ethernet_ip/eth_ip_types.h"
|
|
|
|
|
|
#include "free_rtos/base/swap.h"
|
2023-05-03 14:01:32 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
free_rtos::EthUdpServer::EthUdpServer(EthIpIface& ip_iface) :
|
|
|
|
|
|
ip_iface_{ip_iface}
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<free_rtos::EthUpdClient> free_rtos::EthUdpServer::createClient(uint16_t port_dst,
|
|
|
|
|
|
uint16_t port_src,
|
|
|
|
|
|
bool use_chksum)
|
|
|
|
|
|
{
|
|
|
|
|
|
port_dst = BASE_SWAP16(port_dst);
|
|
|
|
|
|
port_src = BASE_SWAP16(port_src);
|
|
|
|
|
|
|
2023-06-08 12:27:49 +03:00
|
|
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
2023-05-03 14:01:32 +03:00
|
|
|
|
if (connections_.count(port_dst)) {
|
|
|
|
|
|
return nullptr;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<EthUpdClient> p_client = std::make_shared<EthUpdClient>(ip_iface_, port_id_,
|
|
|
|
|
|
port_dst, port_src, use_chksum);
|
|
|
|
|
|
|
|
|
|
|
|
if (p_client == nullptr) {
|
|
|
|
|
|
return nullptr;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
connections_[port_dst] = p_client;
|
|
|
|
|
|
|
|
|
|
|
|
return p_client;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int32_t free_rtos::EthUdpServer::Process(uint8_t * p_data, uint32_t len)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (len <= sizeof(TUdpHeader)) {
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TUdpHeader * hdr = (TUdpHeader *)p_data;
|
|
|
|
|
|
|
|
|
|
|
|
uint16_t port = hdr->Dst_port;
|
|
|
|
|
|
|
|
|
|
|
|
auto item = connections_.find(port);
|
|
|
|
|
|
|
2023-06-08 12:27:49 +03:00
|
|
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2023-05-03 14:01:32 +03:00
|
|
|
|
if (item == connections_.end()) {
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
auto& client = item->second;
|
|
|
|
|
|
|
|
|
|
|
|
TIpHeader * p_ip_hdr = (TIpHeader*)(p_data - sizeof(TIpHeader));
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t src_ip;
|
|
|
|
|
|
|
|
|
|
|
|
memcpy(&src_ip, p_ip_hdr->ip_src, ETH_IP_ADDR_LEN);
|
|
|
|
|
|
|
2023-06-08 12:27:49 +03:00
|
|
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> udp
|
2023-07-14 16:02:53 +03:00
|
|
|
|
client->put_data(src_ip, p_data + sizeof(TUdpHeader), BASE_SWAP16(hdr->Length) - sizeof(TUdpHeader));
|
2023-05-03 14:01:32 +03:00
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-06-08 12:27:49 +03:00
|
|
|
|
uint32_t free_rtos::EthUdpServer::Sender(uint8_t * p_data, size_t scatter_segment)
|
|
|
|
|
|
{
|
2023-06-08 14:46:25 +03:00
|
|
|
|
return 0;
|
2023-06-08 12:27:49 +03:00
|
|
|
|
}
|
2023-05-03 14:01:32 +03:00
|
|
|
|
|