Add NL80211_CMD_NAN_NDP_TERMINATED event to notify userspace when an established NDP is torn down. Add the corresponding parameter structure and event function so the driver can report the NDP identity and teardown reason to userspace. Signed-off-by: Shivani Baranwal --- include/net/cfg80211.h | 28 ++++++++++++++++++++ include/uapi/linux/nl80211.h | 4 +++ net/wireless/nl80211.c | 50 ++++++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+) diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index e3d3dccfa06e..8e0325501bcf 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h @@ -4505,6 +4505,21 @@ struct cfg80211_nan_ndp_confirm_params { bool ipv6_intf_id_set; }; +/** + * 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: termination reason code + */ +struct cfg80211_nan_ndp_terminated_params { + const u8 *peer_nmi; + u8 ndp_id; + const u8 *init_ndi; + u8 reason; +}; + /** * enum cfg80211_nan_conf_changes - indicates changed fields in NAN * configuration @@ -11410,6 +11425,19 @@ void cfg80211_nan_ndp_confirm(struct wireless_dev *wdev, struct cfg80211_nan_ndp_confirm_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. Only valid + * when %WIPHY_NAN_FLAGS_OFFLOAD_NDP is set. + */ +void cfg80211_nan_ndp_terminated(struct wireless_dev *wdev, + 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 58127fbd5738..71ed38992d33 100644 --- a/include/uapi/linux/nl80211.h +++ b/include/uapi/linux/nl80211.h @@ -1494,6 +1494,9 @@ * the NDP confirm parameters including %NL80211_NAN_NDP_ATTR_RESP_NDI. * Userspace should call %NL80211_CMD_NEW_STATION on the NDI interface * to add the peer NDI station. + * @NL80211_CMD_NAN_NDP_TERMINATED: Notification sent to userspace + * when an NDP is terminated. Carries %NL80211_ATTR_MAC (peer NMI) + * and %NL80211_ATTR_NAN_NDP nested with the termination parameters. * * @NL80211_CMD_MAX: highest used command number * @__NL80211_CMD_AFTER_LAST: internal use @@ -1782,6 +1785,7 @@ enum nl80211_commands { NL80211_CMD_NAN_NDP_TERMINATE, NL80211_CMD_NAN_NDP_REQUEST, NL80211_CMD_NAN_NDP_CONFIRM, + NL80211_CMD_NAN_NDP_TERMINATED, /* add new commands above here */ diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index ef7071501915..e4b664bdf53d 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -18952,6 +18952,56 @@ void cfg80211_nan_ndp_confirm(struct wireless_dev *wdev, } EXPORT_SYMBOL(cfg80211_nan_ndp_confirm); +void cfg80211_nan_ndp_terminated(struct wireless_dev *wdev, + 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(!(wiphy->nan_capa.flags & WIPHY_NAN_FLAGS_OFFLOAD_NDP))) + return; + + if (!wdev->owner_nlportid) + return; + + msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); + if (!msg) + return; + + hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NAN_NDP_TERMINATED); + 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(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)) + goto nla_put_failure; + + nla_nest_end(msg, ndp_attr); + genlmsg_end(msg, hdr); + genlmsg_unicast(wiphy_net(wiphy), msg, wdev->owner_nlportid); + 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) -- 2.34.1