Defer remote commands outside receive stack

This commit is contained in:
mikecarper committed 2026-07-24 00:18:35 -07:00
1 parent 6cf0954463
commit c1752f2db1
9 files changed
+281 -28

No files matched your search

+3
View File
@@ -218,7 +218,10 @@ void Mesh::begin() {
void Mesh::loop() {
Dispatcher::loop();
serviceLoopMaintenance();
}
void __attribute__((noinline)) Mesh::serviceLoopMaintenance() {
if (_waiting_direct_retry_count != 0
&& millisHasNowPassed(_next_direct_retry_timeout)) {
for (int i = 0; i < MAX_DIRECT_RETRY_SLOTS; i++) {
+1
View File
@@ -149,6 +149,7 @@ class Mesh : public Dispatcher {
void armFloodRetryOnSendComplete(const Packet* packet);
void clearPendingFloodRetryOnSendFail(const Packet* packet);
void maybeScheduleFloodRetry(const Packet* packet, uint8_t priority);
void serviceLoopMaintenance();
//void routeRecvAcks(Packet* packet, uint32_t delay_millis);
DispatcherAction forwardMultipartDirect(Packet* pkt);
+39
View File
@@ -0,0 +1,39 @@
#if defined(NRF52_PLATFORM)
#include <Arduino.h>
#include <FreeRTOS.h>
#include <task.h>
#include <string.h>
#ifndef MESH_NRF52_LOOP_STACK_WORDS
#define MESH_NRF52_LOOP_STACK_WORDS 2048
#endif
static_assert(MESH_NRF52_LOOP_STACK_WORDS >= 1024,
"The nRF52 loop task stack must not be smaller than the framework default");
extern "C" BaseType_t __real_xTaskCreate(
TaskFunction_t task_code, const char* const task_name,
const configSTACK_DEPTH_TYPE stack_depth, void* const parameters,
UBaseType_t priority, TaskHandle_t* const created_task);
// The Adafruit nRF52 core hard-codes the Arduino loop task to 1024 32-bit
// words (4 KiB). Mesh packet verification and authenticated remote commands
// can legitimately enter Ed25519 routines whose stack peaks do not fit there.
// Wrap task creation so only the framework's "loop" task receives 8 KiB; all
// BLE, timer, callback, and application-created tasks retain their requested
// sizes.
extern "C" BaseType_t __wrap_xTaskCreate(
TaskFunction_t task_code, const char* const task_name,
const configSTACK_DEPTH_TYPE stack_depth, void* const parameters,
UBaseType_t priority, TaskHandle_t* const created_task) {
configSTACK_DEPTH_TYPE adjusted_depth = stack_depth;
if (task_name != NULL && strcmp(task_name, "loop") == 0
&& stack_depth == 1024) {
adjusted_depth = MESH_NRF52_LOOP_STACK_WORDS;
}
return __real_xTaskCreate(task_code, task_name, adjusted_depth, parameters,
priority, created_task);
}
#endif
+57
View File
@@ -0,0 +1,57 @@
#pragma once
#include <MeshCore.h>
#include <stddef.h>
#include <stdint.h>
#include <string.h>
namespace mesh {
// A single-entry mailbox for authenticated remote CLI commands. The repeater
// drains it immediately after Mesh::loop() returns; a second command arriving
// in the same pass receives a busy response. Keeping the command in object
// storage lets the receive/decrypt call chain unwind before command handlers
// perform filesystem or cryptographic work.
struct DeferredCliCommand {
bool pending;
int client_index;
uint32_t sender_timestamp;
uint8_t path_hash_size;
uint8_t secret[PUB_KEY_SIZE];
char command[MAX_PACKET_PAYLOAD + 1];
DeferredCliCommand()
: pending(false), client_index(-1), sender_timestamp(0), path_hash_size(1) {
memset(secret, 0, sizeof(secret));
command[0] = 0;
}
bool enqueue(int new_client_index, uint32_t new_sender_timestamp,
uint8_t new_path_hash_size, const uint8_t* new_secret,
const char* new_command, size_t command_len) {
if (pending || new_secret == NULL || new_command == NULL
|| command_len >= sizeof(command)) {
return false;
}
client_index = new_client_index;
sender_timestamp = new_sender_timestamp;
path_hash_size = new_path_hash_size;
memcpy(secret, new_secret, sizeof(secret));
memcpy(command, new_command, command_len);
command[command_len] = 0;
pending = true;
return true;
}
void clear() {
pending = false;
client_index = -1;
sender_timestamp = 0;
path_hash_size = 1;
memset(secret, 0, sizeof(secret));
memset(command, 0, sizeof(command));
}
};
} // namespace mesh