[WCNCR00169301] regd: add disconnection when connected channel is disabled

[Description]
Expected behavior:
When DUT is configured with a channel 12 or 13 AP during OOBE in the US
(where channel 12/13 are not legal), DUT is expected to disconnect
from the ch12/13 AP after the country code is determined to be US.

Issue repro steps:
1. Factory reset device
2. During Wi-Fi configuration, connect to the ch13 AP.
   (NOTE: DUT should connect to the AP because country code is 00 in OOBE)
3. After DUT OOBE is completed, country is changed to US.
4. DUT remains connected to the Ch13 AP, it is unexpected.

Solution:
Disconnect AP if the disabled channel is connected channel.

Test:
1. In JP channel 13, DUT disconnects from AP when change country to US.
2. DUT reconnects to AP when change country to JP.

Change-Id: Iaa4a81156c74612256c9e3191fa32ba657c1c9a5
CR-Id: WCNCR00169301
Feature: regd
Signed-off-by: ZD Hu <zd.hu@mediatek.com>
Reviewed-on: http://gerrit.mediatek.inc:8080/1240487
CheckPatch: Check Patch <srv_checkpatch@mediatek.com>
Reviewed-by: Sarick Jiang <sarick.jiang@mediatek.com>
Reviewed-by: George Kuo <george.kuo@mediatek.com>
Build: srv_neptune_adm <srv_neptune_adm@mediatek.com>
diff --git a/mgmt/rlm_domain.c b/mgmt/rlm_domain.c
index 0b6fea0..7c933c2 100644
--- a/mgmt/rlm_domain.c
+++ b/mgmt/rlm_domain.c
@@ -2931,6 +2931,11 @@
 	struct ieee80211_channel *chan;
 	struct channel *pCh;
 	char chan_flag_string[64] = {0};
+	P_GLUE_INFO_T prGlueInfo;
+	UINT_8 ucChannelNum = 0;
+	BOOLEAN fgDisconnection = FALSE;
+	WLAN_STATUS rStatus;
+	UINT_32 u4BufLen;
 
 
 	if (!pWiphy) {
@@ -2939,6 +2944,12 @@
 		return;
 	}
 
+	/* Retrieve connected channel */
+	prGlueInfo = rlmDomainGetGlueInfo();
+	if (prGlueInfo && kalGetMediaStateIndicated(prGlueInfo) == PARAM_MEDIA_STATE_CONNECTED) {
+		ucChannelNum = wlanGetChannelNumberByNetwork(prGlueInfo->prAdapter,
+							     prGlueInfo->prAdapter->prAisBssInfo->ucBssIndex);
+	}
 
 	/*
 	 * Ready to parse the channel for bands
@@ -2963,6 +2974,11 @@
 				DBGLOG(RLM, INFO, "channels[%d][%d]: ch%d (freq = %d) flags=0x%x [ %s]\n",
 				    band_idx, ch_idx, chan->hw_value, chan->center_freq, chan->flags,
 				    chan_flag_string);
+
+				/* Disconnect AP in the end of this function*/
+				if (chan->hw_value == ucChannelNum)
+					fgDisconnection = TRUE;
+
 				continue;
 			}
 
@@ -2985,6 +3001,15 @@
 		}
 
 	}
+
+	/* Disconnect with AP if connected channel is disabled in new country */
+	if (fgDisconnection) {
+		DBGLOG(RLM, STATE, "Disconnect! CH%d is DISABLED in this country\n", ucChannelNum);
+		rStatus = kalIoctl(prGlueInfo, wlanoidSetDisassociate, NULL, 0, FALSE, FALSE, TRUE, &u4BufLen);
+
+		if (rStatus != WLAN_STATUS_SUCCESS)
+			DBGLOG(RLM, WARN, "disassociate error:%lx\n", rStatus);
+	}
 }
 void rlmExtractChannelInfo(u32 max_ch_count, struct acctive_channel_list *prBuff)
 {