From: Kavita Kavita Extend the NAN function configuration with ranging parameters including ranging interval, ingress/egress Geofence thresholds, and FTM parameters to allow userspace (e.g., wpa_supplicant) to configure NAN Ranging as part of NAN Service Discovery in offload mode. Add the corresponding nl80211 attributes and parse them in cfg80211 for the NL80211_CMD_NAN_ADD_FUNC command. As mandated by the Wi-Fi Aware Specification, a NAN device must set the Ranging Required bit (bit 7) in the SDEA control field to indicate ranging intent, so the driver/firmware can perform NAN Ranging as part of NAN Service Discovery. Signed-off-by: Kavita Kavita Signed-off-by: Shivani Baranwal --- include/net/cfg80211.h | 21 +++++++ include/uapi/linux/nl80211.h | 23 ++++++++ net/wireless/nl80211.c | 103 +++++++++++++++++++++++++++++++++++ 3 files changed, 147 insertions(+) diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index 59f921c578c2..6ac4e2e22881 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h @@ -4407,6 +4407,19 @@ struct cfg80211_nan_func_filter { * @pairing_cache: if true, this service supports NAN pairing caching. * @pairing_verify: if true, this service supports NAN pairing * verification using a cached NPK. + * @ranging_interval: interval in milliseconds between two consecutive + * ranging measurements, or 0 if not specified. + * @ingress_distance: inner geofence threshold in millimetres, or 0 if + * not specified. + * @egress_distance: outer geofence threshold in millimetres, or 0 if + * not specified. + * @ftms_per_burst: number of FTM frames per burst, or 0 if not specified. + * @preamble: PHY preamble for FTM frames, see &enum nl80211_preamble, + * or %NL80211_PREAMBLE_LEGACY if not specified. + * @chandef_valid: if true, @chandef is valid. + * @chandef: channel definition for FTM ranging. + * @range_report: if true, a NAN Ranging Report is required after the FTM + * session. */ struct cfg80211_nan_func { enum nl80211_nan_function_type type; @@ -4442,6 +4455,14 @@ struct cfg80211_nan_func { bool pairing_setup; bool pairing_cache; bool pairing_verify; + u32 ranging_interval; + u32 ingress_distance; + u32 egress_distance; + u8 ftms_per_burst; + enum nl80211_preamble preamble; + bool chandef_valid; + struct cfg80211_chan_def chandef; + bool range_report; }; /** diff --git a/include/uapi/linux/nl80211.h b/include/uapi/linux/nl80211.h index ab35ff8082ad..1e640a03e73d 100644 --- a/include/uapi/linux/nl80211.h +++ b/include/uapi/linux/nl80211.h @@ -7775,6 +7775,20 @@ enum nl80211_nan_func_term_reason { * @NL80211_NAN_FUNC_ND_PMK: %NL80211_NAN_NDP_PMK_LEN-byte pre-shared NAN * Data Path PMK (ND-PMK). * Requires %NL80211_EXT_FEATURE_SECURE_NAN. + * @NL80211_NAN_FUNC_RANGING_INTERVAL: u32 attribute. Interval in + * milliseconds between two consecutive ranging measurements. + * @NL80211_NAN_FUNC_INGRESS_DISTANCE: u32 attribute. Inner geofence + * threshold in millimetres. + * @NL80211_NAN_FUNC_EGRESS_DISTANCE: u32 attribute. Outer geofence + * threshold in millimetres. + * @NL80211_NAN_FUNC_FTMS_PER_BURST: u8 attribute. Number of FTM + * frames per burst. + * @NL80211_NAN_FUNC_PREAMBLE: u32 attribute. PHY preamble type for + * FTM frames (see &enum nl80211_preamble). + * @NL80211_NAN_FUNC_CHAN: channel definition for FTM ranging, nested, + * using top-level attributes like %NL80211_ATTR_WIPHY_FREQ etc. + * @NL80211_NAN_FUNC_RANGE_REPORT: flag indicating that a NAN Ranging + * Report is required after the FTM session. * * @NUM_NL80211_NAN_FUNC_ATTR: internal * @NL80211_NAN_FUNC_ATTR_MAX: highest NAN function attribute @@ -7804,6 +7818,13 @@ enum nl80211_nan_func_attributes { NL80211_NAN_FUNC_PAIRING_CACHE, NL80211_NAN_FUNC_PAIRING_VERIFY, NL80211_NAN_FUNC_ND_PMK, + NL80211_NAN_FUNC_RANGING_INTERVAL, + NL80211_NAN_FUNC_INGRESS_DISTANCE, + NL80211_NAN_FUNC_EGRESS_DISTANCE, + NL80211_NAN_FUNC_FTMS_PER_BURST, + NL80211_NAN_FUNC_PREAMBLE, + NL80211_NAN_FUNC_CHAN, + NL80211_NAN_FUNC_RANGE_REPORT, /* keep last */ NUM_NL80211_NAN_FUNC_ATTR, @@ -7819,11 +7840,13 @@ enum nl80211_nan_func_attributes { * * @NL80211_NAN_FUNC_SDEA_CTRL_DATAPATH_REQUIRED: bit 2 - Data Path Required. * @NL80211_NAN_FUNC_SDEA_CTRL_SECURITY_REQUIRED: bit 6 - Security Required. + * @NL80211_NAN_FUNC_SDEA_CTRL_RANGING_REQUIRED: bit 7 - Ranging Required. * @NL80211_NAN_FUNC_SDEA_CTRL_GTK_REQUIRED: bit 10 - GTK Required. */ enum nl80211_nan_func_sdea_ctrl_flags { NL80211_NAN_FUNC_SDEA_CTRL_DATAPATH_REQUIRED = 1 << 2, NL80211_NAN_FUNC_SDEA_CTRL_SECURITY_REQUIRED = 1 << 6, + NL80211_NAN_FUNC_SDEA_CTRL_RANGING_REQUIRED = 1 << 7, NL80211_NAN_FUNC_SDEA_CTRL_GTK_REQUIRED = 1 << 10, }; diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index 412d4e599046..e480f556ce62 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -1346,6 +1346,15 @@ nl80211_nan_func_policy[NL80211_NAN_FUNC_ATTR_MAX + 1] = { [NL80211_NAN_FUNC_PAIRING_SETUP] = { .type = NLA_FLAG }, [NL80211_NAN_FUNC_PAIRING_CACHE] = { .type = NLA_FLAG }, [NL80211_NAN_FUNC_PAIRING_VERIFY] = { .type = NLA_FLAG }, + [NL80211_NAN_FUNC_RANGING_INTERVAL] = { .type = NLA_U32 }, + [NL80211_NAN_FUNC_INGRESS_DISTANCE] = { .type = NLA_U32 }, + [NL80211_NAN_FUNC_EGRESS_DISTANCE] = { .type = NLA_U32 }, + [NL80211_NAN_FUNC_FTMS_PER_BURST] = { .type = NLA_U8 }, + [NL80211_NAN_FUNC_PREAMBLE] = + NLA_POLICY_RANGE(NLA_U32, NL80211_PREAMBLE_LEGACY, + NL80211_PREAMBLE_HE), + [NL80211_NAN_FUNC_CHAN] = { .type = NLA_NESTED }, + [NL80211_NAN_FUNC_RANGE_REPORT] = { .type = NLA_FLAG }, }; /* policy for Service Response Filter attributes */ @@ -17674,6 +17683,100 @@ static int nl80211_nan_add_func(struct sk_buff *skb, } } + if (tb[NL80211_NAN_FUNC_RANGING_INTERVAL] || + tb[NL80211_NAN_FUNC_INGRESS_DISTANCE] || + tb[NL80211_NAN_FUNC_EGRESS_DISTANCE] || + tb[NL80211_NAN_FUNC_FTMS_PER_BURST] || + tb[NL80211_NAN_FUNC_PREAMBLE] || + tb[NL80211_NAN_FUNC_CHAN] || + tb[NL80211_NAN_FUNC_RANGE_REPORT]) { + const struct cfg80211_pmsr_capabilities *pmsr_capa = + rdev->wiphy.pmsr_capa; + + /* SDEA Ranging Required bit must be set */ + if (!(func->sdea_ctrl & NL80211_NAN_FUNC_SDEA_CTRL_RANGING_REQUIRED)) { + NL_SET_ERR_MSG(info->extack, + "NAN ranging parameters require SDEA Ranging Required bit"); + err = -EINVAL; + goto out; + } + + if (!(wdev->wiphy->nan_capa.flags & + WIPHY_NAN_FLAGS_OFFLOAD_RANGING) || + !pmsr_capa || !pmsr_capa->ftm.supported) { + NL_SET_ERR_MSG(info->extack, + "NAN ranging not supported by device"); + err = -EOPNOTSUPP; + goto out; + } + + if (tb[NL80211_NAN_FUNC_RANGING_INTERVAL]) + func->ranging_interval = + nla_get_u32(tb[NL80211_NAN_FUNC_RANGING_INTERVAL]); + + if (tb[NL80211_NAN_FUNC_INGRESS_DISTANCE]) + func->ingress_distance = + nla_get_u32(tb[NL80211_NAN_FUNC_INGRESS_DISTANCE]); + + if (tb[NL80211_NAN_FUNC_EGRESS_DISTANCE]) + func->egress_distance = + nla_get_u32(tb[NL80211_NAN_FUNC_EGRESS_DISTANCE]); + + if (tb[NL80211_NAN_FUNC_FTMS_PER_BURST]) { + func->ftms_per_burst = + nla_get_u8(tb[NL80211_NAN_FUNC_FTMS_PER_BURST]); + if (func->ftms_per_burst > 31) { + NL_SET_ERR_MSG_ATTR(info->extack, + tb[NL80211_NAN_FUNC_FTMS_PER_BURST], + "NAN FTMs per burst exceeds limit of 31"); + err = -EINVAL; + goto out; + } + if (pmsr_capa->ftm.max_ftms_per_burst && + func->ftms_per_burst > pmsr_capa->ftm.max_ftms_per_burst) { + NL_SET_ERR_MSG_ATTR(info->extack, + tb[NL80211_NAN_FUNC_FTMS_PER_BURST], + "NAN FTMs per burst exceeds device limit"); + err = -EINVAL; + goto out; + } + } + + if (tb[NL80211_NAN_FUNC_PREAMBLE]) { + func->preamble = + nla_get_u32(tb[NL80211_NAN_FUNC_PREAMBLE]); + if (!(pmsr_capa->ftm.preambles & BIT(func->preamble))) { + NL_SET_ERR_MSG_ATTR(info->extack, + tb[NL80211_NAN_FUNC_PREAMBLE], + "NAN ranging: unsupported preamble"); + err = -EINVAL; + goto out; + } + } + + if (tb[NL80211_NAN_FUNC_CHAN]) { + /* Reuse info->attrs for chandef parsing; the original contents + * are no longer needed. + */ + memset(info->attrs, 0, + sizeof(*info->attrs) * (NL80211_ATTR_MAX + 1)); + err = nla_parse_nested(info->attrs, NL80211_ATTR_MAX, + tb[NL80211_NAN_FUNC_CHAN], + nl80211_policy, info->extack); + if (err) + goto out; + err = nl80211_parse_chandef(rdev, info->extack, + info->attrs, + &func->chandef, false); + if (err) + goto out; + func->chandef_valid = true; + } + + func->range_report = + nla_get_flag(tb[NL80211_NAN_FUNC_RANGE_REPORT]); + } + msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); if (!msg) { err = -ENOMEM; -- 2.34.1