Skip to content

Commit cb2d956

Browse files
lucacoelhojmberg-intel
authored andcommitted
cfg80211: refactor cfg80211_can_use_iftype_chan()
Separate the code that counts the interface types and channels from the code that check the interface combinations. The new function that checks for combinations is exported so it can be called by the drivers. This is done in preparation for moving the interface combinations checks out of cfg80211. Signed-off-by: Luciano Coelho <luciano.coelho@intel.com> Signed-off-by: Johannes Berg <johannes.berg@intel.com>
1 parent c8866e5 commit cb2d956

3 files changed

Lines changed: 96 additions & 56 deletions

File tree

‎Documentation/DocBook/80211.tmpl‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
!Finclude/net/cfg80211.h wdev_priv
101101
!Finclude/net/cfg80211.h ieee80211_iface_limit
102102
!Finclude/net/cfg80211.h ieee80211_iface_combination
103+
!Finclude/net/cfg80211.h cfg80211_check_combinations
103104
</chapter>
104105
<chapter>
105106
<title>Actions and configuration</title>

‎include/net/cfg80211.h‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4692,6 +4692,28 @@ void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp);
46924692
*/
46934693
unsigned int ieee80211_get_num_supported_channels(struct wiphy *wiphy);
46944694

4695+
/**
4696+
* cfg80211_check_combinations - check interface combinations
4697+
*
4698+
* @wiphy: the wiphy
4699+
* @num_different_channels: the number of different channels we want
4700+
* to use for verification
4701+
* @radar_detect: a bitmap where each bit corresponds to a channel
4702+
* width where radar detection is needed, as in the definition of
4703+
* &struct ieee80211_iface_combination.@radar_detect_widths
4704+
* @iftype_num: array with the numbers of interfaces of each interface
4705+
* type. The index is the interface type as specified in &enum
4706+
* nl80211_iftype.
4707+
*
4708+
* This function can be called by the driver to check whether a
4709+
* combination of interfaces and their types are allowed according to
4710+
* the interface combinations.
4711+
*/
4712+
int cfg80211_check_combinations(struct wiphy *wiphy,
4713+
const int num_different_channels,
4714+
const u8 radar_detect,
4715+
const int iftype_num[NUM_NL80211_IFTYPES]);
4716+
46954717
/* Logging, debugging and troubleshooting/diagnostic helpers. */
46964718

46974719
/* wiphy_printk helpers, similar to dev_printk */

‎net/wireless/util.c‎

Lines changed: 73 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,6 +1268,76 @@ int cfg80211_validate_beacon_int(struct cfg80211_registered_device *rdev,
12681268
return res;
12691269
}
12701270

