qcacld-3.0: Add support for the NAN config items

Currently there is no inis for NAN component:
1. To configure the keep alive period for the
NDI interface.
2. To enable/disable discovery of NAN cluster with
Master Preference (MP) as 0 when a new device is
enabling NAN.

Add ini support to configure above mentioned values.

Change-Id: I47b67eb89fb8849960a9f492d2909e45b96308f3
CRs-Fixed: 2617839
diff --git a/components/nan/core/src/nan_main_i.h b/components/nan/core/src/nan_main_i.h
index 4c8e55d..8a1a397 100644
--- a/components/nan/core/src/nan_main_i.h
+++ b/components/nan/core/src/nan_main_i.h
@@ -82,6 +82,10 @@
  * @ndi_mac_randomize: Randomize NAN datapath interface MAC
  * @ndp_inactivity_timeout: NDP inactivity timeout
  * @nan_separate_iface_support: To supports separate iface creation for NAN
+ * @ndp_keep_alive_period: To configure duration of how many seconds to
+ * wait to kickout peer if peer is not reachable
+ * @support_mp0_discovery: To support discovery of NAN cluster with Master
+ * Preference (MP) as 0 when a new device is enabling NAN
  */
 struct nan_cfg_params {
 	bool enable;
@@ -89,6 +93,8 @@
 	bool ndi_mac_randomize;
 	uint16_t ndp_inactivity_timeout;
 	bool nan_separate_iface_support;
+	uint16_t ndp_keep_alive_period;
+	bool support_mp0_discovery;
 };
 
 /**
diff --git a/components/nan/dispatcher/inc/cfg_nan.h b/components/nan/dispatcher/inc/cfg_nan.h
index 1665c32..9537794 100644
--- a/components/nan/dispatcher/inc/cfg_nan.h
+++ b/components/nan/dispatcher/inc/cfg_nan.h
@@ -142,8 +142,58 @@
 						    CFG_VALUE_OR_DEFAULT, \
 						    "NDP Auto Terminate time")
 
+/*
+ * <ini>
+ * gNdpKeepAlivePeriod - To configure duration of how many seconds
+ * to wait to kickout peer if peer is not reachable.
+ *
+ * @Min: 10
+ * @Max: 30
+ * @Default: 20
+ *
+ * Related: None
+ *
+ * Supported Feature: NAN
+ *
+ * Usage: External
+ *
+ * </ini>
+ */
+
+#define CFG_NDP_KEEP_ALIVE_PERIOD CFG_INI_UINT( \
+			"gNdpKeepAlivePeriod", \
+			10, \
+			30, \
+			20, \
+			CFG_VALUE_OR_DEFAULT, \
+			"Keep alive timeout of a peer")
+
+/*
+ * <ini>
+ * gSupportMp0Discovery - To support discovery of NAN cluster with
+ * Master Preference (MP) as 0 when a new device is enabling NAN.
+ *
+ * @Min: 0
+ * @Max: 1
+ * @Default: 0
+ *
+ * Related: None
+ *
+ * Supported Feature: NAN
+ *
+ * Usage: External
+ *
+ * </ini>
+ */
+#define CFG_SUPPORT_MP0_DISCOVERY CFG_INI_BOOL( \
+			"gSupportMp0Discovery", \
+			1, \
+			"Enable/Disable discovery of NAN cluster with Master Preference (MP) as 0")
+
 #ifdef WLAN_FEATURE_NAN
-#define CFG_NAN_DISC CFG(CFG_NAN_ENABLE)
+#define CFG_NAN_DISC CFG(CFG_NAN_ENABLE) \
+			CFG(CFG_NDP_KEEP_ALIVE_PERIOD) \
+			CFG(CFG_SUPPORT_MP0_DISCOVERY)
 #define CFG_NAN_DP      CFG(CFG_NAN_DATAPATH_ENABLE) \
 			CFG(CFG_NAN_RANDOMIZE_NDI_MAC) \
 			CFG(CFG_NAN_NDP_INACTIVITY_TIMEOUT) \
diff --git a/components/nan/dispatcher/inc/cfg_nan_api.h b/components/nan/dispatcher/inc/cfg_nan_api.h
index 0e1d26c..3aed3d6 100644
--- a/components/nan/dispatcher/inc/cfg_nan_api.h
+++ b/components/nan/dispatcher/inc/cfg_nan_api.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved.
+ * Copyright (c) 2018-2020 The Linux Foundation. All rights reserved.
  *
  * Permission to use, copy, modify, and/or distribute this software for
  * any purpose with or without fee is hereby granted, provided that the
@@ -64,6 +64,25 @@
 QDF_STATUS cfg_nan_get_ndp_inactivity_timeout(struct wlan_objmgr_psoc *psoc,
 					      uint16_t *val);
 
+/**
+ * cfg_nan_get_ndp_keepalive_period() - get NDP keepalive period
+ * @psoc: pointer to psoc object
+ * @val: pointer to the value where keepalive period has to be copied to
+ *
+ * Return: QDF_STATUS
+ */
+QDF_STATUS cfg_nan_get_ndp_keepalive_period(struct wlan_objmgr_psoc *psoc,
+					    uint16_t *val);
+
+/**
+ * cfg_nan_get_support_mp0_discovery() - get value of config support mp0
+ * discovery
+ * @psoc: pointer to psoc object
+ *
+ * Return: Value of config join clustur with mp
+ */
+bool cfg_nan_get_support_mp0_discovery(struct wlan_objmgr_psoc *psoc);
+
 #else
 static inline bool cfg_nan_get_enable(struct wlan_objmgr_psoc *psoc)
 {
@@ -86,6 +105,20 @@
 {
 	return QDF_STATUS_SUCCESS;
 }
+
+static inline
+QDF_STATUS cfg_nan_get_ndp_keepalive_period(struct wlan_objmgr_psoc *psoc,
+					    uint16_t *val)
+{
+	return QDF_STATUS_SUCCESS;
+}
+
+static inline bool cfg_nan_get_support_mp0_discovery(
+						struct wlan_objmgr_psoc *psoc)
+{
+	return false;
+}
+
 #endif
 
 #endif
diff --git a/components/nan/dispatcher/src/cfg_nan.c b/components/nan/dispatcher/src/cfg_nan.c
index 78ecf07..8995a45 100644
--- a/components/nan/dispatcher/src/cfg_nan.c
+++ b/components/nan/dispatcher/src/cfg_nan.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved.
+ * Copyright (c) 2018-2020 The Linux Foundation. All rights reserved.
  *
  * Permission to use, copy, modify, and/or distribute this software for
  * any purpose with or without fee is hereby granted, provided that the
@@ -81,3 +81,29 @@
 	return QDF_STATUS_SUCCESS;
 }
 
+QDF_STATUS cfg_nan_get_ndp_keepalive_period(struct wlan_objmgr_psoc *psoc,
+					    uint16_t *val)
+{
+	struct nan_psoc_priv_obj *nan_obj = cfg_nan_get_priv_obj(psoc);
+
+	if (!nan_obj) {
+		nan_err("NAN obj null");
+		return QDF_STATUS_E_INVAL;
+	}
+
+	*val = nan_obj->cfg_param.ndp_keep_alive_period;
+	return QDF_STATUS_SUCCESS;
+}
+
+bool cfg_nan_get_support_mp0_discovery(struct wlan_objmgr_psoc *psoc)
+{
+	struct nan_psoc_priv_obj *nan_obj = cfg_nan_get_priv_obj(psoc);
+
+	if (!nan_obj) {
+		nan_err("NAN obj null");
+		return false;
+	}
+
+	return nan_obj->cfg_param.support_mp0_discovery;
+}
+
diff --git a/components/nan/dispatcher/src/nan_ucfg_api.c b/components/nan/dispatcher/src/nan_ucfg_api.c
index 479c222..3237a7f 100644
--- a/components/nan/dispatcher/src/nan_ucfg_api.c
+++ b/components/nan/dispatcher/src/nan_ucfg_api.c
@@ -48,6 +48,12 @@
 			 struct nan_psoc_priv_obj *nan_obj)
 {
 	nan_obj->cfg_param.enable = cfg_get(psoc, CFG_NAN_ENABLE);
+	nan_obj->cfg_param.support_mp0_discovery =
+					cfg_get(psoc,
+						CFG_SUPPORT_MP0_DISCOVERY);
+	nan_obj->cfg_param.ndp_keep_alive_period =
+					cfg_get(psoc,
+						CFG_NDP_KEEP_ALIVE_PERIOD);
 }
 
 /**
diff --git a/core/hdd/src/wlan_hdd_main.c b/core/hdd/src/wlan_hdd_main.c
index 0c3993a..bc092fc 100644
--- a/core/hdd/src/wlan_hdd_main.c
+++ b/core/hdd/src/wlan_hdd_main.c
@@ -178,6 +178,7 @@
 #include "mac_init_api.h"
 #include "wlan_pkt_capture_ucfg_api.h"
 #include <wlan_hdd_sar_limits.h>
+#include "cfg_nan_api.h"
 
 #ifdef MODULE
 #define WLAN_MODULE_NAME  module_name(THIS_MODULE)
@@ -4808,6 +4809,13 @@
 		hdd_objmgr_put_vdev(vdev);
 	}
 
+	if (QDF_NAN_DISC_MODE == adapter->device_mode) {
+		sme_cli_set_command(
+		adapter->vdev_id,
+		WMI_VDEV_PARAM_ALLOW_NAN_INITIAL_DISCOVERY_OF_MP0_CLUSTER,
+		cfg_nan_get_support_mp0_discovery(hdd_ctx->psoc),
+		VDEV_CMD);
+	}
 	hdd_store_nss_chains_cfg_in_vdev(adapter);
 
 	hdd_nofl_debug("vdev %d created successfully", adapter->vdev_id);
diff --git a/core/hdd/src/wlan_hdd_nan_datapath.c b/core/hdd/src/wlan_hdd_nan_datapath.c
index 74f0db8..1b05577 100644
--- a/core/hdd/src/wlan_hdd_nan_datapath.c
+++ b/core/hdd/src/wlan_hdd_nan_datapath.c
@@ -693,6 +693,7 @@
 	struct csr_roam_info *roam_info;
 	struct bss_description tmp_bss_descp = {0};
 	uint16_t ndp_inactivity_timeout = 0;
+	uint16_t ndp_keep_alive_period;
 	struct qdf_mac_addr bc_mac_addr = QDF_MAC_ADDR_BCAST_INIT;
 
 	hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
@@ -733,6 +734,14 @@
 		sme_cli_set_command(adapter->vdev_id,
 				    WMI_VDEV_PARAM_NDP_INACTIVITY_TIMEOUT,
 				    ndp_inactivity_timeout, VDEV_CMD);
+
+		if (QDF_IS_STATUS_SUCCESS(cfg_nan_get_ndp_keepalive_period(
+						hdd_ctx->psoc,
+						&ndp_keep_alive_period)))
+			sme_cli_set_command(
+				adapter->vdev_id,
+				WMI_VDEV_PARAM_NDP_KEEPALIVE_TIMEOUT,
+				ndp_keep_alive_period, VDEV_CMD);
 	} else {
 		hdd_alert("NDI interface creation failed with reason %d",
 			ndi_rsp->reason /* create_reason */);