Эх сурвалжийг харах

qcacmn: Add scan database init and deinit changes

Add changes to initialize and de-initialize the scan database.
Also registers callback to TXRX module to handle
beacon and probe resp and convert it to scan entry.

Change-Id: Ic55e4fc6dc1b23bdf50165aea219e112dcad676d
CRs-Fixed: 1095299
Abhishek Singh 8 жил өмнө
parent
commit
4caf1a9af4

+ 164 - 3
umac/scan/core/src/wlan_scan_cache_db.c

@@ -19,17 +19,178 @@
 /*
  * DOC: contains scan cache api and functionality
  */
-#include <wlan_scan_ucfg_api.h>
-#include "wlan_scan_cache_db.h"
-#include <qdf_types.h>
 #include <qdf_status.h>
+#include <wlan_objmgr_psoc_obj.h>
+#include <wlan_objmgr_pdev_obj.h>
+#include <wlan_objmgr_vdev_obj.h>
+#include <wlan_scan_public_structs.h>
+#include <wlan_scan_utils_api.h>
+#include "wlan_scan_main.h"
+#include "wlan_scan_cache_db_i.h"
+
+QDF_STATUS scm_handle_bcn_probe(struct scheduler_msg *msg)
+{
+	struct scan_bcn_probe_event *bcn;
+	struct wlan_objmgr_psoc *psoc;
+	struct wlan_objmgr_pdev *pdev = NULL;
+	struct scan_cache_entry *scan_entry;
+	struct wlan_scan_obj *scan_obj;
+	struct scan_dbs *scan_db;
+	QDF_STATUS status;
+
+	bcn = msg->bodyptr;
+
+	if (!bcn) {
+		scm_err("bcn is NULL");
+		return QDF_STATUS_E_INVAL;
+	}
+	if (!bcn->rx_data) {
+		scm_err("rx_data iS NULL");
+		status = QDF_STATUS_E_INVAL;
+		goto free_nbuf;
+	}
+	if (!bcn->buf) {
+		scm_err("buf is NULL");
+		status = QDF_STATUS_E_INVAL;
+		goto free_nbuf;
+	}
+
+	psoc = bcn->psoc;
+	pdev = wlan_objmgr_get_pdev_by_id(psoc,
+			   bcn->rx_data->pdev_id, WLAN_SCAN_ID);
+	if (!pdev) {
+		scm_err("pdev is NULL");
+		status = QDF_STATUS_E_INVAL;
+		goto free_nbuf;
+	}
+	scan_obj = wlan_psoc_get_scan_obj(psoc);
+	if (!scan_obj) {
+		scm_err("scan_obj is NULL");
+		status = QDF_STATUS_E_INVAL;
+		goto free_nbuf;
+	}
+	scan_db = wlan_pdev_get_scan_db(psoc, pdev);
+	if (!scan_db) {
+		scm_err("scan_db is NULL");
+		status = QDF_STATUS_E_INVAL;
+		goto free_nbuf;
+	}
+
+	if (qdf_nbuf_len(bcn->buf) <=
+	   (sizeof(struct wlan_frame_hdr) +
+	   offsetof(struct wlan_bcn_frame, ie))) {
+		scm_err("invalid beacon/probe length");
+		status = QDF_STATUS_E_INVAL;
+		goto free_nbuf;
+	}
+
+	scan_entry =
+		 util_scan_unpack_beacon_frame(qdf_nbuf_data(bcn->buf),
+			qdf_nbuf_len(bcn->buf), bcn->frm_type,
+			bcn->rx_data);
+	if (!scan_entry) {
+		scm_err("failed to unpack frame");
+		status = QDF_STATUS_E_INVAL;
+		goto free_nbuf;
+	}
+
+	scm_info("Received %s from BSSID: %pM tsf_delta = %u Seq Num: %x ssid:%.*s",
+		(bcn->frm_type == MGMT_SUBTYPE_PROBE_RESP) ?
+		"Probe Rsp" : "Beacon", scan_entry->bssid.bytes,
+		scan_entry->tsf_delta, scan_entry->seq_num,
+		scan_entry->ssid.length, scan_entry->ssid.ssid);
+
+	if (scan_obj->cb.update_beacon)
+		scan_obj->cb.update_beacon(pdev, scan_entry);
+
+	if (scan_obj->cb.inform_beacon)
+		scan_obj->cb.inform_beacon(pdev, scan_entry);
+
+free_nbuf:
+	if (pdev)
+		wlan_objmgr_pdev_release_ref(pdev, WLAN_SCAN_ID);
+	if (bcn->rx_data)
+		qdf_mem_free(bcn->rx_data);
+	if (bcn->buf)
+		qdf_nbuf_free(bcn->buf);
+	qdf_mem_free(bcn);
+
+	return status;
+}
+
+QDF_STATUS scm_scan_register_bcn_cb(struct wlan_objmgr_psoc *psoc,
+	update_beacon_cb cb, enum scan_cb_type type)
+{
+	struct wlan_scan_obj *scan_obj;
+
+	scan_obj = wlan_psoc_get_scan_obj(psoc);
+	if (!scan_obj) {
+		scm_err("scan obj is NULL");
+		return QDF_STATUS_E_INVAL;
+	}
+	switch (type) {
+	case SCAN_CB_TYPE_INFORM_BCN:
+		scan_obj->cb.inform_beacon = cb;
+		break;
+	case SCAN_CB_TYPE_UPDATE_BCN:
+		scan_obj->cb.update_beacon = cb;
+		break;
+	default:
+		scm_err("invalid cb type %d", type);
+	}
+
+	return QDF_STATUS_SUCCESS;
+}
 
 QDF_STATUS scm_db_init(struct wlan_objmgr_psoc *psoc)
 {
+	int i, j;
+	struct scan_dbs *scan_db;
+
+	if (!psoc) {
+		scm_err("psoc is NULL");
+		return QDF_STATUS_E_INVAL;
+	}
+
+	/* Initialize the scan database per pdev */
+	for (i = 0; i < WLAN_UMAC_MAX_PDEVS; i++) {
+		scan_db = wlan_pdevid_get_scan_db(psoc, i);
+		if (!scan_db) {
+			scm_err("scan_db is NULL %d", i);
+			continue;
+		}
+		scan_db->num_entries = 0;
+		qdf_spinlock_create(&scan_db->scan_db_lock);
+		for (j = 0; j < SCAN_HASH_SIZE; j++)
+			qdf_list_create(&scan_db->scan_hash_tbl[j],
+				MAX_SCAN_CACHE_SIZE);
+	}
+
 	return QDF_STATUS_SUCCESS;
 }
 
 QDF_STATUS scm_db_deinit(struct wlan_objmgr_psoc *psoc)
 {
+	int i, j;
+	struct scan_dbs *scan_db;
+
+	if (!psoc) {
+		scm_err("scan obj is NULL");
+		return QDF_STATUS_E_INVAL;
+	}
+
+	/* Initialize the scan database per pdev */
+	for (i = 0; i < WLAN_UMAC_MAX_PDEVS; i++) {
+		scan_db = wlan_pdevid_get_scan_db(psoc, i);
+		if (!scan_db) {
+			scm_err("scan_db is NULL %d", i);
+			continue;
+		}
+
+		for (j = 0; j < SCAN_HASH_SIZE; j++)
+			qdf_list_destroy(&scan_db->scan_hash_tbl[j]);
+		qdf_spinlock_destroy(&scan_db->scan_db_lock);
+	}
+
 	return QDF_STATUS_SUCCESS;
 }

