qcacld-3.0: Fix e_sme_command_nss_update stuck issue

Update NSS command is remove once driver receive the tx completion
event for the beacon. If SAP is in CAC wait state driver will not
get the tx completion for the beacon and the update NSS will timeout
after 30 sec and the serialization cmds queues will get stuck.

To avoid this remove the update NSS command from active queue as
soon as beacon is sent to firmware

Change-Id: I6f5b6bce91bdfacd4621020f313be25f74696b9d
CRs-Fixed: 2332302
diff --git a/core/mac/inc/sir_api.h b/core/mac/inc/sir_api.h
index 0a59237..454c46a 100644
--- a/core/mac/inc/sir_api.h
+++ b/core/mac/inc/sir_api.h
@@ -5226,14 +5226,34 @@
 };
 
 /**
- * struct sir_beacon_tx_complete_rsp
- *
- * @session_id: session for which beacon update happened
- * @tx_status: status of the beacon tx from FW
+ * enum sir_bcn_update_reason: bcn update reason
+ * @REASON_DEFAULT: reason default
+ * @REASON_NSS_UPDATE: If NSS is updated
+ * @REASON_CONFIG_UPDATE: Config update
+ * @REASON_SET_HT2040: HT2040 update
+ * @REASON_COLOR_CHANGE: Color change
+ * @REASON_CHANNEL_SWITCH: channel switch
  */
