1 /*
2 * Copyright (C) 2017, The Android Open Source Project
3 *
4 * Licensed under the Apache 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 <android-base/logging.h>
18 #include <android-base/macros.h>
19 #include <cutils/properties.h>
20 #include <gmock/gmock.h>
21
22 #undef NAN // This is weird, NAN is defined in bionic/libc/include/math.h:38
23 #include "wifi_chip.h"
24
25 #include "mock_interface_tool.h"
26 #include "mock_wifi_feature_flags.h"
27 #include "mock_wifi_iface_util.h"
28 #include "mock_wifi_legacy_hal.h"
29 #include "mock_wifi_mode_controller.h"
30
31 using testing::NiceMock;
32 using testing::Return;
33 using testing::Test;
34
35 namespace {
36 using android::hardware::wifi::V1_0::ChipId;
37
38 constexpr ChipId kFakeChipId = 5;
39 } // namespace
40
41 namespace android {
42 namespace hardware {
43 namespace wifi {
44 namespace V1_3 {
45 namespace implementation {
46
47 class WifiChipTest : public Test {
48 protected:
setupV1IfaceCombination()49 void setupV1IfaceCombination() {
50 // clang-format off
51 const hidl_vec<V1_0::IWifiChip::ChipIfaceCombination> combinationsSta = {
52 {{{{IfaceType::STA}, 1}, {{IfaceType::P2P}, 1}}}
53 };
54 const hidl_vec<V1_0::IWifiChip::ChipIfaceCombination> combinationsAp = {
55 {{{{IfaceType::AP}, 1}}}
56 };
57 const std::vector<V1_0::IWifiChip::ChipMode> modes = {
58 {feature_flags::chip_mode_ids::kV1Sta, combinationsSta},
59 {feature_flags::chip_mode_ids::kV1Ap, combinationsAp}
60 };
61 // clang-format on
62 EXPECT_CALL(*feature_flags_, getChipModes())
63 .WillRepeatedly(testing::Return(modes));
64 }
65
setupV1_AwareIfaceCombination()66 void setupV1_AwareIfaceCombination() {
67 // clang-format off
68 const hidl_vec<V1_0::IWifiChip::ChipIfaceCombination> combinationsSta = {
69 {{{{IfaceType::STA}, 1}, {{IfaceType::P2P, IfaceType::NAN}, 1}}}
70 };
71 const hidl_vec<V1_0::IWifiChip::ChipIfaceCombination> combinationsAp = {
72 {{{{IfaceType::AP}, 1}}}
73 };
74 const std::vector<V1_0::IWifiChip::ChipMode> modes = {
75 {feature_flags::chip_mode_ids::kV1Sta, combinationsSta},
76 {feature_flags::chip_mode_ids::kV1Ap, combinationsAp}
77 };
78 // clang-format on
79 EXPECT_CALL(*feature_flags_, getChipModes())
80 .WillRepeatedly(testing::Return(modes));
81 }
82
setupV1_AwareDisabledApIfaceCombination()83 void setupV1_AwareDisabledApIfaceCombination() {
84 // clang-format off
85 const hidl_vec<V1_0::IWifiChip::ChipIfaceCombination> combinationsSta = {
86 {{{{IfaceType::STA}, 1}, {{IfaceType::P2P, IfaceType::NAN}, 1}}}
87 };
88 const std::vector<V1_0::IWifiChip::ChipMode> modes = {
89 {feature_flags::chip_mode_ids::kV1Sta, combinationsSta}
90 };
91 // clang-format on
92 EXPECT_CALL(*feature_flags_, getChipModes())
93 .WillRepeatedly(testing::Return(modes));
94 }
95
setupV2_AwareIfaceCombination()96 void setupV2_AwareIfaceCombination() {
97 // clang-format off
98 const hidl_vec<V1_0::IWifiChip::ChipIfaceCombination> combinations = {
99 {{{{IfaceType::STA}, 1}, {{IfaceType::AP}, 1}}},
100 {{{{IfaceType::STA}, 1}, {{IfaceType::P2P, IfaceType::NAN}, 1}}}
101 };
102 const std::vector<V1_0::IWifiChip::ChipMode> modes = {
103 {feature_flags::chip_mode_ids::kV3, combinations}
104 };
105 // clang-format on
106 EXPECT_CALL(*feature_flags_, getChipModes())
107 .WillRepeatedly(testing::Return(modes));
108 }
109
setupV2_AwareDisabledApIfaceCombination()110 void setupV2_AwareDisabledApIfaceCombination() {
111 // clang-format off
112 const hidl_vec<V1_0::IWifiChip::ChipIfaceCombination> combinations = {
113 {{{{IfaceType::STA}, 1}, {{IfaceType::P2P, IfaceType::NAN}, 1}}}
114 };
115 const std::vector<V1_0::IWifiChip::ChipMode> modes = {
116 {feature_flags::chip_mode_ids::kV3, combinations}
117 };
118 // clang-format on
119 EXPECT_CALL(*feature_flags_, getChipModes())
120 .WillRepeatedly(testing::Return(modes));
121 }
122
setup_MultiIfaceCombination()123 void setup_MultiIfaceCombination() {
124 // clang-format off
125 const hidl_vec<V1_0::IWifiChip::ChipIfaceCombination> combinations = {
126 {{{{IfaceType::STA}, 3}, {{IfaceType::AP}, 1}}}
127 };
128 const std::vector<V1_0::IWifiChip::ChipMode> modes = {
129 {feature_flags::chip_mode_ids::kV3, combinations}
130 };
131 // clang-format on
132 EXPECT_CALL(*feature_flags_, getChipModes())
133 .WillRepeatedly(testing::Return(modes));
134 }
135
assertNumberOfModes(uint32_t num_modes)136 void assertNumberOfModes(uint32_t num_modes) {
137 chip_->getAvailableModes(
138 [num_modes](const WifiStatus& status,
139 const std::vector<WifiChip::ChipMode>& modes) {
140 ASSERT_EQ(WifiStatusCode::SUCCESS, status.code);
141 // V2_Aware has 1 mode of operation.
142 ASSERT_EQ(num_modes, modes.size());
143 });
144 }
145
findModeAndConfigureForIfaceType(const IfaceType & type)146 void findModeAndConfigureForIfaceType(const IfaceType& type) {
147 // This should be aligned with kInvalidModeId in wifi_chip.cpp.
148 ChipModeId mode_id = UINT32_MAX;
149 chip_->getAvailableModes(
150 [&mode_id, &type](const WifiStatus& status,
151 const std::vector<WifiChip::ChipMode>& modes) {
152 ASSERT_EQ(WifiStatusCode::SUCCESS, status.code);
153 for (const auto& mode : modes) {
154 for (const auto& combination : mode.availableCombinations) {
155 for (const auto& limit : combination.limits) {
156 if (limit.types.end() !=
157 std::find(limit.types.begin(),
158 limit.types.end(), type)) {
159 mode_id = mode.id;
160 }
161 }
162 }
163 }
164 });
165 ASSERT_NE(UINT32_MAX, mode_id);
166
167 chip_->configureChip(mode_id, [](const WifiStatus& status) {
168 ASSERT_EQ(WifiStatusCode::SUCCESS, status.code);
169 });
170 }
171
172 // Returns an empty string on error.
createIface(const IfaceType & type)173 std::string createIface(const IfaceType& type) {
174 std::string iface_name;
175 if (type == IfaceType::AP) {
176 chip_->createApIface([&iface_name](const WifiStatus& status,
177 const sp<IWifiApIface>& iface) {
178 if (WifiStatusCode::SUCCESS == status.code) {
179 ASSERT_NE(iface.get(), nullptr);
180 iface->getName([&iface_name](const WifiStatus& status,
181 const hidl_string& name) {
182 ASSERT_EQ(WifiStatusCode::SUCCESS, status.code);
183 iface_name = name.c_str();
184 });
185 }
186 });
187 } else if (type == IfaceType::NAN) {
188 chip_->createNanIface(
189 [&iface_name](
190 const WifiStatus& status,
191 const sp<android::hardware::wifi::V1_0::IWifiNanIface>&
192 iface) {
193 if (WifiStatusCode::SUCCESS == status.code) {
194 ASSERT_NE(iface.get(), nullptr);
195 iface->getName([&iface_name](const WifiStatus& status,
196 const hidl_string& name) {
197 ASSERT_EQ(WifiStatusCode::SUCCESS, status.code);
198 iface_name = name.c_str();
199 });
200 }
201 });
202 } else if (type == IfaceType::P2P) {
203 chip_->createP2pIface(
204 [&iface_name](const WifiStatus& status,
205 const sp<IWifiP2pIface>& iface) {
206 if (WifiStatusCode::SUCCESS == status.code) {
207 ASSERT_NE(iface.get(), nullptr);
208 iface->getName([&iface_name](const WifiStatus& status,
209 const hidl_string& name) {
210 ASSERT_EQ(WifiStatusCode::SUCCESS, status.code);
211 iface_name = name.c_str();
212 });
213 }
214 });
215 } else if (type == IfaceType::STA) {
216 chip_->createStaIface(
217 [&iface_name](const WifiStatus& status,
218 const sp<V1_0::IWifiStaIface>& iface) {
219 if (WifiStatusCode::SUCCESS == status.code) {
220 ASSERT_NE(iface.get(), nullptr);
221 iface->getName([&iface_name](const WifiStatus& status,
222 const hidl_string& name) {
223 ASSERT_EQ(WifiStatusCode::SUCCESS, status.code);
224 iface_name = name.c_str();
225 });
226 }
227 });
228 }
229 return iface_name;
230 }
231
removeIface(const IfaceType & type,const std::string & iface_name)232 void removeIface(const IfaceType& type, const std::string& iface_name) {
233 if (type == IfaceType::AP) {
234 chip_->removeApIface(iface_name, [](const WifiStatus& status) {
235 ASSERT_EQ(WifiStatusCode::SUCCESS, status.code);
236 });
237 } else if (type == IfaceType::NAN) {
238 chip_->removeNanIface(iface_name, [](const WifiStatus& status) {
239 ASSERT_EQ(WifiStatusCode::SUCCESS, status.code);
240 });
241 } else if (type == IfaceType::P2P) {
242 chip_->removeP2pIface(iface_name, [](const WifiStatus& status) {
243 ASSERT_EQ(WifiStatusCode::SUCCESS, status.code);
244 });
245 } else if (type == IfaceType::STA) {
246 chip_->removeStaIface(iface_name, [](const WifiStatus& status) {
247 ASSERT_EQ(WifiStatusCode::SUCCESS, status.code);
248 });
249 }
250 }
251
createRttController()252 bool createRttController() {
253 bool success = false;
254 chip_->createRttController(
255 NULL, [&success](const WifiStatus& status,
256 const sp<IWifiRttController>& rtt) {
257 if (WifiStatusCode::SUCCESS == status.code) {
258 ASSERT_NE(rtt.get(), nullptr);
259 success = true;
260 }
261 });
262 return success;
263 }
264
265 sp<WifiChip> chip_;
266 ChipId chip_id_ = kFakeChipId;
267 std::shared_ptr<NiceMock<wifi_system::MockInterfaceTool>> iface_tool_{
268 new NiceMock<wifi_system::MockInterfaceTool>};
269 std::shared_ptr<NiceMock<legacy_hal::MockWifiLegacyHal>> legacy_hal_{
270 new NiceMock<legacy_hal::MockWifiLegacyHal>(iface_tool_)};
271 std::shared_ptr<NiceMock<mode_controller::MockWifiModeController>>
272 mode_controller_{new NiceMock<mode_controller::MockWifiModeController>};
273 std::shared_ptr<NiceMock<iface_util::MockWifiIfaceUtil>> iface_util_{
274 new NiceMock<iface_util::MockWifiIfaceUtil>(iface_tool_)};
275 std::shared_ptr<NiceMock<feature_flags::MockWifiFeatureFlags>>
276 feature_flags_{new NiceMock<feature_flags::MockWifiFeatureFlags>};
277
278 public:
SetUp()279 void SetUp() override {
280 chip_ = new WifiChip(chip_id_, legacy_hal_, mode_controller_,
281 iface_util_, feature_flags_);
282
283 EXPECT_CALL(*mode_controller_, changeFirmwareMode(testing::_))
284 .WillRepeatedly(testing::Return(true));
285 EXPECT_CALL(*legacy_hal_, start())
286 .WillRepeatedly(testing::Return(legacy_hal::WIFI_SUCCESS));
287 }
288
TearDown()289 void TearDown() override {
290 // Restore default system iface names (This should ideally be using a
291 // mock).
292 property_set("wifi.interface", "wlan0");
293 property_set("wifi.concurrent.interface", "wlan1");
294 }
295 };
296
297 ////////// V1 Iface Combinations ////////////
298 // Mode 1 - STA + P2P
299 // Mode 2 - AP
300 class WifiChipV1IfaceCombinationTest : public WifiChipTest {
301 public:
SetUp()302 void SetUp() override {
303 setupV1IfaceCombination();
304 WifiChipTest::SetUp();
305 // V1 has 2 modes of operation.
306 assertNumberOfModes(2u);
307 }
308 };
309
TEST_F(WifiChipV1IfaceCombinationTest,StaMode_CreateSta_ShouldSucceed)310 TEST_F(WifiChipV1IfaceCombinationTest, StaMode_CreateSta_ShouldSucceed) {
311 findModeAndConfigureForIfaceType(IfaceType::STA);
312 ASSERT_EQ(createIface(IfaceType::STA), "wlan0");
313 }
314
TEST_F(WifiChipV1IfaceCombinationTest,StaMode_CreateP2p_ShouldSucceed)315 TEST_F(WifiChipV1IfaceCombinationTest, StaMode_CreateP2p_ShouldSucceed) {
316 findModeAndConfigureForIfaceType(IfaceType::STA);
317 ASSERT_FALSE(createIface(IfaceType::P2P).empty());
318 }
319
TEST_F(WifiChipV1IfaceCombinationTest,StaMode_CreateNan_ShouldFail)320 TEST_F(WifiChipV1IfaceCombinationTest, StaMode_CreateNan_ShouldFail) {
321 findModeAndConfigureForIfaceType(IfaceType::STA);
322 ASSERT_TRUE(createIface(IfaceType::NAN).empty());
323 }
324
TEST_F(WifiChipV1IfaceCombinationTest,StaMode_CreateAp_ShouldFail)325 TEST_F(WifiChipV1IfaceCombinationTest, StaMode_CreateAp_ShouldFail) {
326 findModeAndConfigureForIfaceType(IfaceType::STA);
327 ASSERT_TRUE(createIface(IfaceType::AP).empty());
328 }
329
TEST_F(WifiChipV1IfaceCombinationTest,StaMode_CreateStaP2p_ShouldSucceed)330 TEST_F(WifiChipV1IfaceCombinationTest, StaMode_CreateStaP2p_ShouldSucceed) {
331 findModeAndConfigureForIfaceType(IfaceType::STA);
332 ASSERT_FALSE(createIface(IfaceType::STA).empty());
333 ASSERT_FALSE(createIface(IfaceType::P2P).empty());
334 }
335
TEST_F(WifiChipV1IfaceCombinationTest,ApMode_CreateAp_ShouldSucceed)336 TEST_F(WifiChipV1IfaceCombinationTest, ApMode_CreateAp_ShouldSucceed) {
337 findModeAndConfigureForIfaceType(IfaceType::AP);
338 ASSERT_EQ(createIface(IfaceType::AP), "wlan0");
339 }
340
TEST_F(WifiChipV1IfaceCombinationTest,ApMode_CreateSta_ShouldFail)341 TEST_F(WifiChipV1IfaceCombinationTest, ApMode_CreateSta_ShouldFail) {
342 findModeAndConfigureForIfaceType(IfaceType::AP);
343 ASSERT_TRUE(createIface(IfaceType::STA).empty());
344 }
345
TEST_F(WifiChipV1IfaceCombinationTest,ApMode_CreateP2p_ShouldFail)346 TEST_F(WifiChipV1IfaceCombinationTest, ApMode_CreateP2p_ShouldFail) {
347 findModeAndConfigureForIfaceType(IfaceType::AP);
348 ASSERT_TRUE(createIface(IfaceType::STA).empty());
349 }
350
TEST_F(WifiChipV1IfaceCombinationTest,ApMode_CreateNan_ShouldFail)351 TEST_F(WifiChipV1IfaceCombinationTest, ApMode_CreateNan_ShouldFail) {
352 findModeAndConfigureForIfaceType(IfaceType::AP);
353 ASSERT_TRUE(createIface(IfaceType::NAN).empty());
354 }
355
356 ////////// V1 + Aware Iface Combinations ////////////
357 // Mode 1 - STA + P2P/NAN
358 // Mode 2 - AP
359 class WifiChipV1_AwareIfaceCombinationTest : public WifiChipTest {
360 public:
SetUp()361 void SetUp() override {
362 setupV1_AwareIfaceCombination();
363 WifiChipTest::SetUp();
364 // V1_Aware has 2 modes of operation.
365 assertNumberOfModes(2u);
366 }
367 };
368
TEST_F(WifiChipV1_AwareIfaceCombinationTest,StaMode_CreateSta_ShouldSucceed)369 TEST_F(WifiChipV1_AwareIfaceCombinationTest, StaMode_CreateSta_ShouldSucceed) {
370 findModeAndConfigureForIfaceType(IfaceType::STA);
371 ASSERT_EQ(createIface(IfaceType::STA), "wlan0");
372 }
373
TEST_F(WifiChipV1_AwareIfaceCombinationTest,StaMode_CreateP2p_ShouldSucceed)374 TEST_F(WifiChipV1_AwareIfaceCombinationTest, StaMode_CreateP2p_ShouldSucceed) {
375 findModeAndConfigureForIfaceType(IfaceType::STA);
376 ASSERT_FALSE(createIface(IfaceType::P2P).empty());
377 }
378
TEST_F(WifiChipV1_AwareIfaceCombinationTest,StaMode_CreateNan_ShouldSucceed)379 TEST_F(WifiChipV1_AwareIfaceCombinationTest, StaMode_CreateNan_ShouldSucceed) {
380 findModeAndConfigureForIfaceType(IfaceType::STA);
381 ASSERT_FALSE(createIface(IfaceType::NAN).empty());
382 }
383
TEST_F(WifiChipV1_AwareIfaceCombinationTest,StaMode_CreateAp_ShouldFail)384 TEST_F(WifiChipV1_AwareIfaceCombinationTest, StaMode_CreateAp_ShouldFail) {
385 findModeAndConfigureForIfaceType(IfaceType::STA);
386 ASSERT_TRUE(createIface(IfaceType::AP).empty());
387 }
388
TEST_F(WifiChipV1_AwareIfaceCombinationTest,StaMode_CreateStaP2p_ShouldSucceed)389 TEST_F(WifiChipV1_AwareIfaceCombinationTest,
390 StaMode_CreateStaP2p_ShouldSucceed) {
391 findModeAndConfigureForIfaceType(IfaceType::STA);
392 ASSERT_FALSE(createIface(IfaceType::STA).empty());
393 ASSERT_FALSE(createIface(IfaceType::P2P).empty());
394 }
395
TEST_F(WifiChipV1_AwareIfaceCombinationTest,StaMode_CreateStaNan_ShouldSucceed)396 TEST_F(WifiChipV1_AwareIfaceCombinationTest,
397 StaMode_CreateStaNan_ShouldSucceed) {
398 findModeAndConfigureForIfaceType(IfaceType::STA);
399 ASSERT_FALSE(createIface(IfaceType::STA).empty());
400 ASSERT_FALSE(createIface(IfaceType::NAN).empty());
401 }
402
TEST_F(WifiChipV1_AwareIfaceCombinationTest,StaMode_CreateStaP2PNan_ShouldFail)403 TEST_F(WifiChipV1_AwareIfaceCombinationTest,
404 StaMode_CreateStaP2PNan_ShouldFail) {
405 findModeAndConfigureForIfaceType(IfaceType::STA);
406 ASSERT_FALSE(createIface(IfaceType::STA).empty());
407 ASSERT_FALSE(createIface(IfaceType::P2P).empty());
408 ASSERT_TRUE(createIface(IfaceType::NAN).empty());
409 }
410
TEST_F(WifiChipV1_AwareIfaceCombinationTest,StaMode_CreateStaNan_AfterP2pRemove_ShouldSucceed)411 TEST_F(WifiChipV1_AwareIfaceCombinationTest,
412 StaMode_CreateStaNan_AfterP2pRemove_ShouldSucceed) {
413 findModeAndConfigureForIfaceType(IfaceType::STA);
414 ASSERT_FALSE(createIface(IfaceType::STA).empty());
415 const auto p2p_iface_name = createIface(IfaceType::P2P);
416 ASSERT_FALSE(p2p_iface_name.empty());
417 ASSERT_TRUE(createIface(IfaceType::NAN).empty());
418
419 // After removing P2P iface, NAN iface creation should succeed.
420 removeIface(IfaceType::P2P, p2p_iface_name);
421 ASSERT_FALSE(createIface(IfaceType::NAN).empty());
422 }
423
TEST_F(WifiChipV1_AwareIfaceCombinationTest,StaMode_CreateStaP2p_AfterNanRemove_ShouldSucceed)424 TEST_F(WifiChipV1_AwareIfaceCombinationTest,
425 StaMode_CreateStaP2p_AfterNanRemove_ShouldSucceed) {
426 findModeAndConfigureForIfaceType(IfaceType::STA);
427 ASSERT_FALSE(createIface(IfaceType::STA).empty());
428 const auto nan_iface_name = createIface(IfaceType::NAN);
429 ASSERT_FALSE(nan_iface_name.empty());
430 ASSERT_TRUE(createIface(IfaceType::P2P).empty());
431
432 // After removing NAN iface, P2P iface creation should succeed.
433 removeIface(IfaceType::NAN, nan_iface_name);
434 ASSERT_FALSE(createIface(IfaceType::P2P).empty());
435 }
436
TEST_F(WifiChipV1_AwareIfaceCombinationTest,ApMode_CreateAp_ShouldSucceed)437 TEST_F(WifiChipV1_AwareIfaceCombinationTest, ApMode_CreateAp_ShouldSucceed) {
438 findModeAndConfigureForIfaceType(IfaceType::AP);
439 ASSERT_EQ(createIface(IfaceType::AP), "wlan0");
440 }
441
TEST_F(WifiChipV1_AwareIfaceCombinationTest,ApMode_CreateSta_ShouldFail)442 TEST_F(WifiChipV1_AwareIfaceCombinationTest, ApMode_CreateSta_ShouldFail) {
443 findModeAndConfigureForIfaceType(IfaceType::AP);
444 ASSERT_TRUE(createIface(IfaceType::STA).empty());
445 }
446
TEST_F(WifiChipV1_AwareIfaceCombinationTest,ApMode_CreateP2p_ShouldFail)447 TEST_F(WifiChipV1_AwareIfaceCombinationTest, ApMode_CreateP2p_ShouldFail) {
448 findModeAndConfigureForIfaceType(IfaceType::AP);
449 ASSERT_TRUE(createIface(IfaceType::STA).empty());
450 }
451
TEST_F(WifiChipV1_AwareIfaceCombinationTest,ApMode_CreateNan_ShouldFail)452 TEST_F(WifiChipV1_AwareIfaceCombinationTest, ApMode_CreateNan_ShouldFail) {
453 findModeAndConfigureForIfaceType(IfaceType::AP);
454 ASSERT_TRUE(createIface(IfaceType::NAN).empty());
455 }
456
TEST_F(WifiChipV1_AwareIfaceCombinationTest,RttControllerFlowStaModeNoSta)457 TEST_F(WifiChipV1_AwareIfaceCombinationTest, RttControllerFlowStaModeNoSta) {
458 findModeAndConfigureForIfaceType(IfaceType::STA);
459 ASSERT_TRUE(createRttController());
460 }
461
TEST_F(WifiChipV1_AwareIfaceCombinationTest,RttControllerFlowStaModeWithSta)462 TEST_F(WifiChipV1_AwareIfaceCombinationTest, RttControllerFlowStaModeWithSta) {
463 findModeAndConfigureForIfaceType(IfaceType::STA);
464 ASSERT_FALSE(createIface(IfaceType::STA).empty());
465 ASSERT_TRUE(createRttController());
466 }
467
TEST_F(WifiChipV1_AwareIfaceCombinationTest,RttControllerFlowApToSta)468 TEST_F(WifiChipV1_AwareIfaceCombinationTest, RttControllerFlowApToSta) {
469 findModeAndConfigureForIfaceType(IfaceType::AP);
470 const auto ap_iface_name = createIface(IfaceType::AP);
471 ASSERT_FALSE(ap_iface_name.empty());
472 ASSERT_FALSE(createRttController());
473
474 removeIface(IfaceType::AP, ap_iface_name);
475
476 findModeAndConfigureForIfaceType(IfaceType::STA);
477 ASSERT_TRUE(createRttController());
478 }
479
TEST_F(WifiChipV1_AwareIfaceCombinationTest,SelectTxScenarioWithOnlySta)480 TEST_F(WifiChipV1_AwareIfaceCombinationTest, SelectTxScenarioWithOnlySta) {
481 findModeAndConfigureForIfaceType(IfaceType::STA);
482 ASSERT_EQ(createIface(IfaceType::STA), "wlan0");
483 EXPECT_CALL(*legacy_hal_, selectTxPowerScenario("wlan0", testing::_))
484 .WillOnce(testing::Return(legacy_hal::WIFI_SUCCESS));
485 chip_->selectTxPowerScenario_1_2(
486 V1_2::IWifiChip::TxPowerScenario::ON_HEAD_CELL_OFF,
487 [](const WifiStatus& status) {
488 ASSERT_EQ(WifiStatusCode::SUCCESS, status.code);
489 });
490 }
491
TEST_F(WifiChipV1_AwareIfaceCombinationTest,SelectTxScenarioWithOnlyAp)492 TEST_F(WifiChipV1_AwareIfaceCombinationTest, SelectTxScenarioWithOnlyAp) {
493 findModeAndConfigureForIfaceType(IfaceType::AP);
494 ASSERT_EQ(createIface(IfaceType::AP), "wlan0");
495 EXPECT_CALL(*legacy_hal_, selectTxPowerScenario("wlan0", testing::_))
496 .WillOnce(testing::Return(legacy_hal::WIFI_SUCCESS));
497 chip_->selectTxPowerScenario_1_2(
498 V1_2::IWifiChip::TxPowerScenario::ON_HEAD_CELL_OFF,
499 [](const WifiStatus& status) {
500 ASSERT_EQ(WifiStatusCode::SUCCESS, status.code);
501 });
502 }
503
504 ////////// V2 + Aware Iface Combinations ////////////
505 // Mode 1 - STA + STA/AP
506 // - STA + P2P/NAN
507 class WifiChipV2_AwareIfaceCombinationTest : public WifiChipTest {
508 public:
SetUp()509 void SetUp() override {
510 setupV2_AwareIfaceCombination();
511 WifiChipTest::SetUp();
512 // V2_Aware has 1 mode of operation.
513 assertNumberOfModes(1u);
514 }
515 };
516
TEST_F(WifiChipV2_AwareIfaceCombinationTest,CreateSta_ShouldSucceed)517 TEST_F(WifiChipV2_AwareIfaceCombinationTest, CreateSta_ShouldSucceed) {
518 findModeAndConfigureForIfaceType(IfaceType::STA);
519 ASSERT_EQ(createIface(IfaceType::STA), "wlan0");
520 }
521
TEST_F(WifiChipV2_AwareIfaceCombinationTest,CreateP2p_ShouldSucceed)522 TEST_F(WifiChipV2_AwareIfaceCombinationTest, CreateP2p_ShouldSucceed) {
523 findModeAndConfigureForIfaceType(IfaceType::STA);
524 ASSERT_FALSE(createIface(IfaceType::P2P).empty());
525 }
526
TEST_F(WifiChipV2_AwareIfaceCombinationTest,CreateNan_ShouldSucceed)527 TEST_F(WifiChipV2_AwareIfaceCombinationTest, CreateNan_ShouldSucceed) {
528 findModeAndConfigureForIfaceType(IfaceType::STA);
529 ASSERT_FALSE(createIface(IfaceType::NAN).empty());
530 }
531
TEST_F(WifiChipV2_AwareIfaceCombinationTest,CreateAp_ShouldSucceed)532 TEST_F(WifiChipV2_AwareIfaceCombinationTest, CreateAp_ShouldSucceed) {
533 findModeAndConfigureForIfaceType(IfaceType::STA);
534 ASSERT_EQ(createIface(IfaceType::AP), "wlan1");
535 }
536
TEST_F(WifiChipV2_AwareIfaceCombinationTest,CreateStaSta_ShouldFail)537 TEST_F(WifiChipV2_AwareIfaceCombinationTest, CreateStaSta_ShouldFail) {
538 findModeAndConfigureForIfaceType(IfaceType::AP);
539 ASSERT_EQ(createIface(IfaceType::STA), "wlan0");
540 ASSERT_TRUE(createIface(IfaceType::STA).empty());
541 }
542
TEST_F(WifiChipV2_AwareIfaceCombinationTest,CreateStaAp_ShouldSucceed)543 TEST_F(WifiChipV2_AwareIfaceCombinationTest, CreateStaAp_ShouldSucceed) {
544 findModeAndConfigureForIfaceType(IfaceType::AP);
545 ASSERT_EQ(createIface(IfaceType::STA), "wlan0");
546 ASSERT_EQ(createIface(IfaceType::AP), "wlan1");
547 }
548
TEST_F(WifiChipV2_AwareIfaceCombinationTest,CreateApSta_ShouldSucceed)549 TEST_F(WifiChipV2_AwareIfaceCombinationTest, CreateApSta_ShouldSucceed) {
550 findModeAndConfigureForIfaceType(IfaceType::AP);
551 ASSERT_EQ(createIface(IfaceType::AP), "wlan1");
552 ASSERT_EQ(createIface(IfaceType::STA), "wlan0");
553 }
554
TEST_F(WifiChipV2_AwareIfaceCombinationTest,CreateSta_AfterStaApRemove_ShouldSucceed)555 TEST_F(WifiChipV2_AwareIfaceCombinationTest,
556 CreateSta_AfterStaApRemove_ShouldSucceed) {
557 findModeAndConfigureForIfaceType(IfaceType::STA);
558 const auto sta_iface_name = createIface(IfaceType::STA);
559 ASSERT_FALSE(sta_iface_name.empty());
560 const auto ap_iface_name = createIface(IfaceType::AP);
561 ASSERT_FALSE(ap_iface_name.empty());
562
563 ASSERT_TRUE(createIface(IfaceType::STA).empty());
564
565 // After removing AP & STA iface, STA iface creation should succeed.
566 removeIface(IfaceType::STA, sta_iface_name);
567 removeIface(IfaceType::AP, ap_iface_name);
568 ASSERT_FALSE(createIface(IfaceType::STA).empty());
569 }
570
TEST_F(WifiChipV2_AwareIfaceCombinationTest,CreateStaP2p_ShouldSucceed)571 TEST_F(WifiChipV2_AwareIfaceCombinationTest, CreateStaP2p_ShouldSucceed) {
572 findModeAndConfigureForIfaceType(IfaceType::STA);
573 ASSERT_FALSE(createIface(IfaceType::STA).empty());
574 ASSERT_FALSE(createIface(IfaceType::P2P).empty());
575 }
576
TEST_F(WifiChipV2_AwareIfaceCombinationTest,CreateStaNan_ShouldSucceed)577 TEST_F(WifiChipV2_AwareIfaceCombinationTest, CreateStaNan_ShouldSucceed) {
578 findModeAndConfigureForIfaceType(IfaceType::STA);
579 ASSERT_FALSE(createIface(IfaceType::STA).empty());
580 ASSERT_FALSE(createIface(IfaceType::NAN).empty());
581 }
582
TEST_F(WifiChipV2_AwareIfaceCombinationTest,CreateStaP2PNan_ShouldFail)583 TEST_F(WifiChipV2_AwareIfaceCombinationTest, CreateStaP2PNan_ShouldFail) {
584 findModeAndConfigureForIfaceType(IfaceType::STA);
585 ASSERT_FALSE(createIface(IfaceType::STA).empty());
586 ASSERT_FALSE(createIface(IfaceType::P2P).empty());
587 ASSERT_TRUE(createIface(IfaceType::NAN).empty());
588 }
589
TEST_F(WifiChipV2_AwareIfaceCombinationTest,CreateStaNan_AfterP2pRemove_ShouldSucceed)590 TEST_F(WifiChipV2_AwareIfaceCombinationTest,
591 CreateStaNan_AfterP2pRemove_ShouldSucceed) {
592 findModeAndConfigureForIfaceType(IfaceType::STA);
593 ASSERT_FALSE(createIface(IfaceType::STA).empty());
594 const auto p2p_iface_name = createIface(IfaceType::P2P);
595 ASSERT_FALSE(p2p_iface_name.empty());
596 ASSERT_TRUE(createIface(IfaceType::NAN).empty());
597
598 // After removing P2P iface, NAN iface creation should succeed.
599 removeIface(IfaceType::P2P, p2p_iface_name);
600 ASSERT_FALSE(createIface(IfaceType::NAN).empty());
601 }
602
TEST_F(WifiChipV2_AwareIfaceCombinationTest,CreateStaP2p_AfterNanRemove_ShouldSucceed)603 TEST_F(WifiChipV2_AwareIfaceCombinationTest,
604 CreateStaP2p_AfterNanRemove_ShouldSucceed) {
605 findModeAndConfigureForIfaceType(IfaceType::STA);
606 ASSERT_FALSE(createIface(IfaceType::STA).empty());
607 const auto nan_iface_name = createIface(IfaceType::NAN);
608 ASSERT_FALSE(nan_iface_name.empty());
609 ASSERT_TRUE(createIface(IfaceType::P2P).empty());
610
611 // After removing NAN iface, P2P iface creation should succeed.
612 removeIface(IfaceType::NAN, nan_iface_name);
613 ASSERT_FALSE(createIface(IfaceType::P2P).empty());
614 }
615
TEST_F(WifiChipV2_AwareIfaceCombinationTest,CreateApNan_ShouldFail)616 TEST_F(WifiChipV2_AwareIfaceCombinationTest, CreateApNan_ShouldFail) {
617 findModeAndConfigureForIfaceType(IfaceType::AP);
618 ASSERT_FALSE(createIface(IfaceType::AP).empty());
619 ASSERT_TRUE(createIface(IfaceType::NAN).empty());
620 }
621
TEST_F(WifiChipV2_AwareIfaceCombinationTest,CreateApP2p_ShouldFail)622 TEST_F(WifiChipV2_AwareIfaceCombinationTest, CreateApP2p_ShouldFail) {
623 findModeAndConfigureForIfaceType(IfaceType::AP);
624 ASSERT_FALSE(createIface(IfaceType::AP).empty());
625 ASSERT_TRUE(createIface(IfaceType::P2P).empty());
626 }
627
TEST_F(WifiChipV2_AwareIfaceCombinationTest,StaMode_CreateStaNan_AfterP2pRemove_ShouldSucceed)628 TEST_F(WifiChipV2_AwareIfaceCombinationTest,
629 StaMode_CreateStaNan_AfterP2pRemove_ShouldSucceed) {
630 findModeAndConfigureForIfaceType(IfaceType::STA);
631 ASSERT_FALSE(createIface(IfaceType::STA).empty());
632 const auto p2p_iface_name = createIface(IfaceType::P2P);
633 ASSERT_FALSE(p2p_iface_name.empty());
634 ASSERT_TRUE(createIface(IfaceType::NAN).empty());
635
636 // After removing P2P iface, NAN iface creation should succeed.
637 removeIface(IfaceType::P2P, p2p_iface_name);
638 ASSERT_FALSE(createIface(IfaceType::NAN).empty());
639 }
640
TEST_F(WifiChipV2_AwareIfaceCombinationTest,StaMode_CreateStaP2p_AfterNanRemove_ShouldSucceed)641 TEST_F(WifiChipV2_AwareIfaceCombinationTest,
642 StaMode_CreateStaP2p_AfterNanRemove_ShouldSucceed) {
643 findModeAndConfigureForIfaceType(IfaceType::STA);
644 ASSERT_FALSE(createIface(IfaceType::STA).empty());
645 const auto nan_iface_name = createIface(IfaceType::NAN);
646 ASSERT_FALSE(nan_iface_name.empty());
647 ASSERT_TRUE(createIface(IfaceType::P2P).empty());
648
649 // After removing NAN iface, P2P iface creation should succeed.
650 removeIface(IfaceType::NAN, nan_iface_name);
651 ASSERT_FALSE(createIface(IfaceType::P2P).empty());
652 }
653
TEST_F(WifiChipV2_AwareIfaceCombinationTest,CreateStaAp_EnsureDifferentIfaceNames)654 TEST_F(WifiChipV2_AwareIfaceCombinationTest,
655 CreateStaAp_EnsureDifferentIfaceNames) {
656 findModeAndConfigureForIfaceType(IfaceType::AP);
657 const auto sta_iface_name = createIface(IfaceType::STA);
658 const auto ap_iface_name = createIface(IfaceType::AP);
659 ASSERT_FALSE(sta_iface_name.empty());
660 ASSERT_FALSE(ap_iface_name.empty());
661 ASSERT_NE(sta_iface_name, ap_iface_name);
662 }
663
TEST_F(WifiChipV2_AwareIfaceCombinationTest,RttControllerFlowStaModeNoSta)664 TEST_F(WifiChipV2_AwareIfaceCombinationTest, RttControllerFlowStaModeNoSta) {
665 findModeAndConfigureForIfaceType(IfaceType::STA);
666 ASSERT_TRUE(createRttController());
667 }
668
TEST_F(WifiChipV2_AwareIfaceCombinationTest,RttControllerFlowStaModeWithSta)669 TEST_F(WifiChipV2_AwareIfaceCombinationTest, RttControllerFlowStaModeWithSta) {
670 findModeAndConfigureForIfaceType(IfaceType::STA);
671 ASSERT_FALSE(createIface(IfaceType::STA).empty());
672 ASSERT_TRUE(createRttController());
673 }
674
TEST_F(WifiChipV2_AwareIfaceCombinationTest,RttControllerFlow)675 TEST_F(WifiChipV2_AwareIfaceCombinationTest, RttControllerFlow) {
676 findModeAndConfigureForIfaceType(IfaceType::STA);
677 ASSERT_FALSE(createIface(IfaceType::STA).empty());
678 ASSERT_FALSE(createIface(IfaceType::AP).empty());
679 ASSERT_TRUE(createRttController());
680 }
681
TEST_F(WifiChipV2_AwareIfaceCombinationTest,SelectTxScenarioWithOnlySta)682 TEST_F(WifiChipV2_AwareIfaceCombinationTest, SelectTxScenarioWithOnlySta) {
683 findModeAndConfigureForIfaceType(IfaceType::STA);
684 ASSERT_EQ(createIface(IfaceType::STA), "wlan0");
685 EXPECT_CALL(*legacy_hal_, selectTxPowerScenario("wlan0", testing::_))
686 .WillOnce(testing::Return(legacy_hal::WIFI_SUCCESS));
687 chip_->selectTxPowerScenario_1_2(
688 V1_2::IWifiChip::TxPowerScenario::ON_HEAD_CELL_OFF,
689 [](const WifiStatus& status) {
690 ASSERT_EQ(WifiStatusCode::SUCCESS, status.code);
691 });
692 }
693
TEST_F(WifiChipV2_AwareIfaceCombinationTest,SelectTxScenarioWithOnlyAp)694 TEST_F(WifiChipV2_AwareIfaceCombinationTest, SelectTxScenarioWithOnlyAp) {
695 findModeAndConfigureForIfaceType(IfaceType::AP);
696 ASSERT_EQ(createIface(IfaceType::AP), "wlan1");
697 EXPECT_CALL(*legacy_hal_, selectTxPowerScenario("wlan1", testing::_))
698 .WillOnce(testing::Return(legacy_hal::WIFI_SUCCESS));
699 chip_->selectTxPowerScenario_1_2(
700 V1_2::IWifiChip::TxPowerScenario::ON_HEAD_CELL_OFF,
701 [](const WifiStatus& status) {
702 ASSERT_EQ(WifiStatusCode::SUCCESS, status.code);
703 });
704 }
705
TEST_F(WifiChipV2_AwareIfaceCombinationTest,InvalidateAndRemoveNanOnStaRemove)706 TEST_F(WifiChipV2_AwareIfaceCombinationTest,
707 InvalidateAndRemoveNanOnStaRemove) {
708 findModeAndConfigureForIfaceType(IfaceType::STA);
709 ASSERT_EQ(createIface(IfaceType::STA), "wlan0");
710
711 // Create NAN iface
712 ASSERT_EQ(createIface(IfaceType::NAN), "wlan0");
713
714 // We should have 1 nan iface.
715 chip_->getNanIfaceNames(
716 [](const WifiStatus& status, const hidl_vec<hidl_string>& iface_names) {
717 ASSERT_EQ(WifiStatusCode::SUCCESS, status.code);
718 ASSERT_EQ(iface_names.size(), 1u);
719 ASSERT_EQ(iface_names[0], "wlan0");
720 });
721 // Retrieve the exact iface object.
722 sp<IWifiNanIface> nan_iface;
723 chip_->getNanIface("wlan0", [&nan_iface](const WifiStatus& status,
724 const sp<IWifiNanIface>& iface) {
725 ASSERT_EQ(WifiStatusCode::SUCCESS, status.code);
726 ASSERT_NE(iface.get(), nullptr);
727 nan_iface = iface;
728 });
729
730 // Remove the STA iface.
731 removeIface(IfaceType::STA, "wlan0");
732 // We should have 0 nan iface now.
733 chip_->getNanIfaceNames(
734 [](const WifiStatus& status, const hidl_vec<hidl_string>& iface_names) {
735 ASSERT_EQ(WifiStatusCode::SUCCESS, status.code);
736 ASSERT_EQ(iface_names.size(), 0u);
737 });
738 // Any operation on the nan iface object should return error now.
739 nan_iface->getName(
740 [](const WifiStatus& status, const std::string& /* iface_name */) {
741 ASSERT_EQ(WifiStatusCode::ERROR_WIFI_IFACE_INVALID, status.code);
742 });
743 }
744
TEST_F(WifiChipV2_AwareIfaceCombinationTest,InvalidateAndRemoveRttControllerOnStaRemove)745 TEST_F(WifiChipV2_AwareIfaceCombinationTest,
746 InvalidateAndRemoveRttControllerOnStaRemove) {
747 findModeAndConfigureForIfaceType(IfaceType::STA);
748 ASSERT_EQ(createIface(IfaceType::STA), "wlan0");
749
750 // Create RTT controller
751 sp<IWifiRttController> rtt_controller;
752 chip_->createRttController(
753 NULL, [&rtt_controller](const WifiStatus& status,
754 const sp<IWifiRttController>& rtt) {
755 if (WifiStatusCode::SUCCESS == status.code) {
756 ASSERT_NE(rtt.get(), nullptr);
757 rtt_controller = rtt;
758 }
759 });
760
761 // Remove the STA iface.
762 removeIface(IfaceType::STA, "wlan0");
763
764 // Any operation on the rtt controller object should return error now.
765 rtt_controller->getBoundIface(
766 [](const WifiStatus& status, const sp<IWifiIface>& /* iface */) {
767 ASSERT_EQ(WifiStatusCode::ERROR_WIFI_RTT_CONTROLLER_INVALID,
768 status.code);
769 });
770 }
771
772 ////////// V1 Iface Combinations when AP creation is disabled //////////
773 class WifiChipV1_AwareDisabledApIfaceCombinationTest : public WifiChipTest {
774 public:
SetUp()775 void SetUp() override {
776 setupV1_AwareDisabledApIfaceCombination();
777 WifiChipTest::SetUp();
778 }
779 };
780
TEST_F(WifiChipV1_AwareDisabledApIfaceCombinationTest,StaMode_CreateSta_ShouldSucceed)781 TEST_F(WifiChipV1_AwareDisabledApIfaceCombinationTest,
782 StaMode_CreateSta_ShouldSucceed) {
783 findModeAndConfigureForIfaceType(IfaceType::STA);
784 ASSERT_FALSE(createIface(IfaceType::STA).empty());
785 ASSERT_TRUE(createIface(IfaceType::AP).empty());
786 }
787
788 ////////// V2 Iface Combinations when AP creation is disabled //////////
789 class WifiChipV2_AwareDisabledApIfaceCombinationTest : public WifiChipTest {
790 public:
SetUp()791 void SetUp() override {
792 setupV2_AwareDisabledApIfaceCombination();
793 WifiChipTest::SetUp();
794 }
795 };
796
TEST_F(WifiChipV2_AwareDisabledApIfaceCombinationTest,CreateSta_ShouldSucceed)797 TEST_F(WifiChipV2_AwareDisabledApIfaceCombinationTest,
798 CreateSta_ShouldSucceed) {
799 findModeAndConfigureForIfaceType(IfaceType::STA);
800 ASSERT_FALSE(createIface(IfaceType::STA).empty());
801 ASSERT_TRUE(createIface(IfaceType::AP).empty());
802 }
803
804 ////////// Hypothetical Iface Combination with multiple ifaces //////////
805 class WifiChip_MultiIfaceTest : public WifiChipTest {
806 public:
SetUp()807 void SetUp() override {
808 setup_MultiIfaceCombination();
809 WifiChipTest::SetUp();
810 }
811 };
812
TEST_F(WifiChip_MultiIfaceTest,Create3Sta)813 TEST_F(WifiChip_MultiIfaceTest, Create3Sta) {
814 findModeAndConfigureForIfaceType(IfaceType::STA);
815 ASSERT_FALSE(createIface(IfaceType::STA).empty());
816 ASSERT_FALSE(createIface(IfaceType::STA).empty());
817 ASSERT_FALSE(createIface(IfaceType::STA).empty());
818 ASSERT_TRUE(createIface(IfaceType::STA).empty());
819 }
820
TEST_F(WifiChip_MultiIfaceTest,CreateStaWithDefaultNames)821 TEST_F(WifiChip_MultiIfaceTest, CreateStaWithDefaultNames) {
822 property_set("wifi.interface.0", "");
823 property_set("wifi.interface.1", "");
824 property_set("wifi.interface.2", "");
825 property_set("wifi.interface", "");
826 property_set("wifi.concurrent.interface", "");
827 findModeAndConfigureForIfaceType(IfaceType::STA);
828 ASSERT_EQ(createIface(IfaceType::STA), "wlan0");
829 ASSERT_EQ(createIface(IfaceType::STA), "wlan1");
830 ASSERT_EQ(createIface(IfaceType::STA), "wlan2");
831 }
832
TEST_F(WifiChip_MultiIfaceTest,CreateStaWithCustomNames)833 TEST_F(WifiChip_MultiIfaceTest, CreateStaWithCustomNames) {
834 property_set("wifi.interface.0", "test0");
835 property_set("wifi.interface.1", "test1");
836 property_set("wifi.interface.2", "test2");
837 property_set("wifi.interface", "bad0");
838 property_set("wifi.concurrent.interface", "bad1");
839 findModeAndConfigureForIfaceType(IfaceType::STA);
840 ASSERT_EQ(createIface(IfaceType::STA), "bad0");
841 ASSERT_EQ(createIface(IfaceType::STA), "bad1");
842 ASSERT_EQ(createIface(IfaceType::STA), "test2");
843 }
844
TEST_F(WifiChip_MultiIfaceTest,CreateStaWithCustomAltNames)845 TEST_F(WifiChip_MultiIfaceTest, CreateStaWithCustomAltNames) {
846 property_set("wifi.interface.0", "");
847 property_set("wifi.interface.1", "");
848 property_set("wifi.interface.2", "");
849 property_set("wifi.interface", "testA0");
850 property_set("wifi.concurrent.interface", "testA1");
851 findModeAndConfigureForIfaceType(IfaceType::STA);
852 ASSERT_EQ(createIface(IfaceType::STA), "testA0");
853 ASSERT_EQ(createIface(IfaceType::STA), "testA1");
854 ASSERT_EQ(createIface(IfaceType::STA), "wlan2");
855 }
856
TEST_F(WifiChip_MultiIfaceTest,CreateApStartsWithIdx1)857 TEST_F(WifiChip_MultiIfaceTest, CreateApStartsWithIdx1) {
858 findModeAndConfigureForIfaceType(IfaceType::STA);
859 // First AP will be slotted to wlan1.
860 ASSERT_EQ(createIface(IfaceType::AP), "wlan1");
861 // First STA will be slotted to wlan0.
862 ASSERT_EQ(createIface(IfaceType::STA), "wlan0");
863 // All further STA will be slotted to the remaining free indices.
864 ASSERT_EQ(createIface(IfaceType::STA), "wlan2");
865 ASSERT_EQ(createIface(IfaceType::STA), "wlan3");
866 }
867 } // namespace implementation
868 } // namespace V1_3
869 } // namespace wifi
870 } // namespace hardware
871 } // namespace android
872