1271+
int cfg80211_check_combinations(struct wiphy *wiphy,
1272+
const int num_different_channels,
1273+
const u8 radar_detect,
1274+
const int iftype_num[NUM_NL80211_IFTYPES])
1275+
{
1276+
int i, j, iftype;
1277+
int num_interfaces = 0;
1278+
u32 used_iftypes = 0;
1279+
1280+
for (iftype = 0; iftype < NUM_NL80211_IFTYPES; iftype++) {
1281+
num_interfaces += iftype_num[iftype];
1282+
if (iftype_num[iftype] > 0 &&
1283+
!(wiphy->software_iftypes & BIT(iftype)))
1284+
used_iftypes |= BIT(iftype);
1285+
}
1286+
1287+
for (i = 0; i < wiphy->n_iface_combinations; i++) {
1288+
const struct ieee80211_iface_combination *c;
1289+
struct ieee80211_iface_limit *limits;
1290+
u32 all_iftypes = 0;
1291+
1292+
c = &wiphy->iface_combinations[i];
1293+
1294+
if (num_interfaces > c->max_interfaces)
1295+
continue;
1296+
if (num_different_channels > c->num_different_channels)
1297+
continue;
1298+
1299+
limits = kmemdup(c->limits, sizeof(limits[0]) * c->n_limits,
1300+
GFP_KERNEL);
1301+
if (!limits)
1302+
return -ENOMEM;
1303+
1304+
for (iftype = 0; iftype < NUM_NL80211_IFTYPES; iftype++) {
1305+
if (wiphy->software_iftypes & BIT(iftype))
1306+
continue;
1307+
for (j = 0; j < c->n_limits; j++) {
1308+
all_iftypes |= limits[j].types;
1309+
if (!(limits[j].types & BIT(iftype)))
1310+
continue;
1311+
if (limits[j].max < iftype_num[iftype])
1312+
goto cont;
1313+
limits[j].max -= iftype_num[iftype];
1314+
}
1315+
}
1316+
1317+
if (radar_detect && !(c->radar_detect_widths & radar_detect))
1318+
goto cont;
1319+
1320+
/* Finally check that all iftypes that we're currently
1321+
* using are actually part of this combination. If they
1322+
* aren't then we can't use this combination and have
1323+
* to continue to the next.
1324+
*/
1325+
if ((all_iftypes & used_iftypes) != used_iftypes)
1326+
goto cont;
1327+
1328+
/* This combination covered all interface types and
1329+
* supported the requested numbers, so we're good.
1330+
*/
1331+
kfree(limits);
1332+
return 0;
1333+
cont:
1334+
kfree(limits);
1335+
}
1336+
1337+
return -EBUSY;
1338+
}
1339+
EXPORT_SYMBOL(cfg80211_check_combinations);
1340+
12711341
int cfg80211_can_use_iftype_chan(struct cfg80211_registered_device *rdev,
12721342
struct wireless_dev *wdev,
12731343
enum nl80211_iftype iftype,
@@ -1276,15 +1346,14 @@ int cfg80211_can_use_iftype_chan(struct cfg80211_registered_device *rdev,
12761346
u8 radar_detect)
12771347
{
12781348
struct wireless_dev *wdev_iter;
1279-
u32 used_iftypes = BIT(iftype);
12801349
int num[NUM_NL80211_IFTYPES];
12811350
struct ieee80211_channel
12821351
*used_channels[CFG80211_MAX_NUM_DIFFERENT_CHANNELS];
12831352
struct ieee80211_channel *ch;
12841353
enum cfg80211_chan_mode chmode;
12851354
int num_different_channels = 0;
12861355
int total = 1;
1287-
int i, j;
1356+
int i;
12881357

12891358
ASSERT_RTNL();
12901359

@@ -1369,65 +1438,13 @@ int cfg80211_can_use_iftype_chan(struct cfg80211_registered_device *rdev,
13691438

13701439
num[wdev_iter->iftype]++;
13711440
total++;
1372-
used_iftypes |= BIT(wdev_iter->iftype);
13731441
}
13741442

13751443
if (total == 1 && !radar_detect)
13761444
return 0;
13771445

1378-
for (i = 0; i < rdev->wiphy.n_iface_combinations; i++) {
1379-
const struct ieee80211_iface_combination *c;
1380-
struct ieee80211_iface_limit *limits;
1381-
u32 all_iftypes = 0;
1382-
1383-
c = &rdev->wiphy.iface_combinations[i];
1384-
1385-
if (total > c->max_interfaces)
1386-
continue;
1387-
if (num_different_channels > c->num_different_channels)
1388-
continue;
1389-
1390-
limits = kmemdup(c->limits, sizeof(limits[0]) * c->n_limits,
1391-
GFP_KERNEL);
1392-
if (!limits)
1393-
return -ENOMEM;
1394-
1395-
for (iftype = 0; iftype < NUM_NL80211_IFTYPES; iftype++) {
1396-
if (rdev->wiphy.software_iftypes & BIT(iftype))
1397-
continue;
1398-
for (j = 0; j < c->n_limits; j++) {
1399-
all_iftypes |= limits[j].types;
1400-
if (!(limits[j].types & BIT(iftype)))
1401-
continue;
1402-
if (limits[j].max < num[iftype])
1403-
goto cont;
1404-
limits[j].max -= num[iftype];
1405-
}
1406-
}
1407-
1408-
if (radar_detect && !(c->radar_detect_widths & radar_detect))
1409-
goto cont;
1410-
1411-
/*
1412-
* Finally check that all iftypes that we're currently
1413-
* using are actually part of this combination. If they
1414-
* aren't then we can't use this combination and have
1415-
* to continue to the next.
1416-
*/
1417-
if ((all_iftypes & used_iftypes) != used_iftypes)
1418-
goto cont;
1419-
1420-
/*
1421-
* This combination covered all interface types and
1422-
* supported the requested numbers, so we're good.
1423-
*/
1424-
kfree(limits);
1425-
return 0;
1426-
cont:
1427-
kfree(limits);
1428-
}
1429-
1430-
return -EBUSY;
1446+
return cfg80211_check_combinations(&rdev->wiphy, num_different_channels,
1447+
radar_detect, num);
14311448
}
14321449

14331450
int ieee80211_get_ratemask(struct ieee80211_supported_band *sband,

0 commit comments

Comments
 (0)