[WCNCR00152848] softap: change dfs master shut down flow and dfs flag

[Description]
Change dfs master shut down flow and dfs flag
1. Add the timer to shut down dfs master
2. Change DFS master compile flag value
3. Enable DFS master by default with kernel version 3.13 or more recent

Change-Id: If68ff820eec2e92de57bfcba60db86819e776a35
Signed-off-by: Chun Lee <chun.lee@mediatek.com>
CR-Id: WCNCR00152848
Feature: softap
diff --git a/include/config.h b/include/config.h
index e29783b..479a106 100644
--- a/include/config.h
+++ b/include/config.h
@@ -155,7 +155,7 @@
 #define CFG_SUPPORT_RRM             0	/* Radio Reasource Measurement (802.11k) */
 #define CFG_SUPPORT_DFS             1	/* DFS (802.11h) */
 #ifndef CFG_SUPPORT_DFS_MASTER
-#define CFG_SUPPORT_DFS_MASTER      0
+#define CFG_SUPPORT_DFS_MASTER      1
 #endif
 
 #if (CFG_SUPPORT_DFS == 1)	/* Add by Enlai */
diff --git a/include/mgmt/p2p_role.h b/include/mgmt/p2p_role.h
index 917c684..6d288fc 100644
--- a/include/mgmt/p2p_role.h
+++ b/include/mgmt/p2p_role.h
@@ -317,6 +317,10 @@
 	/* FSM Timer */
 	TIMER_T rP2pRoleFsmTimeoutTimer;
 
+#if (CFG_SUPPORT_DFS_MASTER == 1)
+	TIMER_T rDfsShutDownTimer;
+#endif
+
 	/* Packet filter for P2P module. */
 	UINT_32 u4P2pPacketFilter;
 
@@ -354,6 +358,8 @@
 VOID p2pRoleFsmRunEventSetNewChannel(IN P_ADAPTER_T prAdapter, IN P_MSG_HDR_T prMsgHdr);
 
 VOID p2pRoleFsmRunEventCsaDone(IN P_ADAPTER_T prAdapter, IN P_MSG_HDR_T prMsgHdr);
+
+VOID p2pRoleFsmRunEventDfsShutDownTimeout(IN P_ADAPTER_T prAdapter, IN ULONG ulParamPtr);
 #endif
 
 VOID p2pRoleFsmRunEventScanRequest(IN P_ADAPTER_T prAdapter, IN P_MSG_HDR_T prMsgHdr);
diff --git a/mgmt/p2p_role_fsm.c b/mgmt/p2p_role_fsm.c
index 2462247..ff21987 100644
--- a/mgmt/p2p_role_fsm.c
+++ b/mgmt/p2p_role_fsm.c
@@ -109,6 +109,13 @@
 				  &(prP2pRoleFsmInfo->rP2pRoleFsmTimeoutTimer),
 				  (PFN_MGMT_TIMEOUT_FUNC) p2pRoleFsmRunEventTimeout, (ULONG) prP2pRoleFsmInfo);
 
+#if (CFG_SUPPORT_DFS_MASTER == 1)
+		cnmTimerInitTimer(prAdapter,
+				  &(prP2pRoleFsmInfo->rDfsShutDownTimer),
+				  (PFN_MGMT_TIMEOUT_FUNC) p2pRoleFsmRunEventDfsShutDownTimeout,
+				  (ULONG) prP2pRoleFsmInfo);
+#endif
+
 		prP2pBssInfo = cnmGetBssInfoAndInit(prAdapter, NETWORK_TYPE_P2P, FALSE);
 
 		if (!prP2pBssInfo) {
@@ -247,6 +254,10 @@
 		/* ensure the timer be stopped */
 		cnmTimerStopTimer(prAdapter, &(prP2pRoleFsmInfo->rP2pRoleFsmTimeoutTimer));
 
+#if (CFG_SUPPORT_DFS_MASTER == 1)
+		cnmTimerStopTimer(prAdapter, &(prP2pRoleFsmInfo->rDfsShutDownTimer));
+#endif
+
 		if (prP2pRoleFsmInfo)
 			kalMemFree(prP2pRoleFsmInfo, VIR_MEM_TYPE, sizeof(P2P_ROLE_FSM_INFO_T));
 
@@ -446,6 +457,7 @@
 			p2pRoleFsmStateTransition(prAdapter, prP2pRoleFsmInfo, P2P_ROLE_STATE_IDLE);
 			kalP2PCacFinishedUpdate(prAdapter->prGlueInfo, prP2pRoleFsmInfo->ucRoleIndex);
 			p2pFuncSetDfsState(DFS_STATE_ACTIVE);
+			cnmTimerStartTimer(prAdapter, &(prP2pRoleFsmInfo->rDfsShutDownTimer), 5000);
 			break;
 #endif
 		default:
@@ -888,6 +900,13 @@
 			cnmTimerStopTimer(prAdapter, &(prP2pRoleFsmInfo->rP2pRoleFsmTimeoutTimer));
 		}
 
+#if (CFG_SUPPORT_DFS_MASTER == 1)
+		if (timerPendingTimer(&(prP2pRoleFsmInfo->rDfsShutDownTimer))) {
+			DBGLOG(P2P, INFO, "p2pRoleFsmRunEventStartAP: Stop DFS shut down timer.\n");
+			cnmTimerStopTimer(prAdapter, &(prP2pRoleFsmInfo->rDfsShutDownTimer));
+		}
+#endif
+
 #if CFG_SUPPORT_DBDC
 		cnmDbdcEnableDecision(prAdapter, prP2pBssInfo->ucBssIndex, prP2pConnReqInfo->rChannelInfo.eBand);
 		cnmGetDbdcCapability(prAdapter,
@@ -1139,6 +1158,11 @@
 			break;
 		}
 
+		if (timerPendingTimer(&(prP2pRoleFsmInfo->rDfsShutDownTimer))) {
+			DBGLOG(P2P, INFO, "p2pRoleFsmRunEventDfsCac: Stop DFS shut down timer.\n");
+			cnmTimerStopTimer(prAdapter, &(prP2pRoleFsmInfo->rDfsShutDownTimer));
+		}
+
 		prP2pBssInfo = prAdapter->aprBssInfo[prP2pRoleFsmInfo->ucBssIndex];
 
 		prP2pConnReqInfo = &(prP2pRoleFsmInfo->rConnReqInfo);
@@ -1235,6 +1259,8 @@
 
 		p2pFuncShowRadarInfo(prAdapter, prMsgP2pRddDetMsg->ucBssIndex);
 
+		cnmTimerStartTimer(prAdapter, &(prP2pRoleFsmInfo->rDfsShutDownTimer), 5000);
+
 	} while (FALSE);
 	if (prMsgHdr)
 		cnmMemFree(prAdapter, prMsgHdr);
@@ -1296,6 +1322,18 @@
 	if (prMsgHdr)
 		cnmMemFree(prAdapter, prMsgHdr);
 }				/*p2pRoleFsmRunEventCsaDone*/
+
+VOID p2pRoleFsmRunEventDfsShutDownTimeout(IN P_ADAPTER_T prAdapter, IN ULONG ulParamPtr)
+{
+	P_P2P_ROLE_FSM_INFO_T prP2pRoleFsmInfo = (P_P2P_ROLE_FSM_INFO_T) ulParamPtr;
+
+	DBGLOG(P2P, INFO, "p2pRoleFsmRunEventDfsShutDownTimeout: DFS shut down.\n");
+
+	p2pFuncSetDfsState(DFS_STATE_INACTIVE);
+	p2pFuncStopRdd(prAdapter, prP2pRoleFsmInfo->ucBssIndex);
+
+}				/* p2pRoleFsmRunEventDfsShutDownTimeout */
+
 #endif
 
 
diff --git a/os/linux/gl_p2p.c b/os/linux/gl_p2p.c
index 6044cbb..76ea3d4 100644
--- a/os/linux/gl_p2p.c
+++ b/os/linux/gl_p2p.c
@@ -160,8 +160,10 @@
 	.set_power_mgmt = mtk_p2p_cfg80211_set_power_mgmt,
 #if (CFG_SUPPORT_DFS_MASTER == 1)
 	.start_radar_detection = mtk_p2p_cfg80211_start_radar_detection,
+#if KERNEL_VERSION(3, 13, 0) <= CFG80211_VERSION_CODE
 	.channel_switch = mtk_p2p_cfg80211_channel_switch,
 #endif
+#endif
 #ifdef CONFIG_NL80211_TESTMODE
 	.testmode_cmd = mtk_p2p_cfg80211_testmode_cmd,
 #endif
diff --git a/os/linux/gl_p2p_cfg80211.c b/os/linux/gl_p2p_cfg80211.c
index 16b37be..b02e43c 100644
--- a/os/linux/gl_p2p_cfg80211.c
+++ b/os/linux/gl_p2p_cfg80211.c
@@ -1467,6 +1467,7 @@
 }
 #endif
 
+#if KERNEL_VERSION(3, 13, 0) <= CFG80211_VERSION_CODE
 int mtk_p2p_cfg80211_channel_switch(struct wiphy *wiphy, struct net_device *dev, struct cfg80211_csa_settings *params)
 {
 	P_GLUE_INFO_T prGlueInfo = (P_GLUE_INFO_T) NULL;
@@ -1630,6 +1631,7 @@
 	return i4Rslt;
 }
 #endif
+#endif
 
 #if 0
 struct cfg80211_beacon_data {
diff --git a/os/linux/gl_p2p_kal.c b/os/linux/gl_p2p_kal.c
index 938dfa3..43f88f4 100644
--- a/os/linux/gl_p2p_kal.c
+++ b/os/linux/gl_p2p_kal.c
@@ -1332,8 +1332,13 @@
 		}
 
 		DBGLOG(INIT, INFO, "kalP2PCacFinishedUpdate: Update to OS\n");
+#if KERNEL_VERSION(3, 14, 0) <= CFG80211_VERSION_CODE
 		cfg80211_cac_event(prGlueInfo->prP2PInfo[ucRoleIndex]->prDevHandler,
 				prGlueInfo->prP2PInfo[ucRoleIndex]->chandef, NL80211_RADAR_CAC_FINISHED, GFP_KERNEL);
+#else
+		cfg80211_cac_event(prGlueInfo->prP2PInfo[ucRoleIndex]->prDevHandler,
+				NL80211_RADAR_CAC_FINISHED, GFP_KERNEL);
+#endif
 		DBGLOG(INIT, INFO, "kalP2PCacFinishedUpdate: Update to OS Done\n");
 
 	} while (FALSE);
diff --git a/os/linux/include/gl_p2p_ioctl.h b/os/linux/include/gl_p2p_ioctl.h
index 550e5e8..a277288 100644
--- a/os/linux/include/gl_p2p_ioctl.h
+++ b/os/linux/include/gl_p2p_ioctl.h
@@ -450,8 +450,10 @@
 #endif
 
 
+#if KERNEL_VERSION(3, 13, 0) <= CFG80211_VERSION_CODE
 int mtk_p2p_cfg80211_channel_switch(struct wiphy *wiphy, struct net_device *dev, struct cfg80211_csa_settings *params);
 #endif
+#endif
 
 int mtk_p2p_cfg80211_change_bss(struct wiphy *wiphy, struct net_device *dev, struct bss_parameters *params);