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 <numeric>
18 #include <vector>
19
20 #include <VtsCoreUtil.h>
21 #include <aidl/Gtest.h>
22 #include <aidl/Vintf.h>
23 #include <aidl/android/hardware/wifi/BnWifi.h>
24 #include <aidl/android/hardware/wifi/BnWifiChipEventCallback.h>
25 #include <aidl/android/hardware/wifi/WifiIfaceMode.h>
26 #include <android/binder_manager.h>
27 #include <android/binder_status.h>
28 #include <binder/IServiceManager.h>
29 #include <binder/ProcessState.h>
30
31 #include "wifi_aidl_test_utils.h"
32
33 using aidl::android::hardware::wifi::BnWifiChipEventCallback;
34 using aidl::android::hardware::wifi::IfaceType;
35 using aidl::android::hardware::wifi::IWifiApIface;
36 using aidl::android::hardware::wifi::IWifiChip;
37 using aidl::android::hardware::wifi::IWifiNanIface;
38 using aidl::android::hardware::wifi::IWifiP2pIface;
39 using aidl::android::hardware::wifi::IWifiRttController;
40 using aidl::android::hardware::wifi::WifiBand;
41 using aidl::android::hardware::wifi::WifiDebugHostWakeReasonStats;
42 using aidl::android::hardware::wifi::WifiDebugRingBufferStatus;
43 using aidl::android::hardware::wifi::WifiDebugRingBufferVerboseLevel;
44 using aidl::android::hardware::wifi::WifiIfaceMode;
45 using aidl::android::hardware::wifi::WifiRadioCombination;
46 using aidl::android::hardware::wifi::WifiStatusCode;
47 using aidl::android::hardware::wifi::WifiUsableChannel;
48
49 class WifiChipAidlTest : public testing::TestWithParam<std::string> {
50 public:
SetUp()51 void SetUp() override {
52 stopWifiService(getInstanceName());
53 wifi_chip_ = getWifiChip(getInstanceName());
54 ASSERT_NE(nullptr, wifi_chip_.get());
55 }
56
TearDown()57 void TearDown() override { stopWifiService(getInstanceName()); }
58
59 protected:
configureChipForConcurrencyType(IfaceConcurrencyType type)60 int configureChipForConcurrencyType(IfaceConcurrencyType type) {
61 int mode_id;
62 EXPECT_TRUE(configureChipToSupportConcurrencyType(wifi_chip_, type, &mode_id));
63 return mode_id;
64 }
65
isConcurrencyTypeSupported(IfaceConcurrencyType type)66 bool isConcurrencyTypeSupported(IfaceConcurrencyType type) {
67 return doesChipSupportConcurrencyType(wifi_chip_, type);
68 }
69
configureChipForStaAndGetIface()70 std::shared_ptr<IWifiStaIface> configureChipForStaAndGetIface() {
71 std::shared_ptr<IWifiStaIface> iface;
72 configureChipForConcurrencyType(IfaceConcurrencyType::STA);
73 EXPECT_TRUE(wifi_chip_->createStaIface(&iface).isOk());
74 EXPECT_NE(nullptr, iface.get());
75 return iface;
76 }
77
configureChipForP2pAndGetIface()78 std::shared_ptr<IWifiP2pIface> configureChipForP2pAndGetIface() {
79 std::shared_ptr<IWifiP2pIface> iface;
80 configureChipForConcurrencyType(IfaceConcurrencyType::P2P);
81 EXPECT_TRUE(wifi_chip_->createP2pIface(&iface).isOk());
82 EXPECT_NE(nullptr, iface.get());
83 return iface;
84 }
85
configureChipForApAndGetIface()86 std::shared_ptr<IWifiApIface> configureChipForApAndGetIface() {
87 std::shared_ptr<IWifiApIface> iface;
88 configureChipForConcurrencyType(IfaceConcurrencyType::AP);
89 EXPECT_TRUE(wifi_chip_->createApIface(&iface).isOk());
90 EXPECT_NE(nullptr, iface.get());
91 return iface;
92 }
93
configureChipForNanAndGetIface()94 std::shared_ptr<IWifiNanIface> configureChipForNanAndGetIface() {
95 std::shared_ptr<IWifiNanIface> iface;
96 configureChipForConcurrencyType(IfaceConcurrencyType::NAN_IFACE);
97 EXPECT_TRUE(wifi_chip_->createNanIface(&iface).isOk());
98 EXPECT_NE(nullptr, iface.get());
99 return iface;
100 }
101
getStaIfaceName(const std::shared_ptr<IWifiStaIface> & iface)102 std::string getStaIfaceName(const std::shared_ptr<IWifiStaIface>& iface) {
103 std::string iface_name;
104 EXPECT_TRUE(iface->getName(&iface_name).isOk());
105 return iface_name;
106 }
107
getP2pIfaceName(const std::shared_ptr<IWifiP2pIface> & iface)108 std::string getP2pIfaceName(const std::shared_ptr<IWifiP2pIface>& iface) {
109 std::string iface_name;
110 EXPECT_TRUE(iface->getName(&iface_name).isOk());
111 return iface_name;
112 }
113
getApIfaceName(const std::shared_ptr<IWifiApIface> & iface)114 std::string getApIfaceName(const std::shared_ptr<IWifiApIface>& iface) {
115 std::string iface_name;
116 EXPECT_TRUE(iface->getName(&iface_name).isOk());
117 return iface_name;
118 }
119
getNanIfaceName(const std::shared_ptr<IWifiNanIface> & iface)120 std::string getNanIfaceName(const std::shared_ptr<IWifiNanIface>& iface) {
121 std::string iface_name;
122 EXPECT_TRUE(iface->getName(&iface_name).isOk());
123 return iface_name;
124 }
125
create2StaIfacesIfPossible()126 std::vector<std::shared_ptr<IWifiStaIface>> create2StaIfacesIfPossible() {
127 std::shared_ptr<IWifiStaIface> iface1 = configureChipForStaAndGetIface();
128
129 // Try create a create second iface.
130 std::shared_ptr<IWifiStaIface> iface2;
131 bool add_second_success = wifi_chip_->createStaIface(&iface2).isOk();
132 if (!add_second_success) {
133 return {iface1};
134 }
135 EXPECT_NE(nullptr, iface2.get());
136 return {iface1, iface2};
137 }
138
getInstanceName()139 const char* getInstanceName() { return GetParam().c_str(); }
140
141 std::shared_ptr<IWifiChip> wifi_chip_;
142 };
143
144 class WifiChipEventCallback : public BnWifiChipEventCallback {
145 public:
146 WifiChipEventCallback() = default;
147
onChipReconfigureFailure(WifiStatusCode)148 ::ndk::ScopedAStatus onChipReconfigureFailure(WifiStatusCode /* status */) override {
149 return ndk::ScopedAStatus::ok();
150 }
onChipReconfigured(int)151 ::ndk::ScopedAStatus onChipReconfigured(int /* modeId */) override {
152 return ndk::ScopedAStatus::ok();
153 }
onDebugErrorAlert(int,const std::vector<uint8_t> &)154 ::ndk::ScopedAStatus onDebugErrorAlert(int /* errorCode */,
155 const std::vector<uint8_t>& /* debugData */) override {
156 return ndk::ScopedAStatus::ok();
157 }
onDebugRingBufferDataAvailable(const WifiDebugRingBufferStatus &,const std::vector<uint8_t> &)158 ::ndk::ScopedAStatus onDebugRingBufferDataAvailable(
159 const WifiDebugRingBufferStatus& /* status */,
160 const std::vector<uint8_t>& /* data */) override {
161 return ndk::ScopedAStatus::ok();
162 }
onIfaceAdded(IfaceType,const std::string &)163 ::ndk::ScopedAStatus onIfaceAdded(IfaceType /* type */,
164 const std::string& /* name */) override {
165 return ndk::ScopedAStatus::ok();
166 }
onIfaceRemoved(IfaceType,const std::string &)167 ::ndk::ScopedAStatus onIfaceRemoved(IfaceType /* type */,
168 const std::string& /* name */) override {
169 return ndk::ScopedAStatus::ok();
170 }
onRadioModeChange(const std::vector<RadioModeInfo> &)171 ::ndk::ScopedAStatus onRadioModeChange(
172 const std::vector<RadioModeInfo>& /* radioModeInfos */) override {
173 return ndk::ScopedAStatus::ok();
174 }
175 };
176
177 /*
178 * RegisterEventCallback
179 *
180 * Note: it is not feasible to test the invocation of the callback function,
181 * since events are triggered internally in the HAL implementation and cannot be
182 * triggered from the test case.
183 */
TEST_P(WifiChipAidlTest,RegisterEventCallback)184 TEST_P(WifiChipAidlTest, RegisterEventCallback) {
185 std::shared_ptr<WifiChipEventCallback> callback =
186 ndk::SharedRefBase::make<WifiChipEventCallback>();
187 ASSERT_NE(nullptr, callback.get());
188 EXPECT_TRUE(wifi_chip_->registerEventCallback(callback).isOk());
189 }
190
191 /*
192 * GetFeatureSet
193 */
TEST_P(WifiChipAidlTest,GetFeatureSet)194 TEST_P(WifiChipAidlTest, GetFeatureSet) {
195 configureChipForConcurrencyType(IfaceConcurrencyType::STA);
196 int32_t features;
197 EXPECT_TRUE(wifi_chip_->getFeatureSet(&features).isOk());
198 }
199
200 /*
201 * GetId
202 */
TEST_P(WifiChipAidlTest,GetId)203 TEST_P(WifiChipAidlTest, GetId) {
204 int id;
205 EXPECT_TRUE(wifi_chip_->getId(&id).isOk());
206 }
207
208 /*
209 * GetAvailableModes
210 */
TEST_P(WifiChipAidlTest,GetAvailableModes)211 TEST_P(WifiChipAidlTest, GetAvailableModes) {
212 std::vector<IWifiChip::ChipMode> modes;
213 EXPECT_TRUE(wifi_chip_->getAvailableModes(&modes).isOk());
214 EXPECT_NE(modes.size(), 0);
215 }
216
217 /*
218 * GetMode
219 */
TEST_P(WifiChipAidlTest,GetMode)220 TEST_P(WifiChipAidlTest, GetMode) {
221 int expected_mode = configureChipForConcurrencyType(IfaceConcurrencyType::STA);
222 int retrieved_mode;
223 EXPECT_TRUE(wifi_chip_->getMode(&retrieved_mode).isOk());
224 EXPECT_EQ(retrieved_mode, expected_mode);
225 }
226
227 /*
228 * GetUsableChannels
229 */
TEST_P(WifiChipAidlTest,GetUsableChannels)230 TEST_P(WifiChipAidlTest, GetUsableChannels) {
231 WifiBand band = WifiBand::BAND_24GHZ_5GHZ_6GHZ;
232 uint32_t ifaceModeMask = static_cast<uint32_t>(WifiIfaceMode::IFACE_MODE_P2P_CLIENT) |
233 static_cast<uint32_t>(WifiIfaceMode::IFACE_MODE_P2P_GO);
234 uint32_t filterMask =
235 static_cast<uint32_t>(IWifiChip::UsableChannelFilter::CELLULAR_COEXISTENCE) |
236 static_cast<uint32_t>(IWifiChip::UsableChannelFilter::CONCURRENCY);
237
238 std::vector<WifiUsableChannel> channels;
239 configureChipForConcurrencyType(IfaceConcurrencyType::STA);
240 auto status = wifi_chip_->getUsableChannels(band, ifaceModeMask, filterMask, &channels);
241 if (checkStatusCode(&status, WifiStatusCode::ERROR_NOT_SUPPORTED)) {
242 GTEST_SKIP() << "getUsableChannels() is not supported by vendor.";
243 }
244 EXPECT_TRUE(status.isOk());
245 }
246
247 /*
248 * GetSupportedRadioCombinations
249 */
TEST_P(WifiChipAidlTest,GetSupportedRadioCombinations)250 TEST_P(WifiChipAidlTest, GetSupportedRadioCombinations) {
251 std::vector<WifiRadioCombination> combinations;
252 configureChipForConcurrencyType(IfaceConcurrencyType::STA);
253 auto status = wifi_chip_->getSupportedRadioCombinations(&combinations);
254 if (checkStatusCode(&status, WifiStatusCode::ERROR_NOT_SUPPORTED)) {
255 GTEST_SKIP() << "Skipping this test since getSupportedRadioCombinations() "
256 "is not supported by vendor.";
257 }
258 EXPECT_TRUE(status.isOk());
259 }
260
261 /*
262 * SetCountryCode
263 */
TEST_P(WifiChipAidlTest,SetCountryCode)264 TEST_P(WifiChipAidlTest, SetCountryCode) {
265 configureChipForConcurrencyType(IfaceConcurrencyType::STA);
266 std::array<uint8_t, 2> country_code = {0x55, 0x53};
267 EXPECT_TRUE(wifi_chip_->setCountryCode(country_code).isOk());
268 }
269
270 /*
271 * SetLatencyMode_normal
272 * Tests the setLatencyMode() API with Latency mode NORMAL.
273 */
TEST_P(WifiChipAidlTest,SetLatencyMode_normal)274 TEST_P(WifiChipAidlTest, SetLatencyMode_normal) {
275 configureChipForConcurrencyType(IfaceConcurrencyType::STA);
276 int32_t features = getChipFeatureSet(wifi_chip_);
277 auto status = wifi_chip_->setLatencyMode(IWifiChip::LatencyMode::NORMAL);
278 if (features & static_cast<int32_t>(IWifiChip::FeatureSetMask::SET_LATENCY_MODE)) {
279 EXPECT_TRUE(status.isOk());
280 } else {
281 EXPECT_TRUE(checkStatusCode(&status, WifiStatusCode::ERROR_NOT_SUPPORTED));
282 }
283 }
284
285 /*
286 * SetLatencyMode_low
287 * Tests the setLatencyMode() API with Latency mode LOW.
288 */
TEST_P(WifiChipAidlTest,SetLatencyMode_low)289 TEST_P(WifiChipAidlTest, SetLatencyMode_low) {
290 configureChipForConcurrencyType(IfaceConcurrencyType::STA);
291 int32_t features = getChipFeatureSet(wifi_chip_);
292 auto status = wifi_chip_->setLatencyMode(IWifiChip::LatencyMode::LOW);
293 if (features & static_cast<int32_t>(IWifiChip::FeatureSetMask::SET_LATENCY_MODE)) {
294 EXPECT_TRUE(status.isOk());
295 } else {
296 EXPECT_TRUE(checkStatusCode(&status, WifiStatusCode::ERROR_NOT_SUPPORTED));
297 }
298 }
299
300 /*
301 * SetMultiStaPrimaryConnection
302 *
303 * Only runs if the device supports 2 STA ifaces.
304 */
TEST_P(WifiChipAidlTest,SetMultiStaPrimaryConnection)305 TEST_P(WifiChipAidlTest, SetMultiStaPrimaryConnection) {
306 auto ifaces = create2StaIfacesIfPossible();
307 if (ifaces.size() < 2) {
308 GTEST_SKIP() << "Device does not support more than 1 STA concurrently";
309 }
310
311 auto status = wifi_chip_->setMultiStaPrimaryConnection(getStaIfaceName(ifaces[0]));
312 if (!status.isOk()) {
313 EXPECT_TRUE(checkStatusCode(&status, WifiStatusCode::ERROR_NOT_SUPPORTED));
314 }
315 }
316
317 /*
318 * SetMultiStaUseCase
319 *
320 * Only runs if the device supports 2 STA ifaces.
321 */
TEST_P(WifiChipAidlTest,setMultiStaUseCase)322 TEST_P(WifiChipAidlTest, setMultiStaUseCase) {
323 auto ifaces = create2StaIfacesIfPossible();
324 if (ifaces.size() < 2) {
325 GTEST_SKIP() << "Device does not support more than 1 STA concurrently";
326 }
327
328 auto status = wifi_chip_->setMultiStaUseCase(
329 IWifiChip::MultiStaUseCase::DUAL_STA_TRANSIENT_PREFER_PRIMARY);
330 if (!status.isOk()) {
331 EXPECT_TRUE(checkStatusCode(&status, WifiStatusCode::ERROR_NOT_SUPPORTED));
332 }
333 }
334
335 /*
336 * SetCoexUnsafeChannels
337 */
TEST_P(WifiChipAidlTest,SetCoexUnsafeChannels)338 TEST_P(WifiChipAidlTest, SetCoexUnsafeChannels) {
339 configureChipForConcurrencyType(IfaceConcurrencyType::STA);
340
341 // Test with an empty vector of CoexUnsafeChannels.
342 std::vector<IWifiChip::CoexUnsafeChannel> vec;
343 int restrictions = 0;
344 auto status = wifi_chip_->setCoexUnsafeChannels(vec, restrictions);
345 if (!status.isOk()) {
346 EXPECT_TRUE(checkStatusCode(&status, WifiStatusCode::ERROR_NOT_SUPPORTED));
347 }
348
349 // Test with a non-empty vector of CoexUnsafeChannels.
350 IWifiChip::CoexUnsafeChannel unsafeChannel24Ghz;
351 unsafeChannel24Ghz.band = WifiBand::BAND_24GHZ;
352 unsafeChannel24Ghz.channel = 6;
353 vec.push_back(unsafeChannel24Ghz);
354 IWifiChip::CoexUnsafeChannel unsafeChannel5Ghz;
355 unsafeChannel5Ghz.band = WifiBand::BAND_5GHZ;
356 unsafeChannel5Ghz.channel = 36;
357 vec.push_back(unsafeChannel5Ghz);
358 restrictions = static_cast<int32_t>(IWifiChip::CoexRestriction::WIFI_AWARE) |
359 static_cast<int32_t>(IWifiChip::CoexRestriction::SOFTAP) |
360 static_cast<int32_t>(IWifiChip::CoexRestriction::WIFI_DIRECT);
361
362 status = wifi_chip_->setCoexUnsafeChannels(vec, restrictions);
363 if (!status.isOk()) {
364 EXPECT_TRUE(checkStatusCode(&status, WifiStatusCode::ERROR_NOT_SUPPORTED));
365 }
366 }
367
368 /*
369 * SelectTxPowerScenario - Body
370 */
TEST_P(WifiChipAidlTest,SelectTxPowerScenario_body)371 TEST_P(WifiChipAidlTest, SelectTxPowerScenario_body) {
372 configureChipForConcurrencyType(IfaceConcurrencyType::STA);
373 int32_t features = getChipFeatureSet(wifi_chip_);
374 int32_t expected_features =
375 static_cast<int32_t>(IWifiChip::FeatureSetMask::SET_TX_POWER_LIMIT) |
376 static_cast<int32_t>(IWifiChip::FeatureSetMask::USE_BODY_HEAD_SAR);
377 auto status = wifi_chip_->selectTxPowerScenario(IWifiChip::TxPowerScenario::ON_BODY_CELL_OFF);
378 if (features & expected_features) {
379 EXPECT_TRUE(status.isOk());
380 } else {
381 EXPECT_TRUE(checkStatusCode(&status, WifiStatusCode::ERROR_NOT_SUPPORTED));
382 }
383 }
384
385 /*
386 * SelectTxPowerScenario - Voice Call
387 */
TEST_P(WifiChipAidlTest,SelectTxPowerScenario_voiceCall)388 TEST_P(WifiChipAidlTest, SelectTxPowerScenario_voiceCall) {
389 configureChipForConcurrencyType(IfaceConcurrencyType::STA);
390 int32_t features = getChipFeatureSet(wifi_chip_);
391 auto status = wifi_chip_->selectTxPowerScenario(IWifiChip::TxPowerScenario::VOICE_CALL);
392 if (features & static_cast<int32_t>(IWifiChip::FeatureSetMask::SET_TX_POWER_LIMIT)) {
393 EXPECT_TRUE(status.isOk());
394 } else {
395 EXPECT_TRUE(checkStatusCode(&status, WifiStatusCode::ERROR_NOT_SUPPORTED));
396 }
397 }
398
399 /*
400 * ResetTxPowerScenario
401 */
TEST_P(WifiChipAidlTest,ResetTxPowerScenario)402 TEST_P(WifiChipAidlTest, ResetTxPowerScenario) {
403 configureChipForConcurrencyType(IfaceConcurrencyType::STA);
404 int32_t features = getChipFeatureSet(wifi_chip_);
405 auto status = wifi_chip_->resetTxPowerScenario();
406 if (features & static_cast<int32_t>(IWifiChip::FeatureSetMask::SET_TX_POWER_LIMIT)) {
407 EXPECT_TRUE(status.isOk());
408 } else {
409 EXPECT_TRUE(checkStatusCode(&status, WifiStatusCode::ERROR_NOT_SUPPORTED));
410 }
411 }
412
413 /*
414 * ConfigureChip
415 */
TEST_P(WifiChipAidlTest,ConfigureChip)416 TEST_P(WifiChipAidlTest, ConfigureChip) {
417 std::vector<IWifiChip::ChipMode> modes;
418 EXPECT_TRUE(wifi_chip_->getAvailableModes(&modes).isOk());
419 EXPECT_NE(modes.size(), 0);
420 for (const auto& mode : modes) {
421 // configureChip() requires a fresh IWifiChip object.
422 wifi_chip_ = getWifiChip(getInstanceName());
423 ASSERT_NE(nullptr, wifi_chip_.get());
424 EXPECT_TRUE(wifi_chip_->configureChip(mode.id).isOk());
425 stopWifiService(getInstanceName());
426 // Sleep for 5 milliseconds between each wifi state toggle.
427 usleep(5000);
428 }
429 }
430
431 /*
432 * RequestChipDebugInfo
433 */
TEST_P(WifiChipAidlTest,RequestChipDebugInfo)434 TEST_P(WifiChipAidlTest, RequestChipDebugInfo) {
435 configureChipForConcurrencyType(IfaceConcurrencyType::STA);
436 IWifiChip::ChipDebugInfo debug_info = {};
437 EXPECT_TRUE(wifi_chip_->requestChipDebugInfo(&debug_info).isOk());
438 EXPECT_NE(debug_info.driverDescription.size(), 0);
439 EXPECT_NE(debug_info.firmwareDescription.size(), 0);
440 }
441
442 /*
443 * RequestFirmwareDebugDump
444 */
TEST_P(WifiChipAidlTest,RequestFirmwareDebugDump)445 TEST_P(WifiChipAidlTest, RequestFirmwareDebugDump) {
446 configureChipForConcurrencyType(IfaceConcurrencyType::STA);
447 std::vector<uint8_t> debug_dump;
448 auto status = wifi_chip_->requestFirmwareDebugDump(&debug_dump);
449 EXPECT_TRUE(status.isOk() || checkStatusCode(&status, WifiStatusCode::ERROR_NOT_SUPPORTED));
450 }
451
452 /*
453 * RequestDriverDebugDump
454 */
TEST_P(WifiChipAidlTest,RequestDriverDebugDump)455 TEST_P(WifiChipAidlTest, RequestDriverDebugDump) {
456 configureChipForConcurrencyType(IfaceConcurrencyType::STA);
457 std::vector<uint8_t> debug_dump;
458 auto status = wifi_chip_->requestDriverDebugDump(&debug_dump);
459 EXPECT_TRUE(status.isOk() || checkStatusCode(&status, WifiStatusCode::ERROR_NOT_SUPPORTED));
460 }
461
462 /*
463 * GetDebugRingBuffersStatus
464 */
TEST_P(WifiChipAidlTest,GetDebugRingBuffersStatus)465 TEST_P(WifiChipAidlTest, GetDebugRingBuffersStatus) {
466 configureChipForConcurrencyType(IfaceConcurrencyType::STA);
467 std::vector<WifiDebugRingBufferStatus> ring_buffer_status;
468 auto status = wifi_chip_->getDebugRingBuffersStatus(&ring_buffer_status);
469 EXPECT_TRUE(status.isOk() || checkStatusCode(&status, WifiStatusCode::ERROR_NOT_SUPPORTED));
470 if (status.isOk()) {
471 ASSERT_NE(ring_buffer_status.size(), 0);
472 for (const auto& ring_buffer : ring_buffer_status) {
473 EXPECT_NE(ring_buffer.ringName.size(), 0);
474 }
475 }
476 }
477
478 /*
479 * GetDebugHostWakeReasonStats
480 */
TEST_P(WifiChipAidlTest,GetDebugHostWakeReasonStats)481 TEST_P(WifiChipAidlTest, GetDebugHostWakeReasonStats) {
482 configureChipForConcurrencyType(IfaceConcurrencyType::STA);
483 WifiDebugHostWakeReasonStats wake_reason_stats = {};
484 auto status = wifi_chip_->getDebugHostWakeReasonStats(&wake_reason_stats);
485 EXPECT_TRUE(status.isOk() || checkStatusCode(&status, WifiStatusCode::ERROR_NOT_SUPPORTED));
486 }
487
488 /*
489 * StartLoggingToDebugRingBuffer
490 */
TEST_P(WifiChipAidlTest,StartLoggingToDebugRingBuffer)491 TEST_P(WifiChipAidlTest, StartLoggingToDebugRingBuffer) {
492 configureChipForConcurrencyType(IfaceConcurrencyType::STA);
493 std::string ring_name;
494 std::vector<WifiDebugRingBufferStatus> ring_buffer_status;
495
496 auto status = wifi_chip_->getDebugRingBuffersStatus(&ring_buffer_status);
497 EXPECT_TRUE(status.isOk() || checkStatusCode(&status, WifiStatusCode::ERROR_NOT_SUPPORTED));
498 if (status.isOk()) {
499 ASSERT_NE(ring_buffer_status.size(), 0);
500 ring_name = ring_buffer_status[0].ringName;
501 }
502
503 status = wifi_chip_->startLoggingToDebugRingBuffer(
504 ring_name, WifiDebugRingBufferVerboseLevel::VERBOSE, 5, 1024);
505 EXPECT_TRUE(status.isOk() || checkStatusCode(&status, WifiStatusCode::ERROR_NOT_SUPPORTED));
506 }
507
508 /*
509 * ForceDumpToDebugRingBuffer
510 */
TEST_P(WifiChipAidlTest,ForceDumpToDebugRingBuffer)511 TEST_P(WifiChipAidlTest, ForceDumpToDebugRingBuffer) {
512 configureChipForConcurrencyType(IfaceConcurrencyType::STA);
513 std::string ring_name;
514 std::vector<WifiDebugRingBufferStatus> ring_buffer_status;
515
516 auto status = wifi_chip_->getDebugRingBuffersStatus(&ring_buffer_status);
517 EXPECT_TRUE(status.isOk() || checkStatusCode(&status, WifiStatusCode::ERROR_NOT_SUPPORTED));
518 if (status.isOk()) {
519 ASSERT_NE(ring_buffer_status.size(), 0);
520 ring_name = ring_buffer_status[0].ringName;
521 }
522
523 status = wifi_chip_->forceDumpToDebugRingBuffer(ring_name);
524 EXPECT_TRUE(status.isOk() || checkStatusCode(&status, WifiStatusCode::ERROR_NOT_SUPPORTED));
525 }
526
527 /*
528 * CreateStaIface
529 * Configures the chip in STA mode and creates an iface.
530 */
TEST_P(WifiChipAidlTest,CreateStaIface)531 TEST_P(WifiChipAidlTest, CreateStaIface) {
532 configureChipForStaAndGetIface();
533 }
534
535 /*
536 * CreateApIface
537 */
TEST_P(WifiChipAidlTest,CreateApIface)538 TEST_P(WifiChipAidlTest, CreateApIface) {
539 if (!isConcurrencyTypeSupported(IfaceConcurrencyType::AP)) {
540 GTEST_SKIP() << "AP is not supported";
541 }
542 configureChipForApAndGetIface();
543 }
544
545 /*
546 * CreateNanIface
547 */
TEST_P(WifiChipAidlTest,CreateNanIface)548 TEST_P(WifiChipAidlTest, CreateNanIface) {
549 if (!::testing::deviceSupportsFeature("android.hardware.wifi.aware")) {
550 GTEST_SKIP() << "Skipping this test since NAN is not supported.";
551 }
552 configureChipForNanAndGetIface();
553 }
554
555 /*
556 * CreateP2pIface
557 */
TEST_P(WifiChipAidlTest,CreateP2pIface)558 TEST_P(WifiChipAidlTest, CreateP2pIface) {
559 if (!isConcurrencyTypeSupported(IfaceConcurrencyType::P2P)) {
560 GTEST_SKIP() << "P2P is not supported";
561 }
562 configureChipForP2pAndGetIface();
563 }
564
565 /*
566 * GetStaIfaceNames
567 * Configures the chip in STA mode and ensures that the iface name list is
568 * empty before creating the iface. Then create the iface and ensure that
569 * iface name is returned in the iface name list.
570 */
TEST_P(WifiChipAidlTest,GetStaIfaceNames)571 TEST_P(WifiChipAidlTest, GetStaIfaceNames) {
572 configureChipForConcurrencyType(IfaceConcurrencyType::STA);
573
574 std::vector<std::string> iface_names;
575 EXPECT_TRUE(wifi_chip_->getP2pIfaceNames(&iface_names).isOk());
576 EXPECT_EQ(iface_names.size(), 0);
577
578 std::shared_ptr<IWifiStaIface> iface;
579 EXPECT_TRUE(wifi_chip_->createStaIface(&iface).isOk());
580 ASSERT_NE(nullptr, iface.get());
581
582 std::string iface_name = getStaIfaceName(iface);
583 EXPECT_TRUE(wifi_chip_->getStaIfaceNames(&iface_names).isOk());
584 EXPECT_EQ(iface_names.size(), 1);
585 EXPECT_EQ(iface_name, iface_names[0]);
586
587 EXPECT_TRUE(wifi_chip_->removeStaIface(iface_name).isOk());
588 EXPECT_TRUE(wifi_chip_->getStaIfaceNames(&iface_names).isOk());
589 EXPECT_EQ(iface_names.size(), 0);
590 }
591
592 /*
593 * GetP2pIfaceNames
594 */
TEST_P(WifiChipAidlTest,GetP2pIfaceNames)595 TEST_P(WifiChipAidlTest, GetP2pIfaceNames) {
596 if (!isConcurrencyTypeSupported(IfaceConcurrencyType::P2P)) {
597 GTEST_SKIP() << "P2P is not supported";
598 }
599 configureChipForConcurrencyType(IfaceConcurrencyType::P2P);
600
601 std::vector<std::string> iface_names;
602 EXPECT_TRUE(wifi_chip_->getP2pIfaceNames(&iface_names).isOk());
603 EXPECT_EQ(iface_names.size(), 0);
604
605 std::shared_ptr<IWifiP2pIface> iface;
606 EXPECT_TRUE(wifi_chip_->createP2pIface(&iface).isOk());
607 ASSERT_NE(nullptr, iface.get());
608
609 std::string iface_name = getP2pIfaceName(iface);
610 EXPECT_TRUE(wifi_chip_->getP2pIfaceNames(&iface_names).isOk());
611 EXPECT_EQ(iface_names.size(), 1);
612 EXPECT_EQ(iface_name, iface_names[0]);
613
614 EXPECT_TRUE(wifi_chip_->removeP2pIface(iface_name).isOk());
615 EXPECT_TRUE(wifi_chip_->getP2pIfaceNames(&iface_names).isOk());
616 EXPECT_EQ(iface_names.size(), 0);
617 }
618
619 /*
620 * GetApIfaceNames
621 */
TEST_P(WifiChipAidlTest,GetApIfaceNames)622 TEST_P(WifiChipAidlTest, GetApIfaceNames) {
623 if (!isConcurrencyTypeSupported(IfaceConcurrencyType::AP)) {
624 GTEST_SKIP() << "AP is not supported";
625 }
626 configureChipForConcurrencyType(IfaceConcurrencyType::AP);
627
628 std::vector<std::string> iface_names;
629 EXPECT_TRUE(wifi_chip_->getApIfaceNames(&iface_names).isOk());
630 EXPECT_EQ(iface_names.size(), 0);
631
632 std::shared_ptr<IWifiApIface> iface;
633 EXPECT_TRUE(wifi_chip_->createApIface(&iface).isOk());
634 ASSERT_NE(nullptr, iface.get());
635
636 std::string iface_name = getApIfaceName(iface);
637 EXPECT_TRUE(wifi_chip_->getApIfaceNames(&iface_names).isOk());
638 EXPECT_EQ(iface_names.size(), 1);
639 EXPECT_EQ(iface_name, iface_names[0]);
640
641 EXPECT_TRUE(wifi_chip_->removeApIface(iface_name).isOk());
642 EXPECT_TRUE(wifi_chip_->getApIfaceNames(&iface_names).isOk());
643 EXPECT_EQ(iface_names.size(), 0);
644 }
645
646 /*
647 * GetNanIfaceNames
648 */
TEST_P(WifiChipAidlTest,GetNanIfaceNames)649 TEST_P(WifiChipAidlTest, GetNanIfaceNames) {
650 if (!::testing::deviceSupportsFeature("android.hardware.wifi.aware")) {
651 GTEST_SKIP() << "Skipping this test since NAN is not supported.";
652 }
653 configureChipForConcurrencyType(IfaceConcurrencyType::NAN_IFACE);
654
655 std::vector<std::string> iface_names;
656 EXPECT_TRUE(wifi_chip_->getNanIfaceNames(&iface_names).isOk());
657 EXPECT_EQ(iface_names.size(), 0);
658
659 std::shared_ptr<IWifiNanIface> iface;
660 EXPECT_TRUE(wifi_chip_->createNanIface(&iface).isOk());
661 ASSERT_NE(nullptr, iface.get());
662
663 std::string iface_name = getNanIfaceName(iface);
664 EXPECT_TRUE(wifi_chip_->getNanIfaceNames(&iface_names).isOk());
665 EXPECT_EQ(iface_names.size(), 1);
666 EXPECT_EQ(iface_name, iface_names[0]);
667
668 EXPECT_TRUE(wifi_chip_->removeNanIface(iface_name).isOk());
669 EXPECT_TRUE(wifi_chip_->getNanIfaceNames(&iface_names).isOk());
670 EXPECT_EQ(iface_names.size(), 0);
671 }
672
673 /*
674 * GetStaIface
675 * Configures the chip in STA mode and creates an iface. Then retrieves
676 * the iface object using its name and ensures that any other name
677 * doesn't retrieve a valid iface object.
678 */
TEST_P(WifiChipAidlTest,GetStaIface)679 TEST_P(WifiChipAidlTest, GetStaIface) {
680 std::shared_ptr<IWifiStaIface> iface = configureChipForStaAndGetIface();
681 std::string iface_name = getStaIfaceName(iface);
682
683 std::shared_ptr<IWifiStaIface> retrieved_iface;
684 EXPECT_TRUE(wifi_chip_->getStaIface(iface_name, &retrieved_iface).isOk());
685 EXPECT_NE(nullptr, retrieved_iface.get());
686
687 std::string invalid_name = iface_name + "0";
688 std::shared_ptr<IWifiStaIface> invalid_iface;
689 auto status = wifi_chip_->getStaIface(invalid_name, &invalid_iface);
690 EXPECT_TRUE(checkStatusCode(&status, WifiStatusCode::ERROR_INVALID_ARGS));
691 EXPECT_EQ(nullptr, invalid_iface.get());
692 }
693
694 /*
695 * GetP2pIface
696 */
TEST_P(WifiChipAidlTest,GetP2pIface)697 TEST_P(WifiChipAidlTest, GetP2pIface) {
698 if (!isConcurrencyTypeSupported(IfaceConcurrencyType::P2P)) {
699 GTEST_SKIP() << "P2P is not supported";
700 }
701 std::shared_ptr<IWifiP2pIface> iface = configureChipForP2pAndGetIface();
702 std::string iface_name = getP2pIfaceName(iface);
703
704 std::shared_ptr<IWifiP2pIface> retrieved_iface;
705 EXPECT_TRUE(wifi_chip_->getP2pIface(iface_name, &retrieved_iface).isOk());
706 EXPECT_NE(nullptr, retrieved_iface.get());
707
708 std::string invalid_name = iface_name + "0";
709 std::shared_ptr<IWifiP2pIface> invalid_iface;
710 auto status = wifi_chip_->getP2pIface(invalid_name, &invalid_iface);
711 EXPECT_TRUE(checkStatusCode(&status, WifiStatusCode::ERROR_INVALID_ARGS));
712 EXPECT_EQ(nullptr, invalid_iface.get());
713 }
714
715 /*
716 * GetApIface
717 */
TEST_P(WifiChipAidlTest,GetApIface)718 TEST_P(WifiChipAidlTest, GetApIface) {
719 if (!isConcurrencyTypeSupported(IfaceConcurrencyType::AP)) {
720 GTEST_SKIP() << "AP is not supported";
721 }
722 std::shared_ptr<IWifiApIface> iface = configureChipForApAndGetIface();
723 std::string iface_name = getApIfaceName(iface);
724
725 std::shared_ptr<IWifiApIface> retrieved_iface;
726 EXPECT_TRUE(wifi_chip_->getApIface(iface_name, &retrieved_iface).isOk());
727 EXPECT_NE(nullptr, retrieved_iface.get());
728
729 std::string invalid_name = iface_name + "0";
730 std::shared_ptr<IWifiApIface> invalid_iface;
731 auto status = wifi_chip_->getApIface(invalid_name, &invalid_iface);
732 EXPECT_TRUE(checkStatusCode(&status, WifiStatusCode::ERROR_INVALID_ARGS));
733 EXPECT_EQ(nullptr, invalid_iface.get());
734 }
735
736 /*
737 * GetNanIface
738 */
TEST_P(WifiChipAidlTest,GetNanIface)739 TEST_P(WifiChipAidlTest, GetNanIface) {
740 if (!::testing::deviceSupportsFeature("android.hardware.wifi.aware")) {
741 GTEST_SKIP() << "Skipping this test since NAN is not supported.";
742 }
743 std::shared_ptr<IWifiNanIface> iface = configureChipForNanAndGetIface();
744 std::string iface_name = getNanIfaceName(iface);
745
746 std::shared_ptr<IWifiNanIface> retrieved_iface;
747 EXPECT_TRUE(wifi_chip_->getNanIface(iface_name, &retrieved_iface).isOk());
748 EXPECT_NE(nullptr, retrieved_iface.get());
749
750 std::string invalid_name = iface_name + "0";
751 std::shared_ptr<IWifiNanIface> invalid_iface;
752 auto status = wifi_chip_->getNanIface(invalid_name, &invalid_iface);
753 EXPECT_TRUE(checkStatusCode(&status, WifiStatusCode::ERROR_INVALID_ARGS));
754 EXPECT_EQ(nullptr, invalid_iface.get());
755 }
756
757 /*
758 * RemoveStaIface
759 * Configures the chip in STA mode and creates an iface. Then removes
760 * the iface object using the correct name and ensures that any other
761 * name doesn't remove the iface.
762 */
TEST_P(WifiChipAidlTest,RemoveStaIface)763 TEST_P(WifiChipAidlTest, RemoveStaIface) {
764 std::shared_ptr<IWifiStaIface> iface = configureChipForStaAndGetIface();
765 std::string iface_name = getStaIfaceName(iface);
766
767 std::string invalid_name = iface_name + "0";
768 auto status = wifi_chip_->removeStaIface(invalid_name);
769 EXPECT_TRUE(checkStatusCode(&status, WifiStatusCode::ERROR_INVALID_ARGS));
770 EXPECT_TRUE(wifi_chip_->removeStaIface(iface_name).isOk());
771
772 // No such iface exists now, so this should return failure.
773 EXPECT_FALSE(wifi_chip_->removeStaIface(iface_name).isOk());
774 }
775
776 /*
777 * RemoveP2pIface
778 */
TEST_P(WifiChipAidlTest,RemoveP2pIface)779 TEST_P(WifiChipAidlTest, RemoveP2pIface) {
780 if (!isConcurrencyTypeSupported(IfaceConcurrencyType::P2P)) {
781 GTEST_SKIP() << "P2P is not supported";
782 }
783 std::shared_ptr<IWifiP2pIface> iface = configureChipForP2pAndGetIface();
784 std::string iface_name = getP2pIfaceName(iface);
785
786 std::string invalid_name = iface_name + "0";
787 auto status = wifi_chip_->removeP2pIface(invalid_name);
788 EXPECT_TRUE(checkStatusCode(&status, WifiStatusCode::ERROR_INVALID_ARGS));
789 EXPECT_TRUE(wifi_chip_->removeP2pIface(iface_name).isOk());
790
791 // No such iface exists now, so this should return failure.
792 EXPECT_FALSE(wifi_chip_->removeP2pIface(iface_name).isOk());
793 }
794
795 /*
796 * RemoveApIface
797 */
TEST_P(WifiChipAidlTest,RemoveApIface)798 TEST_P(WifiChipAidlTest, RemoveApIface) {
799 if (!isConcurrencyTypeSupported(IfaceConcurrencyType::AP)) {
800 GTEST_SKIP() << "AP is not supported";
801 }
802 std::shared_ptr<IWifiApIface> iface = configureChipForApAndGetIface();
803 std::string iface_name = getApIfaceName(iface);
804
805 std::string invalid_name = iface_name + "0";
806 auto status = wifi_chip_->removeApIface(invalid_name);
807 EXPECT_TRUE(checkStatusCode(&status, WifiStatusCode::ERROR_INVALID_ARGS));
808 EXPECT_TRUE(wifi_chip_->removeApIface(iface_name).isOk());
809
810 // No such iface exists now, so this should return failure.
811 EXPECT_FALSE(wifi_chip_->removeApIface(iface_name).isOk());
812 }
813
814 /*
815 * RemoveNanIface
816 */
TEST_P(WifiChipAidlTest,RemoveNanIface)817 TEST_P(WifiChipAidlTest, RemoveNanIface) {
818 if (!::testing::deviceSupportsFeature("android.hardware.wifi.aware")) {
819 GTEST_SKIP() << "Skipping this test since NAN is not supported.";
820 }
821 std::shared_ptr<IWifiNanIface> iface = configureChipForNanAndGetIface();
822 std::string iface_name = getNanIfaceName(iface);
823
824 std::string invalid_name = iface_name + "0";
825 auto status = wifi_chip_->removeNanIface(invalid_name);
826 EXPECT_TRUE(checkStatusCode(&status, WifiStatusCode::ERROR_INVALID_ARGS));
827 EXPECT_TRUE(wifi_chip_->removeNanIface(iface_name).isOk());
828
829 // No such iface exists now, so this should return failure.
830 EXPECT_FALSE(wifi_chip_->removeNanIface(iface_name).isOk());
831 }
832
833 /*
834 * CreateRttController
835 */
TEST_P(WifiChipAidlTest,CreateRttController)836 TEST_P(WifiChipAidlTest, CreateRttController) {
837 std::shared_ptr<IWifiStaIface> iface = configureChipForStaAndGetIface();
838 std::shared_ptr<IWifiRttController> rtt_controller;
839 auto status = wifi_chip_->createRttController(iface, &rtt_controller);
840 if (status.isOk()) {
841 EXPECT_NE(nullptr, rtt_controller.get());
842 } else {
843 EXPECT_TRUE(checkStatusCode(&status, WifiStatusCode::ERROR_NOT_SUPPORTED));
844 }
845 }
846
847 /**
848 * CreateBridgedApIface & RemoveIfaceInstanceFromBridgedApIface
849 */
TEST_P(WifiChipAidlTest,CreateBridgedApIfaceAndremoveIfaceInstanceFromBridgedApIfaceTest)850 TEST_P(WifiChipAidlTest, CreateBridgedApIfaceAndremoveIfaceInstanceFromBridgedApIfaceTest) {
851 bool isBridgedSupport = testing::checkSubstringInCommandOutput(
852 "/system/bin/cmd wifi get-softap-supported-features",
853 "wifi_softap_bridged_ap_supported");
854 if (!isBridgedSupport) {
855 GTEST_SKIP() << "Missing Bridged AP support";
856 }
857
858 std::shared_ptr<IWifiChip> wifi_chip = getWifiChip(getInstanceName());
859 ASSERT_NE(nullptr, wifi_chip.get());
860 std::shared_ptr<IWifiApIface> wifi_ap_iface = getBridgedWifiApIface(wifi_chip);
861 ASSERT_NE(nullptr, wifi_ap_iface.get());
862
863 std::string br_name;
864 std::vector<std::string> instances;
865 EXPECT_TRUE(wifi_ap_iface->getName(&br_name).isOk());
866 EXPECT_TRUE(wifi_ap_iface->getBridgedInstances(&instances).isOk());
867 EXPECT_EQ(instances.size(), 2);
868
869 std::vector<std::string> instances_after_remove;
870 EXPECT_TRUE(wifi_chip->removeIfaceInstanceFromBridgedApIface(br_name, instances[0]).isOk());
871 EXPECT_TRUE(wifi_ap_iface->getBridgedInstances(&instances_after_remove).isOk());
872 EXPECT_EQ(instances_after_remove.size(), 1);
873 }
874
875 /*
876 * SetVoipMode_off
877 * Tests the setVoipMode() API with VoIP mode OFF.
878 */
TEST_P(WifiChipAidlTest,SetVoipMode_off)879 TEST_P(WifiChipAidlTest, SetVoipMode_off) {
880 configureChipForConcurrencyType(IfaceConcurrencyType::STA);
881 int32_t features = getChipFeatureSet(wifi_chip_);
882 if (features & static_cast<int32_t>(IWifiChip::FeatureSetMask::SET_VOIP_MODE)) {
883 auto status = wifi_chip_->setVoipMode(IWifiChip::VoipMode::OFF);
884 EXPECT_TRUE(status.isOk());
885 } else {
886 GTEST_SKIP() << "setVoipMode() is not supported by vendor.";
887 }
888 }
889
890 /*
891 * SetVoipMode_voice
892 * Tests the setVoipMode() API with VoIP mode VOICE.
893 */
TEST_P(WifiChipAidlTest,SetVoipMode_voice)894 TEST_P(WifiChipAidlTest, SetVoipMode_voice) {
895 configureChipForConcurrencyType(IfaceConcurrencyType::STA);
896 int32_t features = getChipFeatureSet(wifi_chip_);
897 if (features & static_cast<int32_t>(IWifiChip::FeatureSetMask::SET_VOIP_MODE)) {
898 auto status = wifi_chip_->setVoipMode(IWifiChip::VoipMode::VOICE);
899 EXPECT_TRUE(status.isOk());
900 } else {
901 GTEST_SKIP() << "setVoipMode() is not supported by vendor.";
902 }
903 }
904
905 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(WifiChipAidlTest);
906 INSTANTIATE_TEST_SUITE_P(WifiTest, WifiChipAidlTest,
907 testing::ValuesIn(android::getAidlHalInstanceNames(IWifi::descriptor)),
908 android::PrintInstanceNameToString);
909
main(int argc,char ** argv)910 int main(int argc, char** argv) {
911 ::testing::InitGoogleTest(&argc, argv);
912 android::ProcessState::self()->setThreadPoolMaxThreadCount(1);
913 android::ProcessState::self()->startThreadPool();
914 return RUN_ALL_TESTS();
915 }
916