Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 42147b7b authored by Les Lee's avatar Les Lee
Browse files

wifi: create interface before running hostapd vts

Adding to support creating interface in hostapd vts.

Bug: 230008250
Test: 1. setprop ro.vendor.wifi.sap.interface swlan0
2. vts-tradefed run commandAndExit vts
--skip-all-system-status-check --primary-abi-only
--skip-preconditions --module VtsHalWifiHostapdV1_2Target
-l INFO

Change-Id: I483671cb01b68bc6f5ac4840c61b10f4c31f10e4
parent 2f7d5765
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -35,6 +35,27 @@ cc_test {
    ],
}

cc_library_static {
    name: "VtsHalWifiV1_4TargetTestUtil",
    defaults: ["VtsHalTargetTestDefaults"],
    srcs: [
        "wifi_hidl_test_utils_1_4.cpp",
    ],
    export_include_dirs: [
        ".",
    ],
    shared_libs: [
        "libnativehelper",
    ],
    static_libs: [
        "VtsHalWifiV1_0TargetTestUtil",
        "android.hardware.wifi@1.0",
        "android.hardware.wifi@1.3",
        "android.hardware.wifi@1.4",
        "libwifi-system-iface",
    ],
}

// SoftAP-specific tests, similar to VtsHalWifiApV1_0TargetTest.
cc_test {
    name: "VtsHalWifiApV1_4TargetTest",
+54 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 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 <VtsHalHidlTargetCallbackBase.h>
#include <android-base/logging.h>

#undef NAN  // NAN is defined in bionic/libc/include/math.h:38

#include <android/hardware/wifi/1.4/IWifi.h>
#include <android/hardware/wifi/1.4/IWifiApIface.h>
#include <android/hardware/wifi/1.4/IWifiChip.h>
#include <gtest/gtest.h>
#include <hidl/GtestPrinter.h>
#include <hidl/ServiceManagement.h>

#include "wifi_hidl_call_util.h"
#include "wifi_hidl_test_utils.h"

using ::android::sp;
using ::android::hardware::hidl_string;
using ::android::hardware::hidl_vec;
using ::android::hardware::Return;
using ::android::hardware::Void;
using ::android::hardware::wifi::V1_0::ChipModeId;
using ::android::hardware::wifi::V1_0::IfaceType;
using ::android::hardware::wifi::V1_4::IWifiApIface;
using ::android::hardware::wifi::V1_4::IWifiChip;

sp<IWifiChip> getWifiChip_1_4(const std::string& instance_name) {
    return IWifiChip::castFrom(getWifiChip(instance_name));
}

sp<IWifiApIface> getWifiApIface_1_4(const std::string& instance_name) {
    LOG(INFO) << "getWifiApIface_1_4";
    ChipModeId mode_id;
    sp<IWifiChip> wifi_chip_ = getWifiChip_1_4(instance_name);
    configureChipToSupportIfaceType(wifi_chip_, IfaceType::AP, &mode_id);
    const auto& status_and_iface = HIDL_INVOKE(wifi_chip_, createApIface);
    LOG(INFO) << "getWifiApIface_1_4 done to status_and_iface";
    return IWifiApIface::castFrom(status_and_iface.second);
}
+33 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 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.
 */

#pragma once

#include <android/hardware/wifi/1.4/IWifi.h>
#include <android/hardware/wifi/1.4/IWifiApIface.h>
#include <android/hardware/wifi/1.4/IWifiChip.h>

#include <getopt.h>

#include <VtsHalHidlTargetTestEnvBase.h>
// Helper functions to obtain references to the various HIDL interface objects.
// Note: We only have a single instance of each of these objects currently.
// These helper functions should be modified to return vectors if we support
// multiple instances.
android::sp<android::hardware::wifi::V1_4::IWifiChip> getWifiChip_1_4(
    const std::string& instance_name);
android::sp<android::hardware::wifi::V1_4::IWifiApIface> getWifiApIface_1_4(
    const std::string& instance_name);
+10 −3
Original line number Diff line number Diff line
@@ -22,15 +22,22 @@ cc_test {
    ],
    static_libs: [
        "VtsHalWifiV1_0TargetTestUtil",
        "VtsHalWifiV1_4TargetTestUtil",
        "VtsHalWifiHostapdV1_0TargetTestUtil",
        "android.hardware.wifi.hostapd@1.0",
        "android.hardware.wifi.hostapd@1.1",
        "android.hardware.wifi.hostapd@1.2",
        "android.hardware.wifi@1.0",
        "android.hardware.wifi@1.1",
        "android.hardware.wifi@1.2",
        "android.hardware.wifi@1.3",
        "android.hardware.wifi@1.4",
        "libgmock",
        "libwifi-system",
        "libwifi-system-iface",
    ],
    test_suites: ["general-tests", "vts"],
    test_suites: [
        "general-tests",
        "vts",
    ],
}
+85 −56
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@

