Add NL80211_CMD_NAN_NDP_INITIATE to allow userspace to initiate a NAN Data Path session when NDP management is offloaded to firmware. Add the corresponding parameter structure, nl80211 policy, command handler, and driver callback. Reject the request if the driver has not advertised NDP offload capability or if security material is provided without secure NAN support. Signed-off-by: Shivani Baranwal --- include/net/cfg80211.h | 50 +++++++++++ include/uapi/linux/nl80211.h | 84 +++++++++++++++++++ net/wireless/nl80211.c | 156 +++++++++++++++++++++++++++++++++++ net/wireless/rdev-ops.h | 16 ++++ net/wireless/trace.h | 22 +++++ 5 files changed, 328 insertions(+) diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index aadfed50b4e2..ed1f476c526a 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h @@ -4334,6 +4334,50 @@ 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: NAN Data Path PMK (%NL80211_NAN_NDP_PMK_LEN bytes, + * valid when @pmk_set is true) + * @pmk_set: if true, @pmk contains a valid PMK + * @pmkid: PMKID (%NL80211_NAN_NDP_PMKID_LEN bytes, + * valid when @pmkid_set is true) + * @pmkid_set: if true, @pmkid contains a valid PMKID + * @gtk_required: if true, GTK protection is required + * @gtk_cipher: GTK cipher suite ID (valid when @gtk_required is true) + * @ipv6_intf_id: IPv6 link-local interface identifier + * (%NL80211_NAN_NDP_IPV6_INTF_ID_LEN bytes, + * valid when @ipv6_intf_id_set is true) + * @ipv6_intf_id_set: if true, @ipv6_intf_id is valid + * @ndpe: if true, use NDPE attribute instead of NDP attribute + */ +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; + u8 pmk[NL80211_NAN_NDP_PMK_LEN]; + bool pmk_set; + u8 pmkid[NL80211_NAN_NDP_PMKID_LEN]; + bool pmkid_set; + bool gtk_required; + u32 gtk_cipher; + u8 ipv6_intf_id[NL80211_NAN_NDP_IPV6_INTF_ID_LEN]; + bool ipv6_intf_id_set; + bool ndpe; +}; + /** * enum cfg80211_nan_conf_changes - indicates changed fields in NAN * configuration @@ -5312,6 +5356,9 @@ struct mgmt_frame_regs { * not included become evacuable again. All provided channels are * guaranteed by cfg80211 to belong to the current local schedule. * + * @nan_ndp_initiate: Initiate a NAN Data Path session as the initiator. + * Only valid if the driver has set %WIPHY_NAN_FLAGS_OFFLOAD_NDP. + * * @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 @@ -5719,6 +5766,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 05ab24b10bf9..02705ce77685 100644 --- a/include/uapi/linux/nl80211.h +++ b/include/uapi/linux/nl80211.h @@ -1468,6 +1468,13 @@ * 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 %WIPHY_NAN_FLAGS_OFFLOAD_NDP. The NDI + * interface specified in %NL80211_NAN_NDP_ATTR_INIT_NDI must already + * exist as a %NL80211_IFTYPE_NAN_DATA interface. Carries + * %NL80211_ATTR_NAN_NDP nested with %NL80211_NAN_NDP_ATTR_* fields. + * * @NL80211_CMD_MAX: highest used command number * @__NL80211_CMD_AFTER_LAST: internal use */ @@ -1750,6 +1757,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 */ @@ -3243,6 +3252,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 @@ -3850,6 +3862,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, @@ -8046,6 +8060,76 @@ enum nl80211_nan_conf_attributes { NL80211_NAN_CONF_ATTR_MAX = NUM_NL80211_NAN_CONF_ATTR - 1, }; +#define NL80211_NAN_NDP_PMKID_LEN 16 +#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). Allocated by the + * initiator and echoed in all subsequent NDP messages. + * @NL80211_NAN_NDP_ATTR_PUBLISH_ID: (u8) Publisher's service instance + * ID. Present in %NL80211_CMD_NAN_NDP_INITIATE and + * %NL80211_CMD_NAN_NDP_REQUEST. Used to match the NDP to a service. + * @NL80211_NAN_NDP_ATTR_SERVICE_ID: binary (%NL80211_NAN_FUNC_SERVICE_ID_LEN + * bytes). NAN service ID derived from the service name. + * @NL80211_NAN_NDP_ATTR_INIT_NDI: (%ETH_ALEN bytes) Initiator NDI MAC + * address. The corresponding %NL80211_IFTYPE_NAN_DATA interface must + * exist. + * @NL80211_NAN_NDP_ATTR_RESP_NDI: (%ETH_ALEN bytes) Responder NDI MAC + * address. Present in %NL80211_CMD_NAN_NDP_RESPOND (if accepting) and + * %NL80211_CMD_NAN_NDP_CONFIRM. The corresponding + * %NL80211_IFTYPE_NAN_DATA interface must exist. + * @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 (no security). See the Wi-Fi Aware Specification for values. + * @NL80211_NAN_NDP_ATTR_PMK: binary (%NL80211_NAN_NDP_PMK_LEN bytes). + * NAN Data Path PMK. + * The driver uses this to compute the PMKID and derive the PTK. + * Requires %NL80211_EXT_FEATURE_SECURE_NAN. + * @NL80211_NAN_NDP_ATTR_PMKID: binary (%NL80211_NAN_NDP_PMKID_LEN bytes). + * PMKID from the peer's + * SCIA attribute. Present in %NL80211_CMD_NAN_NDP_REQUEST to allow + * userspace to look up a cached PMK. + * @NL80211_NAN_NDP_ATTR_GTK_REQUIRED: flag. GTK/IGTK/BIGTK protection + * required for group-addressed NDP frames. + * @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 (%NL80211_NAN_NDP_IPV6_INTF_ID_LEN + * bytes). IPv6 link-local + * interface identifier. Included as NDPE TLV type 0 when present. + * @NL80211_NAN_NDP_ATTR_NDPE: flag. Use NDPE attribute instead of NDP + * attribute when peer supports NDPE. + * @__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_NDPE, + + /* 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 ecab5ca2b690..e0700aa12dbc 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -772,6 +772,30 @@ 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_EXACT_LEN(NL80211_NAN_NDP_PMK_LEN), + [NL80211_NAN_NDP_ATTR_PMKID] = + NLA_POLICY_EXACT_LEN(NL80211_NAN_NDP_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_NDPE] = { .type = NLA_FLAG }, +}; + static const struct nla_policy nl80211_nan_conf_policy[NL80211_NAN_CONF_ATTR_MAX + 1] = { [NL80211_NAN_CONF_CLUSTER_ID] = @@ -1196,6 +1220,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), @@ -18473,6 +18498,131 @@ static int nl80211_nan_set_peer_sched(struct sk_buff *skb, return rdev_nan_set_peer_sched(rdev, wdev, &sched); } +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]; + struct cfg80211_nan_ndp_initiate params = {}; + 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_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; + } + + 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_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]); + + if (tb[NL80211_NAN_NDP_ATTR_PMK]) { + if (!wiphy_ext_feature_isset(&rdev->wiphy, + NL80211_EXT_FEATURE_SECURE_NAN)) { + NL_SET_ERR_MSG_ATTR(info->extack, + tb[NL80211_NAN_NDP_ATTR_PMK], + "PMK requires SECURE_NAN feature"); + return -EOPNOTSUPP; + } + memcpy(params.pmk, + nla_data(tb[NL80211_NAN_NDP_ATTR_PMK]), + NL80211_NAN_NDP_PMK_LEN); + params.pmk_set = true; + } + + if (tb[NL80211_NAN_NDP_ATTR_PMKID]) { + if (!wiphy_ext_feature_isset(&rdev->wiphy, + NL80211_EXT_FEATURE_SECURE_NAN)) { + NL_SET_ERR_MSG_ATTR(info->extack, + tb[NL80211_NAN_NDP_ATTR_PMKID], + "PMKID requires SECURE_NAN feature"); + return -EOPNOTSUPP; + } + memcpy(params.pmkid, + nla_data(tb[NL80211_NAN_NDP_ATTR_PMKID]), + NL80211_NAN_NDP_PMKID_LEN); + params.pmkid_set = true; + } + + if (tb[NL80211_NAN_NDP_ATTR_GTK_REQUIRED]) { + if (!wiphy_ext_feature_isset(&rdev->wiphy, + NL80211_EXT_FEATURE_SECURE_NAN)) { + NL_SET_ERR_MSG_ATTR(info->extack, + tb[NL80211_NAN_NDP_ATTR_GTK_REQUIRED], + "GTK_REQUIRED requires SECURE_NAN feature"); + return -EOPNOTSUPP; + } + + 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]) { + memcpy(params.ipv6_intf_id, + nla_data(tb[NL80211_NAN_NDP_ATTR_IPV6_INTF_ID]), + NL80211_NAN_NDP_IPV6_INTF_ID_LEN); + params.ipv6_intf_id_set = true; + } + + params.ndpe = nla_get_flag(tb[NL80211_NAN_NDP_ATTR_NDPE]); + + return rdev_nan_ndp_initiate(rdev, wdev, ¶ms); +} + static bool nl80211_nan_is_sched_empty(struct cfg80211_nan_local_sched *sched) { if (!sched->n_channels) @@ -21625,6 +21775,12 @@ 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), + }, }; static struct genl_family nl80211_fam __ro_after_init = { diff --git a/net/wireless/rdev-ops.h b/net/wireless/rdev-ops.h index ae15cec9bf8b..dcf2a596a574 100644 --- a/net/wireless/rdev-ops.h +++ b/net/wireless/rdev-ops.h @@ -1183,6 +1183,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..0da1c159315b 100644 --- a/net/wireless/trace.h +++ b/net/wireless/trace.h @@ -2552,6 +2552,28 @@ TRACE_EVENT(rdev_nan_set_non_evac_channels, __entry->n_channels, sizeof(u32))) ); +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) + __field(u8, publish_id) + ), + TP_fast_assign( + WIPHY_ASSIGN; + WDEV_ASSIGN; + memcpy(__entry->peer_nmi, params->peer_nmi, ETH_ALEN); + __entry->publish_id = params->publish_id; + ), + TP_printk(WIPHY_PR_FMT ", " WDEV_PR_FMT + ", peer: %pM, publish_id: %u", + WIPHY_PR_ARG, WDEV_PR_ARG, + __entry->peer_nmi, __entry->publish_id) +); + TRACE_EVENT(rdev_set_mac_acl, TP_PROTO(struct wiphy *wiphy, struct net_device *netdev, struct cfg80211_acl_data *params), -- 2.34.1