Skip to content

Commit 699477d

Browse files
committed
extmod/network_cyw43: Fix handling of networks with open security.
Prior to this commit, the default security=-1 would be passed directly through to the cyw43 driver to auto-detect the security type, but that driver did not correctly handle the case of open security. The cyw43 driver has now been changed to no longer support auto-detection, rather it is up to the caller to always select the security type. The defaults are now implemented in the Python bindings and are: - if no key is given then it selects open security - if a key is given then it selects WPA2_MIXED_PSK Calling `wlan.connect(<ssid>)` will now connect to an open network, on both rp2 and stm32 ports. The form `wlan.connect(<ssid>, <key>)` will connect to a WPA2 network. Fixes issue #9016. Signed-off-by: Damien George <damien@micropython.org>
1 parent b151422 commit 699477d

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

extmod/network_cyw43.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,13 +244,18 @@ STATIC mp_obj_t network_cyw43_connect(size_t n_args, const mp_obj_t *pos_args, m
244244
args[ARG_security] = args[ARG_auth];
245245
}
246246

247+
// Extract the SSID.
247248
mp_buffer_info_t ssid;
248249
mp_get_buffer_raise(args[ARG_ssid].u_obj, &ssid, MP_BUFFER_READ);
250+
251+
// Extract the key, if given.
249252
mp_buffer_info_t key;
250253
key.buf = NULL;
251254
if (args[ARG_key].u_obj != mp_const_none) {
252255
mp_get_buffer_raise(args[ARG_key].u_obj, &key, MP_BUFFER_READ);
253256
}
257+
258+
// Extract the BSSID, if given.
254259
mp_buffer_info_t bssid;
255260
bssid.buf = NULL;
256261
if (args[ARG_bssid].u_obj != mp_const_none) {
@@ -259,8 +264,26 @@ STATIC mp_obj_t network_cyw43_connect(size_t n_args, const mp_obj_t *pos_args, m
259264
mp_raise_ValueError(NULL);
260265
}
261266
}
267+
268+
// Extract the security type, if given.
269+
uint32_t auth_type;
270+
if (args[ARG_security].u_int == -1) {
271+
if (key.buf == NULL || key.len == 0) {
272+
auth_type = 0; // open security
273+
} else {
274+
#if MICROPY_PY_NETWORK_CYW43_USE_LIB_DRIVER
275+
auth_type = CYW43_AUTH_WPA2_MIXED_PSK;
276+
#else
277+
auth_type = 0x008006; // WPA2_MIXED_PSK
278+
#endif
279+
}
280+
} else {
281+
auth_type = args[ARG_security].u_int;
282+
}
283+
284+
// Start the WiFi join procedure. It will run in the background.
262285
int ret = cyw43_wifi_join(self->cyw, ssid.len, ssid.buf, key.len, key.buf,
263-
args[ARG_security].u_int, bssid.buf, args[ARG_channel].u_int);
286+
auth_type, bssid.buf, args[ARG_channel].u_int);
264287
if (ret != 0) {
265288
mp_raise_OSError(-ret);
266289
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy