qcacld-3.0: Re-arrange regulatory code.

Re-arrange core regulatory code between HDD and CDS
layers. Move the OS dependent code to HDD.

Change-Id: I8ac26a48d0e8d613b2f6c23fd764e5cf94365c39
CRs-Fixed: 856727
diff --git a/Kbuild b/Kbuild
index 39a3b15..b2ed9e5 100755
--- a/Kbuild
+++ b/Kbuild
@@ -296,6 +296,7 @@
 		$(HDD_SRC_DIR)/wlan_hdd_ocb.o \
 		$(HDD_SRC_DIR)/wlan_hdd_oemdata.o \
 		$(HDD_SRC_DIR)/wlan_hdd_power.o \
+		$(HDD_SRC_DIR)/wlan_hdd_regulatory.o \
 		$(HDD_SRC_DIR)/wlan_hdd_scan.o \
 		$(HDD_SRC_DIR)/wlan_hdd_softap_tx_rx.o \
 		$(HDD_SRC_DIR)/wlan_hdd_tx_rx.o \
@@ -304,6 +305,7 @@
 		$(HDD_SRC_DIR)/wlan_hdd_wmm.o \
 		$(HDD_SRC_DIR)/wlan_hdd_wowl.o
 
+
 ifeq ($(CONFIG_WLAN_LRO), y)
 HDD_OBJS +=     $(HDD_SRC_DIR)/wlan_hdd_lro.o
 endif
diff --git a/core/cds/inc/cds_reg_service.h b/core/cds/inc/cds_reg_service.h
index e9b9e93..bed2496 100644
--- a/core/cds/inc/cds_reg_service.h
+++ b/core/cds/inc/cds_reg_service.h
@@ -284,8 +284,6 @@
 	uint32_t eeprom_rd_ext;
 	uint16_t country_code;
 	uint8_t alpha2[CDS_COUNTRY_CODE_LEN + 1];
-	uint8_t def_country[CDS_COUNTRY_CODE_LEN + 1];
-	uint8_t dfs_region;
 	uint8_t ctl_2g;
 	uint8_t ctl_5g;
 	const void *regpair;
@@ -314,9 +312,8 @@
 	CHAN_WIDTH_160MHZ
 };
 
-
-extern struct regulatory_channel reg_channels[NUM_RF_CHANNELS];
 extern const struct chan_map chan_mapping[NUM_RF_CHANNELS];
+extern struct regulatory_channel reg_channels[NUM_RF_CHANNELS];
 
 QDF_STATUS cds_get_reg_domain_from_country_code(v_REGDOMAIN_t *pRegDomain,
 						const uint8_t *country_alpha2,
@@ -331,16 +328,16 @@
 					   *channel_40mhz,
 					   uint8_t *num_channels_40mhz);
 
-QDF_STATUS cds_set_reg_domain(void *client_ctxt, v_REGDOMAIN_t reg_domain);
-
 enum channel_state cds_get_channel_state(uint32_t chan_num);
-
-QDF_STATUS cds_regulatory_init(void);
 QDF_STATUS cds_get_dfs_region(uint8_t *dfs_region);
-QDF_STATUS cds_set_dfs_region(uint8_t dfs_region);
+QDF_STATUS cds_put_dfs_region(uint8_t dfs_region);
+
 bool cds_is_dsrc_channel(uint16_t);
 enum channel_state cds_get_bonded_channel_state(uint32_t chan_num,
 					   enum channel_width chan_width);
 enum channel_width cds_get_max_channel_bw(uint32_t chan_num);
 
+QDF_STATUS cds_set_reg_domain(void *client_ctxt, v_REGDOMAIN_t reg_domain);
+
+QDF_STATUS cds_put_default_country(uint8_t *def_country);
 #endif /* __CDS_REG_SERVICE_H */
diff --git a/core/cds/inc/cds_regdomain.h b/core/cds/inc/cds_regdomain.h
index 7f40344..70207ef 100644
--- a/core/cds/inc/cds_regdomain.h
+++ b/core/cds/inc/cds_regdomain.h
@@ -1070,13 +1070,47 @@
 	CTRY_BELGIUM2 = 5002    /* Belgium/Cisco implementation */
 };
 
+
+/**
+ * enum ch_width - channel width
+ * @CH_WIDTH_20MHZ: channel width 20 MHz
+ * @CH_WIDTH_40MHZ: channel width 40 MHz
+ * @CH_WIDTH_80MHZ: channel width 80MHz
+ * @CH_WIDTH_160MHZ: channel width 160 MHz
+ * @CH_WIDTH_80P80MHZ: channel width 160MHz(80+80)
+ */
+enum ch_width {
+	CH_WIDTH_20MHZ = 0,
+	CH_WIDTH_40MHZ = 1,
+	CH_WIDTH_80MHZ = 2,
+	CH_WIDTH_160MHZ = 3,
+	CH_WIDTH_80P80MHZ = 4,
+	CH_WIDTH_MAX
+};
+
+/**
+ * struct ch_params_s
+ *
+ * @ch_width: channel width
+ * @sec_ch_offset: secondary channel offset
+ * @center_freq_seg0: center freq for segment 0
+ * @center_freq_seg1: center freq for segment 1
+ */
+struct ch_params_s {
+	enum ch_width ch_width;
+	uint8_t sec_ch_offset;
+	uint8_t center_freq_seg0;
+	uint8_t center_freq_seg1;
+};
+
+
 int32_t cds_fill_some_regulatory_info(struct regulatory *reg);
 void cds_fill_and_send_ctl_to_fw(struct regulatory *reg);
 int32_t cds_get_country_from_alpha2(uint8_t *alpha2);
 void cds_fill_send_ctl_info_to_fw(struct regulatory *reg, uint32_t modesAvail,
 				  uint32_t modeSelect);
-void cds_set_wma_dfs_region(struct regulatory *reg);
+void cds_set_wma_dfs_region(uint8_t dfs_region);
 void cds_set_ch_params(uint8_t ch, uint32_t phy_mode,
-		chan_params_t *ch_params);
+		       struct ch_params_s *ch_params);
 
 #endif /* REGULATORY_H */
diff --git a/core/cds/src/cds_reg_service.c b/core/cds/src/cds_reg_service.c
index a2d3f70..37dcc63 100644
--- a/core/cds/src/cds_reg_service.c
+++ b/core/cds/src/cds_reg_service.c
@@ -36,92 +36,9 @@
 #include "cds_reg_service.h"
 #include "qdf_trace.h"
 #include "sme_api.h"
-#include "wlan_hdd_main.h"
+#include "cds_api.h"
+#include "cds_reg_service.h"
 #include "cds_regdomain.h"
-#include "cds_regdomain_common.h"
-
-#define WORLD_SKU_MASK          0x00F0
-#define WORLD_SKU_PREFIX        0x0060
-#define REG_WAIT_TIME           50
-
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0)) || defined(WITH_BACKPORTS)
-#define IEEE80211_CHAN_PASSIVE_SCAN IEEE80211_CHAN_NO_IR
-#define IEEE80211_CHAN_NO_IBSS IEEE80211_CHAN_NO_IR
-#endif
-
-#define REG_RULE_2412_2462    REG_RULE(2412-10, 2462+10, 40, 0, 20, 0)
-
-#define REG_RULE_2467_2472    REG_RULE(2467-10, 2472+10, 40, 0, 20, \
-			      NL80211_RRF_PASSIVE_SCAN)
-
-#define REG_RULE_2484         REG_RULE(2484-10, 2484+10, 40, 0, 20, \
-		NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_OFDM)
-
-#define REG_RULE_5180_5320    REG_RULE(5180-10, 5320+10, 80, 0, 20, \
-		NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS)
-
-#define REG_RULE_5500_5720    REG_RULE(5500-10, 5720+10, 80, 0, 20, \
-		NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS)
-
-#define REG_RULE_5745_5925    REG_RULE(5745-10, 5925+10, 80, 0, 20, \
-		NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS)
-
-static const struct ieee80211_regdomain cds_world_regdom_60_61_62 = {
-	.n_reg_rules = 6,
-	.alpha2 =  "00",
-	.reg_rules = {
-		REG_RULE_2412_2462,
-		REG_RULE_2467_2472,
-		REG_RULE_2484,
-		REG_RULE_5180_5320,
-		REG_RULE_5500_5720,
-		REG_RULE_5745_5925,
-	}
-};
-
-static const struct ieee80211_regdomain cds_world_regdom_63_65 = {
-	.n_reg_rules = 4,
-	.alpha2 =  "00",
-	.reg_rules = {
-		REG_RULE_2412_2462,
-		REG_RULE_2467_2472,
-		REG_RULE_5180_5320,
-		REG_RULE_5745_5925,
-	}
-};
-
-static const struct ieee80211_regdomain cds_world_regdom_64 = {
-	.n_reg_rules = 3,
-	.alpha2 =  "00",
-	.reg_rules = {
-		REG_RULE_2412_2462,
-		REG_RULE_5180_5320,
-		REG_RULE_5745_5925,
-	}
-};
-
-static const struct ieee80211_regdomain cds_world_regdom_66_69 = {
-	.n_reg_rules = 4,
-	.alpha2 =  "00",
-	.reg_rules = {
-		REG_RULE_2412_2462,
-		REG_RULE_5180_5320,
-		REG_RULE_5500_5720,
-		REG_RULE_5745_5925,
-	}
-};
-
-static const struct ieee80211_regdomain cds_world_regdom_67_68_6A_6C = {
-	.n_reg_rules = 5,
-	.alpha2 =  "00",
-	.reg_rules = {
-		REG_RULE_2412_2462,
-		REG_RULE_2467_2472,
-		REG_RULE_5180_5320,
-		REG_RULE_5500_5720,
-		REG_RULE_5745_5925,
-	}
-};
 
 const struct chan_map chan_mapping[NUM_RF_CHANNELS] = {
 	{2412, 1},
@@ -212,143 +129,8 @@
 };
 
 struct regulatory_channel reg_channels[NUM_RF_CHANNELS];
-static bool init_by_driver;
-static bool init_by_reg_core;
-
-/**
- * cds_is_world_regdomain() - whether world regdomain
- * @regd: integer regulatory domain
- *
- * Return: bool
- */
-bool cds_is_world_regdomain(uint32_t reg_domain)
-{
-	uint32_t temp_regd = reg_domain & ~WORLDWIDE_ROAMING_FLAG;
-
-	return ((temp_regd & COUNTRY_ERD_FLAG) != COUNTRY_ERD_FLAG) &&
-		(((temp_regd & WORLD_SKU_MASK) == WORLD_SKU_PREFIX) ||
-		 (temp_regd == WORLD));
-
-}
-
-
-/**
- * cds_world_regdomain() - which constant world regdomain
- * @reg: regulatory data
- *
- * Return: regdomain ptr
- */
-static const struct ieee80211_regdomain
-*cds_world_regdomain(struct regulatory *reg)
-{
-	REG_DMN_PAIR_MAPPING *regpair =
-		(REG_DMN_PAIR_MAPPING *)reg->regpair;
-
-	switch (regpair->regDmnEnum) {
-	case 0x60:
-	case 0x61:
-	case 0x62:
-		return &cds_world_regdom_60_61_62;
-	case 0x63:
-	case 0x65:
-		return &cds_world_regdom_63_65;
-	case 0x64:
-		return &cds_world_regdom_64;
-	case 0x66:
-	case 0x69:
-		return &cds_world_regdom_66_69;
-	case 0x67:
-	case 0x68:
-	case 0x6A:
-	case 0x6C:
-		return &cds_world_regdom_67_68_6A_6C;
-	default:
-		WARN_ON(1);
-		return &cds_world_regdom_60_61_62;
-	}
-}
-
-/**
- * cds_regulatory_wiphy_init() - regulatory wiphy init
- * @hdd_ctx: hdd context
- * @reg: regulatory data
- * @wiphy: wiphy structure
- *
- * Return: int
- */
-static int cds_regulatory_wiphy_init(hdd_context_t *hdd_ctx,
-				     struct regulatory *reg,
-				     struct wiphy *wiphy)
-{
-	const struct ieee80211_regdomain *reg_domain;
-
-	if (cds_is_world_regdomain(reg->reg_domain)) {
-		reg_domain = cds_world_regdomain(reg);
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0)) || defined(WITH_BACKPORTS)
-		wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG;
-#else
-		wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY;
-#endif
-	} else if (hdd_ctx->config->fRegChangeDefCountry) {
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0)) || defined(WITH_BACKPORTS)
-		wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG;
-#else
-		wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY;
-#endif
-		reg_domain = &cds_world_regdom_60_61_62;
-	} else {
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0)) || defined(WITH_BACKPORTS)
-		wiphy->regulatory_flags |= REGULATORY_STRICT_REG;
-#else
-		wiphy->flags |= WIPHY_FLAG_STRICT_REGULATORY;
-#endif
-		reg_domain = &cds_world_regdom_60_61_62;
-	}
-
-	/*
-	 * save the original driver regulatory flags
-	 */
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0)) || defined(WITH_BACKPORTS)
-	hdd_ctx->reg.reg_flags = wiphy->regulatory_flags;
-#else
-	hdd_ctx->reg.reg_flags = wiphy->flags;
-#endif
-	wiphy_apply_custom_regulatory(wiphy, reg_domain);
-
-	/*
-	 * restore the driver regulatory flags since
-	 * wiphy_apply_custom_regulatory may have
-	 * changed them
-	 */
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0)) || defined(WITH_BACKPORTS)
-	wiphy->regulatory_flags = hdd_ctx->reg.reg_flags;
-#else
-	wiphy->flags = hdd_ctx->reg.reg_flags;
-#endif
-
-	return 0;
-}
-
-/**
- * cds_update_regulatory_info() - update regulatory info
- * @hdd_ctx: hdd context
- *
- * Return: QDF_STATUS
- */
-static void cds_update_regulatory_info(hdd_context_t *hdd_ctx)
-{
-	uint32_t country_code;
-
-	country_code = cds_get_country_from_alpha2(hdd_ctx->reg.alpha2);
-
-	hdd_ctx->reg.reg_domain = COUNTRY_ERD_FLAG;
-	hdd_ctx->reg.reg_domain |= country_code;
-
-	cds_fill_some_regulatory_info(&hdd_ctx->reg);
-
-	return;
-}
-
+uint8_t default_country[CDS_COUNTRY_CODE_LEN + 1];
+uint8_t dfs_region;
 
 /**
  * cds_get_channel_list_with_power() - retrieve channel list with power
@@ -418,29 +200,20 @@
 
 /**
  * cds_read_default_country() - set the default country
- * @default_country: default country
+ * @def_ctry: default country
  *
  * Return: QDF_STATUS
  */
