xref: /aosp_15_r20/hardware/interfaces/wifi/aidl/vts/functional/wifi_ap_iface_aidl_test.cpp (revision 4d7e907c777eeecc4c5bd7cf640a754fac206ff7)
1 /*
2  * Copyright (C) 2022 The Android Open Source Project
3  *
4  * Licensed under the Staache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <vector>
18 
19 #include <VtsCoreUtil.h>
20 #include <aidl/Gtest.h>
21 #include <aidl/Vintf.h>
22 #include <aidl/android/hardware/wifi/BnWifi.h>
23 #include <android/binder_manager.h>
24 #include <android/binder_status.h>
25 #include <binder/IServiceManager.h>
26 #include <binder/ProcessState.h>
27 
28 #include "wifi_aidl_test_utils.h"
29 
30 using aidl::android::hardware::wifi::IWifiApIface;
31 using aidl::android::hardware::wifi::WifiBand;
32 
33 class WifiApIfaceAidlTest : public testing::TestWithParam<std::string> {
34   public:
SetUp()35     void SetUp() override {
36         isBridgedSupport_ = testing::checkSubstringInCommandOutput(
37                 "/system/bin/cmd wifi get-softap-supported-features",
38                 "wifi_softap_bridged_ap_supported");
39         stopWifiService(getInstanceName());
40 
41         wifi_chip_ = getWifiChip(getInstanceName());
42         ASSERT_NE(nullptr, wifi_chip_.get());
43 
44         bool isApSupported = doesChipSupportConcurrencyType(wifi_chip_, IfaceConcurrencyType::AP);
45         if (!isApSupported) {
46             GTEST_SKIP() << "AP interfaces are not supported";
47         }
48     }
49 
TearDown()50     void TearDown() override { stopWifiService(getInstanceName()); }
51 
52   protected:
53     bool isBridgedSupport_ = false;
54     std::shared_ptr<IWifiChip> wifi_chip_;
getInstanceName()55     const char* getInstanceName() { return GetParam().c_str(); }
56 };
57 
58 /*
59  * SetMacAddress
60  */
TEST_P(WifiApIfaceAidlTest,SetMacAddress)61 TEST_P(WifiApIfaceAidlTest, SetMacAddress) {
62     std::shared_ptr<IWifiApIface> wifi_ap_iface = getWifiApIface(wifi_chip_);
63     ASSERT_NE(nullptr, wifi_ap_iface.get());
64     std::array<uint8_t, 6> mac = {0x12, 0x22, 0x33, 0x52, 0x10, 0x44};
65     EXPECT_TRUE(wifi_ap_iface->setMacAddress(mac).isOk());
66 }
67 
68 /*
69  * SetCountryCode
70  */
TEST_P(WifiApIfaceAidlTest,SetCountryCode)71 TEST_P(WifiApIfaceAidlTest, SetCountryCode) {
72     std::shared_ptr<IWifiApIface> wifi_ap_iface = getWifiApIface(wifi_chip_);
73     ASSERT_NE(nullptr, wifi_ap_iface.get());
74 
75     const std::array<uint8_t, 2> country_code = {0x55, 0x53};
76     EXPECT_TRUE(wifi_ap_iface->setCountryCode(country_code).isOk());
77 }
78 
79 /*
80  * GetFactoryMacAddress
81  */
TEST_P(WifiApIfaceAidlTest,GetFactoryMacAddress)82 TEST_P(WifiApIfaceAidlTest, GetFactoryMacAddress) {
83     std::shared_ptr<IWifiApIface> wifi_ap_iface = getWifiApIface(wifi_chip_);
84     ASSERT_NE(nullptr, wifi_ap_iface.get());
85 
86     std::array<uint8_t, 6> mac;
87     EXPECT_TRUE(wifi_ap_iface->getFactoryMacAddress(&mac).isOk());
88     std::array<uint8_t, 6> all_zero_mac = {0, 0, 0, 0, 0, 0};
89     EXPECT_NE(mac, all_zero_mac);
90 }
91 
92 /**
93  * GetBridgedInstances - non-bridged mode
94  */
TEST_P(WifiApIfaceAidlTest,GetBridgedInstances)95 TEST_P(WifiApIfaceAidlTest, GetBridgedInstances) {
96     std::shared_ptr<IWifiApIface> wifi_ap_iface = getWifiApIface(wifi_chip_);
97     ASSERT_NE(nullptr, wifi_ap_iface.get());
98 
99     std::vector<std::string> instances;
100     EXPECT_TRUE(wifi_ap_iface->getBridgedInstances(&instances).isOk());
101     EXPECT_EQ(instances.size(), 0);
102 }
103 
104 /**
105  * GetBridgedInstances - bridged AP mode.
106  */
TEST_P(WifiApIfaceAidlTest,GetBridgedInstances_Bridged)107 TEST_P(WifiApIfaceAidlTest, GetBridgedInstances_Bridged) {
108     if (!isBridgedSupport_) {
109         GTEST_SKIP() << "Missing Bridged AP support";
110     }
111     std::shared_ptr<IWifiApIface> wifi_ap_iface = getBridgedWifiApIface(wifi_chip_);
112     ASSERT_NE(nullptr, wifi_ap_iface.get());
113 
114     std::vector<std::string> instances;
115     EXPECT_TRUE(wifi_ap_iface->getBridgedInstances(&instances).isOk());
116     EXPECT_EQ(instances.size(), 2);
117 }
118 
119 /**
120  * ResetToFactoryMacAddress - non-bridged mode
121  */
TEST_P(WifiApIfaceAidlTest,ResetToFactoryMacAddress)122 TEST_P(WifiApIfaceAidlTest, ResetToFactoryMacAddress) {
123     std::shared_ptr<IWifiApIface> wifi_ap_iface = getWifiApIface(wifi_chip_);
124     ASSERT_NE(nullptr, wifi_ap_iface.get());
125     EXPECT_TRUE(wifi_ap_iface->resetToFactoryMacAddress().isOk());
126 }
127 
128 /**
129  * ResetToFactoryMacAddress - bridged AP mode
130  */
TEST_P(WifiApIfaceAidlTest,ResetToFactoryMacAddress_Bridged)131 TEST_P(WifiApIfaceAidlTest, ResetToFactoryMacAddress_Bridged) {
132     if (!isBridgedSupport_) {
133         GTEST_SKIP() << "Missing Bridged AP support";
134     }
135     std::shared_ptr<IWifiApIface> wifi_ap_iface = getBridgedWifiApIface(wifi_chip_);
136     ASSERT_NE(nullptr, wifi_ap_iface.get());
137     EXPECT_TRUE(wifi_ap_iface->resetToFactoryMacAddress().isOk());
138 }
139 
140 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(WifiApIfaceAidlTest);
141 INSTANTIATE_TEST_SUITE_P(WifiTest, WifiApIfaceAidlTest,
142                          testing::ValuesIn(android::getAidlHalInstanceNames(IWifi::descriptor)),
143                          android::PrintInstanceNameToString);
144 
main(int argc,char ** argv)145 int main(int argc, char** argv) {
146     ::testing::InitGoogleTest(&argc, argv);
147     android::ProcessState::self()->setThreadPoolMaxThreadCount(1);
148     android::ProcessState::self()->startThreadPool();
149     return RUN_ALL_TESTS();
150 }
151