-struct sir_beacon_tx_complete_rsp {
-	uint8_t session_id;
-	uint8_t tx_status;
+enum sir_bcn_update_reason {
+	REASON_DEFAULT = 0,
+	REASON_NSS_UPDATE = 1,
+	REASON_CONFIG_UPDATE = 2,
+	REASON_SET_HT2040 = 3,
+	REASON_COLOR_CHANGE = 4,
+	REASON_CHANNEL_SWITCH = 5,
+};
+
+/**
+ * struct sir_bcn_update_rsp
+ *
+ * @vdev_id: session for which bcn was updated
+ * @reason: bcn update reason
+ * @status: status of the beacon sent to FW
+ */
+struct sir_bcn_update_rsp {
+	uint8_t vdev_id;
+	enum sir_bcn_update_reason reason;
+	QDF_STATUS status;
 };
 
 /**
diff --git a/core/mac/src/include/sir_params.h b/core/mac/src/include/sir_params.h
index dd9cc12..d41bdad 100644
--- a/core/mac/src/include/sir_params.h
+++ b/core/mac/src/include/sir_params.h
@@ -686,6 +686,8 @@
 #define SIR_HAL_SEND_ADDBA_REQ              (SIR_HAL_ITC_MSG_TYPES_BEGIN + 398)
 #define SIR_HAL_GET_ROAM_SCAN_STATS         (SIR_HAL_ITC_MSG_TYPES_BEGIN + 399)
 #define SIR_HAL_SEND_AP_VDEV_UP             (SIR_HAL_ITC_MSG_TYPES_BEGIN + 400)
+#define SIR_HAL_SEND_BCN_RSP                (SIR_HAL_ITC_MSG_TYPES_BEGIN + 401)
+
 #define SIR_HAL_MSG_TYPES_END               (SIR_HAL_MSG_TYPES_BEGIN + 0x1FF)
 
 /* CFG message types */
diff --git a/core/mac/src/pe/include/sch_api.h b/core/mac/src/pe/include/sch_api.h
index b262230..9744040 100644
--- a/core/mac/src/pe/include/sch_api.h
+++ b/core/mac/src/pe/include/sch_api.h
@@ -56,9 +56,17 @@
 void sch_process_message(tpAniSirGlobal pMac,
 			 struct scheduler_msg *pSchMsg);
 
-/* / The beacon Indication handler function */
-void sch_process_pre_beacon_ind(tpAniSirGlobal pMac,
-				struct scheduler_msg *limMsg);
+/**
+ * sch_process_pre_beacon_ind() - Process the PreBeacon Indication from the Lim
+ * @pMac: pointer to mac structure
+ * @msg: schedular msg
+ * @reason: beaon update reason
+ *
+ * return: success: QDF_STATUS_SUCCESS failure: QDF_STATUS_E_FAILURE
+ */
+QDF_STATUS sch_process_pre_beacon_ind(tpAniSirGlobal pMac,
+				      struct scheduler_msg *msg,
+				      enum sir_bcn_update_reason reason);
 
 /* / Post a message to the scheduler message queue */
 QDF_STATUS sch_post_message(tpAniSirGlobal pMac,
@@ -75,8 +83,20 @@
 
 void sch_set_beacon_interval(tpAniSirGlobal pMac, tpPESession psessionEntry);
 
-QDF_STATUS sch_send_beacon_req(tpAniSirGlobal, uint8_t *, uint16_t,
-			       tpPESession psessionEntry);
+/**
+ * sch_send_beacon_req() - send beacon update req to wma
+ * @mac_ctx: pointer to mac structure
+ * @bcn_payload: beacon payload
+ * @size: beacon size
+ * @session:pe session
+ * @reason: beaon update reason
+ *
+ * return: success: QDF_STATUS_SUCCESS failure: QDF_STATUS_E_FAILURE
+ */
+QDF_STATUS sch_send_beacon_req(tpAniSirGlobal mac_ctx, uint8_t *bcn_payload,
+			       uint16_t size, tpPESession session,
+			       enum sir_bcn_update_reason reason);
+
 
 QDF_STATUS lim_update_probe_rsp_template_ie_bitmap_beacon1(tpAniSirGlobal,
 							   tDot11fBeacon1 *,
diff --git a/core/mac/src/pe/lim/lim_process_message_queue.c b/core/mac/src/pe/lim/lim_process_message_queue.c
index 942c061..3e988c1 100644
--- a/core/mac/src/pe/lim/lim_process_message_queue.c
+++ b/core/mac/src/pe/lim/lim_process_message_queue.c
@@ -1750,7 +1750,8 @@
 		break;
 	case SIR_LIM_BEACON_GEN_IND:
 		if (mac_ctx->lim.gLimSystemRole != eLIM_AP_ROLE)
-			sch_process_pre_beacon_ind(mac_ctx, msg);
+			sch_process_pre_beacon_ind(mac_ctx,
+						   msg, REASON_DEFAULT);
 		break;
 	case SIR_LIM_DELETE_STA_CONTEXT_IND:
 		lim_delete_sta_context(mac_ctx, msg);
@@ -2053,6 +2054,11 @@
 		lim_send_csa_restart_req(mac_ctx, msg->bodyval);
 		break;
 #endif
+	case WMA_SEND_BCN_RSP:
+		lim_send_bcn_rsp(mac_ctx, (tpSendbeaconParams)msg->bodyptr);
+		qdf_mem_free((void *)msg->bodyptr);
+		msg->bodyptr = NULL;
+		break;
 	default:
 		qdf_mem_free((void *)msg->bodyptr);
 		msg->bodyptr = NULL;
diff --git a/core/mac/src/pe/lim/lim_process_mlm_rsp_messages.c b/core/mac/src/pe/lim/lim_process_mlm_rsp_messages.c
index 5002994..3625f3f 100644
--- a/core/mac/src/pe/lim/lim_process_mlm_rsp_messages.c
+++ b/core/mac/src/pe/lim/lim_process_mlm_rsp_messages.c
@@ -3307,25 +3307,25 @@
 	qdf_mem_free(body);
 }
 
-void lim_send_beacon_ind(tpAniSirGlobal pMac, tpPESession psessionEntry)
+QDF_STATUS lim_send_beacon_ind(tpAniSirGlobal pMac, tpPESession psessionEntry,
+			       enum sir_bcn_update_reason reason)
 {
 	tBeaconGenParams *pBeaconGenParams = NULL;
 	struct scheduler_msg limMsg = {0};
 	/** Allocate the Memory for Beacon Pre Message and for Stations in PoweSave*/
-	if (psessionEntry == NULL) {
+	if (!psessionEntry) {
 		pe_err("Error:Unable to get the PESessionEntry");
-		return;
+		return QDF_STATUS_E_INVAL;
 	}
 	pBeaconGenParams = qdf_mem_malloc(sizeof(*pBeaconGenParams));
-	if (NULL == pBeaconGenParams) {
+	if (!pBeaconGenParams) {
 		pe_err("Unable to allocate memory during sending beaconPreMessage");
-		return;
+		return QDF_STATUS_E_NOMEM;
 	}
 	qdf_mem_copy((void *)pBeaconGenParams->bssId,
 		     (void *)psessionEntry->bssId, QDF_MAC_ADDR_SIZE);
 	limMsg.bodyptr = pBeaconGenParams;
-	sch_process_pre_beacon_ind(pMac, &limMsg);
-	return;
+	return sch_process_pre_beacon_ind(pMac, &limMsg, reason);
 }
 
 void lim_process_rx_channel_status_event(tpAniSirGlobal mac_ctx, void *buf)
diff --git a/core/mac/src/pe/lim/lim_process_sme_req_messages.c b/core/mac/src/pe/lim/lim_process_sme_req_messages.c
index d2650bd..9041a39 100644
--- a/core/mac/src/pe/lim/lim_process_sme_req_messages.c
+++ b/core/mac/src/pe/lim/lim_process_sme_req_messages.c
@@ -3799,7 +3799,7 @@
 
 	if (LIM_IS_AP_ROLE(pe_session)) {
 		sch_set_fixed_beacon_fields(mac_ctx, pe_session);
-		lim_send_beacon_ind(mac_ctx, pe_session);
+		lim_send_beacon_ind(mac_ctx, pe_session, REASON_CONFIG_UPDATE);
 	}
 }
 
@@ -4091,7 +4091,7 @@
 
 	/* Update beacon */
 	sch_set_fixed_beacon_fields(pMac, psessionEntry);
-	lim_send_beacon_ind(pMac, psessionEntry);
+	lim_send_beacon_ind(pMac, psessionEntry, REASON_SET_HT2040);
 
 	/* update OP Mode for each associated peer */
 	for (staId = 0; staId < psessionEntry->dph.dphHashTable.size; staId++) {
@@ -5901,6 +5901,56 @@
 }
 
 /**
+ * lim_nss_update_rsp() - send NSS update response to SME
+ * @mac_ctx Pointer to Global MAC structure
+ * @vdev_id: vdev id
+ * @status: nss update status
+ *
+ * Return: None
+ */
+static void lim_nss_update_rsp(tpAniSirGlobal mac_ctx,
+			       uint8_t vdev_id, QDF_STATUS status)
+{
+	struct scheduler_msg msg = {0};
+	struct sir_bcn_update_rsp *nss_rsp;
+	QDF_STATUS qdf_status;
+
+	nss_rsp = qdf_mem_malloc(sizeof(*nss_rsp));
+	if (!nss_rsp) {
+		pe_err("AllocateMemory failed for nss_rsp");
+		return;
+	}
+
+	nss_rsp->vdev_id = vdev_id;
+	nss_rsp->status = status;
+	nss_rsp->reason = REASON_NSS_UPDATE;
+
+	msg.type = eWNI_SME_NSS_UPDATE_RSP;
+	msg.bodyptr = nss_rsp;
+	msg.bodyval = 0;
+	qdf_status = scheduler_post_message(QDF_MODULE_ID_PE, QDF_MODULE_ID_SME,
+					    QDF_MODULE_ID_SME, &msg);
+	if (QDF_IS_STATUS_ERROR(qdf_status)) {
+		pe_err("Failed to post eWNI_SME_NSS_UPDATE_RSP");
+		qdf_mem_free(nss_rsp);
+	}
+}
+
+void lim_send_bcn_rsp(tpAniSirGlobal mac_ctx, tpSendbeaconParams rsp)
+{
+	if (!rsp) {
+		pe_err("rsp is NULL");
+		return;
+	}
+
+	pe_debug("Send beacon resp status %d for reason %d",
+		 rsp->status, rsp->reason);
+
+	if (rsp->reason == REASON_NSS_UPDATE)
+		lim_nss_update_rsp(mac_ctx, rsp->vdev_id, rsp->status);
+}
+
+/**
  * lim_process_nss_update_request() - process sme nss update req
  *
  * @mac_ctx: Pointer to Global MAC structure
@@ -5916,25 +5966,28 @@
 {
 	struct sir_nss_update_request *nss_update_req_ptr;
 	tpPESession session_entry = NULL;
+	QDF_STATUS status = QDF_STATUS_E_FAILURE;
+	uint8_t vdev_id;
 
-	if (msg_buf == NULL) {
+	if (!msg_buf) {
 		pe_err("Buffer is Pointing to NULL");
 		return;
 	}
 
 	nss_update_req_ptr = (struct sir_nss_update_request *)msg_buf;
+	vdev_id = nss_update_req_ptr->vdev_id;
 	session_entry = pe_find_session_by_sme_session_id(mac_ctx,
 				nss_update_req_ptr->vdev_id);
-	if (session_entry == NULL) {
+	if (!session_entry) {
 		pe_err("Session not found for given session_id %d",
 			nss_update_req_ptr->vdev_id);
-		return;
+		goto end;
 	}
 
 	if (session_entry->valid && !LIM_IS_AP_ROLE(session_entry)) {
 		pe_err("Invalid SystemRole %d",
 			GET_LIM_SYSTEM_ROLE(session_entry));
-		return;
+		goto end;
 	}
 
 	/* populate nss field in the beacon */
@@ -5946,16 +5999,28 @@
 			(session_entry->ch_width > CH_WIDTH_80MHZ))
 		session_entry->gLimOperatingMode.chanWidth = CH_WIDTH_80MHZ;
 
-	pe_debug("ch width %hu", session_entry->gLimOperatingMode.chanWidth);
+	pe_debug("ch width %d Rx NSS %d",
+		 session_entry->gLimOperatingMode.chanWidth,
+		 session_entry->gLimOperatingMode.rxNSS);
 
 	/* Send nss update request from here */
-	if (sch_set_fixed_beacon_fields(mac_ctx, session_entry) !=
-			QDF_STATUS_SUCCESS) {
+	status = sch_set_fixed_beacon_fields(mac_ctx, session_entry);
+	if (QDF_IS_STATUS_ERROR(status)) {
 		pe_err("Unable to set op mode IE in beacon");
-		return;
+		goto end;
 	}
 
-	lim_send_beacon_ind(mac_ctx, session_entry);
+	status = lim_send_beacon_ind(mac_ctx, session_entry, REASON_NSS_UPDATE);
+	if (QDF_IS_STATUS_SUCCESS(status))
+		return;
+
+	pe_err("Unable to send beacon");
+end:
+	/*
+	 * send resp only in case of failure,
+	 * success case response will be from wma.
+	 */
+	lim_nss_update_rsp(mac_ctx, vdev_id, status);
 }
 
 /**
diff --git a/core/mac/src/pe/lim/lim_send_messages.c b/core/mac/src/pe/lim/lim_send_messages.c
index e50a440..447aa67 100644
--- a/core/mac/src/pe/lim/lim_send_messages.c
+++ b/core/mac/src/pe/lim/lim_send_messages.c
@@ -133,7 +133,7 @@
 		pe_err("Posting WMA_UPDATE_BEACON_IND, reason=%X",
 			retCode);
 	}
-	lim_send_beacon_ind(pMac, psessionEntry);
+	lim_send_beacon_ind(pMac, psessionEntry, REASON_DEFAULT);
 	return retCode;
 }
 
diff --git a/core/mac/src/pe/lim/lim_send_sme_rsp_messages.c b/core/mac/src/pe/lim/lim_send_sme_rsp_messages.c
index 41a3711..92ea73c 100644
--- a/core/mac/src/pe/lim/lim_send_sme_rsp_messages.c
+++ b/core/mac/src/pe/lim/lim_send_sme_rsp_messages.c
@@ -2352,7 +2352,7 @@
 	}
 
 	/* Send update beacon template message */
-	lim_send_beacon_ind(mac_ctx, session);
+	lim_send_beacon_ind(mac_ctx, session, REASON_COLOR_CHANGE);
 	pe_debug("Updated BSS color change countdown = %d",
 		 session->he_bss_color_change.countdown);
 }
@@ -2406,11 +2406,8 @@
 				  void *event)
 {
 	tpPESession session;
-	struct scheduler_msg msg = {0};
-	struct sir_beacon_tx_complete_rsp *bcn_tx_comp_rsp;
 	tpSirFirstBeaconTxCompleteInd bcn_ind =
 		(tSirFirstBeaconTxCompleteInd *) event;
-	QDF_STATUS status;
 
 	session = pe_find_session_by_bss_idx(mac_ctx, bcn_ind->bssIdx);
 	if (!session) {
@@ -2433,25 +2430,9 @@
 		lim_process_ap_ecsa_timeout(session);
 
 
-	if (session->gLimOperatingMode.present) {
-		/* Done with nss update, send response back to SME */
+	if (session->gLimOperatingMode.present)
+		/* Done with nss update */
 		session->gLimOperatingMode.present = 0;
-		bcn_tx_comp_rsp = qdf_mem_malloc(sizeof(*bcn_tx_comp_rsp));
-		if (!bcn_tx_comp_rsp)
-			return;
-		bcn_tx_comp_rsp->session_id = session->smeSessionId;
-		bcn_tx_comp_rsp->tx_status = QDF_STATUS_SUCCESS;
-		msg.type = eWNI_SME_NSS_UPDATE_RSP;
-		msg.bodyptr = bcn_tx_comp_rsp;
-		msg.bodyval = 0;
-		status = scheduler_post_message(QDF_MODULE_ID_PE,
-						QDF_MODULE_ID_SME,
-						QDF_MODULE_ID_SME, &msg);
-		if (QDF_IS_STATUS_ERROR(status)) {
-			sme_err("Failed to post eWNI_SME_NSS_UPDATE_RSP");
-			qdf_mem_free(bcn_tx_comp_rsp);
-		}
-	}
 
 	lim_handle_bss_color_change_ie(mac_ctx, session);
 
diff --git a/core/mac/src/pe/lim/lim_types.h b/core/mac/src/pe/lim/lim_types.h
index 6f0b371..ddf852e 100644
--- a/core/mac/src/pe/lim/lim_types.h
+++ b/core/mac/src/pe/lim/lim_types.h
@@ -926,20 +926,15 @@
 } /*** end lim_get_ielen_from_bss_description() ***/
 
 /**
- * lim_send_beacon_ind()
+ * lim_send_beacon_ind() - send the beacon indication
+ * @mac_ctx: pointer to mac structure
+ * @session: pe session
+ * @reason: beacon update reason
  *
- ***FUNCTION:
- * This function is called  to send the beacon indication
- * number being scanned.
- *
- ***PARAMS:
- *
- ***LOGIC:
- *
- ***ASSUMPTIONS:
+ * return: success: QDF_STATUS_SUCCESS failure: QDF_STATUS_E_FAILURE
  */
-
-void lim_send_beacon_ind(tpAniSirGlobal pMac, tpPESession psessionEntry);
+QDF_STATUS lim_send_beacon_ind(tpAniSirGlobal mac_ctx, tpPESession session,
+			       enum sir_bcn_update_reason reason);
 
 void
 lim_send_vdev_restart(tpAniSirGlobal pMac, tpPESession psessionEntry,
@@ -1018,6 +1013,15 @@
 #endif
 
 /**
+ * lim_send_bcn_rsp() - handle beacon send response
+ * @mac_ctx Pointer to Global MAC structure
+ * @rsp: beacon send response
+ *
+ * Return: None
+ */
+void lim_send_bcn_rsp(tpAniSirGlobal mac_ctx, tpSendbeaconParams rsp);
+
+/**
  * lim_process_rx_channel_status_event() - processes
  * event WDA_RX_CHN_STATUS_EVENT
  * @mac_ctx Pointer to Global MAC structure
diff --git a/core/mac/src/pe/lim/lim_utils.c b/core/mac/src/pe/lim/lim_utils.c
index ccaad9b..2caa333 100644
--- a/core/mac/src/pe/lim/lim_utils.c
+++ b/core/mac/src/pe/lim/lim_utils.c
@@ -5440,7 +5440,8 @@
 			if (false == mac_ctx->sap.SapDfsInfo.
 					is_dfs_cac_timer_running)
 				lim_send_beacon_ind(mac_ctx,
-						&mac_ctx->lim.gpSession[i]);
+						&mac_ctx->lim.gpSession[i],
+						REASON_DEFAULT);
 		}
 	}
 }
@@ -8298,7 +8299,7 @@
 	}
 
 	/* Send update beacon template message */
-	lim_send_beacon_ind(mac_ctx, session);
+	lim_send_beacon_ind(mac_ctx, session, REASON_CHANNEL_SWITCH);
 	pe_debug("Updated CSA IE, IE COUNT: %d",
 		 session->gLimChannelSwitch.switchCount);
 }
@@ -8537,7 +8538,7 @@
 		return QDF_STATUS_SUCCESS;
 
 	if (op == BEACON_INIT)
-		lim_send_beacon_ind(session->mac_ctx, session);
+		lim_send_beacon_ind(session->mac_ctx, session, REASON_DEFAULT);
 	else if (op == BEACON_CSA)
 		lim_send_csa_restart_resp(session->mac_ctx, session);
 
@@ -8683,7 +8684,7 @@
 
 void lim_send_beacon(tpAniSirGlobal mac_ctx, tpPESession session)
 {
-	lim_send_beacon_ind(mac_ctx, session);
+	lim_send_beacon_ind(mac_ctx, session, REASON_DEFAULT);
 }
 
 void lim_ndi_mlme_vdev_up_transition(tpPESession session)
diff --git a/core/mac/src/pe/sch/sch_api.c b/core/mac/src/pe/sch/sch_api.c
index d37f17d..f3185b7 100644
--- a/core/mac/src/pe/sch/sch_api.c
+++ b/core/mac/src/pe/sch/sch_api.c
@@ -76,42 +76,16 @@
 	return QDF_STATUS_SUCCESS;
 }
 
