1 /*
2 * Copyright (C) 2016 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 <VtsHalHidlTargetTestBase.h>
20
21 #include <android/hardware/wifi/supplicant/1.0/ISupplicantStaNetwork.h>
22
23 #include <android/hardware/wifi/supplicant/1.0/ISupplicantStaNetwork.h>
24
25 #include "supplicant_hidl_call_util.h"
26 #include "supplicant_hidl_test_utils.h"
27
28 using ::android::sp;
29 using ::android::hardware::hidl_array;
30 using ::android::hardware::hidl_string;
31 using ::android::hardware::hidl_vec;
32 using ::android::hardware::Return;
33 using ::android::hardware::Void;
34 using ::android::hardware::wifi::supplicant::V1_0::IfaceType;
35 using ::android::hardware::wifi::supplicant::V1_0::ISupplicantStaIface;
36 using ::android::hardware::wifi::supplicant::V1_0::ISupplicantStaNetwork;
37 using ::android::hardware::wifi::supplicant::V1_0::
38 ISupplicantStaNetworkCallback;
39 using ::android::hardware::wifi::supplicant::V1_0::SupplicantStatus;
40 using ::android::hardware::wifi::supplicant::V1_0::SupplicantStatusCode;
41
42 namespace {
43 constexpr char kTestSsidStr[] = "TestSsid1234";
44 constexpr char kTestPskPassphrase[] = "TestPsk123";
45 constexpr char kTestIdStr[] = "TestIdstr";
46 constexpr char kTestEapPasswdStr[] = "TestEapPasswd1234";
47 constexpr char kTestEapCert[] = "keystore://CERT";
48 constexpr char kTestEapPrivateKeyId[] = "key_id";
49 constexpr char kTestEapMatch[] = "match";
50 constexpr char kTestEapEngineID[] = "engine_id";
51 constexpr uint8_t kTestBssid[] = {0x56, 0x67, 0x67, 0xf4, 0x56, 0x92};
52 constexpr uint8_t kTestWepKey[] = {0x56, 0x67, 0x67, 0xf4, 0x56};
53 constexpr uint8_t kTestKc[] = {0x56, 0x67, 0x67, 0xf4, 0x76, 0x87, 0x98, 0x12};
54 constexpr uint8_t kTestSres[] = {0x56, 0x67, 0x67, 0xf4};
55 constexpr uint8_t kTestRes[] = {0x56, 0x67, 0x67, 0xf4, 0x67};
56 constexpr uint8_t kTestIk[] = {[0 ... 15] = 0x65};
57 constexpr uint8_t kTestCk[] = {[0 ... 15] = 0x45};
58 constexpr uint8_t kTestIdentity[] = {0x45, 0x67, 0x98, 0x67, 0x56};
59 constexpr uint8_t kTestPsk[] = {[0 ... 31] = 0x12};
60 constexpr uint8_t kTestAutParam[] = {[0 ... 13] = 0xe1};
61 constexpr uint32_t kTestWepTxKeyIdx = 2;
62 constexpr uint32_t kTestUpdateIdentifier = 21;
63 constexpr uint32_t kTestKeyMgmt = (ISupplicantStaNetwork::KeyMgmtMask::WPA_PSK |
64 ISupplicantStaNetwork::KeyMgmtMask::WPA_EAP);
65 constexpr uint32_t kTestProto = (ISupplicantStaNetwork::ProtoMask::OSEN |
66 ISupplicantStaNetwork::ProtoMask::RSN);
67 constexpr uint32_t kTestAuthAlg = (ISupplicantStaNetwork::AuthAlgMask::OPEN |
68 ISupplicantStaNetwork::AuthAlgMask::SHARED);
69 constexpr uint32_t kTestGroupCipher =
70 (ISupplicantStaNetwork::GroupCipherMask::CCMP |
71 ISupplicantStaNetwork::GroupCipherMask::WEP104);
72 constexpr uint32_t kTestPairwiseCipher =
73 (ISupplicantStaNetwork::PairwiseCipherMask::CCMP |
74 ISupplicantStaNetwork::PairwiseCipherMask::TKIP);
75 } // namespace
76
77 class SupplicantStaNetworkHidlTest : public ::testing::VtsHalHidlTargetTestBase {
78 public:
SetUp()79 virtual void SetUp() override {
80 startSupplicantAndWaitForHidlService();
81 EXPECT_TRUE(turnOnExcessiveLogging());
82 sta_network_ = createSupplicantStaNetwork();
83 ASSERT_NE(sta_network_.get(), nullptr);
84
85 ssid_.assign(kTestSsidStr, kTestSsidStr + strlen(kTestSsidStr));
86 }
87
TearDown()88 virtual void TearDown() override { stopSupplicant(); }
89
90 protected:
removeNetwork()91 void removeNetwork() {
92 sp<ISupplicantStaIface> sta_iface = getSupplicantStaIface();
93 ASSERT_NE(nullptr, sta_iface.get());
94 uint32_t net_id;
95 sta_network_->getId([&](const SupplicantStatus& status, int network_id) {
96 ASSERT_EQ(SupplicantStatusCode::SUCCESS, status.code);
97 net_id = network_id;
98 });
99 sta_iface->removeNetwork(net_id, [](const SupplicantStatus& status) {
100 ASSERT_EQ(SupplicantStatusCode::SUCCESS, status.code);
101 });
102 }
103
104 // ISupplicantStaNetwork object used for all tests in this fixture.
105 sp<ISupplicantStaNetwork> sta_network_;
106 // SSID to use for various tests.
107 std::vector<uint8_t> ssid_;
108 };
109
110 class NetworkCallback : public ISupplicantStaNetworkCallback {
onNetworkEapSimGsmAuthRequest(const ISupplicantStaNetworkCallback::NetworkRequestEapSimGsmAuthParams &)111 Return<void> onNetworkEapSimGsmAuthRequest(
112 const ISupplicantStaNetworkCallback::NetworkRequestEapSimGsmAuthParams&
113 /* params */) override {
114 return Void();
115 }
onNetworkEapSimUmtsAuthRequest(const ISupplicantStaNetworkCallback::NetworkRequestEapSimUmtsAuthParams &)116 Return<void> onNetworkEapSimUmtsAuthRequest(
117 const ISupplicantStaNetworkCallback::NetworkRequestEapSimUmtsAuthParams&
118 /* params */) override {
119 return Void();
120 }
onNetworkEapIdentityRequest()121 Return<void> onNetworkEapIdentityRequest() override { return Void(); }
122 };
123
124 /*
125 * Create:
126 * Ensures that an instance of the ISupplicantStaNetwork proxy object is
127 * successfully created.
128 */
TEST(SupplicantStaNetworkHidlTestNoFixture,Create)129 TEST(SupplicantStaNetworkHidlTestNoFixture, Create) {
130 startSupplicantAndWaitForHidlService();
131 EXPECT_NE(nullptr, createSupplicantStaNetwork().get());
132 stopSupplicant();
133 }
134
135 /*
136 * RegisterCallback
137 */
TEST_F(SupplicantStaNetworkHidlTest,RegisterCallback)138 TEST_F(SupplicantStaNetworkHidlTest, RegisterCallback) {
139 sta_network_->registerCallback(
140 new NetworkCallback(), [](const SupplicantStatus& status) {
141 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
142 });
143 }
144
145 /*
146 * GetInterfaceName
147 */
TEST_F(SupplicantStaNetworkHidlTest,GetInterfaceName)148 TEST_F(SupplicantStaNetworkHidlTest, GetInterfaceName) {
149 const auto& status_and_interface_name =
150 HIDL_INVOKE(sta_network_, getInterfaceName);
151 EXPECT_EQ(SupplicantStatusCode::SUCCESS,
152 status_and_interface_name.first.code);
153 EXPECT_FALSE(std::string(status_and_interface_name.second).empty());
154 }
155
156 /*
157 * GetType
158 */
TEST_F(SupplicantStaNetworkHidlTest,GetType)159 TEST_F(SupplicantStaNetworkHidlTest, GetType) {
160 const auto& status_and_interface_type = HIDL_INVOKE(sta_network_, getType);
161 EXPECT_EQ(SupplicantStatusCode::SUCCESS,
162 status_and_interface_type.first.code);
163 EXPECT_EQ(status_and_interface_type.second, IfaceType::STA);
164 }
165
166 /* Tests out the various setter/getter methods. */
167 /*
168 * SetGetSsid
169 */
TEST_F(SupplicantStaNetworkHidlTest,SetGetSsid)170 TEST_F(SupplicantStaNetworkHidlTest, SetGetSsid) {
171 sta_network_->setSsid(ssid_, [](const SupplicantStatus& status) {
172 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
173 });
174 sta_network_->getSsid(
175 [&](const SupplicantStatus& status, const hidl_vec<uint8_t>& get_ssid) {
176 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
177 EXPECT_EQ(ssid_, std::vector<uint8_t>(get_ssid));
178 });
179 }
180
181 /*
182 * SetGetBssid
183 */
TEST_F(SupplicantStaNetworkHidlTest,SetGetBssid)184 TEST_F(SupplicantStaNetworkHidlTest, SetGetBssid) {
185 std::array<uint8_t, 6> set_bssid;
186 memcpy(set_bssid.data(), kTestBssid, set_bssid.size());
187 sta_network_->setBssid(set_bssid, [](const SupplicantStatus& status) {
188 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
189 });
190 sta_network_->getBssid([&](const SupplicantStatus& status,
191 const hidl_array<uint8_t, 6>& get_bssid_hidl) {
192 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
193 std::array<uint8_t, 6> get_bssid;
194 memcpy(get_bssid.data(), get_bssid_hidl.data(), get_bssid.size());
195 EXPECT_EQ(set_bssid, get_bssid);
196 });
197 }
198
199 /*
200 * SetGetKeyMgmt
201 */
TEST_F(SupplicantStaNetworkHidlTest,SetGetKeyMgmt)202 TEST_F(SupplicantStaNetworkHidlTest, SetGetKeyMgmt) {
203 sta_network_->setKeyMgmt(kTestKeyMgmt, [](const SupplicantStatus& status) {
204 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
205 });
206 sta_network_->getKeyMgmt(
207 [&](const SupplicantStatus& status, uint32_t key_mgmt) {
208 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
209 EXPECT_EQ(key_mgmt, kTestKeyMgmt);
210 });
211 }
212
213 /*
214 * SetGetProto
215 */
TEST_F(SupplicantStaNetworkHidlTest,SetGetProto)216 TEST_F(SupplicantStaNetworkHidlTest, SetGetProto) {
217 sta_network_->setProto(kTestProto, [](const SupplicantStatus& status) {
218 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
219 });
220 sta_network_->getProto([&](const SupplicantStatus& status, uint32_t proto) {
221 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
222 EXPECT_EQ(proto, kTestProto);
223 });
224 }
225
226 /*
227 * SetGetKeyAuthAlg
228 */
TEST_F(SupplicantStaNetworkHidlTest,SetGetAuthAlg)229 TEST_F(SupplicantStaNetworkHidlTest, SetGetAuthAlg) {
230 sta_network_->setAuthAlg(kTestAuthAlg, [](const SupplicantStatus& status) {
231 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
232 });
233 sta_network_->getAuthAlg(
234 [&](const SupplicantStatus& status, uint32_t auth_alg) {
235 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
236 EXPECT_EQ(auth_alg, kTestAuthAlg);
237 });
238 }
239
240 /*
241 * SetGetGroupCipher
242 */
TEST_F(SupplicantStaNetworkHidlTest,SetGetGroupCipher)243 TEST_F(SupplicantStaNetworkHidlTest, SetGetGroupCipher) {
244 sta_network_->setGroupCipher(
245 kTestGroupCipher, [](const SupplicantStatus& status) {
246 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
247 });
248 sta_network_->getGroupCipher(
249 [&](const SupplicantStatus& status, uint32_t group_cipher) {
250 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
251 EXPECT_EQ(group_cipher, kTestGroupCipher);
252 });
253 }
254
255 /*
256 * SetGetPairwiseCipher
257 */
TEST_F(SupplicantStaNetworkHidlTest,SetGetPairwiseCipher)258 TEST_F(SupplicantStaNetworkHidlTest, SetGetPairwiseCipher) {
259 sta_network_->setPairwiseCipher(
260 kTestPairwiseCipher, [](const SupplicantStatus& status) {
261 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
262 });
263 sta_network_->getPairwiseCipher(
264 [&](const SupplicantStatus& status, uint32_t pairwise_cipher) {
265 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
266 EXPECT_EQ(pairwise_cipher, kTestPairwiseCipher);
267 });
268 }
269
270 /*
271 * SetGetPskPassphrase
272 */
TEST_F(SupplicantStaNetworkHidlTest,SetGetPskPassphrase)273 TEST_F(SupplicantStaNetworkHidlTest, SetGetPskPassphrase) {
274 sta_network_->setPskPassphrase(
275 kTestPskPassphrase, [](const SupplicantStatus& status) {
276 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
277 });
278 sta_network_->getPskPassphrase(
279 [&](const SupplicantStatus& status, const hidl_string& psk) {
280 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
281 EXPECT_EQ(kTestPskPassphrase, std::string(psk.c_str()));
282 });
283 }
284
285 /*
286 * SetGetPsk
287 */
TEST_F(SupplicantStaNetworkHidlTest,SetGetPsk)288 TEST_F(SupplicantStaNetworkHidlTest, SetGetPsk) {
289 EXPECT_EQ(SupplicantStatusCode::SUCCESS,
290 HIDL_INVOKE(sta_network_, setPsk, kTestPsk).code);
291 const auto& status_and_psk = HIDL_INVOKE(sta_network_, getPsk);
292 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status_and_psk.first.code);
293 hidl_array<uint8_t, 32> expected_psk(kTestPsk);
294 EXPECT_EQ(expected_psk, status_and_psk.second);
295 }
296
297 /*
298 * SetGetWepKeys
299 */
TEST_F(SupplicantStaNetworkHidlTest,SetGetWepTxKeyIdx)300 TEST_F(SupplicantStaNetworkHidlTest, SetGetWepTxKeyIdx) {
301 sta_network_->setWepTxKeyIdx(
302 kTestWepTxKeyIdx, [](const SupplicantStatus& status) {
303 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
304 });
305 sta_network_->getWepTxKeyIdx(
306 [&](const SupplicantStatus& status, uint32_t key_idx) {
307 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
308 EXPECT_EQ(kTestWepTxKeyIdx, key_idx);
309 });
310 }
311
312 /*
313 * SetGetWepKeys
314 */
TEST_F(SupplicantStaNetworkHidlTest,SetGetWepKeys)315 TEST_F(SupplicantStaNetworkHidlTest, SetGetWepKeys) {
316 for (uint32_t i = 0;
317 i < static_cast<uint32_t>(
318 ISupplicantStaNetwork::ParamSizeLimits::WEP_KEYS_MAX_NUM);
319 i++) {
320 std::vector<uint8_t> set_wep_key(std::begin(kTestWepKey),
321 std::end(kTestWepKey));
322 sta_network_->setWepKey(
323 i, set_wep_key, [](const SupplicantStatus& status) {
324 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
325 });
326 sta_network_->getWepKey(i, [&](const SupplicantStatus& status,
327 const hidl_vec<uint8_t>& get_wep_key) {
328 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
329 EXPECT_EQ(set_wep_key, std::vector<uint8_t>(get_wep_key));
330 });
331 }
332 }
333
334 /*
335 * SetGetScanSsid
336 */
TEST_F(SupplicantStaNetworkHidlTest,SetGetScanSsid)337 TEST_F(SupplicantStaNetworkHidlTest, SetGetScanSsid) {
338 sta_network_->setScanSsid(
339 true, [](const SupplicantStatus& status) {
340 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
341 });
342 sta_network_->getScanSsid(
343 [&](const SupplicantStatus& status, bool scan_ssid) {
344 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
345 EXPECT_EQ(true, scan_ssid);
346 });
347 }
348
349 /*
350 * SetGetRequirePmf
351 */
TEST_F(SupplicantStaNetworkHidlTest,SetGetRequirePmf)352 TEST_F(SupplicantStaNetworkHidlTest, SetGetRequirePmf) {
353 sta_network_->setRequirePmf(
354 true, [](const SupplicantStatus& status) {
355 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
356 });
357 sta_network_->getRequirePmf(
358 [&](const SupplicantStatus& status, bool require_pmf) {
359 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
360 EXPECT_EQ(true, require_pmf);
361 });
362 }
363
364 /*
365 * SetGetIdStr
366 */
TEST_F(SupplicantStaNetworkHidlTest,SetGetIdStr)367 TEST_F(SupplicantStaNetworkHidlTest, SetGetIdStr) {
368 sta_network_->setIdStr(
369 kTestIdStr, [](const SupplicantStatus& status) {
370 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
371 });
372 sta_network_->getIdStr(
373 [&](const SupplicantStatus& status, const hidl_string& id_str) {
374 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
375 EXPECT_EQ(kTestIdStr, std::string(id_str.c_str()));
376 });
377 }
378
379
380 /*
381 * SetGetEapMethod
382 */
TEST_F(SupplicantStaNetworkHidlTest,SetGetEapMethod)383 TEST_F(SupplicantStaNetworkHidlTest, SetGetEapMethod) {
384 ISupplicantStaNetwork::EapMethod set_eap_method =
385 ISupplicantStaNetwork::EapMethod::PEAP;
386 sta_network_->setEapMethod(
387 set_eap_method, [](const SupplicantStatus& status) {
388 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
389 });
390 sta_network_->getEapMethod(
391 [&](const SupplicantStatus& status,
392 ISupplicantStaNetwork::EapMethod eap_method) {
393 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
394 EXPECT_EQ(set_eap_method, eap_method);
395 });
396 }
397
398 /*
399 * SetGetEapPhase2Method
400 */
TEST_F(SupplicantStaNetworkHidlTest,SetGetEapPhase2Method)401 TEST_F(SupplicantStaNetworkHidlTest, SetGetEapPhase2Method) {
402 ISupplicantStaNetwork::EapMethod set_eap_method =
403 ISupplicantStaNetwork::EapMethod::PEAP;
404 sta_network_->setEapMethod(
405 set_eap_method, [](const SupplicantStatus& status) {
406 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
407 });
408 ISupplicantStaNetwork::EapPhase2Method set_eap_phase2_method =
409 ISupplicantStaNetwork::EapPhase2Method::NONE;
410 sta_network_->setEapPhase2Method(
411 set_eap_phase2_method, [](const SupplicantStatus& status) {
412 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
413 });
414 sta_network_->getEapPhase2Method(
415 [&](const SupplicantStatus& status,
416 ISupplicantStaNetwork::EapPhase2Method eap_phase2_method) {
417 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
418 EXPECT_EQ(set_eap_phase2_method, eap_phase2_method);
419 });
420 }
421
422 /*
423 * SetGetEapIdentity
424 */
TEST_F(SupplicantStaNetworkHidlTest,SetGetEapIdentity)425 TEST_F(SupplicantStaNetworkHidlTest, SetGetEapIdentity) {
426 std::vector<uint8_t> set_identity(kTestIdentity, kTestIdentity + sizeof(kTestIdentity));
427 sta_network_->setEapIdentity(
428 set_identity, [](const SupplicantStatus& status) {
429 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
430 });
431 sta_network_->getEapIdentity(
432 [&](const SupplicantStatus& status, const std::vector<uint8_t>& identity) {
433 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
434 EXPECT_EQ(set_identity, identity);
435 });
436 }
437
438 /*
439 * SetGetEapAnonymousIdentity
440 */
TEST_F(SupplicantStaNetworkHidlTest,SetGetEapAnonymousIdentity)441 TEST_F(SupplicantStaNetworkHidlTest, SetGetEapAnonymousIdentity) {
442 std::vector<uint8_t> set_identity(kTestIdentity, kTestIdentity + sizeof(kTestIdentity));
443 sta_network_->setEapAnonymousIdentity(
444 set_identity, [](const SupplicantStatus& status) {
445 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
446 });
447 sta_network_->getEapAnonymousIdentity(
448 [&](const SupplicantStatus& status, const std::vector<uint8_t>& identity) {
449 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
450 EXPECT_EQ(set_identity, identity);
451 });
452 }
453
454 /*
455 * SetGetEapPassword
456 */
TEST_F(SupplicantStaNetworkHidlTest,SetGetEapPassword)457 TEST_F(SupplicantStaNetworkHidlTest, SetGetEapPassword) {
458 std::vector<uint8_t> set_eap_passwd(
459 kTestEapPasswdStr, kTestEapPasswdStr + strlen(kTestEapPasswdStr));
460 sta_network_->setEapPassword(
461 set_eap_passwd, [](const SupplicantStatus& status) {
462 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
463 });
464 sta_network_->getEapPassword([&](const SupplicantStatus& status,
465 const hidl_vec<uint8_t>& eap_passwd) {
466 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
467 EXPECT_EQ(set_eap_passwd, std::vector<uint8_t>(eap_passwd));
468 });
469 }
470
471 /*
472 * SetGetEapCACert
473 */
TEST_F(SupplicantStaNetworkHidlTest,SetGetEapCACert)474 TEST_F(SupplicantStaNetworkHidlTest, SetGetEapCACert) {
475 sta_network_->setEapCACert(
476 kTestEapCert, [](const SupplicantStatus& status) {
477 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
478 });
479 sta_network_->getEapCACert([&](const SupplicantStatus& status,
480 const hidl_string& eap_cert) {
481 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
482 EXPECT_EQ(kTestEapCert, std::string(eap_cert.c_str()));
483 });
484 }
485
486 /*
487 * SetGetEapCAPath
488 */
TEST_F(SupplicantStaNetworkHidlTest,SetGetEapCAPath)489 TEST_F(SupplicantStaNetworkHidlTest, SetGetEapCAPath) {
490 sta_network_->setEapCAPath(
491 kTestEapCert, [](const SupplicantStatus& status) {
492 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
493 });
494 sta_network_->getEapCAPath([&](const SupplicantStatus& status,
495 const hidl_string& eap_cert) {
496 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
497 EXPECT_EQ(kTestEapCert, std::string(eap_cert.c_str()));
498 });
499 }
500
501 /*
502 * SetGetEapClientCert
503 */
TEST_F(SupplicantStaNetworkHidlTest,SetGetEapClientCert)504 TEST_F(SupplicantStaNetworkHidlTest, SetGetEapClientCert) {
505 sta_network_->setEapClientCert(
506 kTestEapCert, [](const SupplicantStatus& status) {
507 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
508 });
509 sta_network_->getEapClientCert([&](const SupplicantStatus& status,
510 const hidl_string& eap_cert) {
511 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
512 EXPECT_EQ(kTestEapCert, std::string(eap_cert.c_str()));
513 });
514 }
515
516 /*
517 * SetGetEapPrivateKeyId
518 */
TEST_F(SupplicantStaNetworkHidlTest,SetGetEapPrivateKeyId)519 TEST_F(SupplicantStaNetworkHidlTest, SetGetEapPrivateKeyId) {
520 sta_network_->setEapPrivateKeyId(
521 kTestEapPrivateKeyId, [](const SupplicantStatus& status) {
522 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
523 });
524 sta_network_->getEapPrivateKeyId([&](const SupplicantStatus& status,
525 const hidl_string& key_id) {
526 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
527 EXPECT_EQ(kTestEapPrivateKeyId, std::string(key_id.c_str()));
528 });
529 }
530
531 /*
532 * SetGetEapAltSubjectMatch
533 */
TEST_F(SupplicantStaNetworkHidlTest,SetGetEapAltSubjectMatch)534 TEST_F(SupplicantStaNetworkHidlTest, SetGetEapAltSubjectMatch) {
535 sta_network_->setEapAltSubjectMatch(
536 kTestEapMatch, [](const SupplicantStatus& status) {
537 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
538 });
539 sta_network_->getEapAltSubjectMatch([&](const SupplicantStatus& status,
540 const hidl_string& match) {
541 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
542 EXPECT_EQ(kTestEapMatch, std::string(match.c_str()));
543 });
544 }
545
546 /*
547 * SetGetEapSubjectMatch
548 */
TEST_F(SupplicantStaNetworkHidlTest,SetGetEapSubjectMatch)549 TEST_F(SupplicantStaNetworkHidlTest, SetGetEapSubjectMatch) {
550 EXPECT_EQ(
551 SupplicantStatusCode::SUCCESS,
552 HIDL_INVOKE(sta_network_, setEapSubjectMatch, kTestEapMatch).code);
553 const auto& status_and_subject_match =
554 HIDL_INVOKE(sta_network_, getEapSubjectMatch);
555 EXPECT_EQ(SupplicantStatusCode::SUCCESS,
556 status_and_subject_match.first.code);
557 EXPECT_EQ(kTestEapMatch,
558 std::string(status_and_subject_match.second.c_str()));
559 }
560
561 /*
562 * SetGetEapDomainSuffixMatch
563 */
TEST_F(SupplicantStaNetworkHidlTest,SetGetEapDomainSuffixMatch)564 TEST_F(SupplicantStaNetworkHidlTest, SetGetEapDomainSuffixMatch) {
565 sta_network_->setEapDomainSuffixMatch(
566 kTestEapMatch, [](const SupplicantStatus& status) {
567 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
568 });
569 sta_network_->getEapDomainSuffixMatch([&](const SupplicantStatus& status,
570 const hidl_string& match) {
571 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
572 EXPECT_EQ(kTestEapMatch, std::string(match.c_str()));
573 });
574 }
575
576 /*
577 * SetGetEapEngine
578 */
TEST_F(SupplicantStaNetworkHidlTest,SetGetEapEngine)579 TEST_F(SupplicantStaNetworkHidlTest, SetGetEapEngine) {
580 sta_network_->setEapEngine(
581 true, [](const SupplicantStatus& status) {
582 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
583 });
584 sta_network_->getEapEngine([&](const SupplicantStatus& status,
585 bool enable) {
586 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
587 EXPECT_EQ(true, enable);
588 });
589 }
590
591 /*
592 * SetGetEapEngineID
593 */
TEST_F(SupplicantStaNetworkHidlTest,SetGetEapEngineID)594 TEST_F(SupplicantStaNetworkHidlTest, SetGetEapEngineID) {
595 sta_network_->setEapEngineID(
596 kTestEapEngineID, [](const SupplicantStatus& status) {
597 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
598 });
599 sta_network_->getEapEngineID([&](const SupplicantStatus& status,
600 const hidl_string& id) {
601 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
602 EXPECT_EQ(kTestEapEngineID, std::string(id.c_str()));
603 });
604 }
605
606 /*
607 * Enable
608 */
TEST_F(SupplicantStaNetworkHidlTest,Enable)609 TEST_F(SupplicantStaNetworkHidlTest, Enable) {
610 // wpa_supplicant doesn't perform any connection initiation
611 // unless atleast the Ssid and Ket mgmt params are set.
612 sta_network_->setSsid(ssid_, [](const SupplicantStatus& status) {
613 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
614 });
615 sta_network_->setKeyMgmt(kTestKeyMgmt, [](const SupplicantStatus& status) {
616 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
617 });
618
619 sta_network_->enable(false, [](const SupplicantStatus& status) {
620 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
621 });
622 sta_network_->enable(true, [](const SupplicantStatus& status) {
623 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
624 });
625
626 // Now remove the network and ensure that the calls fail.
627 removeNetwork();
628 sta_network_->enable(true, [](const SupplicantStatus& status) {
629 EXPECT_EQ(SupplicantStatusCode::FAILURE_NETWORK_INVALID, status.code);
630 });
631 }
632
633 /*
634 * Disable
635 */
TEST_F(SupplicantStaNetworkHidlTest,Disable)636 TEST_F(SupplicantStaNetworkHidlTest, Disable) {
637 // wpa_supplicant doesn't perform any connection initiation
638 // unless atleast the Ssid and Ket mgmt params are set.
639 sta_network_->setSsid(ssid_, [](const SupplicantStatus& status) {
640 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
641 });
642 sta_network_->setKeyMgmt(kTestKeyMgmt, [](const SupplicantStatus& status) {
643 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
644 });
645
646 sta_network_->disable([](const SupplicantStatus& status) {
647 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
648 });
649 // Now remove the network and ensure that the calls fail.
650 removeNetwork();
651 sta_network_->disable([](const SupplicantStatus& status) {
652 EXPECT_EQ(SupplicantStatusCode::FAILURE_NETWORK_INVALID, status.code);
653 });
654 }
655
656 /*
657 * Select.
658 */
TEST_F(SupplicantStaNetworkHidlTest,Select)659 TEST_F(SupplicantStaNetworkHidlTest, Select) {
660 // wpa_supplicant doesn't perform any connection initiation
661 // unless atleast the Ssid and Ket mgmt params are set.
662 sta_network_->setSsid(ssid_, [](const SupplicantStatus& status) {
663 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
664 });
665 sta_network_->setKeyMgmt(kTestKeyMgmt, [](const SupplicantStatus& status) {
666 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
667 });
668
669 sta_network_->select([](const SupplicantStatus& status) {
670 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
671 });
672 // Now remove the network and ensure that the calls fail.
673 removeNetwork();
674 sta_network_->select([](const SupplicantStatus& status) {
675 EXPECT_EQ(SupplicantStatusCode::FAILURE_NETWORK_INVALID, status.code);
676 });
677 }
678
679 /*
680 * SendNetworkEapSimGsmAuthResponse
681 */
TEST_F(SupplicantStaNetworkHidlTest,SendNetworkEapSimGsmAuthResponse)682 TEST_F(SupplicantStaNetworkHidlTest, SendNetworkEapSimGsmAuthResponse) {
683 std::vector<ISupplicantStaNetwork::NetworkResponseEapSimGsmAuthParams>
684 params;
685 ISupplicantStaNetwork::NetworkResponseEapSimGsmAuthParams param;
686 memcpy(param.kc.data(), kTestKc, param.kc.size());
687 memcpy(param.sres.data(), kTestSres, param.sres.size());
688 params.push_back(param);
689 sta_network_->sendNetworkEapSimGsmAuthResponse(
690 params, [](const SupplicantStatus& status) {
691 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
692 });
693 }
694
695 /*
696 * SendNetworkEapSimGsmAuthFailure
697 */
TEST_F(SupplicantStaNetworkHidlTest,SendNetworkEapSimGsmAuthFailure)698 TEST_F(SupplicantStaNetworkHidlTest, SendNetworkEapSimGsmAuthFailure) {
699 EXPECT_EQ(SupplicantStatusCode::SUCCESS,
700 HIDL_INVOKE(sta_network_, sendNetworkEapSimGsmAuthFailure).code);
701 }
702
703 /*
704 * SendNetworkEapSimUmtsAuthResponse
705 */
TEST_F(SupplicantStaNetworkHidlTest,SendNetworkEapSimUmtsAuthResponse)706 TEST_F(SupplicantStaNetworkHidlTest, SendNetworkEapSimUmtsAuthResponse) {
707 ISupplicantStaNetwork::NetworkResponseEapSimUmtsAuthParams params;
708 params.res = std::vector<uint8_t>(kTestRes, kTestRes + sizeof(kTestRes));
709 memcpy(params.ik.data(), kTestIk, params.ik.size());
710 memcpy(params.ck.data(), kTestCk, params.ck.size());
711 sta_network_->sendNetworkEapSimUmtsAuthResponse(
712 params, [](const SupplicantStatus& status) {
713 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
714 });
715 }
716
717 /*
718 * SendNetworkEapSimUmtsAuthFailure
719 */
TEST_F(SupplicantStaNetworkHidlTest,SendNetworkEapSimUmtsAuthFailure)720 TEST_F(SupplicantStaNetworkHidlTest, SendNetworkEapSimUmtsAuthFailure) {
721 EXPECT_EQ(SupplicantStatusCode::SUCCESS,
722 HIDL_INVOKE(sta_network_, sendNetworkEapSimUmtsAuthFailure).code);
723 }
724
725 /*
726 * SendNetworkEapSimUmtsAutsResponse
727 */
TEST_F(SupplicantStaNetworkHidlTest,SendNetworkEapSimUmtsAutsResponse)728 TEST_F(SupplicantStaNetworkHidlTest, SendNetworkEapSimUmtsAutsResponse) {
729 EXPECT_EQ(SupplicantStatusCode::SUCCESS,
730 HIDL_INVOKE(sta_network_, sendNetworkEapSimUmtsAutsResponse,
731 kTestAutParam)
732 .code);
733 }
734
735 /*
736 * SendNetworkEapIdentityResponse
737 */
TEST_F(SupplicantStaNetworkHidlTest,SendNetworkEapIdentityResponse)738 TEST_F(SupplicantStaNetworkHidlTest, SendNetworkEapIdentityResponse) {
739 sta_network_->sendNetworkEapIdentityResponse(
740 std::vector<uint8_t>(kTestIdentity,
741 kTestIdentity + sizeof(kTestIdentity)),
742 [](const SupplicantStatus& status) {
743 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
744 });
745 }
746
747 /*
748 * SetUpdateIdentifier
749 */
TEST_F(SupplicantStaNetworkHidlTest,SetUpdateIdentifier)750 TEST_F(SupplicantStaNetworkHidlTest, SetUpdateIdentifier) {
751 EXPECT_EQ(
752 SupplicantStatusCode::SUCCESS,
753 HIDL_INVOKE(sta_network_, setUpdateIdentifier, kTestUpdateIdentifier)
754 .code);
755 }
756
757 /*
758 * SetProactiveKeyCaching
759 */
TEST_F(SupplicantStaNetworkHidlTest,SetProactiveKeyCaching)760 TEST_F(SupplicantStaNetworkHidlTest, SetProactiveKeyCaching) {
761 EXPECT_EQ(SupplicantStatusCode::SUCCESS,
762 HIDL_INVOKE(sta_network_, setProactiveKeyCaching, true).code);
763 EXPECT_EQ(SupplicantStatusCode::SUCCESS,
764 HIDL_INVOKE(sta_network_, setProactiveKeyCaching, false).code);
765 }
766
767 /*
768 * GetWpsNfcConfigurationToken
769 */
TEST_F(SupplicantStaNetworkHidlTest,GetWpsNfcConfigurationToken)770 TEST_F(SupplicantStaNetworkHidlTest, GetWpsNfcConfigurationToken) {
771 ASSERT_EQ(SupplicantStatusCode::SUCCESS,
772 HIDL_INVOKE(sta_network_, setSsid, ssid_).code);
773 ASSERT_EQ(SupplicantStatusCode::SUCCESS,
774 HIDL_INVOKE(sta_network_, setKeyMgmt, kTestKeyMgmt).code);
775 ASSERT_EQ(
776 SupplicantStatusCode::SUCCESS,
777 HIDL_INVOKE(sta_network_, setPskPassphrase, kTestPskPassphrase).code);
778 const auto& status_and_token =
779 HIDL_INVOKE(sta_network_, getWpsNfcConfigurationToken);
780 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status_and_token.first.code);
781 EXPECT_FALSE(0 == status_and_token.second.size());
782 }
783