[WCNCR00148136] softap: add dfs test cmd and fix weather cac bug

[Description]
Add dfs test cmd and fix weather cac bug

Change-Id: I293bb3a593e84d991da944b9544922e9ac00cad9
Feature: softap
Signed-off-by: Chun Lee <chun.lee@mediatek.com>
CR-Id: WCNCR00148136
diff --git a/include/mgmt/p2p_func.h b/include/mgmt/p2p_func.h
index f59400e..c194e09 100644
--- a/include/mgmt/p2p_func.h
+++ b/include/mgmt/p2p_func.h
@@ -144,6 +144,12 @@
 VOID p2pFuncDfsSwitchCh(IN P_ADAPTER_T prAdapter, IN P_BSS_INFO_T prBssInfo, IN P2P_CHNL_REQ_INFO_T rP2pChnlReqInfo);
 
 BOOLEAN p2pFuncCheckWeatherRadarBand(IN P_P2P_CHNL_REQ_INFO_T prChnlReqInfo);
+
+INT_32 p2pFuncSetManualCacTime(IN UINT_32 u4ManualCacTime);
+
+UINT_32 p2pFuncGetManualCacTime(VOID);
+
+BOOLEAN p2pFuncIsManualCac(VOID);
 #endif
 
 VOID p2pFuncSetChannel(IN P_ADAPTER_T prAdapter, IN UINT_8 ucRoleIdx, IN P_RF_CHANNEL_INFO_T prRfChannelInfo);
diff --git a/mgmt/p2p_func.c b/mgmt/p2p_func.c
index 3c4272c..6cc0ca7 100644
--- a/mgmt/p2p_func.c
+++ b/mgmt/p2p_func.c
@@ -78,6 +78,11 @@
 
 };
 
+#if (CFG_SUPPORT_DFS_MASTER == 1)
+BOOLEAN g_fgManualCac = FALSE;
+UINT_32 g_u4ManualCacTime;
+#endif
+
 static VOID
 p2pFuncParseBeaconVenderId(IN P_ADAPTER_T prAdapter, IN PUINT_8 pucIE,
 			   IN P_P2P_SPECIFIC_BSS_INFO_T prP2pSpecificBssInfo, IN UINT_8 ucRoleIndex);
@@ -1118,19 +1123,43 @@
 	eChannelWidth = prChnlReqInfo->eChannelWidth;
 	eChnlSco = prChnlReqInfo->eChnlSco;
 
-	if (eChannelWidth == VHT_OP_CHANNEL_WIDTH_80) {
-		if (ucCenterFreqS1 >= 120 && ucCenterFreqS1 <= 128)
-			return TRUE;
-	} else {
-		if ((ucReqChnlNum >= 120 && ucReqChnlNum <= 128))
-			return TRUE;
-		else if (ucReqChnlNum == 116 && eChnlSco == CHNL_EXT_SCA) /* ch116, 120 BW40 */
-			return TRUE;
+	if (rlmDomainGetDfsRegion() == NL80211_DFS_ETSI) {
+		if (eChannelWidth == VHT_OP_CHANNEL_WIDTH_80) {
+			if (ucCenterFreqS1 >= 120 && ucCenterFreqS1 <= 128)
+				return TRUE;
+		} else {
+			if ((ucReqChnlNum >= 120 && ucReqChnlNum <= 128))
+				return TRUE;
+			else if (ucReqChnlNum == 116 && eChnlSco == CHNL_EXT_SCA) /* ch116, 120 BW40 */
+				return TRUE;
+		}
 	}
 
 	return FALSE;
 }
 
+INT_32 p2pFuncSetManualCacTime(IN UINT_32 u4ManualCacTime)
+{
+	WLAN_STATUS i4Status = WLAN_STATUS_SUCCESS;
+
+	g_fgManualCac = TRUE;
+
+	g_u4ManualCacTime = u4ManualCacTime * 1000;
+
+	DBGLOG(P2P, INFO, "p2pFuncSetManualCacTime: g_u4ManualCacTime = %dsec\n", g_u4ManualCacTime/1000);
+
+	return i4Status;
+}
+
+UINT_32 p2pFuncGetManualCacTime(VOID)
+{
+	return g_u4ManualCacTime;
+}
+
+BOOLEAN p2pFuncIsManualCac(VOID)
+{
+	return g_fgManualCac;
+}
 #endif
 
 #if 0
diff --git a/mgmt/p2p_role_fsm.c b/mgmt/p2p_role_fsm.c
index f43bec0..cb166d2 100644
--- a/mgmt/p2p_role_fsm.c
+++ b/mgmt/p2p_role_fsm.c
@@ -1982,6 +1982,9 @@
 				else
 					u4CacTime = prP2pRoleFsmInfo->rChnlReqInfo.u4MaxInterval;
 
+				if (p2pFuncIsManualCac())
+					u4CacTime = p2pFuncGetManualCacTime();
+
 				cnmTimerStartTimer(prAdapter, &(prP2pRoleFsmInfo->rP2pRoleFsmTimeoutTimer),
 					u4CacTime);
 
diff --git a/os/linux/gl_ate_agent.c b/os/linux/gl_ate_agent.c
index e80b992..4cf6dc2 100644
--- a/os/linux/gl_ate_agent.c
+++ b/os/linux/gl_ate_agent.c
@@ -174,6 +174,7 @@
 	{"TxPower", SetTxTargetPower},
 #if (CFG_SUPPORT_DFS_MASTER == 1)
 	{"RDDReport", SetRddReport},
+	{"ByPassCac", SetByPassCac},
 #endif
 
 	{NULL,}
@@ -2016,7 +2017,7 @@
 #if (CFG_SUPPORT_DFS_MASTER == 1)
 /*----------------------------------------------------------------------------*/
 /*!
-* \brief  This routine is called to Set Tx Power.
+* \brief  This routine is called to Set RDD Report
 *
 * \param[in] prNetDev		Pointer to the Net Device
 * \param[in] prInBuf		A pointer to the command string buffer
@@ -2050,6 +2051,44 @@
 
 	return i4Status;
 }
+
+
+/*----------------------------------------------------------------------------*/
+/*!
+* \brief  This routine is called to Set By Pass CAC.
+*
+* \param[in] prNetDev		Pointer to the Net Device
+* \param[in] prInBuf		A pointer to the command string buffer
+* \param[out] None
+*
+* \retval 0				On success.
+* \retval -EINVAL			If invalid argument.
+*/
+/*----------------------------------------------------------------------------*/
+int SetByPassCac(struct net_device *prNetDev, UINT_8 *prInBuf)
+{
+	INT_32 i4Status;
+	INT_32 rv;
+	int byPassCacTime;
+	UINT_8 ucByPassCacTime;
+
+	DBGLOG(REQ, INFO, "MT6632 : ATE_AGENT iwpriv Set By Pass Cac, buf: %s\n", prInBuf);
+
+	rv = kstrtoint(prInBuf, 0, &byPassCacTime);
+
+	DBGLOG(REQ, INFO, "MT6632 : ATE_AGENT iwpriv Set By Pass Cac, prInBuf: %s\n", prInBuf);
+	DBGLOG(INIT, ERROR, "MT6632 : ATE_AGENT iwpriv Set By Pass Cac : %dsec\n", byPassCacTime);
+
+	ucByPassCacTime = (UINT_8) byPassCacTime;
+
+	if (rv == 0)
+		i4Status = p2pFuncSetManualCacTime(ucByPassCacTime);
+	else
+		return -EINVAL;
+
+	return i4Status;
+}
+
 #endif
 
 /*----------------------------------------------------------------------------*/
diff --git a/os/linux/gl_p2p.c b/os/linux/gl_p2p.c
index 68e6dd7..419fe81 100644
--- a/os/linux/gl_p2p.c
+++ b/os/linux/gl_p2p.c
@@ -1301,7 +1301,7 @@
 	/* 2. carrier on & start TX queue */
 	/*DFS todo 20161220_DFS*/
 #if (CFG_SUPPORT_DFS_MASTER == 1)
-	if (mode != RUNNING_AP_MODE) {
+	if (prDev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP) {
 		netif_carrier_on(prDev);
 		netif_tx_start_all_queues(prDev);
 	}
diff --git a/os/linux/gl_p2p_init.c b/os/linux/gl_p2p_init.c
index 71459ec..daa686e 100644
--- a/os/linux/gl_p2p_init.c
+++ b/os/linux/gl_p2p_init.c
@@ -96,7 +96,7 @@
 */
 static PUCHAR ifname = P2P_INF_NAME;
 static PUCHAR ifname2 = P2P_INF_NAME;
-UINT_16 mode = RUNNING_P2P_MODE;
+static UINT_16 mode = RUNNING_P2P_MODE;
 
 
 /*******************************************************************************
diff --git a/os/linux/include/gl_ate_agent.h b/os/linux/include/gl_ate_agent.h
index 560820f..c1403df 100644
--- a/os/linux/include/gl_ate_agent.h
+++ b/os/linux/include/gl_ate_agent.h
@@ -189,6 +189,7 @@
 
 #if (CFG_SUPPORT_DFS_MASTER == 1)
 int SetRddReport(struct net_device *prNetDev, UINT_8 *prInBuf);
+int SetByPassCac(struct net_device *prNetDev, UINT_8 *prInBuf);
 #endif
 
 
diff --git a/os/linux/include/gl_p2p_os.h b/os/linux/include/gl_p2p_os.h
index 8c34bd7..e6cf890 100644
--- a/os/linux/include/gl_p2p_os.h
+++ b/os/linux/include/gl_p2p_os.h
@@ -106,7 +106,6 @@
 extern struct net_device *g_P2pPrDev;
 extern struct wireless_dev *gprP2pWdev;
 extern struct wireless_dev *gprP2pRoleWdev[KAL_P2P_NUM];
-extern UINT_16 mode;
 
 /*******************************************************************************
 *                           P R I V A T E   D A T A