Use for_each_element() in ieee802_11_parse_elems()
Use the new iteration macro to simplify the impelmentation and make it more consistent with other IE parsers. Signed-off-by: Jouni Malinen <j@w1.fi>
This commit is contained in:
parent
b50a638965
commit
092a19222b
1 changed files with 16 additions and 24 deletions
|
@ -299,29 +299,17 @@ ParseRes ieee802_11_parse_elems(const u8 *start, size_t len,
|
||||||
struct ieee802_11_elems *elems,
|
struct ieee802_11_elems *elems,
|
||||||
int show_errors)
|
int show_errors)
|
||||||
{
|
{
|
||||||
size_t left = len;
|
const struct element *elem;
|
||||||
const u8 *pos = start;
|
|
||||||
int unknown = 0;
|
int unknown = 0;
|
||||||
|
|
||||||
os_memset(elems, 0, sizeof(*elems));
|
os_memset(elems, 0, sizeof(*elems));
|
||||||
|
|
||||||
while (left >= 2) {
|
if (!start)
|
||||||
u8 id, elen;
|
return ParseOK;
|
||||||
|
|
||||||
id = *pos++;
|
for_each_element(elem, start, len) {
|
||||||
elen = *pos++;
|
u8 id = elem->id, elen = elem->datalen;
|
||||||
left -= 2;
|
const u8 *pos = elem->data;
|
||||||
|
|
||||||
if (elen > left) {
|
|
||||||
if (show_errors) {
|
|
||||||
wpa_printf(MSG_DEBUG, "IEEE 802.11 element "
|
|
||||||
"parse failed (id=%d elen=%d "
|
|
||||||
"left=%lu)",
|
|
||||||
id, elen, (unsigned long) left);
|
|
||||||
wpa_hexdump(MSG_MSGDUMP, "IEs", start, len);
|
|
||||||
}
|
|
||||||
return ParseFailed;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (id) {
|
switch (id) {
|
||||||
case WLAN_EID_SSID:
|
case WLAN_EID_SSID:
|
||||||
|
@ -469,8 +457,7 @@ ParseRes ieee802_11_parse_elems(const u8 *start, size_t len,
|
||||||
elems->mic = pos;
|
elems->mic = pos;
|
||||||
elems->mic_len = elen;
|
elems->mic_len = elen;
|
||||||
/* after mic everything is encrypted, so stop. */
|
/* after mic everything is encrypted, so stop. */
|
||||||
left = elen;
|
goto done;
|
||||||
break;
|
|
||||||
case WLAN_EID_MULTI_BAND:
|
case WLAN_EID_MULTI_BAND:
|
||||||
if (elems->mb_ies.nof_ies >= MAX_NOF_MB_IES_SUPPORTED) {
|
if (elems->mb_ies.nof_ies >= MAX_NOF_MB_IES_SUPPORTED) {
|
||||||
wpa_printf(MSG_MSGDUMP,
|
wpa_printf(MSG_MSGDUMP,
|
||||||
|
@ -529,14 +516,19 @@ ParseRes ieee802_11_parse_elems(const u8 *start, size_t len,
|
||||||
id, elen);
|
id, elen);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
left -= elen;
|
|
||||||
pos += elen;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (left)
|
if (!for_each_element_completed(elem, start, len)) {
|
||||||
|
if (show_errors) {
|
||||||
|
wpa_printf(MSG_DEBUG,
|
||||||
|
"IEEE 802.11 element parse failed @%d",
|
||||||
|
(int) (start + len - (const u8 *) elem));
|
||||||
|
wpa_hexdump(MSG_MSGDUMP, "IEs", start, len);
|
||||||
|
}
|
||||||
return ParseFailed;
|
return ParseFailed;
|
||||||
|
}
|
||||||
|
|
||||||
|
done:
|
||||||
return unknown ? ParseUnknown : ParseOK;
|
return unknown ? ParseUnknown : ParseOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue