Commit Graph
351 Commits
Author SHA1 Message Date
liquidraver 6861822127 route zephcore_rtc_save() through the deferred-to-main-thread mechanism 2026-06-08 09:01:18 +02:00
liquidraver 2ad185bab4 license "refactor" :) 2026-06-07 22:47:17 +02:00
liquidraver 2cf4b9704e BT DFU fixes + power bump up 2026-06-07 22:33:50 +02:00
liquidraver 7c46f4a343 legacy code cleanup 2026-06-07 13:02:07 +02:00
liquidraver 4fc20de854 legacy dfu hard dep to nrf52 2026-06-07 12:54:37 +02:00
liquidraver 37edf303a2 fix MAX_ANON_CONTACTS 2026-06-07 12:51:31 +02:00
liquidraver 01fd56a573 wire up RTC to out-of-the-box capable nodes 2026-06-07 12:00:05 +02:00
liquidraver 9ef6774d6a add legacy nordic DFU service 2026-06-06 23:55:15 +02:00
liquidraver ffe9ea652d sync to vanilla 1.16 v20260606.150211 2026-06-06 16:42:39 +02:00
liquidraver 4353936328 lr2021 experiments 2026-06-06 15:33:37 +02:00
liquidraver d13d6f4621 version to 1.15.9 v20260605.132226 2026-06-05 14:59:12 +02:00
liquidraver f508c14dbb display improvements 2026-06-05 14:56:11 +02:00
liquidraver 28a8a6999d nrf companion auto-shutdown 2026-06-05 09:27:24 +02:00
liquidraver eda46166b4 companion CLI 2026-06-04 22:43:01 +02:00
liquidraver d3ebb2f172 adc tuning improvements 2026-06-04 13:30:51 +02:00
liquidraver e052f3d231 sync with upstream dev 2026-06-03 22:01:23 +02:00
liquidraver 136bfd5c85 fix battery curve not compiling v20260603.123327 2026-06-03 14:06:00 +02:00
liquidraver 743076b850 bump some magic numbers 2026-06-03 14:02:46 +02:00
liquidraver a77e877ad8 linux native Pi fixes 2026-06-03 13:48:54 +02:00
liquidraver d37b401033 battery: centralized LiPo OCV curve + ADC multiplier corrections
Add a board-aware battery SOC system replacing the two independent
linear approximations that existed in the UI helpers.

New helpers/battery_curve.{h,c}: a 21-point (5% step) OCV lookup table
with integer linear interpolation. The default generic LiPo curve is a
weak symbol — any board can override it by dropping a battery_curve.c
into its board directory. CMakeLists.txt selects the board-specific file
when present, falling back to the generic.

Board.h gains getBattPercent() (default 0); ZephyrBoard implements it
via battery_curve_lookup().

Board-specific curves added for boards with measured cell data:
t1000_e, rak_wismesh_tag, thinknode_m6, sensecap_solar, wio_tracker_l1.

ADC multiplier corrections applied across all nRF52840 boards:
- Boards using a correctly-derived 3600×ratio formula get +0.5% to
  compensate for nRF SAADC gain error (7200→7236, 6300→6332, etc.)
- rak_wismesh_tag, rak3401_1watt, gat562_30s had multipliers copied
  from Arduino's 3.0V AREF formula; corrected to 3600×1.73×1.005=6259
- xiao_nrf52840 (10911) left unchanged — empirically calibrated value
  above the theoretical, assumed already correct for that hardware

get adc.multiplier now reports current mV reading and the board's
curve 100% target, making field calibration self-guiding.
2026-06-03 13:21:06 +02:00
liquidraver 8761a82d93 fix USB protocol handling and bump version v20260603.083228 2026-06-03 10:09:43 +02:00
liquidraver 876e818b00 cleanup repeat function in room servers more v20260603.055722 2026-06-03 07:33:20 +02:00
liquidraver ad4c28cdb0 unbreak build #1 2026-06-03 07:25:24 +02:00
liquidraver a45eace01c Merge pull request #26 from rlwilliamson-dev/room-server
room-server: drop repeater forwarding, neighbour tracking and discovery
2026-06-03 07:14:46 +02:00
rlwilliamson-dev f3da3f7cee room-server: drop repeater forwarding, neighbour tracking and discovery
A room server is an endpoint, not a repeater. Strip the repeater
machinery the role inherited from the RepeaterMesh clone:

- allowPacketForward() returns false unconditionally — never relays
  transit traffic. (Upstream's simple_room_server gates this on
  disable_fwd; hard-off here since the role should never repeat.)
- neighbour tracking: NeighbourInfo/neighbours[], putNeighbour,
  onAdvertRecv, removeNeighbor; formatNeighborsReply -> "not supported"
