git: eb5802659740 - stable/13 - LinuxKPI: 802.11: improve lkpi_80211_mo_sta_state() for non (*sta_state)

From: Bjoern A. Zeeb <bz_at_FreeBSD.org>
Date: Sun, 27 Mar 2022 20:14:10 UTC
The branch stable/13 has been updated by bz:

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

commit eb580265974013be43fa17d37e22124174a7ef86
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-27 18:12:08 +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
    
    (cherry picked from commit 878fb1e5754cc5bfbec57bc24859b07936f82a41)
---
 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? */