]> Pileus Git - ~andy/linux/commitdiff
cfg80211: Add a function to get the number of supported channels
authorIlan Peer <ilan.peer@intel.com>
Thu, 9 Jan 2014 09:37:23 +0000 (11:37 +0200)
committerJohannes Berg <johannes.berg@intel.com>
Thu, 9 Jan 2014 13:24:24 +0000 (14:24 +0100)
Add a utility function to get the number of channels supported by
the device, and update the places in the code that need this data.

Signed-off-by: Ilan Peer <ilan.peer@intel.com>
[replace another occurrence in libertas, fix kernel-doc, fix bugs]
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
drivers/net/wireless/libertas/cfg.c
include/net/cfg80211.h
net/wireless/nl80211.c
net/wireless/scan.c
net/wireless/sme.c
net/wireless/util.c

index 116f4aba08d6f629275b3c29a0b98869191e1334..32f75007a825be6c24b6195d35a9f4e31d590961 100644 (file)
@@ -1268,14 +1268,9 @@ static struct cfg80211_scan_request *
 _new_connect_scan_req(struct wiphy *wiphy, struct cfg80211_connect_params *sme)
 {
        struct cfg80211_scan_request *creq = NULL;
-       int i, n_channels = 0;
+       int i, n_channels = ieee80211_get_num_supported_channels(wiphy);
        enum ieee80211_band band;
 
-       for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
-               if (wiphy->bands[band])
-                       n_channels += wiphy->bands[band]->n_channels;
-       }
-
        creq = kzalloc(sizeof(*creq) + sizeof(struct cfg80211_ssid) +
                       n_channels * sizeof(void *),
                       GFP_ATOMIC);
index 56c597793d6d380cb90c80c5d17f73fe87a63eb6..b1f84b05c67e99371eef66c6c3adad1a45380f50 100644 (file)
@@ -4640,6 +4640,14 @@ void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
  */
 void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp);
 
+/**
+ * ieee80211_get_num_supported_channels - get number of channels device has
+ * @wiphy: the wiphy
+ *
+ * Return: the number of channels supported by the device.
+ */
+unsigned int ieee80211_get_num_supported_channels(struct wiphy *wiphy);
+
 /* Logging, debugging and troubleshooting/diagnostic helpers. */
 
 /* wiphy_printk helpers, similar to dev_printk */
index 20857126f742227127bbe013c84c2185a3990e3c..d0afd82ebd776276795b8657bb4fc78286a7d458 100644 (file)
@@ -5285,12 +5285,7 @@ static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
                        goto unlock;
                }
        } else {
-               enum ieee80211_band band;
-               n_channels = 0;
-
-               for (band = 0; band < IEEE80211_NUM_BANDS; band++)
-                       if (wiphy->bands[band])
-                               n_channels += wiphy->bands[band]->n_channels;
+               n_channels = ieee80211_get_num_supported_channels(wiphy);
        }
 
        if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
@@ -5498,11 +5493,7 @@ static int nl80211_start_sched_scan(struct sk_buff *skb,
                if (!n_channels)
                        return -EINVAL;
        } else {
-               n_channels = 0;
-
-               for (band = 0; band < IEEE80211_NUM_BANDS; band++)
-                       if (wiphy->bands[band])
-                               n_channels += wiphy->bands[band]->n_channels;
+               n_channels = ieee80211_get_num_supported_channels(wiphy);
        }
 
        if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
index a32d52a04c275c6c148e71ab0a31edd9aae3020d..b528e31da2cfc07ccf5826ce02f3014a61b808e4 100644 (file)
@@ -1089,11 +1089,8 @@ int cfg80211_wext_siwscan(struct net_device *dev,
        /* Determine number of channels, needed to allocate creq */
        if (wreq && wreq->num_channels)
                n_channels = wreq->num_channels;
-       else {
-               for (band = 0; band < IEEE80211_NUM_BANDS; band++)
-                       if (wiphy->bands[band])
-                               n_channels += wiphy->bands[band]->n_channels;
-       }
+       else
+               n_channels = ieee80211_get_num_supported_channels(wiphy);
 
        creq = kzalloc(sizeof(*creq) + sizeof(struct cfg80211_ssid) +
                       n_channels * sizeof(void *),
index 3f64202358f4a662e75bfad6499c837101fe461a..c854f1ce22db539aa1ba0d339712acef8a834f4d 100644 (file)
@@ -70,18 +70,11 @@ static int cfg80211_conn_scan(struct wireless_dev *wdev)
        if (rdev->scan_req)
                return -EBUSY;
 
-       if (wdev->conn->params.channel) {
+       if (wdev->conn->params.channel)
                n_channels = 1;
-       } else {
-               enum ieee80211_band band;
-               n_channels = 0;
+       else
+               n_channels = ieee80211_get_num_supported_channels(wdev->wiphy);
 
-               for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
-                       if (!wdev->wiphy->bands[band])
-                               continue;
-                       n_channels += wdev->wiphy->bands[band]->n_channels;
-               }
-       }
        request = kzalloc(sizeof(*request) + sizeof(request->ssids[0]) +
                          sizeof(request->channels[0]) * n_channels,
                          GFP_KERNEL);
index 329b0efb3ded27b244950e8ff1fab9b322687442..d39c37104ae2f125c5def9c943dc65ab8a669f5a 100644 (file)
@@ -1481,6 +1481,19 @@ int ieee80211_get_ratemask(struct ieee80211_supported_band *sband,
        return 0;
 }
 
+unsigned int ieee80211_get_num_supported_channels(struct wiphy *wiphy)
+{
+       enum ieee80211_band band;
+       unsigned int n_channels = 0;
+
+       for (band = 0; band < IEEE80211_NUM_BANDS; band++)
+               if (wiphy->bands[band])
+                       n_channels += wiphy->bands[band]->n_channels;
+
+       return n_channels;
+}
+EXPORT_SYMBOL(ieee80211_get_num_supported_channels);
+
 /* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */
 /* Ethernet-II snap header (RFC1042 for most EtherTypes) */
 const unsigned char rfc1042_header[] __aligned(2) =