Merge "Fix vht_oper_centr_freq_seg0_idx in VapeInteropTest"
diff --git a/acts/framework/acts/controllers/ap_lib/hostapd_config.py b/acts/framework/acts/controllers/ap_lib/hostapd_config.py
index a6d71c2..47afb2e 100644
--- a/acts/framework/acts/controllers/ap_lib/hostapd_config.py
+++ b/acts/framework/acts/controllers/ap_lib/hostapd_config.py
@@ -463,11 +463,13 @@
                 logging.warning(
                     'No channel bandwidth specified.  Using 80MHz for 11ac.')
                 self._vht_oper_chwidth = 1
-            if not vht_channel_width == 20 and vht_center_channel is None:
+            if vht_center_channel is not None:
+                self._vht_oper_centr_freq_seg0_idx = vht_center_channel
+            elif vht_channel_width == 20:
+                self._vht_oper_centr_freq_seg0_idx = channel
+            else:
                 self._vht_oper_centr_freq_seg0_idx = self._get_11ac_center_channel_from_channel(
                     self.channel)
-            else:
-                self._vht_oper_centr_freq_seg0_idx = vht_center_channel
             self._ac_capabilities = set(ac_capabilities)
         self._beacon_footer = beacon_footer
         self._spectrum_mgmt_required = spectrum_mgmt_required
diff --git a/acts/framework/acts/controllers/ap_lib/hostapd_constants.py b/acts/framework/acts/controllers/ap_lib/hostapd_constants.py
index 7f70dfe..588fbc2 100755
--- a/acts/framework/acts/controllers/ap_lib/hostapd_constants.py
+++ b/acts/framework/acts/controllers/ap_lib/hostapd_constants.py
@@ -270,11 +270,11 @@
 HT40_ALLOW_MAP = {
     N_CAPABILITY_HT40_MINUS_CHANNELS:
     tuple(
-        itertools.chain(range(6, 14), range(40, 65, 8), range(104, 137, 8),
+        itertools.chain(range(6, 14), range(40, 65, 8), range(104, 145, 8),
                         [153, 161])),
     N_CAPABILITY_HT40_PLUS_CHANNELS:
     tuple(
-        itertools.chain(range(1, 8), range(36, 61, 8), range(100, 133, 8),
+        itertools.chain(range(1, 8), range(36, 61, 8), range(100, 141, 8),
                         [149, 157]))
 }
 
diff --git a/acts/framework/acts/controllers/ap_lib/third_party_ap_profiles/asus.py b/acts/framework/acts/controllers/ap_lib/third_party_ap_profiles/asus.py
index af489d6..bb13118 100644
--- a/acts/framework/acts/controllers/ap_lib/third_party_ap_profiles/asus.py
+++ b/acts/framework/acts/controllers/ap_lib/third_party_ap_profiles/asus.py
@@ -87,6 +87,7 @@
 
     # Common Parameters
     rates = hostapd_constants.CCK_AND_OFDM_DATA_RATES
+    vht_channel_width = 20
     n_capabilities = [
         hostapd_constants.N_CAPABILITY_LDPC,
         hostapd_constants.N_CAPABILITY_TX_STBC,
@@ -110,8 +111,6 @@
         rates.update(hostapd_constants.CCK_AND_OFDM_BASIC_RATES)
         mode = hostapd_constants.MODE_11N_MIXED
         ac_capabilities = None
-        vht_channel_width = None
-        vht_center_channel = None
 
     # 5GHz
     else:
@@ -126,8 +125,6 @@
             hostapd_constants.AC_CAPABILITY_MAX_MPDU_11454,
             hostapd_constants.AC_CAPABILITY_MAX_A_MPDU_LEN_EXP7
         ]
-        vht_channel_width = 40
-        vht_center_channel = 36
 
     additional_params = utils.merge_dicts(rates, vendor_elements,
                                           hostapd_constants.UAPSD_ENABLED)
@@ -146,7 +143,6 @@
         n_capabilities=n_capabilities,
         ac_capabilities=ac_capabilities,
         vht_channel_width=vht_channel_width,
-        vht_center_channel=vht_center_channel,
         additional_parameters=additional_params)
 
     return config
@@ -313,6 +309,7 @@
 
     # Common Parameters
     rates = hostapd_constants.CCK_AND_OFDM_DATA_RATES
+    vht_channel_width = 20
     qbss = {'bss_load_update_period': 50, 'chan_util_avg_period': 600}
     n_capabilities = [
         hostapd_constants.N_CAPABILITY_LDPC,
@@ -320,6 +317,7 @@
         hostapd_constants.N_CAPABILITY_RX_STBC1,
         hostapd_constants.N_CAPABILITY_SGI20
     ]
+
     # Broadcom IE
     vendor_elements = {'vendor_elements': 'dd090010180200009c0000'}
 
@@ -334,8 +332,6 @@
         '2fd437509c30b3d7f5cf5754fb125aed3b8507045aed3b85' \
         'dd1e00904c0418bf0cb2798b0faaff0000aaff0000c0050001000000c3020002'
         ac_capabilities = None
-        vht_channel_width = None
-        vht_center_channel = None
 
     # 5GHz
     else:
@@ -352,8 +348,6 @@
             hostapd_constants.AC_CAPABILITY_MAX_MPDU_11454,
             hostapd_constants.AC_CAPABILITY_MAX_A_MPDU_LEN_EXP7
         ]
