On the target AP MLD to which the STA will be transitioning, the dynamic context collected and sent by the current AP MLD needs to be programmed on the TX and RX queues to enable seamless transition and reception. Such data include Sequence Number (SN), Packet Number (PN), BlockAck sessions, and any driver-specific data. Add nl80211 support to handle NL80211_CMD_SET_ST_CTX, parse the ST context attributes, and invoke the cfg80211 operation on the target AP MLD. Signed-off-by: Pooventhiran G --- include/net/cfg80211.h | 7 ++ net/wireless/nl80211.c | 323 ++++++++++++++++++++++++++++++++++++++++++++++++ net/wireless/rdev-ops.h | 14 +++ net/wireless/trace.h | 34 +++++ 4 files changed, 378 insertions(+) diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index ade029268548..5269719c8d15 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h @@ -5407,6 +5407,10 @@ struct cfg80211_smd_transition_info { * @execute_st: Execute a previously prepared SMD transition * @abandon_st: Abandon a prepared SMD transition to the given AP MLD. * If @local_only is true don't send the ST abandon action frame. + * + * @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. */ struct cfg80211_ops { int (*suspend)(struct wiphy *wiphy, struct cfg80211_wowlan *wow); @@ -5811,6 +5815,9 @@ struct cfg80211_ops { struct cfg80211_st_exec_request *req); int (*abandon_st)(struct wiphy *wiphy, struct net_device *dev, const u8 *ap_mld_addr, bool local_only); + int (*set_st_ctx)(struct wiphy *wiphy, struct wireless_dev *wdev, + const u8 *addr, + struct cfg80211_smd_transition_info *st_info); }; /* diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index bf81d67f42ac..f76198cc0e84 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -20419,6 +20419,286 @@ static int nl80211_put_st_ctx(struct sk_buff *msg, return -ENOBUFS; } +static int nl80211_parse_st_ctx_ba_params(struct nlattr *tb, + struct ieee80211_st_ctx_ba *ba_tids, + u8 *valid_tid_bmap) +{ + struct nlattr *ba_attr; + int n_tids = 0; + int rem; + + nla_for_each_nested(ba_attr, tb, rem) { + struct nlattr *ba_tb[NL80211_ST_CTX_BA_ATTR_MAX + 1]; + struct ieee80211_st_ctx_ba *ba; + int tid = nla_type(ba_attr) - 1; + + if (tid < 0 || tid >= IEEE80211_ST_CTX_NUM_TIDS) + return -EINVAL; + + nla_parse_nested(ba_tb, NL80211_ST_CTX_BA_ATTR_MAX, + ba_attr, NULL, NULL); + + ba = &ba_tids[tid]; + + if (ba_tb[NL80211_ST_CTX_BA_ATTR_BUFF_SIZE]) + ba->buffer_size = + nla_get_u16(ba_tb[NL80211_ST_CTX_BA_ATTR_BUFF_SIZE]); + + if (ba_tb[NL80211_ST_CTX_BA_ATTR_POLICY]) + ba->ba_policy = + nla_get_u8(ba_tb[NL80211_ST_CTX_BA_ATTR_POLICY]); + + ba->amsdu_supported = + nla_get_flag(ba_tb[NL80211_ST_CTX_BA_ATTR_AMSDU_SUPPORT]); + + if (ba_tb[NL80211_ST_CTX_BA_ATTR_TIMEOUT]) + ba->timeout = + nla_get_u16(ba_tb[NL80211_ST_CTX_BA_ATTR_TIMEOUT]); + + ba->ext_no_frag = + nla_get_flag(ba_tb[NL80211_ST_CTX_BA_ATTR_EXT_NO_FRAG]); + + if (ba_tb[NL80211_ST_CTX_BA_ATTR_EXT_FRAG_LEVEL]) + ba->extfrag_level = + nla_get_u8(ba_tb[NL80211_ST_CTX_BA_ATTR_EXT_FRAG_LEVEL]); + + if (ba_tb[NL80211_ST_CTX_BA_ATTR_WINSTARTO]) + ba->winstarto = + nla_get_u16(ba_tb[NL80211_ST_CTX_BA_ATTR_WINSTARTO]); + + *valid_tid_bmap |= BIT(tid); + n_tids++; + } + + if (!n_tids) + return -EINVAL; + + return 0; +} + +static int nl80211_parse_st_ctx(struct genl_info *info, + struct cfg80211_smd_transition_info *st_info) +{ + struct nlattr *ctx_tb[NL80211_ST_CTX_INFO_ATTR_MAX + 1]; + struct nlattr *tb[NL80211_ST_CTX_ATTR_MAX + 1]; + struct ieee80211_st_ctx *ctx; + struct nlattr *ba_attr; + + st_info->ctx = NULL; + + ctx = kzalloc_obj(*ctx); + if (!ctx) + return -ENOMEM; + + nla_parse_nested(tb, NL80211_ST_CTX_ATTR_MAX, + info->attrs[NL80211_ATTR_ST_CTX], NULL, NULL); + + ctx->no_dl_sn_transfer = 1; + ctx->no_ul_sn_transfer = 1; + + /* DL Context */ + if (tb[NL80211_ST_CTX_ATTR_DL]) { + nla_parse_nested(ctx_tb, NL80211_ST_CTX_INFO_ATTR_MAX, + tb[NL80211_ST_CTX_ATTR_DL], NULL, NULL); + + if (ctx_tb[NL80211_ST_CTX_INFO_ATTR_SN]) { + struct nlattr *sn_attr; + int n_tids = 0; + int rem, tid; + + nla_for_each_nested(sn_attr, + ctx_tb[NL80211_ST_CTX_INFO_ATTR_SN], + rem) { + struct nlattr *per_tid[NL80211_ST_CTX_INFO_ATTR_MAX + 1]; + struct nlattr *sn; + + tid = nla_type(sn_attr) - 1; + if (tid < 0 || + tid >= IEEE80211_ST_CTX_NUM_TIDS) { + GENL_SET_ERR_MSG(info, + "invalid DL SN tid"); + goto err_free_ctx; + } + + nla_parse_nested(per_tid, + NL80211_ST_CTX_INFO_ATTR_MAX, + sn_attr, NULL, NULL); + + sn = per_tid[NL80211_ST_CTX_INFO_ATTR_SN_PER_TID]; + if (!sn) { + GENL_SET_ERR_MSG(info, + "no DL SN for tid"); + goto err_free_ctx; + } + + ctx->dl.sn[tid] = nla_get_u16(sn); + ctx->dl.valid_tid_bmap |= BIT(tid); + n_tids++; + } + + if (!n_tids) { + GENL_SET_ERR_MSG(info, "empty DL SN nesting"); + goto err_free_ctx; + } + + ctx->no_dl_sn_transfer = 0; + } + + if (ctx_tb[NL80211_ST_CTX_INFO_ATTR_DL_PN]) { + memcpy(ctx->dl.pn, + nla_data(ctx_tb[NL80211_ST_CTX_INFO_ATTR_DL_PN]), + nla_len(ctx_tb[NL80211_ST_CTX_INFO_ATTR_DL_PN])); + ctx->pn_valid = 1; + } + + ba_attr = ctx_tb[NL80211_ST_CTX_INFO_ATTR_BA_PARAMS]; + if (ba_attr) { + if (nl80211_parse_st_ctx_ba_params(ba_attr, + ctx->dl.ba, + &ctx->dl.valid_tid_bmap)) { + GENL_SET_ERR_MSG(info, + "failed to parse DL BlockAck params"); + goto err_free_ctx; + } + ctx->ba_params_valid = 1; + } + + if (ctx_tb[NL80211_ST_CTX_INFO_ATTR_MGMT_SN]) { + ctx->dl.mgmt_sn = + nla_get_u16(ctx_tb[NL80211_ST_CTX_INFO_ATTR_MGMT_SN]); + ctx->mgmt_tid_valid = 1; + ctx->no_dl_sn_transfer = 0; + } + } + + /* UL Context */ + if (tb[NL80211_ST_CTX_ATTR_UL]) { + nla_parse_nested(ctx_tb, NL80211_ST_CTX_INFO_ATTR_MAX, + tb[NL80211_ST_CTX_ATTR_UL], NULL, NULL); + + if (ctx_tb[NL80211_ST_CTX_INFO_ATTR_SN]) { + struct nlattr *sn_attr; + int n_tids = 0; + int rem, tid; + + nla_for_each_nested(sn_attr, + ctx_tb[NL80211_ST_CTX_INFO_ATTR_SN], + rem) { + struct nlattr *per_tid[NL80211_ST_CTX_INFO_ATTR_MAX + 1]; + struct nlattr *sn; + + tid = nla_type(sn_attr) - 1; + if (tid < 0 || + tid >= IEEE80211_ST_CTX_NUM_TIDS) { + GENL_SET_ERR_MSG(info, + "invalid UL SN tid"); + goto err_free_ctx; + } + + nla_parse_nested(per_tid, + NL80211_ST_CTX_INFO_ATTR_MAX, + sn_attr, NULL, NULL); + + sn = per_tid[NL80211_ST_CTX_INFO_ATTR_SN_PER_TID]; + if (!sn) { + GENL_SET_ERR_MSG(info, + "no UL SN for tid"); + goto err_free_ctx; + } + + ctx->ul.sn[tid] = nla_get_u16(sn); + ctx->ul.valid_tid_bmap |= BIT(tid); + n_tids++; + } + + if (!n_tids) { + GENL_SET_ERR_MSG(info, "empty UL SN nesting"); + goto err_free_ctx; + } + + ctx->no_ul_sn_transfer = 0; + } + + if (ctx_tb[NL80211_ST_CTX_INFO_ATTR_UL_PN]) { + struct nlattr *pn_attr; + int n_tids = 0; + int rem, tid; + + nla_for_each_nested(pn_attr, + ctx_tb[NL80211_ST_CTX_INFO_ATTR_UL_PN], + rem) { + struct nlattr *per_tid[NL80211_ST_CTX_INFO_ATTR_MAX + 1]; + struct nlattr *pn; + + tid = nla_type(pn_attr) - 1; + if (tid < 0 || + tid >= IEEE80211_ST_CTX_NUM_TIDS) { + GENL_SET_ERR_MSG(info, + "invalid UL PN tid"); + goto err_free_ctx; + } + + nla_parse_nested(per_tid, + NL80211_ST_CTX_INFO_ATTR_MAX, + pn_attr, NULL, NULL); + + pn = per_tid[NL80211_ST_CTX_INFO_ATTR_UL_PN_PER_TID]; + if (!pn) { + GENL_SET_ERR_MSG(info, + "no UL PN for tid"); + goto err_free_ctx; + } + + memcpy(ctx->ul.pn[tid], pn, nla_len(pn)); + n_tids++; + } + + if (!n_tids) { + GENL_SET_ERR_MSG(info, "empty UL PN nesting"); + goto err_free_ctx; + } + + ctx->pn_valid = 1; + } + + ba_attr = ctx_tb[NL80211_ST_CTX_INFO_ATTR_BA_PARAMS]; + if (ba_attr) { + if (nl80211_parse_st_ctx_ba_params(ba_attr, + ctx->ul.ba, + &ctx->ul.valid_tid_bmap)) { + GENL_SET_ERR_MSG(info, + "failed to parse UL BlockAck params"); + goto err_free_ctx; + } + ctx->ba_params_valid = 1; + } + + if (ctx_tb[NL80211_ST_CTX_INFO_ATTR_MGMT_SN]) { + ctx->ul.mgmt_sn = + nla_get_u16(ctx_tb[NL80211_ST_CTX_INFO_ATTR_MGMT_SN]); + ctx->mgmt_tid_valid = 1; + ctx->no_ul_sn_transfer = 0; + } + + if (ctx_tb[NL80211_ST_CTX_INFO_ATTR_UL_MGMT_PN]) { + memcpy(ctx->ul.mgmt_pn, + nla_data(ctx_tb[NL80211_ST_CTX_INFO_ATTR_UL_MGMT_PN]), + IEEE80211_CCMP_PN_LEN); + ctx->mgmt_tid_valid = 1; + ctx->pn_valid = 1; + } + } + + st_info->type = nla_get_u8(info->attrs[NL80211_ATTR_ST_CTX_TYPE]); + st_info->ctx = ctx; + + return 0; + +err_free_ctx: + kfree(ctx); + return -EINVAL; +} + #define NL80211_FLAG_NEED_WIPHY 0x01 #define NL80211_FLAG_NEED_NETDEV 0x02 #define NL80211_FLAG_NEED_RTNL 0x04 @@ -20850,6 +21130,42 @@ static int nl80211_set_sar_specs(struct sk_buff *skb, struct genl_info *info) return err; } +static int nl80211_set_st_ctx(struct sk_buff *skb, struct genl_info *info) +{ + struct cfg80211_registered_device *rdev = info->user_ptr[0]; + struct cfg80211_smd_transition_info st_info = {}; + struct net_device *dev = info->user_ptr[1]; + struct wireless_dev *wdev = dev->ieee80211_ptr; + const u8 *addr; + int err; + + if (!rdev->ops->set_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] || + !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]); + + err = nl80211_parse_st_ctx(info, &st_info); + if (err) + return err; + + /* drivers must copy @ctx for any deferred processing */ + err = rdev_set_st_ctx(rdev, wdev, addr, &st_info); + + kfree(st_info.ctx); + return err; +} + #define SELECTOR(__sel, name, value) \ ((__sel) == (value)) ? NL80211_IFL_SEL_##name : int __missing_selector(void); @@ -21785,6 +22101,13 @@ static const struct genl_small_ops nl80211_small_ops[] = { .flags = GENL_UNS_ADMIN_PERM, .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), }, + { + .cmd = NL80211_CMD_SET_ST_CTX, + .doit = nl80211_set_st_ctx, + .flags = GENL_UNS_ADMIN_PERM, + .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | + NL80211_FLAG_CLEAR_SKB), + }, }; static struct genl_family nl80211_fam __ro_after_init = { diff --git a/net/wireless/rdev-ops.h b/net/wireless/rdev-ops.h index 44a4255bbc03..824b606479db 100644 --- a/net/wireless/rdev-ops.h +++ b/net/wireless/rdev-ops.h @@ -1755,4 +1755,18 @@ static inline int rdev_abandon_st(struct cfg80211_registered_device *rdev, return ret; } +static inline int rdev_set_st_ctx(struct cfg80211_registered_device *rdev, + struct wireless_dev *wdev, const u8 *addr, + struct cfg80211_smd_transition_info *st_info) +{ + int ret = -EOPNOTSUPP; + + trace_rdev_set_st_ctx(&rdev->wiphy, wdev, addr, st_info); + if (rdev->ops->set_st_ctx) + ret = rdev->ops->set_st_ctx(&rdev->wiphy, wdev, addr, st_info); + 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 b0ff3cc4176d..7806a2edb26f 100644 --- a/net/wireless/trace.h +++ b/net/wireless/trace.h @@ -4702,6 +4702,40 @@ DEFINE_EVENT(cfg80211_st_evt, cfg80211_st_abandoned, struct cfg80211_bss **links), TP_ARGS(netdev, links) ); + +TRACE_EVENT(rdev_set_st_ctx, + TP_PROTO(struct wiphy *wiphy, struct wireless_dev *wdev, const u8 *addr, + struct cfg80211_smd_transition_info *st_info), + + TP_ARGS(wiphy, wdev, addr, st_info), + + TP_STRUCT__entry( + WIPHY_ENTRY + WDEV_ENTRY + MAC_ENTRY(sta_addr) + __field(u8, st_type) + __field(u8, dl_tid_bitmap) + __field(u8, ul_tid_bitmap) + ), + + TP_fast_assign( + struct ieee80211_st_ctx *ctx = st_info->ctx; + + WIPHY_ASSIGN; + WDEV_ASSIGN; + MAC_ASSIGN(sta_addr, addr); + __entry->st_type = st_info->type; + __entry->dl_tid_bitmap = ctx->dl.valid_tid_bmap; + __entry->ul_tid_bitmap = ctx->ul.valid_tid_bmap; + ), + + TP_printk(WIPHY_PR_FMT ", " WDEV_PR_FMT + ", sta=%pM, ST type=%u DL TIDs: 0x%x, UL TIDs: 0x%x", + WIPHY_PR_ARG, WDEV_PR_ARG, __entry->sta_addr, + __entry->st_type, + __entry->dl_tid_bitmap, __entry->ul_tid_bitmap + ) +); #endif /* !__RDEV_OPS_TRACE || TRACE_HEADER_MULTI_READ */ #undef TRACE_INCLUDE_PATH -- 2.34.1