]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
cfg80211: Add a function to iterate all BSS entries
authorIlan Peer <ilan.peer@intel.com>
Wed, 29 May 2019 12:25:32 +0000 (15:25 +0300)
committerJohannes Berg <johannes.berg@intel.com>
Fri, 14 Jun 2019 12:16:02 +0000 (14:16 +0200)
Add a function that iterates over the BSS entries associated with a
given wiphy and calls a callback for each iterated BSS. This can be
used by drivers in various ways, e.g., to evaluate some property for
all the BSSs in the medium.

Signed-off-by: Ilan Peer <ilan.peer@intel.com>
Signed-off-by: Luca Coelho <luciano.coelho@intel.com>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
include/net/cfg80211.h
net/wireless/scan.c

index ac758a54e97144c7385f2a2342ed0cdd4a608f7c..4cd2857c06a441cd221e4a034d6291fb0fee9692 100644 (file)
@@ -5750,6 +5750,26 @@ void cfg80211_put_bss(struct wiphy *wiphy, struct cfg80211_bss *bss);
  */
 void cfg80211_unlink_bss(struct wiphy *wiphy, struct cfg80211_bss *bss);
 
+/**
+ * cfg80211_bss_iter - iterate all BSS entries
+ *
+ * This function iterates over the BSS entries associated with the given wiphy
+ * and calls the callback for the iterated BSS. The iterator function is not
+ * allowed to call functions that might modify the internal state of the BSS DB.
+ *
+ * @wiphy: the wiphy
+ * @chandef: if given, the iterator function will be called only if the channel
+ *     of the currently iterated BSS is a subset of the given channel.
+ * @iter: the iterator function to call
+ * @iter_data: an argument to the iterator function
+ */
+void cfg80211_bss_iter(struct wiphy *wiphy,
+                      struct cfg80211_chan_def *chandef,
+                      void (*iter)(struct wiphy *wiphy,
+                                   struct cfg80211_bss *bss,
+                                   void *data),
+                      void *iter_data);
+
 static inline enum nl80211_bss_scan_width
 cfg80211_chandef_to_scan_width(const struct cfg80211_chan_def *chandef)
 {
index f347387f195ad7679607364c2eea258195c6c653..dc1ba21428dd9952c4af41407fd42852fbad92b2 100644 (file)
@@ -1974,6 +1974,27 @@ void cfg80211_unlink_bss(struct wiphy *wiphy, struct cfg80211_bss *pub)
 }
 EXPORT_SYMBOL(cfg80211_unlink_bss);
 
+void cfg80211_bss_iter(struct wiphy *wiphy,
+                      struct cfg80211_chan_def *chandef,
+                      void (*iter)(struct wiphy *wiphy,
+                                   struct cfg80211_bss *bss,
+                                   void *data),
+                      void *iter_data)
+{
+       struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
+       struct cfg80211_internal_bss *bss;
+
+       spin_lock_bh(&rdev->bss_lock);
+
+       list_for_each_entry(bss, &rdev->bss_list, list) {
+               if (!chandef || cfg80211_is_sub_chan(chandef, bss->pub.channel))
+                       iter(wiphy, &bss->pub, iter_data);
+       }
+
+       spin_unlock_bh(&rdev->bss_lock);
+}
+EXPORT_SYMBOL(cfg80211_bss_iter);
+
 #ifdef CONFIG_CFG80211_WEXT
 static struct cfg80211_registered_device *
 cfg80211_get_dev_from_ifindex(struct net *net, int ifindex)