Skip to content

Conversation

@projectgus
Copy link
Contributor

@projectgus projectgus commented Nov 13, 2024

Summary

Configuring the AP for cyw43 writes to some buffers that are only sent to the modem when the interface is brought up. This means you can't configure the AP after calling active(True), the new settings seem to be accepted but the radio doesn't change.

This is different to the documented WLAN behaviour which says to call active(True) before configuring the interface. The esp8266 and esp32 ports require this, even. EDIT: only esp8266 requires this, esp32 works in either order

Fix this by bouncing the AP interface after a config change, if it's active. Configuring with active(False) still works the same as before.

Adds a static variable to track interface active state, rather than relying on the LWIP interface state. This is because the interface state is updated by a driver callback and there's a race: if code calls active(True) and then config(a=b) then the driver doesn't know it's active yet and the changes aren't correctly applied.

Closes #14224

This work was funded through GitHub Sponsors.

Testing

This is one of two fixes which are required for RPI_PICO_W board to pass the wlan test added in #16225.

Trade-Offs and Alternatives

It is possible this pattern will cause the AP to come up briefly with the default "PICOabcd" SSID before being reconfigured, however (due to the aforementioned race condition) it seems like this may not happen at all before the new config is applied. However, if that was a concern then we could hold off bringing the AP interface up until after it's configured. Doing it that way would be a potential breaking change, though.

@projectgus projectgus added extmod Relates to extmod/ directory in source port-rp2 labels Nov 13, 2024
@codecov
Copy link

codecov bot commented Nov 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.57%. Comparing base (af743ea) to head (181800e).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #16226   +/-   ##
=======================================
  Coverage   98.57%   98.57%           
=======================================
  Files         164      164           
  Lines       21347    21347           
=======================================
  Hits        21043    21043           
  Misses        304      304           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

@github-actions
Copy link

Code size report:

   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64:    +0 +0.000% standard
      stm32:    +0 +0.000% PYBV10
     mimxrt:    +0 +0.000% TEENSY40
        rp2:   +84 +0.009% RPI_PICO_W[incl +4(bss)]
       samd:    +0 +0.000% ADAFRUIT_ITSYBITSY_M4_EXPRESS
  qemu rv32:    +0 +0.000% VIRT_RV32

@dpgeorge
Copy link
Member

I think the ordering of active(True) vs configuration is quite a tricky issue. If esp32/8266 really do need the interface to be up before it's configured, then won't they always possibly appear briefly as an unconfigured AP first?

IMO for AP it makes sense to first configure everything and then do active(True). If we could make it work that way on esp then I think that would be better.

Regardless of that, this PR is fixing an inconsistency so is probably good to merge it.

@projectgus
Copy link
Contributor Author

I think the ordering of active(True) vs configuration is quite a tricky issue. If esp32/8266 really do need the interface to be up before it's configured, then won't they always possibly appear briefly as an unconfigured AP first?

Actually I was wrong about esp32, this restriction only exists on esp8266. Will update the commit message and description. esp32 can have active(True) and config() in either order, same as CYW43 (after this commit).

It looks like calling active(True) on the esp8266 without configuring first doesn't result in any AP coming up until you call ap.config() afterward.

@projectgus projectgus force-pushed the bugfix/cyw43_ap_config branch 2 times, most recently from 3eda268 to 4dc55fa Compare November 19, 2024 05:22
Copy link
Member

@dpgeorge dpgeorge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on PYBD_SF6, changing the ssid while the AP is active and it does indeed cycle the AP and the new SSID is then visible.

Configuring the AP for cyw43 writes to some buffers that are only sent to
the modem when the interface is brought up. This means you can't configure
the AP after calling active(True), the new settings seem to be accepted but
the radio doesn't change.

This is different to the WLAN behaviour on other ports. The esp8266 port
requires calling active(True) on the AP before configuring, even.

Fix this by bouncing the AP interface after a config change, if it's
active. Configuring with active(False) still works the same as before.

Adds a static variable to track interface active state, rather than relying
on the LWIP interface state. This is because the interface state is updated
by a driver callback and there's a race: if code calls active(True) and
then config(a=b) then the driver doesn't know it's active yet and the
changes aren't correctly applied.

It is possible this pattern will cause the AP to come up briefly with the
default "PICOabcd" SSID before being reconfigured, however (due to the
aforementioned race condition) it seems like this may not happen at all
before the new config is applied.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
@dpgeorge dpgeorge force-pushed the bugfix/cyw43_ap_config branch from 4dc55fa to 181800e Compare November 20, 2024 03:43
@dpgeorge dpgeorge merged commit 181800e into micropython:master Nov 20, 2024
56 of 60 checks passed
@dpgeorge dpgeorge added this to the release-1.24.1 milestone Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extmod Relates to extmod/ directory in source port-rp2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RPI-PICO-W (CYW43) Wi-Fi AP can only be configured when not active

2 participants