Skip to content

Commit 816cbe4

Browse files
authored
Merge pull request #3992 from anecdata/reason4
wifi: more disconnect reasons for retries & include error code in exception
2 parents fac4d9c + 564dce8 commit 816cbe4

File tree

5 files changed

+42
-14
lines changed

5 files changed

+42
-14
lines changed

locale/circuitpython.pot

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2013,7 +2013,8 @@ msgid "Unhandled ESP TLS error %d %d %x %d"
20132013
msgstr ""
20142014

20152015
#: shared-bindings/wifi/Radio.c
2016-
msgid "Unknown failure"
2016+
#, c-format
2017+
msgid "Unknown failure %d"
20172018
msgstr ""
20182019

20192020
#: ports/nrf/common-hal/_bleio/__init__.c

ports/esp32s2/common-hal/wifi/Radio.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,11 @@ wifi_radio_error_t common_hal_wifi_radio_connect(wifi_radio_obj_t *self, uint8_t
168168
} while ((bits & (WIFI_CONNECTED_BIT | WIFI_DISCONNECTED_BIT)) == 0 && !mp_hal_is_interrupted());
169169
if ((bits & WIFI_DISCONNECTED_BIT) != 0) {
170170
if (self->last_disconnect_reason == WIFI_REASON_AUTH_FAIL) {
171-
return WIFI_RADIO_ERROR_AUTH;
171+
return WIFI_RADIO_ERROR_AUTH_FAIL;
172172
} else if (self->last_disconnect_reason == WIFI_REASON_NO_AP_FOUND) {
173173
return WIFI_RADIO_ERROR_NO_AP_FOUND;
174174
}
175-
return WIFI_RADIO_ERROR_UNKNOWN;
175+
return self->last_disconnect_reason;
176176
}
177177
return WIFI_RADIO_ERROR_NONE;
178178
}

ports/esp32s2/common-hal/wifi/__init__.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,9 @@ static void event_handler(void* arg, esp_event_base_t event_base,
6565
uint8_t reason = d->reason;
6666
ESP_LOGW(TAG, "reason %d 0x%02x", reason, reason);
6767
if (radio->retries_left > 0 &&
68-
(reason == WIFI_REASON_AUTH_EXPIRE ||
69-
reason == WIFI_REASON_NOT_AUTHED ||
70-
reason == WIFI_REASON_ASSOC_EXPIRE ||
71-
reason == WIFI_REASON_CONNECTION_FAIL ||
72-
reason == WIFI_REASON_4WAY_HANDSHAKE_TIMEOUT)) {
68+
reason != WIFI_REASON_AUTH_FAIL &&
69+
reason != WIFI_REASON_NO_AP_FOUND &&
70+
reason != WIFI_REASON_ASSOC_LEAVE) {
7371
radio->retries_left--;
7472
ESP_LOGI(TAG, "Retrying connect. %d retries remaining", radio->retries_left);
7573
esp_wifi_connect();

shared-bindings/wifi/Radio.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,12 +218,12 @@ STATIC mp_obj_t wifi_radio_connect(size_t n_args, const mp_obj_t *pos_args, mp_m
218218
}
219219

220220
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);
221-
if (error == WIFI_RADIO_ERROR_AUTH) {
221+
if (error == WIFI_RADIO_ERROR_AUTH_FAIL) {
222222
mp_raise_ConnectionError(translate("Authentication failure"));
223223
} else if (error == WIFI_RADIO_ERROR_NO_AP_FOUND) {
224224
mp_raise_ConnectionError(translate("No network with that ssid"));
225225
} else if (error != WIFI_RADIO_ERROR_NONE) {
226-
mp_raise_ConnectionError(translate("Unknown failure"));
226+
mp_raise_msg_varg(&mp_type_ConnectionError, translate("Unknown failure %d"), error);
227227
}
228228

229229
return mp_const_none;

shared-bindings/wifi/Radio.h

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,39 @@
3636
const mp_obj_type_t wifi_radio_type;
3737

3838
typedef enum {
39-
WIFI_RADIO_ERROR_NONE,
40-
WIFI_RADIO_ERROR_UNKNOWN,
41-
WIFI_RADIO_ERROR_AUTH,
42-
WIFI_RADIO_ERROR_NO_AP_FOUND
39+
// 0 is circuitpython-specific; 1-53 are IEEE; 200+ are Espressif
40+
WIFI_RADIO_ERROR_NONE = 0,
41+
WIFI_RADIO_ERROR_UNSPECIFIED = 1,
42+
WIFI_RADIO_ERROR_AUTH_EXPIRE = 2,
43+
WIFI_RADIO_ERROR_AUTH_LEAVE = 3,
44+
WIFI_RADIO_ERROR_ASSOC_EXPIRE = 4,
45+
WIFI_RADIO_ERROR_ASSOC_TOOMANY = 5,
46+
WIFI_RADIO_ERROR_NOT_AUTHED = 6,
47+
WIFI_RADIO_ERROR_NOT_ASSOCED = 7,
48+
WIFI_RADIO_ERROR_ASSOC_LEAVE = 8,
49+
WIFI_RADIO_ERROR_ASSOC_NOT_AUTHED = 9,
50+
WIFI_RADIO_ERROR_DISASSOC_PWRCAP_BAD = 10,
51+
WIFI_RADIO_ERROR_DISASSOC_SUPCHAN_BAD = 11,
52+
WIFI_RADIO_ERROR_IE_INVALID = 13,
53+
WIFI_RADIO_ERROR_MIC_FAILURE = 14,
54+
WIFI_RADIO_ERROR_4WAY_HANDSHAKE_TIMEOUT = 15,
55+
WIFI_RADIO_ERROR_GROUP_KEY_UPDATE_TIMEOUT = 16,
56+
WIFI_RADIO_ERROR_IE_IN_4WAY_DIFFERS = 17,
57+
WIFI_RADIO_ERROR_GROUP_CIPHER_INVALID = 18,
58+
WIFI_RADIO_ERROR_PAIRWISE_CIPHER_INVALID = 19,
59+
WIFI_RADIO_ERROR_AKMP_INVALID = 20,
60+
WIFI_RADIO_ERROR_UNSUPP_RSN_IE_VERSION = 21,
61+
WIFI_RADIO_ERROR_INVALID_RSN_IE_CAP = 22,
62+
WIFI_RADIO_ERROR_802_1X_AUTH_FAILED = 23,
63+
WIFI_RADIO_ERROR_CIPHER_SUITE_REJECTED = 24,
64+
WIFI_RADIO_ERROR_INVALID_PMKID = 53,
65+
WIFI_RADIO_ERROR_BEACON_TIMEOUT = 200,
66+
WIFI_RADIO_ERROR_NO_AP_FOUND = 201,
67+
WIFI_RADIO_ERROR_AUTH_FAIL = 202,
68+
WIFI_RADIO_ERROR_ASSOC_FAIL = 203,
69+
WIFI_RADIO_ERROR_HANDSHAKE_TIMEOUT = 204,
70+
WIFI_RADIO_ERROR_CONNECTION_FAIL = 205,
71+
WIFI_RADIO_ERROR_AP_TSF_RESET = 206,
4372
} wifi_radio_error_t;
4473

4574
extern bool common_hal_wifi_radio_get_enabled(wifi_radio_obj_t *self);

0 commit comments

Comments
 (0)