From: Johannes Berg We've always assumed that a station has active_links that are simply sta->valid_links & vif->active_links, and while this should be true most of the time, during SMD transition the target AP MLD will have a different (set of) active link(s) than the vif, and needs to be added so the state can be transferred over. Add and track sta->active_links, and use it in a few places. Upon allocation, a sta initially has no active links, it's up to the caller to fix that; document it. During link switch, the active links change with the interface ones, do that in the drv_change_sta_links() wrapper. Reviewed-by: Miriam Rachel Korenblit Signed-off-by: Johannes Berg --- include/net/mac80211.h | 3 +++ net/mac80211/cfg.c | 8 ++++++++ net/mac80211/driver-ops.c | 13 ++++++++++--- net/mac80211/key.c | 10 +++++++--- net/mac80211/mlme.c | 8 ++++++-- net/mac80211/sta_info.c | 12 ++++++++++-- net/mac80211/sta_info.h | 1 + 7 files changed, 45 insertions(+), 10 deletions(-) diff --git a/include/net/mac80211.h b/include/net/mac80211.h index e54fa07e2cbf..335eee075952 100644 --- a/include/net/mac80211.h +++ b/include/net/mac80211.h @@ -2727,6 +2727,8 @@ struct ieee80211_link_sta { * would be assigned to link[link_id] where link_id is the id assigned * by the AP. * @valid_links: bitmap of valid links, or 0 for non-MLO + * @active_links: bitmap of active links, always a subset of @valid_links; + * unused (0) for non-MLO * @spp_amsdu: indicates whether the STA uses SPP A-MSDU or not. * @epp_peer: indicates that the peer is an EPP peer. * @cip: indicates whether the STA uses control frame protection or not. @@ -2762,6 +2764,7 @@ struct ieee80211_sta { struct ieee80211_txq *txq[IEEE80211_NUM_TIDS + 1]; u16 valid_links; + u16 active_links; u16 ext_mld_capa_ops; bool epp_peer; struct ieee80211_link_sta deflink; diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c index 38898fd58692..9e47360ee8f5 100644 --- a/net/mac80211/cfg.c +++ b/net/mac80211/cfg.c @@ -2935,6 +2935,14 @@ static int ieee80211_add_station(struct wiphy *wiphy, struct wireless_dev *wdev, sta = sta_info_alloc_with_link(link, mac, params->link_sta_params.link_mac ?: mac); + + /* + * In this path (AP side), the link the station is created for + * must be active, so just set the active links. + */ + if (sta) + sta->sta.active_links = + BIT(params->link_sta_params.link_id); } else { sta = sta_info_alloc(sdata, mac, GFP_KERNEL); } diff --git a/net/mac80211/driver-ops.c b/net/mac80211/driver-ops.c index 1f3e0765a8ab..e616bfbe687b 100644 --- a/net/mac80211/driver-ops.c +++ b/net/mac80211/driver-ops.c @@ -515,9 +515,14 @@ int drv_set_key(struct ieee80211_local *local, if (!check_sdata_in_driver(sdata)) return -EIO; - if (WARN_ON(key->link_id >= 0 && sdata->vif.active_links && - !(sdata->vif.active_links & BIT(key->link_id)))) - return -ENOLINK; + if (key->link_id >= 0) { + u16 active_links = sta ? sta->active_links : + sdata->vif.active_links; + + if (WARN_ON(active_links && + !(active_links & BIT(key->link_id)))) + return -ENOLINK; + } if (fips_enabled) return -EOPNOTSUPP; @@ -621,6 +626,8 @@ int drv_change_sta_links(struct ieee80211_local *local, if (ret) return ret; + sta->active_links = new_links; + /* during reconfig don't add it to debugfs again */ if (local->in_reconfig || local->resuming) return 0; diff --git a/net/mac80211/key.c b/net/mac80211/key.c index d1e3fe37d2e3..9b6a1f0627c6 100644 --- a/net/mac80211/key.c +++ b/net/mac80211/key.c @@ -197,9 +197,13 @@ static int ieee80211_key_enable_hw_accel(struct ieee80211_key *key) } } - if (key->conf.link_id >= 0 && sdata->vif.active_links && - !(sdata->vif.active_links & BIT(key->conf.link_id))) - return 0; + if (key->conf.link_id >= 0) { + u16 active_links = sta ? sta->sta.active_links : + sdata->vif.active_links; + + if (active_links && !(active_links & BIT(key->conf.link_id))) + return 0; + } ret = drv_set_key(key->local, SET_KEY, sdata, sta ? &sta->sta : NULL, &key->conf); diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c index 8b95a3277066..4caa1853531a 100644 --- a/net/mac80211/mlme.c +++ b/net/mac80211/mlme.c @@ -9763,11 +9763,15 @@ static int ieee80211_prep_connection(struct ieee80211_sub_if_data *sdata, } if (!have_sta) { - if (mlo) + if (mlo) { new_sta = sta_info_alloc_with_link(link, ap_mld_addr, cbss->bssid); - else + /* the auth/assoc link is currently the active link */ + if (new_sta) + new_sta->sta.active_links = BIT(link_id); + } else { new_sta = sta_info_alloc(sdata, ap_mld_addr, GFP_KERNEL); + } if (!new_sta) { err = -ENOMEM; diff --git a/net/mac80211/sta_info.c b/net/mac80211/sta_info.c index a86da3c70152..a9c0f873266d 100644 --- a/net/mac80211/sta_info.c +++ b/net/mac80211/sta_info.c @@ -672,6 +672,7 @@ __sta_info_alloc(struct ieee80211_sub_if_data *sdata, sta_info_add_link(sta, link_id, &sta->deflink, &sta->sta.deflink); sta->sta.valid_links = BIT(link_id); + /* active_links isn't set yet */ } else { sta_info_add_link(sta, 0, &sta->deflink, &sta->sta.deflink); } @@ -1087,7 +1088,7 @@ static int sta_info_insert_finish(struct sta_info *sta) __acquires(RCU) continue; ieee80211_link_sta_debugfs_add(link_sta); - if (sdata->vif.active_links & BIT(i)) + if (sta->sta.active_links & BIT(i)) ieee80211_link_sta_debugfs_drv_add(link_sta); } } else { @@ -2598,7 +2599,7 @@ void ieee80211_sta_recalc_aggregates(struct ieee80211_sta *pubsta) { struct sta_info *sta = container_of(pubsta, struct sta_info, sta); - __ieee80211_sta_recalc_aggregates(sta, sta->sdata->vif.active_links); + __ieee80211_sta_recalc_aggregates(sta, sta->sta.active_links); } EXPORT_SYMBOL(ieee80211_sta_recalc_aggregates); @@ -3647,6 +3648,13 @@ void ieee80211_sta_remove_link(struct sta_info *sta, unsigned int link_id) ieee80211_unlink_link_sta_keys(sta->local, link_sta); sta->sta.valid_links &= ~BIT(link_id); + sta->sta.active_links &= ~BIT(link_id); + + WARN(!sta->sta.valid_links || !sta->sta.active_links, + "STA %pM has no links after removing %d (valid:0x%x, active:0x%x)\n", + sta->sta.addr, link_id, + sta->sta.valid_links, + sta->sta.active_links); if (!WARN_ON(!test_sta_flag(sta, WLAN_STA_INSERTED))) drv_change_sta_links(sdata->local, sdata, &sta->sta, diff --git a/net/mac80211/sta_info.h b/net/mac80211/sta_info.h index 110788c0d623..4b1c441b610e 100644 --- a/net/mac80211/sta_info.h +++ b/net/mac80211/sta_info.h @@ -922,6 +922,7 @@ struct sta_info *sta_info_get_by_idx(struct ieee80211_sub_if_data *sdata, /* * Create a new STA info, caller owns returned structure * until sta_info_insert(). + * Note: neither allocation function sets sta->sta.active_links! */ struct sta_info *sta_info_alloc(struct ieee80211_sub_if_data *sdata, const u8 *addr, gfp_t gfp); -- 2.56.0