Skip to content

Commit bdfbec2

Browse files
ilanpeer2jmberg-intel
authored andcommitted
cfg80211: Add a function to get the number of supported channels
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>
1 parent 685328b commit bdfbec2

6 files changed

Lines changed: 29 additions & 32 deletions

File tree

‎drivers/net/wireless/libertas/cfg.c‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,14 +1268,9 @@ static struct cfg80211_scan_request *
12681268
_new_connect_scan_req(struct wiphy *wiphy, struct cfg80211_connect_params *sme)
12691269
{
12701270
struct cfg80211_scan_request *creq = NULL;
1271-
int i, n_channels = 0;
1271+
int i, n_channels = ieee80211_get_num_supported_channels(wiphy);
12721272
enum ieee80211_band band;
12731273

1274-
for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1275-
if (wiphy->bands[band])
1276-
n_channels += wiphy->bands[band]->n_channels;
1277-
}
1278-
12791274
creq = kzalloc(sizeof(*creq) + sizeof(struct cfg80211_ssid) +
12801275
n_channels * sizeof(void *),
12811276
GFP_ATOMIC);

‎include/net/cfg80211.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4640,6 +4640,14 @@ void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
46404640
*/
46414641
void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp);
46424642

4643+
/**
4644+
* ieee80211_get_num_supported_channels - get number of channels device has
4645+
* @wiphy: the wiphy
4646+
*
4647+
* Return: the number of channels supported by the device.
4648+
*/
4649+
unsigned int ieee80211_get_num_supported_channels(struct wiphy *wiphy);
4650+
46434651
/* Logging, debugging and troubleshooting/diagnostic helpers. */
46444652

46454653
/* wiphy_printk helpers, similar to dev_printk */

‎net/wireless/nl80211.c‎

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5285,12 +5285,7 @@ static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
52855285
goto unlock;
52865286
}
52875287
} else {
5288-
enum ieee80211_band band;
5289-
n_channels = 0;
5290-
5291-
for (band = 0; band < IEEE80211_NUM_BANDS; band++)
5292-
if (wiphy->bands[band])
5293-
n_channels += wiphy->bands[band]->n_channels;
5288+
n_channels = ieee80211_get_num_supported_channels(wiphy);
52945289
}
52955290

52965291
if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
@@ -5498,11 +5493,7 @@ static int nl80211_start_sched_scan(struct sk_buff *skb,
54985493
if (!n_channels)
54995494
return -EINVAL;
55005495
} else {
5501-
n_channels = 0;
5502-
5503-
for (band = 0; band < IEEE80211_NUM_BANDS; band++)
5504-
if (wiphy->bands[band])
5505-
n_channels += wiphy->bands[band]->n_channels;
5496+
n_channels = ieee80211_get_num_supported_channels(wiphy);
55065497
}
55075498

55085499
if (info->attrs[NL80211_ATTR_SCAN_SSIDS])

‎net/wireless/scan.c‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,11 +1089,8 @@ int cfg80211_wext_siwscan(struct net_device *dev,
10891089
/* Determine number of channels, needed to allocate creq */
10901090
if (wreq && wreq->num_channels)
10911091
n_channels = wreq->num_channels;
1092-
else {
1093-
for (band = 0; band < IEEE80211_NUM_BANDS; band++)
1094-
if (wiphy->bands[band])
1095-
n_channels += wiphy->bands[band]->n_channels;
1096-
}
1092+
else
1093+
n_channels = ieee80211_get_num_supported_channels(wiphy);
10971094

10981095
creq = kzalloc(sizeof(*creq) + sizeof(struct cfg80211_ssid) +
10991096
n_channels * sizeof(void *),

‎net/wireless/sme.c‎

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,11 @@ static int cfg80211_conn_scan(struct wireless_dev *wdev)
7070
if (rdev->scan_req)
7171
return -EBUSY;
7272

73-
if (wdev->conn->params.channel) {
73+
if (wdev->conn->params.channel)
7474
n_channels = 1;
75-
} else {
76-
enum ieee80211_band band;
77-
n_channels = 0;
75+
else
76+
n_channels = ieee80211_get_num_supported_channels(wdev->wiphy);
7877

79-
for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
80-
if (!wdev->wiphy->bands[band])
81-
continue;
82-
n_channels += wdev->wiphy->bands[band]->n_channels;
83-
}
84-
}
8578
request = kzalloc(sizeof(*request) + sizeof(request->ssids[0]) +
8679
sizeof(request->channels[0]) * n_channels,
8780
GFP_KERNEL);

‎net/wireless/util.c‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,6 +1481,19 @@ int ieee80211_get_ratemask(struct ieee80211_supported_band *sband,
14811481
return 0;
14821482
}
14831483

1484+
unsigned int ieee80211_get_num_supported_channels(struct wiphy *wiphy)
1485+
{
1486+
enum ieee80211_band band;
1487+
unsigned int n_channels = 0;
1488+
1489+
for (band = 0; band < IEEE80211_NUM_BANDS; band++)
1490+
if (wiphy->bands[band])
1491+
n_channels += wiphy->bands[band]->n_channels;
1492+
1493+
return n_channels;
1494+
}
1495+
EXPORT_SYMBOL(ieee80211_get_num_supported_channels);
1496+
14841497
/* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */
14851498
/* Ethernet-II snap header (RFC1042 for most EtherTypes) */
14861499
const unsigned char rfc1042_header[] __aligned(2) =

0 commit comments

Comments
 (0)