Skip to content

Commit 368e5a7

Browse files
AyalaBkrjmberg-intel
authored andcommitted
cfg80211: Provide an API to report NAN function termination
Provide a function that reports NAN DE function termination. The function may be terminated due to one of the following reasons: user request, ttl expiration or failure. If the NAN instance is tied to the owner, the notification will be sent to the socket that started the NAN interface only Signed-off-by: Andrei Otcheretianski <[email protected]> Signed-off-by: Emmanuel Grumbach <[email protected]> Signed-off-by: Luca Coelho <[email protected]> Signed-off-by: Johannes Berg <[email protected]>
1 parent 50bcd31 commit 368e5a7

File tree

3 files changed

+94
-0
lines changed

3 files changed

+94
-0
lines changed

include/net/cfg80211.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5731,6 +5731,22 @@ struct cfg80211_nan_match_params {
57315731
void cfg80211_nan_match(struct wireless_dev *wdev,
57325732
struct cfg80211_nan_match_params *match, gfp_t gfp);
57335733

5734+
/**
5735+
* cfg80211_nan_func_terminated - notify about NAN function termination.
5736+
*
5737+
* @wdev: the wireless device reporting the match
5738+
* @inst_id: the local instance id
5739+
* @reason: termination reason (one of the NL80211_NAN_FUNC_TERM_REASON_*)
5740+
* @cookie: unique NAN function identifier
5741+
* @gfp: allocation flags
5742+
*
5743+
* This function reports that the a NAN function is terminated.
5744+
*/
5745+
void cfg80211_nan_func_terminated(struct wireless_dev *wdev,
5746+
u8 inst_id,
5747+
enum nl80211_nan_func_term_reason reason,
5748+
u64 cookie, gfp_t gfp);
5749+
57345750
/* ethtool helper */
57355751
void cfg80211_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info);
57365752

include/uapi/linux/nl80211.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,9 @@
863863
* the response to this command.
864864
* Look at %NL80211_ATTR_SOCKET_OWNER as well.
865865
* @NL80211_CMD_DEL_NAN_FUNCTION: Delete a NAN function by cookie.
866+
* This command is also used as a notification sent when a NAN function is
867+
* terminated. This will contain a %NL80211_ATTR_NAN_FUNC_INST_ID
868+
* and %NL80211_ATTR_COOKIE attributes.
866869
* @NL80211_CMD_CHANGE_NAN_CONFIG: Change current NAN configuration. NAN
867870
* must be operational (%NL80211_CMD_START_NAN was executed).
868871
* It must contain at least one of the following attributes:
@@ -4985,6 +4988,21 @@ enum nl80211_nan_publish_type {
49854988
NL80211_NAN_UNSOLICITED_PUBLISH = 1 << 1,
49864989
};
49874990

4991+
/**
4992+
* enum nl80211_nan_func_term_reason - NAN functions termination reason
4993+
*
4994+
* Defines termination reasons of a NAN function
4995+
*
4996+
* @NL80211_NAN_FUNC_TERM_REASON_USER_REQUEST: requested by user
4997+
* @NL80211_NAN_FUNC_TERM_REASON_TTL_EXPIRED: timeout
4998+
* @NL80211_NAN_FUNC_TERM_REASON_ERROR: errored
4999+
*/
5000+
enum nl80211_nan_func_term_reason {
5001+
NL80211_NAN_FUNC_TERM_REASON_USER_REQUEST,
5002+
NL80211_NAN_FUNC_TERM_REASON_TTL_EXPIRED,
5003+
NL80211_NAN_FUNC_TERM_REASON_ERROR,
5004+
};
5005+
49885006
#define NL80211_NAN_FUNC_SERVICE_ID_LEN 6
49895007
#define NL80211_NAN_FUNC_SERVICE_SPEC_INFO_MAX_LEN 0xff
49905008
#define NL80211_NAN_FUNC_SRF_MAX_LEN 0xff

net/wireless/nl80211.c

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11033,6 +11033,66 @@ void cfg80211_nan_match(struct wireless_dev *wdev,
1103311033
}
1103411034
EXPORT_SYMBOL(cfg80211_nan_match);
1103511035

11036+
void cfg80211_nan_func_terminated(struct wireless_dev *wdev,
11037+
u8 inst_id,
11038+
enum nl80211_nan_func_term_reason reason,
11039+
u64 cookie, gfp_t gfp)
11040+
{
11041+
struct wiphy *wiphy = wdev->wiphy;
11042+
struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
11043+
struct sk_buff *msg;
11044+
struct nlattr *func_attr;
11045+
void *hdr;
11046+
11047+
if (WARN_ON(!inst_id))
11048+
return;
11049+
11050+
msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11051+
if (!msg)
11052+
return;
11053+
11054+
hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_NAN_FUNCTION);
11055+
if (!hdr) {
11056+
nlmsg_free(msg);
11057+
return;
11058+
}
11059+
11060+
if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11061+
(wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11062+
wdev->netdev->ifindex)) ||
11063+
nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
11064+
NL80211_ATTR_PAD))
11065+
goto nla_put_failure;
11066+
11067+
if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
11068+
NL80211_ATTR_PAD))
11069+
goto nla_put_failure;
11070+
11071+
func_attr = nla_nest_start(msg, NL80211_ATTR_NAN_FUNC);
11072+
if (!func_attr)
11073+
goto nla_put_failure;
11074+
11075+
if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, inst_id) ||
11076+
nla_put_u8(msg, NL80211_NAN_FUNC_TERM_REASON, reason))
11077+
goto nla_put_failure;
11078+
11079+
nla_nest_end(msg, func_attr);
11080+
genlmsg_end(msg, hdr);
11081+
11082+
if (!wdev->owner_nlportid)
11083+
genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
11084+
msg, 0, NL80211_MCGRP_NAN, gfp);
11085+
else
11086+
genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
11087+
wdev->owner_nlportid);
11088+
11089+
return;
11090+
11091+
nla_put_failure:
11092+
nlmsg_free(msg);
11093+
}
11094+
EXPORT_SYMBOL(cfg80211_nan_func_terminated);
11095+
1103611096
static int nl80211_get_protocol_features(struct sk_buff *skb,
1103711097
struct genl_info *info)
1103811098
{

0 commit comments

Comments
 (0)