1 /*
2 * Copyright (C) 2018 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
19 #include <android/hardware/wifi/1.2/IWifiChip.h>
20 #include <android/hardware/wifi/1.2/IWifiChipEventCallback.h>
21 #include <android/hardware/wifi/1.3/IWifiChip.h>
22
23 #include <VtsHalHidlTargetCallbackBase.h>
24 #include <VtsHalHidlTargetTestBase.h>
25
26 #include "wifi_hidl_call_util.h"
27 #include "wifi_hidl_test_utils.h"
28
29 using ::android::hardware::hidl_string;
30 using ::android::hardware::hidl_vec;
31 using ::android::hardware::Return;
32 using ::android::hardware::wifi::V1_0::ChipModeId;
33 using ::android::hardware::wifi::V1_0::IfaceType;
34 using ::android::hardware::wifi::V1_0::WifiStatus;
35 using ::android::hardware::wifi::V1_0::WifiDebugRingBufferStatus;
36 using ::android::hardware::wifi::V1_0::WifiStatusCode;
37 using ::android::hardware::wifi::V1_2::IWifiChip;
38 using ::android::hardware::wifi::V1_2::IWifiChipEventCallback;
39 using ::android::hardware::Void;
40 using ::android::sp;
41
42 namespace {
43 constexpr IWifiChip::TxPowerScenario kPowerScenarioBody =
44 IWifiChip::TxPowerScenario::ON_BODY_CELL_OFF;
45
46 constexpr IWifiChip::TxPowerScenario kPowerScenarioVoiceCall =
47 IWifiChip::TxPowerScenario::VOICE_CALL;
48 }; // namespace
49
50 /**
51 * Fixture to use for all Wifi chip HIDL interface tests.
52 */
53 class WifiChipHidlTest : public ::testing::VtsHalHidlTargetTestBase {
54 public:
SetUp()55 virtual void SetUp() override {
56 wifi_chip_ = IWifiChip::castFrom(getWifiChip());
57 ASSERT_NE(nullptr, wifi_chip_.get());
58 }
59
TearDown()60 virtual void TearDown() override { stopWifi(); }
61
62 // A simple test implementation of WifiChipEventCallback.
63 class WifiChipEventCallback
64 : public ::testing::VtsHalHidlTargetCallbackBase<WifiChipHidlTest>,
65 public IWifiChipEventCallback {
66
67 public:
WifiChipEventCallback()68 WifiChipEventCallback() {};
69
70 virtual ~WifiChipEventCallback() = default;
71
onChipReconfigured(uint32_t modeId __unused)72 Return<void> onChipReconfigured(uint32_t modeId __unused) {
73 return Void();
74 };
75
onChipReconfigureFailure(const WifiStatus & status __unused)76 Return<void> onChipReconfigureFailure(const WifiStatus& status __unused) {
77 return Void();
78 };
79
onIfaceAdded(IfaceType type __unused,const hidl_string & name __unused)80 Return<void> onIfaceAdded(IfaceType type __unused, const hidl_string& name __unused) {
81 return Void();
82 };
83
onIfaceRemoved(IfaceType type __unused,const hidl_string & name __unused)84 Return<void> onIfaceRemoved(IfaceType type __unused, const hidl_string& name __unused) {
85 return Void();
86 };
87
onDebugRingBufferDataAvailable(const WifiDebugRingBufferStatus & status __unused,const hidl_vec<uint8_t> & data __unused)88 Return<void> onDebugRingBufferDataAvailable(const WifiDebugRingBufferStatus& status __unused,
89 const hidl_vec<uint8_t>& data __unused) {
90 return Void();
91 };
92
onDebugErrorAlert(int32_t errorCode __unused,const hidl_vec<uint8_t> & debugData __unused)93 Return<void> onDebugErrorAlert(int32_t errorCode __unused,
94 const hidl_vec<uint8_t>& debugData __unused) {
95 return Void();
96 };
97
onRadioModeChange(const hidl_vec<RadioModeInfo> & radioModeInfos __unused)98 Return<void> onRadioModeChange(const hidl_vec<RadioModeInfo>& radioModeInfos __unused) {
99 return Void();
100 };
101 };
102
103 protected:
configureChipForStaIfaceAndGetCapabilities()104 uint32_t configureChipForStaIfaceAndGetCapabilities() {
105 ChipModeId mode_id;
106 EXPECT_TRUE(
107 configureChipToSupportIfaceType(wifi_chip_, IfaceType::STA, &mode_id));
108
109 sp<::android::hardware::wifi::V1_3::IWifiChip> chip_converted =
110 ::android::hardware::wifi::V1_3::IWifiChip::castFrom(wifi_chip_);
111
112 std::pair<WifiStatus, uint32_t> status_and_caps;
113
114 if (chip_converted != nullptr) {
115 // Call the newer HAL version
116 status_and_caps = HIDL_INVOKE(chip_converted, getCapabilities_1_3);
117 } else {
118 status_and_caps = HIDL_INVOKE(wifi_chip_, getCapabilities);
119 }
120
121 EXPECT_EQ(WifiStatusCode::SUCCESS, status_and_caps.first.code);
122 return status_and_caps.second;
123 }
124
125 sp<IWifiChip> wifi_chip_;
126 };
127
128 /*
129 * SelectTxPowerScenario_1_2_body
130 * This test case tests the selectTxPowerScenario_1_2() API with SAR scenarios
131 * newly defined in 1.2
132 */
TEST_F(WifiChipHidlTest,SelectTxPowerScenario_1_2_body)133 TEST_F(WifiChipHidlTest, SelectTxPowerScenario_1_2_body) {
134 uint32_t caps = configureChipForStaIfaceAndGetCapabilities();
135 const auto& status =
136 HIDL_INVOKE(wifi_chip_, selectTxPowerScenario_1_2, kPowerScenarioBody);
137 if (caps & (IWifiChip::ChipCapabilityMask::SET_TX_POWER_LIMIT |
138 IWifiChip::ChipCapabilityMask::USE_BODY_HEAD_SAR)) {
139 EXPECT_EQ(WifiStatusCode::SUCCESS, status.code);
140 } else {
141 EXPECT_EQ(WifiStatusCode::ERROR_NOT_SUPPORTED, status.code);
142 }
143 }
144
145 /*
146 * SelectTxPowerScenario_1_2_voiceCall
147 * This test case tests the selectTxPowerScenario_1_2() API with previously
148 * defined SAR scenarios
149 */
TEST_F(WifiChipHidlTest,SelectTxPowerScenario_1_2_voiceCall)150 TEST_F(WifiChipHidlTest, SelectTxPowerScenario_1_2_voiceCall) {
151 uint32_t caps = configureChipForStaIfaceAndGetCapabilities();
152 const auto& status =
153 HIDL_INVOKE(wifi_chip_, selectTxPowerScenario_1_2, kPowerScenarioVoiceCall);
154 if (caps & (IWifiChip::ChipCapabilityMask::SET_TX_POWER_LIMIT)) {
155 EXPECT_EQ(WifiStatusCode::SUCCESS, status.code);
156 } else {
157 EXPECT_EQ(WifiStatusCode::ERROR_NOT_SUPPORTED, status.code);
158 }
159 }
160
161 /*
162 * registerEventCallback_1_2
163 * This test case tests the registerEventCallback_1_2() API which registers
164 * a call back function with the hal implementation
165 *
166 * Note: it is not feasible to test the invocation of the call back function
167 * since event is triggered internally in the HAL implementation, and can not be
168 * triggered from the test case
169 */
TEST_F(WifiChipHidlTest,registerEventCallback_1_2)170 TEST_F(WifiChipHidlTest, registerEventCallback_1_2) {
171 sp<WifiChipEventCallback> wifiChipEventCallback = new WifiChipEventCallback();
172 const auto& status =
173 HIDL_INVOKE(wifi_chip_, registerEventCallback_1_2, wifiChipEventCallback);
174 EXPECT_EQ(WifiStatusCode::SUCCESS, status.code);
175 }
176