[PATCH 5/5] common: use for_each_element_id/_extid for get_ie/get_ie_ext/get_vendor_ie

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Johannes Berg <johannes.berg@xxxxxxxxx>

Simplifications based on the new iteration macros.

Signed-off-by: Johannes Berg <johannes.berg@xxxxxxxxx>
---
 src/common/ieee802_11_common.c | 45 +++++++++-------------------------
 1 file changed, 11 insertions(+), 34 deletions(-)

diff --git a/src/common/ieee802_11_common.c b/src/common/ieee802_11_common.c
index 1b80e13aa649..cd0d733ff9de 100644
--- a/src/common/ieee802_11_common.c
+++ b/src/common/ieee802_11_common.c
@@ -1464,22 +1464,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 (void *)elem;
 
 	return NULL;
 }
@@ -1497,23 +1488,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 (void *)elem;
 
 	return NULL;
 }
@@ -1521,16 +1502,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 (void *)elem;
 	}
 
 	return NULL;
-- 
2.17.2


_______________________________________________
Hostap mailing list
Hostap@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/hostap



[Index of Archives]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux