1#!/usr/bin/env python3.4 2# 3# Copyright 2016 - The Android Open Source Project 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17import os 18import time 19 20from acts import asserts 21from acts import utils 22from acts.keys import Config 23from acts.test_decorators import test_tracker_info 24from acts_contrib.test_utils.tel import tel_test_utils as tel_utils 25from acts_contrib.test_utils.wifi import wifi_constants 26from acts_contrib.test_utils.wifi import wifi_test_utils as wutils 27from acts_contrib.test_utils.wifi.WifiBaseTest import WifiBaseTest 28 29WifiEnums = wutils.WifiEnums 30WIFI_CONFIG_APBAND_2G = WifiEnums.WIFI_CONFIG_APBAND_2G 31WIFI_CONFIG_APBAND_5G = WifiEnums.WIFI_CONFIG_APBAND_5G 32WIFI_CONFIG_APBAND_AUTO = WifiEnums.WIFI_CONFIG_APBAND_AUTO 33WPA3_SAE_TRANSITION_SOFTAP = WifiEnums.SoftApSecurityType.WPA3_SAE_TRANSITION 34WPA3_SAE_SOFTAP = WifiEnums.SoftApSecurityType.WPA3_SAE 35WAIT_AFTER_REBOOT = 10 36 37 38class WifiSoftApTest(WifiBaseTest): 39 40 def setup_class(self): 41 """It will setup the required dependencies from config file and configure 42 the devices for softap mode testing. 43 44 Returns: 45 True if successfully configured the requirements for testing. 46 """ 47 super().setup_class() 48 self.dut = self.android_devices[0] 49 self.dut_client = self.android_devices[1] 50 req_params = ["dbs_supported_models", "sta_concurrency_supported_models", 51 "sap_wpa3_supported_models", "wifi6_models", "sim_supported_models"] 52 opt_param = ["reference_networks"] 53 self.unpack_userparams( 54 req_param_names=req_params, opt_param_names=opt_param) 55 if "AccessPoint" in self.user_params: 56 self.legacy_configure_ap_and_start() 57 elif "OpenWrtAP" in self.user_params: 58 self.configure_openwrt_ap_and_start(wpa_network=True) 59 self.wifi_network = self.reference_networks[0]["2g"] 60 # Do a simple version of init - mainly just sync the time and enable 61 # verbose logging. This test will fail if the DUT has a sim and cell 62 # data is disabled. We would also like to test with phones in less 63 # constrained states (or add variations where we specifically 64 # constrain). 65 utils.require_sl4a((self.dut, self.dut_client)) 66 utils.sync_device_time(self.dut) 67 utils.sync_device_time(self.dut_client) 68 # Enable verbose logging on the duts 69 self.dut.droid.wifiEnableVerboseLogging(1) 70 asserts.assert_equal(self.dut.droid.wifiGetVerboseLoggingLevel(), 1, 71 "Failed to enable WiFi verbose logging on the softap dut.") 72 self.dut_client.droid.wifiEnableVerboseLogging(1) 73 asserts.assert_equal(self.dut_client.droid.wifiGetVerboseLoggingLevel(), 1, 74 "Failed to enable WiFi verbose logging on the client dut.") 75 wutils.wifi_toggle_state(self.dut, True) 76 wutils.wifi_toggle_state(self.dut_client, True) 77 self.AP_IFACE = 'wlan0' 78 if self.dut.model in self.dbs_supported_models: 79 self.AP_IFACE = 'wlan1' 80 if self.dut.model in self.sta_concurrency_supported_models: 81 self.AP_IFACE = 'wlan2' 82 if len(self.android_devices) > 2: 83 utils.sync_device_time(self.android_devices[2]) 84 self.android_devices[2].droid.wifiEnableVerboseLogging(1) 85 asserts.assert_equal(self.android_devices[2].droid.wifiGetVerboseLoggingLevel(), 1, 86 "Failed to enable WiFi verbose logging on the client dut.") 87 self.dut_client_2 = self.android_devices[2] 88 self.country_code = wutils.WifiEnums.CountryCode.US 89 if hasattr(self, "country_code_file"): 90 if isinstance(self.country_code_file, list): 91 self.country_code_file = self.country_code_file[0] 92 if not os.path.isfile(self.country_code_file): 93 self.country_code_file = os.path.join( 94 self.user_params[Config.key_config_path.value], 95 self.country_code_file) 96 self.country_code = utils.load_config( 97 self.country_code_file)["country"] 98 99 def teardown_class(self): 100 if self.dut.droid.wifiIsApEnabled(): 101 wutils.stop_wifi_tethering(self.dut) 102 wutils.reset_wifi(self.dut) 103 wutils.reset_wifi(self.dut_client) 104 if "AccessPoint" in self.user_params: 105 del self.user_params["reference_networks"] 106 del self.user_params["open_network"] 107 108 def setup_test(self): 109 super().setup_test() 110 for ad in self.android_devices: 111 wutils.wifi_toggle_state(ad, True) 112 if "chan_13" in self.test_name and "OpenWrtAP" in self.user_params: 113 self.access_points[0].close() 114 self.configure_openwrt_ap_and_start(wpa_network=True, 115 channel_2g=13) 116 self.wifi_network = self.reference_networks[0]["2g"] 117 for ad in self.android_devices: 118 wutils.set_wifi_country_code( 119 ad, wutils.WifiEnums.CountryCode.AUSTRALIA) 120 121 def teardown_test(self): 122 super().teardown_test() 123 self.dut.log.debug("Toggling Airplane mode OFF.") 124 asserts.assert_true(utils.force_airplane_mode(self.dut, False), 125 "Can not turn off airplane mode: %s" % self.dut.serial) 126 self.dut.adb.shell("cmd wifi reset-coex-cell-channels") 127 if self.dut.droid.wifiIsApEnabled(): 128 wutils.stop_wifi_tethering(self.dut) 129 if "chan_13" in self.test_name and "OpenWrtAP" in self.user_params: 130 self.access_points[0].close() 131 self.configure_openwrt_ap_and_start(wpa_network=True) 132 self.wifi_network = self.reference_networks[0]["2g"] 133 for ad in self.android_devices: 134 wutils.set_wifi_country_code(ad, self.country_code) 135 136 """ Helper Functions """ 137 def create_softap_config(self): 138 """Create a softap config with ssid and password.""" 139 ap_ssid = "softap_" + utils.rand_ascii_str(8) 140 ap_password = utils.rand_ascii_str(8) 141 self.dut.log.info("softap setup: %s %s", ap_ssid, ap_password) 142 config = {wutils.WifiEnums.SSID_KEY: ap_ssid} 143 config[wutils.WifiEnums.PWD_KEY] = ap_password 144 return config 145 146 def confirm_softap_in_scan_results(self, ap_ssid): 147 """Confirm the ap started by wifi tethering is seen in scan results. 148 149 Args: 150 ap_ssid: SSID of the ap we are looking for. 151 """ 152 wutils.start_wifi_connection_scan_and_ensure_network_found( 153 self.dut_client, ap_ssid); 154 155 def confirm_softap_not_in_scan_results(self, ap_ssid): 156 """Confirm the ap started by wifi tethering is not seen in scan results. 157 158 Args: 159 ap_ssid: SSID of the ap we are looking for. 160 """ 161 wutils.start_wifi_connection_scan_and_ensure_network_not_found( 162 self.dut_client, ap_ssid); 163 164 def check_cell_data_and_enable(self): 165 """Make sure that cell data is enabled if there is a sim present. 166 167 If a sim is active, cell data needs to be enabled to allow provisioning 168 checks through (when applicable). This is done to relax hardware 169 requirements on DUTs - without this check, running this set of tests 170 after other wifi tests may cause failures. 171 """ 172 # We do have a sim. Make sure data is enabled so we can tether. 173 if not self.dut.droid.telephonyIsDataEnabled(): 174 self.dut.log.info("need to enable data") 175 self.dut.droid.telephonyToggleDataConnection(True) 176 asserts.assert_true(self.dut.droid.telephonyIsDataEnabled(), 177 "Failed to enable cell data for softap dut.") 178 179 def validate_full_tether_startup(self, band=None, hidden=None, 180 test_ping=False, test_clients=None, 181 security=None): 182 """Test full startup of wifi tethering 183 184 1. Report current state. 185 2. Switch to AP mode. 186 3. verify SoftAP active. 187 4. Shutdown wifi tethering. 188 5. verify back to previous mode. 189 """ 190 initial_wifi_state = self.dut.droid.wifiCheckState() 191 initial_cell_state = tel_utils.is_sim_ready(self.log, self.dut) 192 self.dut.log.info("current state: %s", initial_wifi_state) 193 self.dut.log.info("is sim ready? %s", initial_cell_state) 194 config = self.create_softap_config() 195 wutils.start_wifi_tethering(self.dut, 196 config[wutils.WifiEnums.SSID_KEY], 197 config[wutils.WifiEnums.PWD_KEY], 198 band, 199 hidden, 200 security) 201 if hidden: 202 # First ensure it's not seen in scan results. 203 self.confirm_softap_not_in_scan_results( 204 config[wutils.WifiEnums.SSID_KEY]) 205 # If the network is hidden, it should be saved on the client to be 206 # seen in scan results. 207 config[wutils.WifiEnums.HIDDEN_KEY] = True 208 ret = self.dut_client.droid.wifiAddNetwork(config) 209 asserts.assert_true(ret != -1, "Add network %r failed" % config) 210 self.dut_client.droid.wifiEnableNetwork(ret, 0) 211 self.confirm_softap_in_scan_results(config[wutils.WifiEnums.SSID_KEY]) 212 if test_ping: 213 self.validate_ping_between_softap_and_client(config) 214 if test_clients: 215 if len(self.android_devices) > 2: 216 self.validate_ping_between_two_clients(config) 217 wutils.stop_wifi_tethering(self.dut) 218 asserts.assert_false(self.dut.droid.wifiIsApEnabled(), 219 "SoftAp is still reported as running") 220 if initial_wifi_state: 221 wutils.wait_for_wifi_state(self.dut, True) 222 elif self.dut.droid.wifiCheckState(): 223 asserts.fail("Wifi was disabled before softap and now it is enabled") 224 225 def validate_ping_between_softap_and_client(self, config): 226 """Test ping between softap and its client. 227 228 Connect one android device to the wifi hotspot. 229 Verify they can ping each other. 230 231 Args: 232 config: wifi network config with SSID, password 233 """ 234 wutils.wifi_connect(self.dut_client, config, check_connectivity=False) 235 236 dut_ip = self.dut.droid.connectivityGetIPv4Addresses(self.AP_IFACE)[0] 237 dut_client_ip = self.dut_client.droid.connectivityGetIPv4Addresses('wlan0')[0] 238 wutils.verify_11ax_softap(self.dut, self.dut_client, self.wifi6_models) 239 240 self.dut.log.info("Try to ping %s" % dut_client_ip) 241 asserts.assert_true( 242 utils.adb_shell_ping(self.dut, count=10, dest_ip=dut_client_ip, timeout=20), 243 "%s ping %s failed" % (self.dut.serial, dut_client_ip)) 244 245 self.dut_client.log.info("Try to ping %s" % dut_ip) 246 asserts.assert_true( 247 utils.adb_shell_ping(self.dut_client, count=10, dest_ip=dut_ip, timeout=20), 248 "%s ping %s failed" % (self.dut_client.serial, dut_ip)) 249 250 def validate_ping_between_two_clients(self, config): 251 """Test ping between softap's clients. 252 253 Connect two android device to the wifi hotspot. 254 Verify the clients can ping each other. 255 256 Args: 257 config: wifi network config with SSID, password 258 """ 259 # Connect DUT to Network 260 ad1 = self.dut_client 261 ad2 = self.android_devices[2] 262 263 wutils.wifi_connect(ad1, config, check_connectivity=False) 264 wutils.wifi_connect(ad2, config, check_connectivity=False) 265 ad1_ip = ad1.droid.connectivityGetIPv4Addresses('wlan0')[0] 266 ad2_ip = ad2.droid.connectivityGetIPv4Addresses('wlan0')[0] 267 268 # Ping each other 269 ad1.log.info("Try to ping %s" % ad2_ip) 270 asserts.assert_true( 271 utils.adb_shell_ping(ad1, count=10, dest_ip=ad2_ip, timeout=20), 272 "%s ping %s failed" % (ad1.serial, ad2_ip)) 273 274 ad2.log.info("Try to ping %s" % ad1_ip) 275 asserts.assert_true( 276 utils.adb_shell_ping(ad2, count=10, dest_ip=ad1_ip, timeout=20), 277 "%s ping %s failed" % (ad2.serial, ad1_ip)) 278 279 def validate_softap_after_reboot(self, band, security, hidden=False): 280 config = self.create_softap_config() 281 softap_config = config.copy() 282 softap_config[WifiEnums.AP_BAND_KEY] = band 283 softap_config[WifiEnums.SECURITY] = security 284 if hidden: 285 softap_config[WifiEnums.HIDDEN_KEY] = hidden 286 asserts.assert_true( 287 self.dut.droid.wifiSetWifiApConfiguration(softap_config), 288 "Failed to update WifiAp Configuration") 289 self.dut.reboot() 290 time.sleep(WAIT_AFTER_REBOOT) 291 wutils.start_wifi_tethering_saved_config(self.dut) 292 wutils.connect_to_wifi_network(self.dut_client, config, hidden=hidden) 293 294 """ Tests Begin """ 295 296 @test_tracker_info(uuid="495f1252-e440-461c-87a7-2c45f369e129") 297 def test_check_wifi_tethering_supported(self): 298 """Test check for wifi tethering support. 299 300 1. Call method to check if wifi hotspot is supported 301 """ 302 # TODO(silberst): wifiIsPortableHotspotSupported() is currently failing. 303 # Remove the extra check and logging when b/30800811 is resolved 304 asserts.skip_if(self.dut.model not in self.sim_supported_models, 305 "Device does not support SIM card, softAp not applicable.") 306 hotspot_supported = self.dut.droid.wifiIsPortableHotspotSupported() 307 tethering_supported = self.dut.droid.connectivityIsTetheringSupported() 308 self.log.info( 309 "IsPortableHotspotSupported: %s, IsTetheringSupported %s." % ( 310 hotspot_supported, tethering_supported)) 311 asserts.assert_true(hotspot_supported, 312 "DUT should support wifi tethering but is reporting false.") 313 asserts.assert_true(tethering_supported, 314 "DUT should also support wifi tethering when called from ConnectivityManager") 315 316 @test_tracker_info(uuid="09c19c35-c708-48a5-939b-ac2bbb403d54") 317 def test_full_tether_startup(self): 318 """Test full startup of wifi tethering in default band. 319 320 1. Report current state. 321 2. Switch to AP mode. 322 3. verify SoftAP active. 323 4. Shutdown wifi tethering. 324 5. verify back to previous mode. 325 """ 326 asserts.skip_if(self.dut.model not in self.sim_supported_models, 327 "Device does not support SIM card, softAp not applicable.") 328 self.validate_full_tether_startup() 329 330 @test_tracker_info(uuid="6437727d-7db1-4f69-963e-f26a7797e47f") 331 def test_full_tether_startup_2G(self): 332 """Test full startup of wifi tethering in 2G band. 333 334 1. Report current state. 335 2. Switch to AP mode. 336 3. verify SoftAP active. 337 4. Shutdown wifi tethering. 338 5. verify back to previous mode. 339 """ 340 asserts.skip_if(self.dut.model not in self.sim_supported_models, 341 "Device does not support SIM card, softAp not applicable.") 342 self.validate_full_tether_startup(WIFI_CONFIG_APBAND_2G) 343 344 @test_tracker_info(uuid="970272fa-1302-429b-b261-51efb4dad779") 345 def test_full_tether_startup_5G(self): 346 """Test full startup of wifi tethering in 5G band. 347 348 1. Report current state. 349 2. Switch to AP mode. 350 3. verify SoftAP active. 351 4. Shutdown wifi tethering. 352 5. verify back to previous mode. 353 """ 354 asserts.skip_if(self.dut.model not in self.sim_supported_models, 355 "Device does not support SIM card, softAp not applicable.") 356 self.validate_full_tether_startup(WIFI_CONFIG_APBAND_5G) 357 358 @test_tracker_info(uuid="f76ed37a-519a-48b4-b260-ee3fc5a9cae0") 359 def test_full_tether_startup_auto(self): 360 """Test full startup of wifi tethering in auto-band. 361 362 1. Report current state. 363 2. Switch to AP mode. 364 3. verify SoftAP active. 365 4. Shutdown wifi tethering. 366 5. verify back to previous mode. 367 """ 368 asserts.skip_if(self.dut.model not in self.sim_supported_models, 369 "Device does not support SIM card, softAp not applicable.") 370 self.validate_full_tether_startup(WIFI_CONFIG_APBAND_AUTO) 371 372 @test_tracker_info(uuid="d26ee4df-5dcb-4191-829f-05a10b1218a7") 373 def test_full_tether_startup_2G_hidden(self): 374 """Test full startup of wifi tethering in 2G band using hidden AP. 375 376 1. Report current state. 377 2. Switch to AP mode. 378 3. verify SoftAP active. 379 4. Shutdown wifi tethering. 380 5. verify back to previous mode. 381 """ 382 asserts.skip_if(self.dut.model not in self.sim_supported_models, 383 "Device does not support SIM card, softAp not applicable.") 384 self.validate_full_tether_startup(WIFI_CONFIG_APBAND_2G, True) 385 386 @test_tracker_info(uuid="229cd585-a789-4c9a-8948-89fa72de9dd5") 387 def test_full_tether_startup_5G_hidden(self): 388 """Test full startup of wifi tethering in 5G band using hidden AP. 389 390 1. Report current state. 391 2. Switch to AP mode. 392 3. verify SoftAP active. 393 4. Shutdown wifi tethering. 394 5. verify back to previous mode. 395 """ 396 asserts.skip_if(self.dut.model not in self.sim_supported_models, 397 "Device does not support SIM card, softAp not applicable.") 398 self.validate_full_tether_startup(WIFI_CONFIG_APBAND_5G, True) 399 400 @test_tracker_info(uuid="d546a143-6047-4ffd-b3c6-5ec81a38001f") 401 def test_full_tether_startup_auto_hidden(self): 402 """Test full startup of wifi tethering in auto-band using hidden AP. 403 404 1. Report current state. 405 2. Switch to AP mode. 406 3. verify SoftAP active. 407 4. Shutdown wifi tethering. 408 5. verify back to previous mode. 409 """ 410 asserts.skip_if(self.dut.model not in self.sim_supported_models, 411 "Device does not support SIM card, softAp not applicable.") 412 self.validate_full_tether_startup(WIFI_CONFIG_APBAND_AUTO, True) 413 414 @test_tracker_info(uuid="25996696-e9c8-4cd3-816a-44536166e69f") 415 def test_full_tether_startup_wpa3(self): 416 """Test full startup of softap in default band and wpa3 security. 417 418 Steps: 419 1. Configure softap in default band and wpa3 security. 420 2. Verify dut client connects to the softap. 421 """ 422 asserts.skip_if(self.dut.model not in self.sim_supported_models, 423 "Device does not support SIM card, softAp not applicable.") 424 asserts.skip_if(self.dut.model not in self.sap_wpa3_supported_models, 425 "DUT does not support WPA3 softAp") 426 self.validate_full_tether_startup(security=WPA3_SAE_SOFTAP) 427 428 @test_tracker_info(uuid="65ecdd4b-857e-4bda-87e7-3db578cee7aa") 429 def test_full_tether_startup_2G_wpa3(self): 430 """Test full startup of softap in 2G band and wpa3 security. 431 432 Steps: 433 1. Configure softap in 2G band and wpa3 security. 434 2. Verify dut client connects to the softap. 435 """ 436 asserts.skip_if(self.dut.model not in self.sim_supported_models, 437 "Device does not support SIM card, softAp not applicable.") 438 asserts.skip_if(self.dut.model not in self.sap_wpa3_supported_models, 439 "DUT does not support WPA3 softAp") 440 self.validate_full_tether_startup( 441 WIFI_CONFIG_APBAND_2G, security=WPA3_SAE_SOFTAP) 442 443 @test_tracker_info(uuid="dbc788dc-bf11-48aa-b88f-c2ee767cd13d") 444 def test_full_tether_startup_5G_wpa3(self): 445 """Test full startup of softap in 5G band and wpa3 security. 446 447 Steps: 448 1. Configure softap in 5G band and wpa3 security. 449 2. Verify dut client connects to the softap. 450 """ 451 asserts.skip_if(self.dut.model not in self.sim_supported_models, 452 "Device does not support SIM card, softAp not applicable.") 453 asserts.skip_if(self.dut.model not in self.sap_wpa3_supported_models, 454 "DUT does not support WPA3 softAp") 455 self.validate_full_tether_startup( 456 WIFI_CONFIG_APBAND_5G, security=WPA3_SAE_SOFTAP) 457 458 @test_tracker_info(uuid="1192c522-824a-4a79-a6cd-bd63b7d19e82") 459 def test_full_tether_startup_auto_wpa3(self): 460 """Test full startup of softap in auto band and wpa3 security. 461 462 Steps: 463 1. Configure softap in auto band and wpa3 security. 464 2. Verify dut client connects to the softap. 465 """ 466 asserts.skip_if(self.dut.model not in self.sim_supported_models, 467 "Device does not support SIM card, softAp not applicable.") 468 asserts.skip_if(self.dut.model not in self.sap_wpa3_supported_models, 469 "DUT does not support WPA3 softAp") 470 self.validate_full_tether_startup( 471 WIFI_CONFIG_APBAND_AUTO, security=WPA3_SAE_SOFTAP) 472 473 @test_tracker_info(uuid="120d2dcb-ded6-40d3-854c-366c200c8deb") 474 def test_full_tether_startup_hidden_wpa3(self): 475 """Test full startup of hidden softap in default band and wpa3 security. 476 477 Steps: 478 1. Configure hidden softap in default band and wpa3 security. 479 2. Verify dut client connects to the softap. 480 """ 481 asserts.skip_if(self.dut.model not in self.sim_supported_models, 482 "Device does not support SIM card, softAp not applicable.") 483 asserts.skip_if(self.dut.model not in self.sap_wpa3_supported_models, 484 "DUT does not support WPA3 softAp") 485 self.validate_full_tether_startup(security=WPA3_SAE_SOFTAP, hidden=True) 486 487 @test_tracker_info(uuid="82fc2329-480b-4cab-bf9d-e1c397673e4a") 488 def test_full_tether_startup_2G_hidden_wpa3(self): 489 """Test full startup of hidden softap in 2G band and wpa3 security. 490 491 Steps: 492 1. Configure hidden softap in 2G band and wpa3 security. 493 2. Verify dut client connects to the softap. 494 """ 495 asserts.skip_if(self.dut.model not in self.sim_supported_models, 496 "Device does not support SIM card, softAp not applicable.") 497 asserts.skip_if(self.dut.model not in self.sap_wpa3_supported_models, 498 "DUT does not support WPA3 softAp") 499 self.validate_full_tether_startup( 500 WIFI_CONFIG_APBAND_2G, True, security=WPA3_SAE_SOFTAP) 501 502 @test_tracker_info(uuid="0da2958e-de0b-4567-aff1-d4ba5439eb4e") 503 def test_full_tether_startup_5G_hidden_wpa3(self): 504 """Test full startup of hidden softap in 5G band and wpa3 security. 505 506 Steps: 507 1. Configure hidden softap in 5G band and wpa3 security. 508 2. Verify dut client connects to the softap. 509 """ 510 asserts.skip_if(self.dut.model not in self.sim_supported_models, 511 "Device does not support SIM card, softAp not applicable.") 512 asserts.skip_if(self.dut.model not in self.sap_wpa3_supported_models, 513 "DUT does not support WPA3 softAp") 514 self.validate_full_tether_startup( 515 WIFI_CONFIG_APBAND_5G, True, security=WPA3_SAE_SOFTAP) 516 517 @test_tracker_info(uuid="1412f928-e89b-4e84-8ad0-1b14e936b239") 518 def test_full_tether_startup_auto_hidden_wpa3(self): 519 """Test full startup of hidden softap in auto band and wpa3 security. 520 521 Steps: 522 1. Configure hidden softap in auto band and wpa3 security. 523 2. Verify dut client connects to the softap. 524 """ 525 asserts.skip_if(self.dut.model not in self.sim_supported_models, 526 "Device does not support SIM card, softAp not applicable.") 527 asserts.skip_if(self.dut.model not in self.sap_wpa3_supported_models, 528 "DUT does not support WPA3 softAp") 529 self.validate_full_tether_startup( 530 WIFI_CONFIG_APBAND_AUTO, True, security=WPA3_SAE_SOFTAP) 531 532 @test_tracker_info(uuid="e1433f7e-57f6-4475-822c-754d77817bbc") 533 def test_full_tether_startup_wpa2_wpa3(self): 534 """Test full startup of softap in default band and wpa2/wpa3 security. 535 536 Steps: 537 1. Configure softap in default band and wpa2/wpa3 security. 538 2. Verify dut client connects to the softap. 539 """ 540 asserts.skip_if(self.dut.model not in self.sim_supported_models, 541 "Device does not support SIM card, softAp not applicable.") 542 asserts.skip_if(self.dut.model not in self.sap_wpa3_supported_models, 543 "DUT does not support WPA2/WPA3 softAp") 544 self.validate_full_tether_startup(security=WPA3_SAE_TRANSITION_SOFTAP) 545 546 @test_tracker_info(uuid="8f55209f-0b9a-4600-a416-84d075c349af") 547 def test_full_tether_startup_2G_wpa2_wpa3(self): 548 """Test full startup of softap in 2G band and wpa2/wpa3 security. 549 550 Steps: 551 1. Configure softap in default band and wpa2/wpa3 security. 552 2. Verify dut client connects to the softap. 553 """ 554 asserts.skip_if(self.dut.model not in self.sim_supported_models, 555 "Device does not support SIM card, softAp not applicable.") 556 asserts.skip_if(self.dut.model not in self.sap_wpa3_supported_models, 557 "DUT does not support WPA2/WPA3 softAp") 558 self.validate_full_tether_startup( 559 WIFI_CONFIG_APBAND_2G, security=WPA3_SAE_TRANSITION_SOFTAP) 560 561 @test_tracker_info(uuid="3d54b7c5-cc34-473f-b484-fc3bf1773a90") 562 def test_full_tether_startup_5G_wpa2_wpa3(self): 563 """Test full startup of softap in 5G band and wpa2/wpa3 security. 564 565 Steps: 566 1. Configure softap in default band and wpa2/wpa3 security. 567 2. Verify dut client connects to the softap. 568 """ 569 asserts.skip_if(self.dut.model not in self.sim_supported_models, 570 "Device does not support SIM card, softAp not applicable.") 571 asserts.skip_if(self.dut.model not in self.sap_wpa3_supported_models, 572 "DUT does not support WPA2/WPA3 softAp") 573 self.validate_full_tether_startup( 574 WIFI_CONFIG_APBAND_5G, security=WPA3_SAE_TRANSITION_SOFTAP) 575 576 @test_tracker_info(uuid="f07bedd2-d768-497d-8922-2e5fe1cd9365") 577 def test_full_tether_startup_auto_wpa2_wpa3(self): 578 """Test full startup of softap in auto band and wpa2/wpa3 security. 579 580 Steps: 581 1. Configure softap in default band and wpa2/wpa3 security. 582 2. Verify dut client connects to the softap. 583 """ 584 asserts.skip_if(self.dut.model not in self.sim_supported_models, 585 "Device does not support SIM card, softAp not applicable.") 586 asserts.skip_if(self.dut.model not in self.sap_wpa3_supported_models, 587 "DUT does not support WPA2/WPA3 softAp") 588 self.validate_full_tether_startup( 589 WIFI_CONFIG_APBAND_AUTO, security=WPA3_SAE_TRANSITION_SOFTAP) 590 591 @test_tracker_info(uuid="9a54f97f-eaca-4a64-ad20-f9e52f8b16a1") 592 def test_full_tether_startup_2G_hidden_wpa2_wpa3(self): 593 """Test full startup of hidden softap in 2G band and wpa2/wpa3. 594 595 Steps: 596 1. Configure hidden softap in 2G band and wpa2/wpa3 security. 597 2. Verify dut client connects to the softap. 598 """ 599 asserts.skip_if(self.dut.model not in self.sim_supported_models, 600 "Device does not support SIM card, softAp not applicable.") 601 asserts.skip_if(self.dut.model not in self.sap_wpa3_supported_models, 602 "DUT does not support WPA2/WPA3 softAp") 603 self.validate_full_tether_startup( 604 WIFI_CONFIG_APBAND_2G, True, security=WPA3_SAE_TRANSITION_SOFTAP) 605 606 @test_tracker_info(uuid="1baef45f-c6c9-46bc-8227-1aacf410e60d") 607 def test_full_tether_startup_5G_hidden_wpa2_wpa3(self): 608 """Test full startup of hidden softap in 5G band and wpa2/wpa3 security. 609 610 Steps: 611 1. Configure hidden softap in 5G band and wpa2/wpa3 security. 612 2. Verify dut client connects to the softap. 613 """ 614 asserts.skip_if(self.dut.model not in self.sim_supported_models, 615 "Device does not support SIM card, softAp not applicable.") 616 asserts.skip_if(self.dut.model not in self.sap_wpa3_supported_models, 617 "DUT does not support WPA2/WPA3 softAp") 618 self.validate_full_tether_startup( 619 WIFI_CONFIG_APBAND_5G, True, security=WPA3_SAE_TRANSITION_SOFTAP) 620 621 @test_tracker_info(uuid="1976ac84-f967-4961-bdb9-4fcfe297fe22") 622 def test_full_tether_startup_auto_hidden_wpa2_wpa3(self): 623 """Test full startup of hidden softap in auto band and wpa2/wpa3. 624 625 Steps: 626 1. Configure hidden softap in auto band and wpa2/wpa3 security. 627 2. Verify dut client connects to the softap. 628 """ 629 asserts.skip_if(self.dut.model not in self.sim_supported_models, 630 "Device does not support SIM card, softAp not applicable.") 631 asserts.skip_if(self.dut.model not in self.sap_wpa3_supported_models, 632 "DUT does not support WPA3 softAp") 633 self.validate_full_tether_startup( 634 WIFI_CONFIG_APBAND_AUTO, True, security=WPA3_SAE_TRANSITION_SOFTAP) 635 636 @test_tracker_info(uuid="dd4c79dc-169f-4d8f-a700-95ba2923af35") 637 def test_softap_wpa3_2g_after_reboot(self): 638 """Test full startup of softap in 2G band, wpa3 security after reboot. 639 640 Steps: 641 1. Save softap in 2G band and wpa3 security. 642 2. Reboot device and start softap. 643 3. Verify dut client connects to the softap. 644 """ 645 asserts.skip_if(self.dut.model not in self.sim_supported_models, 646 "Device does not support SIM card, softAp not applicable.") 647 asserts.skip_if(self.dut.model not in self.sap_wpa3_supported_models, 648 "DUT does not support WPA3 softAp") 649 self.validate_softap_after_reboot( 650 WIFI_CONFIG_APBAND_2G, WPA3_SAE_SOFTAP, False) 651 652 @test_tracker_info(uuid="02f080d8-91e7-4363-a291-da3c87e74758") 653 def test_softap_wpa3_5g_after_reboot(self): 654 """Test full startup of softap in 5G band, wpa3 security after reboot. 655 656 Steps: 657 1. Save softap in 5G band and wpa3 security. 658 2. Reboot device and start softap. 659 3. Verify dut client connects to the softap. 660 """ 661 asserts.skip_if(self.dut.model not in self.sim_supported_models, 662 "Device does not support SIM card, softAp not applicable.") 663 asserts.skip_if(self.dut.model not in self.sap_wpa3_supported_models, 664 "DUT does not support WPA3 softAp") 665 self.validate_softap_after_reboot( 666 WIFI_CONFIG_APBAND_5G, WPA3_SAE_SOFTAP, False) 667 668 @test_tracker_info(uuid="2224f94e-88e8-4ebf-bbab-f78ab24cefda") 669 def test_softap_wpa2_wpa3_2g_after_reboot(self): 670 """Test softap in 2G band, wpa2/wpa3 security after reboot. 671 672 Steps: 673 1. Save softap in 2G band and wpa2/wpa3 security. 674 2. Reboot device and start softap. 675 3. Verify dut client connects to the softap. 676 """ 677 asserts.skip_if(self.dut.model not in self.sim_supported_models, 678 "Device does not support SIM card, softAp not applicable.") 679 asserts.skip_if(self.dut.model not in self.sap_wpa3_supported_models, 680 "DUT does not support WPA2/WPA3 softAp") 681 self.validate_softap_after_reboot( 682 WIFI_CONFIG_APBAND_2G, WPA3_SAE_TRANSITION_SOFTAP, False) 683 684 @test_tracker_info(uuid="320643e2-9e13-4c8c-a2cb-1903b6bd3741") 685 def test_softap_wpa2_wpa3_5g_after_reboot(self): 686 """Test softap in 5G band, wpa2/wpa3 security after reboot. 687 688 Steps: 689 1. Save softap in 5G band and wpa2/wpa3 security. 690 2. Reboot device and start softap. 691 3. Verify dut client connects to the softap. 692 """ 693 asserts.skip_if(self.dut.model not in self.sim_supported_models, 694 "Device does not support SIM card, softAp not applicable.") 695 asserts.skip_if(self.dut.model not in self.sap_wpa3_supported_models, 696 "DUT does not support WPA2/WPA3 softAp") 697 self.validate_softap_after_reboot( 698 WIFI_CONFIG_APBAND_5G, WPA3_SAE_TRANSITION_SOFTAP, False) 699 700 @test_tracker_info(uuid="52005efc-45a2-41df-acd1-5fd551e88a3c") 701 def test_softap_wpa3_2g_hidden_after_reboot(self): 702 """Test hidden softap in 2G band, wpa3 security after reboot. 703 704 Steps: 705 1. Save hidden softap in 2G band and wpa3 security. 706 2. Reboot device and start softap. 707 3. Verify dut client connects to the softap. 708 """ 709 asserts.skip_if(self.dut.model not in self.sim_supported_models, 710 "Device does not support SIM card, softAp not applicable.") 711 asserts.skip_if(self.dut.model not in self.sap_wpa3_supported_models, 712 "DUT does not support WPA3 softAp") 713 self.validate_softap_after_reboot( 714 WIFI_CONFIG_APBAND_2G, WPA3_SAE_SOFTAP, True) 715 716 @test_tracker_info(uuid="78e07c03-f628-482d-b78b-84bdfba0bfaf") 717 def test_softap_wpa3_5g_hidden_after_reboot(self): 718 """Test hidden softap in 5G band, wpa3 security after reboot. 719 720 Steps: 721 1. Save hidden softap in 5G band and wpa3 security. 722 2. Reboot device and start softap. 723 3. Verify dut client connects to the softap. 724 """ 725 asserts.skip_if(self.dut.model not in self.sim_supported_models, 726 "Device does not support SIM card, softAp not applicable.") 727 asserts.skip_if(self.dut.model not in self.sap_wpa3_supported_models, 728 "DUT does not support WPA3 softAp") 729 self.validate_softap_after_reboot( 730 WIFI_CONFIG_APBAND_5G, WPA3_SAE_SOFTAP, True) 731 732 @test_tracker_info(uuid="749ba522-dd1f-459a-81bd-957943201c32") 733 def test_softap_wpa2_wpa3_2g_hidden_after_reboot(self): 734 """Test hidden softap in 2G band, wpa2/wpa3 security after reboot. 735 736 Steps: 737 1. Save hidden softap in 2G band and wpa2/wpa3 security. 738 2. Reboot device and start softap. 739 3. Verify dut client connects to the softap. 740 """ 741 asserts.skip_if(self.dut.model not in self.sim_supported_models, 742 "Device does not support SIM card, softAp not applicable.") 743 asserts.skip_if(self.dut.model not in self.sap_wpa3_supported_models, 744 "DUT does not support WPA2/WPA3 softAp") 745 self.validate_softap_after_reboot( 746 WIFI_CONFIG_APBAND_2G, WPA3_SAE_TRANSITION_SOFTAP, True) 747 748 @test_tracker_info(uuid="638f1456-8556-448d-8cad-63e6b72337ca") 749 def test_softap_wpa2_wpa3_5g_hidden_after_reboot(self): 750 """Test hidden softap in 5G band, wpa2/wpa3 security after reboot. 751 752 Steps: 753 1. Save hidden softap in 5G band and wpa2/wpa3 security. 754 2. Reboot device and start softap. 755 3. Verify dut client connects to the softap. 756 """ 757 asserts.skip_if(self.dut.model not in self.sim_supported_models, 758 "Device does not support SIM card, softAp not applicable.") 759 asserts.skip_if(self.dut.model not in self.sap_wpa3_supported_models, 760 "DUT does not support WPA2/WPA3 softAp") 761 self.validate_softap_after_reboot( 762 WIFI_CONFIG_APBAND_5G, WPA3_SAE_TRANSITION_SOFTAP, True) 763 764 @test_tracker_info(uuid="b2f75330-bf33-4cdd-851a-de390f891ef7") 765 def test_tether_startup_while_connected_to_a_network(self): 766 """Test full startup of wifi tethering in auto-band while the device 767 is connected to a network. 768 769 1. Connect to an open network. 770 2. Turn on AP mode (in auto band). 771 3. Verify SoftAP active. 772 4. Make a client connect to the AP. 773 5. Shutdown wifi tethering. 774 6. Ensure that the client disconnected. 775 """ 776 asserts.skip_if(self.dut.model not in self.sim_supported_models, 777 "Device does not support SIM card, softAp not applicable.") 778 wutils.wifi_toggle_state(self.dut, True) 779 wutils.wifi_connect(self.dut, self.wifi_network) 780 config = self.create_softap_config() 781 wutils.start_wifi_tethering(self.dut, 782 config[wutils.WifiEnums.SSID_KEY], 783 config[wutils.WifiEnums.PWD_KEY], 784 WIFI_CONFIG_APBAND_AUTO) 785 asserts.assert_true(self.dut.droid.wifiIsApEnabled(), 786 "SoftAp is not reported as running") 787 # local hotspot may not have internet connectivity 788 self.confirm_softap_in_scan_results(config[wutils.WifiEnums.SSID_KEY]) 789 wutils.wifi_connect(self.dut_client, config, check_connectivity=False) 790 wutils.verify_11ax_softap(self.dut, self.dut_client, self.wifi6_models) 791 wutils.stop_wifi_tethering(self.dut) 792 wutils.wait_for_disconnect(self.dut_client) 793 794 @test_tracker_info(uuid="f2cf56ad-b8b9-43b6-ab15-a47b1d96b92e") 795 def test_full_tether_startup_2G_with_airplane_mode_on(self): 796 """Test full startup of wifi tethering in 2G band with 797 airplane mode on. 798 799 1. Turn on airplane mode. 800 2. Report current state. 801 3. Switch to AP mode. 802 4. verify SoftAP active. 803 5. Shutdown wifi tethering. 804 6. verify back to previous mode. 805 7. Turn off airplane mode. 806 """ 807 asserts.skip_if(self.dut.model not in self.sim_supported_models, 808 "Device does not support SIM card, softAp not applicable.") 809 self.dut.log.debug("Toggling Airplane mode ON.") 810 asserts.assert_true(utils.force_airplane_mode(self.dut, True), 811 "Can not turn on airplane mode: %s" % self.dut.serial) 812 wutils.wifi_toggle_state(self.dut, True) 813 self.validate_full_tether_startup(WIFI_CONFIG_APBAND_2G) 814 815 @test_tracker_info(uuid="883dd5b1-50c6-4958-a50f-bb4bea77ccaf") 816 def test_full_tether_startup_2G_one_client_ping_softap(self): 817 """(AP) 1 Device can connect to 2G hotspot 818 819 Steps: 820 1. Turn on DUT's 2G softap 821 2. Client connects to the softap 822 3. Client and DUT ping each other 823 """ 824 asserts.skip_if(self.dut.model not in self.sim_supported_models, 825 "Device does not support SIM card, softAp not applicable.") 826 self.validate_full_tether_startup(WIFI_CONFIG_APBAND_2G, test_ping=True) 827 828 @test_tracker_info(uuid="6604e848-99d6-422c-9fdc-2882642438b6") 829 def test_full_tether_startup_5G_one_client_ping_softap(self): 830 """(AP) 1 Device can connect to 5G hotspot 831 832 Steps: 833 1. Turn on DUT's 5G softap 834 2. Client connects to the softap 835 3. Client and DUT ping each other 836 """ 837 asserts.skip_if(self.dut.model not in self.sim_supported_models, 838 "Device does not support SIM card, softAp not applicable.") 839 self.validate_full_tether_startup(WIFI_CONFIG_APBAND_5G, test_ping=True) 840 841 @test_tracker_info(uuid="17725ecd-f900-4cf7-8b2d-d7515b0a595c") 842 def test_softap_2G_two_clients_ping_each_other(self): 843 """Test for 2G hotspot with 2 clients 844 845 1. Turn on 2G hotspot 846 2. Two clients connect to the hotspot 847 3. Two clients ping each other 848 """ 849 asserts.skip_if(self.dut.model not in self.sim_supported_models, 850 "Device does not support SIM card, softAp not applicable.") 851 asserts.skip_if(len(self.android_devices) < 3, 852 "No extra android devices. Skip test") 853 self.validate_full_tether_startup(WIFI_CONFIG_APBAND_2G, test_clients=True) 854 855 @test_tracker_info(uuid="98c09888-1021-4f79-9065-b3cf9b132146") 856 def test_softap_5G_two_clients_ping_each_other(self): 857 """Test for 5G hotspot with 2 clients 858 859 1. Turn on 5G hotspot 860 2. Two clients connect to the hotspot 861 3. Two clients ping each other 862 """ 863 asserts.skip_if(self.dut.model not in self.sim_supported_models, 864 "Device does not support SIM card, softAp not applicable.") 865 asserts.skip_if(len(self.android_devices) < 3, 866 "No extra android devices. Skip test") 867 self.validate_full_tether_startup(WIFI_CONFIG_APBAND_5G, test_clients=True) 868 869 @test_tracker_info(uuid="b991129e-030a-4998-9b08-0687270bec24") 870 def test_number_of_softap_clients(self): 871 """Test for number of softap clients to be updated correctly 872 873 1. Turn of hotspot 874 2. Register softap callback 875 3. Let client connect to the hotspot 876 4. Register second softap callback 877 5. Force client connect/disconnect to hotspot 878 6. Unregister second softap callback 879 7. Force second client connect to hotspot (if supported) 880 8. Turn off hotspot 881 9. Verify second softap callback doesn't respond after unregister 882 """ 883 asserts.skip_if(self.dut.model not in self.sim_supported_models, 884 "Device does not support SIM card, softAp not applicable.") 885 config = wutils.start_softap_and_verify(self, WIFI_CONFIG_APBAND_AUTO) 886 # Register callback after softap enabled to avoid unnecessary callback 887 # impact the test 888 callbackId = self.dut.droid.registerSoftApCallback() 889 # Verify clients will update immediately after register callback 890 wutils.wait_for_expected_number_of_softap_clients( 891 self.dut, callbackId, 0) 892 wutils.wait_for_expected_softap_state(self.dut, callbackId, 893 wifi_constants.WIFI_AP_ENABLED_STATE) 894 895 # Force DUTs connect to Network 896 wutils.wifi_connect(self.dut_client, config, 897 check_connectivity=False) 898 wutils.wait_for_expected_number_of_softap_clients( 899 self.dut, callbackId, 1) 900 901 # Register another callback to verify multi callback clients case 902 callbackId_2 = self.dut.droid.registerSoftApCallback() 903 # Verify clients will update immediately after register callback 904 wutils.wait_for_expected_number_of_softap_clients( 905 self.dut, callbackId_2, 1) 906 wutils.wait_for_expected_softap_state(self.dut, callbackId_2, 907 wifi_constants.WIFI_AP_ENABLED_STATE) 908 909 # Client Off/On Wifi to verify number of softap clients will be updated 910 wutils.toggle_wifi_and_wait_for_reconnection(self.dut_client, config) 911 912 wutils.wait_for_expected_number_of_softap_clients(self.dut, 913 callbackId, 0) 914 wutils.wait_for_expected_number_of_softap_clients(self.dut, 915 callbackId_2, 0) 916 wutils.wait_for_expected_number_of_softap_clients(self.dut, 917 callbackId, 1) 918 wutils.wait_for_expected_number_of_softap_clients(self.dut, 919 callbackId_2, 1) 920 921 # Unregister callbackId_2 to verify multi callback clients case 922 self.dut.droid.unregisterSoftApCallback(callbackId_2) 923 924 if len(self.android_devices) > 2: 925 wutils.wifi_connect(self.android_devices[2], config, 926 check_connectivity=False) 927 wutils.wait_for_expected_number_of_softap_clients( 928 self.dut, callbackId, 2) 929 930 # Turn off softap when clients connected 931 wutils.stop_wifi_tethering(self.dut) 932 wutils.wait_for_disconnect(self.dut_client) 933 if len(self.android_devices) > 2: 934 wutils.wait_for_disconnect(self.android_devices[2]) 935 936 # Verify client number change back to 0 after softap stop if client 937 # doesn't disconnect before softap stop 938 wutils.wait_for_expected_softap_state(self.dut, callbackId, 939 wifi_constants.WIFI_AP_DISABLING_STATE) 940 wutils.wait_for_expected_softap_state(self.dut, callbackId, 941 wifi_constants.WIFI_AP_DISABLED_STATE) 942 wutils.wait_for_expected_number_of_softap_clients( 943 self.dut, callbackId, 0) 944 # Unregister callback 945 self.dut.droid.unregisterSoftApCallback(callbackId) 946 947 # Check no any callbackId_2 event after unregister 948 asserts.assert_equal( 949 wutils.get_current_number_of_softap_clients( 950 self.dut, callbackId_2), None) 951 952 @test_tracker_info(uuid="35bc4ba1-bade-42ee-a563-0c73afb2402a") 953 def test_softap_auto_shut_off(self): 954 """Test for softap auto shut off 955 956 1. Turn off hotspot 957 2. Register softap callback 958 3. Let client connect to the hotspot 959 4. Start wait [wifi_constants.DEFAULT_SOFTAP_TIMEOUT_S] seconds 960 5. Check hotspot doesn't shut off 961 6. Let client disconnect to the hotspot 962 7. Start wait [wifi_constants.DEFAULT_SOFTAP_TIMEOUT_S] seconds 963 8. Check hotspot auto shut off 964 """ 965 asserts.skip_if(self.dut.model not in self.sim_supported_models, 966 "Device does not support SIM card, softAp not applicable.") 967 config = wutils.start_softap_and_verify(self, WIFI_CONFIG_APBAND_AUTO) 968 # Register callback after softap enabled to avoid unnecessary callback 969 # impact the test 970 callbackId = self.dut.droid.registerSoftApCallback() 971 # Verify clients will update immediately after register callback 972 wutils.wait_for_expected_number_of_softap_clients(self.dut, 973 callbackId, 0) 974 wutils.wait_for_expected_softap_state(self.dut, callbackId, 975 wifi_constants.WIFI_AP_ENABLED_STATE) 976 977 # Force DUTs connect to Network 978 wutils.wifi_connect(self.dut_client, config, check_connectivity=False) 979 wutils.wait_for_expected_number_of_softap_clients( 980 self.dut, callbackId, 1) 981 982 self.dut.log.info("Start waiting %s seconds with 1 clients ", 983 wifi_constants.DEFAULT_SOFTAP_TIMEOUT_S*1.1) 984 time.sleep(wifi_constants.DEFAULT_SOFTAP_TIMEOUT_S*1.1) 985 986 # When client connected, softap should keep as enabled 987 asserts.assert_true(self.dut.droid.wifiIsApEnabled(), 988 "SoftAp is not reported as running") 989 990 wutils.wifi_toggle_state(self.dut_client, False) 991 wutils.wait_for_expected_number_of_softap_clients(self.dut, 992 callbackId, 0) 993 self.dut.log.info("Start waiting %s seconds with 0 client", 994 wifi_constants.DEFAULT_SOFTAP_TIMEOUT_S*1.1) 995 time.sleep(wifi_constants.DEFAULT_SOFTAP_TIMEOUT_S*1.1) 996 # Softap should stop since no client connected 997 # doesn't disconnect before softap stop 998 wutils.wait_for_expected_softap_state(self.dut, callbackId, 999 wifi_constants.WIFI_AP_DISABLING_STATE) 1000 wutils.wait_for_expected_softap_state(self.dut, callbackId, 1001 wifi_constants.WIFI_AP_DISABLED_STATE) 1002 asserts.assert_false(self.dut.droid.wifiIsApEnabled(), 1003 "SoftAp is not reported as running") 1004 self.dut.droid.unregisterSoftApCallback(callbackId) 1005 1006 @test_tracker_info(uuid="3a10c7fd-cd8d-4d46-9d12-88a68640e060") 1007 def test_softap_auto_shut_off_with_customized_timeout(self): 1008 """Test for softap auto shut off 1009 1. Turn on hotspot 1010 2. Register softap callback 1011 3. Backup original shutdown timeout value 1012 4. Set up test_shutdown_timeout_value 1013 5. Let client connect to the hotspot 1014 6. Start wait test_shutdown_timeout_value * 1.1 seconds 1015 7. Check hotspot doesn't shut off 1016 8. Let client disconnect to the hotspot 1017 9. Start wait test_shutdown_timeout_value seconds 1018 10. Check hotspot auto shut off 1019 """ 1020 asserts.skip_if(self.dut.model not in self.sim_supported_models, 1021 "Device does not support SIM card, softAp not applicable.") 1022 # Backup config 1023 original_softap_config = self.dut.droid.wifiGetApConfiguration() 1024 # This config only included SSID and Password which used for connection 1025 # only. 1026 config = wutils.start_softap_and_verify(self, WIFI_CONFIG_APBAND_AUTO) 1027 1028 # Get current configuration to use for update configuration 1029 current_softap_config = self.dut.droid.wifiGetApConfiguration() 1030 # Register callback after softap enabled to avoid unnecessary callback 1031 # impact the test 1032 callbackId = self.dut.droid.registerSoftApCallback() 1033 # Verify clients will update immediately after register callback 1034 wutils.wait_for_expected_number_of_softap_clients(self.dut, 1035 callbackId, 0) 1036 wutils.wait_for_expected_softap_state(self.dut, callbackId, 1037 wifi_constants.WIFI_AP_ENABLED_STATE) 1038 1039 # Setup shutdown timeout value 1040 test_shutdown_timeout_value_s = 10 1041 wutils.save_wifi_soft_ap_config(self.dut, current_softap_config, 1042 shutdown_timeout_millis=test_shutdown_timeout_value_s * 1000) 1043 # Force DUTs connect to Network 1044 wutils.wifi_connect(self.dut_client, config, check_connectivity=False) 1045 wutils.wait_for_expected_number_of_softap_clients( 1046 self.dut, callbackId, 1) 1047 1048 self.dut.log.info("Start waiting %s seconds with 1 clients ", 1049 test_shutdown_timeout_value_s * 1.1) 1050 time.sleep(test_shutdown_timeout_value_s * 1.1) 1051 1052 # When client connected, softap should keep as enabled 1053 asserts.assert_true(self.dut.droid.wifiIsApEnabled(), 1054 "SoftAp is not reported as running") 1055 1056 wutils.wifi_toggle_state(self.dut_client, False) 1057 wutils.wait_for_expected_number_of_softap_clients(self.dut, 1058 callbackId, 0) 1059 self.dut.log.info("Start waiting %s seconds with 0 client", 1060 test_shutdown_timeout_value_s * 1.1) 1061 time.sleep(test_shutdown_timeout_value_s * 1.1) 1062 # Softap should stop since no client connected 1063 # doesn't disconnect before softap stop 1064 wutils.wait_for_expected_softap_state(self.dut, callbackId, 1065 wifi_constants.WIFI_AP_DISABLING_STATE) 1066 wutils.wait_for_expected_softap_state(self.dut, callbackId, 1067 wifi_constants.WIFI_AP_DISABLED_STATE) 1068 asserts.assert_false(self.dut.droid.wifiIsApEnabled(), 1069 "SoftAp is not reported as running") 1070 self.dut.droid.unregisterSoftApCallback(callbackId) 1071 1072 # Restore config 1073 wutils.save_wifi_soft_ap_config(self.dut, original_softap_config) 1074 1075 @test_tracker_info(uuid="a9444699-f0d3-4ac3-922b-05e9d4f67968") 1076 def test_softap_configuration_update(self): 1077 """Test for softap configuration update 1078 1. Get current softap configuration 1079 2. Update to Open Security configuration 1080 3. Update to WPA2_PSK configuration 1081 4. Update to Multi-Channels, Mac Randomization off, 1082 bridged_shutdown off, 11ax off configuration which are introduced in S. 1083 5. Restore the configuration 1084 """ 1085 asserts.skip_if(self.dut.model not in self.sim_supported_models, 1086 "Device does not support SIM card, softAp not applicable.") 1087 # Backup config 1088 original_softap_config = self.dut.droid.wifiGetApConfiguration() 1089 wutils.save_wifi_soft_ap_config(self.dut, {"SSID":"ACTS_TEST"}, 1090 band=WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G, hidden=False, 1091 security=WifiEnums.SoftApSecurityType.OPEN, password="", 1092 channel=11, max_clients=0, shutdown_timeout_enable=False, 1093 shutdown_timeout_millis=0, client_control_enable=True, 1094 allowedList=[], blockedList=[]) 1095 1096 wutils.save_wifi_soft_ap_config(self.dut, {"SSID":"ACTS_TEST"}, 1097 band=WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G_5G, hidden=True, 1098 security=WifiEnums.SoftApSecurityType.WPA2, password="12345678", 1099 channel=0, max_clients=1, shutdown_timeout_enable=True, 1100 shutdown_timeout_millis=10000, client_control_enable=False, 1101 allowedList=["aa:bb:cc:dd:ee:ff"], blockedList=["11:22:33:44:55:66"]) 1102 1103 if self.dut.droid.isSdkAtLeastS(): 1104 wutils.save_wifi_soft_ap_config(self.dut, {"SSID":"ACTS_TEST"}, 1105 channel_frequencys=[2412,5745], 1106 mac_randomization_setting = wifi_constants.SOFTAP_RANDOMIZATION_NONE, 1107 bridged_opportunistic_shutdown_enabled=False, 1108 ieee80211ax_enabled=False) 1109 1110 # Restore config 1111 wutils.save_wifi_soft_ap_config(self.dut, original_softap_config) 1112 1113 @test_tracker_info(uuid="8a5d81fa-649c-4679-a823-5cef50828a94") 1114 def test_softap_client_control(self): 1115 """Test Client Control feature 1116 1. Check SoftApCapability to make sure feature is supported 1117 2. Backup config 1118 3. Setup configuration which used to start softap 1119 4. Register callback after softap enabled 1120 5. Trigger client connect to softap 1121 6. Verify blocking event 1122 7. Add client into allowed list 1123 8. Verify client connected 1124 9. Restore Config 1125 """ 1126 asserts.skip_if(self.dut.model not in self.sim_supported_models, 1127 "Device does not support SIM card, softAp not applicable.") 1128 # Register callback to check capability first 1129 callbackId = self.dut.droid.registerSoftApCallback() 1130 # Check capability first to make sure DUT support this test. 1131 capabilityEventStr = wifi_constants.SOFTAP_CALLBACK_EVENT + str( 1132 callbackId) + wifi_constants.SOFTAP_CAPABILITY_CHANGED 1133 capability = self.dut.ed.pop_event(capabilityEventStr, 10) 1134 asserts.skip_if(not capability['data'][wifi_constants 1135 .SOFTAP_CAPABILITY_FEATURE_CLIENT_CONTROL], 1136 "Client control isn't supported, ignore test") 1137 1138 # Unregister callback before start test to avoid 1139 # unnecessary callback impact the test 1140 self.dut.droid.unregisterSoftApCallback(callbackId) 1141 1142 # start the test 1143 1144 # Backup config 1145 original_softap_config = self.dut.droid.wifiGetApConfiguration() 1146 # Setup configuration which used to start softap 1147 wutils.save_wifi_soft_ap_config(self.dut, {"SSID":"ACTS_TEST"}, 1148 band=WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G_5G, hidden=False, 1149 security=WifiEnums.SoftApSecurityType.WPA2, password="12345678", 1150 client_control_enable=True) 1151 1152 wutils.start_wifi_tethering_saved_config(self.dut) 1153 current_softap_config = self.dut.droid.wifiGetApConfiguration() 1154 # Register callback after softap enabled to avoid unnecessary callback 1155 # impact the test 1156 callbackId = self.dut.droid.registerSoftApCallback() 1157 1158 # Verify clients will update immediately after register callback 1159 wutils.wait_for_expected_number_of_softap_clients(self.dut, 1160 callbackId, 0) 1161 wutils.wait_for_expected_softap_state(self.dut, callbackId, 1162 wifi_constants.WIFI_AP_ENABLED_STATE) 1163 1164 # Trigger client connection 1165 self.dut_client.droid.wifiConnectByConfig(current_softap_config) 1166 1167 eventStr = wifi_constants.SOFTAP_CALLBACK_EVENT + str( 1168 callbackId) + wifi_constants.SOFTAP_BLOCKING_CLIENT_CONNECTING 1169 blockedClient = self.dut.ed.pop_event(eventStr, 10) 1170 asserts.assert_equal(blockedClient['data'][wifi_constants. 1171 SOFTAP_BLOCKING_CLIENT_REASON_KEY], 1172 wifi_constants.SAP_CLIENT_BLOCK_REASON_CODE_BLOCKED_BY_USER, 1173 "Blocked reason code doesn't match") 1174 1175 # Update configuration, add client into allowed list 1176 wutils.save_wifi_soft_ap_config(self.dut, current_softap_config, 1177 allowedList=[blockedClient['data'][wifi_constants. 1178 SOFTAP_BLOCKING_CLIENT_WIFICLIENT_KEY]]) 1179 1180 # Wait configuration updated 1181 time.sleep(3) 1182 # Trigger connection again 1183 self.dut_client.droid.wifiConnectByConfig(current_softap_config) 1184 1185 # Verify client connected 1186 wutils.wait_for_expected_number_of_softap_clients(self.dut, 1187 callbackId, 1) 1188 1189 # Restore config 1190 wutils.save_wifi_soft_ap_config(self.dut, original_softap_config) 1191 1192 # Unregister callback 1193 self.dut.droid.unregisterSoftApCallback(callbackId) 1194 1195 @test_tracker_info(uuid="d0b61b58-fa2b-4ced-bc52-3366cb826e79") 1196 def test_softap_max_client_setting(self): 1197 """Test Client Control feature 1198 1. Check device number and capability to make sure feature is supported 1199 2. Backup config 1200 3. Setup configuration which used to start softap 1201 4. Register callback after softap enabled 1202 5. Trigger client connect to softap 1203 6. Verify blocking event 1204 7. Extend max client setting 1205 8. Verify client connected 1206 9. Restore Config 1207 """ 1208 asserts.skip_if(self.dut.model not in self.sim_supported_models, 1209 "Device does not support SIM card, softAp not applicable.") 1210 asserts.skip_if(len(self.android_devices) < 3, 1211 "Device less than 3, skip the test.") 1212 # Register callback to check capability first 1213 callbackId = self.dut.droid.registerSoftApCallback() 1214 # Check capability first to make sure DUT support this test. 1215 capabilityEventStr = wifi_constants.SOFTAP_CALLBACK_EVENT + str( 1216 callbackId) + wifi_constants.SOFTAP_CAPABILITY_CHANGED 1217 capability = self.dut.ed.pop_event(capabilityEventStr, 10) 1218 asserts.skip_if(not capability['data'][wifi_constants 1219 .SOFTAP_CAPABILITY_FEATURE_CLIENT_CONTROL], 1220 "Client control isn't supported, ignore test") 1221 1222 # Unregister callback before start test to avoid 1223 # unnecessary callback impact the test 1224 self.dut.droid.unregisterSoftApCallback(callbackId) 1225 1226 # Backup config 1227 original_softap_config = self.dut.droid.wifiGetApConfiguration() 1228 # Setup configuration which used to start softap 1229 wutils.save_wifi_soft_ap_config(self.dut, {"SSID":"ACTS_TEST"}, 1230 band=WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G_5G, hidden=False, 1231 security=WifiEnums.SoftApSecurityType.WPA2, password="12345678", 1232 max_clients=1) 1233 1234 wutils.start_wifi_tethering_saved_config(self.dut) 1235 current_softap_config = self.dut.droid.wifiGetApConfiguration() 1236 # Register callback again after softap enabled to avoid 1237 # unnecessary callback impact the test 1238 callbackId = self.dut.droid.registerSoftApCallback() 1239 1240 # Verify clients will update immediately after register calliback 1241 wutils.wait_for_expected_number_of_softap_clients(self.dut, 1242 callbackId, 0) 1243 wutils.wait_for_expected_softap_state(self.dut, callbackId, 1244 wifi_constants.WIFI_AP_ENABLED_STATE) 1245 1246 # Trigger client connection 1247 self.dut_client.droid.wifiConnectByConfig(current_softap_config) 1248 self.dut_client_2.droid.wifiConnectByConfig(current_softap_config) 1249 # Wait client connect 1250 time.sleep(3) 1251 1252 # Verify one client connected and one blocked due to max client 1253 eventStr = wifi_constants.SOFTAP_CALLBACK_EVENT + str( 1254 callbackId) + wifi_constants.SOFTAP_BLOCKING_CLIENT_CONNECTING 1255 blockedClient = self.dut.ed.pop_event(eventStr, 10) 1256 asserts.assert_equal(blockedClient['data'][wifi_constants. 1257 SOFTAP_BLOCKING_CLIENT_REASON_KEY], 1258 wifi_constants.SAP_CLIENT_BLOCK_REASON_CODE_NO_MORE_STAS, 1259 "Blocked reason code doesn't match") 1260 wutils.wait_for_expected_number_of_softap_clients(self.dut, 1261 callbackId, 1) 1262 1263 # Update configuration, extend client to 2 1264 wutils.save_wifi_soft_ap_config(self.dut, current_softap_config, 1265 max_clients=2) 1266 1267 # Wait configuration updated 1268 time.sleep(3) 1269 # Trigger connection again 1270 self.dut_client_2.droid.wifiConnectByConfig(current_softap_config) 1271 # Wait client connect 1272 time.sleep(3) 1273 # Verify client connected 1274 wutils.wait_for_expected_number_of_softap_clients(self.dut, 1275 callbackId, 2) 1276 1277 # Restore config 1278 wutils.save_wifi_soft_ap_config(self.dut, original_softap_config) 1279 1280 # Unregister callback 1281 self.dut.droid.unregisterSoftApCallback(callbackId) 1282 1283 @test_tracker_info(uuid="07b4e5b3-48ce-49b9-a83e-3e288bb88e91") 1284 def test_softap_5g_preferred_country_code_de(self): 1285 """Verify softap works when set to 5G preferred band 1286 with country code 'DE'. 1287 1288 Steps: 1289 1. Set country code to Germany 1290 2. Save a softap configuration set to 5G preferred band. 1291 3. Start softap and verify it works 1292 4. Verify a client device can connect to it. 1293 """ 1294 asserts.skip_if(self.dut.model not in self.sim_supported_models, 1295 "Device does not support SIM card, softAp not applicable.") 1296 wutils.set_wifi_country_code( 1297 self.dut, wutils.WifiEnums.CountryCode.GERMANY) 1298 sap_config = self.create_softap_config() 1299 wifi_network = sap_config.copy() 1300 sap_config[ 1301 WifiEnums.AP_BAND_KEY] = WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G_5G 1302 sap_config[WifiEnums.SECURITY] = WifiEnums.SoftApSecurityType.WPA2 1303 asserts.assert_true( 1304 self.dut.droid.wifiSetWifiApConfiguration(sap_config), 1305 "Failed to set WifiAp Configuration") 1306 wutils.start_wifi_tethering_saved_config(self.dut) 1307 softap_conf = self.dut.droid.wifiGetApConfiguration() 1308 self.log.info("softap conf: %s" % softap_conf) 1309 sap_band = softap_conf[WifiEnums.AP_BAND_KEY] 1310 asserts.assert_true( 1311 sap_band == WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G_5G, 1312 "Soft AP didn't start in 5G preferred band") 1313 wutils.connect_to_wifi_network(self.dut_client, wifi_network) 1314 wutils.verify_11ax_softap(self.dut, self.dut_client, self.wifi6_models) 1315 1316 @test_tracker_info(uuid="dbcd653c-ec65-400f-a6ce-77bb13add473") 1317 def test_softp_2g_channel_when_connected_to_chan_13(self): 1318 """Verify softAp 2G channel when connected to network on channel 13. 1319 1320 Steps: 1321 1. Configure AP in channel 13 on 2G band and connect DUT to it. 1322 2. Start softAp on DUT on 2G band. 1323 3. Verify softAp is started on channel 13. 1324 """ 1325 asserts.skip_if(self.dut.model not in self.sim_supported_models, 1326 "Device does not support SIM card, softAp not applicable.") 1327 asserts.skip_if("OpenWrtAP" not in self.user_params, 1328 "Need openwrt AP to configure channel 13.") 1329 wutils.connect_to_wifi_network(self.dut, self.wifi_network) 1330 sap_config = self.create_softap_config() 1331 sap_config[WifiEnums.AP_BAND_KEY] = WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G 1332 asserts.assert_true( 1333 self.dut.droid.wifiSetWifiApConfiguration(sap_config), 1334 "Failed to set WifiAp Configuration") 1335 wutils.start_wifi_tethering_saved_config(self.dut) 1336 softap_conf = self.dut.droid.wifiGetApConfiguration() 1337 self.log.info("softap conf: %s" % softap_conf) 1338 wutils.connect_to_wifi_network(self.dut_client, sap_config) 1339 softap_channel = self.dut_client.droid.wifiGetConnectionInfo( 1340 ) 1341 conn_info = self.dut_client.droid.wifiGetConnectionInfo() 1342 self.log.info("Wifi connection info on dut_client: %s" % conn_info) 1343 softap_channel = wutils.WifiEnums.freq_to_channel[conn_info["frequency"]] 1344 asserts.assert_true(softap_channel == 13, 1345 "Dut client did not connect to softAp on channel 13") 1346 1347 def test_softap_2G_two_clients_ping_each_other_with_lte_coex(self): 1348 """Test for 2G hotspot with 2 clients when lte coex applied 1349 1350 1. Set country code as TW and set lte coex channels 1351 2. Turn on 2G hotspot 1352 3. Two clients connect to the hotspot 1353 4. Two clients ping each other 1354 """ 1355 1356 asserts.skip_if(self.dut.model not in self.sim_supported_models, 1357 "Device does not support SIM card, softAp not applicable.") 1358 asserts.skip_if(len(self.android_devices) < 3, 1359 "No extra android devices. Skip test") 1360 1361 wutils.set_wifi_country_code(self.dut, "TW") 1362 self.dut.adb.shell("cmd wifi set-coex-cell-channels " 1363 "lte 7 2650000 20000 2530000 20000 " 1364 "lte 3 1860000 10000 -1 0 " 1365 "lte 8 955000 10000 -1 0 " 1366 "lte 7 2685000 10000 -1 0") 1367 self.validate_full_tether_startup(WIFI_CONFIG_APBAND_2G, test_clients=True) 1368 1369 """ Tests End """ 1370 1371 1372if __name__ == "__main__": 1373 pass 1374