diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index cdd61d15f..3ba46ccf2 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -1607,15 +1607,19 @@ void NodeDB::resetNodes(bool keepFavorites) numMeshNodes = 1; if (keepFavorites) { LOG_INFO("Clearing node database - preserving favorites"); - for (size_t i = 0; i < meshNodes->size(); i++) { - meshtastic_NodeInfoLite &node = meshNodes->at(i); - if (i > 0 && !nodeInfoLiteIsFavorite(&node)) { - eraseNodeSatellites(node.num); - node = meshtastic_NodeInfoLite(); - } else { + // Compact favorites into contiguous low slots: zeroing in place leaves one above + // numMeshNodes, invisible to every `i < numMeshNodes` scan yet still serialized to flash. + for (size_t i = 1; i < meshNodes->size(); i++) { + const meshtastic_NodeInfoLite &node = meshNodes->at(i); + if (nodeInfoLiteIsFavorite(&node)) { + if (numMeshNodes != i) + meshNodes->at(numMeshNodes) = node; numMeshNodes += 1; + } else if (node.num) { + eraseNodeSatellites(node.num); } - }; + } + std::fill(nodeDatabase.nodes.begin() + numMeshNodes, nodeDatabase.nodes.end(), meshtastic_NodeInfoLite()); } else { LOG_INFO("Clearing node database - removing favorites"); for (size_t i = 1; i < meshNodes->size(); i++) { diff --git a/src/mesh/PhoneAPI.cpp b/src/mesh/PhoneAPI.cpp index 572b79242..f86d25773 100644 --- a/src/mesh/PhoneAPI.cpp +++ b/src/mesh/PhoneAPI.cpp @@ -767,6 +767,12 @@ size_t PhoneAPI::getFromRadio(uint8_t *buf) LOG_DEBUG("Send config: bluetooth"); fromRadioScratch.config.which_payload_variant = meshtastic_Config_bluetooth_tag; fromRadioScratch.config.payload_variant.bluetooth = config.bluetooth; +#ifdef MESHTASTIC_PHONEAPI_ACCESS_CONTROL + if (!getAdminAuthorized()) { + // The pairing PIN is a shared secret; never expose it to an unauthenticated client. + fromRadioScratch.config.payload_variant.bluetooth.fixed_pin = 0; + } +#endif break; case meshtastic_Config_security_tag: LOG_DEBUG("Send config: security"); diff --git a/src/mesh/api/PacketAPI.cpp b/src/mesh/api/PacketAPI.cpp index 3f145bfe3..9408e9266 100644 --- a/src/mesh/api/PacketAPI.cpp +++ b/src/mesh/api/PacketAPI.cpp @@ -6,6 +6,12 @@ #include "RadioInterface.h" #include "modules/NodeInfoModule.h" +#ifdef MESHTASTIC_PHONEAPI_ACCESS_CONTROL +// receivePacket() dispatches ToRadio straight to MeshService, bypassing handleToRadioPacket and so +// the lockdown admin gate. Fail the build rather than silently ship an admin-auth bypass. +#error "USE_PACKET_API is incompatible with MESHTASTIC_PHONEAPI_ACCESS_CONTROL (PacketAPI bypasses the lockdown admin gate)" +#endif + PacketAPI *packetAPI = nullptr; PacketAPI *PacketAPI::create(PacketServer *_server)