Add independent Companion Bluetooth stealth flag

Keep stealth separate from custom, saved-random and rotating MAC policies without migrating the development MAC mode. Persist authenticated peer state, guard advertising transitions and recovery, and expose the setting through the CLI and WebConfig.

Add regression and CI checks and record exact XIAO BLE pairing, reconnect, reboot and address-rotation hardware results.
This commit is contained in:
mikecarper committed 2026-09-07 23:46:55 -07:00
1 parent 4b400ea56b
commit 6958d82432
29 files changed
+3984 -2020

No files matched your search

+56 -1
View File
@@ -1185,7 +1185,7 @@ the frame and reply format.
**Usage:**
- `get bluetooth.mac`
- `set bluetooth.mac <address|random|random-every-boot|default>`
- `set bluetooth.mac <address|random|random-every-boot|random-after-connect|default>`
`get ble.mac` and `set ble.mac ...` are accepted aliases. The setting is
available on every Companion build that includes Bluetooth.
@@ -1195,6 +1195,7 @@ available on every Companion build that includes Bluetooth.
| `C2:11:22:33:44:55` | Save and use that custom address. |
| `random` | Generate one random address now, save it, and reuse it on later boots. |
| `random-every-boot` | Generate a new address once at each boot. `random everyboot` is also accepted. |
| `random-after-connect` | Keep one random address through unused boots. After an authenticated connection, arm a new address for the next boot. |
| `default` or `clear` | Remove the override and use the chipset's factory Bluetooth address. |
A custom value must be a valid BLE random-static address in
@@ -1207,9 +1208,63 @@ the device. Forget the old device entry and pair again. `random-every-boot`
also clears the Companion's saved peer bonds during each startup, so pairing
and PIN entry are expected again after every reboot.
`random-after-connect` keeps the same address across any number of reboots when
nobody successfully authenticated. As soon as an authenticated BLE connection
succeeds, the next boot rotates the address and clears stale bonds. The marker
is saved while connected, so a normal reboot, power switch, or battery pull
after that connection all produce the same next-boot rotation.
The address setting does not enable or disable stealth. Use the separate
`bluetooth.stealth` flag below. `default` changes only the address policy.
#### View or change Bluetooth stealth (BLE Companion)
```text
get bluetooth.stealth
set bluetooth.stealth on
set bluetooth.stealth off
```
`get ble.stealth` and `set ble.stealth on|off` are short aliases. This flag
defaults to `off` and is independent of the Bluetooth address policy. Enabling
or disabling it keeps the configured custom/random/factory address policy
unchanged and requires a reboot. Repeating `on` keeps an existing stealth
pairing; repeating `off` does not alter address settings.
For a custom address with stealth:
```text
set bluetooth.mac C2:11:22:33:44:55
set bluetooth.stealth on
reboot
```
Use `set bluetooth.mac random` instead of the first line for one saved random
address. Both combinations keep their address and bond across later boots.
Rotating policies still rotate: `random-every-boot` reopens pairing at every
boot, while `random-after-connect` reopens it on the first boot after an
authenticated connection. Stealth stays enabled; each new address begins
with a fresh pairing window so it cannot get hidden behind an unusable bond.
With stealth on, the node is normally discoverable until the first authenticated pairing.
After that, nRF52 uses directed advertising to the saved peer. ESP32 uses a
minimal unnamed advertisement and a controller allowlist because its common
Arduino BLE API does not expose the directed-advertising peer field. Both
reject connection and scan requests from other peers. BLE cannot be completely
radio silent and still accept a connection, so a passive radio sniffer may
still observe packets. To deliberately clear the saved stealth peer, send
`set bluetooth.stealth off`, then `set bluetooth.stealth on`, then reboot over
USB or an existing authenticated connection. To leave stealth, set it `off`
and reboot. If the saved node-side bond is lost, recovery reopens pairing.
The former `set bluetooth.mac stealth` command is no longer accepted.
This changes only the running MeshCore Companion application. On nRF52, the
OTAFIX bootloader still uses its own address, which is visible only while the
board is in BLE DFU/recovery mode. USB and LoRa updates are unaffected.
Bluetooth update tools must follow that separate bootloader address after the
handoff; they must not assume that a custom application address remains the
DFU address. See the [hardware observations](hardware_validation_bluetooth_stealth_2026-09-07.md)
for the tested XIAO handoff and host-cache caveats.
---
+18 -6
View File
@@ -289,7 +289,8 @@ The equivalent framed CLI commands are:
| FEM receive gain | `get radio.fem.rxgain`; `set radio.fem.rxgain on|off` |
| WiFi power save | `get wifi.powersave`; `set wifi.powersave none|min|max` |
| Bluetooth name | `get bluetooth.name`; `set bluetooth.name <name|default>` |
| Bluetooth address | `get bluetooth.mac`; `set bluetooth.mac <address|random|random-every-boot|default>` |
| Bluetooth address | `get bluetooth.mac`; `set bluetooth.mac <address|random|random-every-boot|random-after-connect|default>` |
| Bluetooth stealth | `get bluetooth.stealth`; `set bluetooth.stealth on|off` |
The framed form works over the normal binary USB, BLE, or TCP transport and
does not need the USB terminal-start token. Unsupported settings return the
@@ -328,11 +329,22 @@ custom name is limited to 31 valid UTF-8 bytes and takes effect after reboot.
Bluetooth Companion builds also accept `bluetooth.mac` (`ble.mac` is an
alias). A literal address must be a BLE random-static address; `random`
generates and saves one, `random-every-boot` rotates it at each startup, and
`default` or `clear` restores the factory address. The change takes effect
after reboot. The client must forget and re-pair the old identity. Per-boot
random mode clears local peer bonds each startup and therefore requires a new
pairing after every reboot. This is an application setting; an nRF52 OTAFIX
bootloader continues to advertise its separate DFU identity.
`random-after-connect` retains it through unused boots but rotates it on the
first boot after an authenticated connection. `default` or `clear` restores
the factory address. The change takes effect after reboot.
`bluetooth.stealth on|off` (`ble.stealth` is an alias) is a separate flag,
defaulting to off. It preserves the address policy and can be combined with
custom, saved random, rotating random, or factory addresses. With stealth on,
the node advertises normally until the first authenticated pairing, then
permits only that bonded peer to reconnect. Address changes clear the saved
peer and reopen pairing without disabling stealth. Rotating policies retain
their normal rotation triggers. Repeating `on` does not clear an existing bond.
Both flag changes require reboot. The old MAC value `stealth` is not accepted.
BLE still transmits directed or allowlisted advertisements; stealth is not
radio silence. These are application settings; an nRF52 OTAFIX bootloader
continues to advertise its separate DFU identity.
### Bluetooth LoRa mOTA source
+18 -7
View File
@@ -384,13 +384,24 @@ prefix, accept up to 31 valid UTF-8 bytes, and take effect after reboot. This
does not change the node's mesh advertisement name.
Every Bluetooth Companion also supports `get bluetooth.mac` and
`set bluetooth.mac <address|random|random-every-boot|default>`. A literal
address is a BLE random-static identity, `random` creates one persistent
identity, `random-every-boot` rotates it on startup, and `default` (or `clear`)
restores the chipset address. Reboot and re-pair after changing modes. The
per-boot mode intentionally clears local bonds and needs a new pairing after
every reboot. On nRF52 this affects the MeshCore application only, not the
OTAFIX bootloader's separate BLE DFU identity.
`set bluetooth.mac <address|random|random-every-boot|random-after-connect|default>`.
A literal address is a BLE random-static identity, `random` creates one
persistent identity, `random-every-boot` rotates it on startup, and
`random-after-connect` rotates it on the first boot after an authenticated
connection while leaving unused boots unchanged. `default` (or `clear`)
restores the chipset address. None of these values changes the stealth flag.
Reboot and re-pair after changing modes or after a rotation. Address rotation
clears stale local bonds. On nRF52 this affects the MeshCore application only,
not the OTAFIX bootloader's separate BLE DFU identity.
`get bluetooth.stealth` and `set bluetooth.stealth on|off` control an independent
flag, defaulting to off. Combine it with a custom address or `random` to retain
the address and bond across boots. With stealth on, normal discovery ends
after the first authenticated pairing and only the saved peer may reconnect.
Rotating MAC policies still rotate and reopen first pairing when they do;
stealth remains enabled. Repeating `on` keeps an existing bond. Toggle `off`,
then `on`, then reboot to reset first pairing. All flag changes need reboot.
The node still sends directed or allowlisted BLE packets; it is not radio silent.
ESP32 ports 5000, 5001, 5002, and WebConfig have no independent login layer.
Expose them only on a trusted LAN or temporary setup network. See
@@ -0,0 +1,200 @@
# XIAO Bluetooth stealth hardware validation - 2026-09-07
Historical command syntax: the initial run used stealth as a MAC mode.
Current firmware uses the independent `bluetooth.stealth on|off` flag instead
and does not migrate that development mode. See [current commands](cli_commands.md)
and the independent-flag follow-up below. Each observation applies only to
the exact artifact listed in its section.
This is a hardware observation report, not an all-board or phone qualification.
The test host was the MercerWoodMesh Raspberry Pi Zero 2 W, accessed remotely
over Tailscale. Tests used its built-in Bluetooth adapter, not USB resets or
hub power switching. Local timestamps below use America/Los_Angeles.
## Exact target and firmware
- Board: Seeed XIAO nRF52840; application name `MeshCore-4610BBD2`.
- Factory/bootloader address: `E5:C3:A8:B0:60:66`.
- Fresh stealth test address: `DC:8D:5E:45:89:6F`.
- Bonded test central: Mercer Pi, public address `B8:27:EB:F9:6E:8E`.
- Environment: `Xiao_nrf52_companion_radio_ble`, supported build wrapper,
target radio preset, default profile, GCC 14.2.1.
- Firmware: `dev-stealth3-4b400ea5`, including the uncommitted Bluetooth
identity changes on top of `4b400ea5`.
- Application ZIP SHA-256:
`acdce0af2334349c6e0a5786db5525b00d19befef340411d2e99008ce4d316ae`.
- Linked RAM: 183,232 / 237,568 bytes; flash: 616,504 / 708,608 bytes.
The application was installed with Nordic Legacy BLE DFU. The tool verified
the exact ZIP hash, bootloader advertisement and live DIS model
`XIAO nRF52840` before transmitting 616,584 application bytes. Target image
validation and target-initiated activation disconnect passed. The transfer
reported about 2,223 bytes/second (about 277 seconds for payload transmission).
Authenticated MeshCore device queries subsequently returned protocol 14,
board `Seeed Xiao-nrf52`, and the expected unique test-version prefix.
## Observed results
| Check | Result and evidence |
| --- | --- |
| First-pair discovery | `set bluetooth.mac stealth` saved a new random-static address; reboot returned that exact address with the normal name and Nordic UART advertisement. |
| First authenticated pairing | The Pi received a passkey request and completed pairing. BlueZ reported both Paired and Bonded. MITM-protected Nordic UART notifications and real command/reply exchanges worked at MTU 247. |
| Pairing transition keeps the session alive | The initial connection returned `stealth; bonded-peer-only advertising`, remained usable for five more seconds, and answered another command without disconnecting or pairing again. |
| Advertising after disconnect | A public-address passive scan captured `ADV_DIRECT_IND` from the exact target, with advertising data length zero. The capture contained no undirected advertisement or scan response from that address. |
| Bonded reconnect | Subsequent direct connections by saved BlueZ device identity succeeded without a new passkey, including live version, core-statistics and Bluetooth-mode replies. |
| Warm reboot persistence | Two commanded reboots retained the address and saved bond. Directed advertising was captured after reboot, followed by authenticated reconnect. Device uptime decreased from 61 seconds before the second reboot to 35 seconds at the next query; core error flags were zero. |
| Slow advertising interval | A successful bonded reconnect occurred about 61 seconds after reboot, beyond the 30-second fast-advertising interval. |
| Reopen pairing | Setting `stealth` again from an existing bonded connection generated a new address, and the next boot allowed a fresh first pairing. |
| Restore default | `set bluetooth.mac default` plus reboot restored `E5:C3:A8:B0:60:66` and normal discovery. Fresh PIN pairing, version/core-statistics queries and repeated `factory address (default)` replies passed. The bench target was left in this discoverable mode. |
The newly completed pairing reaches Bluefruit's secured callback before its
bonded flag is necessarily ready. Recording the completed pairing in the
pair-complete callback as well, waiting for the deferred bond write, and
deferring identity-list reconfiguration until disconnect are covered by this
fresh-pair hardware run. Static source contracts also check those paths.
The binary reboot command can reset the target before BlueZ receives its ATT
write acknowledgement. One initial harness run reported `Unlikely Error`
after successful pre-reboot commands. Later checks require an observed
disconnect, a live post-reboot query and decreased device uptime; they do not
treat the write exception or tool exit code alone as a successful reboot.
## Discovery and DFU cautions found during testing
An ordinary BlueZ discovery scan used a temporary random local address and
did not show the directed target. A passive scan using the Pi's public
identity did show it. Reconnection must use the saved peer/device identity;
absence from an ordinary scan is not proof that the node stopped working.
Conversely, BlueZ can retain a cached name after pairing, so a displayed name
is not proof that the name is still being advertised. The packet-type and
zero-length-payload capture is the relevant evidence here.
The existing DFU handoff helper assumed the application and bootloader shared
one address. That assumption is false with a custom application address:
the authenticated handoff worked, but the helper timed out looking for DFU
at the application address. A fresh exact-address scan found the known
factory-address `XIAO_DFU` instead. An old factory-address host bond also
caused the first DFU service-discovery attempt to disconnect; clearing only
that old lab record allowed DFU. No bootloader code was changed for this test.
An earlier application-address host pairing record was also removed before
its saved stealth state was known. A direct, known-address connection from
the same Pi identity allowed fresh PIN pairing and protected commands again.
This does not prove that an arbitrary replacement phone can rediscover or
recover a stealth node after forgetting its bond.
## Remaining hardware gates
- True cold boot with all XIAO power sources, including battery, disconnected.
The XIAO reported a battery voltage and did not enumerate as USB on the Pi;
a Pi-only reboot or power cycle would not prove this gate.
- Unused-boot retention with `random-after-connect`, using a reboot trigger
that does not itself authenticate over BLE. The policy has native tests;
the remote BLE reboot command cannot prove this hardware gate.
- Android and iOS bonded reconnect, including a phone changing its resolvable
private address, and direct-connection behavior in the actual MeshCore app.
- Rejection of a connection from a second, unbonded physical central.
- ESP32 Bluedroid and NimBLE hardware. Those use allowlisted minimal
advertising rather than nRF52 directed advertisements.
- Node-side missing/corrupt bond and failed settings/bond-write fault injection.
## Repeatable regression procedure
1. Record the exact board, application version, ZIP hash, local/remote BLE
identities and original Bluetooth setting. Keep a working recovery path.
2. Set the desired custom or random MAC, enable `bluetooth.stealth on`, reboot,
and capture normal discovery before pairing.
3. Pair once. Require a stored bond and successful protected MeshCore commands,
then keep the original session open and issue another command.
4. Disconnect. Capture the actual advertising type and payload with an
appropriate receiving identity; do not use cached scan names as evidence.
5. Reconnect by the saved peer without another PIN and exchange commands.
6. For custom and saved-random addresses, repeat `bluetooth.stealth on`, reboot
twice, and verify unchanged identity/bond, decreased uptime and live
commands. Include a reconnect after the fast-advertising period ends.
7. Separately remove all target power and repeat the persistence checks.
8. Test `bluetooth.stealth off`, then `on`, as a pairing reset, and `off` as
the exit from stealth. Verify live discovery, pairing, commands and an
unchanged MAC policy. Changing the address to `default` is a separate step.
9. With each rotating MAC policy, verify that its rotation trigger still
works, stealth stays enabled, and the new address permits fresh pairing.
10. Repeat relevant gates for a phone with address privacy and each BLE backend.
Raw VM-side logs, the exact artifact and bounded test helper are in
`/home/mesh/mercer-stealth-validation.jUDW0v/`. Raw Bluetooth captures are
local diagnostics and should not be published without privacy review.
## Mercer crash capture
During this run the Pi used its existing `dwc_otg.speed=1` full-speed USB
configuration. Kernel and health logs were streamed to this VM. No new kernel
errors or Pi lockup were observed during these tests; that does not establish
the cause of the earlier lockup.
The live test streams and all temporary scans were stopped at approximately
22:56 PDT. Journald remained active, the restore service remained enabled,
and the test XIAO was disconnected in default mode. Disk journals occupied
about 4.9 MiB at the final check.
At 22:35 PDT, temporary persistent journaling was enabled with a 16 MiB
configured disk-use limit, 2 MiB journal files, one-day retention and a
30-second normal sync interval. Recent buffered messages can still be lost
in a sudden failure. The original `Storage=volatile` configuration is intact.
`mercer-crash-capture-restore.service` is enabled for the next Pi boot. It
checks the armed boot ID, removes only the unchanged managed override,
switches journald back to RAM and leaves the old disk journals for collection.
Its same-boot no-op guard and unit syntax passed. The next-boot restoration
has not yet been exercised; no Pi crash or reboot was deliberately induced.
## Independent-flag follow-up - dev-stflag
The same XIAO and Pi were used later on 2026-09-07 to test the separate
`bluetooth.stealth on|off` flag, with no development-mode migration. This run
used `Xiao_nrf52_companion_radio_ble`, target radio preset, default profile,
and firmware `dev-stflag-4b400ea5` with the uncommitted flag changes.
- Application ZIP SHA-256:
`48fc0ff2c716281771f8b525c62a0015c7605b07e7c513ab854c8b3ff3113f42`.
- Linked RAM: 183,232 / 237,568 bytes; flash: 617,192 / 708,608 bytes.
- Nordic Legacy BLE DFU verified the exact target, hash and model, transferred
617,272 application bytes at a reported 3,522 bytes/second, passed target
validation, and observed the target activation disconnect.
- Protected live device queries returned `dev-stflag-4b400ea5`, protocol 14,
and `Seeed Xiao-nrf52`; every queried core error-flags value was zero.
| Check | Observed result |
| --- | --- |
| Default and rejected input | Initial mode was factory address with stealth off. `set bluetooth.mac stealth` and `set bluetooth.stealth maybe` returned errors, leaving both settings unchanged. |
| Custom plus stealth | `D2:27:5A:40:06:99` advertised normally before first pairing. Fresh PIN pairing, stored bond, protected commands, and a five-second held session passed with stealth on. |
| Repeated on and warm reboot | Repeating `set bluetooth.stealth on` retained the paired state. After reboot, the same custom address accepted protected commands without another PIN. Uptime decreased from 84 to 67 seconds. |
| Actual advertising after reboot | A public-address passive capture showed `ADV_DIRECT_IND` for the custom address, data length zero, and no undirected advertisement or scan response from that address. The scan was explicitly disabled afterward. |
| Off preserves custom address | `set ble.stealth off` and reboot restored normal discovery at the same custom address. A live connection returned stealth off and the unchanged custom policy. |
| Saved random plus stealth | `F2:2E:E5:65:18:5E` passed first pairing and held commands. After reboot, it retained its address, saved-random policy and stealth bond; protected reconnect needed no PIN. Uptime decreased from 55 to 30 seconds. |
| Random-after-connect plus stealth | Selecting this policy kept stealth on and reopened pairing at `C7:FD:29:44:4F:3E`. Pairing produced both bonded-peer-only status and an armed next-boot rotation. Reboot changed the address to `F5:F3:89:B7:B5:26`, where normal discovery, fresh pairing and protected commands passed with stealth still on. |
| Random-every-boot plus stealth | The first boot used `F9:B2:03:DD:CC:43`, completed fresh pairing, and answered commands with stealth on. The next commanded reboot advertised `F8:C7:C0:96:1E:00`; fresh PIN pairing and protected commands passed again with the rotating policy and stealth on. |
| Restore the bench target | Setting the MAC to `default` kept stealth on until the separate `set bluetooth.stealth off`. After reboot, factory-address discovery, fresh PIN pairing and protected commands confirmed default MAC and stealth off. The obsolete factory-address host bond was replaced during this final pairing. |
These checks used actual encrypted BLE connections at MTU 247, not scan
sightings alone. Two first-pair harness attempts stopped before connecting
because their unpaired BlueZ discovery object no longer existed. A fresh
bounded scan immediately followed by pairing was used for retries; this was
not a firmware GATT command failure. Reboot-write/disconnect races were
accepted only with an observed disconnect and subsequent live device checks.
Local automated verification passed 39 native cases, 32 source/persistence/UI
contracts, and 11 real-browser cases. Supported-wrapper builds passed for
XIAO nRF52, XIAO C3, M5Stack Unit C6L and XIAO S3 WIO Full Companion, covering
nRF52, ESP32 NimBLE and ESP32 Bluedroid integration. The contracts and browser
suite are included in the unit-test workflow; a browser must be available for
the optional browser suite to execute instead of skip.
Exact artifacts, build logs, command logs and the private packet capture are
in `/home/mesh/bluetooth-stealth-flag.ApLB8o/` on the VM. The remaining hardware
gates above still apply; these results do not qualify every board or phone.
At 23:42 PDT the XIAO was disconnected in normal discoverable mode. The Pi
retained the same boot ID throughout, remained responsive, and had no new
kernel messages in the streamed log. Journald was active, the next-boot
volatile-log restoration service was still enabled, and disk journals used
about 5.9 MiB. No USB reset, Pi reboot, or target battery removal was used.
+11
View File
@@ -10,6 +10,17 @@ when its log identifies the physical device, firmware artifact, artifact hash,
command result, and cold/warm boot outcome. Do not infer success from a tool's
exit code when the tool has a documented false-success mode.
## Bluetooth stealth qualification - 2026-09-07
The [XIAO stealth report](hardware_validation_bluetooth_stealth_2026-09-07.md)
records exact artifacts for the initial implementation and independent-flag
follow-up. The flag run covers custom/saved-random pairing and bonded reboot
reconnect, idempotent `on`, `off` preserving the MAC, directed advertising,
and both rotating policies with stealth still enabled. It also gives the
repeatable hardware regression procedure. True battery-disconnected cold boot,
phone address-privacy behavior, a second unbonded central, and ESP32 hardware
remain separate uncompleted gates; do not infer them from the XIAO results.
## Current marathon ledger (through 2026-09-04)
| Hardware | Stable identity | Current state | Next blocking check |
+18 -5
View File
@@ -87,15 +87,28 @@ takes effect after reboot. `get ble.name` and `set ble.name` are short aliases.
```
get bluetooth.mac
set bluetooth.mac {address|random|random-every-boot|default}
set bluetooth.mac {address|random|random-every-boot|random-after-connect|default}
get bluetooth.stealth
set bluetooth.stealth {on|off}
```
Shows or changes the Bluetooth identity on Companion builds with BLE. A
literal address must be BLE random-static, such as `C2:11:22:33:44:55`.
`random` generates and saves one address; `random-every-boot` generates a new
one on each startup (`random everyboot` is also accepted); `default` or `clear`
restores the factory address. Reboot,
forget the old phone entry, and pair again. Per-boot random mode requires
pairing after every reboot. `get ble.mac` and `set ble.mac` are short aliases.
one on each startup (`random everyboot` is also accepted).
`random-after-connect` keeps its address across unused power cycles, then
rotates on the next boot after an authenticated connection. `default` or
`clear` restores the factory address without changing the stealth flag.
Reboot, forget the old phone entry, and pair again after an address change.
`get ble.mac` and `set ble.mac` are short aliases.
The independent `bluetooth.stealth` flag defaults off and preserves the chosen
address policy. With it on, the node is discoverable until its first
authenticated pairing, then accepts only that bonded peer. Custom and saved
random addresses keep the bond across boots; rotating modes reopen pairing
when the address rotates, leaving stealth enabled. It still transmits the
directed or allowlisted packets BLE requires for reconnection. Repeating `on`
keeps the bond. Send `off`, then `on`, then reboot to reopen pairing manually.
`ble.stealth` is the short alias. Flag changes require reboot.
```
set lat {latitude}