From: Vinay Gannevaram The NDL attribute can carry a Max Idle Period field (Wi-Fi Aware v4.0, Table 106), the time a peer may refrain from transmitting over the NDL before the NDPs over it are terminated. Userspace NDP implementations set this field themselves. With NDP offload the device builds the NDL attribute, so userspace has no way to set it. Add NL80211_NAN_CONF_MAX_NDL_IDLE_PERIOD to the NAN configuration, in units of 1024 TUs, where 0 means that the field is not advertised. Accept it only for devices that advertise NDP offload. Signed-off-by: Vinay Gannevaram Signed-off-by: Shivani Baranwal --- include/net/cfg80211.h | 5 +++++ include/uapi/linux/nl80211.h | 6 ++++++ net/mac80211/cfg.c | 1 + net/wireless/nl80211.c | 13 +++++++++++++ net/wireless/trace.h | 13 +++++++++---- 5 files changed, 34 insertions(+), 4 deletions(-) diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index 76f5e83d4308..7645fab0d5d0 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h @@ -4252,6 +4252,10 @@ struct cfg80211_nan_band_config { * Chapter 13 of the Wi-Fi Aware Specification v4.0. * @instant_comm_5ghz: if true, use the configured 5 GHz NAN discovery channel * for Instant Communication; otherwise use the 2.4 GHz discovery channel. + * @max_ndl_idle_period: Max Idle Period to advertise in the NDL attribute of + * the NDLs that the device negotiates, in units of 1024 TUs; 0 means that + * it is not advertised. See %NL80211_NAN_CONF_MAX_NDL_IDLE_PERIOD. Only + * set for devices with %WIPHY_NAN_FLAGS_OFFLOAD_NDP. * @pairing_setup: if true, enable NAN pairing setup. * @pairing_npk_caching: if true, enable NPK/NIK caching. * @band_cfgs: array of band specific configurations, indexed by @@ -4271,6 +4275,7 @@ struct cfg80211_nan_conf { bool enable_dw_notification; bool instant_comm; bool instant_comm_5ghz; + u16 max_ndl_idle_period; bool pairing_setup; bool pairing_npk_caching; struct cfg80211_nan_band_config band_cfgs[NUM_NL80211_BANDS]; diff --git a/include/uapi/linux/nl80211.h b/include/uapi/linux/nl80211.h index 862c7018c909..4cbaec00b030 100644 --- a/include/uapi/linux/nl80211.h +++ b/include/uapi/linux/nl80211.h @@ -8214,6 +8214,11 @@ enum nl80211_nan_band_conf_attributes { * provides a discovery channel. When set, IC uses that 5 GHz channel; * otherwise IC uses the 2.4 GHz NAN discovery channel. Wi-Fi Aware v4.0 * uses 5 GHz when the intended peer is known to support it. + * @NL80211_NAN_CONF_MAX_NDL_IDLE_PERIOD: u16 Max Idle Period that the device + * advertises in the NDL attribute of the NDLs it negotiates, in units of + * 1024 TUs. It is the time a peer may refrain from transmitting over the + * NDL without the device terminating the NDPs over it. 0 means that it is + * not advertised. Requires %NL80211_NAN_CAPA_OFFLOAD_NDP. * @NUM_NL80211_NAN_CONF_ATTR: Internal. * @NL80211_NAN_CONF_ATTR_MAX: Highest NAN configuration attribute. * @@ -8233,6 +8238,7 @@ enum nl80211_nan_conf_attributes { NL80211_NAN_CONF_PAIRING_SETUP, NL80211_NAN_CONF_PAIRING_NPK_CACHING, NL80211_NAN_CONF_INSTANT_COMM_5GHZ, + NL80211_NAN_CONF_MAX_NDL_IDLE_PERIOD, /* keep last */ NUM_NL80211_NAN_CONF_ATTR, diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c index ed5955c94d5b..bec02fbc7183 100644 --- a/net/mac80211/cfg.c +++ b/net/mac80211/cfg.c @@ -370,6 +370,7 @@ static int ieee80211_nan_conf_copy(struct cfg80211_nan_conf *dst, dst->enable_dw_notification = src->enable_dw_notification; dst->instant_comm = src->instant_comm; dst->instant_comm_5ghz = src->instant_comm_5ghz; + dst->max_ndl_idle_period = src->max_ndl_idle_period; memcpy(&dst->band_cfgs, &src->band_cfgs, sizeof(dst->band_cfgs)); diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index c9fff1e9d66f..8ebbd93c6474 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -927,6 +927,7 @@ nl80211_nan_conf_policy[NL80211_NAN_CONF_ATTR_MAX + 1] = { [NL80211_NAN_CONF_PAIRING_SETUP] = { .type = NLA_FLAG }, [NL80211_NAN_CONF_PAIRING_NPK_CACHING] = { .type = NLA_FLAG }, [NL80211_NAN_CONF_INSTANT_COMM_5GHZ] = { .type = NLA_FLAG }, + [NL80211_NAN_CONF_MAX_NDL_IDLE_PERIOD] = { .type = NLA_U16 }, }; static const struct netlink_range_validation nl80211_punct_bitmap_range = { @@ -17454,6 +17455,18 @@ static int nl80211_parse_nan_conf(struct wiphy *wiphy, conf->pairing_npk_caching = nla_get_flag(attrs[NL80211_NAN_CONF_PAIRING_NPK_CACHING]); + if (attrs[NL80211_NAN_CONF_MAX_NDL_IDLE_PERIOD]) { + if (!(wiphy->nan_capa.flags & WIPHY_NAN_FLAGS_OFFLOAD_NDP)) { + NL_SET_ERR_MSG_ATTR(info->extack, + attrs[NL80211_NAN_CONF_MAX_NDL_IDLE_PERIOD], + "Max NDL Idle Period requires NDP offload"); + return -EOPNOTSUPP; + } + + conf->max_ndl_idle_period = + nla_get_u16(attrs[NL80211_NAN_CONF_MAX_NDL_IDLE_PERIOD]); + } + out: if (!conf->band_cfgs[NL80211_BAND_5GHZ].chan && (!conf->bands || conf->bands & BIT(NL80211_BAND_5GHZ))) { diff --git a/net/wireless/trace.h b/net/wireless/trace.h index 405b232508f0..fd6e6c2f1137 100644 --- a/net/wireless/trace.h +++ b/net/wireless/trace.h @@ -2389,6 +2389,7 @@ TRACE_EVENT(rdev_start_nan, __field(u8, bands) __field(u8, instant_comm) __field(u8, instant_comm_5ghz) + __field(u16, max_ndl_idle_period) ), TP_fast_assign( WIPHY_ASSIGN; @@ -2397,12 +2398,13 @@ TRACE_EVENT(rdev_start_nan, __entry->bands = conf->bands; __entry->instant_comm = conf->instant_comm; __entry->instant_comm_5ghz = conf->instant_comm_5ghz; + __entry->max_ndl_idle_period = conf->max_ndl_idle_period; ), TP_printk(WIPHY_PR_FMT ", " WDEV_PR_FMT - ", master preference: %u, bands: 0x%0x, IC: %u, IC 5 GHz: %u", + ", master preference: %u, bands: 0x%0x, IC: %u, IC 5 GHz: %u, max NDL idle period: %u", WIPHY_PR_ARG, WDEV_PR_ARG, __entry->master_pref, __entry->bands, __entry->instant_comm, - __entry->instant_comm_5ghz) + __entry->instant_comm_5ghz, __entry->max_ndl_idle_period) ); TRACE_EVENT(rdev_nan_change_conf, @@ -2416,6 +2418,7 @@ TRACE_EVENT(rdev_nan_change_conf, __field(u8, bands) __field(u8, instant_comm) __field(u8, instant_comm_5ghz) + __field(u16, max_ndl_idle_period) __field(u32, changes) ), TP_fast_assign( @@ -2425,13 +2428,15 @@ TRACE_EVENT(rdev_nan_change_conf, __entry->bands = conf->bands; __entry->instant_comm = conf->instant_comm; __entry->instant_comm_5ghz = conf->instant_comm_5ghz; + __entry->max_ndl_idle_period = conf->max_ndl_idle_period; __entry->changes = changes; ), TP_printk(WIPHY_PR_FMT ", " WDEV_PR_FMT - ", master preference: %u, bands: 0x%0x, IC: %u, IC 5 GHz: %u, changes: %x", + ", master preference: %u, bands: 0x%0x, IC: %u, IC 5 GHz: %u, changes: %x, max NDL idle period: %u", WIPHY_PR_ARG, WDEV_PR_ARG, __entry->master_pref, __entry->bands, __entry->instant_comm, - __entry->instant_comm_5ghz, __entry->changes) + __entry->instant_comm_5ghz, __entry->changes, + __entry->max_ndl_idle_period) ); DEFINE_EVENT(wiphy_wdev_evt, rdev_stop_nan, -- 2.34.1