Commit Graph
56 Commits
Author SHA1 Message Date
liquidraver 14cb8c61f9 meshtimesync p1 2026-07-03 09:11:43 +02:00
liquidraver fc940d27ba sync with dev 2026-07-02 13:13:26 +02:00
liquidraver 3af781ee87 get rid of flash writes initiated by ZephyrGPSManager 2026-07-02 09:20:10 +02:00
liquidraver bd363781ac companion hybrid refactor v1 2026-06-23 22:45:25 +02:00
liquidraver 906ef08b05 3 way FS self-heal 2026-06-17 22:05:21 +02:00
liquidraver c4a1777956 refactor gps manager 2026-06-17 15:42:50 +02:00
liquidraver b4a7a4b6c1 fix mismatched guards 2026-06-15 15:29:32 +02:00
liquidraver f9bc6934b9 initial_advert_work race 2026-06-08 10:21:55 +02:00
liquidraver 7e00a6682d ble race fixes 2026-06-08 09:57:58 +02:00
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 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 2026-06-06 16:42:39 +02:00
liquidraver d13d6f4621 version to 1.15.9 2026-06-05 14:59:12 +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 8761a82d93 fix USB protocol handling and bump version 2026-06-03 10:09:43 +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
liquidraver 799d694914 crypto: simplify entropy path after audit review
- Lift duplicated identity-gen block from main_companion.cpp +
  main_repeater.cpp into ZephyrRNG::generateFirstBootIdentity().
  Both mains shrink from ~40 lines to a 3-line helper call.
- Add LocalIdentity::fromSeed() so seed-derived keygen doesn't need
  a one-shot RNG wrapper; delete SeededRNG.
- Drop the per-byte ADC sampling loop: getBattMilliVolts() does an
  8-sample average + 10ms regulator settle internally, costing
  300-480ms of real wall-time and actively destroying the LSB jitter
  it was meant to harvest. Jitter mixer already dwarfs it.
- Centralize the printk + sys_reboot pattern as
  Utils::cryptoPanicReboot(); drop the 2000ms pre-reboot k_msleep
  (printk is synchronous, sleep just blocked the mesh thread on
  the ZephyrRNG::random() retry-failure path).
- Inline sample_cpu_jitter health check via online scalars instead
  of a 512-byte deltas[] array. Saves 1.5KB stack churn across boot
  and tracks every sample instead of only the first 128.
- extract_via_aes_ctr now uses Utils::sha256 instead of open-coding
  psa_hash_compute.
2026-05-29 07:58:54 +02:00
liquidraver b692ca72ed crypto: harden all crypto-sensitive memcmp + memset sites
Audit-driven sweep found additional compiler-optimization-sensitive
patterns beyond the login password compare just fixed:

P4.F3 (HIGH) — Utils::MACThenDecrypt verified packet MACs with
plain memcmp. Runs on EVERY encrypted-then-MAC'd packet in the
mesh; a timing oracle here lets attackers forge MACs byte-by-byte
across the whole mesh layer. Replaced with constantTimeEqual.

P4.F4 (MEDIUM) — Multiple memset(secret, 0, ...) calls on
stack-resident crypto buffers (Ed25519 seed, ADC noise pool, AES
key derived in extract_via_aes_ctr, HWINFO unique ID) were
subject to dead-store elimination under -Os. GCC/Clang routinely
elide these when the buffer is never read after; the wipe vanishes
and the secret persists on stack until next call overwrites.
Replaced with secureZeroize using volatile pointer writes.

P4.F5 (LOW) — Identity::validatePrivateKey boot self-test compared
shared secrets with plain memcmp. Boot-only, no attacker
observation channel, but hygiene matters and the fix is one line.
Also added secret-wipe for ss1/ss2 on all return paths.

Promoted the local ct_memeq() previously added to RepeaterMesh.cpp
into Utils::constantTimeEqual + Utils::secureZeroize (Utils.h/cpp)
so the login compare and MAC compare share the same audited helper.

Both helpers verified by Thumb-2 disassembly on rak3401_1watt:
- constantTimeEqual: loop branches on iterator, accumulator
  load-modify-stored to stack every iteration, final return uses
  CLZ+LSR (no conditional branch on result).
- secureZeroize: STRB.W to memory in a counted loop, not replaced
  with memset builtin and not eliminated.
