wifi: Add new HAL API: getBridgedInstances

Also fix the instances doesn't update after removing the instance

Cherry-pick from ag/13382534 which finished the review in master branch

Bug: 173999527
Test: atest -c VtsHalWifiApV1_5TargetTest

Change-Id: I439922d38c35b5367823f95f5f7d0e4c6ed05f57
This commit is contained in:
lesl 2021-01-22 19:37:47 +08:00
parent 3e44dd3fb2
commit 669c906329
6 changed files with 89 additions and 9 deletions

View file

@ -37,4 +37,18 @@ interface IWifiApIface extends @1.4::IWifiApIface {
* |WifiStatusCode.ERROR_UNKNOWN|
*/
resetToFactoryMacAddress() generates (WifiStatus status);
/**
* Get the names of the bridged AP instances.
*
* @return status WifiStatus of the operation
* Possible status codes:
* |WifiStatusCode.SUCCESS|,
* |WifiStatusCode.ERROR_WIFI_IFACE_INVALID|,
* |WifiStatusCode.ERROR_UNKNOWN|
*
* @return instances A vector which contains the names of the bridged AP
* instances. Note: Returns an empty vector for a non-bridged AP.
*/
getBridgedInstances() generates (WifiStatus status, vec<string> instances);
};

View file

@ -47,6 +47,12 @@ bool WifiApIface::isValid() { return is_valid_; }
std::string WifiApIface::getName() { return ifname_; }
void WifiApIface::removeInstance(std::string instance) {
instances_.erase(
std::remove(instances_.begin(), instances_.end(), instance),
instances_.end());
}
Return<void> WifiApIface::getName(getName_cb hidl_status_cb) {
return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
&WifiApIface::getNameInternal, hidl_status_cb);
@ -93,6 +99,13 @@ Return<void> WifiApIface::resetToFactoryMacAddress(
hidl_status_cb);
}
Return<void> WifiApIface::getBridgedInstances(
getBridgedInstances_cb hidl_status_cb) {
return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
&WifiApIface::getBridgedInstancesInternal,
hidl_status_cb);
}
std::pair<WifiStatus, std::string> WifiApIface::getNameInternal() {
return {createWifiStatus(WifiStatusCode::SUCCESS), ifname_};
}
@ -178,6 +191,15 @@ WifiStatus WifiApIface::resetToFactoryMacAddressInternal() {
}
return createWifiStatus(WifiStatusCode::SUCCESS);
}
std::pair<WifiStatus, std::vector<hidl_string>>
WifiApIface::getBridgedInstancesInternal() {
std::vector<hidl_string> instances;
for (const auto& instance_name : instances_) {
instances.push_back(instance_name);
}
return {createWifiStatus(WifiStatusCode::SUCCESS), instances};
}
} // namespace implementation
} // namespace V1_5
} // namespace wifi

View file

