qcacld-3.0: Add support for regulatory component ucfg apis

Add support for regulatory component ucfg apis to provide user
configuration

Change-Id: I994e53b17788472de979df9dce9e18c6f68de850
CRs-Fixed: 2012415
diff --git a/core/hdd/inc/wlan_hdd_assoc.h b/core/hdd/inc/wlan_hdd_assoc.h
index a98e8fe..0a02de0 100644
--- a/core/hdd/inc/wlan_hdd_assoc.h
+++ b/core/hdd/inc/wlan_hdd_assoc.h
@@ -234,10 +234,10 @@
  * hdd_conn_get_connected_band() - get current connection radio band
  * @pHddStaCtx:    pointer to global HDD Station context
  *
- * Return: eCSR_BAND_24 or eCSR_BAND_5G based on current AP connection
- *      eCSR_BAND_ALL if not connected
+ * Return: BAND_2G or BAND_5G based on current AP connection
+ *      BAND_ALL if not connected
  */
-eCsrBand hdd_conn_get_connected_band(hdd_station_ctx_t *pHddStaCtx);
+enum band_info hdd_conn_get_connected_band(hdd_station_ctx_t *pHddStaCtx);
 
 /**
  * hdd_sme_roam_callback() - hdd sme roam callback
diff --git a/core/hdd/inc/wlan_hdd_regulatory.h b/core/hdd/inc/wlan_hdd_regulatory.h
index 24d8a06..caf9606 100644
--- a/core/hdd/inc/wlan_hdd_regulatory.h
+++ b/core/hdd/inc/wlan_hdd_regulatory.h
@@ -43,4 +43,22 @@
 void hdd_program_country_code(hdd_context_t *hdd_ctx);
 void hdd_reset_global_reg_params(void);
 
+/**
+ * hdd_reg_set_country() - helper function for setting the regulatory country
+ * @hdd_ctx: the HDD context to set the country for
+ * @country_code: the two character country code to configure
+ *
+ * Return: zero for success, non-zero error code for failure
+ */
+int hdd_reg_set_country(hdd_context_t *hdd_ctx, char *country_code);
+
+/**
+ * hdd_reg_set_band() - helper function for setting the regulatory band
+ * @hdd_ctx: the HDD context to set the band for
+ * @ui_band: the UI band to configure
+ *
+ * Return: zero for success, non-zero error code for failure
+ */
+int hdd_reg_set_band(struct net_device *dev, u8 ui_band);
+
 #endif
diff --git a/core/hdd/inc/wlan_hdd_wext.h b/core/hdd/inc/wlan_hdd_wext.h
index 828d5c6..b4ad078 100644
--- a/core/hdd/inc/wlan_hdd_wext.h
+++ b/core/hdd/inc/wlan_hdd_wext.h
@@ -68,9 +68,6 @@
 #define WLAN_HDD_UI_BAND_AUTO                          0
 #define WLAN_HDD_UI_BAND_5_GHZ                         1
 #define WLAN_HDD_UI_BAND_2_4_GHZ                       2