#include "hostapd_hidl_call_util.h"
#include "hostapd_hidl_test_utils.h"
#include "wifi_hidl_test_utils_1_4.h"

using ::android::sp;
using ::android::hardware::hidl_string;
@@ -38,6 +39,9 @@ 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;
using ::android::hardware::wifi::V1_0::WifiStatusCode;
using ::android::hardware::wifi::V1_4::IWifiApIface;
using ::android::hardware::wifi::V1_4::IWifiChip;

namespace {
constexpr unsigned char kNwSsid[] = {'t', 'e', 's', 't', '1',
@@ -82,23 +86,25 @@ class HostapdHidlTest
   protected:
    bool isWpa3SaeSupport_ = false;
    bool isAcsSupport_ = false;
    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();

    std::string setupApIfaceIfNeededAndGetName() {
        sp<IWifiApIface> wifi_ap_iface;
        wifi_ap_iface = getWifiApIface_1_4(wifi_instance_name_);
        EXPECT_NE(nullptr, wifi_ap_iface.get());

        const auto& status_and_name = HIDL_INVOKE(wifi_ap_iface, getName);
        EXPECT_EQ(WifiStatusCode::SUCCESS, status_and_name.first.code);
        return status_and_name.second;
    }

    IHostapd::IfaceParams getIfaceParamsWithoutAcs() {
    IHostapd::IfaceParams getIfaceParamsWithoutAcs(std::string iface_name) {
        ::android::hardware::wifi::hostapd::V1_0::IHostapd::IfaceParams
            iface_params;
        ::android::hardware::wifi::hostapd::V1_1::IHostapd::IfaceParams
            iface_params_1_1;
        IHostapd::IfaceParams iface_params_1_2;

        iface_params.ifaceName = getPrimaryWlanIfaceName();
        iface_params.ifaceName = iface_name;
        iface_params.hwModeParams.enable80211N = true;
        iface_params.hwModeParams.enable80211AC = false;
        iface_params.channelParams.enableAcs = false;
@@ -115,9 +121,10 @@ class HostapdHidlTest
        return iface_params_1_2;
    }

    IHostapd::IfaceParams getIfaceParamsWithAcs() {
    IHostapd::IfaceParams getIfaceParamsWithAcs(std::string iface_name) {
        // First get the settings for WithoutAcs and then make changes
        IHostapd::IfaceParams iface_params_1_2 = getIfaceParamsWithoutAcs();
        IHostapd::IfaceParams iface_params_1_2 =
            getIfaceParamsWithoutAcs(iface_name);
        iface_params_1_2.V1_1.V1_0.channelParams.enableAcs = true;
        iface_params_1_2.V1_1.V1_0.channelParams.acsShouldExcludeDfs = true;
        iface_params_1_2.V1_1.V1_0.channelParams.channel = 0;
@@ -127,8 +134,10 @@ class HostapdHidlTest
        return iface_params_1_2;
    }

    IHostapd::IfaceParams getIfaceParamsWithAcsAndFreqRange() {
        IHostapd::IfaceParams iface_params_1_2 = getIfaceParamsWithAcs();
    IHostapd::IfaceParams getIfaceParamsWithAcsAndFreqRange(
        std::string iface_name) {
        IHostapd::IfaceParams iface_params_1_2 =
            getIfaceParamsWithAcs(iface_name);
        ::android::hardware::wifi::hostapd::V1_2::IHostapd::AcsFrequencyRange
            acsFrequencyRange;
        acsFrequencyRange.start = 2412;
@@ -142,9 +151,10 @@ class HostapdHidlTest
        return iface_params_1_2;
    }

    IHostapd::IfaceParams getIfaceParamsWithAcsAndInvalidFreqRange() {
    IHostapd::IfaceParams getIfaceParamsWithAcsAndInvalidFreqRange(
        std::string iface_name) {
        IHostapd::IfaceParams iface_params_1_2 =
            getIfaceParamsWithAcsAndFreqRange();
            getIfaceParamsWithAcsAndFreqRange(iface_name);
        iface_params_1_2.channelParams.acsChannelFreqRangesMhz[0].start = 222;
        iface_params_1_2.channelParams.acsChannelFreqRangesMhz[0].end = 999;
        return iface_params_1_2;
@@ -206,8 +216,10 @@ class HostapdHidlTest
        return nw_params_1_2;
    }

    IHostapd::IfaceParams getIfaceParamsWithInvalidChannel() {
        IHostapd::IfaceParams iface_params_1_2 = getIfaceParamsWithoutAcs();
    IHostapd::IfaceParams getIfaceParamsWithInvalidChannel(
        std::string iface_name) {
        IHostapd::IfaceParams iface_params_1_2 =
            getIfaceParamsWithoutAcs(iface_name);
        iface_params_1_2.V1_1.V1_0.channelParams.channel = kIfaceInvalidChannel;
        return iface_params_1_2;
    }
@@ -224,8 +236,9 @@ class HostapdHidlTest
 */
TEST_P(HostapdHidlTest, AddPskAccessPointWithAcs) {
    if (!isAcsSupport_) GTEST_SKIP() << "Missing ACS support";
    std::string ifname = setupApIfaceIfNeededAndGetName();
    auto status = HIDL_INVOKE(hostapd_, addAccessPoint_1_2,
                              getIfaceParamsWithAcs(), getPskNwParams());
                              getIfaceParamsWithAcs(ifname), getPskNwParams());
    EXPECT_EQ(HostapdStatusCode::SUCCESS, status.code);
}

@@ -235,9 +248,10 @@ TEST_P(HostapdHidlTest, AddPskAccessPointWithAcs) {
 */
TEST_P(HostapdHidlTest, AddPskAccessPointWithAcsAndFreqRange) {
    if (!isAcsSupport_) GTEST_SKIP() << "Missing ACS support";
    auto status =
        HIDL_INVOKE(hostapd_, addAccessPoint_1_2,
                    getIfaceParamsWithAcsAndFreqRange(), getPskNwParams());
    std::string ifname = setupApIfaceIfNeededAndGetName();
    auto status = HIDL_INVOKE(hostapd_, addAccessPoint_1_2,
                              getIfaceParamsWithAcsAndFreqRange(ifname),
                              getPskNwParams());
    EXPECT_EQ(HostapdStatusCode::SUCCESS, status.code);
}

@@ -247,8 +261,9 @@ TEST_P(HostapdHidlTest, AddPskAccessPointWithAcsAndFreqRange) {
 */
TEST_P(HostapdHidlTest, AddPskAccessPointWithAcsAndInvalidFreqRange) {
    if (!isAcsSupport_) GTEST_SKIP() << "Missing ACS support";
    std::string ifname = setupApIfaceIfNeededAndGetName();
    auto status = HIDL_INVOKE(hostapd_, addAccessPoint_1_2,
                              getIfaceParamsWithAcsAndInvalidFreqRange(),
                              getIfaceParamsWithAcsAndInvalidFreqRange(ifname),
                              getPskNwParams());
    EXPECT_NE(HostapdStatusCode::SUCCESS, status.code);
}
@@ -259,8 +274,9 @@ TEST_P(HostapdHidlTest, AddPskAccessPointWithAcsAndInvalidFreqRange) {
 */
TEST_P(HostapdHidlTest, AddOpenAccessPointWithAcs) {
    if (!isAcsSupport_) GTEST_SKIP() << "Missing ACS support";
    std::string ifname = setupApIfaceIfNeededAndGetName();
    auto status = HIDL_INVOKE(hostapd_, addAccessPoint_1_2,
                              getIfaceParamsWithAcs(), getOpenNwParams());
                              getIfaceParamsWithAcs(ifname), getOpenNwParams());
    EXPECT_EQ(HostapdStatusCode::SUCCESS, status.code);
}

@@ -269,8 +285,10 @@ TEST_P(HostapdHidlTest, AddOpenAccessPointWithAcs) {
 * Access point creation should pass.
 */
TEST_P(HostapdHidlTest, AddPskAccessPointWithoutAcs) {
    auto status = HIDL_INVOKE(hostapd_, addAccessPoint_1_2,
                              getIfaceParamsWithoutAcs(), getPskNwParams());
    std::string ifname = setupApIfaceIfNeededAndGetName();
    auto status =
        HIDL_INVOKE(hostapd_, addAccessPoint_1_2,
                    getIfaceParamsWithoutAcs(ifname), getPskNwParams());
    EXPECT_EQ(HostapdStatusCode::SUCCESS, status.code);
}

@@ -279,8 +297,10 @@ TEST_P(HostapdHidlTest, AddPskAccessPointWithoutAcs) {
 * Access point creation should pass.
 */
TEST_P(HostapdHidlTest, AddOpenAccessPointWithoutAcs) {
    auto status = HIDL_INVOKE(hostapd_, addAccessPoint_1_2,
                              getIfaceParamsWithoutAcs(), getOpenNwParams());
    std::string ifname = setupApIfaceIfNeededAndGetName();
    auto status =
        HIDL_INVOKE(hostapd_, addAccessPoint_1_2,
                    getIfaceParamsWithoutAcs(ifname), getOpenNwParams());
    EXPECT_EQ(HostapdStatusCode::SUCCESS, status.code);
}

@@ -290,8 +310,9 @@ TEST_P(HostapdHidlTest, AddOpenAccessPointWithoutAcs) {
 */
TEST_P(HostapdHidlTest, AddSaeTransitionAccessPointWithoutAcs) {
    if (!isWpa3SaeSupport_) GTEST_SKIP() << "Missing SAE support";
    auto status =
        HIDL_INVOKE(hostapd_, addAccessPoint_1_2, getIfaceParamsWithoutAcs(),
    std::string ifname = setupApIfaceIfNeededAndGetName();
    auto status = HIDL_INVOKE(hostapd_, addAccessPoint_1_2,
                              getIfaceParamsWithoutAcs(ifname),
                              getSaeTransitionNwParams());
    EXPECT_EQ(HostapdStatusCode::SUCCESS, status.code);
}
@@ -302,8 +323,10 @@ TEST_P(HostapdHidlTest, AddSaeTransitionAccessPointWithoutAcs) {
 */
TEST_P(HostapdHidlTest, AddSAEAccessPointWithoutAcs) {
    if (!isWpa3SaeSupport_) GTEST_SKIP() << "Missing SAE support";
    auto status = HIDL_INVOKE(hostapd_, addAccessPoint_1_2,
                              getIfaceParamsWithoutAcs(), getSaeNwParams());
    std::string ifname = setupApIfaceIfNeededAndGetName();
    auto status =
        HIDL_INVOKE(hostapd_, addAccessPoint_1_2,
                    getIfaceParamsWithoutAcs(ifname), getSaeNwParams());
    EXPECT_EQ(HostapdStatusCode::SUCCESS, status.code);
}

@@ -313,11 +336,12 @@ TEST_P(HostapdHidlTest, AddSAEAccessPointWithoutAcs) {
 */
TEST_P(HostapdHidlTest, RemoveAccessPointWithAcs) {
    if (!isAcsSupport_) GTEST_SKIP() << "Missing ACS support";
    auto status_1_2 = HIDL_INVOKE(hostapd_, addAccessPoint_1_2,
                                  getIfaceParamsWithAcs(), getPskNwParams());
    std::string ifname = setupApIfaceIfNeededAndGetName();
    auto status_1_2 =
        HIDL_INVOKE(hostapd_, addAccessPoint_1_2, getIfaceParamsWithAcs(ifname),
                    getPskNwParams());
    EXPECT_EQ(HostapdStatusCode::SUCCESS, status_1_2.code);
    auto status =
        HIDL_INVOKE(hostapd_, removeAccessPoint, getPrimaryWlanIfaceName());
    auto status = HIDL_INVOKE(hostapd_, removeAccessPoint, ifname);
    EXPECT_EQ(
        android::hardware::wifi::hostapd::V1_0::HostapdStatusCode::SUCCESS,
        status.code);
@@ -328,11 +352,12 @@ TEST_P(HostapdHidlTest, RemoveAccessPointWithAcs) {
 * Access point creation & removal should pass.
 */
TEST_P(HostapdHidlTest, RemoveAccessPointWithoutAcs) {
    auto status_1_2 = HIDL_INVOKE(hostapd_, addAccessPoint_1_2,
                                  getIfaceParamsWithoutAcs(), getPskNwParams());
    std::string ifname = setupApIfaceIfNeededAndGetName();
    auto status_1_2 =
        HIDL_INVOKE(hostapd_, addAccessPoint_1_2,
                    getIfaceParamsWithoutAcs(ifname), getPskNwParams());
    EXPECT_EQ(HostapdStatusCode::SUCCESS, status_1_2.code);
    auto status =
        HIDL_INVOKE(hostapd_, removeAccessPoint, getPrimaryWlanIfaceName());
    auto status = HIDL_INVOKE(hostapd_, removeAccessPoint, ifname);
    EXPECT_EQ(
        android::hardware::wifi::hostapd::V1_0::HostapdStatusCode::SUCCESS,
        status.code);
@@ -343,9 +368,10 @@ TEST_P(HostapdHidlTest, RemoveAccessPointWithoutAcs) {
 * Access point creation should fail.
 */
TEST_P(HostapdHidlTest, AddPskAccessPointWithInvalidChannel) {
    std::string ifname = setupApIfaceIfNeededAndGetName();
    auto status =
        HIDL_INVOKE(hostapd_, addAccessPoint_1_2,
                    getIfaceParamsWithInvalidChannel(), getPskNwParams());
                    getIfaceParamsWithInvalidChannel(ifname), getPskNwParams());
    EXPECT_NE(HostapdStatusCode::SUCCESS, status.code);
}

@@ -354,9 +380,10 @@ TEST_P(HostapdHidlTest, AddPskAccessPointWithInvalidChannel) {
 * Access point creation should fail.
 */
TEST_P(HostapdHidlTest, AddInvalidPskAccessPointWithoutAcs) {
    std::string ifname = setupApIfaceIfNeededAndGetName();
    auto status =
        HIDL_INVOKE(hostapd_, addAccessPoint_1_2, getIfaceParamsWithoutAcs(),
                    getInvalidPskNwParams());
        HIDL_INVOKE(hostapd_, addAccessPoint_1_2,
                    getIfaceParamsWithoutAcs(ifname), getInvalidPskNwParams());
    EXPECT_NE(HostapdStatusCode::SUCCESS, status.code);
}

@@ -366,8 +393,9 @@ TEST_P(HostapdHidlTest, AddInvalidPskAccessPointWithoutAcs) {
 */
TEST_P(HostapdHidlTest, AddInvalidSaeTransitionAccessPointWithoutAcs) {
    if (!isWpa3SaeSupport_) GTEST_SKIP() << "Missing SAE support";
    auto status =
        HIDL_INVOKE(hostapd_, addAccessPoint_1_2, getIfaceParamsWithoutAcs(),
    std::string ifname = setupApIfaceIfNeededAndGetName();
    auto status = HIDL_INVOKE(hostapd_, addAccessPoint_1_2,
                              getIfaceParamsWithoutAcs(ifname),
                              getInvalidSaeTransitionNwParams());
    EXPECT_NE(HostapdStatusCode::SUCCESS, status.code);
}
@@ -378,9 +406,10 @@ TEST_P(HostapdHidlTest, AddInvalidSaeTransitionAccessPointWithoutAcs) {
 */
TEST_P(HostapdHidlTest, AddInvalidSaeAccessPointWithoutAcs) {
    if (!isWpa3SaeSupport_) GTEST_SKIP() << "Missing SAE support";
    std::string ifname = setupApIfaceIfNeededAndGetName();
    auto status =
        HIDL_INVOKE(hostapd_, addAccessPoint_1_2, getIfaceParamsWithoutAcs(),
                    getInvalidSaeNwParams());
        HIDL_INVOKE(hostapd_, addAccessPoint_1_2,
                    getIfaceParamsWithoutAcs(ifname), getInvalidSaeNwParams());
    EXPECT_NE(HostapdStatusCode::SUCCESS, status.code);
}

@@ -389,8 +418,8 @@ TEST_P(HostapdHidlTest, AddInvalidSaeAccessPointWithoutAcs) {
 * when hotspot interface doesn't init..
 */
TEST_P(HostapdHidlTest, DisconnectClientWhenIfaceNotAvailable) {
    auto status =
        HIDL_INVOKE(hostapd_, forceClientDisconnect, getPrimaryWlanIfaceName(),
    std::string ifname = setupApIfaceIfNeededAndGetName();
    auto status = HIDL_INVOKE(hostapd_, forceClientDisconnect, ifname,
                              kTestZeroMacAddr, kTestDisconnectReasonCode);
    EXPECT_EQ(HostapdStatusCode::FAILURE_IFACE_UNKNOWN, status.code);
}
@@ -400,13 +429,13 @@ TEST_P(HostapdHidlTest, DisconnectClientWhenIfaceNotAvailable) {
 * when hotspot interface available.
 */
TEST_P(HostapdHidlTest, DisconnectClientWhenIfacAvailable) {
    std::string ifname = setupApIfaceIfNeededAndGetName();
    auto status_1_2 =
        HIDL_INVOKE(hostapd_, addAccessPoint_1_2, getIfaceParamsWithoutAcs(),
                    getOpenNwParams());
        HIDL_INVOKE(hostapd_, addAccessPoint_1_2,
                    getIfaceParamsWithoutAcs(ifname), getOpenNwParams());
    EXPECT_EQ(HostapdStatusCode::SUCCESS, status_1_2.code);

    status_1_2 =
        HIDL_INVOKE(hostapd_, forceClientDisconnect, getPrimaryWlanIfaceName(),
    status_1_2 = HIDL_INVOKE(hostapd_, forceClientDisconnect, ifname,
                             kTestZeroMacAddr, kTestDisconnectReasonCode);
    EXPECT_EQ(HostapdStatusCode::FAILURE_CLIENT_UNKNOWN, status_1_2.code);
}