Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion ports/espressif/common-hal/wifi/Radio.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ void common_hal_wifi_radio_stop_station(wifi_radio_obj_t *self) {
}

void common_hal_wifi_radio_start_ap(wifi_radio_obj_t *self, uint8_t *ssid, size_t ssid_len, uint8_t *password, size_t password_len, uint8_t channel, uint32_t authmode, uint8_t max_connections) {
bool was_ap = self->ap_mode;
set_mode_ap(self, true);

uint8_t esp_authmode = 0;
Expand Down Expand Up @@ -275,7 +276,18 @@ void common_hal_wifi_radio_start_ap(wifi_radio_obj_t *self, uint8_t *ssid, size_

config->ap.max_connection = max_connections;

esp_wifi_set_config(WIFI_IF_AP, config);
esp_err_t result = esp_wifi_set_config(WIFI_IF_AP, config);
if (result != ESP_OK) {
if (!was_ap) {
set_mode_ap(self, false);
}
// The IDF returns ESP_ERR_INVALID_ARG for a channel this radio or its
// country setting cannot use (wifi_ap_config_t.channel).
if (result == ESP_ERR_INVALID_ARG) {
mp_arg_error_invalid(MP_QSTR_channel);
}
raise_esp_error(result);
}
// Wait a few ms for the AP to start. Empirically, this takes < 3ms on ESP32, and < 1ms on other chips.
for (size_t ms = 0; ms < 10; ms++) {
if (common_hal_wifi_radio_get_ap_active(self)) {
Expand Down
3 changes: 3 additions & 0 deletions ports/raspberrypi/common-hal/wifi/Radio.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ void common_hal_wifi_radio_start_ap(wifi_radio_obj_t *self, uint8_t *ssid, size_
mp_raise_RuntimeError(MP_ERROR_TEXT("WiFi is not enabled"));
}

// The CYW43 is 2.4 GHz only.
mp_arg_validate_int_max(channel, 13, MP_QSTR_channel);

/* TODO: If the AP is stopped once it cannot be restarted.
* This means that if if the user does:
*
Expand Down
9 changes: 7 additions & 2 deletions shared-bindings/wifi/Radio.c
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,8 @@ MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_stop_station_obj, wifi_radio_stop_station);
//|
//| If ``channel`` is given, the access point will use that channel unless
//| a station is already operating on a different channel.
//| On dual-band radios, 5 GHz channels (36 and above) may also be given.
//| A channel the radio does not support raises `ValueError`.
//|
//| If ``authmode`` is not None, the access point will use the given authentication modes.
//| If a non-empty password is given, ``authmode`` must not include ``OPEN``.
Expand All @@ -363,7 +365,8 @@ MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_stop_station_obj, wifi_radio_stop_station);
//|
//| .. note::
//|
//| In the raspberrypi port (RP2040 CYW43), ``max_connections`` is ignored.
//| In the raspberrypi port (RP2040 CYW43), ``max_connections`` is ignored
//| and only 2.4 GHz channels (1-13) are accepted.
//| """
//| ...
//|
Expand Down Expand Up @@ -403,7 +406,9 @@ static mp_obj_t wifi_radio_start_ap(size_t n_args, const mp_obj_t *pos_args, mp_
}
}

mp_int_t channel = mp_arg_validate_int_range(args[ARG_channel].u_int, 1, 13, MP_QSTR_channel);
// 165 is the highest channel in the scan pattern. Channels the radio
// doesn't support are rejected by the port rather than here.
mp_int_t channel = mp_arg_validate_int_range(args[ARG_channel].u_int, 1, 165, MP_QSTR_channel);

if (authmode == AUTHMODE_OPEN && password.len > 0) {
mp_raise_ValueError(MP_ERROR_TEXT("AuthMode.OPEN is not used with password"));
Expand Down
Loading