+ 6 - 7
umac/scan/core/src/wlan_scan_cache_db.h

@@ -24,6 +24,9 @@
 #define _WLAN_SCAN_CACHE_DB_H_
 
 #include <scheduler_api.h>
+#include <wlan_objmgr_psoc_obj.h>
+#include <wlan_objmgr_pdev_obj.h>
+#include <wlan_objmgr_vdev_obj.h>
 #include <wlan_scan_public_structs.h>
 
 #define SCAN_HASH_SIZE 64
@@ -69,16 +72,12 @@ struct scan_bcn_probe_event {
 QDF_STATUS scm_handle_bcn_probe(struct scheduler_msg *msg);
 
 /**
- * scm_flush_scan_entry() - API to flush the scan entry
+ * scm_age_out_entries() - Age out entries older than aging time
  * @scan_db: scan database
- * @scan_entry:entry scan_node
  *
- * API to flush the scan entry
- *
- * Return: QDF status.
+ * Return: void.
  */
-QDF_STATUS scm_flush_scan_entry(struct scan_dbs *scan_db,
-	struct scan_cache_node *scan_node);
+void scm_age_out_entries(struct scan_dbs *scan_db);
 
 /**
  * scm_get_scan_result() - fetches scan result

+ 25 - 1
umac/scan/dispatcher/inc/wlan_scan_public_structs.h

@@ -179,10 +179,12 @@ struct bss_info {
 /**
  * struct scan_cache_node - Scan cache entry node
  * @node: node pointers
+ * @ref_cnt: ref count if in use
  * @entry: scan entry pointer
  */
 struct scan_cache_node {
-	qdf_list_node_t node;   /* MUST be first element */
+	qdf_list_node_t node;
+	qdf_atomic_t ref_cnt;
 	struct scan_cache_entry *entry;
 };
 
@@ -788,4 +790,26 @@ enum scan_cb_type {
  * struct pno_scan_req_params - forward declaration
  */
 struct pno_scan_req_params;
+
+/**
+ * update_beacon_cb() - cb to inform/update beacon
+ * @psoc: psoc pointer
+ * @scan_params:  scan entry to inform/update
+ *
+ * @Return: void
+ */
+typedef void (*update_beacon_cb) (struct wlan_objmgr_pdev *pdev,
+	struct scan_cache_entry *scan_entry);
+
+/**
+ * scan_iterator_func() - function prototype of scan iterator function
+ * @scan_entry: scan entry object
+ * @arg: extra argument
+ *
+ * PROTO TYPE, scan iterator function prototype
+ *
+ * @Return: QDF_STATUS
+ */
+typedef QDF_STATUS (*scan_iterator_func) (void *arg,
+	struct scan_cache_entry *scan_entry);
 #endif

+ 2 - 1
umac/scan/dispatcher/inc/wlan_scan_tgt_api.h

@@ -45,7 +45,8 @@
  */
 QDF_STATUS tgt_scan_bcn_probe_rx_callback(struct wlan_objmgr_psoc *psoc,
 	struct wlan_objmgr_peer *peer, qdf_nbuf_t buf,
-	struct mgmt_rx_event_params *rx_param, uint32_t frm_type);
+	struct mgmt_rx_event_params *rx_param,
+	enum mgmt_frame_type frm_type);
 
 /**
  * tgt_scan_nlo_complete_evt_handler() - The callbeack registered

+ 0 - 22
umac/scan/dispatcher/inc/wlan_scan_ucfg_api.h

@@ -160,18 +160,6 @@ QDF_STATUS ucfg_scan_flush_results(struct wlan_objmgr_pdev *pdev,
 void ucfg_scan_filter_valid_channel(struct wlan_objmgr_pdev *pdev,
 	uint8_t *chan_list, uint32_t num_chan);
 
-/**
- * scan_iterator_func() - function prototype of scan iterator function
- * @scan_entry: scan entry object
- * @arg: extra argument
- *
- * PROTO TYPE, scan iterator function prototype
- *
- * @Return: QDF_STATUS
- */
-typedef QDF_STATUS (*scan_iterator_func) (void *arg,
-	struct scan_cache_entry *scan_entry);
-
 /**
  * ucfg_scan_db_iterate() - function to iterate scan table
  * @pdev: pdev object
@@ -305,16 +293,6 @@ ucfg_scan_get_vdev_status(struct wlan_objmgr_vdev *vdev);
 enum scm_scan_status
 ucfg_scan_get_pdev_status(struct wlan_objmgr_pdev *pdev);
 
-/**
- * update_beacon_cb() - cb to inform/update beacon
- * @psoc: psoc pointer
- * @scan_params:  scan entry to inform/update
- *
- * @Return: void
- */
-typedef void (*update_beacon_cb) (struct wlan_objmgr_pdev *pdev,
-	struct scan_cache_entry *scan_entry);
-
 /**
  * ucfg_scan_register_bcn_cb() - API to register api
  * to inform/update bcn/probe as soon as they are received

+ 57 - 0
umac/scan/dispatcher/src/wlan_scan_tgt_api.c

@@ -20,6 +20,10 @@
  * DOC: contains scan south bound interface definitions
  */
 
+#include <wlan_cmn.h>
+#include <qdf_list.h>
+#include "../../core/src/wlan_scan_main.h"
+#include <wlan_scan_utils_api.h>
 #include <wlan_scan_ucfg_api.h>
 #include <wlan_scan_tgt_api.h>
 #include <wlan_objmgr_cmn.h>
@@ -175,3 +179,56 @@ tgt_scan_event_handler(struct wlan_objmgr_psoc *psoc,
 
 	return scheduler_post_msg(QDF_MODULE_ID_TARGET_IF, &msg);
 }
+
+QDF_STATUS tgt_scan_bcn_probe_rx_callback(struct wlan_objmgr_psoc *psoc,
+	struct wlan_objmgr_peer *peer, qdf_nbuf_t buf,
+	struct mgmt_rx_event_params *rx_param,
+	enum mgmt_frame_type frm_type)
+{
+	struct scheduler_msg msg = {0};
+	struct scan_bcn_probe_event *bcn;
+	QDF_STATUS status;
+
+	if ((frm_type != MGMT_PROBE_RESP) &&
+	   (frm_type != MGMT_BEACON)) {
+		scm_err("frame is not beacon or probe resp");
+		qdf_nbuf_free(buf);
+		return QDF_STATUS_E_INVAL;
+	}
+	bcn = qdf_mem_malloc(sizeof(*bcn));
+
+	if (!bcn) {
+		scm_err("Failed to allocate memory for bcn");
+		qdf_nbuf_free(buf);
+		return QDF_STATUS_E_NOMEM;
+	}
+	bcn->rx_data =
+		qdf_mem_malloc(sizeof(*rx_param));
+	if (!bcn->rx_data) {
+		scm_err("Failed to allocate memory for rx_data");
+		qdf_mem_free(bcn);
+		qdf_nbuf_free(buf);
+		return QDF_STATUS_E_NOMEM;
+	}
+
+	if (frm_type == MGMT_PROBE_RESP)
+		bcn->frm_type = MGMT_SUBTYPE_PROBE_RESP;
+	else
+		bcn->frm_type = MGMT_SUBTYPE_BEACON;
+	bcn->psoc = psoc;
+	bcn->buf = buf;
+	qdf_mem_copy(bcn->rx_data, rx_param, sizeof(*rx_param));
+
+	msg.bodyptr = bcn;
+	msg.callback = scm_handle_bcn_probe;
+
+	status = scheduler_post_msg(QDF_MODULE_ID_TARGET_IF, &msg);
+
+	if (!QDF_IS_STATUS_SUCCESS(status)) {
+		scm_err("failed to post to QDF_MODULE_ID_TARGET_IF");
+		qdf_mem_free(bcn->rx_data);
+		qdf_mem_free(bcn);
+		qdf_nbuf_free(buf);
+	}
+	return status;
+}

+ 33 - 2
umac/scan/dispatcher/src/wlan_scan_ucfg_api.c

@@ -30,6 +30,12 @@
 #include "../../core/src/wlan_scan_manager.h"
 #include "../../core/src/wlan_scan_cache_db.h"
 
+QDF_STATUS ucfg_scan_register_bcn_cb(struct wlan_objmgr_psoc *psoc,
+	update_beacon_cb cb, enum scan_cb_type type)
+{
+	return scm_scan_register_bcn_cb(psoc, cb, type);
+}
+
 QDF_STATUS ucfg_scan_init(void)
 {
 	QDF_STATUS status;
@@ -604,6 +610,29 @@ ucfg_scan_get_pdev_status(struct wlan_objmgr_pdev *pdev)
 	return get_scan_status_from_serialization_status(status);
 }
 
+static void
+ucfg_scan_register_unregister_bcn_cb(struct wlan_objmgr_psoc *psoc,
+	bool enable)
+{
+	QDF_STATUS status;
+	struct mgmt_txrx_mgmt_frame_cb_info cb_info[2];
+
+	cb_info[0].frm_type = MGMT_PROBE_RESP;
+	cb_info[0].mgmt_rx_cb = tgt_scan_bcn_probe_rx_callback;
+	cb_info[1].frm_type = MGMT_BEACON;
+	cb_info[1].mgmt_rx_cb = tgt_scan_bcn_probe_rx_callback;
+
+	if (enable)
+		status = wlan_mgmt_txrx_register_rx_cb(psoc,
+					 WLAN_UMAC_COMP_SCAN, cb_info, 2);
+	else
+		status = wlan_mgmt_txrx_deregister_rx_cb(psoc,
+					 WLAN_UMAC_COMP_SCAN, cb_info, 2);
+	if (status != QDF_STATUS_SUCCESS)
+		scm_err("%s the Handle with MGMT TXRX layer has failed",
+			enable ? "Registering" : "Deregistering");
+}
+
 QDF_STATUS
 ucfg_scan_psoc_open(struct wlan_objmgr_psoc *psoc)
 {
@@ -622,7 +651,6 @@ ucfg_scan_psoc_open(struct wlan_objmgr_psoc *psoc)
 	/* Initialize the scan Globals */
 	wlan_scan_global_init(scan_obj);
 	qdf_spinlock_create(&scan_obj->lock);
-	scm_db_init(psoc);
 
 	return QDF_STATUS_SUCCESS;
 }
@@ -643,7 +671,6 @@ ucfg_scan_psoc_close(struct wlan_objmgr_psoc *psoc)
 		return QDF_STATUS_E_FAILURE;
 	}
 	qdf_spinlock_destroy(&scan_obj->lock);
