When user space does the authentication, for example for FT with iwd, there is no matching auth_data. Then in ieee80211_mgd_assoc(), conn.mode is limited only by our own capabilities. The AP's capabilities are applied later, by ieee80211_determine_chan_mode() in ieee80211_prep_connection() or ieee80211_prep_channel(). ieee80211_mgd_get_ap_ht_vht_capa() runs before that. It fails the association with -EINVAL if conn.mode is HT or VHT and the AP has no HT operation element, or no VHT capability element on 5 GHz. Thus, an association to a legacy AP, or to an HT-only AP on 5 GHz, fails. For an FT roam the old AP has already been left, so the connection is lost. To fix it, get the AP's HT operation and VHT capability data when the association request is built, after conn.mode is set from the AP's capabilities, and use zero values if the AP does not have the element. Remove the early check and the copies in the association data, since they are not needed anymore. Note that as a side-effect, a 5 GHz AP that gives VHT operation information only in its HE operation element, without a VHT capability element, is now also accepted with in-kernel authentication. Fixes: 7d8b02592d52 ("wifi: mac80211: obtain AP HT/VHT data for assoc request") Signed-off-by: Raphaël Mélotte --- Notes: The problem was noticed with iwd connected to an HT AP, while a legacy AP with WMM enabled was a roaming candidate in the same mobility domain. The FT roam to the legacy AP always failed in NL80211_CMD_ASSOCIATE with -EINVAL, after the FT authentication was successful. Then iwd must connect again from the start, which takes much longer than an FT roam. With mlme debug, the kernel logs "no HT operation on BSS ". This seems to occurs only when there is no auth_data, that is, when user space does the authentication. With in-kernel authentication, conn.mode is already lower than HT for a legacy AP when the association starts. wpa_supplicant uses in-kernel authentication for FT by default, so it should not have this problem. SAE or FILS with external authentication can possibly have the same problem, but I did not test this. I also did not test the VHT case (an HT-only AP on 5 GHz) on real hardware. Another way to fix it would be in ieee80211_mgd_get_ap_ht_vht_capa() to lower conn.mode instead of returning -EINVAL. I did not use this approach, because then that function changes the mode, which its callers do not expect, and ieee80211_determine_chan_mode() sets the mode later anyway. Note that this changes at least one behavior: a (bogus) 5 GHz AP could theoretically give VHT operation information in its HE operation element without a VHT capability element. Then conn.mode can be VHT or higher after ieee80211_determine_chan_mode(). Before this patch, such an association failed also with in-kernel authentication. Now it continues. Tests (mac80211_hwsim, iwd test-runner, qemu): - AP 1: 5 GHz, HT/VHT, FT-PSK, mobility domain aabb. - AP 2: 5 GHz, legacy (ieee80211n/ac/ax=0, wmm_enabled=1), FT-PSK, same mobility domain. - iwd connects to AP 1, then roams with FT to AP 2. Without this patch, the roam fails (netdev_cmd_ft_reassociate_cb() -22). With this patch, the roam is successful, and a normal connection to AP 2 is also successful. I did the tests on v6.18.48 and on wireless/main (045958acaa75). Note that I used an LLM tool to help analyze the problem, re-write the patch and setup the test infra. I examined and tested the result. net/mac80211/ieee80211_i.h | 4 -- net/mac80211/mlme.c | 130 +++++++++++++------------------------ 2 files changed, 45 insertions(+), 89 deletions(-) diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h index 9374c2942489..4d1734c60e64 100644 --- a/net/mac80211/ieee80211_i.h +++ b/net/mac80211/ieee80211_i.h @@ -446,10 +446,6 @@ struct ieee80211_mgd_assoc_data { u8 addr[ETH_ALEN] __aligned(2); - u8 ap_ht_param; - - struct ieee80211_vht_cap ap_vht_cap; - size_t elems_len; u8 *elems; /* pointing to inside ie[] below */ diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c index 3c31c16860ab..9b97ae3b353e 100644 --- a/net/mac80211/mlme.c +++ b/net/mac80211/mlme.c @@ -2148,6 +2148,43 @@ ieee80211_assoc_add_ml_elem(struct ieee80211_sub_if_data *sdata, const u16 *present_elems, struct ieee80211_mgd_assoc_data *assoc_data); +/* + * Get the AP HT and VHT data that some of our association request elements + * use. Do this only after conn.mode is set from the AP capabilities. Before + * that, for example if user space did the authentication, conn.mode can show + * HT or VHT for an AP that does not have these elements. If the AP does not + * have the element, use zero values. This makes sure that we do not use + * capabilities that the AP did not show. + */ +static u8 ieee80211_get_ap_ht_param(struct cfg80211_bss *cbss) +{ + const struct element *elem; + u8 ap_ht_param = 0; + + rcu_read_lock(); + elem = ieee80211_bss_get_elem(cbss, WLAN_EID_HT_OPERATION); + if (elem && elem->datalen >= sizeof(struct ieee80211_ht_operation)) + ap_ht_param = + ((struct ieee80211_ht_operation *)elem->data)->ht_param; + rcu_read_unlock(); + + return ap_ht_param; +} + +static void ieee80211_get_ap_vht_cap(struct cfg80211_bss *cbss, + struct ieee80211_vht_cap *ap_vht_cap) +{ + const struct element *elem; + + memset(ap_vht_cap, 0, sizeof(*ap_vht_cap)); + + rcu_read_lock(); + elem = ieee80211_bss_get_elem(cbss, WLAN_EID_VHT_CAPABILITY); + if (elem && elem->datalen >= sizeof(struct ieee80211_vht_cap)) + memcpy(ap_vht_cap, elem->data, sizeof(*ap_vht_cap)); + rcu_read_unlock(); +} + static size_t ieee80211_add_link_elems(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb, u16 *capab, @@ -2262,7 +2299,7 @@ ieee80211_add_link_elems(struct ieee80211_sub_if_data *sdata, if (sband->band != NL80211_BAND_6GHZ && assoc_data->link[link_id].conn.mode >= IEEE80211_CONN_MODE_HT) { ieee80211_add_ht_ie(sdata, skb, - assoc_data->link[link_id].ap_ht_param, + ieee80211_get_ap_ht_param(cbss), sband, chan, smps_mode, &assoc_data->link[link_id].conn); ADD_PRESENT_ELEM(WLAN_EID_HT_CAPABILITY); @@ -2276,10 +2313,13 @@ ieee80211_add_link_elems(struct ieee80211_sub_if_data *sdata, if (sband->band != NL80211_BAND_6GHZ && assoc_data->link[link_id].conn.mode >= IEEE80211_CONN_MODE_VHT && sband->vht_cap.vht_supported) { - bool mu_mimo_owner = - ieee80211_add_vht_ie(sdata, skb, sband, - &assoc_data->link[link_id].ap_vht_cap, - &assoc_data->link[link_id].conn); + struct ieee80211_vht_cap ap_vht_cap; + bool mu_mimo_owner; + + ieee80211_get_ap_vht_cap(cbss, &ap_vht_cap); + mu_mimo_owner = ieee80211_add_vht_ie(sdata, skb, sband, + &ap_vht_cap, + &assoc_data->link[link_id].conn); if (link) link->conf->mu_mimo_owner = mu_mimo_owner; @@ -10224,67 +10264,6 @@ ieee80211_setup_assoc_link(struct ieee80211_sub_if_data *sdata, } } -static int -ieee80211_mgd_get_ap_ht_vht_capa(struct ieee80211_sub_if_data *sdata, - struct ieee80211_mgd_assoc_data *assoc_data, - int link_id) -{ - struct cfg80211_bss *cbss = assoc_data->link[link_id].bss; - enum nl80211_band band = cbss->channel->band; - struct ieee80211_supported_band *sband; - const struct element *elem; - int err; - - /* neither HT nor VHT elements used on 6 GHz */ - if (band == NL80211_BAND_6GHZ) - return 0; - - if (assoc_data->link[link_id].conn.mode < IEEE80211_CONN_MODE_HT) - return 0; - - rcu_read_lock(); - elem = ieee80211_bss_get_elem(cbss, WLAN_EID_HT_OPERATION); - if (!elem || elem->datalen < sizeof(struct ieee80211_ht_operation)) { - mlme_link_id_dbg(sdata, link_id, "no HT operation on BSS %pM\n", - cbss->bssid); - err = -EINVAL; - goto out_rcu; - } - assoc_data->link[link_id].ap_ht_param = - ((struct ieee80211_ht_operation *)(elem->data))->ht_param; - rcu_read_unlock(); - - if (assoc_data->link[link_id].conn.mode < IEEE80211_CONN_MODE_VHT) - return 0; - - /* some drivers want to support VHT on 2.4 GHz even */ - sband = sdata->local->hw.wiphy->bands[band]; - if (!sband->vht_cap.vht_supported) - return 0; - - rcu_read_lock(); - elem = ieee80211_bss_get_elem(cbss, WLAN_EID_VHT_CAPABILITY); - /* but even then accept it not being present on the AP */ - if (!elem && band == NL80211_BAND_2GHZ) { - err = 0; - goto out_rcu; - } - if (!elem || elem->datalen < sizeof(struct ieee80211_vht_cap)) { - mlme_link_id_dbg(sdata, link_id, "no VHT capa on BSS %pM\n", - cbss->bssid); - err = -EINVAL; - goto out_rcu; - } - memcpy(&assoc_data->link[link_id].ap_vht_cap, elem->data, - sizeof(struct ieee80211_vht_cap)); - rcu_read_unlock(); - - return 0; -out_rcu: - rcu_read_unlock(); - return err; -} - static bool ieee80211_mgd_assoc_bss_has_mld_ext_capa_ops(struct cfg80211_assoc_request *req) { @@ -10488,14 +10467,6 @@ int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata, req->links[i].error = err; goto err_free; } - - err = ieee80211_mgd_get_ap_ht_vht_capa(sdata, - assoc_data, i); - if (err) { - err = -EINVAL; - req->links[i].error = err; - goto err_free; - } } assoc_data->wmm = true; @@ -10531,10 +10502,6 @@ int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata, &assoc_data->link[0].conn); uapsd_supported = bss->uapsd_supported; - - err = ieee80211_mgd_get_ap_ht_vht_capa(sdata, assoc_data, 0); - if (err) - goto err_free; } assoc_data->spp_amsdu = req->flags & ASSOC_REQ_SPP_AMSDU; @@ -11477,13 +11444,6 @@ int ieee80211_mgd_assoc_ml_reconf(struct ieee80211_sub_if_data *sdata, err = -EINVAL; goto err_free; } - - err = ieee80211_mgd_get_ap_ht_vht_capa(sdata, data, - link_id); - if (err) { - err = -EINVAL; - goto err_free; - } } /* Require U-APSD support if we enabled it */ base-commit: 045958acaa75205b31578cb22c4345e28dd2e4bf -- 2.54.0