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/BnSupplicantP2pIfaceCallback.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::BnSupplicantP2pIfaceCallback;
31 using aidl::android::hardware::wifi::supplicant::DebugLevel;
32 using aidl::android::hardware::wifi::supplicant::FreqRange;
33 using aidl::android::hardware::wifi::supplicant::IfaceType;
34 using aidl::android::hardware::wifi::supplicant::ISupplicant;
35 using aidl::android::hardware::wifi::supplicant::ISupplicantP2pIface;
36 using aidl::android::hardware::wifi::supplicant::MiracastMode;
37 using aidl::android::hardware::wifi::supplicant::P2pFrameTypeMask;
38 using aidl::android::hardware::wifi::supplicant::P2pGroupCapabilityMask;
39 using aidl::android::hardware::wifi::supplicant::P2pProvDiscStatusCode;
40 using aidl::android::hardware::wifi::supplicant::P2pStatusCode;
41 using aidl::android::hardware::wifi::supplicant::WpsConfigMethods;
42 using aidl::android::hardware::wifi::supplicant::WpsDevPasswordId;
43 using aidl::android::hardware::wifi::supplicant::WpsProvisionMethod;
44 using android::ProcessState;
45
46 namespace {
47 const std::string kTestSsidStr = "TestSsid1234";
48 const std::vector<uint8_t> kTestSsid =
49 std::vector<uint8_t>(kTestSsidStr.begin(), kTestSsidStr.end());
50 const std::vector<uint8_t> kTestMacAddr = {0x56, 0x67, 0x67, 0xf4, 0x56, 0x92};
51 const std::vector<uint8_t> kTestPeerMacAddr = {0x56, 0x67, 0x55,
52 0xf4, 0x56, 0x92};
53 const std::vector<uint8_t> kTestZeroMacAddr = std::vector<uint8_t>(6, 0);
54 const std::string kTestPassphrase = "P2pWorld1234";
55 const std::string kTestConnectPin = "34556665";
56 const std::string kTestGroupIfName = "TestGroup";
57 const uint32_t kTestFindTimeout = 5;
58 const uint32_t kTestConnectGoIntent = 6;
59 const uint32_t kTestNetworkId = 7;
60 const uint32_t kTestGroupFreq = 0;
61 const bool kTestGroupPersistent = false;
62 const bool kTestGroupIsJoin = false;
63
64 } // namespace
65
66 class SupplicantP2pIfaceCallback : public BnSupplicantP2pIfaceCallback {
67 public:
68 SupplicantP2pIfaceCallback() = default;
69
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> &)70 ::ndk::ScopedAStatus onDeviceFound(
71 const std::vector<uint8_t>& /* srcAddress */,
72 const std::vector<uint8_t>& /* p2pDeviceAddress */,
73 const std::vector<uint8_t>& /* primaryDeviceType */,
74 const std::string& /* deviceName */,
75 WpsConfigMethods /* configMethods */, int8_t /* deviceCapabilities */,
76 P2pGroupCapabilityMask /* groupCapabilities */,
77 const std::vector<uint8_t>& /* wfdDeviceInfo */) override {
78 return ndk::ScopedAStatus::ok();
79 }
onDeviceLost(const std::vector<uint8_t> &)80 ::ndk::ScopedAStatus onDeviceLost(
81 const std::vector<uint8_t>& /* p2pDeviceAddress */) override {
82 return ndk::ScopedAStatus::ok();
83 }
onFindStopped()84 ::ndk::ScopedAStatus onFindStopped() override {
85 return ndk::ScopedAStatus::ok();
86 }
onGoNegotiationCompleted(P2pStatusCode)87 ::ndk::ScopedAStatus onGoNegotiationCompleted(
88 P2pStatusCode /* status */) override {
89 return ndk::ScopedAStatus::ok();
90 }
onGoNegotiationRequest(const std::vector<uint8_t> &,WpsDevPasswordId)91 ::ndk::ScopedAStatus onGoNegotiationRequest(
92 const std::vector<uint8_t>& /* srcAddress */,
93 WpsDevPasswordId /* passwordId */) override {
94 return ndk::ScopedAStatus::ok();
95 }
onGroupFormationFailure(const std::string &)96 ::ndk::ScopedAStatus onGroupFormationFailure(
97 const std::string& /* failureReason */) override {
98 return ndk::ScopedAStatus::ok();
99 }
onGroupFormationSuccess()100 ::ndk::ScopedAStatus onGroupFormationSuccess() override {
101 return ndk::ScopedAStatus::ok();
102 }
onGroupRemoved(const std::string &,bool)103 ::ndk::ScopedAStatus onGroupRemoved(const std::string& /* groupIfname */,
104 bool /* isGroupOwner */) override {
105 return ndk::ScopedAStatus::ok();
106 }
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)107 ::ndk::ScopedAStatus onGroupStarted(
108 const std::string& /* groupIfname */, bool /* isGroupOwner */,
109 const std::vector<uint8_t>& /* ssid */, int32_t /* frequency */,
110 const std::vector<uint8_t>& /* psk */,
111 const std::string& /* passphrase */,
112 const std::vector<uint8_t>& /* goDeviceAddress */,
113 bool /* isPersistent */) override {
114 return ndk::ScopedAStatus::ok();
115 }
onInvitationReceived(const std::vector<uint8_t> &,const std::vector<uint8_t> &,const std::vector<uint8_t> &,int32_t,int32_t)116 ::ndk::ScopedAStatus onInvitationReceived(
117 const std::vector<uint8_t>& /* srcAddress */,
118 const std::vector<uint8_t>& /* goDeviceAddress */,
119 const std::vector<uint8_t>& /* bssid */,
120 int32_t /* persistentNetworkId */,
121 int32_t /* operatingFrequency */) override {
122 return ndk::ScopedAStatus::ok();
123 }
onInvitationResult(const std::vector<uint8_t> &,P2pStatusCode)124 ::ndk::ScopedAStatus onInvitationResult(
125 const std::vector<uint8_t>& /* bssid */,
126 P2pStatusCode /* status */) override {
127 return ndk::ScopedAStatus::ok();
128 }
onProvisionDiscoveryCompleted(const std::vector<uint8_t> &,bool,P2pProvDiscStatusCode,WpsConfigMethods,const std::string &)129 ::ndk::ScopedAStatus onProvisionDiscoveryCompleted(
130 const std::vector<uint8_t>& /* p2pDeviceAddress */,
131 bool /* isRequest */, P2pProvDiscStatusCode /* status */,
132 WpsConfigMethods /* configMethods */,
133 const std::string& /* generatedPin */) override {
134 return ndk::ScopedAStatus::ok();
135 }
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> &)136 ::ndk::ScopedAStatus onR2DeviceFound(
137 const std::vector<uint8_t>& /* srcAddress */,
138 const std::vector<uint8_t>& /* p2pDeviceAddress */,
139 const std::vector<uint8_t>& /* primaryDeviceType */,
140 const std::string& /* deviceName */,
141 WpsConfigMethods /* configMethods */, int8_t /* deviceCapabilities */,
142 P2pGroupCapabilityMask /* groupCapabilities */,
143 const std::vector<uint8_t>& /* wfdDeviceInfo */,
144 const std::vector<uint8_t>& /* wfdR2DeviceInfo */) override {
145 return ndk::ScopedAStatus::ok();
146 }
onServiceDiscoveryResponse(const std::vector<uint8_t> &,char16_t,const std::vector<uint8_t> &)147 ::ndk::ScopedAStatus onServiceDiscoveryResponse(
148 const std::vector<uint8_t>& /* srcAddress */,
149 char16_t /* updateIndicator */,
150 const std::vector<uint8_t>& /* tlvs */) override {
151 return ndk::ScopedAStatus::ok();
152 }
onStaAuthorized(const std::vector<uint8_t> &,const std::vector<uint8_t> &)153 ::ndk::ScopedAStatus onStaAuthorized(
154 const std::vector<uint8_t>& /* srcAddress */,
155 const std::vector<uint8_t>& /* p2pDeviceAddress */) override {
156 return ndk::ScopedAStatus::ok();
157 }
onStaDeauthorized(const std::vector<uint8_t> &,const std::vector<uint8_t> &)158 ::ndk::ScopedAStatus onStaDeauthorized(
159 const std::vector<uint8_t>& /* srcAddress */,
160 const std::vector<uint8_t>& /* p2pDeviceAddress */) override {
161 return ndk::ScopedAStatus::ok();
162 }
onGroupFrequencyChanged(const std::string &,int32_t)163 ::ndk::ScopedAStatus onGroupFrequencyChanged(const std::string& /* groupIfname */,
164 int32_t /* frequency */) override {
165 return ndk::ScopedAStatus::ok();
166 }
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> &)167 ::ndk::ScopedAStatus onDeviceFoundWithVendorElements(
168 const std::vector<uint8_t>& /* srcAddress */,
169 const std::vector<uint8_t>& /* p2pDeviceAddress */,
170 const std::vector<uint8_t>& /* primaryDeviceType */,
171 const std::string& /* deviceName */, WpsConfigMethods /* configMethods */,
172 int8_t /* deviceCapabilities */, P2pGroupCapabilityMask /* groupCapabilities */,
173 const std::vector<uint8_t>& /* wfdDeviceInfo */,
174 const std::vector<uint8_t>& /* wfdR2DeviceInfo */,
175 const std::vector<uint8_t>& /* vendorElemBytes */) override {
176 return ndk::ScopedAStatus::ok();
177 }
178 };
179
180 class SupplicantP2pIfaceAidlTest : public testing::TestWithParam<std::string> {
181 public:
SetUp()182 void SetUp() override {
183 initializeService();
184 supplicant_ = getSupplicant(GetParam().c_str());
185 ASSERT_NE(supplicant_, nullptr);
186 ASSERT_TRUE(supplicant_
187 ->setDebugParams(DebugLevel::EXCESSIVE,
188 true, // show timestamps
189 true)
190 .isOk());
191
192 bool p2pEnabled =
193 testing::deviceSupportsFeature("android.hardware.wifi.direct");
194 if (!p2pEnabled) {
195 GTEST_SKIP() << "Wi-Fi Direct is not supported, skip this test.";
196 }
197
198 EXPECT_TRUE(supplicant_->getP2pInterface(getP2pIfaceName(), &p2p_iface_)
199 .isOk());
200 ASSERT_NE(p2p_iface_, nullptr);
201 }
202
TearDown()203 void TearDown() override {
204 stopSupplicantService();
205 startWifiFramework();
206 }
207
208 protected:
209 std::shared_ptr<ISupplicant> supplicant_;
210 std::shared_ptr<ISupplicantP2pIface> p2p_iface_;
211 };
212
213 /*
214 * RegisterCallback
215 */
TEST_P(SupplicantP2pIfaceAidlTest,RegisterCallback)216 TEST_P(SupplicantP2pIfaceAidlTest, RegisterCallback) {
217 std::shared_ptr<SupplicantP2pIfaceCallback> callback =
218 ndk::SharedRefBase::make<SupplicantP2pIfaceCallback>();
219 ASSERT_NE(callback, nullptr);
220 EXPECT_TRUE(p2p_iface_->registerCallback(callback).isOk());
221 }
222
223 /*
224 * GetName
225 */
TEST_P(SupplicantP2pIfaceAidlTest,GetName)226 TEST_P(SupplicantP2pIfaceAidlTest, GetName) {
227 std::string name;
228 EXPECT_TRUE(p2p_iface_->getName(&name).isOk());
229 EXPECT_NE(name.size(), 0);
230 }
231
232 /*
233 * GetType
234 */
TEST_P(SupplicantP2pIfaceAidlTest,GetType)235 TEST_P(SupplicantP2pIfaceAidlTest, GetType) {
236 IfaceType type;
237 EXPECT_TRUE(p2p_iface_->getType(&type).isOk());
238 EXPECT_EQ(type, IfaceType::P2P);
239 }
240
241 /*
242 * GetDeviceAddress
243 */
TEST_P(SupplicantP2pIfaceAidlTest,GetDeviceAddress)244 TEST_P(SupplicantP2pIfaceAidlTest, GetDeviceAddress) {
245 std::vector<uint8_t> macAddr;
246 EXPECT_TRUE(p2p_iface_->getDeviceAddress(&macAddr).isOk());
247 EXPECT_EQ(macAddr.size(), 6);
248 }
249
250 /*
251 * GetSsid
252 */
TEST_P(SupplicantP2pIfaceAidlTest,GetSsid)253 TEST_P(SupplicantP2pIfaceAidlTest, GetSsid) {
254 // This will fail with fake values.
255 std::vector<uint8_t> ssid;
256 EXPECT_FALSE(p2p_iface_->getSsid(kTestMacAddr, &ssid).isOk());
257 }
258
259 /*
260 * GetGroupCapability
261 */
TEST_P(SupplicantP2pIfaceAidlTest,GetGroupCapability)262 TEST_P(SupplicantP2pIfaceAidlTest, GetGroupCapability) {
263 // This will fail with fake values.
264 P2pGroupCapabilityMask cap;
265 EXPECT_FALSE(p2p_iface_->getGroupCapability(kTestMacAddr, &cap).isOk());
266 }
267
268 /*
269 * Set/Get Edmg
270 */
TEST_P(SupplicantP2pIfaceAidlTest,SetGetEdmg)271 TEST_P(SupplicantP2pIfaceAidlTest, SetGetEdmg) {
272 bool emdg = false;
273 EXPECT_TRUE(p2p_iface_->setEdmg(true).isOk());
274 EXPECT_TRUE(p2p_iface_->getEdmg(&emdg).isOk());
275 EXPECT_EQ(emdg, true);
276
277 EXPECT_TRUE(p2p_iface_->setEdmg(false).isOk());
278 EXPECT_TRUE(p2p_iface_->getEdmg(&emdg).isOk());
279 EXPECT_EQ(emdg, false);
280 }
281
282 /*
283 * SetWpsDeviceName
284 */
TEST_P(SupplicantP2pIfaceAidlTest,SetWpsDeviceName)285 TEST_P(SupplicantP2pIfaceAidlTest, SetWpsDeviceName) {
286 const std::string deviceName = "TestWpsDeviceName";
287 EXPECT_TRUE(p2p_iface_->setWpsDeviceName(deviceName).isOk());
288 }
289
290 /*
291 * SetWpsDeviceType
292 */
TEST_P(SupplicantP2pIfaceAidlTest,SetWpsDeviceType)293 TEST_P(SupplicantP2pIfaceAidlTest, SetWpsDeviceType) {
294 const std::vector<uint8_t> deviceType = std::vector<uint8_t>(8, 0x01);
295 EXPECT_TRUE(p2p_iface_->setWpsDeviceType(deviceType).isOk());
296 }
297
298 /*
299 * SetWpsManufacturer
300 */
TEST_P(SupplicantP2pIfaceAidlTest,SetWpsManufacturer)301 TEST_P(SupplicantP2pIfaceAidlTest, SetWpsManufacturer) {
302 const std::string deviceManufacturer = "TestManufacturer";
303 EXPECT_TRUE(p2p_iface_->setWpsManufacturer(deviceManufacturer).isOk());
304 }
305
306 /*
307 * SetWpsModelName
308 */
TEST_P(SupplicantP2pIfaceAidlTest,SetWpsModelName)309 TEST_P(SupplicantP2pIfaceAidlTest, SetWpsModelName) {
310 const std::string modelName = "TestModelName";
311 EXPECT_TRUE(p2p_iface_->setWpsModelName(modelName).isOk());
312 }
313
314 /*
315 * SetWpsModelNumber
316 */
TEST_P(SupplicantP2pIfaceAidlTest,SetWpsModelNumber)317 TEST_P(SupplicantP2pIfaceAidlTest, SetWpsModelNumber) {
318 const std::string modelNumber = "TestModelNumber";
319 EXPECT_TRUE(p2p_iface_->setWpsModelName(modelNumber).isOk());
320 }
321
322 /*
323 * SetWpsSerialNumber
324 */
TEST_P(SupplicantP2pIfaceAidlTest,SetWpsSerialNumber)325 TEST_P(SupplicantP2pIfaceAidlTest, SetWpsSerialNumber) {
326 const std::string serialNumber = "TestSerialNumber";
327 EXPECT_TRUE(p2p_iface_->setWpsSerialNumber(serialNumber).isOk());
328 }
329
330 /*
331 * SetWpsConfigMethods
332 */
TEST_P(SupplicantP2pIfaceAidlTest,SetWpsConfigMethods)333 TEST_P(SupplicantP2pIfaceAidlTest, SetWpsConfigMethods) {
334 const WpsConfigMethods config = WpsConfigMethods::DISPLAY;
335 EXPECT_TRUE(p2p_iface_->setWpsConfigMethods(config).isOk());
336 }
337
338 /*
339 * SetSsidPostfix
340 */
TEST_P(SupplicantP2pIfaceAidlTest,SetSsidPostfix)341 TEST_P(SupplicantP2pIfaceAidlTest, SetSsidPostfix) {
342 const std::vector<uint8_t> ssidPostfix = {'t', 'e', 's', 't'};
343 EXPECT_TRUE(p2p_iface_->setSsidPostfix(ssidPostfix).isOk());
344 }
345
346 /*
347 * SetWfdDeviceInfo
348 */
TEST_P(SupplicantP2pIfaceAidlTest,SetWfdDeviceInfo)349 TEST_P(SupplicantP2pIfaceAidlTest, SetWfdDeviceInfo) {
350 const std::vector<uint8_t> wfdDeviceInfo = std::vector<uint8_t>(6, 0x01);
351 EXPECT_TRUE(p2p_iface_->setWfdDeviceInfo(wfdDeviceInfo).isOk());
352 }
353
354 /*
355 * SetWfdR2DeviceInfo
356 */
TEST_P(SupplicantP2pIfaceAidlTest,SetWfdR2DeviceInfo)357 TEST_P(SupplicantP2pIfaceAidlTest, SetWfdR2DeviceInfo) {
358 const std::vector<uint8_t> wfdR2DeviceInfo = std::vector<uint8_t>(4, 0x01);
359 EXPECT_TRUE(p2p_iface_->setWfdR2DeviceInfo(wfdR2DeviceInfo).isOk());
360 }
361
362 /*
363 * SetGroupIdle
364 */
TEST_P(SupplicantP2pIfaceAidlTest,SetGroupIdle)365 TEST_P(SupplicantP2pIfaceAidlTest, SetGroupIdle) {
366 // This will fail with fake values.
367 const uint32_t groupIdleTimeout = 8;
368 EXPECT_FALSE(
369 p2p_iface_->setGroupIdle(kTestGroupIfName, groupIdleTimeout).isOk());
370 }
371
372 /*
373 * SetPowerSave
374 */
TEST_P(SupplicantP2pIfaceAidlTest,SetPowerSave)375 TEST_P(SupplicantP2pIfaceAidlTest, SetPowerSave) {
376 // This will fail with fake values.
377 EXPECT_FALSE(p2p_iface_->setPowerSave(kTestGroupIfName, true).isOk());
378 EXPECT_FALSE(p2p_iface_->setPowerSave(kTestGroupIfName, false).isOk());
379 }
380
381 /*
382 * SetMiracastMode
383 */
TEST_P(SupplicantP2pIfaceAidlTest,SetMiracastMode)384 TEST_P(SupplicantP2pIfaceAidlTest, SetMiracastMode) {
385 EXPECT_TRUE(p2p_iface_->setMiracastMode(MiracastMode::DISABLED).isOk());
386 EXPECT_TRUE(p2p_iface_->setMiracastMode(MiracastMode::SOURCE).isOk());
387 EXPECT_TRUE(p2p_iface_->setMiracastMode(MiracastMode::SINK).isOk());
388 }
389
390 /*
391 * SetDisallowedFrequencies
392 */
TEST_P(SupplicantP2pIfaceAidlTest,SetDisallowedFrequencies)393 TEST_P(SupplicantP2pIfaceAidlTest, SetDisallowedFrequencies) {
394 FreqRange range1;
395 range1.min = 2412;
396 range1.max = 2432;
397 const std::vector<FreqRange> ranges = {range1};
398 EXPECT_TRUE(p2p_iface_->setDisallowedFrequencies(ranges).isOk());
399 }
400
401 /*
402 * SetListenChannel
403 */
TEST_P(SupplicantP2pIfaceAidlTest,SetListenChannel)404 TEST_P(SupplicantP2pIfaceAidlTest, SetListenChannel) {
405 const uint32_t testChannel = 1;
406 const uint32_t testOperatingClass = 81;
407 EXPECT_TRUE(
408 p2p_iface_->setListenChannel(testChannel, testOperatingClass).isOk());
409 }
410
411 /*
412 * SetMacRandomization
413 */
TEST_P(SupplicantP2pIfaceAidlTest,EnableMacRandomization)414 TEST_P(SupplicantP2pIfaceAidlTest, EnableMacRandomization) {
415 // Enable twice
416 EXPECT_TRUE(p2p_iface_->setMacRandomization(true).isOk());
417 EXPECT_TRUE(p2p_iface_->setMacRandomization(true).isOk());
418
419 // Disable twice
420 EXPECT_TRUE(p2p_iface_->setMacRandomization(false).isOk());
421 EXPECT_TRUE(p2p_iface_->setMacRandomization(false).isOk());
422 }
423
424 /*
425 * AddGroup
426 */
TEST_P(SupplicantP2pIfaceAidlTest,AddGroup)427 TEST_P(SupplicantP2pIfaceAidlTest, AddGroup) {
428 EXPECT_TRUE(p2p_iface_->addGroup(false, kTestNetworkId).isOk());
429 }
430
431 /*
432 * RemoveGroup
433 */
TEST_P(SupplicantP2pIfaceAidlTest,RemoveGroup)434 TEST_P(SupplicantP2pIfaceAidlTest, RemoveGroup) {
435 // This will fail with fake values.
436 EXPECT_FALSE(p2p_iface_->removeGroup(kTestGroupIfName).isOk());
437 }
438
439 /*
440 * AddGroupWithConfig - success.
441 */
TEST_P(SupplicantP2pIfaceAidlTest,AddGroupWithConfig_Success)442 TEST_P(SupplicantP2pIfaceAidlTest, AddGroupWithConfig_Success) {
443 EXPECT_TRUE(p2p_iface_
444 ->addGroupWithConfig(kTestSsid, kTestPassphrase,
445 kTestGroupPersistent, kTestGroupFreq,
446 kTestZeroMacAddr, kTestGroupIsJoin)
447 .isOk());
448 }
449
450 /*
451 * AddGroupWithConfig - failure due to invalid SSID.
452 */
TEST_P(SupplicantP2pIfaceAidlTest,AddGroupWithConfig_FailureInvalidSsid)453 TEST_P(SupplicantP2pIfaceAidlTest, AddGroupWithConfig_FailureInvalidSsid) {
454 const std::vector<uint8_t> ssid;
455 EXPECT_FALSE(p2p_iface_
456 ->addGroupWithConfig(ssid, kTestPassphrase,
457 kTestGroupPersistent, kTestGroupFreq,
458 kTestZeroMacAddr, kTestGroupIsJoin)
459 .isOk());
460 }
461
462 /*
463 * AddGroupWithConfig - failure due to invalid passphrase.
464 */
TEST_P(SupplicantP2pIfaceAidlTest,AddGroupWithConfig_FailureInvalidPassphrase)465 TEST_P(SupplicantP2pIfaceAidlTest,
466 AddGroupWithConfig_FailureInvalidPassphrase) {
467 const std::string passphrase = "1234";
468 EXPECT_FALSE(p2p_iface_
469 ->addGroupWithConfig(kTestSsid, passphrase,
470 kTestGroupPersistent, kTestGroupFreq,
471 kTestZeroMacAddr, kTestGroupIsJoin)
472 .isOk());
473 }
474
475 /*
476 * AddGroupWithConfig - failure due to invalid frequency.
477 */
TEST_P(SupplicantP2pIfaceAidlTest,AddGroupWithConfig_FailureInvalidFrequency)478 TEST_P(SupplicantP2pIfaceAidlTest, AddGroupWithConfig_FailureInvalidFrequency) {
479 const int freq = 9999;
480 EXPECT_FALSE(p2p_iface_
481 ->addGroupWithConfig(kTestSsid, kTestPassphrase,
482 kTestGroupPersistent, freq,
483 kTestZeroMacAddr, kTestGroupIsJoin)
484 .isOk());
485 }
486
487 /*
488 * Find
489 */
TEST_P(SupplicantP2pIfaceAidlTest,Find)490 TEST_P(SupplicantP2pIfaceAidlTest, Find) {
491 EXPECT_TRUE(p2p_iface_->find(kTestFindTimeout).isOk());
492 }
493
494 /*
495 * FindSocialChannelsOnly
496 */
TEST_P(SupplicantP2pIfaceAidlTest,FindSocialChannelsOnly)497 TEST_P(SupplicantP2pIfaceAidlTest, FindSocialChannelsOnly) {
498 EXPECT_TRUE(p2p_iface_->findOnSocialChannels(kTestFindTimeout).isOk());
499 }
500
501 /*
502 * FindSpecificFrequency
503 */
TEST_P(SupplicantP2pIfaceAidlTest,FindSpecificFrequency)504 TEST_P(SupplicantP2pIfaceAidlTest, FindSpecificFrequency) {
505 EXPECT_TRUE(p2p_iface_->findOnSpecificFrequency(2412, kTestFindTimeout).isOk());
506 }
507
508 /*
509 * StopFind
510 */
TEST_P(SupplicantP2pIfaceAidlTest,StopFind)511 TEST_P(SupplicantP2pIfaceAidlTest, StopFind) {
512 EXPECT_TRUE(p2p_iface_->find(kTestFindTimeout).isOk());
513 EXPECT_TRUE(p2p_iface_->stopFind().isOk());
514 }
515
516 /*
517 * Flush
518 */
TEST_P(SupplicantP2pIfaceAidlTest,Flush)519 TEST_P(SupplicantP2pIfaceAidlTest, Flush) {
520 EXPECT_TRUE(p2p_iface_->flush().isOk());
521 }
522
523 /*
524 * Connect
525 */
TEST_P(SupplicantP2pIfaceAidlTest,Connect)526 TEST_P(SupplicantP2pIfaceAidlTest, Connect) {
527 /*
528 * Auto-join is not enabled before R. After enabling auto-join,
529 * this should always succeed.
530 */
531 std::string pin;
532 EXPECT_TRUE(p2p_iface_
533 ->connect(kTestMacAddr, WpsProvisionMethod::PBC,
534 kTestConnectPin, false, false,
535 kTestConnectGoIntent, &pin)
536 .isOk());
537 }
538
539 /*
540 * CancelConnect
541 */
TEST_P(SupplicantP2pIfaceAidlTest,CancelConnect)542 TEST_P(SupplicantP2pIfaceAidlTest, CancelConnect) {
543 std::string pin;
544 EXPECT_TRUE(p2p_iface_
545 ->connect(kTestMacAddr, WpsProvisionMethod::PBC,
546 kTestConnectPin, false, false,
547 kTestConnectGoIntent, &pin)
548 .isOk());
549 EXPECT_TRUE(p2p_iface_->cancelConnect().isOk());
550 }
551
552 /*
553 * ProvisionDiscovery
554 */
TEST_P(SupplicantP2pIfaceAidlTest,ProvisionDiscovery)555 TEST_P(SupplicantP2pIfaceAidlTest, ProvisionDiscovery) {
556 // This will fail with fake values.
557 EXPECT_FALSE(
558 p2p_iface_->provisionDiscovery(kTestMacAddr, WpsProvisionMethod::PBC)
559 .isOk());
560 }
561
562 /*
563 * Reject
564 */
TEST_P(SupplicantP2pIfaceAidlTest,Reject)565 TEST_P(SupplicantP2pIfaceAidlTest, Reject) {
566 // This will fail with fake values.
567 ASSERT_FALSE(p2p_iface_->reject(kTestMacAddr).isOk());
568 }
569
570 /*
571 * Invite
572 */
TEST_P(SupplicantP2pIfaceAidlTest,Invite)573 TEST_P(SupplicantP2pIfaceAidlTest, Invite) {
574 // This will fail with fake values.
575 EXPECT_FALSE(
576 p2p_iface_->invite(kTestGroupIfName, kTestMacAddr, kTestPeerMacAddr)
577 .isOk());
578 }
579
580 /*
581 * Reinvoke
582 */
TEST_P(SupplicantP2pIfaceAidlTest,Reinvoke)583 TEST_P(SupplicantP2pIfaceAidlTest, Reinvoke) {
584 // This will fail with fake values.
585 EXPECT_FALSE(p2p_iface_->reinvoke(kTestNetworkId, kTestMacAddr).isOk());
586 }
587
588 /*
589 * ConfigureExtListen
590 */
TEST_P(SupplicantP2pIfaceAidlTest,ConfigureExtListen)591 TEST_P(SupplicantP2pIfaceAidlTest, ConfigureExtListen) {
592 const uint32_t extListenPeriod = 400;
593 const uint32_t extListenInterval = 400;
594 EXPECT_TRUE(
595 p2p_iface_->configureExtListen(extListenPeriod, extListenInterval)
596 .isOk());
597 }
598
599 /*
600 * FlushServices
601 */
TEST_P(SupplicantP2pIfaceAidlTest,FlushServices)602 TEST_P(SupplicantP2pIfaceAidlTest, FlushServices) {
603 EXPECT_TRUE(p2p_iface_->flushServices().isOk());
604 }
605
606 /*
607 * EnableWfd
608 */
TEST_P(SupplicantP2pIfaceAidlTest,EnableWfd)609 TEST_P(SupplicantP2pIfaceAidlTest, EnableWfd) {
610 EXPECT_TRUE(p2p_iface_->enableWfd(true).isOk());
611 EXPECT_TRUE(p2p_iface_->enableWfd(false).isOk());
612 }
613
614 /*
615 * Add/Remove BonjourService
616 */
TEST_P(SupplicantP2pIfaceAidlTest,AddAndRemoveBonjourService)617 TEST_P(SupplicantP2pIfaceAidlTest, AddAndRemoveBonjourService) {
618 const std::string serviceQueryStr = "testquery";
619 const std::string serviceResponseStr = "testresponse";
620 const std::vector<uint8_t> bonjourServiceQuery =
621 std::vector<uint8_t>(serviceQueryStr.begin(), serviceQueryStr.end());
622 const std::vector<uint8_t> bonjourServiceResponse = std::vector<uint8_t>(
623 serviceResponseStr.begin(), serviceResponseStr.end());
624
625 EXPECT_TRUE(
626 p2p_iface_
627 ->addBonjourService(bonjourServiceQuery, bonjourServiceResponse)
628 .isOk());
629 EXPECT_TRUE(p2p_iface_->removeBonjourService(bonjourServiceQuery).isOk());
630
631 // This will fail because the boujour service with
632 // bonjourServiceQuery was already removed.
633 EXPECT_FALSE(p2p_iface_->removeBonjourService(bonjourServiceQuery).isOk());
634 }
635
636 /*
637 * Add/Remove UpnpService
638 */
TEST_P(SupplicantP2pIfaceAidlTest,AddAndRemoveUpnpService)639 TEST_P(SupplicantP2pIfaceAidlTest, AddAndRemoveUpnpService) {
640 const std::string upnpServiceName = "TestServiceName";
641 EXPECT_TRUE(
642 p2p_iface_->addUpnpService(0 /* version */, upnpServiceName).isOk());
643 EXPECT_TRUE(
644 p2p_iface_->removeUpnpService(0 /* version */, upnpServiceName).isOk());
645
646 // This will fail because Upnp service with
647 // upnpServiceName was already removed.
648 EXPECT_FALSE(
649 p2p_iface_->removeUpnpService(0 /* version */, upnpServiceName).isOk());
650 }
651
652 /*
653 * SetVendorElements
654 */
TEST_P(SupplicantP2pIfaceAidlTest,SetVendorElements)655 TEST_P(SupplicantP2pIfaceAidlTest, SetVendorElements) {
656 LOG(INFO) << "SupplicantP2pIfaceAidlTest::SetVendorElements start";
657
658 std::vector<uint8_t> vendorElemBytes;
659 EXPECT_TRUE(
660 p2p_iface_
661 ->setVendorElements(P2pFrameTypeMask::P2P_FRAME_PROBE_RESP_P2P, vendorElemBytes)
662 .isOk());
663
664 LOG(INFO) << "SupplicantP2pIfaceAidlTest::SetVendorElements end";
665 }
666
667 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(SupplicantP2pIfaceAidlTest);
668 INSTANTIATE_TEST_SUITE_P(Supplicant, SupplicantP2pIfaceAidlTest,
669 testing::ValuesIn(android::getAidlHalInstanceNames(
670 ISupplicant::descriptor)),
671 android::PrintInstanceNameToString);
672
main(int argc,char ** argv)673 int main(int argc, char** argv) {
674 ::testing::InitGoogleTest(&argc, argv);
675 ProcessState::self()->setThreadPoolMaxThreadCount(1);
676 ProcessState::self()->startThreadPool();
677 return RUN_ALL_TESTS();
678 }
679