From 3b17c379c5f15ce9691bf062c06b9b608e233fc7 Mon Sep 17 00:00:00 2001 From: Jeff Johnson Date: Tue, 9 Jan 2018 10:26:11 -0800 Subject: [PATCH] qcacmn: Introduce wlan_is_ie_valid() In change "qcacld-3.0: Validate Scan Default IEs" in the qcacld-3.0 project (Change-Id: Ifd8739c96a9990f01ff159eb59a7e904f7b8c592) the utility API hdd_is_ie_valid() was introduced. One review comment was that this should be a converged API, so rename and relocate the API. Change-Id: I8d2a520ea70645ab54b450de83452c0035653485 CRs-Fixed: 2169420 --- umac/cmn_services/utils/inc/wlan_utility.h | 15 +++++++++++++++ umac/cmn_services/utils/src/wlan_utility.c | 21 +++++++++++++++++++++ 2 files changed, 36 insertions(+) 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,