1# Copyright 2019 - The Android Open Source Project 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15from acts import utils 16 17from acts.controllers.ap_lib import hostapd_config 18from acts.controllers.ap_lib import hostapd_constants 19from acts.controllers.ap_lib import hostapd_utils 20 21 22def tplink_archerc5(iface_wlan_2g=None, 23 iface_wlan_5g=None, 24 channel=None, 25 security=None, 26 ssid=None): 27 # TODO(b/144446076): Address non-whirlwind hardware capabilities. 28 """A simulated implementation of an TPLink ArcherC5 AP. 29 Args: 30 iface_wlan_2g: The 2.4Ghz interface of the test AP. 31 iface_wlan_5g: The 5GHz interface of the test AP. 32 channel: What channel to use. 33 security: A security profile (None or WPA2). 34 ssid: The network name. 35 Returns: 36 A hostapd config. 37 Differences from real ArcherC5: 38 2.4GHz: 39 Rates: 40 ArcherC5: 41 Supported: 1, 2, 5.5, 11, 18, 24, 36, 54 42 Extended: 6, 9, 12, 48 43 Simulated: 44 Supported: 1, 2, 5.5, 11, 6, 9, 12, 18 45 Extended: 24, 36, 48, 54 46 HT Capab: 47 Info: 48 ArcherC5: Green Field supported 49 Simulated: Green Field not supported on Whirlwind. 50 5GHz: 51 VHT Capab: 52 ArcherC5: 53 SU Beamformer Supported, 54 SU Beamformee Supported, 55 Beamformee STS Capability: 3, 56 Number of Sounding Dimensions: 3, 57 VHT Link Adaptation: Both 58 Simulated: 59 Above are not supported on Whirlwind. 60 VHT Operation Info: 61 ArcherC5: Basic MCS Map (0x0000) 62 Simulated: Basic MCS Map (0xfffc) 63 VHT Tx Power Envelope: 64 ArcherC5: Local Max Tx Pwr Constraint: 1.0 dBm 65 Simulated: Local Max Tx Pwr Constraint: 23.0 dBm 66 Both: 67 HT Capab: 68 A-MPDU 69 ArcherC5: MPDU Density 4 70 Simulated: MPDU Density 8 71 HT Info: 72 ArcherC5: RIFS Permitted 73 Simulated: RIFS Prohibited 74 """ 75 # Verify interface and security 76 hostapd_utils.verify_interface(iface_wlan_2g, 77 hostapd_constants.INTERFACE_2G_LIST) 78 hostapd_utils.verify_interface(iface_wlan_5g, 79 hostapd_constants.INTERFACE_5G_LIST) 80 hostapd_utils.verify_security_mode(security, 81 [None, hostapd_constants.WPA2]) 82 if security: 83 hostapd_utils.verify_cipher(security, 84 [hostapd_constants.WPA2_DEFAULT_CIPER]) 85 86 # Common Parameters 87 rates = hostapd_constants.CCK_AND_OFDM_DATA_RATES 88 vht_channel_width = 20 89 n_capabilities = [ 90 hostapd_constants.N_CAPABILITY_SGI20, 91 hostapd_constants.N_CAPABILITY_TX_STBC, 92 hostapd_constants.N_CAPABILITY_RX_STBC1, 93 hostapd_constants.N_CAPABILITY_MAX_AMSDU_7935 94 ] 95 # WPS IE 96 # Broadcom IE 97 vendor_elements = { 98 'vendor_elements': 99 'dd310050f204104a000110104400010210470010d96c7efc2f8938f1efbd6e5148bfa8' 100 '12103c0001031049000600372a000120' 101 'dd090010180200001c0000' 102 } 103 qbss = {'bss_load_update_period': 50, 'chan_util_avg_period': 600} 104 105 # 2.4GHz 106 if channel <= 11: 107 interface = iface_wlan_2g 108 rates.update(hostapd_constants.CCK_AND_OFDM_BASIC_RATES) 109 short_preamble = True 110 mode = hostapd_constants.MODE_11N_MIXED 111 n_capabilities.append(hostapd_constants.N_CAPABILITY_DSSS_CCK_40) 112 ac_capabilities = None 113 114 # 5GHz 115 else: 116 interface = iface_wlan_5g 117 rates.update(hostapd_constants.OFDM_ONLY_BASIC_RATES) 118 short_preamble = False 119 mode = hostapd_constants.MODE_11AC_MIXED 120 n_capabilities.append(hostapd_constants.N_CAPABILITY_LDPC) 121 ac_capabilities = [ 122 hostapd_constants.AC_CAPABILITY_MAX_MPDU_11454, 123 hostapd_constants.AC_CAPABILITY_SHORT_GI_80, 124 hostapd_constants.AC_CAPABILITY_RXLDPC, 125 hostapd_constants.AC_CAPABILITY_TX_STBC_2BY1, 126 hostapd_constants.AC_CAPABILITY_RX_STBC_1, 127 hostapd_constants.AC_CAPABILITY_MAX_A_MPDU_LEN_EXP7, 128 ] 129 130 additional_params = utils.merge_dicts( 131 rates, vendor_elements, qbss, 132 hostapd_constants.ENABLE_RRM_BEACON_REPORT, 133 hostapd_constants.ENABLE_RRM_NEIGHBOR_REPORT, 134 hostapd_constants.UAPSD_ENABLED) 135 136 config = hostapd_config.HostapdConfig( 137 ssid=ssid, 138 channel=channel, 139 hidden=False, 140 security=security, 141 interface=interface, 142 mode=mode, 143 force_wmm=True, 144 beacon_interval=100, 145 dtim_period=1, 146 short_preamble=short_preamble, 147 n_capabilities=n_capabilities, 148 ac_capabilities=ac_capabilities, 149 vht_channel_width=vht_channel_width, 150 additional_parameters=additional_params) 151 return config 152 153 154def tplink_archerc7(iface_wlan_2g=None, 155 iface_wlan_5g=None, 156 channel=None, 157 security=None, 158 ssid=None): 159 # TODO(b/143104825): Permit RIFS once it is supported 160 """A simulated implementation of an TPLink ArcherC7 AP. 161 Args: 162 iface_wlan_2g: The 2.4Ghz interface of the test AP. 163 iface_wlan_5g: The 5GHz interface of the test AP. 164 channel: What channel to use. 165 security: A security profile (None or WPA2). 166 ssid: The network name. 167 Returns: 168 A hostapd config. 169 Differences from real ArcherC7: 170 5GHz: 171 Country Code: 172 Simulated: Has two country code IEs, one that matches 173 the actual, and another explicit IE that was required for 174 hostapd's 802.11d to work. 175 Both: 176 HT Info: 177 ArcherC7: RIFS Permitted 178 Simulated: RIFS Prohibited 179 RSN Capabilities (w/ WPA2): 180 ArcherC7: 181 RSN PTKSA Replay Counter Capab: 1 182 Simulated: 183 RSN PTKSA Replay Counter Capab: 16 184 """ 185 # Verify interface and security 186 hostapd_utils.verify_interface(iface_wlan_2g, 187 hostapd_constants.INTERFACE_2G_LIST) 188 hostapd_utils.verify_interface(iface_wlan_5g, 189 hostapd_constants.INTERFACE_5G_LIST) 190 hostapd_utils.verify_security_mode(security, 191 [None, hostapd_constants.WPA2]) 192 if security: 193 hostapd_utils.verify_cipher(security, 194 [hostapd_constants.WPA2_DEFAULT_CIPER]) 195 196 # Common Parameters 197 rates = hostapd_constants.CCK_AND_OFDM_DATA_RATES 198 vht_channel_width = 80 199 n_capabilities = [ 200 hostapd_constants.N_CAPABILITY_LDPC, 201 hostapd_constants.N_CAPABILITY_SGI20, 202 hostapd_constants.N_CAPABILITY_TX_STBC, 203 hostapd_constants.N_CAPABILITY_RX_STBC1 204 ] 205 # Atheros IE 206 # WPS IE 207 vendor_elements = { 208 'vendor_elements': 209 'dd0900037f01010000ff7f' 210 'dd180050f204104a00011010440001021049000600372a000120' 211 } 212 213 # 2.4GHz 214 if channel <= 11: 215 interface = iface_wlan_2g 216 rates.update(hostapd_constants.CCK_AND_OFDM_BASIC_RATES) 217 short_preamble = True 218 mode = hostapd_constants.MODE_11N_MIXED 219 spectrum_mgmt = False 220 pwr_constraint = {} 221 ac_capabilities = None 222 vht_channel_width = None 223 224 # 5GHz 225 else: 226 interface = iface_wlan_5g 227 rates.update(hostapd_constants.OFDM_ONLY_BASIC_RATES) 228 short_preamble = False 229 mode = hostapd_constants.MODE_11AC_MIXED 230 spectrum_mgmt = True 231 # Country Information IE (w/ individual channel info) 232 vendor_elements['vendor_elements'] += ( 233 '074255532024011e28011e2c011e30' 234 '011e3401173801173c01174001176401176801176c0117700117740117840117' 235 '8801178c011795011e99011e9d011ea1011ea5011e') 236 pwr_constraint = {'local_pwr_constraint': 3} 237 n_capabilities += [ 238 hostapd_constants.N_CAPABILITY_SGI40, 239 hostapd_constants.N_CAPABILITY_MAX_AMSDU_7935 240 ] 241 242 if hostapd_config.ht40_plus_allowed(channel): 243 n_capabilities.append(hostapd_constants.N_CAPABILITY_HT40_PLUS) 244 elif hostapd_config.ht40_minus_allowed(channel): 245 n_capabilities.append(hostapd_constants.N_CAPABILITY_HT40_MINUS) 246 247 ac_capabilities = [ 248 hostapd_constants.AC_CAPABILITY_MAX_MPDU_11454, 249 hostapd_constants.AC_CAPABILITY_RXLDPC, 250 hostapd_constants.AC_CAPABILITY_SHORT_GI_80, 251 hostapd_constants.AC_CAPABILITY_TX_STBC_2BY1, 252 hostapd_constants.AC_CAPABILITY_RX_STBC_1, 253 hostapd_constants.AC_CAPABILITY_MAX_A_MPDU_LEN_EXP7, 254 hostapd_constants.AC_CAPABILITY_RX_ANTENNA_PATTERN, 255 hostapd_constants.AC_CAPABILITY_TX_ANTENNA_PATTERN 256 ] 257 258 additional_params = utils.merge_dicts(rates, vendor_elements, 259 hostapd_constants.UAPSD_ENABLED, 260 pwr_constraint) 261 262 config = hostapd_config.HostapdConfig( 263 ssid=ssid, 264 channel=channel, 265 hidden=False, 266 security=security, 267 interface=interface, 268 mode=mode, 269 force_wmm=True, 270 beacon_interval=100, 271 dtim_period=1, 272 short_preamble=short_preamble, 273 n_capabilities=n_capabilities, 274 ac_capabilities=ac_capabilities, 275 vht_channel_width=vht_channel_width, 276 spectrum_mgmt_required=spectrum_mgmt, 277 additional_parameters=additional_params) 278 return config 279 280 281def tplink_c1200(iface_wlan_2g=None, 282 iface_wlan_5g=None, 283 channel=None, 284 security=None, 285 ssid=None): 286 # TODO(b/143104825): Permit RIFS once it is supported 287 # TODO(b/144446076): Address non-whirlwind hardware capabilities. 288 """A simulated implementation of an TPLink C1200 AP. 289 Args: 290 iface_wlan_2g: The 2.4Ghz interface of the test AP. 291 iface_wlan_5g: The 5GHz interface of the test AP. 292 channel: What channel to use. 293 security: A security profile (None or WPA2). 294 ssid: The network name. 295 Returns: 296 A hostapd config. 297 Differences from real C1200: 298 2.4GHz: 299 Rates: 300 C1200: 301 Supported: 1, 2, 5.5, 11, 18, 24, 36, 54 302 Extended: 6, 9, 12, 48 303 Simulated: 304 Supported: 1, 2, 5.5, 11, 6, 9, 12, 18 305 Extended: 24, 36, 48, 54 306 HT Capab: 307 Info: 308 C1200: Green Field supported 309 Simulated: Green Field not supported on Whirlwind. 310 5GHz: 311 VHT Operation Info: 312 C1200: Basic MCS Map (0x0000) 313 Simulated: Basic MCS Map (0xfffc) 314 VHT Tx Power Envelope: 315 C1200: Local Max Tx Pwr Constraint: 7.0 dBm 316 Simulated: Local Max Tx Pwr Constraint: 23.0 dBm 317 Both: 318 HT Info: 319 C1200: RIFS Permitted 320 Simulated: RIFS Prohibited 321 """ 322 # Verify interface and security 323 hostapd_utils.verify_interface(iface_wlan_2g, 324 hostapd_constants.INTERFACE_2G_LIST) 325 hostapd_utils.verify_interface(iface_wlan_5g, 326 hostapd_constants.INTERFACE_5G_LIST) 327 hostapd_utils.verify_security_mode(security, 328 [None, hostapd_constants.WPA2]) 329 if security: 330 hostapd_utils.verify_cipher(security, 331 [hostapd_constants.WPA2_DEFAULT_CIPER]) 332 333 # Common Parameters 334 rates = hostapd_constants.CCK_AND_OFDM_DATA_RATES 335 vht_channel_width = 20 336 n_capabilities = [ 337 hostapd_constants.N_CAPABILITY_SGI20, 338 hostapd_constants.N_CAPABILITY_TX_STBC, 339 hostapd_constants.N_CAPABILITY_RX_STBC1, 340 hostapd_constants.N_CAPABILITY_MAX_AMSDU_7935 341 ] 342 # WPS IE 343 # Broadcom IE 344 vendor_elements = { 345 'vendor_elements': 346 'dd350050f204104a000110104400010210470010000000000000000000000000000000' 347 '00103c0001031049000a00372a00012005022688' 348 'dd090010180200000c0000' 349 } 350 351 # 2.4GHz 352 if channel <= 11: 353 interface = iface_wlan_2g 354 rates.update(hostapd_constants.CCK_AND_OFDM_BASIC_RATES) 355 short_preamble = True 356 mode = hostapd_constants.MODE_11N_MIXED 357 ac_capabilities = None 358 359 # 5GHz 360 else: 361 interface = iface_wlan_5g 362 rates.update(hostapd_constants.OFDM_ONLY_BASIC_RATES) 363 short_preamble = False 364 mode = hostapd_constants.MODE_11AC_MIXED 365 n_capabilities.append(hostapd_constants.N_CAPABILITY_LDPC) 366 ac_capabilities = [ 367 hostapd_constants.AC_CAPABILITY_MAX_MPDU_11454, 368 hostapd_constants.AC_CAPABILITY_SHORT_GI_80, 369 hostapd_constants.AC_CAPABILITY_RXLDPC, 370 hostapd_constants.AC_CAPABILITY_TX_STBC_2BY1, 371 hostapd_constants.AC_CAPABILITY_RX_STBC_1, 372 hostapd_constants.AC_CAPABILITY_MAX_A_MPDU_LEN_EXP7, 373 ] 374 375 additional_params = utils.merge_dicts( 376 rates, vendor_elements, hostapd_constants.ENABLE_RRM_BEACON_REPORT, 377 hostapd_constants.ENABLE_RRM_NEIGHBOR_REPORT, 378 hostapd_constants.UAPSD_ENABLED) 379 380 config = hostapd_config.HostapdConfig( 381 ssid=ssid, 382 channel=channel, 383 hidden=False, 384 security=security, 385 interface=interface, 386 mode=mode, 387 force_wmm=True, 388 beacon_interval=100, 389 dtim_period=1, 390 short_preamble=short_preamble, 391 n_capabilities=n_capabilities, 392 ac_capabilities=ac_capabilities, 393 vht_channel_width=vht_channel_width, 394 additional_parameters=additional_params) 395 return config 396 397 398def tplink_tlwr940n(iface_wlan_2g=None, 399 channel=None, 400 security=None, 401 ssid=None): 402 # TODO(b/143104825): Permit RIFS once it is supported 403 """A simulated implementation of an TPLink TLWR940N AP. 404 Args: 405 iface_wlan_2g: The 2.4Ghz interface of the test AP. 406 channel: What channel to use. 407 security: A security profile (None or WPA2). 408 ssid: The network name. 409 Returns: 410 A hostapd config. 411 Differences from real TLWR940N: 412 HT Info: 413 TLWR940N: RIFS Permitted 414 Simulated: RIFS Prohibited 415 RSN Capabilities (w/ WPA2): 416 TLWR940N: 417 RSN PTKSA Replay Counter Capab: 1 418 Simulated: 419 RSN PTKSA Replay Counter Capab: 16 420 """ 421 if channel > 11: 422 raise ValueError('The mock TP-Link TLWR940N does not support 5Ghz. ' 423 'Invalid channel (%s)' % channel) 424 # Verify interface and security 425 hostapd_utils.verify_interface(iface_wlan_2g, 426 hostapd_constants.INTERFACE_2G_LIST) 427 hostapd_utils.verify_security_mode(security, 428 [None, hostapd_constants.WPA2]) 429 if security: 430 hostapd_utils.verify_cipher(security, 431 [hostapd_constants.WPA2_DEFAULT_CIPER]) 432 433 n_capabilities = [ 434 hostapd_constants.N_CAPABILITY_SGI20, 435 hostapd_constants.N_CAPABILITY_TX_STBC, 436 hostapd_constants.N_CAPABILITY_RX_STBC1 437 ] 438 439 rates = utils.merge_dicts(hostapd_constants.CCK_AND_OFDM_BASIC_RATES, 440 hostapd_constants.CCK_AND_OFDM_DATA_RATES) 441 442 # Atheros Communications, Inc. IE 443 # WPS IE 444 vendor_elements = { 445 'vendor_elements': 446 'dd0900037f01010000ff7f' 447 'dd260050f204104a0001101044000102104900140024e2600200010160000002000160' 448 '0100020001' 449 } 450 451 additional_params = utils.merge_dicts(rates, vendor_elements, 452 hostapd_constants.UAPSD_ENABLED) 453 454 config = hostapd_config.HostapdConfig( 455 ssid=ssid, 456 channel=channel, 457 hidden=False, 458 security=security, 459 interface=iface_wlan_2g, 460 mode=hostapd_constants.MODE_11N_MIXED, 461 force_wmm=True, 462 beacon_interval=100, 463 dtim_period=1, 464 short_preamble=True, 465 n_capabilities=n_capabilities, 466 additional_parameters=additional_params) 467 468 return config 469