-	scm_db_deinit(psoc);
 
 	return QDF_STATUS_SUCCESS;
 }
@@ -661,6 +688,8 @@ ucfg_scan_psoc_enable(struct wlan_objmgr_psoc *psoc)
 	/* Subscribe for scan events from lmac layesr */
 	status = tgt_scan_register_ev_handler(psoc);
 	QDF_ASSERT(status == QDF_STATUS_SUCCESS);
+	scm_db_init(psoc);
+	ucfg_scan_register_unregister_bcn_cb(psoc, true);
 
 	return status;
 }
@@ -678,6 +707,8 @@ ucfg_scan_psoc_disable(struct wlan_objmgr_psoc *psoc)
 	/* Unsubscribe for scan events from lmac layesr */
 	status = tgt_scan_unregister_ev_handler(psoc);
 	QDF_ASSERT(status == QDF_STATUS_SUCCESS);
+	ucfg_scan_register_unregister_bcn_cb(psoc, false);
+	scm_db_deinit(psoc);
 
 	return status;
 }

+ 509 - 0
umac/scan/dispatcher/src/wlan_scan_utils_api.c

@@ -20,6 +20,7 @@
  * DOC: Defines scan utility functions
  */
 
+#include <wlan_cmn.h>
 #include <wlan_scan_ucfg_api.h>
 #include <wlan_scan_utils_api.h>
 #include <../../core/src/wlan_scan_cache_db.h>
