With an offloaded NAN Discovery Engine, userspace may need to change the service-specific information of an active publish function. Add a separate NL80211_CMD_UPDATE_NAN_PUBLISH command, identified only by a non-zero cookie, to update the service-specific information as specified by the UpdatePublish method in Wi-Fi Aware v4.0, section 4.1.1.1. A zero-length value clears the information. All other function parameters remain unchanged, and the update does not change the remaining lifetime (TTL). Keep NL80211_CMD_ADD_NAN_FUNCTION semantics unchanged for existing drivers. Advertise the new command in the supported-commands list when the driver provides the update callback. As a new command, it uses strict netlink validation: generic netlink rejects relaxed validation flags for commands at or above the family's resv_start_op, which would make registration of the nl80211 family fail. Signed-off-by: Shivani Baranwal --- include/net/cfg80211.h | 23 ++++++++++++ include/uapi/linux/nl80211.h | 8 ++++ net/wireless/nl80211.c | 71 ++++++++++++++++++++++++++++++++++++ net/wireless/rdev-ops.h | 16 ++++++++ net/wireless/trace.h | 22 +++++++++++ 5 files changed, 140 insertions(+) diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index 99d8eb202f84..e44c5da96ece 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h @@ -4735,6 +4735,21 @@ struct cfg80211_nan_func { bool range_report; }; +/** + * struct cfg80211_nan_update_publish - update NAN publish service info + * + * @cookie: non-zero cookie of the active publish function to update + * @serv_spec_info: replacement service-specific information. The pointer is + * valid only for the duration of the callback and must not be retained. + * @serv_spec_info_len: length of @serv_spec_info. A zero length clears the + * current service-specific information. + */ +struct cfg80211_nan_update_publish { + u64 cookie; + const u8 *serv_spec_info; + u8 serv_spec_info_len; +}; + /** * struct cfg80211_pmk_conf - PMK configuration * @@ -5564,6 +5579,11 @@ struct mgmt_frame_regs { * cfg80211_free_nan_func(). * On success the driver should assign an instance_id in the * provided @nan_func. + * @nan_update_publish: Update the service-specific information of an active + * NAN publish function identified by the cookie in @params. Return -ENOENT if + * the cookie does not identify an active publish function of this wdev; + * subscribe functions cannot be updated. The service-info pointer is valid + * only for the duration of the callback. * @del_nan_func: Delete a NAN function. * @nan_change_conf: changes NAN configuration. The changed parameters must * be specified in @changes (using &enum cfg80211_nan_conf_changes); @@ -6012,6 +6032,9 @@ struct cfg80211_ops { void (*stop_nan)(struct wiphy *wiphy, struct wireless_dev *wdev); int (*add_nan_func)(struct wiphy *wiphy, struct wireless_dev *wdev, struct cfg80211_nan_func *nan_func); + int (*nan_update_publish)(struct wiphy *wiphy, + struct wireless_dev *wdev, + const struct cfg80211_nan_update_publish *params); void (*del_nan_func)(struct wiphy *wiphy, struct wireless_dev *wdev, u64 cookie); int (*nan_change_conf)(struct wiphy *wiphy, diff --git a/include/uapi/linux/nl80211.h b/include/uapi/linux/nl80211.h index b498d5ef094c..e6172abab0d6 100644 --- a/include/uapi/linux/nl80211.h +++ b/include/uapi/linux/nl80211.h @@ -1175,6 +1175,13 @@ * This command is also used as a notification sent when a NAN function is * terminated. This will contain a %NL80211_ATTR_NAN_FUNC_INST_ID * and %NL80211_ATTR_COOKIE attributes. + * @NL80211_CMD_UPDATE_NAN_PUBLISH: Update only the service-specific + * information of an active NAN publish function. The function is identified + * by a non-zero %NL80211_ATTR_COOKIE. Supply the new information as + * %NL80211_NAN_FUNC_SERVICE_INFO nested in %NL80211_ATTR_NAN_FUNC. A + * zero-length service-info attribute clears the current value. All other + * function parameters remain unchanged, and the update does not change the + * function's remaining lifetime (TTL). * @NL80211_CMD_CHANGE_NAN_CONFIG: Change current NAN * configuration. NAN must be operational (%NL80211_CMD_START_NAN * was executed). It must contain at least one of the following @@ -1927,6 +1934,7 @@ enum nl80211_commands { NL80211_CMD_NAN_NDP_RESPOND, NL80211_CMD_NAN_NDP_TERMINATE, NL80211_CMD_NAN_NDP_STATUS, + NL80211_CMD_UPDATE_NAN_PUBLISH, /* add new commands above here */ diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index f32ae55797a5..c74386dc6e01 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -3538,6 +3538,7 @@ static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev, if (rdev->wiphy.flags & WIPHY_FLAG_SMD_TRANSITION_CLIENT) CMD(execute_st, EXECUTE_SMD_TRANSITION); + CMD(nan_update_publish, UPDATE_NAN_PUBLISH); } #undef CMD @@ -17908,6 +17909,69 @@ static int nl80211_nan_add_func(struct sk_buff *skb, return -ENOBUFS; } +static int nl80211_nan_update_publish(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[NUM_NL80211_NAN_FUNC_ATTR]; + struct nlattr *func_attr, *attr; + struct cfg80211_nan_update_publish params = {}; + int rem, err; + + if (wdev->iftype != NL80211_IFTYPE_NAN) + return -EOPNOTSUPP; + + if (!wdev_running(wdev)) + return -ENOTCONN; + + if (wdev->wiphy->nan_capa.flags & WIPHY_NAN_FLAGS_USERSPACE_DE) { + NL_SET_ERR_MSG(info->extack, + "NAN Discovery Engine is in userspace"); + return -EOPNOTSUPP; + } + + if (!info->attrs[NL80211_ATTR_COOKIE] || + !info->attrs[NL80211_ATTR_NAN_FUNC]) + return -EINVAL; + + params.cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); + if (!params.cookie) { + NL_SET_ERR_MSG_ATTR(info->extack, + info->attrs[NL80211_ATTR_COOKIE], + "NAN publish cookie must be non-zero"); + return -EINVAL; + } + + func_attr = info->attrs[NL80211_ATTR_NAN_FUNC]; + nla_for_each_nested(attr, func_attr, rem) { + if (nla_type(attr) == NL80211_NAN_FUNC_SERVICE_INFO) + continue; + + NL_SET_ERR_MSG_ATTR(info->extack, attr, + "Only service-specific information can be updated"); + return -EINVAL; + } + + err = nla_parse_nested(tb, NL80211_NAN_FUNC_ATTR_MAX, func_attr, + nl80211_nan_func_policy, info->extack); + if (err) + return err; + + if (!tb[NL80211_NAN_FUNC_SERVICE_INFO]) { + NL_SET_ERR_MSG_ATTR(info->extack, func_attr, + "Service-specific information is required"); + return -EINVAL; + } + + params.serv_spec_info = + nla_data(tb[NL80211_NAN_FUNC_SERVICE_INFO]); + params.serv_spec_info_len = + nla_len(tb[NL80211_NAN_FUNC_SERVICE_INFO]); + + return rdev_nan_update_publish(rdev, wdev, ¶ms); +} + static int nl80211_nan_del_func(struct sk_buff *skb, struct genl_info *info) { @@ -22184,6 +22248,13 @@ static const struct genl_small_ops nl80211_small_ops[] = { .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP | NL80211_FLAG_CLEAR_SKB), }, + { + .cmd = NL80211_CMD_UPDATE_NAN_PUBLISH, + .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, + .doit = nl80211_nan_update_publish, + .flags = GENL_ADMIN_PERM, + .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP), + }, { .cmd = NL80211_CMD_DEL_NAN_FUNCTION, .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, diff --git a/net/wireless/rdev-ops.h b/net/wireless/rdev-ops.h index 3e4e0d768ae5..5dd95091977e 100644 --- a/net/wireless/rdev-ops.h +++ b/net/wireless/rdev-ops.h @@ -1096,6 +1096,22 @@ rdev_add_nan_func(struct cfg80211_registered_device *rdev, return ret; } +static inline int +rdev_nan_update_publish(struct cfg80211_registered_device *rdev, + struct wireless_dev *wdev, + const struct cfg80211_nan_update_publish *params) +{ + int ret; + + trace_rdev_nan_update_publish(&rdev->wiphy, wdev, params); + if (rdev->ops->nan_update_publish) + ret = rdev->ops->nan_update_publish(&rdev->wiphy, wdev, params); + else + ret = -EOPNOTSUPP; + trace_rdev_return_int(&rdev->wiphy, ret); + return ret; +} + static inline void rdev_del_nan_func(struct cfg80211_registered_device *rdev, struct wireless_dev *wdev, u64 cookie) { diff --git a/net/wireless/trace.h b/net/wireless/trace.h index b7e1eaa061c8..0b0bef1e8cb7 100644 --- a/net/wireless/trace.h +++ b/net/wireless/trace.h @@ -2460,6 +2460,28 @@ TRACE_EVENT(rdev_add_nan_func, __entry->cookie) ); +TRACE_EVENT(rdev_nan_update_publish, + TP_PROTO(struct wiphy *wiphy, struct wireless_dev *wdev, + const struct cfg80211_nan_update_publish *params), + TP_ARGS(wiphy, wdev, params), + TP_STRUCT__entry( + WIPHY_ENTRY + WDEV_ENTRY + __field(u64, cookie) + __field(u8, serv_spec_info_len) + ), + TP_fast_assign( + WIPHY_ASSIGN; + WDEV_ASSIGN; + __entry->cookie = params->cookie; + __entry->serv_spec_info_len = params->serv_spec_info_len; + ), + TP_printk(WIPHY_PR_FMT ", " WDEV_PR_FMT + ", cookie=%llu, ssi_len=%u", + WIPHY_PR_ARG, WDEV_PR_ARG, __entry->cookie, + __entry->serv_spec_info_len) +); + TRACE_EVENT(rdev_del_nan_func, TP_PROTO(struct wiphy *wiphy, struct wireless_dev *wdev, u64 cookie), -- 2.34.1