During ST, the non-AP MLD that has been prepared with a target AP MLD may send the ST Execution frame directly to the target AP MLD. In such scenarios, the target AP MLD should pull the context from the current AP MLD to program TX and RX queues. Add nl80211 support to handle NL80211_CMD_GET_ST_CTX, which is sent by userspace of the current AP MLD on behalf of the target AP MLD. This command carries the context type to indicate to the drivers which context needs to be collected. Once the collection is complete, the context is sent back to userspace as an asynchronous multicast event using NL80211_CMD_ST_CTX_EVENT with full context data carried in NL80211_ATTR_ST_CTX. Signed-off-by: Pooventhiran G --- include/net/cfg80211.h | 20 +++++++++++++ net/wireless/nl80211.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++-- net/wireless/nl80211.h | 3 ++ net/wireless/rdev-ops.h | 14 +++++++++ net/wireless/trace.h | 26 +++++++++++++++++ 5 files changed, 138 insertions(+), 2 deletions(-) diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index 5269719c8d15..f07b7064dcb1 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h @@ -5411,6 +5411,7 @@ struct cfg80211_smd_transition_info { * @set_st_ctx: Set ST context data for the non-AP MLD. @st_info->ctx is freed * immediately after this call returns; drivers must copy @st_info->ctx * if asynchronous processing is required. + * @get_st_ctx: Get ST context data for the non-AP MLD. */ struct cfg80211_ops { int (*suspend)(struct wiphy *wiphy, struct cfg80211_wowlan *wow); @@ -5818,6 +5819,8 @@ struct cfg80211_ops { int (*set_st_ctx)(struct wiphy *wiphy, struct wireless_dev *wdev, const u8 *addr, struct cfg80211_smd_transition_info *st_info); + int (*get_st_ctx)(struct wiphy *wiphy, struct wireless_dev *wdev, + const u8 *addr, enum nl80211_st_ctx_type type); }; /* @@ -11522,4 +11525,21 @@ struct ieee80211_st_ctx { } ul; }; +/** + * cfg80211_notify_get_st_ctx_done - deliver async GET_ST_CTX result to + * userspace + * @wdev: wireless device that handled the request + * @sta_addr: non-AP MLD address the context was collected for + * @st_info: SMD Transition Info (set @st_info->ctx to NULL to indicate + * failure) + * + * Sends a multicast %NL80211_CMD_ST_CTX_EVENT reply to userspace (MLME group). + * + * Return: None + */ +void +cfg80211_notify_get_st_ctx_done(struct wireless_dev *wdev, + const u8 *sta_addr, + struct cfg80211_smd_transition_info *st_info); + #endif /* __NET_CFG80211_H */ diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index f76198cc0e84..ae54b96bc573 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -20282,8 +20282,8 @@ nl80211_put_st_ctx_ba_params(struct sk_buff *msg, unsigned long tid_bmap, return -ENOBUFS; } -static int nl80211_put_st_ctx(struct sk_buff *msg, - struct cfg80211_smd_transition_info *st_info) +int nl80211_put_st_ctx(struct sk_buff *msg, + struct cfg80211_smd_transition_info *st_info) { unsigned long dl_tid_bmap, ul_tid_bmap; const struct ieee80211_st_ctx *ctx; @@ -21166,6 +21166,36 @@ static int nl80211_set_st_ctx(struct sk_buff *skb, struct genl_info *info) return err; } +static int nl80211_get_st_ctx(struct sk_buff *skb, struct genl_info *info) +{ + struct cfg80211_registered_device *rdev = info->user_ptr[0]; + struct net_device *dev = info->user_ptr[1]; + struct wireless_dev *wdev = dev->ieee80211_ptr; + enum nl80211_st_ctx_type type; + const u8 *addr = NULL; + int err; + + if (!rdev->ops->get_st_ctx) + return -EOPNOTSUPP; + + if (wdev->iftype != NL80211_IFTYPE_AP && + wdev->iftype != NL80211_IFTYPE_AP_VLAN) + return -EINVAL; + + if (!info->attrs[NL80211_ATTR_MLD_ADDR] || + !info->attrs[NL80211_ATTR_ST_CTX_TYPE]) { + GENL_SET_ERR_MSG(info, "required attributes are missing"); + return -EINVAL; + } + + addr = nla_data(info->attrs[NL80211_ATTR_MLD_ADDR]); + type = nla_get_u8(info->attrs[NL80211_ATTR_ST_CTX_TYPE]); + + err = rdev_get_st_ctx(rdev, wdev, addr, type); + + return err; +} + #define SELECTOR(__sel, name, value) \ ((__sel) == (value)) ? NL80211_IFL_SEL_##name : int __missing_selector(void); @@ -22108,6 +22138,12 @@ static const struct genl_small_ops nl80211_small_ops[] = { .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | NL80211_FLAG_CLEAR_SKB), }, + { + .cmd = NL80211_CMD_GET_ST_CTX, + .doit = nl80211_get_st_ctx, + .flags = GENL_UNS_ADMIN_PERM, + .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), + }, }; static struct genl_family nl80211_fam __ro_after_init = { @@ -25304,6 +25340,43 @@ void cfg80211_nan_channel_evac(struct wireless_dev *wdev, } EXPORT_SYMBOL(cfg80211_nan_channel_evac); +void +cfg80211_notify_get_st_ctx_done(struct wireless_dev *wdev, + const u8 *sta_addr, + struct cfg80211_smd_transition_info *st_info) +{ + struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); + struct net_device *dev = wdev->netdev; + struct sk_buff *msg; + void *hdr; + + msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); + if (!msg) + return; + + hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ST_CTX_EVENT); + if (!hdr) + goto nla_put_failure; + + if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || + nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || + nla_put(msg, NL80211_ATTR_MLD_ADDR, ETH_ALEN, sta_addr)) + goto nla_put_failure; + + if (st_info->ctx && nl80211_put_st_ctx(msg, st_info)) + goto nla_put_failure; + + genlmsg_end(msg, hdr); + + genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, + NL80211_MCGRP_MLME, GFP_ATOMIC); + return; + +nla_put_failure: + nlmsg_free(msg); +} +EXPORT_SYMBOL(cfg80211_notify_get_st_ctx_done); + /* initialisation/exit functions */ int __init nl80211_init(void) diff --git a/net/wireless/nl80211.h b/net/wireless/nl80211.h index 1e75b38ad88d..075988f03d51 100644 --- a/net/wireless/nl80211.h +++ b/net/wireless/nl80211.h @@ -140,4 +140,7 @@ void nl80211_st_execution_response(struct cfg80211_registered_device *rdev, void nl80211_st_done(struct cfg80211_registered_device *rdev, struct net_device *dev); +int nl80211_put_st_ctx(struct sk_buff *msg, + struct cfg80211_smd_transition_info *st_info); + #endif /* __NET_WIRELESS_NL80211_H */ diff --git a/net/wireless/rdev-ops.h b/net/wireless/rdev-ops.h index 824b606479db..eb555e0c0d6a 100644 --- a/net/wireless/rdev-ops.h +++ b/net/wireless/rdev-ops.h @@ -1769,4 +1769,18 @@ static inline int rdev_set_st_ctx(struct cfg80211_registered_device *rdev, return ret; } +static inline int rdev_get_st_ctx(struct cfg80211_registered_device *rdev, + struct wireless_dev *wdev, const u8 *addr, + enum nl80211_st_ctx_type type) +{ + int ret = -EOPNOTSUPP; + + trace_rdev_get_st_ctx(&rdev->wiphy, wdev, addr, type); + if (rdev->ops->get_st_ctx) + ret = rdev->ops->get_st_ctx(&rdev->wiphy, wdev, addr, type); + trace_rdev_return_int(&rdev->wiphy, ret); + + return ret; +} + #endif /* __CFG80211_RDEV_OPS */ diff --git a/net/wireless/trace.h b/net/wireless/trace.h index 7806a2edb26f..fbd8068edb93 100644 --- a/net/wireless/trace.h +++ b/net/wireless/trace.h @@ -4736,6 +4736,32 @@ TRACE_EVENT(rdev_set_st_ctx, __entry->dl_tid_bitmap, __entry->ul_tid_bitmap ) ); + +TRACE_EVENT(rdev_get_st_ctx, + TP_PROTO(struct wiphy *wiphy, struct wireless_dev *wdev, const u8 *addr, + enum nl80211_st_ctx_type type), + + TP_ARGS(wiphy, wdev, addr, type), + + TP_STRUCT__entry( + WIPHY_ENTRY + WDEV_ENTRY + MAC_ENTRY(sta_addr) + __field(u8, st_type) + ), + + TP_fast_assign( + WIPHY_ASSIGN; + WDEV_ASSIGN; + MAC_ASSIGN(sta_addr, addr); + __entry->st_type = type; + ), + + TP_printk(WIPHY_PR_FMT ", " WDEV_PR_FMT + ", sta=%pM, ST type=%u", + WIPHY_PR_ARG, WDEV_PR_ARG, __entry->sta_addr, + __entry->st_type) +); #endif /* !__RDEV_OPS_TRACE || TRACE_HEADER_MULTI_READ */ #undef TRACE_INCLUDE_PATH -- 2.34.1