Skip to content

wifi: more disconnect reasons for retries & include error code in exception #3992

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 15, 2021
Merged
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
3 changes: 2 additions & 1 deletion locale/circuitpython.pot
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions ports/esp32s2/common-hal/wifi/Radio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
8 changes: 3 additions & 5 deletions ports/esp32s2/common-hal/wifi/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions shared-bindings/wifi/Radio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
37 changes: 33 additions & 4 deletions shared-bindings/wifi/Radio.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down