1 /*
2 * Copyright (C) 2018 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 <android-base/logging.h>
21
22 #include <android/hardware/wifi/1.3/IWifiStaIface.h>
23
24 #include <VtsHalHidlTargetTestBase.h>
25
26 #include "wifi_hidl_call_util.h"
27 #include "wifi_hidl_test_utils.h"
28
29 using ::android::sp;
30 using ::android::hardware::wifi::V1_0::WifiStatusCode;
31 using ::android::hardware::wifi::V1_3::IWifiStaIface;
32
33 /**
34 * Fixture to use for all STA Iface HIDL interface tests.
35 */
36 class WifiStaIfaceHidlTest : public ::testing::VtsHalHidlTargetTestBase {
37 public:
SetUp()38 virtual void SetUp() override {
39 wifi_sta_iface_ = IWifiStaIface::castFrom(getWifiStaIface());
40 ASSERT_NE(nullptr, wifi_sta_iface_.get());
41 }
42
TearDown()43 virtual void TearDown() override { stopWifi(); }
44
45 protected:
isCapabilitySupported(IWifiStaIface::StaIfaceCapabilityMask cap_mask)46 bool isCapabilitySupported(IWifiStaIface::StaIfaceCapabilityMask cap_mask) {
47 const auto& status_and_caps =
48 HIDL_INVOKE(wifi_sta_iface_, getCapabilities);
49 EXPECT_EQ(WifiStatusCode::SUCCESS, status_and_caps.first.code);
50 return (status_and_caps.second & cap_mask) != 0;
51 }
52
53 sp<IWifiStaIface> wifi_sta_iface_;
54 };
55
56 /*
57 * GetFactoryMacAddress:
58 * Ensures that calls to get factory MAC address will retrieve a non-zero MAC
59 * and return a success status code.
60 */
TEST_F(WifiStaIfaceHidlTest,GetFactoryMacAddress)61 TEST_F(WifiStaIfaceHidlTest, GetFactoryMacAddress) {
62 const auto& status_and_mac =
63 HIDL_INVOKE(wifi_sta_iface_, getFactoryMacAddress);
64 EXPECT_EQ(WifiStatusCode::SUCCESS, status_and_mac.first.code);
65 const int num_elements = sizeof(status_and_mac.second) / sizeof(uint8_t);
66 EXPECT_EQ(6, num_elements);
67 for (int i = 0; i < num_elements; i++) {
68 EXPECT_NE(0, status_and_mac.second[i]);
69 }
70 }
71
72 /*
73 * GetLinkLayerStats_1_3
74 * Ensures that calls to get link layer stats V1_3 will retrieve a non-empty
75 * StaLinkLayerStats after link layer stats collection is enabled.
76 */
TEST_F(WifiStaIfaceHidlTest,GetLinkLayerStats_1_3)77 TEST_F(WifiStaIfaceHidlTest, GetLinkLayerStats_1_3) {
78 if (!isCapabilitySupported(
79 IWifiStaIface::StaIfaceCapabilityMask::LINK_LAYER_STATS)) {
80 // No-op if link layer stats is not supported.
81 return;
82 }
83
84 // Enable link layer stats collection.
85 EXPECT_EQ(WifiStatusCode::SUCCESS,
86 HIDL_INVOKE(wifi_sta_iface_, enableLinkLayerStatsCollection, true)
87 .code);
88 // Retrieve link layer stats.
89 const auto& status_and_stats =
90 HIDL_INVOKE(wifi_sta_iface_, getLinkLayerStats_1_3);
91 EXPECT_EQ(WifiStatusCode::SUCCESS, status_and_stats.first.code);
92 EXPECT_GT(status_and_stats.second.timeStampInMs, 0u);
93 // Disable link layer stats collection.
94 EXPECT_EQ(
95 WifiStatusCode::SUCCESS,
96 HIDL_INVOKE(wifi_sta_iface_, disableLinkLayerStatsCollection).code);
97 }
98