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 | 23 ++++++++-- net/wireless/nl80211.c | 81 ++++++++++++++++++++++++++++++++++++ net/wireless/trace.h | 73 ++++++++++++++++++++++++++++++++ 4 files changed, 226 insertions(+), 4 deletions(-) diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index caff65d0c801..6c3902939132 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h @@ -4550,6 +4550,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 @@ -11729,6 +11766,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 5c2dbe4f1463..a0d0d77346d4 100644 --- a/include/uapi/linux/nl80211.h +++ b/include/uapi/linux/nl80211.h @@ -1617,6 +1617,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 @@ -1908,6 +1919,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 */ @@ -8218,8 +8230,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_QOS_MIN_SLOTS: optional u8 Minimum Time Slots field @@ -8234,10 +8246,13 @@ enum nl80211_nan_conf_attributes { * %NL80211_CMD_NAN_NDP_RESPOND. * @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 c9b7a5b4600a..f0f25aa71b22 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -19081,6 +19081,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 be7b3162c821..7c3d8b3ac94f 100644 --- a/net/wireless/trace.h +++ b/net/wireless/trace.h @@ -4773,6 +4773,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