summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXin Li <delphij@google.com>2024-03-06 09:30:16 -0800
committerXin Li <delphij@google.com>2024-03-06 18:58:28 -0800
commitf19a77c24e7251d1a8112433fdacc02ac5a02a72 (patch)
tree5db5e8f130a276dbb37731e287cdfe3e812b6887
parent50264c8fdf9eac8788d5017ba32b5f1f3c1ea287 (diff)
parentc310a0d0592c9db68aa7e2a737e923f610a2eab0 (diff)
downloadwificond-master.tar.gz
Merge Android 14 QPR2 to AOSP mainHEADmastermain
Bug: 319669529 Merged-In: I06539bc33a2734c04c6158f25be60163bdd1e416 Change-Id: Icaf0b04ba619a7c50e7d8dcefb0d5b693348a8cf
-rw-r--r--Android.bp6
-rw-r--r--net/netlink_utils.cpp5
-rw-r--r--net/netlink_utils.h3
-rw-r--r--server.cpp39
-rw-r--r--server.h4
-rw-r--r--tests/netlink_utils_unittest.cpp4
6 files changed, 43 insertions, 18 deletions
diff --git a/Android.bp b/Android.bp
index a554cda..4443468 100644
--- a/Android.bp
+++ b/Android.bp
@@ -64,8 +64,6 @@ cc_defaults {
include_dirs: ["system/security/keystore/include"],
shared_libs: [
- "android.hardware.net.nlinterceptor-V1-ndk",
- "android.security.legacykeystore-ndk",
"libbinder",
"libbinder_ndk",
"libbase",
@@ -76,9 +74,11 @@ cc_defaults {
"libssl",
"libutils",
"libwifi-system-iface",
- "android.system.wifi.keystore@1.0",
],
static_libs: [
+ "android.hardware.net.nlinterceptor-V1-ndk",
+ "android.security.legacykeystore-ndk",
+ "android.system.wifi.keystore@1.0",
"libwificond", // Wificond daemon
"libwifikeystorehal", // Wifi Keystore HAL service
],
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.
diff --git a/server.cpp b/server.cpp
index 9b6bc38..6ad9462 100644
--- a/server.cpp
+++ b/server.cpp
@@ -77,6 +77,11 @@ Status Server::registerWificondEventCallback(const sp<IWificondEventCallback>& c
}
LOG(INFO) << "New wificond event callback registered";
wificond_event_callbacks_.push_back(callback);
+
+ // Inform immediately about current country code
+ if (!current_country_code_.empty())
+ callback->OnRegDomainChanged(current_country_code_);
+
return Status::ok();
}
@@ -297,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;
@@ -463,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(
@@ -514,19 +535,18 @@ void Server::handleCountryCodeChanged() {
}
void Server::OnRegDomainChanged(uint32_t wiphy_index, std::string& country_code) {
- string current_country_code;
if (country_code.empty()) {
LOG(DEBUG) << "Regulatory domain changed with empty country code (world mode?)";
- if (!netlink_utils_->GetCountryCode(&current_country_code)) {
+ if (!netlink_utils_->GetCountryCode(wiphy_index, &current_country_code_)) {
LOG(ERROR) << "Fail to get country code on wiphy_index:" << wiphy_index;
}
} else {
- current_country_code = country_code;
+ current_country_code_ = country_code;
}
- if (!current_country_code.empty()) {
- LOG(INFO) << "Regulatory domain changed to country: " << current_country_code
+ if (!current_country_code_.empty()) {
+ LOG(INFO) << "Regulatory domain changed to country: " << current_country_code_
<< " on wiphy_index: " << wiphy_index;
- BroadcastRegDomainChanged(current_country_code);
+ BroadcastRegDomainChanged();
}
// Sometimes lower layer sends stale wiphy index when there are no
// interfaces. So update band - wiphy index mapping only if an
@@ -610,10 +630,9 @@ void Server::BroadcastApInterfaceTornDown(
}
}
-void Server::BroadcastRegDomainChanged(
- std::string country_code) {
+void Server::BroadcastRegDomainChanged() {
for (const auto& it : wificond_event_callbacks_) {
- it->OnRegDomainChanged(country_code);
+ it->OnRegDomainChanged(current_country_code_);
}
}
diff --git a/server.h b/server.h
index df0968c..35f214a 100644
--- a/server.h
+++ b/server.h
@@ -130,7 +130,7 @@ class Server : public android::net::wifi::nl80211::BnWificond {
android::sp<android::net::wifi::nl80211::IClientInterface> network_interface);
void BroadcastApInterfaceTornDown(
android::sp<android::net::wifi::nl80211::IApInterface> network_interface);
- void BroadcastRegDomainChanged(std::string country_code);
+ void BroadcastRegDomainChanged();
void MarkDownAllInterfaces();
int FindWiphyIndex(const std::string& iface_name);
bool GetBandInfo(int wiphy_index, BandInfo* band_info);
@@ -156,6 +156,8 @@ class Server : public android::net::wifi::nl80211::BnWificond {
// Cached interface list from kernel for dumping.
std::vector<InterfaceInfo> debug_interfaces_;
+ std::string current_country_code_;
+
DISALLOW_COPY_AND_ASSIGN(Server);
};
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) {