nl80211: Re-factor nl80211_remove_links() function

nl80211_remove_links() iterated over all active links in the given BSS
and removed all of them. However, at times it is required to remove only
one link and not all links.

Add a helper function nl80211_remove_link() which will remove just the
given link_id from the passed BSS. nl80211_remove_links() will use this
and will call this for each of the active links to be removed.

Signed-off-by: Aditya Kumar Singh <quic_adisi@quicinc.com>
This commit is contained in:
Aditya Kumar Singh 2024-03-06 12:08:58 +05:30 committed by Jouni Malinen
parent b810426eaa
commit b162886fd0

View file

@ -9422,18 +9422,24 @@ fail:
} }
static void nl80211_remove_links(struct i802_bss *bss) static int nl80211_remove_link(struct i802_bss *bss, int link_id)
{ {
struct wpa_driver_nl80211_data *drv = bss->drv; struct wpa_driver_nl80211_data *drv = bss->drv;
struct i802_link *link;
struct nl_msg *msg; struct nl_msg *msg;
size_t i;
int ret; int ret;
u8 link_id, i;
for_each_link(bss->valid_links, link_id) { wpa_printf(MSG_DEBUG, "nl80211: Remove link (ifindex=%d link_id=%u)",
struct i802_link *link = &bss->links[link_id]; bss->ifindex, link_id);
wpa_printf(MSG_DEBUG, "nl80211: MLD: remove link_id=%u", if (!(bss->valid_links & BIT(link_id))) {
link_id); wpa_printf(MSG_DEBUG,
"nl80211: MLD: remove link: Link not found");
return -1;
}
link = &bss->links[link_id];
wpa_driver_nl80211_del_beacon(bss, link_id); wpa_driver_nl80211_del_beacon(bss, link_id);
@ -9464,19 +9470,33 @@ static void nl80211_remove_links(struct i802_bss *bss)
nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link_id)) { nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link_id)) {
nlmsg_free(msg); nlmsg_free(msg);
wpa_printf(MSG_ERROR, wpa_printf(MSG_ERROR,
"nl80211: remove link (%d) failed", "nl80211: remove link (%d) failed", link_id);
link_id); return -1;
continue;
} }
ret = send_and_recv_cmd(drv, msg); ret = send_and_recv_cmd(drv, msg);
if (ret) { if (ret)
wpa_printf(MSG_ERROR, wpa_printf(MSG_ERROR,
"nl80211: remove link (%d) failed. ret=%d (%s)", "nl80211: remove link (%d) failed. ret=%d (%s)",
link_id, ret, strerror(-ret)); link_id, ret, strerror(-ret));
continue;
return ret;
} }
static void nl80211_remove_links(struct i802_bss *bss)
{
int ret;
u8 link_id;
for_each_link(bss->valid_links, link_id) {
ret = nl80211_remove_link(bss, link_id);
if (ret)
break;
} }
if (bss->flink)
os_memcpy(bss->flink->addr, bss->addr, ETH_ALEN);
} }