common: Use for_each_element_id() in ieee802_11_vendor_ie_concat()

Simple cleanup using the new iteration helper macro.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
This commit is contained in:
Johannes Berg 2019-02-08 17:57:50 +01:00 committed by Jouni Malinen
parent eb84238df6
commit 9008048f0f

View file

@ -560,24 +560,17 @@ struct wpabuf * ieee802_11_vendor_ie_concat(const u8 *ies, size_t ies_len,
u32 oui_type) u32 oui_type)
{ {
struct wpabuf *buf; struct wpabuf *buf;
const u8 *end, *pos, *ie; const struct element *elem, *found = NULL;
pos = ies; for_each_element_id(elem, WLAN_EID_VENDOR_SPECIFIC, ies, ies_len) {
end = ies + ies_len; if (elem->datalen >= 4 &&
ie = NULL; WPA_GET_BE32(elem->data) == oui_type) {
found = elem;
while (end - pos > 1) {
if (2 + pos[1] > end - pos)
return NULL;
if (pos[0] == WLAN_EID_VENDOR_SPECIFIC && pos[1] >= 4 &&
WPA_GET_BE32(&pos[2]) == oui_type) {
ie = pos;
break; break;
} }
pos += 2 + pos[1];
} }
if (ie == NULL) if (!found)
return NULL; /* No specified vendor IE found */ return NULL; /* No specified vendor IE found */
buf = wpabuf_alloc(ies_len); buf = wpabuf_alloc(ies_len);
@ -588,13 +581,9 @@ struct wpabuf * ieee802_11_vendor_ie_concat(const u8 *ies, size_t ies_len,
* There may be multiple vendor IEs in the message, so need to * There may be multiple vendor IEs in the message, so need to
* concatenate their data fields. * concatenate their data fields.
*/ */
while (end - pos > 1) { for_each_element_id(elem, WLAN_EID_VENDOR_SPECIFIC, ies, ies_len) {
if (2 + pos[1] > end - pos) if (elem->datalen >= 4 && WPA_GET_BE32(elem->data) == oui_type)
break; wpabuf_put_data(buf, elem->data + 4, elem->datalen - 4);
if (pos[0] == WLAN_EID_VENDOR_SPECIFIC && pos[1] >= 4 &&
WPA_GET_BE32(&pos[2]) == oui_type)
wpabuf_put_data(buf, pos + 6, pos[1] - 4);
pos += 2 + pos[1];
} }
return buf; return buf;