1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <android-base/logging.h>
18 #include <gtest/gtest.h>
19 #include <hidl/GtestPrinter.h>
20 #include <hidl/ServiceManagement.h>
21 
22 #include <VtsCoreUtil.h>
23 #include <android/hardware/wifi/1.0/IWifi.h>
24 #include <android/hardware/wifi/supplicant/1.0/ISupplicantP2pIface.h>
25 
26 #include "supplicant_hidl_call_util.h"
27 #include "supplicant_hidl_test_utils.h"
28 
29 using ::android::sp;
30 using ::android::hardware::hidl_array;
31 using ::android::hardware::hidl_string;
32 using ::android::hardware::hidl_vec;
33 using ::android::hardware::Return;
34 using ::android::hardware::Void;
35 using ::android::hardware::wifi::supplicant::V1_0::IfaceType;
36 using ::android::hardware::wifi::supplicant::V1_0::ISupplicant;
37 using ::android::hardware::wifi::supplicant::V1_0::ISupplicantP2pIface;
38 using ::android::hardware::wifi::supplicant::V1_0::ISupplicantP2pIfaceCallback;
39 using ::android::hardware::wifi::supplicant::V1_0::SupplicantNetworkId;
40 using ::android::hardware::wifi::supplicant::V1_0::SupplicantStatus;
41 using ::android::hardware::wifi::supplicant::V1_0::SupplicantStatusCode;
42 using ::android::hardware::wifi::V1_0::IWifi;
43 
44 namespace {
45 constexpr uint8_t kTestSsidPostfix[] = {'t', 'e', 's', 't'};
46 constexpr uint8_t kTestMacAddr[] = {0x56, 0x67, 0x67, 0xf4, 0x56, 0x92};
47 constexpr uint8_t kTestPeerMacAddr[] = {0x56, 0x67, 0x55, 0xf4, 0x56, 0x92};
48 constexpr uint8_t kTestBonjourServiceQuery[] = {'t', 'e', 's', 't', 'q',
49                                                 'u', 'e', 'r', 'y'};
50 constexpr uint8_t kTestBonjourServiceResponse[] = {
51     't', 'e', 's', 't', 'r', 'e', 's', 'p', 'o', 'n', 's', 'e'};
52 constexpr uint8_t kTestWfdDeviceInfo[] = {[0 ... 5] = 0x01};
53 constexpr char kTestConnectPin[] = "34556665";
54 constexpr char kTestGroupIfName[] = "TestGroup";
55 constexpr char kTestWpsDeviceName[] = "TestWpsDeviceName";
56 constexpr char kTestWpsManufacturer[] = "TestManufacturer";
57 constexpr char kTestWpsModelName[] = "TestModelName";
58 constexpr char kTestWpsModelNumber[] = "TestModelNumber";
59 constexpr char kTestWpsSerialNumber[] = "TestSerialNumber";
60 constexpr char kTestUpnpServiceName[] = "TestServiceName";
61 constexpr uint8_t kTestWpsDeviceType[] = {[0 ... 7] = 0x01};
62 constexpr uint16_t kTestWpsConfigMethods = 0xffff;
63 constexpr uint32_t kTestConnectGoIntent = 6;
64 constexpr uint32_t kTestFindTimeout = 5;
65 constexpr uint32_t kTestSetGroupIdleTimeout = 6;
66 constexpr uint32_t kTestChannel = 1;
67 constexpr uint32_t kTestOperatingClass = 81;
68 constexpr uint32_t kTestFreqRange[] = {2412, 2432};
69 constexpr uint32_t kTestExtListenPeriod = 400;
70 constexpr uint32_t kTestExtListenInterval = 400;
71 constexpr SupplicantNetworkId kTestNetworkId = 5;
72 }  // namespace
73 
74 class SupplicantP2pIfaceHidlTest
75     : public ::testing::TestWithParam<std::tuple<std::string, std::string>> {
76    public:
SetUp()77     virtual void SetUp() override {
78         wifi_instance_name_ = std::get<0>(GetParam());
79         supplicant_instance_name_ = std::get<1>(GetParam());
80         stopSupplicant(wifi_instance_name_);
81         startSupplicantAndWaitForHidlService(wifi_instance_name_,
82                                              supplicant_instance_name_);
83         isP2pOn_ =
84             testing::deviceSupportsFeature("android.hardware.wifi.direct");
85         supplicant_ = getSupplicant(supplicant_instance_name_, isP2pOn_);
86         EXPECT_TRUE(turnOnExcessiveLogging(supplicant_));
87         p2p_iface_ = getSupplicantP2pIface(supplicant_);
88         ASSERT_NE(p2p_iface_.get(), nullptr);
89 
90         memcpy(mac_addr_.data(), kTestMacAddr, mac_addr_.size());
91         memcpy(peer_mac_addr_.data(), kTestPeerMacAddr, peer_mac_addr_.size());
92     }
93 
TearDown()94     virtual void TearDown() override { stopSupplicant(wifi_instance_name_); }
95 
96    protected:
97     bool isP2pOn_ = false;
98     sp<ISupplicant> supplicant_;
99     // ISupplicantP2pIface object used for all tests in this fixture.
100     sp<ISupplicantP2pIface> p2p_iface_;
101     // MAC address to use for various tests.
102     std::array<uint8_t, 6> mac_addr_;
103     std::array<uint8_t, 6> peer_mac_addr_;
104     std::string wifi_instance_name_;
105     std::string supplicant_instance_name_;
106 };
107 
108 class IfaceCallback : public ISupplicantP2pIfaceCallback {
onNetworkAdded(uint32_t)109     Return<void> onNetworkAdded(uint32_t /* id */) override { return Void(); }
onNetworkRemoved(uint32_t)110     Return<void> onNetworkRemoved(uint32_t /* id */) override { return Void(); }
onDeviceFound(const hidl_array<uint8_t,6> &,const hidl_array<uint8_t,6> &,const hidl_array<uint8_t,8> &,const hidl_string &,uint16_t,uint8_t,uint32_t,const hidl_array<uint8_t,6> &)111     Return<void> onDeviceFound(
112         const hidl_array<uint8_t, 6>& /* srcAddress */,
113         const hidl_array<uint8_t, 6>& /* p2pDeviceAddress */,
114         const hidl_array<uint8_t, 8>& /* primaryDeviceType */,
115         const hidl_string& /* deviceName */, uint16_t /* configMethods */,
116         uint8_t /* deviceCapabilities */, uint32_t /* groupCapabilities */,
117         const hidl_array<uint8_t, 6>& /* wfdDeviceInfo */) override {
118         return Void();
119     }
onDeviceLost(const hidl_array<uint8_t,6> &)120     Return<void> onDeviceLost(
121         const hidl_array<uint8_t, 6>& /* p2pDeviceAddress */) override {
122         return Void();
123     }
onFindStopped()124     Return<void> onFindStopped() override { return Void(); }
onGoNegotiationRequest(const hidl_array<uint8_t,6> &,ISupplicantP2pIfaceCallback::WpsDevPasswordId)125     Return<void> onGoNegotiationRequest(
126         const hidl_array<uint8_t, 6>& /* srcAddress */,
127         ISupplicantP2pIfaceCallback::WpsDevPasswordId /* passwordId */)
128         override {
129         return Void();
130     }
onGoNegotiationCompleted(ISupplicantP2pIfaceCallback::P2pStatusCode)131     Return<void> onGoNegotiationCompleted(
132         ISupplicantP2pIfaceCallback::P2pStatusCode /* status */) override {
133         return Void();
134     }
onGroupFormationSuccess()135     Return<void> onGroupFormationSuccess() override { return Void(); }
onGroupFormationFailure(const hidl_string &)136     Return<void> onGroupFormationFailure(
137         const hidl_string& /* failureReason */) override {
138         return Void();
139     }
onGroupStarted(const hidl_string &,bool,const hidl_vec<uint8_t> &,uint32_t,const hidl_array<uint8_t,32> &,const hidl_string &,const hidl_array<uint8_t,6> &,bool)140     Return<void> onGroupStarted(
141         const hidl_string& /* groupIfname */, bool /* isGo */,
142         const hidl_vec<uint8_t>& /* ssid */, uint32_t /* frequency */,
143         const hidl_array<uint8_t, 32>& /* psk */,
144         const hidl_string& /* passphrase */,
145         const hidl_array<uint8_t, 6>& /* goDeviceAddress */,
146         bool /* isPersistent */) override {
147         return Void();
148     }
onGroupRemoved(const hidl_string &,bool)149     Return<void> onGroupRemoved(const hidl_string& /* groupIfname */,
150                                 bool /* isGo */) override {
151         return Void();
152     }
onInvitationReceived(const hidl_array<uint8_t,6> &,const hidl_array<uint8_t,6> &,const hidl_array<uint8_t,6> &,uint32_t,uint32_t)153     Return<void> onInvitationReceived(
154         const hidl_array<uint8_t, 6>& /* srcAddress */,
155         const hidl_array<uint8_t, 6>& /* goDeviceAddress */,
156         const hidl_array<uint8_t, 6>& /* bssid */,
157         uint32_t /* persistentNetworkId */,
158         uint32_t /* operatingFrequency */) override {
159         return Void();
160     }
onInvitationResult(const hidl_array<uint8_t,6> &,ISupplicantP2pIfaceCallback::P2pStatusCode)161     Return<void> onInvitationResult(
162         const hidl_array<uint8_t, 6>& /* bssid */,
163         ISupplicantP2pIfaceCallback::P2pStatusCode /* status */) override {
164         return Void();
165     }
onProvisionDiscoveryCompleted(const hidl_array<uint8_t,6> &,bool,ISupplicantP2pIfaceCallback::P2pProvDiscStatusCode,uint16_t,const hidl_string &)166     Return<void> onProvisionDiscoveryCompleted(
167         const hidl_array<uint8_t, 6>& /* p2pDeviceAddress */,
168         bool /* isRequest */,
169         ISupplicantP2pIfaceCallback::P2pProvDiscStatusCode /* status */,
170         uint16_t /* configMethods */,
171         const hidl_string& /* generatedPin */) override {
172         return Void();
173     }
onServiceDiscoveryResponse(const hidl_array<uint8_t,6> &,uint16_t,const hidl_vec<uint8_t> &)174     Return<void> onServiceDiscoveryResponse(
175         const hidl_array<uint8_t, 6>& /* srcAddress */,
176         uint16_t /* updateIndicator */,
177         const hidl_vec<uint8_t>& /* tlvs */) override {
178         return Void();
179     }
onStaAuthorized(const hidl_array<uint8_t,6> &,const hidl_array<uint8_t,6> &)180     Return<void> onStaAuthorized(
181         const hidl_array<uint8_t, 6>& /* srcAddress */,
182         const hidl_array<uint8_t, 6>& /* p2pDeviceAddress */) override {
183         return Void();
184     }
onStaDeauthorized(const hidl_array<uint8_t,6> &,const hidl_array<uint8_t,6> &)185     Return<void> onStaDeauthorized(
186         const hidl_array<uint8_t, 6>& /* srcAddress */,
187         const hidl_array<uint8_t, 6>& /* p2pDeviceAddress */) override {
188         return Void();
189     }
190 };
191 
192 /*
193  * Create:
194  * Ensures that an instance of the ISupplicantP2pIface proxy object is
195  * successfully created.
196  */
TEST_P(SupplicantP2pIfaceHidlTest,Create)197 TEST_P(SupplicantP2pIfaceHidlTest, Create) {
198     stopSupplicant(wifi_instance_name_);
199     startSupplicantAndWaitForHidlService(wifi_instance_name_,
200                                          supplicant_instance_name_);
201     sp<ISupplicantP2pIface> p2p_iface = getSupplicantP2pIface(
202         getSupplicant(supplicant_instance_name_, isP2pOn_));
203 
204     EXPECT_NE(nullptr, p2p_iface.get());
205 }
206 
207 /*
208  * RegisterCallback
209  */
TEST_P(SupplicantP2pIfaceHidlTest,RegisterCallback)210 TEST_P(SupplicantP2pIfaceHidlTest, RegisterCallback) {
211     p2p_iface_->registerCallback(
212         new IfaceCallback(), [](const SupplicantStatus& status) {
213             EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
214         });
215 }
216 
217 /*
218  * GetName
219  */
TEST_P(SupplicantP2pIfaceHidlTest,GetName)220 TEST_P(SupplicantP2pIfaceHidlTest, GetName) {
221     const auto& status_and_interface_name = HIDL_INVOKE(p2p_iface_, getName);
222     EXPECT_EQ(SupplicantStatusCode::SUCCESS,
223               status_and_interface_name.first.code);
224     EXPECT_FALSE(std::string(status_and_interface_name.second).empty());
225 }
226 
227 /*
228  * GetType
229  */
TEST_P(SupplicantP2pIfaceHidlTest,GetType)230 TEST_P(SupplicantP2pIfaceHidlTest, GetType) {
231     const auto& status_and_interface_type = HIDL_INVOKE(p2p_iface_, getType);
232     EXPECT_EQ(SupplicantStatusCode::SUCCESS,
233               status_and_interface_type.first.code);
234     EXPECT_EQ(status_and_interface_type.second, IfaceType::P2P);
235 }
236 
237 /*
238  * GetDeviceAddress
239  */
TEST_P(SupplicantP2pIfaceHidlTest,GetDeviceAddress)240 TEST_P(SupplicantP2pIfaceHidlTest, GetDeviceAddress) {
241     p2p_iface_->getDeviceAddress(
242         [](const SupplicantStatus& status,
243            const hidl_array<uint8_t, 6>& /* mac_addr */) {
244             EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
245         });
246 }
247 
248 /*
249  * SetSsidPostfix
250  */
TEST_P(SupplicantP2pIfaceHidlTest,SetSsidPostfix)251 TEST_P(SupplicantP2pIfaceHidlTest, SetSsidPostfix) {
252     std::vector<uint8_t> ssid(kTestSsidPostfix,
253                               kTestSsidPostfix + sizeof(kTestSsidPostfix));
254     p2p_iface_->setSsidPostfix(ssid, [](const SupplicantStatus& status) {
255         EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
256     });
257 }
258 
259 /*
260  * Find
261  */
TEST_P(SupplicantP2pIfaceHidlTest,Find)262 TEST_P(SupplicantP2pIfaceHidlTest, Find) {
263     p2p_iface_->find(kTestFindTimeout, [](const SupplicantStatus& status) {
264         EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
265     });
266 }
267 
268 /*
269  * StopFind
270  */
TEST_P(SupplicantP2pIfaceHidlTest,StopFind)271 TEST_P(SupplicantP2pIfaceHidlTest, StopFind) {
272     p2p_iface_->find(kTestFindTimeout, [](const SupplicantStatus& status) {
273         EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
274     });
275 
276     p2p_iface_->stopFind([](const SupplicantStatus& status) {
277         EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
278     });
279 }
280 
281 /*
282  * Flush
283  */
TEST_P(SupplicantP2pIfaceHidlTest,Flush)284 TEST_P(SupplicantP2pIfaceHidlTest, Flush) {
285     p2p_iface_->flush([](const SupplicantStatus& status) {
286         EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
287     });
288 }
289 
290 /*
291  * Connect
292  */
TEST_P(SupplicantP2pIfaceHidlTest,Connect)293 TEST_P(SupplicantP2pIfaceHidlTest, Connect) {
294     p2p_iface_->connect(
295         mac_addr_, ISupplicantP2pIface::WpsProvisionMethod::PBC,
296         kTestConnectPin, false, false, kTestConnectGoIntent,
297         [](const SupplicantStatus& status, const hidl_string& /* pin */) {
298             // This is not going to work with fake values.
299             EXPECT_EQ(SupplicantStatusCode::FAILURE_UNKNOWN, status.code);
300         });
301 }
302 
303 /*
304  * CancelConnect
305  */
TEST_P(SupplicantP2pIfaceHidlTest,CancelConnect)306 TEST_P(SupplicantP2pIfaceHidlTest, CancelConnect) {
307     p2p_iface_->connect(
308         mac_addr_, ISupplicantP2pIface::WpsProvisionMethod::PBC,
309         kTestConnectPin, false, false, kTestConnectGoIntent,
310         [](const SupplicantStatus& status, const hidl_string& /* pin */) {
311             // This is not going to work with fake values.
312             EXPECT_EQ(SupplicantStatusCode::FAILURE_UNKNOWN, status.code);
313         });
314 
315     p2p_iface_->cancelConnect([](const SupplicantStatus& status) {
316         EXPECT_EQ(SupplicantStatusCode::FAILURE_UNKNOWN, status.code);
317     });
318 }
319 
320 /*
321  * ProvisionDiscovery
322  */
TEST_P(SupplicantP2pIfaceHidlTest,ProvisionDiscovery)323 TEST_P(SupplicantP2pIfaceHidlTest, ProvisionDiscovery) {
324     p2p_iface_->provisionDiscovery(
325         mac_addr_, ISupplicantP2pIface::WpsProvisionMethod::PBC,
326         [](const SupplicantStatus& status) {
327             // This is not going to work with fake values.
328             EXPECT_EQ(SupplicantStatusCode::FAILURE_UNKNOWN, status.code);
329         });
330 }
331 
332 /*
333  * AddGroup
334  */
TEST_P(SupplicantP2pIfaceHidlTest,AddGroup)335 TEST_P(SupplicantP2pIfaceHidlTest, AddGroup) {
336     p2p_iface_->addGroup(false, kTestNetworkId,
337                          [](const SupplicantStatus& /* status */) {
338                              // TODO: Figure out the initialization sequence for
339                              // this to work.
340                              // EXPECT_EQ(SupplicantStatusCode::SUCCESS,
341                              // status.code);
342                          });
343 }
344 
345 /*
346  * RemoveGroup
347  */
TEST_P(SupplicantP2pIfaceHidlTest,RemoveGroup)348 TEST_P(SupplicantP2pIfaceHidlTest, RemoveGroup) {
349     // This is not going to work with fake values.
350     EXPECT_NE(SupplicantStatusCode::SUCCESS,
351               HIDL_INVOKE(p2p_iface_, removeGroup, kTestGroupIfName).code);
352 }
353 
354 /*
355  * Reject
356  */
TEST_P(SupplicantP2pIfaceHidlTest,Reject)357 TEST_P(SupplicantP2pIfaceHidlTest, Reject) {
358     p2p_iface_->reject(mac_addr_, [](const SupplicantStatus& status) {
359         // This is not going to work with fake values.
360         EXPECT_EQ(SupplicantStatusCode::FAILURE_UNKNOWN, status.code);
361     });
362 }
363 
364 /*
365  * Invite
366  */
TEST_P(SupplicantP2pIfaceHidlTest,Invite)367 TEST_P(SupplicantP2pIfaceHidlTest, Invite) {
368     p2p_iface_->invite(kTestGroupIfName, mac_addr_, peer_mac_addr_,
369                        [](const SupplicantStatus& status) {
370                            // This is not going to work with fake values.
371                            EXPECT_EQ(SupplicantStatusCode::FAILURE_UNKNOWN,
372                                      status.code);
373                        });
374 }
375 
376 /*
377  * Reinvoke
378  */
TEST_P(SupplicantP2pIfaceHidlTest,Reinvoke)379 TEST_P(SupplicantP2pIfaceHidlTest, Reinvoke) {
380     p2p_iface_->reinvoke(
381         kTestNetworkId, mac_addr_, [](const SupplicantStatus& status) {
382             // This is not going to work with fake values.
383             EXPECT_EQ(SupplicantStatusCode::FAILURE_NETWORK_UNKNOWN,
384                       status.code);
385         });
386 }
387 
388 /*
389  * ConfigureExtListen
390  */
TEST_P(SupplicantP2pIfaceHidlTest,ConfigureExtListen)391 TEST_P(SupplicantP2pIfaceHidlTest, ConfigureExtListen) {
392     p2p_iface_->configureExtListen(kTestExtListenPeriod, kTestExtListenInterval,
393                                    [](const SupplicantStatus& status) {
394                                        EXPECT_EQ(SupplicantStatusCode::SUCCESS,
395                                                  status.code);
396                                    });
397 }
398 
399 /*
400  * SetListenChannel
401  */
TEST_P(SupplicantP2pIfaceHidlTest,SetListenChannel)402 TEST_P(SupplicantP2pIfaceHidlTest, SetListenChannel) {
403     p2p_iface_->setListenChannel(
404         kTestChannel, kTestOperatingClass, [](const SupplicantStatus& status) {
405             EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
406         });
407 }
408 
409 /*
410  * SetDisallowedFrequencies
411  */
TEST_P(SupplicantP2pIfaceHidlTest,SetDisallowedFrequencies)412 TEST_P(SupplicantP2pIfaceHidlTest, SetDisallowedFrequencies) {
413     std::vector<ISupplicantP2pIface::FreqRange> ranges = {
414         {kTestFreqRange[0], kTestFreqRange[1]}};
415     p2p_iface_->setDisallowedFrequencies(
416         ranges, [](const SupplicantStatus& status) {
417             EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
418         });
419 }
420 
421 /*
422  * GetSsid
423  */
TEST_P(SupplicantP2pIfaceHidlTest,GetSsid)424 TEST_P(SupplicantP2pIfaceHidlTest, GetSsid) {
425     std::array<uint8_t, 6> mac_addr;
426     memcpy(mac_addr.data(), kTestMacAddr, mac_addr.size());
427     p2p_iface_->getSsid(mac_addr, [](const SupplicantStatus& status,
428                                      const hidl_vec<uint8_t>& /* ssid */) {
429         // This is not going to work with fake values.
430         EXPECT_EQ(SupplicantStatusCode::FAILURE_UNKNOWN, status.code);
431     });
432 }
433 
434 /*
435  * GetGroupCapability
436  */
TEST_P(SupplicantP2pIfaceHidlTest,GetGroupCapability)437 TEST_P(SupplicantP2pIfaceHidlTest, GetGroupCapability) {
438     std::array<uint8_t, 6> mac_addr;
439     memcpy(mac_addr.data(), kTestMacAddr, mac_addr.size());
440     p2p_iface_->getGroupCapability(
441         mac_addr, [](const SupplicantStatus& status, uint32_t /* caps */) {
442             // This is not going to work with fake values.
443             EXPECT_EQ(SupplicantStatusCode::FAILURE_UNKNOWN, status.code);
444         });
445 }
446 
447 /*
448  * FlushServices
449  */
TEST_P(SupplicantP2pIfaceHidlTest,FlushServices)450 TEST_P(SupplicantP2pIfaceHidlTest, FlushServices) {
451     p2p_iface_->flushServices([](const SupplicantStatus& status) {
452         EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
453     });
454 }
455 
456 /*
457  * SetMiracastMode
458  */
TEST_P(SupplicantP2pIfaceHidlTest,SetMiracastMode)459 TEST_P(SupplicantP2pIfaceHidlTest, SetMiracastMode) {
460     p2p_iface_->setMiracastMode(ISupplicantP2pIface::MiracastMode::DISABLED,
461                                 [](const SupplicantStatus& status) {
462                                     EXPECT_EQ(SupplicantStatusCode::SUCCESS,
463                                               status.code);
464                                 });
465     p2p_iface_->setMiracastMode(ISupplicantP2pIface::MiracastMode::SOURCE,
466                                 [](const SupplicantStatus& status) {
467                                     EXPECT_EQ(SupplicantStatusCode::SUCCESS,
468                                               status.code);
469                                 });
470     p2p_iface_->setMiracastMode(ISupplicantP2pIface::MiracastMode::SINK,
471                                 [](const SupplicantStatus& status) {
472                                     EXPECT_EQ(SupplicantStatusCode::SUCCESS,
473                                               status.code);
474                                 });
475 }
476 
477 /*
478  * SetGroupIdle
479  */
TEST_P(SupplicantP2pIfaceHidlTest,SetGroupIdle)480 TEST_P(SupplicantP2pIfaceHidlTest, SetGroupIdle) {
481     // This is not going to work with fake values.
482     EXPECT_NE(SupplicantStatusCode::SUCCESS,
483               HIDL_INVOKE(p2p_iface_, setGroupIdle, kTestGroupIfName,
484                           kTestSetGroupIdleTimeout)
485                   .code);
486 }
487 
488 /*
489  * SetPowerSave
490  */
TEST_P(SupplicantP2pIfaceHidlTest,SetPowerSave)491 TEST_P(SupplicantP2pIfaceHidlTest, SetPowerSave) {
492     // This is not going to work with fake values.
493     EXPECT_NE(
494         SupplicantStatusCode::SUCCESS,
495         HIDL_INVOKE(p2p_iface_, setPowerSave, kTestGroupIfName, true).code);
496     // This is not going to work with fake values.
497     EXPECT_NE(
498         SupplicantStatusCode::SUCCESS,
499         HIDL_INVOKE(p2p_iface_, setPowerSave, kTestGroupIfName, false).code);
500 }
501 
502 /*
503  * SetWpsDeviceName
504  */
TEST_P(SupplicantP2pIfaceHidlTest,SetWpsDeviceName)505 TEST_P(SupplicantP2pIfaceHidlTest, SetWpsDeviceName) {
506     EXPECT_EQ(
507         SupplicantStatusCode::SUCCESS,
508         HIDL_INVOKE(p2p_iface_, setWpsDeviceName, kTestWpsDeviceName).code);
509 }
510 
511 /*
512  * SetWpsDeviceType
513  */
TEST_P(SupplicantP2pIfaceHidlTest,SetWpsDeviceType)514 TEST_P(SupplicantP2pIfaceHidlTest, SetWpsDeviceType) {
515     EXPECT_EQ(
516         SupplicantStatusCode::SUCCESS,
517         HIDL_INVOKE(p2p_iface_, setWpsDeviceType, kTestWpsDeviceType).code);
518 }
519 
520 /*
521  * SetWpsManufacturer
522  */
TEST_P(SupplicantP2pIfaceHidlTest,SetWpsManufacturer)523 TEST_P(SupplicantP2pIfaceHidlTest, SetWpsManufacturer) {
524     EXPECT_EQ(
525         SupplicantStatusCode::SUCCESS,
526         HIDL_INVOKE(p2p_iface_, setWpsManufacturer, kTestWpsManufacturer).code);
527 }
528 
529 /*
530  * SetWpsModelName
531  */
TEST_P(SupplicantP2pIfaceHidlTest,SetWpsModelName)532 TEST_P(SupplicantP2pIfaceHidlTest, SetWpsModelName) {
533     EXPECT_EQ(SupplicantStatusCode::SUCCESS,
534               HIDL_INVOKE(p2p_iface_, setWpsModelName, kTestWpsModelName).code);
535 }
536 
537 /*
538  * SetWpsModelNumber
539  */
TEST_P(SupplicantP2pIfaceHidlTest,SetWpsModelNumber)540 TEST_P(SupplicantP2pIfaceHidlTest, SetWpsModelNumber) {
541     EXPECT_EQ(
542         SupplicantStatusCode::SUCCESS,
543         HIDL_INVOKE(p2p_iface_, setWpsModelNumber, kTestWpsModelNumber).code);
544 }
545 
546 /*
547  * SetWpsSerialNumber
548  */
TEST_P(SupplicantP2pIfaceHidlTest,SetWpsSerialNumber)549 TEST_P(SupplicantP2pIfaceHidlTest, SetWpsSerialNumber) {
550     EXPECT_EQ(
551         SupplicantStatusCode::SUCCESS,
552         HIDL_INVOKE(p2p_iface_, setWpsSerialNumber, kTestWpsSerialNumber).code);
553 }
554 
555 /*
556  * SetWpsConfigMethods
557  */
TEST_P(SupplicantP2pIfaceHidlTest,SetWpsConfigMethods)558 TEST_P(SupplicantP2pIfaceHidlTest, SetWpsConfigMethods) {
559     EXPECT_EQ(
560         SupplicantStatusCode::SUCCESS,
561         HIDL_INVOKE(p2p_iface_, setWpsConfigMethods, kTestWpsConfigMethods)
562             .code);
563 }
564 
565 /*
566  * AddAndRemoveBonjourService
567  * This tests that we are able to add a bonjour service, and we can remove it
568  * by using the same query data.
569  * This also tests that removeBonjourSerive() returns error when there is no
570  * existing bonjour service with the same query data.
571  */
TEST_P(SupplicantP2pIfaceHidlTest,AddAndRemoveBonjourService)572 TEST_P(SupplicantP2pIfaceHidlTest, AddAndRemoveBonjourService) {
573     EXPECT_EQ(SupplicantStatusCode::SUCCESS,
574               HIDL_INVOKE(
575                   p2p_iface_, addBonjourService,
576                   std::vector<uint8_t>(kTestBonjourServiceQuery,
577                                        kTestBonjourServiceQuery +
578                                            sizeof(kTestBonjourServiceQuery)),
579                   std::vector<uint8_t>(kTestBonjourServiceResponse,
580                                        kTestBonjourServiceResponse +
581                                            sizeof(kTestBonjourServiceResponse)))
582                   .code);
583     EXPECT_EQ(
584         SupplicantStatusCode::SUCCESS,
585         HIDL_INVOKE(p2p_iface_, removeBonjourService,
586                     std::vector<uint8_t>(kTestBonjourServiceQuery,
587                                          kTestBonjourServiceQuery +
588                                              sizeof(kTestBonjourServiceQuery)))
589             .code);
590     // This will fail because boujour service with kTestBonjourServiceQuery was
591     // already removed.
592     EXPECT_NE(
593         SupplicantStatusCode::SUCCESS,
594         HIDL_INVOKE(p2p_iface_, removeBonjourService,
595                     std::vector<uint8_t>(kTestBonjourServiceQuery,
596                                          kTestBonjourServiceQuery +
597                                              sizeof(kTestBonjourServiceQuery)))
598             .code);
599 }
600 
601 /*
602  * AddAndRemoveUpnpService
603  * This tests that we are able to add a upnp service, and we can remove it
604  * by using the same service name.
605  * This also tests that removeUpnpService() returns error when there is no
606  * exsiting upnp service with the same service name.
607  */
TEST_P(SupplicantP2pIfaceHidlTest,AddAndRemoveUpnpService)608 TEST_P(SupplicantP2pIfaceHidlTest, AddAndRemoveUpnpService) {
609     EXPECT_EQ(SupplicantStatusCode::SUCCESS,
610               HIDL_INVOKE(p2p_iface_, addUpnpService, 0 /* version */,
611                           kTestUpnpServiceName)
612                   .code);
613     EXPECT_EQ(SupplicantStatusCode::SUCCESS,
614               HIDL_INVOKE(p2p_iface_, removeUpnpService, 0 /* version */,
615                           kTestUpnpServiceName)
616                   .code);
617     // This will fail because Upnp service with kTestUpnpServiceName was
618     // already removed.
619     EXPECT_NE(SupplicantStatusCode::SUCCESS,
620               HIDL_INVOKE(p2p_iface_, removeUpnpService, 0 /* version */,
621                           kTestUpnpServiceName)
622                   .code);
623 }
624 
625 /*
626  * EnableWfd
627  */
TEST_P(SupplicantP2pIfaceHidlTest,EnableWfd)628 TEST_P(SupplicantP2pIfaceHidlTest, EnableWfd) {
629     EXPECT_EQ(SupplicantStatusCode::SUCCESS,
630               HIDL_INVOKE(p2p_iface_, enableWfd, true).code);
631     EXPECT_EQ(SupplicantStatusCode::SUCCESS,
632               HIDL_INVOKE(p2p_iface_, enableWfd, false).code);
633 }
634 
635 /*
636  * SetWfdDeviceInfo
637  */
TEST_P(SupplicantP2pIfaceHidlTest,SetWfdDeviceInfo)638 TEST_P(SupplicantP2pIfaceHidlTest, SetWfdDeviceInfo) {
639     EXPECT_EQ(
640         SupplicantStatusCode::SUCCESS,
641         HIDL_INVOKE(p2p_iface_, setWfdDeviceInfo, kTestWfdDeviceInfo).code);
642 }
643 
644 INSTANTIATE_TEST_CASE_P(
645     PerInstance, SupplicantP2pIfaceHidlTest,
646     testing::Combine(
647         testing::ValuesIn(
648             android::hardware::getAllHalInstanceNames(IWifi::descriptor)),
649         testing::ValuesIn(android::hardware::getAllHalInstanceNames(
650             ISupplicant::descriptor))),
651     android::hardware::PrintInstanceTupleNameToString<>);