aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohannes Berg <johannes.berg@intel.com>2019-02-08 16:57:52 (GMT)
committerJouni Malinen <j@w1.fi>2019-02-11 11:37:22 (GMT)
commitb50a638965528066d75562bf918255b74a800fb4 (patch)
treee80d26c3a4692af9fba6f716f33b7e69f49d455a
parentb64479742953ad7227f1b691c27a0288528f9503 (diff)
downloadhostap-b50a638965528066d75562bf918255b74a800fb4.zip
hostap-b50a638965528066d75562bf918255b74a800fb4.tar.gz
hostap-b50a638965528066d75562bf918255b74a800fb4.tar.bz2
common: Use for_each_element_id/_extid for get_ie/get_ie_ext/get_vendor_ie
Simplifications based on the new iteration macros. Signed-off-by: Johannes Berg <johannes.berg@intel.com>
-rw-r--r--src/common/ieee802_11_common.c45
1 files changed, 11 insertions, 34 deletions
diff --git a/src/common/ieee802_11_common.c b/src/common/ieee802_11_common.c
index 79aa66a..56151b3 100644
--- a/src/common/ieee802_11_common.c
+++ b/src/common/ieee802_11_common.c
@@ -1465,22 +1465,13 @@ size_t global_op_class_size = ARRAY_SIZE(global_op_class);
*/
const u8 * get_ie(const u8 *ies, size_t len, u8 eid)
{
- const u8 *end;
+ const struct element *elem;
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];
- }
+ for_each_element_id(elem, eid, ies, len)
+ return &elem->id;
return NULL;
}
@@ -1498,23 +1489,13 @@ const u8 * get_ie(const u8 *ies, size_t len, u8 eid)
*/
const u8 * get_ie_ext(const u8 *ies, size_t len, u8 ext)
{
- const u8 *end;
+ const struct element *elem;
if (!ies)
return NULL;
- end = ies + len;
-
- while (end - ies > 1) {
- if (2 + ies[1] > end - ies)
- break;
-
- if (ies[0] == WLAN_EID_EXTENSION && ies[1] >= 1 &&
- ies[2] == ext)
- return ies;
-
- ies += 2 + ies[1];
- }
+ for_each_element_extid(elem, ext, ies, len)
+ return &elem->id;
return NULL;
}
@@ -1522,16 +1503,12 @@ const u8 * get_ie_ext(const u8 *ies, size_t len, u8 ext)
const u8 * get_vendor_ie(const u8 *ies, size_t len, u32 vendor_type)
{
- const u8 *pos = ies, *end = ies + len;
-
- while (end - pos > 1) {
- if (2 + pos[1] > end - pos)
- break;
+ const struct element *elem;
- if (pos[0] == WLAN_EID_VENDOR_SPECIFIC && pos[1] >= 4 &&
- vendor_type == WPA_GET_BE32(&pos[2]))
- return pos;
- pos += 2 + pos[1];
+ for_each_element_id(elem, WLAN_EID_VENDOR_SPECIFIC, ies, len) {
+ if (elem->datalen >= 4 &&
+ vendor_type == WPA_GET_BE32(elem->data))
+ return &elem->id;
}
return NULL;