Extend NAN service function definitions with SDEA control field, pairing capability, cipher suite, GTK, and ND-PMK attributes needed when the driver hosts the NAN Discovery Engine. Introduce WIPHY_NAN_FLAGS_OFFLOAD_NDP for drivers that handle NAN Data Path setup autonomously. Add parsing support in cfg80211 for the new attributes, gating security-related attributes on NL80211_EXT_FEATURE_SECURE_NAN and the SDEA Data Path bit on WIPHY_NAN_FLAGS_OFFLOAD_NDP. Signed-off-by: Shivani Baranwal --- include/net/cfg80211.h | 27 ++++++++++ include/uapi/linux/nl80211.h | 46 +++++++++++++++++ net/wireless/nl80211.c | 98 ++++++++++++++++++++++++++++++++++++ net/wireless/util.c | 1 + 4 files changed, 172 insertions(+) diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index 46ba0fb27b14..5dae55db355a 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h @@ -4395,6 +4395,21 @@ struct cfg80211_nan_func_filter { * @num_tx_filters: length of &tx_filters. * @instance_id: driver allocated id of the function. * @cookie: unique NAN function identifier. + * @sdea_ctrl: SDEA control field bitmask as defined in Wi-Fi Aware + * specification Table 9-297. Bit 2: Data Path Required. Bit 6: + * Security Required. Bit 10: GTK Required. The Security Required and + * GTK Required bits require %NL80211_EXT_FEATURE_SECURE_NAN. + * @pairing_bootstrap_methods: bitmap of supported NAN pairing + * bootstrapping methods per the Wi-Fi Aware Specification Table 9-321. + * @csids: array of u32 NAN Cipher Suite ID (CSID) selectors supported by + * this service. See the Wi-Fi Aware Specification for cipher suite values. + * @num_csids: number of entries in @csids. + * @nd_pmk: pre-shared NAN Data Path PMK (%NL80211_NAN_NDP_PMK_LEN bytes). + * @nd_pmk_set: if true, @nd_pmk contains a valid pre-shared ND-PMK. + * @pairing_setup: if true, this service supports NAN pairing setup. + * @pairing_cache: if true, this service supports NAN pairing caching. + * @pairing_verify: if true, this service supports NAN pairing + * verification using a cached NPK. */ struct cfg80211_nan_func { enum nl80211_nan_function_type type; @@ -4421,6 +4436,15 @@ struct cfg80211_nan_func { u8 num_rx_filters; u8 instance_id; u64 cookie; + u16 sdea_ctrl; + u16 pairing_bootstrap_methods; + u32 *csids; + u8 num_csids; + u8 nd_pmk[NL80211_NAN_NDP_PMK_LEN]; + bool nd_pmk_set; + bool pairing_setup; + bool pairing_cache; + bool pairing_verify; }; /** @@ -6355,11 +6379,14 @@ struct wiphy_radio { * @WIPHY_NAN_FLAGS_USERSPACE_DE: Device doesn't support DE offload. * @WIPHY_NAN_FLAGS_INSTANT_COMM: Device can switch to Instant Communication * (IC) mode. Can only be set along with %WIPHY_NAN_FLAGS_CONFIGURABLE_SYNC. + * @WIPHY_NAN_FLAGS_OFFLOAD_NDP: Driver handles NAN Data Path (NDP) handshake + * frames and data path key installation autonomously. */ enum wiphy_nan_flags { WIPHY_NAN_FLAGS_CONFIGURABLE_SYNC = BIT(0), WIPHY_NAN_FLAGS_USERSPACE_DE = BIT(1), WIPHY_NAN_FLAGS_INSTANT_COMM = BIT(2), + WIPHY_NAN_FLAGS_OFFLOAD_NDP = BIT(3), }; /** diff --git a/include/uapi/linux/nl80211.h b/include/uapi/linux/nl80211.h index b56a96f57bec..d610b3f8ab96 100644 --- a/include/uapi/linux/nl80211.h +++ b/include/uapi/linux/nl80211.h @@ -7715,6 +7715,8 @@ enum nl80211_nan_func_term_reason { #define NL80211_NAN_FUNC_SERVICE_SPEC_INFO_MAX_LEN 0xff #define NL80211_NAN_FUNC_SRF_MAX_LEN 0xff +#define NL80211_NAN_NDP_PMK_LEN 32 + /** * enum nl80211_nan_func_attributes - NAN function attributes * @__NL80211_NAN_FUNC_INVALID: invalid @@ -7753,6 +7755,26 @@ enum nl80211_nan_func_term_reason { * Its type is u8 and it cannot be 0. * @NL80211_NAN_FUNC_TERM_REASON: NAN function termination reason. * See &enum nl80211_nan_func_term_reason. + * @NL80211_NAN_FUNC_SDEA_CTRL: u16 Service Descriptor Extension Attribute + * (SDEA) control field bitmask as defined in the Wi-Fi Aware Specification + * Table 9-297. See &enum nl80211_nan_func_sdea_ctrl_flags for the + * relevant bit definitions. The Security Required and GTK Required bits + * require %NL80211_EXT_FEATURE_SECURE_NAN. + * @NL80211_NAN_FUNC_PAIRING_BOOTSTRAP_METHODS: u16 bitmap of supported + * NAN pairing bootstrapping methods as defined in Wi-Fi Aware + * specification Table 9-321. Each bit corresponds to one method. + * @NL80211_NAN_FUNC_CSIDS: a set of u32 NAN Cipher Suite ID (CSID) + * selectors supported by this service. Requires + * %NL80211_EXT_FEATURE_SECURE_NAN. + * @NL80211_NAN_FUNC_PAIRING_SETUP: flag attribute. This service supports + * NAN pairing setup (new pairing). + * @NL80211_NAN_FUNC_PAIRING_CACHE: flag attribute. This service supports + * NAN pairing caching (NPK caching). + * @NL80211_NAN_FUNC_PAIRING_VERIFY: flag attribute. This service supports + * NAN pairing verification using a cached NPK. + * @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. * * @NUM_NL80211_NAN_FUNC_ATTR: internal * @NL80211_NAN_FUNC_ATTR_MAX: highest NAN function attribute @@ -7775,12 +7797,36 @@ enum nl80211_nan_func_attributes { NL80211_NAN_FUNC_TX_MATCH_FILTER, NL80211_NAN_FUNC_INSTANCE_ID, NL80211_NAN_FUNC_TERM_REASON, + NL80211_NAN_FUNC_SDEA_CTRL, + NL80211_NAN_FUNC_PAIRING_BOOTSTRAP_METHODS, + NL80211_NAN_FUNC_CSIDS, + NL80211_NAN_FUNC_PAIRING_SETUP, + NL80211_NAN_FUNC_PAIRING_CACHE, + NL80211_NAN_FUNC_PAIRING_VERIFY, + NL80211_NAN_FUNC_ND_PMK, /* keep last */ NUM_NL80211_NAN_FUNC_ATTR, NL80211_NAN_FUNC_ATTR_MAX = NUM_NL80211_NAN_FUNC_ATTR - 1 }; +/** + * enum nl80211_nan_func_sdea_ctrl_flags - NAN SDEA control field bit flags + * + * Bit definitions for the u16 SDEA control field carried in + * %NL80211_NAN_FUNC_SDEA_CTRL, as specified in the Wi-Fi Aware + * Specification Table 9-297. + * + * @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_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_GTK_REQUIRED = 1 << 10, +}; + /** * enum nl80211_nan_srf_attributes - NAN Service Response filter attributes * @__NL80211_NAN_SRF_INVALID: invalid diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index dd187990dd08..9900f8b91a83 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -1334,6 +1334,15 @@ nl80211_nan_func_policy[NL80211_NAN_FUNC_ATTR_MAX + 1] = { [NL80211_NAN_FUNC_TX_MATCH_FILTER] = { .type = NLA_NESTED }, [NL80211_NAN_FUNC_INSTANCE_ID] = { .type = NLA_U8 }, [NL80211_NAN_FUNC_TERM_REASON] = { .type = NLA_U8 }, + [NL80211_NAN_FUNC_SDEA_CTRL] = { .type = NLA_U16 }, + [NL80211_NAN_FUNC_PAIRING_BOOTSTRAP_METHODS] = { .type = NLA_U16 }, + [NL80211_NAN_FUNC_CSIDS] = { .type = NLA_BINARY, + .len = U8_MAX * sizeof(u32) }, + [NL80211_NAN_FUNC_ND_PMK] = + NLA_POLICY_EXACT_LEN(NL80211_NAN_NDP_PMK_LEN), + [NL80211_NAN_FUNC_PAIRING_SETUP] = { .type = NLA_FLAG }, + [NL80211_NAN_FUNC_PAIRING_CACHE] = { .type = NLA_FLAG }, + [NL80211_NAN_FUNC_PAIRING_VERIFY] = { .type = NLA_FLAG }, }; /* policy for Service Response Filter attributes */ @@ -17581,6 +17590,95 @@ static int nl80211_nan_add_func(struct sk_buff *skb, goto out; } + if (tb[NL80211_NAN_FUNC_SDEA_CTRL]) { + u16 sdea = nla_get_u16(tb[NL80211_NAN_FUNC_SDEA_CTRL]); + + if ((sdea & NL80211_NAN_FUNC_SDEA_CTRL_SECURITY_REQUIRED) && + !(sdea & NL80211_NAN_FUNC_SDEA_CTRL_DATAPATH_REQUIRED)) { + NL_SET_ERR_MSG(info->extack, + "SDEA Security Required requires Data Path Required"); + err = -EINVAL; + goto out; + } + + if ((sdea & (NL80211_NAN_FUNC_SDEA_CTRL_SECURITY_REQUIRED | + NL80211_NAN_FUNC_SDEA_CTRL_GTK_REQUIRED)) && + !wiphy_ext_feature_isset(wdev->wiphy, + NL80211_EXT_FEATURE_SECURE_NAN)) { + NL_SET_ERR_MSG(info->extack, + "SDEA security bits require SECURE_NAN"); + err = -EOPNOTSUPP; + goto out; + } + + if ((sdea & NL80211_NAN_FUNC_SDEA_CTRL_DATAPATH_REQUIRED) && + !(wdev->wiphy->nan_capa.flags & + WIPHY_NAN_FLAGS_OFFLOAD_NDP)) { + NL_SET_ERR_MSG(info->extack, + "SDEA Data Path bit requires OFFLOAD_NDP"); + err = -EOPNOTSUPP; + goto out; + } + func->sdea_ctrl = sdea; + } + + if (tb[NL80211_NAN_FUNC_PAIRING_BOOTSTRAP_METHODS] || + tb[NL80211_NAN_FUNC_PAIRING_SETUP] || + tb[NL80211_NAN_FUNC_PAIRING_CACHE] || + tb[NL80211_NAN_FUNC_PAIRING_VERIFY] || + tb[NL80211_NAN_FUNC_CSIDS] || + tb[NL80211_NAN_FUNC_ND_PMK]) { + if (!wiphy_ext_feature_isset(wdev->wiphy, + NL80211_EXT_FEATURE_SECURE_NAN)) { + NL_SET_ERR_MSG(info->extack, + "Security attributes require SECURE_NAN"); + err = -EINVAL; + goto out; + } + + if (tb[NL80211_NAN_FUNC_PAIRING_BOOTSTRAP_METHODS]) + func->pairing_bootstrap_methods = + nla_get_u16(tb[NL80211_NAN_FUNC_PAIRING_BOOTSTRAP_METHODS]); + + func->pairing_setup = + nla_get_flag(tb[NL80211_NAN_FUNC_PAIRING_SETUP]); + func->pairing_cache = + nla_get_flag(tb[NL80211_NAN_FUNC_PAIRING_CACHE]); + func->pairing_verify = + nla_get_flag(tb[NL80211_NAN_FUNC_PAIRING_VERIFY]); + + if (tb[NL80211_NAN_FUNC_CSIDS]) { + int len = nla_len(tb[NL80211_NAN_FUNC_CSIDS]); + int n = len / sizeof(u32); + + if (len % sizeof(u32)) { + NL_SET_ERR_MSG_ATTR(info->extack, + tb[NL80211_NAN_FUNC_CSIDS], + "CSIDs must be an array of u32 values"); + err = -EINVAL; + goto out; + } + + if (n > 0) { + func->csids = + kmemdup(nla_data(tb[NL80211_NAN_FUNC_CSIDS]), + len, GFP_KERNEL); + if (!func->csids) { + err = -ENOMEM; + goto out; + } + func->num_csids = n; + } + } + + if (tb[NL80211_NAN_FUNC_ND_PMK]) { + memcpy(func->nd_pmk, + nla_data(tb[NL80211_NAN_FUNC_ND_PMK]), + sizeof(func->nd_pmk)); + func->nd_pmk_set = true; + } + } + msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); if (!msg) { err = -ENOMEM; diff --git a/net/wireless/util.c b/net/wireless/util.c index ad0e7b279111..750ddb90739f 100644 --- a/net/wireless/util.c +++ b/net/wireless/util.c @@ -2874,6 +2874,7 @@ void cfg80211_free_nan_func(struct cfg80211_nan_func *f) kfree(f->serv_spec_info); kfree(f->srf_bf); kfree(f->srf_macs); + kfree(f->csids); for (i = 0; i < f->num_rx_filters; i++) kfree(f->rx_filters[i].filter); -- 2.34.1