extmod/network_cyw43: Fix STA default netif after AP mode switch.#140
Open
prafulfillment wants to merge 1 commit intoopenmv:masterfrom
Open
extmod/network_cyw43: Fix STA default netif after AP mode switch.#140prafulfillment wants to merge 1 commit intoopenmv:masterfrom
prafulfillment wants to merge 1 commit intoopenmv:masterfrom
Conversation
Member
|
Hi! Can you send this upstream please? Once it's merged, I'll cherry-pick it back here. |
849804c to
1e0d11e
Compare
Signed-off-by: Praful Mathur <praful.mathur@gmail.com>
1e0d11e to
1d6f09e
Compare
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.
Summary
After switching from AP mode back to STA mode,
netif_defaultremains pointing to the APnetif. This causes all outbound TCP connections to fail withEHOSTUNREACH (errno 113)because traffic routes through the now-defunct AP gateway instead of the STA gateway.The root cause is in cyw43_wifi_set_up() in cyw43_ctrl.c: when STA is reactivated,
itf_statebit 0 is still set from the initial boot, socyw43_tcpip_init(STA)is skipped entirely and with it, the only call tonetif_set_default(STA).This fix adds an explicit
netif_set_default()call innetwork_cyw43_active()whenever STA is activated, ensuring STA is always the default route regardless ofitf_state.Testing
Tested on OpenMV AE3
deinit()ormachine.reset()— PASSTrade-offs and Alternatives
The fix is a redundant
netif_set_default()call on every STA activation, even when STA is already the default.The ideal fix would be in
cyw43_wifi_set_up()in cyw43_ctrl.c (the upstream cyw43-driver), either by clearing itf_state bit 0 on STA teardown or by callingcyw43_tcpip_deinit(STA)in the up=false path. However, that driver is maintained separately. This fix in the MicroPython binding layer is self-contained and does not require upstream driver changes.The alternative that I tried and worked is calling
wlan.deinit()which resets the entire CYW43 chip, killing BLE and requiring full reinitialization (~3-4 seconds of downtime).