Skip to content

Commit 67f8938

Browse files
projectgusdpgeorge
authored andcommitted
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 <[email protected]>
1 parent 20a6d82 commit 67f8938

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

extmod/network_cyw43.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,17 @@ static MP_DEFINE_CONST_FUN_OBJ_1(network_cyw43_disconnect_obj, network_cyw43_dis
311311

312312
static mp_obj_t network_cyw43_isconnected(mp_obj_t self_in) {
313313
network_cyw43_obj_t *self = MP_OBJ_TO_PTR(self_in);
314-
return mp_obj_new_bool(cyw43_tcpip_link_status(self->cyw, self->itf) == 3);
314+
bool result = (cyw43_tcpip_link_status(self->cyw, self->itf) == CYW43_LINK_UP);
315+
316+
if (result && self->itf == CYW43_ITF_AP) {
317+
// For AP we need to not only know if the link is up, but also if any stations
318+
// have associated.
319+
uint8_t mac_buf[6];
320+
int num_stas = 1;
321+
cyw43_wifi_ap_get_stas(self->cyw, &num_stas, mac_buf);
322+
result = num_stas > 0;
323+
}
324+
return mp_obj_new_bool(result);
315325
}
316326
static MP_DEFINE_CONST_FUN_OBJ_1(network_cyw43_isconnected_obj, network_cyw43_isconnected);
317327

0 commit comments

Comments
 (0)