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

Commit a2d1efb4 authored by Mingguang Xu's avatar Mingguang Xu Committed by Android (Google) Code Review
Browse files

Merge "WiFi: Get peer information (BSS load and rate statistics) from link layer stats" into sc-dev

parents 620835b4 41242be7
Loading
Loading
Loading
Loading
+40 −0
Original line number Diff line number Diff line
@@ -1077,6 +1077,17 @@ bool convertLegacyLinkLayerStatsToHidl(
        legacy_stats.iface.ac[legacy_hal::WIFI_AC_VO].contention_num_samples;
    hidl_stats->iface.timeSliceDutyCycleInPercent =
        legacy_stats.iface.info.time_slicing_duty_cycle_percent;
    // peer info legacy_stats conversion.
    std::vector<StaPeerInfo> hidl_peers_info_stats;
    for (const auto& legacy_peer_info_stats : legacy_stats.peers) {
        StaPeerInfo hidl_peer_info_stats;
        if (!convertLegacyPeerInfoStatsToHidl(legacy_peer_info_stats,
                                              &hidl_peer_info_stats)) {
            return false;
        }
        hidl_peers_info_stats.push_back(hidl_peer_info_stats);
    }
    hidl_stats->iface.peers = hidl_peers_info_stats;
    // radio legacy_stats conversion.
    std::vector<V1_3::StaLinkLayerRadioStats> hidl_radios_stats;
    for (const auto& legacy_radio_stats : legacy_stats.radios) {
@@ -1094,6 +1105,35 @@ bool convertLegacyLinkLayerStatsToHidl(
    return true;
}

bool convertLegacyPeerInfoStatsToHidl(
    const legacy_hal::WifiPeerInfo& legacy_peer_info_stats,
    StaPeerInfo* hidl_peer_info_stats) {
    if (!hidl_peer_info_stats) {
        return false;
    }
    *hidl_peer_info_stats = {};
    hidl_peer_info_stats->staCount =
        legacy_peer_info_stats.peer_info.bssload.sta_count;
    hidl_peer_info_stats->chanUtil =
        legacy_peer_info_stats.peer_info.bssload.chan_util;

    std::vector<StaRateStat> hidlRateStats;
    for (const auto& legacy_rate_stats : legacy_peer_info_stats.rate_stats) {
        StaRateStat rateStat;
        if (!convertLegacyWifiRateInfoToHidl(legacy_rate_stats.rate,
                                             &rateStat.rateInfo)) {
            return false;
        }
        rateStat.txMpdu = legacy_rate_stats.tx_mpdu;
        rateStat.rxMpdu = legacy_rate_stats.rx_mpdu;
        rateStat.mpduLost = legacy_rate_stats.mpdu_lost;
        rateStat.retries = legacy_rate_stats.retries;
        hidlRateStats.push_back(rateStat);
    }
    hidl_peer_info_stats->rateStats = hidlRateStats;
    return true;
}

bool convertLegacyRoamingCapabilitiesToHidl(
    const legacy_hal::wifi_roaming_capabilities& legacy_caps,
    StaRoamingCapabilities* hidl_caps) {
+5 −0
Original line number Diff line number Diff line
@@ -212,6 +212,11 @@ uint32_t convertHidlUsableChannelFilterToLegacy(uint32_t hidl_filter_mask);
bool convertLegacyWifiUsableChannelsToHidl(
    const std::vector<legacy_hal::wifi_usable_channel>& legacy_usable_channels,
    std::vector<V1_5::WifiUsableChannel>* hidl_usable_channels);
bool convertLegacyPeerInfoStatsToHidl(
    const legacy_hal::WifiPeerInfo& legacy_peer_info_stats,
    StaPeerInfo* hidl_peer_info_stats);
bool convertLegacyWifiRateInfoToHidl(const legacy_hal::wifi_rate& legacy_rate,
                                     V1_4::WifiRateInfo* hidl_rate);
}  // namespace hidl_struct_util
}  // namespace implementation
}  // namespace V1_5
+59 −0
Original line number Diff line number Diff line
@@ -132,6 +132,8 @@ TEST_F(HidlStructUtilTest, canConvertLegacyLinkLayerStatsToHidl) {
    legacy_hal::LinkLayerStats legacy_stats{};
    legacy_stats.radios.push_back(legacy_hal::LinkLayerRadioStats{});
    legacy_stats.radios.push_back(legacy_hal::LinkLayerRadioStats{});
    legacy_stats.peers.push_back(legacy_hal::WifiPeerInfo{});
    legacy_stats.peers.push_back(legacy_hal::WifiPeerInfo{});
    legacy_stats.iface.beacon_rx = rand();
    legacy_stats.iface.rssi_mgmt = rand();
    legacy_stats.iface.ac[legacy_hal::WIFI_AC_BE].rx_mpdu = rand();
@@ -175,6 +177,7 @@ TEST_F(HidlStructUtilTest, canConvertLegacyLinkLayerStatsToHidl) {
        rand();

    legacy_stats.iface.info.time_slicing_duty_cycle_percent = rand();
    legacy_stats.iface.num_peers = 1;

    for (auto& radio : legacy_stats.radios) {
        radio.stats.on_time = rand();
@@ -204,6 +207,31 @@ TEST_F(HidlStructUtilTest, canConvertLegacyLinkLayerStatsToHidl) {
        radio.channel_stats.push_back(channel_stat2);
    }

    for (auto& peer : legacy_stats.peers) {
        peer.peer_info.bssload.sta_count = rand();
        peer.peer_info.bssload.chan_util = rand();
        wifi_rate_stat rate_stat1 = {
            .rate = {3, 1, 2, 5, 0, 0},
            .tx_mpdu = 0,
            .rx_mpdu = 1,
            .mpdu_lost = 2,
            .retries = 3,
            .retries_short = 4,
            .retries_long = 5,
        };
        wifi_rate_stat rate_stat2 = {
            .rate = {2, 2, 1, 6, 0, 1},
            .tx_mpdu = 6,
            .rx_mpdu = 7,
            .mpdu_lost = 8,
            .retries = 9,
            .retries_short = 10,
            .retries_long = 11,
        };
        peer.rate_stats.push_back(rate_stat1);
        peer.rate_stats.push_back(rate_stat2);
    }

    V1_5::StaLinkLayerStats converted{};
    hidl_struct_util::convertLegacyLinkLayerStatsToHidl(legacy_stats,
                                                        &converted);
@@ -330,6 +358,37 @@ TEST_F(HidlStructUtilTest, canConvertLegacyLinkLayerStatsToHidl) {
                      converted.radios[i].channelStats[k].onTimeInMs);
        }
    }

    EXPECT_EQ(legacy_stats.peers.size(), converted.iface.peers.size());
    for (size_t i = 0; i < legacy_stats.peers.size(); i++) {
        EXPECT_EQ(legacy_stats.peers[i].peer_info.bssload.sta_count,
                  converted.iface.peers[i].staCount);
        EXPECT_EQ(legacy_stats.peers[i].peer_info.bssload.chan_util,
                  converted.iface.peers[i].chanUtil);
        for (size_t j = 0; j < legacy_stats.peers[i].rate_stats.size(); j++) {
            EXPECT_EQ(legacy_stats.peers[i].rate_stats[j].rate.preamble,
                      (uint32_t)converted.iface.peers[i]
                          .rateStats[j]
                          .rateInfo.preamble);
            EXPECT_EQ(
                legacy_stats.peers[i].rate_stats[j].rate.nss,
                (uint32_t)converted.iface.peers[i].rateStats[j].rateInfo.nss);
            EXPECT_EQ(
                legacy_stats.peers[i].rate_stats[j].rate.bw,
                (uint32_t)converted.iface.peers[i].rateStats[j].rateInfo.bw);
            EXPECT_EQ(
                legacy_stats.peers[i].rate_stats[j].rate.rateMcsIdx,
                converted.iface.peers[i].rateStats[j].rateInfo.rateMcsIdx);
            EXPECT_EQ(legacy_stats.peers[i].rate_stats[j].tx_mpdu,
                      converted.iface.peers[i].rateStats[j].txMpdu);
            EXPECT_EQ(legacy_stats.peers[i].rate_stats[j].rx_mpdu,
                      converted.iface.peers[i].rateStats[j].rxMpdu);
            EXPECT_EQ(legacy_stats.peers[i].rate_stats[j].mpdu_lost,
                      converted.iface.peers[i].rateStats[j].mpduLost);
            EXPECT_EQ(legacy_stats.peers[i].rate_stats[j].retries,
                      converted.iface.peers[i].rateStats[j].retries);
        }
    }
}

