]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
Refactor wpa_supplicant_need_to_roam()
authorMatthew Wang <matthewmwang@chromium.org>
Tue, 2 Jun 2020 00:10:15 +0000 (17:10 -0700)
committerJouni Malinen <j@w1.fi>
Fri, 19 Jun 2020 15:30:08 +0000 (18:30 +0300)
Pull all the within-ESS roam code out of wpa_supplicant_need_to_roam()
and into its own function, wpa_supplicant_need_to_roam_within_ess().
This way, we avoid interleaving several #ifndef's in the original
function and wrap the new function in one big #ifndef. This also
modularizes the within-ESS roam code and makes it easier to test.

Signed-off-by: Matthew Wang <matthewmwang@chromium.org>
wpa_supplicant/events.c
wpa_supplicant/wpa_supplicant_i.h

index b93c62c8e05b4c0a02f9777c7ea2967683c7cb36..e3cf853931b244db3f2167169a9da22ba8a4a240 100644 (file)
@@ -1855,52 +1855,18 @@ wpas_get_est_throughput_from_bss_snr(const struct wpa_supplicant *wpa_s,
        return wpas_get_est_tpt(wpa_s, ies, ie_len, rate, snr);
 }
 
-#endif /* CONFIG_NO_ROAMING */
-
 
-static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
-                                      struct wpa_bss *selected,
-                                      struct wpa_ssid *ssid)
+int wpa_supplicant_need_to_roam_within_ess(struct wpa_supplicant *wpa_s,
+                                          struct wpa_bss *current_bss,
+                                          struct wpa_bss *selected)
 {
-       struct wpa_bss *current_bss = NULL;
-#ifndef CONFIG_NO_ROAMING
        int min_diff, diff;
        int to_5ghz;
        int cur_level;
        unsigned int cur_est, sel_est;
        struct wpa_signal_info si;
        int cur_snr = 0;
-#endif /* CONFIG_NO_ROAMING */
-
-       if (wpa_s->reassociate)
-               return 1; /* explicit request to reassociate */
-       if (wpa_s->wpa_state < WPA_ASSOCIATED)
-               return 1; /* we are not associated; continue */
-       if (wpa_s->current_ssid == NULL)
-               return 1; /* unknown current SSID */
-       if (wpa_s->current_ssid != ssid)
-               return 1; /* different network block */
-
-       if (wpas_driver_bss_selection(wpa_s))
-               return 0; /* Driver-based roaming */
 
-       if (wpa_s->current_ssid->ssid)
-               current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
-                                         wpa_s->current_ssid->ssid,
-                                         wpa_s->current_ssid->ssid_len);
-       if (!current_bss)
-               current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
-
-       if (!current_bss)
-               return 1; /* current BSS not seen in scan results */
-
-       if (current_bss == selected)
-               return 0;
-
-       if (selected->last_update_idx > current_bss->last_update_idx)
-               return 1; /* current BSS not seen in the last scan */
-
-#ifndef CONFIG_NO_ROAMING
        wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
        wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR
                " freq=%d level=%d snr=%d est_throughput=%u",
@@ -2026,6 +1992,48 @@ static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
                "Allow reassociation due to difference in signal level (%d >= %d)",
                diff, min_diff);
        return 1;
+}
+
+#endif /* CONFIG_NO_ROAMING */
+
+
+static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
+                                      struct wpa_bss *selected,
+                                      struct wpa_ssid *ssid)
+{
+       struct wpa_bss *current_bss = NULL;
+
+       if (wpa_s->reassociate)
+               return 1; /* explicit request to reassociate */
+       if (wpa_s->wpa_state < WPA_ASSOCIATED)
+               return 1; /* we are not associated; continue */
+       if (wpa_s->current_ssid == NULL)
+               return 1; /* unknown current SSID */
+       if (wpa_s->current_ssid != ssid)
+               return 1; /* different network block */
+
+       if (wpas_driver_bss_selection(wpa_s))
+               return 0; /* Driver-based roaming */
+
+       if (wpa_s->current_ssid->ssid)
+               current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
+                                         wpa_s->current_ssid->ssid,
+                                         wpa_s->current_ssid->ssid_len);
+       if (!current_bss)
+               current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
+
+       if (!current_bss)
+               return 1; /* current BSS not seen in scan results */
+
+       if (current_bss == selected)
+               return 0;
+
+       if (selected->last_update_idx > current_bss->last_update_idx)
+               return 1; /* current BSS not seen in the last scan */
+
+#ifndef CONFIG_NO_ROAMING
+       return wpa_supplicant_need_to_roam_within_ess(wpa_s, current_bss,
+                                                     selected);
 #else /* CONFIG_NO_ROAMING */
        return 0;
 #endif /* CONFIG_NO_ROAMING */
index 28867f04ec23e8ff364837a79378fca605390a71..341d84156e5fec1ac3be6f6b5d936953daf99b3c 100644 (file)
@@ -1523,6 +1523,9 @@ struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
 int wpas_temp_disabled(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid);
 void wpa_supplicant_update_channel_list(struct wpa_supplicant *wpa_s,
                                        struct channel_list_changed *info);
+int wpa_supplicant_need_to_roam_within_ess(struct wpa_supplicant *wpa_s,
+                                          struct wpa_bss *current_bss,
+                                          struct wpa_bss *seleceted);
 
 /* eap_register.c */
 int eap_register_methods(void);