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