- node discovery: onControlDataRecv, sendNodeDiscoverReq, the
  discover.neighbors CLI, discover rate-limiter + pending state
- loop detection: isLooped + max_loop_* tables + loop_detect pref
- dead code: RepeaterStats struct, GET_NEIGHBOURS handler, simple_sort

-344 lines net. Builds clean (FLASH 30.7% / RAM 32.2%); login, post,
push/sync, read-only guest and admin remote-management all
hardware-verified on the GAT562 kit.
2026-06-02 18:19:22 -05:00
liquidraver 9ffb3802bf Merge pull request #25 from rlwilliamson-dev/room-server
app: add Room Server (BBS) role
2026-06-02 23:05:25 +02:00
liquidraver 209f74411c fix linux repeater build 2026-06-02 22:56:32 +02:00
rlwilliamson-dev 79afecf11b docs: document the Room Server role
- README: add Room Server to "Device Roles" + a build command in "Building"
- ARCHITECTURE.md: role list two -> four (add Room Server + the
  previously-undocumented Observer)
- Repeater_CLI_commands.md: note the room server shares this CLI
- boards/example_board/README.md: add the room_server.conf build snippet
2026-06-02 15:53:27 -05:00
rlwilliamson-dev 05fce66b16 room-server: drop dead anon-request handlers inherited from the clone
The room server's onAnonDataRecv handles login inline (the room login
protocol carries a sync_since cursor the repeater's doesn't), so the
cloned repeater helpers handleLoginReq + handleAnonRegionsReq /
handleAnonOwnerReq / handleAnonClockReq — and the anon_limiter they used
— were dead after the port. Remove them (~160 lines). No behavior change.

The inherited neighbor-tracking / node-discovery machinery is also unused
on a room server; left in place for now (can be trimmed in a follow-up).
2026-06-02 15:43:29 -05:00
rlwilliamson-dev fcd5fd8641 room-server: fix login when a password is set over a longer one
StrHelper::strncpy null-terminates but does NOT zero-pad the 16-byte
password buffer, so setting a shorter password over a longer previous
value (e.g. one inherited from a prior repeater config) leaves trailing
garbage. onAnonDataRecv's constant-time compare runs over the full
buffer width, so a correct password stopped matching — admin/guest
logins were silently rejected, or downgraded to a read-only guest when
allow_read_only was on (the login looked identical to read-only).

Fix: copy both stored passwords into zeroed buffers (up to strnlen)
before the constant-time compare, so the comparison reflects the actual
string while staying constant-time over the full width.

Hardware-verified on the kit: admin login with the correct password now
grants ADMIN (post + remote management), confirmed server-side via
get acl (perms 03).

Note: the repeater's handleLoginReq shares this latent issue.
2026-06-02 15:07:50 -05:00
liquidraver b06239f84f build linux executables too 2026-06-02 21:30:24 +02:00
liquidraver 9f7029abaa GAT562 cleanup + gps
Cleanups 1–3 (cosmetic):

Removed the dead uart1_default/uart1_sleep pinctrl groups + stale "GPS on UART1" comments → gat562_30s-pinctrl.dtsi
Removed the QSPI pinctrl groups (board has no QSPI; pins collide with the joystick) and replaced them with a comment explaining why
Untangled the GPS UART0-vs-async rationale in the DTS and the &uart1 comment
GPS driver switch (functional, you approved the full switch) → gat562_30s.dts, board.conf:

gnss-nmea-generic → luatos,air530z with on-off-gpios = <&gpio1 2 GPIO_ACTIVE_HIGH> (matches the sibling rak_wismesh_tag, same AT6558R chip)
Deleted the always-on gps_power_en gpio-hog (the driver owns P1.02 now → GPS can be powered down)
Removed the CONFIG_UART_ASYNC_API=y override
Updated all related comments
2026-06-02 21:22:55 +02:00
rlwilliamson-dev 58dbba7f3b room-server: drive push engine on a timer + cut delivery latency
Two hardware-found fixes after on-air testing on the GAT562 kit:

- Add a 500ms push timer in main_room_server.cpp so the post-sync
  engine advances at its intended cadence. ZephCore is event-driven
  (no Arduino superloop), so without this the engine only ran on the
  5s housekeeping tick — posts dripped out every ~5s and transmits
  bunched up, causing timeouts/resends.

- Lower the post-sync hold from upstream's conservative defaults
  (POST_SYNC_DELAY 6s -> 2s, PUSH_NOTIFY 2000ms -> 1000ms). These are
  server-side timing only (no wire-format change), and take measured
  delivery from ~6-7s down to ~2s.

