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

Commit 6036c02d authored by Roshan Pius's avatar Roshan Pius
Browse files

wifi(implementation): Use the active iface for chip operation

For the chip level operations, the actual interface itself does not
matter. So, instead of hard-coding these operations to wlan0 interface,
find the first active interface to use. This will still return wlan0 if
it's active, but if only AP is up (& pinned to wlan1), then it will use
wlan1 instead.

Bug: 129358937
Test: ./data/android.hardware.wifi@1.0-service-tests
Test: Verified manually that SAR commands are now correctly sent down.
Change-Id: I5a6175579027cbb45c09d32633ed81b9f72224dd
parent a3e5b7fc
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -43,6 +43,12 @@ class MockWifiLegacyHal : public WifiLegacyHal {
                 const std::string& iface_name));
    MOCK_METHOD1(getDriverVersion, std::pair<wifi_error, std::string>(
                 const std::string& iface_name));

    MOCK_METHOD2(selectTxPowerScenario,
                 wifi_error(const std::string& iface_name,
                            wifi_power_scenario scenario));
    MOCK_METHOD1(resetTxPowerScenario,
                 wifi_error(const std::string& iface_name));
    MOCK_METHOD2(nanRegisterCallbackHandlers,
                 wifi_error(const std::string&, const NanCallbackHandlers&));
    MOCK_METHOD2(nanDisableRequest,
+62 −15
Original line number Diff line number Diff line
@@ -261,6 +261,17 @@ class WifiChipTest : public Test {
        return success;
    }

    sp<WifiChip> chip_;
    ChipId chip_id_ = kFakeChipId;
    std::shared_ptr<NiceMock<legacy_hal::MockWifiLegacyHal>> legacy_hal_{
        new NiceMock<legacy_hal::MockWifiLegacyHal>};
    std::shared_ptr<NiceMock<mode_controller::MockWifiModeController>>
        mode_controller_{new NiceMock<mode_controller::MockWifiModeController>};
    std::shared_ptr<NiceMock<iface_util::MockWifiIfaceUtil>> iface_util_{
        new NiceMock<iface_util::MockWifiIfaceUtil>};
    std::shared_ptr<NiceMock<feature_flags::MockWifiFeatureFlags>>
        feature_flags_{new NiceMock<feature_flags::MockWifiFeatureFlags>};

   public:
    void SetUp() override {
        chip_ = new WifiChip(chip_id_, legacy_hal_, mode_controller_,
@@ -278,18 +289,6 @@ class WifiChipTest : public Test {
        property_set("wifi.interface", "wlan0");
        property_set("wifi.concurrent.interface", "wlan1");
    }

   private:
    sp<WifiChip> chip_;
    ChipId chip_id_ = kFakeChipId;
    std::shared_ptr<NiceMock<legacy_hal::MockWifiLegacyHal>> legacy_hal_{
        new NiceMock<legacy_hal::MockWifiLegacyHal>};
    std::shared_ptr<NiceMock<mode_controller::MockWifiModeController>>
        mode_controller_{new NiceMock<mode_controller::MockWifiModeController>};
    std::shared_ptr<NiceMock<iface_util::MockWifiIfaceUtil>> iface_util_{
        new NiceMock<iface_util::MockWifiIfaceUtil>};
    std::shared_ptr<NiceMock<feature_flags::MockWifiFeatureFlags>>
        feature_flags_{new NiceMock<feature_flags::MockWifiFeatureFlags>};
};

////////// V1 Iface Combinations ////////////
@@ -452,18 +451,18 @@ TEST_F(WifiChipV1_AwareIfaceCombinationTest, ApMode_CreateNan_ShouldFail) {
    ASSERT_TRUE(createIface(IfaceType::NAN).empty());
}

TEST_F(WifiChipV1IfaceCombinationTest, RttControllerFlowStaModeNoSta) {
TEST_F(WifiChipV1_AwareIfaceCombinationTest, RttControllerFlowStaModeNoSta) {
    findModeAndConfigureForIfaceType(IfaceType::STA);
    ASSERT_TRUE(createRttController());
}

TEST_F(WifiChipV1IfaceCombinationTest, RttControllerFlowStaModeWithSta) {
TEST_F(WifiChipV1_AwareIfaceCombinationTest, RttControllerFlowStaModeWithSta) {
    findModeAndConfigureForIfaceType(IfaceType::STA);
    ASSERT_FALSE(createIface(IfaceType::STA).empty());
    ASSERT_TRUE(createRttController());
}

TEST_F(WifiChipV1IfaceCombinationTest, RttControllerFlowApToSta) {
TEST_F(WifiChipV1_AwareIfaceCombinationTest, RttControllerFlowApToSta) {
    findModeAndConfigureForIfaceType(IfaceType::AP);
    const auto ap_iface_name = createIface(IfaceType::AP);
    ASSERT_FALSE(ap_iface_name.empty());
@@ -475,6 +474,30 @@ TEST_F(WifiChipV1IfaceCombinationTest, RttControllerFlowApToSta) {
    ASSERT_TRUE(createRttController());
}

TEST_F(WifiChipV1_AwareIfaceCombinationTest, SelectTxScenarioWithOnlySta) {
    findModeAndConfigureForIfaceType(IfaceType::STA);
    ASSERT_EQ(createIface(IfaceType::STA), "wlan0");
    EXPECT_CALL(*legacy_hal_, selectTxPowerScenario("wlan0", testing::_))
        .WillOnce(testing::Return(legacy_hal::WIFI_SUCCESS));
    chip_->selectTxPowerScenario_1_2(
        V1_2::IWifiChip::TxPowerScenario::ON_HEAD_CELL_OFF,
        [](const WifiStatus& status) {
            ASSERT_EQ(WifiStatusCode::SUCCESS, status.code);
        });
}

TEST_F(WifiChipV1_AwareIfaceCombinationTest, SelectTxScenarioWithOnlyAp) {
    findModeAndConfigureForIfaceType(IfaceType::AP);
    ASSERT_EQ(createIface(IfaceType::AP), "wlan0");
    EXPECT_CALL(*legacy_hal_, selectTxPowerScenario("wlan0", testing::_))
        .WillOnce(testing::Return(legacy_hal::WIFI_SUCCESS));
    chip_->selectTxPowerScenario_1_2(
        V1_2::IWifiChip::TxPowerScenario::ON_HEAD_CELL_OFF,
        [](const WifiStatus& status) {
            ASSERT_EQ(WifiStatusCode::SUCCESS, status.code);
        });
}

////////// V2 + Aware Iface Combinations ////////////
// Mode 1 - STA + STA/AP
//        - STA + P2P/NAN
@@ -653,6 +676,30 @@ TEST_F(WifiChipV2_AwareIfaceCombinationTest, RttControllerFlow) {
    ASSERT_TRUE(createRttController());
}

TEST_F(WifiChipV2_AwareIfaceCombinationTest, SelectTxScenarioWithOnlySta) {
    findModeAndConfigureForIfaceType(IfaceType::STA);
    ASSERT_EQ(createIface(IfaceType::STA), "wlan0");
    EXPECT_CALL(*legacy_hal_, selectTxPowerScenario("wlan0", testing::_))
        .WillOnce(testing::Return(legacy_hal::WIFI_SUCCESS));
    chip_->selectTxPowerScenario_1_2(
        V1_2::IWifiChip::TxPowerScenario::ON_HEAD_CELL_OFF,
        [](const WifiStatus& status) {
            ASSERT_EQ(WifiStatusCode::SUCCESS, status.code);
        });
}

TEST_F(WifiChipV2_AwareIfaceCombinationTest, SelectTxScenarioWithOnlyAp) {
    findModeAndConfigureForIfaceType(IfaceType::AP);
    ASSERT_EQ(createIface(IfaceType::AP), "wlan1");
    EXPECT_CALL(*legacy_hal_, selectTxPowerScenario("wlan1", testing::_))
        .WillOnce(testing::Return(legacy_hal::WIFI_SUCCESS));
    chip_->selectTxPowerScenario_1_2(
        V1_2::IWifiChip::TxPowerScenario::ON_HEAD_CELL_OFF,
        [](const WifiStatus& status) {
            ASSERT_EQ(WifiStatusCode::SUCCESS, status.code);
        });
}

////////// V1 Iface Combinations when AP creation is disabled //////////
class WifiChipV1_AwareDisabledApIfaceCombinationTest : public WifiChipTest {
   public:
+35 −20
Original line number Diff line number Diff line
@@ -641,7 +641,7 @@ std::pair<WifiStatus, uint32_t> WifiChip::getCapabilitiesInternal_1_3() {
    legacy_hal::wifi_error legacy_status;
    uint32_t legacy_feature_set;
    uint32_t legacy_logger_feature_set;
    const auto ifname = getWlanIfaceName(0);
    const auto ifname = getFirstActiveWlanIfaceName();
    std::tie(legacy_status, legacy_feature_set) =
        legacy_hal_.lock()->getSupportedFeatureSet(ifname);
    if (legacy_status != legacy_hal::WIFI_SUCCESS) {
@@ -709,7 +709,7 @@ WifiChip::requestChipDebugInfoInternal() {
    IWifiChip::ChipDebugInfo result;
    legacy_hal::wifi_error legacy_status;
    std::string driver_desc;
    const auto ifname = getWlanIfaceName(0);
    const auto ifname = getFirstActiveWlanIfaceName();
    std::tie(legacy_status, driver_desc) =
        legacy_hal_.lock()->getDriverVersion(ifname);
    if (legacy_status != legacy_hal::WIFI_SUCCESS) {
@@ -741,7 +741,8 @@ WifiChip::requestDriverDebugDumpInternal() {
    legacy_hal::wifi_error legacy_status;
    std::vector<uint8_t> driver_dump;
    std::tie(legacy_status, driver_dump) =
        legacy_hal_.lock()->requestDriverMemoryDump(getWlanIfaceName(0));
        legacy_hal_.lock()->requestDriverMemoryDump(
            getFirstActiveWlanIfaceName());
    if (legacy_status != legacy_hal::WIFI_SUCCESS) {
        LOG(ERROR) << "Failed to get driver debug dump: "
                   << legacyErrorToString(legacy_status);
@@ -756,7 +757,8 @@ WifiChip::requestFirmwareDebugDumpInternal() {
    legacy_hal::wifi_error legacy_status;
    std::vector<uint8_t> firmware_dump;
    std::tie(legacy_status, firmware_dump) =
        legacy_hal_.lock()->requestFirmwareMemoryDump(getWlanIfaceName(0));
        legacy_hal_.lock()->requestFirmwareMemoryDump(
            getFirstActiveWlanIfaceName());
    if (legacy_status != legacy_hal::WIFI_SUCCESS) {
        LOG(ERROR) << "Failed to get firmware debug dump: "
                   << legacyErrorToString(legacy_status);
@@ -817,7 +819,7 @@ std::pair<WifiStatus, sp<IWifiNanIface>> WifiChip::createNanIfaceInternal() {
        return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}};
    }
    // These are still assumed to be based on wlan0.
    std::string ifname = getWlanIfaceName(0);
    std::string ifname = getFirstActiveWlanIfaceName();
    sp<WifiNanIface> iface = new WifiNanIface(ifname, legacy_hal_);
    nan_ifaces_.push_back(iface);
    for (const auto& callback : event_cb_handler_.getCallbacks()) {
@@ -959,8 +961,8 @@ WifiChip::createRttControllerInternal(const sp<IWifiIface>& bound_iface) {
                      "(and RTT by extension)";
        return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}};
    }
    sp<WifiRttController> rtt =
        new WifiRttController(getWlanIfaceName(0), bound_iface, legacy_hal_);
    sp<WifiRttController> rtt = new WifiRttController(
        getFirstActiveWlanIfaceName(), bound_iface, legacy_hal_);
    rtt_controllers_.emplace_back(rtt);
    return {createWifiStatus(WifiStatusCode::SUCCESS), rtt};
}
@@ -971,7 +973,7 @@ WifiChip::getDebugRingBuffersStatusInternal() {
    std::vector<legacy_hal::wifi_ring_buffer_status>
        legacy_ring_buffer_status_vec;
    std::tie(legacy_status, legacy_ring_buffer_status_vec) =
        legacy_hal_.lock()->getRingBuffersStatus(getWlanIfaceName(0));
        legacy_hal_.lock()->getRingBuffersStatus(getFirstActiveWlanIfaceName());
    if (legacy_status != legacy_hal::WIFI_SUCCESS) {
        return {createWifiStatusFromLegacyError(legacy_status), {}};
    }
@@ -993,7 +995,7 @@ WifiStatus WifiChip::startLoggingToDebugRingBufferInternal(
    }
    legacy_hal::wifi_error legacy_status =
        legacy_hal_.lock()->startRingBufferLogging(
            getWlanIfaceName(0), ring_name,
            getFirstActiveWlanIfaceName(), ring_name,
            static_cast<
                std::underlying_type<WifiDebugRingBufferVerboseLevel>::type>(
                verbose_level),
@@ -1010,7 +1012,8 @@ WifiStatus WifiChip::forceDumpToDebugRingBufferInternal(
        return status;
    }
    legacy_hal::wifi_error legacy_status =
        legacy_hal_.lock()->getRingBufferData(getWlanIfaceName(0), ring_name);
        legacy_hal_.lock()->getRingBufferData(getFirstActiveWlanIfaceName(),
                                              ring_name);

    return createWifiStatusFromLegacyError(legacy_status);
}
@@ -1026,7 +1029,7 @@ WifiStatus WifiChip::flushRingBufferToFileInternal() {
WifiStatus WifiChip::stopLoggingToDebugRingBufferInternal() {
    legacy_hal::wifi_error legacy_status =
        legacy_hal_.lock()->deregisterRingBufferCallbackHandler(
            getWlanIfaceName(0));
            getFirstActiveWlanIfaceName());
    return createWifiStatusFromLegacyError(legacy_status);
}

@@ -1035,7 +1038,7 @@ WifiChip::getDebugHostWakeReasonStatsInternal() {
    legacy_hal::wifi_error legacy_status;
    legacy_hal::WakeReasonStats legacy_stats;
    std::tie(legacy_status, legacy_stats) =
        legacy_hal_.lock()->getWakeReasonStats(getWlanIfaceName(0));
        legacy_hal_.lock()->getWakeReasonStats(getFirstActiveWlanIfaceName());
    if (legacy_status != legacy_hal::WIFI_SUCCESS) {
        return {createWifiStatusFromLegacyError(legacy_status), {}};
    }
@@ -1067,10 +1070,10 @@ WifiStatus WifiChip::enableDebugErrorAlertsInternal(bool enable) {
            }
        };
        legacy_status = legacy_hal_.lock()->registerErrorAlertCallbackHandler(
            getWlanIfaceName(0), on_alert_callback);
            getFirstActiveWlanIfaceName(), on_alert_callback);
    } else {
        legacy_status = legacy_hal_.lock()->deregisterErrorAlertCallbackHandler(
            getWlanIfaceName(0));
            getFirstActiveWlanIfaceName());
    }
    return createWifiStatusFromLegacyError(legacy_status);
}
@@ -1078,20 +1081,20 @@ WifiStatus WifiChip::enableDebugErrorAlertsInternal(bool enable) {
WifiStatus WifiChip::selectTxPowerScenarioInternal(
    V1_1::IWifiChip::TxPowerScenario scenario) {
    auto legacy_status = legacy_hal_.lock()->selectTxPowerScenario(
        getWlanIfaceName(0),
        getFirstActiveWlanIfaceName(),
        hidl_struct_util::convertHidlTxPowerScenarioToLegacy(scenario));
    return createWifiStatusFromLegacyError(legacy_status);
}

WifiStatus WifiChip::resetTxPowerScenarioInternal() {
    auto legacy_status =
        legacy_hal_.lock()->resetTxPowerScenario(getWlanIfaceName(0));
        legacy_hal_.lock()->resetTxPowerScenario(getFirstActiveWlanIfaceName());
    return createWifiStatusFromLegacyError(legacy_status);
}

WifiStatus WifiChip::setLatencyModeInternal(LatencyMode mode) {
    auto legacy_status = legacy_hal_.lock()->setLatencyMode(
        getWlanIfaceName(0),
        getFirstActiveWlanIfaceName(),
        hidl_struct_util::convertHidlLatencyModeToLegacy(mode));
    return createWifiStatusFromLegacyError(legacy_status);
}
@@ -1107,7 +1110,7 @@ WifiStatus WifiChip::registerEventCallbackInternal_1_2(
WifiStatus WifiChip::selectTxPowerScenarioInternal_1_2(
    TxPowerScenario scenario) {
    auto legacy_status = legacy_hal_.lock()->selectTxPowerScenario(
        getWlanIfaceName(0),
        getFirstActiveWlanIfaceName(),
        hidl_struct_util::convertHidlTxPowerScenarioToLegacy_1_2(scenario));
    return createWifiStatusFromLegacyError(legacy_status);
}
@@ -1197,7 +1200,7 @@ WifiStatus WifiChip::registerDebugRingBufferCallback() {
        };
    legacy_hal::wifi_error legacy_status =
        legacy_hal_.lock()->registerRingBufferCallbackHandler(
            getWlanIfaceName(0), on_ring_buffer_data_callback);
            getFirstActiveWlanIfaceName(), on_ring_buffer_data_callback);

    if (legacy_status == legacy_hal::WIFI_SUCCESS) {
        debug_ring_buffer_cb_registered_ = true;
@@ -1231,7 +1234,7 @@ WifiStatus WifiChip::registerRadioModeChangeCallback() {
        };
    legacy_hal::wifi_error legacy_status =
        legacy_hal_.lock()->registerRadioModeChangeCallbackHandler(
            getWlanIfaceName(0), on_radio_mode_change_callback);
            getFirstActiveWlanIfaceName(), on_radio_mode_change_callback);
    return createWifiStatusFromLegacyError(legacy_status);
}

@@ -1415,6 +1418,18 @@ bool WifiChip::isStaApConcurrencyAllowedInCurrentMode() {
    return canCurrentModeSupportIfaceCombo(req_iface_combo);
}

std::string WifiChip::getFirstActiveWlanIfaceName() {
    for (unsigned idx = 0; idx < kMaxWlanIfaces; idx++) {
        const auto ifname = getWlanIfaceName(idx);
        if (findUsingName(sta_ifaces_, ifname)) return ifname;
        if (findUsingName(ap_ifaces_, ifname)) return ifname;
    }
    // This could happen if the chip call is made before any STA/AP
    // iface is created. Default to wlan0 for such cases.
    LOG(WARNING) << "No active wlan interfaces in use!";
    return getWlanIfaceName(0);
}

// Return the first wlan (wlan0, wlan1 etc.) starting from |start_idx|
// not already in use.
// Note: This doesn't check the actual presence of these interfaces.
+1 −0
Original line number Diff line number Diff line
@@ -237,6 +237,7 @@ class WifiChip : public V1_3::IWifiChip {
    bool canCurrentModeSupportIfaceOfType(IfaceType requested_type);
    bool isValidModeId(ChipModeId mode_id);
    bool isStaApConcurrencyAllowedInCurrentMode();
    std::string getFirstActiveWlanIfaceName();
    std::string allocateApOrStaIfaceName(uint32_t start_idx);
    std::string allocateApIfaceName();
    std::string allocateStaIfaceName();
+3 −3
Original line number Diff line number Diff line
@@ -254,9 +254,9 @@ class WifiLegacyHal {
                                          uint32_t cmd_id);
    wifi_error setScanningMacOui(const std::string& iface_name,
                                 const std::array<uint8_t, 3>& oui);
    wifi_error selectTxPowerScenario(const std::string& iface_name,
    virtual wifi_error selectTxPowerScenario(const std::string& iface_name,
                                             wifi_power_scenario scenario);
    wifi_error resetTxPowerScenario(const std::string& iface_name);
    virtual wifi_error resetTxPowerScenario(const std::string& iface_name);
    wifi_error setLatencyMode(const std::string& iface_name,
                              wifi_latency_mode mode);
    // Logger/debug functions.