Merge observer firmware with persistent opt-in advert signature verification
Add Waveshare LR1121 observer recipes. Adapt observer advert verification to existing transactional CLI, append-only binary preferences and Companion NVS, preserving default file lengths and WiFi credentials. Reject oversized unsigned advert tails consistently with Mesh::onRecvPacket. Keep current BLE recovery and GPS claim accounting.
This commit is contained in:
commit
b5e493996c
27 files changed
+641
-48
No files matched your search
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <MeshCore.h>
|
||||
|
||||
// Signed-message layout of an ADVERT payload, mirroring Mesh::onRecvPacket:
|
||||
// pub_key(32) + timestamp(4) + signature(64) + app_data. Oversized app_data is
|
||||
// rejected, like Mesh::onRecvPacket: truncation would accept an unsigned tail.
|
||||
namespace AdvertSignature {
|
||||
|
||||
static const int kHeaderLen = PUB_KEY_SIZE + 4 + SIGNATURE_SIZE;
|
||||
static const int kMaxMessageLen = PUB_KEY_SIZE + 4 + MAX_ADVERT_DATA_SIZE;
|
||||
|
||||
// Builds the signed message into `out` (kMaxMessageLen bytes) and points `sig`
|
||||
// at the signature. Returns the message length, or -1 for invalid arguments or
|
||||
// a payload outside the complete signed advert layout. Clears sig on failure.
|
||||
static inline int buildMessage(const uint8_t* payload, int payload_len,
|
||||
uint8_t* out, const uint8_t** sig) {
|
||||
if (sig == nullptr) return -1;
|
||||
*sig = nullptr;
|
||||
if (payload == nullptr || out == nullptr || payload_len < kHeaderLen ||
|
||||
payload_len > kHeaderLen + MAX_ADVERT_DATA_SIZE) return -1;
|
||||
int app_data_len = payload_len - kHeaderLen;
|
||||
memcpy(out, payload, PUB_KEY_SIZE + 4);
|
||||
memcpy(out + PUB_KEY_SIZE + 4, payload + kHeaderLen, app_data_len);
|
||||
*sig = payload + PUB_KEY_SIZE + 4;
|
||||
return PUB_KEY_SIZE + 4 + app_data_len;
|
||||
}
|
||||
|
||||
} // namespace AdvertSignature
|
||||
@@ -2776,11 +2776,11 @@ void CommonCLI::loadMQTTPrefs(
|
||||
if (MQTTPrefsCodec::repairDisplayPrefs(&_mqtt_prefs)) {
|
||||
// Old payloads retain valid defaults because the object was defaulted before
|
||||
// their shorter prefix was copied. This branch repairs only a full/newer
|
||||
// payload carrying invalid display values.
|
||||
// payload carrying invalid display or advert-verification values.
|
||||
if (!_mqtt_prefs_hold) {
|
||||
mqtt_rewrite_pending = true;
|
||||
}
|
||||
MESH_DEBUG_PRINTLN("MQTT: invalid display preferences reset to defaults");
|
||||
MESH_DEBUG_PRINTLN("MQTT: invalid display/advert preferences reset to defaults");
|
||||
}
|
||||
_legacy_tail.valid = false;
|
||||
|
||||
|
||||
@@ -330,6 +330,19 @@ bool CommonCLI::handleObserverSetCmd(uint32_t sender_timestamp, const char* conf
|
||||
_mqtt_prefs.mqtt_rx_enabled = memcmp(&config[8], "on", 2) == 0 ? 1 : 0;
|
||||
saveObserverPrefs();
|
||||
strcpy(reply, "OK");
|
||||
} else if (memcmp(config, "mqtt.advert.verify ", 19) == 0) {
|
||||
if (strcmp(config + 19, "on") != 0 && strcmp(config + 19, "off") != 0) {
|
||||
strcpy(reply, "Error: must be on or off");
|
||||
return true;
|
||||
}
|
||||
const uint8_t previous = _mqtt_prefs.mqtt_advert_verify;
|
||||
_mqtt_prefs.mqtt_advert_verify = strcmp(config + 19, "on") == 0;
|
||||
if (!saveObserverPrefs()) {
|
||||
_mqtt_prefs.mqtt_advert_verify = previous;
|
||||
strcpy(reply, "Error: settings could not be saved");
|
||||
return true;
|
||||
}
|
||||
strcpy(reply, "OK");
|
||||
} else if (memcmp(config, "mqtt.interval ", 14) == 0) {
|
||||
uint32_t minutes = _atoi(&config[14]);
|
||||
if (minutes >= 1 && minutes <= 60) {
|
||||
@@ -956,6 +969,8 @@ bool CommonCLI::handleObserverGetCmd(uint32_t sender_timestamp, const char* conf
|
||||
sprintf(reply, "> %s", tx_str);
|
||||
} else if (memcmp(config, "mqtt.rx", 7) == 0) {
|
||||
sprintf(reply, "> %s", _mqtt_prefs.mqtt_rx_enabled ? "on" : "off");
|
||||
} else if (strcmp(config, "mqtt.advert.verify") == 0) {
|
||||
sprintf(reply, "> %s", _mqtt_prefs.mqtt_advert_verify ? "on" : "off");
|
||||
} else if (memcmp(config, "mqtt.interval", 13) == 0) {
|
||||
uint32_t minutes = (_mqtt_prefs.mqtt_status_interval + 29999) / 60000;
|
||||
sprintf(reply, "> %u minutes (%lu ms)", minutes, (unsigned long)_mqtt_prefs.mqtt_status_interval);
|
||||
|
||||
@@ -9,8 +9,10 @@
|
||||
|
||||
// The ESP32 Companion setup portal stores a raw MQTTPrefs blob in NVS rather
|
||||
// than the observer's versioned /mqtt_prefs file. Display preferences are not
|
||||
// used by Companion firmware, so keep writing the last pre-display boundary:
|
||||
// older firmware can then read a record saved by a newer image after rollback.
|
||||
// used by Companion firmware. With advert verification off, keep writing the
|
||||
// last pre-display boundary so rollback preserves a normally configured node.
|
||||
// Enabling verification opts into a separately marked blob: an old recovery
|
||||
// record's former padding must never silently enable a new packet filter.
|
||||
namespace CompanionMqttPrefsNvs {
|
||||
|
||||
static constexpr size_t kWriteSize = MQTT_PREFS_V1_PRE_DISPLAY_PAYLOAD_SIZE;
|
||||
@@ -20,10 +22,24 @@ static constexpr size_t kWriteSize = MQTT_PREFS_V1_PRE_DISPLAY_PAYLOAD_SIZE;
|
||||
static constexpr size_t kRecoverySize = 2880;
|
||||
static_assert(sizeof(MQTTPrefs) >= kRecoverySize,
|
||||
"MQTTPrefs no longer contains the recoverable NVS prefix");
|
||||
static constexpr size_t kVerifiedSize = 2881;
|
||||
static constexpr uint8_t kVerifiedMarker = 0xa7;
|
||||
struct Record {
|
||||
MQTTPrefs prefs;
|
||||
uint8_t marker;
|
||||
};
|
||||
static_assert(offsetof(Record, marker) == kRecoverySize,
|
||||
"the marked NVS blob must append exactly one format byte");
|
||||
static_assert(sizeof(Record) >= kVerifiedSize,
|
||||
"the marked NVS record must contain its whole serialized blob");
|
||||
|
||||
inline size_t writeSizeFor(const MQTTPrefs& prefs) {
|
||||
return prefs.mqtt_advert_verify != 0 ? kVerifiedSize : kWriteSize;
|
||||
}
|
||||
|
||||
inline bool accepts(uint16_t version, size_t length) {
|
||||
return version == MQTT_PREFS_VERSION
|
||||
&& (length == kWriteSize || length == kRecoverySize);
|
||||
&& (length == kWriteSize || length == kRecoverySize || length == kVerifiedSize);
|
||||
}
|
||||
|
||||
} // namespace CompanionMqttPrefsNvs
|
||||
|
||||
@@ -594,12 +594,20 @@ bool CompanionMqttSetupPortal::loadStoredConfig(MQTTPrefs& prefs) {
|
||||
// default its append-only display tail so adding observer UI preferences
|
||||
// cannot discard an existing Companion MQTT setup after an update.
|
||||
const bool shape_ok = CompanionMqttPrefsNvs::accepts(version, length);
|
||||
MQTTPrefs loaded;
|
||||
CompanionMqttPrefsNvs::Record record = {};
|
||||
MQTTPrefs& loaded = record.prefs;
|
||||
applyMQTTDefaults(&loaded);
|
||||
const size_t read = shape_ok ? nvs.getBytes(NVS_PREFS_KEY, &loaded, length) : 0;
|
||||
const size_t read = shape_ok ? nvs.getBytes(NVS_PREFS_KEY, &record, length) : 0;
|
||||
nvs.end();
|
||||
if (!shape_ok || read != length) return false;
|
||||
|
||||
// The old 2880-byte recovery blob ended with unspecified padding, including
|
||||
// potentially 1. Only an explicitly marked new blob can opt into filtering.
|
||||
// Invalid optional metadata must not discard otherwise valid credentials.
|
||||
if (length != CompanionMqttPrefsNvs::kVerifiedSize ||
|
||||
record.marker != CompanionMqttPrefsNvs::kVerifiedMarker ||
|
||||
loaded.mqtt_advert_verify > 1) loaded.mqtt_advert_verify = 0;
|
||||
|
||||
if (!storedStringsAreValid(loaded)
|
||||
|| loaded.mqtt_status_enabled > 1
|
||||
|| loaded.mqtt_packets_enabled > 1
|
||||
@@ -663,15 +671,20 @@ bool CompanionMqttSetupPortal::saveEnabled(bool enabled) {
|
||||
bool CompanionMqttSetupPortal::saveStoredConfig(const MQTTPrefs& prefs) {
|
||||
Preferences nvs;
|
||||
if (!nvs.begin(NVS_NAMESPACE, false)) return false;
|
||||
// Companion does not consume the appended observer display tail. Keeping
|
||||
// this record at the pre-display boundary makes a firmware rollback retain
|
||||
// the MQTT setup. loadStoredConfig() still accepts the briefly written 2880
|
||||
// byte runtime shape so development images remain recoverable.
|
||||
const size_t written = nvs.putBytes(
|
||||
NVS_PREFS_KEY, &prefs, CompanionMqttPrefsNvs::kWriteSize);
|
||||
// Default configuration keeps the rollback-readable pre-display boundary.
|
||||
// Advert verification and its format marker are one atomic NVS blob write,
|
||||
// not separate preference keys that can disagree after power loss.
|
||||
const size_t payload_size = CompanionMqttPrefsNvs::writeSizeFor(prefs);
|
||||
size_t written;
|
||||
if (prefs.mqtt_advert_verify != 0) {
|
||||
const CompanionMqttPrefsNvs::Record record = {prefs, CompanionMqttPrefsNvs::kVerifiedMarker};
|
||||
written = nvs.putBytes(NVS_PREFS_KEY, &record, payload_size);
|
||||
} else {
|
||||
written = nvs.putBytes(NVS_PREFS_KEY, &prefs, payload_size);
|
||||
}
|
||||
const size_t version_written = nvs.putUShort(NVS_VERSION_KEY, MQTT_PREFS_VERSION);
|
||||
nvs.end();
|
||||
return written == CompanionMqttPrefsNvs::kWriteSize
|
||||
return written == payload_size
|
||||
&& version_written == sizeof(uint16_t);
|
||||
}
|
||||
|
||||
|
||||
@@ -70,6 +70,7 @@ static inline void applyMQTTDefaults(MQTTPrefs* prefs) {
|
||||
prefs->mqtt_raw_enabled = 0;
|
||||
prefs->mqtt_tx_enabled = 2;
|
||||
prefs->mqtt_rx_enabled = 1;
|
||||
prefs->mqtt_advert_verify = 0;
|
||||
prefs->mqtt_status_interval = 300000;
|
||||
prefs->wifi_power_save = mesh::wifi::kDefaultPowerSave;
|
||||
|
||||
|
||||
@@ -40,21 +40,24 @@ static const size_t kV1PreObserverPayloadSize = MQTT_PREFS_V1_PRE_OBSERVER_PAYLO
|
||||
static const size_t kV1PreNeighborsPayloadSize = MQTT_PREFS_V1_PRE_NEIGHBORS_PAYLOAD_SIZE;
|
||||
static const size_t kV1PreFilterPayloadSize = MQTT_PREFS_V1_PRE_FILTER_PAYLOAD_SIZE;
|
||||
static const size_t kV1PreDisplayPayloadSize = MQTT_PREFS_V1_PRE_DISPLAY_PAYLOAD_SIZE;
|
||||
static const size_t kV1PreAdvertPayloadSize = MQTT_PREFS_V1_PRE_ADVERT_PAYLOAD_SIZE;
|
||||
static const size_t kV1BaselinePayloadSize = MQTT_PREFS_V1_FULL_PAYLOAD_SIZE;
|
||||
static const size_t kEncodedSize = sizeof(MQTTPrefsHeader) + kV1BaselinePayloadSize;
|
||||
|
||||
// Shortest payload length that still round-trips this configuration.
|
||||
//
|
||||
// The packet-filter and display tails are optional. Their defaults are exactly
|
||||
// The packet-filter, display and advert-verification tails are optional. Their
|
||||
// defaults are exactly
|
||||
// what a decoder supplies when the corresponding tail is missing, so merely
|
||||
// upgrading does not lengthen the file. That matters because /mqtt_prefs also
|
||||
// carries WiFi credentials: old firmware that cannot read a longer payload can
|
||||
// otherwise lose its network configuration after a downgrade. Changing a
|
||||
// filter or display control deliberately opts the node into the required tail.
|
||||
// filter, display or verification control deliberately opts into its tail.
|
||||
inline size_t payloadLenFor(const MQTTPrefs& prefs) {
|
||||
if (prefs.mqtt_advert_verify != 0) return kV1BaselinePayloadSize;
|
||||
if (prefs.display_timeout_secs != DISPLAY_TIMEOUT_DEFAULT_SECS ||
|
||||
prefs.display_flip != 0) {
|
||||
return kV1BaselinePayloadSize;
|
||||
return kV1PreAdvertPayloadSize;
|
||||
}
|
||||
return MQTTPacketFilter::allMasksDefault(prefs.mqtt_slot_packet_filter,
|
||||
MQTT_PREFS_SLOT_COUNT)
|
||||
@@ -62,7 +65,8 @@ inline size_t payloadLenFor(const MQTTPrefs& prefs) {
|
||||
: kV1PreDisplayPayloadSize;
|
||||
}
|
||||
|
||||
// Clamp the display tail after loading. Returns true when a persisted value was
|
||||
// Clamp the optional display/verification tails after loading. Retain the helper
|
||||
// name for callers predating advert verification. Returns true when a value was
|
||||
// repaired and should be rewritten (unless the source file is being held).
|
||||
inline bool repairDisplayPrefs(MQTTPrefs* prefs) {
|
||||
if (prefs == nullptr) return false;
|
||||
@@ -75,6 +79,10 @@ inline bool repairDisplayPrefs(MQTTPrefs* prefs) {
|
||||
prefs->display_flip = 0;
|
||||
repaired = true;
|
||||
}
|
||||
if (prefs->mqtt_advert_verify > 1) {
|
||||
prefs->mqtt_advert_verify = 0;
|
||||
repaired = true;
|
||||
}
|
||||
return repaired;
|
||||
}
|
||||
|
||||
@@ -156,6 +164,10 @@ inline DecodePlan classify(const uint8_t* prefix, size_t prefix_read, size_t fil
|
||||
if (header.payload_len == kV1BaselinePayloadSize) {
|
||||
return {Source::Current, false, false, true, kV1BaselinePayloadSize};
|
||||
}
|
||||
if (header.payload_len == kV1PreAdvertPayloadSize) {
|
||||
// Former complete layout. The default keeps advert verification off.
|
||||
return {Source::Current, false, false, true, kV1PreAdvertPayloadSize};
|
||||
}
|
||||
if (header.payload_len == kV1PreDisplayPayloadSize) {
|
||||
// Written before runtime display controls. Defaults supply timeout and
|
||||
// flip while preserving the packet-filter tail.
|
||||
|
||||
@@ -203,10 +203,10 @@ class MQTTPrefsSerializer : public ConfigSerializer {
|
||||
|
||||
class MqttPrefs : public ConfigSerializer {
|
||||
MQTTPrefs* _prefs;
|
||||
int32_t _packets_enabled, _raw_enabled, _tx_enabled, _rx_enabled;
|
||||
int32_t _packets_enabled, _raw_enabled, _tx_enabled, _rx_enabled, _advert_verify;
|
||||
char _default_iata[sizeof(MQTTPrefs::mqtt_iata)];
|
||||
bool _seen_origin = false, _seen_iata = false, _seen_packets = false;
|
||||
bool _seen_raw = false, _seen_tx = false, _seen_rx = false;
|
||||
bool _seen_raw = false, _seen_tx = false, _seen_rx = false, _seen_advert_verify = false;
|
||||
bool _seen_status = false, _seen_neighbors = false, _seen_owner = false;
|
||||
bool _seen_slot1 = false, _seen_slot2 = false, _seen_slot3 = false;
|
||||
bool _seen_slot4 = false, _seen_slot5 = false, _seen_slot6 = false;
|
||||
@@ -224,6 +224,7 @@ class MQTTPrefsSerializer : public ConfigSerializer {
|
||||
defStrict("raw_enabled", _raw_enabled, _seen_raw);
|
||||
defStrict("tx_enabled", _tx_enabled, _seen_tx);
|
||||
defStrict("rx_enabled", _rx_enabled, _seen_rx);
|
||||
defStrict("advert_verify", _advert_verify, _seen_advert_verify);
|
||||
defStrict("status", _status, _seen_status);
|
||||
defStrict("neighbors", _neighbors, _seen_neighbors);
|
||||
defStrict("owner", _owner, _seen_owner);
|
||||
@@ -239,7 +240,8 @@ class MQTTPrefsSerializer : public ConfigSerializer {
|
||||
MQTTPrefsPresetValidator preset_valid)
|
||||
: _prefs(prefs), _packets_enabled(prefs->mqtt_packets_enabled),
|
||||
_raw_enabled(prefs->mqtt_raw_enabled), _tx_enabled(prefs->mqtt_tx_enabled),
|
||||
_rx_enabled(prefs->mqtt_rx_enabled), _status(prefs), _neighbors(prefs),
|
||||
_rx_enabled(prefs->mqtt_rx_enabled), _advert_verify(prefs->mqtt_advert_verify),
|
||||
_status(prefs), _neighbors(prefs),
|
||||
_owner(prefs), _slot1(prefs, 0, preset_valid),
|
||||
_slot2(prefs, 1, preset_valid), _slot3(prefs, 2, preset_valid),
|
||||
_slot4(prefs, 3, preset_valid), _slot5(prefs, 4, preset_valid),
|
||||
@@ -257,10 +259,12 @@ class MQTTPrefsSerializer : public ConfigSerializer {
|
||||
if (_raw_enabled < 0 || _raw_enabled > 1) { _raw_enabled = 0; *repaired = true; }
|
||||
if (_tx_enabled < 0 || _tx_enabled > 2) { _tx_enabled = 2; *repaired = true; }
|
||||
if (_rx_enabled < 0 || _rx_enabled > 1) { _rx_enabled = 1; *repaired = true; }
|
||||
if (_advert_verify < 0 || _advert_verify > 1) { _advert_verify = 0; *repaired = true; }
|
||||
_prefs->mqtt_packets_enabled = static_cast<uint8_t>(_packets_enabled);
|
||||
_prefs->mqtt_raw_enabled = static_cast<uint8_t>(_raw_enabled);
|
||||
_prefs->mqtt_tx_enabled = static_cast<uint8_t>(_tx_enabled);
|
||||
_prefs->mqtt_rx_enabled = static_cast<uint8_t>(_rx_enabled);
|
||||
_prefs->mqtt_advert_verify = static_cast<uint8_t>(_advert_verify);
|
||||
if (_prefs->mqtt_iata[0] != '\0') {
|
||||
if (!mqttIataValid(_prefs->mqtt_iata)) {
|
||||
memcpy(_prefs->mqtt_iata, _default_iata, sizeof(_default_iata));
|
||||
|
||||
@@ -125,10 +125,13 @@ struct MQTTPrefs {
|
||||
|
||||
// Runtime display controls. These are an append-only v1 tail: older payloads
|
||||
// stop before them and retain the defaults below. The serialized payload ends
|
||||
// after display_flip at byte 2879; the compiler's final alignment byte is not
|
||||
// part of the on-flash format.
|
||||
// after display_flip at byte 2879 on pre-verification firmware.
|
||||
uint16_t display_timeout_secs;
|
||||
uint8_t display_flip;
|
||||
// Drop received adverts whose Ed25519 signature fails before publishing.
|
||||
// Append-only v1 tail at byte 2879 (formerly final struct padding). Defaults
|
||||
// off; only enabling verification requires the 2880-byte serialized payload.
|
||||
uint8_t mqtt_advert_verify;
|
||||
};
|
||||
|
||||
// Neighbor discovery is scheduled with the wrap-safe millis() helpers, whose
|
||||
@@ -144,7 +147,7 @@ static const uint32_t MQTT_NEIGHBORS_DEFAULT_INTERVAL_MS = MQTT_NEIGHBORS_DEFAUL
|
||||
static const uint16_t DISPLAY_TIMEOUT_DEFAULT_SECS = 60;
|
||||
static const uint16_t DISPLAY_TIMEOUT_MAX_SECS = 3600;
|
||||
|
||||
// Version-1 has five payload layouts this firmware can decode. Never infer a
|
||||
// Version-1 has six payload layouts this firmware can decode. Never infer a
|
||||
// compatible payload from an arbitrary SHORTER size: raw prefs have no
|
||||
// checksum, so a short length has to match a boundary that was really shipped.
|
||||
//
|
||||
@@ -157,18 +160,20 @@ static const uint16_t DISPLAY_TIMEOUT_MAX_SECS = 3600;
|
||||
// - PRE_NEIGHBORS (2860): full observer tail, no neighbors fields yet.
|
||||
// - PRE_FILTER (2864): neighbors tail, no per-slot packet filters.
|
||||
// - PRE_DISPLAY (2876): six filter masks, no runtime display controls.
|
||||
// - FULL (2879): timeout plus flip, excluding final struct padding.
|
||||
// - PRE_ADVERT (2879): timeout plus flip, excluding final struct padding.
|
||||
// - FULL (2880): advert verification consumes that former padding.
|
||||
//
|
||||
// FULL is the maximum written, not the default: MQTTPrefsCodec::payloadLenFor()
|
||||
// keeps emitting PRE_FILTER while every slot and display control has its
|
||||
// default. A non-default filter writes PRE_DISPLAY; a non-default display
|
||||
// control writes FULL. See the rollback note there -- /mqtt_prefs also carries
|
||||
// the WiFi credentials.
|
||||
// control writes PRE_ADVERT; enabling advert verification writes FULL. See the
|
||||
// rollback note there -- /mqtt_prefs also carries the WiFi credentials.
|
||||
static const size_t MQTT_PREFS_V1_PRE_OBSERVER_PAYLOAD_SIZE = 2736;
|
||||
static const size_t MQTT_PREFS_V1_PRE_NEIGHBORS_PAYLOAD_SIZE = 2860;
|
||||
static const size_t MQTT_PREFS_V1_PRE_FILTER_PAYLOAD_SIZE = 2864;
|
||||
static const size_t MQTT_PREFS_V1_PRE_DISPLAY_PAYLOAD_SIZE = 2876;
|
||||
static const size_t MQTT_PREFS_V1_FULL_PAYLOAD_SIZE = 2879;
|
||||
static const size_t MQTT_PREFS_V1_PRE_ADVERT_PAYLOAD_SIZE = 2879;
|
||||
static const size_t MQTT_PREFS_V1_FULL_PAYLOAD_SIZE = 2880;
|
||||
|
||||
// /mqtt_prefs starts with a self-describing 8-byte header. Headerless files
|
||||
// are deployed legacy layouts and continue to be distinguished by size.
|
||||
@@ -303,8 +308,13 @@ static_assert(offsetof(MQTTPrefs, mqtt_slot_packet_filter) == MQTT_PREFS_V1_PRE_
|
||||
static_assert(offsetof(MQTTPrefs, display_timeout_secs) == MQTT_PREFS_V1_PRE_DISPLAY_PAYLOAD_SIZE,
|
||||
"display timeout must begin at the pre-display payload boundary");
|
||||
static_assert(offsetof(MQTTPrefs, display_flip) + sizeof(MQTTPrefs::display_flip) ==
|
||||
MQTT_PREFS_V1_FULL_PAYLOAD_SIZE,
|
||||
MQTT_PREFS_V1_PRE_ADVERT_PAYLOAD_SIZE,
|
||||
"serialized display tail must end immediately after display_flip");
|
||||
static_assert(offsetof(MQTTPrefs, mqtt_advert_verify) == MQTT_PREFS_V1_PRE_ADVERT_PAYLOAD_SIZE,
|
||||
"advert verification must consume only the former final padding byte");
|
||||
static_assert(offsetof(MQTTPrefs, mqtt_advert_verify) + sizeof(MQTTPrefs::mqtt_advert_verify) ==
|
||||
MQTT_PREFS_V1_FULL_PAYLOAD_SIZE,
|
||||
"serialized advert verification tail must end immediately after its flag");
|
||||
static_assert(sizeof(OldMQTTPrefs) == 472, "frozen pre-slot /mqtt_prefs layout changed");
|
||||
static_assert(sizeof(PreWifiPowerOldMQTTPrefs) == 472, "frozen pre-WiFi-power /mqtt_prefs layout changed");
|
||||
static_assert(offsetof(OldMQTTPrefs, wifi_power_save) == 144,
|
||||
|
||||
@@ -29,7 +29,7 @@ static const char* const WC_ALLOWED_SET_KEYS[] = {
|
||||
// MQTTPrefs (WiFi / MQTT / misc observer)
|
||||
"wifi.ssid", "wifi.pwd", "wifi.powersave", "espnow.channel",
|
||||
"mqtt.enabled", "mqtt.origin", "mqtt.iata", "mqtt.status", "mqtt.packets", "mqtt.raw",
|
||||
"mqtt.tx", "mqtt.rx", "mqtt.interval", "mqtt.neighbors", "mqtt.neighbors.interval",
|
||||
"mqtt.tx", "mqtt.rx", "mqtt.advert.verify", "mqtt.interval", "mqtt.neighbors", "mqtt.neighbors.interval",
|
||||
"mqtt.ntp", "mqtt.owner", "mqtt.email",
|
||||
"timezone", "timezone.offset", "snmp", "snmp.community",
|
||||
};
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "../MQTTReplyFormat.h"
|
||||
#include "../MQTTRuntimeBufferLifecycle.h"
|
||||
#include "../MQTTTopicRouter.h"
|
||||
#include "../AdvertSignature.h"
|
||||
#include "../TxtDataHelpers.h"
|
||||
#include "../UsbLogging.h"
|
||||
#include "../WiFiPowerSave.h"
|
||||
@@ -519,6 +520,14 @@ void MQTTBridge::formatMqttStatsReply(char* buf, size_t bufsize) {
|
||||
if (b->_filtered_packets > 0) {
|
||||
replyAppendf(buf, bufsize, &pos, " filt=%lu", b->_filtered_packets);
|
||||
}
|
||||
// badsig=<n>: RX adverts dropped by mqtt.advert.verify. Omitted while zero.
|
||||
if (b->_bad_sig_adverts > 0) {
|
||||
replyAppendf(buf, bufsize, &pos, " badsig=%lu", b->_bad_sig_adverts);
|
||||
}
|
||||
// down=<n>: ready slots that are not connected. Without this the reply cannot
|
||||
// show an outage at all - sN= counts publishes, and a slot that never connects
|
||||
// never publishes, so its ok freezes and its err stays 0 for the whole outage.
|
||||
// Omitted while zero, like filt=, so a healthy node's reply keeps its length.
|
||||
int down = 0;
|
||||
for (int i = 0; i < RUNTIME_MQTT_SLOTS; i++) {
|
||||
if (MQTTConnectionHealth::isOutageSlot(
|
||||
@@ -3931,6 +3940,19 @@ void MQTTBridge::onPacketReceived(mesh::Packet *packet) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Opt-in: drop adverts that fail verification (RF corruption that passed the
|
||||
// LoRa CRC). The observer callback runs before Mesh::onRecvPacket validates
|
||||
// received adverts; its opt-in filter must enforce the same signed layout.
|
||||
if (_obs->mqtt_advert_verify && packet->getPayloadType() == PAYLOAD_TYPE_ADVERT) {
|
||||
uint8_t message[AdvertSignature::kMaxMessageLen];
|
||||
const uint8_t* sig = nullptr;
|
||||
int msg_len = AdvertSignature::buildMessage(packet->payload, packet->payload_len, message, &sig);
|
||||
if (msg_len < 0 || !mesh::Identity(packet->payload).verify(sig, message, msg_len)) {
|
||||
_bad_sig_adverts++;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Queue packet for transmission
|
||||
queuePacket(packet, false);
|
||||
}
|
||||
|
||||
@@ -423,6 +423,7 @@ private:
|
||||
// on Core 1 (radio callbacks), read on Core 0 for `mqtt.stats`; a torn read of
|
||||
// a diagnostic counter is harmless, so no atomic is warranted.
|
||||
unsigned long _filtered_packets = 0;
|
||||
unsigned long _bad_sig_adverts = 0; // RX adverts dropped by mqtt.advert.verify
|
||||
|
||||
// Status publish retry tracking
|
||||
unsigned long _last_status_retry; // Track last retry attempt (separate from successful publish)
|
||||
|
||||
@@ -2188,6 +2188,7 @@ void WebConfigServer::handleConfigGet(AsyncWebServerRequest* req) {
|
||||
mqtt["tx"] = obs->mqtt_tx_enabled == 2 ? "advert"
|
||||
: obs->mqtt_tx_enabled == 1 ? "on" : "off";
|
||||
mqtt["rx"] = (bool)obs->mqtt_rx_enabled;
|
||||
mqtt["advert_verify"] = (bool)obs->mqtt_advert_verify;
|
||||
mqtt["interval"] = obs->mqtt_status_interval / 60000;
|
||||
mqtt["neighbors"] = (bool)obs->mqtt_neighbors_enabled;
|
||||
mqtt["neighbors_interval"] = obs->mqtt_neighbors_interval / 3600000UL;
|
||||
|
||||
Reference in new issue
Block a user