Verified on hardware (910.525/62.5/SF7/CR8, two clients): normal-pace
messages deliver in ~2s with clean ACKs. Rapid-fire bursts can still
drop out-of-order messages via the per-client timestamp replay check
(unchanged from upstream) — left as-is to stay upstream-compatible.
2026-06-02 14:12:08 -05:00
liquidraver f0baeae892 Merge pull request #24 from rlwilliamson-dev/board/gat562-30s
boards: add GAT562 30S Mesh Kit (nRF52840, RAK4631 core)
2026-06-02 21:02:13 +02:00
rlwilliamson-dev bb6d9c60e1 app: add Room Server (BBS) role
Add the MeshCore Room Server role to ZephCore — a store-and-forward
shared message room. Clients log in with an admin or guest password
and post messages; the server pushes each new post to all other
logged-in clients (round-robin, per-client sync cursor, ACK + retry,
3-strike eviction).

Ported from upstream MeshCore's simple_room_server, structured as a
near-clone of RepeaterMesh so it reuses the proven ACL, region
filtering, CLI, adverts and telemetry; the post buffer + push engine
are the only net-new pieces:
- RoomServerMesh: PostInfo ring (MAX_UNSYNCED_POSTS=32), addPost,
  pushPostToClient, getUnsyncedCount, processAck, onAckRecv, the
  loop() push driver; room login (onAnonDataRecv parses the
  sync_since cursor); posts/admin-CLI/keep-alive (onPeerDataRecv);
  ADV_TYPE_ROOM advert; ServerStats wire layout; disable_fwd=1.
- main_room_server.cpp: event-loop entry (USB serial CLI, no BLE).
- Kconfig: ZEPHCORE_ROLE_ROOM_SERVER + ZEPHCORE_MAX_UNSYNCED_POSTS.
- CMakeLists role gating; boards/common/room_server.conf.

Post frame, SHA-256 ACK and login-reply layouts match upstream for
MeshCore app compatibility. Builds for gat562_30s
(FLASH 30.95% / RAM 32.46%). Not yet hardware-tested.
2026-06-02 13:02:57 -05:00
rlwilliamson-dev 568d311ab0 boards: add GAT562 30S Mesh Kit (nRF52840, RAK4631 core)
The GAT562 30S Mesh Kit is an nRF52840 + SX1262 board built on the
RAK4631 WisBlock core module with a 30 dBm (1 W) external PA, so it
reuses the proven rak4631 LoRa path. Deltas vs rak4631: 1.8 V TCXO
(per the MeshCore variant), battery multiplier 6232, buzzer on P1.01,
an AT6558R UART GPS, active-high LEDs, and a 5-way joystick that
selects the joystick companion menu UI.

A single board serves both the full kit and the screenless solar
repeater pod; absent peripherals (OLED, GPS, joystick, buzzer) are
optional in devicetree and skipped at runtime.

Board-specific notes:
- GPS: AT6558R NMEA on UART0 @ 9600 (P0.15 RX / P0.16 TX), powered by a
  WB_IO2/P1.02 gpio-hog and parsed by gnss-nmea-generic. Uses
  CONFIG_UART_ASYNC_API (DMA receive); nRF UARTE interrupt-driven RX did
  not feed the modem backend.
- The 6 button/joystick inputs are routed to GPIO SENSE (sense-edge-mask
  on &gpio0) so they don't consume the GPIOTE channel the SX1262 DIO1
  "done" IRQ needs.

Registration: board definition, CMakeLists.txt platform-conf match,
build.sh (nRF_boards), supported_boards.md, the top-level README board
table, and the porting-guide board table.

Hardware-tested on the kit, companion and repeater: LoRa TX/RX with BLE
active (no CAD errors), BLE pairing (PIN 123456) and two-way messaging,
joystick menu UI, SSD1306 OLED, buzzer, battery %, UF2 + DFU-zip
flashing, and a 14-satellite GPS fix.
2026-06-02 11:28:44 -05:00
liquidraver 3c94b83f70 linux native fixup #3 2026-06-02 16:08:51 +02:00
liquidraver eb4e6583c7 linux native fixup #2 2026-06-02 14:50:31 +02:00
liquidraver 99e05e3b03 sync with vanilla dev 2026-06-02 14:50:18 +02:00
liquidraver fac4716ee1 counter zombie packets with header_error check 2026-06-02 13:21:46 +02:00
liquidraver eded1d7f04 linux native fixup #1 2026-06-01 22:29:53 +02:00
liquidraver 09074d8852 refactor(crypto): replace orlp/ed25519 with Monocypher 4.0.2
Swap the vendored orlp/ed25519 (frozen ~2017 ref10) for Monocypher
4.0.2, an actively maintained, audited, single-file implementation.

The persisted private key keeps its 64-byte expanded layout
(clamped SHA-512(seed) scalar a || nonce prefix), so identities
written by older firmware load, sign, verify and key-exchange
unchanged -- no re-key, no storage migration, full wire
compatibility with the existing mesh and Arduino MeshCore.

