wlan: Get bt_profile status from wcnss driver

bt_profile entry in sysfs is created by wcnss driver,
so get the status of bt_profile from wcnss driver and
process it in hdd.

Change-Id: I526473dbecbb12ca454e99bfe73dbc85fee4ea17
CRs-Fixed: 2800939
diff --git a/CORE/HDD/inc/wlan_hdd_main.h b/CORE/HDD/inc/wlan_hdd_main.h
index 31f5c6a..c4c33ae 100644
--- a/CORE/HDD/inc/wlan_hdd_main.h
+++ b/CORE/HDD/inc/wlan_hdd_main.h
@@ -2433,4 +2433,30 @@
 #else
 void hdd_fill_last_rx(hdd_adapter_t *adapter);
 #endif
+
+#ifdef FEATURE_WLAN_SW_PTA
+/**
+ * hdd_process_bt_sco_profile - process BT SCO profile
+ * @hdd_ctx: pointer to HDD context
+ * @bt_enabled: status of BT
+ * @bt_sco: status of SCO
+ *
+ * Return: 0 on success, error on failure
+ */
+int hdd_process_bt_sco_profile(hdd_context_t *hdd_ctx,
+			       bool bt_enabled, bool bt_sco);
+
+/**
+ * hdd_is_sw_pta_enabled - is sw pta enabled
+ * @hdd_ctx: pointer to HDD context
+ *
+ * Return: bool
+ */
+bool hdd_is_sw_pta_enabled(hdd_context_t *hdd_ctx);
+#else
+static inline bool hdd_is_sw_pta_enabled(hdd_context_t *hdd_ctx)
+{
+	return 0;
+}
+#endif
 #endif    // end #if !defined( WLAN_HDD_MAIN_H )
diff --git a/CORE/HDD/src/wlan_hdd_cfg80211.c b/CORE/HDD/src/wlan_hdd_cfg80211.c
index ad272eb..553f73c 100644
--- a/CORE/HDD/src/wlan_hdd_cfg80211.c
+++ b/CORE/HDD/src/wlan_hdd_cfg80211.c
@@ -620,6 +620,13 @@
 };
 #endif /* WLAN_NL80211_TESTMODE */
 
+#ifdef FEATURE_WLAN_SW_PTA
+bool hdd_is_sw_pta_enabled(hdd_context_t *hdd_ctx)
+{
+	return hdd_ctx->cfg_ini->is_sw_pta_enabled;
+}
+#endif
+
 #ifdef FEATURE_WLAN_CH_AVOID
 /*
  * FUNCTION: wlan_hdd_send_avoid_freq_event
@@ -15810,7 +15817,7 @@
      * for every second, so indicating framework that scan is aborted
      * and return success.
      */
