From 76fc67a6af2834bccdda388b99f4dc0272bb4dad Mon Sep 17 00:00:00 2001 From: Purushottam Kushwaha Date: Thu, 14 May 2020 18:34:27 +0530 Subject: [PATCH] wificond: Handle NL80211_CMD_CH_SWITCH_NOTIFY Add support to handle NL80211_CMD_CH_SWITCH_NOTIFY mainly to update association frequency. Bug: 155941506 Bug: 156588935 Test: Manual-Verified that channel is updated upon handling CSA. Test: system/connectivity/wificond/runtests.sh Signed-off-by: Purushottam Kushwaha Change-Id: I239c9e6ea0a082a909f9fe9caa007784ffab9112 --- client_interface_impl.cpp | 16 ++++++++++++++++ client_interface_impl.h | 1 + tests/client_interface_impl_unittest.cpp | 4 ++++ 3 files changed, 21 insertions(+) diff --git a/client_interface_impl.cpp b/client_interface_impl.cpp index 15df0fd..38a59ff 100644 --- a/client_interface_impl.cpp +++ b/client_interface_impl.cpp @@ -40,6 +40,8 @@ using std::string; using std::unique_ptr; using std::vector; +using namespace std::placeholders; + namespace android { namespace wificond { @@ -131,6 +133,9 @@ ClientInterfaceImpl::ClientInterfaceImpl( } }); + netlink_utils_->SubscribeChannelSwitchEvent(interface_index_, + std::bind(&ClientInterfaceImpl::OnChannelSwitchEvent, this, _1)); + if (!netlink_utils_->GetWiphyInfo(wiphy_index_, &band_info_, &scan_capabilities_, @@ -154,6 +159,7 @@ ClientInterfaceImpl::~ClientInterfaceImpl() { scanner_->Invalidate(); netlink_utils_->UnsubscribeFrameTxStatusEvent(interface_index_); netlink_utils_->UnsubscribeMlmeEvent(interface_index_); + netlink_utils_->UnsubscribeChannelSwitchEvent(interface_index_); if_tool_->SetUpState(interface_name_.c_str(), false); } @@ -251,6 +257,16 @@ bool ClientInterfaceImpl::RefreshAssociateFreq() { return false; } +bool ClientInterfaceImpl::OnChannelSwitchEvent(uint32_t frequency) { + if(!frequency) { + LOG(ERROR) << "Frequency value is null"; + return false; + } + LOG(INFO) << "New channel on frequency: " << frequency; + associate_freq_ = frequency; + return true; +} + bool ClientInterfaceImpl::IsAssociated() const { return is_associated_; } diff --git a/client_interface_impl.h b/client_interface_impl.h index b4e35ba..4ecbf1d 100644 --- a/client_interface_impl.h +++ b/client_interface_impl.h @@ -88,6 +88,7 @@ class ClientInterfaceImpl { private: bool RefreshAssociateFreq(); + bool OnChannelSwitchEvent(uint32_t frequency); const uint32_t wiphy_index_; const std::string interface_name_; diff --git a/tests/client_interface_impl_unittest.cpp b/tests/client_interface_impl_unittest.cpp index d4b6a62..1dc2699 100644 --- a/tests/client_interface_impl_unittest.cpp +++ b/tests/client_interface_impl_unittest.cpp @@ -77,6 +77,8 @@ class ClientInterfaceImplTest : public ::testing::Test { OnFrameTxStatusEventHandler handler) { frame_tx_status_event_handler_ = handler; }); + EXPECT_CALL(*netlink_utils_, + SubscribeChannelSwitchEvent(kTestInterfaceIndex, _)); client_interface_.reset(new ClientInterfaceImpl{ kTestWiphyIndex, kTestInterfaceName, @@ -92,6 +94,8 @@ class ClientInterfaceImplTest : public ::testing::Test { UnsubscribeMlmeEvent(kTestInterfaceIndex)); EXPECT_CALL(*netlink_utils_, UnsubscribeFrameTxStatusEvent(kTestInterfaceIndex)); + EXPECT_CALL(*netlink_utils_, + UnsubscribeChannelSwitchEvent(kTestInterfaceIndex)); } unique_ptr> if_tool_{