googletest suite covering hysteresis (boundary-inclusive), the two-reading
debounce, 30 s sampling cadence, CLI parsing and rejections, /batt_cfg
persistence (roundtrip, missing/truncated/corrupted file, suspended flag
not persisted, lazy-save timing), and the RAM-only drop counter. New
[env:native_battery_gate] env mirrors native_packet_filter, reusing its
NativeShim.h; voltages are injected via a MockBoard.
The repeater otherwise repeats until the battery dies, leaving the node
dark. Add a fork-owned BatteryGate (examples/simple_repeater/BatteryGate.*)
that samples the battery every 30 s from MyMesh::loop() and suspends all
forwarding while the voltage is low, resuming automatically on recovery.
Hysteresis (default resume = suspend + 200 mV) plus a two-reading debounce
prevent flapping; the suspended flag is RAM-only and recomputed on boot, so
a reboot mid-suspend can never leave the repeater off after charging.
CLI replies and the node's own adverts are originated, never forwarded, so
the node stays reachable while suspended. Manual 'set off' and the packet
filter remain orthogonal.
Thresholds persist in /batt_cfg using the same lazy-dirty-save pattern as
the filter. Upstream-merge footprint is three hook lines in MyMesh.cpp plus
one member declaration; all logic lives in fork-owned files. Documented in
BATTERY.md.
109 googletest cases covering the fork-owned repeater filter code
(PacketFilter, TinyRegex): TinyRegex matching and step budget,
packet-level and content-rule matching, the advert rate limiter
(eviction, window refresh, wrap-safe timing), rule/channel management,
persistence (roundtrip, v3 upgrade, truncated/unknown configs, lazy
save), and the filter CLI surface.
Runs via a new self-contained [env:native_packet_filter] environment:
pio test -e native_packet_filter
test/test_packet_filter/NativeShim.h (force-included) provides Arduino
FILESYSTEM/File stand-ins; RegionMapStub.cpp resolves findByNamePrefix()
from a fixed table so src/helpers/RegionMap.cpp need not be linked.
-DGTEST_HAS_POSIX_RE=0 keeps glibc <regex.h> from clashing with
TinyRegex.h in the same translation units.
Two bugs found by the new native unit tests (next commit):
1. An interval predicate with both endpoints exclusive ("(a,b)", e.g.
hops=(2,4)) parsed to Interval::flags == 0, which is the "unset =
wildcard" sentinel, so the rule silently matched every packet on
that predicate. Store a FILTER_IV_SET sentinel bit for that case;
endpoint inclusivity logic and old persisted configs are unchanged.
2. FilterRules::load() reused hdr[] for the second header read, so the
version byte was lost and rule_bytes was always chosen as the v3
size: v4 configs loaded with regions wiped and every channel after
the first rule shifted 32 bytes into garbage on boot. Capture the
version byte before the buffer is reused.
Adds a packet-level `region=` predicate to the repeater filter CLI, letting
an admin drop (or logonly-shadow) traffic based on the flood region a packet
arrived in, optionally combined with any other predicate:
filter add chan=Public region=unscoped action=drop
filter add region=Foo,Bar action=drop
- region= accepts a comma list (OR within the predicate, same convention as
chan=/type=); token `unscoped` matches plain scope-less floods; names are
resolved via findByNamePrefix at add time and stored canonically, so rules
survive a region-table rebuild under the same name.
- Direct-routed packets have no region and never match a region= predicate.
- MyMesh::onRecvPacket already classifies recv_pkt_region before dispatch;
checkPacket/checkContent gain a const RegionEntry* parameter and both hook
sites pass it through. No core src/ changes.
- Config version 3 -> 4: a v3 rule record is a prefix of a v4 record, so
load() accepts v3 or v4 and migrates in place (existing rules, channels,
and ratelimit survive the upgrade with no re-entry). save() always writes
v4.
- FILTER.md: predicate rows, region-identity notes, limits row, walkthrough.
Upstream merges and the resulting firmware releases don't need to land
every day; pick up upstream changes weekly (Mon 03:30 UTC). Manual
dispatch still allows syncing sooner when something big lands.
Add two self-contained workflows for the repeater-filter fork branch:
- filter-build.yml: reusable build + release. Validates targets against
'build.sh list', builds them as a matrix via setup-build-environment,
and attaches artifacts to a release tagged with the upstream
'git describe' version plus a UTC build id and short SHA. Targets
default to the FIRMWARE_TARGETS repo variable; manual dispatch also
supported for filter-code-only changes.
- sync-upstream.yml: daily fast-forward of fork/dev from upstream dev,
merge into repeater-filter, then build+release when new upstream code
landed. Merge conflicts abort the merge, file/update an issue listing
the conflicted files, and fail the run (human resolves).
Modeled on the upstream firmware-builder workflow but not tag-gated.
Remove dead code: unused FILESYSTEM* _fs member, unused isDirty(),
redundant memset before a full-width memcpy in searchChannelsByHash().
Deduplicate: single hex-digit parser (hexVal, shared by filterDecodeHex
and parseHexHash) and consolidate the seven hand-rolled
'dirty = true; dirty_since = millis()' stamps into markDirty().
No behavior change.
Channel PSKs are shared as hex strings, so accept hex in addChannel()
and the 'filter chan add' CLI (<psk-hex>). Carries a small hex decoder
since the densaugeo/base64 lib is not in the repeater envs' lib_deps.
The Public channel PSK constant becomes its hex form (same bytes).
Saved configs are unaffected: /filter_cfg stores decoded binary secrets.
Vanity pubkeys are ground to match at the leading bytes (c0ffee,
deadbeef), and sometimes at trailing bytes, so contiguous prefix keys
collide far above random chance within a vanity club — worst case,
every repeater sharing a 4-byte vanity shares one cache entry, and the
least-frequent advertiser gets suppressed indefinitely.
Sample the 4-byte key at fixed offsets {8,14,20,26}, clear of the
vanity zones at both ends: grinded keys stay uniformly random there,
restoring ~2^-32 pairwise collision odds. No RAM change (same 8-byte
entry); the cache is RAM-only so there is no config-format impact.
Two no-loss-of-function storage reductions, -1520 B measured on all
targets (fork total 6734 -> 5214 B):
- AdvertSeenEntry pubkey prefix 6 -> 4 bytes: entry drops from 12 to
8 B (padding gone). Prefix collisions are a ~0.001% chance per 256
distinct nodes; worst case is one falsely suppressed advert per
window. The cache is RAM-only, so no config-format impact.
- FilterChannel.hash 32 -> 1 byte: core's GroupChannel.hash is
PATH_HASH_SIZE (1) and only hash[0] is ever compared or copied
(same pattern as stock BaseChatMesh); Utils::sha256 truncates to
hash_len. Saves 31 B per channel entry.
Config format comment updated to cover both v3 layout changes.
chan_mask was one bit per channel and one byte wide, capping the store at
8. Widen it to 16 bits (guard, delChannel remap arithmetic, ~128 B per
rule slot) and double FILTER_MAX_CHANNELS to 16 (+712 B RAM, verified
across nRF52/RP2040/ESP32 targets). Config format v3: older configs are
discarded on upgrade.
matchone() compared the pattern char (unsigned char) against the subject
char (signed char), so any byte >= 0x80 promoted to different values and
never matched. All multi-byte UTF-8 (emoji, accented characters) in
sender/text regex patterns silently failed to match; ASCII was unaffected.
Compare as unsigned char so literal UTF-8 sequences match byte-for-byte.
Document the byte-wise matching semantics in FILTER.md and note the
divergence in TinyRegex.h.
/filter_cfg previously stored raw FilterRule structs, which included the
per-rule hits counter: a config change saved whatever the counters were
at that moment, and a reboot restored stale counts. Persisting stats was
never intended - only configuration belongs in the file.
Rule records on disk now end at the hits field (offsetof(FilterRule,
hits)); counters and the advert cache are RAM-only and reset on reboot.
Format version bumped to 2; version-1 files are discarded on load.
FILTER.md updated to match.
Describes the rule model and evaluation phases (packet-level vs
decrypted-content), the keyed channel store, the per-origin advert rate
limiter, persistence, the full 'filter ...' CLI with predicate syntax,
use-case walkthroughs, remote administration, and behaviour notes.
delChannel() shifts the channel store down one slot, but rule chan_mask
bits were left untouched, so rules silently retargeted the wrong channels
after deleting any channel below them (and kept a dangling bit for the
deleted slot itself). Now the deleted channel's bit is dropped and masks
above the deleted slot shift down to match the store.
Found during on-device testing: a rule 'chan=#zC' became 'chan=#zB'
after deleting '#zA'.
Interval endpoints are stored as uint16 but compared via int16_t casts
(negative quarter-dB SNR shares the representation); cap non-SNR values
at 32767 so out-of-range values are rejected at 'filter add' time
instead of wrapping.
Adds a personal-fork packet filter to the simple_repeater firmware:
configurable drop/logonly rules over the repeater CLI, evaluated at
MyMesh::allowPacketForward() and onGroupDataRecv().
- PacketFilter.h/.cpp: rule model (type/route/hops/len/snr/chanhash/
path/hashsize packet-level predicates; keyed-channel, sender-regex and
text-regex content predicates evaluated on MAC-verified decrypted group
payloads), keyed channel store (Public pre-provisioned; '#' channels
auto-provisioned from sha256(name)[0..15]), per-node advert rate limiter
(RAM-only 6-byte pubkey-prefix cache), /filter_cfg persistence, and the
'filter ...' CLI (list/get/add/del/enable/disable/clear/chan/ratelimit/
stats, all replies within the 160-byte CLI buffer).
- PacketFilterConfig.h: build-time tunables (rule/channel/cache counts,
pattern lengths) with #ifndef defaults.
- TinyRegex.h/.cpp: vendored kokke/tiny-regex-c (public domain) with a
backtracking step budget; fail-open on exhaustion, aborts counted in
'filter stats'.
- MyMesh.h/.cpp: minimal hook lines only (one checkPacket call, two
virtual overrides, one CLI dispatch line, begin/loop save wiring).
All fork-owned logic lives in new files; no changes to src/.
SPI pins that are set to -1 cause OOB reads on NRF52. The unused Serial2 pin definitions were removed to avoid potential issues with the Uart framework.
Setting SPI pins to values that are OOB of the g_ADigitalPinMap[] array causes OOB reads. This variant.h has pin 0 as 0xFF which passes through as NRFX_SPIM_PIN_NOT_USED.