git: 878fb1e5754c - main - LinuxKPI: 802.11: improve lkpi_80211_mo_sta_state() for non (*sta_state)

From: Bjoern A. Zeeb <bz_at_FreeBSD.org>
Date: Thu, 24 Mar 2022 16:14:20 UTC
The branch main has been updated by bz:

URL: https://cgit.FreeBSD.org/src/commit/?id=878fb1e5754cc5bfbec57bc24859b07936f82a41

commit 878fb1e5754cc5bfbec57bc24859b07936f82a41
Author:     Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2022-03-24 15:34:57 +0000
Commit:     Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2022-03-24 15:34:57 +0000

    LinuxKPI: 802.11: improve lkpi_80211_mo_sta_state() for non (*sta_state)
    
    If a driver does not support (*sta_state)() we internally in
    lkpi_80211_mo_sta_state() fall back to using (*sta_add/*sta_remove)().
    In that case add tracking of both added_to_drv and state fields for the
    lsta so that our state machine keeps working and assertions do not fire.
    
    Sponsored by:   The FreeBSD Foundation
    MFC after:      3 days
---
 sys/compat/linuxkpi/common/src/linux_80211_macops.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/sys/compat/linuxkpi/common/src/linux_80211_macops.c b/sys/compat/linuxkpi/common/src/linux_80211_macops.c
index 68e9ca47634b..e77aeb9afb67 100644
--- a/sys/compat/linuxkpi/common/src/linux_80211_macops.c
+++ b/sys/compat/linuxkpi/common/src/linux_80211_macops.c
@@ -355,14 +355,20 @@ lkpi_80211_mo_sta_state(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
 	}
 
 	/* XXX-BZ is the change state AUTH or ASSOC here? */
-	if (lsta->state < IEEE80211_STA_ASSOC && nstate == IEEE80211_STA_ASSOC)
+	if (lsta->state < IEEE80211_STA_ASSOC && nstate == IEEE80211_STA_ASSOC) {
 		error = lkpi_80211_mo_sta_add(hw, vif, sta);
-	else if (lsta->state >= IEEE80211_STA_ASSOC &&
-	    nstate < IEEE80211_STA_ASSOC)
+		if (error == 0)
+			lsta->added_to_drv = true;
+	} else if (lsta->state >= IEEE80211_STA_ASSOC &&
+	    nstate < IEEE80211_STA_ASSOC) {
 		error = lkpi_80211_mo_sta_remove(hw, vif, sta);
-	else
+		if (error == 0)
+			lsta->added_to_drv = false;
+	} else
 		/* Nothing to do. */
 		error = 0;
+	if (error == 0)
+		lsta->state = nstate;
 
 out:
 	/* XXX-BZ should we manage state in here? */