wifi: allow 5 GHz channels in start_ap() - #11374
Conversation
The channel was clamped to 1..13, so dual-band radios could not run a 5 GHz access point. Accept 1..165, matching start_scanning_networks(), and let each port reject what its radio does not support: - espressif: raise on esp_wifi_set_config() failure. An invalid channel raises ValueError. If this call turned AP mode on, turn it off again. - raspberrypi: CYW43 is 2.4 GHz only; keep its bound at 13. The IDF further limits 5 GHz by country and station band. With the default world-safe country only 36-64 are allowed while disconnected. Fixes adafruit#11338 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
|
This is great, looks like you've got it! I'll do some testing after the artifacts are done. Did you happen to look at the issue with custom AP MAC address on 5GHz... just curious if I missed some possible way of doing it (perhaps via some restructuring of our core code), or if it is an upstream issue. Definitely not an immediate issue. |
|
Yes. Tested on the ESP32-C5-DevKitC-1-N8R8 with this PR: radio off, |
|
OK, I'll look at it again. It theoretically shouldn't need to associate as a station (a known wifi network may not be available). One other thing... maybe should be its own issue. iirc when AP was first implemented, there wasn't a supported WPA2-WPA3 transitional authmode (or I think no WPA3 AP support at all ...edit: not at all #4650 (comment)).
This works for WPA-WPA2 transitional: edit: ah, WPA3 doesn't seem to work? >>> AUTHMODE = [wifi.AuthMode.WPA3, wifi.AuthMode.PSK]
>>> wifi.radio.start_ap("Bob", "YourUncle", channel=48, authmode=AUTHMODE)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: Invalid authmodeI guess it never got added into the circuitpython/ports/espressif/common-hal/wifi/Radio.c Lines 244 to 265 in 7396914 |
|
On 149: that is the IDF default country. It ships as world-safe "01", which allows only 36-64 on 5 GHz until the station picks up a country from the AP it joins. CircuitPython never sets a country. A On WPA3: agreed, its own issue. The espressif |
What
start_ap(channel=)accepts 1 to 165. Ports raiseValueErrorfor channels the radio or its country setting rejects.Why
Fixes #11338. The 1 to 13 clamp in
shared-bindingsmade a 5 GHz access point impossible on the ESP32-C5.esp_wifi_set_config;ESP_ERR_INVALID_ARG->ValueError: Invalid channel; undo AP mode if this call turned it onchannel must be <= 13No new translatable strings;
Invalid %qis reused.Hardware tested
Not tested: Pico W, zephyr-cp boards.
How I tested it
REPL lines below are condensed from scripted runs; outputs are verbatim.
ESP32-C5,
start_ap("x", pw, channel=ch)over the full 5 GHz list, station state varied:Seen from a dual-band Linux client (
nmcli dev wifi list), BSSID is the C5's AP MAC:Rejected values:
A rejected
start_apleaves a running AP alone and does not leave a half-started one:Metro ESP32-S2 (2.4 GHz only), the IDF rejects 5 GHz itself:
Pico 2 W:
A Metro ESP32-S2 scan then saw
pico1on channel 1 with the Pico's AP MAC.The ordering from the issue comment also works on the C5:
enabled = False,start_ap(channel=36), setmac_address_ap,enabled = Truegives an active AP with the new MAC.Try it
code.pyfor an ESP32-C5. Keeps the AP up, since WiFi started from the REPL is reset when the session ends.Scope
anecdata's POC on #11339 saw an invalid channel silently remapped by the IDF; here it raises instead.
wifi.Monitor(#11339) is a separate PR. A country setting, which decides which 5 GHz channels the IDF allows, is not part of this.AI assistance
Claude drafted the change and the test scripts. I reviewed the diff, ran every test on the boards above, and checked the IDF headers for the country and band rules.
🤖 Generated with Claude Code