]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
Move throughput estimation into a helper function
authorEmmanuel Grumbach <emmanuel.grumbach@intel.com>
Fri, 6 Dec 2019 22:27:47 +0000 (14:27 -0800)
committerJouni Malinen <j@w1.fi>
Mon, 30 Dec 2019 22:17:04 +0000 (00:17 +0200)
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 <emmanuel.grumbach@intel.com>
wpa_supplicant/scan.c
wpa_supplicant/scan.h

index fea410250a6273bd475e2d12fb3d4cfdc309edbc..205653a67b631caeee2da1c97f0c317d96fb70c2 100644 (file)
@@ -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) */
 }
 
 
index 5ad1ce9f1b305ddaaee458b5e6486955b82409af..c9ce2cecf8aeaacb8cb27409c8228504b062d16c 100644 (file)
@@ -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 */