@ -43,6 +43,7 @@ class WifiApIface : public V1_5::IWifiApIface {
void invalidate();
bool isValid();
std::string getName();
void removeInstance(std::string instance);
// HIDL methods exposed.
Return<void> getName(getName_cb hidl_status_cb) override;
@ -59,6 +60,9 @@ class WifiApIface : public V1_5::IWifiApIface {
Return<void> resetToFactoryMacAddress(
resetToFactoryMacAddress_cb hidl_status_cb) override;
Return<void> getBridgedInstances(
getBridgedInstances_cb hidl_status_cb) override;
private:
// Corresponding worker functions for the HIDL methods.
std::pair<WifiStatus, std::string> getNameInternal();
@ -70,6 +74,8 @@ class WifiApIface : public V1_5::IWifiApIface {
std::pair<WifiStatus, std::array<uint8_t, 6>> getFactoryMacAddressInternal(
const std::string& ifaceName);
WifiStatus resetToFactoryMacAddressInternal();
std::pair<WifiStatus, std::vector<hidl_string>>
getBridgedInstancesInternal();
std::string ifname_;
std::vector<std::string> instances_;

View file

@ -1067,6 +1067,7 @@ WifiStatus WifiChip::removeIfaceInstanceFromBridgedApIfaceInternal(
}
}
br_ifaces_ap_instances_.erase(ifInstanceName);
iface->removeInstance(ifInstanceName);
return createWifiStatus(WifiStatusCode::SUCCESS);
}

View file

@ -67,8 +67,8 @@ class WifiApIfaceHidlTest : public ::testing::TestWithParam<std::string> {
std::string GetInstanceName() { return GetParam(); }
};
/*
* resetToFactoryMacAddress
/**
* resetToFactoryMacAddress in bridged AP mode.
*/
TEST_P(WifiApIfaceHidlTest, resetToFactoryMacAddressInBridgedModeTest) {
if (!isBridgedSupport_) GTEST_SKIP() << "Missing Bridged AP support";
@ -79,8 +79,8 @@ TEST_P(WifiApIfaceHidlTest, resetToFactoryMacAddressInBridgedModeTest) {
EXPECT_EQ(WifiStatusCode::SUCCESS, status.code);
}
/*
* resetToFactoryMacAddress
/**
* resetToFactoryMacAddress in non-bridged mode
*/
TEST_P(WifiApIfaceHidlTest, resetToFactoryMacAddressTest) {
sp<IWifiApIface> wifi_ap_iface = getWifiApIface_1_5(GetInstanceName());
@ -89,6 +89,34 @@ TEST_P(WifiApIfaceHidlTest, resetToFactoryMacAddressTest) {
EXPECT_EQ(WifiStatusCode::SUCCESS, status.code);
}
/**
* getBridgedInstances in non-bridged mode
*/
TEST_P(WifiApIfaceHidlTest, getBridgedInstancesTest) {
sp<IWifiApIface> wifi_ap_iface = getWifiApIface_1_5(GetInstanceName());
ASSERT_NE(nullptr, wifi_ap_iface.get());
const auto& status_and_instances =
HIDL_INVOKE(wifi_ap_iface, getBridgedInstances);
EXPECT_EQ(WifiStatusCode::SUCCESS, status_and_instances.first.code);
const auto& instances = status_and_instances.second;
EXPECT_EQ(0, instances.size());
}
/**
* getBridgedInstances in bridged AP mode.
*/
TEST_P(WifiApIfaceHidlTest, getBridgedInstancesInBridgedModeTest) {
if (!isBridgedSupport_) GTEST_SKIP() << "Missing Bridged AP support";
sp<IWifiApIface> wifi_ap_iface =
getBridgedWifiApIface_1_5(GetInstanceName());
ASSERT_NE(nullptr, wifi_ap_iface.get());
const auto& status_and_instances =
HIDL_INVOKE(wifi_ap_iface, getBridgedInstances);
EXPECT_EQ(WifiStatusCode::SUCCESS, status_and_instances.first.code);
const auto& instances = status_and_instances.second;
EXPECT_EQ(2, instances.size());
}
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(WifiApIfaceHidlTest);
INSTANTIATE_TEST_SUITE_P(
PerInstance, WifiApIfaceHidlTest,

View file

@ -101,14 +101,23 @@ TEST_P(WifiChipHidlTest,
ASSERT_NE(nullptr, wifi_ap_iface.get());
const auto& status_and_name = HIDL_INVOKE(wifi_ap_iface, getName);
EXPECT_EQ(WifiStatusCode::SUCCESS, status_and_name.first.code);
// TODO: b/173999527, add API to get instance name to replace it.
std::string br_name = status_and_name.second; // ap_br_ is the pre-fix
std::string instance_name =
br_name.substr(6, br_name.length()); // remove the pre-fex
std::string br_name = status_and_name.second;
const auto& status_and_instances =
HIDL_INVOKE(wifi_ap_iface, getBridgedInstances);
EXPECT_EQ(WifiStatusCode::SUCCESS, status_and_instances.first.code);
const auto& instances = status_and_instances.second;
EXPECT_EQ(2, instances.size());
const auto& status_code =
HIDL_INVOKE(wifi_chip_, removeIfaceInstanceFromBridgedApIface, br_name,
instance_name);
instances[0]);
EXPECT_EQ(WifiStatusCode::SUCCESS, status_code.code);
const auto& status_and_instances_after_remove =
HIDL_INVOKE(wifi_ap_iface, getBridgedInstances);
EXPECT_EQ(WifiStatusCode::SUCCESS,
status_and_instances_after_remove.first.code);
const auto& instances_after_remove =
status_and_instances_after_remove.second;
EXPECT_EQ(1, instances_after_remove.size());
}
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(WifiChipHidlTest);