set the hostapd channel bandwidth

This change takes care of setting the channel
bandwidth when framework doesn't provide the bandwidth.
Changes are,
1. 40MHz bandwidth in 2.4GHz band is not common and
is prone to inter-op issues. So disable setting 40MHz
in 2.4GHz band only configuration and cases where 60GHz
is used.
2. Set 40MHz & vht operational channel width only in 5GHz and 6GHz
when 11AC is enabled and 60GHz is not used cases.
3. set he operational channel width when 11ax is enabled and
60GHz is not used cases.

Bug: 213122226
Test: atest android.net.wifi.cts.WifiManagerTest
Test: adb shell cmd wifi force-softap-channel enabled 2412
Change-Id: I4e707d709f885daa5dcc7fdcafbfad751e3a62e1
diff --git a/hostapd/aidl/hostapd.cpp b/hostapd/aidl/hostapd.cpp
index d973dae..f0fa687 100644
--- a/hostapd/aidl/hostapd.cpp
+++ b/hostapd/aidl/hostapd.cpp
@@ -321,6 +321,7 @@
 	// Encryption config string
 	uint32_t band = 0;
 	band |= static_cast<uint32_t>(channelParams.bandMask);
+	bool is_2Ghz_band_only = band == static_cast<uint32_t>(band2Ghz);
 	bool is_6Ghz_band_only = band == static_cast<uint32_t>(band6Ghz);
 	bool is_60Ghz_band_only = band == static_cast<uint32_t>(band60Ghz);
 	std::string encryption_config_as_string;
@@ -460,9 +461,7 @@
 	std::string hw_mode_as_string;
 	std::string enable_edmg_as_string;
 	std::string edmg_channel_as_string;
-#ifdef CONFIG_IEEE80211AX
 	bool is_60Ghz_used = false;
-#endif /* CONFIG_IEEE80211AX */
 
 	if (((band & band60Ghz) != 0)) {
 		hw_mode_as_string = "hw_mode=ad";
@@ -472,9 +471,7 @@
 				"edmg_channel=%d",
 				channelParams.channel);
 		}
-#ifdef CONFIG_IEEE80211AX
 		is_60Ghz_used = true;
-#endif /* CONFIG_IEEE80211AX */
 	} else if ((band & band2Ghz) != 0) {
 		if (((band & band5Ghz) != 0)
 		    || ((band & band6Ghz) != 0)) {
@@ -550,17 +547,17 @@
 			iface_params.hwModeParams.enable80211AC ? 2 : 0);
 		break;
 	default:
-		ht_cap_vht_oper_he_oper_chwidth_as_string = StringPrintf(
-			"ht_capab=[HT40+]\n"
+		if (!is_2Ghz_band_only && !is_60Ghz_used
+		    && iface_params.hwModeParams.enable80211AC) {
+			ht_cap_vht_oper_he_oper_chwidth_as_string =
+					"ht_capab=[HT40+]\n"
+					"vht_oper_chwidth=1\n";
+		}
 #ifdef CONFIG_IEEE80211AX
-			"he_oper_chwidth=%d\n"
+		if (iface_params.hwModeParams.enable80211AX && !is_60Ghz_used) {
+			ht_cap_vht_oper_he_oper_chwidth_as_string += "he_oper_chwidth=1";
+		}
 #endif
-			"vht_oper_chwidth=%d",
-#ifdef CONFIG_IEEE80211AX
-			(iface_params.hwModeParams.enable80211AX && !is_60Ghz_used) ? 1 : 0,
-#endif
-			((((band & band5Ghz) != 0) || ((band & band6Ghz) != 0))
-			&& iface_params.hwModeParams.enable80211AC) ? 1 : 0);
 		break;
 	}