-QDF_STATUS cds_read_default_country(uint8_t *default_country)
+QDF_STATUS cds_read_default_country(uint8_t *def_ctry)
 {
-	hdd_context_t *hdd_ctx;
-
-	hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
-	if (!hdd_ctx) {
-		QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
-			  "invalid hdd_ctx pointer");
-		return QDF_STATUS_E_FAULT;
-	}
-
-	memcpy(default_country,
-	       hdd_ctx->reg.def_country,
+	memcpy(def_ctry,
+	       default_country,
 	       CDS_COUNTRY_CODE_LEN + 1);
 
 	QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_INFO,
 		  "default country is %c%c\n",
-		  default_country[0],
-		  default_country[1]);
+		  def_ctry[0],
+		  def_ctry[1]);
 
 	return QDF_STATUS_SUCCESS;
 }
@@ -565,90 +338,15 @@
 
 }
 
-static int cds_bw20_ch_index_to_bw40_ch_index(int k)
-{
-	int m = -1;
-	if (k >= RF_CHAN_1 && k <= RF_CHAN_13) {
-		/*
-		 * Channel bonding is not valid for channel 14,
-		 * Hence don't consider it
-		 */
-		m = k - RF_CHAN_1 + RF_CHAN_BOND_3;
-		if (m > RF_CHAN_BOND_11)
-			m = RF_CHAN_BOND_11;
-	} else if (k >= RF_CHAN_36 && k <= RF_CHAN_64) {
-		m = k - RF_CHAN_36 + RF_CHAN_BOND_38;
-		if (m > RF_CHAN_BOND_62)
-			m = RF_CHAN_BOND_62;
-	} else if (k >= RF_CHAN_100 && k <= RF_CHAN_144) {
-		m = k - RF_CHAN_100 + RF_CHAN_BOND_102;
-		if (m > RF_CHAN_BOND_142)
-			m = RF_CHAN_BOND_142;
-	} else if (k >= RF_CHAN_149 && k <= RF_CHAN_165) {
-		m = k - RF_CHAN_149 + RF_CHAN_BOND_151;
-		if (m > RF_CHAN_BOND_163)
-			m = RF_CHAN_BOND_163;
-	}
-	return m;
-}
-
-/**
- * cds_set_dfs_region() - set the dfs_region
- * @dfs_region: the dfs_region to set
- *
- * Return: QDF_STATUS_SUCCESS if dfs_region set correctly
- *         QDF_STATUS_E_EXISTS if hdd context not found
- */
-QDF_STATUS cds_set_dfs_region(uint8_t dfs_region)
-{
-	hdd_context_t *hdd_ctx;
-
-	hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
-
-	if (NULL == hdd_ctx)
-		return QDF_STATUS_E_EXISTS;
-
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0)) || defined(WITH_BACKPORTS)
-	hdd_ctx->reg.dfs_region = dfs_region;
-#else
-
-	/* remap the ctl code to dfs region code */
-	switch (hdd_ctx->reg.ctl_5g) {
-	case FCC:
-		hdd_ctx->reg.dfs_region = DFS_FCC_DOMAIN;
-		break;
-	case ETSI:
-		hdd_ctx->reg.dfs_region = DFS_ETSI_DOMAIN;
-		break;
-	case MKK:
-		hdd_ctx->reg.dfs_region = DFS_MKK4_DOMAIN;
-		break;
-	default:
-		/* set default dfs_region to FCC */
-		hdd_ctx->reg.dfs_region = DFS_FCC_DOMAIN;
-		break;
-	}
-#endif
-	return QDF_STATUS_SUCCESS;
-}
-
 /**
  * cds_get_dfs_region() - get the dfs_region
  * @dfs_region: the dfs_region to return
  *
- * Return: QDF_STATUS_SUCCESS if dfs_region set correctly
- *         QDF_STATUS_E_EXISTS if hdd context not found
+ * Return: QDF_STATUS
  */
-QDF_STATUS cds_get_dfs_region(uint8_t *dfs_region)
+QDF_STATUS cds_get_dfs_region(uint8_t *dfs_reg)
 {
-	hdd_context_t *hdd_ctx;
-
-	hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
-
-	if (NULL == hdd_ctx)
-		return QDF_STATUS_E_EXISTS;
-
-	*dfs_region = hdd_ctx->reg.dfs_region;
+	*dfs_reg = dfs_region;
 
 	return QDF_STATUS_SUCCESS;
 }
@@ -665,12 +363,9 @@
 						const uint8_t *country_alpha2,
 						enum country_src source)
 {
-	hdd_context_t *hdd_ctx = NULL;
-	struct wiphy *wiphy = NULL;
-
 	if (NULL == reg_domain_ptr) {
 		QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
-			  ("Invalid reg domain pointer"));
+			  "Invalid reg domain pointer");
 		return QDF_STATUS_E_FAULT;
 	}
 
@@ -681,7 +376,7 @@
 
 	if (NULL == country_alpha2) {
 		QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
-			  ("Country code array is NULL"));
+			  "Country code array is NULL");
 		return QDF_STATUS_E_FAULT;
 	}
 
@@ -691,28 +386,9 @@
 		return QDF_STATUS_SUCCESS;
 	}
 
-	hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
-
-	if (NULL == hdd_ctx) {
-		QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
-			  ("Invalid pHddCtx pointer"));
-		return QDF_STATUS_E_FAULT;
-	}
-
-	wiphy = hdd_ctx->wiphy;
-
-	if ((SOURCE_DRIVER == source) && (false == init_by_reg_core)) {
-		init_by_driver = true;
-		if (('0' != country_alpha2[0]) || ('0' != country_alpha2[1])) {
-			INIT_COMPLETION(hdd_ctx->reg_init);
-			regulatory_hint(wiphy, country_alpha2);
-			wait_for_completion_timeout(&hdd_ctx->reg_init,
-					       msecs_to_jiffies(REG_WAIT_TIME));
-		}
-	} else if (SOURCE_11D == source || SOURCE_USERSPACE == source) {
+	if (SOURCE_11D == source || SOURCE_USERSPACE == source)
 		regulatory_hint_user(country_alpha2,
 				     NL80211_USER_REG_HINT_USER);
-	}
 
 	return QDF_STATUS_SUCCESS;
 }