@@ -103,3 +104,511 @@ util_get_last_scan_time(struct wlan_objmgr_vdev *vdev)
 
 	return scan_obj->pdev_info[pdev_id].last_scan_time;
 }
+
+static enum wlan_band scm_chan_to_band(uint32_t chan)
+{
+	if (WLAN_CHAN_IS_2GHZ(chan))
+		return WLAN_BAND_2_4_GHZ;
+
+	return WLAN_BAND_5_GHZ;
+}
+
+static bool util_is_pureg_rate(uint8_t *rates, uint8_t nrates)
+{
+	static const uint8_t g_rates[] = {12, 18, 24, 36, 48, 72, 96, 108};
+	bool pureg = false;
+	uint8_t i, j;
+
+	for (i = 0; i < nrates; i++) {
+		for (j = 0; j < QDF_ARRAY_SIZE(g_rates); j++) {
+			if (WLAN_RV(rates[i]) == g_rates[j]) {
+				pureg = true;
+				break;
+			}
+		}
+		if (pureg)
+			break;
+	}
+
+	return pureg;
+}
+static enum wlan_phymode
+util_scan_get_phymode_5g(struct scan_cache_entry *scan_params)
+{
+	enum wlan_phymode phymode = WLAN_PHYMODE_AUTO;
+	uint16_t ht_cap = 0;
+	struct htcap_cmn_ie *htcap;
+	struct wlan_ie_htinfo_cmn *htinfo;
+	struct wlan_ie_vhtop *vhtop;
+
+	htcap = (struct htcap_cmn_ie *)
+		util_scan_entry_htcap(scan_params);
+	htinfo = (struct wlan_ie_htinfo_cmn *)
+		util_scan_entry_htinfo(scan_params);
+	vhtop = (struct wlan_ie_vhtop *)
+		util_scan_entry_vhtop(scan_params);
+
+	if (!(htcap && htinfo))
+		return WLAN_PHYMODE_11A;
+
+	if (htcap)
+		ht_cap = le16toh(htcap->hc_cap);
+
+	if (util_scan_entry_vhtcap(scan_params) && vhtop) {
+		switch (vhtop->vht_op_chwidth) {
+		case WLAN_VHTOP_CHWIDTH_2040:
+			if ((ht_cap & WLAN_HTCAP_C_CHWIDTH40) &&
+			   (htinfo->hi_extchoff ==
+			   WLAN_HTINFO_EXTOFFSET_ABOVE))
+				phymode = WLAN_PHYMODE_11AC_VHT40PLUS;
+			else if ((ht_cap & WLAN_HTCAP_C_CHWIDTH40) &&
+			   (htinfo->hi_extchoff ==
+			   WLAN_HTINFO_EXTOFFSET_BELOW))
+				phymode = WLAN_PHYMODE_11AC_VHT40MINUS;
+			else
+				phymode = WLAN_PHYMODE_11AC_VHT20;
+			break;
+		case WLAN_VHTOP_CHWIDTH_80:
+			if (WLAN_IS_REVSIG_VHT80_80(vhtop))
+				phymode = WLAN_PHYMODE_11AC_VHT80_80;
+			else if (WLAN_IS_REVSIG_VHT160(vhtop))
+				phymode = WLAN_PHYMODE_11AC_VHT160;
+			else
+				phymode = WLAN_PHYMODE_11AC_VHT80;
+			break;
+		case WLAN_VHTOP_CHWIDTH_160:
+			phymode = WLAN_PHYMODE_11AC_VHT160;
+			break;
+		case WLAN_VHTOP_CHWIDTH_80_80:
+			phymode = WLAN_PHYMODE_11AC_VHT80_80;
+			break;
+		default:
+			scm_err("bad channel: %d",
+					vhtop->vht_op_chwidth);
+			break;
+		}
+	} else if ((ht_cap & WLAN_HTCAP_C_CHWIDTH40) &&
+	   (htinfo->hi_extchoff == WLAN_HTINFO_EXTOFFSET_ABOVE))
+		phymode = WLAN_PHYMODE_11NA_HT40PLUS;
+	else if ((ht_cap & WLAN_HTCAP_C_CHWIDTH40) &&
+	   (htinfo->hi_extchoff == WLAN_HTINFO_EXTOFFSET_BELOW))
+		phymode = WLAN_PHYMODE_11NA_HT40MINUS;
+	else
+		phymode = WLAN_PHYMODE_11NA_HT20;
+
+	return phymode;
+}
+
+static enum wlan_phymode
+util_scan_get_phymode_2g(struct scan_cache_entry *scan_params)
+{
+	enum wlan_phymode phymode = WLAN_PHYMODE_AUTO;
+	uint16_t ht_cap = 0;
+	struct htcap_cmn_ie *htcap;
+	struct wlan_ie_htinfo_cmn *htinfo;
+	struct wlan_ie_vhtop *vhtop;
+
+	htcap = (struct htcap_cmn_ie *)
+		util_scan_entry_htcap(scan_params);
+	htinfo = (struct wlan_ie_htinfo_cmn *)
+		util_scan_entry_htinfo(scan_params);
+	vhtop = (struct wlan_ie_vhtop *)
+		util_scan_entry_vhtop(scan_params);
+
+	if (htcap)
+		ht_cap = le16toh(htcap->hc_cap);
+
+	if (htcap && htinfo) {
+		if ((ht_cap & WLAN_HTCAP_C_CHWIDTH40) &&
+		   (htinfo->hi_extchoff == WLAN_HTINFO_EXTOFFSET_ABOVE))
+			phymode = WLAN_PHYMODE_11NG_HT40PLUS;
+		else if ((ht_cap & WLAN_HTCAP_C_CHWIDTH40) &&
+		   (htinfo->hi_extchoff == WLAN_HTINFO_EXTOFFSET_BELOW))
+			phymode = WLAN_PHYMODE_11NG_HT40MINUS;
+		else
+			phymode = WLAN_PHYMODE_11NG_HT20;
+	} else if (util_scan_entry_xrates(scan_params)) {
+		/* only 11G stations will have more than 8 rates */
+		phymode = WLAN_PHYMODE_11G;
+	} else {
+		/* Some mischievous g-only APs do not set extended rates */
+		if (util_scan_entry_rates(scan_params)) {
+			if (util_is_pureg_rate(&scan_params->ie_list.rates[2],
+			   scan_params->ie_list.rates[1]))
+				phymode = WLAN_PHYMODE_11G;
+			else
+				phymode = WLAN_PHYMODE_11B;
+		} else {
+			phymode = WLAN_PHYMODE_11B;
+		}
+	}
+
+	return phymode;
+}
+
+static QDF_STATUS
+util_scan_parse_chan_switch_wrapper_ie(struct scan_cache_entry *scan_params,
+	struct ie_header *sub_ie, qdf_size_t sub_ie_len)
+{
+	/* Walk through to check nothing is malformed */
+	while (sub_ie_len >= sizeof(struct ie_header)) {
+		/* At least one more header is present */
+		sub_ie_len -= sizeof(struct ie_header);
+
+		if (sub_ie->ie_len == 0) {
+			sub_ie += 1;
+			continue;
+		}
+		if (sub_ie_len < sub_ie->ie_len) {
+			scm_err("Incomplete corrupted IE:%x",
+				WLAN_ELEMID_CHAN_SWITCH_WRAP);
+			return QDF_STATUS_E_INVAL;
+		}
+		switch (sub_ie->ie_id) {
+		case WLAN_ELEMID_COUNTRY:
+			scan_params->ie_list.country = (uint8_t *)sub_ie;
+			break;
+		case WLAN_ELEMID_WIDE_BAND_CHAN_SWITCH:
+			scan_params->ie_list.widebw = (uint8_t *)sub_ie;
+			break;
+		case WLAN_ELEMID_VHT_TX_PWR_ENVLP:
+			scan_params->ie_list.txpwrenvlp = (uint8_t *)sub_ie;
+			break;
+		}
+		/* Consume sub info element */
+		sub_ie_len -= sub_ie->ie_len;
+		/* go to next Sub IE */
+		sub_ie = (struct ie_header *)
+			(((uint8_t *) sub_ie) +
+			sizeof(struct ie_header) + sub_ie->ie_len);
+	}
+
+	return QDF_STATUS_SUCCESS;
+}
+
+static bool
+util_scan_is_hidden_ssid(struct ie_ssid *ssid)
+{
+	uint8_t i;
+
+	/*
+	 * We flag this as Hidden SSID if the Length is 0
+	 * of the SSID only contains 0's
+	 */
+	if (!ssid || !ssid->ssid_len)
+		return true;
+
+	for (i = 0; i < ssid->ssid_len; i++)
+		if (ssid->ssid[i] != 0)
+			return false;
+
+	/* All 0's */
+	return true;
+}
+
+static void
+util_scan_parse_vendor_ie(struct scan_cache_entry *scan_params,
+	struct ie_header *ie)
+{
+
+	if (scan_params->ie_list.vendor == NULL)
+		scan_params->ie_list.vendor = (uint8_t *)ie;
+
+	if (is_wpa_oui((uint8_t *)ie)) {
+		scan_params->ie_list.wpa = (uint8_t *)ie;
+	} else if (is_wps_oui((uint8_t *)ie)) {
+		scan_params->ie_list.wps = (uint8_t *)ie;
+		/* WCN IE should be a subset of WPS IE */
+		if (is_wcn_oui((uint8_t *)ie))
+			scan_params->ie_list.wcn = (uint8_t *)ie;
+	} else if (is_wme_param((uint8_t *)ie)) {
+		scan_params->ie_list.wmeparam = (uint8_t *)ie;
+	} else if (is_wme_info((uint8_t *)ie)) {
+		scan_params->ie_list.wmeinfo = (uint8_t *)ie;
+	} else if (is_atheros_oui((uint8_t *)ie)) {
+		scan_params->ie_list.athcaps = (uint8_t *)ie;
+	} else if (is_atheros_extcap_oui((uint8_t *)ie)) {
+		scan_params->ie_list.athextcaps = (uint8_t *)ie;
+	} else if (is_sfa_oui((uint8_t *)ie)) {
+		scan_params->ie_list.sfa = (uint8_t *)ie;
+	} else if (is_p2p_oui((uint8_t *)ie)) {
+		scan_params->ie_list.p2p = (uint8_t *)ie;
+	} else if (is_qca_whc_oui((uint8_t *)ie,
+	   QCA_OUI_WHC_AP_INFO_SUBTYPE)) {
+		scan_params->ie_list.sonadv = (uint8_t *)ie;
+	} else if (is_ht_cap((uint8_t *)ie)) {
+		/* we only care if there isn't already an HT IE (ANA) */
+		if (scan_params->ie_list.htcap == NULL)
+			scan_params->ie_list.htcap =
+			  (uint8_t *)&(((struct wlan_vendor_ie_htcap *)ie)->ie);
+	} else if (is_ht_info((uint8_t *)ie)) {
+		/* we only care if there isn't already an HT IE (ANA) */
+		if (scan_params->ie_list.htinfo == NULL)
+			scan_params->ie_list.htinfo =
+			  (uint8_t *)&(((struct wlan_vendor_ie_htinfo *)
+			  ie)->hi_ie);
+	} else if (is_interop_vht((uint8_t *)ie) &&
+	    !(scan_params->ie_list.vhtop)) {
+		/* location where Interop Vht Cap IE and VHT OP IE Present */
+		scan_params->ie_list.vhtcap = (((uint8_t *)(ie)) + 7);
+		scan_params->ie_list.vhtop = (((uint8_t *)(ie)) + 21);
+	} else if (is_bwnss_oui((uint8_t *)ie)) {
+		/*
+		 * Bandwidth-NSS map has sub-type & version.
+		 * hence copy data just after version byte
+		 */
+		scan_params->ie_list.bwnss_map = (((uint8_t *)ie) + 8);
+	}
+}
+
+static QDF_STATUS
+util_scan_populate_bcn_ie_list(struct scan_cache_entry *scan_params)
+{
+	struct ie_header *ie, *sub_ie;
+	uint32_t ie_len, sub_ie_len;
+	QDF_STATUS status;
+
+	ie_len = util_scan_entry_ie_len(scan_params);
+	ie = (struct ie_header *)
+		  util_scan_entry_ie_data(scan_params);
+
+	while (ie_len >= sizeof(struct ie_header)) {
+		ie_len -= sizeof(struct ie_header);
+
+		if (!ie->ie_len) {
+			ie += 1;
+			continue;
+		}
+
+		if (ie_len < ie->ie_len) {
+			scm_err("Incomplete corrupted IE:%x",
+				ie->ie_id);
+			return QDF_STATUS_E_INVAL;
+		}
+
+		switch (ie->ie_id) {
+		case WLAN_ELEMID_SSID:
+			scan_params->ie_list.ssid = (uint8_t *)ie;
+			break;
+		case WLAN_ELEMID_RATES:
+			scan_params->ie_list.rates = (uint8_t *)ie;
+			break;
+		case WLAN_ELEMID_DSPARMS:
+			scan_params->channel.chan_idx =
+				((struct ds_ie *)ie)->cur_chan;
+			break;
+		case WLAN_ELEMID_TIM:
+			scan_params->ie_list.tim = (uint8_t *)ie;
+			scan_params->dtim_period =
+				((struct wlan_tim_ie *)ie)->tim_period;
+			break;
+		case WLAN_ELEMID_COUNTRY:
+			scan_params->ie_list.country = (uint8_t *)ie;
+			break;
+		case WLAN_ELEMID_QBSS_LOAD:
+			scan_params->ie_list.qbssload = (uint8_t *)ie;
+			break;
+		case WLAN_ELEMID_CHANSWITCHANN:
+			scan_params->ie_list.csa = (uint8_t *)ie;
+			break;
+		case WLAN_ELEMID_IBSSDFS:
+			scan_params->ie_list.ibssdfs = (uint8_t *)ie;
+			break;
+		case WLAN_ELEMID_QUIET:
+			scan_params->ie_list.quiet = (uint8_t *)ie;
+			break;
+		case WLAN_ELEMID_ERP:
+			scan_params->erp = ((struct erp_ie *)ie)->value;
+			break;
+		case WLAN_ELEMID_HTCAP_ANA:
+			scan_params->ie_list.htcap =
+				(uint8_t *)&(((struct htcap_ie *)ie)->ie);
+			break;
+		case WLAN_ELEMID_RSN:
+			scan_params->ie_list.rsn = (uint8_t *)ie;
+			break;
+		case WLAN_ELEMID_XRATES:
+			scan_params->ie_list.xrates = (uint8_t *)ie;
+			break;
+		case WLAN_ELEMID_EXTCHANSWITCHANN:
+			scan_params->ie_list.xcsa = (uint8_t *)ie;
+			break;
+		case WLAN_ELEMID_SECCHANOFFSET:
+			scan_params->ie_list.secchanoff = (uint8_t *)ie;
+			break;
+		case WLAN_ELEMID_HTINFO_ANA:
+			scan_params->ie_list.htinfo =
+			  (uint8_t *)&(((struct wlan_ie_htinfo *) ie)->hi_ie);
+			scan_params->channel.chan_idx =
+			  ((struct wlan_ie_htinfo_cmn *)
+			  (scan_params->ie_list.htinfo))->hi_ctrlchannel;
+			break;
+		case WLAN_ELEMID_WAPI:
+			scan_params->ie_list.wapi = (uint8_t *)ie;
+			break;
+		case WLAN_ELEMID_XCAPS:
+			scan_params->ie_list.extcaps = (uint8_t *)ie;
+			break;
+		case WLAN_ELEMID_VHTCAP:
+			scan_params->ie_list.vhtcap = (uint8_t *)ie;
+			break;
+		case WLAN_ELEMID_VHTOP:
+			scan_params->ie_list.vhtop = (uint8_t *)ie;
+			break;
+		case WLAN_ELEMID_OP_MODE_NOTIFY:
+				scan_params->ie_list.opmode = (uint8_t *)ie;
+			break;
+		case WLAN_ELEMID_MOBILITY_DOMAIN:
+			scan_params->ie_list.mdie = (uint8_t *)ie;
+			break;
+		case WLAN_ELEMID_VENDOR:
+			util_scan_parse_vendor_ie(scan_params,
+				ie);
+			break;
+		case WLAN_ELEMID_CHAN_SWITCH_WRAP:
+			scan_params->ie_list.cswrp = (uint8_t *)ie;
+			/* Go to next sub IE */
+			sub_ie = (struct ie_header *)
+			(((uint8_t *)ie) + sizeof(struct ie_header));
+			sub_ie_len = ie->ie_len;
+			status =
+				util_scan_parse_chan_switch_wrapper_ie(
+					scan_params, sub_ie, sub_ie_len);
+			if (QDF_IS_STATUS_ERROR(status)) {
+				scm_err("failed to parse chan_switch_wrapper_ie");
+				return status;
+			}
+			break;
+		default:
+			break;
+		}
+
+		/* Consume info element */
+		ie_len -= ie->ie_len;
+		/* Go to next IE */
+		ie = (struct ie_header *)
+			(((uint8_t *) ie) +
+			sizeof(struct ie_header) +
+			ie->ie_len);
+	}
+
+	return QDF_STATUS_SUCCESS;
+}
+
+struct scan_cache_entry *
+util_scan_unpack_beacon_frame(uint8_t *frame,
+	qdf_size_t frame_len, uint32_t frm_subtype,
+	struct mgmt_rx_event_params *rx_param)
+{
+	struct wlan_frame_hdr *hdr;
+	struct wlan_bcn_frame *bcn;
+	QDF_STATUS status;
+	struct ie_ssid *ssid;
+	struct scan_cache_entry *scan_entry = NULL;
+
+	scan_entry = qdf_mem_malloc(sizeof(*scan_entry));
+	if (!scan_entry) {
+		scm_err("failed to allocate memory for scan_entry");
+		return NULL;
+	}
+	scan_entry->raw_frame.ptr =
+			qdf_mem_malloc(frame_len);
+	if (!scan_entry->raw_frame.ptr) {
+		scm_err("failed to allocate memory for frame");
+		qdf_mem_free(scan_entry);
+		return NULL;
+	}
+
+	bcn = (struct wlan_bcn_frame *)
+			   (frame + sizeof(*hdr));
+	hdr = (struct wlan_frame_hdr *)frame;
+
+	scan_entry->frm_subtype = frm_subtype;
+	qdf_mem_copy(scan_entry->bssid.bytes,
+		hdr->i_addr3, QDF_MAC_ADDR_SIZE);
+	/* Scr addr */
+	qdf_mem_copy(scan_entry->mac_addr.bytes,
+		hdr->i_addr2, QDF_MAC_ADDR_SIZE);
+	scan_entry->seq_num =
+		(le16toh(*(uint16_t *)hdr->i_seq) >> WLAN_SEQ_SEQ_SHIFT);
+
+	scan_entry->rssi_raw = rx_param->rssi;
+	scan_entry->tsf_delta = rx_param->tsf_delta;
+
+	/* store jiffies */
+	scan_entry->rrm_parent_tsf = (u_int32_t) qdf_system_ticks();
+
+	scan_entry->bcn_int = le16toh(bcn->beacon_interval);
+
+	/*
+	 * In case if the beacon dosnt have
+	 * valid beacon interval falback to def
+	 */
+	if (!scan_entry->bcn_int)
+		scan_entry->bcn_int = 100;
+	scan_entry->cap_info.value = le16toh(bcn->capability.value);
+	qdf_mem_copy(scan_entry->tsf_info.data,
+		bcn->timestamp, 8);
+	scan_entry->erp = ERP_NON_ERP_PRESENT;
+
+
+	scan_entry->rssi_timestamp =
+		scan_entry->scan_entry_time =
+			qdf_mc_timer_get_system_time();
+
+	scan_entry->raw_frame.len = frame_len;
+	qdf_mem_copy(scan_entry->raw_frame.ptr,
+		frame, frame_len);
+	status = util_scan_populate_bcn_ie_list(scan_entry);
+	if (QDF_IS_STATUS_ERROR(status)) {
+		scm_err("failed to parse beacon IE");
+		qdf_mem_free(scan_entry->raw_frame.ptr);
+		qdf_mem_free(scan_entry);
+		return NULL;
+	}
+
+	if (!scan_entry->ie_list.rates) {
+		qdf_mem_free(scan_entry->raw_frame.ptr);
+		qdf_mem_free(scan_entry);
+		return NULL;
+	}
+
+	ssid = (struct ie_ssid *)
+		scan_entry->ie_list.ssid;
+
+	if (ssid && (ssid->ssid_len > WLAN_SSID_MAX_LEN)) {
+		qdf_mem_free(scan_entry->raw_frame.ptr);
+		qdf_mem_free(scan_entry);
+		return NULL;
+	}
+
+	if (scan_entry->ie_list.p2p)
+		scan_entry->is_p2p = true;
+
+	/* If no channel info is present in beacon use meta channel */
+	if (!scan_entry->channel.chan_idx) {
+		scan_entry->channel.chan_idx =
+				rx_param->channel;
+	} else if (rx_param->channel !=
+	   scan_entry->channel.chan_idx) {
+		scan_entry->channel_mismatch = true;
+	}
+
+	if (util_scan_is_hidden_ssid(ssid)) {
+		scan_entry->ie_list.ssid = NULL;
+	} else {
+		qdf_mem_copy(scan_entry->ssid.ssid,
+				ssid->ssid, WLAN_SSID_MAX_LEN);
+		scan_entry->ssid.length = ssid->ssid_len;
+		scan_entry->hidden_ssid_timestamp =
+			scan_entry->scan_entry_time;
+	}
+
+	if (WLAN_CHAN_IS_5GHZ(scan_entry->channel.chan_idx))
+		scan_entry->phy_mode = util_scan_get_phymode_5g(scan_entry);
+	else
+		scan_entry->phy_mode = util_scan_get_phymode_2g(scan_entry);
+
+	/* TODO calculate channel struct */
+	return scan_entry;
+}