2026-05-28 13:26:20 +02:00
liquidraver 515f3610e1 crypto: harden first-boot identity entropy + 3 RNG fixes
Adds a layered entropy mixer for first-boot identity Ed25519 keygen,
primarily to address ESP32 where the hardware TRNG (WDEV_RND_REG) is
only fed real entropy once the internal WiFi/BT radio is enabled —
but identity gen runs before that on companion and indefinitely
before that on a bare repeater. ESP-IDF's bootloader_random_enable()
is not compiled by Zephyr-Espressif HAL, ruling out that workaround.
Design reviewed with nextgens (author of upstream meshcore-dev/
MeshCore#2280 which fixes the same issue via BT/WiFi init/pull/deinit).

ZephyrRNG::random — retry sys_csrand_get up to 4x with k_msleep
backoff; cold-reboot on persistent failure. Previously fell back
silently to sys_rand_get (xoshiro PRNG), which would have produced
a weak Ed25519 seed on CSPRNG error. BUILD_ASSERT enforces
CONFIG_CSPRNG_ENABLED.

ZephyrRNG::mixIdentitySeed — layered entropy mixer for one-shot
identity keygen. Combines sys_csrand_get (early + late),
HWINFO unique device ID, caller-supplied ADC LSB noise, 200ms of
CPU cycle-counter jitter (NIST SP 800-90B class source), and
50ms more jitter in an independent timing window. Conditioned via
AES-256-CTR (NIST SP 800-108 KDF-in-Counter-Mode): SHA-256 of the
pool extracts a 32-byte AES key; AES-256-ECB on an incrementing
128-bit counter expands to the requested output length. Uses PSA
crypto already enabled in zephcore_common.conf. NIST-style
repetition-count + variance health check on jitter samples;
reboot on degenerate output. ~280ms one-time cost at first boot.
LoRa radio TRNG was considered as an additional source but rejected
on expert advice — radio sources are attacker-influenceable
(jamming/spoofing).

ui-joystick BLE passkey — switch from sys_rand32_get (non-crypto
xoshiro) to sys_csrand_get. The 6-digit passkey is the MITM
protection the rest of the BLE config enforces; predictable PINs
weaken it.

Identity reserved-prefix loop — replace the silent 10-attempt cap
(which committed whatever it had on fall-through) with a
bounded-retry-then-reboot pattern.

Also: fix a pre-existing scope bug at main_companion.cpp:357 in
the MESH_EVENT_PREFS_DIRTY handler — data_store was referenced
inside mesh_event_loop() but declared 50+ lines later. Moved the
call into a forward-declared helper defined after the statics.
Unrelated to crypto work but uncovered during build verification;
every companion build was broken.
2026-05-28 09:34:43 +02:00
liquidraver 57b971fc2c remove redundant main thread wakeups 2026-05-27 09:46:48 +02:00
liquidraver f06c472e87 usb: unify companion + repeater CDC ACM init, drop boot waits
Single ZephyrUSBCDC module owns the usbd context, 1200-baud DFU
detection, and DTR transitions for both roles. The boot banner
now blocks on a k_event signalled by the usbd_msg_callback when
DTR transitions high — host attached → wakes immediately; no host
→ bounded timeout (2 s repeater, 1 s companion). Replaces the
fixed k_sleep delays in both mains.

Deletes the companion's 10 s DTR-polling work — line state changes
arrive as events now, same callback handles disconnect (resets V3
parser, flips active_iface) and DFU touch (reboots to bootloader).

Side effect: prod companion no longer enumerates a phantom CDC ACM
port (CONFIG_LOG=n skips the whole stack instead of auto-initing
an unused device).
2026-05-27 09:04:32 +02:00
liquidraver 051adef93e native linux initial commit 2026-05-24 20:06:49 +02:00
liquidraver 322460fa78 joystick UI:
make UI show actual time source
2026-05-22 11:29:25 +02:00
liquidraver 07efffc417 zephcore_ble_is_enabled → zephcore_ble_is_enabled().
The watchdog now actually honors the disabled state instead of re-enabling BLE on every housekeeping tick.
2026-05-21 21:46:49 +02:00
Steve Calvário 5caf53a496 Add GPS altitude support, add channel “reply to” targeting, fix snake wall collisions, fix unread navigation incorrectly returning to home, and fix BLE continuing to advertise after being disabled 2026-05-21 17:09:13 +01:00
liquidraver 597daee6c3 Merge Calvario/ZephCore ui_joystick into joysticktest
# Conflicts:
#	zephcore/helpers/ui-button/ui_task.c
2026-05-20 22:14:35 +02:00
liquidraver 3a35fec8b3 ui: make housekeeping refresh path on-demand
Stop doing UI work nobody asked for. The 5 s housekeeping tick was
reading env sensors (I2C, 10-50 ms), the battery ADC (regulator
toggle + 8 samples, every 60 s), and re-rendering the display
unconditionally — all while the display might be off and nothing
on-air had requested any of it.

Now:
- render_sensors() reads env sensors only when the user is on
  that page (event-driven, never fires during idle)
- battery refresh is lazy on ui_pages_render() with a 30 s
  freshness guard; explicit ui_set_battery() calls also count
- the unconditional OLED rerender from housekeeping is gone;
  real state changes (messages, BLE, button press) still fire
  schedule_render() directly

Telemetry / stats paths read fresh ADC + sensors on demand and
were never using the UI cache, so over-the-air consumers are
unaffected.
2026-05-20 22:10:14 +02:00
Steve Calvário 56b10f70a1 Init 2026-05-20 20:40:58 +01:00
liquidraver d7e420bf2f fix(ble,usb): three bugs from BLE audit
1. USB takeover opcode mismatch
   ZephyrCompanionUSB.cpp checked payload[0] == 0x03 with a comment
   claiming CMD_APP_START, but CMD_APP_START is 0x01 (0x03 is
   CMD_SEND_CHANNEL_TXT_MSG). The USB handshake silently dropped the
   companion app's first frame on every connection; the app appeared
   broken over USB until the user happened to send a channel message.

2. CMD_SET_ADVERT_NAME didn't propagate to BLE adv data
   Name changes were persisted to prefs but the advertising payload
   and GATT device name kept the old value until reboot. Added
   zephcore_ble_update_name() and called it from the handler.

3. No advertising-health watchdog
   If bt_le_adv_start() ever failed transiently (HCI timeout,
   controller pacing), the device would silently stop advertising
   and stay undiscoverable until reboot. Added an adv_running flag
   and a 5s watchdog in the companion housekeeping handler that
   nudges adv back on if it stops outside a connection. Tracks
   Arduino nrf52's equivalent 10s watchdog.
2026-05-20 11:09:45 +02:00
liquidraver 6bc3ba7405 disable default duty cycling + SX driver fixes 2026-05-05 21:56:00 +02:00
liquidraver b84830b3b3 (greatly) improve our BLE 2026-04-29 12:09:21 +02:00
liquidraver 1092c49a7d port vanilla duty cycling logic 2026-04-28 14:43:12 +02:00
liquidraver d03deda313 port adc.multiplier command 2026-04-22 10:49:41 +02:00
liquidraver d2cec84100 sync with vanilla dev 2026-04-17 13:21:30 +02:00
Rastislav Vysoky da22b127c3 sx1276 2026-04-07 19:05:32 +02:00
liquidraver c9013d85d4 update zephyr 2026-03-23 08:56:21 +01:00
liquidraver 0bf8bd72a3 promicro LR2021 build fix 2026-03-16 19:49:53 +01:00
liquidraver eb5149fd0f fix BLE advert name for backwards compatibility 2026-03-16 11:49:12 +01:00
liquidraver 2584e237f6 led switcher page in ui
rx duty cycle + noise floor measurement marriage
ui fixes
2026-03-06 22:15:13 +01:00
liquidraver 1f48735ae6 includes cleanup 2026-03-06 14:21:22 +01:00
liquidraver d949ca4f6e fix: buffer overflow, OOB read, packet leaks, BLE sign leak, USB timeout, atomics, fs_read checks
- RegionMap::findMatch(): fix 1-byte stack overflow in tmp[] with bounded memcpy
- Packet::readFrom(): add bounds checks before reading transport codes
- Mesh::sendFlood(): release packet on TRACE type and invalid hash_size early returns
- CompanionMesh: add cleanupSignState() called from BLE disconnect to free sign buffer
- ZephyrCompanionUSB: add 2s timeout for partial V3 frames to prevent parser stall
- ui_mesh_actions: replace volatile bool with Zephyr atomic_t for cross-thread state
- CommonCLI: wrap ~40 fs_read() calls in prefs_read() helper with truncation warning
2026-03-04 22:12:13 +01:00
liquidraver a4e96fa6e6 separate main events from housekeeping ones 2026-03-04 21:08:21 +01:00
liquidraver 57d8cf1c46 ditch arduino's hacky-hacky FS, back to zephyr native
mg24 fix
dfu zip generation fix
2026-03-03 13:46:48 +01:00
liquidraver b62214ad3e offline queue bump, lossless message sync via ble 2026-02-28 21:49:58 +01:00
liquidraver bb5aca423c refactor storage, got rid of packet loss on lr1110 2026-02-27 22:41:16 +01:00
liquidraver 225b59e0e5 rx duty cycle rework 2026-02-27 08:51:39 +01:00
liquidraver ced260c8c3 t1000 fixes 2026-02-26 14:34:18 +01:00