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 <cutils/properties.h>
19
20 #include <VtsCoreUtil.h>
21 #include <android/hardware/wifi/1.0/IWifi.h>
22 #include <android/hardware/wifi/supplicant/1.0/types.h>
23 #include <android/hardware/wifi/supplicant/1.1/ISupplicant.h>
24 #include <hidl/GtestPrinter.h>
25 #include <hidl/ServiceManagement.h>
26
27 #include "supplicant_hidl_test_utils.h"
28 #include "supplicant_hidl_test_utils_1_1.h"
29
30 using ::android::hardware::hidl_vec;
31 using ::android::hardware::wifi::supplicant::V1_0::ISupplicantIface;
32 using ::android::hardware::wifi::supplicant::V1_0::SupplicantStatus;
33 using ::android::hardware::wifi::supplicant::V1_0::SupplicantStatusCode;
34 using ::android::hardware::wifi::supplicant::V1_0::IfaceType;
35 using ::android::hardware::wifi::supplicant::V1_1::ISupplicant;
36 using ::android::hardware::wifi::V1_0::IWifi;
37 using ::android::sp;
38
39 class SupplicantHidlTest : public SupplicantHidlTestBaseV1_1 {
40 public:
SetUp()41 virtual void SetUp() override { SupplicantHidlTestBaseV1_1::SetUp(); }
42
43 protected:
getWlan0IfaceName()44 std::string getWlan0IfaceName() {
45 std::array<char, PROPERTY_VALUE_MAX> buffer;
46 property_get("wifi.interface", buffer.data(), "wlan0");
47 return buffer.data();
48 }
49
getP2pIfaceName()50 std::string getP2pIfaceName() {
51 std::array<char, PROPERTY_VALUE_MAX> buffer;
52 property_get("wifi.direct.interface", buffer.data(), "p2p0");
53 return buffer.data();
54 }
55 };
56
57 /*
58 * AddStaInterface
59 */
TEST_P(SupplicantHidlTest,AddStaInterface)60 TEST_P(SupplicantHidlTest, AddStaInterface) {
61 ISupplicant::IfaceInfo iface_info;
62 iface_info.name = getWlan0IfaceName();
63 iface_info.type = IfaceType::STA;
64 supplicant_->addInterface(
65 iface_info,
66 [&](const SupplicantStatus& status, const sp<ISupplicantIface>& iface) {
67 EXPECT_TRUE(
68 (status.code == SupplicantStatusCode::SUCCESS) ||
69 (status.code == SupplicantStatusCode::FAILURE_IFACE_EXISTS));
70 EXPECT_NE(nullptr, iface.get());
71 });
72 }
73
74 /*
75 * AddP2pInterface
76 */
TEST_P(SupplicantHidlTest,AddP2pInterface)77 TEST_P(SupplicantHidlTest, AddP2pInterface) {
78 if (!isP2pOn_) return;
79 ISupplicant::IfaceInfo iface_info;
80 iface_info.name = getP2pIfaceName();
81 iface_info.type = IfaceType::P2P;
82 supplicant_->addInterface(
83 iface_info,
84 [&](const SupplicantStatus& status, const sp<ISupplicantIface>& iface) {
85 EXPECT_TRUE(
86 (status.code == SupplicantStatusCode::SUCCESS) ||
87 (status.code == SupplicantStatusCode::FAILURE_IFACE_EXISTS));
88 EXPECT_NE(nullptr, iface.get());
89 });
90 }
91
92 /*
93 * RemoveStaInterface
94 */
TEST_P(SupplicantHidlTest,RemoveStaInterface)95 TEST_P(SupplicantHidlTest, RemoveStaInterface) {
96 ISupplicant::IfaceInfo iface_info;
97 iface_info.name = getWlan0IfaceName();
98 iface_info.type = IfaceType::STA;
99
100 supplicant_->addInterface(
101 iface_info,
102 [&](const SupplicantStatus& status, const sp<ISupplicantIface>& iface) {
103 EXPECT_TRUE(
104 (status.code == SupplicantStatusCode::SUCCESS) ||
105 (status.code == SupplicantStatusCode::FAILURE_IFACE_EXISTS));
106 EXPECT_NE(nullptr, iface.get());
107 });
108 supplicant_->removeInterface(
109 iface_info, [&](const SupplicantStatus& status) {
110 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
111 });
112 }
113
114 /*
115 * RemoveP2pInterface
116 */
TEST_P(SupplicantHidlTest,RemoveP2pInterface)117 TEST_P(SupplicantHidlTest, RemoveP2pInterface) {
118 if (!isP2pOn_) return;
119 ISupplicant::IfaceInfo iface_info;
120 iface_info.name = getP2pIfaceName();
121 iface_info.type = IfaceType::P2P;
122
123 supplicant_->addInterface(
124 iface_info,
125 [&](const SupplicantStatus& status, const sp<ISupplicantIface>& iface) {
126 EXPECT_TRUE(
127 (status.code == SupplicantStatusCode::SUCCESS) ||
128 (status.code == SupplicantStatusCode::FAILURE_IFACE_EXISTS));
129 EXPECT_NE(nullptr, iface.get());
130 });
131 supplicant_->removeInterface(
132 iface_info, [&](const SupplicantStatus& status) {
133 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
134 });
135 }
136
137 /*
138 * Terminate
139 * This terminates the service.
140 */
TEST_P(SupplicantHidlTest,Terminate)141 TEST_P(SupplicantHidlTest, Terminate) { supplicant_->terminate(); }
142
143 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(SupplicantHidlTest);
144 INSTANTIATE_TEST_CASE_P(
145 PerInstance, SupplicantHidlTest,
146 testing::Combine(
147 testing::ValuesIn(
148 android::hardware::getAllHalInstanceNames(IWifi::descriptor)),
149 testing::ValuesIn(android::hardware::getAllHalInstanceNames(
150 android::hardware::wifi::supplicant::V1_1::ISupplicant::
151 descriptor))),
152 android::hardware::PrintInstanceTupleNameToString<>);
153