Skip to content

Commit

Permalink
Moved RDM E1.37-2 code from network.cpp to rdmhandlere137.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
vanvught committed Nov 16, 2024
1 parent aa5e3ec commit b3dba55
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 288 deletions.
47 changes: 3 additions & 44 deletions lib-network/include/emac/network.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,22 +102,13 @@ class Network {
void EnableDhcp();

bool IsDhcpUsed() {
const auto b = net::netif_dhcp();
return b;
return net::netif_dhcp();
}

bool IsDhcpKnown() const {
return true;
}

network::dhcp::Mode GetDhcpMode() {
if (IsDhcpUsed()) {
return network::dhcp::Mode::ACTIVE;
}

return network::dhcp::Mode::INACTIVE;
}

/*
* Zeroconf / autoip
*/
Expand Down Expand Up @@ -197,7 +188,7 @@ class Network {
}

void SendTo(int32_t nHandle, const void *pBuffer, uint32_t nLength, uint32_t to_ip, uint16_t remote_port) {
if (__builtin_expect((GetIp() != 0), 1)) {
if (__builtin_expect((GetIp() != 0), 1)) { //FIXME
net::udp_send(nHandle, reinterpret_cast<const uint8_t *>(pBuffer), nLength, to_ip, remote_port);
}
}
Expand Down Expand Up @@ -238,18 +229,6 @@ class Network {
net::igmp_leave(nIp);
}

void SetQueuedStaticIp(const uint32_t nStaticIp, const uint32_t nNetmask);
void SetQueuedDefaultRoute(const uint32_t nGatewayIp);
void SetQueuedDhcp(const network::dhcp::Mode mode) {
m_QueuedConfig.mode = mode;
m_QueuedConfig.nMask |= QueuedConfig::DHCP;
}
void SetQueuedZeroconf() {
m_QueuedConfig.nMask |= QueuedConfig::ZEROCONF;
}

bool ApplyQueuedConfig();

uint32_t GetNetmaskCIDR() {
return static_cast<uint32_t>(__builtin_popcount(GetNetmask()));
}
Expand Down Expand Up @@ -303,27 +282,7 @@ class Network {
char m_aDomainName[network::DOMAINNAME_SIZE];
uint32_t m_nNameservers[network::NAMESERVERS_COUNT];

struct QueuedConfig {
static constexpr uint32_t NONE = 0;
static constexpr uint32_t STATIC_IP = (1U << 0);
static constexpr uint32_t NETMASK = (1U << 1);
static constexpr uint32_t GW = (1U << 2);
static constexpr uint32_t DHCP = (1U << 3);
static constexpr uint32_t ZEROCONF = (1U << 4);
uint32_t nMask = QueuedConfig::NONE;
uint32_t nStaticIp;
uint32_t nNetmask;
uint32_t nGateway;
network::dhcp::Mode mode;
};

QueuedConfig m_QueuedConfig;

bool isQueuedMaskSet(const uint32_t nMask) {
return (m_QueuedConfig.nMask & nMask) == nMask;
}

static Network *s_pThis;
static inline Network *s_pThis;
};

#endif /* EMAC_NETWORK_H_ */
44 changes: 0 additions & 44 deletions lib-network/include/linux/network.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,6 @@ class Network {
return false;
}

void SetQueuedStaticIp(const uint32_t nStaticIp, const uint32_t nNetmask);
void SetQueuedDefaultRoute(const uint32_t nGatewayIp);
void SetQueuedDhcp(const network::dhcp::Mode mode) {
m_QueuedConfig.mode = mode;
m_QueuedConfig.nMask |= QueuedConfig::DHCP;
}
void SetQueuedZeroconf() {
m_QueuedConfig.nMask |= QueuedConfig::ZEROCONF;
}

bool ApplyQueuedConfig();

uint32_t GetGatewayIp() const {
return m_nGatewayIp;
}
Expand Down Expand Up @@ -174,18 +162,6 @@ class Network {
#endif
}

network::dhcp::Mode GetDhcpMode() const {
if (IsDhcpKnown()) {
if (m_IsDhcpUsed) {
return network::dhcp::Mode::ACTIVE;
}

return network::dhcp::Mode::INACTIVE;
}

return network::dhcp::Mode::UNKNOWN;
}

const char *GetIfName() const {
return m_aIfName;
}
Expand Down Expand Up @@ -247,26 +223,6 @@ class Network {
uint8_t m_aNetMacaddr[network::MAC_SIZE];
char m_aIfName[IFNAMSIZ];

struct QueuedConfig {
static constexpr uint32_t NONE = 0;
static constexpr uint32_t STATIC_IP = (1U << 0);
static constexpr uint32_t NETMASK = (1U << 1);
static constexpr uint32_t GW = (1U << 2);
static constexpr uint32_t DHCP = (1U << 3);
static constexpr uint32_t ZEROCONF = (1U << 4);
uint32_t nMask = QueuedConfig::NONE;
uint32_t nStaticIp;
uint32_t nNetmask;
uint32_t nGateway;
network::dhcp::Mode mode;
};

QueuedConfig m_QueuedConfig;

bool isQueuedMaskSet(uint32_t nMask) {
return (m_QueuedConfig.nMask & nMask) == nMask;
}

static Network *s_pThis;
};

Expand Down
10 changes: 0 additions & 10 deletions lib-network/include/network.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,6 @@

#include "ip4_address.h"

namespace network {
namespace dhcp {
enum class Mode: uint8_t {
INACTIVE = 0x00, ///< The IP address was not obtained via DHCP
ACTIVE = 0x01, ///< The IP address was obtained via DHCP
UNKNOWN = 0x02 ///< The system cannot determine if the address was obtained via DHCP
};
} // namespace dhcp
} // namespace network

#if defined(__linux__) || defined (__APPLE__)
# if defined (CONFIG_NETWORK_USE_MINIMUM)
# include "linux/minimum/network.h"
Expand Down
90 changes: 1 addition & 89 deletions lib-network/src/emac/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@ static void netif_ext_callback(const uint16_t reason, [[maybe_unused]] const net
DEBUG_EXIT
}

Network *Network::s_pThis;

Network::Network() {
DEBUG_ENTRY
assert(s_pThis == nullptr);
Expand Down Expand Up @@ -242,6 +240,7 @@ void Network::SetHostName(const char *pHostName) {
m_aHostName[network::HOSTNAME_SIZE - 1] = '\0';

NetworkStore::SaveHostName(m_aHostName, static_cast<uint32_t>(strlen(m_aHostName)));

#if !defined(CONFIG_NET_APPS_NO_MDNS)
mdns_send_announcement(mdns::MDNS_RESPONSE_TTL);
#endif
Expand Down Expand Up @@ -270,93 +269,6 @@ void Network::EnableDhcp() {
DEBUG_EXIT
}

void Network::SetQueuedStaticIp(const uint32_t nStaticIp, const uint32_t nNetmask) {
DEBUG_ENTRY
DEBUG_PRINTF(IPSTR ", nNetmask=" IPSTR, IP2STR(nStaticIp), IP2STR(nNetmask));

if (nStaticIp != 0) {
m_QueuedConfig.nStaticIp = nStaticIp;
} else {
m_QueuedConfig.nStaticIp = GetIp();
}

if (nNetmask != 0) {
m_QueuedConfig.nNetmask = nNetmask;
} else {
m_QueuedConfig.nNetmask = GetNetmask();
}

m_QueuedConfig.nMask |= QueuedConfig::STATIC_IP;
m_QueuedConfig.nMask |= QueuedConfig::NETMASK;

DEBUG_EXIT
}

void Network::SetQueuedDefaultRoute(const uint32_t nGatewayIp) {
if (nGatewayIp != 0) {
m_QueuedConfig.nGateway = nGatewayIp;
} else {
m_QueuedConfig.nGateway = GetGatewayIp();
}

m_QueuedConfig.nMask |= QueuedConfig::GW;
}

bool Network::ApplyQueuedConfig() {
DEBUG_ENTRY
DEBUG_PRINTF("m_QueuedConfig.nMask=%x, " IPSTR ", " IPSTR, m_QueuedConfig.nMask, IP2STR(m_QueuedConfig.nStaticIp), IP2STR(m_QueuedConfig.nNetmask));

if (m_QueuedConfig.nMask == QueuedConfig::NONE) {
DEBUG_EXIT
return false;
}

if ((isQueuedMaskSet(QueuedConfig::STATIC_IP)) || (isQueuedMaskSet(QueuedConfig::NETMASK)) || (isQueuedMaskSet(QueuedConfig::GW))) {
// After SetIp all ip address might be zero.
if (isQueuedMaskSet(QueuedConfig::STATIC_IP)) {
SetIp(m_QueuedConfig.nStaticIp);
}

if (isQueuedMaskSet(QueuedConfig::NETMASK)) {
SetNetmask(m_QueuedConfig.nNetmask);
}

if (isQueuedMaskSet(QueuedConfig::GW)) {
SetGatewayIp(m_QueuedConfig.nGateway);
}

m_QueuedConfig.nMask = QueuedConfig::NONE;

DEBUG_EXIT
return true;
}

if (isQueuedMaskSet(QueuedConfig::DHCP)) {
if (m_QueuedConfig.mode == network::dhcp::Mode::ACTIVE) {
EnableDhcp();
} else if (m_QueuedConfig.mode == network::dhcp::Mode::INACTIVE) {

}

m_QueuedConfig.mode = network::dhcp::Mode::UNKNOWN;
m_QueuedConfig.nMask = QueuedConfig::NONE;

DEBUG_EXIT
return true;
}

if (isQueuedMaskSet(QueuedConfig::ZEROCONF)) {
SetZeroconf();
m_QueuedConfig.nMask = QueuedConfig::NONE;

DEBUG_EXIT
return true;
}

DEBUG_EXIT
return false;
}

void Network::Print() {
printf("Network [%c]\n", GetAddressingMode());
printf(" Hostname : %s\n", m_aHostName);
Expand Down
89 changes: 0 additions & 89 deletions lib-network/src/linux/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -581,95 +581,6 @@ void Network::SetHostName(const char *pHostName) {

}

// COMMON

void Network::SetQueuedStaticIp(const uint32_t nStaticIp, const uint32_t nNetmask) {
DEBUG_ENTRY
DEBUG_PRINTF(IPSTR ", nNetmask=" IPSTR, IP2STR(nStaticIp), IP2STR(nNetmask));

if (nStaticIp != 0) {
m_QueuedConfig.nStaticIp = nStaticIp;
} else {
m_QueuedConfig.nStaticIp = GetIp();
}

if (nNetmask != 0) {
m_QueuedConfig.nNetmask = nNetmask;
} else {
m_QueuedConfig.nNetmask = GetNetmask();
}

m_QueuedConfig.nMask |= QueuedConfig::STATIC_IP;
m_QueuedConfig.nMask |= QueuedConfig::NETMASK;

DEBUG_EXIT
}

void Network::SetQueuedDefaultRoute(const uint32_t nGatewayIp) {
if (nGatewayIp != 0) {
m_QueuedConfig.nGateway = nGatewayIp;
} else {
m_QueuedConfig.nGateway = GetGatewayIp();
}

m_QueuedConfig.nMask |= QueuedConfig::GW;
}

bool Network::ApplyQueuedConfig() {
DEBUG_ENTRY
DEBUG_PRINTF("m_QueuedConfig.nMask=%x, " IPSTR ", " IPSTR, m_QueuedConfig.nMask, IP2STR(m_QueuedConfig.nStaticIp), IP2STR(m_QueuedConfig.nNetmask));

if (m_QueuedConfig.nMask == QueuedConfig::NONE) {
DEBUG_EXIT
return false;
}

if ((isQueuedMaskSet(QueuedConfig::STATIC_IP)) || (isQueuedMaskSet(QueuedConfig::NETMASK)) || (isQueuedMaskSet(QueuedConfig::GW))) {
// After SetIp all ip address might be zero.
if (isQueuedMaskSet(QueuedConfig::STATIC_IP)) {
SetIp(m_QueuedConfig.nStaticIp);
}

if (isQueuedMaskSet(QueuedConfig::NETMASK)) {
SetNetmask(m_QueuedConfig.nNetmask);
}

if (isQueuedMaskSet(QueuedConfig::GW)) {
SetGatewayIp(m_QueuedConfig.nGateway);
}

m_QueuedConfig.nMask = QueuedConfig::NONE;

DEBUG_EXIT
return true;
}

if (isQueuedMaskSet(QueuedConfig::DHCP)) {
if (m_QueuedConfig.mode == network::dhcp::Mode::ACTIVE) {
EnableDhcp();
} else if (m_QueuedConfig.mode == network::dhcp::Mode::INACTIVE) {

}

m_QueuedConfig.mode = network::dhcp::Mode::UNKNOWN;
m_QueuedConfig.nMask = QueuedConfig::NONE;

DEBUG_EXIT
return true;
}

if (isQueuedMaskSet(QueuedConfig::ZEROCONF)) {
SetZeroconf();
m_QueuedConfig.nMask = QueuedConfig::NONE;

DEBUG_EXIT
return true;
}

DEBUG_EXIT
return false;
}

void Network::Print() {
printf("Network\n");
printf(" Hostname : %s\n", m_aHostName);
Expand Down
Loading

0 comments on commit b3dba55

Please sign in to comment.