@@ -734,417 +410,6 @@
 }
 
 /**
- * cds_process_regulatory_data() - process regulatory data
- * @wiphy: wiphy
- * @band_capability: band_capability
- *
- * Return: int
- */
-static int cds_process_regulatory_data(struct wiphy *wiphy,
-				       uint8_t band_capability,
-				       bool reset)
-{
-	int i, j, m;
-	int k = 0, n = 0;
-	hdd_context_t *hdd_ctx;
-	const struct ieee80211_reg_rule *reg_rule;
-	struct ieee80211_channel *chan;
-	struct regulatory_channel *temp_chan_k, *temp_chan_n, *temp_chan;
-
-	hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
-	if (NULL == hdd_ctx) {
-		QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
-			  "invalid hdd_ctx pointer");
-		return QDF_STATUS_E_FAULT;
-	}
-
-	hdd_ctx->isVHT80Allowed = 0;
-
-	if (band_capability == eCSR_BAND_24)
-		QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_INFO,
-			  "band capability is set to 2G only");
-
-	for (i = 0, m = 0; i < IEEE80211_NUM_BANDS; i++) {
-
-		if (i == IEEE80211_BAND_2GHZ && band_capability == eCSR_BAND_5G)
-			continue;
-
-		else if (i == IEEE80211_BAND_5GHZ
-			 && band_capability == eCSR_BAND_24)
-			continue;
-
-		if (wiphy->bands[i] == NULL)
-			continue;
-
-		if (i == 0)
-			m = 0;
-		else
-			m = wiphy->bands[i-1]->n_channels + m;
-
-		for (j = 0; j < wiphy->bands[i]->n_channels; j++) {
-
-			k = m + j;
-			n = cds_bw20_ch_index_to_bw40_ch_index(k);
-
-			chan = &(wiphy->bands[i]->channels[j]);
-			temp_chan_k = &(reg_channels[k]);
-			temp_chan_n = &(reg_channels[n]);
-
-			if ((!reset) &&
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0)) || defined(WITH_BACKPORTS)
-			    (wiphy->regulatory_flags &
-			     REGULATORY_CUSTOM_REG)) {
-#else
-				(wiphy->flags &
-				 WIPHY_FLAG_CUSTOM_REGULATORY)) {
-#endif
-				reg_rule = freq_reg_info(wiphy,
-							 MHZ_TO_KHZ(chan->
-								 center_freq));
-
-				if (!IS_ERR(reg_rule)) {
-					chan->flags &=
-						~IEEE80211_CHAN_DISABLED;
-
-					if (!(reg_rule->flags &
-					      NL80211_RRF_DFS)) {
-						QDF_TRACE(QDF_MODULE_ID_QDF,
-							  QDF_TRACE_LEVEL_INFO,
-							  "%s: Remove passive scan restriction for %u",
-							  __func__,
-							  chan->center_freq);
-						chan->flags &=
-							~IEEE80211_CHAN_RADAR;
-					}
-
-					if (!(reg_rule->flags &
-					      NL80211_RRF_PASSIVE_SCAN)) {
-						QDF_TRACE(QDF_MODULE_ID_QDF,
-							  QDF_TRACE_LEVEL_INFO,
-							  "%s: Remove passive scan restriction for %u",
-							  __func__,
-							  chan->center_freq);
-						chan->flags &=
-						   ~IEEE80211_CHAN_PASSIVE_SCAN;
-					}
-
-					if (!(reg_rule->flags &
-					      NL80211_RRF_NO_IBSS)) {
-						QDF_TRACE(QDF_MODULE_ID_QDF,
-							  QDF_TRACE_LEVEL_INFO,
-							  "%s: Remove no ibss restriction for %u",
-							  __func__,
-							  chan->center_freq);
-						chan->flags &=
-							~IEEE80211_CHAN_NO_IBSS;
-					}
-
-					chan->max_power = MBM_TO_DBM(reg_rule->
-								     power_rule.
-								     max_eirp);
-				}
-			}
-
-			if (chan->flags & IEEE80211_CHAN_DISABLED) {
-				temp_chan_k->state =
-					CHANNEL_STATE_DISABLE;
-				temp_chan_k->flags = chan->flags;
-				if (n != -1) {
-					temp_chan_n->state =
-						CHANNEL_STATE_DISABLE;
-					temp_chan_n->flags = chan->flags;
-				}
-			} else if (chan->flags &
-				   (IEEE80211_CHAN_RADAR |
-				    IEEE80211_CHAN_PASSIVE_SCAN
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 16, 0))
-					|
-					IEEE80211_CHAN_INDOOR_ONLY
-#endif
-				)) {
-
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 16, 0))
-				if (chan->flags &
-				    IEEE80211_CHAN_INDOOR_ONLY)
-					chan->flags |=
-						IEEE80211_CHAN_PASSIVE_SCAN;
-#endif
-				temp_chan_k->state = CHANNEL_STATE_DFS;
-				temp_chan_k->pwr_limit =
-					chan->max_power;
-				temp_chan_k->flags = chan->flags;
-
-				if (n != -1) {
-					if ((chan->flags &
-					     IEEE80211_CHAN_NO_HT40) ==
-					    IEEE80211_CHAN_NO_HT40) {
-						temp_chan_n->state =
-							CHANNEL_STATE_DISABLE;
-					} else {
-						temp_chan_n->state =
-							CHANNEL_STATE_DFS;
-						temp_chan_n->pwr_limit =
-							 chan->max_power-3;
-					}
-					temp_chan_n->flags = chan->flags;
-				}
-				if ((chan->flags &
-				     IEEE80211_CHAN_NO_80MHZ) == 0)
-					hdd_ctx->isVHT80Allowed = 1;
-			} else {
-				temp_chan_k->state = CHANNEL_STATE_ENABLE;
-				temp_chan_k->pwr_limit = chan->max_power;
-				temp_chan_k->flags = chan->flags;
-				if (n != -1) {
-					if ((chan->flags &
-					     IEEE80211_CHAN_NO_HT40) ==
-					    IEEE80211_CHAN_NO_HT40) {
-						temp_chan_n->state =
-							CHANNEL_STATE_DISABLE;
-					} else {
-						temp_chan_n->state =
-							CHANNEL_STATE_ENABLE;
-						temp_chan_n->pwr_limit =
-							chan->max_power - 3;
-					}
-					temp_chan_n->flags = chan->flags;
-				}
-				if ((chan->flags &
-				     IEEE80211_CHAN_NO_80MHZ) == 0)
-					hdd_ctx->isVHT80Allowed = 1;
-			}
-		}
-	}
-
-	if (0 == (hdd_ctx->reg.eeprom_rd_ext &
-		  (1 << WHAL_REG_EXT_FCC_CH_144))) {
-		temp_chan = &(reg_channels[RF_CHAN_144]);
-		temp_chan->state =
-			CHANNEL_STATE_DISABLE;
-	}
-
-	if (k == 0)
-		return -1;
-
-	return QDF_STATUS_SUCCESS;
-}
-
-#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 14, 0)) && !defined(WITH_BACKPORTS)
-/**
- * restore_custom_reg_settings() - restore custom reg settings
- * @wiphy: wiphy structure
- *
- * Return: void
- */
-static void restore_custom_reg_settings(struct wiphy *wiphy)
-{
-	struct ieee80211_supported_band *sband;
-	enum ieee80211_band band;
-	struct ieee80211_channel *chan;
-	int i;
-
-	for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
-		sband = wiphy->bands[band];
-		if (!sband)
-			continue;
-		for (i = 0; i < sband->n_channels; i++) {
-			chan = &sband->channels[i];
-			chan->flags = chan->orig_flags;
-			chan->max_antenna_gain = chan->orig_mag;
-			chan->max_power = chan->orig_mpwr;
-		}
-	}
-}
-#endif
-
-/**
- * __hdd_reg_notifier() - regulatory notifier
- * @wiphy: wiphy
- * @request: regulatory request
- *
- * Return: void or int
- */
-void __hdd_reg_notifier(struct wiphy *wiphy,
-		      struct regulatory_request *request)
-{
-	hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
-	eCsrBand band_capability = eCSR_BAND_ALL;
-	bool vht80_allowed;
-	bool reset = false;
-
-	QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_INFO,
-		  FL("country: %c%c, initiator %d, dfs_region: %d"),
-		  request->alpha2[0],
-		  request->alpha2[1],
-		  request->initiator,
-		  request->dfs_region);
-
-	if (NULL == hdd_ctx) {
-		QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
-			  ("Invalid pHddCtx pointer"));
-		return;
-	}
-
-	if (cds_is_driver_unloading() || cds_is_driver_recovering()) {
-		QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
-			  "%s: Unloading or SSR in Progress, Ignore!!!",
-			  __func__);
-		return;
-	}
-
-	sme_get_freq_band(hdd_ctx->hHal, &band_capability);
-
-	/* first check if this callback is in response to the driver callback */
-
-	switch (request->initiator) {
-	case NL80211_REGDOM_SET_BY_DRIVER:
-	case NL80211_REGDOM_SET_BY_CORE:
-	case NL80211_REGDOM_SET_BY_USER:
-
-		if ((false == init_by_driver) &&
-		    (false == init_by_reg_core)) {
-
-			if (NL80211_REGDOM_SET_BY_CORE == request->initiator) {
-				return;
-			}
-			init_by_reg_core = true;
-		}
-
-		if ((NL80211_REGDOM_SET_BY_DRIVER == request->initiator) &&
-		    (true == init_by_driver)) {
-
-			/*
-			 * restore the driver regulatory flags since
-			 * regulatory_hint may have
-			 * changed them
-			 */
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0)) || defined(WITH_BACKPORTS)
-			wiphy->regulatory_flags = hdd_ctx->reg.reg_flags;
-#else
-			wiphy->flags = hdd_ctx->reg.reg_flags;
-#endif
-		}
-
-		if (NL80211_REGDOM_SET_BY_CORE == request->initiator) {
-			hdd_ctx->reg.cc_src = SOURCE_CORE;
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0)) || defined(WITH_BACKPORTS)
-			if (wiphy->regulatory_flags & REGULATORY_CUSTOM_REG)
-#else
-			if (wiphy->flags & WIPHY_FLAG_CUSTOM_REGULATORY)
-#endif
-				reset = true;
-		} else if (NL80211_REGDOM_SET_BY_DRIVER == request->initiator)
-			hdd_ctx->reg.cc_src = SOURCE_DRIVER;
-		else {
-			hdd_ctx->reg.cc_src = SOURCE_USERSPACE;
-#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 14, 0)) && !defined(WITH_BACKPORTS)
-			if ((request->alpha2[0] == '0') &&
-			    (request->alpha2[1] == '0') &&
-			    (wiphy->flags & WIPHY_FLAG_CUSTOM_REGULATORY)) {
-				restore_custom_reg_settings(wiphy);
-				reset = true;
-			}
-#endif
-		}
-
-		hdd_ctx->reg.alpha2[0] = request->alpha2[0];
-		hdd_ctx->reg.alpha2[1] = request->alpha2[1];
-
-		cds_update_regulatory_info(hdd_ctx);
-
-		vht80_allowed = hdd_ctx->isVHT80Allowed;
-		if (cds_process_regulatory_data(wiphy, band_capability,
-						reset) == 0) {
-			QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_INFO,
-				  (" regulatory entry created"));
-		}
-		if (hdd_ctx->isVHT80Allowed != vht80_allowed)
-			hdd_checkandupdate_phymode(hdd_ctx);
-
-		if (NL80211_REGDOM_SET_BY_DRIVER == request->initiator)
-			complete(&hdd_ctx->reg_init);
-
-		sme_generic_change_country_code(hdd_ctx->hHal,
-						hdd_ctx->reg.alpha2);
-
-		cds_fill_and_send_ctl_to_fw(&hdd_ctx->reg);
-
-		cds_set_dfs_region(request->dfs_region);
-
-		cds_set_wma_dfs_region(&hdd_ctx->reg);
-	default:
-		break;
-	}
-
-	return;
-}
-
-/**
- * hdd_reg_notifier() - regulatory notifier
- * @wiphy: wiphy
- * @request: regulatory request
- *
- * Return: void or int
- */
-void hdd_reg_notifier(struct wiphy *wiphy,
-		      struct regulatory_request *request)
-{
-	cds_ssr_protect(__func__);
-	__hdd_reg_notifier(wiphy, request);
-	cds_ssr_unprotect(__func__);
-}
-
-/**
- * cds_regulatory_init() - regulatory_init
- * Return: QDF_STATUS
- */
-QDF_STATUS cds_regulatory_init(void)
-{
-	hdd_context_t *hdd_ctx = NULL;
-	struct wiphy *wiphy = NULL;
-	int ret_val = 0;
-	struct regulatory *reg_info;
-
-	hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
-	if (!hdd_ctx) {
-		QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
-			  "invalid hdd_ctx pointer");
-		return QDF_STATUS_E_FAULT;
-	}
-
-	wiphy = hdd_ctx->wiphy;
-
-	reg_info = &hdd_ctx->reg;
-
-	cds_regulatory_wiphy_init(hdd_ctx, reg_info, wiphy);
-
-	if (cds_process_regulatory_data(wiphy,
-					hdd_ctx->config->
-					nBandCapability, true) != 0) {
-		QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
-			  ("Error while creating regulatory entry"));
-		return QDF_STATUS_E_FAULT;
-	}
-
-	reg_info->cc_src = SOURCE_DRIVER;
-
-	ret_val = cds_fill_some_regulatory_info(reg_info);
-	if (ret_val) {
-		qdf_print(KERN_ERR "Error in getting country code\n");
-		return ret_val;
-	}
-
-	hdd_ctx->reg.def_country[0] = reg_info->alpha2[0];
-	hdd_ctx->reg.def_country[1] = reg_info->alpha2[1];
-
-	init_completion(&hdd_ctx->reg_init);
-
-	cds_fill_and_send_ctl_to_fw(reg_info);
-
-	return QDF_STATUS_SUCCESS;
-}
-
-/**
  * cds_set_reg_domain() - set regulatory domain
  * @client_ctxt: client context
  * @reg_domain: regulatory domain
@@ -1154,7 +419,7 @@
 QDF_STATUS cds_set_reg_domain(void *client_ctxt, v_REGDOMAIN_t reg_domain)
 {
 	if (reg_domain >= REGDOMAIN_COUNT) {
-		QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
+		QDF_TRACE(QDF_MODULE_ID_QDF_DEVICE, QDF_TRACE_LEVEL_ERROR,
 			  "CDS set reg domain, invalid REG domain ID %d",
 			  reg_domain);
 		return QDF_STATUS_E_INVAL;
@@ -1164,6 +429,33 @@
 }
 
 /**
+ * cds_put_dfs_region() - save dfs region
+ * @dfs_reg: dfs region
+ *
+ * Return: QDF_STATUS
+ */
+QDF_STATUS cds_put_dfs_region(uint8_t dfs_reg)
+{
+	dfs_region = dfs_reg;
+
+	return QDF_STATUS_SUCCESS;
+}
+
+/**
+ * cds_put_default_country() - save the default country
+ * @dfs_country: default country
+ *
+ * Return: QDF_STATUS
+ */
+QDF_STATUS cds_put_default_country(uint8_t *def_country)
+{
+	default_country[0] = def_country[0];
+	default_country[1] = def_country[1];
+
+	return QDF_STATUS_SUCCESS;
+}
+
+/**
  * cds_set_ch_params() - set channel parameters
  * @ch: channel
  * @phy_mode: physical mode
@@ -1172,7 +464,7 @@
  * Return: None
  */
 void cds_set_ch_params(uint8_t ch, uint32_t phy_mode,
-		chan_params_t *ch_params)
+		       struct ch_params_s *ch_params)
 {
 	tHalHandle *hal_ctx = cds_get_context(QDF_MODULE_ID_PE);
 	if (!hal_ctx) {
diff --git a/core/cds/src/cds_regdomain.c b/core/cds/src/cds_regdomain.c
index c75d61f..0507496 100644
--- a/core/cds/src/cds_regdomain.c
+++ b/core/cds/src/cds_regdomain.c
@@ -557,7 +557,7 @@
  *
  * Return: none
  */
-void cds_set_wma_dfs_region(struct regulatory *reg)
+void cds_set_wma_dfs_region(uint8_t dfs_region)
 {
 	tp_wma_handle wma = cds_get_context(QDF_MODULE_ID_WMA);
 
@@ -566,8 +566,8 @@
 		return;
 	}
 
-	qdf_print("%s: dfs_region: %d", __func__, reg->dfs_region);
-	wma_set_dfs_region(wma, reg->dfs_region);
+	qdf_print("%s: dfs_region: %d", __func__, dfs_region);
+	wma_set_dfs_region(wma, dfs_region);
 }
 
 void cds_fill_and_send_ctl_to_fw(struct regulatory *reg)
diff --git a/core/hdd/inc/wlan_hdd_main.h b/core/hdd/inc/wlan_hdd_main.h
index fb65d0a..796e10d 100644
--- a/core/hdd/inc/wlan_hdd_main.h
+++ b/core/hdd/inc/wlan_hdd_main.h
@@ -1344,7 +1344,7 @@
    -------------------------------------------------------------------------*/
 int hdd_validate_channel_and_bandwidth(hdd_adapter_t *adapter,
 				uint32_t chan_number,
-				phy_ch_width chan_bw);
+				enum ch_width chan_bw);
 #ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
 void wlan_hdd_check_sta_ap_concurrent_ch_intf(void *sta_pAdapter);
 #endif
@@ -1530,7 +1530,7 @@
 void hdd_indicate_mgmt_frame(tSirSmeMgmtFrameInd *frame_ind);
 hdd_adapter_t *hdd_get_adapter_by_sme_session_id(hdd_context_t *hdd_ctx,
 						uint32_t sme_session_id);
-phy_ch_width hdd_map_nl_chan_width(enum nl80211_chan_width ch_width);
+enum ch_width hdd_map_nl_chan_width(enum nl80211_chan_width ch_width);
 uint8_t wlan_hdd_find_opclass(tHalHandle hal, uint8_t channel,
 			uint8_t bw_offset);
 void hdd_update_config(hdd_context_t *hdd_ctx);