-    if (pHddCtx->cfg_ini->is_sw_pta_enabled && pHddCtx->is_sco_enabled) {
+    if (hdd_is_sw_pta_enabled(pHddCtx) && pHddCtx->is_sco_enabled) {
         VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
                   FL("BT SCO operation in progress"));
         hdd_cfg80211_scan_done(pAdapter, request, true);
@@ -16338,7 +16345,7 @@
     /**
      * If sw pta is enabled, new connections should not allowed.
      */
-    if (pHddCtx->cfg_ini->is_sw_pta_enabled && pHddCtx->is_sco_enabled) {
+    if (hdd_is_sw_pta_enabled(pHddCtx) && pHddCtx->is_sco_enabled) {
         hddLog(VOS_TRACE_LEVEL_ERROR, "%s: BT SCO operation in progress",
                __func__);
         return -EINVAL;
@@ -20101,7 +20108,7 @@
     /**
      * If sw pta is enabled, scan results should not send to framework.
      */
-    if (pHddCtx->cfg_ini->is_sw_pta_enabled && pHddCtx->is_sco_enabled) {
+    if (hdd_is_sw_pta_enabled(pHddCtx) && pHddCtx->is_sco_enabled) {
         VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
                   FL("BT SCO operation in progress"));
         return;
diff --git a/CORE/HDD/src/wlan_hdd_main.c b/CORE/HDD/src/wlan_hdd_main.c
index 8d311cc..9c44e86 100644
--- a/CORE/HDD/src/wlan_hdd_main.c
+++ b/CORE/HDD/src/wlan_hdd_main.c
@@ -3909,7 +3909,7 @@
 	hdd_ctx = (hdd_context_t*)vos_get_context(VOS_MODULE_ID_HDD, vos_ctx);
 	if (!hdd_ctx) {
 		hddLog(VOS_TRACE_LEVEL_FATAL,
-		       "%s: HDD context is Null",__func__);
+		       "%s: HDD context is Null", __func__);
 		return;
 	}
 
@@ -3925,8 +3925,8 @@
 	complete(&hdd_ctx->sw_pta_comp);
 }
 
-static ssize_t __hdd_process_bt_sco_profile(hdd_context_t *hdd_ctx,
-					    char *profile_mode)
+int hdd_process_bt_sco_profile(hdd_context_t *hdd_ctx,
+			       bool bt_enabled, bool bt_sco)
 {
 	tpAniSirGlobal mac_ctx = PMAC_STRUCT(hdd_ctx->hHal);
 	hdd_station_ctx_t *hdd_sta_ctx;
@@ -3941,24 +3941,20 @@
 		return -EINVAL;
 	}
 
-	if (!strcmp(profile_mode, "ENABLE")) {
+	if (bt_sco) {
 		if (hdd_ctx->is_sco_enabled) {
-			hddLog(VOS_TRACE_LEVEL_ERROR, "%s: BT SCO is already enabled",
-			       __func__);
+			hddLog(VOS_TRACE_LEVEL_ERROR,
+			       "%s: BT SCO is already enabled", __func__);
 			return 0;
 		}
 		sco_status = true;
-	} else if (!strcmp(profile_mode, "DISABLE")) {
+	} else {
 		if (!hdd_ctx->is_sco_enabled) {
-			hddLog(VOS_TRACE_LEVEL_ERROR, "%s: BT SCO is already disabled",
-			       __func__);
+			hddLog(VOS_TRACE_LEVEL_ERROR,
+			       "%s: BT SCO is already disabled", __func__);
 			return 0;
 		}
 		sco_status = false;
-	} else {
-		hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid profile mode %s",
-		       __func__, profile_mode);
-		return -EINVAL;
 	}
 
 	INIT_COMPLETION(hdd_ctx->sw_pta_comp);
@@ -3981,7 +3977,7 @@
 		return -EINVAL;
 	}
 
-	if (!strcmp(profile_mode, "DISABLE")) {
+	if (!bt_sco) {
 		hdd_ctx->is_sco_enabled = false;
 		mac_ctx->isCoexScoIndSet = 0;
 		return 0;
@@ -4032,6 +4028,23 @@
 
 	return 0;
 }
+
+static void hdd_init_sw_pta(hdd_context_t *hdd_ctx)
+{
+	init_completion(&hdd_ctx->sw_pta_comp);
+}
+
+static void hdd_deinit_sw_pta(hdd_context_t *hdd_ctx)
+{
+	complete(&hdd_ctx->sw_pta_comp);
+}
+#else
+static void hdd_init_sw_pta(hdd_context_t *hdd_ctx)
+{
+}
+static void hdd_deinit_sw_pta(hdd_context_t *hdd_ctx)
+{
+}
 #endif
 
 static int hdd_driver_command(hdd_adapter_t *pAdapter,
@@ -12632,6 +12645,7 @@
       wlan_hdd_ftm_close(pHddCtx);
       goto free_hdd_ctx;
    }
+   hdd_deinit_sw_pta(pHddCtx);
 
    /* DeRegister with platform driver as client for Suspend/Resume */
    vosStatus = hddDeregisterPmOps(pHddCtx);
@@ -14752,6 +14766,8 @@
    hdd_assoc_registerFwdEapolCB(pVosContext);
 
    mutex_init(&pHddCtx->cache_channel_lock);
+
+   hdd_init_sw_pta(pHddCtx);
    goto success;
 
 err_open_cesium_nl_sock:
diff --git a/CORE/VOSS/inc/vos_api.h b/CORE/VOSS/inc/vos_api.h
index 60bf16c..38325b9 100644
--- a/CORE/VOSS/inc/vos_api.h
+++ b/CORE/VOSS/inc/vos_api.h
@@ -604,4 +604,25 @@
 VOS_STATUS vos_smd_open(const char *szname, WCTS_ControlBlockType* wcts_cb);
 
 void wlan_unregister_driver(void);
+
+#ifdef FEATURE_WLAN_SW_PTA
+/**
+ * vos_process_bt_profile - process BT profile
+ * @bt_enabled: status of BT
+ * @ble: status of BLE
+ * @a2dp: stautus of A2DP
+ * @bt_sco: status of SCO
+ *
+ * Return: 0 on success and error on failure
+ */
+int vos_process_bt_profile(bool bt_enabled, bool ble,
+			   bool a2dp, bool bt_sco);
+#else
+static inline int
+vos_process_bt_profile(bool bt_enabled, bool ble,
+		       bool a2dp, bool bt_sco)
+{
+	return -ENOTSUPP;
+}
+#endif /* FEATURE_WLAN_SW_PTA */
 #endif // if !defined __VOS_NVITEM_H
diff --git a/CORE/VOSS/src/vos_api.c b/CORE/VOSS/src/vos_api.c
index be63f54..8931d73 100644
--- a/CORE/VOSS/src/vos_api.c
+++ b/CORE/VOSS/src/vos_api.c
@@ -3986,6 +3986,42 @@
 {
 	wcnss_unregister_driver(&driver_ops);
 }
+
+#ifdef FEATURE_WLAN_SW_PTA
+int vos_process_bt_profile(bool bt_enabled, bool ble,
+			   bool a2dp, bool bt_sco)
+{
+	v_CONTEXT_t vos_ctx = vos_get_global_context(VOS_MODULE_ID_SYS, NULL);
+	hdd_context_t *hdd_ctx;
+	int ret;
+
+	if (!vos_ctx) {
+		VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
+			  "%s: Global VOS context is Null", __func__);
+		return -EINVAL;
+	}
+
+	hdd_ctx = vos_get_context(VOS_MODULE_ID_HDD, vos_ctx);
+	if (wlan_hdd_validate_context(hdd_ctx)) {
+		if (hdd_ctx && hdd_ctx->isLogpInProgress)
+			return -EAGAIN;
+		return -EINVAL;
+	}
+
+	if (!hdd_ctx->cfg_ini->is_sw_pta_enabled) {
+		VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
+			  "%s: sw pta is not enabled", __func__);
+		return -EINVAL;
+	}
+
+	ret = hdd_process_bt_sco_profile(hdd_ctx, bt_enabled, bt_sco);
+	if (ret)
+		VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
+			  "%s: Unable to process bt sco profile", __func__);
+
+	return ret;
+}
+#endif
 #else
 VOS_STATUS vos_smd_open(const char *szname, WCTS_ControlBlockType* wcts_cb)
 {
diff --git a/CORE/WDI/TRP/CTS/src/wlan_qct_wdi_cts.c b/CORE/WDI/TRP/CTS/src/wlan_qct_wdi_cts.c
index 2a68401..6994f5b 100644
--- a/CORE/WDI/TRP/CTS/src/wlan_qct_wdi_cts.c
+++ b/CORE/WDI/TRP/CTS/src/wlan_qct_wdi_cts.c
@@ -588,10 +588,16 @@
 
 int WCTS_bt_profile_state_process(void *priv, struct bt_profile_state *state)
 {
+	int ret;
+
 	WPAL_TRACE(eWLAN_MODULE_DAL_CTRL, eWLAN_PAL_TRACE_LEVEL_ERROR,
 		   "%s: Received bt_profile state update %s", __func__,
 		   state->bt_enabled ? "ENABLED" : "DISABLED");
-	return 0;
+
+	ret = vos_process_bt_profile(state->bt_enabled, state->bt_ble,
+				     state->bt_a2dp, state->bt_sco);
+
+	return ret;
 }
 #else
 void