From ad06ac0b04cc0a3efa8ec5b3e7814f2b4d864d88 Mon Sep 17 00:00:00 2001 From: Emmanuel Grumbach Date: Fri, 6 Dec 2019 14:27:47 -0800 Subject: [PATCH] Move throughput estimation into a helper function This is a step towards allowing this functionality to update the scan result -based values with the values from a signal poll for the current BSS. Signed-off-by: Emmanuel Grumbach --- wpa_supplicant/scan.c | 50 +++++++++++++++++++++++++++---------------- wpa_supplicant/scan.h | 3 +++ 2 files changed, 35 insertions(+), 18 deletions(-) diff --git a/wpa_supplicant/scan.c b/wpa_supplicant/scan.c index fea410250..205653a67 100644 --- a/wpa_supplicant/scan.c +++ b/wpa_supplicant/scan.c @@ -2248,20 +2248,13 @@ static unsigned int max_vht80_rate(int snr) } -void scan_est_throughput(struct wpa_supplicant *wpa_s, - struct wpa_scan_res *res) +unsigned int wpas_get_est_tpt(const struct wpa_supplicant *wpa_s, + const u8 *ies, size_t ies_len, int rate, + int snr) { enum local_hw_capab capab = wpa_s->hw_capab; - int rate; /* max legacy rate in 500 kb/s units */ - const u8 *ie; unsigned int est, tmp; - int snr = res->snr; - - if (res->est_throughput) - return; - - /* Get maximum legacy rate */ - rate = wpa_scan_get_max_rate(res); + const u8 *ie; /* Limit based on estimated SNR */ if (rate > 1 * 2 && snr < 1) @@ -2287,7 +2280,7 @@ void scan_est_throughput(struct wpa_supplicant *wpa_s, est = rate * 500; if (capab == CAPAB_HT || capab == CAPAB_HT40 || capab == CAPAB_VHT) { - ie = wpa_scan_get_ie(res, WLAN_EID_HT_CAP); + ie = get_ie(ies, ies_len, WLAN_EID_HT_CAP); if (ie) { tmp = max_ht20_rate(snr); if (tmp > est) @@ -2296,7 +2289,7 @@ void scan_est_throughput(struct wpa_supplicant *wpa_s, } if (capab == CAPAB_HT40 || capab == CAPAB_VHT) { - ie = wpa_scan_get_ie(res, WLAN_EID_HT_OPERATION); + ie = get_ie(ies, ies_len, WLAN_EID_HT_OPERATION); if (ie && ie[1] >= 2 && (ie[3] & HT_INFO_HT_PARAM_SECONDARY_CHNL_OFF_MASK)) { tmp = max_ht40_rate(snr); @@ -2307,13 +2300,13 @@ void scan_est_throughput(struct wpa_supplicant *wpa_s, if (capab == CAPAB_VHT) { /* Use +1 to assume VHT is always faster than HT */ - ie = wpa_scan_get_ie(res, WLAN_EID_VHT_CAP); + ie = get_ie(ies, ies_len, WLAN_EID_VHT_CAP); if (ie) { tmp = max_ht20_rate(snr) + 1; if (tmp > est) est = tmp; - ie = wpa_scan_get_ie(res, WLAN_EID_HT_OPERATION); + ie = get_ie(ies, ies_len, WLAN_EID_HT_OPERATION); if (ie && ie[1] >= 2 && (ie[3] & HT_INFO_HT_PARAM_SECONDARY_CHNL_OFF_MASK)) { @@ -2322,7 +2315,7 @@ void scan_est_throughput(struct wpa_supplicant *wpa_s, est = tmp; } - ie = wpa_scan_get_ie(res, WLAN_EID_VHT_OPERATION); + ie = get_ie(ies, ies_len, WLAN_EID_VHT_OPERATION); if (ie && ie[1] >= 1 && (ie[2] & VHT_OPMODE_CHANNEL_WIDTH_MASK)) { tmp = max_vht80_rate(snr) + 1; @@ -2332,9 +2325,30 @@ void scan_est_throughput(struct wpa_supplicant *wpa_s, } } - /* TODO: channel utilization and AP load (e.g., from AP Beacon) */ + return est; +} + + +void scan_est_throughput(struct wpa_supplicant *wpa_s, + struct wpa_scan_res *res) +{ + int rate; /* max legacy rate in 500 kb/s units */ + int snr = res->snr; + const u8 *ies = (const void *) (res + 1); + size_t ie_len = res->ie_len; + + if (res->est_throughput) + return; + + /* Get maximum legacy rate */ + rate = wpa_scan_get_max_rate(res); - res->est_throughput = est; + if (!ie_len) + ie_len = res->beacon_ie_len; + res->est_throughput = + wpas_get_est_tpt(wpa_s, ies, res->ie_len, rate, snr); + + /* TODO: channel utilization and AP load (e.g., from AP Beacon) */ } diff --git a/wpa_supplicant/scan.h b/wpa_supplicant/scan.h index 5ad1ce9f1..c9ce2cecf 100644 --- a/wpa_supplicant/scan.h +++ b/wpa_supplicant/scan.h @@ -82,6 +82,9 @@ void filter_scan_res(struct wpa_supplicant *wpa_s, void scan_snr(struct wpa_scan_res *res); void scan_est_throughput(struct wpa_supplicant *wpa_s, struct wpa_scan_res *res); +unsigned int wpas_get_est_tpt(const struct wpa_supplicant *wpa_s, + const u8 *ies, size_t ies_len, int rate, + int snr); void wpa_supplicant_set_default_scan_ies(struct wpa_supplicant *wpa_s); #endif /* SCAN_H */ -- 2.39.2