From 5742a12497afd62ffa53b72d6b32cae995021394 Mon Sep 17 00:00:00 2001 From: anecdata <16617689+anecdata@users.noreply.github.com> Date: Sun, 13 Feb 2022 22:14:45 -0600 Subject: [PATCH] input validation consistent with esp-idf is moved to common-hal --- ports/espressif/common-hal/wifi/Radio.c | 5 +++++ shared-bindings/wifi/Radio.c | 6 +----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/ports/espressif/common-hal/wifi/Radio.c b/ports/espressif/common-hal/wifi/Radio.c index 80d32da5ea..5d4fcab417 100644 --- a/ports/espressif/common-hal/wifi/Radio.c +++ b/ports/espressif/common-hal/wifi/Radio.c @@ -213,7 +213,12 @@ void common_hal_wifi_radio_start_ap(wifi_radio_obj_t *self, uint8_t *ssid, size_ config->ap.password[password_len] = 0; config->ap.channel = channel; config->ap.authmode = authmode; + + if (max_connections < 0 || max_connections > 10) { + mp_raise_ValueError(translate("max_connections must be between 0 and 10")); + } config->ap.max_connection = max_connections; + esp_wifi_set_config(WIFI_IF_AP, config); } diff --git a/shared-bindings/wifi/Radio.c b/shared-bindings/wifi/Radio.c index ccbce2c573..bb8ef18be1 100644 --- a/shared-bindings/wifi/Radio.c +++ b/shared-bindings/wifi/Radio.c @@ -243,7 +243,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_stop_station_obj, wifi_radio_stop_station); //| otherwise ``WPA_WPA2_PSK``. //| //| If ``max_connections`` is given, the access point will allow up to -//| that number of stations to connect. Default is 4. Maximum is 10.""" +//| that number of stations to connect.""" //| ... //| STATIC mp_obj_t wifi_radio_start_ap(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { @@ -288,10 +288,6 @@ STATIC mp_obj_t wifi_radio_start_ap(size_t n_args, const mp_obj_t *pos_args, mp_ authmode = 1; } - if (args[ARG_max_connections].u_int < 0 || args[ARG_max_connections].u_int > 10) { - mp_raise_ValueError(translate("max_connections must be between 0 and 10")); - } - common_hal_wifi_radio_start_ap(self, ssid.buf, ssid.len, password.buf, password.len, args[ARG_channel].u_int, authmode, args[ARG_max_connections].u_int); return mp_const_none; }