diff options
author | Veerendranath Jakkam <quic_vjakkam@quicinc.com> | 2023-12-02 03:29:40 +0530 |
---|---|---|
committer | Sunil Ravi <sunilravi@google.com> | 2023-12-06 23:24:23 +0000 |
commit | 17423481a0ca14cfe54db89c64472a8abda3418d (patch) | |
tree | 9488c9c6693fa6166b2321e23aeba10a756fa698 | |
parent | 41d0276c5cbd368e5dc44f6dd89cadd9721784df (diff) | |
download | wificond-17423481a0ca14cfe54db89c64472a8abda3418d.tar.gz |
Specify wiphy index while fetching driver country code
NL80211_CMD_GET_REG gives global country code information which may be
different from actual driver country code. Thus, use wiphy index while
fetching driver country code.
Also, the country code changes not subscribed with NetlinkUtils() when
there are no active interfaces in wificond internal structures. So,
fetch the current country code just before subscribing for country code
change events with NetlinkUtils() and broadcast to all registered
framework callbacks.
Bug: 314689364
Test: Manual - SoftAp turn on/off & verified the country code from
bugreport
Test: Manual - Wi-Fi turned ON and verified the country code from logs
Change-Id: I9a4e847abf1c5faa756ed3a624c350812e98bb8c
-rw-r--r-- | net/netlink_utils.cpp | 5 | ||||
-rw-r--r-- | net/netlink_utils.h | 3 | ||||
-rw-r--r-- | server.cpp | 24 | ||||
-rw-r--r-- | tests/netlink_utils_unittest.cpp | 4 |
4 files changed, 26 insertions, 10 deletions
diff --git a/net/netlink_utils.cpp b/net/netlink_utils.cpp index fc705d6..5ee595c 100644 --- a/net/netlink_utils.cpp +++ b/net/netlink_utils.cpp @@ -847,12 +847,15 @@ bool NetlinkUtils::MergePacketsForSplitWiphyDump( return true; } -bool NetlinkUtils::GetCountryCode(string* out_country_code) { +bool NetlinkUtils::GetCountryCode(uint32_t wiphy_index, + string* out_country_code) { NL80211Packet get_country_code( netlink_manager_->GetFamilyId(), NL80211_CMD_GET_REG, netlink_manager_->GetSequenceNumber(), getpid()); + get_country_code.AddAttribute(NL80211Attr<uint32_t>(NL80211_ATTR_WIPHY, + wiphy_index)); unique_ptr<const NL80211Packet> response; if (!netlink_manager_->SendMessageAndGetSingleResponse(get_country_code, &response)) { diff --git a/net/netlink_utils.h b/net/netlink_utils.h index 3b334d9..c8f6756 100644 --- a/net/netlink_utils.h +++ b/net/netlink_utils.h @@ -241,7 +241,8 @@ class NetlinkUtils { // Get current alpha2 country code from kernel. // Returns true on success. - virtual bool GetCountryCode(std::string* out_country_code); + virtual bool GetCountryCode(uint32_t wiphy_index, + std::string* out_country_code); // Sign up to be notified when there is MLME event. // Only one handler can be registered per interface index. @@ -78,10 +78,6 @@ Status Server::registerWificondEventCallback(const sp<IWificondEventCallback>& c LOG(INFO) << "New wificond event callback registered"; wificond_event_callbacks_.push_back(callback); - if (current_country_code_.empty() && - !netlink_utils_->GetCountryCode(¤t_country_code_)) { - LOG(ERROR) << "Fail to get country code"; - } // Inform immediately about current country code if (!current_country_code_.empty()) callback->OnRegDomainChanged(current_country_code_); @@ -306,7 +302,9 @@ status_t Server::dump(int fd, const Vector<String16>& /*args*/) { } string country_code; - if (netlink_utils_->GetCountryCode(&country_code)) { + uint32_t wiphy_index; + if (netlink_utils_->GetWiphyIndex(&wiphy_index) && + netlink_utils_->GetCountryCode(wiphy_index, &country_code)) { ss << "Current country code from kernel: " << country_code << endl; } else { ss << "Failed to get country code from kernel." << endl; @@ -472,6 +470,20 @@ bool Server::SetupInterface(const std::string& iface_name, LOG(ERROR) << "Failed to get wiphy index"; return false; } + + std::string country_code; + if (!netlink_utils_->GetCountryCode(*wiphy_index, &country_code) || + country_code.empty()) { + LOG(ERROR) << "Fail to get country code"; + } else { + LOG(INFO) << "Current driver country code " << country_code; + if (current_country_code_.empty() || + current_country_code_.compare(country_code) != 0) { + current_country_code_ = country_code; + BroadcastRegDomainChanged(); + } + } + // TODO: It may need to handle multi-chips case to get multi-wiphy index and // register corresponding callback. netlink_utils_->SubscribeRegDomainChange( @@ -525,7 +537,7 @@ void Server::handleCountryCodeChanged() { void Server::OnRegDomainChanged(uint32_t wiphy_index, std::string& country_code) { if (country_code.empty()) { LOG(DEBUG) << "Regulatory domain changed with empty country code (world mode?)"; - if (!netlink_utils_->GetCountryCode(¤t_country_code_)) { + if (!netlink_utils_->GetCountryCode(wiphy_index, ¤t_country_code_)) { LOG(ERROR) << "Fail to get country code on wiphy_index:" << wiphy_index; } } else { diff --git a/tests/netlink_utils_unittest.cpp b/tests/netlink_utils_unittest.cpp index 1b27cc8..26cd0d3 100644 --- a/tests/netlink_utils_unittest.cpp +++ b/tests/netlink_utils_unittest.cpp @@ -918,7 +918,7 @@ TEST_F(NetlinkUtilsTest, CanGetCountryCode) { WillOnce(DoAll(MakeupResponse(response), Return(true))); string country_code; - EXPECT_TRUE(netlink_utils_->GetCountryCode(&country_code)); + EXPECT_TRUE(netlink_utils_->GetCountryCode(0, &country_code)); EXPECT_EQ(kFakeCountryCode, country_code); } @@ -930,7 +930,7 @@ TEST_F(NetlinkUtilsTest, CanHandleGetCountryCodeError) { WillOnce(DoAll(MakeupResponse(response), Return(true))); string country_code_ignored; - EXPECT_FALSE(netlink_utils_->GetCountryCode(&country_code_ignored)); + EXPECT_FALSE(netlink_utils_->GetCountryCode(0, &country_code_ignored)); } TEST_F(NetlinkUtilsTest, CanSendMgmtFrame) { |