diff --git a/umac/cmn_services/utils/inc/wlan_utility.h b/umac/cmn_services/utils/inc/wlan_utility.h index 68ce960a0b6b..8acc72cd0bba 100644 --- a/umac/cmn_services/utils/inc/wlan_utility.h +++ b/umac/cmn_services/utils/inc/wlan_utility.h @@ -62,6 +62,21 @@ bool wlan_is_dsrc_channel(uint16_t center_freq); */ uint8_t wlan_freq_to_chan(uint32_t freq); +/** + * wlan_is_ie_valid() - Determine if an IE sequence is valid + * @ie: Pointer to the IE buffer + * @ie_len: Length of the IE buffer @ie + * + * This function validates that the IE sequence is valid by verifying + * that the sum of the lengths of the embedded elements match the + * length of the sequence. + * + * Note well that a 0-length IE sequence is considered valid. + * + * Return: true if the IE sequence is valid, false if it is invalid + */ +bool wlan_is_ie_valid(const uint8_t *ie, size_t ie_len); + /** * wlan_get_ie_ptr_from_eid() - Find out ie from eid * @eid: element id diff --git a/umac/cmn_services/utils/src/wlan_utility.c b/umac/cmn_services/utils/src/wlan_utility.c index 15a9e66b60cc..5875db6750e8 100644 --- a/umac/cmn_services/utils/src/wlan_utility.c +++ b/umac/cmn_services/utils/src/wlan_utility.c @@ -72,6 +72,27 @@ uint8_t wlan_freq_to_chan(uint32_t freq) return chan; } +bool wlan_is_ie_valid(const uint8_t *ie, size_t ie_len) +{ + uint8_t elen; + + while (ie_len) { + if (ie_len < 2) + return false; + + elen = ie[1]; + ie_len -= 2; + ie += 2; + if (elen > ie_len) + return false; + + ie_len -= elen; + ie += elen; + } + + return true; +} + static const uint8_t *wlan_get_ie_ptr_from_eid_n_oui(uint8_t eid, const uint8_t *oui, uint8_t oui_size,