[PATCH v2 1/5] wpa_supplicant: reduce OWE transition network code duplication
David Bauer
mail at david-bauer.net
Sun Apr 28 06:13:40 PDT 2024
Reduce the code-duplication for methods handling the OWE transition
mode. This is required for adding bgscan support for transition
networks.
Signed-off-by: David Bauer <mail at david-bauer.net>
---
wpa_supplicant/bss.c | 30 ++++++++++++++++++++++++++++++
wpa_supplicant/bss.h | 2 ++
wpa_supplicant/events.c | 21 +++++----------------
wpa_supplicant/scan.c | 20 +++-----------------
wpa_supplicant/wpa_supplicant.c | 17 +++++------------
5 files changed, 45 insertions(+), 45 deletions(-)
diff --git a/wpa_supplicant/bss.c b/wpa_supplicant/bss.c
index 289035310..c213d15ad 100644
--- a/wpa_supplicant/bss.c
+++ b/wpa_supplicant/bss.c
@@ -817,6 +817,36 @@ void wpa_bss_update_start(struct wpa_supplicant *wpa_s)
wpa_s->last_scan_res_used = 0;
}
+int wpa_bss_get_owe_trans_network(struct wpa_supplicant *wpa_s, const u8 *owe_ie,
+ const u8 **bssid, const u8 **ssid, size_t *ssid_len)
+{
+#ifdef CONFIG_OWE
+ const u8 *pos, *end;
+ u8 ssid_len_tmp;
+
+ if (!owe_ie)
+ return 1;
+
+ pos = owe_ie + 6;
+ end = owe_ie + 2 + owe_ie[1];
+
+ if (end - pos < ETH_ALEN + 1)
+ return 1;
+ *bssid = pos;
+ pos += ETH_ALEN;
+ ssid_len_tmp = *pos++;
+ if (end - pos < ssid_len_tmp || ssid_len_tmp > SSID_MAX_LEN)
+ return 1;
+
+ *ssid = pos;
+ *ssid_len = ssid_len_tmp;
+
+ return 0;
+#else /* CONFIG_OWE */
+ return 1;
+#endif /* CONFIG_OWE */
+}
+
/**
* wpa_bss_update_scan_res - Update a BSS table entry based on a scan result
diff --git a/wpa_supplicant/bss.h b/wpa_supplicant/bss.h
index cc0496324..8acedbce7 100644
--- a/wpa_supplicant/bss.h
+++ b/wpa_supplicant/bss.h
@@ -185,6 +185,8 @@ struct wpabuf * wpa_bss_get_vendor_ie_multi_beacon(const struct wpa_bss *bss,
u32 vendor_type);
int wpa_bss_get_max_rate(const struct wpa_bss *bss);
int wpa_bss_get_bit_rates(const struct wpa_bss *bss, u8 **rates);
+int wpa_bss_get_owe_trans_network(struct wpa_supplicant *wpa_s, const u8 *owe_ie,
+ const u8 **bssid, const u8 **ssid, size_t *ssid_len);
struct wpa_bss_anqp * wpa_bss_anqp_alloc(void);
int wpa_bss_anqp_unshare_alloc(struct wpa_bss *bss);
const u8 * wpa_bss_get_fils_cache_id(const struct wpa_bss *bss);
diff --git a/wpa_supplicant/events.c b/wpa_supplicant/events.c
index 8dc618e5c..abeaefff1 100644
--- a/wpa_supplicant/events.c
+++ b/wpa_supplicant/events.c
@@ -1108,30 +1108,19 @@ static void owe_trans_ssid(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
const u8 **ret_ssid, size_t *ret_ssid_len)
{
#ifdef CONFIG_OWE
- const u8 *owe, *pos, *end, *bssid;
- u8 ssid_len;
+ const u8 *owe, *bssid;
owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE);
if (!owe || !wpa_bss_get_ie(bss, WLAN_EID_RSN))
return;
- pos = owe + 6;
- end = owe + 2 + owe[1];
-
- if (end - pos < ETH_ALEN + 1)
- return;
- bssid = pos;
- pos += ETH_ALEN;
- ssid_len = *pos++;
- if (end - pos < ssid_len || ssid_len > SSID_MAX_LEN)
+ if (wpa_bss_get_owe_trans_network(wpa_s, owe, &bssid, ret_ssid, ret_ssid_len))
return;
/* Match the profile SSID against the OWE transition mode SSID on the
* open network. */
wpa_dbg(wpa_s, MSG_DEBUG, "OWE: transition mode BSSID: " MACSTR
- " SSID: %s", MAC2STR(bssid), wpa_ssid_txt(pos, ssid_len));
- *ret_ssid = pos;
- *ret_ssid_len = ssid_len;
+ " SSID: %s", MAC2STR(bssid), wpa_ssid_txt(*ret_ssid, *ret_ssid_len));
if (!(bss->flags & WPA_BSS_OWE_TRANSITION)) {
struct wpa_ssid *ssid;
@@ -1139,8 +1128,8 @@ static void owe_trans_ssid(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
if (wpas_network_disabled(wpa_s, ssid))
continue;
- if (ssid->ssid_len == ssid_len &&
- os_memcmp(ssid->ssid, pos, ssid_len) == 0) {
+ if (ssid->ssid_len == *ret_ssid_len &&
+ os_memcmp(ssid->ssid, ret_ssid, *ret_ssid_len) == 0) {
/* OWE BSS in transition mode for a currently
* enabled OWE network. */
wpa_dbg(wpa_s, MSG_DEBUG,
diff --git a/wpa_supplicant/scan.c b/wpa_supplicant/scan.c
index 8b59e409b..52fe89746 100644
--- a/wpa_supplicant/scan.c
+++ b/wpa_supplicant/scan.c
@@ -954,8 +954,7 @@ static void wpa_add_owe_scan_ssid(struct wpa_supplicant *wpa_s,
wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
- const u8 *owe, *pos, *end;
- const u8 *owe_ssid;
+ const u8 *owe, *owe_bssid, *owe_ssid;
size_t owe_ssid_len;
if (bss->ssid_len != ssid->ssid_len ||
@@ -966,21 +965,8 @@ static void wpa_add_owe_scan_ssid(struct wpa_supplicant *wpa_s,
if (!owe || owe[1] < 4)
continue;
- pos = owe + 6;
- end = owe + 2 + owe[1];
-
- /* Must include BSSID and ssid_len */
- if (end - pos < ETH_ALEN + 1)
- return;
-
- /* Skip BSSID */
- pos += ETH_ALEN;
- owe_ssid_len = *pos++;
- owe_ssid = pos;
-
- if ((size_t) (end - pos) < owe_ssid_len ||
- owe_ssid_len > SSID_MAX_LEN)
- return;
+ if (wpa_bss_get_owe_trans_network(wpa_s, owe, &owe_bssid, &owe_ssid, &owe_ssid_len))
+ continue;
wpa_printf(MSG_DEBUG,
"OWE: scan_ssids: transition mode OWE ssid=%s",
diff --git a/wpa_supplicant/wpa_supplicant.c b/wpa_supplicant/wpa_supplicant.c
index eeb667515..06161a6dc 100644
--- a/wpa_supplicant/wpa_supplicant.c
+++ b/wpa_supplicant/wpa_supplicant.c
@@ -5276,8 +5276,8 @@ int wpa_supplicant_set_debug_params(struct wpa_global *global, int debug_level,
static int owe_trans_ssid_match(struct wpa_supplicant *wpa_s, const u8 *bssid,
const u8 *entry_ssid, size_t entry_ssid_len)
{
- const u8 *owe, *pos, *end;
- u8 ssid_len;
+ const u8 *owe, *owe_bssid, *owe_ssid;
+ size_t owe_ssid_len;
struct wpa_bss *bss;
/* Check network profile SSID aganst the SSID in the
@@ -5291,18 +5291,11 @@ static int owe_trans_ssid_match(struct wpa_supplicant *wpa_s, const u8 *bssid,
if (!owe)
return 0;
- pos = owe + 6;
- end = owe + 2 + owe[1];
-
- if (end - pos < ETH_ALEN + 1)
- return 0;
- pos += ETH_ALEN;
- ssid_len = *pos++;
- if (end - pos < ssid_len || ssid_len > SSID_MAX_LEN)
+ if (wpa_bss_get_owe_trans_network(wpa_s, owe, &owe_bssid, &owe_ssid, &owe_ssid_len))
return 0;
- return entry_ssid_len == ssid_len &&
- os_memcmp(pos, entry_ssid, ssid_len) == 0;
+ return entry_ssid_len == owe_ssid_len &&
+ os_memcmp(owe_ssid, entry_ssid, owe_ssid_len) == 0;
}
#endif /* CONFIG_OWE */
--
2.43.0
More information about the Hostap
mailing list