hostapd(hidl): Add new param for restricting ACS channel

This allows the device to select one of the specified channels
when ACS is enabled.

Bug: 116839455
Test: Manual
Signed-off-by: Daichi Ueura <daichi.ueura@sony.com>
Change-Id: I4d28aba1bb3acbd76aef9061631e3d62a326ae34
(cherry-picked from b0425ce8cdec18d8b832b3b18794501675712514)
diff --git a/hostapd/hidl/1.1/hostapd.cpp b/hostapd/hidl/1.1/hostapd.cpp
index 340b22c..0298537 100644
--- a/hostapd/hidl/1.1/hostapd.cpp
+++ b/hostapd/hidl/1.1/hostapd.cpp
@@ -126,26 +126,38 @@
 	}
 
 	std::string channel_config_as_string;
-	if (iface_params.channelParams.enableAcs) {
+	if (iface_params.V1_0.channelParams.enableAcs) {
+		std::string chanlist_as_string;
+		for (const auto &range :
+		     iface_params.channelParams.acsChannelRanges) {
+			if (range.start != range.end) {
+				chanlist_as_string +=
+					StringPrintf("%d-%d ", range.start, range.end);
+			} else {
+				chanlist_as_string += StringPrintf("%d ", range.start);
+			}
+		}
 		channel_config_as_string = StringPrintf(
 		    "channel=0\n"
-		    "acs_exclude_dfs=%d",
-		    iface_params.channelParams.acsShouldExcludeDfs);
+		    "acs_exclude_dfs=%d\n"
+		    "chanlist=%s",
+		    iface_params.V1_0.channelParams.acsShouldExcludeDfs,
+		    chanlist_as_string.c_str());
 	} else {
 		channel_config_as_string = StringPrintf(
-		    "channel=%d", iface_params.channelParams.channel);
+		    "channel=%d", iface_params.V1_0.channelParams.channel);
 	}
 
 	// Hw Mode String
 	std::string hw_mode_as_string;
 	std::string ht_cap_vht_oper_chwidth_as_string;
