Rewrite CYW43 WiFi connection scheme #3160
Merged
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.
Fixes #3157
Fixes #1837
The SDK's CYW43 WiFi connection scheme combined both link layer (WiFi net connection) and IP (getting an IP address from DHCP) into a single step. We worked around it with a hack wrapped function, but it resulted in the WiFi.begin() timeout being 2x as long as specified.
Remove the SDK's cyw43_arch_wifi_connect_timeout_ms and replace with our own custom CYW43::begin which will only look at the link layer. Note that the SDK docs are hokey and the cyw43_link_status is set to 1 while network connection attempts are underway. This means we can't actually just look at the link state, it will be in JOIN even if it's not really joined. So, we peek at the state internal CYW43 join FSM to see we're really connected.
This exposed a corner case which @ledereyes seems to have run into in his own app where the LwipIntfDev could potentially try and register the same netif twice because the underlying lower-level CYW43 link had failed. Ensure we netif_remove() in that case to avoid this issue.
On WiFi.end(), just disconnect the network and don't deinitialize the chip in case Bluetooth is active.