1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
|
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Staache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <android-base/logging.h>
#include <android/hardware/wifi/1.0/IWifi.h>
#include <android/hardware/wifi/1.0/IWifiStaIface.h>
#include <android/hardware/wifi/1.3/IWifiStaIface.h>
#include <gtest/gtest.h>
#include <hidl/GtestPrinter.h>
#include <hidl/ServiceManagement.h>
#include "wifi_hidl_call_util.h"
#include "wifi_hidl_test_utils.h"
using ::android::sp;
using ::android::hardware::wifi::V1_0::Bssid;
using ::android::hardware::wifi::V1_0::CommandId;
using ::android::hardware::wifi::V1_0::IfaceType;
using ::android::hardware::wifi::V1_0::IWifi;
using ::android::hardware::wifi::V1_0::IWifiStaIface;
using ::android::hardware::wifi::V1_0::Rssi;
using ::android::hardware::wifi::V1_0::Ssid;
using ::android::hardware::wifi::V1_0::StaApfPacketFilterCapabilities;
using ::android::hardware::wifi::V1_0::StaRoamingConfig;
using ::android::hardware::wifi::V1_0::StaRoamingState;
using ::android::hardware::wifi::V1_0::WifiBand;
using ::android::hardware::wifi::V1_0::WifiStatus;
using ::android::hardware::wifi::V1_0::WifiStatusCode;
/**
* Fixture to use for all STA Iface HIDL interface tests.
*/
class WifiStaIfaceHidlTest : public ::testing::TestWithParam<std::string> {
public:
virtual void SetUp() override {
// Make sure test starts with a clean state
stopWifi(GetInstanceName());
wifi_sta_iface_ = getWifiStaIface(GetInstanceName());
ASSERT_NE(nullptr, wifi_sta_iface_.get());
}
virtual void TearDown() override { stopWifi(GetInstanceName()); }
protected:
bool isCapabilitySupported(IWifiStaIface::StaIfaceCapabilityMask cap_mask) {
const auto& status_and_caps =
HIDL_INVOKE(wifi_sta_iface_, getCapabilities);
EXPECT_EQ(WifiStatusCode::SUCCESS, status_and_caps.first.code);
return (status_and_caps.second & cap_mask) != 0;
}
sp<IWifiStaIface> wifi_sta_iface_;
std::string GetInstanceName() { return GetParam(); }
};
/*
* Create:
* Ensures that an instance of the IWifiStaIface proxy object is
* successfully created.
*/
TEST_P(WifiStaIfaceHidlTest, Create) {
// The creation of a proxy object is tested as part of SetUp method.
}
/*
* GetCapabilities:
*/
TEST_P(WifiStaIfaceHidlTest, GetCapabilities) {
const auto& status_and_caps = HIDL_INVOKE(wifi_sta_iface_, getCapabilities);
EXPECT_EQ(WifiStatusCode::SUCCESS, status_and_caps.first.code);
EXPECT_GT(status_and_caps.second, 0u);
}
/*
* GetType:
* Ensures that the correct interface type is returned for station interface.
*/
TEST_P(WifiStaIfaceHidlTest, GetType) {
const auto& status_and_type = HIDL_INVOKE(wifi_sta_iface_, getType);
EXPECT_EQ(WifiStatusCode::SUCCESS, status_and_type.first.code);
EXPECT_EQ(IfaceType::STA, status_and_type.second);
}
/*
* GetApfPacketFilterCapabilities:
* Ensures that we can retrieve APF packet filter capabilites.
*/
TEST_P(WifiStaIfaceHidlTest, GetApfPacketFilterCapabilities) {
if (!isCapabilitySupported(IWifiStaIface::StaIfaceCapabilityMask::APF)) {
// No-op if APF packet filer is not supported.
return;
}
const auto& status_and_caps =
HIDL_INVOKE(wifi_sta_iface_, getApfPacketFilterCapabilities);
EXPECT_EQ(WifiStatusCode::SUCCESS, status_and_caps.first.code);
}
/*
* GetBackgroundScanCapabilities:
* Ensures that we can retrieve background scan capabilities.
*/
TEST_P(WifiStaIfaceHidlTest, GetBackgroundScanCapabilities) {
if (!isCapabilitySupported(
IWifiStaIface::StaIfaceCapabilityMask::BACKGROUND_SCAN)) {
// No-op if background scan is not supported.
return;
}
const auto& status_and_caps =
HIDL_INVOKE(wifi_sta_iface_, getBackgroundScanCapabilities);
EXPECT_EQ(WifiStatusCode::SUCCESS, status_and_caps.first.code);
}
/*
* GetValidFrequenciesForBand:
* Ensures that we can retrieve valid frequencies for 2.4 GHz band.
*/
TEST_P(WifiStaIfaceHidlTest, GetValidFrequenciesForBand) {
const auto& status_and_freqs = HIDL_INVOKE(
wifi_sta_iface_, getValidFrequenciesForBand, WifiBand::BAND_24GHZ);
EXPECT_EQ(WifiStatusCode::SUCCESS, status_and_freqs.first.code);
EXPECT_GT(status_and_freqs.second.size(), 0u);
}
/*
* LinkLayerStatsCollection:
* Ensures that calls to enable, disable, and retrieve link layer stats
* will return a success status code.
*/
TEST_P(WifiStaIfaceHidlTest, LinkLayerStatsCollection) {
if (!isCapabilitySupported(
IWifiStaIface::StaIfaceCapabilityMask::LINK_LAYER_STATS)) {
// No-op if link layer stats is not supported.
return;
}
sp<::android::hardware::wifi::V1_3::IWifiStaIface> iface_converted =
::android::hardware::wifi::V1_3::IWifiStaIface::castFrom(
wifi_sta_iface_);
if (iface_converted != nullptr) {
// Skip this test since this API is deprecated in this newer HAL version
return;
}
// Enable link layer stats collection.
EXPECT_EQ(WifiStatusCode::SUCCESS,
HIDL_INVOKE(wifi_sta_iface_, enableLinkLayerStatsCollection, true)
.code);
// Retrieve link layer stats.
EXPECT_EQ(WifiStatusCode::SUCCESS,
HIDL_INVOKE(wifi_sta_iface_, getLinkLayerStats).first.code);
// Disable link layer stats collection.
EXPECT_EQ(
WifiStatusCode::SUCCESS,
HIDL_INVOKE(wifi_sta_iface_, disableLinkLayerStatsCollection).code);
}
/*
* RSSIMonitoring:
* Ensures that calls to enable RSSI monitoring will return an error status
* code if device is not connected to an AP.
* Ensures that calls to disable RSSI monitoring will return an error status
* code if RSSI monitoring is not enabled.
*/
TEST_P(WifiStaIfaceHidlTest, RSSIMonitoring) {
if (!isCapabilitySupported(
IWifiStaIface::StaIfaceCapabilityMask::RSSI_MONITOR)) {
// No-op if RSSI monitor is not supported.
return;
}
const CommandId kCmd = 1;
const Rssi kMaxRssi = -50;
const Rssi kMinRssi = -90;
// This is going to fail because device is not connected to an AP.
EXPECT_NE(WifiStatusCode::SUCCESS,
HIDL_INVOKE(wifi_sta_iface_, startRssiMonitoring, kCmd, kMaxRssi,
kMinRssi)
.code);
// This is going to fail because RSSI monitoring is not enabled.
EXPECT_NE(WifiStatusCode::SUCCESS,
HIDL_INVOKE(wifi_sta_iface_, stopRssiMonitoring, kCmd).code);
}
/*
* RoamingControl:
* Ensures that calls to configure and enable roaming will return a success
* status code.
*/
TEST_P(WifiStaIfaceHidlTest, RoamingControl) {
if (!isCapabilitySupported(
IWifiStaIface::StaIfaceCapabilityMask::CONTROL_ROAMING)) {
// No-op if roaming control is not supported.
return;
}
// Retrieve roaming capabilities.
const auto& status_and_cap =
HIDL_INVOKE(wifi_sta_iface_, getRoamingCapabilities);
EXPECT_EQ(WifiStatusCode::SUCCESS, status_and_cap.first.code);
// Setup roaming configuration based on roaming capabilities.
const auto& cap = status_and_cap.second;
StaRoamingConfig roaming_config;
if (cap.maxBlacklistSize > 0) {
Bssid black_list_bssid{
std::array<uint8_t, 6>{{0x11, 0x22, 0x33, 0x44, 0x55, 0x66}}};
roaming_config.bssidBlacklist =
android::hardware::hidl_vec<Bssid>{black_list_bssid};
}
if (cap.maxWhitelistSize > 0) {
Ssid white_list_ssid{
std::array<uint8_t, 32>{{0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC}}};
roaming_config.ssidWhitelist =
android::hardware::hidl_vec<Ssid>{white_list_ssid};
}
// Configure roaming.
EXPECT_EQ(
WifiStatusCode::SUCCESS,
HIDL_INVOKE(wifi_sta_iface_, configureRoaming, roaming_config).code);
// Enable roaming.
EXPECT_EQ(
WifiStatusCode::SUCCESS,
HIDL_INVOKE(wifi_sta_iface_, setRoamingState, StaRoamingState::ENABLED)
.code);
}
/*
* EnableNDOffload:
* Ensures that calls to enable neighbor discovery offload will return a success
* status code.
*/
TEST_P(WifiStaIfaceHidlTest, EnableNDOffload) {
if (!isCapabilitySupported(
IWifiStaIface::StaIfaceCapabilityMask::ND_OFFLOAD)) {
// No-op if nd offload is not supported.
return;
}
EXPECT_EQ(WifiStatusCode::SUCCESS,
HIDL_INVOKE(wifi_sta_iface_, enableNdOffload, true).code);
}
/*
* SetScanningMacOui:
* Ensures that calls to set scanning MAC OUI will return a NOT_SUPPORTED
* code since it is now deprecated.
*/
TEST_P(WifiStaIfaceHidlTest, SetScanningMacOui) {
if (!isCapabilitySupported(
IWifiStaIface::StaIfaceCapabilityMask::SCAN_RAND)) {
// No-op if SetScanningMacOui is not supported.
return;
}
const android::hardware::hidl_array<uint8_t, 3> kOui{
std::array<uint8_t, 3>{{0x10, 0x22, 0x33}}};
EXPECT_EQ(WifiStatusCode::ERROR_NOT_SUPPORTED,
HIDL_INVOKE(wifi_sta_iface_, setScanningMacOui, kOui).code);
}
/*
* PacketFateMonitoring:
* Ensures that calls to start packet fate monitoring and retrieve TX/RX
* packets will return a success status code.
*/
TEST_P(WifiStaIfaceHidlTest, PacketFateMonitoring) {
if (!isCapabilitySupported(
IWifiStaIface::StaIfaceCapabilityMask::DEBUG_PACKET_FATE)) {
// No-op if packet fate monitor is not supported.
return;
}
// Start packet fate monitoring.
EXPECT_EQ(
WifiStatusCode::SUCCESS,
HIDL_INVOKE(wifi_sta_iface_, startDebugPacketFateMonitoring).code);
// Retrieve packets.
EXPECT_EQ(WifiStatusCode::SUCCESS,
HIDL_INVOKE(wifi_sta_iface_, getDebugTxPacketFates).first.code);
EXPECT_EQ(WifiStatusCode::SUCCESS,
HIDL_INVOKE(wifi_sta_iface_, getDebugRxPacketFates).first.code);
}
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(WifiStaIfaceHidlTest);
INSTANTIATE_TEST_SUITE_P(
PerInstance, WifiStaIfaceHidlTest,
testing::ValuesIn(
android::hardware::getAllHalInstanceNames(IWifi::descriptor)),
android::hardware::PrintInstanceNameToString);
|