From: Vinay Gannevaram NAN data paths can't use 6 GHz channels, because nl80211 rejects 6 GHz channels in NAN schedules. Allow them when the wiphy lists 6 GHz in nan_supported_bands, and document that 6 GHz has no NAN discovery channel. The Wi-Fi Aware R5 specification addendum (draft v0.0.16, Table 121) describes a 320 MHz channel with the NAN Availability Extension attribute (ID 0x32). A schedule that also has narrower channels uses it together with the NAN Availability attribute (ID 0x12), so let the availability blob of the local schedule hold one or more of these attributes. Some regulatory domains, such as the US, mark the 6 GHz channels NO_IR, so the regulatory check rejects them in NAN schedules. Accept such a channel if VLP AP operation is allowed on it, as for an AP that uses VLP; VLP is the 6 GHz power mode that needs neither AFC nor an LPI AP. Do this both when the schedule is set and when the channels are checked again after a regulatory change, since that check would otherwise stop NAN. Document that the device has to use VLP transmit power on such a channel. Signed-off-by: Vinay Gannevaram Signed-off-by: Shivani Baranwal --- include/net/cfg80211.h | 4 +++ include/uapi/linux/nl80211.h | 5 +++ net/wireless/nl80211.c | 61 +++++++++++++++++++++++------------- net/wireless/reg.c | 11 +++++-- 4 files changed, 56 insertions(+), 25 deletions(-) diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index ac87ab226638..76f5e83d4308 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h @@ -4206,6 +4206,7 @@ struct cfg80211_qos_map { * channel 6. For 5 GHz band, the channel is either 44 or 149, according * to the regulatory constraints. If chan pointer is NULL the entire band * configuration entry is considered invalid and should not be used. + * It is never set for 6 GHz, which has no NAN discovery channel. * @rssi_close: RSSI close threshold used for NAN state transition algorithm * as described in chapters 3.3.6 and 3.3.7 "NAN Device Role and State * Transition" of Wi-Fi Aware Specification v4.0. If not @@ -7035,6 +7036,9 @@ struct wiphy_nan_capa { * bitmap of &enum nl80211_band values. For instance, for * NL80211_BAND_2GHZ, bit 0 would be set * (i.e. BIT(NL80211_BAND_2GHZ)). + * Setting 6 GHz allows 6 GHz channels in NAN schedules. A NO_IR 6 GHz + * channel is accepted only if VLP AP operation is allowed on it, and the + * device then has to use VLP transmit power on it. * @nan_capa: NAN capabilities * * @txq_limit: configuration of internal TX queue frame limit diff --git a/include/uapi/linux/nl80211.h b/include/uapi/linux/nl80211.h index 5281fef9e5f0..862c7018c909 100644 --- a/include/uapi/linux/nl80211.h +++ b/include/uapi/linux/nl80211.h @@ -3331,6 +3331,10 @@ enum nl80211_commands { * specification Table 93 (NAN Availability attribute format). Required with * %NL80211_CMD_NAN_SET_LOCAL_SCHED to provide the raw NAN Availability * attribute. Used by the device to publish Schedule Update NAFs. + * The blob may hold more than one attribute, each either a NAN + * Availability attribute (ID 0x12) or a NAN Availability Extension + * attribute (ID 0x32), which the Wi-Fi Aware R5 specification addendum + * defines for 320 MHz channels. * @NL80211_ATTR_NAN_SCHED_DEFERRED: Flag attribute used with * %NL80211_CMD_NAN_SET_LOCAL_SCHED. When present, the command is a * request from the device to perform an announced schedule update. This @@ -8117,6 +8121,7 @@ enum nl80211_nan_match_attributes { * The allowed values are 5220 (channel 44) or 5745 (channel 149). * If not present, channel 149 is used if allowed, otherwise channel 44 * will be selected. The value is in MHz (u16). + * This attribute isn't valid on 6 GHz, which has no NAN discovery channel. * @NL80211_NAN_BAND_CONF_RSSI_CLOSE: RSSI close threshold used for NAN state * transition algorithm as described in chapters 3.3.6 and 3.3.7 "NAN * Device Role and State Transition" of Wi-Fi Aware (TM) Specification diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index 9002b68fc630..c9fff1e9d66f 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -529,30 +529,42 @@ static int validate_nan_avail_blob(const struct nlattr *attr, { const u8 *data = nla_data(attr); unsigned int len = nla_len(attr); - u16 attr_len; + unsigned int pos = 0; - /* Need at least: Attr ID (1) + Length (2) */ - if (len < 3) { - NL_SET_ERR_MSG_FMT(extack, - "NAN Availability: Too short (need at least 3 bytes, have %u)", - len); + if (!len) { + NL_SET_ERR_MSG(extack, "NAN Availability: Empty blob"); return -EINVAL; } - if (data[0] != 0x12) { - NL_SET_ERR_MSG_FMT(extack, - "NAN Availability: Invalid Attribute ID 0x%02x (expected 0x12)", - data[0]); - return -EINVAL; - } + while (pos < len) { + unsigned int remaining = len - pos; + u16 attr_len; - attr_len = get_unaligned_le16(&data[1]); + /* Need at least: Attr ID (1) + Length (2) */ + if (remaining < 3) { + NL_SET_ERR_MSG_FMT(extack, + "NAN Availability: Incomplete attribute header (need 3 bytes, have %u)", + remaining); + return -EINVAL; + } - if (attr_len != len - 3) { - NL_SET_ERR_MSG_FMT(extack, - "NAN Availability: Length field (%u) doesn't match data length (%u)", - attr_len, len - 3); - return -EINVAL; + /* NAN Availability or NAN Availability Extension attribute */ + if (data[pos] != 0x12 && data[pos] != 0x32) { + NL_SET_ERR_MSG_FMT(extack, + "NAN Availability: Invalid Attribute ID 0x%02x (expected 0x12 or 0x32)", + data[pos]); + return -EINVAL; + } + + attr_len = get_unaligned_le16(&data[pos + 1]); + if (attr_len > remaining - 3) { + NL_SET_ERR_MSG_FMT(extack, + "NAN Availability: Length field (%u) exceeds remaining data (%u)", + attr_len, remaining - 3); + return -EINVAL; + } + + pos += 3 + attr_len; } return 0; @@ -18393,6 +18405,10 @@ static int nl80211_parse_nan_channel(struct cfg80211_registered_device *rdev, { struct nlattr **channel_parsed __free(kfree) = NULL; struct cfg80211_chan_def chandef; + struct cfg80211_beaconing_check_config config = { + .iftype = NL80211_IFTYPE_NAN, + .reg_power = IEEE80211_REG_VLP_AP, + }; u8 n_rx_nss; int ret; @@ -18410,14 +18426,15 @@ static int nl80211_parse_nan_channel(struct cfg80211_registered_device *rdev, if (ret) return ret; - if (chandef.chan->band == NL80211_BAND_6GHZ) { + if (chandef.chan->band == NL80211_BAND_6GHZ && + !(rdev->wiphy.nan_supported_bands & BIT(NL80211_BAND_6GHZ))) { NL_SET_ERR_MSG(info->extack, - "6 GHz band is not supported"); + "6 GHz band is not supported for NAN"); return -EOPNOTSUPP; } - if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, - NL80211_IFTYPE_NAN)) { + /* A NO_IR 6 GHz channel can be used if VLP AP operation is allowed */ + if (!cfg80211_reg_check_beaconing(&rdev->wiphy, &chandef, &config)) { NL_SET_ERR_MSG_ATTR(info->extack, channel, "Channel in NAN schedule is not allowed for NAN operation"); return -EINVAL; diff --git a/net/wireless/reg.c b/net/wireless/reg.c index 090d21739d7d..da8468c68ab9 100644 --- a/net/wireless/reg.c +++ b/net/wireless/reg.c @@ -2385,10 +2385,15 @@ static bool reg_wdev_chan_valid(struct wiphy *wiphy, struct wireless_dev *wdev) /* NAN doesn't have links, handle it separately */ if (iftype == NL80211_IFTYPE_NAN) { + struct cfg80211_beaconing_check_config config = { + .iftype = NL80211_IFTYPE_NAN, + .reg_power = IEEE80211_REG_VLP_AP, + }; + for (int i = 0; i < wdev->u.nan.n_channels; i++) { - ret = cfg80211_reg_can_beacon(wiphy, - &wdev->u.nan.chandefs[i], - NL80211_IFTYPE_NAN); + chandef = wdev->u.nan.chandefs[i]; + ret = cfg80211_reg_check_beaconing(wiphy, &chandef, + &config); if (!ret) return false; } -- 2.34.1