qcacmn: Add APIs to get IE by EID and Ext ID

Add wlan utility APIs to get IE pointer from within IE buffer by
EID or Ext ID.

Change-Id: I26492078cec73b5877f3fc346a91223a045f31aa
CRs-Fixed: 2103529
diff --git a/umac/cmn_services/inc/wlan_cmn.h b/umac/cmn_services/inc/wlan_cmn.h
index 9a37679..ca690a8 100644
--- a/umac/cmn_services/inc/wlan_cmn.h
+++ b/umac/cmn_services/inc/wlan_cmn.h
@@ -91,6 +91,7 @@
 #define WLAN_CHAN_170_FREQ      (5852)
 
 #define WLAN_MAC_EID_VENDOR     221
+#define WLAN_MAC_EID_EXT        255
 
 /**
  * enum wlan_umac_comp_id - UMAC component id
diff --git a/umac/cmn_services/utils/inc/wlan_utility.h b/umac/cmn_services/utils/inc/wlan_utility.h
index c604ee5..35e32ee 100644
--- a/umac/cmn_services/utils/inc/wlan_utility.h
+++ b/umac/cmn_services/utils/inc/wlan_utility.h
@@ -63,6 +63,19 @@
 uint8_t wlan_freq_to_chan(uint32_t freq);
 
 /**
+ * wlan_get_ie_ptr_from_eid() - Find out ie from eid
+ * @eid: element id
+ * @ie: source ie address
+ * @ie_len: source ie length
+ *
+ * Return: vendor ie address - success
+ *         NULL - failure
+ */
+const uint8_t *wlan_get_ie_ptr_from_eid(uint8_t eid,
+					const uint8_t *ie,
+					int ie_len);
+
+/**
  * wlan_get_vendor_ie_ptr_from_oui() - Find out vendor ie
  * @oui: oui buffer
  * @oui_size: oui size
@@ -74,8 +87,27 @@
  * Return: vendor ie address - success
  *         NULL - failure
  */
-uint8_t *wlan_get_vendor_ie_ptr_from_oui(uint8_t *oui,
-	uint8_t oui_size, uint8_t *ie, uint16_t ie_len);
+const uint8_t *wlan_get_vendor_ie_ptr_from_oui(const uint8_t *oui,
+					       uint8_t oui_size,
+					       const uint8_t *ie,
+					       uint16_t ie_len);
+
+/**
+ * wlan_get_ext_ie_ptr_from_ext_id() - Find out ext ie
+ * @oui: oui buffer
+ * @oui_size: oui size
+ * @ie: source ie address
+ * @ie_len: source ie length
+ *
+ * This function find out ext ie from ext id (passed oui)
+ *
+ * Return: vendor ie address - success
+ *         NULL - failure
+ */
+const uint8_t *wlan_get_ext_ie_ptr_from_ext_id(const uint8_t *oui,
+					       uint8_t oui_size,
+					       const uint8_t *ie,
+					       uint16_t ie_len);
 
 /**
  * wlan_is_emulation_platform() - check if platform is emulation based
diff --git a/umac/cmn_services/utils/src/wlan_utility.c b/umac/cmn_services/utils/src/wlan_utility.c
index a2a17f7..7a76d46 100644
--- a/umac/cmn_services/utils/src/wlan_utility.c
+++ b/umac/cmn_services/utils/src/wlan_utility.c
@@ -72,21 +72,37 @@
 	return chan;
 }
 
-uint8_t *wlan_get_vendor_ie_ptr_from_oui(uint8_t *oui,
-	uint8_t oui_size, uint8_t *ie, uint16_t ie_len)
+static const uint8_t *wlan_get_ie_ptr_from_eid_n_oui(uint8_t eid,
+						     const uint8_t *oui,
+						     uint8_t oui_size,
+						     const uint8_t *ie,
+						     uint16_t ie_len)
 {
 	int32_t left = ie_len;
-	uint8_t *ptr = ie;
+	const uint8_t *ptr = ie;
 	uint8_t elem_id, elem_len;
 
 	while (left >= 2) {
 		elem_id  = ptr[0];
 		elem_len = ptr[1];
 		left -= 2;
+
 		if (elem_len > left)
 			return NULL;
-		if (WLAN_MAC_EID_VENDOR == elem_id) {
-			if (memcmp(&ptr[2], oui, oui_size) == 0)
+
+		if (eid == elem_id) {
+			/* if oui is not provide eid match is enough */
+			if (!oui)
+				return ptr;
+
+			/*
+			 * if oui is provided and oui_size is more than left
+			 * bytes, then we cannot have match
+			 */
+			if (oui_size > left)
+				return NULL;
+
+			if (qdf_mem_cmp(&ptr[2], oui, oui_size) == 0)
 				return ptr;
 		}
 
@@ -97,6 +113,31 @@
 	return NULL;
 }
 
+const uint8_t *wlan_get_ie_ptr_from_eid(uint8_t eid,
+					const uint8_t *ie,
+					int ie_len)
+{
+	return wlan_get_ie_ptr_from_eid_n_oui(eid, NULL, 0, ie, ie_len);
+}
+
+const uint8_t *wlan_get_vendor_ie_ptr_from_oui(const uint8_t *oui,
+					       uint8_t oui_size,
+					       const uint8_t *ie,
+					       uint16_t ie_len)
+{
+	return wlan_get_ie_ptr_from_eid_n_oui(WLAN_MAC_EID_VENDOR,
+					      oui, oui_size, ie, ie_len);
+}
+
+const uint8_t *wlan_get_ext_ie_ptr_from_ext_id(const uint8_t *oui,
+					       uint8_t oui_size,
+					       const uint8_t *ie,
+					       uint16_t ie_len)
+{
+	return wlan_get_ie_ptr_from_eid_n_oui(WLAN_MAC_EID_EXT,
+					      oui, oui_size, ie, ie_len);
+}
+
 bool wlan_is_emulation_platform(uint32_t phy_version)
 {
 	if ((phy_version == 0xABC0) || (phy_version == 0xABC1) ||