-/* --------------------------------------------------------------------------- */
-
-/**
- * sch_send_beacon_req
- *
- * FUNCTION:
- *
- * LOGIC:
- * 1) SCH received SIR_SCH_BEACON_GEN_IND
- * 2) SCH updates TIM IE and other beacon related IE's
- * 3) SCH sends WMA_SEND_BEACON_REQ to HAL. HAL then copies the beacon
- *    template to memory
- *
- * ASSUMPTIONS:
- * Memory allocation is reqd to send this message and SCH allocates memory.
- * The assumption is that HAL will "free" this memory.
- *
- * NOTE:
- *
- * @param pMac global
- *
- * @param beaconPayload
- *
- * @param size - Length of the beacon
- *
- * @return QDF_STATUS
- */
 QDF_STATUS sch_send_beacon_req(tpAniSirGlobal pMac, uint8_t *beaconPayload,
-			       uint16_t size, tpPESession psessionEntry)
+			       uint16_t size, tpPESession psessionEntry,
+			       enum sir_bcn_update_reason reason)
 {
 	struct scheduler_msg msgQ = {0};
 	tpSendbeaconParams beaconParams = NULL;
 	QDF_STATUS retCode;
 
-	pe_debug("Indicating HAL to copy the beacon template [%d bytes] to memory",
-		size);
+	pe_debug("Indicating HAL to copy the beacon template [%d bytes] to memory, reason %d",
+		size, reason);
 
 	if (LIM_IS_AP_ROLE(psessionEntry) &&
 	   (pMac->sch.schObject.fBeaconChanged)) {
@@ -151,6 +125,9 @@
 		}
 	}
 
