diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h
index 7b0f328fec79..b68f5f6837be 100644
--- a/include/net/cfg80211.h
+++ b/include/net/cfg80211.h
@@ -5329,6 +5329,10 @@ struct cfg80211_smd_transition_info {
*
* @start_pd: Start the PD interface.
* @stop_pd: Stop the PD interface.
+ *
+ * @set_smd_ctx: Set UHR SMD 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);@@ -5707,6 +5711,9 @@ struct cfg80211_ops {
bool val);
int (*start_pd)(struct wiphy *wiphy, struct wireless_dev *wdev);
void (*stop_pd)(struct wiphy *wiphy, struct wireless_dev *wdev);
+ int (*set_smd_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 5065dc75b0bc..70b8697e5dac 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -19827,6 +19827,293 @@ static int nl80211_put_smd_ctx(struct sk_buff *msg,
return -EINVAL;
}
+static int
+nl80211_parse_smd_ctx_ba_params(struct nlattr *tb,
+ struct ieee80211_smd_ctx_ba *ba_tids,
+ unsigned long *valid_ctx_bmap)
+{
+ struct nlattr *ba_tb[NL80211_SMD_CTX_BA_ATTR_MAX + 1];
+ struct ieee80211_smd_ctx_ba *ba;
+ struct nlattr *ba_attr;
+ int n_tids = 0;
+ int rem, tid;
+
+ if (!tb)
+ return 0;
+
+ nla_for_each_nested(ba_attr, tb, rem) {
+ tid = nla_type(ba_attr) - 1;
+ if (tid < 0 || tid >= IEEE80211_SMD_CTX_NUM_TIDS)
+ return -EINVAL;
+
+ if (nla_parse_nested(ba_tb, NL80211_SMD_CTX_BA_ATTR_MAX,
+ ba_attr, nl80211_smd_ctx_ba_policy,
+ NULL))
+ return -EINVAL;
+
+ ba = &ba_tids[tid];
+
+ if (ba_tb[NL80211_SMD_CTX_BA_ATTR_BUFF_SIZE])
+ ba->buffer_size =
+ nla_get_u16(ba_tb[NL80211_SMD_CTX_BA_ATTR_BUFF_SIZE]);
+
+ if (ba_tb[NL80211_SMD_CTX_BA_ATTR_POLICY])
+ ba->ba_policy =
+ nla_get_u8(ba_tb[NL80211_SMD_CTX_BA_ATTR_POLICY]);
+
+ ba->amsdu_supported =
+ !!ba_tb[NL80211_SMD_CTX_BA_ATTR_AMSDU_SUPPORT];
+
+ if (ba_tb[NL80211_SMD_CTX_BA_ATTR_TIMEOUT])
+ ba->timeout =
+ nla_get_u16(ba_tb[NL80211_SMD_CTX_BA_ATTR_TIMEOUT]);
+
+ ba->ext_no_frag = !!ba_tb[NL80211_SMD_CTX_BA_ATTR_EXT_NO_FRAG];
+
+ if (ba_tb[NL80211_SMD_CTX_BA_ATTR_EXT_FRAG_LEVEL])
+ ba->extfrag_level =
+ nla_get_u8(ba_tb[NL80211_SMD_CTX_BA_ATTR_EXT_FRAG_LEVEL]);
+
+ if (ba_tb[NL80211_SMD_CTX_BA_ATTR_EXT_BUFF_SIZE])
+ ba->ext_buffer_size =
+ nla_get_u16(ba_tb[NL80211_SMD_CTX_BA_ATTR_EXT_BUFF_SIZE]);
+
+ n_tids++;
+ }
+
+ if (!n_tids)
+ return -EINVAL;
+
+ set_bit(IEEE80211_SMD_CTX_VALID_BA_PARAMS, valid_ctx_bmap);
+
+ return 0;
+}
+
+static int nl80211_parse_smd_ctx(struct genl_info *info,
+ struct cfg80211_smd_transition_info *st_info)
+{
+ struct nlattr *dl_tb[NL80211_SMD_CTX_DL_ATTR_MAX + 1];
+ struct nlattr *ul_tb[NL80211_SMD_CTX_UL_ATTR_MAX + 1];
+ struct nlattr *tb[NL80211_SMD_CTX_ATTR_MAX + 1];
+ struct ieee80211_smd_ctx *ctx;
+ struct nlattr *bmap_attr;
+ size_t drv_ctx_size = 0;
+
+ st_info->type = nla_get_u8(info->attrs[NL80211_ATTR_SMD_CTX_TYPE]);
+
+ if (nla_parse_nested(tb, NL80211_SMD_CTX_ATTR_MAX,
+ info->attrs[NL80211_ATTR_SMD_CTX],
+ nl80211_smd_ctx_policy, NULL)) {
+ GENL_SET_ERR_MSG(info, "failed to parse SMD context");
+ return -EINVAL;
+ }
+
+ if (tb[NL80211_SMD_CTX_ATTR_DRV_DATA])
+ drv_ctx_size = nla_len(tb[NL80211_SMD_CTX_ATTR_DRV_DATA]);
+
+ ctx = kzalloc(sizeof(*ctx) + drv_ctx_size, GFP_KERNEL);
+ if (!ctx)
+ return -ENOMEM;
+
+ st_info->ctx = ctx;
+
+ /* DL Context */
+ if (tb[NL80211_SMD_CTX_ATTR_DL]) {
+ struct nlattr *ba_attr;
+
+ if (nla_parse_nested(dl_tb, NL80211_SMD_CTX_DL_ATTR_MAX,
+ tb[NL80211_SMD_CTX_ATTR_DL],
+ nl80211_smd_ctx_dl_policy, NULL)) {
+ GENL_SET_ERR_MSG(info, "failed to parse DL context");
+ goto err_free_ctx;
+ }
+
+ bmap_attr = dl_tb[NL80211_SMD_CTX_DL_ATTR_VALID_TID_BITMAP];
+ if (bmap_attr)
+ bitmap_write(ctx->dl.valid_tid_bmap,
+ nla_get_u8(bmap_attr),
+ 0, IEEE80211_SMD_CTX_NUM_TIDS);
+
+ if (dl_tb[NL80211_SMD_CTX_DL_ATTR_SN]) {
+ struct nlattr *sn_attr;
+ int n_tids = 0;
+ int rem, tid;
+
+ nla_for_each_nested(sn_attr,
+ dl_tb[NL80211_SMD_CTX_DL_ATTR_SN],
+ rem) {
+ tid = nla_type(sn_attr) - 1;
+ if (tid < 0 ||
+ tid >= IEEE80211_SMD_CTX_NUM_TIDS) {
+ GENL_SET_ERR_MSG(info,
+ "invalid DL SN tid");
+ goto err_free_ctx;
+ }
+
+ if (nla_len(sn_attr) != sizeof(u16)) {
+ GENL_SET_ERR_MSG(info,
+ "invalid DL SN len");
+ goto err_free_ctx;
+ }
+
+ ctx->dl.sn[tid] = nla_get_u16(sn_attr);
+ n_tids++;
+ }
+
+ if (!n_tids) {
+ GENL_SET_ERR_MSG(info, "empty DL SN nesting");
+ goto err_free_ctx;
+ }
+
+ set_bit(IEEE80211_SMD_CTX_VALID_DL_SN,
+ ctx->valid_ctx_bmap);
+ }
+
+ if (dl_tb[NL80211_SMD_CTX_DL_ATTR_PN]) {
+ const u8 *pn_data =
+ nla_data(dl_tb[NL80211_SMD_CTX_DL_ATTR_PN]);
+
+ ctx->pn_len =
+ nla_len(dl_tb[NL80211_SMD_CTX_DL_ATTR_PN]);
+
+ memcpy(ctx->dl.pn, pn_data, ctx->pn_len);
+ set_bit(IEEE80211_SMD_CTX_VALID_PN,
+ ctx->valid_ctx_bmap);
+ }
+
+ ba_attr = dl_tb[NL80211_SMD_CTX_DL_ATTR_BA_PARAMS];
+ if (ba_attr &&
+ nl80211_parse_smd_ctx_ba_params(ba_attr, ctx->dl.ba,
+ ctx->valid_ctx_bmap)) {
+ GENL_SET_ERR_MSG(info,
+ "failed to parse DL BlockAck params");
+ goto err_free_ctx;
+ }
+ }
+
+ /* UL Context */
+ if (tb[NL80211_SMD_CTX_ATTR_UL]) {
+ struct nlattr *ba_attr;
+
+ if (nla_parse_nested(ul_tb, NL80211_SMD_CTX_UL_ATTR_MAX,
+ tb[NL80211_SMD_CTX_ATTR_UL],
+ nl80211_smd_ctx_ul_policy, NULL)) {
+ GENL_SET_ERR_MSG(info, "failed to parse UL context");
+ goto err_free_ctx;
+ }
+
+ bmap_attr = ul_tb[NL80211_SMD_CTX_UL_ATTR_VALID_TID_BITMAP];
+ if (bmap_attr)
+ bitmap_write(ctx->ul.valid_tid_bmap,
+ nla_get_u8(bmap_attr),
+ 0, IEEE80211_SMD_CTX_NUM_TIDS);
+
+ if (ul_tb[NL80211_SMD_CTX_UL_ATTR_SN]) {
+ struct nlattr *sn_attr;
+ int n_tids = 0;
+ int rem, tid;
+
+ nla_for_each_nested(sn_attr,
+ ul_tb[NL80211_SMD_CTX_UL_ATTR_SN],
+ rem) {
+ tid = nla_type(sn_attr) - 1;
+ if (tid < 0 ||
+ tid >= IEEE80211_SMD_CTX_NUM_TIDS) {
+ GENL_SET_ERR_MSG(info,
+ "invalid UL SN tid");
+ goto err_free_ctx;
+ }
+
+ if (nla_len(sn_attr) != sizeof(u16)) {
+ GENL_SET_ERR_MSG(info,
+ "invalid UL SN len");
+ goto err_free_ctx;
+ }
+
+ ctx->ul.sn[tid] = nla_get_u16(sn_attr);
+ n_tids++;
+ }
+
+ if (!n_tids) {
+ GENL_SET_ERR_MSG(info, "empty UL SN nesting");
+ goto err_free_ctx;
+ }
+
+ set_bit(IEEE80211_SMD_CTX_VALID_UL_SN,
+ ctx->valid_ctx_bmap);
+ }
+
+ if (ul_tb[NL80211_SMD_CTX_UL_ATTR_PN]) {
+ struct nlattr *pn_attr;
+ int n_tids = 0;
+ int rem, tid;
+
+ nla_for_each_nested(pn_attr,
+ ul_tb[NL80211_SMD_CTX_UL_ATTR_PN],
+ rem) {
+ u8 pn_len;
+
+ tid = nla_type(pn_attr) - 1;
+ if (tid < 0 ||
+ tid >= IEEE80211_SMD_CTX_NUM_TIDS) {
+ GENL_SET_ERR_MSG(info,
+ "invalid UL PN tid");
+ goto err_free_ctx;
+ }
+
+ /*
+ * PN length must be the same for all DL and
+ * UL TIDs.
+ */
+ pn_len = nla_len(pn_attr);
+ if (pn_len > IEEE80211_SMD_CTX_MAX_PN_LEN ||
+ (ctx->pn_len && pn_len != ctx->pn_len)) {
+ GENL_SET_ERR_MSG(info,
+ "invalid PN length");
+ goto err_free_ctx;
+ }
+ ctx->pn_len = pn_len;
+
+ memcpy(ctx->ul.pn[tid], nla_data(pn_attr),
+ ctx->pn_len);
+ n_tids++;
+ }
+
+ if (!n_tids) {
+ GENL_SET_ERR_MSG(info, "empty UL PN nesting");
+ goto err_free_ctx;
+ }
+
+ set_bit(IEEE80211_SMD_CTX_VALID_PN,
+ ctx->valid_ctx_bmap);
+ }
+
+ ba_attr = ul_tb[NL80211_SMD_CTX_UL_ATTR_BA_PARAMS];
+ if (ba_attr &&
+ nl80211_parse_smd_ctx_ba_params(ba_attr, ctx->ul.ba,
+ ctx->valid_ctx_bmap)) {
+ GENL_SET_ERR_MSG(info,
+ "failed to parse UL BlockAck params");
+ goto err_free_ctx;
+ }
+ }
+
+ /* Driver data */
+ if (tb[NL80211_SMD_CTX_ATTR_DRV_DATA]) {
+ ctx->drv_ctx_size = drv_ctx_size;
+ memcpy(ctx->drv_ctx,
+ nla_data(tb[NL80211_SMD_CTX_ATTR_DRV_DATA]),
+ drv_ctx_size);
+ }
+
+ return 0;
+
+err_free_ctx:
+ kfree(ctx);
+ st_info->ctx = NULL;
+ return -EINVAL;
+}
+
#define NL80211_FLAG_NEED_WIPHY 0x01
#define NL80211_FLAG_NEED_NETDEV 0x02
#define NL80211_FLAG_NEED_RTNL 0x04@@ -20168,6 +20455,44 @@ static int nl80211_set_sar_specs(struct sk_buff *skb, struct genl_info *info)
return err;
}
+static int nl80211_set_smd_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_smd_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_SMD_CTX] ||
+ !info->attrs[NL80211_ATTR_SMD_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_smd_ctx(info, &st_info);
+ if (err)
+ return err;
+
+ /*
+ * Drivers must copy @ctx if processing is deferred after
+ * returning from this function.
+ */
+ err = rdev_set_smd_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);@@ -21069,6 +21394,13 @@ static const struct genl_small_ops nl80211_small_ops[] = {
.flags = GENL_ADMIN_PERM,
.internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP),
},
+ {
+ .cmd = NL80211_CMD_SET_SMD_CTX,
+ .doit = nl80211_set_smd_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 46849fe8d0b3..d33a969606d7 100644
--- a/net/wireless/rdev-ops.h
+++ b/net/wireless/rdev-ops.h
@@ -1636,4 +1636,18 @@ rdev_set_epcs(struct cfg80211_registered_device *rdev,
return ret;
}
+static inline int rdev_set_smd_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_smd_ctx(&rdev->wiphy, wdev, addr, st_info);
+ if (rdev->ops->set_smd_ctx)
+ ret = rdev->ops->set_smd_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 8c2a91b85c39..6234ceb9ebb1 100644
--- a/net/wireless/trace.h
+++ b/net/wireless/trace.h
@@ -4405,6 +4405,53 @@ TRACE_EVENT(cfg80211_nan_channel_evac,
TP_printk(WDEV_PR_FMT ", " WIPHY_PR_FMT ", " CHAN_DEF_PR_FMT,
WDEV_PR_ARG, WIPHY_PR_ARG, CHAN_DEF_PR_ARG)
);
+
+TRACE_EVENT(rdev_set_smd_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(unsigned int, num_tids)
+ __dynamic_array(unsigned long, tx_tid_bitmap,
+ BITS_TO_LONGS(IEEE80211_SMD_CTX_NUM_TIDS))
+ __dynamic_array(unsigned long, rx_tid_bitmap,
+ BITS_TO_LONGS(IEEE80211_SMD_CTX_NUM_TIDS))
+ ),
+
+ TP_fast_assign(
+ struct ieee80211_smd_ctx *ctx = st_info->ctx;
+ unsigned long sz;
+
+ WIPHY_ASSIGN;
+ WDEV_ASSIGN;
+ MAC_ASSIGN(sta_addr, addr);
+ __entry->st_type = st_info->type;
+
+ __entry->num_tids = IEEE80211_SMD_CTX_NUM_TIDS;
+ sz = BITS_TO_LONGS(__entry->num_tids) * sizeof(unsigned long);
+
+ memcpy(__get_dynamic_array(tx_tid_bitmap),
+ ctx->dl.valid_tid_bmap, sz);
+ memcpy(__get_dynamic_array(rx_tid_bitmap),
+ ctx->ul.valid_tid_bmap, sz);
+ ),
+
+ TP_printk(WIPHY_PR_FMT ", " WDEV_PR_FMT
+ ", sta=%pM, ST type=%u DL TIDs: %*pb, UL TIDs: %*pb",
+ WIPHY_PR_ARG, WDEV_PR_ARG, __entry->sta_addr,
+ __entry->st_type,
+ __entry->num_tids,
+ (unsigned long *)__get_dynamic_array(tx_tid_bitmap),
+ __entry->num_tids,
+ (unsigned long *)__get_dynamic_array(rx_tid_bitmap))
+);
+
#endif /* !__RDEV_OPS_TRACE || TRACE_HEADER_MULTI_READ */
#undef TRACE_INCLUDE_PATH
--
2.34.1