DHD: Skip country on AP/GO, NDP cases

Bug: 317174880
Test: T6pro country code set correctly
Change-Id: Ic7eef1d5951c8d27506fd7b7e30af629f90bd45d
Signed-off-by: Stephen Chu <stephen.chu@synaptics.corp-partner.google.com>
diff --git a/wl_cfg80211.c b/wl_cfg80211.c
index c321bba..92940b9 100644
--- a/wl_cfg80211.c
+++ b/wl_cfg80211.c
@@ -10969,6 +10969,35 @@
 }
 
 static bool
+wl_is_ccode_change_allowed(struct net_device *net)
+{
+	struct wireless_dev *wdev = ndev_to_wdev(net);
+	struct wiphy *wiphy = wdev->wiphy;
+	struct bcm_cfg80211 *cfg = wiphy_priv(wiphy);
+	struct net_info *iter, *next;
+
+	/* Country code isn't allowed change on AP/GO, NDP established  */
+	GCC_DIAGNOSTIC_PUSH_SUPPRESS_CAST();
+	for_each_ndev(cfg, iter, next) {
+		GCC_DIAGNOSTIC_POP();
+		if (iter->ndev) {
+			if (wl_get_drv_status(cfg, AP_CREATED, iter->ndev)) {
+				WL_ERR(("AP active. skip country ccode change"));
+				return false;
+			}
+		}
+	}
+
+#ifdef WL_NAN
+	if (wl_cfgnan_is_enabled(cfg) && wl_cfgnan_is_dp_active(net)) {
+		WL_ERR(("NDP established. skip country ccode change"));
+		return false;
+	}
+#endif /* WL_NAN */
+	return true;
+}
+
+static bool
 wl_is_ccode_change_required(struct net_device *net,
 	char *country_code, int revinfo)
 {
@@ -11215,6 +11244,12 @@
 		goto exit;
 	}
 
+	if (wl_is_ccode_change_allowed(net) == false) {
+		WL_ERR(("country code change isn't allowed during AP role/NAN connected\n"));
+		ret = BCME_EPERM;
+		goto exit;
+	}
+
 #ifdef WL_AUTO_COUNTRY
 	ret = wl_config_autocountry(cfg, net, country_code);
 #endif /* WL_AUTO_COUNTRY */