1 /*
2 * Copyright (C) 2020 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 <VtsCoreUtil.h>
18
19 #include <android-base/logging.h>
20 #include <cutils/properties.h>
21
22 #include <gtest/gtest.h>
23 #include <hidl/GtestPrinter.h>
24 #include <hidl/ServiceManagement.h>
25
26 #include <android/hardware/wifi/1.0/IWifi.h>
27 #include <android/hardware/wifi/hostapd/1.3/IHostapd.h>
28
29 #include "hostapd_hidl_call_util.h"
30 #include "hostapd_hidl_test_utils.h"
31 #include "wifi_hidl_test_utils_1_5.h"
32
33 using ::android::sp;
34 using ::android::hardware::hidl_string;
35 using ::android::hardware::Return;
36 using ::android::hardware::Void;
37 using ::android::hardware::wifi::hostapd::V1_2::DebugLevel;
38 using ::android::hardware::wifi::hostapd::V1_2::HostapdStatusCode;
39 using ::android::hardware::wifi::hostapd::V1_2::Ieee80211ReasonCode;
40 using ::android::hardware::wifi::hostapd::V1_3::IHostapd;
41 using ::android::hardware::wifi::V1_0::IWifi;
42 using ::android::hardware::wifi::V1_0::WifiStatusCode;
43 using ::android::hardware::wifi::V1_5::IWifiApIface;
44
45 namespace {
46 constexpr unsigned char kNwSsid[] = {'t', 'e', 's', 't', '1',
47 '2', '3', '4', '5'};
48 constexpr char kNwPassphrase[] = "test12345";
49 constexpr char kInvalidMaxPskNwPassphrase[] =
50 "0123456789012345678901234567890123456789012345678901234567890123456789";
51 constexpr char kInvalidMinPskNwPassphrase[] = "test";
52 constexpr int kIfaceChannel = 6;
53 constexpr int kIfaceInvalidChannel = 567;
54 constexpr uint8_t kTestZeroMacAddr[] = {[0 ... 5] = 0x0};
55 constexpr Ieee80211ReasonCode kTestDisconnectReasonCode =
56 Ieee80211ReasonCode::WLAN_REASON_UNSPECIFIED;
57 } // namespace
58
59 class HostapdHidlTest
60 : public ::testing::TestWithParam<std::tuple<std::string, std::string>> {
61 public:
SetUp()62 virtual void SetUp() override {
63 wifi_instance_name_ = std::get<0>(GetParam());
64 hostapd_instance_name_ = std::get<1>(GetParam());
65 stopSupplicantIfNeeded(wifi_instance_name_);
66 startHostapdAndWaitForHidlService(wifi_instance_name_,
67 hostapd_instance_name_);
68 hostapd_ = IHostapd::getService(hostapd_instance_name_);
69 ASSERT_NE(hostapd_.get(), nullptr);
70 HIDL_INVOKE(hostapd_, setDebugParams, DebugLevel::EXCESSIVE);
71 isAcsSupport_ = testing::checkSubstringInCommandOutput(
72 "/system/bin/cmd wifi get-softap-supported-features",
73 "wifi_softap_acs_supported");
74 isWpa3SaeSupport_ = testing::checkSubstringInCommandOutput(
75 "/system/bin/cmd wifi get-softap-supported-features",
76 "wifi_softap_wpa3_sae_supported");
77 isBridgedSupport_ = testing::checkSubstringInCommandOutput(
78 "/system/bin/cmd wifi get-softap-supported-features",
79 "wifi_softap_bridged_ap_supported");
80 }
81
TearDown()82 virtual void TearDown() override {
83 HIDL_INVOKE_VOID_WITHOUT_ARGUMENTS(hostapd_, terminate);
84 // Wait 3 seconds to allow terminate processing before kill hostapd.
85 sleep(3);
86 stopHostapd(wifi_instance_name_);
87 }
88
89 protected:
90 bool isWpa3SaeSupport_ = false;
91 bool isAcsSupport_ = false;
92 bool isBridgedSupport_ = false;
93
setupApIfaceAndGetName(bool isBridged)94 std::string setupApIfaceAndGetName(bool isBridged) {
95 sp<IWifiApIface> wifi_ap_iface;
96 if (isBridged) {
97 wifi_ap_iface = getBridgedWifiApIface_1_5(wifi_instance_name_);
98 } else {
99 wifi_ap_iface = getWifiApIface_1_5(wifi_instance_name_);
100 }
101 EXPECT_NE(nullptr, wifi_ap_iface.get());
102
103 const auto& status_and_name = HIDL_INVOKE(wifi_ap_iface, getName);
104 EXPECT_EQ(WifiStatusCode::SUCCESS, status_and_name.first.code);
105 return status_and_name.second;
106 }
107
getIfaceParamsWithoutAcs(std::string iface_name)108 IHostapd::IfaceParams getIfaceParamsWithoutAcs(std::string iface_name) {
109 ::android::hardware::wifi::hostapd::V1_0::IHostapd::IfaceParams
110 iface_params;
111 ::android::hardware::wifi::hostapd::V1_1::IHostapd::IfaceParams
112 iface_params_1_1;
113 ::android::hardware::wifi::hostapd::V1_2::IHostapd::IfaceParams
114 iface_params_1_2;
115 IHostapd::IfaceParams iface_params_1_3;
116
117 std::vector<
118 ::android::hardware::wifi::hostapd::V1_3::IHostapd::ChannelParams>
119 vec_channelParams;
120
121 ::android::hardware::wifi::hostapd::V1_3::IHostapd::ChannelParams
122 channelParams_1_3;
123
124 iface_params.ifaceName = iface_name;
125 iface_params.hwModeParams.enable80211N = true;
126 iface_params.hwModeParams.enable80211AC = false;
127 iface_params.channelParams.enableAcs = false;
128 iface_params.channelParams.acsShouldExcludeDfs = false;
129 iface_params.channelParams.channel = kIfaceChannel;
130 iface_params_1_1.V1_0 = iface_params;
131 iface_params_1_2.V1_1 = iface_params_1_1;
132 // Newly added attributes in V1_2
133 iface_params_1_2.hwModeParams.enable80211AX = false;
134 iface_params_1_2.hwModeParams.enable6GhzBand = false;
135 iface_params_1_2.channelParams.bandMask = 0;
136 iface_params_1_2.channelParams.bandMask |=
137 IHostapd::BandMask::BAND_2_GHZ;
138
139 // Newly added attributes in V1_3
140 channelParams_1_3.channel = iface_params.channelParams.channel;
141 channelParams_1_3.enableAcs = iface_params.channelParams.enableAcs;
142 channelParams_1_3.bandMask = iface_params_1_2.channelParams.bandMask;
143 channelParams_1_3.V1_2 = iface_params_1_2.channelParams;
144
145 vec_channelParams.push_back(channelParams_1_3);
146 iface_params_1_3.V1_2 = iface_params_1_2;
147 iface_params_1_3.channelParamsList = vec_channelParams;
148 return iface_params_1_3;
149 }
150
getIfaceParamsWithBridgedModeACS(std::string iface_name)151 IHostapd::IfaceParams getIfaceParamsWithBridgedModeACS(
152 std::string iface_name) {
153 // First get the settings for WithoutAcs and then make changes
154 IHostapd::IfaceParams iface_params_1_3 =
155 getIfaceParamsWithoutAcs(iface_name);
156 iface_params_1_3.V1_2.V1_1.V1_0.channelParams.enableAcs = true;
157 iface_params_1_3.V1_2.V1_1.V1_0.channelParams.acsShouldExcludeDfs =
158 true;
159
160 std::vector<
161 ::android::hardware::wifi::hostapd::V1_3::IHostapd::ChannelParams>
162 vec_channelParams;
163
164 vec_channelParams.push_back(iface_params_1_3.channelParamsList[0]);
165
166 ::android::hardware::wifi::hostapd::V1_3::IHostapd::ChannelParams
167 second_channelParams_1_3;
168 second_channelParams_1_3.channel = 0;
169 second_channelParams_1_3.enableAcs = true;
170 second_channelParams_1_3.bandMask = 0;
171 second_channelParams_1_3.bandMask |= IHostapd::BandMask::BAND_5_GHZ;
172 second_channelParams_1_3.V1_2 = iface_params_1_3.V1_2.channelParams;
173 second_channelParams_1_3.V1_2.bandMask = 0;
174 second_channelParams_1_3.V1_2.bandMask |=
175 IHostapd::BandMask::BAND_5_GHZ;
176 vec_channelParams.push_back(second_channelParams_1_3);
177
178 iface_params_1_3.channelParamsList = vec_channelParams;
179 return iface_params_1_3;
180 }
181
getIfaceParamsWithAcs(std::string iface_name)182 IHostapd::IfaceParams getIfaceParamsWithAcs(std::string iface_name) {
183 // First get the settings for WithoutAcs and then make changes
184 IHostapd::IfaceParams iface_params_1_3 =
185 getIfaceParamsWithoutAcs(iface_name);
186 iface_params_1_3.V1_2.V1_1.V1_0.channelParams.enableAcs = true;
187 iface_params_1_3.V1_2.V1_1.V1_0.channelParams.acsShouldExcludeDfs =
188 true;
189 iface_params_1_3.V1_2.V1_1.V1_0.channelParams.channel = 0;
190 iface_params_1_3.V1_2.channelParams.bandMask |=
191 IHostapd::BandMask::BAND_5_GHZ;
192 iface_params_1_3.channelParamsList[0].channel =
193 iface_params_1_3.V1_2.V1_1.V1_0.channelParams.channel;
194 iface_params_1_3.channelParamsList[0].enableAcs =
195 iface_params_1_3.V1_2.V1_1.V1_0.channelParams.enableAcs;
196 iface_params_1_3.channelParamsList[0].V1_2 =
197 iface_params_1_3.V1_2.channelParams;
198 iface_params_1_3.channelParamsList[0].bandMask =
199 iface_params_1_3.V1_2.channelParams.bandMask;
200 return iface_params_1_3;
201 }
202
getIfaceParamsWithAcsAndFreqRange(std::string iface_name)203 IHostapd::IfaceParams getIfaceParamsWithAcsAndFreqRange(
204 std::string iface_name) {
205 IHostapd::IfaceParams iface_params_1_3 =
206 getIfaceParamsWithAcs(iface_name);
207 ::android::hardware::wifi::hostapd::V1_2::IHostapd::AcsFrequencyRange
208 acsFrequencyRange;
209 acsFrequencyRange.start = 2412;
210 acsFrequencyRange.end = 2462;
211 std::vector<::android::hardware::wifi::hostapd::V1_2::IHostapd::
212 AcsFrequencyRange>
213 vec_acsFrequencyRange;
214 vec_acsFrequencyRange.push_back(acsFrequencyRange);
215 iface_params_1_3.V1_2.channelParams.acsChannelFreqRangesMhz =
216 vec_acsFrequencyRange;
217 iface_params_1_3.channelParamsList[0].V1_2 =
218 iface_params_1_3.V1_2.channelParams;
219 return iface_params_1_3;
220 }
221
getIfaceParamsWithAcsAndInvalidFreqRange(std::string iface_name)222 IHostapd::IfaceParams getIfaceParamsWithAcsAndInvalidFreqRange(
223 std::string iface_name) {
224 IHostapd::IfaceParams iface_params_1_3 =
225 getIfaceParamsWithAcsAndFreqRange(iface_name);
226 iface_params_1_3.V1_2.channelParams.acsChannelFreqRangesMhz[0].start =
227 222;
228 iface_params_1_3.V1_2.channelParams.acsChannelFreqRangesMhz[0].end =
229 999;
230 iface_params_1_3.channelParamsList[0].V1_2 =
231 iface_params_1_3.V1_2.channelParams;
232 return iface_params_1_3;
233 }
234
getOpenNwParams()235 IHostapd::NetworkParams getOpenNwParams() {
236 IHostapd::NetworkParams nw_params_1_3;
237 ::android::hardware::wifi::hostapd::V1_2::IHostapd::NetworkParams
238 nw_params_1_2;
239 ::android::hardware::wifi::hostapd::V1_0::IHostapd::NetworkParams
240 nw_params_1_0;
241 nw_params_1_0.ssid =
242 std::vector<uint8_t>(kNwSsid, kNwSsid + sizeof(kNwSsid));
243 nw_params_1_0.isHidden = false;
244 nw_params_1_2.V1_0 = nw_params_1_0;
245 nw_params_1_2.encryptionType = IHostapd::EncryptionType::NONE;
246 nw_params_1_3.V1_2 = nw_params_1_2;
247 nw_params_1_3.isMetered = true;
248 return nw_params_1_3;
249 }
250
getPskNwParamsWithNonMetered()251 IHostapd::NetworkParams getPskNwParamsWithNonMetered() {
252 IHostapd::NetworkParams nw_params_1_3 = getOpenNwParams();
253 nw_params_1_3.V1_2.encryptionType = IHostapd::EncryptionType::WPA2;
254 nw_params_1_3.V1_2.passphrase = kNwPassphrase;
255 nw_params_1_3.isMetered = false;
256 return nw_params_1_3;
257 }
258
getPskNwParams()259 IHostapd::NetworkParams getPskNwParams() {
260 IHostapd::NetworkParams nw_params_1_3 = getOpenNwParams();
261 nw_params_1_3.V1_2.encryptionType = IHostapd::EncryptionType::WPA2;
262 nw_params_1_3.V1_2.passphrase = kNwPassphrase;
263 return nw_params_1_3;
264 }
265
getInvalidPskNwParams()266 IHostapd::NetworkParams getInvalidPskNwParams() {
267 IHostapd::NetworkParams nw_params_1_3 = getOpenNwParams();
268 nw_params_1_3.V1_2.encryptionType = IHostapd::EncryptionType::WPA2;
269 nw_params_1_3.V1_2.passphrase = kInvalidMaxPskNwPassphrase;
270
271 return nw_params_1_3;
272 }
273
getSaeTransitionNwParams()274 IHostapd::NetworkParams getSaeTransitionNwParams() {
275 IHostapd::NetworkParams nw_params_1_3 = getOpenNwParams();
276 nw_params_1_3.V1_2.encryptionType =
277 IHostapd::EncryptionType::WPA3_SAE_TRANSITION;
278 nw_params_1_3.V1_2.passphrase = kNwPassphrase;
279 return nw_params_1_3;
280 }
281
getInvalidSaeTransitionNwParams()282 IHostapd::NetworkParams getInvalidSaeTransitionNwParams() {
283 IHostapd::NetworkParams nw_params_1_3 = getOpenNwParams();
284 nw_params_1_3.V1_2.encryptionType = IHostapd::EncryptionType::WPA2;
285 nw_params_1_3.V1_2.passphrase = kInvalidMinPskNwPassphrase;
286 return nw_params_1_3;
287 }
288
getSaeNwParams()289 IHostapd::NetworkParams getSaeNwParams() {
290 IHostapd::NetworkParams nw_params_1_3 = getOpenNwParams();
291 nw_params_1_3.V1_2.encryptionType = IHostapd::EncryptionType::WPA3_SAE;
292 nw_params_1_3.V1_2.passphrase = kNwPassphrase;
293 return nw_params_1_3;
294 }
295
getInvalidSaeNwParams()296 IHostapd::NetworkParams getInvalidSaeNwParams() {
297 IHostapd::NetworkParams nw_params_1_3 = getOpenNwParams();
298 nw_params_1_3.V1_2.encryptionType = IHostapd::EncryptionType::WPA3_SAE;
299 nw_params_1_3.V1_2.passphrase = "";
300 return nw_params_1_3;
301 }
302
getIfaceParamsWithInvalidChannel(std::string iface_name)303 IHostapd::IfaceParams getIfaceParamsWithInvalidChannel(
304 std::string iface_name) {
305 IHostapd::IfaceParams iface_params_1_3 =
306 getIfaceParamsWithoutAcs(iface_name);
307 iface_params_1_3.V1_2.V1_1.V1_0.channelParams.channel =
308 kIfaceInvalidChannel;
309 iface_params_1_3.channelParamsList[0].channel =
310 iface_params_1_3.V1_2.V1_1.V1_0.channelParams.channel;
311 return iface_params_1_3;
312 }
313
314 // IHostapd object used for all tests in this fixture.
315 sp<IHostapd> hostapd_;
316 std::string wifi_instance_name_;
317 std::string hostapd_instance_name_;
318 };
319
320 /**
321 * Adds an access point with PSK network config & ACS enabled.
322 * Access point creation should pass.
323 */
TEST_P(HostapdHidlTest,AddPskAccessPointWithAcs)324 TEST_P(HostapdHidlTest, AddPskAccessPointWithAcs) {
325 if (!isAcsSupport_) GTEST_SKIP() << "Missing ACS support";
326 std::string ifname = setupApIfaceAndGetName(false);
327 auto status = HIDL_INVOKE(hostapd_, addAccessPoint_1_3,
328 getIfaceParamsWithAcs(ifname), getPskNwParams());
329 EXPECT_EQ(HostapdStatusCode::SUCCESS, status.code);
330 }
331
332 /**
333 * Adds an access point with PSK network config, ACS enabled & frequency Range.
334 * Access point creation should pass.
335 */
TEST_P(HostapdHidlTest,AddPskAccessPointWithAcsAndFreqRange)336 TEST_P(HostapdHidlTest, AddPskAccessPointWithAcsAndFreqRange) {
337 if (!isAcsSupport_) GTEST_SKIP() << "Missing ACS support";
338 std::string ifname = setupApIfaceAndGetName(false);
339 auto status = HIDL_INVOKE(hostapd_, addAccessPoint_1_3,
340 getIfaceParamsWithAcsAndFreqRange(ifname),
341 getPskNwParams());
342 EXPECT_EQ(HostapdStatusCode::SUCCESS, status.code);
343 }
344
345 /**
346 * Adds an access point with invalid channel range.
347 * Access point creation should fail.
348 */
TEST_P(HostapdHidlTest,AddPskAccessPointWithAcsAndInvalidFreqRange)349 TEST_P(HostapdHidlTest, AddPskAccessPointWithAcsAndInvalidFreqRange) {
350 if (!isAcsSupport_) GTEST_SKIP() << "Missing ACS support";
351 std::string ifname = setupApIfaceAndGetName(false);
352 auto status = HIDL_INVOKE(hostapd_, addAccessPoint_1_3,
353 getIfaceParamsWithAcsAndInvalidFreqRange(ifname),
354 getPskNwParams());
355 EXPECT_NE(HostapdStatusCode::SUCCESS, status.code);
356 }
357
358 /**
359 * Adds an access point with Open network config & ACS enabled.
360 * Access point creation should pass.
361 */
TEST_P(HostapdHidlTest,AddOpenAccessPointWithAcs)362 TEST_P(HostapdHidlTest, AddOpenAccessPointWithAcs) {
363 if (!isAcsSupport_) GTEST_SKIP() << "Missing ACS support";
364 std::string ifname = setupApIfaceAndGetName(false);
365 auto status = HIDL_INVOKE(hostapd_, addAccessPoint_1_3,
366 getIfaceParamsWithAcs(ifname), getOpenNwParams());
367 EXPECT_EQ(HostapdStatusCode::SUCCESS, status.code);
368 }
369
370 /**
371 * Adds an access point with PSK network config & ACS disabled.
372 * Access point creation should pass.
373 */
TEST_P(HostapdHidlTest,AddPskAccessPointWithoutAcs)374 TEST_P(HostapdHidlTest, AddPskAccessPointWithoutAcs) {
375 std::string ifname = setupApIfaceAndGetName(false);
376 auto status =
377 HIDL_INVOKE(hostapd_, addAccessPoint_1_3,
378 getIfaceParamsWithoutAcs(ifname), getPskNwParams());
379 EXPECT_EQ(HostapdStatusCode::SUCCESS, status.code);
380 }
381
382 /**
383 * Adds an access point with PSK network config, ACS disabled & Non metered.
384 * Access point creation should pass.
385 */
TEST_P(HostapdHidlTest,AddPskAccessPointWithoutAcsAndNonMetered)386 TEST_P(HostapdHidlTest, AddPskAccessPointWithoutAcsAndNonMetered) {
387 std::string ifname = setupApIfaceAndGetName(false);
388 auto status = HIDL_INVOKE(hostapd_, addAccessPoint_1_3,
389 getIfaceParamsWithoutAcs(ifname),
390 getPskNwParamsWithNonMetered());
391 EXPECT_EQ(HostapdStatusCode::SUCCESS, status.code);
392 }
393
394 /**
395 * Adds an access point with Open network config & ACS disabled.
396 * Access point creation should pass.
397 */
TEST_P(HostapdHidlTest,AddOpenAccessPointWithoutAcs)398 TEST_P(HostapdHidlTest, AddOpenAccessPointWithoutAcs) {
399 std::string ifname = setupApIfaceAndGetName(false);
400 auto status =
401 HIDL_INVOKE(hostapd_, addAccessPoint_1_3,
402 getIfaceParamsWithoutAcs(ifname), getOpenNwParams());
403 EXPECT_EQ(HostapdStatusCode::SUCCESS, status.code);
404 }
405
406 /**
407 * Adds an access point with SAE Transition network config & ACS disabled.
408 * Access point creation should pass.
409 */
TEST_P(HostapdHidlTest,AddSaeTransitionAccessPointWithoutAcs)410 TEST_P(HostapdHidlTest, AddSaeTransitionAccessPointWithoutAcs) {
411 if (!isWpa3SaeSupport_) GTEST_SKIP() << "Missing SAE support";
412 std::string ifname = setupApIfaceAndGetName(false);
413 auto status = HIDL_INVOKE(hostapd_, addAccessPoint_1_3,
414 getIfaceParamsWithoutAcs(ifname),
415 getSaeTransitionNwParams());
416 EXPECT_EQ(HostapdStatusCode::SUCCESS, status.code);
417 }
418
419 /**
420 * Adds an access point with SAE network config & ACS disabled.
421 * Access point creation should pass.
422 */
TEST_P(HostapdHidlTest,AddSAEAccessPointWithoutAcs)423 TEST_P(HostapdHidlTest, AddSAEAccessPointWithoutAcs) {
424 if (!isWpa3SaeSupport_) GTEST_SKIP() << "Missing SAE support";
425 std::string ifname = setupApIfaceAndGetName(false);
426 auto status =
427 HIDL_INVOKE(hostapd_, addAccessPoint_1_3,
428 getIfaceParamsWithoutAcs(ifname), getSaeNwParams());
429 EXPECT_EQ(HostapdStatusCode::SUCCESS, status.code);
430 }
431
432 /**
433 * Adds & then removes an access point with PSK network config & ACS enabled.
434 * Access point creation & removal should pass.
435 */
TEST_P(HostapdHidlTest,RemoveAccessPointWithAcs)436 TEST_P(HostapdHidlTest, RemoveAccessPointWithAcs) {
437 if (!isAcsSupport_) GTEST_SKIP() << "Missing ACS support";
438 std::string ifname = setupApIfaceAndGetName(false);
439 auto status_1_2 =
440 HIDL_INVOKE(hostapd_, addAccessPoint_1_3, getIfaceParamsWithAcs(ifname),
441 getPskNwParams());
442 EXPECT_EQ(HostapdStatusCode::SUCCESS, status_1_2.code);
443 auto status = HIDL_INVOKE(hostapd_, removeAccessPoint, ifname);
444 EXPECT_EQ(
445 android::hardware::wifi::hostapd::V1_0::HostapdStatusCode::SUCCESS,
446 status.code);
447 }
448
449 /**
450 * Adds & then removes an access point with PSK network config & ACS disabled.
451 * Access point creation & removal should pass.
452 */
TEST_P(HostapdHidlTest,RemoveAccessPointWithoutAcs)453 TEST_P(HostapdHidlTest, RemoveAccessPointWithoutAcs) {
454 std::string ifname = setupApIfaceAndGetName(false);
455 auto status_1_2 =
456 HIDL_INVOKE(hostapd_, addAccessPoint_1_3,
457 getIfaceParamsWithoutAcs(ifname), getPskNwParams());
458 EXPECT_EQ(HostapdStatusCode::SUCCESS, status_1_2.code);
459 auto status = HIDL_INVOKE(hostapd_, removeAccessPoint, ifname);
460 EXPECT_EQ(
461 android::hardware::wifi::hostapd::V1_0::HostapdStatusCode::SUCCESS,
462 status.code);
463 }
464
465 /**
466 * Adds an access point with invalid channel.
467 * Access point creation should fail.
468 */
TEST_P(HostapdHidlTest,AddPskAccessPointWithInvalidChannel)469 TEST_P(HostapdHidlTest, AddPskAccessPointWithInvalidChannel) {
470 std::string ifname = setupApIfaceAndGetName(false);
471 auto status =
472 HIDL_INVOKE(hostapd_, addAccessPoint_1_3,
473 getIfaceParamsWithInvalidChannel(ifname), getPskNwParams());
474 EXPECT_NE(HostapdStatusCode::SUCCESS, status.code);
475 }
476
477 /**
478 * Adds an access point with invalid PSK network config.
479 * Access point creation should fail.
480 */
TEST_P(HostapdHidlTest,AddInvalidPskAccessPointWithoutAcs)481 TEST_P(HostapdHidlTest, AddInvalidPskAccessPointWithoutAcs) {
482 std::string ifname = setupApIfaceAndGetName(false);
483 auto status =
484 HIDL_INVOKE(hostapd_, addAccessPoint_1_3,
485 getIfaceParamsWithoutAcs(ifname), getInvalidPskNwParams());
486 EXPECT_NE(HostapdStatusCode::SUCCESS, status.code);
487 }
488
489 /**
490 * Adds an access point with invalid SAE transition network config.
491 * Access point creation should fail.
492 */
TEST_P(HostapdHidlTest,AddInvalidSaeTransitionAccessPointWithoutAcs)493 TEST_P(HostapdHidlTest, AddInvalidSaeTransitionAccessPointWithoutAcs) {
494 if (!isWpa3SaeSupport_) GTEST_SKIP() << "Missing SAE support";
495 std::string ifname = setupApIfaceAndGetName(false);
496 auto status = HIDL_INVOKE(hostapd_, addAccessPoint_1_3,
497 getIfaceParamsWithoutAcs(ifname),
498 getInvalidSaeTransitionNwParams());
499 EXPECT_NE(HostapdStatusCode::SUCCESS, status.code);
500 }
501
502 /**
503 * Adds an access point with invalid SAE network config.
504 * Access point creation should fail.
505 */
TEST_P(HostapdHidlTest,AddInvalidSaeAccessPointWithoutAcs)506 TEST_P(HostapdHidlTest, AddInvalidSaeAccessPointWithoutAcs) {
507 if (!isWpa3SaeSupport_) GTEST_SKIP() << "Missing SAE support";
508 std::string ifname = setupApIfaceAndGetName(false);
509 auto status =
510 HIDL_INVOKE(hostapd_, addAccessPoint_1_3,
511 getIfaceParamsWithoutAcs(ifname), getInvalidSaeNwParams());
512 EXPECT_NE(HostapdStatusCode::SUCCESS, status.code);
513 }
514
515 /**
516 * forceClientDisconnect should return FAILURE_CLIENT_UNKNOWN
517 * when hotspot interface available.
518 */
TEST_P(HostapdHidlTest,DisconnectClientWhenIfacAvailable)519 TEST_P(HostapdHidlTest, DisconnectClientWhenIfacAvailable) {
520 std::string ifname = setupApIfaceAndGetName(false);
521 auto status_1_2 =
522 HIDL_INVOKE(hostapd_, addAccessPoint_1_3,
523 getIfaceParamsWithoutAcs(ifname), getOpenNwParams());
524 EXPECT_EQ(HostapdStatusCode::SUCCESS, status_1_2.code);
525
526 status_1_2 = HIDL_INVOKE(hostapd_, forceClientDisconnect, ifname,
527 kTestZeroMacAddr, kTestDisconnectReasonCode);
528 EXPECT_EQ(HostapdStatusCode::FAILURE_CLIENT_UNKNOWN, status_1_2.code);
529 }
530
531 /**
532 * AddAccessPointWithDualBandConfig should pass
533 */
TEST_P(HostapdHidlTest,AddAccessPointWithDualBandConfig)534 TEST_P(HostapdHidlTest, AddAccessPointWithDualBandConfig) {
535 if (!isBridgedSupport_) GTEST_SKIP() << "Missing Bridged AP support";
536 std::string ifname = setupApIfaceAndGetName(true);
537 auto status_1_2 = HIDL_INVOKE(hostapd_, addAccessPoint_1_3,
538 getIfaceParamsWithBridgedModeACS(ifname),
539 getOpenNwParams());
540 EXPECT_EQ(HostapdStatusCode::SUCCESS, status_1_2.code);
541 }
542
543 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(HostapdHidlTest);
544 INSTANTIATE_TEST_CASE_P(
545 PerInstance, HostapdHidlTest,
546 testing::Combine(
547 testing::ValuesIn(
548 android::hardware::getAllHalInstanceNames(IWifi::descriptor)),
549 testing::ValuesIn(android::hardware::getAllHalInstanceNames(
550 android::hardware::wifi::hostapd::V1_3::IHostapd::descriptor))),
551 android::hardware::PrintInstanceTupleNameToString<>);
552