• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 #include <aidl/Gtest.h>
19 #include <aidl/Vintf.h>
20 #include <aidl/android/hardware/wifi/supplicant/BnSupplicant.h>
21 #include <aidl/android/hardware/wifi/supplicant/BnSupplicantStaIfaceCallback.h>
22 #include <android/binder_manager.h>
23 #include <android/binder_status.h>
24 #include <binder/IServiceManager.h>
25 #include <binder/ProcessState.h>
26 #include <cutils/properties.h>
27 
28 #include "supplicant_test_utils.h"
29 
30 using aidl::android::hardware::wifi::supplicant::AnqpInfoId;
31 using aidl::android::hardware::wifi::supplicant::BnSupplicantStaIfaceCallback;
32 using aidl::android::hardware::wifi::supplicant::BtCoexistenceMode;
33 using aidl::android::hardware::wifi::supplicant::ConnectionCapabilities;
34 using aidl::android::hardware::wifi::supplicant::DebugLevel;
35 using aidl::android::hardware::wifi::supplicant::DppAkm;
36 using aidl::android::hardware::wifi::supplicant::DppConnectionKeys;
37 using aidl::android::hardware::wifi::supplicant::DppCurve;
38 using aidl::android::hardware::wifi::supplicant::DppNetRole;
39 using aidl::android::hardware::wifi::supplicant::DppResponderBootstrapInfo;
40 using aidl::android::hardware::wifi::supplicant::Hs20AnqpSubtypes;
41 using aidl::android::hardware::wifi::supplicant::IfaceType;
42 using aidl::android::hardware::wifi::supplicant::ISupplicant;
43 using aidl::android::hardware::wifi::supplicant::ISupplicantStaIface;
44 using aidl::android::hardware::wifi::supplicant::ISupplicantStaNetwork;
45 using aidl::android::hardware::wifi::supplicant::KeyMgmtMask;
46 using aidl::android::hardware::wifi::supplicant::WpaDriverCapabilitiesMask;
47 using aidl::android::hardware::wifi::supplicant::WpsConfigMethods;
48 using android::ProcessState;
49 
50 static constexpr int TIMEOUT_PERIOD = 60;
51 class IfaceDppCallback;
52 
53 namespace {
54 const std::vector<uint8_t> kTestMacAddr = {0x56, 0x67, 0x67, 0xf4, 0x56, 0x92};
55 const std::string kTestUri =
56     "DPP:C:81/1,117/"
57     "40;M:48d6d5bd1de1;I:G1197843;K:MDkwEwYHKoZIzj0CAQYIKoZIzj"
58     "0DAQcDIgAD0edY4X3N//HhMFYsZfMbQJTiNFtNIWF/cIwMB/gzqOM=;;";
59 }  // namespace
60 
61 class SupplicantStaIfaceCallback : public BnSupplicantStaIfaceCallback {
62    public:
63     SupplicantStaIfaceCallback() = default;
64 
onAnqpQueryDone(const std::vector<uint8_t> &,const::aidl::android::hardware::wifi::supplicant::AnqpData &,const::aidl::android::hardware::wifi::supplicant::Hs20AnqpData &)65     ::ndk::ScopedAStatus onAnqpQueryDone(
66         const std::vector<uint8_t>& /* bssid */,
67         const ::aidl::android::hardware::wifi::supplicant::AnqpData& /* data */,
68         const ::aidl::android::hardware::wifi::supplicant::
69             Hs20AnqpData& /* hs20Data */) override {
70         return ndk::ScopedAStatus::ok();
71     }
onAssociationRejected(const::aidl::android::hardware::wifi::supplicant::AssociationRejectionData &)72     ::ndk::ScopedAStatus onAssociationRejected(
73         const ::aidl::android::hardware::wifi::supplicant::
74             AssociationRejectionData& /* assocRejectData */) override {
75         return ndk::ScopedAStatus::ok();
76     }
onAuthenticationTimeout(const std::vector<uint8_t> &)77     ::ndk::ScopedAStatus onAuthenticationTimeout(
78         const std::vector<uint8_t>& /* bssid */) override {
79         return ndk::ScopedAStatus::ok();
80     }
onAuxiliarySupplicantEvent(::aidl::android::hardware::wifi::supplicant::AuxiliarySupplicantEventCode,const std::vector<uint8_t> &,const std::string &)81     ::ndk::ScopedAStatus onAuxiliarySupplicantEvent(
82             ::aidl::android::hardware::wifi::supplicant ::
83                     AuxiliarySupplicantEventCode /* eventCode */,
84             const std::vector<uint8_t>& /* bssid */,
85             const std::string& /* reasonString */) override {
86         return ndk::ScopedAStatus::ok();
87     }
onBssTmHandlingDone(const::aidl::android::hardware::wifi::supplicant::BssTmData &)88     ::ndk::ScopedAStatus onBssTmHandlingDone(
89         const ::aidl::android::hardware::wifi::supplicant::
90             BssTmData& /* tmData */) override {
91         return ndk::ScopedAStatus::ok();
92     }
onBssidChanged(::aidl::android::hardware::wifi::supplicant::BssidChangeReason,const std::vector<uint8_t> &)93     ::ndk::ScopedAStatus onBssidChanged(
94         ::aidl::android::hardware::wifi::supplicant::
95             BssidChangeReason /* reason */,
96         const std::vector<uint8_t>& /* bssid */) override {
97         return ndk::ScopedAStatus::ok();
98     }
onDisconnected(const std::vector<uint8_t> &,bool,::aidl::android::hardware::wifi::supplicant::StaIfaceReasonCode)99     ::ndk::ScopedAStatus onDisconnected(
100         const std::vector<uint8_t>& /* bssid */, bool /* locallyGenerated */,
101         ::aidl::android::hardware::wifi::supplicant::
102             StaIfaceReasonCode /* reasonCode */) override {
103         return ndk::ScopedAStatus::ok();
104     }
onDppFailure(::aidl::android::hardware::wifi::supplicant::DppFailureCode,const std::string &,const std::string &,const std::vector<char16_t> &)105     ::ndk::ScopedAStatus onDppFailure(
106         ::aidl::android::hardware::wifi::supplicant::DppFailureCode /* code */,
107         const std::string& /* ssid */, const std::string& /* channelList */,
108         const std::vector<char16_t>& /* bandList */) override {
109         return ndk::ScopedAStatus::ok();
110     }
onDppProgress(::aidl::android::hardware::wifi::supplicant::DppProgressCode)111     ::ndk::ScopedAStatus onDppProgress(
112         ::aidl::android::hardware::wifi::supplicant::DppProgressCode /* code */)
113         override {
114         return ndk::ScopedAStatus::ok();
115     }
onDppSuccess(::aidl::android::hardware::wifi::supplicant::DppEventType)116     ::ndk::ScopedAStatus onDppSuccess(
117         ::aidl::android::hardware::wifi::supplicant::DppEventType /* type */)
118         override {
119         return ndk::ScopedAStatus::ok();
120     }
onDppSuccessConfigReceived(const std::vector<uint8_t> &,const std::string &,const std::vector<uint8_t> &,::aidl::android::hardware::wifi::supplicant::DppAkm,const::aidl::android::hardware::wifi::supplicant::DppConnectionKeys &)121     ::ndk::ScopedAStatus onDppSuccessConfigReceived(
122             const std::vector<uint8_t>& /* ssid */, const std::string& /* password */,
123             const std::vector<uint8_t>& /* psk */,
124             ::aidl::android::hardware::wifi::supplicant::DppAkm /* securityAkm */,
125             const ::aidl::android::hardware::wifi::supplicant::
126                     DppConnectionKeys& /* DppConnectionKeys */) override {
127         return ndk::ScopedAStatus::ok();
128     }
onDppSuccessConfigSent()129     ::ndk::ScopedAStatus onDppSuccessConfigSent() override {
130         return ndk::ScopedAStatus::ok();
131     }
onEapFailure(const std::vector<uint8_t> &,int32_t)132     ::ndk::ScopedAStatus onEapFailure(const std::vector<uint8_t>& /* bssid */,
133                                       int32_t /* errorCode */) override {
134         return ndk::ScopedAStatus::ok();
135     }
onExtRadioWorkStart(int32_t)136     ::ndk::ScopedAStatus onExtRadioWorkStart(int32_t /* id */) override {
137         return ndk::ScopedAStatus::ok();
138     }
onExtRadioWorkTimeout(int32_t)139     ::ndk::ScopedAStatus onExtRadioWorkTimeout(int32_t /* id */) override {
140         return ndk::ScopedAStatus::ok();
141     }
onHs20DeauthImminentNotice(const std::vector<uint8_t> &,int32_t,int32_t,const std::string &)142     ::ndk::ScopedAStatus onHs20DeauthImminentNotice(
143         const std::vector<uint8_t>& /* bssid */, int32_t /* reasonCode */,
144         int32_t /* reAuthDelayInSec */, const std::string& /* url */) override {
145         return ndk::ScopedAStatus::ok();
146     }
onHs20IconQueryDone(const std::vector<uint8_t> &,const std::string &,const std::vector<uint8_t> &)147     ::ndk::ScopedAStatus onHs20IconQueryDone(
148         const std::vector<uint8_t>& /* bssid */,
149         const std::string& /* fileName */,
150         const std::vector<uint8_t>& /* data */) override {
151         return ndk::ScopedAStatus::ok();
152     }
onHs20SubscriptionRemediation(const std::vector<uint8_t> &,::aidl::android::hardware::wifi::supplicant::OsuMethod,const std::string &)153     ::ndk::ScopedAStatus onHs20SubscriptionRemediation(
154         const std::vector<uint8_t>& /* bssid */,
155         ::aidl::android::hardware::wifi::supplicant::OsuMethod /* osuMethod */,
156         const std::string& /* url */) override {
157         return ndk::ScopedAStatus::ok();
158     }
159     ::ndk::ScopedAStatus
onHs20TermsAndConditionsAcceptanceRequestedNotification(const std::vector<uint8_t> &,const std::string &)160     onHs20TermsAndConditionsAcceptanceRequestedNotification(
161         const std::vector<uint8_t>& /* bssid */,
162         const std::string& /* url */) override {
163         return ndk::ScopedAStatus::ok();
164     }
onNetworkAdded(int32_t)165     ::ndk::ScopedAStatus onNetworkAdded(int32_t /* id */) override {
166         return ndk::ScopedAStatus::ok();
167     }
onNetworkNotFound(const std::vector<uint8_t> &)168     ::ndk::ScopedAStatus onNetworkNotFound(
169         const std::vector<uint8_t>& /* ssid */) override {
170         return ndk::ScopedAStatus::ok();
171     }
onNetworkRemoved(int32_t)172     ::ndk::ScopedAStatus onNetworkRemoved(int32_t /* id */) override {
173         return ndk::ScopedAStatus::ok();
174     }
onPmkCacheAdded(int64_t,const std::vector<uint8_t> &)175     ::ndk::ScopedAStatus onPmkCacheAdded(
176         int64_t /* expirationTimeInSec */,
177         const std::vector<uint8_t>& /* serializedEntry */) override {
178         return ndk::ScopedAStatus::ok();
179     }
onStateChanged(::aidl::android::hardware::wifi::supplicant::StaIfaceCallbackState,const std::vector<uint8_t> &,int32_t,const std::vector<uint8_t> &,bool)180     ::ndk::ScopedAStatus onStateChanged(
181         ::aidl::android::hardware::wifi::supplicant::
182             StaIfaceCallbackState /* newState */,
183         const std::vector<uint8_t>& /* bssid */, int32_t /* id */,
184         const std::vector<uint8_t>& /* ssid */,
185         bool /* filsHlpSent */) override {
186         return ndk::ScopedAStatus::ok();
187     }
onWpsEventFail(const std::vector<uint8_t> &,::aidl::android::hardware::wifi::supplicant::WpsConfigError,::aidl::android::hardware::wifi::supplicant::WpsErrorIndication)188     ::ndk::ScopedAStatus onWpsEventFail(
189         const std::vector<uint8_t>& /* bssid */,
190         ::aidl::android::hardware::wifi::supplicant::
191             WpsConfigError /* configError */,
192         ::aidl::android::hardware::wifi::supplicant::
193             WpsErrorIndication /* errorInd */) override {
194         return ndk::ScopedAStatus::ok();
195     }
onWpsEventPbcOverlap()196     ::ndk::ScopedAStatus onWpsEventPbcOverlap() override {
197         return ndk::ScopedAStatus::ok();
198     }
onWpsEventSuccess()199     ::ndk::ScopedAStatus onWpsEventSuccess() override {
200         return ndk::ScopedAStatus::ok();
201     }
onQosPolicyReset()202     ::ndk::ScopedAStatus onQosPolicyReset() override { return ndk::ScopedAStatus::ok(); }
onQosPolicyRequest(int32_t,const std::vector<::aidl::android::hardware::wifi::supplicant::QosPolicyData> &)203     ::ndk::ScopedAStatus onQosPolicyRequest(
204             int32_t /* qosPolicyRequestId */,
205             const std::vector<::aidl::android::hardware::wifi::supplicant ::
206                                       QosPolicyData /* qosPolicyData */>&) override {
207         return ndk::ScopedAStatus::ok();
208     }
209 };
210 
211 class SupplicantStaIfaceAidlTest : public testing::TestWithParam<std::string> {
212    public:
SetUp()213     void SetUp() override {
214         initializeService();
215         supplicant_ = getSupplicant(GetParam().c_str());
216         ASSERT_NE(supplicant_, nullptr);
217         ASSERT_TRUE(supplicant_
218                         ->setDebugParams(DebugLevel::EXCESSIVE,
219                                          true,  // show timestamps
220                                          true)
221                         .isOk());
222         EXPECT_TRUE(supplicant_->getStaInterface(getStaIfaceName(), &sta_iface_)
223                         .isOk());
224         ASSERT_NE(sta_iface_, nullptr);
225     }
226 
TearDown()227     void TearDown() override {
228         stopSupplicantService();
229         startWifiFramework();
230     }
231 
232     enum DppCallbackType {
233         ANY_CALLBACK = -2,
234         INVALID = -1,
235         EVENT_SUCCESS = 0,
236         EVENT_PROGRESS,
237         EVENT_FAILURE,
238     };
239 
240     DppCallbackType dppCallbackType;
241     uint32_t code;
242 
243     // Used as a mechanism to inform the test about data/event callback
notify()244     inline void notify() {
245         std::unique_lock<std::mutex> lock(mtx_);
246         cv_.notify_one();
247     }
248 
249     // Test code calls this function to wait for data/event callback
wait(DppCallbackType waitForCallbackType)250     inline std::cv_status wait(DppCallbackType waitForCallbackType) {
251         std::unique_lock<std::mutex> lock(mtx_);
252         EXPECT_NE(INVALID, waitForCallbackType);  // can't ASSERT in a
253                                                   // non-void-returning method
254         auto now = std::chrono::system_clock::now();
255         std::cv_status status =
256             cv_.wait_until(lock, now + std::chrono::seconds(TIMEOUT_PERIOD));
257         return status;
258     }
259 
260    protected:
261     std::shared_ptr<ISupplicant> supplicant_;
262     std::shared_ptr<ISupplicantStaIface> sta_iface_;
263 
264    private:
265     // synchronization objects
266     std::mutex mtx_;
267     std::condition_variable cv_;
268 };
269 
270 /*
271  * RegisterCallback
272  */
TEST_P(SupplicantStaIfaceAidlTest,RegisterCallback)273 TEST_P(SupplicantStaIfaceAidlTest, RegisterCallback) {
274     std::shared_ptr<SupplicantStaIfaceCallback> callback =
275         ndk::SharedRefBase::make<SupplicantStaIfaceCallback>();
276     ASSERT_NE(callback, nullptr);
277     EXPECT_TRUE(sta_iface_->registerCallback(callback).isOk());
278 }
279 
280 /*
281  * GetConnectionCapabilities
282  */
TEST_P(SupplicantStaIfaceAidlTest,GetConnectionCapabilities)283 TEST_P(SupplicantStaIfaceAidlTest, GetConnectionCapabilities) {
284     ConnectionCapabilities cap;
285     EXPECT_TRUE(sta_iface_->getConnectionCapabilities(&cap).isOk());
286 }
287 
288 /*
289  * GetWpaDriverCapabilities
290  */
TEST_P(SupplicantStaIfaceAidlTest,GetWpaDriverCapabilities)291 TEST_P(SupplicantStaIfaceAidlTest, GetWpaDriverCapabilities) {
292     WpaDriverCapabilitiesMask cap;
293     EXPECT_TRUE(sta_iface_->getWpaDriverCapabilities(&cap).isOk());
294 }
295 
296 /*
297  * GetKeyMgmtCapabilities
298  */
TEST_P(SupplicantStaIfaceAidlTest,GetKeyMgmtCapabilities)299 TEST_P(SupplicantStaIfaceAidlTest, GetKeyMgmtCapabilities) {
300     KeyMgmtMask cap;
301     EXPECT_TRUE(sta_iface_->getKeyMgmtCapabilities(&cap).isOk());
302 
303     // Even though capabilities vary, these two are always set.
304     EXPECT_TRUE(!!(static_cast<uint32_t>(cap) &
305                    static_cast<uint32_t>(KeyMgmtMask::NONE)));
306     EXPECT_TRUE(!!(static_cast<uint32_t>(cap) &
307                    static_cast<uint32_t>(KeyMgmtMask::IEEE8021X)));
308 }
309 
310 /*
311  * GetName
312  */
TEST_P(SupplicantStaIfaceAidlTest,GetName)313 TEST_P(SupplicantStaIfaceAidlTest, GetName) {
314     std::string name;
315     EXPECT_TRUE(sta_iface_->getName(&name).isOk());
316     EXPECT_NE(name.size(), 0);
317 }
318 
319 /*
320  * GetType
321  */
TEST_P(SupplicantStaIfaceAidlTest,GetType)322 TEST_P(SupplicantStaIfaceAidlTest, GetType) {
323     IfaceType type;
324     EXPECT_TRUE(sta_iface_->getType(&type).isOk());
325     EXPECT_EQ(type, IfaceType::STA);
326 }
327 
328 /*
329  * GetMacAddress
330  */
TEST_P(SupplicantStaIfaceAidlTest,GetMacAddress)331 TEST_P(SupplicantStaIfaceAidlTest, GetMacAddress) {
332     std::vector<uint8_t> macAddr;
333     EXPECT_TRUE(sta_iface_->getMacAddress(&macAddr).isOk());
334     EXPECT_EQ(macAddr.size(), 6);
335 }
336 
337 /*
338  * ListNetworks
339  */
TEST_P(SupplicantStaIfaceAidlTest,ListNetworks)340 TEST_P(SupplicantStaIfaceAidlTest, ListNetworks) {
341     std::vector<int32_t> networks;
342     EXPECT_TRUE(sta_iface_->listNetworks(&networks).isOk());
343 }
344 
345 /*
346  * SetBtCoexistenceMode
347  */
TEST_P(SupplicantStaIfaceAidlTest,SetBtCoexistenceMode)348 TEST_P(SupplicantStaIfaceAidlTest, SetBtCoexistenceMode) {
349     EXPECT_TRUE(
350         sta_iface_->setBtCoexistenceMode(BtCoexistenceMode::ENABLED).isOk());
351     EXPECT_TRUE(
352         sta_iface_->setBtCoexistenceMode(BtCoexistenceMode::DISABLED).isOk());
353     EXPECT_TRUE(
354         sta_iface_->setBtCoexistenceMode(BtCoexistenceMode::SENSE).isOk());
355 }
356 
357 /*
358  * SetBtCoexistenceScanModeEnabled
359  */
TEST_P(SupplicantStaIfaceAidlTest,SetBtCoexistenceScanModeEnabled)360 TEST_P(SupplicantStaIfaceAidlTest, SetBtCoexistenceScanModeEnabled) {
361     EXPECT_TRUE(sta_iface_->setBtCoexistenceScanModeEnabled(true).isOk());
362     EXPECT_TRUE(sta_iface_->setBtCoexistenceScanModeEnabled(false).isOk());
363 }
364 
365 /*
366  * SetSuspendModeEnabled
367  */
TEST_P(SupplicantStaIfaceAidlTest,SetSuspendModeEnabled)368 TEST_P(SupplicantStaIfaceAidlTest, SetSuspendModeEnabled) {
369     EXPECT_TRUE(sta_iface_->setSuspendModeEnabled(true).isOk());
370     EXPECT_TRUE(sta_iface_->setSuspendModeEnabled(false).isOk());
371 }
372 
373 /*
374  * SetCountryCode
375  */
TEST_P(SupplicantStaIfaceAidlTest,SetCountryCode)376 TEST_P(SupplicantStaIfaceAidlTest, SetCountryCode) {
377     const std::vector<uint8_t> countryCode = {'M', 'X'};
378     EXPECT_TRUE(sta_iface_->setCountryCode(countryCode).isOk());
379 }
380 
381 /*
382  * SetWpsDeviceName
383  */
TEST_P(SupplicantStaIfaceAidlTest,SetWpsDeviceName)384 TEST_P(SupplicantStaIfaceAidlTest, SetWpsDeviceName) {
385     const std::string deviceName = "TestWpsDeviceName";
386     EXPECT_TRUE(sta_iface_->setWpsDeviceName(deviceName).isOk());
387 }
388 
389 /*
390  * SetWpsDeviceType
391  */
TEST_P(SupplicantStaIfaceAidlTest,SetWpsDeviceType)392 TEST_P(SupplicantStaIfaceAidlTest, SetWpsDeviceType) {
393     const std::vector<uint8_t> deviceType = {8, 0x1};
394     EXPECT_TRUE(sta_iface_->setWpsDeviceType(deviceType).isOk());
395 }
396 
397 /*
398  * SetWpsManufacturer
399  */
TEST_P(SupplicantStaIfaceAidlTest,SetWpsManufacturer)400 TEST_P(SupplicantStaIfaceAidlTest, SetWpsManufacturer) {
401     const std::string wpsManufacturer = "TestManufacturer";
402     EXPECT_TRUE(sta_iface_->setWpsManufacturer(wpsManufacturer).isOk());
403 }
404 
405 /*
406  * SetWpsModelName
407  */
TEST_P(SupplicantStaIfaceAidlTest,SetWpsModelName)408 TEST_P(SupplicantStaIfaceAidlTest, SetWpsModelName) {
409     const std::string modelName = "TestModelName";
410     EXPECT_TRUE(sta_iface_->setWpsModelName(modelName).isOk());
411 }
412 
413 /*
414  * SetWpsModelNumber
415  */
TEST_P(SupplicantStaIfaceAidlTest,SetWpsModelNumber)416 TEST_P(SupplicantStaIfaceAidlTest, SetWpsModelNumber) {
417     const std::string modelNumber = "TestModelNumber";
418     EXPECT_TRUE(sta_iface_->setWpsModelNumber(modelNumber).isOk());
419 }
420 
421 /*
422  * SetWpsSerialNumber
423  */
TEST_P(SupplicantStaIfaceAidlTest,SetWpsSerialNumber)424 TEST_P(SupplicantStaIfaceAidlTest, SetWpsSerialNumber) {
425     const std::string serialNumber = "TestSerialNumber";
426     EXPECT_TRUE(sta_iface_->setWpsSerialNumber(serialNumber).isOk());
427 }
428 
429 /*
430  * SetWpsConfigMethods
431  */
TEST_P(SupplicantStaIfaceAidlTest,SetWpsConfigMethods)432 TEST_P(SupplicantStaIfaceAidlTest, SetWpsConfigMethods) {
433     const WpsConfigMethods configMethods = WpsConfigMethods::KEYPAD;
434     EXPECT_TRUE(sta_iface_->setWpsConfigMethods(configMethods).isOk());
435 }
436 
437 /*
438  * SetExternalSim
439  */
TEST_P(SupplicantStaIfaceAidlTest,SetExternalSim)440 TEST_P(SupplicantStaIfaceAidlTest, SetExternalSim) {
441     EXPECT_TRUE(sta_iface_->setExternalSim(true).isOk());
442     EXPECT_TRUE(sta_iface_->setExternalSim(false).isOk());
443 }
444 
445 /*
446  * SetMboCellularDataStatus
447  */
TEST_P(SupplicantStaIfaceAidlTest,SetMboCellularDataStatus)448 TEST_P(SupplicantStaIfaceAidlTest, SetMboCellularDataStatus) {
449     WpaDriverCapabilitiesMask cap;
450     EXPECT_TRUE(sta_iface_->getWpaDriverCapabilities(&cap).isOk());
451 
452     // Operation should succeed if MBO is supported, or fail if it's not.
453     bool mboSupported =
454         !!(static_cast<uint32_t>(cap) &
455            static_cast<uint32_t>(WpaDriverCapabilitiesMask::MBO));
456     EXPECT_EQ(mboSupported, sta_iface_->setMboCellularDataStatus(true).isOk());
457 }
458 
459 /*
460  * InitiateTdlsDiscover
461  */
TEST_P(SupplicantStaIfaceAidlTest,InitiateTdlsDiscover)462 TEST_P(SupplicantStaIfaceAidlTest, InitiateTdlsDiscover) {
463     EXPECT_TRUE(sta_iface_->initiateTdlsDiscover(kTestMacAddr).isOk());
464 }
465 
466 /*
467  * InitiateTdlsSetup
468  */
TEST_P(SupplicantStaIfaceAidlTest,InitiateTdlsSetup)469 TEST_P(SupplicantStaIfaceAidlTest, InitiateTdlsSetup) {
470     EXPECT_TRUE(sta_iface_->initiateTdlsSetup(kTestMacAddr).isOk());
471 }
472 
473 /*
474  * InitiateTdlsTeardown
475  */
TEST_P(SupplicantStaIfaceAidlTest,InitiateTdlsTeardown)476 TEST_P(SupplicantStaIfaceAidlTest, InitiateTdlsTeardown) {
477     EXPECT_TRUE(sta_iface_->initiateTdlsTeardown(kTestMacAddr).isOk());
478 }
479 
480 /*
481  * InitiateAnqpQuery
482  */
TEST_P(SupplicantStaIfaceAidlTest,InitiateAnqpQuery)483 TEST_P(SupplicantStaIfaceAidlTest, InitiateAnqpQuery) {
484     const std::vector<AnqpInfoId> anqpIds = {
485         AnqpInfoId::VENUE_NAME, AnqpInfoId::NAI_REALM, AnqpInfoId::DOMAIN_NAME};
486     const std::vector<Hs20AnqpSubtypes> hsTypes = {
487         Hs20AnqpSubtypes::WAN_METRICS,
488         Hs20AnqpSubtypes::OPERATOR_FRIENDLY_NAME};
489 
490     // Request should fail since the BSSID mentioned
491     // is not present in the scan results
492     EXPECT_FALSE(
493         sta_iface_->initiateAnqpQuery(kTestMacAddr, anqpIds, hsTypes).isOk());
494 }
495 
496 /*
497  * InitiateHs20IconQuery
498  */
TEST_P(SupplicantStaIfaceAidlTest,InitiateHs20IconQuery)499 TEST_P(SupplicantStaIfaceAidlTest, InitiateHs20IconQuery) {
500     // Request should fail since the BSSID mentioned
501     // is not present in the scan results
502     const std::string hs20IconFile = "TestFile";
503     EXPECT_FALSE(
504         sta_iface_->initiateHs20IconQuery(kTestMacAddr, hs20IconFile).isOk());
505 }
506 
507 /*
508  * InitiateVenueUrlAnqpQuery.
509  */
TEST_P(SupplicantStaIfaceAidlTest,InitiateVenueUrlAnqpQuery)510 TEST_P(SupplicantStaIfaceAidlTest, InitiateVenueUrlAnqpQuery) {
511     // Request should fail since the BSSID mentioned
512     // is not present in the scan results
513     EXPECT_FALSE(sta_iface_->initiateVenueUrlAnqpQuery(kTestMacAddr).isOk());
514 }
515 
516 /*
517  * Reassociate
518  */
TEST_P(SupplicantStaIfaceAidlTest,Reassociate)519 TEST_P(SupplicantStaIfaceAidlTest, Reassociate) {
520     EXPECT_TRUE(sta_iface_->reassociate().isOk());
521 }
522 
523 /*
524  * Reconnect
525  */
TEST_P(SupplicantStaIfaceAidlTest,Reconnect)526 TEST_P(SupplicantStaIfaceAidlTest, Reconnect) {
527     EXPECT_FALSE(sta_iface_->reconnect().isOk());
528 }
529 
530 /*
531  * Disconnect
532  */
TEST_P(SupplicantStaIfaceAidlTest,Disconnect)533 TEST_P(SupplicantStaIfaceAidlTest, Disconnect) {
534     EXPECT_TRUE(sta_iface_->disconnect().isOk());
535 }
536 
537 /*
538  * SetPowerSave
539  */
TEST_P(SupplicantStaIfaceAidlTest,SetPowerSave)540 TEST_P(SupplicantStaIfaceAidlTest, SetPowerSave) {
541     EXPECT_TRUE(sta_iface_->setPowerSave(true).isOk());
542     EXPECT_TRUE(sta_iface_->setPowerSave(false).isOk());
543 }
544 
545 /*
546  * AddExtRadioWork
547  */
TEST_P(SupplicantStaIfaceAidlTest,AddExtRadioWork)548 TEST_P(SupplicantStaIfaceAidlTest, AddExtRadioWork) {
549     const std::string radioWorkName = "TestRadioWork";
550     const int32_t radioWorkFreq = 2412;
551     const int32_t radioWorkTimeout = 8;
552     int32_t radioWorkId;
553     EXPECT_TRUE(sta_iface_
554                     ->addExtRadioWork(radioWorkName, radioWorkFreq,
555                                       radioWorkTimeout, &radioWorkId)
556                     .isOk());
557     // removeExtRadio only succeeds if the added radio work hasn't started yet,
558     // so there is no guaranteed result from calling removeExtRadioWork here.
559     // Given that, we can't currently test removeExtRadioWork following
560     // a call to addExtRadioWork.
561 }
562 
563 /*
564  * RemoveExtRadioWork
565  */
TEST_P(SupplicantStaIfaceAidlTest,RemoveExtRadioWork)566 TEST_P(SupplicantStaIfaceAidlTest, RemoveExtRadioWork) {
567     // This fails because there is no ongoing radio work with radioWorkId
568     const int32_t radioWorkId = 16;
569     EXPECT_FALSE(sta_iface_->removeExtRadioWork(radioWorkId).isOk());
570 }
571 
572 /*
573  * Add/Remove DppPeerUri
574  */
TEST_P(SupplicantStaIfaceAidlTest,AddRemoveDppPeerUri)575 TEST_P(SupplicantStaIfaceAidlTest, AddRemoveDppPeerUri) {
576     if (!keyMgmtSupported(sta_iface_, KeyMgmtMask::DPP)) {
577         GTEST_SKIP() << "Missing DPP support";
578     }
579     // Add a peer URI and then remove it.
580     int32_t peerId;
581     EXPECT_TRUE(sta_iface_->addDppPeerUri(kTestUri, &peerId).isOk());
582     EXPECT_TRUE(sta_iface_->removeDppUri(peerId).isOk());
583 }
584 
585 /*
586  * FilsHlpAddRequest
587  */
TEST_P(SupplicantStaIfaceAidlTest,FilsHlpAddRequest)588 TEST_P(SupplicantStaIfaceAidlTest, FilsHlpAddRequest) {
589     if (!isFilsSupported(sta_iface_)) {
590         GTEST_SKIP()
591             << "Skipping test since driver/supplicant doesn't support FILS";
592     }
593     const std::vector<uint8_t> destMacAddr = {0x00, 0x11, 0x22,
594                                               0x33, 0x44, 0x55};
595     const std::vector<uint8_t> pktBuffer = std::vector<uint8_t>(300, 0x3a);
596     EXPECT_TRUE(sta_iface_->filsHlpAddRequest(destMacAddr, pktBuffer).isOk());
597 }
598 
599 /*
600  * FilsHlpFlushRequest
601  */
TEST_P(SupplicantStaIfaceAidlTest,FilsHlpFlushRequest)602 TEST_P(SupplicantStaIfaceAidlTest, FilsHlpFlushRequest) {
603     if (!isFilsSupported(sta_iface_)) {
604         GTEST_SKIP()
605             << "Skipping test since driver/supplicant doesn't support FILS";
606     }
607     EXPECT_TRUE(sta_iface_->filsHlpFlushRequest().isOk());
608 }
609 
610 /*
611  * StartDppEnrolleeResponder
612  */
TEST_P(SupplicantStaIfaceAidlTest,StartDppEnrolleeResponder)613 TEST_P(SupplicantStaIfaceAidlTest, StartDppEnrolleeResponder) {
614     if (!keyMgmtSupported(sta_iface_, KeyMgmtMask::DPP)) {
615         GTEST_SKIP() << "Missing DPP support";
616     }
617 
618     const std::string deviceInfo = "DPP_Responder_Mode_VTS_Test";
619     const std::vector<uint8_t> mac_address = {0x22, 0x33, 0x44,
620                                               0x55, 0x66, 0x77};
621 
622     // Generate DPP bootstrap information.
623     DppResponderBootstrapInfo bootstrapInfo;
624     EXPECT_TRUE(
625         sta_iface_
626             ->generateDppBootstrapInfoForResponder(
627                 mac_address, deviceInfo, DppCurve::PRIME256V1, &bootstrapInfo)
628             .isOk());
629     EXPECT_NE(-1, bootstrapInfo.bootstrapId);
630     EXPECT_NE(0, bootstrapInfo.bootstrapId);
631     EXPECT_NE(0, bootstrapInfo.listenChannel);
632     const uint32_t bootstrap_id = bootstrapInfo.bootstrapId;
633     const uint32_t listen_channel = bootstrapInfo.listenChannel;
634 
635     // Start DPP as Enrollee-Responder.
636     EXPECT_TRUE(sta_iface_->startDppEnrolleeResponder(listen_channel).isOk());
637 
638     // Stop DPP Enrollee-Responder mode, ie remove the URI and stop listen.
639     EXPECT_TRUE(sta_iface_->stopDppResponder(bootstrap_id).isOk());
640 }
641 
642 class IfaceDppCallback : public SupplicantStaIfaceCallback {
643     SupplicantStaIfaceAidlTest& parent_;
onDppSuccess(::aidl::android::hardware::wifi::supplicant::DppEventType event)644     ::ndk::ScopedAStatus onDppSuccess(
645         ::aidl::android::hardware::wifi::supplicant::DppEventType event)
646         override {
647         parent_.code = (uint32_t)event;
648         parent_.dppCallbackType =
649             SupplicantStaIfaceAidlTest::DppCallbackType::EVENT_SUCCESS;
650         parent_.notify();
651         return ndk::ScopedAStatus::ok();
652     }
onDppProgress(aidl::android::hardware::wifi::supplicant::DppProgressCode code)653     ::ndk::ScopedAStatus onDppProgress(
654         aidl::android::hardware::wifi::supplicant::DppProgressCode code)
655         override {
656         parent_.code = (uint32_t)code;
657         parent_.dppCallbackType =
658             SupplicantStaIfaceAidlTest::DppCallbackType::EVENT_PROGRESS;
659         parent_.notify();
660         return ndk::ScopedAStatus::ok();
661     }
onDppFailure(aidl::android::hardware::wifi::supplicant::DppFailureCode code,const std::string & ssid,const std::string & channelList,const std::vector<char16_t> & bandList)662     ::ndk::ScopedAStatus onDppFailure(
663         aidl::android::hardware::wifi::supplicant::DppFailureCode code,
664         const std::string& ssid __attribute__((unused)),
665         const std::string& channelList __attribute__((unused)),
666         const std::vector<char16_t>& bandList
667         __attribute__((unused))) override {
668         parent_.code = (uint32_t)code;
669         parent_.dppCallbackType =
670             SupplicantStaIfaceAidlTest::DppCallbackType::EVENT_FAILURE;
671         parent_.notify();
672         return ndk::ScopedAStatus::ok();
673     }
674 
675    public:
IfaceDppCallback(SupplicantStaIfaceAidlTest & parent)676     IfaceDppCallback(SupplicantStaIfaceAidlTest& parent) : parent_(parent){};
677 };
678 
679 /*
680  * StartDppEnrolleeInitiator
681  */
TEST_P(SupplicantStaIfaceAidlTest,StartDppEnrolleeInitiator)682 TEST_P(SupplicantStaIfaceAidlTest, StartDppEnrolleeInitiator) {
683     if (!keyMgmtSupported(sta_iface_, KeyMgmtMask::DPP)) {
684         GTEST_SKIP() << "Missing DPP support";
685     }
686 
687     // Register callback
688     std::shared_ptr<IfaceDppCallback> callback =
689         ndk::SharedRefBase::make<IfaceDppCallback>(*this);
690     EXPECT_NE(callback, nullptr);
691     EXPECT_TRUE(sta_iface_->registerCallback(callback).isOk());
692 
693     // Add a peer URI
694     int32_t peer_id = 0;
695     EXPECT_TRUE(sta_iface_->addDppPeerUri(kTestUri, &peer_id).isOk());
696     EXPECT_NE(0, peer_id);
697     EXPECT_NE(-1, peer_id);
698 
699     // Start DPP as Enrollee-Initiator. Since this operation requires two
700     // devices, we start the operation and expect a timeout.
701     EXPECT_TRUE(sta_iface_->startDppEnrolleeInitiator(peer_id, 0).isOk());
702 
703     // Wait for the timeout callback
704     EXPECT_EQ(std::cv_status::no_timeout,
705               wait(SupplicantStaIfaceAidlTest::DppCallbackType::EVENT_FAILURE));
706     EXPECT_EQ(SupplicantStaIfaceAidlTest::DppCallbackType::EVENT_FAILURE,
707               dppCallbackType);
708 
709     // ...and then remove the peer URI.
710     EXPECT_TRUE(sta_iface_->removeDppUri(peer_id).isOk());
711 }
712 
713 /*
714  * StartDppConfiguratorInitiator
715  */
TEST_P(SupplicantStaIfaceAidlTest,StartDppConfiguratorInitiator)716 TEST_P(SupplicantStaIfaceAidlTest, StartDppConfiguratorInitiator) {
717     if (!keyMgmtSupported(sta_iface_, KeyMgmtMask::DPP)) {
718         GTEST_SKIP() << "Missing DPP support";
719     }
720 
721     // Register callback
722     std::shared_ptr<IfaceDppCallback> callback =
723         ndk::SharedRefBase::make<IfaceDppCallback>(*this);
724     EXPECT_NE(callback, nullptr);
725     EXPECT_TRUE(sta_iface_->registerCallback(callback).isOk());
726 
727     // Add a peer URI
728     int32_t peer_id = 0;
729     EXPECT_TRUE(sta_iface_->addDppPeerUri(kTestUri, &peer_id).isOk());
730     EXPECT_NE(0, peer_id);
731     EXPECT_NE(-1, peer_id);
732 
733     const std::string ssid =
734         "6D795F746573745F73736964";  // 'my_test_ssid' encoded in hex
735     const std::string password =
736         "746F70736563726574";  // 'topsecret' encoded in hex
737     const std::vector<uint8_t> eckey_in = {0x2, 0x3, 0x4};
738     std::vector<uint8_t> eckey_out = {};
739 
740     // Start DPP as Configurator-Initiator. Since this operation requires two
741     // devices, we start the operation and expect a timeout.
742     EXPECT_TRUE(sta_iface_
743                         ->startDppConfiguratorInitiator(peer_id, 0, ssid, password, "",
744                                                         DppNetRole::STA, DppAkm::PSK, eckey_in,
745                                                         &eckey_out)
746                         .isOk());
747 
748     // Wait for the timeout callback
749     ASSERT_EQ(std::cv_status::no_timeout,
750               wait(SupplicantStaIfaceAidlTest::DppCallbackType::EVENT_FAILURE));
751     ASSERT_EQ(SupplicantStaIfaceAidlTest::DppCallbackType::EVENT_FAILURE,
752               dppCallbackType);
753 
754     // ...and then remove the peer URI.
755     EXPECT_TRUE(sta_iface_->removeDppUri(peer_id).isOk());
756 }
757 
758 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(SupplicantStaIfaceAidlTest);
759 INSTANTIATE_TEST_SUITE_P(Supplicant, SupplicantStaIfaceAidlTest,
760                          testing::ValuesIn(android::getAidlHalInstanceNames(
761                              ISupplicant::descriptor)),
762                          android::PrintInstanceNameToString);
763 
main(int argc,char ** argv)764 int main(int argc, char** argv) {
765     ::testing::InitGoogleTest(&argc, argv);
766     ProcessState::self()->setThreadPoolMaxThreadCount(1);
767     ProcessState::self()->startThreadPool();
768     return RUN_ALL_TESTS();
769 }
770