diff --git a/core/hdd/inc/wlan_hdd_regulatory.h b/core/hdd/inc/wlan_hdd_regulatory.h
new file mode 100644
index 0000000..d541b14
--- /dev/null
+++ b/core/hdd/inc/wlan_hdd_regulatory.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2016 The Linux Foundation. All rights reserved.
+ *
+ * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
+ *
+ *
+ * Permission to use, copy, modify, and/or distribute this software for
+ * any purpose with or without fee is hereby granted, provided that the
+ * above copyright notice and this permission notice appear in all
+ * copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
+ * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/*
+ * This file was originally distributed by Qualcomm Atheros, Inc.
+ * under proprietary terms before Copyright ownership was assigned
+ * to the Linux Foundation.
+ */
+
+#if !defined __HDD_REGULATORY_H
+#define __HDD_REGULATORY_H
+
+/**
+ * DOC: wlan_hdd_regulatory.h
+ *
+ * HDD Regulatory prototype implementation
+ */
+
+int hdd_regulatory_init(hdd_context_t *hdd_ctx, struct wiphy *wiphy);
+
+void hdd_program_country_code(hdd_context_t *hdd_ctx);
+
+#endif
diff --git a/core/hdd/src/wlan_hdd_cfg80211.c b/core/hdd/src/wlan_hdd_cfg80211.c
index 7b229e6..9176680 100644
--- a/core/hdd/src/wlan_hdd_cfg80211.c
+++ b/core/hdd/src/wlan_hdd_cfg80211.c
@@ -7776,7 +7776,7 @@
 {
 	uint8_t iniDot11Mode = (WLAN_HDD_GET_CTX(pAdapter))->config->dot11Mode;
 	eHddDot11Mode hddDot11Mode = iniDot11Mode;
-	chan_params_t ch_params;
+	struct ch_params_s ch_params;
 	ch_params.ch_width =
 			(WLAN_HDD_GET_CTX(pAdapter))->config->vhtChannelWidth;
 
@@ -11166,7 +11166,7 @@
 	uint8_t channel;
 	uint16_t freq;
 	int ret;
-	phy_ch_width ch_width;
+	enum ch_width ch_width;
 
 	hddLog(LOG1, FL("Set Freq %d"),
 		  csa_params->chandef.chan->center_freq);
diff --git a/core/hdd/src/wlan_hdd_hostapd.c b/core/hdd/src/wlan_hdd_hostapd.c
index 2e82f5f..4351c72 100644
--- a/core/hdd/src/wlan_hdd_hostapd.c
+++ b/core/hdd/src/wlan_hdd_hostapd.c
@@ -2005,7 +2005,7 @@
  * Return: 0 for success, non zero for failure
  */
 int hdd_softap_set_channel_change(struct net_device *dev, int target_channel,
-				 phy_ch_width target_bw)
+				 enum ch_width target_bw)
 {
 	QDF_STATUS status;
 	int ret = 0;
diff --git a/core/hdd/src/wlan_hdd_hostapd.h b/core/hdd/src/wlan_hdd_hostapd.h
index 0706e56..eff1d5d 100644
--- a/core/hdd/src/wlan_hdd_hostapd.h
+++ b/core/hdd/src/wlan_hdd_hostapd.h
@@ -58,8 +58,8 @@
 hdd_translate_rsn_to_csr_auth_type(uint8_t auth_suite[4]);
 
 int hdd_softap_set_channel_change(struct net_device *dev,
-				int target_channel,
-				phy_ch_width target_bw);
+				  int target_channel,
+				  enum ch_width target_bw);
 
 eCsrEncryptionType
 hdd_translate_rsn_to_csr_encryption_type(uint8_t cipher_suite[4]);
diff --git a/core/hdd/src/wlan_hdd_ioctl.c b/core/hdd/src/wlan_hdd_ioctl.c
index 25882c7..e8d80bb 100644
--- a/core/hdd/src/wlan_hdd_ioctl.c
+++ b/core/hdd/src/wlan_hdd_ioctl.c
@@ -6022,7 +6022,7 @@
 	int status;
 	uint32_t chan_number = 0, chan_bw = 0;
 	uint8_t *value = command;
