wifi: mac80211: move sta_info_move_state() up
authorJohannes Berg <johannes.berg@intel.com>
Sun, 4 Jun 2023 09:11:21 +0000 (12:11 +0300)
committerJohannes Berg <johannes.berg@intel.com>
Tue, 6 Jun 2023 12:15:46 +0000 (14:15 +0200)
To fix a sequencing issue, this code needs to be changed
a bit. Move it up in the file to prepare for that.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Gregory Greenman <gregory.greenman@intel.com>
Link: https://lore.kernel.org/r/20230604120651.05bb735d7075.I984b5c194a0f84580247d73620a4e61a5f82a774@changeid
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
net/mac80211/sta_info.c

index a1cd5c2..dc76bc4 100644 (file)
@@ -4,7 +4,7 @@
  * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
  * Copyright 2013-2014  Intel Mobile Communications GmbH
  * Copyright (C) 2015 - 2017 Intel Deutschland GmbH
- * Copyright (C) 2018-2022 Intel Corporation
+ * Copyright (C) 2018-2023 Intel Corporation
  */
 
 #include <linux/module.h>
@@ -1274,6 +1274,105 @@ static int __must_check __sta_info_destroy_part1(struct sta_info *sta)
        return 0;
 }
 
+int sta_info_move_state(struct sta_info *sta,
+                       enum ieee80211_sta_state new_state)
+{
+       might_sleep();
+
+       if (sta->sta_state == new_state)
+               return 0;
+
+       /* check allowed transitions first */
+
+       switch (new_state) {
+       case IEEE80211_STA_NONE:
+               if (sta->sta_state != IEEE80211_STA_AUTH)
+                       return -EINVAL;
+               break;
+       case IEEE80211_STA_AUTH:
+               if (sta->sta_state != IEEE80211_STA_NONE &&
+                   sta->sta_state != IEEE80211_STA_ASSOC)
+                       return -EINVAL;
+               break;
+       case IEEE80211_STA_ASSOC:
+               if (sta->sta_state != IEEE80211_STA_AUTH &&
+                   sta->sta_state != IEEE80211_STA_AUTHORIZED)
+                       return -EINVAL;
+               break;
+       case IEEE80211_STA_AUTHORIZED:
+               if (sta->sta_state != IEEE80211_STA_ASSOC)
+                       return -EINVAL;
+               break;
+       default:
+               WARN(1, "invalid state %d", new_state);
+               return -EINVAL;
+       }
+
+       sta_dbg(sta->sdata, "moving STA %pM to state %d\n",
+               sta->sta.addr, new_state);
+
+       /* notify the driver before the actual changes so it can
+        * fail the transition
+        */
+       if (test_sta_flag(sta, WLAN_STA_INSERTED)) {
+               int err = drv_sta_state(sta->local, sta->sdata, sta,
+                                       sta->sta_state, new_state);
+               if (err)
+                       return err;
+       }
+
+       /* reflect the change in all state variables */
+
+       switch (new_state) {
+       case IEEE80211_STA_NONE:
+               if (sta->sta_state == IEEE80211_STA_AUTH)
+                       clear_bit(WLAN_STA_AUTH, &sta->_flags);
+               break;
+       case IEEE80211_STA_AUTH:
+               if (sta->sta_state == IEEE80211_STA_NONE) {
+                       set_bit(WLAN_STA_AUTH, &sta->_flags);
+               } else if (sta->sta_state == IEEE80211_STA_ASSOC) {
+                       clear_bit(WLAN_STA_ASSOC, &sta->_flags);
+                       ieee80211_recalc_min_chandef(sta->sdata, -1);
+                       if (!sta->sta.support_p2p_ps)
+                               ieee80211_recalc_p2p_go_ps_allowed(sta->sdata);
+               }
+               break;
+       case IEEE80211_STA_ASSOC:
+               if (sta->sta_state == IEEE80211_STA_AUTH) {
+                       set_bit(WLAN_STA_ASSOC, &sta->_flags);
+                       sta->assoc_at = ktime_get_boottime_ns();
+                       ieee80211_recalc_min_chandef(sta->sdata, -1);
+                       if (!sta->sta.support_p2p_ps)
+                               ieee80211_recalc_p2p_go_ps_allowed(sta->sdata);
+               } else if (sta->sta_state == IEEE80211_STA_AUTHORIZED) {
+                       ieee80211_vif_dec_num_mcast(sta->sdata);
+                       clear_bit(WLAN_STA_AUTHORIZED, &sta->_flags);
+                       ieee80211_clear_fast_xmit(sta);
+                       ieee80211_clear_fast_rx(sta);
+               }
+               break;
+       case IEEE80211_STA_AUTHORIZED:
+               if (sta->sta_state == IEEE80211_STA_ASSOC) {
+                       ieee80211_vif_inc_num_mcast(sta->sdata);
+                       set_bit(WLAN_STA_AUTHORIZED, &sta->_flags);
+                       ieee80211_check_fast_xmit(sta);
+                       ieee80211_check_fast_rx(sta);
+               }
+               if (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
+                   sta->sdata->vif.type == NL80211_IFTYPE_AP)
+                       cfg80211_send_layer2_update(sta->sdata->dev,
+                                                   sta->sta.addr);
+               break;
+       default:
+               break;
+       }
+
+       sta->sta_state = new_state;
+
+       return 0;
+}
+
 static void __sta_info_destroy_part2(struct sta_info *sta)
 {
        struct ieee80211_local *local = sta->local;
@@ -2252,106 +2351,6 @@ void ieee80211_sta_update_pending_airtime(struct ieee80211_local *local,
        }
 }
 
