• 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/BandMask.h>
21 #include <aidl/android/hardware/wifi/supplicant/BnSupplicant.h>
22 #include <aidl/android/hardware/wifi/supplicant/BnSupplicantP2pIfaceCallback.h>
23 #include <aidl/android/hardware/wifi/supplicant/P2pPairingBootstrappingMethodMask.h>
24 #include <aidl/android/hardware/wifi/supplicant/SupplicantStatusCode.h>
25 #include <android/binder_manager.h>
26 #include <android/binder_status.h>
27 #include <binder/IServiceManager.h>
28 #include <binder/ProcessState.h>
29 #include <cutils/properties.h>
30 
31 #include "supplicant_test_utils.h"
32 #include "wifi_aidl_test_utils.h"
33 
34 using aidl::android::hardware::wifi::supplicant::BandMask;
35 using aidl::android::hardware::wifi::supplicant::BnSupplicantP2pIfaceCallback;
36 using aidl::android::hardware::wifi::supplicant::DebugLevel;
37 using aidl::android::hardware::wifi::supplicant::FreqRange;
38 using aidl::android::hardware::wifi::supplicant::IfaceType;
39 using aidl::android::hardware::wifi::supplicant::ISupplicant;
40 using aidl::android::hardware::wifi::supplicant::ISupplicantP2pIface;
41 using aidl::android::hardware::wifi::supplicant::ISupplicantP2pNetwork;
42 using aidl::android::hardware::wifi::supplicant::MiracastMode;
43 using aidl::android::hardware::wifi::supplicant::P2pAddGroupConfigurationParams;
44 using aidl::android::hardware::wifi::supplicant::P2pConnectInfo;
45 using aidl::android::hardware::wifi::supplicant::P2pCreateGroupOwnerInfo;
46 using aidl::android::hardware::wifi::supplicant::P2pDeviceFoundEventParams;
47 using aidl::android::hardware::wifi::supplicant::P2pDirInfo;
48 using aidl::android::hardware::wifi::supplicant::P2pDiscoveryInfo;
49 using aidl::android::hardware::wifi::supplicant::P2pExtListenInfo;
50 using aidl::android::hardware::wifi::supplicant::P2pFrameTypeMask;
51 using aidl::android::hardware::wifi::supplicant::P2pGoNegotiationReqEventParams;
52 using aidl::android::hardware::wifi::supplicant::P2pGroupCapabilityMask;
53 using aidl::android::hardware::wifi::supplicant::P2pGroupStartedEventParams;
54 using aidl::android::hardware::wifi::supplicant::P2pInvitationEventParams;
55 using aidl::android::hardware::wifi::supplicant::P2pPairingBootstrappingMethodMask;
56 using aidl::android::hardware::wifi::supplicant::P2pPeerClientDisconnectedEventParams;
57 using aidl::android::hardware::wifi::supplicant::P2pPeerClientJoinedEventParams;
58 using aidl::android::hardware::wifi::supplicant::P2pProvDiscStatusCode;
59 using aidl::android::hardware::wifi::supplicant::P2pProvisionDiscoveryCompletedEventParams;
60 using aidl::android::hardware::wifi::supplicant::P2pProvisionDiscoveryParams;
61 using aidl::android::hardware::wifi::supplicant::P2pReinvokePersistentGroupParams;
62 using aidl::android::hardware::wifi::supplicant::P2pScanType;
63 using aidl::android::hardware::wifi::supplicant::P2pStatusCode;
64 using aidl::android::hardware::wifi::supplicant::P2pUsdBasedServiceAdvertisementConfig;
65 using aidl::android::hardware::wifi::supplicant::P2pUsdBasedServiceDiscoveryConfig;
66 using aidl::android::hardware::wifi::supplicant::P2pUsdBasedServiceDiscoveryResultParams;
67 using aidl::android::hardware::wifi::supplicant::SupplicantStatusCode;
68 using aidl::android::hardware::wifi::supplicant::UsdTerminateReasonCode;
69 using aidl::android::hardware::wifi::supplicant::WpsConfigMethods;
70 using aidl::android::hardware::wifi::supplicant::WpsDevPasswordId;
71 using aidl::android::hardware::wifi::supplicant::WpsProvisionMethod;
72 using android::ProcessState;
73 
74 namespace {
75 const std::string kTestSsidStr = "TestSsid1234";
76 const std::vector<uint8_t> kTestSsid =
77     std::vector<uint8_t>(kTestSsidStr.begin(), kTestSsidStr.end());
78 const std::vector<uint8_t> kTestMacAddr = {0x56, 0x67, 0x67, 0xf4, 0x56, 0x92};
79 const std::vector<uint8_t> kTestPeerMacAddr = {0x56, 0x67, 0x55,
80                                                0xf4, 0x56, 0x92};
81 const std::vector<uint8_t> kTestZeroMacAddr = std::vector<uint8_t>(6, 0);
82 const std::string kTestServiceSpecificInfoStr = "TestServiceSpecificInfo";
83 const std::vector<uint8_t> kTestServiceSpecificInfo = std::vector<uint8_t>(
84         kTestServiceSpecificInfoStr.begin(), kTestServiceSpecificInfoStr.end());
85 const std::vector<uint8_t> kTestNonce = {0x11, 0x22, 0x33, 0x44, 0x55, 0x92, 0x22, 0x33};
86 const std::vector<uint8_t> kTestDirTag = {0xaa, 0x22, 0x55, 0x44, 0x55, 0x92, 0x22, 0x33};
87 const std::string kTestPassphrase = "P2pWorld1234";
88 const std::string kTestConnectPin = "34556665";
89 const std::string kTestGroupIfName = "TestGroup";
90 const std::string kTestServiceName = "TestServiceName";
91 const uint32_t kTestFindTimeout = 5;
92 const uint32_t kTestConnectGoIntent = 6;
93 const uint32_t kTestNetworkId = 7;
94 const uint32_t kTestGroupFreq = 0;
95 const uint32_t kTestServiceProtocolType = 1;
96 const bool kTestGroupPersistent = false;
97 const bool kTestGroupIsJoin = false;
98 const auto& kTestVendorDataOptional = generateOuiKeyedDataListOptional(5);
99 
100 }  // namespace
101 
102 class SupplicantP2pIfaceCallback : public BnSupplicantP2pIfaceCallback {
103    public:
104     SupplicantP2pIfaceCallback() = default;
105 
onDeviceFound(const std::vector<uint8_t> &,const std::vector<uint8_t> &,const std::vector<uint8_t> &,const std::string &,WpsConfigMethods,int8_t,P2pGroupCapabilityMask,const std::vector<uint8_t> &)106     ::ndk::ScopedAStatus onDeviceFound(
107         const std::vector<uint8_t>& /* srcAddress */,
108         const std::vector<uint8_t>& /* p2pDeviceAddress */,
109         const std::vector<uint8_t>& /* primaryDeviceType */,
110         const std::string& /* deviceName */,
111         WpsConfigMethods /* configMethods */, int8_t /* deviceCapabilities */,
112         P2pGroupCapabilityMask /* groupCapabilities */,
113         const std::vector<uint8_t>& /* wfdDeviceInfo */) override {
114         return ndk::ScopedAStatus::ok();
115     }
onDeviceLost(const std::vector<uint8_t> &)116     ::ndk::ScopedAStatus onDeviceLost(
117         const std::vector<uint8_t>& /* p2pDeviceAddress */) override {
118         return ndk::ScopedAStatus::ok();
119     }
onFindStopped()120     ::ndk::ScopedAStatus onFindStopped() override {
121         return ndk::ScopedAStatus::ok();
122     }
onGoNegotiationCompleted(P2pStatusCode)123     ::ndk::ScopedAStatus onGoNegotiationCompleted(
124         P2pStatusCode /* status */) override {
125         return ndk::ScopedAStatus::ok();
126     }
onGoNegotiationRequest(const std::vector<uint8_t> &,WpsDevPasswordId)127     ::ndk::ScopedAStatus onGoNegotiationRequest(
128         const std::vector<uint8_t>& /* srcAddress */,
129         WpsDevPasswordId /* passwordId */) override {
130         return ndk::ScopedAStatus::ok();
131     }
onGroupFormationFailure(const std::string &)132     ::ndk::ScopedAStatus onGroupFormationFailure(
133         const std::string& /* failureReason */) override {
134         return ndk::ScopedAStatus::ok();
135     }
onGroupFormationSuccess()136     ::ndk::ScopedAStatus onGroupFormationSuccess() override {
137         return ndk::ScopedAStatus::ok();
138     }
onGroupRemoved(const std::string &,bool)139     ::ndk::ScopedAStatus onGroupRemoved(const std::string& /* groupIfname */,
140                                         bool /* isGroupOwner */) override {
141         return ndk::ScopedAStatus::ok();
142     }
onGroupStarted(const std::string &,bool,const std::vector<uint8_t> &,int32_t,const std::vector<uint8_t> &,const std::string &,const std::vector<uint8_t> &,bool)143     ::ndk::ScopedAStatus onGroupStarted(
144         const std::string& /* groupIfname */, bool /* isGroupOwner */,
145         const std::vector<uint8_t>& /* ssid */, int32_t /* frequency */,
146         const std::vector<uint8_t>& /* psk */,
147         const std::string& /* passphrase */,
148         const std::vector<uint8_t>& /* goDeviceAddress */,
149         bool /* isPersistent */) override {
150         return ndk::ScopedAStatus::ok();
151     }
onInvitationReceived(const std::vector<uint8_t> &,const std::vector<uint8_t> &,const std::vector<uint8_t> &,int32_t,int32_t)152     ::ndk::ScopedAStatus onInvitationReceived(
153         const std::vector<uint8_t>& /* srcAddress */,
154         const std::vector<uint8_t>& /* goDeviceAddress */,
155         const std::vector<uint8_t>& /* bssid */,
156         int32_t /* persistentNetworkId */,
157         int32_t /* operatingFrequency */) override {
158         return ndk::ScopedAStatus::ok();
159     }
onInvitationResult(const std::vector<uint8_t> &,P2pStatusCode)160     ::ndk::ScopedAStatus onInvitationResult(
161         const std::vector<uint8_t>& /* bssid */,
162         P2pStatusCode /* status */) override {
163         return ndk::ScopedAStatus::ok();
164     }
onProvisionDiscoveryCompleted(const std::vector<uint8_t> &,bool,P2pProvDiscStatusCode,WpsConfigMethods,const std::string &)165     ::ndk::ScopedAStatus onProvisionDiscoveryCompleted(
166         const std::vector<uint8_t>& /* p2pDeviceAddress */,
167         bool /* isRequest */, P2pProvDiscStatusCode /* status */,
168         WpsConfigMethods /* configMethods */,
169         const std::string& /* generatedPin */) override {
170         return ndk::ScopedAStatus::ok();
171     }
onR2DeviceFound(const std::vector<uint8_t> &,const std::vector<uint8_t> &,const std::vector<uint8_t> &,const std::string &,WpsConfigMethods,int8_t,P2pGroupCapabilityMask,const std::vector<uint8_t> &,const std::vector<uint8_t> &)172     ::ndk::ScopedAStatus onR2DeviceFound(
173         const std::vector<uint8_t>& /* srcAddress */,
174         const std::vector<uint8_t>& /* p2pDeviceAddress */,
175         const std::vector<uint8_t>& /* primaryDeviceType */,
176         const std::string& /* deviceName */,
177         WpsConfigMethods /* configMethods */, int8_t /* deviceCapabilities */,
178         P2pGroupCapabilityMask /* groupCapabilities */,
179         const std::vector<uint8_t>& /* wfdDeviceInfo */,
180         const std::vector<uint8_t>& /* wfdR2DeviceInfo */) override {
181         return ndk::ScopedAStatus::ok();
182     }
onServiceDiscoveryResponse(const std::vector<uint8_t> &,char16_t,const std::vector<uint8_t> &)183     ::ndk::ScopedAStatus onServiceDiscoveryResponse(
184         const std::vector<uint8_t>& /* srcAddress */,
185         char16_t /* updateIndicator */,
186         const std::vector<uint8_t>& /* tlvs */) override {
187         return ndk::ScopedAStatus::ok();
188     }
onStaAuthorized(const std::vector<uint8_t> &,const std::vector<uint8_t> &)189     ::ndk::ScopedAStatus onStaAuthorized(
190         const std::vector<uint8_t>& /* srcAddress */,
191         const std::vector<uint8_t>& /* p2pDeviceAddress */) override {
192         return ndk::ScopedAStatus::ok();
193     }
onStaDeauthorized(const std::vector<uint8_t> &,const std::vector<uint8_t> &)194     ::ndk::ScopedAStatus onStaDeauthorized(
195         const std::vector<uint8_t>& /* srcAddress */,
196         const std::vector<uint8_t>& /* p2pDeviceAddress */) override {
197         return ndk::ScopedAStatus::ok();
198     }
onGroupFrequencyChanged(const std::string &,int32_t)199     ::ndk::ScopedAStatus onGroupFrequencyChanged(const std::string& /* groupIfname */,
200                                                  int32_t /* frequency */) override {
201         return ndk::ScopedAStatus::ok();
202     }
onDeviceFoundWithVendorElements(const std::vector<uint8_t> &,const std::vector<uint8_t> &,const std::vector<uint8_t> &,const std::string &,WpsConfigMethods,int8_t,P2pGroupCapabilityMask,const std::vector<uint8_t> &,const std::vector<uint8_t> &,const std::vector<uint8_t> &)203     ::ndk::ScopedAStatus onDeviceFoundWithVendorElements(
204             const std::vector<uint8_t>& /* srcAddress */,
205             const std::vector<uint8_t>& /* p2pDeviceAddress */,
206             const std::vector<uint8_t>& /* primaryDeviceType */,
207             const std::string& /* deviceName */, WpsConfigMethods /* configMethods */,
208             int8_t /* deviceCapabilities */, P2pGroupCapabilityMask /* groupCapabilities */,
209             const std::vector<uint8_t>& /* wfdDeviceInfo */,
210             const std::vector<uint8_t>& /* wfdR2DeviceInfo */,
211             const std::vector<uint8_t>& /* vendorElemBytes */) override {
212         return ndk::ScopedAStatus::ok();
213     }
onGroupStartedWithParams(const P2pGroupStartedEventParams &)214     ::ndk::ScopedAStatus onGroupStartedWithParams(
215             const P2pGroupStartedEventParams& /* groupStartedEventParams */) override {
216         return ndk::ScopedAStatus::ok();
217     }
onPeerClientJoined(const P2pPeerClientJoinedEventParams &)218     ::ndk::ScopedAStatus onPeerClientJoined(
219             const P2pPeerClientJoinedEventParams& /* clientJoinedEventParams */) override {
220         return ndk::ScopedAStatus::ok();
221     }
onPeerClientDisconnected(const P2pPeerClientDisconnectedEventParams &)222     ::ndk::ScopedAStatus onPeerClientDisconnected(
223             const P2pPeerClientDisconnectedEventParams& /* clientDisconnectedEventParams */)
224             override {
225         return ndk::ScopedAStatus::ok();
226     }
onProvisionDiscoveryCompletedEvent(const P2pProvisionDiscoveryCompletedEventParams &)227     ::ndk::ScopedAStatus onProvisionDiscoveryCompletedEvent(
228             const P2pProvisionDiscoveryCompletedEventParams&
229             /* provisionDiscoveryCompletedEventParams */) override {
230         return ndk::ScopedAStatus::ok();
231     }
onDeviceFoundWithParams(const P2pDeviceFoundEventParams &)232     ::ndk::ScopedAStatus onDeviceFoundWithParams(
233             const P2pDeviceFoundEventParams& /* deviceFoundEventParams */) override {
234         return ndk::ScopedAStatus::ok();
235     }
onGoNegotiationRequestWithParams(const P2pGoNegotiationReqEventParams &)236     ::ndk::ScopedAStatus onGoNegotiationRequestWithParams(
237             const P2pGoNegotiationReqEventParams& /* goNegotiationReqEventParams */) override {
238         return ndk::ScopedAStatus::ok();
239     }
onInvitationReceivedWithParams(const P2pInvitationEventParams &)240     ::ndk::ScopedAStatus onInvitationReceivedWithParams(
241             const P2pInvitationEventParams& /* invitationEventParams */) override {
242         return ndk::ScopedAStatus::ok();
243     }
onUsdBasedServiceDiscoveryResult(const P2pUsdBasedServiceDiscoveryResultParams &)244     ::ndk::ScopedAStatus onUsdBasedServiceDiscoveryResult(
245             const P2pUsdBasedServiceDiscoveryResultParams& /* discoveryResultParams*/) override {
246         return ndk::ScopedAStatus::ok();
247     }
onUsdBasedServiceDiscoveryTerminated(int32_t,UsdTerminateReasonCode)248     ::ndk::ScopedAStatus onUsdBasedServiceDiscoveryTerminated(
249             int32_t /* sessionId */, UsdTerminateReasonCode /* reasonCode */) override {
250         return ndk::ScopedAStatus::ok();
251     }
onUsdBasedServiceAdvertisementTerminated(int32_t,UsdTerminateReasonCode)252     ::ndk::ScopedAStatus onUsdBasedServiceAdvertisementTerminated(
253             int32_t /* sessionId */, UsdTerminateReasonCode /* reasonCode */) override {
254         return ndk::ScopedAStatus::ok();
255     }
256 };
257 
258 class SupplicantP2pIfaceAidlTest : public testing::TestWithParam<std::string> {
259    public:
SetUp()260     void SetUp() override {
261         initializeService();
262         supplicant_ = getSupplicant(GetParam().c_str());
263         ASSERT_NE(supplicant_, nullptr);
264         ASSERT_TRUE(supplicant_->getInterfaceVersion(&interface_version_).isOk());
265         ASSERT_TRUE(supplicant_
266                         ->setDebugParams(DebugLevel::EXCESSIVE,
267                                          true,  // show timestamps
268                                          true)
269                         .isOk());
270 
271         bool p2pEnabled =
272             testing::deviceSupportsFeature("android.hardware.wifi.direct");
273         if (!p2pEnabled) {
274             GTEST_SKIP() << "Wi-Fi Direct is not supported, skip this test.";
275         }
276 
277         EXPECT_TRUE(supplicant_->getP2pInterface(getP2pIfaceName(), &p2p_iface_)
278                         .isOk());
279         ASSERT_NE(p2p_iface_, nullptr);
280         if (interface_version_ >= 4) {
281             EXPECT_TRUE(p2p_iface_->getFeatureSet(&supported_features_).isOk());
282         }
283     }
284 
TearDown()285     void TearDown() override {
286         stopSupplicantService();
287         startWifiFramework();
288     }
289 
290    protected:
291     std::shared_ptr<ISupplicant> supplicant_;
292     std::shared_ptr<ISupplicantP2pIface> p2p_iface_;
293     int interface_version_;
294     int64_t supported_features_;
295 };
296 
297 /*
298  * RegisterCallback
299  */
TEST_P(SupplicantP2pIfaceAidlTest,RegisterCallback)300 TEST_P(SupplicantP2pIfaceAidlTest, RegisterCallback) {
301     std::shared_ptr<SupplicantP2pIfaceCallback> callback =
302         ndk::SharedRefBase::make<SupplicantP2pIfaceCallback>();
303     ASSERT_NE(callback, nullptr);
304     EXPECT_TRUE(p2p_iface_->registerCallback(callback).isOk());
305 }
306 
307 /*
308  * GetName
309  */
TEST_P(SupplicantP2pIfaceAidlTest,GetName)310 TEST_P(SupplicantP2pIfaceAidlTest, GetName) {
311     std::string name;
312     EXPECT_TRUE(p2p_iface_->getName(&name).isOk());
313     EXPECT_NE(name.size(), 0);
314 }
315 
316 /*
317  * GetType
318  */
TEST_P(SupplicantP2pIfaceAidlTest,GetType)319 TEST_P(SupplicantP2pIfaceAidlTest, GetType) {
320     IfaceType type;
321     EXPECT_TRUE(p2p_iface_->getType(&type).isOk());
322     EXPECT_EQ(type, IfaceType::P2P);
323 }
324 
325 /*
326  * GetDeviceAddress
327  */
TEST_P(SupplicantP2pIfaceAidlTest,GetDeviceAddress)328 TEST_P(SupplicantP2pIfaceAidlTest, GetDeviceAddress) {
329     std::vector<uint8_t> macAddr;
330     EXPECT_TRUE(p2p_iface_->getDeviceAddress(&macAddr).isOk());
331     EXPECT_EQ(macAddr.size(), 6);
332 }
333 
334 /*
335  * GetSsid
336  */
TEST_P(SupplicantP2pIfaceAidlTest,GetSsid)337 TEST_P(SupplicantP2pIfaceAidlTest, GetSsid) {
338     // This will fail with fake values.
339     std::vector<uint8_t> ssid;
340     EXPECT_FALSE(p2p_iface_->getSsid(kTestMacAddr, &ssid).isOk());
341 }
342 
343 /*
344  * GetGroupCapability
345  */
TEST_P(SupplicantP2pIfaceAidlTest,GetGroupCapability)346 TEST_P(SupplicantP2pIfaceAidlTest, GetGroupCapability) {
347     // This will fail with fake values.
348     P2pGroupCapabilityMask cap;
349     EXPECT_FALSE(p2p_iface_->getGroupCapability(kTestMacAddr, &cap).isOk());
350 }
351 
352 /*
353  * Set/Get Edmg
354  */
TEST_P(SupplicantP2pIfaceAidlTest,SetGetEdmg)355 TEST_P(SupplicantP2pIfaceAidlTest, SetGetEdmg) {
356     bool emdg = false;
357     EXPECT_TRUE(p2p_iface_->setEdmg(true).isOk());
358     EXPECT_TRUE(p2p_iface_->getEdmg(&emdg).isOk());
359     EXPECT_EQ(emdg, true);
360 
361     EXPECT_TRUE(p2p_iface_->setEdmg(false).isOk());
362     EXPECT_TRUE(p2p_iface_->getEdmg(&emdg).isOk());
363     EXPECT_EQ(emdg, false);
364 }
365 
366 /*
367  * SetWpsDeviceName
368  */
TEST_P(SupplicantP2pIfaceAidlTest,SetWpsDeviceName)369 TEST_P(SupplicantP2pIfaceAidlTest, SetWpsDeviceName) {
370     const std::string deviceName = "TestWpsDeviceName";
371     EXPECT_TRUE(p2p_iface_->setWpsDeviceName(deviceName).isOk());
372 }
373 
374 /*
375  * SetWpsDeviceType
376  */
TEST_P(SupplicantP2pIfaceAidlTest,SetWpsDeviceType)377 TEST_P(SupplicantP2pIfaceAidlTest, SetWpsDeviceType) {
378     const std::vector<uint8_t> deviceType = std::vector<uint8_t>(8, 0x01);
379     EXPECT_TRUE(p2p_iface_->setWpsDeviceType(deviceType).isOk());
380 }
381 
382 /*
383  * SetWpsManufacturer
384  */
TEST_P(SupplicantP2pIfaceAidlTest,SetWpsManufacturer)385 TEST_P(SupplicantP2pIfaceAidlTest, SetWpsManufacturer) {
386     const std::string deviceManufacturer = "TestManufacturer";
387     EXPECT_TRUE(p2p_iface_->setWpsManufacturer(deviceManufacturer).isOk());
388 }
389 
390 /*
391  * SetWpsModelName
392  */
TEST_P(SupplicantP2pIfaceAidlTest,SetWpsModelName)393 TEST_P(SupplicantP2pIfaceAidlTest, SetWpsModelName) {
394     const std::string modelName = "TestModelName";
395     EXPECT_TRUE(p2p_iface_->setWpsModelName(modelName).isOk());
396 }
397 
398 /*
399  * SetWpsModelNumber
400  */
TEST_P(SupplicantP2pIfaceAidlTest,SetWpsModelNumber)401 TEST_P(SupplicantP2pIfaceAidlTest, SetWpsModelNumber) {
402     const std::string modelNumber = "Model1234";
403     EXPECT_TRUE(p2p_iface_->setWpsModelNumber(modelNumber).isOk());
404 }
405 
406 /*
407  * SetWpsSerialNumber
408  */
TEST_P(SupplicantP2pIfaceAidlTest,SetWpsSerialNumber)409 TEST_P(SupplicantP2pIfaceAidlTest, SetWpsSerialNumber) {
410     const std::string serialNumber = "TestSerialNumber";
411     EXPECT_TRUE(p2p_iface_->setWpsSerialNumber(serialNumber).isOk());
412 }
413 
414 /*
415  * SetWpsConfigMethods
416  */
TEST_P(SupplicantP2pIfaceAidlTest,SetWpsConfigMethods)417 TEST_P(SupplicantP2pIfaceAidlTest, SetWpsConfigMethods) {
418     const WpsConfigMethods config = WpsConfigMethods::DISPLAY;
419     EXPECT_TRUE(p2p_iface_->setWpsConfigMethods(config).isOk());
420 }
421 
422 /*
423  * SetSsidPostfix
424  */
TEST_P(SupplicantP2pIfaceAidlTest,SetSsidPostfix)425 TEST_P(SupplicantP2pIfaceAidlTest, SetSsidPostfix) {
426     const std::vector<uint8_t> ssidPostfix = {'t', 'e', 's', 't'};
427     EXPECT_TRUE(p2p_iface_->setSsidPostfix(ssidPostfix).isOk());
428 }
429 
430 /*
431  * SetWfdDeviceInfo
432  */
TEST_P(SupplicantP2pIfaceAidlTest,SetWfdDeviceInfo)433 TEST_P(SupplicantP2pIfaceAidlTest, SetWfdDeviceInfo) {
434     const std::vector<uint8_t> wfdDeviceInfo = std::vector<uint8_t>(6, 0x01);
435     EXPECT_TRUE(p2p_iface_->setWfdDeviceInfo(wfdDeviceInfo).isOk());
436 }
437 
438 /*
439  * SetWfdR2DeviceInfo
440  */
TEST_P(SupplicantP2pIfaceAidlTest,SetWfdR2DeviceInfo)441 TEST_P(SupplicantP2pIfaceAidlTest, SetWfdR2DeviceInfo) {
442     const std::vector<uint8_t> wfdR2DeviceInfo = std::vector<uint8_t>(4, 0x01);
443     EXPECT_TRUE(p2p_iface_->setWfdR2DeviceInfo(wfdR2DeviceInfo).isOk());
444 }
445 
446 /*
447  * SetGroupIdle
448  */
TEST_P(SupplicantP2pIfaceAidlTest,SetGroupIdle)449 TEST_P(SupplicantP2pIfaceAidlTest, SetGroupIdle) {
450     // This will fail with fake values.
451     const uint32_t groupIdleTimeout = 8;
452     EXPECT_FALSE(
453         p2p_iface_->setGroupIdle(kTestGroupIfName, groupIdleTimeout).isOk());
454 }
455 
456 /*
457  * SetPowerSave
458  */
TEST_P(SupplicantP2pIfaceAidlTest,SetPowerSave)459 TEST_P(SupplicantP2pIfaceAidlTest, SetPowerSave) {
460     // This will fail with fake values.
461     EXPECT_FALSE(p2p_iface_->setPowerSave(kTestGroupIfName, true).isOk());
462     EXPECT_FALSE(p2p_iface_->setPowerSave(kTestGroupIfName, false).isOk());
463 }
464 
465 /*
466  * SetMiracastMode
467  */
TEST_P(SupplicantP2pIfaceAidlTest,SetMiracastMode)468 TEST_P(SupplicantP2pIfaceAidlTest, SetMiracastMode) {
469     EXPECT_TRUE(p2p_iface_->setMiracastMode(MiracastMode::DISABLED).isOk());
470     EXPECT_TRUE(p2p_iface_->setMiracastMode(MiracastMode::SOURCE).isOk());
471     EXPECT_TRUE(p2p_iface_->setMiracastMode(MiracastMode::SINK).isOk());
472 }
473 
474 /*
475  * SetDisallowedFrequencies
476  */
TEST_P(SupplicantP2pIfaceAidlTest,SetDisallowedFrequencies)477 TEST_P(SupplicantP2pIfaceAidlTest, SetDisallowedFrequencies) {
478     FreqRange range1;
479     range1.min = 2412;
480     range1.max = 2432;
481     const std::vector<FreqRange> ranges = {range1};
482     EXPECT_TRUE(p2p_iface_->setDisallowedFrequencies(ranges).isOk());
483 }
484 
485 /*
486  * SetListenChannel
487  */
TEST_P(SupplicantP2pIfaceAidlTest,SetListenChannel)488 TEST_P(SupplicantP2pIfaceAidlTest, SetListenChannel) {
489     const uint32_t testChannel = 1;
490     const uint32_t testOperatingClass = 81;
491     EXPECT_TRUE(
492         p2p_iface_->setListenChannel(testChannel, testOperatingClass).isOk());
493 }
494 
495 /*
496  * SetMacRandomization
497  */
TEST_P(SupplicantP2pIfaceAidlTest,EnableMacRandomization)498 TEST_P(SupplicantP2pIfaceAidlTest, EnableMacRandomization) {
499     // Enable twice
500     auto status = p2p_iface_->setMacRandomization(true);
501     if (!status.isOk() && status.getServiceSpecificError() ==
502                                   static_cast<int32_t>(SupplicantStatusCode::FAILURE_UNSUPPORTED)) {
503         GTEST_SKIP() << "Mac randomization is not supported.";
504     }
505     EXPECT_TRUE(status.isOk());
506     EXPECT_TRUE(p2p_iface_->setMacRandomization(true).isOk());
507 
508     // Disable twice
509     EXPECT_TRUE(p2p_iface_->setMacRandomization(false).isOk());
510     EXPECT_TRUE(p2p_iface_->setMacRandomization(false).isOk());
511 }
512 
513 /*
514  * AddGroup
515  */
TEST_P(SupplicantP2pIfaceAidlTest,AddGroup)516 TEST_P(SupplicantP2pIfaceAidlTest, AddGroup) {
517     EXPECT_TRUE(p2p_iface_->addGroup(false, kTestNetworkId).isOk());
518 }
519 
520 /*
521  * RemoveGroup
522  */
TEST_P(SupplicantP2pIfaceAidlTest,RemoveGroup)523 TEST_P(SupplicantP2pIfaceAidlTest, RemoveGroup) {
524     // This will fail with fake values.
525     EXPECT_FALSE(p2p_iface_->removeGroup(kTestGroupIfName).isOk());
526 }
527 
528 /*
529  * AddGroupWithConfig - success.
530  */
TEST_P(SupplicantP2pIfaceAidlTest,AddGroupWithConfig_Success)531 TEST_P(SupplicantP2pIfaceAidlTest, AddGroupWithConfig_Success) {
532     EXPECT_TRUE(p2p_iface_
533                     ->addGroupWithConfig(kTestSsid, kTestPassphrase,
534                                          kTestGroupPersistent, kTestGroupFreq,
535                                          kTestZeroMacAddr, kTestGroupIsJoin)
536                     .isOk());
537 }
538 
539 /*
540  * AddGroupWithConfig - failure due to invalid SSID.
541  */
TEST_P(SupplicantP2pIfaceAidlTest,AddGroupWithConfig_FailureInvalidSsid)542 TEST_P(SupplicantP2pIfaceAidlTest, AddGroupWithConfig_FailureInvalidSsid) {
543     const std::vector<uint8_t> ssid;
544     EXPECT_FALSE(p2p_iface_
545                      ->addGroupWithConfig(ssid, kTestPassphrase,
546                                           kTestGroupPersistent, kTestGroupFreq,
547                                           kTestZeroMacAddr, kTestGroupIsJoin)
548                      .isOk());
549 }
550 
551 /*
552  * AddGroupWithConfig - failure due to invalid passphrase.
553  */
TEST_P(SupplicantP2pIfaceAidlTest,AddGroupWithConfig_FailureInvalidPassphrase)554 TEST_P(SupplicantP2pIfaceAidlTest,
555        AddGroupWithConfig_FailureInvalidPassphrase) {
556     const std::string passphrase = "1234";
557     EXPECT_FALSE(p2p_iface_
558                      ->addGroupWithConfig(kTestSsid, passphrase,
559                                           kTestGroupPersistent, kTestGroupFreq,
560                                           kTestZeroMacAddr, kTestGroupIsJoin)
561                      .isOk());
562 }
563 
564 /*
565  * AddGroupWithConfig - failure due to invalid frequency.
566  */
TEST_P(SupplicantP2pIfaceAidlTest,AddGroupWithConfig_FailureInvalidFrequency)567 TEST_P(SupplicantP2pIfaceAidlTest, AddGroupWithConfig_FailureInvalidFrequency) {
568     const int freq = 9999;
569     EXPECT_FALSE(p2p_iface_
570                      ->addGroupWithConfig(kTestSsid, kTestPassphrase,
571                                           kTestGroupPersistent, freq,
572                                           kTestZeroMacAddr, kTestGroupIsJoin)
573                      .isOk());
574 }
575 
576 /*
577  * CreateGroupOwner
578  */
TEST_P(SupplicantP2pIfaceAidlTest,CreateGroupOwner)579 TEST_P(SupplicantP2pIfaceAidlTest, CreateGroupOwner) {
580     if (interface_version_ < 3) {
581         GTEST_SKIP() << "createGroupOwner is available as of Supplicant V3";
582     }
583 
584     P2pCreateGroupOwnerInfo info;
585     info.persistent = false;
586     info.persistentNetworkId = kTestNetworkId;
587     info.vendorData = kTestVendorDataOptional;
588 
589     EXPECT_TRUE(p2p_iface_->createGroupOwner(info).isOk());
590 }
591 
592 /*
593  * AddGroupWithConfigurationParams
594  */
TEST_P(SupplicantP2pIfaceAidlTest,AddGroupWithConfigurationParams)595 TEST_P(SupplicantP2pIfaceAidlTest, AddGroupWithConfigurationParams) {
596     if (interface_version_ < 3) {
597         GTEST_SKIP() << "addGroupWithConfigurationParams is available as of Supplicant V3";
598     }
599 
600     P2pAddGroupConfigurationParams params;
601     params.ssid = kTestSsid;
602     params.passphrase = kTestPassphrase;
603     params.isPersistent = kTestGroupPersistent;
604     params.frequencyMHzOrBand = kTestGroupFreq;
605     params.goInterfaceAddress = vecToArrayMacAddr(kTestZeroMacAddr);
606     params.joinExistingGroup = kTestGroupIsJoin;
607     params.keyMgmtMask = 0;
608     params.vendorData = kTestVendorDataOptional;
609 
610     EXPECT_TRUE(p2p_iface_->addGroupWithConfigurationParams(params).isOk());
611 }
612 
613 /*
614  * Find
615  */
TEST_P(SupplicantP2pIfaceAidlTest,Find)616 TEST_P(SupplicantP2pIfaceAidlTest, Find) {
617     EXPECT_TRUE(p2p_iface_->find(kTestFindTimeout).isOk());
618 }
619 
620 /*
621  * FindSocialChannelsOnly
622  */
TEST_P(SupplicantP2pIfaceAidlTest,FindSocialChannelsOnly)623 TEST_P(SupplicantP2pIfaceAidlTest, FindSocialChannelsOnly) {
624     EXPECT_TRUE(p2p_iface_->findOnSocialChannels(kTestFindTimeout).isOk());
625 }
626 
627 /*
628  * FindSpecificFrequency
629  */
TEST_P(SupplicantP2pIfaceAidlTest,FindSpecificFrequency)630 TEST_P(SupplicantP2pIfaceAidlTest, FindSpecificFrequency) {
631     EXPECT_TRUE(p2p_iface_->findOnSpecificFrequency(2412, kTestFindTimeout).isOk());
632 }
633 
634 /*
635  * FindWithParams
636  */
TEST_P(SupplicantP2pIfaceAidlTest,FindWithParams)637 TEST_P(SupplicantP2pIfaceAidlTest, FindWithParams) {
638     if (interface_version_ < 3) {
639         GTEST_SKIP() << "findWithParams is available as of Supplicant V3";
640     }
641 
642     P2pDiscoveryInfo discoveryParams;
643     discoveryParams.timeoutInSec = kTestFindTimeout;
644     discoveryParams.vendorData = kTestVendorDataOptional;
645 
646     discoveryParams.scanType = P2pScanType::FULL;
647     EXPECT_TRUE(p2p_iface_->findWithParams(discoveryParams).isOk());
648     EXPECT_TRUE(p2p_iface_->stopFind().isOk());
649     sleep(1);
650 
651     discoveryParams.scanType = P2pScanType::SOCIAL;
652     EXPECT_TRUE(p2p_iface_->findWithParams(discoveryParams).isOk());
653     EXPECT_TRUE(p2p_iface_->stopFind().isOk());
654     sleep(1);
655 
656     discoveryParams.scanType = P2pScanType::SPECIFIC_FREQ;
657     discoveryParams.frequencyMhz = 2412;
658     EXPECT_TRUE(p2p_iface_->findWithParams(discoveryParams).isOk());
659     EXPECT_TRUE(p2p_iface_->stopFind().isOk());
660 }
661 
662 /*
663  * StopFind
664  */
TEST_P(SupplicantP2pIfaceAidlTest,StopFind)665 TEST_P(SupplicantP2pIfaceAidlTest, StopFind) {
666     EXPECT_TRUE(p2p_iface_->find(kTestFindTimeout).isOk());
667     EXPECT_TRUE(p2p_iface_->stopFind().isOk());
668 }
669 
670 /*
671  * Flush
672  */
TEST_P(SupplicantP2pIfaceAidlTest,Flush)673 TEST_P(SupplicantP2pIfaceAidlTest, Flush) {
674     EXPECT_TRUE(p2p_iface_->flush().isOk());
675 }
676 
677 /*
678  * Connect
679  */
TEST_P(SupplicantP2pIfaceAidlTest,Connect)680 TEST_P(SupplicantP2pIfaceAidlTest, Connect) {
681     std::string pin;
682     EXPECT_TRUE(p2p_iface_
683                         ->connect(kTestMacAddr, WpsProvisionMethod::PBC, kTestConnectPin, true,
684                                   false, kTestConnectGoIntent, &pin)
685                         .isOk());
686 }
687 
688 /*
689  * ConnectWithParams
690  */
TEST_P(SupplicantP2pIfaceAidlTest,ConnectWithParams)691 TEST_P(SupplicantP2pIfaceAidlTest, ConnectWithParams) {
692     if (interface_version_ < 3) {
693         GTEST_SKIP() << "connectWithParams is available as of Supplicant V3";
694     }
695 
696     P2pConnectInfo connectInfo;
697     connectInfo.peerAddress = vecToArrayMacAddr(kTestMacAddr);
698     connectInfo.provisionMethod = WpsProvisionMethod::PBC;
699     connectInfo.preSelectedPin = kTestConnectPin;
700     connectInfo.joinExistingGroup = true;
701     connectInfo.persistent = false;
702     connectInfo.goIntent = kTestConnectGoIntent;
703     connectInfo.vendorData = kTestVendorDataOptional;
704 
705     std::string pin;
706     EXPECT_TRUE(p2p_iface_->connectWithParams(connectInfo, &pin).isOk());
707 }
708 
709 /*
710  * CancelConnect
711  */
TEST_P(SupplicantP2pIfaceAidlTest,CancelConnect)712 TEST_P(SupplicantP2pIfaceAidlTest, CancelConnect) {
713     std::string pin;
714     EXPECT_TRUE(p2p_iface_
715                         ->connect(kTestMacAddr, WpsProvisionMethod::PBC, kTestConnectPin, true,
716                                   false, kTestConnectGoIntent, &pin)
717                         .isOk());
718     EXPECT_TRUE(p2p_iface_->cancelConnect().isOk());
719 }
720 
721 /*
722  * ProvisionDiscovery
723  */
TEST_P(SupplicantP2pIfaceAidlTest,ProvisionDiscovery)724 TEST_P(SupplicantP2pIfaceAidlTest, ProvisionDiscovery) {
725     // This will fail with fake values.
726     EXPECT_FALSE(
727         p2p_iface_->provisionDiscovery(kTestMacAddr, WpsProvisionMethod::PBC)
728             .isOk());
729 }
730 
731 /*
732  * Reject
733  */
TEST_P(SupplicantP2pIfaceAidlTest,Reject)734 TEST_P(SupplicantP2pIfaceAidlTest, Reject) {
735     // This will fail with fake values.
736     ASSERT_FALSE(p2p_iface_->reject(kTestMacAddr).isOk());
737 }
738 
739 /*
740  * Invite
741  */
TEST_P(SupplicantP2pIfaceAidlTest,Invite)742 TEST_P(SupplicantP2pIfaceAidlTest, Invite) {
743     // This will fail with fake values.
744     EXPECT_FALSE(
745         p2p_iface_->invite(kTestGroupIfName, kTestMacAddr, kTestPeerMacAddr)
746             .isOk());
747 }
748 
749 /*
750  * Reinvoke
751  */
TEST_P(SupplicantP2pIfaceAidlTest,Reinvoke)752 TEST_P(SupplicantP2pIfaceAidlTest, Reinvoke) {
753     // This will fail with fake values.
754     EXPECT_FALSE(p2p_iface_->reinvoke(kTestNetworkId, kTestMacAddr).isOk());
755 }
756 
757 /*
758  * ConfigureExtListen
759  */
TEST_P(SupplicantP2pIfaceAidlTest,ConfigureExtListen)760 TEST_P(SupplicantP2pIfaceAidlTest, ConfigureExtListen) {
761     const uint32_t extListenPeriod = 400;
762     const uint32_t extListenInterval = 400;
763     EXPECT_TRUE(
764         p2p_iface_->configureExtListen(extListenPeriod, extListenInterval)
765             .isOk());
766 }
767 
768 /*
769  * ConfigureExtListenWithParams
770  */
TEST_P(SupplicantP2pIfaceAidlTest,ConfigureExtListenWithParams)771 TEST_P(SupplicantP2pIfaceAidlTest, ConfigureExtListenWithParams) {
772     if (interface_version_ < 3) {
773         GTEST_SKIP() << "configureExtListenWithParams is available as of Supplicant V3";
774     }
775 
776     P2pExtListenInfo info;
777     info.periodMs = 400;
778     info.intervalMs = 400;
779     info.vendorData = kTestVendorDataOptional;
780 
781     EXPECT_TRUE(p2p_iface_->configureExtListenWithParams(info).isOk());
782 }
783 
784 /*
785  * FlushServices
786  */
TEST_P(SupplicantP2pIfaceAidlTest,FlushServices)787 TEST_P(SupplicantP2pIfaceAidlTest, FlushServices) {
788     EXPECT_TRUE(p2p_iface_->flushServices().isOk());
789 }
790 
791 /*
792  * EnableWfd
793  */
TEST_P(SupplicantP2pIfaceAidlTest,EnableWfd)794 TEST_P(SupplicantP2pIfaceAidlTest, EnableWfd) {
795     EXPECT_TRUE(p2p_iface_->enableWfd(true).isOk());
796     EXPECT_TRUE(p2p_iface_->enableWfd(false).isOk());
797 }
798 
799 /*
800  * Add/Remove BonjourService
801  */
TEST_P(SupplicantP2pIfaceAidlTest,AddAndRemoveBonjourService)802 TEST_P(SupplicantP2pIfaceAidlTest, AddAndRemoveBonjourService) {
803     const std::string serviceQueryStr = "testquery";
804     const std::string serviceResponseStr = "testresponse";
805     const std::vector<uint8_t> bonjourServiceQuery =
806         std::vector<uint8_t>(serviceQueryStr.begin(), serviceQueryStr.end());
807     const std::vector<uint8_t> bonjourServiceResponse = std::vector<uint8_t>(
808         serviceResponseStr.begin(), serviceResponseStr.end());
809 
810     EXPECT_TRUE(
811         p2p_iface_
812             ->addBonjourService(bonjourServiceQuery, bonjourServiceResponse)
813             .isOk());
814     EXPECT_TRUE(p2p_iface_->removeBonjourService(bonjourServiceQuery).isOk());
815 
816     // This will fail because the boujour service with
817     // bonjourServiceQuery was already removed.
818     EXPECT_FALSE(p2p_iface_->removeBonjourService(bonjourServiceQuery).isOk());
819 }
820 
821 /*
822  * Add/Remove UpnpService
823  */
TEST_P(SupplicantP2pIfaceAidlTest,AddAndRemoveUpnpService)824 TEST_P(SupplicantP2pIfaceAidlTest, AddAndRemoveUpnpService) {
825     const std::string upnpServiceName = "TestServiceName";
826     EXPECT_TRUE(
827         p2p_iface_->addUpnpService(0 /* version */, upnpServiceName).isOk());
828     EXPECT_TRUE(
829         p2p_iface_->removeUpnpService(0 /* version */, upnpServiceName).isOk());
830 
831     // This will fail because Upnp service with
832     // upnpServiceName was already removed.
833     EXPECT_FALSE(
834         p2p_iface_->removeUpnpService(0 /* version */, upnpServiceName).isOk());
835 }
836 
837 /*
838  * SetVendorElements
839  */
TEST_P(SupplicantP2pIfaceAidlTest,SetVendorElements)840 TEST_P(SupplicantP2pIfaceAidlTest, SetVendorElements) {
841     LOG(INFO) << "SupplicantP2pIfaceAidlTest::SetVendorElements start";
842 
843     std::vector<uint8_t> vendorElemBytes;
844     EXPECT_TRUE(
845             p2p_iface_
846                     ->setVendorElements(P2pFrameTypeMask::P2P_FRAME_PROBE_RESP_P2P, vendorElemBytes)
847                     .isOk());
848 
849     LOG(INFO) << "SupplicantP2pIfaceAidlTest::SetVendorElements end";
850 }
851 
852 /*
853  * GetFeatureSet
854  */
TEST_P(SupplicantP2pIfaceAidlTest,gGetFeatureSet)855 TEST_P(SupplicantP2pIfaceAidlTest, gGetFeatureSet) {
856     if (interface_version_ < 4) {
857         GTEST_SKIP() << "getFeatureSet is available as of Supplicant V4";
858     }
859     int64_t featureSet;
860     EXPECT_TRUE(p2p_iface_->getFeatureSet(&featureSet).isOk());
861 }
862 
863 /*
864  * StartUsdBasedServiceDiscovery/stopUsdBasedServiceDiscovery
865  */
TEST_P(SupplicantP2pIfaceAidlTest,StartStopUsdBasedServiceDiscovery)866 TEST_P(SupplicantP2pIfaceAidlTest, StartStopUsdBasedServiceDiscovery) {
867     if (interface_version_ < 4) {
868         GTEST_SKIP() << "Start/Stop UsdBasedServiceDiscovery is available as of Supplicant V4";
869     }
870     if (!(supported_features_ & ISupplicantP2pIface::P2P_FEATURE_V2)) {
871         GTEST_SKIP() << "P2P2 is not supported";
872     }
873 
874     int32_t sessionId;
875     P2pUsdBasedServiceDiscoveryConfig config;
876     config.serviceName = kTestServiceName;
877     config.serviceProtocolType = kTestServiceProtocolType;
878     config.serviceSpecificInfo = kTestServiceSpecificInfo;
879     config.bandMask = BandMask::BAND_2_GHZ;
880     config.timeoutInSeconds = 30;
881 
882     EXPECT_TRUE(p2p_iface_->startUsdBasedServiceDiscovery(config, &sessionId).isOk());
883     sleep(1);
884     EXPECT_TRUE(p2p_iface_->stopUsdBasedServiceDiscovery(sessionId).isOk());
885 }
886 
887 /*
888  * StartUsdBasedServiceAdvertisement/StopUsdBasedServiceAdvertisement
889  */
TEST_P(SupplicantP2pIfaceAidlTest,StartStopUsdBasedServiceAdvertisement)890 TEST_P(SupplicantP2pIfaceAidlTest, StartStopUsdBasedServiceAdvertisement) {
891     if (interface_version_ < 4) {
892         GTEST_SKIP() << "start/Stop UsdBasedServiceAdvertisement is available as of Supplicant V4";
893     }
894     if (!(supported_features_ & ISupplicantP2pIface::P2P_FEATURE_V2)) {
895         GTEST_SKIP() << "P2P2 is not supported";
896     }
897 
898     int32_t sessionId;
899     P2pUsdBasedServiceAdvertisementConfig config;
900     config.serviceName = kTestServiceName;
901     config.serviceProtocolType = kTestServiceProtocolType;
902     config.serviceSpecificInfo = kTestServiceSpecificInfo;
903     config.frequencyMHz = 2412;
904     config.timeoutInSeconds = 30;
905 
906     EXPECT_TRUE(p2p_iface_->startUsdBasedServiceAdvertisement(config, &sessionId).isOk());
907     sleep(1);
908     EXPECT_TRUE(p2p_iface_->stopUsdBasedServiceAdvertisement(sessionId).isOk());
909 }
910 
911 /*
912  * ProvisionDiscoveryWithParams
913  */
TEST_P(SupplicantP2pIfaceAidlTest,ProvisionDiscoveryWithParams)914 TEST_P(SupplicantP2pIfaceAidlTest, ProvisionDiscoveryWithParams) {
915     if (interface_version_ < 4) {
916         GTEST_SKIP() << "ProvisionDiscoveryWithParams is available as of Supplicant V4";
917     }
918     if (!(supported_features_ & ISupplicantP2pIface::P2P_FEATURE_V2)) {
919         GTEST_SKIP() << "P2P2 is not supported";
920     }
921 
922     P2pProvisionDiscoveryParams params;
923     params.peerMacAddress = vecToArrayMacAddr(kTestMacAddr);
924     params.provisionMethod = WpsProvisionMethod::NONE;
925     params.pairingBootstrappingMethod =
926             P2pPairingBootstrappingMethodMask::BOOTSTRAPPING_OPPORTUNISTIC;
927 
928     EXPECT_TRUE(p2p_iface_->provisionDiscoveryWithParams(params).isOk());
929 }
930 
931 /*
932  * ValidateDirInfo
933  */
TEST_P(SupplicantP2pIfaceAidlTest,ValidateDirInfo)934 TEST_P(SupplicantP2pIfaceAidlTest, ValidateDirInfo) {
935     if (interface_version_ < 4) {
936         GTEST_SKIP() << "ValidateDirInfo is available as of Supplicant V4";
937     }
938     if (!(supported_features_ & ISupplicantP2pIface::P2P_FEATURE_V2)) {
939         GTEST_SKIP() << "P2P2 is not supported";
940     }
941 
942     int32_t ret;
943     P2pDirInfo dirInfo;
944     dirInfo.cipherVersion = P2pDirInfo::CipherVersion::DIRA_CIPHER_VERSION_128_BIT;
945     dirInfo.deviceInterfaceMacAddress = vecToArrayMacAddr(kTestMacAddr);
946     dirInfo.nonce = kTestNonce;
947     dirInfo.dirTag = kTestDirTag;
948     EXPECT_TRUE(p2p_iface_->validateDirInfo(dirInfo, &ret).isOk());
949 }
950 
951 /*
952  * GetDirInfo
953  */
TEST_P(SupplicantP2pIfaceAidlTest,GetDirInfo)954 TEST_P(SupplicantP2pIfaceAidlTest, GetDirInfo) {
955     if (interface_version_ < 4) {
956         GTEST_SKIP() << "GetDirInfo is available as of Supplicant V4";
957     }
958     if (!(supported_features_ & ISupplicantP2pIface::P2P_FEATURE_V2)) {
959         GTEST_SKIP() << "P2P2 is not supported";
960     }
961 
962     P2pDirInfo dirInfo;
963     EXPECT_TRUE(p2p_iface_->getDirInfo(&dirInfo).isOk());
964 }
965 
966 /*
967  * ReinvokePersistentGroup
968  */
TEST_P(SupplicantP2pIfaceAidlTest,ReinvokePersistentGroup)969 TEST_P(SupplicantP2pIfaceAidlTest, ReinvokePersistentGroup) {
970     if (interface_version_ < 4) {
971         GTEST_SKIP() << "ReinvokePersistentGroup is available as of Supplicant V4";
972     }
973     if (!(supported_features_ & ISupplicantP2pIface::P2P_FEATURE_V2)) {
974         GTEST_SKIP() << "P2P2 is not supported";
975     }
976 
977     P2pReinvokePersistentGroupParams params;
978     params.peerMacAddress = vecToArrayMacAddr(kTestMacAddr);
979     params.persistentNetworkId = 0;
980     params.deviceIdentityEntryId = 0;
981 
982     EXPECT_TRUE(p2p_iface_->reinvokePersistentGroup(params).isOk());
983 }
984 
985 /*
986  * Test the P2P network management functions.
987  */
TEST_P(SupplicantP2pIfaceAidlTest,ManageNetworks)988 TEST_P(SupplicantP2pIfaceAidlTest, ManageNetworks) {
989     // Create a persistent group to bring up a network
990     EXPECT_TRUE(p2p_iface_->addGroup(true /* persistent */, -1).isOk());
991     sleep(2);
992 
993     std::vector<int32_t> networkList;
994     EXPECT_TRUE(p2p_iface_->listNetworks(&networkList).isOk());
995     ASSERT_FALSE(networkList.empty());
996 
997     int networkId = networkList[0];
998     std::shared_ptr<ISupplicantP2pNetwork> network;
999     EXPECT_TRUE(p2p_iface_->getNetwork(networkId, &network).isOk());
1000     ASSERT_NE(network, nullptr);
1001     EXPECT_TRUE(p2p_iface_->removeNetwork(networkId).isOk());
1002 }
1003 
1004 /*
1005  * Request and cancel service discovery
1006  */
TEST_P(SupplicantP2pIfaceAidlTest,RequestAndCancelServiceDiscovery)1007 TEST_P(SupplicantP2pIfaceAidlTest, RequestAndCancelServiceDiscovery) {
1008     int64_t discoveryId;
1009     std::vector<uint8_t> query = {0x11, 0x22, 0x33};
1010     EXPECT_TRUE(p2p_iface_->requestServiceDiscovery(kTestMacAddr, query, &discoveryId).isOk());
1011     EXPECT_TRUE(p2p_iface_->cancelServiceDiscovery(discoveryId).isOk());
1012 }
1013 
1014 /*
1015  * Start and stop WPS
1016  */
TEST_P(SupplicantP2pIfaceAidlTest,StartAndStopWps)1017 TEST_P(SupplicantP2pIfaceAidlTest, StartAndStopWps) {
1018     // Expected to fail with test values
1019     std::string generatedPin;
1020     EXPECT_FALSE(p2p_iface_->startWpsPbc(kTestGroupIfName, kTestMacAddr).isOk());
1021     EXPECT_FALSE(
1022             p2p_iface_->startWpsPinDisplay(kTestGroupIfName, kTestMacAddr, &generatedPin).isOk());
1023     EXPECT_FALSE(p2p_iface_->startWpsPinKeypad(kTestGroupIfName, kTestConnectPin).isOk());
1024     EXPECT_FALSE(p2p_iface_->cancelWps(kTestGroupIfName).isOk());
1025 }
1026 
1027 /*
1028  * Create message and report handover for NFC Request
1029  */
TEST_P(SupplicantP2pIfaceAidlTest,CreateAndReportNfcRequest)1030 TEST_P(SupplicantP2pIfaceAidlTest, CreateAndReportNfcRequest) {
1031     std::vector<uint8_t> requestMsg;
1032     EXPECT_TRUE(p2p_iface_->createNfcHandoverRequestMessage(&requestMsg).isOk());
1033     EXPECT_FALSE(requestMsg.empty());
1034     EXPECT_TRUE(p2p_iface_->reportNfcHandoverResponse(requestMsg).isOk());
1035 }
1036 
1037 /*
1038  * Create message and report handover for NFC Select
1039  */
TEST_P(SupplicantP2pIfaceAidlTest,CreateAndReportNfcSelect)1040 TEST_P(SupplicantP2pIfaceAidlTest, CreateAndReportNfcSelect) {
1041     std::vector<uint8_t> selectMsg;
1042     EXPECT_TRUE(p2p_iface_->createNfcHandoverSelectMessage(&selectMsg).isOk());
1043     EXPECT_FALSE(selectMsg.empty());
1044     EXPECT_TRUE(p2p_iface_->reportNfcHandoverInitiation(selectMsg).isOk());
1045 }
1046 
1047 /*
1048  * RemoveClient
1049  */
TEST_P(SupplicantP2pIfaceAidlTest,RemoveClient)1050 TEST_P(SupplicantP2pIfaceAidlTest, RemoveClient) {
1051     // Method returns success for any valid MAC address
1052     EXPECT_TRUE(p2p_iface_->removeClient(kTestMacAddr, false).isOk());
1053     // Returns failure for any invalid MAC address
1054     std::vector<uint8_t> invalidMacAddr = {0x11, 0x22};
1055     EXPECT_FALSE(p2p_iface_->removeClient(invalidMacAddr, false).isOk());
1056 }
1057 
1058 /*
1059  * ConfigureEapolIpAddressAllocationParams
1060  */
TEST_P(SupplicantP2pIfaceAidlTest,ConfigureEapolIpAddressAllocationParams)1061 TEST_P(SupplicantP2pIfaceAidlTest, ConfigureEapolIpAddressAllocationParams) {
1062     if (interface_version_ < 2) {
1063         GTEST_SKIP() << "ConfigureEapolIpAddressAllocationParams is available as of Supplicant V2";
1064     }
1065     // The IP addresses are IPV4 addresses and higher-order address bytes are in the
1066     // lower-order int bytes (e.g. 192.168.1.1 is represented as 0x0101A8C0)
1067     EXPECT_TRUE(p2p_iface_
1068                         ->configureEapolIpAddressAllocationParams(0x0101A8C0, 0x00FFFFFF,
1069                                                                   0x0501A8C0, 0x0801A8C0)
1070                         .isOk());
1071 
1072     // Clear the configuration.
1073     EXPECT_TRUE(p2p_iface_->configureEapolIpAddressAllocationParams(0, 0, 0, 0).isOk());
1074 }
1075 
1076 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(SupplicantP2pIfaceAidlTest);
1077 INSTANTIATE_TEST_SUITE_P(Supplicant, SupplicantP2pIfaceAidlTest,
1078                          testing::ValuesIn(android::getAidlHalInstanceNames(
1079                              ISupplicant::descriptor)),
1080                          android::PrintInstanceNameToString);
1081 
main(int argc,char ** argv)1082 int main(int argc, char** argv) {
1083     ::testing::InitGoogleTest(&argc, argv);
1084     ProcessState::self()->setThreadPoolMaxThreadCount(1);
1085     ProcessState::self()->startThreadPool();
1086     return RUN_ALL_TESTS();
1087 }
1088