From: Kavita Kavita Extend the NAN function configuration with ranging parameters such as the ranging interval, geofence thresholds, FTM parameters, channel, and range report request. Add the RANGING_REQUIRED flag to express the SDEA ranging intent for the service. Require the device to advertise NAN ranging offload and NAN FTM support when RANGING_REQUIRED is set. Reject ranging parameters without that flag so the driver and firmware receive an unambiguous ranging request. Signed-off-by: Kavita Kavita Signed-off-by: Shivani Baranwal --- include/net/cfg80211.h | 23 ++++++++ include/uapi/linux/nl80211.h | 25 +++++++++ net/wireless/nl80211.c | 101 +++++++++++++++++++++++++++++++++++ 3 files changed, 149 insertions(+) diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index 084e23d2391a..6bb840a1aef3 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h @@ -4457,6 +4457,20 @@ struct cfg80211_nan_func_filter { * @num_csids: number of entries in @csids. * @nd_pmk: pointer to the pre-shared NAN Data Path PMK (ND-PMK). * @nd_pmk_len: length of @nd_pmk in bytes; depends on the cipher suite. + * @ranging_required: if true, the SDEA Ranging Required bit is set. + * @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; @@ -4491,6 +4505,15 @@ struct cfg80211_nan_func { u8 num_csids; const u8 *nd_pmk; u8 nd_pmk_len; + bool ranging_required; + 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 849e6c19d122..eed7b015bb20 100644 --- a/include/uapi/linux/nl80211.h +++ b/include/uapi/linux/nl80211.h @@ -7873,6 +7873,23 @@ enum nl80211_nan_func_term_reason { * %NL80211_EXT_FEATURE_SECURE_NAN. * @NL80211_NAN_FUNC_ND_PMK: pre-shared NAN Data Path PMK (ND-PMK); its length * depends on the cipher suite. Requires %NL80211_EXT_FEATURE_SECURE_NAN. + * @NL80211_NAN_FUNC_RANGING_REQUIRED: flag attribute. Sets the SDEA "Ranging + * Required" bit. Requires %NL80211_NAN_CAPA_OFFLOAD_RANGING and NAN FTM + * support, indicated by %NL80211_PMSR_FTM_TYPE_CAPA_ATTR_NAN_SUPPORT. + * @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 @@ -7901,6 +7918,14 @@ enum nl80211_nan_func_attributes { NL80211_NAN_FUNC_PAIRING_BOOTSTRAP_METHODS, NL80211_NAN_FUNC_CSIDS, NL80211_NAN_FUNC_ND_PMK, + NL80211_NAN_FUNC_RANGING_REQUIRED, + 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, diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index eb5ca1d1aff0..7b55a34a733f 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -1396,6 +1396,16 @@ nl80211_nan_func_policy[NL80211_NAN_FUNC_ATTR_MAX + 1] = { [NL80211_NAN_FUNC_ND_PMK] = NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_nan_pmk, WLAN_PMK_LEN_SUITE_B_192), + [NL80211_NAN_FUNC_RANGING_REQUIRED] = { .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] = NLA_POLICY_MAX(NLA_U8, 31), + [NL80211_NAN_FUNC_PREAMBLE] = + NLA_POLICY_RANGE(NLA_U32, NL80211_PREAMBLE_LEGACY, + NL80211_PREAMBLE_HE), + [NL80211_NAN_FUNC_CHAN] = NLA_POLICY_NESTED(nl80211_policy), + [NL80211_NAN_FUNC_RANGE_REPORT] = { .type = NLA_FLAG }, }; /* policy for Service Response Filter attributes */ @@ -17727,6 +17737,97 @@ static int nl80211_nan_add_func(struct sk_buff *skb, } } + func->ranging_required = + nla_get_flag(tb[NL80211_NAN_FUNC_RANGING_REQUIRED]); + + if (!func->ranging_required && + (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])) { + NL_SET_ERR_MSG(info->extack, + "NAN ranging parameters require RANGING_REQUIRED"); + err = -EINVAL; + goto out; + } + + if (func->ranging_required) { + const struct cfg80211_pmsr_capabilities *pmsr_capa = + rdev->wiphy.pmsr_capa; + + if (!(wdev->wiphy->nan_capa.flags & + WIPHY_NAN_FLAGS_OFFLOAD_RANGING) || + !pmsr_capa || !pmsr_capa->ftm.supported || + !pmsr_capa->ftm.type.nan_support) { + 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 (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