Add secure host CLI bridge and harden OTA workflows
Expose the Full Companion terminal over TCP and add an authenticated, replay-resistant host command service with documented CPU temperature, reboot, and allowlisted program examples.\n\nImprove LoRa OTA diagnostics and persistent CLI handling, reduce clock correction drift to ten minutes, and make mOTA stream flush behavior an explicit transport policy with regression coverage.
This commit is contained in:
1 parent
83c1dd95fe
commit
b699e552ec
46 files changed
+4364
-359
No files matched your search
+2
-1
@@ -55,6 +55,7 @@ does not reflect the GoogleTest count -- run the built binary directly
|
||||
| `test_companion_node_prefs` | `examples/companion_radio/NodePrefs.h` | independent device power saving, RXPS, Wi-Fi, and FEM preferences; one-time migration of the regressed power-saving default |
|
||||
| `test_config_serializer` | `src/helpers/ConfigSerializer.cpp`, Companion `NodePrefs` | escaped config save/load, whitespace and malformed input, unknown fields, and FEM preference round trips |
|
||||
| `test_deferred_cli_command` | `src/helpers/DeferredCliCommand.h` | copying authenticated command context, single-pending-command enforcement, clearing, and length rejection |
|
||||
| `test_host_cli_bridge` | `src/helpers/HostCliBridge.h` | bounded request/reply parsing, Base64URL serial framing, correlation preservation, one-time service-claim proofs, request-token fields, line safety, and UTF-8-safe truncation |
|
||||
| `test_kiss_modem` | `examples/kiss_modem/KissModem.cpp` | KISS escaping/framing and packet metadata under partial writes, host TX backpressure, queue saturation, and radio completion; run with `native_kiss_modem` |
|
||||
| `test_mesh_tables` | `src/helpers/SimpleMeshTables.h` | packet and ACK/multipart deduplication, scope-independent identity, route-prefix matching, and deterministic recent-repeater expiry/eviction |
|
||||
| `test_mqtt_lifecycle` | `src/helpers/MQTTLifecycle.h` | idempotent start/stop, initialization rollback, cooperative stop acknowledgment and timeout, callback ownership, restart, and the OTA flash barrier |
|
||||
@@ -71,7 +72,7 @@ does not reflect the GoogleTest count -- run the built binary directly
|
||||
| `test_utf8_helpers` | `src/helpers/UTF8Helpers.h` | byte-limit truncation at complete code-point boundaries and rejection of malformed or truncated UTF-8 |
|
||||
| `test_wifi_ota_seeder_policy` | `src/helpers/WiFiOtaSeederPolicy.h`, `WiFiOtaSeederStatus.h` | listener state versus network availability, serial/TCP folder ownership, detach detection, and bounded status formatting |
|
||||
| `test_ota` | `src/helpers/ota/` | v2 application/v3 bootloader parser separation; legacy XIAO, generic internal, and exact MeshTower V2 SD embedded identity, vector, capability, explicit-confirmation, codec-isolation, scratch-headroom/shared-slot no-EndF gates, and no-autofetch gates; container and EndF integrity; protocol codecs; transfer, resume, and layered apply safety; adaptive 2-to-4 block-request window growth and stall contraction; active-transfer priority classification |
|
||||
| `test_trace_retry` | `src/Mesh.cpp` retry and relay policy | app-v2 and boot-v3 traffic sharing `PAYLOAD_TYPE_OTA=0x0C` and the TempRadio suspend policy; opaque OTA relay behavior; background discovery priority; immediate primary transfer relay, receive-delay bypass, fast CAD retry, and no generic flood retry; trace and non-OTA flood retry timing |
|
||||
| `test_trace_retry` | `src/Mesh.cpp`, `RTCClock`, `ClockSyncUtils.h`, retry and relay policy | app-v2 and boot-v3 traffic sharing `PAYLOAD_TYPE_OTA=0x0C` and the TempRadio suspend policy; opaque OTA relay behavior; background discovery priority; immediate primary transfer relay, receive-delay bypass, fast CAD retry, and no generic flood retry; trace and non-OTA flood retry timing; backward RTC correction; clock consensus/path policy and the 10-minute default drift threshold |
|
||||
| `test_utils` | `src/Utils.cpp` | `Utils::toHex` (upstream) |
|
||||
|
||||
## Conventions (and how to add a suite)
|
||||
|
||||
@@ -319,14 +319,27 @@ TEST(CLICommandUtils, RejectsMalformedTerminalPaths) {
|
||||
"A1B2C3,D4E5F6", route, sizeof(route), 63, path));
|
||||
}
|
||||
|
||||
TEST(CLICommandUtils, MasksOnlyTerminalLoginPasswordInput) {
|
||||
TEST(CLICommandUtils, MasksTerminalPasswordInput) {
|
||||
EXPECT_FALSE(mesh::cli::shouldMaskTerminalInput("login"));
|
||||
EXPECT_FALSE(mesh::cli::shouldMaskTerminalInput("login "));
|
||||
EXPECT_TRUE(mesh::cli::shouldMaskTerminalInput("login s"));
|
||||
EXPECT_TRUE(mesh::cli::shouldMaskTerminalInput("LOGIN s"));
|
||||
EXPECT_TRUE(mesh::cli::shouldMaskTerminalInput(" login secret phrase"));
|
||||
EXPECT_FALSE(mesh::cli::shouldMaskTerminalInput("set wifi.pwd"));
|
||||
EXPECT_FALSE(mesh::cli::shouldMaskTerminalInput("set wifi.pwd "));
|
||||
EXPECT_TRUE(mesh::cli::shouldMaskTerminalInput("set wifi.pwd s"));
|
||||
EXPECT_TRUE(mesh::cli::shouldMaskTerminalInput("SET WIFI.PWD secret phrase"));
|
||||
EXPECT_TRUE(mesh::cli::shouldMaskTerminalInput(" set wifi.pwd secret"));
|
||||
EXPECT_FALSE(mesh::cli::shouldMaskTerminalInput("cmd login secret"));
|
||||
EXPECT_FALSE(mesh::cli::shouldMaskTerminalInput("cmd set wifi.pwd secret"));
|
||||
EXPECT_FALSE(mesh::cli::shouldMaskTerminalInput("set wifi.pwd-status secret"));
|
||||
EXPECT_FALSE(mesh::cli::shouldMaskTerminalInput("login-status"));
|
||||
|
||||
const char* login = " login secret phrase";
|
||||
EXPECT_STREQ("secret phrase", mesh::cli::terminalPasswordInput(login));
|
||||
const char* wifi = "set wifi.pwd secret phrase";
|
||||
EXPECT_STREQ("secret phrase", mesh::cli::terminalPasswordInput(wifi));
|
||||
EXPECT_EQ(nullptr, mesh::cli::terminalPasswordInput("set wifi.pwd "));
|
||||
}
|
||||
|
||||
TEST(CLICommandUtils, BackspaceErasesAsciiAndUtf8Characters) {
|
||||
|
||||
@@ -0,0 +1,172 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <helpers/HostCliBridge.h>
|
||||
|
||||
TEST(HostCliBridge, ParsesPlainAndCorrelatedRequests) {
|
||||
mesh::HostCliBridge::RequestView request;
|
||||
EXPECT_EQ(mesh::HostCliBridge::VALID_HOST_COMMAND,
|
||||
mesh::HostCliBridge::parseRequest("host cpu-temp", request));
|
||||
ASSERT_NE(nullptr, request.text);
|
||||
EXPECT_STREQ("cpu-temp", request.text);
|
||||
EXPECT_EQ(8U, request.text_len);
|
||||
EXPECT_EQ(0U, request.correlation_len);
|
||||
|
||||
EXPECT_EQ(mesh::HostCliBridge::VALID_HOST_COMMAND,
|
||||
mesh::HostCliBridge::parseRequest("A7|host get status", request));
|
||||
ASSERT_NE(nullptr, request.correlation);
|
||||
EXPECT_EQ(0, memcmp("A7|", request.correlation, 3));
|
||||
EXPECT_EQ(3U, request.correlation_len);
|
||||
EXPECT_STREQ("get status", request.text);
|
||||
|
||||
EXPECT_EQ(mesh::HostCliBridge::VALID_HOST_COMMAND,
|
||||
mesh::HostCliBridge::parseRequest(
|
||||
"host cpu-temp \t\r\n", request));
|
||||
EXPECT_EQ(8U, request.text_len);
|
||||
char record[mesh::HostCliBridge::USB_SIGNED_CONTENT_MAX + 1U];
|
||||
ASSERT_TRUE(mesh::HostCliBridge::formatUsbRequest(
|
||||
record, sizeof(record), 1U, 2U, request.text, request.text_len));
|
||||
EXPECT_STREQ("HOSTCLI/1 REQUEST 00000001 0000000000000002 "
|
||||
"Y3B1LXRlbXA", record);
|
||||
}
|
||||
|
||||
TEST(HostCliBridge, DistinguishesInvalidHostRequestsFromOtherCommands) {
|
||||
mesh::HostCliBridge::RequestView request;
|
||||
EXPECT_EQ(mesh::HostCliBridge::INVALID_HOST_COMMAND,
|
||||
mesh::HostCliBridge::parseRequest("host", request));
|
||||
EXPECT_EQ(mesh::HostCliBridge::INVALID_HOST_COMMAND,
|
||||
mesh::HostCliBridge::parseRequest("host ", request));
|
||||
EXPECT_EQ(mesh::HostCliBridge::NOT_HOST_COMMAND,
|
||||
mesh::HostCliBridge::parseRequest("host.reply 12345678 OK", request));
|
||||
EXPECT_EQ(mesh::HostCliBridge::NOT_HOST_COMMAND,
|
||||
mesh::HostCliBridge::parseRequest("get host", request));
|
||||
}
|
||||
|
||||
TEST(HostCliBridge, EnforcesRemoteCommandLengthWithAndWithoutCorrelation) {
|
||||
char command[mesh::HostCliBridge::REMOTE_COMMAND_MAX + 2U];
|
||||
memcpy(command, "host ", 5);
|
||||
memset(command + 5, 'x', mesh::HostCliBridge::REQUEST_TEXT_MAX);
|
||||
command[mesh::HostCliBridge::REMOTE_COMMAND_MAX] = 0;
|
||||
|
||||
mesh::HostCliBridge::RequestView request;
|
||||
EXPECT_EQ(mesh::HostCliBridge::VALID_HOST_COMMAND,
|
||||
mesh::HostCliBridge::parseRequest(command, request));
|
||||
|
||||
command[mesh::HostCliBridge::REMOTE_COMMAND_MAX] = 'x';
|
||||
command[mesh::HostCliBridge::REMOTE_COMMAND_MAX + 1U] = 0;
|
||||
EXPECT_EQ(mesh::HostCliBridge::INVALID_HOST_COMMAND,
|
||||
mesh::HostCliBridge::parseRequest(command, request));
|
||||
|
||||
memcpy(command, "Q2|host ", 8);
|
||||
memset(command + 8, 'y',
|
||||
mesh::HostCliBridge::REQUEST_TEXT_WITH_CORRELATION_MAX);
|
||||
command[mesh::HostCliBridge::REMOTE_COMMAND_MAX] = 0;
|
||||
EXPECT_EQ(mesh::HostCliBridge::VALID_HOST_COMMAND,
|
||||
mesh::HostCliBridge::parseRequest(command, request));
|
||||
}
|
||||
|
||||
TEST(HostCliBridge, FormatsLineSafeBase64UrlUsbRecord) {
|
||||
char record[mesh::HostCliBridge::USB_SIGNED_CONTENT_MAX + 1U];
|
||||
ASSERT_TRUE(mesh::HostCliBridge::formatUsbRequest(
|
||||
record, sizeof(record), 0x89ABCDEFU, 0x0123456789ABCDEFULL,
|
||||
"cpu-temp", 8));
|
||||
EXPECT_STREQ(
|
||||
"HOSTCLI/1 REQUEST 89ABCDEF 0123456789ABCDEF Y3B1LXRlbXA",
|
||||
record);
|
||||
|
||||
const char unsafe[] = "line one\nline two";
|
||||
ASSERT_TRUE(mesh::HostCliBridge::formatUsbRequest(
|
||||
record, sizeof(record), 1U, 2U, unsafe, strlen(unsafe)));
|
||||
EXPECT_EQ(nullptr, strchr(record, '\n'));
|
||||
EXPECT_EQ(nullptr, strchr(record, '='));
|
||||
}
|
||||
|
||||
TEST(HostCliBridge, ParsesAndFormatsServiceClaimProof) {
|
||||
uint64_t challenge = 0;
|
||||
EXPECT_TRUE(mesh::HostCliBridge::parseServiceClaim(
|
||||
"@claim=0123456789ABCDEF", 23U, challenge));
|
||||
EXPECT_EQ(0x0123456789ABCDEFULL, challenge);
|
||||
EXPECT_FALSE(mesh::HostCliBridge::parseServiceClaim(
|
||||
"@claim=0123456789ABCDEG", 23U, challenge));
|
||||
EXPECT_FALSE(mesh::HostCliBridge::parseServiceClaim(
|
||||
"@claim=0000000000000000", 23U, challenge));
|
||||
EXPECT_FALSE(mesh::HostCliBridge::parseServiceClaim(
|
||||
"@claim=0123456789ABCDE", 22U, challenge));
|
||||
|
||||
char record[mesh::HostCliBridge::CLAIMED_SIGNED_CONTENT_MAX + 1U];
|
||||
ASSERT_TRUE(mesh::HostCliBridge::formatUsbClaim(
|
||||
record, sizeof(record), 0x89ABCDEFU, 0x0123456789ABCDEFULL,
|
||||
0xFEDCBA9876543210ULL));
|
||||
EXPECT_STREQ(
|
||||
"HOSTCLI/1 CLAIMED 89ABCDEF 0123456789ABCDEF FEDCBA9876543210",
|
||||
record);
|
||||
}
|
||||
|
||||
TEST(HostCliBridge, ParsesOnlyBoundedLineSafeUtf8Replies) {
|
||||
mesh::HostCliBridge::ReplyView reply;
|
||||
EXPECT_EQ(mesh::HostCliBridge::VALID_HOST_COMMAND,
|
||||
mesh::HostCliBridge::parseReply(
|
||||
"host.reply 89abcdef 0123456789abcdef CPU 47.2 C", reply));
|
||||
EXPECT_EQ(0x89ABCDEFU, reply.request_id);
|
||||
EXPECT_EQ(0x0123456789ABCDEFULL, reply.request_nonce);
|
||||
EXPECT_STREQ("CPU 47.2 C", reply.text);
|
||||
|
||||
EXPECT_EQ(mesh::HostCliBridge::INVALID_HOST_COMMAND,
|
||||
mesh::HostCliBridge::parseReply(
|
||||
"host.reply 89ABCDE 0123456789ABCDEF CPU 1 C", reply));
|
||||
EXPECT_EQ(mesh::HostCliBridge::INVALID_HOST_COMMAND,
|
||||
mesh::HostCliBridge::parseReply("host.reply ", reply));
|
||||
EXPECT_EQ(mesh::HostCliBridge::INVALID_HOST_COMMAND,
|
||||
mesh::HostCliBridge::parseReply(
|
||||
"host.reply 89ABCDEF 0123456789ABCDEG CPU 1 C", reply));
|
||||
EXPECT_EQ(mesh::HostCliBridge::INVALID_HOST_COMMAND,
|
||||
mesh::HostCliBridge::parseReply(
|
||||
"host.reply 89ABCDEF 0123456789ABCDEF first\nsecond", reply));
|
||||
EXPECT_EQ(mesh::HostCliBridge::NOT_HOST_COMMAND,
|
||||
mesh::HostCliBridge::parseReply(
|
||||
"host.replyx 89ABCDEF 0123456789ABCDEF OK", reply));
|
||||
|
||||
const char valid_utf8[] =
|
||||
"host.reply 12345678 FEDCBA9876543210 " "\xE2\x82\xAC";
|
||||
EXPECT_EQ(mesh::HostCliBridge::VALID_HOST_COMMAND,
|
||||
mesh::HostCliBridge::parseReply(valid_utf8, reply));
|
||||
const char invalid_utf8[] =
|
||||
"host.reply 12345678 FEDCBA9876543210 " "\xE2\x82";
|
||||
EXPECT_EQ(mesh::HostCliBridge::INVALID_HOST_COMMAND,
|
||||
mesh::HostCliBridge::parseReply(invalid_utf8, reply));
|
||||
}
|
||||
|
||||
TEST(HostCliBridge, EnforcesMaximumReplyLength) {
|
||||
char command[mesh::HostCliBridge::SERIAL_REPLY_COMMAND_MAX + 2U];
|
||||
const int prefix_len = snprintf(command, sizeof(command),
|
||||
"host.reply 12345678 FEDCBA9876543210 ");
|
||||
ASSERT_GT(prefix_len, 0);
|
||||
memset(command + prefix_len, 'r', mesh::HostCliBridge::REMOTE_REPLY_MAX);
|
||||
command[prefix_len + mesh::HostCliBridge::REMOTE_REPLY_MAX] = 0;
|
||||
|
||||
mesh::HostCliBridge::ReplyView reply;
|
||||
EXPECT_EQ(mesh::HostCliBridge::VALID_HOST_COMMAND,
|
||||
mesh::HostCliBridge::parseReply(command, reply));
|
||||
command[prefix_len + mesh::HostCliBridge::REMOTE_REPLY_MAX] = 'r';
|
||||
command[prefix_len + mesh::HostCliBridge::REMOTE_REPLY_MAX + 1U] = 0;
|
||||
EXPECT_EQ(mesh::HostCliBridge::INVALID_HOST_COMMAND,
|
||||
mesh::HostCliBridge::parseReply(command, reply));
|
||||
}
|
||||
|
||||
TEST(HostCliBridge, PreservesCorrelationAndDoesNotSplitUtf8AtLimit) {
|
||||
char output[mesh::HostCliBridge::REMOTE_REPLY_MAX + 1U];
|
||||
EXPECT_EQ(5U, mesh::HostCliBridge::formatRemoteReply(
|
||||
output, sizeof(output), "B4|host cpu-temp", "OK"));
|
||||
EXPECT_STREQ("B4|OK", output);
|
||||
|
||||
char short_output[5];
|
||||
const char service_reply[] = "abc" "\xE2\x82\xAC";
|
||||
EXPECT_EQ(3U, mesh::HostCliBridge::formatRemoteReply(
|
||||
short_output, sizeof(short_output), "host test",
|
||||
service_reply));
|
||||
EXPECT_STREQ("abc", short_output);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <array>
|
||||
#include <vector>
|
||||
#include <cstring>
|
||||
#include <type_traits>
|
||||
|
||||
#include "helpers/ota/MotaContainer.h"
|
||||
#include "helpers/ota/MerkleTree.h"
|
||||
@@ -10,6 +11,7 @@
|
||||
#include "helpers/ota/FirmwareInfo.h"
|
||||
#include "helpers/ota/MotaSeederProto.h"
|
||||
#include "helpers/ota/MotaSourceSerial.h"
|
||||
#include "helpers/ota/FolderMotaStore.h"
|
||||
#include "helpers/ota/SignerAllowlist.h"
|
||||
#include "helpers/ota/OtaStore.h"
|
||||
#include "helpers/ota/OtaProtocol.h"
|
||||
@@ -688,21 +690,43 @@ public:
|
||||
}
|
||||
|
||||
int read() override {
|
||||
return response_pos < response.size() ? response[response_pos++] : -1;
|
||||
if (response_pos < response.size()) return response[response_pos++];
|
||||
++g_mock_millis;
|
||||
return -1;
|
||||
}
|
||||
|
||||
void flush() override {
|
||||
++flush_calls;
|
||||
if (flush_discards_receive) {
|
||||
response.clear();
|
||||
response_pos = 0;
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<uint32_t> offsets;
|
||||
std::vector<uint16_t> lengths;
|
||||
bool request_valid = true;
|
||||
bool flush_discards_receive = false;
|
||||
size_t flush_calls = 0;
|
||||
|
||||
private:
|
||||
std::vector<uint8_t> response;
|
||||
size_t response_pos = 0;
|
||||
};
|
||||
|
||||
static_assert(!std::is_constructible<SerialMotaSource, Stream&>::value,
|
||||
"mOTA source callers must choose a stream write policy");
|
||||
static_assert(!std::is_constructible<SerialMotaSource, Stream&, uint32_t>::value,
|
||||
"a timeout must not be mistaken for a stream write policy");
|
||||
static_assert(!std::is_constructible<FolderMotaStore, Stream&>::value,
|
||||
"folder store callers must choose a stream write policy");
|
||||
static_assert(!std::is_constructible<FolderMotaStore, Stream&, uint32_t>::value,
|
||||
"a timeout must not be mistaken for a stream write policy");
|
||||
|
||||
TEST(MotaSourceSerial, SplitsOneKilobyteReadsBelowCdcReceiveRing) {
|
||||
resetArduinoMock();
|
||||
FakeMotaSeederStream stream;
|
||||
SerialMotaSource source(stream);
|
||||
SerialMotaSource source(stream, MotaStreamWritePolicy::FlushTransmit);
|
||||
std::array<uint8_t, 1024> data{};
|
||||
|
||||
ASSERT_TRUE(source.read(0, 0x1000, data.data(), data.size()));
|
||||
@@ -711,14 +735,16 @@ TEST(MotaSourceSerial, SplitsOneKilobyteReadsBelowCdcReceiveRing) {
|
||||
(std::vector<uint32_t>{0x1000, 0x10C0, 0x1180, 0x1240, 0x1300, 0x13C0}));
|
||||
EXPECT_EQ(stream.lengths,
|
||||
(std::vector<uint16_t>{192, 192, 192, 192, 192, 64}));
|
||||
EXPECT_EQ(stream.flush_calls, 6U);
|
||||
for (size_t i = 0; i < data.size(); i++) {
|
||||
EXPECT_EQ(data[i], (uint8_t)(0x1000 + i));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(MotaSourceSerial, AcceptsEmptyReadAndRejectsInvalidRange) {
|
||||
resetArduinoMock();
|
||||
FakeMotaSeederStream stream;
|
||||
SerialMotaSource source(stream);
|
||||
SerialMotaSource source(stream, MotaStreamWritePolicy::FlushTransmit);
|
||||
uint8_t byte = 0;
|
||||
|
||||
EXPECT_TRUE(source.read(0, 123, nullptr, 0));
|
||||
@@ -727,6 +753,96 @@ TEST(MotaSourceSerial, AcceptsEmptyReadAndRejectsInvalidRange) {
|
||||
EXPECT_TRUE(stream.offsets.empty());
|
||||
}
|
||||
|
||||
TEST(MotaSourceSerial, NetworkPolicyPreservesReplyWhenFlushWouldDiscardRx) {
|
||||
resetArduinoMock();
|
||||
FakeMotaSeederStream stream;
|
||||
stream.flush_discards_receive = true;
|
||||
SerialMotaSource source(stream, MotaStreamWritePolicy::NoFlush, 20);
|
||||
std::array<uint8_t, 16> data{};
|
||||
|
||||
ASSERT_TRUE(source.read(0, 0x2000, data.data(), data.size()));
|
||||
EXPECT_EQ(stream.flush_calls, 0U);
|
||||
for (size_t i = 0; i < data.size(); i++) {
|
||||
EXPECT_EQ(data[i], (uint8_t)(0x2000 + i));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(MotaSourceSerial, WrongFlushPolicyDemonstratesNetworkReplyLoss) {
|
||||
resetArduinoMock();
|
||||
FakeMotaSeederStream stream;
|
||||
stream.flush_discards_receive = true;
|
||||
SerialMotaSource source(stream, MotaStreamWritePolicy::FlushTransmit, 20);
|
||||
std::array<uint8_t, 4> data{};
|
||||
|
||||
EXPECT_FALSE(source.read(0, 0x3000, data.data(), data.size()));
|
||||
EXPECT_EQ(stream.flush_calls, 1U);
|
||||
}
|
||||
|
||||
class FakeFolderMotaSeederStream : public Stream {
|
||||
public:
|
||||
using Stream::write;
|
||||
|
||||
size_t write(const uint8_t* request, size_t len) override {
|
||||
request_valid = len >= 4
|
||||
&& request[0] == MOTA_SEEDER_REQ_MAGIC0
|
||||
&& request[1] == MOTA_SEEDER_REQ_MAGIC1;
|
||||
if (!request_valid) return len;
|
||||
|
||||
uint8_t checksum = request[2];
|
||||
for (size_t i = 3; i + 1 < len; i++) checksum ^= request[i];
|
||||
request_valid = checksum == request[len - 1];
|
||||
if (!request_valid) return len;
|
||||
|
||||
operations.push_back(request[2]);
|
||||
response = {
|
||||
MOTA_SEEDER_RSP_MAGIC0,
|
||||
MOTA_SEEDER_RSP_MAGIC1,
|
||||
request[2],
|
||||
MS_STATUS_OK,
|
||||
(uint8_t)(MOTA_SEEDER_RSP_MAGIC0 ^ MOTA_SEEDER_RSP_MAGIC1
|
||||
^ request[2] ^ MS_STATUS_OK),
|
||||
};
|
||||
response_pos = 0;
|
||||
return len;
|
||||
}
|
||||
|
||||
int read() override {
|
||||
if (response_pos < response.size()) return response[response_pos++];
|
||||
++g_mock_millis;
|
||||
return -1;
|
||||
}
|
||||
|
||||
void flush() override {
|
||||
++flush_calls;
|
||||
response.clear();
|
||||
response_pos = 0;
|
||||
}
|
||||
|
||||
std::vector<uint8_t> operations;
|
||||
bool request_valid = true;
|
||||
size_t flush_calls = 0;
|
||||
|
||||
private:
|
||||
std::vector<uint8_t> response;
|
||||
size_t response_pos = 0;
|
||||
};
|
||||
|
||||
TEST(FolderMotaStore, NetworkPolicyPreservesFastBeginAndWriteReplies) {
|
||||
resetArduinoMock();
|
||||
FakeFolderMotaSeederStream stream;
|
||||
FolderMotaStore store(stream, MotaStreamWritePolicy::NoFlush, 20);
|
||||
const uint8_t mid[4] = {0x10, 0x20, 0x30, 0x40};
|
||||
const uint8_t data[4] = {1, 2, 3, 4};
|
||||
store.set_mid(mid);
|
||||
|
||||
ASSERT_TRUE(store.begin(64));
|
||||
ASSERT_TRUE(store.write(0, data, sizeof(data)));
|
||||
EXPECT_TRUE(stream.request_valid);
|
||||
EXPECT_EQ(stream.operations,
|
||||
(std::vector<uint8_t>{MS_OP_BEGIN, MS_OP_WRITE}));
|
||||
EXPECT_EQ(stream.flush_calls, 0U);
|
||||
}
|
||||
|
||||
// Build a flashed-image layout (body || fixed 56-byte EndF) the way the host packager / build hook do:
|
||||
// marker(4) body_len(4) body_hash8(8) fw_version(4) target_id(4) hw_id(32). Identity is always present
|
||||
// (zero/"" = unknown).
|
||||
|
||||
@@ -458,6 +458,10 @@ TEST(ClockSyncPathPolicy, EdgeModeAllowsOnePath) {
|
||||
EXPECT_FALSE(mesh::clockSyncRequiresUniquePath(true));
|
||||
}
|
||||
|
||||
TEST(ClockSyncDefaults, DriftCorrectionThresholdIsTenMinutes) {
|
||||
EXPECT_EQ(600U, mesh::CLOCK_SYNC_DRIFT_DEFAULT_SECONDS);
|
||||
}
|
||||
|
||||
TEST(MeshReceiveHooks, GroupPacketIsObservedWhenForwardingIsDisabled) {
|
||||
TraceTestClock clock;
|
||||
TraceTestRTC rtc;
|
||||
|
||||
Reference in new issue
Block a user