Repository navigation
Wi-Fi lifecycle (EPIC-14) - #15
Merged
Merged
Conversation
After a link loss the device stayed off the network until someone reset it: the link and status callbacks reset our state but nothing ever reconnected. A non-blocking supervisor now runs in the main loop with two detectors. The first is the ordinary one: cyw43_tcpip_link_status() reporting anything but CYW43_LINK_UP, which is what lwIP is told when the link genuinely drops. The second exists because the failure this story was written for is invisible to every status call. The plan assumed the driver's join state would show a lost association. It does not: cyw43_ctrl.c:434 collapses the state to WIFI_JOIN_STATE_ACTIVE the moment a join completes, so a healthy station reads 0x0001 -- exactly the value captured over SWD on a device that had silently dropped off the network. The first implementation followed that wrong reading and the hardware caught it: watching the join bits declared a working link dead and rejoined it in a loop while HTTP answered 200 throughout. So the supervisor asks the network instead. Every 60 s it flushes the interface's ARP cache and sends an ARP request for the default gateway; no reply within 3 s is a failure, retried after 5 s, and three in a row mean the network is gone however healthy the link claims to be. On either signal it arms an asynchronous join after a 5 s grace period, with backoff doubling 5 s to 60 s and holding there, BADAUTH pinned to the ceiling and shown on the menu. network_wifiStaConnect is split into arming and waiting so the 30 s wait loop can never run inside the main loop, and the watchdog is fed across the rejoin. Verified with two debug-only injections, since neither failure can be produced on demand: a real disassociation is detected at once and recovers 9 s later, and a gateway made unanswerable while the association stays healthy is detected in 52 s and recovers 4 s after that. The genuine silent failure has only ever appeared spontaneously and remains unreproducible, so the probe is built to its signature but unproven against the real thing. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016emgLTZm7w3qZsRbukWwE4
The configured power mode never reached the radio. network_wifiInit applied PARAM_WIFI_POWER, then every connect called network_resetStaInterface, whose disable clears the only interface bit -- so the matching enable runs cyw43_wifi_set_up with itf_state 0, and that path applies CYW43_DEFAULT_PM unconditionally (cyw43_ctrl.c:558-561). That is CYW43_PERFORMANCE_PM, a PM2 power-save mode, so every session ran in power save whatever the setting said. PARAM_WIFI_POWER is now ignored outright, with the reason written where it used to be read: it never arrived, and no value of it is wanted on a mains-powered board answering an Atari blocked on the cartridge bus. network_applyNoPowerSave() sets CYW43_NONE_PM and reads the mode back, and runs after every STA bring-up -- each boot attempt and each STORY-01 rejoin alike, since both go through the shared connect path. The health report gained a wifi object: link_up, power_save, rejoins and unreachable. power_save is read from the radio on every request rather than cached at bring-up; the first version cached it and duly reported "off" while the radio was in PM2. Measured with a debug hook that puts PM2 back, everything else equal: ping over 20 packets goes from 26.9 ms average and 5% loss to 99.8 ms and 15%, and a 4 MB download from 8.82 s to 9.62 s. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016emgLTZm7w3qZsRbukWwE4
The story named two prints in network.c. There were three, and a fourth leak that mattered more than any of them: settings_print() dumps every key and value to the console, and gconfig_init, aconfig_init and main all call it at boot, so every boot printed WIFI_PASSWORD (STR) with the password in clear. That is the line that ends up in pasted logs. All three settings_print callers pass NULL, which means the debug console and nothing else, so a value whose key contains PASSWORD now prints as <set> or <none> there. A key-value store arguably should not know what a password is, but a store that prints its contents into a log is the right place to stop printing secrets. The network.c prints -- the AP-mode password, "The password is: %s", and the SSID/password/auth line before the async join -- report <set> or <none> too. Verified on the device: boots before the change print the password three times, the boot after prints <set> in all of them and the secret appears nowhere in the log. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016emgLTZm7w3qZsRbukWwE4
The static branch read the address, netmask and gateway as settings_find_entry(...)->value with no NULL check, so a global config missing any of the three faulted before the setup menu came up -- and the menu is where such a setting gets fixed. The values then went through ipaddr_addr(), which accepts "10" and "1.2" as addresses, and dhcp_stop() ran before any of it was parsed, so a half-valid configuration left the interface with neither DHCP nor a usable address. Everything is now validated before the interface is touched: four decimal octets and nothing else, no unusable address, a netmask that is a contiguous run of ones, and a non-zero gateway inside the subnet. Any failure logs a reason, leaves DHCP running, and records the reason for the menu, which renders it on the IP line. dhcp_stop() and netif_set_addr() run only once everything has passed. Verified with a debug hook that overrides the settings in memory only (settings_put_* does not write flash), so the real configuration was never rewritten: an invalid address, an empty address, a non-contiguous netmask and an off-subnet gateway each fall back to DHCP with their own message and the API stays reachable, and a fully valid configuration is still applied and answers on the configured address. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016emgLTZm7w3qZsRbukWwE4
select_configure() ran after the network was brought up, so for the whole boot connect -- up to three attempts of 30 s -- the SELECT button did nothing. The one situation where a factory reset is wanted, a device that cannot reach its access point, was exactly the situation where the button was dead. It now runs before the network. emul_pollTick() also polls select_checkPushReset(). That callback stands in for the main loop while a connect runs and already serviced the ST, USB and the terminal, but not the button. And the connect loop's wait drops from 2 s to 10 ms per turn, matching the main loop: at 2 s a 300 ms press could land entirely between polls, and the debounce needs several polls across 30 ms windows to accept one at all. STORY-01's supervisor is unaffected -- it arms an asynchronous join and never enters this loop. Verified with a debug hook that reproduces the boot connect (a nonexistent SSID staged in memory, the same blocking connect, the same polling callback): a press 8 s into the failing attempt was detected and reset the device, and the reboot restored the real SSID from flash. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016emgLTZm7w3qZsRbukWwE4
md-devops never writes the global config -- every settings_save in the tree passes aconfig_getContext(), never gconfig_getContext() -- so these defaults cannot be persisted over Booster's values. They are visible only for a key missing from flash, or on a blank global config, and there they should read the same as Booster. Three were stale. The apps catalog URL pointed at the old host over plain HTTP, the boot feature said CONFIGURATOR where Booster says FABRIC, and the Wi-Fi power default differed. The last is aligned for consistency only, since md-devops ignores that setting outright after STORY-02; a value that matches Booster and is never read is less confusing than one that differs and is also never read. All 19 keys now match booster/src/gconfig.c at v2.4.2, checked by diffing the parsed tables. On the device the stored values still win, and with WIFI_POWER at 4 in flash the health report still reports power saving off. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016emgLTZm7w3qZsRbukWwE4
Neither had a caller anywhere in rp/src, and the linker had already proved they cost nothing: network_scan, network_getFoundNetworks and select_coreWaitPush are all absent from the built ELF, garbage collected by --gc-sections along with the ~6 KB scan table. The reasons for removing them are about the source, not the image. network_scan and friends: Wi-Fi scanning and configuration belong to Booster, which this app only reads settings from, so there is no future in which this is called -- and its scan callbacks were GCC nested functions, which clang cannot parse, so the dead code degraded clang-tidy for the whole file. select_coreWaitPush, its disable and the orphaned blocking select_waitPush: it launches core 1, and EPIC-07 STORY-01 already backed core 1 out because running it froze the Wi-Fi poll loop the main loop depends on. Anyone reaching for it would also need Booster's core-1 flash lockout. A ready-made entry point into a known hazard is worse than no entry point. SELECT is polled in the foreground by select_checkPushReset, which EPIC-13 STORY-07 and EPIC-14 STORY-04 build on. A comment stands where each used to be. pico/multicore.h is gone from the SELECT path, SELECT still resets the device, and smoke.py passes 8/8. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016emgLTZm7w3qZsRbukWwE4
Stages the real SSID with a wrong password in memory, so the bad-key path can be exercised without touching the access point. It does fail and hand over to the supervisor, but this access point answers LINK JOIN and then times out rather than reporting BADAUTH, so the branch that pins the backoff to the ceiling and shows BAD AUTH on the menu is still unproven. STORY-08 is closed as blocked: the remaining scenarios need the access point taken down, which is not available here. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016emgLTZm7w3qZsRbukWwE4
diegoparrilla
added a commit
that referenced
this pull request
Sep 17, 2026
Wi-Fi lifecycle (EPIC-14)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The device rejoins the network by itself, the radio stops sleeping, and a bad
static-IP setting can no longer fault the boot.
Three of the seven stories turned out to be live bugs rather than hardening.
The radio has always run in power save
PARAM_WIFI_POWERnever reached it.network_wifiInitapplied the configured mode, then everyconnect called
network_resetStaInterface, whose disable clears the only interface bit — so thematching enable runs
cyw43_wifi_set_upwithitf_state == 0, and that path appliesCYW43_DEFAULT_PMunconditionally (cyw43_ctrl.c:558-561). That is PM2. Whatever was configuredwas overwritten before the first packet.
Measured with a debug hook that puts PM2 back, everything else equal:
The setting is now ignored outright, with the reason written where it used to be read, and the mode
is re-applied after every bring-up — boot attempts and rejoins alike.
A missing static-IP key faulted the boot
The static branch read the address, netmask and gateway as
settings_find_entry(...)->valuewith noNULL check, so a global config missing any of the three HardFaulted before the setup menu came
up — and the menu is where such a setting gets fixed. Values then went through
ipaddr_addr(),which accepts
"10"and"1.2", anddhcp_stop()ran before any of it was parsed.Everything is now validated before the interface is touched: four decimal octets and nothing else,
no unusable address, a contiguous netmask, and a non-zero gateway inside the subnet. Any failure
falls back to DHCP and says why on the menu's IP line.
SELECT was dead for the whole boot connect
select_configure()ran after the network came up, so for up to three attempts of 30 s the buttondid nothing at all — and a device that cannot reach its access point is exactly when a factory reset
is wanted. It now runs before the network,
emul_pollTickpolls it during a connect, and the connectloop's wait drops from 2 s to 10 ms so the debounce can see a press at all.
Rejoining, and a correction
The device never reconnected after a link loss; it stayed off the network until someone reset it.
A non-blocking supervisor now runs in the main loop with two detectors.
The first is ordinary:
cyw43_tcpip_link_status()not reportingCYW43_LINK_UP.The second exists because the failure this epic was written for is invisible to every status
call, and the analysis in the epic notes was wrong. It assumed the driver's join state would show
a lost association. It does not:
cyw43_ctrl.c:434collapses the state toWIFI_JOIN_STATE_ACTIVEas soon as a join completes, so a healthy station reads
0x0001— the same value captured over SWDon a device that had silently dropped off the network. The first implementation followed that wrong
reading and the hardware caught it: it declared a working link dead and rejoined it in a loop while
HTTP answered 200 throughout. So the supervisor asks the network instead — every 60 s it flushes the
interface's ARP cache and asks the default gateway to answer, and three consecutive misses mean the
network is gone however healthy the link claims to be.
Either signal arms an asynchronous join after a 5 s grace, backoff 5 s doubling to 60 s.
network_wifiStaConnectis split into arming and waiting so its 30 s loop can never run inside themain loop.
Also
settings_print()dumpingWIFI_PASSWORDin clear on every boot, which is the one that endsup in pasted logs.
settings_savepassesaconfig_getContext()— so these only matter on a blank config, where theyshould read the same as Booster. The apps catalog URL was the wrong host over plain HTTP.
network_scan(GCC nested functions that defeat clang tooling;scanning belongs to Booster) and
select_coreWaitPush(launches core 1, which EPIC-07 backed outfor freezing the Wi-Fi poll loop). Both were already absent from the ELF via
--gc-sections, sothis is source hygiene, not size.
wifiobject:link_up,power_save(read from the radio on every request, not cached),rejoins,unreachable.Verified
By fault injection on hardware, with debug-only hooks, each staged in memory so nothing was
persisted:
16/10555714/16smoke.py8/8 on debug.What is NOT verified
STORY-08 is closed as blocked. The access point here is the household network and cannot be
taken down, so these remain unproven: AP reboot while idle / during a tail / during an upload, out
of range and back, a changed DHCP reservation, booting with the AP off, and the
CYW43_LINK_BADAUTHpath (a wrong key made this AP answer
LINK JOINthen time out, neverBADAUTH).The detectors are proven against injected faults that reproduce the observable symptoms of the
real failures, not against a real radio losing a real access point. The silent case has been seen
twice, never on demand. EPIC-16 should treat "Wi-Fi recovers from a real AP outage" as unproven; the
console will now name it if it happens (
WiFi probe: gateway did not answer).