mirror of
https://github.com/meshtastic/firmware.git
synced 2026-01-05 01:20:59 +00:00
Re-use Uplink / downlink controls for UDP
This commit is contained in:
@@ -355,13 +355,21 @@ ErrorCode Router::send(meshtastic_MeshPacket *p)
|
||||
if (moduleConfig.mqtt.enabled && isFromUs(p) && mqtt) {
|
||||
mqtt->onSend(*p, *p_decoded, chIndex);
|
||||
}
|
||||
#endif
|
||||
#if HAS_UDP_MULTICAST
|
||||
// Only publish to UDP if we're the original transmitter of the packet
|
||||
if (udpHandler && config.network.enabled_protocols & meshtastic_Config_NetworkConfig_ProtocolFlags_UDP_BROADCAST &&
|
||||
isFromUs(p)) {
|
||||
udpHandler->onSend(const_cast<meshtastic_MeshPacket *>(p), chIndex);
|
||||
}
|
||||
#endif
|
||||
packetPool.release(p_decoded);
|
||||
}
|
||||
|
||||
#if HAS_UDP_MULTICAST
|
||||
if (udpHandler && config.network.enabled_protocols & meshtastic_Config_NetworkConfig_ProtocolFlags_UDP_BROADCAST) {
|
||||
udpHandler->onSend(const_cast<meshtastic_MeshPacket *>(p));
|
||||
// For packets that are already encrypted, we need to determine the channel from packet info
|
||||
else if (udpHandler && config.network.enabled_protocols & meshtastic_Config_NetworkConfig_ProtocolFlags_UDP_BROADCAST &&
|
||||
isFromUs(p)) {
|
||||
udpHandler->onSend(const_cast<meshtastic_MeshPacket *>(p), p->channel);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#if HAS_UDP_MULTICAST
|
||||
#include "configuration.h"
|
||||
#include "main.h"
|
||||
#include "mesh/Channels.h"
|
||||
#include "mesh/Router.h"
|
||||
|
||||
#if HAS_ETHERNET && defined(ARCH_NRF52)
|
||||
@@ -53,6 +54,13 @@ class UdpMulticastHandler final
|
||||
LOG_DEBUG("Decoding MeshPacket from UDP len=%u", packetLength);
|
||||
bool isPacketDecoded = pb_decode_from_bytes(packet.data(), packetLength, &meshtastic_MeshPacket_msg, &mp);
|
||||
if (isPacketDecoded && router && mp.which_payload_variant == meshtastic_MeshPacket_encrypted_tag) {
|
||||
// Check if downlink is enabled for this channel
|
||||
auto &ch = channels.getByIndex(mp.channel);
|
||||
if (!ch.settings.downlink_enabled) {
|
||||
LOG_DEBUG("UDP downlink disabled for channel %d", mp.channel);
|
||||
return;
|
||||
}
|
||||
|
||||
mp.transport_mechanism = meshtastic_MeshPacket_TransportMechanism_TRANSPORT_MULTICAST_UDP;
|
||||
mp.pki_encrypted = false;
|
||||
mp.public_key.size = 0;
|
||||
@@ -65,11 +73,17 @@ class UdpMulticastHandler final
|
||||
}
|
||||
}
|
||||
|
||||
bool onSend(const meshtastic_MeshPacket *mp)
|
||||
bool onSend(const meshtastic_MeshPacket *mp, ChannelIndex chIndex)
|
||||
{
|
||||
if (!mp || !udp) {
|
||||
return false;
|
||||
}
|
||||
// Check if uplink is enabled for this specific channel
|
||||
auto &ch = channels.getByIndex(chIndex);
|
||||
if (!ch.settings.uplink_enabled) {
|
||||
LOG_DEBUG("UDP uplink disabled for channel %d", chIndex);
|
||||
return false;
|
||||
}
|
||||
#if defined(ARCH_NRF52)
|
||||
if (!isEthernetAvailable()) {
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user