TEST_F(HidlStructUtilTest, CanConvertLegacyFeaturesToHidl) {
+20 −0
Original line number Diff line number Diff line
@@ -719,9 +719,29 @@ std::pair<wifi_error, LinkLayerStats> WifiLegacyHal::getLinkLayerStats(
                          wifi_iface_stat* iface_stats_ptr, int num_radios,
                          wifi_radio_stat* radio_stats_ptr) {
            wifi_radio_stat* l_radio_stats_ptr;
            wifi_peer_info* l_peer_info_stats_ptr;

            if (iface_stats_ptr != nullptr) {
                link_stats_ptr->iface = *iface_stats_ptr;
                l_peer_info_stats_ptr = iface_stats_ptr->peer_info;
                for (uint32_t i = 0; i < iface_stats_ptr->num_peers; i++) {
                    WifiPeerInfo peer;
                    peer.peer_info = *l_peer_info_stats_ptr;
                    if (l_peer_info_stats_ptr->num_rate > 0) {
                        /* Copy the rate stats */
                        peer.rate_stats.assign(
                            l_peer_info_stats_ptr->rate_stats,
                            l_peer_info_stats_ptr->rate_stats +
                                l_peer_info_stats_ptr->num_rate);
                    }
                    peer.peer_info.num_rate = 0;
                    link_stats_ptr->peers.push_back(peer);
                    l_peer_info_stats_ptr =
                        (wifi_peer_info*)((u8*)l_peer_info_stats_ptr +
                                          sizeof(wifi_peer_info) +
                                          (sizeof(wifi_rate_stat) *
                                           l_peer_info_stats_ptr->num_rate));
                }
                link_stats_ptr->iface.num_peers = 0;
            } else {
                LOG(ERROR) << "Invalid iface stats in link layer stats";
+6 −0
Original line number Diff line number Diff line
@@ -340,9 +340,15 @@ struct LinkLayerRadioStats {
    std::vector<wifi_channel_stat> channel_stats;
};

struct WifiPeerInfo {
    wifi_peer_info peer_info;
    std::vector<wifi_rate_stat> rate_stats;
};

struct LinkLayerStats {
    wifi_iface_stat iface;
    std::vector<LinkLayerRadioStats> radios;
    std::vector<WifiPeerInfo> peers;
};
#pragma GCC diagnostic pop

Loading