From bd37f861552dabd7c4ea068cf2b968674490470d Mon Sep 17 00:00:00 2001 From: Nicolas Escande Date: Fri, 7 Jul 2023 15:37:18 +0200 Subject: [PATCH] Fix MESH-PEER-DISCONNECTED message logic on control iface When using mesh we have incoherent MESH-PEER-CONNECTED/MESH-PEER-DISCONNECTED messages when we restart one of the devices without disconnecting it first. Sometimes we have the right behavior, a peer disconnect and then a peer connect, sometimes we only have a a peer connected without a peer disconnected first, and sometimes we have nothing at all. As the plink count seem to be correctly tracked and because we only send the connected event on plink count increase, lets send the peer disconnected event on plink count decrease. Signed-off-by: Nicolas Escande --- wpa_supplicant/mesh_mpm.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/wpa_supplicant/mesh_mpm.c b/wpa_supplicant/mesh_mpm.c index c9e14d5c2..643796672 100644 --- a/wpa_supplicant/mesh_mpm.c +++ b/wpa_supplicant/mesh_mpm.c @@ -561,8 +561,11 @@ static int mesh_mpm_plink_close(struct hostapd_data *hapd, struct sta_info *sta, int reason = WLAN_REASON_MESH_PEERING_CANCELLED; if (sta) { - if (sta->plink_state == PLINK_ESTAB) + if (sta->plink_state == PLINK_ESTAB) { hapd->num_plinks--; + wpa_msg(wpa_s, MSG_INFO, MESH_PEER_DISCONNECTED MACSTR, + MAC2STR(sta->addr)); + } wpa_mesh_set_plink_state(wpa_s, sta, PLINK_HOLDING); mesh_mpm_send_plink_action(wpa_s, sta, PLINK_CLOSE, reason); wpa_printf(MSG_DEBUG, "MPM closing plink sta=" MACSTR, @@ -1428,8 +1431,13 @@ void mesh_mpm_action_rx(struct wpa_supplicant *wpa_s, /* called by ap_free_sta */ void mesh_mpm_free_sta(struct hostapd_data *hapd, struct sta_info *sta) { - if (sta->plink_state == PLINK_ESTAB) + struct wpa_supplicant *wpa_s = hapd->iface->owner; + + if (sta->plink_state == PLINK_ESTAB) { hapd->num_plinks--; + wpa_msg(wpa_s, MSG_INFO, MESH_PEER_DISCONNECTED MACSTR, + MAC2STR(sta->addr)); + } eloop_cancel_timeout(plink_timer, ELOOP_ALL_CTX, sta); eloop_cancel_timeout(mesh_auth_timer, ELOOP_ALL_CTX, sta); }