-/* SETBAND x */
-/* 012345678 */
-#define WLAN_HDD_UI_SET_BAND_VALUE_OFFSET              8
 
 enum hdd_wlan_wmm_direction {
 	HDD_WLAN_WMM_DIRECTION_UPSTREAM = 0,
@@ -440,8 +437,6 @@
 
 void wlan_hdd_change_country_code_callback(void *pAdapter);
 
-int hdd_set_band(struct net_device *dev, u8 ui_band);
-int hdd_set_band_helper(struct net_device *dev, const char *command);
 int wlan_hdd_update_phymode(struct net_device *net, tHalHandle hal,
 			    int new_phymode, hdd_context_t *phddctx);
 
diff --git a/core/hdd/src/wlan_hdd_assoc.c b/core/hdd/src/wlan_hdd_assoc.c
index 3079262..5b05fcd 100644
--- a/core/hdd/src/wlan_hdd_assoc.c
+++ b/core/hdd/src/wlan_hdd_assoc.c
@@ -240,7 +240,7 @@
  * Return: eCSR_BAND_24 or eCSR_BAND_5G based on current AP connection
  *	eCSR_BAND_ALL if not connected
  */
-eCsrBand hdd_conn_get_connected_band(hdd_station_ctx_t *pHddStaCtx)
+enum band_info hdd_conn_get_connected_band(hdd_station_ctx_t *pHddStaCtx)
 {
 	uint8_t staChannel = 0;
 
@@ -248,11 +248,11 @@
 		staChannel = pHddStaCtx->conn_info.operationChannel;
 
 	if (staChannel > 0 && staChannel < 14)
-		return eCSR_BAND_24;
+		return BAND_2G;
 	else if (staChannel >= 36 && staChannel <= 184)
-		return eCSR_BAND_5G;
+		return BAND_5G;
 	else   /* If station is not connected return as eCSR_BAND_ALL */
-		return eCSR_BAND_ALL;
+		return BAND_ALL;
 }
 
 /**
diff --git a/core/hdd/src/wlan_hdd_cfg80211.c b/core/hdd/src/wlan_hdd_cfg80211.c
index bfd0182..8127025 100644
--- a/core/hdd/src/wlan_hdd_cfg80211.c
+++ b/core/hdd/src/wlan_hdd_cfg80211.c
@@ -110,6 +110,7 @@
 #include "wlan_pmo_ucfg_api.h"
 #include "os_if_wifi_pos.h"
 #include "wlan_utility.h"
+#include "wlan_reg_ucfg_api.h"
 
 #define g_mode_rates_size (12)
 #define a_mode_rates_size (8)
@@ -3322,71 +3323,54 @@
 }
 
 /**
- * wlan_hdd_disable_dfs_chan_scan() - disable/enable DFS channels
+ * wlan_hdd_enable_dfs_chan_scan() - disable/enable DFS channels
  * @hdd_ctx: HDD context within host driver
- * @adapter: Adapter pointer
- * @no_dfs_flag: If TRUE, DFS channels cannot be used for scanning
+ * @enable_dfs_channels: If true, DFS channels can be used for scanning
  *
  * Loops through devices to see who is operating on DFS channels
- * and then disables/enables DFS channels by calling SME API.
+ * and then disables/enables DFS channels.
  * Fails the disable request if any device is active on a DFS channel.
  *
  * Return: 0 or other error codes.
  */
 
-int wlan_hdd_disable_dfs_chan_scan(hdd_context_t *hdd_ctx,
-				   hdd_adapter_t *adapter,
-				   uint32_t no_dfs_flag)
+int wlan_hdd_enable_dfs_chan_scan(hdd_context_t *hdd_ctx,
+				  bool enable_dfs_channels)
 {
-	tHalHandle h_hal = WLAN_HDD_GET_HAL_CTX(adapter);
 	QDF_STATUS status;
-	int ret_val = -EPERM;
+	bool err;
 
-	if (no_dfs_flag == hdd_ctx->config->enableDFSChnlScan) {
-		if (no_dfs_flag) {
-			status = wlan_hdd_check_dfs_channel_for_adapter(
-				hdd_ctx, QDF_STA_MODE);
-
-			if (true == status)
-				return -EOPNOTSUPP;
-
-			status = wlan_hdd_check_dfs_channel_for_adapter(
-				hdd_ctx, QDF_SAP_MODE);
-
-			if (true == status)
-				return -EOPNOTSUPP;
-		}
-
-		hdd_ctx->config->enableDFSChnlScan = !no_dfs_flag;
-
-		hdd_abort_mac_scan_all_adapters(hdd_ctx);
-
-		/*
-		 *  call the SME API to tunnel down the new channel list
-		 *  to the firmware
-		 */
-		status = sme_handle_dfs_chan_scan(
-			h_hal, hdd_ctx->config->enableDFSChnlScan);
-
-		if (QDF_STATUS_SUCCESS == status) {
-			ret_val = 0;
-
-			/*
-			 * Clear the SME scan cache also. Note that the
-			 * clearing of scan results is independent of session;
-			 * so no need to iterate over
-			 * all sessions
-			 */
-			status = sme_scan_flush_result(h_hal);
-			if (QDF_STATUS_SUCCESS != status)
-				ret_val = -EPERM;
-		}
-
-	} else {
-		hdd_debug(" the DFS flag has not changed");
-		ret_val = 0;
+	if (enable_dfs_channels == hdd_ctx->config->enableDFSChnlScan) {
+		hdd_info("DFS channels are already %s",
+			 enable_dfs_channels ? "enabled" : "disabled");
+		return 0;
 	}
-	return ret_val;
+
+	if (!enable_dfs_channels) {
+		err = wlan_hdd_check_dfs_channel_for_adapter(hdd_ctx,
+							     QDF_STA_MODE);
+		if (err)
+			return -EOPNOTSUPP;
+
+		err = wlan_hdd_check_dfs_channel_for_adapter(hdd_ctx,
+							     QDF_SAP_MODE);
+		if (err)
+			return -EOPNOTSUPP;
+	}
+
+	hdd_ctx->config->enableDFSChnlScan = enable_dfs_channels;
+
+	hdd_abort_mac_scan_all_adapters(hdd_ctx);
+
+	/* pass dfs channel status to regulatory component */
+	status = ucfg_reg_enable_dfs_channels(hdd_ctx->hdd_pdev,
+			enable_dfs_channels);
+
+	if (QDF_IS_STATUS_ERROR(status))
+		hdd_err("Failed to %s DFS channels",
+			enable_dfs_channels ? "enable" : "disable");
+
+	return qdf_status_to_os_return(status);
 }
 
 /**
@@ -3403,7 +3387,6 @@
 						     int data_len)
 {
 	struct net_device *dev = wdev->netdev;
-	hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
 	hdd_context_t *hdd_ctx  = wiphy_priv(wiphy);
 	struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_SET_NO_DFS_FLAG_MAX + 1];
 	int ret_val;
@@ -3437,8 +3420,7 @@
 		return -EINVAL;
 	}
 
-	ret_val = wlan_hdd_disable_dfs_chan_scan(hdd_ctx, adapter,
-						 no_dfs_flag);
+	ret_val = wlan_hdd_enable_dfs_chan_scan(hdd_ctx, !no_dfs_flag);
 	return ret_val;
 }
 
@@ -8686,8 +8668,8 @@
 				       struct wireless_dev *wdev,
 				       const void *data, int data_len)
 {
-	struct net_device *dev = wdev->netdev;
 	hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
+	struct net_device *dev = wdev->netdev;
 	struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_MAX + 1];
 	int ret;
 	static const struct nla_policy policy[QCA_WLAN_VENDOR_ATTR_MAX + 1]
@@ -8709,8 +8691,8 @@
 		return -EINVAL;
 	}
 
-	ret = hdd_set_band(dev,
-			nla_get_u32(tb[QCA_WLAN_VENDOR_ATTR_SETBAND_VALUE]));
+	ret = hdd_reg_set_band(dev,
+		nla_get_u32(tb[QCA_WLAN_VENDOR_ATTR_SETBAND_VALUE]));
 
 	EXIT();
 	return ret;
diff --git a/core/hdd/src/wlan_hdd_cfg80211.h b/core/hdd/src/wlan_hdd_cfg80211.h
index 78f318d..8dcc734 100644
--- a/core/hdd/src/wlan_hdd_cfg80211.h
+++ b/core/hdd/src/wlan_hdd_cfg80211.h
@@ -347,9 +347,8 @@
 enum policy_mgr_con_mode wlan_hdd_convert_nl_iftype_to_hdd_type(
 					enum nl80211_iftype type);
 
-int wlan_hdd_disable_dfs_chan_scan(hdd_context_t *hdd_ctx,
-				   hdd_adapter_t *adapter,
-				   uint32_t no_dfs_flag);
+int wlan_hdd_enable_dfs_chan_scan(hdd_context_t *hdd_ctx,
+				  bool enable_dfs_channels);
 
 int wlan_hdd_cfg80211_update_band(hdd_context_t *hdd_ctx, struct wiphy *wiphy,
 				  eCsrBand eBand);
diff --git a/core/hdd/src/wlan_hdd_hostapd.c b/core/hdd/src/wlan_hdd_hostapd.c
index d285d5a..1721b9b 100644
--- a/core/hdd/src/wlan_hdd_hostapd.c
+++ b/core/hdd/src/wlan_hdd_hostapd.c
@@ -84,6 +84,7 @@
 #include <cdp_txrx_stats.h>
 #include "wlan_hdd_he.h"
 #include "wlan_dfs_tgt_api.h"
+#include <wlan_reg_ucfg_api.h>
 
 #define    IS_UP(_dev) \
 	(((_dev)->flags & (IFF_RUNNING|IFF_UP)) == (IFF_RUNNING|IFF_UP))
@@ -7502,8 +7503,12 @@
 		if (pIe) {
 			pConfig->ieee80211d = 1;
 			qdf_mem_copy(pConfig->countryCode, &pIe[2], 3);
-			sme_set_reg_info(hHal, pConfig->countryCode);
-			sme_apply_channel_power_info_to_fw(hHal);
+			status = ucfg_reg_set_country(pHddCtx->hdd_pdev,
+					pConfig->countryCode);
+			if (QDF_IS_STATUS_ERROR(status)) {
+				hdd_err("Failed to set country");
+				pConfig->ieee80211d = 0;
+			}
 		} else {
 			pConfig->countryCode[0] = pHddCtx->reg.alpha2[0];
 			pConfig->countryCode[1] = pHddCtx->reg.alpha2[1];
diff --git a/core/hdd/src/wlan_hdd_ioctl.c b/core/hdd/src/wlan_hdd_ioctl.c
index 1c1cee7..281bcbe 100644
--- a/core/hdd/src/wlan_hdd_ioctl.c
+++ b/core/hdd/src/wlan_hdd_ioctl.c
@@ -32,12 +32,13 @@
 #include "wlan_hdd_trace.h"
 #include "wlan_hdd_ioctl.h"
 #include "wlan_hdd_power.h"
+#include "wlan_hdd_regulatory.h"
 #include "wlan_hdd_request_manager.h"
 #include "wlan_hdd_driver_ops.h"
 #include "wlan_policy_mgr_api.h"
 #include "wlan_hdd_hostapd.h"
 #include "scheduler_api.h"
-
+#include "wlan_reg_ucfg_api.h"
 #include "wlan_hdd_p2p.h"
 #include <linux/ctype.h>
 #include "wma.h"
@@ -2861,24 +2862,20 @@
 			    uint8_t command_len,
 			    hdd_priv_data_t *priv_data)
 {
-	int ret = 0;
-
-	uint8_t *ptr = command;
-
-	/* Change band request received */
+	int err;
+	uint8_t band;
 
 	/*
-	 * First 8 bytes will have "SETBAND " and
-	 * 9 byte will have band setting value
+	 * Parse the band value passed from userspace. The first 8 bytes
+	 * should be "SETBAND " and the 9th byte should be a UI band value
 	 */
-	hdd_debug("SetBandCommand Info  comm %s UL %d, TL %d",
-		  command, priv_data->used_len,
-		  priv_data->total_len);
+	err = kstrtou8(command + command_len + 1, 10, &band);
+	if (err) {
+		hdd_err("error %d parsing userspace band parameter", err);
+		return err;
+	}
 
-	/* Change band request received */
-	ret = hdd_set_band_helper(adapter->dev, ptr);
-
-	return ret;
+	return hdd_reg_set_band(adapter->dev, band);
 }
 
 static int drv_cmd_set_wmmps(hdd_adapter_t *adapter,
@@ -2890,41 +2887,13 @@
 	return hdd_wmmps_helper(adapter, command);
 }
 
-static int drv_cmd_country(hdd_adapter_t *adapter,
-			   hdd_context_t *hdd_ctx,
-			   uint8_t *command,
-			   uint8_t command_len,
-			   hdd_priv_data_t *priv_data)
+static inline int drv_cmd_country(hdd_adapter_t *adapter,
+				  hdd_context_t *hdd_ctx,
+				  uint8_t *command,
+				  uint8_t command_len,
+				  hdd_priv_data_t *priv_data)
 {
-	int ret = 0;
-	QDF_STATUS status;
-	unsigned long rc;
-	char *country_code;
-
-	country_code = command + 8;
-
-	INIT_COMPLETION(adapter->change_country_code);
-
-	status = sme_change_country_code(hdd_ctx->hHal,
-			wlan_hdd_change_country_code_callback,
-			country_code,
-			adapter,
-			hdd_ctx->pcds_context,
-			eSIR_TRUE,
-			eSIR_TRUE);
-	if (status == QDF_STATUS_SUCCESS) {
-		rc = wait_for_completion_timeout(
-			&adapter->change_country_code,
-			 msecs_to_jiffies(WLAN_WAIT_TIME_COUNTRY));
-		if (!rc)
-			hdd_err("SME while setting country code timed out");
-	} else {
-		hdd_err("SME Change Country code fail, status %d",
-			 status);
-		ret = -EINVAL;
-	}
-
-	return ret;
+	return hdd_reg_set_country(hdd_ctx, command + command_len + 1);
 }
 
 static int drv_cmd_set_roam_trigger(hdd_adapter_t *adapter,
@@ -5734,8 +5703,8 @@
 	/* When DFS scanning is disabled, the DFS channels need to be
 	 * removed from the operation of device.
 	 */
-	ret = wlan_hdd_disable_dfs_chan_scan(hdd_ctx, adapter,
-			(dfsScanMode == CFG_ROAMING_DFS_CHANNEL_DISABLED));
+	ret = wlan_hdd_enable_dfs_chan_scan(hdd_ctx,
+			dfsScanMode != CFG_ROAMING_DFS_CHANNEL_DISABLED);
 	if (ret < 0) {
 		/* Some conditions prevented it from disabling DFS channels */
 		hdd_err("disable/enable DFS channel request was denied");
@@ -6589,11 +6558,9 @@
 				   uint8_t command_len,
 				   hdd_priv_data_t *priv_data)
 {
-	uint8_t *value;
-	uint8_t fcc_constraint;
 	QDF_STATUS status;
-	bool scan_pending;
-	int ret = 0;
+	uint8_t fcc_constraint;
+	int err;
 
 	/*
 	 * this command would be called by user-space when it detects WLAN
@@ -6605,31 +6572,20 @@
 	 * country code is set
 	 */
 
-	value =  command + command_len + 1;
-
-	ret = kstrtou8(value, 10, &fcc_constraint);
-	if ((ret < 0) || (fcc_constraint > 1)) {
-		/*
-		 *  If the input value is greater than max value of datatype,
-		 *  then also it is a failure
-		 */
-		hdd_err("value out of range");
-		return -EINVAL;
-	}
-#ifndef NAPIER_SCAN
-	/* This code will be removed*/
-	scan_pending = !qdf_list_empty(&hdd_ctx->hdd_scan_req_q);
-#else
-	scan_pending = ucfg_scan_get_pdev_status(hdd_ctx->hdd_pdev);
-#endif
-	status = sme_handle_set_fcc_channel(hdd_ctx->hHal, !fcc_constraint,
-					    scan_pending);
-	if (status != QDF_STATUS_SUCCESS) {
-		hdd_err("sme disable fn. returned err");
-		ret = -EPERM;
+	err = kstrtou8(command + command_len + 1, 10, &fcc_constraint);
+	if (err) {
+		hdd_err("error %d parsing userspace fcc parameter", err);
+		return err;
 	}
 
-	return ret;
+	status = ucfg_reg_set_fcc_constraint(hdd_ctx->hdd_pdev,
+			fcc_constraint);
+
+	if (QDF_IS_STATUS_ERROR(status))
+		hdd_err("Failed to %s tx power for channels 12/13",
+			fcc_constraint ? "reduce" : "restore");
+
+	return qdf_status_to_os_return(status);
 }
 
 /**
diff --git a/core/hdd/src/wlan_hdd_main.c b/core/hdd/src/wlan_hdd_main.c
index 300e62e..b3672f4 100644
--- a/core/hdd/src/wlan_hdd_main.c
+++ b/core/hdd/src/wlan_hdd_main.c
@@ -7649,46 +7649,17 @@
 /**
  * hdd_update_country_code - Update country code
  * @hdd_ctx: HDD context
- * @adapter: Primary adapter context
  *
- * Update country code based on module parameter country_code at SME and wait
- * for the settings to take effect.
+ * Update country code based on module parameter country_code
  *
  * Return: 0 on success and errno on failure
  */
-static int hdd_update_country_code(hdd_context_t *hdd_ctx,
-				  hdd_adapter_t *adapter)
+static int hdd_update_country_code(hdd_context_t *hdd_ctx)
 {
-	QDF_STATUS status;
-	int ret = 0;
-	unsigned long rc;
-
-	if (country_code == NULL)
+	if (!country_code)
 		return 0;
 
-	INIT_COMPLETION(adapter->change_country_code);
-
-	status = sme_change_country_code(hdd_ctx->hHal,
-					 wlan_hdd_change_country_code_callback,
-					 country_code, adapter,
-					 hdd_ctx->pcds_context, eSIR_TRUE,
-					 eSIR_TRUE);
-
-
-	if (!QDF_IS_STATUS_SUCCESS(status)) {
-		hdd_err("SME Change Country code from module param fail ret=%d",
-			ret);
-		return -EINVAL;
-	}
-
-	rc = wait_for_completion_timeout(&adapter->change_country_code,
-			 msecs_to_jiffies(WLAN_WAIT_TIME_COUNTRY));
-	if (!rc) {
-		hdd_err("SME while setting country code timed out");
-		ret = -ETIMEDOUT;
-	}
-
-	return ret;
+	return hdd_reg_set_country(hdd_ctx, country_code);
 }
 
 #ifdef QCA_LL_TX_FLOW_CONTROL_V2
@@ -8636,7 +8607,7 @@
 
 	ENTER();
 
-	ret = hdd_update_country_code(hdd_ctx, adapter);
+	ret = hdd_update_country_code(hdd_ctx);
 	if (ret) {
 		hdd_err("Failed to update country code: %d", ret);
 		goto out;
diff --git a/core/hdd/src/wlan_hdd_regulatory.c b/core/hdd/src/wlan_hdd_regulatory.c
index 296e529..433208d 100644
--- a/core/hdd/src/wlan_hdd_regulatory.c
+++ b/core/hdd/src/wlan_hdd_regulatory.c
@@ -544,7 +544,7 @@
 
 	reg_info->cc_src = SOURCE_DRIVER;
 
-	wlan_reg_set_default_country(hdd_ctx->hdd_psoc, reg_info->alpha2);
+	ucfg_reg_set_default_country(hdd_ctx->hdd_psoc, reg_info->alpha2);
 
 	cds_fill_and_send_ctl_to_fw(reg_info);
 
@@ -580,6 +580,28 @@
 	}
 }
 
+int hdd_reg_set_country(hdd_context_t *hdd_ctx, char *country_code)
+{
+	int err;
+	QDF_STATUS status;
+
+	/* validation */
+	err = wlan_hdd_validate_context(hdd_ctx);
+	if (err)
+		return err;
+
+	if (!country_code) {
+		hdd_err("country_code is null");
+		return -EINVAL;
+	}
+
+	/* call regulatory set_country api */
+	status = ucfg_reg_set_country(hdd_ctx->hdd_pdev, country_code);
+	if (QDF_IS_STATUS_ERROR(status))
+		hdd_err("Failed to set country");
+
+	return qdf_status_to_os_return(status);
+}
 
 /**
  * hdd_restore_custom_reg_settings() - restore custom reg settings
diff --git a/core/hdd/src/wlan_hdd_wext.c b/core/hdd/src/wlan_hdd_wext.c
index 67d359f..b097c44 100644
--- a/core/hdd/src/wlan_hdd_wext.c
+++ b/core/hdd/src/wlan_hdd_wext.c
@@ -100,6 +100,8 @@
 #include <cdp_txrx_stats.h>
 #include <cds_api.h>
 #include <wlan_osif_priv.h>
+#include "wlan_hdd_regulatory.h"
+#include "wlan_reg_ucfg_api.h"
 
 #define HDD_FINISH_ULA_TIME_OUT         800
 #define HDD_SET_MCBC_FILTERS_TO_FW      1
@@ -7309,7 +7311,7 @@
 	switch (new_phymode) {
 	case IEEE80211_MODE_AUTO:
 		sme_set_phy_mode(hal, eCSR_DOT11_MODE_AUTO);
-		if (hdd_set_band(net, WLAN_HDD_UI_BAND_AUTO) == 0) {
+		if (hdd_reg_set_band(net, WLAN_HDD_UI_BAND_AUTO) == 0) {
 			phymode = eCSR_DOT11_MODE_AUTO;
 			hdd_dot11mode = eHDD_DOT11_MODE_AUTO;
 			chwidth = WNI_CFG_CHANNEL_BONDING_MODE_ENABLE;
@@ -7322,7 +7324,7 @@
 		break;
 	case IEEE80211_MODE_11A:
 		sme_set_phy_mode(hal, eCSR_DOT11_MODE_11a);
-		if ((hdd_set_band(net, WLAN_HDD_UI_BAND_5_GHZ) == 0)) {
+		if (hdd_reg_set_band(net, WLAN_HDD_UI_BAND_5_GHZ) == 0) {
 			phymode = eCSR_DOT11_MODE_11a;
 			hdd_dot11mode = eHDD_DOT11_MODE_11a;
 			chwidth = WNI_CFG_CHANNEL_BONDING_MODE_DISABLE;
@@ -7334,7 +7336,7 @@
 		break;
 	case IEEE80211_MODE_11B:
 		sme_set_phy_mode(hal, eCSR_DOT11_MODE_11b);
-		if ((hdd_set_band(net, WLAN_HDD_UI_BAND_2_4_GHZ) == 0)) {
+		if (hdd_reg_set_band(net, WLAN_HDD_UI_BAND_2_4_GHZ) == 0) {
 			phymode = eCSR_DOT11_MODE_11b;
 			hdd_dot11mode = eHDD_DOT11_MODE_11b;
 			chwidth = WNI_CFG_CHANNEL_BONDING_MODE_DISABLE;
@@ -7346,7 +7348,7 @@
 		break;
 	case IEEE80211_MODE_11G:
 		sme_set_phy_mode(hal, eCSR_DOT11_MODE_11g);
-		if ((hdd_set_band(net, WLAN_HDD_UI_BAND_2_4_GHZ) == 0)) {
+		if (hdd_reg_set_band(net, WLAN_HDD_UI_BAND_2_4_GHZ) == 0) {
 			phymode = eCSR_DOT11_MODE_11g;
 			hdd_dot11mode = eHDD_DOT11_MODE_11g;
 			chwidth = WNI_CFG_CHANNEL_BONDING_MODE_DISABLE;
@@ -7362,7 +7364,7 @@
 	 */
 	case IEEE80211_MODE_11NA_HT20:
 		sme_set_phy_mode(hal, eCSR_DOT11_MODE_11n);
-		if ((hdd_set_band(net, WLAN_HDD_UI_BAND_5_GHZ) == 0)) {
+		if (hdd_reg_set_band(net, WLAN_HDD_UI_BAND_5_GHZ) == 0) {
 			phymode = eCSR_DOT11_MODE_11n;
 			hdd_dot11mode = eHDD_DOT11_MODE_11n;
 			chwidth = WNI_CFG_CHANNEL_BONDING_MODE_DISABLE;
@@ -7374,7 +7376,7 @@
 		break;
 	case IEEE80211_MODE_11NA_HT40:
 		sme_set_phy_mode(hal, eCSR_DOT11_MODE_11n);
-		if ((hdd_set_band(net, WLAN_HDD_UI_BAND_5_GHZ) == 0)) {
+		if (hdd_reg_set_band(net, WLAN_HDD_UI_BAND_5_GHZ) == 0) {
 			phymode = eCSR_DOT11_MODE_11n;
 			hdd_dot11mode = eHDD_DOT11_MODE_11n;
 			chwidth = WNI_CFG_CHANNEL_BONDING_MODE_ENABLE;
@@ -7386,7 +7388,7 @@
 		break;
 	case IEEE80211_MODE_11NG_HT20:
 		sme_set_phy_mode(hal, eCSR_DOT11_MODE_11n);
-		if ((hdd_set_band(net, WLAN_HDD_UI_BAND_2_4_GHZ) == 0)) {
+		if (hdd_reg_set_band(net, WLAN_HDD_UI_BAND_2_4_GHZ) == 0) {
 			phymode = eCSR_DOT11_MODE_11n;
 			hdd_dot11mode = eHDD_DOT11_MODE_11n;
 			chwidth = WNI_CFG_CHANNEL_BONDING_MODE_DISABLE;
@@ -7398,7 +7400,7 @@
 		break;
 	case IEEE80211_MODE_11NG_HT40:
 		sme_set_phy_mode(hal, eCSR_DOT11_MODE_11n);
-		if ((hdd_set_band(net, WLAN_HDD_UI_BAND_2_4_GHZ) == 0)) {
+		if (hdd_reg_set_band(net, WLAN_HDD_UI_BAND_2_4_GHZ) == 0) {
 			phymode = eCSR_DOT11_MODE_11n;
 			hdd_dot11mode = eHDD_DOT11_MODE_11n;
 			chwidth = WNI_CFG_CHANNEL_BONDING_MODE_ENABLE;
@@ -7412,7 +7414,7 @@
 	case IEEE80211_MODE_11AC_VHT40:
 	case IEEE80211_MODE_11AC_VHT80:
 		sme_set_phy_mode(hal, eCSR_DOT11_MODE_11ac);
-		if ((hdd_set_band(net, WLAN_HDD_UI_BAND_5_GHZ) == 0)) {
+		if (hdd_reg_set_band(net, WLAN_HDD_UI_BAND_5_GHZ) == 0) {
 			phymode = eCSR_DOT11_MODE_11ac;
 			hdd_dot11mode = eHDD_DOT11_MODE_11ac;
 			chwidth = WNI_CFG_CHANNEL_BONDING_MODE_ENABLE;
@@ -7424,7 +7426,7 @@
 		break;
 	case IEEE80211_MODE_2G_AUTO:
 		sme_set_phy_mode(hal, eCSR_DOT11_MODE_AUTO);
-		if ((hdd_set_band(net, WLAN_HDD_UI_BAND_2_4_GHZ) == 0)) {
+		if (hdd_reg_set_band(net, WLAN_HDD_UI_BAND_2_4_GHZ) == 0) {
 			phymode = eCSR_DOT11_MODE_AUTO;
 			hdd_dot11mode = eHDD_DOT11_MODE_AUTO;
 			chwidth = WNI_CFG_CHANNEL_BONDING_MODE_ENABLE;
@@ -7436,7 +7438,7 @@
 		break;
 	case IEEE80211_MODE_5G_AUTO:
 		sme_set_phy_mode(hal, eCSR_DOT11_MODE_AUTO);
-		if ((hdd_set_band(net, WLAN_HDD_UI_BAND_5_GHZ) == 0)) {
+		if (hdd_reg_set_band(net, WLAN_HDD_UI_BAND_5_GHZ) == 0) {
 			phymode = eCSR_DOT11_MODE_AUTO;
 			hdd_dot11mode = eHDD_DOT11_MODE_AUTO;
 			chwidth = WNI_CFG_CHANNEL_BONDING_MODE_ENABLE;
@@ -7449,7 +7451,7 @@
 		break;
 	case IEEE80211_MODE_11AGN:
 		sme_set_phy_mode(hal, eCSR_DOT11_MODE_11n);
-		if ((hdd_set_band(net, WLAN_HDD_UI_BAND_AUTO) == 0)) {
+		if (hdd_reg_set_band(net, WLAN_HDD_UI_BAND_AUTO) == 0) {
 			phymode = eCSR_DOT11_MODE_11n;
 			hdd_dot11mode = eHDD_DOT11_MODE_11n;
 			chwidth = WNI_CFG_CHANNEL_BONDING_MODE_ENABLE;
@@ -12306,17 +12308,18 @@
 #endif /* FEATURE_WLAN_SCAN_PNO */
 
 /* Common function to SetBand */
-int hdd_set_band(struct net_device *dev, u8 ui_band)
+int hdd_reg_set_band(struct net_device *dev, u8 ui_band)
 {
 	hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
 	tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
-	eCsrBand band;
+	enum band_info band;
 
 	QDF_STATUS status;
 	hdd_context_t *pHddCtx;
 	hdd_adapter_list_node_t *pAdapterNode, *pNext;
-	eCsrBand currBand = eCSR_BAND_MAX;
-	eCsrBand connectedBand;
+	enum band_info currBand;
+	enum band_info connectedBand;
+	long lrc;
 
 	pAdapterNode = NULL;
 	pNext = NULL;
@@ -12324,140 +12327,114 @@
 
 	switch (ui_band) {
 	case WLAN_HDD_UI_BAND_AUTO:
-		band = eCSR_BAND_ALL;
+		band = BAND_ALL;
 		break;
 	case WLAN_HDD_UI_BAND_5_GHZ:
-		band = eCSR_BAND_5G;
+		band = BAND_5G;
 		break;
 	case WLAN_HDD_UI_BAND_2_4_GHZ:
-		band = eCSR_BAND_24;
+		band = BAND_2G;
 		break;
 	default:
-		band = eCSR_BAND_MAX;
-	}
-
-	hdd_debug("change band to %u", band);
-
-	if (band == eCSR_BAND_MAX) {
-		/* Received change band request with invalid band value */
 		hdd_err("Invalid band value %u", ui_band);
 		return -EINVAL;
 	}
 
-	if ((band == eCSR_BAND_24 && pHddCtx->config->nBandCapability == 2) ||
-	    (band == eCSR_BAND_5G && pHddCtx->config->nBandCapability == 1)) {
+	hdd_debug("change band to %u", band);
+
+	if ((band == BAND_2G && pHddCtx->config->nBandCapability == 2) ||
+	    (band == BAND_5G && pHddCtx->config->nBandCapability == 1)) {
 		hdd_err("band value %u violate INI settings %u",
 			  band, pHddCtx->config->nBandCapability);
 		return -EIO;
 	}
 
-	if (band == eCSR_BAND_ALL) {
+	if (band == BAND_ALL) {
 		hdd_debug("Auto band received. Setting band same as ini value %d",
 			pHddCtx->config->nBandCapability);
 		band = pHddCtx->config->nBandCapability;
 	}
 
-	if (QDF_STATUS_SUCCESS != sme_get_freq_band(hHal, &currBand)) {
+	if (QDF_STATUS_SUCCESS != ucfg_reg_get_curr_band(pHddCtx->hdd_pdev,
+				&currBand)) {
 		hdd_debug("Failed to get current band config");
 		return -EIO;
 	}
 
-	if (currBand != band) {
-		/* Change band request received.
-		 * Abort pending scan requests, flush the existing scan results,
-		 * and change the band capability
-		 */
-		hdd_debug("Current band value = %u, new setting %u ",
-			   currBand, band);
+	if (currBand == band)
+		return 0;
 
-		status = hdd_get_front_adapter(pHddCtx, &pAdapterNode);
-		while (NULL != pAdapterNode && QDF_STATUS_SUCCESS == status) {
-			pAdapter = pAdapterNode->pAdapter;
-			hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
-			wlan_abort_scan(pHddCtx->hdd_pdev, INVAL_PDEV_ID,
+	/* Change band request received.
+	 * Abort pending scan requests, flush the existing scan results,
+	 * and change the band capability
+	 */
+	hdd_debug("Current band value = %u, new setting %u ",
+			currBand, band);
+
+	status = hdd_get_front_adapter(pHddCtx, &pAdapterNode);
+	while (NULL != pAdapterNode && QDF_STATUS_SUCCESS == status) {
+		pAdapter = pAdapterNode->pAdapter;
+		hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
+		wlan_abort_scan(pHddCtx->hdd_pdev, INVAL_PDEV_ID,
 				pAdapter->sessionId, INVALID_SCAN_ID, false);
-			connectedBand =
-				hdd_conn_get_connected_band
-					(WLAN_HDD_GET_STATION_CTX_PTR(pAdapter));
+		connectedBand = hdd_conn_get_connected_band(
+				WLAN_HDD_GET_STATION_CTX_PTR(pAdapter));
 
-			/* Handling is done only for STA and P2P */
-			if (band != eCSR_BAND_ALL &&
-			    ((pAdapter->device_mode == QDF_STA_MODE)
-			     || (pAdapter->device_mode == QDF_P2P_CLIENT_MODE))
-			    &&
-			    (hdd_conn_is_connected
-				     (WLAN_HDD_GET_STATION_CTX_PTR(pAdapter)))
-			    && (connectedBand != band)) {
-				QDF_STATUS status = QDF_STATUS_SUCCESS;
-				long lrc;
+		/* Handling is done only for STA and P2P */
+		if (band != BAND_ALL &&
+			((pAdapter->device_mode == QDF_STA_MODE) ||
+			 (pAdapter->device_mode == QDF_P2P_CLIENT_MODE)) &&
+			(hdd_conn_is_connected(
+				WLAN_HDD_GET_STATION_CTX_PTR(pAdapter)))
+			&& (connectedBand != band)) {
+			status = QDF_STATUS_SUCCESS;
 
-				/* STA already connected on current
-				 * band, So issue disconnect first,
-				 * then change the band
-				 */
+			/* STA already connected on current
+			 * band, So issue disconnect first,
+			 * then change the band
+			 */
 
-				hdd_debug("STA (Device mode %s(%d)) connected in band %u, Changing band to %u, Issuing Disconnect",
+			hdd_debug("STA (Device mode %s(%d)) connected in band %u, Changing band to %u, Issuing Disconnect",
 					hdd_device_mode_to_string(pAdapter->device_mode),
 					pAdapter->device_mode, currBand, band);
-				INIT_COMPLETION(pAdapter->disconnect_comp_var);
+			INIT_COMPLETION(pAdapter->disconnect_comp_var);
 
-				status =
-					sme_roam_disconnect(WLAN_HDD_GET_HAL_CTX
-								    (pAdapter),
-							    pAdapter->sessionId,
-							    eCSR_DISCONNECT_REASON_UNSPECIFIED);
+			status = sme_roam_disconnect(
+					WLAN_HDD_GET_HAL_CTX(pAdapter),
+					pAdapter->sessionId,
+					eCSR_DISCONNECT_REASON_UNSPECIFIED);
 
-				if (QDF_STATUS_SUCCESS != status) {
-					hdd_err("sme_roam_disconnect failure, status: %d",
+			if (QDF_STATUS_SUCCESS != status) {
+				hdd_err("sme_roam_disconnect failure, status: %d",
 						(int)status);
-					return -EINVAL;
-				}
-
-				lrc =
-					wait_for_completion_timeout(&pAdapter->
-								    disconnect_comp_var,
-								    msecs_to_jiffies
-									    (WLAN_WAIT_TIME_DISCONNECT));
-
-				if (lrc == 0) {
-					hdd_err("Timeout while waiting for csr_roam_disconnect");
-					return -ETIMEDOUT;
-				}
+				return -EINVAL;
 			}
 
-			sme_scan_flush_result(hHal);
+			lrc = wait_for_completion_timeout(
+					&pAdapter->disconnect_comp_var,
+					msecs_to_jiffies(
+						WLAN_WAIT_TIME_DISCONNECT));
 
-			status =
-				hdd_get_next_adapter(pHddCtx, pAdapterNode, &pNext);
-			pAdapterNode = pNext;
+			if (lrc == 0) {
+				hdd_err("Timeout while waiting for csr_roam_disconnect");
+				return -ETIMEDOUT;
+			}
 		}
 
-		if (QDF_STATUS_SUCCESS !=
-		    sme_set_freq_band(hHal, pAdapter->sessionId, band)) {
-			hdd_err("Failed to set the band value to %u",
-				  band);
-			return -EINVAL;
-		}
-		wlan_hdd_cfg80211_update_band(pHddCtx, pHddCtx->wiphy,
-				(eCsrBand)band);
+		sme_scan_flush_result(hHal);
+
+		status = hdd_get_next_adapter(pHddCtx, pAdapterNode, &pNext);
+		pAdapterNode = pNext;
 	}
-	return 0;
-}
 
-int hdd_set_band_helper(struct net_device *dev, const char *command)
-{
-	uint8_t band;
-	int ret;
-
-	/* Convert the band value from ascii to integer */
-	command += WLAN_HDD_UI_SET_BAND_VALUE_OFFSET;
-	ret = kstrtou8(command, 10, &band);
-	if (ret < 0) {
-		hdd_err("kstrtou8 failed");
+	if (QDF_STATUS_SUCCESS !=
+			ucfg_reg_set_band(pHddCtx->hdd_pdev, band)) {
+		hdd_err("Failed to set the band value to %u",
+				band);
 		return -EINVAL;
 	}
 
-	return hdd_set_band(dev, band);
+	return 0;
 }
 
 static int __iw_set_band_config(struct net_device *dev,
@@ -12481,7 +12458,7 @@
 	if (0 != ret)
 		return ret;
 
-	return hdd_set_band(dev, value[0]);
+	return hdd_reg_set_band(dev, value[0]);
 }
 
 static int iw_set_band_config(struct net_device *dev,