-	switch (iface_params.channelParams.band) {
+	switch (iface_params.V1_0.channelParams.band) {
 	case IHostapd::Band::BAND_2_4_GHZ:
 		hw_mode_as_string = "hw_mode=g";
 		break;
 	case IHostapd::Band::BAND_5_GHZ:
 		hw_mode_as_string = "hw_mode=a";
-		if (iface_params.channelParams.enableAcs) {
+		if (iface_params.V1_0.channelParams.enableAcs) {
 			ht_cap_vht_oper_chwidth_as_string =
 			    "ht_capab=[HT40+]\n"
 			    "vht_oper_chwidth=1";
@@ -153,7 +165,7 @@
 		break;
 	case IHostapd::Band::BAND_ANY:
 		hw_mode_as_string = "hw_mode=any";
-		if (iface_params.channelParams.enableAcs) {
+		if (iface_params.V1_0.channelParams.enableAcs) {
 			ht_cap_vht_oper_chwidth_as_string =
 			    "ht_capab=[HT40+]\n"
 			    "vht_oper_chwidth=1";
@@ -180,10 +192,10 @@
 	    "ignore_broadcast_ssid=%d\n"
 	    "wowlan_triggers=any\n"
 	    "%s\n",
-	    iface_params.ifaceName.c_str(), ssid_as_string.c_str(),
+	    iface_params.V1_0.ifaceName.c_str(), ssid_as_string.c_str(),
 	    channel_config_as_string.c_str(),
-	    iface_params.hwModeParams.enable80211N ? 1 : 0,
-	    iface_params.hwModeParams.enable80211AC ? 1 : 0,
+	    iface_params.V1_0.hwModeParams.enable80211N ? 1 : 0,
+	    iface_params.V1_0.hwModeParams.enable80211AC ? 1 : 0,
 	    hw_mode_as_string.c_str(), ht_cap_vht_oper_chwidth_as_string.c_str(),
 	    nw_params.isHidden ? 1 : 0, encryption_config_as_string.c_str());
 }
@@ -221,11 +233,20 @@
 {}
 
 Return<void> Hostapd::addAccessPoint(
+    const V1_0::IHostapd::IfaceParams& iface_params,
+    const NetworkParams& nw_params, addAccessPoint_cb _hidl_cb)
+{
+	return call(
+	    this, &Hostapd::addAccessPointInternal, _hidl_cb, iface_params,
+	    nw_params);
+}
+
+Return<void> Hostapd::addAccessPoint_1_1(
     const IfaceParams& iface_params, const NetworkParams& nw_params,
     addAccessPoint_cb _hidl_cb)
 {
 	return call(
-	    this, &Hostapd::addAccessPointInternal, _hidl_cb, iface_params,
+	    this, &Hostapd::addAccessPointInternal_1_1, _hidl_cb, iface_params,
 	    nw_params);
 }
 
@@ -251,12 +272,19 @@
 }
 
 HostapdStatus Hostapd::addAccessPointInternal(
+    const V1_0::IHostapd::IfaceParams& iface_params,
+    const NetworkParams& nw_params)
+{
+	return {HostapdStatusCode::FAILURE_UNKNOWN, ""};
+}
+
+HostapdStatus Hostapd::addAccessPointInternal_1_1(
     const IfaceParams& iface_params, const NetworkParams& nw_params)
 {
-	if (hostapd_get_iface(interfaces_, iface_params.ifaceName.c_str())) {
+	if (hostapd_get_iface(interfaces_, iface_params.V1_0.ifaceName.c_str())) {
 		wpa_printf(
 		    MSG_ERROR, "Interface %s already present",
-		    iface_params.ifaceName.c_str());
+		    iface_params.V1_0.ifaceName.c_str());
 		return {HostapdStatusCode::FAILURE_IFACE_EXISTS, ""};
 	}
 	const auto conf_params = CreateHostapdConfig(iface_params, nw_params);
@@ -265,13 +293,13 @@
 		return {HostapdStatusCode::FAILURE_ARGS_INVALID, ""};
 	}
 	const auto conf_file_path =
-	    WriteHostapdConfig(iface_params.ifaceName, conf_params);
+	    WriteHostapdConfig(iface_params.V1_0.ifaceName, conf_params);
 	if (conf_file_path.empty()) {
 		wpa_printf(MSG_ERROR, "Failed to write config file");
 		return {HostapdStatusCode::FAILURE_UNKNOWN, ""};
 	}
 	std::string add_iface_param_str = StringPrintf(
-	    "%s config=%s", iface_params.ifaceName.c_str(),
+	    "%s config=%s", iface_params.V1_0.ifaceName.c_str(),
 	    conf_file_path.c_str());
 	std::vector<char> add_iface_param_vec(
 	    add_iface_param_str.begin(), add_iface_param_str.end() + 1);
@@ -282,7 +310,7 @@
 		return {HostapdStatusCode::FAILURE_UNKNOWN, ""};
 	}
 	struct hostapd_data* iface_hapd =
-	    hostapd_get_iface(interfaces_, iface_params.ifaceName.c_str());
+	    hostapd_get_iface(interfaces_, iface_params.V1_0.ifaceName.c_str());
 	WPA_ASSERT(iface_hapd != nullptr && iface_hapd->iface != nullptr);
 	// Register the setup complete callbacks
 	on_setup_complete_internal_callback =
@@ -304,7 +332,7 @@
 	if (hostapd_enable_iface(iface_hapd->iface) < 0) {
 		wpa_printf(
 		    MSG_ERROR, "Enabling interface %s failed",
-		    iface_params.ifaceName.c_str());
+		    iface_params.V1_0.ifaceName.c_str());
 		return {HostapdStatusCode::FAILURE_UNKNOWN, ""};
 	}
 	return {HostapdStatusCode::SUCCESS, ""};