From e519dd3c5269745f4d6c66a012974e622bc08343 Mon Sep 17 00:00:00 2001 From: anecdata <16617689+anecdata@users.noreply.github.com> Date: Wed, 13 Jan 2021 23:45:59 -0600 Subject: [PATCH 1/5] Retry on all disconnect reasons other than: 2 exception reasons & 1 manual disconnect reason. --- ports/esp32s2/common-hal/wifi/__init__.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/ports/esp32s2/common-hal/wifi/__init__.c b/ports/esp32s2/common-hal/wifi/__init__.c index 08d7a164f4..b8e8f731bd 100644 --- a/ports/esp32s2/common-hal/wifi/__init__.c +++ b/ports/esp32s2/common-hal/wifi/__init__.c @@ -65,11 +65,9 @@ static void event_handler(void* arg, esp_event_base_t event_base, uint8_t reason = d->reason; ESP_LOGW(TAG, "reason %d 0x%02x", reason, reason); if (radio->retries_left > 0 && - (reason == WIFI_REASON_AUTH_EXPIRE || - reason == WIFI_REASON_NOT_AUTHED || - reason == WIFI_REASON_ASSOC_EXPIRE || - reason == WIFI_REASON_CONNECTION_FAIL || - reason == WIFI_REASON_4WAY_HANDSHAKE_TIMEOUT)) { + reason != WIFI_REASON_AUTH_FAIL && + reason != WIFI_REASON_NO_AP_FOUND && + reason != WIFI_REASON_ASSOC_LEAVE) { radio->retries_left--; ESP_LOGI(TAG, "Retrying connect. %d retries remaining", radio->retries_left); esp_wifi_connect(); From f75bb5c50f3fac1d12c058abfc3446345d97f013 Mon Sep 17 00:00:00 2001 From: anecdata <16617689+anecdata@users.noreply.github.com> Date: Wed, 13 Jan 2021 23:46:35 -0600 Subject: [PATCH 2/5] Rename to match WIFI_REASON. Also return specific reason code. --- ports/esp32s2/common-hal/wifi/Radio.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ports/esp32s2/common-hal/wifi/Radio.c b/ports/esp32s2/common-hal/wifi/Radio.c index e9f374a06b..9302300889 100644 --- a/ports/esp32s2/common-hal/wifi/Radio.c +++ b/ports/esp32s2/common-hal/wifi/Radio.c @@ -168,11 +168,11 @@ wifi_radio_error_t common_hal_wifi_radio_connect(wifi_radio_obj_t *self, uint8_t } while ((bits & (WIFI_CONNECTED_BIT | WIFI_DISCONNECTED_BIT)) == 0 && !mp_hal_is_interrupted()); if ((bits & WIFI_DISCONNECTED_BIT) != 0) { if (self->last_disconnect_reason == WIFI_REASON_AUTH_FAIL) { - return WIFI_RADIO_ERROR_AUTH; + return WIFI_RADIO_ERROR_AUTH_FAIL; } else if (self->last_disconnect_reason == WIFI_REASON_NO_AP_FOUND) { return WIFI_RADIO_ERROR_NO_AP_FOUND; } - return WIFI_RADIO_ERROR_UNKNOWN; + return self->last_disconnect_reason; } return WIFI_RADIO_ERROR_NONE; } From d1249fbe470bfdaf376e510c8deb2f35f14bb55c Mon Sep 17 00:00:00 2001 From: anecdata <16617689+anecdata@users.noreply.github.com> Date: Wed, 13 Jan 2021 23:46:52 -0600 Subject: [PATCH 3/5] Include all reason codes. --- shared-bindings/wifi/Radio.h | 37 ++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/shared-bindings/wifi/Radio.h b/shared-bindings/wifi/Radio.h index 1e8f362e34..64c1052f7b 100644 --- a/shared-bindings/wifi/Radio.h +++ b/shared-bindings/wifi/Radio.h @@ -36,10 +36,39 @@ const mp_obj_type_t wifi_radio_type; typedef enum { - WIFI_RADIO_ERROR_NONE, - WIFI_RADIO_ERROR_UNKNOWN, - WIFI_RADIO_ERROR_AUTH, - WIFI_RADIO_ERROR_NO_AP_FOUND + // 0 is circuitpython-specific; 1-53 are IEEE; 200+ are Espressif + WIFI_RADIO_ERROR_NONE = 0, + WIFI_RADIO_ERROR_UNSPECIFIED = 1, + WIFI_RADIO_ERROR_AUTH_EXPIRE = 2, + WIFI_RADIO_ERROR_AUTH_LEAVE = 3, + WIFI_RADIO_ERROR_ASSOC_EXPIRE = 4, + WIFI_RADIO_ERROR_ASSOC_TOOMANY = 5, + WIFI_RADIO_ERROR_NOT_AUTHED = 6, + WIFI_RADIO_ERROR_NOT_ASSOCED = 7, + WIFI_RADIO_ERROR_ASSOC_LEAVE = 8, + WIFI_RADIO_ERROR_ASSOC_NOT_AUTHED = 9, + WIFI_RADIO_ERROR_DISASSOC_PWRCAP_BAD = 10, + WIFI_RADIO_ERROR_DISASSOC_SUPCHAN_BAD = 11, + WIFI_RADIO_ERROR_IE_INVALID = 13, + WIFI_RADIO_ERROR_MIC_FAILURE = 14, + WIFI_RADIO_ERROR_4WAY_HANDSHAKE_TIMEOUT = 15, + WIFI_RADIO_ERROR_GROUP_KEY_UPDATE_TIMEOUT = 16, + WIFI_RADIO_ERROR_IE_IN_4WAY_DIFFERS = 17, + WIFI_RADIO_ERROR_GROUP_CIPHER_INVALID = 18, + WIFI_RADIO_ERROR_PAIRWISE_CIPHER_INVALID = 19, + WIFI_RADIO_ERROR_AKMP_INVALID = 20, + WIFI_RADIO_ERROR_UNSUPP_RSN_IE_VERSION = 21, + WIFI_RADIO_ERROR_INVALID_RSN_IE_CAP = 22, + WIFI_RADIO_ERROR_802_1X_AUTH_FAILED = 23, + WIFI_RADIO_ERROR_CIPHER_SUITE_REJECTED = 24, + WIFI_RADIO_ERROR_INVALID_PMKID = 53, + WIFI_RADIO_ERROR_BEACON_TIMEOUT = 200, + WIFI_RADIO_ERROR_NO_AP_FOUND = 201, + WIFI_RADIO_ERROR_AUTH_FAIL = 202, + WIFI_RADIO_ERROR_ASSOC_FAIL = 203, + WIFI_RADIO_ERROR_HANDSHAKE_TIMEOUT = 204, + WIFI_RADIO_ERROR_CONNECTION_FAIL = 205, + WIFI_RADIO_ERROR_AP_TSF_RESET = 206, } wifi_radio_error_t; extern bool common_hal_wifi_radio_get_enabled(wifi_radio_obj_t *self); From 8febdee2640570932c1659817bcaadd429761e8b Mon Sep 17 00:00:00 2001 From: anecdata <16617689+anecdata@users.noreply.github.com> Date: Wed, 13 Jan 2021 23:47:23 -0600 Subject: [PATCH 4/5] Rename to match WIFI_REASON. Also include specific error code in "Unknown failure" Exception. --- shared-bindings/wifi/Radio.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shared-bindings/wifi/Radio.c b/shared-bindings/wifi/Radio.c index 63f507067a..8181fc4c96 100644 --- a/shared-bindings/wifi/Radio.c +++ b/shared-bindings/wifi/Radio.c @@ -218,12 +218,12 @@ STATIC mp_obj_t wifi_radio_connect(size_t n_args, const mp_obj_t *pos_args, mp_m } wifi_radio_error_t error = common_hal_wifi_radio_connect(self, ssid.buf, ssid.len, password.buf, password.len, args[ARG_channel].u_int, timeout, bssid.buf, bssid.len); - if (error == WIFI_RADIO_ERROR_AUTH) { + if (error == WIFI_RADIO_ERROR_AUTH_FAIL) { mp_raise_ConnectionError(translate("Authentication failure")); } else if (error == WIFI_RADIO_ERROR_NO_AP_FOUND) { mp_raise_ConnectionError(translate("No network with that ssid")); } else if (error != WIFI_RADIO_ERROR_NONE) { - mp_raise_ConnectionError(translate("Unknown failure")); + mp_raise_msg_varg(&mp_type_ConnectionError, translate("Unknown failure %d"), error); } return mp_const_none; From 564dce858f2307c649155bb9c14810aad6b823c1 Mon Sep 17 00:00:00 2001 From: anecdata <16617689+anecdata@users.noreply.github.com> Date: Thu, 14 Jan 2021 17:53:37 -0600 Subject: [PATCH 5/5] Update translations --- locale/circuitpython.pot | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index 82058a6110..09ce1718d8 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -2013,7 +2013,8 @@ msgid "Unhandled ESP TLS error %d %d %x %d" msgstr "" #: shared-bindings/wifi/Radio.c -msgid "Unknown failure" +#, c-format +msgid "Unknown failure %d" msgstr "" #: ports/nrf/common-hal/_bleio/__init__.c