If the driver advertises WIPHY_NAN_FLAGS_USERSPACE_DE, the NAN Discovery Engine is not offloaded to the driver. Reject the request to add/delete a NAN function in cfg80211. Signed-off-by: Shivani Baranwal --- net/wireless/nl80211.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index 2fc680382418..858baaff9db9 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -17400,6 +17400,12 @@ static int nl80211_nan_add_func(struct sk_buff *skb, if (!wdev_running(wdev)) return -ENOTCONN; + if (wdev->wiphy->nan_capa.flags & WIPHY_NAN_FLAGS_USERSPACE_DE) { + NL_SET_ERR_MSG(info->extack, + "NAN Discovery Engine is in userspace"); + return -EOPNOTSUPP; + } + if (!info->attrs[NL80211_ATTR_NAN_FUNC]) return -EINVAL; @@ -17633,6 +17639,12 @@ static int nl80211_nan_del_func(struct sk_buff *skb, if (!wdev_running(wdev)) return -ENOTCONN; + if (wdev->wiphy->nan_capa.flags & WIPHY_NAN_FLAGS_USERSPACE_DE) { + NL_SET_ERR_MSG(info->extack, + "NAN Discovery Engine is in userspace"); + return -EOPNOTSUPP; + } + if (!info->attrs[NL80211_ATTR_COOKIE]) return -EINVAL; -- 2.34.1 Allow userspace to provide the NAN service parameters needed by an offloaded Discovery Engine. Add flags for the SDEA Data Path Required, Security Required, and GTK Required bits, and attributes for pairing bootstrapping methods, supported NAN cipher suite IDs, and the ND-PMK. Require SECURE_NAN for security-related service parameters, and validate CSID arrays and ND-PMK lengths in the netlink policy. Pairing Setup and NPK/NIK Caching are device capabilities advertised in the Device Capability Extension attribute, so carry them in NAN config. Accept these flags only when the Discovery Engine is offloaded and SECURE_NAN is supported. Store ND-PMK material in dynamically sized memory, free it with kfree_sensitive(), and clear the ADD_NAN_FUNCTION request skb because it may contain key material. Signed-off-by: Shivani Baranwal --- include/net/cfg80211.h | 24 +++++++ include/uapi/linux/nl80211.h | 36 +++++++++++ net/wireless/nl80211.c | 118 ++++++++++++++++++++++++++++++++++- net/wireless/util.c | 2 + 4 files changed, 179 insertions(+), 1 deletion(-) diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index 46ba0fb27b14..11d5650c23c5 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h @@ -4203,6 +4203,8 @@ struct cfg80211_nan_band_config { * notifications. * @instant_comm: if true, start Instant Communication (IC) as defined in * Chapter 13 of the Wi-Fi Aware Specification v4.0. + * @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 * &enum nl80211_band values. * @extra_nan_attrs: pointer to additional NAN attributes. @@ -4219,6 +4221,8 @@ struct cfg80211_nan_conf { u8 discovery_beacon_interval; bool enable_dw_notification; bool instant_comm; + bool pairing_setup; + bool pairing_npk_caching; struct cfg80211_nan_band_config band_cfgs[NUM_NL80211_BANDS]; const u8 *extra_nan_attrs; u16 extra_nan_attrs_len; @@ -4395,6 +4399,18 @@ 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. + * @data_path_required: if true, the SDEA Data Path Required bit is set. + * @security_required: if true, the SDEA Security Required bit is set. Requires + * @data_path_required and %NL80211_EXT_FEATURE_SECURE_NAN. + * @gtk_required: if true, the SDEA GTK Required bit is set for GTK protection + * of group-addressed data frames. Requires %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: 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. */ struct cfg80211_nan_func { enum nl80211_nan_function_type type; @@ -4421,6 +4437,14 @@ struct cfg80211_nan_func { u8 num_rx_filters; u8 instance_id; u64 cookie; + bool data_path_required; + bool security_required; + bool gtk_required; + u16 pairing_bootstrap_methods; + u32 *csids; + u8 num_csids; + const u8 *nd_pmk; + u8 nd_pmk_len; }; /** diff --git a/include/uapi/linux/nl80211.h b/include/uapi/linux/nl80211.h index b56a96f57bec..4037a0f78ef6 100644 --- a/include/uapi/linux/nl80211.h +++ b/include/uapi/linux/nl80211.h @@ -7753,6 +7753,24 @@ 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_DATA_PATH_REQUIRED: flag attribute. Sets the SDEA "Data + * Path Required" bit. + * @NL80211_NAN_FUNC_SECURITY_REQUIRED: flag attribute. Sets the SDEA + * "Security Required" bit. Requires + * @NL80211_NAN_FUNC_DATA_PATH_REQUIRED and + * %NL80211_EXT_FEATURE_SECURE_NAN. + * @NL80211_NAN_FUNC_GTK_REQUIRED: flag attribute. Sets the SDEA "GTK + * Required" bit for GTK protection of group-addressed data frames. + * Requires %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. Requires + * %NL80211_EXT_FEATURE_SECURE_NAN. + * @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_ND_PMK: pre-shared NAN Data Path PMK (ND-PMK); its length + * depends on the cipher suite. Requires %NL80211_EXT_FEATURE_SECURE_NAN. * * @NUM_NL80211_NAN_FUNC_ATTR: internal * @NL80211_NAN_FUNC_ATTR_MAX: highest NAN function attribute @@ -7775,6 +7793,12 @@ enum nl80211_nan_func_attributes { NL80211_NAN_FUNC_TX_MATCH_FILTER, NL80211_NAN_FUNC_INSTANCE_ID, NL80211_NAN_FUNC_TERM_REASON, + NL80211_NAN_FUNC_DATA_PATH_REQUIRED, + NL80211_NAN_FUNC_SECURITY_REQUIRED, + NL80211_NAN_FUNC_GTK_REQUIRED, + NL80211_NAN_FUNC_PAIRING_BOOTSTRAP_METHODS, + NL80211_NAN_FUNC_CSIDS, + NL80211_NAN_FUNC_ND_PMK, /* keep last */ NUM_NL80211_NAN_FUNC_ATTR, @@ -7916,6 +7940,16 @@ enum nl80211_nan_band_conf_attributes { * Wi-Fi Aware Specification v4.0. * %NL80211_NAN_CONF_DISCOVERY_BEACON_INTERVAL must be set as well. * This is a flag attribute. + * @NL80211_NAN_CONF_PAIRING_SETUP: flag attribute. Enables NAN pairing setup + * and is advertised as "Pairing Setup Enabled" in the DCEA. Only valid for + * devices that offload the NAN Discovery Engine (i.e. without + * %NL80211_NAN_CAPA_USERSPACE_DE) and requires + * %NL80211_EXT_FEATURE_SECURE_NAN. + * @NL80211_NAN_CONF_PAIRING_NPK_CACHING: flag attribute. Enables NPK/NIK + * caching and is advertised as "NPK/NIK Caching Enabled" in the DCEA. Only + * valid for devices that offload the NAN Discovery Engine (i.e. without + * %NL80211_NAN_CAPA_USERSPACE_DE) and requires + * %NL80211_EXT_FEATURE_SECURE_NAN. * @NUM_NL80211_NAN_CONF_ATTR: Internal. * @NL80211_NAN_CONF_ATTR_MAX: Highest NAN configuration attribute. * @@ -7932,6 +7966,8 @@ enum nl80211_nan_conf_attributes { NL80211_NAN_CONF_DISCOVERY_BEACON_INTERVAL, NL80211_NAN_CONF_NOTIFY_DW, NL80211_NAN_CONF_INSTANT_COMM, + NL80211_NAN_CONF_PAIRING_SETUP, + NL80211_NAN_CONF_PAIRING_NPK_CACHING, /* keep last */ NUM_NL80211_NAN_CONF_ATTR, diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index 858baaff9db9..1331fe716985 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -432,6 +432,34 @@ static int validate_nan_cluster_id(const struct nlattr *attr, return 0; } +static int validate_nan_csids(const struct nlattr *attr, + struct netlink_ext_ack *extack) +{ + unsigned int len = nla_len(attr); + + if (!len || len % sizeof(u32)) { + NL_SET_ERR_MSG_ATTR(extack, attr, + "CSIDs must be a non-empty array of u32 values"); + return -EINVAL; + } + + return 0; +} + +static int validate_nan_pmk(const struct nlattr *attr, + struct netlink_ext_ack *extack) +{ + unsigned int len = nla_len(attr); + + if (len != WLAN_PMK_LEN && len != WLAN_PMK_LEN_SUITE_B_192) { + NL_SET_ERR_MSG_ATTR(extack, attr, + "ND-PMK length must be 32 or 48 octets"); + return -EINVAL; + } + + return 0; +} + static int validate_nan_avail_blob(const struct nlattr *attr, struct netlink_ext_ack *extack) { @@ -787,6 +815,8 @@ nl80211_nan_conf_policy[NL80211_NAN_CONF_ATTR_MAX + 1] = { NLA_POLICY_RANGE(NLA_U8, 50, 200), [NL80211_NAN_CONF_NOTIFY_DW] = { .type = NLA_FLAG }, [NL80211_NAN_CONF_INSTANT_COMM] = { .type = NLA_FLAG }, + [NL80211_NAN_CONF_PAIRING_SETUP] = { .type = NLA_FLAG }, + [NL80211_NAN_CONF_PAIRING_NPK_CACHING] = { .type = NLA_FLAG }, }; static const struct netlink_range_validation nl80211_punct_bitmap_range = { @@ -1334,6 +1364,16 @@ 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_DATA_PATH_REQUIRED] = { .type = NLA_FLAG }, + [NL80211_NAN_FUNC_SECURITY_REQUIRED] = { .type = NLA_FLAG }, + [NL80211_NAN_FUNC_GTK_REQUIRED] = { .type = NLA_FLAG }, + [NL80211_NAN_FUNC_PAIRING_BOOTSTRAP_METHODS] = { .type = NLA_U16 }, + [NL80211_NAN_FUNC_CSIDS] = + NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_nan_csids, + U8_MAX * sizeof(u32)), + [NL80211_NAN_FUNC_ND_PMK] = + NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_nan_pmk, + WLAN_PMK_LEN_SUITE_B_192), }; /* policy for Service Response Filter attributes */ @@ -17243,6 +17283,27 @@ static int nl80211_parse_nan_conf(struct wiphy *wiphy, } } + if (attrs[NL80211_NAN_CONF_PAIRING_SETUP] || + attrs[NL80211_NAN_CONF_PAIRING_NPK_CACHING]) { + if (wiphy->nan_capa.flags & WIPHY_NAN_FLAGS_USERSPACE_DE) { + NL_SET_ERR_MSG(info->extack, + "Pairing configuration requires an offloaded NAN Discovery Engine"); + return -EOPNOTSUPP; + } + + if (!wiphy_ext_feature_isset(wiphy, + NL80211_EXT_FEATURE_SECURE_NAN)) { + NL_SET_ERR_MSG(info->extack, + "Pairing configuration requires SECURE_NAN"); + return -EOPNOTSUPP; + } + } + + conf->pairing_setup = + nla_get_flag(attrs[NL80211_NAN_CONF_PAIRING_SETUP]); + conf->pairing_npk_caching = + nla_get_flag(attrs[NL80211_NAN_CONF_PAIRING_NPK_CACHING]); + out: if (!conf->band_cfgs[NL80211_BAND_5GHZ].chan && (!conf->bands || conf->bands & BIT(NL80211_BAND_5GHZ))) { @@ -17581,6 +17642,60 @@ static int nl80211_nan_add_func(struct sk_buff *skb, goto out; } + func->data_path_required = + nla_get_flag(tb[NL80211_NAN_FUNC_DATA_PATH_REQUIRED]); + func->security_required = + nla_get_flag(tb[NL80211_NAN_FUNC_SECURITY_REQUIRED]); + func->gtk_required = nla_get_flag(tb[NL80211_NAN_FUNC_GTK_REQUIRED]); + + if (func->security_required && !func->data_path_required) { + NL_SET_ERR_MSG(info->extack, + "SDEA Security Required requires Data Path Required"); + err = -EINVAL; + goto out; + } + + if (func->security_required || func->gtk_required || + tb[NL80211_NAN_FUNC_PAIRING_BOOTSTRAP_METHODS] || + 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 = -EOPNOTSUPP; + goto out; + } + + if (tb[NL80211_NAN_FUNC_PAIRING_BOOTSTRAP_METHODS]) + func->pairing_bootstrap_methods = + nla_get_u16(tb[NL80211_NAN_FUNC_PAIRING_BOOTSTRAP_METHODS]); + + if (tb[NL80211_NAN_FUNC_CSIDS]) { + int len = nla_len(tb[NL80211_NAN_FUNC_CSIDS]); + int n = len / sizeof(u32); + + 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]) { + int len = nla_len(tb[NL80211_NAN_FUNC_ND_PMK]); + + func->nd_pmk = kmemdup(nla_data(tb[NL80211_NAN_FUNC_ND_PMK]), + len, GFP_KERNEL); + if (!func->nd_pmk) { + err = -ENOMEM; + goto out; + } + func->nd_pmk_len = len; + } + } + msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); if (!msg) { err = -ENOMEM; @@ -21051,7 +21166,8 @@ static const struct genl_small_ops nl80211_small_ops[] = { .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, .doit = nl80211_nan_add_func, .flags = GENL_ADMIN_PERM, - .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP), + .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP | + NL80211_FLAG_CLEAR_SKB), }, { .cmd = NL80211_CMD_DEL_NAN_FUNCTION, diff --git a/net/wireless/util.c b/net/wireless/util.c index 24cf0a2ba721..980b16c72d4f 100644 --- a/net/wireless/util.c +++ b/net/wireless/util.c @@ -2878,6 +2878,8 @@ 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); + kfree_sensitive(f->nd_pmk); for (i = 0; i < f->num_rx_filters; i++) kfree(f->rx_filters[i].filter); -- 2.34.1 Allow userspace to inspect every attribute in a received Service Discovery Frame when the NAN Discovery Engine is offloaded. Such frames can contain SDEA, NPBA, CSIA, SCIA, DCEA, and extended SSI. Report the complete received management frame, including the 802.11 header, in NL80211_ATTR_FRAME, along with its frequency and RSSI when available. This lets userspace parse attributes without requiring a separate nl80211 attribute for each. Document that the peer Service Info may contain the SSI from the SDA or the SDEA. Signed-off-by: Shivani Baranwal --- include/net/cfg80211.h | 21 +++++++++++++++++++-- include/uapi/linux/nl80211.h | 8 +++++++- net/wireless/nl80211.c | 13 +++++++++++-- 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index 11d5650c23c5..285aa6991efa 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h @@ -10584,8 +10584,20 @@ void cfg80211_free_nan_func(struct cfg80211_nan_func *f); * @inst_id: the local instance id * @peer_inst_id: the instance id of the peer's function * @addr: the MAC address of the peer - * @info_len: the length of the &info - * @info: the Service Specific Info from the peer (if any) + * @info_len: the length of @info + * @info: SSI from the peer, i.e. the Service Info of the Service Descriptor + * attribute (SDA) or the Service Info of the Service Descriptor Extension + * attribute (SDEA; extended SSI), whichever the peer used. + * @frame: complete management frame containing the received NAN SDF, + * including the 802.11 header (optional). It is reported as received and, + * for protected frames, after decryption, as with received frames reported + * with %NL80211_CMD_FRAME. This lets userspace distinguish protected + * (Protected Dual of Public Action) and unprotected frames. + * @frame_len: length of @frame + * @freq: frequency in MHz on which @frame was received, or 0 if unknown + * @rssi: received signal strength in dBm at the time of the match. + * Only valid when @rssi_valid is true. + * @rssi_valid: if true, @rssi contains a valid RSSI measurement. * @cookie: unique identifier of the corresponding function */ struct cfg80211_nan_match_params { @@ -10595,6 +10607,11 @@ struct cfg80211_nan_match_params { const u8 *addr; u8 info_len; const u8 *info; + const u8 *frame; + size_t frame_len; + u32 freq; + s32 rssi; + bool rssi_valid; u64 cookie; }; diff --git a/include/uapi/linux/nl80211.h b/include/uapi/linux/nl80211.h index 4037a0f78ef6..38dd596b54c2 100644 --- a/include/uapi/linux/nl80211.h +++ b/include/uapi/linux/nl80211.h @@ -1127,7 +1127,13 @@ * only a subset was changed. * @NL80211_CMD_NAN_MATCH: Notification sent when a match is reported. * This will contain a %NL80211_ATTR_NAN_MATCH nested attribute and - * %NL80211_ATTR_COOKIE. + * %NL80211_ATTR_COOKIE. It may also contain %NL80211_ATTR_FRAME, + * %NL80211_ATTR_WIPHY_FREQ, and %NL80211_ATTR_RX_SIGNAL_DBM so userspace + * can parse any attribute in the received SDF. The frame is the complete + * received management frame, including the 802.11 header. It is reported as + * received and, for protected frames, after decryption, as with received + * frames reported with %NL80211_CMD_FRAME. This lets userspace distinguish + * protected (Protected Dual of Public Action) and unprotected frames. * * @NL80211_CMD_UPDATE_CONNECT_PARAMS: Update one or more connect parameters * for subsequent roaming cases if the driver or firmware uses internal diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index 1331fe716985..44d512675065 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -17850,7 +17850,10 @@ void cfg80211_nan_match(struct wireless_dev *wdev, if (WARN_ON(!match->inst_id || !match->peer_inst_id || !match->addr)) return; - msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); + if (WARN_ON_ONCE(match->frame_len && !match->frame)) + return; + + msg = nlmsg_new(NLMSG_DEFAULT_SIZE + match->frame_len, gfp); if (!msg) return; @@ -17869,7 +17872,13 @@ void cfg80211_nan_match(struct wireless_dev *wdev, if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, match->cookie, NL80211_ATTR_PAD) || - nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, match->addr)) + nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, match->addr) || + (match->frame && match->frame_len && + nla_put(msg, NL80211_ATTR_FRAME, match->frame_len, match->frame)) || + (match->freq && + nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, match->freq)) || + (match->rssi_valid && + nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, match->rssi))) goto nla_put_failure; match_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_MATCH); -- 2.34.1 From: Kavita Kavita Add NL80211_PMSR_FTM_TYPE_CAPA_ATTR_NAN_SUPPORT to the FTM type capability enum so that userspace (e.g., wpa_supplicant) can query whether the driver supports FTM-based ranging within a NAN Ranging Session before initiating a NAN Ranging Request. Add the corresponding nan_support bit to cfg80211_pmsr_capabilities and include it in the capability advertisement in nl80211_send_pmsr_ftm_capa(). NAN ranging always uses ASAP and a single burst, independent of the generic ASAP capability. Signed-off-by: Kavita Kavita Signed-off-by: Shivani Baranwal --- include/net/cfg80211.h | 6 +++++- include/uapi/linux/nl80211.h | 6 ++++++ net/wireless/nl80211.c | 7 ++++++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index 285aa6991efa..91bc06a46a3f 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h @@ -6246,6 +6246,9 @@ cfg80211_get_iftype_ext_capa(struct wiphy *wiphy, enum nl80211_iftype type); * @ftm.type.pd_support: supports peer-to-peer ranging as mentioned in the * specification "PR Implementation Consideration Draft 1.9 rev 1" where * PD stands for proximity detection + * @ftm.type.nan_support: supports NAN ranging as defined in + * the "Wi-Fi Aware Specification v4.0, clause 8". NAN ranging always uses + * ASAP and a single burst, regardless of @ftm.asap. * @ftm.concurrent_ista_rsta_support: indicates if the device can * simultaneously act as initiator and responder in a multi-peer * measurement request. Only valid if @ftm.rsta_support is set. @@ -6296,7 +6299,8 @@ struct cfg80211_pmsr_capabilities { u32 min_allowed_ranging_interval_ntb; struct { u8 infra_support:1, - pd_support:1; + pd_support:1, + nan_support:1; } type; u8 concurrent_ista_rsta_support:1; u32 pd_preambles; diff --git a/include/uapi/linux/nl80211.h b/include/uapi/linux/nl80211.h index 38dd596b54c2..bd18cb922310 100644 --- a/include/uapi/linux/nl80211.h +++ b/include/uapi/linux/nl80211.h @@ -8439,6 +8439,11 @@ enum nl80211_peer_measurement_ftm_capa { * the device supports peer-to-peer ranging as mentioned in the * specification "PR Implementation Consideration Draft 1.9 rev 1" where * PD stands for proximity detection + * @NL80211_PMSR_FTM_TYPE_CAPA_ATTR_NAN_SUPPORT: flag attribute indicating + * that the device supports NAN ranging between two NAN devices as + * defined in the "Wi-Fi Aware Specification v4.0, clause 8". NAN ranging + * uses ASAP and a single burst, irrespective of whether + * %NL80211_PMSR_FTM_CAPA_ATTR_ASAP is advertised. * * @NUM_NL80211_PMSR_FTM_TYPE_CAPA_ATTR: internal * @NL80211_PMSR_FTM_TYPE_CAPA_ATTR_MAX: highest attribute number @@ -8448,6 +8453,7 @@ enum nl80211_peer_measurement_ftm_type_capa { NL80211_PMSR_FTM_TYPE_CAPA_ATTR_INFRA_SUPPORT, NL80211_PMSR_FTM_TYPE_CAPA_ATTR_PD_SUPPORT, + NL80211_PMSR_FTM_TYPE_CAPA_ATTR_NAN_SUPPORT, /* keep last */ NUM_NL80211_PMSR_FTM_TYPE_CAPA_ATTR, diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index 44d512675065..ca08b40baf96 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -2770,7 +2770,8 @@ nl80211_send_pmsr_ftm_capa(const struct cfg80211_pmsr_capabilities *cap, cap->ftm.min_allowed_ranging_interval_ntb)) return -ENOBUFS; - if (cap->ftm.type.infra_support || cap->ftm.type.pd_support) { + if (cap->ftm.type.infra_support || cap->ftm.type.pd_support || + cap->ftm.type.nan_support) { struct nlattr *pd_caps; pd_caps = nla_nest_start_noflag(msg, @@ -2786,6 +2787,10 @@ nl80211_send_pmsr_ftm_capa(const struct cfg80211_pmsr_capabilities *cap, nla_put_flag(msg, NL80211_PMSR_FTM_TYPE_CAPA_ATTR_PD_SUPPORT)) return -ENOBUFS; + if (cap->ftm.type.nan_support && + nla_put_flag(msg, NL80211_PMSR_FTM_TYPE_CAPA_ATTR_NAN_SUPPORT)) + return -ENOBUFS; + nla_nest_end(msg, pd_caps); } -- 2.34.1 From: Kavita Kavita Add NL80211_NAN_CAPA_OFFLOAD_RANGING so userspace (e.g., wpa_supplicant) can determine whether firmware supports fully offloaded NAN ranging before starting a NAN ranging session. Add WIPHY_NAN_FLAGS_OFFLOAD_RANGING for drivers to report this capability and expose it through the NAN capabilities handler. Fully offloaded NAN ranging includes ranging session setup, update, and termination, FTM protocol and procedure, and ranging report. Signed-off-by: Kavita Kavita Signed-off-by: Shivani Baranwal --- include/net/cfg80211.h | 4 ++++ include/uapi/linux/nl80211.h | 4 ++++ net/wireless/nl80211.c | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index 91bc06a46a3f..2c5f1a7e5722 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h @@ -6383,11 +6383,15 @@ 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_RANGING: Firmware supports fully offloaded NAN + * ranging procedure, including ranging session setup, update, and + * termination, FTM protocol and procedure, and ranging report. */ 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_RANGING = BIT(3), }; /** diff --git a/include/uapi/linux/nl80211.h b/include/uapi/linux/nl80211.h index bd18cb922310..17b3bbc04d8b 100644 --- a/include/uapi/linux/nl80211.h +++ b/include/uapi/linux/nl80211.h @@ -9201,6 +9201,9 @@ enum nl80211_s1g_short_beacon_attrs { * of the Wi-Fi Aware Specification v4.0. Can only be set if * %NL80211_NAN_CAPA_CONFIGURABLE_SYNC is set. When IC is enabled, the IC * schedule is expected to be configured by user space. + * @NL80211_NAN_CAPA_OFFLOAD_RANGING: flag attribute. Firmware supports the + * fully offloaded NAN ranging procedure, including ranging session setup, + * update, and termination, FTM protocol and procedure, and ranging reports. * @__NL80211_NAN_CAPABILITIES_LAST: Internal * @NL80211_NAN_CAPABILITIES_MAX: Highest NAN capability attribute. */ @@ -9215,6 +9218,7 @@ enum nl80211_nan_capabilities { NL80211_NAN_CAPA_CAPABILITIES, NL80211_NAN_CAPA_PHY, NL80211_NAN_CAPA_INSTANT_COMM, + NL80211_NAN_CAPA_OFFLOAD_RANGING, /* keep last */ __NL80211_NAN_CAPABILITIES_LAST, NL80211_NAN_CAPABILITIES_MAX = __NL80211_NAN_CAPABILITIES_LAST - 1, diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index ca08b40baf96..3c9847a83311 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -3183,6 +3183,10 @@ static int nl80211_put_nan_capa(struct wiphy *wiphy, struct sk_buff *msg) nla_put_flag(msg, NL80211_NAN_CAPA_INSTANT_COMM)) goto fail; + if ((wiphy->nan_capa.flags & WIPHY_NAN_FLAGS_OFFLOAD_RANGING) && + nla_put_flag(msg, NL80211_NAN_CAPA_OFFLOAD_RANGING)) + goto fail; + if (nla_put_u8(msg, NL80211_NAN_CAPA_OP_MODE, wiphy->nan_capa.op_mode) || nla_put_u8(msg, NL80211_NAN_CAPA_NUM_ANTENNAS, -- 2.34.1 From: Kavita Kavita Extend the peer measurement framework with a NAN FTM request type to allow userspace (e.g., wpa_supplicant) to initiate a NAN Ranging Request in offload mode. Extend the nl80211 parser to handle NAN-specific FTM parameters and validate the request type so the driver/firmware can identify and trigger the NAN Ranging Session on behalf of userspace. Reject the request if it is a NAN Ranging Request and the interface is not a NAN interface, as mandated by the Wi-Fi Aware Specification, or if the driver does not advertise NAN ranging capability. Treat ASAP and single burst as inherent to NAN ranging. Userspace need not request generic ASAP mode, and NUM_BURSTS_EXP must be zero if set. Signed-off-by: Kavita Kavita Signed-off-by: Shivani Baranwal --- include/net/cfg80211.h | 10 +++- include/uapi/linux/nl80211.h | 13 +++++ net/wireless/nl80211.c | 5 +- net/wireless/nl80211.h | 3 + net/wireless/pmsr.c | 110 ++++++++++++++++++++++++++++++++++- 5 files changed, 138 insertions(+), 3 deletions(-) diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index 2c5f1a7e5722..82cd89766ee4 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h @@ -4729,6 +4729,8 @@ struct cfg80211_pmsr_result { * @trigger_based or @non_trigger_based is set. * @rsta: Operate as the RSTA in the measurement. Only valid if @lmr_feedback * and either @trigger_based or @non_trigger_based is set. + * Also valid when @range_report is set and @request_type is + * %NL80211_PMSR_FTM_REQ_TYPE_NAN. * @bss_color: the bss color of the responder. Optional. Set to zero to * indicate the driver should set the BSS color. Only valid if * @non_trigger_based or @trigger_based is set. @@ -4774,6 +4776,10 @@ struct cfg80211_pmsr_result { * provide ranging services to a peer (e.g. in RSTA role) but does * not report the measurement results to userspace. Only valid when * @request_type is %NL80211_PMSR_FTM_REQ_TYPE_PD. + * @range_report: a NAN Ranging Report is required after the FTM session. + * Only valid for a NAN RSTA request. + * @min_delta_ftm: NAN Min Delta FTM value in units of 100 microseconds. + * Zero indicates no preference. * * See also nl80211 for the respective attribute documentation. */ @@ -4790,6 +4796,7 @@ struct cfg80211_pmsr_ftm_request_peer { rsta:1; u8 num_bursts_exp; u8 burst_duration; + u8 min_delta_ftm; u8 ftms_per_burst; u8 ftmr_retries; u8 bss_color; @@ -4802,7 +4809,8 @@ struct cfg80211_pmsr_ftm_request_peer { u32 num_measurements; u64 ingress_distance; u64 egress_distance; - u8 pd_suppress_range_results:1; + u8 pd_suppress_range_results:1, + range_report:1; }; /** diff --git a/include/uapi/linux/nl80211.h b/include/uapi/linux/nl80211.h index 17b3bbc04d8b..f4d7e259a777 100644 --- a/include/uapi/linux/nl80211.h +++ b/include/uapi/linux/nl80211.h @@ -8185,12 +8185,18 @@ enum nl80211_peer_measurement_resp { * @NL80211_PMSR_FTM_REQ_TYPE_PD: peer-to-peer ranging as defined in the * Wi-Fi Alliance specification "Proximity Ranging (PR) Implementation * Consideration Draft 1.9 Rev 1" + * @NL80211_PMSR_FTM_REQ_TYPE_NAN: NAN ranging between two NAN devices as + * defined in the "Wi-Fi Aware Specification v4.0, clause 8". + * Must be issued on a %NL80211_IFTYPE_NAN interface. + * ASAP mode and a single burst are implied. If + * %NL80211_PMSR_FTM_REQ_ATTR_NUM_BURSTS_EXP is present, it must be zero. * @NUM_NL80211_PMSR_FTM_REQ_TYPE: internal * @NL80211_PMSR_FTM_REQ_TYPE_MAX: highest request type value */ enum nl80211_peer_measurement_ftm_req_type { NL80211_PMSR_FTM_REQ_TYPE_INFRA, NL80211_PMSR_FTM_REQ_TYPE_PD, + NL80211_PMSR_FTM_REQ_TYPE_NAN, /* keep last */ NUM_NL80211_PMSR_FTM_REQ_TYPE, @@ -8560,6 +8566,11 @@ enum nl80211_peer_measurement_ftm_type_capa { * but results are not reported to userspace, regardless of ranging role * or type. Only valid when %NL80211_PMSR_PEER_ATTR_REQ_TYPE is set to * %NL80211_PMSR_FTM_REQ_TYPE_PD. + * @NL80211_PMSR_FTM_REQ_ATTR_RANGE_REPORT: Flag indicating that a NAN + * Ranging Report is required after the FTM session. Only valid for a NAN + * RSTA request. + * @NL80211_PMSR_FTM_REQ_ATTR_MIN_DELTA_FTM: NAN Min Delta FTM value in units + * of 100 microseconds (u8, 0-63). A value of 0 indicates no preference. * * @NUM_NL80211_PMSR_FTM_REQ_ATTR: internal * @NL80211_PMSR_FTM_REQ_ATTR_MAX: highest attribute number @@ -8590,6 +8601,8 @@ enum nl80211_peer_measurement_ftm_req { NL80211_PMSR_FTM_REQ_ATTR_INGRESS, NL80211_PMSR_FTM_REQ_ATTR_EGRESS, NL80211_PMSR_FTM_REQ_ATTR_PD_SUPPRESS_RESULTS, + NL80211_PMSR_FTM_REQ_ATTR_RANGE_REPORT, + NL80211_PMSR_FTM_REQ_ATTR_MIN_DELTA_FTM, /* keep last */ NUM_NL80211_PMSR_FTM_REQ_ATTR, diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index 3c9847a83311..c64b918f2748 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -585,7 +585,7 @@ nl80211_ftm_responder_policy[NL80211_FTM_RESP_ATTR_MAX + 1] = { .len = U8_MAX }, }; -static const struct nla_policy +const struct nla_policy nl80211_pmsr_ftm_req_attr_policy[NL80211_PMSR_FTM_REQ_ATTR_MAX + 1] = { [NL80211_PMSR_FTM_REQ_ATTR_ASAP] = { .type = NLA_FLAG }, [NL80211_PMSR_FTM_REQ_ATTR_PREAMBLE] = @@ -617,6 +617,9 @@ nl80211_pmsr_ftm_req_attr_policy[NL80211_PMSR_FTM_REQ_ATTR_MAX + 1] = { [NL80211_PMSR_FTM_REQ_ATTR_INGRESS] = { .type = NLA_U64 }, [NL80211_PMSR_FTM_REQ_ATTR_EGRESS] = { .type = NLA_U64 }, [NL80211_PMSR_FTM_REQ_ATTR_PD_SUPPRESS_RESULTS] = { .type = NLA_FLAG }, + [NL80211_PMSR_FTM_REQ_ATTR_RANGE_REPORT] = { .type = NLA_FLAG }, + [NL80211_PMSR_FTM_REQ_ATTR_MIN_DELTA_FTM] = + NLA_POLICY_MAX(NLA_U8, 63), }; static const struct nla_policy diff --git a/net/wireless/nl80211.h b/net/wireless/nl80211.h index bdb065d14054..31a2c2eb6276 100644 --- a/net/wireless/nl80211.h +++ b/net/wireless/nl80211.h @@ -126,6 +126,9 @@ void cfg80211_free_coalesce(struct cfg80211_coalesce *coalesce); /* peer measurement */ int nl80211_pmsr_start(struct sk_buff *skb, struct genl_info *info); +extern const struct nla_policy +nl80211_pmsr_ftm_req_attr_policy[NL80211_PMSR_FTM_REQ_ATTR_MAX + 1]; + void nl80211_mlo_reconf_add_done(struct net_device *dev, struct cfg80211_mlo_reconf_done_data *data); diff --git a/net/wireless/pmsr.c b/net/wireless/pmsr.c index 97449bcb9a22..d1e59042f10b 100644 --- a/net/wireless/pmsr.c +++ b/net/wireless/pmsr.c @@ -306,11 +306,98 @@ static int pmsr_parse_ftm(struct cfg80211_registered_device *rdev, return 0; } +static int pmsr_parse_ftm_nan(struct cfg80211_registered_device *rdev, + struct nlattr *ftmreq, + struct cfg80211_pmsr_request_peer *out, + struct genl_info *info) +{ + const struct cfg80211_pmsr_capabilities *capa = rdev->wiphy.pmsr_capa; + struct nlattr *tb[NL80211_PMSR_FTM_REQ_ATTR_MAX + 1]; + int err; + + err = nla_parse_nested(tb, NL80211_PMSR_FTM_REQ_ATTR_MAX, ftmreq, + nl80211_pmsr_ftm_req_attr_policy, + info->extack); + if (err) + return err; + + out->ftm.requested = true; + + /* NAN ranging always uses ASAP */ + out->ftm.asap = true; + + /* NAN ranging always uses a single burst */ + if (tb[NL80211_PMSR_FTM_REQ_ATTR_NUM_BURSTS_EXP] && + nla_get_u8(tb[NL80211_PMSR_FTM_REQ_ATTR_NUM_BURSTS_EXP]) != 0) { + NL_SET_ERR_MSG(info->extack, + "FTM: NAN ranging requires single burst"); + return -EINVAL; + } + + out->ftm.rsta = !!tb[NL80211_PMSR_FTM_REQ_ATTR_RSTA]; + out->ftm.range_report = + !!tb[NL80211_PMSR_FTM_REQ_ATTR_RANGE_REPORT]; + if (out->ftm.range_report && !out->ftm.rsta) { + NL_SET_ERR_MSG_ATTR(info->extack, + tb[NL80211_PMSR_FTM_REQ_ATTR_RANGE_REPORT], + "FTM: range report is valid only for NAN RSTA"); + return -EINVAL; + } + + if (tb[NL80211_PMSR_FTM_REQ_ATTR_PREAMBLE]) { + out->ftm.preamble = + nla_get_u32(tb[NL80211_PMSR_FTM_REQ_ATTR_PREAMBLE]); + if (!(capa->ftm.preambles & BIT(out->ftm.preamble))) { + NL_SET_ERR_MSG_ATTR(info->extack, + tb[NL80211_PMSR_FTM_REQ_ATTR_PREAMBLE], + "FTM: unsupported preamble for NAN ranging"); + return -EINVAL; + } + } + + if (tb[NL80211_PMSR_FTM_REQ_ATTR_FTMS_PER_BURST]) { + out->ftm.ftms_per_burst = + nla_get_u8(tb[NL80211_PMSR_FTM_REQ_ATTR_FTMS_PER_BURST]); + if (out->ftm.ftms_per_burst > 31) { + NL_SET_ERR_MSG_ATTR(info->extack, + tb[NL80211_PMSR_FTM_REQ_ATTR_FTMS_PER_BURST], + "FTM: NAN FTMs per burst exceeds limit of 31"); + return -EINVAL; + } + if (capa->ftm.max_ftms_per_burst && + out->ftm.ftms_per_burst > capa->ftm.max_ftms_per_burst) { + NL_SET_ERR_MSG_ATTR(info->extack, + tb[NL80211_PMSR_FTM_REQ_ATTR_FTMS_PER_BURST], + "FTM: FTMs per burst exceeds device limit"); + return -EINVAL; + } + } + + if (tb[NL80211_PMSR_FTM_REQ_ATTR_BURST_DURATION]) + out->ftm.burst_duration = + nla_get_u8(tb[NL80211_PMSR_FTM_REQ_ATTR_BURST_DURATION]); + + if (tb[NL80211_PMSR_FTM_REQ_ATTR_MIN_DELTA_FTM]) + out->ftm.min_delta_ftm = + nla_get_u8(tb[NL80211_PMSR_FTM_REQ_ATTR_MIN_DELTA_FTM]); + + if (tb[NL80211_PMSR_FTM_REQ_ATTR_INGRESS]) + out->ftm.ingress_distance = + nla_get_u64(tb[NL80211_PMSR_FTM_REQ_ATTR_INGRESS]); + + if (tb[NL80211_PMSR_FTM_REQ_ATTR_EGRESS]) + out->ftm.egress_distance = + nla_get_u64(tb[NL80211_PMSR_FTM_REQ_ATTR_EGRESS]); + + return 0; +} + static int pmsr_parse_peer(struct cfg80211_registered_device *rdev, struct nlattr *peer, struct cfg80211_pmsr_request_peer *out, struct genl_info *info) { + struct wireless_dev *wdev = info->user_ptr[1]; struct nlattr *tb[NL80211_PMSR_PEER_ATTR_MAX + 1]; struct nlattr *req[NL80211_PMSR_REQ_ATTR_MAX + 1]; bool have_measurement_type = false; @@ -344,6 +431,22 @@ static int pmsr_parse_peer(struct cfg80211_registered_device *rdev, "FTM: PD request type not supported by device"); return -EINVAL; } + + if (out->ftm.request_type == NL80211_PMSR_FTM_REQ_TYPE_NAN) { + if (!rdev->wiphy.pmsr_capa->ftm.type.nan_support) { + NL_SET_ERR_MSG_ATTR(info->extack, + tb[NL80211_PMSR_PEER_ATTR_REQ_TYPE], + "FTM: NAN ranging not supported by device"); + return -EOPNOTSUPP; + } + if (wdev->iftype != NL80211_IFTYPE_NAN) { + NL_SET_ERR_MSG_ATTR(info->extack, + tb[NL80211_PMSR_PEER_ATTR_REQ_TYPE], + "FTM: NAN ranging requires a NAN interface"); + return -EOPNOTSUPP; + } + } + /* reuse info->attrs */ memset(info->attrs, 0, sizeof(*info->attrs) * (NL80211_ATTR_MAX + 1)); err = nla_parse_nested_deprecated(info->attrs, NL80211_ATTR_MAX, @@ -390,7 +493,12 @@ static int pmsr_parse_peer(struct cfg80211_registered_device *rdev, switch (nla_type(treq)) { case NL80211_PMSR_TYPE_FTM: - err = pmsr_parse_ftm(rdev, treq, out, info); + if (out->ftm.request_type == + NL80211_PMSR_FTM_REQ_TYPE_NAN) + err = pmsr_parse_ftm_nan(rdev, treq, + out, info); + else + err = pmsr_parse_ftm(rdev, treq, out, info); break; default: NL_SET_ERR_MSG_ATTR(info->extack, treq, -- 2.34.1 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 82cd89766ee4..facd5d8bc5e1 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h @@ -4411,6 +4411,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; @@ -4445,6 +4459,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 f4d7e259a777..e71db9de3ef2 100644 --- a/include/uapi/linux/nl80211.h +++ b/include/uapi/linux/nl80211.h @@ -7777,6 +7777,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 @@ -7805,6 +7822,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 c64b918f2748..f86d593a1baf 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -1377,6 +1377,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 */ @@ -17708,6 +17718,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 From: Kavita Kavita Extend cfg80211_nan_match_params with ranging_indication and ranging_measurement fields to allow the driver/firmware to report NAN Ranging results as part of the NAN Service Match indication in offload mode. Add the corresponding attributes NL80211_NAN_MATCH_RANGING_INDICATION and NL80211_NAN_MATCH_RANGING_MEASUREMENT and serialize them in cfg80211_nan_match() so that userspace (e.g., wpa_supplicant) can receive the NAN Ranging Report along with the NAN Service Match event. Send ranging info to userspace only if ranging_indication is non-zero. ranging_indication is a bitmask with four valid combinations: - bit 0 set: continuous ranging - bit 1 set: ingress condition met - bit 2 set: egress condition met - bit 1 and bit 2 set: both ingress and egress conditions met Leave validation of the combination to userspace (e.g., wpa_supplicant). Signed-off-by: Kavita Kavita Signed-off-by: Shivani Baranwal --- include/net/cfg80211.h | 4 ++++ include/uapi/linux/nl80211.h | 8 ++++++++ net/wireless/nl80211.c | 11 +++++++++++ 3 files changed, 23 insertions(+) diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index facd5d8bc5e1..ef8c84aab332 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h @@ -10638,6 +10638,8 @@ void cfg80211_free_nan_func(struct cfg80211_nan_func *f); * Only valid when @rssi_valid is true. * @rssi_valid: if true, @rssi contains a valid RSSI measurement. * @cookie: unique identifier of the corresponding function + * @ranging_indication: bitmap indicating the type of ranging performed. + * @ranging_measurement: distance to the peer in millimetres. */ struct cfg80211_nan_match_params { enum nl80211_nan_function_type type; @@ -10652,6 +10654,8 @@ struct cfg80211_nan_match_params { s32 rssi; bool rssi_valid; u64 cookie; + u8 ranging_indication; + s32 ranging_measurement; }; /** diff --git a/include/uapi/linux/nl80211.h b/include/uapi/linux/nl80211.h index e71db9de3ef2..bc70a8e31af6 100644 --- a/include/uapi/linux/nl80211.h +++ b/include/uapi/linux/nl80211.h @@ -7872,6 +7872,12 @@ enum nl80211_nan_srf_attributes { * @NL80211_NAN_MATCH_FUNC_PEER: the peer function * that caused the match. This is a nested attribute. * See &enum nl80211_nan_func_attributes. + * @NL80211_NAN_MATCH_RANGING_INDICATION: u8 attribute. Bitmap indicating + * the type of ranging performed: bit 0: continuous ranging, + * bit 1: ingress condition met, bit 2: egress condition met, + * bit 1 and bit 2: both conditions met. Only present when non-zero. + * @NL80211_NAN_MATCH_RANGING_MEASUREMENT: s32 attribute. Distance to + * the peer in millimetres measured via FTM. * * @NUM_NL80211_NAN_MATCH_ATTR: internal * @NL80211_NAN_MATCH_ATTR_MAX: highest NAN match attribute @@ -7880,6 +7886,8 @@ enum nl80211_nan_match_attributes { __NL80211_NAN_MATCH_INVALID, NL80211_NAN_MATCH_FUNC_LOCAL, NL80211_NAN_MATCH_FUNC_PEER, + NL80211_NAN_MATCH_RANGING_INDICATION, + NL80211_NAN_MATCH_RANGING_MEASUREMENT, /* keep last */ NUM_NL80211_NAN_MATCH_ATTR, diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index f86d593a1baf..97ee36dd8b11 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -18023,6 +18023,17 @@ void cfg80211_nan_match(struct wireless_dev *wdev, goto nla_put_failure; nla_nest_end(msg, peer_func_attr); + + /* report ranging info only if ranging was indicated */ + if (match->ranging_indication) { + if (nla_put_u8(msg, NL80211_NAN_MATCH_RANGING_INDICATION, + match->ranging_indication)) + goto nla_put_failure; + + if (nla_put_s32(msg, NL80211_NAN_MATCH_RANGING_MEASUREMENT, + match->ranging_measurement)) + goto nla_put_failure; + } nla_nest_end(msg, match_attr); genlmsg_end(msg, hdr); -- 2.34.1 Advertise whether a device performs the complete NAN Data Path setup and teardown handshake, including security negotiation. An offload device assigns NDP IDs for locally initiated sessions and derives and installs the data path keys, including GTK when requested. Expose the capability through the NAN capabilities response so userspace can determine whether the device supports the NAN NDP commands and notifications. Secure NDPs additionally require SECURE_NAN. NDP Request/Response/Confirm frames carry the NDL attribute and NAN Availability, so the device that runs the handshake owns the schedule. Userspace schedule configuration would conflict with that negotiated state. Reject NL80211_CMD_NAN_SET_LOCAL_SCHED, NL80211_CMD_NAN_SET_PEER_SCHED, and NL80211_CMD_NAN_SET_NON_EVAC_CHANNELS for such devices. Signed-off-by: Shivani Baranwal --- include/net/cfg80211.h | 25 +++++++++++++++++++++++-- include/uapi/linux/nl80211.h | 35 ++++++++++++++++++++++++++++++++--- net/wireless/nl80211.c | 30 +++++++++++++++++++++++++++++- 3 files changed, 84 insertions(+), 6 deletions(-) diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index ef8c84aab332..60152bc5aa9a 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h @@ -5302,7 +5302,8 @@ struct mgmt_frame_regs { * in which each entry maps each time slot to the channel on which the * radio should operate on. If the chandef of a NAN channel is not * changed, the channel entry must also remain unchanged. It is the - * driver's responsibility to verify this. + * driver's responsibility to verify this. Not supported when + * %WIPHY_NAN_FLAGS_OFFLOAD_NDP is set; the device manages the schedule. * @nan_set_peer_sched: configure the peer schedule for NAN. The schedule * consists of an array of %cfg80211_nan_channel and the schedule itself, * in which each entry maps each time slot to a channel on which the @@ -5310,12 +5311,16 @@ struct mgmt_frame_regs { * information such as committed DW, etc. When updating an existing peer * schedule, the full new schedule is provided - partial updates are not * supported, and the new schedule completely replaces the previous one. + * Not supported when %WIPHY_NAN_FLAGS_OFFLOAD_NDP is set; the device learns + * and manages peer schedules. * * @nan_set_non_evac_channels: set the list of local schedule channels that * must not be evacuated for concurrent operations. The provided list * replaces the previous set; channels of the current schedule that are * not included become evacuable again. All provided channels are - * guaranteed by cfg80211 to belong to the current local schedule. + * guaranteed by cfg80211 to belong to the current local schedule. Not + * supported when %WIPHY_NAN_FLAGS_OFFLOAD_NDP is set; the device manages + * channel evacuation. * * @set_multicast_to_unicast: configure multicast to unicast conversion for BSS * @@ -6417,12 +6422,28 @@ struct wiphy_radio { * @WIPHY_NAN_FLAGS_OFFLOAD_RANGING: Firmware supports fully offloaded NAN * ranging procedure, including ranging session setup, update, and * termination, FTM protocol and procedure, and ranging report. + * @WIPHY_NAN_FLAGS_OFFLOAD_NDP: Device offloads the complete NDP setup and + * teardown handshake with its peer, including NDP Request/Response/Confirm + * and security handshakes. It negotiates the NDL and manages local and peer + * NAN schedules, including NDC and immutable schedules, ULW, schedule updates, + * and evacuation of its own channels. It assigns NDP IDs for locally initiated + * NDPs, derives, installs, and removes PTKs and, when requested, GTKs. The + * device creates and removes NDI peer stations for offloaded NDPs. Userspace + * must not configure NAN schedules or add those NDI peer stations or their + * keys. The driver implements @nan_ndp_initiate, @nan_ndp_respond, and + * @nan_ndp_terminate callbacks. It supports %NL80211_CMD_NAN_NDP_INITIATE, + * %NL80211_CMD_NAN_NDP_RESPOND, and %NL80211_CMD_NAN_NDP_TERMINATE, and + * reports peer requests, setup status, and termination with + * cfg80211_nan_ndp_request(), cfg80211_nan_ndp_status(), and + * cfg80211_nan_ndp_terminated(). Secure NDPs require + * %NL80211_EXT_FEATURE_SECURE_NAN. */ 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_RANGING = BIT(3), + WIPHY_NAN_FLAGS_OFFLOAD_NDP = BIT(4), }; /** diff --git a/include/uapi/linux/nl80211.h b/include/uapi/linux/nl80211.h index bc70a8e31af6..3406e37df5c4 100644 --- a/include/uapi/linux/nl80211.h +++ b/include/uapi/linux/nl80211.h @@ -397,7 +397,9 @@ * %NL80211_ATTR_KEY_IDX, %NL80211_ATTR_MAC, %NL80211_ATTR_KEY_CIPHER, * and %NL80211_ATTR_KEY_SEQ attributes. %NL80211_ATTR_MAC represents * peer's MLD address for MLO pairwise key. The link to add MLO - * group key is identified by %NL80211_ATTR_MLO_LINK_ID. + * group key is identified by %NL80211_ATTR_MLO_LINK_ID. For an NDI peer + * station participating in an offloaded NDP, userspace must not add keys; + * the device manages the NDP keys. * @NL80211_CMD_DEL_KEY: delete a key identified by %NL80211_ATTR_KEY_IDX * or %NL80211_ATTR_MAC. %NL80211_ATTR_MAC represents peer's MLD address * for MLO pairwise key. The link to delete group key is identified by @@ -430,7 +432,9 @@ * @NL80211_CMD_SET_STATION: Set station attributes for station identified by * %NL80211_ATTR_MAC on the interface identified by %NL80211_ATTR_IFINDEX. * @NL80211_CMD_NEW_STATION: Add a station with given attributes to the - * interface identified by %NL80211_ATTR_IFINDEX. + * interface identified by %NL80211_ATTR_IFINDEX. For an offloaded NDP, + * the device creates and removes the NDI peer station; userspace must not + * add a duplicate station. * @NL80211_CMD_DEL_STATION: Remove a station identified by %NL80211_ATTR_MAC * or, if no MAC address given, all stations, on the interface identified * by %NL80211_ATTR_IFINDEX. For MLD station, MLD address is used in @@ -1396,6 +1400,8 @@ * channels that remain in the new schedule keep their marking, channels * that are removed simply lose it, and newly added channels are * evacuable by default. + * Not supported when %NL80211_NAN_CAPA_OFFLOAD_NDP is advertised; the + * device manages the local NAN schedule for offloaded NDPs. * @NL80211_CMD_NAN_SCHED_UPDATE_DONE: Event sent to user space to notify that * a deferred local NAN schedule update (requested with * %NL80211_CMD_NAN_SET_LOCAL_SCHED and %NL80211_ATTR_NAN_SCHED_DEFERRED) @@ -1403,6 +1409,8 @@ * indicates that the update was successful. * @NL80211_CMD_NAN_SET_PEER_SCHED: Set the peer NAN schedule. NAN * must be operational (%NL80211_CMD_START_NAN was executed). + * Not supported when %NL80211_NAN_CAPA_OFFLOAD_NDP is advertised; the + * device learns and manages peer schedules for offloaded NDPs. * Required attributes: %NL80211_ATTR_MAC (peer NMI address) and * %NL80211_ATTR_NAN_COMMITTED_DW. * Optionally, the full schedule can be provided by including all of: @@ -1464,6 +1472,8 @@ * keep their non-evacuable marking, removed channels lose it, and newly * added channels are evacuable by default; issue this command again to * change the non-evacuable set. + * Not supported when %NL80211_NAN_CAPA_OFFLOAD_NDP is advertised; the + * device manages channel evacuation for offloaded NDPs. * @NL80211_CMD_UPDATE_BEACON: Update the beacon and other templates of an AP * interface, but only that. Same attributes as %NL80211_CMD_SET_BEACON, * %NL80211_ATTR_BEACON_HEAD and %NL80211_ATTR_BEACON_TAIL are required, @@ -3176,7 +3186,8 @@ enum nl80211_commands { * the update failed. * @NL80211_ATTR_NAN_NMI_MAC: The address of the NMI station to which this NDI * station belongs. Used with %NL80211_CMD_NEW_STATION when adding an NDI - * station. + * station. With %NL80211_NAN_CAPA_OFFLOAD_NDP, the device creates and removes + * NDI peer stations for offloaded NDPs; userspace must not add duplicates. * @NL80211_ATTR_NAN_ULW: (Binary) The initial ULW(s) as published by the * peer, as defined in the Wi-Fi Aware (TM) 4.0 specification Table 109 * (Unaligned Schedule attribute format). Used to configure the device @@ -9250,6 +9261,23 @@ enum nl80211_s1g_short_beacon_attrs { * @NL80211_NAN_CAPA_OFFLOAD_RANGING: flag attribute. Firmware supports the * fully offloaded NAN ranging procedure, including ranging session setup, * update, and termination, FTM protocol and procedure, and ranging reports. + * @NL80211_NAN_CAPA_OFFLOAD_NDP: flag attribute. The device performs the + * complete NAN Data Path setup and teardown handshake with the peer, + * including NDP Request/Response/Confirm and the security handshake. It + * negotiates the NDL and manages local and peer NAN schedules, including NDC + * and immutable schedules, ULW, schedule updates, and evacuation of its own + * channels. It assigns NDP IDs for locally initiated NDPs and derives, + * installs, and removes data path keys (PTK and, when requested, GTK). The + * device creates and removes NDI peer stations for offloaded NDPs. Userspace + * must not configure NAN schedules or add those NDI peer stations or their + * keys. In particular, %NL80211_CMD_NAN_SET_LOCAL_SCHED, + * %NL80211_CMD_NAN_SET_PEER_SCHED, and + * %NL80211_CMD_NAN_SET_NON_EVAC_CHANNELS are not supported. The device + * supports %NL80211_CMD_NAN_NDP_INITIATE, %NL80211_CMD_NAN_NDP_RESPOND, and + * %NL80211_CMD_NAN_NDP_TERMINATE, and reports peer requests, setup status, + * and termination with %NL80211_CMD_NAN_NDP_INITIATE, + * %NL80211_CMD_NAN_NDP_STATUS, and %NL80211_CMD_NAN_NDP_TERMINATE. + * Secure NDPs additionally require %NL80211_EXT_FEATURE_SECURE_NAN. * @__NL80211_NAN_CAPABILITIES_LAST: Internal * @NL80211_NAN_CAPABILITIES_MAX: Highest NAN capability attribute. */ @@ -9265,6 +9293,7 @@ enum nl80211_nan_capabilities { NL80211_NAN_CAPA_PHY, NL80211_NAN_CAPA_INSTANT_COMM, NL80211_NAN_CAPA_OFFLOAD_RANGING, + NL80211_NAN_CAPA_OFFLOAD_NDP, /* keep last */ __NL80211_NAN_CAPABILITIES_LAST, NL80211_NAN_CAPABILITIES_MAX = __NL80211_NAN_CAPABILITIES_LAST - 1, diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index 97ee36dd8b11..4bcb62a0172f 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -3200,6 +3200,10 @@ static int nl80211_put_nan_capa(struct wiphy *wiphy, struct sk_buff *msg) nla_put_flag(msg, NL80211_NAN_CAPA_OFFLOAD_RANGING)) goto fail; + if ((wiphy->nan_capa.flags & WIPHY_NAN_FLAGS_OFFLOAD_NDP) && + nla_put_flag(msg, NL80211_NAN_CAPA_OFFLOAD_NDP)) + goto fail; + if (nla_put_u8(msg, NL80211_NAN_CAPA_OP_MODE, wiphy->nan_capa.op_mode) || nla_put_u8(msg, NL80211_NAN_CAPA_NUM_ANTENNAS, @@ -18327,6 +18331,18 @@ static int nl80211_nan_validate_map_pair(struct genl_info *info, return 0; } +static int +nl80211_nan_sched_offload_check(struct wiphy *wiphy, + struct genl_info *info) +{ + if (!(wiphy->nan_capa.flags & WIPHY_NAN_FLAGS_OFFLOAD_NDP)) + return 0; + + NL_SET_ERR_MSG(info->extack, + "NAN schedule is managed by the device with NDP offload"); + return -EOPNOTSUPP; +} + static int nl80211_nan_set_peer_sched(struct sk_buff *skb, struct genl_info *info) { @@ -18340,6 +18356,10 @@ static int nl80211_nan_set_peer_sched(struct sk_buff *skb, if (wdev->iftype != NL80211_IFTYPE_NAN) return -EOPNOTSUPP; + ret = nl80211_nan_sched_offload_check(&rdev->wiphy, info); + if (ret) + return ret; + if (!info->attrs[NL80211_ATTR_MAC] || !info->attrs[NL80211_ATTR_NAN_COMMITTED_DW]) { NL_SET_ERR_MSG(info->extack, @@ -18501,6 +18521,10 @@ static int nl80211_nan_set_local_sched(struct sk_buff *skb, if (wdev->iftype != NL80211_IFTYPE_NAN) return -EOPNOTSUPP; + ret = nl80211_nan_sched_offload_check(&rdev->wiphy, info); + if (ret) + return ret; + if (!wdev_running(wdev)) return -ENOTCONN; @@ -18595,12 +18619,16 @@ static int nl80211_nan_set_non_evac_channels(struct sk_buff *skb, { struct cfg80211_registered_device *rdev = info->user_ptr[0]; struct wireless_dev *wdev = info->user_ptr[1]; - int rem, i = 0, n_channels = 0; + int rem, i = 0, n_channels = 0, ret; struct nlattr *channel; if (wdev->iftype != NL80211_IFTYPE_NAN) return -EOPNOTSUPP; + ret = nl80211_nan_sched_offload_check(&rdev->wiphy, info); + if (ret) + return ret; + if (!wdev_running(wdev)) return -ENOTCONN; -- 2.34.1 Add NL80211_CMD_NAN_NDP_INITIATE to let userspace initiate a NAN Data Path session when NDP management is offloaded to the device. Validate that the initiator NDI exists locally, pass key material by pointer, and apply the NAN security requirements to cipher suite, PMK, PMKID, and GTK. Let the initiator provide transport port and protocol information for its service in the NDPE Service Info TLV. It can also request a preferred NDL channel or require that the device include it. The device chooses the bandwidth and reports setup failure if it cannot use a forced channel. Let the driver assign the NDP ID and return it in the command reply. Clear the request skb after handling it because it may contain PMK data. Trace the non-secret request parameters without recording PMK or PMKID bytes. Signed-off-by: Shivani Baranwal --- include/net/cfg80211.h | 66 +++++++++ include/uapi/linux/nl80211.h | 110 +++++++++++++++ net/wireless/nl80211.c | 263 +++++++++++++++++++++++++++++++++++ net/wireless/rdev-ops.h | 16 +++ net/wireless/trace.h | 94 +++++++++++++ 5 files changed, 549 insertions(+) diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index 60152bc5aa9a..eb753c83722e 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h @@ -4341,6 +4341,60 @@ struct cfg80211_nan_peer_sched { struct cfg80211_nan_peer_map maps[CFG80211_NAN_MAX_PEER_MAPS]; }; +/** + * struct cfg80211_nan_ndp_initiate - NAN NDP initiate parameters + * + * @peer_nmi: peer NMI address + * @publish_id: publisher's service instance ID + * @service_id: NAN service ID (%NL80211_NAN_FUNC_SERVICE_ID_LEN bytes) + * @init_ndi: initiator NDI MAC address. The corresponding + * %NL80211_IFTYPE_NAN_DATA interface must exist. + * @ssi: service-specific info (may be NULL) + * @ssi_len: length of @ssi + * @cipher_suite: NAN cipher suite ID, 0 for open NDP + * @pmk: ND-PMK used to derive the PTK; NULL if absent. Its length depends on + * the cipher suite and is given by @pmk_len. Requires non-zero + * @cipher_suite and %NL80211_EXT_FEATURE_SECURE_NAN. + * @pmk_len: length of @pmk in bytes + * @pmkid: PMKID (16 octets) to include in the NDP Request, or NULL if absent + * @gtk_required: if true, GTK protection is required for group-addressed data + * frames + * @gtk_cipher: GTK cipher suite ID, valid when @gtk_required is true + * @ipv6_intf_id: IPv6 link-local interface identifier, or NULL if absent + * @ndp_id: output NDP ID assigned by the driver on success (1-255) + * @transport_info: if true, convey @transport_port and @transport_protocol to + * the peer in the NDPE Service Info TLV (Generic Service Protocol). These + * values are not conveyed if the peer does not support NDPE. + * @transport_port: transport port to convey when @transport_info is true + * @transport_protocol: IANA protocol number to convey when @transport_info is + * true + * @chan: preferred channel for the NDL, or NULL when the device chooses the + * channels + * @chan_forced: if true, @chan must be included in the NDL; valid only when + * @chan is non-NULL + */ +struct cfg80211_nan_ndp_initiate { + const u8 *peer_nmi; + u8 publish_id; + u8 service_id[NL80211_NAN_FUNC_SERVICE_ID_LEN]; + const u8 *init_ndi; + const u8 *ssi; + u8 ssi_len; + u32 cipher_suite; + const u8 *pmk; + u8 pmk_len; + const u8 *pmkid; + bool gtk_required; + u32 gtk_cipher; + const u8 *ipv6_intf_id; + u8 ndp_id; + bool transport_info; + u16 transport_port; + u8 transport_protocol; + struct ieee80211_channel *chan; + bool chan_forced; +}; + /** * enum cfg80211_nan_conf_changes - indicates changed fields in NAN * configuration @@ -5322,6 +5376,15 @@ struct mgmt_frame_regs { * supported when %WIPHY_NAN_FLAGS_OFFLOAD_NDP is set; the device manages * channel evacuation. * + * @nan_ndp_initiate: Initiate a NAN Data Path session as the initiator. + * Only valid if the driver has set %WIPHY_NAN_FLAGS_OFFLOAD_NDP. + * The driver must set params->ndp_id to the assigned NDP ID (1-255) on + * success. Each accepted setup attempt completes asynchronously with one + * status notification, including on failure or timeout. If the parameters + * specify a channel, drivers advertising NDP offload must honor it as a + * channel preference. If the channel is forced and cannot be included in the + * NDL, the driver must fail the request. + * * @set_multicast_to_unicast: configure multicast to unicast conversion for BSS * * @get_txq_stats: Get TXQ stats for interface or phy. If wdev is %NULL, this @@ -5729,6 +5792,9 @@ struct cfg80211_ops { int (*nan_set_non_evac_channels)(struct wiphy *wiphy, struct wireless_dev *wdev, struct cfg80211_nan_non_evac_channels *channels); + int (*nan_ndp_initiate)(struct wiphy *wiphy, + struct wireless_dev *wdev, + struct cfg80211_nan_ndp_initiate *params); int (*set_multicast_to_unicast)(struct wiphy *wiphy, struct net_device *dev, const bool enabled); diff --git a/include/uapi/linux/nl80211.h b/include/uapi/linux/nl80211.h index 3406e37df5c4..d6b601556248 100644 --- a/include/uapi/linux/nl80211.h +++ b/include/uapi/linux/nl80211.h @@ -1484,6 +1484,26 @@ * and multiple can be nested in %NL80211_ATTR_MLO_LINKS but then the * update isn't atomic if any failures happen. * Only supported with %NL80211_EXT_FEATURE_UPDATE_BEACON. + * + * @NL80211_CMD_NAN_NDP_INITIATE: Initiate NAN Data Path (NDP) setup + * as the initiator. Requires %NL80211_NAN_CAPA_OFFLOAD_NDP, + * %NL80211_ATTR_MAC (peer NMI), and %NL80211_ATTR_NAN_NDP. The NDI + * interface specified in %NL80211_NAN_NDP_ATTR_INIT_NDI must already + * exist as a %NL80211_IFTYPE_NAN_DATA interface. For a locally + * initiated NDP, the driver assigns the NDP ID and returns it in the + * %NL80211_ATTR_NAN_NDP reply. + * %NL80211_NAN_NDP_ATTR_TRANSPORT_PORT and + * %NL80211_NAN_NDP_ATTR_TRANSPORT_PROTOCOL may be supplied together to + * include transport information in the NDPE Service Info TLV. + * Without %NL80211_NAN_NDP_ATTR_CHANNEL_FREQ, the device chooses the + * channels of the NDL. A supplied channel frequency is a preference unless + * %NL80211_NAN_NDP_ATTR_CHANNEL_FORCED is also present; the device may then + * use other channels. With %NL80211_NAN_NDP_ATTR_CHANNEL_FORCED, the device + * must include the requested channel in the NDL or fail setup, reporting the + * failure with %NL80211_CMD_NAN_NDP_STATUS. The device chooses the bandwidth. + * Each accepted setup attempt completes asynchronously with exactly one + * %NL80211_CMD_NAN_NDP_STATUS notification, including on failure or timeout. + * * @NL80211_CMD_MAX: highest used command number * @__NL80211_CMD_AFTER_LAST: internal use */ @@ -1766,6 +1786,8 @@ enum nl80211_commands { NL80211_CMD_UPDATE_BEACON, + NL80211_CMD_NAN_NDP_INITIATE, + /* add new commands above here */ /* used to define NL80211_CMD_MAX below */ @@ -3260,6 +3282,9 @@ enum nl80211_commands { * @NL80211_ATTR_ASSOC_PROTECTED_TWT: Enable protected TWT for the association, * requires protected TWT support (flag attribute) * + * @NL80211_ATTR_NAN_NDP: nested attribute carrying NAN Data Path parameters. + * See &enum nl80211_nan_ndp_attributes. + * * @NUM_NL80211_ATTR: total number of nl80211_attrs available * @NL80211_ATTR_MAX: highest attribute number currently defined * @__NL80211_ATTR_AFTER_LAST: internal use @@ -3867,6 +3892,8 @@ enum nl80211_attrs { NL80211_ATTR_ASSOC_PROTECTED_TWT, + NL80211_ATTR_NAN_NDP, + /* add attributes here, update the policy in nl80211.c */ __NL80211_ATTR_AFTER_LAST, @@ -8024,6 +8051,89 @@ enum nl80211_nan_conf_attributes { NL80211_NAN_CONF_ATTR_MAX = NUM_NL80211_NAN_CONF_ATTR - 1, }; +#define NL80211_NAN_NDP_IPV6_INTF_ID_LEN 8 + +/** + * enum nl80211_nan_ndp_attributes - NAN Data Path attributes + * + * Nested attributes used within %NL80211_ATTR_NAN_NDP for NDP setup commands + * and events. + * + * @__NL80211_NAN_NDP_ATTR_INVALID: Invalid. + * @NL80211_NAN_NDP_ATTR_ID: u8 NDP ID (1-255), assigned by the NDP initiator. + * For locally initiated NDPs the driver assigns it and returns it in the + * %NL80211_CMD_NAN_NDP_INITIATE reply; do not include it in that request. + * @NL80211_NAN_NDP_ATTR_PUBLISH_ID: u8 publisher's service instance ID, used + * to match the NDP to a service. + * @NL80211_NAN_NDP_ATTR_SERVICE_ID: binary NAN service ID derived from the + * service name, %NL80211_NAN_FUNC_SERVICE_ID_LEN bytes. + * @NL80211_NAN_NDP_ATTR_INIT_NDI: ETH_ALEN-byte initiator NDI MAC address. + * For locally initiated NDPs, the corresponding + * %NL80211_IFTYPE_NAN_DATA interface must exist. + * @NL80211_NAN_NDP_ATTR_RESP_NDI: ETH_ALEN-byte responder NDI MAC address. + * @NL80211_NAN_NDP_ATTR_SSI: binary. Service-specific info carried in + * the NDP setup frames. + * @NL80211_NAN_NDP_ATTR_CIPHER_SUITE: u32 NAN cipher suite ID; 0 for open NDP. + * See the Wi-Fi Aware Specification for values. + * @NL80211_NAN_NDP_ATTR_PMK: binary ND-PMK used to derive the PTK; its length + * depends on the cipher suite. Requires non-zero + * @NL80211_NAN_NDP_ATTR_CIPHER_SUITE and %NL80211_EXT_FEATURE_SECURE_NAN. + * @NL80211_NAN_NDP_ATTR_PMKID: 16-octet PMKID. In + * %NL80211_CMD_NAN_NDP_INITIATE requests it identifies the PMK and is + * included in the SCIA of the NDP Request. In a peer-request notification, + * it carries the PMKID received in the peer's SCIA for cached-PMK lookup. + * @NL80211_NAN_NDP_ATTR_GTK_REQUIRED: flag indicating that GTK protection is + * required for group-addressed data frames. Requires + * @NL80211_NAN_NDP_ATTR_GTK_CIPHER; IGTK and BIGTK are not covered. + * @NL80211_NAN_NDP_ATTR_GTK_CIPHER: u32 GTK cipher suite ID. Required if + * @NL80211_NAN_NDP_ATTR_GTK_REQUIRED is set. + * @NL80211_NAN_NDP_ATTR_IPV6_INTF_ID: binary IPv6 link-local interface + * identifier, %NL80211_NAN_NDP_IPV6_INTF_ID_LEN bytes. The driver conveys it + * in the NDPE attribute and selects NDP or NDPE based on peer capabilities. + * @NL80211_NAN_NDP_ATTR_TRANSPORT_PORT: u16 transport port. Must be supplied + * with @NL80211_NAN_NDP_ATTR_TRANSPORT_PROTOCOL. The driver carries the pair + * in the NDPE Service Info TLV (Generic Service Protocol). If the peer does + * not support NDPE, the values are not conveyed. + * @NL80211_NAN_NDP_ATTR_TRANSPORT_PROTOCOL: u8 IANA protocol number. Must be + * supplied with @NL80211_NAN_NDP_ATTR_TRANSPORT_PORT. + * @NL80211_NAN_NDP_ATTR_CHANNEL_FREQ: optional u32 channel frequency in MHz. + * Valid only with %NL80211_CMD_NAN_NDP_INITIATE. When supplied without + * @NL80211_NAN_NDP_ATTR_CHANNEL_FORCED it is a preference, and the device + * may use other channels for the NDL. Without this attribute, the device + * chooses the NDL channels. The device chooses the channel bandwidth. + * @NL80211_NAN_NDP_ATTR_CHANNEL_FORCED: optional flag valid only with + * %NL80211_CMD_NAN_NDP_INITIATE and + * @NL80211_NAN_NDP_ATTR_CHANNEL_FREQ. The requested channel must be included + * in the NDL. If it cannot be used, for example because it is incompatible + * with peer availability, setup fails. + * @__NL80211_NAN_NDP_ATTR_LAST: Internal. + * @NL80211_NAN_NDP_ATTR_MAX: Highest NDP attribute. + */ +enum nl80211_nan_ndp_attributes { + __NL80211_NAN_NDP_ATTR_INVALID, + + NL80211_NAN_NDP_ATTR_ID, + NL80211_NAN_NDP_ATTR_PUBLISH_ID, + NL80211_NAN_NDP_ATTR_SERVICE_ID, + NL80211_NAN_NDP_ATTR_INIT_NDI, + NL80211_NAN_NDP_ATTR_RESP_NDI, + NL80211_NAN_NDP_ATTR_SSI, + NL80211_NAN_NDP_ATTR_CIPHER_SUITE, + NL80211_NAN_NDP_ATTR_PMK, + NL80211_NAN_NDP_ATTR_PMKID, + NL80211_NAN_NDP_ATTR_GTK_REQUIRED, + NL80211_NAN_NDP_ATTR_GTK_CIPHER, + NL80211_NAN_NDP_ATTR_IPV6_INTF_ID, + NL80211_NAN_NDP_ATTR_TRANSPORT_PORT, + NL80211_NAN_NDP_ATTR_TRANSPORT_PROTOCOL, + NL80211_NAN_NDP_ATTR_CHANNEL_FREQ, + NL80211_NAN_NDP_ATTR_CHANNEL_FORCED, + + /* keep last */ + __NL80211_NAN_NDP_ATTR_LAST, + NL80211_NAN_NDP_ATTR_MAX = __NL80211_NAN_NDP_ATTR_LAST - 1, +}; + /** * enum nl80211_external_auth_action - Action to perform with external * authentication request. Used by NL80211_ATTR_EXTERNAL_AUTH_ACTION. diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index 4bcb62a0172f..fb1190a60748 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -800,6 +800,34 @@ nl80211_nan_peer_map_policy[NL80211_NAN_PEER_MAP_ATTR_MAX + 1] = { NLA_POLICY_EXACT_LEN(CFG80211_NAN_SCHED_NUM_TIME_SLOTS), }; +static const struct nla_policy +nl80211_nan_ndp_policy[NL80211_NAN_NDP_ATTR_MAX + 1] = { + [NL80211_NAN_NDP_ATTR_ID] = NLA_POLICY_RANGE(NLA_U8, 1, 255), + [NL80211_NAN_NDP_ATTR_PUBLISH_ID] = { .type = NLA_U8 }, + [NL80211_NAN_NDP_ATTR_SERVICE_ID] = + NLA_POLICY_EXACT_LEN(NL80211_NAN_FUNC_SERVICE_ID_LEN), + [NL80211_NAN_NDP_ATTR_INIT_NDI] = NLA_POLICY_EXACT_LEN(ETH_ALEN), + [NL80211_NAN_NDP_ATTR_RESP_NDI] = NLA_POLICY_EXACT_LEN(ETH_ALEN), + [NL80211_NAN_NDP_ATTR_SSI] = { + .type = NLA_BINARY, + .len = NL80211_NAN_FUNC_SERVICE_SPEC_INFO_MAX_LEN + }, + [NL80211_NAN_NDP_ATTR_CIPHER_SUITE] = { .type = NLA_U32 }, + [NL80211_NAN_NDP_ATTR_PMK] = + NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_nan_pmk, + WLAN_PMK_LEN_SUITE_B_192), + [NL80211_NAN_NDP_ATTR_PMKID] = + NLA_POLICY_EXACT_LEN(WLAN_PMKID_LEN), + [NL80211_NAN_NDP_ATTR_GTK_REQUIRED] = { .type = NLA_FLAG }, + [NL80211_NAN_NDP_ATTR_GTK_CIPHER] = { .type = NLA_U32 }, + [NL80211_NAN_NDP_ATTR_IPV6_INTF_ID] = + NLA_POLICY_EXACT_LEN(NL80211_NAN_NDP_IPV6_INTF_ID_LEN), + [NL80211_NAN_NDP_ATTR_TRANSPORT_PORT] = { .type = NLA_U16 }, + [NL80211_NAN_NDP_ATTR_TRANSPORT_PROTOCOL] = { .type = NLA_U8 }, + [NL80211_NAN_NDP_ATTR_CHANNEL_FREQ] = { .type = NLA_U32 }, + [NL80211_NAN_NDP_ATTR_CHANNEL_FORCED] = { .type = NLA_FLAG }, +}; + static const struct nla_policy nl80211_nan_conf_policy[NL80211_NAN_CONF_ATTR_MAX + 1] = { [NL80211_NAN_CONF_CLUSTER_ID] = @@ -1226,6 +1254,7 @@ static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = { [NL80211_ATTR_NAN_MAX_CHAN_SWITCH_TIME] = { .type = NLA_U16 }, [NL80211_ATTR_NAN_PEER_MAPS] = NLA_POLICY_NESTED_ARRAY(nl80211_nan_peer_map_policy), + [NL80211_ATTR_NAN_NDP] = NLA_POLICY_NESTED(nl80211_nan_ndp_policy), [NL80211_ATTR_NPCA_PRIMARY_FREQ] = { .type = NLA_U32 }, [NL80211_ATTR_NPCA_PUNCT_BITMAP] = NLA_POLICY_FULL_RANGE(NLA_U32, &nl80211_punct_bitmap_range), @@ -18495,6 +18524,233 @@ static int nl80211_nan_set_peer_sched(struct sk_buff *skb, return rdev_nan_set_peer_sched(rdev, wdev, &sched); } +static bool nl80211_nan_ndi_exists(struct cfg80211_registered_device *rdev, + const u8 *addr) +{ + struct wireless_dev *wdev; + + lockdep_assert_wiphy(&rdev->wiphy); + + list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { + if (wdev->iftype == NL80211_IFTYPE_NAN_DATA && + ether_addr_equal(wdev_address(wdev), addr)) + return true; + } + + return false; +} + +static int nl80211_nan_ndp_initiate(struct sk_buff *skb, + struct genl_info *info) +{ + struct cfg80211_registered_device *rdev = info->user_ptr[0]; + struct wireless_dev *wdev = info->user_ptr[1]; + struct nlattr *tb[NL80211_NAN_NDP_ATTR_MAX + 1], *ndp_attr; + struct cfg80211_nan_ndp_initiate params = {}; + struct sk_buff *msg; + void *hdr; + bool secure_nan; + int err; + + if (wdev->iftype != NL80211_IFTYPE_NAN) { + NL_SET_ERR_MSG(info->extack, + "NDP initiate requires NAN interface"); + return -EOPNOTSUPP; + } + + if (!(rdev->wiphy.nan_capa.flags & WIPHY_NAN_FLAGS_OFFLOAD_NDP)) { + NL_SET_ERR_MSG(info->extack, + "NAN NDP offload not supported by driver"); + return -EOPNOTSUPP; + } + + if (!info->attrs[NL80211_ATTR_MAC] || + !info->attrs[NL80211_ATTR_NAN_NDP]) { + NL_SET_ERR_MSG(info->extack, + "NDP initiate requires peer NMI and NDP params"); + return -EINVAL; + } + + err = nla_parse_nested(tb, NL80211_NAN_NDP_ATTR_MAX, + info->attrs[NL80211_ATTR_NAN_NDP], + nl80211_nan_ndp_policy, + info->extack); + if (err) + return err; + + if (!!tb[NL80211_NAN_NDP_ATTR_TRANSPORT_PORT] != + !!tb[NL80211_NAN_NDP_ATTR_TRANSPORT_PROTOCOL]) { + NL_SET_ERR_MSG(info->extack, + "Transport port and protocol must be supplied together"); + return -EINVAL; + } + + if (tb[NL80211_NAN_NDP_ATTR_CHANNEL_FORCED] && + !tb[NL80211_NAN_NDP_ATTR_CHANNEL_FREQ]) { + NL_SET_ERR_MSG_ATTR(info->extack, + tb[NL80211_NAN_NDP_ATTR_CHANNEL_FORCED], + "CHANNEL_FORCED requires CHANNEL_FREQ"); + return -EINVAL; + } + + if (tb[NL80211_NAN_NDP_ATTR_ID]) { + NL_SET_ERR_MSG_ATTR(info->extack, + tb[NL80211_NAN_NDP_ATTR_ID], + "NDP ID is assigned by the driver"); + return -EINVAL; + } + + if (!tb[NL80211_NAN_NDP_ATTR_INIT_NDI] || + !tb[NL80211_NAN_NDP_ATTR_PUBLISH_ID] || + !tb[NL80211_NAN_NDP_ATTR_SERVICE_ID]) { + NL_SET_ERR_MSG(info->extack, + "NDP initiate requires INIT_NDI, PUBLISH_ID and SERVICE_ID"); + return -EINVAL; + } + + if (!nl80211_nan_ndi_exists(rdev, + nla_data(tb[NL80211_NAN_NDP_ATTR_INIT_NDI]))) { + NL_SET_ERR_MSG_ATTR(info->extack, + tb[NL80211_NAN_NDP_ATTR_INIT_NDI], + "INIT_NDI must identify an existing NAN Data interface"); + return -ENODEV; + } + + params.peer_nmi = nla_data(info->attrs[NL80211_ATTR_MAC]); + params.init_ndi = nla_data(tb[NL80211_NAN_NDP_ATTR_INIT_NDI]); + params.publish_id = nla_get_u8(tb[NL80211_NAN_NDP_ATTR_PUBLISH_ID]); + memcpy(params.service_id, + nla_data(tb[NL80211_NAN_NDP_ATTR_SERVICE_ID]), + NL80211_NAN_FUNC_SERVICE_ID_LEN); + if (tb[NL80211_NAN_NDP_ATTR_TRANSPORT_PORT]) { + params.transport_info = true; + params.transport_port = + nla_get_u16(tb[NL80211_NAN_NDP_ATTR_TRANSPORT_PORT]); + params.transport_protocol = + nla_get_u8(tb[NL80211_NAN_NDP_ATTR_TRANSPORT_PROTOCOL]); + } + + if (tb[NL80211_NAN_NDP_ATTR_SSI]) { + params.ssi = nla_data(tb[NL80211_NAN_NDP_ATTR_SSI]); + params.ssi_len = nla_len(tb[NL80211_NAN_NDP_ATTR_SSI]); + } + + if (tb[NL80211_NAN_NDP_ATTR_CIPHER_SUITE]) + params.cipher_suite = + nla_get_u32(tb[NL80211_NAN_NDP_ATTR_CIPHER_SUITE]); + + secure_nan = wiphy_ext_feature_isset(&rdev->wiphy, + NL80211_EXT_FEATURE_SECURE_NAN); + if (params.cipher_suite && !secure_nan) { + NL_SET_ERR_MSG_ATTR(info->extack, + tb[NL80211_NAN_NDP_ATTR_CIPHER_SUITE], + "NDP cipher suite requires SECURE_NAN"); + return -EOPNOTSUPP; + } + + if (tb[NL80211_NAN_NDP_ATTR_PMK] || + tb[NL80211_NAN_NDP_ATTR_PMKID] || + tb[NL80211_NAN_NDP_ATTR_GTK_REQUIRED]) { + if (!secure_nan || !params.cipher_suite) { + NL_SET_ERR_MSG(info->extack, + "PMK, PMKID, and GTK require SECURE_NAN and a non-zero cipher suite"); + return -EINVAL; + } + } + + if (tb[NL80211_NAN_NDP_ATTR_PMK]) { + params.pmk = nla_data(tb[NL80211_NAN_NDP_ATTR_PMK]); + params.pmk_len = nla_len(tb[NL80211_NAN_NDP_ATTR_PMK]); + } + + if (tb[NL80211_NAN_NDP_ATTR_PMKID]) + params.pmkid = nla_data(tb[NL80211_NAN_NDP_ATTR_PMKID]); + + if (tb[NL80211_NAN_NDP_ATTR_GTK_REQUIRED]) { + if (!tb[NL80211_NAN_NDP_ATTR_GTK_CIPHER]) { + NL_SET_ERR_MSG_ATTR(info->extack, + tb[NL80211_NAN_NDP_ATTR_GTK_REQUIRED], + "GTK_CIPHER is required when GTK_REQUIRED is set"); + return -EINVAL; + } + + params.gtk_required = true; + params.gtk_cipher = + nla_get_u32(tb[NL80211_NAN_NDP_ATTR_GTK_CIPHER]); + } else if (tb[NL80211_NAN_NDP_ATTR_GTK_CIPHER]) { + NL_SET_ERR_MSG_ATTR(info->extack, + tb[NL80211_NAN_NDP_ATTR_GTK_CIPHER], + "GTK_CIPHER requires GTK_REQUIRED"); + return -EINVAL; + } + + if (tb[NL80211_NAN_NDP_ATTR_IPV6_INTF_ID]) + params.ipv6_intf_id = + nla_data(tb[NL80211_NAN_NDP_ATTR_IPV6_INTF_ID]); + + if (tb[NL80211_NAN_NDP_ATTR_CHANNEL_FREQ]) { + u32 freq = nla_get_u32(tb[NL80211_NAN_NDP_ATTR_CHANNEL_FREQ]); + + params.chan = ieee80211_get_channel(&rdev->wiphy, freq); + if (!params.chan) { + NL_SET_ERR_MSG_ATTR(info->extack, + tb[NL80211_NAN_NDP_ATTR_CHANNEL_FREQ], + "Channel frequency is not supported"); + return -EINVAL; + } + if (params.chan->flags & IEEE80211_CHAN_DISABLED) { + NL_SET_ERR_MSG_ATTR(info->extack, + tb[NL80211_NAN_NDP_ATTR_CHANNEL_FREQ], + "Channel is disabled"); + return -EINVAL; + } + if (!(rdev->wiphy.nan_supported_bands & + BIT(params.chan->band))) { + NL_SET_ERR_MSG_ATTR(info->extack, + tb[NL80211_NAN_NDP_ATTR_CHANNEL_FREQ], + "Channel band is not supported for NAN"); + return -EOPNOTSUPP; + } + params.chan_forced = + !!tb[NL80211_NAN_NDP_ATTR_CHANNEL_FORCED]; + } + + msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); + if (!msg) + return -ENOMEM; + + hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, + NL80211_CMD_NAN_NDP_INITIATE); + if (!hdr) { + nlmsg_free(msg); + return -ENOMEM; + } + + err = rdev_nan_ndp_initiate(rdev, wdev, ¶ms); + if (err) { + nlmsg_free(msg); + return err; + } + + if (WARN_ON_ONCE(!params.ndp_id)) { + nlmsg_free(msg); + return -EINVAL; + } + + ndp_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_NDP); + if (!ndp_attr || + nla_put_u8(msg, NL80211_NAN_NDP_ATTR_ID, params.ndp_id)) + goto nla_put_failure; + + nla_nest_end(msg, ndp_attr); + genlmsg_end(msg, hdr); + return genlmsg_reply(msg, info); + +nla_put_failure: + nlmsg_free(msg); + return -ENOBUFS; +} + static bool nl80211_nan_is_sched_empty(struct cfg80211_nan_local_sched *sched) { if (!sched->n_channels) @@ -21656,6 +21912,13 @@ static const struct genl_small_ops nl80211_small_ops[] = { .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | NL80211_FLAG_NO_WIPHY_MTX), }, + { + .cmd = NL80211_CMD_NAN_NDP_INITIATE, + .doit = nl80211_nan_ndp_initiate, + .flags = GENL_ADMIN_PERM, + .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP | + NL80211_FLAG_CLEAR_SKB), + }, }; static struct genl_family nl80211_fam __ro_after_init = { diff --git a/net/wireless/rdev-ops.h b/net/wireless/rdev-ops.h index 7b8440c1f697..df8ec338e59d 100644 --- a/net/wireless/rdev-ops.h +++ b/net/wireless/rdev-ops.h @@ -1189,6 +1189,22 @@ static inline void rdev_stop_pd(struct cfg80211_registered_device *rdev, trace_rdev_return_void(&rdev->wiphy); } +static inline int +rdev_nan_ndp_initiate(struct cfg80211_registered_device *rdev, + struct wireless_dev *wdev, + struct cfg80211_nan_ndp_initiate *params) +{ + int ret; + + if (!rdev->ops->nan_ndp_initiate) + return -EOPNOTSUPP; + + trace_rdev_nan_ndp_initiate(&rdev->wiphy, wdev, params); + ret = rdev->ops->nan_ndp_initiate(&rdev->wiphy, wdev, params); + trace_rdev_return_int(&rdev->wiphy, ret); + return ret; +} + static inline int rdev_set_mac_acl(struct cfg80211_registered_device *rdev, struct net_device *dev, struct cfg80211_acl_data *params) diff --git a/net/wireless/trace.h b/net/wireless/trace.h index 31000ffebe43..131fb5657004 100644 --- a/net/wireless/trace.h +++ b/net/wireless/trace.h @@ -2552,6 +2552,100 @@ TRACE_EVENT(rdev_nan_set_non_evac_channels, __entry->n_channels, sizeof(u32))) ); +#define RDEV_NAN_NDP_INITIATE_FMT_1 \ + ", peer: %pM, init_ndi: %pM, publish_id: %u, " +#define RDEV_NAN_NDP_INITIATE_FMT_2 \ + "service_id: %s, ssi_len: %u, ssi: %s, " +#define RDEV_NAN_NDP_INITIATE_FMT_3 \ + "cipher_suite: %u, pmk_len: %u, pmkid_present: %d, " +#define RDEV_NAN_NDP_INITIATE_FMT_4 \ + "gtk_required: %d, gtk_cipher: %u, ipv6_intf_id_present: %d, " +#define RDEV_NAN_NDP_INITIATE_FMT_5 \ + "ipv6_intf_id: %s, channel_freq: %u, channel_forced: %d" +TRACE_EVENT(rdev_nan_ndp_initiate, + TP_PROTO(struct wiphy *wiphy, struct wireless_dev *wdev, + struct cfg80211_nan_ndp_initiate *params), + TP_ARGS(wiphy, wdev, params), + TP_STRUCT__entry( + WIPHY_ENTRY + WDEV_ENTRY + __array(u8, peer_nmi, ETH_ALEN) + __array(u8, init_ndi, ETH_ALEN) + __field(u8, publish_id) + __array(u8, service_id, NL80211_NAN_FUNC_SERVICE_ID_LEN) + __field(u8, ssi_len) + __dynamic_array(u8, ssi, params->ssi_len) + __field(u32, cipher_suite) + __field(u8, pmk_len) + __field(bool, pmkid_present) + __field(bool, gtk_required) + __field(u32, gtk_cipher) + __field(bool, transport_info) + __field(u16, transport_port) + __field(u8, transport_protocol) + __field(bool, ipv6_intf_id_present) + __array(u8, ipv6_intf_id, NL80211_NAN_NDP_IPV6_INTF_ID_LEN) + __field(u32, channel_freq) + __field(bool, channel_forced) + ), + TP_fast_assign( + WIPHY_ASSIGN; + WDEV_ASSIGN; + memcpy(__entry->peer_nmi, params->peer_nmi, ETH_ALEN); + memcpy(__entry->init_ndi, params->init_ndi, ETH_ALEN); + __entry->publish_id = params->publish_id; + memcpy(__entry->service_id, params->service_id, + NL80211_NAN_FUNC_SERVICE_ID_LEN); + __entry->ssi_len = params->ssi_len; + if (params->ssi_len) + memcpy(__get_dynamic_array(ssi), params->ssi, + params->ssi_len); + __entry->cipher_suite = params->cipher_suite; + __entry->pmk_len = params->pmk ? params->pmk_len : 0; + __entry->pmkid_present = !!params->pmkid; + __entry->gtk_required = params->gtk_required; + __entry->gtk_cipher = params->gtk_cipher; + __entry->transport_info = params->transport_info; + __entry->transport_port = params->transport_port; + __entry->transport_protocol = params->transport_protocol; + __entry->ipv6_intf_id_present = !!params->ipv6_intf_id; + if (params->ipv6_intf_id) + memcpy(__entry->ipv6_intf_id, params->ipv6_intf_id, + NL80211_NAN_NDP_IPV6_INTF_ID_LEN); + else + memset(__entry->ipv6_intf_id, 0, + NL80211_NAN_NDP_IPV6_INTF_ID_LEN); + __entry->channel_freq = params->chan ? + params->chan->center_freq : 0; + __entry->channel_forced = params->chan_forced; + ), + TP_printk(WIPHY_PR_FMT ", " WDEV_PR_FMT + RDEV_NAN_NDP_INITIATE_FMT_1 RDEV_NAN_NDP_INITIATE_FMT_2 + RDEV_NAN_NDP_INITIATE_FMT_3 RDEV_NAN_NDP_INITIATE_FMT_4 + RDEV_NAN_NDP_INITIATE_FMT_5 + ", transport_info: %d, transport_port: %u, transport_protocol: %u", + WIPHY_PR_ARG, WDEV_PR_ARG, __entry->peer_nmi, __entry->init_ndi, + __entry->publish_id, + __print_array(__entry->service_id, + NL80211_NAN_FUNC_SERVICE_ID_LEN, sizeof(u8)), + __entry->ssi_len, + __print_array(__get_dynamic_array(ssi), __entry->ssi_len, + sizeof(u8)), + __entry->cipher_suite, __entry->pmk_len, + __entry->pmkid_present, __entry->gtk_required, + __entry->gtk_cipher, __entry->ipv6_intf_id_present, + __print_array(__entry->ipv6_intf_id, + NL80211_NAN_NDP_IPV6_INTF_ID_LEN, sizeof(u8)), + __entry->channel_freq, __entry->channel_forced, + __entry->transport_info, __entry->transport_port, + __entry->transport_protocol) +); +#undef RDEV_NAN_NDP_INITIATE_FMT_1 +#undef RDEV_NAN_NDP_INITIATE_FMT_2 +#undef RDEV_NAN_NDP_INITIATE_FMT_3 +#undef RDEV_NAN_NDP_INITIATE_FMT_4 +#undef RDEV_NAN_NDP_INITIATE_FMT_5 + TRACE_EVENT(rdev_set_mac_acl, TP_PROTO(struct wiphy *wiphy, struct net_device *netdev, struct cfg80211_acl_data *params), -- 2.34.1 Add NL80211_CMD_NAN_NDP_RESPOND so userspace can accept or reject an incoming NDP request when the device offloads NDP management. Require a local responder NDI only when accepting; the initiator NDI belongs to the peer and is not validated as a local interface. Restrict rejection requests to the reason and optional SSI, and enforce the NAN security requirements when accepting. Pass PMK material by pointer, clear the request skb, and trace request parameters without recording key bytes. Allow the responder to provide transport port and protocol information when accepting an NDP request. Reject channel request attributes on the response command, since channel selection is requested by the initiator. Signed-off-by: Shivani Baranwal --- include/net/cfg80211.h | 55 +++++++++++ include/uapi/linux/nl80211.h | 28 +++++- net/wireless/nl80211.c | 175 +++++++++++++++++++++++++++++++++++ net/wireless/rdev-ops.h | 16 ++++ net/wireless/trace.h | 86 +++++++++++++++++ 5 files changed, 357 insertions(+), 3 deletions(-) diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index eb753c83722e..151555fa8404 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h @@ -4395,6 +4395,54 @@ struct cfg80211_nan_ndp_initiate { bool chan_forced; }; +/** + * struct cfg80211_nan_ndp_respond - NAN NDP respond parameters + * + * @peer_nmi: peer NMI address + * @ndp_id: NDP ID from the received NDP Request + * @init_ndi: initiator NDI MAC from the received NDP Request + * @resp_ndi: responder NDI MAC. The corresponding + * %NL80211_IFTYPE_NAN_DATA interface must exist when accepting. + * @accept: if true, accept the NDP; if false, reject it + * @reason: Wi-Fi Aware reason code for rejection (valid when @accept is false) + * @ssi: response service-specific info (may be NULL) + * @ssi_len: length of @ssi + * @cipher_suite: NAN cipher suite ID (must match the initiator's) + * @pmk: ND-PMK used to derive the PTK; NULL if absent. Its length depends on + * the cipher suite and is given by @pmk_len. Requires non-zero + * @cipher_suite and %NL80211_EXT_FEATURE_SECURE_NAN. + * @pmk_len: length of @pmk in bytes + * @gtk_required: if true, GTK protection is required for group-addressed data + * frames + * @gtk_cipher: GTK cipher suite ID, valid when @gtk_required is true + * @ipv6_intf_id: IPv6 link-local interface identifier, or NULL if absent + * @transport_info: if true, convey @transport_port and @transport_protocol to + * the peer in the NDPE Service Info TLV (Generic Service Protocol). These + * values are not conveyed if the peer does not support NDPE. + * @transport_port: transport port to convey when @transport_info is true + * @transport_protocol: IANA protocol number to convey when @transport_info is + * true + */ +struct cfg80211_nan_ndp_respond { + const u8 *peer_nmi; + u8 ndp_id; + const u8 *init_ndi; + const u8 *resp_ndi; + bool accept; + u8 reason; + const u8 *ssi; + u8 ssi_len; + u32 cipher_suite; + const u8 *pmk; + u8 pmk_len; + bool gtk_required; + u32 gtk_cipher; + const u8 *ipv6_intf_id; + bool transport_info; + u16 transport_port; + u8 transport_protocol; +}; + /** * enum cfg80211_nan_conf_changes - indicates changed fields in NAN * configuration @@ -5384,6 +5432,10 @@ struct mgmt_frame_regs { * specify a channel, drivers advertising NDP offload must honor it as a * channel preference. If the channel is forced and cannot be included in the * NDL, the driver must fail the request. + * @nan_ndp_respond: Respond to an incoming NDP request as the responder. + * Only valid if the driver has set %WIPHY_NAN_FLAGS_OFFLOAD_NDP. Returning + * success acknowledges the response command only; setup outcome is reported + * asynchronously after the handshake. * * @set_multicast_to_unicast: configure multicast to unicast conversion for BSS * @@ -5795,6 +5847,9 @@ struct cfg80211_ops { int (*nan_ndp_initiate)(struct wiphy *wiphy, struct wireless_dev *wdev, struct cfg80211_nan_ndp_initiate *params); + int (*nan_ndp_respond)(struct wiphy *wiphy, + struct wireless_dev *wdev, + struct cfg80211_nan_ndp_respond *params); int (*set_multicast_to_unicast)(struct wiphy *wiphy, struct net_device *dev, const bool enabled); diff --git a/include/uapi/linux/nl80211.h b/include/uapi/linux/nl80211.h index d6b601556248..bdd52fcafe85 100644 --- a/include/uapi/linux/nl80211.h +++ b/include/uapi/linux/nl80211.h @@ -1503,6 +1503,15 @@ * failure with %NL80211_CMD_NAN_NDP_STATUS. The device chooses the bandwidth. * Each accepted setup attempt completes asynchronously with exactly one * %NL80211_CMD_NAN_NDP_STATUS notification, including on failure or timeout. + * @NL80211_CMD_NAN_NDP_RESPOND: Respond to a received NDP request as + * the responder. Requires %NL80211_NAN_CAPA_OFFLOAD_NDP. The NDI + * interface specified in %NL80211_NAN_NDP_ATTR_RESP_NDI must already + * exist as a %NL80211_IFTYPE_NAN_DATA interface. Carries + * %NL80211_ATTR_NAN_NDP nested with %NL80211_NAN_NDP_ATTR_* fields. + * The command reply only acknowledges that the response was accepted for + * processing; setup outcome is reported asynchronously by + * %NL80211_CMD_NAN_NDP_STATUS. + * Transport port and protocol may be supplied together only when accepting. * * @NL80211_CMD_MAX: highest used command number * @__NL80211_CMD_AFTER_LAST: internal use @@ -1787,6 +1796,7 @@ enum nl80211_commands { NL80211_CMD_UPDATE_BEACON, NL80211_CMD_NAN_NDP_INITIATE, + NL80211_CMD_NAN_NDP_RESPOND, /* add new commands above here */ @@ -8071,6 +8081,8 @@ enum nl80211_nan_conf_attributes { * For locally initiated NDPs, the corresponding * %NL80211_IFTYPE_NAN_DATA interface must exist. * @NL80211_NAN_NDP_ATTR_RESP_NDI: ETH_ALEN-byte responder NDI MAC address. + * When accepting with %NL80211_CMD_NAN_NDP_RESPOND, this must identify an + * existing local %NL80211_IFTYPE_NAN_DATA interface. * @NL80211_NAN_NDP_ATTR_SSI: binary. Service-specific info carried in * the NDP setup frames. * @NL80211_NAN_NDP_ATTR_CIPHER_SUITE: u32 NAN cipher suite ID; 0 for open NDP. @@ -8091,9 +8103,11 @@ enum nl80211_nan_conf_attributes { * identifier, %NL80211_NAN_NDP_IPV6_INTF_ID_LEN bytes. The driver conveys it * in the NDPE attribute and selects NDP or NDPE based on peer capabilities. * @NL80211_NAN_NDP_ATTR_TRANSPORT_PORT: u16 transport port. Must be supplied - * with @NL80211_NAN_NDP_ATTR_TRANSPORT_PROTOCOL. The driver carries the pair - * in the NDPE Service Info TLV (Generic Service Protocol). If the peer does - * not support NDPE, the values are not conveyed. + * with @NL80211_NAN_NDP_ATTR_TRANSPORT_PROTOCOL. The pair may be used in + * %NL80211_CMD_NAN_NDP_INITIATE and in an accepting + * %NL80211_CMD_NAN_NDP_RESPOND. The driver carries these values in the NDPE + * Service Info TLV (Generic Service Protocol). If the peer does not support + * NDPE, these values are not conveyed. * @NL80211_NAN_NDP_ATTR_TRANSPORT_PROTOCOL: u8 IANA protocol number. Must be * supplied with @NL80211_NAN_NDP_ATTR_TRANSPORT_PORT. * @NL80211_NAN_NDP_ATTR_CHANNEL_FREQ: optional u32 channel frequency in MHz. @@ -8106,6 +8120,12 @@ enum nl80211_nan_conf_attributes { * @NL80211_NAN_NDP_ATTR_CHANNEL_FREQ. The requested channel must be included * in the NDL. If it cannot be used, for example because it is incompatible * with peer availability, setup fails. + * @NL80211_NAN_NDP_ATTR_ACCEPT: flag. If present in + * %NL80211_CMD_NAN_NDP_RESPOND, it accepts the request; if absent, it is + * rejected. + * @NL80211_NAN_NDP_ATTR_REASON: u8 Wi-Fi Aware reason code, not an IEEE 802.11 + * reason code (%NL80211_ATTR_REASON_CODE). Used for rejection with + * %NL80211_CMD_NAN_NDP_RESPOND. * @__NL80211_NAN_NDP_ATTR_LAST: Internal. * @NL80211_NAN_NDP_ATTR_MAX: Highest NDP attribute. */ @@ -8128,6 +8148,8 @@ enum nl80211_nan_ndp_attributes { NL80211_NAN_NDP_ATTR_TRANSPORT_PROTOCOL, NL80211_NAN_NDP_ATTR_CHANNEL_FREQ, NL80211_NAN_NDP_ATTR_CHANNEL_FORCED, + NL80211_NAN_NDP_ATTR_ACCEPT, + NL80211_NAN_NDP_ATTR_REASON, /* keep last */ __NL80211_NAN_NDP_ATTR_LAST, diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index fb1190a60748..85b8181b7c68 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -826,6 +826,8 @@ nl80211_nan_ndp_policy[NL80211_NAN_NDP_ATTR_MAX + 1] = { [NL80211_NAN_NDP_ATTR_TRANSPORT_PROTOCOL] = { .type = NLA_U8 }, [NL80211_NAN_NDP_ATTR_CHANNEL_FREQ] = { .type = NLA_U32 }, [NL80211_NAN_NDP_ATTR_CHANNEL_FORCED] = { .type = NLA_FLAG }, + [NL80211_NAN_NDP_ATTR_ACCEPT] = { .type = NLA_FLAG }, + [NL80211_NAN_NDP_ATTR_REASON] = { .type = NLA_U8 }, }; static const struct nla_policy @@ -18751,6 +18753,172 @@ static int nl80211_nan_ndp_initiate(struct sk_buff *skb, return -ENOBUFS; } +static int nl80211_nan_ndp_respond(struct sk_buff *skb, + struct genl_info *info) +{ + struct cfg80211_registered_device *rdev = info->user_ptr[0]; + struct wireless_dev *wdev = info->user_ptr[1]; + struct nlattr *tb[NL80211_NAN_NDP_ATTR_MAX + 1]; + struct cfg80211_nan_ndp_respond params = {}; + bool secure_nan; + int err; + + if (wdev->iftype != NL80211_IFTYPE_NAN) { + NL_SET_ERR_MSG(info->extack, + "NDP respond requires NAN interface"); + return -EOPNOTSUPP; + } + + if (!(rdev->wiphy.nan_capa.flags & WIPHY_NAN_FLAGS_OFFLOAD_NDP)) { + NL_SET_ERR_MSG(info->extack, + "NAN NDP offload not supported by driver"); + return -EOPNOTSUPP; + } + + if (!info->attrs[NL80211_ATTR_MAC] || + !info->attrs[NL80211_ATTR_NAN_NDP]) { + NL_SET_ERR_MSG(info->extack, + "NDP respond requires peer NMI and NDP params"); + return -EINVAL; + } + + err = nla_parse_nested(tb, NL80211_NAN_NDP_ATTR_MAX, + info->attrs[NL80211_ATTR_NAN_NDP], + nl80211_nan_ndp_policy, + info->extack); + if (err) + return err; + + if (!!tb[NL80211_NAN_NDP_ATTR_TRANSPORT_PORT] != + !!tb[NL80211_NAN_NDP_ATTR_TRANSPORT_PROTOCOL]) { + NL_SET_ERR_MSG(info->extack, + "Transport port and protocol must be supplied together"); + return -EINVAL; + } + + if (tb[NL80211_NAN_NDP_ATTR_CHANNEL_FREQ] || + tb[NL80211_NAN_NDP_ATTR_CHANNEL_FORCED]) { + NL_SET_ERR_MSG(info->extack, + "Channel request is only valid with NDP initiate"); + return -EINVAL; + } + + if (!tb[NL80211_NAN_NDP_ATTR_ID] || + !tb[NL80211_NAN_NDP_ATTR_INIT_NDI]) { + NL_SET_ERR_MSG(info->extack, + "NDP respond requires NDP ID and INIT_NDI"); + return -EINVAL; + } + + params.peer_nmi = nla_data(info->attrs[NL80211_ATTR_MAC]); + params.ndp_id = nla_get_u8(tb[NL80211_NAN_NDP_ATTR_ID]); + params.init_ndi = nla_data(tb[NL80211_NAN_NDP_ATTR_INIT_NDI]); + params.accept = nla_get_flag(tb[NL80211_NAN_NDP_ATTR_ACCEPT]); + + if (params.accept) { + if (tb[NL80211_NAN_NDP_ATTR_REASON]) { + NL_SET_ERR_MSG_ATTR(info->extack, + tb[NL80211_NAN_NDP_ATTR_REASON], + "REASON is only valid when rejecting"); + return -EINVAL; + } + + if (!tb[NL80211_NAN_NDP_ATTR_RESP_NDI]) { + NL_SET_ERR_MSG(info->extack, + "NDP accept requires RESP_NDI"); + return -EINVAL; + } + params.resp_ndi = nla_data(tb[NL80211_NAN_NDP_ATTR_RESP_NDI]); + if (!nl80211_nan_ndi_exists(rdev, + params.resp_ndi)) { + NL_SET_ERR_MSG_ATTR(info->extack, + tb[NL80211_NAN_NDP_ATTR_RESP_NDI], + "RESP_NDI must identify an existing NAN Data interface"); + return -ENODEV; + } + + if (tb[NL80211_NAN_NDP_ATTR_TRANSPORT_PORT]) { + params.transport_info = true; + params.transport_port = + nla_get_u16(tb[NL80211_NAN_NDP_ATTR_TRANSPORT_PORT]); + params.transport_protocol = + nla_get_u8(tb[NL80211_NAN_NDP_ATTR_TRANSPORT_PROTOCOL]); + } + } else { + if (tb[NL80211_NAN_NDP_ATTR_RESP_NDI] || + tb[NL80211_NAN_NDP_ATTR_CIPHER_SUITE] || + tb[NL80211_NAN_NDP_ATTR_PMK] || + tb[NL80211_NAN_NDP_ATTR_GTK_REQUIRED] || + tb[NL80211_NAN_NDP_ATTR_GTK_CIPHER] || + tb[NL80211_NAN_NDP_ATTR_IPV6_INTF_ID] || + tb[NL80211_NAN_NDP_ATTR_TRANSPORT_PORT] || + tb[NL80211_NAN_NDP_ATTR_TRANSPORT_PROTOCOL]) { + NL_SET_ERR_MSG(info->extack, + "RESP_NDI, cipher, PMK, GTK, IPv6 IID, transport info only valid when accepting"); + return -EINVAL; + } + + if (tb[NL80211_NAN_NDP_ATTR_REASON]) + params.reason = + nla_get_u8(tb[NL80211_NAN_NDP_ATTR_REASON]); + } + + if (tb[NL80211_NAN_NDP_ATTR_SSI]) { + params.ssi = nla_data(tb[NL80211_NAN_NDP_ATTR_SSI]); + params.ssi_len = nla_len(tb[NL80211_NAN_NDP_ATTR_SSI]); + } + + if (tb[NL80211_NAN_NDP_ATTR_CIPHER_SUITE]) + params.cipher_suite = + nla_get_u32(tb[NL80211_NAN_NDP_ATTR_CIPHER_SUITE]); + + secure_nan = wiphy_ext_feature_isset(&rdev->wiphy, + NL80211_EXT_FEATURE_SECURE_NAN); + if (params.cipher_suite && !secure_nan) { + NL_SET_ERR_MSG_ATTR(info->extack, + tb[NL80211_NAN_NDP_ATTR_CIPHER_SUITE], + "NDP cipher suite requires SECURE_NAN"); + return -EOPNOTSUPP; + } + + if ((tb[NL80211_NAN_NDP_ATTR_PMK] || + tb[NL80211_NAN_NDP_ATTR_GTK_REQUIRED]) && + (!secure_nan || !params.cipher_suite)) { + NL_SET_ERR_MSG(info->extack, + "PMK and GTK require SECURE_NAN and a non-zero cipher suite"); + return -EINVAL; + } + + if (tb[NL80211_NAN_NDP_ATTR_PMK]) { + params.pmk = nla_data(tb[NL80211_NAN_NDP_ATTR_PMK]); + params.pmk_len = nla_len(tb[NL80211_NAN_NDP_ATTR_PMK]); + } + + if (tb[NL80211_NAN_NDP_ATTR_GTK_REQUIRED]) { + if (!tb[NL80211_NAN_NDP_ATTR_GTK_CIPHER]) { + NL_SET_ERR_MSG_ATTR(info->extack, + tb[NL80211_NAN_NDP_ATTR_GTK_REQUIRED], + "GTK_CIPHER is required when GTK_REQUIRED is set"); + return -EINVAL; + } + + params.gtk_required = true; + params.gtk_cipher = + nla_get_u32(tb[NL80211_NAN_NDP_ATTR_GTK_CIPHER]); + } else if (tb[NL80211_NAN_NDP_ATTR_GTK_CIPHER]) { + NL_SET_ERR_MSG_ATTR(info->extack, + tb[NL80211_NAN_NDP_ATTR_GTK_CIPHER], + "GTK_CIPHER requires GTK_REQUIRED"); + return -EINVAL; + } + + if (tb[NL80211_NAN_NDP_ATTR_IPV6_INTF_ID]) + params.ipv6_intf_id = + nla_data(tb[NL80211_NAN_NDP_ATTR_IPV6_INTF_ID]); + + return rdev_nan_ndp_respond(rdev, wdev, ¶ms); +} + static bool nl80211_nan_is_sched_empty(struct cfg80211_nan_local_sched *sched) { if (!sched->n_channels) @@ -21919,6 +22087,13 @@ static const struct genl_small_ops nl80211_small_ops[] = { .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP | NL80211_FLAG_CLEAR_SKB), }, + { + .cmd = NL80211_CMD_NAN_NDP_RESPOND, + .doit = nl80211_nan_ndp_respond, + .flags = GENL_ADMIN_PERM, + .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP | + NL80211_FLAG_CLEAR_SKB), + }, }; static struct genl_family nl80211_fam __ro_after_init = { diff --git a/net/wireless/rdev-ops.h b/net/wireless/rdev-ops.h index df8ec338e59d..d65dd39a1bcb 100644 --- a/net/wireless/rdev-ops.h +++ b/net/wireless/rdev-ops.h @@ -1205,6 +1205,22 @@ rdev_nan_ndp_initiate(struct cfg80211_registered_device *rdev, return ret; } +static inline int +rdev_nan_ndp_respond(struct cfg80211_registered_device *rdev, + struct wireless_dev *wdev, + struct cfg80211_nan_ndp_respond *params) +{ + int ret; + + if (!rdev->ops->nan_ndp_respond) + return -EOPNOTSUPP; + + trace_rdev_nan_ndp_respond(&rdev->wiphy, wdev, params); + ret = rdev->ops->nan_ndp_respond(&rdev->wiphy, wdev, params); + trace_rdev_return_int(&rdev->wiphy, ret); + return ret; +} + static inline int rdev_set_mac_acl(struct cfg80211_registered_device *rdev, struct net_device *dev, struct cfg80211_acl_data *params) diff --git a/net/wireless/trace.h b/net/wireless/trace.h index 131fb5657004..7888a2c8d256 100644 --- a/net/wireless/trace.h +++ b/net/wireless/trace.h @@ -2646,6 +2646,92 @@ TRACE_EVENT(rdev_nan_ndp_initiate, #undef RDEV_NAN_NDP_INITIATE_FMT_4 #undef RDEV_NAN_NDP_INITIATE_FMT_5 +#define NDP_RESP_FMT_1 \ + ", peer_nmi: %pM, ndp_id: %u, init_ndi: %pM, " +#define NDP_RESP_FMT_2 \ + "resp_ndi: %pM, accept: %d, reason: %u, ssi_len: %u, ssi: %s, " +#define NDP_RESP_FMT_3 \ + "cipher_suite: %u, pmk_len: %u, gtk_required: %d, gtk_cipher: %u, " +#define NDP_RESP_FMT_4 \ + "ipv6_intf_id_present: %d, ipv6_intf_id: %s" + +TRACE_EVENT(rdev_nan_ndp_respond, + TP_PROTO(struct wiphy *wiphy, struct wireless_dev *wdev, + struct cfg80211_nan_ndp_respond *params), + TP_ARGS(wiphy, wdev, params), + TP_STRUCT__entry( + WIPHY_ENTRY + WDEV_ENTRY + __array(u8, peer_nmi, ETH_ALEN) + __field(u8, ndp_id) + __array(u8, init_ndi, ETH_ALEN) + __array(u8, resp_ndi, ETH_ALEN) + __field(bool, accept) + __field(u8, reason) + __field(u8, ssi_len) + __dynamic_array(u8, ssi, params->ssi_len) + __field(u32, cipher_suite) + __field(u8, pmk_len) + __field(bool, gtk_required) + __field(u32, gtk_cipher) + __field(bool, transport_info) + __field(u16, transport_port) + __field(u8, transport_protocol) + __field(bool, ipv6_intf_id_present) + __array(u8, ipv6_intf_id, NL80211_NAN_NDP_IPV6_INTF_ID_LEN) + ), + TP_fast_assign( + WIPHY_ASSIGN; + WDEV_ASSIGN; + memcpy(__entry->peer_nmi, params->peer_nmi, ETH_ALEN); + __entry->ndp_id = params->ndp_id; + memcpy(__entry->init_ndi, params->init_ndi, ETH_ALEN); + if (params->resp_ndi) + memcpy(__entry->resp_ndi, params->resp_ndi, ETH_ALEN); + else + memset(__entry->resp_ndi, 0, ETH_ALEN); + __entry->accept = params->accept; + __entry->reason = params->reason; + __entry->ssi_len = params->ssi_len; + if (params->ssi && params->ssi_len) + memcpy(__get_dynamic_array(ssi), params->ssi, + params->ssi_len); + __entry->cipher_suite = params->cipher_suite; + __entry->pmk_len = params->pmk ? params->pmk_len : 0; + __entry->gtk_required = params->gtk_required; + __entry->gtk_cipher = params->gtk_cipher; + __entry->transport_info = params->transport_info; + __entry->transport_port = params->transport_port; + __entry->transport_protocol = params->transport_protocol; + __entry->ipv6_intf_id_present = !!params->ipv6_intf_id; + if (params->ipv6_intf_id) + memcpy(__entry->ipv6_intf_id, params->ipv6_intf_id, + NL80211_NAN_NDP_IPV6_INTF_ID_LEN); + else + memset(__entry->ipv6_intf_id, 0, + NL80211_NAN_NDP_IPV6_INTF_ID_LEN); + ), + TP_printk(WIPHY_PR_FMT ", " WDEV_PR_FMT + NDP_RESP_FMT_1 NDP_RESP_FMT_2 NDP_RESP_FMT_3 NDP_RESP_FMT_4 + ", transport_info: %d, transport_port: %u, transport_protocol: %u", + WIPHY_PR_ARG, WDEV_PR_ARG, __entry->peer_nmi, __entry->ndp_id, + __entry->init_ndi, __entry->resp_ndi, __entry->accept, + __entry->reason, __entry->ssi_len, + __print_array(__get_dynamic_array(ssi), __entry->ssi_len, + sizeof(u8)), + __entry->cipher_suite, __entry->pmk_len, + __entry->gtk_required, __entry->gtk_cipher, + __entry->ipv6_intf_id_present, + __print_array(__entry->ipv6_intf_id, + NL80211_NAN_NDP_IPV6_INTF_ID_LEN, sizeof(u8)), + __entry->transport_info, __entry->transport_port, + __entry->transport_protocol) +); +#undef NDP_RESP_FMT_1 +#undef NDP_RESP_FMT_2 +#undef NDP_RESP_FMT_3 +#undef NDP_RESP_FMT_4 + TRACE_EVENT(rdev_set_mac_acl, TP_PROTO(struct wiphy *wiphy, struct net_device *netdev, struct cfg80211_acl_data *params), -- 2.34.1 Add NL80211_CMD_NAN_NDP_TERMINATE to let userspace tear down an established NDP session when the device offloads NDP management. Pass the initiator NDI from the request through to the driver; it may identify either the local or peer NDI and is not validated as a local interface. Add the termination parameter structure, command handler, and driver callback, and trace the initiator NDI with the other request metadata. Signed-off-by: Shivani Baranwal --- include/net/cfg80211.h | 22 ++++++++++++++ include/uapi/linux/nl80211.h | 7 +++++ net/wireless/nl80211.c | 58 ++++++++++++++++++++++++++++++++++++ net/wireless/rdev-ops.h | 16 ++++++++++ net/wireless/trace.h | 27 +++++++++++++++++ 5 files changed, 130 insertions(+) diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index 151555fa8404..e07e167caaf7 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h @@ -4443,6 +4443,21 @@ struct cfg80211_nan_ndp_respond { u8 transport_protocol; }; +/** + * struct cfg80211_nan_ndp_terminate - NAN NDP terminate parameters + * + * @peer_nmi: peer NMI address + * @ndp_id: NDP ID to terminate + * @init_ndi: initiator NDI MAC address + * @reason: Wi-Fi Aware reason code for termination + */ +struct cfg80211_nan_ndp_terminate { + const u8 *peer_nmi; + u8 ndp_id; + const u8 *init_ndi; + u8 reason; +}; + /** * enum cfg80211_nan_conf_changes - indicates changed fields in NAN * configuration @@ -5436,6 +5451,10 @@ struct mgmt_frame_regs { * Only valid if the driver has set %WIPHY_NAN_FLAGS_OFFLOAD_NDP. Returning * success acknowledges the response command only; setup outcome is reported * asynchronously after the handshake. + * @nan_ndp_terminate: Terminate an established NDP session. + * Only valid if the driver has set %WIPHY_NAN_FLAGS_OFFLOAD_NDP. Returning + * success acknowledges the request; report completion asynchronously with + * cfg80211_nan_ndp_terminated(). * * @set_multicast_to_unicast: configure multicast to unicast conversion for BSS * @@ -5850,6 +5869,9 @@ struct cfg80211_ops { int (*nan_ndp_respond)(struct wiphy *wiphy, struct wireless_dev *wdev, struct cfg80211_nan_ndp_respond *params); + int (*nan_ndp_terminate)(struct wiphy *wiphy, + struct wireless_dev *wdev, + struct cfg80211_nan_ndp_terminate *params); int (*set_multicast_to_unicast)(struct wiphy *wiphy, struct net_device *dev, const bool enabled); diff --git a/include/uapi/linux/nl80211.h b/include/uapi/linux/nl80211.h index bdd52fcafe85..0303b9f22a5d 100644 --- a/include/uapi/linux/nl80211.h +++ b/include/uapi/linux/nl80211.h @@ -1512,6 +1512,12 @@ * processing; setup outcome is reported asynchronously by * %NL80211_CMD_NAN_NDP_STATUS. * Transport port and protocol may be supplied together only when accepting. + * @NL80211_CMD_NAN_NDP_TERMINATE: Terminate an established NDP. + * Requires %NL80211_NAN_CAPA_OFFLOAD_NDP. Carries %NL80211_ATTR_NAN_NDP + * nested with %NL80211_NAN_NDP_ATTR_ID, %NL80211_NAN_NDP_ATTR_INIT_NDI + * and optionally %NL80211_NAN_NDP_ATTR_REASON. + * The command reply acknowledges the request; teardown completion is + * reported asynchronously by the termination notification. * * @NL80211_CMD_MAX: highest used command number * @__NL80211_CMD_AFTER_LAST: internal use @@ -1797,6 +1803,7 @@ enum nl80211_commands { NL80211_CMD_NAN_NDP_INITIATE, NL80211_CMD_NAN_NDP_RESPOND, + NL80211_CMD_NAN_NDP_TERMINATE, /* add new commands above here */ diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index 85b8181b7c68..abd17ee04c94 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -18919,6 +18919,58 @@ static int nl80211_nan_ndp_respond(struct sk_buff *skb, return rdev_nan_ndp_respond(rdev, wdev, ¶ms); } +static int nl80211_nan_ndp_terminate(struct sk_buff *skb, + struct genl_info *info) +{ + struct cfg80211_registered_device *rdev = info->user_ptr[0]; + struct wireless_dev *wdev = info->user_ptr[1]; + struct nlattr *tb[NL80211_NAN_NDP_ATTR_MAX + 1]; + struct cfg80211_nan_ndp_terminate params = {}; + int err; + + if (wdev->iftype != NL80211_IFTYPE_NAN) { + NL_SET_ERR_MSG(info->extack, + "NDP terminate requires NAN interface"); + return -EOPNOTSUPP; + } + + if (!(rdev->wiphy.nan_capa.flags & WIPHY_NAN_FLAGS_OFFLOAD_NDP)) { + NL_SET_ERR_MSG(info->extack, + "NAN NDP offload not supported by driver"); + return -EOPNOTSUPP; + } + + if (!info->attrs[NL80211_ATTR_MAC] || + !info->attrs[NL80211_ATTR_NAN_NDP]) { + NL_SET_ERR_MSG(info->extack, + "NDP terminate requires peer NMI and NDP params"); + return -EINVAL; + } + + err = nla_parse_nested(tb, NL80211_NAN_NDP_ATTR_MAX, + info->attrs[NL80211_ATTR_NAN_NDP], + nl80211_nan_ndp_policy, + info->extack); + if (err) + return err; + + if (!tb[NL80211_NAN_NDP_ATTR_ID] || + !tb[NL80211_NAN_NDP_ATTR_INIT_NDI]) { + NL_SET_ERR_MSG(info->extack, + "NDP terminate requires NDP ID and INIT_NDI"); + return -EINVAL; + } + + params.peer_nmi = nla_data(info->attrs[NL80211_ATTR_MAC]); + params.ndp_id = nla_get_u8(tb[NL80211_NAN_NDP_ATTR_ID]); + params.init_ndi = nla_data(tb[NL80211_NAN_NDP_ATTR_INIT_NDI]); + + if (tb[NL80211_NAN_NDP_ATTR_REASON]) + params.reason = nla_get_u8(tb[NL80211_NAN_NDP_ATTR_REASON]); + + return rdev_nan_ndp_terminate(rdev, wdev, ¶ms); +} + static bool nl80211_nan_is_sched_empty(struct cfg80211_nan_local_sched *sched) { if (!sched->n_channels) @@ -22094,6 +22146,12 @@ static const struct genl_small_ops nl80211_small_ops[] = { .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP | NL80211_FLAG_CLEAR_SKB), }, + { + .cmd = NL80211_CMD_NAN_NDP_TERMINATE, + .doit = nl80211_nan_ndp_terminate, + .flags = GENL_ADMIN_PERM, + .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP), + }, }; static struct genl_family nl80211_fam __ro_after_init = { diff --git a/net/wireless/rdev-ops.h b/net/wireless/rdev-ops.h index d65dd39a1bcb..8bcc999be166 100644 --- a/net/wireless/rdev-ops.h +++ b/net/wireless/rdev-ops.h @@ -1221,6 +1221,22 @@ rdev_nan_ndp_respond(struct cfg80211_registered_device *rdev, return ret; } +static inline int +rdev_nan_ndp_terminate(struct cfg80211_registered_device *rdev, + struct wireless_dev *wdev, + struct cfg80211_nan_ndp_terminate *params) +{ + int ret; + + if (!rdev->ops->nan_ndp_terminate) + return -EOPNOTSUPP; + + trace_rdev_nan_ndp_terminate(&rdev->wiphy, wdev, params); + ret = rdev->ops->nan_ndp_terminate(&rdev->wiphy, wdev, params); + trace_rdev_return_int(&rdev->wiphy, ret); + return ret; +} + static inline int rdev_set_mac_acl(struct cfg80211_registered_device *rdev, struct net_device *dev, struct cfg80211_acl_data *params) diff --git a/net/wireless/trace.h b/net/wireless/trace.h index 7888a2c8d256..c7a3c0e4b565 100644 --- a/net/wireless/trace.h +++ b/net/wireless/trace.h @@ -2732,6 +2732,33 @@ TRACE_EVENT(rdev_nan_ndp_respond, #undef NDP_RESP_FMT_3 #undef NDP_RESP_FMT_4 +TRACE_EVENT(rdev_nan_ndp_terminate, + TP_PROTO(struct wiphy *wiphy, struct wireless_dev *wdev, + struct cfg80211_nan_ndp_terminate *params), + TP_ARGS(wiphy, wdev, params), + TP_STRUCT__entry( + WIPHY_ENTRY + WDEV_ENTRY + __array(u8, peer_nmi, ETH_ALEN) + __field(u8, ndp_id) + __array(u8, init_ndi, ETH_ALEN) + __field(u8, reason) + ), + TP_fast_assign( + WIPHY_ASSIGN; + WDEV_ASSIGN; + memcpy(__entry->peer_nmi, params->peer_nmi, ETH_ALEN); + __entry->ndp_id = params->ndp_id; + memcpy(__entry->init_ndi, params->init_ndi, ETH_ALEN); + __entry->reason = params->reason; + ), + TP_printk(WIPHY_PR_FMT ", " WDEV_PR_FMT + ", peer_nmi: %pM, ndp_id: %u, init_ndi: %pM, reason: %u", + WIPHY_PR_ARG, WDEV_PR_ARG, + __entry->peer_nmi, __entry->ndp_id, __entry->init_ndi, + __entry->reason) +); + TRACE_EVENT(rdev_set_mac_acl, TP_PROTO(struct wiphy *wiphy, struct net_device *netdev, struct cfg80211_acl_data *params), -- 2.34.1 Use NL80211_CMD_NAN_NDP_INITIATE to notify userspace when the device receives an NDP Request from a peer. Provide the received request parameters through cfg80211_nan_ndp_request() so userspace can choose the responder NDI and accept or reject the request. Carry transport port and protocol values received from the peer in the request indication, so userspace can learn how to reach the peer service. Validate the notification parameters, trace them without PMKID bytes, and deliver the event to the NAN owner or multicast group. Signed-off-by: Shivani Baranwal --- include/net/cfg80211.h | 55 ++++++++++++++++++++ include/uapi/linux/nl80211.h | 9 +++- net/wireless/nl80211.c | 99 ++++++++++++++++++++++++++++++++++++ net/wireless/trace.h | 83 ++++++++++++++++++++++++++++++ 4 files changed, 245 insertions(+), 1 deletion(-) diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index e07e167caaf7..f208db3541f8 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h @@ -4458,6 +4458,46 @@ struct cfg80211_nan_ndp_terminate { u8 reason; }; +/** + * struct cfg80211_nan_ndp_request_params - NAN NDP request event parameters + * + * Sent to userspace when the driver receives a NDP Request frame. + * + * @peer_nmi: peer NMI address + * @ndp_id: NDP ID from the received frame + * @init_ndi: initiator NDI MAC from the received frame + * @publish_id: publisher's service instance ID + * @ssi: service-specific info (may be NULL) + * @ssi_len: length of @ssi + * @cipher_suite: initiator's cipher suite ID + * @pmkid: PMKID from the peer's SCIA attribute (16 bytes), or NULL if absent + * @gtk_required: if true, initiator requires GTK protection + * @gtk_cipher: GTK cipher suite ID, included when @gtk_required is true + * @ipv6_intf_id: initiator's IPv6 link-local interface identifier, or NULL + * if absent + * @transport_info: if true, the request contained transport information + * @transport_port: transport port received from the peer when + * @transport_info is true + * @transport_protocol: IANA protocol number received from the peer when + * @transport_info is true + */ +struct cfg80211_nan_ndp_request_params { + const u8 *peer_nmi; + u8 ndp_id; + const u8 *init_ndi; + u8 publish_id; + const u8 *ssi; + u8 ssi_len; + u32 cipher_suite; + const u8 *pmkid; + bool gtk_required; + u32 gtk_cipher; + const u8 *ipv6_intf_id; + bool transport_info; + u16 transport_port; + u8 transport_protocol; +}; + /** * enum cfg80211_nan_conf_changes - indicates changed fields in NAN * configuration @@ -11355,6 +11395,21 @@ cfg80211_s1g_get_primary_sibling(struct wiphy *wiphy, } +/** + * cfg80211_nan_ndp_request - notify userspace of a received NDP request + * @wdev: the wireless device reporting the event + * @params: NDP request parameters parsed from the received frame + * @gfp: allocation flags + * + * Notify userspace that a NAN Data Path request was received from a peer. + * This starts a responder-side setup attempt; the driver reports its final + * result once, including on rejection, failure, or timeout. Only valid when + * %WIPHY_NAN_FLAGS_OFFLOAD_NDP is set. + */ +void cfg80211_nan_ndp_request(struct wireless_dev *wdev, + const struct cfg80211_nan_ndp_request_params *params, + gfp_t gfp); + /** * cfg80211_incumbent_signal_notify - Notify userspace of incumbent signal detection * @wiphy: the wiphy to use diff --git a/include/uapi/linux/nl80211.h b/include/uapi/linux/nl80211.h index 0303b9f22a5d..ee5ec11267a3 100644 --- a/include/uapi/linux/nl80211.h +++ b/include/uapi/linux/nl80211.h @@ -1503,6 +1503,12 @@ * failure with %NL80211_CMD_NAN_NDP_STATUS. The device chooses the bandwidth. * Each accepted setup attempt completes asynchronously with exactly one * %NL80211_CMD_NAN_NDP_STATUS notification, including on failure or timeout. + * This command is also used as a notification when an NDP Request is + * received from a peer. The notification carries %NL80211_ATTR_MAC and + * %NL80211_ATTR_NAN_NDP with the received parameters. Userspace must ensure + * the responder NDI exists before sending @NL80211_CMD_NAN_NDP_RESPOND. + * Each indicated request is a setup attempt and completes with exactly one + * %NL80211_CMD_NAN_NDP_STATUS notification, including on failure or timeout. * @NL80211_CMD_NAN_NDP_RESPOND: Respond to a received NDP request as * the responder. Requires %NL80211_NAN_CAPA_OFFLOAD_NDP. The NDI * interface specified in %NL80211_NAN_NDP_ATTR_RESP_NDI must already @@ -8114,7 +8120,8 @@ enum nl80211_nan_conf_attributes { * %NL80211_CMD_NAN_NDP_INITIATE and in an accepting * %NL80211_CMD_NAN_NDP_RESPOND. The driver carries these values in the NDPE * Service Info TLV (Generic Service Protocol). If the peer does not support - * NDPE, these values are not conveyed. + * NDPE, these values are not conveyed. Peer-request notifications include + * the pair when it was included by the peer. * @NL80211_NAN_NDP_ATTR_TRANSPORT_PROTOCOL: u8 IANA protocol number. Must be * supplied with @NL80211_NAN_NDP_ATTR_TRANSPORT_PORT. * @NL80211_NAN_NDP_ATTR_CHANNEL_FREQ: optional u32 channel frequency in MHz. diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index abd17ee04c94..acbaf745df9f 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -18971,6 +18971,105 @@ static int nl80211_nan_ndp_terminate(struct sk_buff *skb, return rdev_nan_ndp_terminate(rdev, wdev, ¶ms); } +static void nl80211_send_nan_ndp_event(struct wireless_dev *wdev, + struct sk_buff *msg, gfp_t gfp) +{ + struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); + + if (wdev->owner_nlportid) + genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, + wdev->owner_nlportid); + else + genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), + msg, 0, NL80211_MCGRP_NAN, gfp); +} + +void cfg80211_nan_ndp_request(struct wireless_dev *wdev, + const struct cfg80211_nan_ndp_request_params *params, + gfp_t gfp) +{ + struct wiphy *wiphy = wdev->wiphy; + struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); + struct nlattr *ndp_attr; + struct sk_buff *msg; + void *hdr; + + if (WARN_ON_ONCE(!params->peer_nmi || !params->init_ndi || + !params->ndp_id || wdev->iftype != NL80211_IFTYPE_NAN || + !(wiphy->nan_capa.flags & + WIPHY_NAN_FLAGS_OFFLOAD_NDP))) + return; + + trace_cfg80211_nan_ndp_request(wiphy, wdev, params); + + msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); + if (!msg) + return; + + hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NAN_NDP_INITIATE); + if (!hdr) + goto nla_put_failure; + + if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || + nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), + NL80211_ATTR_PAD) || + nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->peer_nmi)) + goto nla_put_failure; + + ndp_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_NDP); + if (!ndp_attr) + goto nla_put_failure; + + if (nla_put_u8(msg, NL80211_NAN_NDP_ATTR_ID, params->ndp_id) || + nla_put(msg, NL80211_NAN_NDP_ATTR_INIT_NDI, ETH_ALEN, + params->init_ndi) || + nla_put_u8(msg, NL80211_NAN_NDP_ATTR_PUBLISH_ID, + params->publish_id)) + goto nla_put_failure; + + if (params->ssi && params->ssi_len && + nla_put(msg, NL80211_NAN_NDP_ATTR_SSI, params->ssi_len, + params->ssi)) + goto nla_put_failure; + + if (params->cipher_suite && + nla_put_u32(msg, NL80211_NAN_NDP_ATTR_CIPHER_SUITE, + params->cipher_suite)) + goto nla_put_failure; + + if (params->pmkid && + nla_put(msg, NL80211_NAN_NDP_ATTR_PMKID, WLAN_PMKID_LEN, + params->pmkid)) + goto nla_put_failure; + + if (params->gtk_required && + (nla_put_flag(msg, NL80211_NAN_NDP_ATTR_GTK_REQUIRED) || + nla_put_u32(msg, NL80211_NAN_NDP_ATTR_GTK_CIPHER, + params->gtk_cipher))) + goto nla_put_failure; + + if (params->ipv6_intf_id && + nla_put(msg, NL80211_NAN_NDP_ATTR_IPV6_INTF_ID, + NL80211_NAN_NDP_IPV6_INTF_ID_LEN, params->ipv6_intf_id)) + goto nla_put_failure; + + if (params->transport_info && + (nla_put_u16(msg, NL80211_NAN_NDP_ATTR_TRANSPORT_PORT, + params->transport_port) || + nla_put_u8(msg, NL80211_NAN_NDP_ATTR_TRANSPORT_PROTOCOL, + params->transport_protocol))) + goto nla_put_failure; + + nla_nest_end(msg, ndp_attr); + genlmsg_end(msg, hdr); + nl80211_send_nan_ndp_event(wdev, msg, gfp); + return; + +nla_put_failure: + nlmsg_free(msg); +} +EXPORT_SYMBOL(cfg80211_nan_ndp_request); + static bool nl80211_nan_is_sched_empty(struct cfg80211_nan_local_sched *sched) { if (!sched->n_channels) diff --git a/net/wireless/trace.h b/net/wireless/trace.h index c7a3c0e4b565..09fe1e52431e 100644 --- a/net/wireless/trace.h +++ b/net/wireless/trace.h @@ -4607,6 +4607,89 @@ TRACE_EVENT(cfg80211_nan_cluster_joined, __entry->new_cluster ? " [new]" : "") ); +#define CFG80211_NDP_REQUEST_FMT_1 \ + ", peer_nmi: %pM, ndp_id: %u, init_ndi: %pM, " +#define CFG80211_NDP_REQUEST_FMT_2 \ + "publish_id: %u, ssi_len: %u, ssi: %s, " +#define CFG80211_NDP_REQUEST_FMT_3 \ + "cipher_suite: %u, pmkid_present: %d, " +#define CFG80211_NDP_REQUEST_FMT_4 \ + "gtk_required: %d, gtk_cipher: %u, " +#define CFG80211_NDP_REQUEST_FMT_5 \ + "ipv6_intf_id_present: %d, ipv6_intf_id: %s" + +TRACE_EVENT(cfg80211_nan_ndp_request, + TP_PROTO(struct wiphy *wiphy, struct wireless_dev *wdev, + const struct cfg80211_nan_ndp_request_params *params), + TP_ARGS(wiphy, wdev, params), + TP_STRUCT__entry( + WIPHY_ENTRY + WDEV_ENTRY + __array(u8, peer_nmi, ETH_ALEN) + __field(u8, ndp_id) + __array(u8, init_ndi, ETH_ALEN) + __field(u8, publish_id) + __field(u8, ssi_len) + __dynamic_array(u8, ssi, params->ssi_len) + __field(u32, cipher_suite) + __field(bool, pmkid_present) + __field(bool, gtk_required) + __field(u32, gtk_cipher) + __field(bool, transport_info) + __field(u16, transport_port) + __field(u8, transport_protocol) + __field(bool, ipv6_intf_id_present) + __array(u8, ipv6_intf_id, NL80211_NAN_NDP_IPV6_INTF_ID_LEN) + ), + TP_fast_assign( + WIPHY_ASSIGN; + WDEV_ASSIGN; + memcpy(__entry->peer_nmi, params->peer_nmi, ETH_ALEN); + __entry->ndp_id = params->ndp_id; + memcpy(__entry->init_ndi, params->init_ndi, ETH_ALEN); + __entry->publish_id = params->publish_id; + __entry->ssi_len = params->ssi_len; + if (params->ssi && params->ssi_len) + memcpy(__get_dynamic_array(ssi), params->ssi, + params->ssi_len); + __entry->cipher_suite = params->cipher_suite; + __entry->pmkid_present = !!params->pmkid; + __entry->gtk_required = params->gtk_required; + __entry->gtk_cipher = params->gtk_cipher; + __entry->transport_info = params->transport_info; + __entry->transport_port = params->transport_port; + __entry->transport_protocol = params->transport_protocol; + __entry->ipv6_intf_id_present = !!params->ipv6_intf_id; + if (params->ipv6_intf_id) + memcpy(__entry->ipv6_intf_id, params->ipv6_intf_id, + NL80211_NAN_NDP_IPV6_INTF_ID_LEN); + else + memset(__entry->ipv6_intf_id, 0, + NL80211_NAN_NDP_IPV6_INTF_ID_LEN); + ), + TP_printk(WIPHY_PR_FMT ", " WDEV_PR_FMT + CFG80211_NDP_REQUEST_FMT_1 CFG80211_NDP_REQUEST_FMT_2 + CFG80211_NDP_REQUEST_FMT_3 CFG80211_NDP_REQUEST_FMT_4 + CFG80211_NDP_REQUEST_FMT_5 + ", transport_info: %d, transport_port: %u, transport_protocol: %u", + WIPHY_PR_ARG, WDEV_PR_ARG, __entry->peer_nmi, __entry->ndp_id, + __entry->init_ndi, __entry->publish_id, __entry->ssi_len, + __print_array(__get_dynamic_array(ssi), __entry->ssi_len, + sizeof(u8)), + __entry->cipher_suite, __entry->pmkid_present, + __entry->gtk_required, __entry->gtk_cipher, + __entry->ipv6_intf_id_present, + __print_array(__entry->ipv6_intf_id, + NL80211_NAN_NDP_IPV6_INTF_ID_LEN, sizeof(u8)), + __entry->transport_info, __entry->transport_port, + __entry->transport_protocol) +); +#undef CFG80211_NDP_REQUEST_FMT_1 +#undef CFG80211_NDP_REQUEST_FMT_2 +#undef CFG80211_NDP_REQUEST_FMT_3 +#undef CFG80211_NDP_REQUEST_FMT_4 +#undef CFG80211_NDP_REQUEST_FMT_5 + TRACE_EVENT(cfg80211_incumbent_signal_notify, TP_PROTO(struct wiphy *wiphy, const struct cfg80211_chan_def *chandef, -- 2.34.1 Add NL80211_CMD_NAN_NDP_STATUS to notify both NDP peers when setup finishes. Use the ACCEPT flag to indicate successful setup and include the responder NDI on success; report the rejection or failure reason otherwise. Add cfg80211_nan_ndp_status() and its parameter structure, validate the notification parameters, trace the status without key material, and deliver it to the NAN owner or multicast group. Include the transport port and protocol received from the peer when present. Signed-off-by: Shivani Baranwal --- include/net/cfg80211.h | 53 +++++++++++++++++++++++ include/uapi/linux/nl80211.h | 26 +++++++++--- net/wireless/nl80211.c | 81 ++++++++++++++++++++++++++++++++++++ net/wireless/trace.h | 73 ++++++++++++++++++++++++++++++++ 4 files changed, 228 insertions(+), 5 deletions(-) diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index f208db3541f8..c0846bff31be 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h @@ -4498,6 +4498,43 @@ struct cfg80211_nan_ndp_request_params { u8 transport_protocol; }; +/** + * struct cfg80211_nan_ndp_status_params - NAN NDP status event parameters + * + * Sent exactly once to userspace for each NDP setup attempt, after the driver + * completes setup successfully, fails it, or times it out. This covers both + * locally initiated NDPs and peer requests reported to userspace. + * + * @peer_nmi: peer NMI address + * @ndp_id: NDP ID + * @init_ndi: initiator NDI MAC address + * @resp_ndi: responder NDI MAC address (valid when @accepted is true) + * @accepted: if true, NDP setup succeeded; if false, setup failed + * @reason: Wi-Fi Aware reason code for failure (valid when @accepted is false) + * @ssi: response service-specific info (may be NULL) + * @ssi_len: length of @ssi + * @ipv6_intf_id: peer's IPv6 link-local interface identifier, or NULL if absent + * @transport_info: if true, the peer included transport information + * @transport_port: transport port received from the peer when + * @transport_info is true + * @transport_protocol: IANA protocol number received from the peer when + * @transport_info is true + */ +struct cfg80211_nan_ndp_status_params { + const u8 *peer_nmi; + u8 ndp_id; + const u8 *init_ndi; + const u8 *resp_ndi; + bool accepted; + u8 reason; + const u8 *ssi; + u8 ssi_len; + const u8 *ipv6_intf_id; + bool transport_info; + u16 transport_port; + u8 transport_protocol; +}; + /** * enum cfg80211_nan_conf_changes - indicates changed fields in NAN * configuration @@ -11410,6 +11447,22 @@ void cfg80211_nan_ndp_request(struct wireless_dev *wdev, const struct cfg80211_nan_ndp_request_params *params, gfp_t gfp); +/** + * cfg80211_nan_ndp_status - notify userspace that NDP setup is complete + * @wdev: the wireless device reporting the event + * @params: NDP status parameters + * @gfp: allocation flags + * + * Notify userspace that NAN Data Path setup is complete. Includes the + * setup status and, if successful, the responder NDI. Call exactly once for + * every locally initiated setup attempt and every indicated peer request, + * including failure and timeout (for example, when the peer does not respond). + * Only valid when %WIPHY_NAN_FLAGS_OFFLOAD_NDP is set. + */ +void cfg80211_nan_ndp_status(struct wireless_dev *wdev, + const struct cfg80211_nan_ndp_status_params *params, + gfp_t gfp); + /** * cfg80211_incumbent_signal_notify - Notify userspace of incumbent signal detection * @wiphy: the wiphy to use diff --git a/include/uapi/linux/nl80211.h b/include/uapi/linux/nl80211.h index ee5ec11267a3..c7b61fa16943 100644 --- a/include/uapi/linux/nl80211.h +++ b/include/uapi/linux/nl80211.h @@ -1524,6 +1524,17 @@ * and optionally %NL80211_NAN_NDP_ATTR_REASON. * The command reply acknowledges the request; teardown completion is * reported asynchronously by the termination notification. + * @NL80211_CMD_NAN_NDP_STATUS: Notification-only event sent to userspace on + * the initiator and responder sides when NDP setup finishes, successfully or + * not. If %NL80211_NAN_NDP_ATTR_ACCEPT is present, setup succeeded and + * %NL80211_NAN_NDP_ATTR_RESP_NDI is present; otherwise the notification + * carries %NL80211_NAN_NDP_ATTR_REASON. Also carries %NL80211_ATTR_MAC and + * %NL80211_ATTR_NAN_NDP. Exactly one status notification is sent for each + * setup attempt, whether initiated locally or from an indicated peer request. + * It is sent after success, failure, or timeout, including when the peer does + * not respond. + * %NL80211_ATTR_NAN_NDP, including transport information when it was + * included by the peer. * * @NL80211_CMD_MAX: highest used command number * @__NL80211_CMD_AFTER_LAST: internal use @@ -1810,6 +1821,7 @@ enum nl80211_commands { NL80211_CMD_NAN_NDP_INITIATE, NL80211_CMD_NAN_NDP_RESPOND, NL80211_CMD_NAN_NDP_TERMINATE, + NL80211_CMD_NAN_NDP_STATUS, /* add new commands above here */ @@ -8120,8 +8132,8 @@ enum nl80211_nan_conf_attributes { * %NL80211_CMD_NAN_NDP_INITIATE and in an accepting * %NL80211_CMD_NAN_NDP_RESPOND. The driver carries these values in the NDPE * Service Info TLV (Generic Service Protocol). If the peer does not support - * NDPE, these values are not conveyed. Peer-request notifications include - * the pair when it was included by the peer. + * NDPE, these values are not conveyed. Peer-request and status notifications + * include the pair when it was included by the peer. * @NL80211_NAN_NDP_ATTR_TRANSPORT_PROTOCOL: u8 IANA protocol number. Must be * supplied with @NL80211_NAN_NDP_ATTR_TRANSPORT_PORT. * @NL80211_NAN_NDP_ATTR_CHANNEL_FREQ: optional u32 channel frequency in MHz. @@ -8133,13 +8145,17 @@ enum nl80211_nan_conf_attributes { * %NL80211_CMD_NAN_NDP_INITIATE and * @NL80211_NAN_NDP_ATTR_CHANNEL_FREQ. The requested channel must be included * in the NDL. If it cannot be used, for example because it is incompatible - * with peer availability, setup fails. + * with the peer's availability, setup fails and the failure is reported + * with %NL80211_CMD_NAN_NDP_STATUS. * @NL80211_NAN_NDP_ATTR_ACCEPT: flag. If present in * %NL80211_CMD_NAN_NDP_RESPOND, it accepts the request; if absent, it is - * rejected. + * rejected. In %NL80211_CMD_NAN_NDP_STATUS it indicates setup succeeded and + * @NL80211_NAN_NDP_ATTR_RESP_NDI is present. * @NL80211_NAN_NDP_ATTR_REASON: u8 Wi-Fi Aware reason code, not an IEEE 802.11 * reason code (%NL80211_ATTR_REASON_CODE). Used for rejection with - * %NL80211_CMD_NAN_NDP_RESPOND. + * %NL80211_CMD_NAN_NDP_RESPOND, setup failure with + * %NL80211_CMD_NAN_NDP_STATUS, or termination with + * %NL80211_CMD_NAN_NDP_TERMINATE. * @__NL80211_NAN_NDP_ATTR_LAST: Internal. * @NL80211_NAN_NDP_ATTR_MAX: Highest NDP attribute. */ diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index acbaf745df9f..45d5c630e2a9 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -19070,6 +19070,87 @@ void cfg80211_nan_ndp_request(struct wireless_dev *wdev, } EXPORT_SYMBOL(cfg80211_nan_ndp_request); +void cfg80211_nan_ndp_status(struct wireless_dev *wdev, + const struct cfg80211_nan_ndp_status_params *params, + gfp_t gfp) +{ + struct wiphy *wiphy = wdev->wiphy; + struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); + struct nlattr *ndp_attr; + struct sk_buff *msg; + void *hdr; + + if (WARN_ON_ONCE(!params->peer_nmi || !params->init_ndi || + !params->ndp_id || wdev->iftype != NL80211_IFTYPE_NAN || + !(wiphy->nan_capa.flags & + WIPHY_NAN_FLAGS_OFFLOAD_NDP))) + return; + + if (WARN_ON_ONCE(params->accepted && !params->resp_ndi)) + return; + + trace_cfg80211_nan_ndp_status(wiphy, wdev, params); + + msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); + if (!msg) + return; + + hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NAN_NDP_STATUS); + if (!hdr) + goto nla_put_failure; + + if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || + nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), + NL80211_ATTR_PAD) || + nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->peer_nmi)) + goto nla_put_failure; + + ndp_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_NDP); + if (!ndp_attr) + goto nla_put_failure; + + if (nla_put_u8(msg, NL80211_NAN_NDP_ATTR_ID, params->ndp_id) || + nla_put(msg, NL80211_NAN_NDP_ATTR_INIT_NDI, ETH_ALEN, + params->init_ndi)) + goto nla_put_failure; + + if (params->accepted) { + if (nla_put_flag(msg, NL80211_NAN_NDP_ATTR_ACCEPT) || + nla_put(msg, NL80211_NAN_NDP_ATTR_RESP_NDI, ETH_ALEN, + params->resp_ndi)) + goto nla_put_failure; + } else if (nla_put_u8(msg, NL80211_NAN_NDP_ATTR_REASON, + params->reason)) { + goto nla_put_failure; + } + + if (params->ssi && params->ssi_len && + nla_put(msg, NL80211_NAN_NDP_ATTR_SSI, params->ssi_len, + params->ssi)) + goto nla_put_failure; + + if (params->ipv6_intf_id && + nla_put(msg, NL80211_NAN_NDP_ATTR_IPV6_INTF_ID, + NL80211_NAN_NDP_IPV6_INTF_ID_LEN, params->ipv6_intf_id)) + goto nla_put_failure; + + if (params->transport_info && + (nla_put_u16(msg, NL80211_NAN_NDP_ATTR_TRANSPORT_PORT, + params->transport_port) || + nla_put_u8(msg, NL80211_NAN_NDP_ATTR_TRANSPORT_PROTOCOL, + params->transport_protocol))) + goto nla_put_failure; + + nla_nest_end(msg, ndp_attr); + genlmsg_end(msg, hdr); + nl80211_send_nan_ndp_event(wdev, msg, gfp); + return; + +nla_put_failure: + nlmsg_free(msg); +} +EXPORT_SYMBOL(cfg80211_nan_ndp_status); + static bool nl80211_nan_is_sched_empty(struct cfg80211_nan_local_sched *sched) { if (!sched->n_channels) diff --git a/net/wireless/trace.h b/net/wireless/trace.h index 09fe1e52431e..518fdc91f534 100644 --- a/net/wireless/trace.h +++ b/net/wireless/trace.h @@ -4690,6 +4690,79 @@ TRACE_EVENT(cfg80211_nan_ndp_request, #undef CFG80211_NDP_REQUEST_FMT_4 #undef CFG80211_NDP_REQUEST_FMT_5 +#define CFG_NDP_STATUS_FMT_1 \ + ", peer_nmi: %pM, ndp_id: %u, init_ndi: %pM, " +#define CFG_NDP_STATUS_FMT_2 \ + "resp_ndi: %pM, accepted: %d, reason: %u, ssi_len: %u, " +#define CFG_NDP_STATUS_FMT_3 \ + "ssi: %s, ipv6_intf_id_present: %d, ipv6_intf_id: %s" + +TRACE_EVENT(cfg80211_nan_ndp_status, + TP_PROTO(struct wiphy *wiphy, struct wireless_dev *wdev, + const struct cfg80211_nan_ndp_status_params *params), + TP_ARGS(wiphy, wdev, params), + TP_STRUCT__entry( + WIPHY_ENTRY + WDEV_ENTRY + __array(u8, peer_nmi, ETH_ALEN) + __field(u8, ndp_id) + __array(u8, init_ndi, ETH_ALEN) + __array(u8, resp_ndi, ETH_ALEN) + __field(bool, accepted) + __field(u8, reason) + __field(u8, ssi_len) + __dynamic_array(u8, ssi, params->ssi_len) + __field(bool, transport_info) + __field(u16, transport_port) + __field(u8, transport_protocol) + __field(bool, ipv6_intf_id_present) + __array(u8, ipv6_intf_id, NL80211_NAN_NDP_IPV6_INTF_ID_LEN) + ), + TP_fast_assign( + WIPHY_ASSIGN; + WDEV_ASSIGN; + memcpy(__entry->peer_nmi, params->peer_nmi, ETH_ALEN); + __entry->ndp_id = params->ndp_id; + memcpy(__entry->init_ndi, params->init_ndi, ETH_ALEN); + if (params->resp_ndi) + memcpy(__entry->resp_ndi, params->resp_ndi, ETH_ALEN); + else + memset(__entry->resp_ndi, 0, ETH_ALEN); + __entry->accepted = params->accepted; + __entry->reason = params->reason; + __entry->ssi_len = params->ssi_len; + if (params->ssi && params->ssi_len) + memcpy(__get_dynamic_array(ssi), params->ssi, + params->ssi_len); + __entry->transport_info = params->transport_info; + __entry->transport_port = params->transport_port; + __entry->transport_protocol = params->transport_protocol; + __entry->ipv6_intf_id_present = !!params->ipv6_intf_id; + if (params->ipv6_intf_id) + memcpy(__entry->ipv6_intf_id, params->ipv6_intf_id, + NL80211_NAN_NDP_IPV6_INTF_ID_LEN); + else + memset(__entry->ipv6_intf_id, 0, + NL80211_NAN_NDP_IPV6_INTF_ID_LEN); + ), + TP_printk(WIPHY_PR_FMT ", " WDEV_PR_FMT + CFG_NDP_STATUS_FMT_1 CFG_NDP_STATUS_FMT_2 CFG_NDP_STATUS_FMT_3 + ", transport_info: %d, transport_port: %u, transport_protocol: %u", + WIPHY_PR_ARG, WDEV_PR_ARG, __entry->peer_nmi, __entry->ndp_id, + __entry->init_ndi, __entry->resp_ndi, __entry->accepted, + __entry->reason, __entry->ssi_len, + __print_array(__get_dynamic_array(ssi), __entry->ssi_len, + sizeof(u8)), + __entry->ipv6_intf_id_present, + __print_array(__entry->ipv6_intf_id, + NL80211_NAN_NDP_IPV6_INTF_ID_LEN, sizeof(u8)), + __entry->transport_info, __entry->transport_port, + __entry->transport_protocol) +); +#undef CFG_NDP_STATUS_FMT_1 +#undef CFG_NDP_STATUS_FMT_2 +#undef CFG_NDP_STATUS_FMT_3 + TRACE_EVENT(cfg80211_incumbent_signal_notify, TP_PROTO(struct wiphy *wiphy, const struct cfg80211_chan_def *chandef, -- 2.34.1 Use NL80211_CMD_NAN_NDP_TERMINATE to notify userspace when an NDP is terminated. Include the NDP identity and reason, and add the LOCALLY_GENERATED output flag to distinguish locally initiated termination from peer-initiated termination. Add the termination parameter and cfg80211 notification function, validate and trace the event, and deliver it to the NAN owner or multicast group. Signed-off-by: Shivani Baranwal --- include/net/cfg80211.h | 35 +++++++++++++++++++++++ include/uapi/linux/nl80211.h | 15 +++++++++- net/wireless/nl80211.c | 54 ++++++++++++++++++++++++++++++++++++ net/wireless/trace.h | 29 +++++++++++++++++++ 4 files changed, 132 insertions(+), 1 deletion(-) diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index c0846bff31be..634dffbc2ed1 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h @@ -4535,6 +4535,25 @@ struct cfg80211_nan_ndp_status_params { u8 transport_protocol; }; +/** + * struct cfg80211_nan_ndp_terminated_params - NAN NDP terminated event + * + * @peer_nmi: peer NMI address + * @ndp_id: NDP ID + * @init_ndi: initiator NDI MAC address + * @reason: Wi-Fi Aware reason code for termination + * @locally_generated: if true, teardown was initiated or detected locally + * (userspace or device) rather than by a peer termination request. Includes + * NDI down/removal, NAN stop, and peer loss. + */ +struct cfg80211_nan_ndp_terminated_params { + const u8 *peer_nmi; + u8 ndp_id; + const u8 *init_ndi; + u8 reason; + bool locally_generated; +}; + /** * enum cfg80211_nan_conf_changes - indicates changed fields in NAN * configuration @@ -11463,6 +11482,22 @@ void cfg80211_nan_ndp_status(struct wireless_dev *wdev, const struct cfg80211_nan_ndp_status_params *params, gfp_t gfp); +/** + * cfg80211_nan_ndp_terminated - notify userspace that an NDP was terminated + * @wdev: the wireless device reporting the event + * @params: NDP termination parameters + * @gfp: allocation flags + * + * Notify userspace that a NAN Data Path was torn down. Call exactly once for + * each established NDP, including teardown due to NDI down/removal, NAN stop, + * or peer loss. Only valid when %WIPHY_NAN_FLAGS_OFFLOAD_NDP is set. + * The locally_generated field is true when teardown was initiated or detected + * locally (userspace or device), and false when the peer initiated it. + */ +void cfg80211_nan_ndp_terminated(struct wireless_dev *wdev, + const struct cfg80211_nan_ndp_terminated_params *params, + gfp_t gfp); + /** * cfg80211_incumbent_signal_notify - Notify userspace of incumbent signal detection * @wiphy: the wiphy to use diff --git a/include/uapi/linux/nl80211.h b/include/uapi/linux/nl80211.h index c7b61fa16943..1901d0dc86d0 100644 --- a/include/uapi/linux/nl80211.h +++ b/include/uapi/linux/nl80211.h @@ -1524,6 +1524,13 @@ * and optionally %NL80211_NAN_NDP_ATTR_REASON. * The command reply acknowledges the request; teardown completion is * reported asynchronously by the termination notification. + * This command is also used as a notification when an NDP is terminated. + * The notification carries %NL80211_ATTR_MAC and %NL80211_ATTR_NAN_NDP with + * %NL80211_NAN_NDP_ATTR_ID, %NL80211_NAN_NDP_ATTR_INIT_NDI, + * %NL80211_NAN_NDP_ATTR_REASON, and, when applicable, + * %NL80211_NAN_NDP_ATTR_LOCALLY_GENERATED. Exactly one notification is sent + * for each established NDP that terminates, including teardown due to NDI + * down/removal, NAN stop, or peer loss. * @NL80211_CMD_NAN_NDP_STATUS: Notification-only event sent to userspace on * the initiator and responder sides when NDP setup finishes, successfully or * not. If %NL80211_NAN_NDP_ATTR_ACCEPT is present, setup succeeded and @@ -8155,7 +8162,12 @@ enum nl80211_nan_conf_attributes { * reason code (%NL80211_ATTR_REASON_CODE). Used for rejection with * %NL80211_CMD_NAN_NDP_RESPOND, setup failure with * %NL80211_CMD_NAN_NDP_STATUS, or termination with - * %NL80211_CMD_NAN_NDP_TERMINATE. + * %NL80211_CMD_NAN_NDP_TERMINATE, including its termination notification. + * @NL80211_NAN_NDP_ATTR_LOCALLY_GENERATED: output-only flag, present in the + * termination notification when teardown was initiated or detected locally + * (by userspace or the device), rather than by a peer termination request. + * This includes teardown on NDI down/removal, NAN stop, and peer loss; the + * flag is absent when the peer initiated termination. * @__NL80211_NAN_NDP_ATTR_LAST: Internal. * @NL80211_NAN_NDP_ATTR_MAX: Highest NDP attribute. */ @@ -8180,6 +8192,7 @@ enum nl80211_nan_ndp_attributes { NL80211_NAN_NDP_ATTR_CHANNEL_FORCED, NL80211_NAN_NDP_ATTR_ACCEPT, NL80211_NAN_NDP_ATTR_REASON, + NL80211_NAN_NDP_ATTR_LOCALLY_GENERATED, /* keep last */ __NL80211_NAN_NDP_ATTR_LAST, diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index 45d5c630e2a9..b781e71979d0 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -19151,6 +19151,60 @@ void cfg80211_nan_ndp_status(struct wireless_dev *wdev, } EXPORT_SYMBOL(cfg80211_nan_ndp_status); +void cfg80211_nan_ndp_terminated(struct wireless_dev *wdev, + const struct cfg80211_nan_ndp_terminated_params *params, + gfp_t gfp) +{ + struct wiphy *wiphy = wdev->wiphy; + struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); + struct nlattr *ndp_attr; + struct sk_buff *msg; + void *hdr; + + if (WARN_ON_ONCE(!params->peer_nmi || !params->init_ndi || + !params->ndp_id || wdev->iftype != NL80211_IFTYPE_NAN || + !(wiphy->nan_capa.flags & + WIPHY_NAN_FLAGS_OFFLOAD_NDP))) + return; + + trace_cfg80211_nan_ndp_terminated(wiphy, wdev, params); + + msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); + if (!msg) + return; + + hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NAN_NDP_TERMINATE); + if (!hdr) + goto nla_put_failure; + + if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || + nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), + NL80211_ATTR_PAD) || + nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->peer_nmi)) + goto nla_put_failure; + + ndp_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_NDP); + if (!ndp_attr) + goto nla_put_failure; + + if (nla_put_u8(msg, NL80211_NAN_NDP_ATTR_ID, params->ndp_id) || + nla_put(msg, NL80211_NAN_NDP_ATTR_INIT_NDI, ETH_ALEN, + params->init_ndi) || + nla_put_u8(msg, NL80211_NAN_NDP_ATTR_REASON, params->reason) || + (params->locally_generated && + nla_put_flag(msg, NL80211_NAN_NDP_ATTR_LOCALLY_GENERATED))) + goto nla_put_failure; + + nla_nest_end(msg, ndp_attr); + genlmsg_end(msg, hdr); + nl80211_send_nan_ndp_event(wdev, msg, gfp); + return; + +nla_put_failure: + nlmsg_free(msg); +} +EXPORT_SYMBOL(cfg80211_nan_ndp_terminated); + static bool nl80211_nan_is_sched_empty(struct cfg80211_nan_local_sched *sched) { if (!sched->n_channels) diff --git a/net/wireless/trace.h b/net/wireless/trace.h index 518fdc91f534..9ea561402b6c 100644 --- a/net/wireless/trace.h +++ b/net/wireless/trace.h @@ -4763,6 +4763,35 @@ TRACE_EVENT(cfg80211_nan_ndp_status, #undef CFG_NDP_STATUS_FMT_2 #undef CFG_NDP_STATUS_FMT_3 +TRACE_EVENT(cfg80211_nan_ndp_terminated, + TP_PROTO(struct wiphy *wiphy, struct wireless_dev *wdev, + const struct cfg80211_nan_ndp_terminated_params *params), + TP_ARGS(wiphy, wdev, params), + TP_STRUCT__entry( + WIPHY_ENTRY + WDEV_ENTRY + __array(u8, peer_nmi, ETH_ALEN) + __field(u8, ndp_id) + __array(u8, init_ndi, ETH_ALEN) + __field(u8, reason) + __field(bool, locally_generated) + ), + TP_fast_assign( + WIPHY_ASSIGN; + WDEV_ASSIGN; + memcpy(__entry->peer_nmi, params->peer_nmi, ETH_ALEN); + __entry->ndp_id = params->ndp_id; + memcpy(__entry->init_ndi, params->init_ndi, ETH_ALEN); + __entry->reason = params->reason; + __entry->locally_generated = params->locally_generated; + ), + TP_printk(WIPHY_PR_FMT ", " WDEV_PR_FMT + ", peer_nmi: %pM, ndp_id: %u, init_ndi: %pM, reason: %u, locally_generated: %d", + WIPHY_PR_ARG, WDEV_PR_ARG, __entry->peer_nmi, + __entry->ndp_id, __entry->init_ndi, __entry->reason, + __entry->locally_generated) +); + TRACE_EVENT(cfg80211_incumbent_signal_notify, TP_PROTO(struct wiphy *wiphy, const struct cfg80211_chan_def *chandef, -- 2.34.1 From: Vinay Gannevaram With an offloaded NAN Discovery Engine, user space may need to change the service specific information of an active publish function. Allow NL80211_CMD_ADD_NAN_FUNCTION to update an existing publish function: if NL80211_ATTR_COOKIE is included, the function identified by the cookie and by NL80211_NAN_FUNC_INSTANCE_ID is updated with the complete function definition from the request. cfg80211 keeps the given cookie instead of assigning a new one and passes the instance ID to the driver, which replaces the existing function. The reply carries the same cookie and instance ID. Signed-off-by: Vinay Gannevaram Signed-off-by: Shivani Baranwal --- include/net/cfg80211.h | 10 ++++++++-- include/uapi/linux/nl80211.h | 5 +++++ net/mac80211/cfg.c | 4 ++++ net/wireless/nl80211.c | 24 +++++++++++++++++++++++- 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index 634dffbc2ed1..1216bc5a183e 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h @@ -4610,8 +4610,11 @@ struct cfg80211_nan_func_filter { * @tx_filters: filters that should be transmitted in the SDF. * @num_rx_filters: length of &rx_filters. * @num_tx_filters: length of &tx_filters. - * @instance_id: driver allocated id of the function. - * @cookie: unique NAN function identifier. + * @instance_id: driver allocated id of the function. For an update of an + * existing publish function (see %NL80211_CMD_ADD_NAN_FUNCTION), the + * instance ID of that function. + * @cookie: unique NAN function identifier. For an update, the cookie of the + * function that is updated. * @data_path_required: if true, the SDEA Data Path Required bit is set. * @security_required: if true, the SDEA Security Required bit is set. Requires * @data_path_required and %NL80211_EXT_FEATURE_SECURE_NAN. @@ -5506,6 +5509,9 @@ struct mgmt_frame_regs { * cfg80211_free_nan_func(). * On success the driver should assign an instance_id in the * provided @nan_func. + * If @nan_func->instance_id is set, the request updates the existing + * publish function with that instance ID and @nan_func->cookie, and the + * driver replaces that function with @nan_func. * @del_nan_func: Delete a NAN function. * @nan_change_conf: changes NAN configuration. The changed parameters must * be specified in @changes (using &enum cfg80211_nan_conf_changes); diff --git a/include/uapi/linux/nl80211.h b/include/uapi/linux/nl80211.h index 1901d0dc86d0..9a149db238ec 100644 --- a/include/uapi/linux/nl80211.h +++ b/include/uapi/linux/nl80211.h @@ -1113,6 +1113,11 @@ * returns, so userspace shouldn't process NAN events until it processes * the response to this command. * Look at %NL80211_ATTR_SOCKET_OWNER as well. + * If %NL80211_ATTR_COOKIE is included, the command updates the existing + * publish function identified by the cookie and by + * %NL80211_NAN_FUNC_INSTANCE_ID in %NL80211_ATTR_NAN_FUNC, e.g., to change + * the service specific information. The request carries the complete + * function definition and the function keeps its cookie and instance ID. * @NL80211_CMD_DEL_NAN_FUNCTION: Delete a NAN function by cookie. * This command is also used as a notification sent when a NAN function is * terminated. This will contain a %NL80211_ATTR_NAN_FUNC_INST_ID diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c index 6e466f8e1653..8b399d7829d8 100644 --- a/net/mac80211/cfg.c +++ b/net/mac80211/cfg.c @@ -506,6 +506,10 @@ static int ieee80211_add_nan_func(struct wiphy *wiphy, if (WARN_ON(wiphy->nan_capa.flags & WIPHY_NAN_FLAGS_USERSPACE_DE)) return -EOPNOTSUPP; + /* mac80211 allocates the instance IDs and does not support updates */ + if (nan_func->instance_id) + return -EOPNOTSUPP; + spin_lock_bh(&sdata->u.nan.de.func_lock); ret = idr_alloc(&sdata->u.nan.de.function_inst_ids, diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index b781e71979d0..15c2294d4be6 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -17511,6 +17511,7 @@ static int nl80211_nan_add_func(struct sk_buff *skb, struct sk_buff *msg = NULL; void *hdr = NULL; int err = 0; + bool update; if (wdev->iftype != NL80211_IFTYPE_NAN) return -EOPNOTSUPP; @@ -17538,7 +17539,14 @@ static int nl80211_nan_add_func(struct sk_buff *skb, if (!func) return -ENOMEM; - func->cookie = cfg80211_assign_cookie(rdev); + /* A cookie identifies an existing publish function that is updated + * with the function definition from this request. + */ + update = !!info->attrs[NL80211_ATTR_COOKIE]; + if (update) + func->cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); + else + func->cookie = cfg80211_assign_cookie(rdev); if (!tb[NL80211_NAN_FUNC_TYPE]) { err = -EINVAL; @@ -17548,6 +17556,20 @@ static int nl80211_nan_add_func(struct sk_buff *skb, func->type = nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]); + if (update) { + if (func->type != NL80211_NAN_FUNC_PUBLISH || !func->cookie || + !tb[NL80211_NAN_FUNC_INSTANCE_ID] || + !nla_get_u8(tb[NL80211_NAN_FUNC_INSTANCE_ID])) { + NL_SET_ERR_MSG(info->extack, + "NAN function update requires a publish function, a cookie and an instance ID"); + err = -EINVAL; + goto out; + } + + func->instance_id = + nla_get_u8(tb[NL80211_NAN_FUNC_INSTANCE_ID]); + } + if (!tb[NL80211_NAN_FUNC_SERVICE_ID]) { err = -EINVAL; goto out; -- 2.34.1 From: Vinay Gannevaram With an offloaded NAN Discovery Engine the device builds and transmits the Service Discovery Frames, so everything that goes into them has to be expressed with function attributes. NAN pairing, however, can be handled in user space: the PASN Authentication frames, the bootstrapping frames and the Follow-up messages with the Shared Key Descriptor attribute are built by user space and sent with NL80211_CMD_FRAME. For pairing verification, the NAN Identity Resolution attribute, which user space derives from its NAN Identity Key, must also be included in the Publish and Subscribe messages that the device transmits in the discovery windows. Add NL80211_NAN_FUNC_EXTRA_ATTRS to pass a list of complete NAN attributes that the device appends to the frames of the function. This keeps pairing, and the NAN Identity Key, in user space. Validate the attribute framing, bound the length like information elements, and only accept the attribute if the driver advertises NL80211_NAN_CAPA_FUNC_EXTRA_ATTRS. Signed-off-by: Vinay Gannevaram Signed-off-by: Shivani Baranwal --- include/net/cfg80211.h | 14 ++++++++ include/uapi/linux/nl80211.h | 15 +++++++++ net/wireless/core.c | 4 +++ net/wireless/nl80211.c | 63 ++++++++++++++++++++++++++++++++++++ net/wireless/trace.h | 9 ++++-- net/wireless/util.c | 1 + 6 files changed, 103 insertions(+), 3 deletions(-) diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index 1216bc5a183e..75fa387f3a0c 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h @@ -4641,6 +4641,14 @@ struct cfg80211_nan_func_filter { * @chandef: channel definition for FTM ranging. * @range_report: if true, a NAN Ranging Report is required after the FTM * session. + * @extra_attrs: additional NAN attributes to append to the Service Discovery + * Frames transmitted for this function. It must not contain attributes that + * the device adds itself, such as the Service Descriptor attribute or + * attributes derived from other function fields. Typical uses include the + * NAN Identity Resolution attribute for pairing verification in Publish and + * Subscribe messages. The driver is responsible for ensuring the resulting + * frame fits its supported limits. + * @extra_attrs_len: length of @extra_attrs. */ struct cfg80211_nan_func { enum nl80211_nan_function_type type; @@ -4684,6 +4692,8 @@ struct cfg80211_nan_func { bool chandef_valid; struct cfg80211_chan_def chandef; bool range_report; + const u8 *extra_attrs; + u16 extra_attrs_len; }; /** @@ -6682,6 +6692,9 @@ struct wiphy_radio { * cfg80211_nan_ndp_request(), cfg80211_nan_ndp_status(), and * cfg80211_nan_ndp_terminated(). Secure NDPs require * %NL80211_EXT_FEATURE_SECURE_NAN. + * @WIPHY_NAN_FLAGS_FUNC_EXTRA_ATTRS: Driver accepts additional per-function + * NAN attributes when the Discovery Engine is offloaded. This flag cannot + * be used with %WIPHY_NAN_FLAGS_USERSPACE_DE. */ enum wiphy_nan_flags { WIPHY_NAN_FLAGS_CONFIGURABLE_SYNC = BIT(0), @@ -6689,6 +6702,7 @@ enum wiphy_nan_flags { WIPHY_NAN_FLAGS_INSTANT_COMM = BIT(2), WIPHY_NAN_FLAGS_OFFLOAD_RANGING = BIT(3), WIPHY_NAN_FLAGS_OFFLOAD_NDP = BIT(4), + WIPHY_NAN_FLAGS_FUNC_EXTRA_ATTRS = BIT(5), }; /** diff --git a/include/uapi/linux/nl80211.h b/include/uapi/linux/nl80211.h index 9a149db238ec..66894f79148b 100644 --- a/include/uapi/linux/nl80211.h +++ b/include/uapi/linux/nl80211.h @@ -7879,6 +7879,15 @@ enum nl80211_nan_func_term_reason { * 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. + * @NL80211_NAN_FUNC_EXTRA_ATTRS: binary attribute containing additional NAN + * attributes to append to Service Discovery Frames transmitted for this + * function. Each attribute is encoded as a one-octet ID, a two-octet + * little-endian length, and that many body octets. It must not contain + * attributes that the device adds itself, such as the Service Descriptor + * attribute or attributes derived from other function attributes. Typical + * uses include the NAN Identity Resolution attribute for pairing + * verification in Publish and Subscribe messages. Requires + * %NL80211_NAN_CAPA_FUNC_EXTRA_ATTRS. * * @NUM_NL80211_NAN_FUNC_ATTR: internal * @NL80211_NAN_FUNC_ATTR_MAX: highest NAN function attribute @@ -7915,6 +7924,7 @@ enum nl80211_nan_func_attributes { NL80211_NAN_FUNC_PREAMBLE, NL80211_NAN_FUNC_CHAN, NL80211_NAN_FUNC_RANGE_REPORT, + NL80211_NAN_FUNC_EXTRA_ATTRS, /* keep last */ NUM_NL80211_NAN_FUNC_ATTR, @@ -9458,6 +9468,10 @@ enum nl80211_s1g_short_beacon_attrs { * and termination with %NL80211_CMD_NAN_NDP_INITIATE, * %NL80211_CMD_NAN_NDP_STATUS, and %NL80211_CMD_NAN_NDP_TERMINATE. * Secure NDPs additionally require %NL80211_EXT_FEATURE_SECURE_NAN. + * @NL80211_NAN_CAPA_FUNC_EXTRA_ATTRS: flag attribute. The device accepts + * %NL80211_NAN_FUNC_EXTRA_ATTRS for NAN functions when the NAN Discovery + * Engine is offloaded. This capability is not available when + * %NL80211_NAN_CAPA_USERSPACE_DE is set. * @__NL80211_NAN_CAPABILITIES_LAST: Internal * @NL80211_NAN_CAPABILITIES_MAX: Highest NAN capability attribute. */ @@ -9474,6 +9488,7 @@ enum nl80211_nan_capabilities { NL80211_NAN_CAPA_INSTANT_COMM, NL80211_NAN_CAPA_OFFLOAD_RANGING, NL80211_NAN_CAPA_OFFLOAD_NDP, + NL80211_NAN_CAPA_FUNC_EXTRA_ATTRS, /* keep last */ __NL80211_NAN_CAPABILITIES_LAST, NL80211_NAN_CAPABILITIES_MAX = __NL80211_NAN_CAPABILITIES_LAST - 1, diff --git a/net/wireless/core.c b/net/wireless/core.c index f4153c249599..0d8f9505116e 100644 --- a/net/wireless/core.c +++ b/net/wireless/core.c @@ -934,6 +934,10 @@ int wiphy_register(struct wiphy *wiphy) !rdev->ops->add_nan_func || !rdev->ops->del_nan_func || !(wiphy->nan_supported_bands & BIT(NL80211_BAND_2GHZ))))) return -EINVAL; + if (WARN_ON((wiphy->nan_capa.flags & + WIPHY_NAN_FLAGS_FUNC_EXTRA_ATTRS) && + (wiphy->nan_capa.flags & WIPHY_NAN_FLAGS_USERSPACE_DE))) + return -EINVAL; if (WARN_ON((wiphy->interface_modes & BIT(NL80211_IFTYPE_NAN_DATA)) && (!wiphy->nan_capa.phy.ht.ht_supported || wiphy->n_radio > 1))) diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index 15c2294d4be6..e1dac3d912ff 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -460,6 +460,42 @@ static int validate_nan_pmk(const struct nlattr *attr, return 0; } +static int validate_nan_func_extra_attrs(const struct nlattr *attr, + struct netlink_ext_ack *extack) +{ + const u8 *data = nla_data(attr); + unsigned int len = nla_len(attr); + unsigned int pos = 0; + + if (!len) { + NL_SET_ERR_MSG_ATTR(extack, attr, + "NAN function extra attributes must not be empty"); + return -EINVAL; + } + + while (pos < len) { + u16 attr_len; + + if (len - pos < 3) { + NL_SET_ERR_MSG_ATTR(extack, attr, + "NAN function extra attribute has a truncated header"); + return -EINVAL; + } + + attr_len = get_unaligned_le16(data + pos + 1); + pos += 3; + if (attr_len > len - pos) { + NL_SET_ERR_MSG_ATTR(extack, attr, + "NAN function extra attribute length exceeds remaining data"); + return -EINVAL; + } + + pos += attr_len; + } + + return 0; +} + static int validate_nan_avail_blob(const struct nlattr *attr, struct netlink_ext_ack *extack) { @@ -1418,6 +1454,10 @@ nl80211_nan_func_policy[NL80211_NAN_FUNC_ATTR_MAX + 1] = { NL80211_PREAMBLE_HE), [NL80211_NAN_FUNC_CHAN] = NLA_POLICY_NESTED(nl80211_policy), [NL80211_NAN_FUNC_RANGE_REPORT] = { .type = NLA_FLAG }, + [NL80211_NAN_FUNC_EXTRA_ATTRS] = + NLA_POLICY_VALIDATE_FN(NLA_BINARY, + validate_nan_func_extra_attrs, + IEEE80211_MAX_DATA_LEN), }; /* policy for Service Response Filter attributes */ @@ -3235,6 +3275,10 @@ static int nl80211_put_nan_capa(struct wiphy *wiphy, struct sk_buff *msg) nla_put_flag(msg, NL80211_NAN_CAPA_OFFLOAD_NDP)) goto fail; + if ((wiphy->nan_capa.flags & WIPHY_NAN_FLAGS_FUNC_EXTRA_ATTRS) && + nla_put_flag(msg, NL80211_NAN_CAPA_FUNC_EXTRA_ATTRS)) + goto fail; + if (nla_put_u8(msg, NL80211_NAN_CAPA_OP_MODE, wiphy->nan_capa.op_mode) || nla_put_u8(msg, NL80211_NAN_CAPA_NUM_ANTENNAS, @@ -17721,6 +17765,25 @@ static int nl80211_nan_add_func(struct sk_buff *skb, goto out; } + if (tb[NL80211_NAN_FUNC_EXTRA_ATTRS]) { + if (!(wdev->wiphy->nan_capa.flags & + WIPHY_NAN_FLAGS_FUNC_EXTRA_ATTRS)) { + NL_SET_ERR_MSG(info->extack, + "Extra NAN function attributes are not supported"); + err = -EOPNOTSUPP; + goto out; + } + + func->extra_attrs_len = nla_len(tb[NL80211_NAN_FUNC_EXTRA_ATTRS]); + func->extra_attrs = + kmemdup(nla_data(tb[NL80211_NAN_FUNC_EXTRA_ATTRS]), + func->extra_attrs_len, GFP_KERNEL); + if (!func->extra_attrs) { + err = -ENOMEM; + goto out; + } + } + func->data_path_required = nla_get_flag(tb[NL80211_NAN_FUNC_DATA_PATH_REQUIRED]); func->security_required = diff --git a/net/wireless/trace.h b/net/wireless/trace.h index 9ea561402b6c..e893dbbe66fe 100644 --- a/net/wireless/trace.h +++ b/net/wireless/trace.h @@ -2448,16 +2448,19 @@ TRACE_EVENT(rdev_add_nan_func, WDEV_ENTRY __field(u8, func_type) __field(u64, cookie) + __field(u16, extra_attrs_len) ), TP_fast_assign( WIPHY_ASSIGN; WDEV_ASSIGN; __entry->func_type = func->type; - __entry->cookie = func->cookie + __entry->cookie = func->cookie; + __entry->extra_attrs_len = func->extra_attrs_len; ), - TP_printk(WIPHY_PR_FMT ", " WDEV_PR_FMT ", type=%u, cookie=%llu", + TP_printk(WIPHY_PR_FMT ", " WDEV_PR_FMT + ", type=%u, cookie=%llu, extra_attrs_len=%u", WIPHY_PR_ARG, WDEV_PR_ARG, __entry->func_type, - __entry->cookie) + __entry->cookie, __entry->extra_attrs_len) ); TRACE_EVENT(rdev_del_nan_func, diff --git a/net/wireless/util.c b/net/wireless/util.c index 980b16c72d4f..4e1cbe50af1e 100644 --- a/net/wireless/util.c +++ b/net/wireless/util.c @@ -2876,6 +2876,7 @@ void cfg80211_free_nan_func(struct cfg80211_nan_func *f) return; kfree(f->serv_spec_info); + kfree(f->extra_attrs); kfree(f->srf_bf); kfree(f->srf_macs); kfree(f->csids); -- 2.34.1 From: Vinay Gannevaram A NAN service advertises in its Cipher Suite Info attribute whether it supports group keys (GTK and IGTK, optionally BIGTK) and whether IGTK and BIGTK use NCS-BIP-GMAC-256 instead of NCS-BIP-CMAC-128. With an offloaded Discovery Engine and NDP setup, the device builds this attribute for the Service Discovery Frames of the function and for the NDP setup frames, and it distributes and installs the group keys during NDP setup. So far, NDP offload only covers the GTK, which is requested per NDP. Add NL80211_NAN_FUNC_GROUP_KEYS and NL80211_NAN_FUNC_BIP_GMAC_256 to configure the group-key support of a function. The device also uses it for NDPs of the service and establishes the group keys that both peers support; the per-NDP GTK requirement and GTK cipher are unchanged. Use typed attributes rather than the raw capability field, whose other bits, such as the number of replay counters, are properties of the device. Signed-off-by: Vinay Gannevaram Signed-off-by: Shivani Baranwal --- include/net/cfg80211.h | 36 ++++++++++++++++++++++++------- include/uapi/linux/nl80211.h | 41 ++++++++++++++++++++++++++++++------ net/wireless/nl80211.c | 18 ++++++++++++++++ 3 files changed, 80 insertions(+), 15 deletions(-) diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index 75fa387f3a0c..6154b9c06029 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h @@ -4358,7 +4358,8 @@ struct cfg80211_nan_peer_sched { * @pmk_len: length of @pmk in bytes * @pmkid: PMKID (16 octets) to include in the NDP Request, or NULL if absent * @gtk_required: if true, GTK protection is required for group-addressed data - * frames + * frames. IGTK and BIGTK follow the service group-key support, see + * &struct cfg80211_nan_func.group_keys. * @gtk_cipher: GTK cipher suite ID, valid when @gtk_required is true * @ipv6_intf_id: IPv6 link-local interface identifier, or NULL if absent * @ndp_id: output NDP ID assigned by the driver on success (1-255) @@ -4413,7 +4414,8 @@ struct cfg80211_nan_ndp_initiate { * @cipher_suite and %NL80211_EXT_FEATURE_SECURE_NAN. * @pmk_len: length of @pmk in bytes * @gtk_required: if true, GTK protection is required for group-addressed data - * frames + * frames. IGTK and BIGTK follow the service group-key support, see + * &struct cfg80211_nan_func.group_keys. * @gtk_cipher: GTK cipher suite ID, valid when @gtk_required is true * @ipv6_intf_id: IPv6 link-local interface identifier, or NULL if absent * @transport_info: if true, convey @transport_port and @transport_protocol to @@ -4471,7 +4473,9 @@ struct cfg80211_nan_ndp_terminate { * @ssi_len: length of @ssi * @cipher_suite: initiator's cipher suite ID * @pmkid: PMKID from the peer's SCIA attribute (16 bytes), or NULL if absent - * @gtk_required: if true, initiator requires GTK protection + * @gtk_required: if true, the initiator requires GTK protection. IGTK and + * BIGTK follow the service group-key support, see + * &struct cfg80211_nan_func.group_keys. * @gtk_cipher: GTK cipher suite ID, included when @gtk_required is true * @ipv6_intf_id: initiator's IPv6 link-local interface identifier, or NULL * if absent @@ -4619,7 +4623,20 @@ struct cfg80211_nan_func_filter { * @security_required: if true, the SDEA Security Required bit is set. Requires * @data_path_required and %NL80211_EXT_FEATURE_SECURE_NAN. * @gtk_required: if true, the SDEA GTK Required bit is set for GTK protection - * of group-addressed data frames. Requires %NL80211_EXT_FEATURE_SECURE_NAN. + * of group-addressed data frames. This is independent of @group_keys, which + * advertises service group-key support. Requires + * %NL80211_EXT_FEATURE_SECURE_NAN. + * @group_keys: group-key support of the service, advertised in the Cipher + * Suite Info attribute of the Service Discovery Frames of this function, as + * defined by &enum nl80211_nan_group_keys. With + * %WIPHY_NAN_FLAGS_OFFLOAD_NDP the device also uses it for NDPs of the + * service: it advertises it in NDP setup frames (an NDP initiator uses its + * subscribe function) and establishes the group keys that both peers + * support. If zero, no group-key support is advertised. Requires + * %NL80211_EXT_FEATURE_SECURE_NAN. + * @bip_gmac_256: if true, IGTK and BIGTK use NCS-BIP-GMAC-256 instead of + * NCS-BIP-CMAC-128. Requires @group_keys and + * %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 @@ -4678,6 +4695,8 @@ struct cfg80211_nan_func { bool data_path_required; bool security_required; bool gtk_required; + u8 group_keys; + bool bip_gmac_256; u16 pairing_bootstrap_methods; u32 *csids; u8 num_csids; @@ -6682,10 +6701,11 @@ struct wiphy_radio { * and security handshakes. It negotiates the NDL and manages local and peer * NAN schedules, including NDC and immutable schedules, ULW, schedule updates, * and evacuation of its own channels. It assigns NDP IDs for locally initiated - * NDPs, derives, installs, and removes PTKs and, when requested, GTKs. The - * device creates and removes NDI peer stations for offloaded NDPs. Userspace - * must not configure NAN schedules or add those NDI peer stations or their - * keys. The driver implements @nan_ndp_initiate, @nan_ndp_respond, and + * NDPs, derives, installs, and removes PTKs and, when negotiated, GTKs, + * IGTKs, and BIGTKs (see &struct cfg80211_nan_func.group_keys). The device + * creates and removes NDI peer stations for offloaded NDPs. Userspace must + * not configure NAN schedules or add those NDI peer stations or their keys. + * The driver implements @nan_ndp_initiate, @nan_ndp_respond, and * @nan_ndp_terminate callbacks. It supports %NL80211_CMD_NAN_NDP_INITIATE, * %NL80211_CMD_NAN_NDP_RESPOND, and %NL80211_CMD_NAN_NDP_TERMINATE, and * reports peer requests, setup status, and termination with diff --git a/include/uapi/linux/nl80211.h b/include/uapi/linux/nl80211.h index 66894f79148b..c56428ce721a 100644 --- a/include/uapi/linux/nl80211.h +++ b/include/uapi/linux/nl80211.h @@ -7787,6 +7787,17 @@ enum nl80211_nan_publish_type { NL80211_NAN_UNSOLICITED_PUBLISH = 1 << 1, }; +/** + * enum nl80211_nan_group_keys - NAN group key support + * @NL80211_NAN_GROUP_KEYS_GTK_IGTK: the service supports GTK and IGTK. + * @NL80211_NAN_GROUP_KEYS_GTK_IGTK_BIGTK: the service supports GTK, IGTK, + * and BIGTK. + */ +enum nl80211_nan_group_keys { + NL80211_NAN_GROUP_KEYS_GTK_IGTK = 1, + NL80211_NAN_GROUP_KEYS_GTK_IGTK_BIGTK = 2, +}; + /** * enum nl80211_nan_func_term_reason - NAN functions termination reason * @@ -7852,7 +7863,9 @@ enum nl80211_nan_func_term_reason { * %NL80211_EXT_FEATURE_SECURE_NAN. * @NL80211_NAN_FUNC_GTK_REQUIRED: flag attribute. Sets the SDEA "GTK * Required" bit for GTK protection of group-addressed data frames. - * Requires %NL80211_EXT_FEATURE_SECURE_NAN. + * This is separate from @NL80211_NAN_FUNC_GROUP_KEYS, which advertises the + * service's group-key support in its Cipher Suite Info attribute. Requires + * %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. Requires @@ -7888,6 +7901,17 @@ enum nl80211_nan_func_term_reason { * uses include the NAN Identity Resolution attribute for pairing * verification in Publish and Subscribe messages. Requires * %NL80211_NAN_CAPA_FUNC_EXTRA_ATTRS. + * @NL80211_NAN_FUNC_GROUP_KEYS: u8 attribute, see &enum nl80211_nan_group_keys. + * Group-key support of the service, advertised in the Cipher Suite Info + * attribute of the Service Discovery Frames of this function. With + * %NL80211_NAN_CAPA_OFFLOAD_NDP the device also uses it for NDPs of the + * service: it advertises it in the NDP setup frames (an NDP initiator uses + * its subscribe function) and establishes the group keys that both peers + * support. If absent, no group-key support is advertised. Requires + * %NL80211_EXT_FEATURE_SECURE_NAN. + * @NL80211_NAN_FUNC_BIP_GMAC_256: flag attribute. IGTK and BIGTK use + * NCS-BIP-GMAC-256 instead of NCS-BIP-CMAC-128. Requires + * @NL80211_NAN_FUNC_GROUP_KEYS and %NL80211_EXT_FEATURE_SECURE_NAN. * * @NUM_NL80211_NAN_FUNC_ATTR: internal * @NL80211_NAN_FUNC_ATTR_MAX: highest NAN function attribute @@ -7925,6 +7949,8 @@ enum nl80211_nan_func_attributes { NL80211_NAN_FUNC_CHAN, NL80211_NAN_FUNC_RANGE_REPORT, NL80211_NAN_FUNC_EXTRA_ATTRS, + NL80211_NAN_FUNC_GROUP_KEYS, + NL80211_NAN_FUNC_BIP_GMAC_256, /* keep last */ NUM_NL80211_NAN_FUNC_ATTR, @@ -8143,7 +8169,8 @@ enum nl80211_nan_conf_attributes { * it carries the PMKID received in the peer's SCIA for cached-PMK lookup. * @NL80211_NAN_NDP_ATTR_GTK_REQUIRED: flag indicating that GTK protection is * required for group-addressed data frames. Requires - * @NL80211_NAN_NDP_ATTR_GTK_CIPHER; IGTK and BIGTK are not covered. + * @NL80211_NAN_NDP_ATTR_GTK_CIPHER. IGTK and BIGTK are set up according to + * the group-key support of the service, see %NL80211_NAN_FUNC_GROUP_KEYS. * @NL80211_NAN_NDP_ATTR_GTK_CIPHER: u32 GTK cipher suite ID. Required if * @NL80211_NAN_NDP_ATTR_GTK_REQUIRED is set. * @NL80211_NAN_NDP_ATTR_IPV6_INTF_ID: binary IPv6 link-local interface @@ -9457,11 +9484,11 @@ enum nl80211_s1g_short_beacon_attrs { * negotiates the NDL and manages local and peer NAN schedules, including NDC * and immutable schedules, ULW, schedule updates, and evacuation of its own * channels. It assigns NDP IDs for locally initiated NDPs and derives, - * installs, and removes data path keys (PTK and, when requested, GTK). The - * device creates and removes NDI peer stations for offloaded NDPs. Userspace - * must not configure NAN schedules or add those NDI peer stations or their - * keys. In particular, %NL80211_CMD_NAN_SET_LOCAL_SCHED, - * %NL80211_CMD_NAN_SET_PEER_SCHED, and + * installs, and removes data path keys (PTK and, when negotiated, GTK, IGTK, + * and BIGTK, see %NL80211_NAN_FUNC_GROUP_KEYS). The device creates and + * removes NDI peer stations for offloaded NDPs. Userspace must not configure + * NAN schedules or add those NDI peer stations or their keys. In particular, + * %NL80211_CMD_NAN_SET_LOCAL_SCHED, %NL80211_CMD_NAN_SET_PEER_SCHED, and * %NL80211_CMD_NAN_SET_NON_EVAC_CHANNELS are not supported. The device * supports %NL80211_CMD_NAN_NDP_INITIATE, %NL80211_CMD_NAN_NDP_RESPOND, and * %NL80211_CMD_NAN_NDP_TERMINATE, and reports peer requests, setup status, diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index e1dac3d912ff..66ce4bc3e3a0 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -1458,6 +1458,10 @@ nl80211_nan_func_policy[NL80211_NAN_FUNC_ATTR_MAX + 1] = { NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_nan_func_extra_attrs, IEEE80211_MAX_DATA_LEN), + [NL80211_NAN_FUNC_GROUP_KEYS] = + NLA_POLICY_RANGE(NLA_U8, NL80211_NAN_GROUP_KEYS_GTK_IGTK, + NL80211_NAN_GROUP_KEYS_GTK_IGTK_BIGTK), + [NL80211_NAN_FUNC_BIP_GMAC_256] = { .type = NLA_FLAG }, }; /* policy for Service Response Filter attributes */ @@ -17789,6 +17793,11 @@ static int nl80211_nan_add_func(struct sk_buff *skb, func->security_required = nla_get_flag(tb[NL80211_NAN_FUNC_SECURITY_REQUIRED]); func->gtk_required = nla_get_flag(tb[NL80211_NAN_FUNC_GTK_REQUIRED]); + if (tb[NL80211_NAN_FUNC_GROUP_KEYS]) + func->group_keys = + nla_get_u8(tb[NL80211_NAN_FUNC_GROUP_KEYS]); + func->bip_gmac_256 = + nla_get_flag(tb[NL80211_NAN_FUNC_BIP_GMAC_256]); if (func->security_required && !func->data_path_required) { NL_SET_ERR_MSG(info->extack, @@ -17798,6 +17807,8 @@ static int nl80211_nan_add_func(struct sk_buff *skb, } if (func->security_required || func->gtk_required || + tb[NL80211_NAN_FUNC_GROUP_KEYS] || + tb[NL80211_NAN_FUNC_BIP_GMAC_256] || tb[NL80211_NAN_FUNC_PAIRING_BOOTSTRAP_METHODS] || tb[NL80211_NAN_FUNC_CSIDS] || tb[NL80211_NAN_FUNC_ND_PMK]) { if (!wiphy_ext_feature_isset(wdev->wiphy, @@ -17808,6 +17819,13 @@ static int nl80211_nan_add_func(struct sk_buff *skb, goto out; } + if (func->bip_gmac_256 && !func->group_keys) { + NL_SET_ERR_MSG(info->extack, + "BIP-GMAC-256 requires group key support"); + 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]); -- 2.34.1 With Instant Communication (IC), defined in Chapter 13 of the Wi-Fi Aware Specification v4.0, the device has to know the IC channel. With a user space NAN Discovery Engine, user space configures the IC schedule. A device that offloads the Discovery Engine runs IC itself and needs to be told the channel instead. Add NL80211_NAN_CONF_INSTANT_COMM_FREQ for the IC channel frequency, and require it when IC is enabled on a device that offloads the Discovery Engine. Check that the frequency is an enabled channel in a band supported for NAN, and pass the channel to the driver in the NAN configuration. Reject the attribute without IC and on devices with a user space Discovery Engine, which keep using the user space IC schedule. Signed-off-by: Shivani Baranwal --- include/net/cfg80211.h | 4 ++++ include/uapi/linux/nl80211.h | 9 ++++++++ net/wireless/nl80211.c | 43 ++++++++++++++++++++++++++++++++++++ net/wireless/trace.h | 20 +++++++++++++---- 4 files changed, 72 insertions(+), 4 deletions(-) diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index 6154b9c06029..551ad4636177 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h @@ -4203,6 +4203,9 @@ struct cfg80211_nan_band_config { * notifications. * @instant_comm: if true, start Instant Communication (IC) as defined in * Chapter 13 of the Wi-Fi Aware Specification v4.0. + * @instant_comm_chan: Instant Communication channel, set when @instant_comm + * is true and the NAN Discovery Engine is offloaded (i.e. without + * %WIPHY_NAN_FLAGS_USERSPACE_DE), %NULL otherwise. * @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 @@ -4221,6 +4224,7 @@ struct cfg80211_nan_conf { u8 discovery_beacon_interval; bool enable_dw_notification; bool instant_comm; + struct ieee80211_channel *instant_comm_chan; 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 c56428ce721a..c590f6170c36 100644 --- a/include/uapi/linux/nl80211.h +++ b/include/uapi/linux/nl80211.h @@ -8099,6 +8099,8 @@ enum nl80211_nan_band_conf_attributes { * start Instant Communication (IC) as defined in Chapter 13 of the * Wi-Fi Aware Specification v4.0. * %NL80211_NAN_CONF_DISCOVERY_BEACON_INTERVAL must be set as well. + * %NL80211_NAN_CONF_INSTANT_COMM_FREQ must also be set when NAN Discovery + * Engine offload is used. * This is a flag attribute. * @NL80211_NAN_CONF_PAIRING_SETUP: flag attribute. Enables NAN pairing setup * and is advertised as "Pairing Setup Enabled" in the DCEA. Only valid for @@ -8110,6 +8112,12 @@ enum nl80211_nan_band_conf_attributes { * valid for devices that offload the NAN Discovery Engine (i.e. without * %NL80211_NAN_CAPA_USERSPACE_DE) and requires * %NL80211_EXT_FEATURE_SECURE_NAN. + * @NL80211_NAN_CONF_INSTANT_COMM_FREQ: u32 frequency in MHz of the Instant + * Communication channel. Only valid together with + * %NL80211_NAN_CONF_INSTANT_COMM on devices that offload the NAN Discovery + * Engine (i.e. without %NL80211_NAN_CAPA_USERSPACE_DE); required for them + * when %NL80211_NAN_CONF_INSTANT_COMM is set. The channel must be enabled + * and in a band supported for NAN. * @NUM_NL80211_NAN_CONF_ATTR: Internal. * @NL80211_NAN_CONF_ATTR_MAX: Highest NAN configuration attribute. * @@ -8128,6 +8136,7 @@ enum nl80211_nan_conf_attributes { NL80211_NAN_CONF_INSTANT_COMM, NL80211_NAN_CONF_PAIRING_SETUP, NL80211_NAN_CONF_PAIRING_NPK_CACHING, + NL80211_NAN_CONF_INSTANT_COMM_FREQ, /* keep last */ NUM_NL80211_NAN_CONF_ATTR, diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index 66ce4bc3e3a0..5843f8e793d7 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -886,6 +886,7 @@ nl80211_nan_conf_policy[NL80211_NAN_CONF_ATTR_MAX + 1] = { [NL80211_NAN_CONF_INSTANT_COMM] = { .type = NLA_FLAG }, [NL80211_NAN_CONF_PAIRING_SETUP] = { .type = NLA_FLAG }, [NL80211_NAN_CONF_PAIRING_NPK_CACHING] = { .type = NLA_FLAG }, + [NL80211_NAN_CONF_INSTANT_COMM_FREQ] = { .type = NLA_U32 }, }; static const struct netlink_range_validation nl80211_punct_bitmap_range = { @@ -17372,6 +17373,40 @@ static int nl80211_parse_nan_conf(struct wiphy *wiphy, nla_get_flag(attrs[NL80211_NAN_CONF_NOTIFY_DW]); conf->instant_comm = nla_get_flag(attrs[NL80211_NAN_CONF_INSTANT_COMM]); + if (attrs[NL80211_NAN_CONF_INSTANT_COMM_FREQ]) { + struct nlattr *ic_freq = + attrs[NL80211_NAN_CONF_INSTANT_COMM_FREQ]; + struct ieee80211_channel *chan; + + if (wiphy->nan_capa.flags & WIPHY_NAN_FLAGS_USERSPACE_DE) { + NL_SET_ERR_MSG_ATTR(info->extack, + ic_freq, + "Instant Communication frequency requires an offloaded NAN Discovery Engine"); + return -EOPNOTSUPP; + } + + if (!conf->instant_comm) { + NL_SET_ERR_MSG_ATTR(info->extack, ic_freq, + "Instant Communication frequency requires Instant Communication"); + return -EINVAL; + } + + chan = ieee80211_get_channel(wiphy, nla_get_u32(ic_freq)); + if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { + NL_SET_ERR_MSG_ATTR(info->extack, ic_freq, + "Instant Communication channel is not usable"); + return -EINVAL; + } + + if (!(wiphy->nan_supported_bands & BIT(chan->band))) { + NL_SET_ERR_MSG_ATTR(info->extack, ic_freq, + "Instant Communication channel band is not supported for NAN"); + return -EOPNOTSUPP; + } + + conf->instant_comm_chan = chan; + } + if (conf->instant_comm) { if (!(wiphy->nan_capa.flags & WIPHY_NAN_FLAGS_INSTANT_COMM)) { NL_SET_ERR_MSG_ATTR(info->extack, @@ -17386,6 +17421,14 @@ static int nl80211_parse_nan_conf(struct wiphy *wiphy, "Instant Communication requires a discovery beacon interval"); return -EINVAL; } + + if (!(wiphy->nan_capa.flags & WIPHY_NAN_FLAGS_USERSPACE_DE) && + !conf->instant_comm_chan) { + NL_SET_ERR_MSG_ATTR(info->extack, + attrs[NL80211_NAN_CONF_INSTANT_COMM], + "Instant Communication offload requires a frequency"); + return -EINVAL; + } } if (attrs[NL80211_NAN_CONF_PAIRING_SETUP] || diff --git a/net/wireless/trace.h b/net/wireless/trace.h index e893dbbe66fe..d5e29aa98089 100644 --- a/net/wireless/trace.h +++ b/net/wireless/trace.h @@ -2387,17 +2387,23 @@ TRACE_EVENT(rdev_start_nan, WDEV_ENTRY __field(u8, master_pref) __field(u8, bands) + __field(u8, instant_comm) + __field(u32, instant_comm_freq) ), TP_fast_assign( WIPHY_ASSIGN; WDEV_ASSIGN; __entry->master_pref = conf->master_pref; __entry->bands = conf->bands; + __entry->instant_comm = conf->instant_comm; + __entry->instant_comm_freq = conf->instant_comm_chan ? + conf->instant_comm_chan->center_freq : 0; ), TP_printk(WIPHY_PR_FMT ", " WDEV_PR_FMT - ", master preference: %u, bands: 0x%0x", + ", master preference: %u, bands: 0x%0x, IC: %u, IC frequency: %u", WIPHY_PR_ARG, WDEV_PR_ARG, __entry->master_pref, - __entry->bands) + __entry->bands, __entry->instant_comm, + __entry->instant_comm_freq) ); TRACE_EVENT(rdev_nan_change_conf, @@ -2409,6 +2415,8 @@ TRACE_EVENT(rdev_nan_change_conf, WDEV_ENTRY __field(u8, master_pref) __field(u8, bands) + __field(u8, instant_comm) + __field(u32, instant_comm_freq) __field(u32, changes) ), TP_fast_assign( @@ -2416,12 +2424,16 @@ TRACE_EVENT(rdev_nan_change_conf, WDEV_ASSIGN; __entry->master_pref = conf->master_pref; __entry->bands = conf->bands; + __entry->instant_comm = conf->instant_comm; + __entry->instant_comm_freq = conf->instant_comm_chan ? + conf->instant_comm_chan->center_freq : 0; __entry->changes = changes; ), TP_printk(WIPHY_PR_FMT ", " WDEV_PR_FMT - ", master preference: %u, bands: 0x%0x, changes: %x", + ", master preference: %u, bands: 0x%0x, IC: %u, IC frequency: %u, changes: %x", WIPHY_PR_ARG, WDEV_PR_ARG, __entry->master_pref, - __entry->bands, __entry->changes) + __entry->bands, __entry->instant_comm, + __entry->instant_comm_freq, __entry->changes) ); DEFINE_EVENT(wiphy_wdev_evt, rdev_stop_nan, -- 2.34.1