diff options
author | lesl <lesl@google.com> | 2019-12-02 23:48:58 +0800 |
---|---|---|
committer | lesl <lesl@google.com> | 2019-12-10 17:55:27 +0800 |
commit | 0bad28f064a31fc1c659b16e1f3383247b525d43 (patch) | |
tree | ef9d648258c8c5f0657771314d844b6f8f257bbe /wifi/hostapd/1.2/vts/functional/hostapd_hidl_test.cpp | |
parent | 050316231e7cbf3b0a34ba5d714e6d8d98c67d02 (diff) |
IHostapd: Add hostapd 1.2
Add new API: forceClientDisconnect
Bug:142752869
Test: Manual Test
Test: VTS: VtsHalWifiHostapdV1_2Target
Change-Id: Ia05ec993815c16731aa9be1f257f941eacf1575f
Diffstat (limited to 'wifi/hostapd/1.2/vts/functional/hostapd_hidl_test.cpp')
-rw-r--r-- | wifi/hostapd/1.2/vts/functional/hostapd_hidl_test.cpp | 140 |
1 files changed, 140 insertions, 0 deletions
diff --git a/wifi/hostapd/1.2/vts/functional/hostapd_hidl_test.cpp b/wifi/hostapd/1.2/vts/functional/hostapd_hidl_test.cpp new file mode 100644 index 0000000000..0d372213ce --- /dev/null +++ b/wifi/hostapd/1.2/vts/functional/hostapd_hidl_test.cpp @@ -0,0 +1,140 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <android-base/logging.h> +#include <cutils/properties.h> + +#include <gtest/gtest.h> +#include <hidl/GtestPrinter.h> +#include <hidl/ServiceManagement.h> + +#include <android/hardware/wifi/1.0/IWifi.h> +#include <android/hardware/wifi/hostapd/1.2/IHostapd.h> + +#include "hostapd_hidl_call_util.h" +#include "hostapd_hidl_test_utils.h" + +using ::android::sp; +using ::android::hardware::hidl_string; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::hardware::wifi::hostapd::V1_2::HostapdStatusCode; +using ::android::hardware::wifi::hostapd::V1_2::Ieee80211ReasonCode; +using ::android::hardware::wifi::hostapd::V1_2::IHostapd; +using ::android::hardware::wifi::V1_0::IWifi; + +namespace { +constexpr unsigned char kNwSsid[] = {'t', 'e', 's', 't', '1', + '2', '3', '4', '5'}; +constexpr int kIfaceChannel = 6; +constexpr uint8_t kTestZeroMacAddr[] = {[0 ... 5] = 0x0}; +constexpr Ieee80211ReasonCode kTestDisconnectReasonCode = + Ieee80211ReasonCode::WLAN_REASON_UNSPECIFIED; +} // namespace + +class HostapdHidlTest + : public ::testing::TestWithParam<std::tuple<std::string, std::string>> { + public: + virtual void SetUp() override { + wifi_instance_name_ = std::get<0>(GetParam()); + hostapd_instance_name_ = std::get<1>(GetParam()); + stopSupplicantIfNeeded(wifi_instance_name_); + startHostapdAndWaitForHidlService(wifi_instance_name_, + hostapd_instance_name_); + hostapd_ = IHostapd::getService(hostapd_instance_name_); + ASSERT_NE(hostapd_.get(), nullptr); + } + + virtual void TearDown() override { stopHostapd(wifi_instance_name_); } + + protected: + std::string getPrimaryWlanIfaceName() { + std::array<char, PROPERTY_VALUE_MAX> buffer; + auto res = property_get("ro.vendor.wifi.sap.interface", buffer.data(), + nullptr); + if (res > 0) return buffer.data(); + property_get("wifi.interface", buffer.data(), "wlan0"); + return buffer.data(); + } + + IHostapd::IfaceParams getIfaceParamsWithoutAcs() { + ::android::hardware::wifi::hostapd::V1_0::IHostapd::IfaceParams + iface_params; + IHostapd::IfaceParams iface_params_1_1; + + iface_params.ifaceName = getPrimaryWlanIfaceName(); + iface_params.hwModeParams.enable80211N = true; + iface_params.hwModeParams.enable80211AC = false; + iface_params.channelParams.enableAcs = false; + iface_params.channelParams.acsShouldExcludeDfs = false; + iface_params.channelParams.channel = kIfaceChannel; + iface_params.channelParams.band = IHostapd::Band::BAND_2_4_GHZ; + iface_params_1_1.V1_0 = iface_params; + return iface_params_1_1; + } + + IHostapd::NetworkParams getOpenNwParams() { + IHostapd::NetworkParams nw_params; + nw_params.ssid = + std::vector<uint8_t>(kNwSsid, kNwSsid + sizeof(kNwSsid)); + nw_params.isHidden = false; + nw_params.encryptionType = IHostapd::EncryptionType::NONE; + return nw_params; + } + + // IHostapd object used for all tests in this fixture. + sp<IHostapd> hostapd_; + std::string wifi_instance_name_; + std::string hostapd_instance_name_; +}; + +/** + * forceClientDisconnect should return FAILURE_IFACE_UNKNOWN + * when hotspot interface doesn't init.. + */ +TEST_P(HostapdHidlTest, DisconnectClientWhenIfaceNotAvailable) { + auto status = + HIDL_INVOKE(hostapd_, forceClientDisconnect, getPrimaryWlanIfaceName(), + kTestZeroMacAddr, kTestDisconnectReasonCode); + EXPECT_EQ(HostapdStatusCode::FAILURE_IFACE_UNKNOWN, status.code); +} + +/** + * forceClientDisconnect should return FAILURE_CLIENT_UNKNOWN + * when hotspot interface available. + */ +TEST_P(HostapdHidlTest, DisconnectClientWhenIfacAvailable) { + auto status_1_0 = + HIDL_INVOKE(hostapd_, addAccessPoint_1_1, getIfaceParamsWithoutAcs(), + getOpenNwParams()); + EXPECT_EQ( + android::hardware::wifi::hostapd::V1_0::HostapdStatusCode::SUCCESS, + status_1_0.code); + + auto status_1_2 = + HIDL_INVOKE(hostapd_, forceClientDisconnect, getPrimaryWlanIfaceName(), + kTestZeroMacAddr, kTestDisconnectReasonCode); + EXPECT_EQ(HostapdStatusCode::FAILURE_CLIENT_UNKNOWN, status_1_2.code); +} + +INSTANTIATE_TEST_CASE_P( + PerInstance, HostapdHidlTest, + testing::Combine( + testing::ValuesIn( + android::hardware::getAllHalInstanceNames(IWifi::descriptor)), + testing::ValuesIn(android::hardware::getAllHalInstanceNames( + android::hardware::wifi::hostapd::V1_2::IHostapd::descriptor))), + android::hardware::PrintInstanceTupleNameToString<>); |