From b5e4e89b4ca8140a10995ef16f671f4437a76a73 Mon Sep 17 00:00:00 2001 From: Stefano Avallone Date: Thu, 20 Jun 2024 16:32:30 +0200 Subject: [PATCH] wifi: Fix address returned by StaWifiMac::DoGetLocalAddress() Return the address of the link used to communicate with the single-link AP if the remote address is the BSSID, or the MLD address otherwise. --- src/wifi/model/sta-wifi-mac.cc | 15 +++++++++++---- src/wifi/model/wifi-mac.cc | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/wifi/model/sta-wifi-mac.cc b/src/wifi/model/sta-wifi-mac.cc index 45f819854..6a2db0532 100644 --- a/src/wifi/model/sta-wifi-mac.cc +++ b/src/wifi/model/sta-wifi-mac.cc @@ -960,10 +960,17 @@ StaWifiMac::GetSetupLinkIds() const Mac48Address StaWifiMac::DoGetLocalAddress(const Mac48Address& remoteAddr) const { - auto linkIds = GetSetupLinkIds(); - NS_ASSERT_MSG(!linkIds.empty(), "Not associated"); - uint8_t linkId = *linkIds.begin(); - return GetFrameExchangeManager(linkId)->GetAddress(); + for (const auto& [id, link] : GetLinks()) + { + if (GetStaLink(link).bssid == remoteAddr) + { + // the remote address is the address of the (single link) AP we are associated with; + return link->feManager->GetAddress(); + } + } + + // the remote address is unknown + return GetAddress(); } bool diff --git a/src/wifi/model/wifi-mac.cc b/src/wifi/model/wifi-mac.cc index df291846b..724acfd15 100644 --- a/src/wifi/model/wifi-mac.cc +++ b/src/wifi/model/wifi-mac.cc @@ -1780,7 +1780,7 @@ WifiMac::GetLocalAddress(const Mac48Address& remoteAddr) const // this is a single link device return m_address; } - // this is an MLD (hence the remote device is single link) + // this is an MLD (hence the remote device is single link or unknown) return DoGetLocalAddress(remoteAddr); }