-	phy_ch_width width;
+	enum ch_width width;
 
 	if ((adapter->device_mode != WLAN_HDD_P2P_GO) &&
 		(adapter->device_mode != WLAN_HDD_SOFTAP)) {
diff --git a/core/hdd/src/wlan_hdd_main.c b/core/hdd/src/wlan_hdd_main.c
index f24caa1..8c4a7bf 100644
--- a/core/hdd/src/wlan_hdd_main.c
+++ b/core/hdd/src/wlan_hdd_main.c
@@ -106,6 +106,7 @@
 #include "wlan_hdd_green_ap.h"
 #include "platform_icnss.h"
 #include "bmi.h"
+#include <wlan_hdd_regulatory.h>
 
 #ifdef MODULE
 #define WLAN_MODULE_NAME  module_name(THIS_MODULE)
@@ -245,7 +246,7 @@
  */
 int hdd_validate_channel_and_bandwidth(hdd_adapter_t *adapter,
 		uint32_t chan_number,
-		phy_ch_width chan_bw)
+		enum ch_width chan_bw)
 {
 	uint8_t chan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
 	uint32_t len = WNI_CFG_VALID_CHANNEL_LIST_LEN, i;
@@ -432,7 +433,7 @@
  * Return: Converted channel width. In case of non matching NL channel width,
  * CH_WIDTH_MAX will be returned.
  */
-phy_ch_width hdd_map_nl_chan_width(enum nl80211_chan_width ch_width)
+enum ch_width hdd_map_nl_chan_width(enum nl80211_chan_width ch_width)
 {
 	switch (ch_width) {
 	case NL80211_CHAN_WIDTH_20_NOHT:
@@ -4163,10 +4164,10 @@
 	return true;
 }
 
-static QDF_STATUS wlan_hdd_regulatory_init(hdd_context_t *hdd_ctx)
+static int hdd_wiphy_init(hdd_context_t *hdd_ctx)
 {
 	struct wiphy *wiphy;
-	QDF_STATUS status = QDF_STATUS_SUCCESS;
+	int ret_val;
 
 	wiphy = hdd_ctx->wiphy;
 
@@ -4174,11 +4175,10 @@
 	 * The channel information in
 	 * wiphy needs to be initialized before wiphy registration
 	 */
-	status = cds_regulatory_init();
-	if (!QDF_IS_STATUS_SUCCESS(status)) {
-		hddLog(QDF_TRACE_LEVEL_FATAL,
-		       FL("cds_init_wiphy failed"));
-		return status;
+	ret_val = hdd_regulatory_init(hdd_ctx, wiphy);
+	if (ret_val) {
+		hdd_alert("regulatory init failed");
+		return ret_val;
 	}
 
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
@@ -4200,12 +4200,11 @@
 #endif
 
 	/* registration of wiphy dev with cfg80211 */
-	if (0 > wlan_hdd_cfg80211_register(wiphy)) {
-		hddLog(QDF_TRACE_LEVEL_ERROR, FL("wiphy register failed"));
-		status = QDF_STATUS_E_FAILURE;
-	}
+	ret_val = wlan_hdd_cfg80211_register(wiphy);
+	if (0 > ret_val)
+		hdd_err("wiphy registration failed");
 
-	return status;
+	return ret_val;
 }
 
 #ifdef MSM_PLATFORM
@@ -5468,6 +5467,7 @@
 	tSirTxPowerLimit hddtxlimit;
 	bool rtnl_held;
 	tSirRetStatus hal_status;
+	int ret_val;
 
 	ENTER();
 
@@ -5516,11 +5516,10 @@
 
 	ol_txrx_register_pause_cb(wlan_hdd_txrx_pause_cb);
 
-	status = wlan_hdd_regulatory_init(hdd_ctx);
+	ret_val = hdd_wiphy_init(hdd_ctx);
 
-	if (status != QDF_STATUS_SUCCESS) {
-		hddLog(QDF_TRACE_LEVEL_FATAL,
-		       FL("Failed to init channel list"));
+	if (ret_val) {
+		hdd_alert("failed to initialize wiphy");
 		goto err_cds_close;
 	}
 
@@ -5554,6 +5553,8 @@
 		       __func__, ret);
 	}
 
+	hdd_program_country_code(hdd_ctx);
+
 	status = hdd_set_sme_chan_list(hdd_ctx);
 	if (status != QDF_STATUS_SUCCESS) {
 		hddLog(QDF_TRACE_LEVEL_FATAL,
diff --git a/core/hdd/src/wlan_hdd_regulatory.c b/core/hdd/src/wlan_hdd_regulatory.c
new file mode 100644
index 0000000..35886b7
--- /dev/null
+++ b/core/hdd/src/wlan_hdd_regulatory.c
@@ -0,0 +1,766 @@
+/*
+ * Copyright (c) 2014-2016 The Linux Foundation. All rights reserved.
+ *
+ * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
+ *
+ *
+ * Permission to use, copy, modify, and/or distribute this software for
+ * any purpose with or without fee is hereby granted, provided that the
+ * above copyright notice and this permission notice appear in all
+ * copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
+ * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/*
+ * This file was originally distributed by Qualcomm Atheros, Inc.
+ * under proprietary terms before Copyright ownership was assigned
+ * to the Linux Foundation.
+ */
+
+/**
+ * DOC: wlan_hdd_regulatory.c
+ *
+ * hdd regulatory implementation
+ */
+
+#include "qdf_types.h"
+#include "cds_reg_service.h"
+#include "qdf_trace.h"
+#include "sme_api.h"
+#include "wlan_hdd_main.h"
+#include "cds_regdomain.h"
+#include "cds_regdomain_common.h"
+#include "wlan_hdd_regulatory.h"
+
+#define WORLD_SKU_MASK      0x00F0
+#define WORLD_SKU_PREFIX    0x0060
+#define REG_WAIT_TIME       50
+
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0)) || defined(WITH_BACKPORTS)
+#define IEEE80211_CHAN_PASSIVE_SCAN IEEE80211_CHAN_NO_IR
+#define IEEE80211_CHAN_NO_IBSS IEEE80211_CHAN_NO_IR
+#endif
+
+#define REG_RULE_2412_2462    REG_RULE(2412-10, 2462+10, 40, 0, 20, 0)
+
+#define REG_RULE_2467_2472    REG_RULE(2467-10, 2472+10, 40, 0, 20, \
+			      NL80211_RRF_PASSIVE_SCAN)
+
+#define REG_RULE_2484         REG_RULE(2484-10, 2484+10, 40, 0, 20, \
+		NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_OFDM)
+
+#define REG_RULE_5180_5320    REG_RULE(5180-10, 5320+10, 80, 0, 20, \
+		NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS)
+
+#define REG_RULE_5500_5720    REG_RULE(5500-10, 5720+10, 80, 0, 20, \
+		NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS)
+
+#define REG_RULE_5745_5925    REG_RULE(5745-10, 5925+10, 80, 0, 20, \
+		NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS)
+
+static bool init_by_driver;
+static bool init_by_reg_core;
+
+static const struct ieee80211_regdomain
+hdd_world_regrules_60_61_62 = {
+	.n_reg_rules = 6,
+	.alpha2 =  "00",
+	.reg_rules = {
+		REG_RULE_2412_2462,
+		REG_RULE_2467_2472,
+		REG_RULE_2484,
+		REG_RULE_5180_5320,
+		REG_RULE_5500_5720,
+		REG_RULE_5745_5925,
+	}
+};
+
+static const struct ieee80211_regdomain
+hdd_world_regrules_63_65 = {
+	.n_reg_rules = 4,
+	.alpha2 =  "00",
+	.reg_rules = {
+		REG_RULE_2412_2462,
+		REG_RULE_2467_2472,
+		REG_RULE_5180_5320,
+		REG_RULE_5745_5925,
+	}
+};
+
+static const struct ieee80211_regdomain
+hdd_world_regrules_64 = {
+	.n_reg_rules = 3,
+	.alpha2 =  "00",
+	.reg_rules = {
+		REG_RULE_2412_2462,
+		REG_RULE_5180_5320,
+		REG_RULE_5745_5925,
+	}
+};
+
+static const struct ieee80211_regdomain
+hdd_world_regrules_66_69 = {
+	.n_reg_rules = 4,
+	.alpha2 =  "00",
+	.reg_rules = {
+		REG_RULE_2412_2462,
+		REG_RULE_5180_5320,
+		REG_RULE_5500_5720,
+		REG_RULE_5745_5925,
+	}
+};
+
+static const struct ieee80211_regdomain
+hdd_world_regrules_67_68_6A_6C = {
+	.n_reg_rules = 5,
+	.alpha2 =  "00",
+	.reg_rules = {
+		REG_RULE_2412_2462,
+		REG_RULE_2467_2472,
+		REG_RULE_5180_5320,
+		REG_RULE_5500_5720,
+		REG_RULE_5745_5925,
+	}
+};
+
+/**
+ * hdd_get_world_regrules() - get the appropriate world regrules
+ * @reg: regulatory data
+ *
+ * Return: regulatory rules ptr
+ */
+static const struct ieee80211_regdomain *hdd_get_world_regrules(
+struct regulatory *reg)
+{
+	REG_DMN_PAIR_MAPPING *regpair =
+		(REG_DMN_PAIR_MAPPING *)reg->regpair;
+
+	switch (regpair->regDmnEnum) {
+	case 0x60:
+	case 0x61:
+	case 0x62:
+		return &hdd_world_regrules_60_61_62;
+	case 0x63:
+	case 0x65:
+		return &hdd_world_regrules_63_65;
+	case 0x64:
+		return &hdd_world_regrules_64;
+	case 0x66:
+	case 0x69:
+		return &hdd_world_regrules_66_69;
+	case 0x67:
+	case 0x68:
+	case 0x6A:
+	case 0x6C:
+		return &hdd_world_regrules_67_68_6A_6C;
+	default:
+		hdd_warn("invalid world mode in BDF");
+		return &hdd_world_regrules_60_61_62;
+	}
+}
+
+/**
+ * hdd_is_world_regdomain() - whether world regdomain
+ * @reg_domain: integer regulatory domain
+ *
+ * Return: bool
+ */
+bool hdd_is_world_regdomain(uint32_t reg_domain)
+{
+	uint32_t temp_regd = reg_domain & ~WORLDWIDE_ROAMING_FLAG;
+
+	return ((temp_regd & COUNTRY_ERD_FLAG) != COUNTRY_ERD_FLAG) &&
+		(((temp_regd & WORLD_SKU_MASK) == WORLD_SKU_PREFIX) ||
+		 (temp_regd == WORLD));
+}
+
+
+/**
+ * hdd_update_regulatory_info() - update regulatory info
+ * @hdd_ctx: hdd context
+ *
+ * Return: void
+ */
+static void hdd_update_regulatory_info(hdd_context_t *hdd_ctx)
+{
+	uint32_t country_code;
+
+	country_code = cds_get_country_from_alpha2(hdd_ctx->reg.alpha2);
+
+	hdd_ctx->reg.reg_domain = COUNTRY_ERD_FLAG;
+	hdd_ctx->reg.reg_domain |= country_code;
+
+	cds_fill_some_regulatory_info(&hdd_ctx->reg);
+
+}
+
+/**
+ * hdd_regulatory_wiphy_init() - regulatory wiphy init
+ * @hdd_ctx: hdd context
+ * @reg: regulatory data
+ * @wiphy: wiphy structure
+ *
+ * Return: void
+ */
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0)) || defined(WITH_BACKPORTS)
+static void hdd_regulatory_wiphy_init(hdd_context_t *hdd_ctx,
+				     struct regulatory *reg,
+				     struct wiphy *wiphy)
+{
+	const struct ieee80211_regdomain *reg_rules;
+
+	if (hdd_is_world_regdomain(reg->reg_domain)) {
+		reg_rules = hdd_get_world_regrules(reg);
+		wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG;
+	} else if (hdd_ctx->config->fRegChangeDefCountry) {
+		wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG;
+		reg_rules = &hdd_world_regrules_60_61_62;
+	} else {
+		wiphy->regulatory_flags |= REGULATORY_STRICT_REG;
+		reg_rules = &hdd_world_regrules_60_61_62;
+	}
+
+	/*
+	 * save the original driver regulatory flags
+	 */
+	hdd_ctx->reg.reg_flags = wiphy->regulatory_flags;
+	wiphy_apply_custom_regulatory(wiphy, reg_rules);
+
+	/*
+	 * restore the driver regulatory flags since
+	 * wiphy_apply_custom_regulatory may have
+	 * changed them
+	 */
+	wiphy->regulatory_flags = hdd_ctx->reg.reg_flags;
+
+}
+#else
+static void hdd_regulatory_wiphy_init(hdd_context_t *hdd_ctx,
+				     struct regulatory *reg,
+				     struct wiphy *wiphy)
+{
+	const struct ieee80211_regdomain *reg_rules;
+
+	if (hdd_is_world_regdomain(reg->reg_domain)) {
+		reg_rules = hdd_get_world_regrules(reg);
+		wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY;
+	} else if (hdd_ctx->config->fRegChangeDefCountry) {
+		wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY;
+		reg_rules = &hdd_world_regrules_60_61_62;
+	} else {
+		wiphy->flags |= WIPHY_FLAG_STRICT_REGULATORY;
+		reg_rules = &hdd_world_regrules_60_61_62;
+	}
+
+	/*
+	 * save the original driver regulatory flags
+	 */
+	hdd_ctx->reg.reg_flags = wiphy->flags;
+	wiphy_apply_custom_regulatory(wiphy, reg_rules);
+
+	/*
+	 * restore the driver regulatory flags since
+	 * wiphy_apply_custom_regulatory may have
+	 * changed them
+	 */
+	wiphy->flags = hdd_ctx->reg.reg_flags;
+
+}
+#endif
+
+/**
+ * hdd_bw20_ch_index_to_() - convert 20 mhhz channel index to 40 mhz index
+ * @k: 20 mhz channel index
+ *
+ * Return: void
+ */
+static int hdd_bw20_ch_index_to_bw40_ch_index(int k)
+{
+	int m = -1;
+
+	if (k >= RF_CHAN_1 && k <= RF_CHAN_14) {
+		m = k - RF_CHAN_1 + RF_CHAN_BOND_3;
+		if (m > RF_CHAN_BOND_11)
+			m = RF_CHAN_BOND_11;
+	} else if (k >= RF_CHAN_36 && k <= RF_CHAN_64) {
+		m = k - RF_CHAN_36 + RF_CHAN_BOND_38;
+		if (m > RF_CHAN_BOND_62)
+			m = RF_CHAN_BOND_62;
+	} else if (k >= RF_CHAN_100 && k <= RF_CHAN_144) {
+		m = k - RF_CHAN_100 + RF_CHAN_BOND_102;
+		if (m > RF_CHAN_BOND_142)
+			m = RF_CHAN_BOND_142;
+	} else if (k >= RF_CHAN_149 && k <= RF_CHAN_165) {
+		m = k - RF_CHAN_149 + RF_CHAN_BOND_151;
+		if (m > RF_CHAN_BOND_163)
+			m = RF_CHAN_BOND_163;
+	}
+
+	return m;
+}
+
+/**
+ * is_wiphy_custom_regulatory() - is custom regulatory defined
+ * @wiphy: wiphy
+ *
+ * Return: int
+ */
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0)) || defined(WITH_BACKPORTS)
+static int is_wiphy_custom_regulatory(struct wiphy *wiphy)
+{
+
+	return wiphy->regulatory_flags & REGULATORY_CUSTOM_REG;
+}
+#else
+static int is_wiphy_custom_regulatory(struct wiphy *wiphy)
+{
+	return wiphy->flags & WIPHY_FLAG_CUSTOM_REGULATORY;
+}
+#endif
+
+
+/**
+ * hdd_modify_wiphy() - modify wiphy
+ * @wiphy: wiphy
+ * @chan: channel structure
+ *
+ * Return: void
+ */
+static void hdd_modify_wiphy(struct wiphy  *wiphy,
+			     struct ieee80211_channel *chan)
+{
+	const struct ieee80211_reg_rule *reg_rule;
+
+	if (is_wiphy_custom_regulatory(wiphy)) {
+		reg_rule = freq_reg_info(wiphy, MHZ_TO_KHZ(chan->center_freq));
+		if (!IS_ERR(reg_rule)) {
+			chan->flags &= ~IEEE80211_CHAN_DISABLED;
+
+			if (!(reg_rule->flags & NL80211_RRF_DFS)) {
+				hdd_info("%s: remove dfs restriction for %u",
+					 __func__, chan->center_freq);
+				chan->flags &= ~IEEE80211_CHAN_RADAR;
+			}
+
+			if (!(reg_rule->flags & NL80211_RRF_PASSIVE_SCAN)) {
+				hdd_info("%s: remove passive restriction for %u",
+					 __func__, chan->center_freq);
+				chan->flags &= ~IEEE80211_CHAN_PASSIVE_SCAN;
+			}
+
+			if (!(reg_rule->flags & NL80211_RRF_NO_IBSS)) {
+				hdd_info("%s: remove no ibss restriction for %u",
+					 __func__, chan->center_freq);
+				chan->flags &= ~IEEE80211_CHAN_NO_IBSS;
+			}
+
+			chan->max_power =
+				MBM_TO_DBM(reg_rule->power_rule.max_eirp);
+		}
+	}
+}
+
+/**
+ * hdd_process_regulatory_data() - process regulatory data
+ * @hdd_ctx: hdd context
+ * @wiphy: wiphy
+ * @reset: whether to reset channel data
+ *
+ * Return: void
+ */
+static void hdd_process_regulatory_data(hdd_context_t *hdd_ctx,
+					struct wiphy *wiphy,
+					bool reset)
+{
+	int i, j, m;
+	int k = 0, n = 0;
+	struct ieee80211_channel *chan;
+	struct regulatory_channel *temp_chan_k, *temp_chan_n, *temp_chan;
+	uint8_t band_capability;
+
+	band_capability = hdd_ctx->config->nBandCapability;
+
+	hdd_ctx->isVHT80Allowed = 0;
+
+	if (band_capability == eCSR_BAND_24)
+		hdd_info("band capability is set to 2G only");
+
+	for (i = 0, m = 0; i < IEEE80211_NUM_BANDS; i++) {
+
+		if (i == IEEE80211_BAND_2GHZ &&
+		    band_capability == eCSR_BAND_5G)
+			continue;
+
+		else if (i == IEEE80211_BAND_5GHZ &&
+			 band_capability == eCSR_BAND_24)
+			continue;
+
+		if (wiphy->bands[i] == NULL) {
+			hdd_info("wiphy band no %d is NULL", i);
+			continue;
+		}
+
+		if (i == 0)
+			m = 0;
+		else
+			m = wiphy->bands[i-1]->n_channels + m;
+
+		for (j = 0; j < wiphy->bands[i]->n_channels; j++) {
+
+			k = m + j;
+			n = hdd_bw20_ch_index_to_bw40_ch_index(k);
+
+			chan = &(wiphy->bands[i]->channels[j]);
+			temp_chan_k = &(reg_channels[k]);
+			temp_chan_n = &(reg_channels[n]);
+
+			if (!reset)
+				hdd_modify_wiphy(wiphy, chan);
+
+			if (chan->flags & IEEE80211_CHAN_DISABLED) {
+				temp_chan_k->state =
+					CHANNEL_STATE_DISABLE;
+				temp_chan_k->flags = chan->flags;
+				if (n != -1) {
+					temp_chan_n->state =
+						CHANNEL_STATE_DISABLE;
+					temp_chan_n->flags = chan->flags;
+				}
+			} else if (chan->flags &
+				   (IEEE80211_CHAN_RADAR |
+				    IEEE80211_CHAN_PASSIVE_SCAN |
+				    IEEE80211_CHAN_INDOOR_ONLY)) {
+
+				if (chan->flags &
+				    IEEE80211_CHAN_INDOOR_ONLY)
+					chan->flags |=
+						IEEE80211_CHAN_PASSIVE_SCAN;
+				temp_chan_k->state = CHANNEL_STATE_DFS;
+				temp_chan_k->pwr_limit =
+					chan->max_power;
+				temp_chan_k->flags = chan->flags;
+
+				if (n != -1) {
+					if ((chan->flags &
+					     IEEE80211_CHAN_NO_HT40) ==
+					    IEEE80211_CHAN_NO_HT40) {
+						temp_chan_n->state =
+							CHANNEL_STATE_DISABLE;
+					} else {
+						temp_chan_n->state =
+							CHANNEL_STATE_DFS;
+						temp_chan_n->pwr_limit =
+							 chan->max_power-3;
+					}
+					temp_chan_n->flags = chan->flags;
+				}
+				if ((chan->flags &
+				     IEEE80211_CHAN_NO_80MHZ) == 0)
+					hdd_ctx->isVHT80Allowed = 1;
+			} else {
+				temp_chan_k->state = CHANNEL_STATE_ENABLE;
+				temp_chan_k->pwr_limit = chan->max_power;
+				temp_chan_k->flags = chan->flags;
+				if (n != -1) {
+					if ((chan->flags &
+					     IEEE80211_CHAN_NO_HT40) ==
+					    IEEE80211_CHAN_NO_HT40) {
+						temp_chan_n->state =
+							CHANNEL_STATE_DISABLE;
+					} else {
+						temp_chan_n->state =
+							CHANNEL_STATE_ENABLE;
+						temp_chan_n->pwr_limit =
+							chan->max_power - 3;
+					}
+					temp_chan_n->flags = chan->flags;
+				}
+				if ((chan->flags &
+				     IEEE80211_CHAN_NO_80MHZ) == 0)
+					hdd_ctx->isVHT80Allowed = 1;
+			}
+		}
+	}
+
+	if (0 == (hdd_ctx->reg.eeprom_rd_ext &
+		  (1 << WHAL_REG_EXT_FCC_CH_144))) {
+		temp_chan = &(reg_channels[RF_CHAN_144]);
+		temp_chan->state =
+			CHANNEL_STATE_DISABLE;
+	}
+
+}
+
+
+/**
+ * hdd_regulatory_init() - regulatory_init
+ * @hdd_ctx: hdd context
+ * @wiphy: wiphy
+ *
+ * Return: int
+ */
+int hdd_regulatory_init(hdd_context_t *hdd_ctx, struct wiphy *wiphy)
+{
+	int ret_val;
+	struct regulatory *reg_info;
+
+	reg_info = &hdd_ctx->reg;
+
+	hdd_regulatory_wiphy_init(hdd_ctx, reg_info, wiphy);
+
+	hdd_process_regulatory_data(hdd_ctx, wiphy, true);
+
+	reg_info->cc_src = SOURCE_DRIVER;
+
+	ret_val = cds_fill_some_regulatory_info(reg_info);
+	if (ret_val) {
+		hdd_err("incorrect BDF regulatory data");
+		return ret_val;
+	}
+
+	cds_put_default_country(reg_info->alpha2);
+
+	init_completion(&hdd_ctx->reg_init);
+
+	cds_fill_and_send_ctl_to_fw(reg_info);
+
+	return 0;
+}
+
+/**
+ * hdd_program_country_code() - process channel information from country code
+ * @hdd_ctx: hddc context
+ *
+ * Return: void
+ */
+void hdd_program_country_code(hdd_context_t *hdd_ctx)
+{
+	struct wiphy *wiphy = hdd_ctx->wiphy;
+	uint8_t *country_alpha2 = hdd_ctx->reg.alpha2;
+
+	if (false == init_by_reg_core) {
+		init_by_driver = true;
+		if (('0' != country_alpha2[0]) ||
+		    ('0' != country_alpha2[1])) {
+			INIT_COMPLETION(hdd_ctx->reg_init);
+			regulatory_hint(wiphy, country_alpha2);
+			wait_for_completion_timeout(&hdd_ctx->reg_init,
+					      msecs_to_jiffies(REG_WAIT_TIME));
+		}
+	}
+}
+
+
+/**
+ * hdd_set_dfs_region() - set the dfs_region
+ * @dfs_region: the dfs_region to set
+ *
+ * Return: void
+ */
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0)) || defined(WITH_BACKPORTS)
+static void hdd_set_dfs_region(hdd_context_t *hdd_ctx,
+			       uint8_t dfs_reg)
+{
+	cds_put_dfs_region(dfs_reg);
+}
+#else
+static void hdd_set_dfs_region(hdd_context_t *hdd_ctx,
+				     uint8_t dfs_reg)
+{
+
+	/* remap the ctl code to dfs region code */
+	switch (hdd_ctx->reg.ctl_5g) {
+	case FCC:
+		cds_put_dfs_region(DFS_FCC_DOMAIN);
+		break;
+	case ETSI:
+		cds_put_dfs_region(DFS_ETSI_DOMAIN);
+		break;
+	case MKK:
+		cds_put_dfs_region(DFS_MKK4_DOMAIN);
+		break;
+	default:
+		/* set default dfs_region to FCC */
+		cds_put_dfs_region(DFS_FCC_DOMAIN);
+		break;
+	}
+
+}
+#endif
+
+/**
+ * hdd_restore_custom_reg_settings() - restore custom reg settings
+ * @wiphy: wiphy structure
+ * @country_alpha2: alpha2 of the country
+ * @reset: whether wiphy is reset
+ *
+ * Return: void
+ */
+#if (LINUX_VERSION_CODE > KERNEL_VERSION(3, 14, 0)) || defined(WITH_BACKPORTS)
+static void hdd_restore_custom_reg_settings(struct wiphy *wiphy,
+					    uint8_t *country_alpha2,
+					    bool *reset)
+{
+}
+#else
+static void hdd_restore_custom_reg_settings(struct wiphy *wiphy,
+					    uint8_t *country_alpha2,
+					    bool *reset)
+{
+	struct ieee80211_supported_band *sband;
+	enum ieee80211_band band;
+	struct ieee80211_channel *chan;
+	int i;
+
+	if ((country_alpha2[0] == '0') &&
+	    (country_alpha2[1] == '0') &&
+	    (wiphy->flags & WIPHY_FLAG_CUSTOM_REGULATORY)) {
+
+		for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
+			sband = wiphy->bands[band];
+			if (!sband)
+				continue;
+			for (i = 0; i < sband->n_channels; i++) {
+				chan = &sband->channels[i];
+				chan->flags = chan->orig_flags;
+				chan->max_antenna_gain = chan->orig_mag;
+				chan->max_power = chan->orig_mpwr;
+			}
+		}
+		*reset = true;
+	}
+}
+#endif
+
+
+/**
+ * hdd_restore_reg_flags() - restore regulatory flags
+ * @flags: regulatory flags
+ *
+ * Return: void
+ */
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0)) || defined(WITH_BACKPORTS)
+static void hdd_restore_reg_flags(struct wiphy *wiphy, uint32_t flags)
+{
+	wiphy->regulatory_flags = flags;
+}
+#else
+static void hdd_restore_reg_flags(struct wiphy *wiphy, uint32_t flags)
+{
+	wiphy->flags = flags;
+}
+#endif
+
+
+/**
+ * hdd_reg_notifier() - regulatory notifier
+ * @wiphy: wiphy
+ * @request: regulatory request
+ *
+ * Return: void
+ */
+void hdd_reg_notifier(struct wiphy *wiphy,
+		      struct regulatory_request *request)
+{
+	hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
+	eCsrBand band_capability = eCSR_BAND_ALL;
+	bool vht80_allowed;
+	bool reset = false;
+	uint8_t dfs_reg;
+
+	hdd_info("country: %c%c, initiator %d, dfs_region: %d",
+		  request->alpha2[0],
+		  request->alpha2[1],
+		  request->initiator,
+		  request->dfs_region);
+
+	if (NULL == hdd_ctx) {
+		hdd_err("invalid hdd_ctx pointer");
+		return;
+	}
+
+	if (cds_is_driver_unloading() || cds_is_driver_recovering()) {
+		hdd_err("%s: unloading or ssr in progress, ignore",
+			__func__);
+		return;
+	}
+
+	sme_get_freq_band(hdd_ctx->hHal, &band_capability);
+
+	/* first check if this callback is in response to the driver callback */
+
+	switch (request->initiator) {
+	case NL80211_REGDOM_SET_BY_DRIVER:
+	case NL80211_REGDOM_SET_BY_CORE:
+	case NL80211_REGDOM_SET_BY_USER:
+
+		if ((false == init_by_driver) &&
+		    (false == init_by_reg_core)) {
+
+			if (NL80211_REGDOM_SET_BY_CORE == request->initiator)
+				return;
+			init_by_reg_core = true;
+		}
+
+		if ((NL80211_REGDOM_SET_BY_DRIVER == request->initiator) &&
+		    (true == init_by_driver)) {
+
+			/*
+			 * restore the driver regulatory flags since
+			 * regulatory_hint may have
+			 * changed them
+			 */
+			hdd_restore_reg_flags(wiphy, hdd_ctx->reg.reg_flags);
+		}
+
+		if (NL80211_REGDOM_SET_BY_CORE == request->initiator) {
+			hdd_ctx->reg.cc_src = SOURCE_CORE;
+			if (is_wiphy_custom_regulatory(wiphy))
+				reset = true;
+		} else if (NL80211_REGDOM_SET_BY_DRIVER == request->initiator)
+			hdd_ctx->reg.cc_src = SOURCE_DRIVER;
+		else {
+			hdd_ctx->reg.cc_src = SOURCE_USERSPACE;
+			hdd_restore_custom_reg_settings(wiphy,
+							request->alpha2,
+							&reset);
+		}
+
+		hdd_ctx->reg.alpha2[0] = request->alpha2[0];
+		hdd_ctx->reg.alpha2[1] = request->alpha2[1];
+
+		hdd_update_regulatory_info(hdd_ctx);
+
+		vht80_allowed = hdd_ctx->isVHT80Allowed;
+
+		hdd_process_regulatory_data(hdd_ctx, wiphy, reset);
+
+		if (hdd_ctx->isVHT80Allowed != vht80_allowed)
+			hdd_checkandupdate_phymode(hdd_ctx);
+
+		if (NL80211_REGDOM_SET_BY_DRIVER == request->initiator)
+			complete(&hdd_ctx->reg_init);
+
+		sme_generic_change_country_code(hdd_ctx->hHal,
+						hdd_ctx->reg.alpha2);
+
+		cds_fill_and_send_ctl_to_fw(&hdd_ctx->reg);
+
+		hdd_set_dfs_region(hdd_ctx, request->dfs_region);
+
+		cds_get_dfs_region(&dfs_reg);
+		cds_set_wma_dfs_region(dfs_reg);
+		break;
+
+	default:
+		break;
+	}
+}
diff --git a/core/mac/inc/sir_api.h b/core/mac/inc/sir_api.h
index 4e38f8a..e32a9d9 100644
--- a/core/mac/inc/sir_api.h
+++ b/core/mac/inc/sir_api.h
@@ -38,6 +38,9 @@
 #ifndef __SIR_API_H
 #define __SIR_API_H
 
