Skip to content

Commit

Permalink
extmod/network_cyw43: Fix isconnected() result on AP interface.
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
projectgus authored and dpgeorge committed Nov 20, 2024
1 parent 20a6d82 commit 67f8938
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion extmod/network_cyw43.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 67f8938

Please sign in to comment.