]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
utils: Share a single helper function to get IE by ID
authorAvraham Stern <avraham.stern@intel.com>
Mon, 15 Feb 2016 14:53:17 +0000 (16:53 +0200)
committerJouni Malinen <j@w1.fi>
Sun, 21 Feb 2016 15:14:56 +0000 (17:14 +0200)
Add a helper function to find a certain IE inside IEs buffer by ID and
use this function in several places that implemented similar
functionality locally.

Signed-off-by: Avraham Stern <avraham.stern@intel.com>
src/common/ieee802_11_common.c
src/common/ieee802_11_common.h
src/drivers/driver_nl80211.h
src/drivers/driver_nl80211_event.c
src/drivers/driver_nl80211_scan.c
wpa_supplicant/bss.c
wpa_supplicant/scan.c

index 8dee8830594193b32c71cc8059d5fb34652e4457..9af2606913f3489741f6d0ec87225e0076dd0d58 100644 (file)
@@ -1172,3 +1172,36 @@ struct wpabuf * mb_ies_by_info(struct mb_ies_info *info)
 
        return mb_ies;
 }
+
+
+/**
+ * get_ie - Fetch a specified information element from IEs buffer
+ * @ies: Information elements buffer
+ * @len: Information elements buffer length
+ * @eid: Information element identifier (WLAN_EID_*)
+ * Returns: Pointer to the information element (id field) or %NULL if not found
+ *
+ * This function returns the first matching information element in the IEs
+ * buffer or %NULL in case the element is not found.
+ */
+const u8 * get_ie(const u8 *ies, size_t len, u8 eid)
+{
+       const u8 *end;
+
+       if (!ies)
+               return NULL;
+
+       end = ies + len;
+
+       while (end - ies > 1) {
+               if (2 + ies[1] > end - ies)
+                       break;
+
+               if (ies[0] == eid)
+                       return ies;
+
+               ies += 2 + ies[1];
+       }
+
+       return NULL;
+}
index 55ce0223d923530f4b35b5294688e62bc27c0fad..f1ee30204cdd94bd2721ed8aebd866ca62392e02 100644 (file)
@@ -125,4 +125,7 @@ int mb_ies_info_by_ies(struct mb_ies_info *info, const u8 *ies_buf,
 struct wpabuf * mb_ies_by_info(struct mb_ies_info *info);
 
 const char * fc2str(u16 fc);
+
+const u8 * get_ie(const u8 *ies, size_t len, u8 eid);
+
 #endif /* IEEE802_11_COMMON_H */
index 09e03b3dda3583dc534493637e8f047f035019c3..4fa7d5f82bd31595790f8d3c9d577770620e32c7 100644 (file)
@@ -285,7 +285,6 @@ int wpa_driver_nl80211_stop_sched_scan(void *priv);
 struct wpa_scan_results * wpa_driver_nl80211_get_scan_results(void *priv);
 void nl80211_dump_scan(struct wpa_driver_nl80211_data *drv);
 int wpa_driver_nl80211_abort_scan(void *priv);
-const u8 * nl80211_get_ie(const u8 *ies, size_t ies_len, u8 ie);
 int wpa_driver_nl80211_vendor_scan(struct i802_bss *bss,
                                   struct wpa_driver_scan_params *params);
 
index 2b2086c37c25d1b4e9f03a17be150d7ecf5d111d..98a2744597dc47407583a5f95d2f58f5a60ddcab 100644 (file)
@@ -335,9 +335,9 @@ static void mlme_event_connect(struct wpa_driver_nl80211_data *drv,
                event.assoc_info.req_ies_len = nla_len(req_ie);
 
                if (cmd == NL80211_CMD_ROAM) {
-                       ssid = nl80211_get_ie(event.assoc_info.req_ies,
-                                             event.assoc_info.req_ies_len,
-                                             WLAN_EID_SSID);
+                       ssid = get_ie(event.assoc_info.req_ies,
+                                     event.assoc_info.req_ies_len,
+                                     WLAN_EID_SSID);
                        if (ssid && ssid[1] > 0 && ssid[1] <= 32) {
                                drv->ssid_len = ssid[1];
                                os_memcpy(drv->ssid, ssid + 2, ssid[1]);
index 2ff254e43ec1db5c666d477169c941f1ffb76c26..2145022914c418caa692ec03fb43495faddb7460 100644 (file)
@@ -15,6 +15,7 @@
 #include "utils/common.h"
 #include "utils/eloop.h"
 #include "common/ieee802_11_defs.h"
+#include "common/ieee802_11_common.h"
 #include "common/qca-vendor.h"
 #include "driver_nl80211.h"
 
@@ -522,28 +523,6 @@ int wpa_driver_nl80211_stop_sched_scan(void *priv)
 }
 
 
-const u8 * nl80211_get_ie(const u8 *ies, size_t ies_len, u8 ie)
-{
-       const u8 *end, *pos;
-
-       if (ies == NULL)
-               return NULL;
-
-       pos = ies;
-       end = ies + ies_len;
-
-       while (end - pos > 1) {
-               if (2 + pos[1] > end - pos)
-                       break;
-               if (pos[0] == ie)
-                       return pos;
-               pos += 2 + pos[1];
-       }
-
-       return NULL;
-}
-
-
 static int nl80211_scan_filtered(struct wpa_driver_nl80211_data *drv,
                                 const u8 *ie, size_t ie_len)
 {
@@ -553,7 +532,7 @@ static int nl80211_scan_filtered(struct wpa_driver_nl80211_data *drv,
        if (drv->filter_ssids == NULL)
                return 0;
 
-       ssid = nl80211_get_ie(ie, ie_len, WLAN_EID_SSID);
+       ssid = get_ie(ie, ie_len, WLAN_EID_SSID);
        if (ssid == NULL)
                return 1;
 
@@ -714,9 +693,9 @@ int bss_info_handler(struct nl_msg *msg, void *arg)
                if (os_memcmp(res->res[i]->bssid, r->bssid, ETH_ALEN) != 0)
                        continue;
 
-               s1 = nl80211_get_ie((u8 *) (res->res[i] + 1),
-                                   res->res[i]->ie_len, WLAN_EID_SSID);
-               s2 = nl80211_get_ie((u8 *) (r + 1), r->ie_len, WLAN_EID_SSID);
+               s1 = get_ie((u8 *) (res->res[i] + 1),
+                           res->res[i]->ie_len, WLAN_EID_SSID);
+               s2 = get_ie((u8 *) (r + 1), r->ie_len, WLAN_EID_SSID);
                if (s1 == NULL || s2 == NULL || s1[1] != s2[1] ||
                    os_memcmp(s1, s2, 2 + s1[1]) != 0)
                        continue;
index 24cc98682363ddaec1c2e3d5251860370297ed71..a83ca101b954f784cadde51172f6d7f7e7cbc200 100644 (file)
@@ -1019,20 +1019,7 @@ struct wpa_bss * wpa_bss_get_id_range(struct wpa_supplicant *wpa_s,
  */
 const u8 * wpa_bss_get_ie(const struct wpa_bss *bss, u8 ie)
 {
-       const u8 *end, *pos;
-
-       pos = (const u8 *) (bss + 1);
-       end = pos + bss->ie_len;
-
-       while (end - pos > 1) {
-               if (2 + pos[1] > end - pos)
-                       break;
-               if (pos[0] == ie)
-                       return pos;
-               pos += 2 + pos[1];
-       }
-
-       return NULL;
+       return get_ie((const u8 *) (bss + 1), bss->ie_len, ie);
 }
 
 
index f4f2c20c9021efe3997dbe30e920a9c30c276279..30bec2caecbb1d20ebf7e59f2c2f0d1693047c2a 100644 (file)
@@ -1535,20 +1535,7 @@ static int wpa_scan_get_max_rate(const struct wpa_scan_res *res)
  */
 const u8 * wpa_scan_get_ie(const struct wpa_scan_res *res, u8 ie)
 {
-       const u8 *end, *pos;
-
-       pos = (const u8 *) (res + 1);
-       end = pos + res->ie_len;
-
-       while (end - pos > 1) {
-               if (2 + pos[1] > end - pos)
-                       break;
-               if (pos[0] == ie)
-                       return pos;
-               pos += 2 + pos[1];
-       }
-
-       return NULL;
+       return get_ie((const u8 *) (res + 1), res->ie_len, ie);
 }