• 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     }
onSupplicantStateChanged(const::aidl::android::hardware::wifi::supplicant::SupplicantStateChangeData &)209     ::ndk::ScopedAStatus onSupplicantStateChanged(
210             const ::aidl::android::hardware::wifi::supplicant::
211                     SupplicantStateChangeData& /* stateChangeData */) override {
212         return ndk::ScopedAStatus::ok();
213     }
onMloLinksInfoChanged(::aidl::android::hardware::wifi::supplicant::ISupplicantStaIfaceCallback::MloLinkInfoChangeReason)214     ::ndk::ScopedAStatus onMloLinksInfoChanged(
215             ::aidl::android::hardware::wifi::supplicant::ISupplicantStaIfaceCallback::
216                     MloLinkInfoChangeReason /* reason */) override {
217         return ndk::ScopedAStatus::ok();
218     }
onDppConfigReceived(const::aidl::android::hardware::wifi::supplicant::DppConfigurationData &)219     ::ndk::ScopedAStatus onDppConfigReceived(
220             const ::aidl::android::hardware::wifi::supplicant::
221                     DppConfigurationData& /* configData */) override {
222         return ndk::ScopedAStatus::ok();
223     }
onDppConnectionStatusResultSent(::aidl::android::hardware::wifi::supplicant::DppStatusErrorCode)224     ::ndk::ScopedAStatus onDppConnectionStatusResultSent(
225             ::aidl::android::hardware::wifi::supplicant::DppStatusErrorCode /* code */) override {
226         return ndk::ScopedAStatus::ok();
227     }
onBssFrequencyChanged(int32_t)228     ::ndk::ScopedAStatus onBssFrequencyChanged(int32_t /* frequencyMhz */) override {
229         return ndk::ScopedAStatus::ok();
230     }
onQosPolicyResponseForScs(const std::vector<::aidl::android::hardware::wifi::supplicant::QosPolicyScsResponseStatus> &)231     ::ndk::ScopedAStatus onQosPolicyResponseForScs(
232             const std::vector<::aidl::android::hardware::wifi::supplicant::
233                                       QosPolicyScsResponseStatus>& /* qosPolicyScsResponseStatus */)
234             override {
235         return ndk::ScopedAStatus::ok();
236     }
onPmkSaCacheAdded(const::aidl::android::hardware::wifi::supplicant::PmkSaCacheData &)237     ::ndk::ScopedAStatus onPmkSaCacheAdded(
238             const ::aidl::android::hardware::wifi::supplicant::PmkSaCacheData& /* pmkSaData */)
239             override {
240         return ndk::ScopedAStatus::ok();
241     }
242 };
243 
244 class SupplicantStaIfaceAidlTest : public testing::TestWithParam<std::string> {
245    public:
SetUp()246     void SetUp() override {
247         initializeService();
248         supplicant_ = getSupplicant(GetParam().c_str());
249         ASSERT_NE(supplicant_, nullptr);
250         ASSERT_TRUE(supplicant_
251                         ->setDebugParams(DebugLevel::EXCESSIVE,
252                                          true,  // show timestamps
253                                          true)
254                         .isOk());
255         EXPECT_TRUE(supplicant_->getStaInterface(getStaIfaceName(), &sta_iface_)
256                         .isOk());
257         ASSERT_NE(sta_iface_, nullptr);
258     }
259 
TearDown()260     void TearDown() override {
261         stopSupplicantService();
262         startWifiFramework();
263     }
264 
265     enum DppCallbackType {
266         ANY_CALLBACK = -2,
267         INVALID = -1,
268         EVENT_SUCCESS = 0,
269         EVENT_PROGRESS,
270         EVENT_FAILURE,
271     };
272 
273     DppCallbackType dppCallbackType;
274     uint32_t code;
275 
276     // Used as a mechanism to inform the test about data/event callback
notify()277     inline void notify() {
278         std::unique_lock<std::mutex> lock(mtx_);
279         cv_.notify_one();
280     }
281 
282     // Test code calls this function to wait for data/event callback
wait(DppCallbackType waitForCallbackType)283     inline std::cv_status wait(DppCallbackType waitForCallbackType) {
284         std::unique_lock<std::mutex> lock(mtx_);
285         EXPECT_NE(INVALID, waitForCallbackType);  // can't ASSERT in a
286                                                   // non-void-returning method
287         auto now = std::chrono::system_clock::now();
288         std::cv_status status =
289             cv_.wait_until(lock, now + std::chrono::seconds(TIMEOUT_PERIOD));
290         return status;
291     }
292 
293    protected:
294     std::shared_ptr<ISupplicant> supplicant_;
295     std::shared_ptr<ISupplicantStaIface> sta_iface_;
296 
297    private:
298     // synchronization objects
299     std::mutex mtx_;
300     std::condition_variable cv_;
301 };
302 
303 /*
304  * RegisterCallback
305  */
TEST_P(SupplicantStaIfaceAidlTest,RegisterCallback)306 TEST_P(SupplicantStaIfaceAidlTest, RegisterCallback) {
307     std::shared_ptr<SupplicantStaIfaceCallback> callback =
308         ndk::SharedRefBase::make<SupplicantStaIfaceCallback>();
309     ASSERT_NE(callback, nullptr);
310     EXPECT_TRUE(sta_iface_->registerCallback(callback).isOk());
311 }
312 
313 /*
314  * GetConnectionCapabilities
315  */
TEST_P(SupplicantStaIfaceAidlTest,GetConnectionCapabilities)316 TEST_P(SupplicantStaIfaceAidlTest, GetConnectionCapabilities) {
317     ConnectionCapabilities cap;
318     EXPECT_TRUE(sta_iface_->getConnectionCapabilities(&cap).isOk());
319 }
320 
321 /*
322  * GetWpaDriverCapabilities
323  */
TEST_P(SupplicantStaIfaceAidlTest,GetWpaDriverCapabilities)324 TEST_P(SupplicantStaIfaceAidlTest, GetWpaDriverCapabilities) {
325     WpaDriverCapabilitiesMask cap;
326     EXPECT_TRUE(sta_iface_->getWpaDriverCapabilities(&cap).isOk());
327 }
328 
329 /*
330  * GetKeyMgmtCapabilities
331  */
TEST_P(SupplicantStaIfaceAidlTest,GetKeyMgmtCapabilities)332 TEST_P(SupplicantStaIfaceAidlTest, GetKeyMgmtCapabilities) {
333     KeyMgmtMask cap;
334     EXPECT_TRUE(sta_iface_->getKeyMgmtCapabilities(&cap).isOk());
335 
336     // Even though capabilities vary, these two are always set.
337     EXPECT_TRUE(!!(static_cast<uint32_t>(cap) &
338                    static_cast<uint32_t>(KeyMgmtMask::NONE)));
339     EXPECT_TRUE(!!(static_cast<uint32_t>(cap) &
340                    static_cast<uint32_t>(KeyMgmtMask::IEEE8021X)));
341 }
342 
343 /*
344  * GetName
345  */
TEST_P(SupplicantStaIfaceAidlTest,GetName)346 TEST_P(SupplicantStaIfaceAidlTest, GetName) {
347     std::string name;
348     EXPECT_TRUE(sta_iface_->getName(&name).isOk());
349     EXPECT_NE(name.size(), 0);
350 }
351 
352 /*
353  * GetType
354  */
TEST_P(SupplicantStaIfaceAidlTest,GetType)355 TEST_P(SupplicantStaIfaceAidlTest, GetType) {
356     IfaceType type;
357     EXPECT_TRUE(sta_iface_->getType(&type).isOk());
358     EXPECT_EQ(type, IfaceType::STA);
359 }
360 
361 /*
362  * GetMacAddress
363  */
TEST_P(SupplicantStaIfaceAidlTest,GetMacAddress)364 TEST_P(SupplicantStaIfaceAidlTest, GetMacAddress) {
365     std::vector<uint8_t> macAddr;
366     EXPECT_TRUE(sta_iface_->getMacAddress(&macAddr).isOk());
367     EXPECT_EQ(macAddr.size(), 6);
368 }
369 
370 /*
371  * ListNetworks
372  */
TEST_P(SupplicantStaIfaceAidlTest,ListNetworks)373 TEST_P(SupplicantStaIfaceAidlTest, ListNetworks) {
374     std::vector<int32_t> networks;
375     EXPECT_TRUE(sta_iface_->listNetworks(&networks).isOk());
376 }
377 
378 /*
379  * SetBtCoexistenceMode
380  */
TEST_P(SupplicantStaIfaceAidlTest,SetBtCoexistenceMode)381 TEST_P(SupplicantStaIfaceAidlTest, SetBtCoexistenceMode) {
382     EXPECT_TRUE(
383         sta_iface_->setBtCoexistenceMode(BtCoexistenceMode::ENABLED).isOk());
384     EXPECT_TRUE(
385         sta_iface_->setBtCoexistenceMode(BtCoexistenceMode::DISABLED).isOk());
386     EXPECT_TRUE(
387         sta_iface_->setBtCoexistenceMode(BtCoexistenceMode::SENSE).isOk());
388 }
389 
390 /*
391  * SetBtCoexistenceScanModeEnabled
392  */
TEST_P(SupplicantStaIfaceAidlTest,SetBtCoexistenceScanModeEnabled)393 TEST_P(SupplicantStaIfaceAidlTest, SetBtCoexistenceScanModeEnabled) {
394     EXPECT_TRUE(sta_iface_->setBtCoexistenceScanModeEnabled(true).isOk());
395     EXPECT_TRUE(sta_iface_->setBtCoexistenceScanModeEnabled(false).isOk());
396 }
397 
398 /*
399  * SetSuspendModeEnabled
400  */
TEST_P(SupplicantStaIfaceAidlTest,SetSuspendModeEnabled)401 TEST_P(SupplicantStaIfaceAidlTest, SetSuspendModeEnabled) {
402     EXPECT_TRUE(sta_iface_->setSuspendModeEnabled(true).isOk());
403     EXPECT_TRUE(sta_iface_->setSuspendModeEnabled(false).isOk());
404 }
405 
406 /*
407  * SetCountryCode
408  */
TEST_P(SupplicantStaIfaceAidlTest,SetCountryCode)409 TEST_P(SupplicantStaIfaceAidlTest, SetCountryCode) {
410     const std::vector<uint8_t> countryCode = {'M', 'X'};
411     EXPECT_TRUE(sta_iface_->setCountryCode(countryCode).isOk());
412 }
413 
414 /*
415  * SetWpsDeviceName
416  */
TEST_P(SupplicantStaIfaceAidlTest,SetWpsDeviceName)417 TEST_P(SupplicantStaIfaceAidlTest, SetWpsDeviceName) {
418     const std::string deviceName = "TestWpsDeviceName";
419     EXPECT_TRUE(sta_iface_->setWpsDeviceName(deviceName).isOk());
420 }
421 
422 /*
423  * SetWpsDeviceType
424  */
TEST_P(SupplicantStaIfaceAidlTest,SetWpsDeviceType)425 TEST_P(SupplicantStaIfaceAidlTest, SetWpsDeviceType) {
426     const std::vector<uint8_t> deviceType = {8, 0x1};
427     EXPECT_TRUE(sta_iface_->setWpsDeviceType(deviceType).isOk());
428 }
429 
430 /*
431  * SetWpsManufacturer
432  */
TEST_P(SupplicantStaIfaceAidlTest,SetWpsManufacturer)433 TEST_P(SupplicantStaIfaceAidlTest, SetWpsManufacturer) {
434     const std::string wpsManufacturer = "TestManufacturer";
435     EXPECT_TRUE(sta_iface_->setWpsManufacturer(wpsManufacturer).isOk());
436 }
437 
438 /*
439  * SetWpsModelName
440  */
TEST_P(SupplicantStaIfaceAidlTest,SetWpsModelName)441 TEST_P(SupplicantStaIfaceAidlTest, SetWpsModelName) {
442     const std::string modelName = "TestModelName";
443     EXPECT_TRUE(sta_iface_->setWpsModelName(modelName).isOk());
444 }
445 
446 /*
447  * SetWpsModelNumber
448  */
TEST_P(SupplicantStaIfaceAidlTest,SetWpsModelNumber)449 TEST_P(SupplicantStaIfaceAidlTest, SetWpsModelNumber) {
450     const std::string modelNumber = "TestModelNumber";
451     EXPECT_TRUE(sta_iface_->setWpsModelNumber(modelNumber).isOk());
452 }
453 
454 /*
455  * SetWpsSerialNumber
456  */
TEST_P(SupplicantStaIfaceAidlTest,SetWpsSerialNumber)457 TEST_P(SupplicantStaIfaceAidlTest, SetWpsSerialNumber) {
458     const std::string serialNumber = "TestSerialNumber";
459     EXPECT_TRUE(sta_iface_->setWpsSerialNumber(serialNumber).isOk());
460 }
461 
462 /*
463  * SetWpsConfigMethods
464  */
TEST_P(SupplicantStaIfaceAidlTest,SetWpsConfigMethods)465 TEST_P(SupplicantStaIfaceAidlTest, SetWpsConfigMethods) {
466     const WpsConfigMethods configMethods = WpsConfigMethods::KEYPAD;
467     EXPECT_TRUE(sta_iface_->setWpsConfigMethods(configMethods).isOk());
468 }
469 
470 /*
471  * SetExternalSim
472  */
TEST_P(SupplicantStaIfaceAidlTest,SetExternalSim)473 TEST_P(SupplicantStaIfaceAidlTest, SetExternalSim) {
474     EXPECT_TRUE(sta_iface_->setExternalSim(true).isOk());
475     EXPECT_TRUE(sta_iface_->setExternalSim(false).isOk());
476 }
477 
478 /*
479  * SetMboCellularDataStatus
480  */
TEST_P(SupplicantStaIfaceAidlTest,SetMboCellularDataStatus)481 TEST_P(SupplicantStaIfaceAidlTest, SetMboCellularDataStatus) {
482     WpaDriverCapabilitiesMask cap;
483     EXPECT_TRUE(sta_iface_->getWpaDriverCapabilities(&cap).isOk());
484 
485     // Operation should succeed if MBO is supported, or fail if it's not.
486     bool mboSupported =
487         !!(static_cast<uint32_t>(cap) &
488            static_cast<uint32_t>(WpaDriverCapabilitiesMask::MBO));
489     EXPECT_EQ(mboSupported, sta_iface_->setMboCellularDataStatus(true).isOk());
490 }
491 
492 /*
493  * InitiateTdlsDiscover
494  */
TEST_P(SupplicantStaIfaceAidlTest,InitiateTdlsDiscover)495 TEST_P(SupplicantStaIfaceAidlTest, InitiateTdlsDiscover) {
496     EXPECT_TRUE(sta_iface_->initiateTdlsDiscover(kTestMacAddr).isOk());
497 }
498 
499 /*
500  * InitiateTdlsSetup
501  */
TEST_P(SupplicantStaIfaceAidlTest,InitiateTdlsSetup)502 TEST_P(SupplicantStaIfaceAidlTest, InitiateTdlsSetup) {
503     EXPECT_TRUE(sta_iface_->initiateTdlsSetup(kTestMacAddr).isOk());
504 }
505 
506 /*
507  * InitiateTdlsTeardown
508  */
TEST_P(SupplicantStaIfaceAidlTest,InitiateTdlsTeardown)509 TEST_P(SupplicantStaIfaceAidlTest, InitiateTdlsTeardown) {
510     EXPECT_TRUE(sta_iface_->initiateTdlsTeardown(kTestMacAddr).isOk());
511 }
512 
513 /*
514  * InitiateAnqpQuery
515  */
TEST_P(SupplicantStaIfaceAidlTest,InitiateAnqpQuery)516 TEST_P(SupplicantStaIfaceAidlTest, InitiateAnqpQuery) {
517     const std::vector<AnqpInfoId> anqpIds = {
518         AnqpInfoId::VENUE_NAME, AnqpInfoId::NAI_REALM, AnqpInfoId::DOMAIN_NAME};
519     const std::vector<Hs20AnqpSubtypes> hsTypes = {
520         Hs20AnqpSubtypes::WAN_METRICS,
521         Hs20AnqpSubtypes::OPERATOR_FRIENDLY_NAME};
522 
523     // Request should fail since the BSSID mentioned
524     // is not present in the scan results
525     EXPECT_FALSE(
526         sta_iface_->initiateAnqpQuery(kTestMacAddr, anqpIds, hsTypes).isOk());
527 }
528 
529 /*
530  * InitiateHs20IconQuery
531  */
TEST_P(SupplicantStaIfaceAidlTest,InitiateHs20IconQuery)532 TEST_P(SupplicantStaIfaceAidlTest, InitiateHs20IconQuery) {
533     // Request should fail since the BSSID mentioned
534     // is not present in the scan results
535     const std::string hs20IconFile = "TestFile";
536     EXPECT_FALSE(
537         sta_iface_->initiateHs20IconQuery(kTestMacAddr, hs20IconFile).isOk());
538 }
539 
540 /*
541  * InitiateVenueUrlAnqpQuery.
542  */
TEST_P(SupplicantStaIfaceAidlTest,InitiateVenueUrlAnqpQuery)543 TEST_P(SupplicantStaIfaceAidlTest, InitiateVenueUrlAnqpQuery) {
544     // Request should fail since the BSSID mentioned
545     // is not present in the scan results
546     EXPECT_FALSE(sta_iface_->initiateVenueUrlAnqpQuery(kTestMacAddr).isOk());
547 }
548 
549 /*
550  * Reassociate
551  */
TEST_P(SupplicantStaIfaceAidlTest,Reassociate)552 TEST_P(SupplicantStaIfaceAidlTest, Reassociate) {
553     EXPECT_TRUE(sta_iface_->reassociate().isOk());
554 }
555 
556 /*
557  * Reconnect
558  */
TEST_P(SupplicantStaIfaceAidlTest,Reconnect)559 TEST_P(SupplicantStaIfaceAidlTest, Reconnect) {
560     EXPECT_FALSE(sta_iface_->reconnect().isOk());
561 }
562 
563 /*
564  * Disconnect
565  */
TEST_P(SupplicantStaIfaceAidlTest,Disconnect)566 TEST_P(SupplicantStaIfaceAidlTest, Disconnect) {
567     EXPECT_TRUE(sta_iface_->disconnect().isOk());
568 }
569 
570 /*
571  * SetPowerSave
572  */
TEST_P(SupplicantStaIfaceAidlTest,SetPowerSave)573 TEST_P(SupplicantStaIfaceAidlTest, SetPowerSave) {
574     EXPECT_TRUE(sta_iface_->setPowerSave(true).isOk());
575     EXPECT_TRUE(sta_iface_->setPowerSave(false).isOk());
576 }
577 
578 /*
579  * AddExtRadioWork
580  */
TEST_P(SupplicantStaIfaceAidlTest,AddExtRadioWork)581 TEST_P(SupplicantStaIfaceAidlTest, AddExtRadioWork) {
582     const std::string radioWorkName = "TestRadioWork";
583     const int32_t radioWorkFreq = 2412;
584     const int32_t radioWorkTimeout = 8;
585     int32_t radioWorkId;
586     EXPECT_TRUE(sta_iface_
587                     ->addExtRadioWork(radioWorkName, radioWorkFreq,
588                                       radioWorkTimeout, &radioWorkId)
589                     .isOk());
590     // removeExtRadio only succeeds if the added radio work hasn't started yet,
591     // so there is no guaranteed result from calling removeExtRadioWork here.
592     // Given that, we can't currently test removeExtRadioWork following
593     // a call to addExtRadioWork.
594 }
595 
596 /*
597  * RemoveExtRadioWork
598  */
TEST_P(SupplicantStaIfaceAidlTest,RemoveExtRadioWork)599 TEST_P(SupplicantStaIfaceAidlTest, RemoveExtRadioWork) {
600     // This fails because there is no ongoing radio work with radioWorkId
601     const int32_t radioWorkId = 16;
602     EXPECT_FALSE(sta_iface_->removeExtRadioWork(radioWorkId).isOk());
603 }
604 
605 /*
606  * Add/Remove DppPeerUri
607  */
TEST_P(SupplicantStaIfaceAidlTest,AddRemoveDppPeerUri)608 TEST_P(SupplicantStaIfaceAidlTest, AddRemoveDppPeerUri) {
609     if (!keyMgmtSupported(sta_iface_, KeyMgmtMask::DPP)) {
610         GTEST_SKIP() << "Missing DPP support";
611     }
612     // Add a peer URI and then remove it.
613     int32_t peerId;
614     EXPECT_TRUE(sta_iface_->addDppPeerUri(kTestUri, &peerId).isOk());
615     EXPECT_TRUE(sta_iface_->removeDppUri(peerId).isOk());
616 }
617 
618 /*
619  * FilsHlpAddRequest
620  */
TEST_P(SupplicantStaIfaceAidlTest,FilsHlpAddRequest)621 TEST_P(SupplicantStaIfaceAidlTest, FilsHlpAddRequest) {
622     if (!isFilsSupported(sta_iface_)) {
623         GTEST_SKIP()
624             << "Skipping test since driver/supplicant doesn't support FILS";
625     }
626     const std::vector<uint8_t> destMacAddr = {0x00, 0x11, 0x22,
627                                               0x33, 0x44, 0x55};
628     const std::vector<uint8_t> pktBuffer = std::vector<uint8_t>(300, 0x3a);
629     EXPECT_TRUE(sta_iface_->filsHlpAddRequest(destMacAddr, pktBuffer).isOk());
630 }
631 
632 /*
633  * FilsHlpFlushRequest
634  */
TEST_P(SupplicantStaIfaceAidlTest,FilsHlpFlushRequest)635 TEST_P(SupplicantStaIfaceAidlTest, FilsHlpFlushRequest) {
636     if (!isFilsSupported(sta_iface_)) {
637         GTEST_SKIP()
638             << "Skipping test since driver/supplicant doesn't support FILS";
639     }
640     EXPECT_TRUE(sta_iface_->filsHlpFlushRequest().isOk());
641 }
642 
643 /*
644  * StartDppEnrolleeResponder
645  */
TEST_P(SupplicantStaIfaceAidlTest,StartDppEnrolleeResponder)646 TEST_P(SupplicantStaIfaceAidlTest, StartDppEnrolleeResponder) {
647     if (!keyMgmtSupported(sta_iface_, KeyMgmtMask::DPP)) {
648         GTEST_SKIP() << "Missing DPP support";
649     }
650 
651     const std::string deviceInfo = "DPP_Responder_Mode_VTS_Test";
652     const std::vector<uint8_t> mac_address = {0x22, 0x33, 0x44,
653                                               0x55, 0x66, 0x77};
654 
655     // Generate DPP bootstrap information.
656     DppResponderBootstrapInfo bootstrapInfo;
657     EXPECT_TRUE(
658         sta_iface_
659             ->generateDppBootstrapInfoForResponder(
660                 mac_address, deviceInfo, DppCurve::PRIME256V1, &bootstrapInfo)
661             .isOk());
662     EXPECT_NE(-1, bootstrapInfo.bootstrapId);
663     EXPECT_NE(0, bootstrapInfo.bootstrapId);
664     EXPECT_NE(0, bootstrapInfo.listenChannel);
665     const uint32_t bootstrap_id = bootstrapInfo.bootstrapId;
666     const uint32_t listen_channel = bootstrapInfo.listenChannel;
667 
668     // Start DPP as Enrollee-Responder.
669     EXPECT_TRUE(sta_iface_->startDppEnrolleeResponder(listen_channel).isOk());
670 
671     // Stop DPP Enrollee-Responder mode, ie remove the URI and stop listen.
672     EXPECT_TRUE(sta_iface_->stopDppResponder(bootstrap_id).isOk());
673 }
674 
675 class IfaceDppCallback : public SupplicantStaIfaceCallback {
676     SupplicantStaIfaceAidlTest& parent_;
onDppSuccess(::aidl::android::hardware::wifi::supplicant::DppEventType event)677     ::ndk::ScopedAStatus onDppSuccess(
678         ::aidl::android::hardware::wifi::supplicant::DppEventType event)
679         override {
680         parent_.code = (uint32_t)event;
681         parent_.dppCallbackType =
682             SupplicantStaIfaceAidlTest::DppCallbackType::EVENT_SUCCESS;
683         parent_.notify();
684         return ndk::ScopedAStatus::ok();
685     }
onDppProgress(aidl::android::hardware::wifi::supplicant::DppProgressCode code)686     ::ndk::ScopedAStatus onDppProgress(
687         aidl::android::hardware::wifi::supplicant::DppProgressCode code)
688         override {
689         parent_.code = (uint32_t)code;
690         parent_.dppCallbackType =
691             SupplicantStaIfaceAidlTest::DppCallbackType::EVENT_PROGRESS;
692         parent_.notify();
693         return ndk::ScopedAStatus::ok();
694     }
onDppFailure(aidl::android::hardware::wifi::supplicant::DppFailureCode code,const std::string & ssid,const std::string & channelList,const std::vector<char16_t> & bandList)695     ::ndk::ScopedAStatus onDppFailure(
696         aidl::android::hardware::wifi::supplicant::DppFailureCode code,
697         const std::string& ssid __attribute__((unused)),
698         const std::string& channelList __attribute__((unused)),
699         const std::vector<char16_t>& bandList
700         __attribute__((unused))) override {
701         parent_.code = (uint32_t)code;
702         parent_.dppCallbackType =
703             SupplicantStaIfaceAidlTest::DppCallbackType::EVENT_FAILURE;
704         parent_.notify();
705         return ndk::ScopedAStatus::ok();
706     }
707 
708    public:
IfaceDppCallback(SupplicantStaIfaceAidlTest & parent)709     IfaceDppCallback(SupplicantStaIfaceAidlTest& parent) : parent_(parent){};
710 };
711 
712 /*
713  * StartDppEnrolleeInitiator
714  */
TEST_P(SupplicantStaIfaceAidlTest,StartDppEnrolleeInitiator)715 TEST_P(SupplicantStaIfaceAidlTest, StartDppEnrolleeInitiator) {
716     if (!keyMgmtSupported(sta_iface_, KeyMgmtMask::DPP)) {
717         GTEST_SKIP() << "Missing DPP support";
718     }
719 
720     // Register callback
721     std::shared_ptr<IfaceDppCallback> callback =
722         ndk::SharedRefBase::make<IfaceDppCallback>(*this);
723     EXPECT_NE(callback, nullptr);
724     EXPECT_TRUE(sta_iface_->registerCallback(callback).isOk());
725 
726     // Add a peer URI
727     int32_t peer_id = 0;
728     EXPECT_TRUE(sta_iface_->addDppPeerUri(kTestUri, &peer_id).isOk());
729     EXPECT_NE(0, peer_id);
730     EXPECT_NE(-1, peer_id);
731 
732     // Start DPP as Enrollee-Initiator. Since this operation requires two
733     // devices, we start the operation and expect a timeout.
734     EXPECT_TRUE(sta_iface_->startDppEnrolleeInitiator(peer_id, 0).isOk());
735 
736     // Wait for the timeout callback
737     EXPECT_EQ(std::cv_status::no_timeout,
738               wait(SupplicantStaIfaceAidlTest::DppCallbackType::EVENT_FAILURE));
739     EXPECT_EQ(SupplicantStaIfaceAidlTest::DppCallbackType::EVENT_FAILURE,
740               dppCallbackType);
741 
742     // ...and then remove the peer URI.
743     EXPECT_TRUE(sta_iface_->removeDppUri(peer_id).isOk());
744 }
745 
746 /*
747  * StartDppConfiguratorInitiator
748  */
TEST_P(SupplicantStaIfaceAidlTest,StartDppConfiguratorInitiator)749 TEST_P(SupplicantStaIfaceAidlTest, StartDppConfiguratorInitiator) {
750     if (!keyMgmtSupported(sta_iface_, KeyMgmtMask::DPP)) {
751         GTEST_SKIP() << "Missing DPP support";
752     }
753 
754     // Register callback
755     std::shared_ptr<IfaceDppCallback> callback =
756         ndk::SharedRefBase::make<IfaceDppCallback>(*this);
757     EXPECT_NE(callback, nullptr);
758     EXPECT_TRUE(sta_iface_->registerCallback(callback).isOk());
759 
760     // Add a peer URI
761     int32_t peer_id = 0;
762     EXPECT_TRUE(sta_iface_->addDppPeerUri(kTestUri, &peer_id).isOk());
763     EXPECT_NE(0, peer_id);
764     EXPECT_NE(-1, peer_id);
765 
766     const std::string ssid =
767         "6D795F746573745F73736964";  // 'my_test_ssid' encoded in hex
768     const std::string password =
769         "746F70736563726574";  // 'topsecret' encoded in hex
770     const std::vector<uint8_t> eckey_in = {0x2, 0x3, 0x4};
771     std::vector<uint8_t> eckey_out = {};
772 
773     // Start DPP as Configurator-Initiator. Since this operation requires two
774     // devices, we start the operation and expect a timeout.
775     EXPECT_TRUE(sta_iface_
776                         ->startDppConfiguratorInitiator(peer_id, 0, ssid, password, "",
777                                                         DppNetRole::STA, DppAkm::PSK, eckey_in,
778                                                         &eckey_out)
779                         .isOk());
780 
781     // Wait for the timeout callback
782     ASSERT_EQ(std::cv_status::no_timeout,
783               wait(SupplicantStaIfaceAidlTest::DppCallbackType::EVENT_FAILURE));
784     ASSERT_EQ(SupplicantStaIfaceAidlTest::DppCallbackType::EVENT_FAILURE,
785               dppCallbackType);
786 
787     // ...and then remove the peer URI.
788     EXPECT_TRUE(sta_iface_->removeDppUri(peer_id).isOk());
789 }
790 
791 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(SupplicantStaIfaceAidlTest);
792 INSTANTIATE_TEST_SUITE_P(Supplicant, SupplicantStaIfaceAidlTest,
793                          testing::ValuesIn(android::getAidlHalInstanceNames(
794                              ISupplicant::descriptor)),
795                          android::PrintInstanceNameToString);
796 
main(int argc,char ** argv)797 int main(int argc, char** argv) {
798     ::testing::InitGoogleTest(&argc, argv);
799     ProcessState::self()->setThreadPoolMaxThreadCount(1);
800     ProcessState::self()->startThreadPool();
801     return RUN_ALL_TESTS();
802 }
803