While packing the received management frame in nl80211_send_mgmt() to send to userspace, nest the ST dynamic context along with the frame message. This shall be used by userspace to transport the context to the target AP MLD for programming the dynamic state of the STA session for seamless roaming as part of ST. Suggested-by: Jouni Malinen Co-developed-by: Aditya Sathish Signed-off-by: Aditya Sathish Signed-off-by: Pooventhiran G --- include/net/cfg80211.h | 13 ++++ net/wireless/nl80211.c | 191 ++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 203 insertions(+), 1 deletion(-) diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index 8df01cc53274..ade029268548 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h @@ -4926,6 +4926,17 @@ struct mgmt_frame_regs { u32 global_mcast_stypes, interface_mcast_stypes; }; +/** + * struct cfg80211_smd_transition_info - SMD Transition info + * + * @ctx: Dynamic context to be transferred as part of ST + * @type: Type of ST indication + */ +struct cfg80211_smd_transition_info { + struct ieee80211_st_ctx *ctx; + enum nl80211_st_ctx_type type; +}; + /** * struct cfg80211_ops - backend description for wireless configuration * @@ -9740,6 +9751,7 @@ void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, * @rx_tstamp: Hardware timestamp of frame RX in nanoseconds * @ack_tstamp: Hardware timestamp of ack TX in nanoseconds * @no_sta: set if no station is known for the frame (relevant for MLD) + * @st_info: SMD Transition data */ struct cfg80211_rx_info { int freq; @@ -9752,6 +9764,7 @@ struct cfg80211_rx_info { u64 rx_tstamp; u64 ack_tstamp; bool no_sta; + struct cfg80211_smd_transition_info st_info; }; /** diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index 3e51ce0155d3..bf81d67f42ac 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -20234,6 +20234,191 @@ static int nl80211_abandon_st(struct sk_buff *skb, struct genl_info *info) info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]); } +static int +nl80211_put_st_ctx_ba_params(struct sk_buff *msg, unsigned long tid_bmap, + const struct ieee80211_st_ctx_ba *ba_tids, + bool dl) +{ + struct nlattr *ctx_ba; + u8 tid; + + ctx_ba = nla_nest_start(msg, NL80211_ST_CTX_INFO_ATTR_BA_PARAMS); + if (!ctx_ba) + return -ENOBUFS; + + for_each_set_bit(tid, &tid_bmap, IEEE80211_ST_CTX_NUM_TIDS) { + const struct ieee80211_st_ctx_ba *ba = &ba_tids[tid]; + struct nlattr *tid_ba = nla_nest_start(msg, tid + 1); + + if (!tid_ba) + goto nla_fail; + + if (nla_put_u16(msg, NL80211_ST_CTX_BA_ATTR_BUFF_SIZE, + ba->buffer_size) || + nla_put_u8(msg, NL80211_ST_CTX_BA_ATTR_POLICY, + ba->ba_policy) || + (ba->amsdu_supported && + nla_put_flag(msg, + NL80211_ST_CTX_BA_ATTR_AMSDU_SUPPORT)) || + nla_put_u16(msg, NL80211_ST_CTX_BA_ATTR_TIMEOUT, + ba->timeout) || + (ba->ext_no_frag && + nla_put_flag(msg, NL80211_ST_CTX_BA_ATTR_EXT_NO_FRAG)) || + nla_put_u8(msg, NL80211_ST_CTX_BA_ATTR_EXT_FRAG_LEVEL, + ba->extfrag_level) || + (dl && nla_put_u16(msg, NL80211_ST_CTX_BA_ATTR_WINSTARTO, + ba->winstarto))) { + nla_nest_cancel(msg, tid_ba); + goto nla_fail; + } + + nla_nest_end(msg, tid_ba); + } + + nla_nest_end(msg, ctx_ba); + return 0; + +nla_fail: + return -ENOBUFS; +} + +static 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; + struct nlattr *st_ctx, *dl, *ul; + + /* ST Type */ + if (nla_put_u8(msg, NL80211_ATTR_ST_CTX_TYPE, st_info->type)) + goto nla_fail; + + st_ctx = nla_nest_start(msg, NL80211_ATTR_ST_CTX); + if (!st_ctx) + goto nla_fail; + + ctx = st_info->ctx; + + /* Build DL context */ + dl_tid_bmap = ctx->dl.valid_tid_bmap; + + dl = nla_nest_start(msg, NL80211_ST_CTX_ATTR_DL); + if (!dl) + goto nla_fail; + + if (!ctx->no_dl_sn_transfer) { + struct nlattr *dl_sn = + nla_nest_start(msg, NL80211_ST_CTX_INFO_ATTR_SN); + u8 tid; + + if (!dl_sn) + goto nla_fail; + + for_each_set_bit(tid, &dl_tid_bmap, + IEEE80211_ST_CTX_NUM_TIDS) { + struct nlattr *tid_sn = nla_nest_start(msg, tid + 1); + + if (!tid_sn || + nla_put_u16(msg, NL80211_ST_CTX_INFO_ATTR_SN_PER_TID, + ctx->dl.sn[tid])) + goto nla_fail; + + nla_nest_end(msg, tid_sn); + } + nla_nest_end(msg, dl_sn); + } + + if (ctx->pn_valid && + nla_put(msg, NL80211_ST_CTX_INFO_ATTR_DL_PN, + IEEE80211_CCMP_PN_LEN, ctx->dl.pn)) + goto nla_fail; + + if (ctx->ba_params_valid && + nl80211_put_st_ctx_ba_params(msg, dl_tid_bmap, ctx->dl.ba, true)) + goto nla_fail; + + if (!ctx->no_dl_sn_transfer && ctx->mgmt_tid_valid && + nla_put_u16(msg, NL80211_ST_CTX_INFO_ATTR_MGMT_SN, ctx->dl.mgmt_sn)) + goto nla_fail; + + nla_nest_end(msg, dl); + + /* Build UL context */ + ul_tid_bmap = ctx->ul.valid_tid_bmap; + + ul = nla_nest_start(msg, NL80211_ST_CTX_ATTR_UL); + if (!ul) + goto nla_fail; + + if (!ctx->no_ul_sn_transfer) { + struct nlattr *ul_sn = + nla_nest_start(msg, NL80211_ST_CTX_INFO_ATTR_SN); + u8 tid; + + if (!ul_sn) + goto nla_fail; + + for_each_set_bit(tid, &ul_tid_bmap, + IEEE80211_ST_CTX_NUM_TIDS) { + struct nlattr *tid_sn = nla_nest_start(msg, tid + 1); + + if (!tid_sn || + nla_put_u16(msg, NL80211_ST_CTX_INFO_ATTR_SN_PER_TID, + ctx->ul.sn[tid])) + goto nla_fail; + + nla_nest_end(msg, tid_sn); + } + nla_nest_end(msg, ul_sn); + } + + if (ctx->pn_valid) { + struct nlattr *ul_pn = + nla_nest_start(msg, NL80211_ST_CTX_INFO_ATTR_UL_PN); + u8 tid; + + if (!ul_pn) + goto nla_fail; + + for_each_set_bit(tid, &ul_tid_bmap, + IEEE80211_ST_CTX_NUM_TIDS) { + struct nlattr *tid_pn = nla_nest_start(msg, tid + 1); + + if (!tid_pn || + nla_put(msg, NL80211_ST_CTX_INFO_ATTR_UL_PN_PER_TID, + IEEE80211_CCMP_PN_LEN, ctx->ul.pn[tid])) + goto nla_fail; + nla_nest_end(msg, tid_pn); + } + nla_nest_end(msg, ul_pn); + } + + if (ctx->ba_params_valid && + nl80211_put_st_ctx_ba_params(msg, ul_tid_bmap, ctx->ul.ba, false)) + goto nla_fail; + + if (ctx->mgmt_tid_valid) { + if (!ctx->no_ul_sn_transfer && + nla_put_u16(msg, NL80211_ST_CTX_INFO_ATTR_MGMT_SN, + ctx->ul.mgmt_sn)) + goto nla_fail; + + if (ctx->pn_valid && + nla_put(msg, NL80211_ST_CTX_INFO_ATTR_UL_MGMT_PN, + IEEE80211_CCMP_PN_LEN, ctx->ul.mgmt_pn)) + goto nla_fail; + } + + nla_nest_end(msg, ul); + + nla_nest_end(msg, st_ctx); + + return 0; + +nla_fail: + return -ENOBUFS; +} + #define NL80211_FLAG_NEED_WIPHY 0x01 #define NL80211_FLAG_NEED_NETDEV 0x02 #define NL80211_FLAG_NEED_RTNL 0x04 @@ -23157,7 +23342,7 @@ int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, struct sk_buff *msg; void *hdr; - msg = nlmsg_new(100 + info->len, gfp); + msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); if (!msg) return -ENOMEM; @@ -23193,6 +23378,10 @@ int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, nla_put_flag(msg, NL80211_ATTR_FRAME_NO_STA))) goto nla_put_failure; + if (info->st_info.ctx && + nl80211_put_st_ctx(msg, &info->st_info)) + goto nla_put_failure; + genlmsg_end(msg, hdr); return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); -- 2.34.1