cfg80211: fix NAN bands definition

The nl80211_nan_dual_band_conf enumeration doesn't make much sense.
The default value is assigned to a bit, which makes it weird if the
default bit and other bits are set at the same time.

To improve this, get rid of NL80211_NAN_BAND_DEFAULT and add a wiphy
configuration to let the drivers define which bands are supported.
This is exposed to the userspace, which then can make a decision on
which band(s) to use.  Additionally, rename all "dual_band" elements
to "bands", to make things clearer.

Signed-off-by: Luca Coelho <[email protected]>
Signed-off-by: Johannes Berg <[email protected]>
This commit is contained in:
Luca Coelho 2017-02-08 15:00:34 +02:00 • committed by Johannes Berg
commit 8585989d14
7 changed files with 86 additions and 63 deletions

View file

@ -626,7 +626,8 @@ int wiphy_register(struct wiphy *wiphy)
if (WARN_ON((wiphy->interface_modes & BIT(NL80211_IFTYPE_NAN)) &&
(!rdev->ops->start_nan || !rdev->ops->stop_nan ||
!rdev->ops->add_nan_func || !rdev->ops->del_nan_func)))
!rdev->ops->add_nan_func || !rdev->ops->del_nan_func ||
!(wiphy->nan_supported_bands & BIT(NL80211_BAND_2GHZ)))))
return -EINVAL;
#ifndef CONFIG_WIRELESS_WDS

View file

@ -398,7 +398,7 @@ static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = {
},
[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR] = { .len = ETH_ALEN },
[NL80211_ATTR_NAN_MASTER_PREF] = { .type = NLA_U8 },
[NL80211_ATTR_NAN_DUAL] = { .type = NLA_U8 },
[NL80211_ATTR_BANDS] = { .type = NLA_U32 },
[NL80211_ATTR_NAN_FUNC] = { .type = NLA_NESTED },
[NL80211_ATTR_FILS_KEK] = { .type = NLA_BINARY,
.len = FILS_MAX_KEK_LEN },
@ -1886,6 +1886,10 @@ static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
}
}
if (nla_put_u32(msg, NL80211_ATTR_BANDS,
rdev->wiphy.nan_supported_bands))
goto nla_put_failure;
/* done */
state->split_start = 0;
break;
@ -10777,15 +10781,22 @@ static int nl80211_start_nan(struct sk_buff *skb, struct genl_info *info)
if (!info->attrs[NL80211_ATTR_NAN_MASTER_PREF])
return -EINVAL;
if (!info->attrs[NL80211_ATTR_NAN_DUAL])
return -EINVAL;
conf.master_pref =
nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]);
if (!conf.master_pref)
return -EINVAL;
conf.dual = nla_get_u8(info->attrs[NL80211_ATTR_NAN_DUAL]);
if (info->attrs[NL80211_ATTR_BANDS]) {
u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]);
if (bands & ~(u32)wdev->wiphy->nan_supported_bands)
return -EOPNOTSUPP;
if (bands && !(bands & BIT(NL80211_BAND_2GHZ)))
return -EINVAL;
conf.bands = bands;
}
err = rdev_start_nan(rdev, wdev, &conf);
if (err)
@ -11150,9 +11161,17 @@ static int nl80211_nan_change_config(struct sk_buff *skb,
changed |= CFG80211_NAN_CONF_CHANGED_PREF;
}
if (info->attrs[NL80211_ATTR_NAN_DUAL]) {
conf.dual = nla_get_u8(info->attrs[NL80211_ATTR_NAN_DUAL]);
changed |= CFG80211_NAN_CONF_CHANGED_DUAL;
if (info->attrs[NL80211_ATTR_BANDS]) {
u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]);
if (bands & ~(u32)wdev->wiphy->nan_supported_bands)
return -EOPNOTSUPP;
if (bands && !(bands & BIT(NL80211_BAND_2GHZ)))
return -EINVAL;
conf.bands = bands;
changed |= CFG80211_NAN_CONF_CHANGED_BANDS;
}
if (!changed)

View file

@ -1915,18 +1915,18 @@ TRACE_EVENT(rdev_start_nan,
WIPHY_ENTRY
WDEV_ENTRY
__field(u8, master_pref)
__field(u8, dual);
__field(u8, bands);
),
TP_fast_assign(
WIPHY_ASSIGN;
WDEV_ASSIGN;
__entry->master_pref = conf->master_pref;
__entry->dual = conf->dual;
__entry->bands = conf->bands;
),
TP_printk(WIPHY_PR_FMT ", " WDEV_PR_FMT
", master preference: %u, dual: %d",
", master preference: %u, bands: 0x%0x",
WIPHY_PR_ARG, WDEV_PR_ARG, __entry->master_pref,
__entry->dual)
__entry->bands)
);
TRACE_EVENT(rdev_nan_change_conf,
@ -1937,20 +1937,20 @@ TRACE_EVENT(rdev_nan_change_conf,
WIPHY_ENTRY
WDEV_ENTRY
__field(u8, master_pref)
__field(u8, dual);
__field(u8, bands);
__field(u32, changes);
),
TP_fast_assign(
WIPHY_ASSIGN;
WDEV_ASSIGN;
__entry->master_pref = conf->master_pref;
__entry->dual = conf->dual;
__entry->bands = conf->bands;
__entry->changes = changes;
),
TP_printk(WIPHY_PR_FMT ", " WDEV_PR_FMT
", master preference: %u, dual: %d, changes: %x",
", master preference: %u, bands: 0x%0x, changes: %x",
WIPHY_PR_ARG, WDEV_PR_ARG, __entry->master_pref,
__entry->dual, __entry->changes)
__entry->bands, __entry->changes)
);
DEFINE_EVENT(wiphy_wdev_evt, rdev_stop_nan,