Commit Graph
3365 Commits
Author SHA1 Message Date
Jason Huebert 2ebf23ae7b test(repeater): native unit tests for the battery gate
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.
2026-10-05 10:46:04 +00:00
Jason Huebert 1b76abae16 feat(repeater): battery gate to suspend repeating below configurable voltage
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.
2026-10-05 10:46:04 +00:00
Jason Huebert 41e9eb9500 test(repeater): native unit tests for the packet filter
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.
2026-10-05 10:46:04 +00:00
Jason Huebert 7cb14a456c fix(repeater): packet filter interval and config-load bugs
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.
2026-10-05 10:46:04 +00:00
Jason Huebert d00bfdc2fd feat(repeater): region= rule predicate for the packet filter
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.
2026-10-05 10:46:04 +00:00
Jason Huebert f5e272e114 docs: use generic bot names in FILTER.md examples 2026-10-05 10:46:04 +00:00
Jason Huebert a2696d746a docs: rewrite FILTER.md as user guide and reference
Drop implementation details (fork file layout, hook points, engine
internals, build-time constant names) and reorganize around what a
repeater operator needs: rule model, CLI reference, walkthroughs,
remote admin, and behaviour notes.
2026-10-05 10:46:04 +00:00
Jason Huebert b66028aa91 sync-upstream: run weekly instead of daily
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.
2026-10-05 10:46:04 +00:00
Jason Huebert c3e136ac0c filter-build: use target_commitish input for gh-release
'commitish' is not a valid input for softprops/action-gh-release; the
correct name is target_commitish.
2026-10-05 10:46:04 +00:00
Jason Huebert 2f1a9a06f0 sync-upstream: check out dev explicitly from origin
Adding the upstream remote makes 'git checkout dev' ambiguous between
origin/dev and upstream/dev; track origin/dev explicitly.
2026-10-05 10:46:04 +00:00
Jason Huebert 7ef7a1a526 Add CI workflows for filter firmware builds and upstream sync
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.
2026-10-05 10:46:04 +00:00
Jason Huebert 64a2e92850 simple_repeater: filter code cleanups
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.
2026-10-05 10:46:04 +00:00
Jason Huebert 40373f372e simple_repeater: enter filter channel PSKs as hex instead of base64
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.
2026-10-05 10:46:04 +00:00
Jason Huebert 3aa4d48ee5 simple_repeater: sample advert cache key from pubkey middle bytes
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.
2026-10-05 10:46:04 +00:00
Jason Huebert 3976cc5087 simple_repeater: shrink filter RAM (advert prefix, channel hash)
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.
2026-10-05 10:46:04 +00:00
Jason Huebert f123701d7e simple_repeater: double keyed channel store to 16 entries
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.
2026-10-05 10:46:04 +00:00
Jason Huebert e6cb14f9b2 simple_repeater: fix TinyRegex matching of bytes >= 0x80
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.
2026-10-05 10:46:04 +00:00
Jason Huebert 8ec7457bd1 simple_repeater: keep stats out of the filter config file
/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.
2026-10-05 10:46:04 +00:00
Jason Huebert a017721981 Add FILTER.md: documentation for the repeater packet filter
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.
2026-10-05 10:46:04 +00:00
Jason Huebert 600e92563a simple_repeater: remap filter rule channel masks on channel delete
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'.
2026-10-05 10:46:04 +00:00
Jason Huebert 7122eafc66 simple_repeater: reject interval endpoints above int16 range
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.
2026-10-05 10:46:04 +00:00
Jason Huebert 2e296c11c0 simple_repeater: add remote-configurable packet filter (fork feature)
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/.
2026-10-05 10:46:04 +00:00
Liam Cottle a366955cb2 Merge pull request #3528 from liamcottle/docs/radio-presets
Add documentation for radio presets
2026-09-30 14:56:20 +13:00
liamcottle a11009f2df add radio preset docs 2026-09-30 14:52:58 +13:00
Liam Cottle e94125987e Merge pull request #3445 from mojoaxel/patch-1
docs: fix frame format tables
2026-09-20 10:26:16 +12:00
Alexander Wunschik 448d1b2239 docs: fix frame format tables 2026-09-18 16:59:26 +02:00
Liam Cottle 0679dbeffc Merge pull request #3282 from recrof/patch-3
FAQ: Fixed instructions on wiping and resetting nrf52 devices
2026-08-24 19:49:40 +12:00
Rastislav Vysoky acac4af3ec FAQ: Fixed instructions on wiping and resetting nrf52 devices 2026-08-23 20:13:12 +02:00
Scott Powell d929643524 * version 1.17.1 companion-v1.17.1 room-server-v1.17.1 repeater-v1.17.1 2026-08-14 22:19:19 +10:00
Huw Duddy 24bdc24b39 Merge pull request #3206 from meshcore-dev/nrf-combine-rng-entropy
combine radio's entropy with CC310 RNG
2026-08-14 22:09:26 +10:00
Scott Powell fcb9bdf209 * combine radio's entropy with CC310 RNG 2026-08-14 17:46:43 +10:00
Huw Duddy 50a51a6479 Merge pull request #3203 from meshcore-dev/companion-fem-pref-fix
commenting out the load/save of the fem_ properties
2026-08-14 16:44:59 +10:00
Scott Powell e78bff0041 * unit test no longer valid 2026-08-14 16:42:54 +10:00
Scott Powell 890a2e2cff * commenting out the load/save of the fem_ properties, until they can be set 2026-08-14 16:30:12 +10:00
ripplebiz b09cb27a1f Merge pull request #3106 from ViezeVingertjes/fix/scoped-reply-routing
Fix replies dropped when flood.max.unscoped is low
2026-08-13 15:00:37 +10:00
ripplebiz abd3546d75 Merge pull request #3189 from oltaco/nrf52-unused-pin-sweep
Fix unused pin definitions on some NRF52 boards
2026-08-13 13:48:59 +10:00
taco 7cd1d207af Fix LilyGo T-Echo Lite SPI pins 2026-08-13 00:53:58 +10:00
taco c2a4ef082f Fix Heltec MeshPocket SPI pins 2026-08-13 00:15:34 +10:00
taco 3ea541f1f2 Fix Heltec T1 pin definitions
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.
2026-08-13 00:12:37 +10:00
ripplebiz e9edfc8e1a Merge pull request #3188 from oltaco/heltec-t096-pin-fix
Fix Heltec T096 Tx issue
2026-08-12 23:00:31 +10:00
taco 49d9f9a839 Heltec T096: fix PIN_SPI1_MISO
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.
2026-08-12 22:31:57 +10:00
taco f43e1cde89 Revert "t096 compiler layout workaround"
This reverts commit 9c60f9696e.
2026-08-12 22:28:36 +10:00
taco 264d778168 Revert "T096 PA_CTX pin direction workaround"
This reverts commit 82de18fb0e.
2026-08-12 22:28:05 +10:00
ripplebiz 956094b271 Merge pull request #3185 from oltaco/fix-techo-card-txco-voltage
Set T-Echo Card TCXO voltage to 3.0
2026-08-12 18:13:44 +10:00
ripplebiz a4ab7f0e59 Merge pull request #3137 from agessaman/feat/station-g3-fem-prefs
Station G3: Expose, persist, and apply FEM gain preferences
2026-08-12 16:11:23 +10:00
taco 9d6dcc673e set T-Echo Card TCXO voltage to 3.0
as per https://github.com/meshcore-dev/MeshCore/pull/3140 and https://github.com/Xinyuan-LilyGO/T-Echo-Lite/issues/14
2026-08-12 16:08:05 +10:00
ripplebiz 1cb308b694 Merge pull request #3182 from oltaco/t096-tx-workaround
Workaround for Heltec T096 transmit issue
2026-08-12 14:49:32 +10:00
taco 82de18fb0e T096 PA_CTX pin direction workaround 2026-08-12 14:07:31 +10:00
taco 9c60f9696e t096 compiler layout workaround
see https://github.com/meshcore-dev/MeshCore/issues/3151
2026-08-12 14:04:50 +10:00
ripplebiz e027263d1e Merge pull request #3154 from fdlamotte/nrf52_hwcrypto_init
nrf52: call nRFCrypto.begin()/end() only once
2026-08-12 12:14:21 +10:00