-int sta_info_move_state(struct sta_info *sta,
-                       enum ieee80211_sta_state new_state)
-{
-       might_sleep();
-
-       if (sta->sta_state == new_state)
-               return 0;
-
-       /* check allowed transitions first */
-
-       switch (new_state) {
-       case IEEE80211_STA_NONE:
-               if (sta->sta_state != IEEE80211_STA_AUTH)
-                       return -EINVAL;
-               break;
-       case IEEE80211_STA_AUTH:
-               if (sta->sta_state != IEEE80211_STA_NONE &&
-                   sta->sta_state != IEEE80211_STA_ASSOC)
-                       return -EINVAL;
-               break;
-       case IEEE80211_STA_ASSOC:
-               if (sta->sta_state != IEEE80211_STA_AUTH &&
-                   sta->sta_state != IEEE80211_STA_AUTHORIZED)
-                       return -EINVAL;
-               break;
-       case IEEE80211_STA_AUTHORIZED:
-               if (sta->sta_state != IEEE80211_STA_ASSOC)
-                       return -EINVAL;
-               break;
-       default:
-               WARN(1, "invalid state %d", new_state);
-               return -EINVAL;
-       }
-
-       sta_dbg(sta->sdata, "moving STA %pM to state %d\n",
-               sta->sta.addr, new_state);
-
-       /*
-        * notify the driver before the actual changes so it can
-        * fail the transition
-        */
-       if (test_sta_flag(sta, WLAN_STA_INSERTED)) {
-               int err = drv_sta_state(sta->local, sta->sdata, sta,
-                                       sta->sta_state, new_state);
-               if (err)
-                       return err;
-       }
-
-       /* reflect the change in all state variables */
-
-       switch (new_state) {
-       case IEEE80211_STA_NONE:
-               if (sta->sta_state == IEEE80211_STA_AUTH)
-                       clear_bit(WLAN_STA_AUTH, &sta->_flags);
-               break;
-       case IEEE80211_STA_AUTH:
-               if (sta->sta_state == IEEE80211_STA_NONE) {
-                       set_bit(WLAN_STA_AUTH, &sta->_flags);
-               } else if (sta->sta_state == IEEE80211_STA_ASSOC) {
-                       clear_bit(WLAN_STA_ASSOC, &sta->_flags);
-                       ieee80211_recalc_min_chandef(sta->sdata, -1);
-                       if (!sta->sta.support_p2p_ps)
-                               ieee80211_recalc_p2p_go_ps_allowed(sta->sdata);
-               }
-               break;
-       case IEEE80211_STA_ASSOC:
-               if (sta->sta_state == IEEE80211_STA_AUTH) {
-                       set_bit(WLAN_STA_ASSOC, &sta->_flags);
-                       sta->assoc_at = ktime_get_boottime_ns();
-                       ieee80211_recalc_min_chandef(sta->sdata, -1);
-                       if (!sta->sta.support_p2p_ps)
-                               ieee80211_recalc_p2p_go_ps_allowed(sta->sdata);
-               } else if (sta->sta_state == IEEE80211_STA_AUTHORIZED) {
-                       ieee80211_vif_dec_num_mcast(sta->sdata);
-                       clear_bit(WLAN_STA_AUTHORIZED, &sta->_flags);
-                       ieee80211_clear_fast_xmit(sta);
-                       ieee80211_clear_fast_rx(sta);
-               }
-               break;
-       case IEEE80211_STA_AUTHORIZED:
-               if (sta->sta_state == IEEE80211_STA_ASSOC) {
-                       ieee80211_vif_inc_num_mcast(sta->sdata);
-                       set_bit(WLAN_STA_AUTHORIZED, &sta->_flags);
-                       ieee80211_check_fast_xmit(sta);
-                       ieee80211_check_fast_rx(sta);
-               }
-               if (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
-                   sta->sdata->vif.type == NL80211_IFTYPE_AP)
-                       cfg80211_send_layer2_update(sta->sdata->dev,
-                                                   sta->sta.addr);
-               break;
-       default:
-               break;
-       }
-
-       sta->sta_state = new_state;
-
-       return 0;
-}
-
 static struct ieee80211_sta_rx_stats *
 sta_get_last_rx_stats(struct sta_info *sta)
 {