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 QoS requirements for the NDL schedule through the minimum time slots and maximum latency fields. The device uses these values to allocate the NDL schedule within the user-configured local schedule. 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. Build the reply and reserve the NDP ID field before calling the driver, so reply construction cannot fail after the driver accepts the request. Signed-off-by: Shivani Baranwal --- include/net/cfg80211.h | 65 ++++++++++ include/uapi/linux/nl80211.h | 105 +++++++++++++++ net/wireless/nl80211.c | 242 +++++++++++++++++++++++++++++++++++ net/wireless/rdev-ops.h | 16 +++ net/wireless/trace.h | 93 ++++++++++++++ 5 files changed, 521 insertions(+) diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index b1289d5fcd93..6b3b46a993a3 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h @@ -4387,6 +4387,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 + * @qos_min_slots: minimum number of NAN time slots required for this NDP; 0 + * means no preference + * @qos_max_latency: maximum number of NAN slots between two non-contiguous + * NDL CRBs; 0xffff means no preference + */ +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; + u8 qos_min_slots; + u16 qos_max_latency; +}; + /** * enum cfg80211_nan_conf_changes - indicates changed fields in NAN * configuration @@ -5374,6 +5428,14 @@ struct mgmt_frame_regs { * offloaded NDPs, userspace configures these channels for the device to * consider while negotiating NDL schedules. * + * @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 device cannot + * meet the QoS requirements in @params, it reports setup failure with the + * Wi-Fi Aware reason QoS_UNACCEPTABLE. + * * @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 @@ -5788,6 +5850,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 f22ad0a018a7..33af139c4d4b 100644 --- a/include/uapi/linux/nl80211.h +++ b/include/uapi/linux/nl80211.h @@ -1575,6 +1575,25 @@ * addresses (%NL80211_ATTR_MLO_LINKS, each nested link with * %NL80211_ATTR_MLO_LINK_ID, %NL80211_ATTR_BSSID and %NL80211_ATTR_MAC). * + * @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. + * %NL80211_NAN_NDP_ATTR_QOS_MIN_SLOTS and + * %NL80211_NAN_NDP_ATTR_QOS_MAX_LATENCY may be supplied as NDL QoS + * requirements. The device uses them to allocate the NDL schedule within the + * user-configured local schedule. If the device cannot meet the QoS + * requirements, setup fails and the status notification reports the Wi-Fi + * Aware reason QoS_UNACCEPTABLE. + * 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 */ @@ -1862,6 +1881,8 @@ enum nl80211_commands { NL80211_CMD_EXECUTE_SMD_TRANSITION, NL80211_CMD_COMPLETED_SMD_TRANSITION, + NL80211_CMD_NAN_NDP_INITIATE, + /* add new commands above here */ /* used to define NL80211_CMD_MAX below */ @@ -3356,6 +3377,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 @@ -3963,6 +3987,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, @@ -8120,6 +8146,85 @@ 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_QOS_MIN_SLOTS: optional u8 Minimum Time Slots field + * of the NDL QoS attribute, specifying the minimum number of NAN time slots + * required for this NDP. Absent or 0 means no preference. + * @NL80211_NAN_NDP_ATTR_QOS_MAX_LATENCY: optional u16 Maximum Latency field of + * the NDL QoS attribute, specifying the maximum number of NAN slots between + * two non-contiguous NDL CRBs. Absent or 0xffff means no preference. + * @__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_QOS_MIN_SLOTS, + NL80211_NAN_NDP_ATTR_QOS_MAX_LATENCY, + + /* 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 7426d2c8a40b..53cd9d5cd648 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -819,6 +819,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_QOS_MIN_SLOTS] = { .type = NLA_U8 }, + [NL80211_NAN_NDP_ATTR_QOS_MAX_LATENCY] = { .type = NLA_U16 }, +}; + static const struct nla_policy nl80211_nan_conf_policy[NL80211_NAN_CONF_ATTR_MAX + 1] = { [NL80211_NAN_CONF_CLUSTER_ID] = @@ -1112,6 +1140,7 @@ static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = { [NL80211_ATTR_BANDS] = { .type = NLA_U32 }, [NL80211_ATTR_NAN_CONFIG] = NLA_POLICY_NESTED(nl80211_nan_conf_policy), [NL80211_ATTR_NAN_FUNC] = { .type = NLA_NESTED }, + [NL80211_ATTR_NAN_NDP] = NLA_POLICY_NESTED(nl80211_nan_ndp_policy), [NL80211_ATTR_FILS_KEK] = { .type = NLA_BINARY, .len = FILS_MAX_KEK_LEN }, [NL80211_ATTR_FILS_NONCES] = NLA_POLICY_EXACT_LEN_WARN(2 * FILS_NONCE_LEN), @@ -18504,6 +18533,212 @@ 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]; + struct nlattr *ndp_attr, *id_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_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_QOS_MIN_SLOTS]) + params.qos_min_slots = + nla_get_u8(tb[NL80211_NAN_NDP_ATTR_QOS_MIN_SLOTS]); + + params.qos_max_latency = U16_MAX; + if (tb[NL80211_NAN_NDP_ATTR_QOS_MAX_LATENCY]) + params.qos_max_latency = + nla_get_u16(tb[NL80211_NAN_NDP_ATTR_QOS_MAX_LATENCY]); + + 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; + } + + ndp_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_NDP); + if (!ndp_attr) { + nlmsg_free(msg); + return -ENOBUFS; + } + + id_attr = nla_reserve(msg, NL80211_NAN_NDP_ATTR_ID, sizeof(u8)); + if (!id_attr) { + nlmsg_free(msg); + return -ENOBUFS; + } + + 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; + } + + *(u8 *)nla_data(id_attr) = params.ndp_id; + nla_nest_end(msg, ndp_attr); + genlmsg_end(msg, hdr); + return genlmsg_reply(msg, info); +} + static bool nl80211_nan_is_sched_empty(struct cfg80211_nan_local_sched *sched) { if (!sched->n_channels) @@ -21816,6 +22051,13 @@ static const struct genl_small_ops nl80211_small_ops[] = { .flags = GENL_UNS_ADMIN_PERM, .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), }, + { + .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 44a4255bbc03..e60478a25a31 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 b0ff3cc4176d..26e966c743c8 100644 --- a/net/wireless/trace.h +++ b/net/wireless/trace.h @@ -2552,6 +2552,99 @@ 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, qos_min_slots: %u, qos_max_latency: %u" +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(u8, qos_min_slots) + __field(u16, qos_max_latency) + ), + 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->qos_min_slots = params->qos_min_slots; + __entry->qos_max_latency = params->qos_max_latency; + ), + 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->qos_min_slots, __entry->qos_max_latency, + __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