Because the stored key carries no seed for Monocypher's high-level
EdDSA API, Identity drives signing from the low-level primitives
(crypto_sha512 + crypto_eddsa_reduce/scalarbase/mul_add); verify
uses crypto_ed25519_check and ECDH uses crypto_eddsa_to_x25519 +
crypto_x25519. Nonce material is now wiped after signing.

Validated byte-for-byte against the previous orlp output via a
known-answer harness (keygen, sign-from-expanded-key, verify
accept/reject, X25519-over-Ed25519 shared secret) before the swap.

Frees ~42 KB of flash: orlp linked ~55 KB (dominated by its ~30 KB
ref10 precomputed tables); the Monocypher Ed25519/X25519/SHA-512
paths link ~14 KB, with --gc-sections dropping all unused algos.
wio_tracker_l1 pristine build: FLASH 54.14%, links clean.

Monocypher is CC0-1.0 OR BSD-2-Clause.
2026-05-31 22:07:43 +02:00
liquidraver 2545f0220c bump west 2026-05-31 20:51:59 +02:00
liquidraver e445e97fc3 fix(usb): release the interface on VBUS removal
A device-side cable yank often skips the DTR=0 line-state change, so the
companion stayed stuck on the USB interface and rejected every BLE
connection until reboot. Treat USBD_MSG_VBUS_REMOVED as a DTR drop.
2026-05-31 15:36:46 +02:00
liquidraver ec982ca15f fix(dispatcher): wake the loop for zero-delay sends
Companion BLE/USB direct & zero-hop sends enqueue with delay 0 from
sysworkq, off the main loop. Since 57b971f dropped the per-frame RX
wake, fire the tx-queued callback for delay 0 too so they actually
drain (USB companion has no tx-idle backstop and would stall).
2026-05-31 15:36:41 +02:00
liquidraver ab89cdd6d4 fix(ui): resolve channel by name for the Unread-screen reply
Channel replies from the Unread screen passed index -1, which
sendComposedMessage can't route, so they silently failed to send. Look
up the real channel slot by name and bail if it can't be resolved.
2026-05-31 15:36:35 +02:00
liquidraver 65b5371a65 fix(repeater): flood anon reply when the return path is rejected
The three anon handlers ignored copyPath's return value: on a rejected
(over-long) path, reply_path_len kept the attacker byte while reply_path
stayed stale, so the reply went out with a corrupt direct path. Reset to
OUT_PATH_UNKNOWN so it floods instead; keep the legit zero-length case.
2026-05-31 15:36:31 +02:00
liquidraver b26bd5eee4 fix(rng): hard-fail seed KDF on SHA-256 error
extract_via_aes_ctr used the void Utils::sha256, which silently zeroes
its output on PSA failure -> an all-zero AES key -> a constant,
device-shared Ed25519 identity that the degenerate check misses.
Re-inline psa_hash_compute with its status check so a failure reboots.
2026-05-31 15:36:25 +02:00
liquidraver ff705b0d5d fix: unbreak the production (CONFIG_LOG=n) build
553b71c made production the default but broke configure+link:
- ZEPHCORE_COMPANION_USB sat inside the role choice (recursive dep)
- CONFIG_RESET_ON_FATAL_ERROR was an undefined, unimplemented symbol
- USB companion sources still gated on CONFIG_LOG, not ZEPHCORE_USB_STACK

Move the USB toggle out of the choice, add a real
ZEPHCORE_RESET_ON_FATAL_ERROR Kconfig + k_sys_fatal_error_handler that
cold-reboots, and match the CMake USB guard to ZEPHCORE_USB_STACK.
2026-05-31 15:36:10 +02:00
liquidraver 553b71c44a Make production the default build; decouple USB companion from CONFIG_LOG
Production (LOG=n, ASSERT=n, RTT=n, reboot-on-fatal) is now the prj.conf
default; debug.conf is the opt-in bundle. Removed prod.conf and the
logging.conf auto-include; relocated RTT/ASSERT out of the always-on
platform confs so they no longer override the prod defaults.

Add CONFIG_ZEPHCORE_COMPANION_USB so the USB CDC companion transport
compiles independently of logging (default-y on USB-capable companions,
opt-in on ESP32-S3 via esp32s3_usb.conf). Gate all USB sites behind one
ZEPHCORE_USB_STACK macro.

Rework BLE/USB interface arbitration to first-come-first-served: neither
transport evicts a live session. Make active_iface mutation thread-safe
(mutex + atomic claim) across the BLE callback thread and USB workqueue.

Share the ESP32-S3 USB OTG / console DTS via common dtsi includes; enable
uart0 (GPIO43/44) on station_g2 and xiao so the console reroute works.
2026-05-30 21:05:42 +02:00