nl80211: Fix link indexing in nl80211_connect_common()

In some places the wrong index variable was used to access the link
configuration. Fix this by simply using link_id instead of i.

With this, the i loop variable is not needed anymore. We can simply
always pass 0 to nla_nest_start(). Also, the kernel does not care about
the order that the links are provides, so just remove the special
handling for the association link.

Fixes: a2c4c0b1b6 ("nl80211: Support MLD association request")
Signed-off-by: Benjamin Berg <benjamin.berg@intel.com>
This commit is contained in:
Benjamin Berg 2024-02-20 14:18:10 +01:00 committed by Jouni Malinen
parent 408a399aa4
commit 6cb421c1fa

View file

@ -6718,7 +6718,6 @@ static int nl80211_connect_common(struct wpa_driver_nl80211_data *drv,
if (params->mld_params.mld_addr && params->mld_params.valid_links > 0) { if (params->mld_params.mld_addr && params->mld_params.valid_links > 0) {
struct wpa_driver_mld_params *mld_params = &params->mld_params; struct wpa_driver_mld_params *mld_params = &params->mld_params;
struct nlattr *links, *attr; struct nlattr *links, *attr;
int i;
u8 link_id; u8 link_id;
wpa_printf(MSG_DEBUG, " * MLD: MLD addr=" MACSTR, wpa_printf(MSG_DEBUG, " * MLD: MLD addr=" MACSTR,
@ -6734,31 +6733,11 @@ static int nl80211_connect_common(struct wpa_driver_nl80211_data *drv,
if (!links) if (!links)
return -1; return -1;
attr = nla_nest_start(msg, 0); for (link_id = 0; link_id < MAX_NUM_MLD_LINKS; link_id++) {
if (!attr) if (!(mld_params->valid_links & BIT(link_id)))
return -1;
/* First add the association link ID */
link_id = mld_params->assoc_link_id;
if (nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link_id) ||
nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN,
mld_params->mld_links[link_id].bssid) ||
nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
mld_params->mld_links[link_id].freq))
return -1;
os_memcpy(drv->sta_mlo_info.links[link_id].bssid,
mld_params->mld_links[link_id].bssid, ETH_ALEN);
nla_nest_end(msg, attr);
for (i = 1, link_id = 0; link_id < MAX_NUM_MLD_LINKS;
link_id++) {
if (!(mld_params->valid_links & BIT(link_id)) ||
link_id == mld_params->assoc_link_id)
continue; continue;
attr = nla_nest_start(msg, i); attr = nla_nest_start(msg, 0);
if (!attr) if (!attr)
return -1; return -1;
@ -6768,11 +6747,11 @@ static int nl80211_connect_common(struct wpa_driver_nl80211_data *drv,
mld_params->mld_links[link_id].bssid) || mld_params->mld_links[link_id].bssid) ||
nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
mld_params->mld_links[link_id].freq) || mld_params->mld_links[link_id].freq) ||
(mld_params->mld_links[i].disabled && (mld_params->mld_links[link_id].disabled &&
nla_put_flag(msg, nla_put_flag(msg,
NL80211_ATTR_MLO_LINK_DISABLED)) || NL80211_ATTR_MLO_LINK_DISABLED)) ||
(mld_params->mld_links[link_id].ies && (mld_params->mld_links[link_id].ies &&
mld_params->mld_links[i].ies_len && mld_params->mld_links[link_id].ies_len &&
nla_put(msg, NL80211_ATTR_IE, nla_put(msg, NL80211_ATTR_IE,
mld_params->mld_links[link_id].ies_len, mld_params->mld_links[link_id].ies_len,
mld_params->mld_links[link_id].ies))) mld_params->mld_links[link_id].ies)))
@ -6782,7 +6761,6 @@ static int nl80211_connect_common(struct wpa_driver_nl80211_data *drv,
mld_params->mld_links[link_id].bssid, mld_params->mld_links[link_id].bssid,
ETH_ALEN); ETH_ALEN);
nla_nest_end(msg, attr); nla_nest_end(msg, attr);
i++;
} }
nla_nest_end(msg, links); nla_nest_end(msg, links);