+	beaconParams->vdev_id = psessionEntry->smeSessionId;
+	beaconParams->reason = reason;
+
 	/* p2pIeOffset should be atleast greater than timIeOffset */
 	if ((pMac->sch.schObject.p2pIeOffset != 0) &&
 	    (pMac->sch.schObject.p2pIeOffset <
diff --git a/core/mac/src/pe/sch/sch_beacon_gen.c b/core/mac/src/pe/sch/sch_beacon_gen.c
index f54a1bd..537450c 100644
--- a/core/mac/src/pe/sch/sch_beacon_gen.c
+++ b/core/mac/src/pe/sch/sch_beacon_gen.c
@@ -889,26 +889,20 @@
 	IeBitmap[index] = temp;
 }
 
-/* -------------------------------------------------------------------- */
 /**
- * write_beacon_to_memory
+ * write_beacon_to_memory() - send the beacon to the wma
+ * @pMac: pointer to mac structure
+ * @size: Size of the beacon to write to memory
+ * @length: Length field of the beacon to write to memory
+ * @psessionEntry: pe session
+ * @reason: beacon update reason
  *
- * FUNCTION:
- *
- * LOGIC:
- *
- * ASSUMPTIONS:
- *
- * NOTE:
- *
- * @param None
- * @param size    Size of the beacon to write to memory
- * @param length Length field of the beacon to write to memory
- * @return None
+ * return: success: QDF_STATUS_SUCCESS failure: QDF_STATUS_E_FAILURE
  */
-
-static void write_beacon_to_memory(tpAniSirGlobal pMac, uint16_t size,
-				   uint16_t length, tpPESession psessionEntry)
+static QDF_STATUS write_beacon_to_memory(tpAniSirGlobal pMac, uint16_t size,
+					 uint16_t length,
+					 tpPESession psessionEntry,
+					 enum sir_bcn_update_reason reason)
 {
 	uint16_t i;
 	tpAniBeaconStruct pBeacon;
@@ -931,7 +925,7 @@
 		pBeacon->beaconLength = (uint32_t) size - sizeof(uint32_t);
 
 	if (!pMac->sch.schObject.fBeaconChanged)
-		return;
+		return QDF_STATUS_E_FAILURE;
 
 	/*
 	 * Copy beacon data to SoftMAC shared memory...
@@ -940,12 +934,13 @@
 
 	size = (size + 3) & (~3);
 	status = sch_send_beacon_req(pMac, psessionEntry->pSchBeaconFrameBegin,
-				     size, psessionEntry);
+				     size, psessionEntry, reason);
 	if (QDF_IS_STATUS_ERROR(status))
 		pe_err("sch_send_beacon_req() returned an error %d, size %d",
 		       status, size);
-
 	pMac->sch.schObject.fBeaconChanged = 0;
+
+	return status;
 }
 
 /**
@@ -1000,31 +995,19 @@
 
 	*pPtr = ptr;
 }
-/* -------------------------------------------------------------------- */
-/**
- * @function: SchProcessPreBeaconInd
- *
- * @brief : Process the PreBeacon Indication from the Lim
- *
- * ASSUMPTIONS:
- *
- * NOTE:
- *
- * @param : pMac - tpAniSirGlobal
- *
- * @return None
- */
 
-void sch_process_pre_beacon_ind(tpAniSirGlobal pMac,
-				struct scheduler_msg *limMsg)
+QDF_STATUS sch_process_pre_beacon_ind(tpAniSirGlobal pMac,
+				      struct scheduler_msg *limMsg,
+				      enum sir_bcn_update_reason reason)
 {
 	tpBeaconGenParams pMsg = (tpBeaconGenParams) limMsg->bodyptr;
 	uint32_t beaconSize;
 	tpPESession psessionEntry;
 	uint8_t sessionId;
+	QDF_STATUS status = QDF_STATUS_E_FAILURE;
 
 	psessionEntry = pe_find_session_by_bssid(pMac, pMsg->bssId, &sessionId);
-	if (psessionEntry == NULL) {
+	if (!psessionEntry) {
 		pe_err("session lookup fails");
 		goto end;
 	}
@@ -1043,12 +1026,13 @@
 	case eLIM_STA_IN_IBSS_ROLE:
 		/* generate IBSS parameter set */
 		if (psessionEntry->statypeForBss == STA_ENTRY_SELF)
-			write_beacon_to_memory(pMac, (uint16_t) beaconSize,
-					       (uint16_t) beaconSize,
-					       psessionEntry);
+			status =
+			    write_beacon_to_memory(pMac, (uint16_t) beaconSize,
+						   (uint16_t) beaconSize,
+						   psessionEntry, reason);
 		else
 			pe_err("can not send beacon for PEER session entry");
-			break;
+		break;
 
 	case eLIM_AP_ROLE: {
 		uint8_t *ptr =
@@ -1060,9 +1044,10 @@
 			sch_generate_tim(pMac, &ptr, &timLength,
 					 psessionEntry->dtimPeriod);
 			beaconSize += 2 + timLength;
-			write_beacon_to_memory(pMac, (uint16_t) beaconSize,
-					       (uint16_t) beaconSize,
-					       psessionEntry);
+			status =
+			    write_beacon_to_memory(pMac, (uint16_t) beaconSize,
+						   (uint16_t) beaconSize,
+						   psessionEntry, reason);
 		} else
 			pe_err("can not send beacon for PEER session entry");
 			}
@@ -1074,6 +1059,7 @@
 	}
 
 end:
-		qdf_mem_free(pMsg);
+	qdf_mem_free(pMsg);
 
-	}
+	return status;
+}