-        vht_channel_width = 40
-        vht_center_channel = 36
 
     additional_params = utils.merge_dicts(rates, qbss, vendor_elements,
                                           hostapd_constants.UAPSD_ENABLED)
@@ -372,7 +366,6 @@
         n_capabilities=n_capabilities,
         ac_capabilities=ac_capabilities,
         vht_channel_width=vht_channel_width,
-        vht_center_channel=vht_center_channel,
         additional_parameters=additional_params)
     return config
 
diff --git a/acts/framework/acts/controllers/ap_lib/third_party_ap_profiles/linksys.py b/acts/framework/acts/controllers/ap_lib/third_party_ap_profiles/linksys.py
index 1ee4869..8bb2841 100644
--- a/acts/framework/acts/controllers/ap_lib/third_party_ap_profiles/linksys.py
+++ b/acts/framework/acts/controllers/ap_lib/third_party_ap_profiles/linksys.py
@@ -258,8 +258,7 @@
         hostapd_constants.AC_CAPABILITY_TX_ANTENNA_PATTERN,
         hostapd_constants.AC_CAPABILITY_MAX_A_MPDU_LEN_EXP7
     ]
-    vht_channel_width = 40
-    vht_center_channel = 0
+    vht_channel_width = 20
     # Epigram, Inc. HT Capabilities IE
     # Epigram, Inc. HT Additional Capabilities IE
     # Marvell Semiconductor IE
@@ -308,7 +307,6 @@
         n_capabilities=n_capabilities,
         ac_capabilities=ac_capabilities,
         vht_channel_width=vht_channel_width,
-        vht_center_channel=vht_center_channel,
         spectrum_mgmt_required=spectrum_mgmt,
         additional_parameters=additional_params)
     return config
diff --git a/acts/framework/acts/controllers/ap_lib/third_party_ap_profiles/netgear.py b/acts/framework/acts/controllers/ap_lib/third_party_ap_profiles/netgear.py
index 331dcdf..922d51a 100644
--- a/acts/framework/acts/controllers/ap_lib/third_party_ap_profiles/netgear.py
+++ b/acts/framework/acts/controllers/ap_lib/third_party_ap_profiles/netgear.py
@@ -91,6 +91,7 @@
 
     # Common Parameters
     rates = hostapd_constants.CCK_AND_OFDM_DATA_RATES