+#include "qdf_types.h"
+#include "cds_reg_service.h"
+#include "cds_regdomain.h"
 #include "sir_types.h"
 #include "sir_mac_prot_def.h"
 #include "ani_system_defs.h"
@@ -288,37 +291,6 @@
 	uint8_t max_randn_interval;
 	uint8_t rm_capability[RMENABLEDCAP_MAX_LEN];
 };
-/**
- * typedef ch_width - channel width
- * @CH_WIDTH_20MHZ: channel width 20 MHz
- * @CH_WIDTH_40MHZ: channel width 40 MHz
- * @CH_WIDTH_80MHZ: channel width 80MHz
- * @CH_WIDTH_160MHZ: channel width 160 MHz
- * @CH_WIDTH_80P80MHZ: channel width 160MHz(80+80)
- */
-typedef enum ch_width {
-	CH_WIDTH_20MHZ = 0,
-	CH_WIDTH_40MHZ = 1,
-	CH_WIDTH_80MHZ = 2,
-	CH_WIDTH_160MHZ = 3,
-	CH_WIDTH_80P80MHZ = 4,
-	CH_WIDTH_MAX
-} phy_ch_width;
-
-/**
- * struct ch_params_s
- *
- * @ch_width: channel width
- * @sec_ch_offset: secondary channel offset
- * @center_freq_seg0: center freq for segment 0
- * @center_freq_seg1: center freq for segment 1
- */
-typedef struct ch_params_s {
-	enum ch_width ch_width;
-	uint8_t sec_ch_offset;
-	uint8_t center_freq_seg0;
-	uint8_t center_freq_seg1;
-} chan_params_t;
 
 /* each station added has a rate mode which specifies the sta attributes */
 typedef enum eStaRateMode {
@@ -3838,7 +3810,7 @@
 	uint16_t messageLen;
 	uint8_t targetChannel;
 	uint8_t sec_ch_offset;
-	phy_ch_width ch_width;
+	enum ch_width ch_width;
 	uint8_t center_freq_seg_0;
 	uint8_t center_freq_seg_1;
 	uint8_t bssid[QDF_MAC_ADDR_SIZE];
diff --git a/core/mac/src/pe/include/lim_global.h b/core/mac/src/pe/include/lim_global.h
index 336a0e8..ce289a4 100644
--- a/core/mac/src/pe/include/lim_global.h
+++ b/core/mac/src/pe/include/lim_global.h
@@ -506,7 +506,7 @@
 	uint8_t ch_center_freq_seg0;
 	uint8_t ch_center_freq_seg1;
 	uint8_t sec_ch_offset;
-	phy_ch_width ch_width;
+	enum ch_width ch_width;
 	int8_t switchCount;
 	uint32_t switchTimeoutValue;
 	uint8_t switchMode;
diff --git a/core/mac/src/pe/include/lim_session.h b/core/mac/src/pe/include/lim_session.h
index a952383..67efbf0 100644
--- a/core/mac/src/pe/include/lim_session.h
+++ b/core/mac/src/pe/include/lim_session.h
@@ -313,7 +313,7 @@
 	tLimOperatingModeInfo gLimOperatingMode;
 	uint8_t vhtCapabilityPresentInBeacon;
 	uint8_t ch_center_freq_seg0;
-	phy_ch_width ch_width;
+	enum ch_width ch_width;
 	uint8_t ch_center_freq_seg1;
 	uint8_t txBFIniFeatureEnabled;
 	uint8_t txbf_csn_value;
diff --git a/core/mac/src/pe/lim/lim_process_mlm_req_messages.c b/core/mac/src/pe/lim/lim_process_mlm_req_messages.c
index d4b6d52..003034d 100644
--- a/core/mac/src/pe/lim/lim_process_mlm_req_messages.c
+++ b/core/mac/src/pe/lim/lim_process_mlm_req_messages.c
@@ -2888,7 +2888,7 @@
  */
 void lim_set_channel(tpAniSirGlobal mac_ctx, uint8_t channel,
 		     uint8_t ch_center_freq_seg0, uint8_t ch_center_freq_seg1,
-		     phy_ch_width ch_width, int8_t max_tx_power,
+		     enum ch_width ch_width, int8_t max_tx_power,
 		     uint8_t pe_session_id)
 {
 	tpPESession pe_session;
diff --git a/core/mac/src/pe/lim/lim_send_messages.c b/core/mac/src/pe/lim/lim_send_messages.c
index b3ed195..e04af17 100644
--- a/core/mac/src/pe/lim/lim_send_messages.c
+++ b/core/mac/src/pe/lim/lim_send_messages.c
@@ -207,7 +207,7 @@
 					  uint8_t chnlNumber,
 					  uint8_t ch_center_freq_seg0,
 					  uint8_t ch_center_freq_seg1,
-					  phy_ch_width ch_width,
+					  enum ch_width ch_width,
 					  int8_t maxTxPower,
 					  uint8_t peSessionId,
 					  uint8_t is_restart)
diff --git a/core/mac/src/pe/lim/lim_send_messages.h b/core/mac/src/pe/lim/lim_send_messages.h
index 7db70c4..5bca220 100644
--- a/core/mac/src/pe/lim/lim_send_messages.h
+++ b/core/mac/src/pe/lim/lim_send_messages.h
@@ -67,10 +67,11 @@
 					  uint8_t chnlNumber,
 					  uint8_t ch_center_freq_seg0,
 					  uint8_t ch_center_freq_seg1,
-					  phy_ch_width ch_width,
+					  enum ch_width ch_width,
 					  int8_t maxTxPower,
 					  uint8_t peSessionId,
 					  uint8_t is_restart);
