Merge pull request #3992 from anecdata/reason4

wifi: more disconnect reasons for retries & include error code in exception
This commit is contained in:
Scott Shawcroft 2021-01-15 11:52:34 -08:00 committed by GitHub
commit 816cbe4704
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 42 additions and 14 deletions

View File

@ -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

View File

@ -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;
}

View File

@ -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();

View File

@ -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;

View File

@ -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);