+    vht_channel_width = 80
     n_capabilities = [
         hostapd_constants.N_CAPABILITY_LDPC,
         hostapd_constants.N_CAPABILITY_TX_STBC,
@@ -119,8 +120,6 @@
         mode = hostapd_constants.MODE_11N_MIXED
         obss_interval = 300
         ac_capabilities = None
-        vht_channel_width = None
-        vht_center_channel = None
 
     # 5GHz
     else:
@@ -129,8 +128,13 @@
         mode = hostapd_constants.MODE_11AC_MIXED
         n_capabilities += [
             hostapd_constants.N_CAPABILITY_SGI40,
-            hostapd_constants.N_CAPABILITY_HT40_PLUS
         ]
+
+        if hostapd_config.ht40_plus_allowed(channel):
+            n_capabilities.append(hostapd_constants.N_CAPABILITY_HT40_PLUS)
+        elif hostapd_config.ht40_minus_allowed(channel):
+            n_capabilities.append(hostapd_constants.N_CAPABILITY_HT40_MINUS)
+
         obss_interval = None
         ac_capabilities = [
             hostapd_constants.AC_CAPABILITY_RXLDPC,
@@ -140,8 +144,6 @@
             hostapd_constants.AC_CAPABILITY_MAX_MPDU_11454,
             hostapd_constants.AC_CAPABILITY_MAX_A_MPDU_LEN_EXP7
         ]
-        vht_channel_width = 80
-        vht_center_channel = 42
 
     additional_params = utils.merge_dicts(
         rates, vendor_elements, qbss,
@@ -164,7 +166,6 @@
         n_capabilities=n_capabilities,
         ac_capabilities=ac_capabilities,
         vht_channel_width=vht_channel_width,
-        vht_center_channel=vht_center_channel,
         additional_parameters=additional_params)
     return config
 
diff --git a/acts/framework/acts/controllers/ap_lib/third_party_ap_profiles/tplink.py b/acts/framework/acts/controllers/ap_lib/third_party_ap_profiles/tplink.py
index 15961ba..e3e9894 100644
--- a/acts/framework/acts/controllers/ap_lib/third_party_ap_profiles/tplink.py
+++ b/acts/framework/acts/controllers/ap_lib/third_party_ap_profiles/tplink.py
@@ -85,6 +85,7 @@
 
     # Common Parameters
     rates = hostapd_constants.CCK_AND_OFDM_DATA_RATES
+    vht_channel_width = 20
     n_capabilities = [
         hostapd_constants.N_CAPABILITY_SGI20,
         hostapd_constants.N_CAPABILITY_TX_STBC,
@@ -109,8 +110,6 @@
         mode = hostapd_constants.MODE_11N_MIXED
         n_capabilities.append(hostapd_constants.N_CAPABILITY_DSSS_CCK_40)
         ac_capabilities = None
-        vht_channel_width = None
-        vht_center_channel = None
 
     # 5GHz
     else:
@@ -127,8 +126,6 @@
             hostapd_constants.AC_CAPABILITY_RX_STBC_1,
             hostapd_constants.AC_CAPABILITY_MAX_A_MPDU_LEN_EXP7,
         ]
-        vht_channel_width = 40
-        vht_center_channel = 36
 
     additional_params = utils.merge_dicts(
         rates, vendor_elements, qbss,
@@ -150,7 +147,6 @@
         n_capabilities=n_capabilities,
         ac_capabilities=ac_capabilities,
         vht_channel_width=vht_channel_width,
-        vht_center_channel=vht_center_channel,
         additional_parameters=additional_params)
     return config
 
@@ -199,6 +195,7 @@
 
     # Common Parameters
     rates = hostapd_constants.CCK_AND_OFDM_DATA_RATES
+    vht_channel_width = 80
     n_capabilities = [
         hostapd_constants.N_CAPABILITY_LDPC,
         hostapd_constants.N_CAPABILITY_SGI20,
@@ -223,7 +220,6 @@
         pwr_constraint = {}
         ac_capabilities = None
         vht_channel_width = None
-        vht_center_channel = None
 
     # 5GHz
     else:
@@ -239,10 +235,15 @@
             '8801178c011795011e99011e9d011ea1011ea5011e')
         pwr_constraint = {'local_pwr_constraint': 3}
         n_capabilities += [
-            hostapd_constants.N_CAPABILITY_HT40_PLUS,
             hostapd_constants.N_CAPABILITY_SGI40,
             hostapd_constants.N_CAPABILITY_MAX_AMSDU_7935
         ]
+
+        if hostapd_config.ht40_plus_allowed(channel):
+            n_capabilities.append(hostapd_constants.N_CAPABILITY_HT40_PLUS)
+        elif hostapd_config.ht40_minus_allowed(channel):
+            n_capabilities.append(hostapd_constants.N_CAPABILITY_HT40_MINUS)
+
         ac_capabilities = [
             hostapd_constants.AC_CAPABILITY_MAX_MPDU_11454,
             hostapd_constants.AC_CAPABILITY_RXLDPC,
@@ -253,8 +254,6 @@
             hostapd_constants.AC_CAPABILITY_RX_ANTENNA_PATTERN,
             hostapd_constants.AC_CAPABILITY_TX_ANTENNA_PATTERN
         ]
-        vht_channel_width = 80
-        vht_center_channel = 42
 
     additional_params = utils.merge_dicts(rates, vendor_elements,
                                           hostapd_constants.UAPSD_ENABLED,
@@ -274,7 +273,6 @@
         n_capabilities=n_capabilities,
         ac_capabilities=ac_capabilities,
         vht_channel_width=vht_channel_width,
-        vht_center_channel=vht_center_channel,
         spectrum_mgmt_required=spectrum_mgmt,
         additional_parameters=additional_params)
     return config
@@ -334,6 +332,7 @@
 
     # Common Parameters
     rates = hostapd_constants.CCK_AND_OFDM_DATA_RATES
+    vht_channel_width = 20
     n_capabilities = [
         hostapd_constants.N_CAPABILITY_SGI20,
         hostapd_constants.N_CAPABILITY_TX_STBC,
@@ -356,8 +355,6 @@
         short_preamble = True
         mode = hostapd_constants.MODE_11N_MIXED
         ac_capabilities = None
-        vht_channel_width = None
-        vht_center_channel = None
 
     # 5GHz
     else:
@@ -374,8 +371,6 @@
             hostapd_constants.AC_CAPABILITY_RX_STBC_1,
             hostapd_constants.AC_CAPABILITY_MAX_A_MPDU_LEN_EXP7,
         ]
-        vht_channel_width = 40
-        vht_center_channel = 36
 
     additional_params = utils.merge_dicts(
         rates, vendor_elements, hostapd_constants.ENABLE_RRM_BEACON_REPORT,
@@ -396,12 +391,13 @@
         n_capabilities=n_capabilities,
         ac_capabilities=ac_capabilities,
         vht_channel_width=vht_channel_width,
-        vht_center_channel=vht_center_channel,
         additional_parameters=additional_params)
     return config
 
 
-def tplink_tlwr940n(iface_wlan_2g=None, channel=None, security=None,
+def tplink_tlwr940n(iface_wlan_2g=None,
+                    channel=None,
+                    security=None,
                     ssid=None):
     # TODO(b/143104825): Permit RIFS once it is supported
     """A simulated implementation of an TPLink TLWR940N AP.