+
 tSirRetStatus lim_send_edca_params(tpAniSirGlobal pMac,
 				   tSirMacEdcaParamRecord *pUpdatedEdcaParams,
 				   uint16_t bssIdx);
diff --git a/core/mac/src/pe/lim/lim_send_sme_rsp_messages.c b/core/mac/src/pe/lim/lim_send_sme_rsp_messages.c
index 6e9d494..73adb6e 100644
--- a/core/mac/src/pe/lim/lim_send_sme_rsp_messages.c
+++ b/core/mac/src/pe/lim/lim_send_sme_rsp_messages.c
@@ -2023,7 +2023,7 @@
 	uint8_t session_id;
 	uint16_t aid = 0;
 	uint16_t chan_space = 0;
-	chan_params_t ch_params;
+	struct ch_params_s ch_params;
 
 	tLimWiderBWChannelSwitchInfo *chnl_switch_info = NULL;
 	tLimChannelSwitchInfo *lim_ch_switch = NULL;
diff --git a/core/mac/src/pe/lim/lim_types.h b/core/mac/src/pe/lim/lim_types.h
index a8ed593..c6067ac 100644
--- a/core/mac/src/pe/lim/lim_types.h
+++ b/core/mac/src/pe/lim/lim_types.h
@@ -552,7 +552,7 @@
 /* / Function that Switches the Channel and sets the CB Mode */
 void lim_set_channel(tpAniSirGlobal pMac, uint8_t channel,
 		uint8_t ch_center_freq_seg0, uint8_t ch_center_freq_seg1,
-		phy_ch_width ch_width, int8_t maxTxPower,
+		enum ch_width ch_width, int8_t maxTxPower,
 		uint8_t peSessionId);
 
 
diff --git a/core/mac/src/pe/lim/lim_utils.c b/core/mac/src/pe/lim/lim_utils.c
index 512cf83..bb560d5 100644
--- a/core/mac/src/pe/lim/lim_utils.c
+++ b/core/mac/src/pe/lim/lim_utils.c
@@ -2727,7 +2727,7 @@
 					uint8_t newChannel,
 					uint8_t ch_center_freq_seg0,
 					uint8_t ch_center_freq_seg1,
-					phy_ch_width ch_width)
+					enum ch_width ch_width)
 {
 	uint8_t subband = 0;
 
diff --git a/core/mac/src/pe/lim/lim_utils.h b/core/mac/src/pe/lim/lim_utils.h
index 98b1e17..7d4ea1d 100644
--- a/core/mac/src/pe/lim/lim_utils.h
+++ b/core/mac/src/pe/lim/lim_utils.h
@@ -219,7 +219,7 @@
 					uint8_t newChannel,
 					uint8_t ch_center_freq_seg0,
 					uint8_t ch_center_freq_seg1,
-					phy_ch_width ch_width);
+					enum ch_width ch_width);
 void limUpdateStaRunTimeHTSwtichChnlParams(tpAniSirGlobal pMac,
 		tDot11fIEHTInfo *pRcvdHTInfo,
 		uint8_t bssIdx);
diff --git a/core/sap/inc/sap_api.h b/core/sap/inc/sap_api.h
index f0564b5..e793044 100644
--- a/core/sap/inc/sap_api.h
+++ b/core/sap/inc/sap_api.h
@@ -507,7 +507,7 @@
 	struct qdf_mac_addr self_macaddr;       /* self macaddress or BSSID */
 	uint8_t channel;          /* Operation channel */
 	uint8_t sec_ch;
-	chan_params_t ch_params;
+	struct ch_params_s ch_params;
 	uint32_t ch_width_orig;
 	uint8_t max_num_sta;      /* maximum number of STAs in station table */
 	uint8_t dtim_period;      /* dtim interval */
@@ -621,9 +621,9 @@
 	 * New channel width and new channel bonding mode
 	 * will only be updated via channel fallback mechanism
 	 */
