summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorAngus Gratton <angus@redyak.com.au>2024-11-13 18:14:47 +1100
committerDamien George <damien@micropython.org>2024-11-20 14:21:57 +1100
commitf562aa1291ad44605f6b5be75b325a40a208ec41 (patch)
tree398c0bfcc2638ddcefb06cbfe358e043f0f25fb8
parentc1b8e65c8e216ce2e90933aef6772de46ad54407 (diff)
downloadmicropython-f562aa1291ad44605f6b5be75b325a40a208ec41.tar.gz
micropython-f562aa1291ad44605f6b5be75b325a40a208ec41.zip
extmod/network_cyw43: Fix isconnected() result on AP interface.
This function is documented to return True if any stations are connected to the AP. Without this fix it returns True whenever the driver has brought the AP interface up. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
-rw-r--r--extmod/network_cyw43.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/extmod/network_cyw43.c b/extmod/network_cyw43.c
index 3066cac75d..891e945de5 100644
--- a/extmod/network_cyw43.c
+++ b/extmod/network_cyw43.c
@@ -311,7 +311,17 @@ static MP_DEFINE_CONST_FUN_OBJ_1(network_cyw43_disconnect_obj, network_cyw43_dis
static mp_obj_t network_cyw43_isconnected(mp_obj_t self_in) {
network_cyw43_obj_t *self = MP_OBJ_TO_PTR(self_in);
- return mp_obj_new_bool(cyw43_tcpip_link_status(self->cyw, self->itf) == 3);
+ bool result = (cyw43_tcpip_link_status(self->cyw, self->itf) == CYW43_LINK_UP);
+
+ if (result && self->itf == CYW43_ITF_AP) {
+ // For AP we need to not only know if the link is up, but also if any stations
+ // have associated.
+ uint8_t mac_buf[6];
+ int num_stas = 1;
+ cyw43_wifi_ap_get_stas(self->cyw, &num_stas, mac_buf);
+ result = num_stas > 0;
+ }
+ return mp_obj_new_bool(result);
}
static MP_DEFINE_CONST_FUN_OBJ_1(network_cyw43_isconnected_obj, network_cyw43_isconnected);