-	phy_ch_width orig_chanWidth;
-	phy_ch_width new_chanWidth;
-	chan_params_t new_ch_params;
+	enum ch_width orig_chanWidth;
+	enum ch_width new_chanWidth;
+	struct ch_params_s new_ch_params;
 
 	/*
 	 * INI param to enable/disable SAP W53
@@ -827,9 +827,8 @@
 QDF_STATUS wlansap_deauth_sta(void *p_cds_gctx,
 			struct tagCsrDelStaParams *pDelStaParams);
 QDF_STATUS wlansap_set_channel_change_with_csa(void *p_cds_gctx,
-			uint32_t targetChannel, phy_ch_width target_bw);
-QDF_STATUS wlansap_set_key_sta(void *p_cds_gctx,
-	tCsrRoamSetKey *pSetKeyInfo);
+			uint32_t targetChannel, enum ch_width target_bw);
+QDF_STATUS wlansap_set_key_sta(void *p_cds_gctx, tCsrRoamSetKey *pSetKeyInfo);
 QDF_STATUS wlansap_get_assoc_stations(void *p_cds_gctx,
 	 QDF_MODULE_ID module, tpSap_AssocMacAddr pAssocStas);
 QDF_STATUS wlansap_remove_wps_session_overlap(void *p_cds_gctx,
diff --git a/core/sap/src/sap_api_link_cntl.c b/core/sap/src/sap_api_link_cntl.c
index 777c0ed..643a21e 100644
--- a/core/sap/src/sap_api_link_cntl.c
+++ b/core/sap/src/sap_api_link_cntl.c
@@ -238,7 +238,7 @@
 							uint32_t sec_ch)
 {
 	uint32_t channel = sap_ctx->acs_cfg->pri_ch;
-	chan_params_t ch_params = {0};
+	struct ch_params_s ch_params = {0};
 
 	ch_params.ch_width = sap_ctx->acs_cfg->ch_width;
 	sme_set_ch_params(hal, sap_ctx->csr_roamProfile.phyMode, channel,
diff --git a/core/sap/src/sap_fsm.c b/core/sap/src/sap_fsm.c
index f112224..b5a7353 100644
--- a/core/sap/src/sap_fsm.c
+++ b/core/sap/src/sap_fsm.c
@@ -890,7 +890,7 @@
  */
 bool
 sap_find_target_channel_in_channel_matrix(ptSapContext sapContext,
-					  phy_ch_width ch_width,
+					  enum ch_width ch_width,
 					  uint8_t NOL_channel,
 					  tSapTxLeakInfo **pTarget_chnl_mtrx)
 {
@@ -955,7 +955,7 @@
 
 QDF_STATUS
 sap_mark_channels_leaking_into_nol(ptSapContext sap_ctx,
-		phy_ch_width ch_width,
+		enum ch_width ch_width,
 		tSapDfsNolInfo *nol,
 		uint8_t temp_ch_lst_sz,
 		uint8_t *temp_ch_lst)
@@ -1069,7 +1069,7 @@
  * Return: number of channels found
  */
 static uint8_t sap_populate_available_channels(chan_bonding_bitmap *bitmap,
-		phy_ch_width ch_width,
+		enum ch_width ch_width,
 		uint8_t *avail_chnl)
 {
 	uint8_t i = 0;
@@ -1246,7 +1246,7 @@
 	uint8_t channelID;
 	tHalHandle hHal = CDS_GET_HAL_CB(sapContext->p_cds_gctx);
 	tpAniSirGlobal pMac;
-	phy_ch_width ch_width;
+	enum ch_width ch_width;
 	uint8_t   *tmp_ch_lst = NULL;
 	uint8_t   dfs_region;
 
diff --git a/core/sap/src/sap_internal.h b/core/sap/src/sap_internal.h
index d52d4f6..3a1d2c8 100644
--- a/core/sap/src/sap_internal.h
+++ b/core/sap/src/sap_internal.h
@@ -212,7 +212,7 @@
 	uint8_t *channelList;
 	tSapChannelListInfo SapChnlList;
 	uint16_t ch_width_orig;
-	chan_params_t ch_params;
+	struct ch_params_s ch_params;
 
 	/* session to scan */
 	bool isScanSessionOpen;
diff --git a/core/sap/src/sap_module.c b/core/sap/src/sap_module.c
index 31450ec..a2aee09 100644
--- a/core/sap/src/sap_module.c
+++ b/core/sap/src/sap_module.c
@@ -1437,7 +1437,7 @@
  */
 QDF_STATUS
 wlansap_set_channel_change_with_csa(void *p_cds_gctx, uint32_t targetChannel,
-					phy_ch_width target_bw)
+				    enum ch_width target_bw)
 {
 
 	ptSapContext sapContext = NULL;
@@ -2246,7 +2246,7 @@
 	void *hHal = NULL;
 	tpAniSirGlobal mac_ctx = NULL;
 	eCsrPhyMode phy_mode;
-	chan_params_t ch_params;
+	struct ch_params_s ch_params;
 	sapContext = (ptSapContext) pSapCtx;
 
 	if (NULL == sapContext) {
diff --git a/core/sme/inc/csr_api.h b/core/sme/inc/csr_api.h
index c8714f8..cd86914 100644
--- a/core/sme/inc/csr_api.h
+++ b/core/sme/inc/csr_api.h
@@ -876,7 +876,7 @@
 	eCsrCBChoice CBMode;
 	tCsrChannelInfo ChannelInfo;
 	uint8_t operationChannel;
-	chan_params_t ch_params;
+	struct ch_params_s ch_params;
 	/* If this is 0, SME will fill in for caller. */
 	uint16_t beaconInterval;
 	/*
diff --git a/core/sme/inc/csr_internal.h b/core/sme/inc/csr_internal.h
index fb6107f..0231e1e 100644
--- a/core/sme/inc/csr_internal.h
+++ b/core/sme/inc/csr_internal.h
@@ -333,7 +333,7 @@
 	tSirMacRateSet operationalRateSet;
 	tSirMacRateSet extendedRateSet;
 	uint8_t operationChn;
-	chan_params_t ch_params;
+	struct ch_params_s ch_params;
 	eCsrCfgDot11Mode uCfgDot11Mode;
 	uint8_t privacy;
 	bool fwdWPSPBCProbeReq;
@@ -1323,21 +1323,21 @@
 bool csr_roam_is_sta_mode(tpAniSirGlobal pMac, uint32_t sessionId);
 
 /* Post Channel Change Indication */
-QDF_STATUS csr_roam_channel_change_req(tpAniSirGlobal pMac,
-		struct qdf_mac_addr bssid, chan_params_t *ch_params,
-		tCsrRoamProfile *profile);
+QDF_STATUS csr_roam_channel_change_req(tpAniSirGlobal pMac, struct qdf_mac_addr
+				       bssid, struct ch_params_s *ch_params,
+				       tCsrRoamProfile *profile);
 
 /* Post Beacon Tx Start Indication */
 QDF_STATUS csr_roam_start_beacon_req(tpAniSirGlobal pMac,
 		struct qdf_mac_addr bssid, uint8_t dfsCacWaitStatus);
 
-QDF_STATUS
-csr_roam_send_chan_sw_ie_request(tpAniSirGlobal pMac, struct qdf_mac_addr bssid,
-		uint8_t targetChannel, uint8_t csaIeReqd,
-		chan_params_t *ch_params);
-QDF_STATUS
-csr_roam_modify_add_ies(tpAniSirGlobal pMac,
-		tSirModifyIE *pModifyIE, eUpdateIEsType updateType);
+QDF_STATUS csr_roam_send_chan_sw_ie_request(tpAniSirGlobal pMac,
+					    struct qdf_mac_addr bssid,
+					    uint8_t targetChannel,
+					    uint8_t csaIeReqd,
+					    struct ch_params_s *ch_params);
+QDF_STATUS csr_roam_modify_add_ies(tpAniSirGlobal pMac, tSirModifyIE *pModifyIE,
+				   eUpdateIEsType updateType);
 QDF_STATUS
 csr_roam_update_add_ies(tpAniSirGlobal pMac,
 		tSirUpdateIE *pUpdateIE, eUpdateIEsType updateType);
diff --git a/core/sme/inc/sme_api.h b/core/sme/inc/sme_api.h
index d9b61b1..f0b2268 100644
--- a/core/sme/inc/sme_api.h
+++ b/core/sme/inc/sme_api.h
@@ -693,9 +693,11 @@
  * SME API to determine the channel bonding mode
  */
 QDF_STATUS sme_set_ch_params(tHalHandle hHal, eCsrPhyMode eCsrPhyMode,
-		uint8_t channel, uint8_t ht_sec_ch, chan_params_t *ch_params);
+			     uint8_t channel, uint8_t ht_sec_ch,
+			     struct ch_params_s *ch_params);
+
 QDF_STATUS sme_handoff_request(tHalHandle hHal, uint8_t sessionId,
-		tCsrHandoffRequest *pHandoffInfo);
+			       tCsrHandoffRequest *pHandoffInfo);
 QDF_STATUS sme_is_sta_p2p_client_connected(tHalHandle hHal);
 #ifdef FEATURE_WLAN_LPHB
 QDF_STATUS sme_lphb_config_req(tHalHandle hHal,
@@ -769,15 +771,19 @@
 QDF_STATUS sme_set_auto_shutdown_timer(tHalHandle hHal, uint32_t timer_value);
 #endif
 QDF_STATUS sme_roam_channel_change_req(tHalHandle hHal,
-		struct qdf_mac_addr bssid, chan_params_t *ch_params,
-		tCsrRoamProfile *profile);
+				       struct qdf_mac_addr bssid,
+				       struct ch_params_s *ch_params,
+				       tCsrRoamProfile *profile);
+
 QDF_STATUS sme_roam_start_beacon_req(tHalHandle hHal,
 		struct qdf_mac_addr bssid, uint8_t dfsCacWaitStatus);
 QDF_STATUS sme_roam_csa_ie_request(tHalHandle hHal, struct qdf_mac_addr bssid,
-		uint8_t targetChannel, uint8_t csaIeReqd,
-		chan_params_t *ch_params);
+				   uint8_t targetChannel, uint8_t csaIeReqd,
+				   struct ch_params_s *ch_params);
+
 QDF_STATUS sme_init_thermal_info(tHalHandle hHal,
-		tSmeThermalParams thermalParam);
+				 tSmeThermalParams thermalParam);
+
 QDF_STATUS sme_set_thermal_level(tHalHandle hHal, uint8_t level);
 QDF_STATUS sme_txpower_limit(tHalHandle hHal, tSirTxPowerLimit *psmetx);
 QDF_STATUS sme_get_link_speed(tHalHandle hHal, tSirLinkSpeedInfo *lsReq,
diff --git a/core/sme/src/common/sme_api.c b/core/sme/src/common/sme_api.c
index 6b0832e..9614bf6 100644
--- a/core/sme/src/common/sme_api.c
+++ b/core/sme/src/common/sme_api.c
@@ -10150,7 +10150,7 @@
 }
 
 void sme_set_160bw_params(tpAniSirGlobal mac_ctx, uint8_t channel,
-		chan_params_t *ch_params)
+		struct ch_params_s *ch_params)
 {
 	uint8_t start_ch = 0;
 	QDF_STATUS status = QDF_STATUS_SUCCESS;
@@ -10173,7 +10173,7 @@
 }
 
 void sme_set_80bw_params(tpAniSirGlobal mac_ctx, uint8_t channel,
-		chan_params_t *ch_params)
+		struct ch_params_s *ch_params)
 {
 	uint8_t start_ch = 0;
 	QDF_STATUS status = QDF_STATUS_SUCCESS;
@@ -10208,7 +10208,7 @@
 }
 
 void sme_set_40bw_params(tpAniSirGlobal mac_ctx, uint8_t channel,
-		chan_params_t *ch_params, uint8_t is_11ac_mode)
+		struct ch_params_s *ch_params, uint8_t is_11ac_mode)
 {
 	uint8_t tmp;
 	uint8_t center_freq = 0;
@@ -10246,7 +10246,8 @@
  * SME API to determine the channel bonding mode
  */
 QDF_STATUS sme_set_ch_params(tHalHandle hHal, eCsrPhyMode eCsrPhyMode,
-		uint8_t channel, uint8_t ht_sec_ch, chan_params_t *ch_params)
+			     uint8_t channel, uint8_t ht_sec_ch,
+			     struct ch_params_s *ch_params)
 {
 	tpAniSirGlobal mac_ctx = PMAC_STRUCT(hHal);
 	int is_11ac_mode = CSR_IS_PHY_MODE_11ac(eCsrPhyMode);
@@ -11894,8 +11895,9 @@
  * Return: QDF_STATUS
  */
 QDF_STATUS sme_roam_channel_change_req(tHalHandle hHal,
-	struct qdf_mac_addr bssid, chan_params_t *ch_params,
-	tCsrRoamProfile *profile)
+				       struct qdf_mac_addr bssid,
+				       struct ch_params_s *ch_params,
+				       tCsrRoamProfile *profile)
 {
 	QDF_STATUS status = QDF_STATUS_E_FAILURE;
 	tpAniSirGlobal pMac = PMAC_STRUCT(hHal);
@@ -12004,7 +12006,7 @@
  */
 QDF_STATUS sme_roam_csa_ie_request(tHalHandle hHal, struct qdf_mac_addr bssid,
 				uint8_t targetChannel, uint8_t csaIeReqd,
-				chan_params_t *ch_params)
+				struct ch_params_s *ch_params)
 {
 	QDF_STATUS status = QDF_STATUS_E_FAILURE;
 	tpAniSirGlobal pMac = PMAC_STRUCT(hHal);
diff --git a/core/sme/src/csr/csr_api_roam.c b/core/sme/src/csr/csr_api_roam.c
index d364d79..bd4e8dd 100644
--- a/core/sme/src/csr/csr_api_roam.c
+++ b/core/sme/src/csr/csr_api_roam.c
@@ -48,6 +48,7 @@
 #include "cds_reg_service.h"
 #include "mac_trace.h"
 #include "csr_neighbor_roam.h"
+#include "cds_regdomain.h"
 #include "cds_regdomain_common.h"
 #include "cds_utils.h"
 #include "sir_types.h"
@@ -340,8 +341,6 @@
 QDF_STATUS csr_init_chan_list(tpAniSirGlobal mac, uint8_t *alpha2)
 {
 	QDF_STATUS status;
-	v_REGDOMAIN_t reg_id;
-	enum country_src source = SOURCE_DRIVER;
 
 	mac->scan.countryCodeDefault[0] = alpha2[0];
 	mac->scan.countryCodeDefault[1] = alpha2[1];
@@ -350,21 +349,9 @@
 	sms_log(mac, LOGE, FL("init time country code %.2s"),
 		mac->scan.countryCodeDefault);
 
-	status = csr_get_regulatory_domain_for_country(mac,
-						       mac->scan.countryCodeDefault,
-						       &reg_id, source);
-	if (status != QDF_STATUS_SUCCESS) {
-		sms_log(mac, LOGE,
-			FL("csr_get_regulatory_domain_for_country failed"));
-		return status;
-	}
+	mac->scan.domainIdDefault = 0;
+	mac->scan.domainIdCurrent = 0;
 
-	if (cds_set_reg_domain(mac, reg_id) != QDF_STATUS_SUCCESS) {
-		sms_log(mac, LOGE, FL("cds_set_reg_domain failed"));
-		return QDF_STATUS_E_FAILURE;
-	}
-	mac->scan.domainIdDefault = reg_id;
-	mac->scan.domainIdCurrent = mac->scan.domainIdDefault;
 	qdf_mem_copy(mac->scan.countryCodeCurrent,
 		     mac->scan.countryCodeDefault, WNI_CFG_COUNTRY_CODE_LEN);
 	qdf_mem_copy(mac->scan.countryCodeElected,
@@ -18014,8 +18001,9 @@
  * Return: QDF_STATUS
  */
 QDF_STATUS csr_roam_channel_change_req(tpAniSirGlobal pMac,
-			struct qdf_mac_addr bssid,
-			chan_params_t *ch_params, tCsrRoamProfile *profile)
+				       struct qdf_mac_addr bssid,
+				       struct ch_params_s *ch_params,
+				       tCsrRoamProfile *profile)
 {
 	QDF_STATUS status = QDF_STATUS_SUCCESS;
 	tSirChanChangeRequest *pMsg;
@@ -18245,10 +18233,11 @@
  *
  * Return: success or failure
  **/
-QDF_STATUS
-csr_roam_send_chan_sw_ie_request(tpAniSirGlobal mac_ctx,
-		struct qdf_mac_addr bssid, uint8_t target_channel,
-		uint8_t csa_ie_reqd, chan_params_t *ch_params)
+QDF_STATUS csr_roam_send_chan_sw_ie_request(tpAniSirGlobal mac_ctx,
+					    struct qdf_mac_addr bssid,
+					    uint8_t target_channel,
+					    uint8_t csa_ie_reqd,
+					    struct ch_params_s *ch_params)
 {
 	QDF_STATUS status = QDF_STATUS_SUCCESS;
 	tSirDfsCsaIeRequest *msg;
@@ -18265,7 +18254,7 @@
 	msg->targetChannel = target_channel;
 	msg->csaIeRequired = csa_ie_reqd;
 	qdf_mem_copy(msg->bssid, bssid.bytes, QDF_MAC_ADDR_SIZE);
-	qdf_mem_copy(&msg->ch_params, ch_params, sizeof(chan_params_t));
+	qdf_mem_copy(&msg->ch_params, ch_params, sizeof(struct ch_params_s));
 
 	status = cds_send_mb_message_to_mac(msg);
 
diff --git a/core/wma/inc/wma.h b/core/wma/inc/wma.h
index 4ad606e..06f390f 100644
--- a/core/wma/inc/wma.h
+++ b/core/wma/inc/wma.h
@@ -1493,7 +1493,7 @@
 	uint32_t beacon_intval;
 	uint32_t dtim_period;
 	int32_t max_txpow;
-	phy_ch_width chan_width;
+	enum ch_width chan_width;
 	bool is_dfs;
 	uint8_t vdev_id;
 	uint8_t chan;
diff --git a/core/wma/inc/wma_if.h b/core/wma/inc/wma_if.h
index dcce413..848f9c8 100644
--- a/core/wma/inc/wma_if.h
+++ b/core/wma/inc/wma_if.h
@@ -498,7 +498,7 @@
 	uint8_t halPersona;
 	uint8_t bSpectrumMgtEnabled;
 	uint8_t vhtCapable;
-	phy_ch_width ch_width;
+	enum ch_width ch_width;
 	uint8_t ch_center_freq_seg0;
 	uint8_t ch_center_freq_seg1;
 	uint8_t reassocReq;     /* Set only during roaming reassociation */
@@ -912,7 +912,7 @@
 	uint16_t smpsMode;
 	uint8_t isDfsChannel;
 	uint8_t vhtCapable;
-	phy_ch_width ch_width;
+	enum ch_width ch_width;
 	uint8_t ch_center_freq_seg0;
 	uint8_t ch_center_freq_seg1;
 	uint8_t dot11_mode;
diff --git a/core/wma/inc/wma_internal.h b/core/wma/inc/wma_internal.h
index 0dd428c..195bef7 100644
--- a/core/wma/inc/wma_internal.h
+++ b/core/wma/inc/wma_internal.h
@@ -891,7 +891,7 @@
 QDF_STATUS wma_process_dhcp_ind(tp_wma_handle wma_handle,
 				tAniDHCPInd *ta_dhcp_ind);
 
-WLAN_PHY_MODE wma_chan_to_mode(u8 chan, phy_ch_width chan_width,
+WLAN_PHY_MODE wma_chan_to_mode(u8 chan, enum ch_width chan_width,
 				      u8 vht_capable, u8 dot11_mode);
 
 QDF_STATUS wma_get_link_speed(WMA_HANDLE handle, tSirLinkSpeedInfo *pLinkSpeed);
diff --git a/core/wma/src/wma_features.c b/core/wma/src/wma_features.c
index 5e5283f..2db824c 100644
--- a/core/wma/src/wma_features.c
+++ b/core/wma/src/wma_features.c
@@ -677,7 +677,7 @@
  *
  * Return: return phy mode
  */
-WLAN_PHY_MODE wma_chan_to_mode(u8 chan, phy_ch_width chan_width,
+WLAN_PHY_MODE wma_chan_to_mode(u8 chan, enum ch_width chan_width,
 				      u8 vht_capable, u8 dot11_mode)
 {
 	WLAN_PHY_MODE phymode = MODE_UNKNOWN;