• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2#
3#   Copyright 2021 - 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
17
18import logging
19import time
20from acts import asserts
21from acts import signals
22from acts.test_decorators import test_tracker_info
23import acts_contrib.test_utils.wifi.wifi_test_utils as wutils
24from acts_contrib.test_utils.wifi import wifi_constants
25from acts_contrib.test_utils.wifi.WifiBaseTest import WifiBaseTest
26from acts.controllers.ap_lib.hostapd_constants import BAND_2G
27from acts.controllers.ap_lib.hostapd_constants import BAND_5G
28from acts.controllers.ap_lib import hostapd_constants
29
30
31WifiEnums = wutils.WifiEnums
32# Each wait time add 5 seconds as buffer.
33BRIDGED_AP_LAUNCH_INTERVAL_5_SECONDS = 5
34BRIDGED_AP_SHUTDOWN_INTERVAL_5_MINUTES = 305
35BRIDGED_AP_SHUTDOWN_INTERVAL_5_SECONDS = 5
36SOFT_AP_SHUTDOWN_INTERVAL_10_MINUTES = 605
37INTERVAL_9_MINUTES = 545
38INTERVAL_2_MINUTES = 125
39INTERVAL_1_MINUTES = 65
40
41
42class WifiBridgedApTest(WifiBaseTest):
43    """WiFi BridgedAp test class.
44
45    Test Bed Requirement:
46        * Android device x 1 with BridgedAp supported.
47        * Android devices x2 as clients, at least Android 10.
48        * OpenWrt AP x 1.
49        * Google Wi-Fi x 2 as packet captures.
50    """
51
52    def setup_class(self):
53        super().setup_class()
54
55        if len(self.android_devices) == 3:
56            self.dut = self.android_devices[0]
57            self.client1 = self.android_devices[1]
58            self.client2 = self.android_devices[2]
59        else:
60            raise signals.TestAbortClass("WifiBridgedApTest requires 3 DUTs")
61
62        if not self.dut.droid.wifiIsBridgedApConcurrencySupported():
63            raise signals.TestAbortClass("Legacy phone is not supported")
64
65        req_params = ["dbs_supported_models"]
66        opt_param = []
67
68        self.unpack_userparams(
69            req_param_names=req_params, opt_param_names=opt_param)
70
71    def setup_test(self):
72        super().setup_test()
73        for ad in self.android_devices:
74            wutils.reset_wifi(ad)
75        wutils.wifi_toggle_state(self.dut, False)
76        wutils.wifi_toggle_state(self.client1, True)
77        wutils.wifi_toggle_state(self.client2, True)
78
79    def teardown_test(self):
80        super().teardown_test()
81        # Reset unplugged status
82        self.dut.adb.shell("cmd battery reset")
83        if self.dut.droid.wifiIsApEnabled():
84            wutils.stop_wifi_tethering(self.dut)
85        for ad in self.android_devices:
86            wutils.reset_wifi(ad)
87            wutils.set_wifi_country_code(
88                ad, wutils.WifiEnums.CountryCode.US)
89
90        # Stop packet captures.
91        if hasattr(self, "sniffer_procs"):
92            for i in range(len(self.sniffer_procs)):
93                try:
94                    wutils.stop_pcap(
95                        self.packet_capture[i], self.sniffer_procs[i], False)
96                    logging.info("packet_capture[{}] is STOPPED".format(i))
97                except:
98                    logging.info("packet_capture[{}] is NOT STOPPED".format(i))
99
100    def teardown_class(self):
101        super().teardown_class()
102        for ad in self.android_devices:
103            wutils.reset_wifi(ad)
104        if "AccessPoint" in self.user_params:
105            del self.user_params["reference_networks"]
106            del self.user_params["open_network"]
107
108    def set_country_code_and_verify(self, ad, country_code):
109        wutils.set_wifi_country_code(ad, country_code)
110        # Wi-Fi ON and OFF to make sure country code take effect.
111        wutils.wifi_toggle_state(ad, True)
112        wutils.wifi_toggle_state(ad, False)
113
114        country = ad.droid.wifiGetCountryCode()
115        asserts.assert_true(country == country_code,
116                            "country code {} is not set".format(country_code))
117        ad.log.info("Country code set to : {}".format(country))
118
119    def verify_clients_support_wpa3_sae(self, *args):
120        """Check if clients support WPA3 SAE.
121
122        Args:
123            args: arbitrary number of clients. e.g., self.dut1, self.dut2, ...
124        """
125        duts = args
126        for dut in duts:
127            asserts.skip_if(not dut.droid.wifiIsWpa3SaeSupported(),
128                            "All DUTs support WPA3 SAE is required")
129
130    def verify_band_of_bridged_ap_instance(self, ad, infos, bands):
131        """Check bands enabled as expected.
132           This function won't be called directly.
133
134        Args:
135            infos: SoftAp info list.
136            bands: A list of bands.
137                   e,g,. [WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G,
138                          WifiEnums.WIFI_CONFIG_SOFTAP_BAND_5G]
139        """
140        self.dut.log.info("Length of infos: {}, Length of bands: {}"
141                          .format(len(infos), len(bands)))
142        asserts.assert_true(len(infos) == len(bands),
143                            "There should be {} BridgedAp instance, "
144                            "instead of {}".format(len(bands), len(infos)))
145        if len(bands) == 1 and (bands[0] == WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G):
146            asserts.assert_true(infos[0][wifi_constants.
147                                SOFTAP_INFO_FREQUENCY_CALLBACK_KEY]
148                                in WifiEnums.softap_band_frequencies[bands[0]],
149                                "This should be a {} instance".format(bands[0]))
150        if len(bands) == 2 and (bands[0] == WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G):
151            asserts.assert_true((infos[0][wifi_constants.
152                                SOFTAP_INFO_FREQUENCY_CALLBACK_KEY]
153                                in WifiEnums.ALL_2G_FREQUENCIES and
154                                infos[1][wifi_constants.
155                                SOFTAP_INFO_FREQUENCY_CALLBACK_KEY]
156                                in WifiEnums.ALL_5G_FREQUENCIES) or
157                                (infos[0][wifi_constants.
158                                 SOFTAP_INFO_FREQUENCY_CALLBACK_KEY]
159                                 in WifiEnums.ALL_5G_FREQUENCIES and
160                                 infos[1][wifi_constants.
161                                 SOFTAP_INFO_FREQUENCY_CALLBACK_KEY]
162                                 in WifiEnums.ALL_2G_FREQUENCIES),
163                                "There should only be 2G and 5G instances")
164
165    def verify_softap_freq_equals_to_ap_freq(self, ad, infos):
166        """Verify if instance frequency equal to AP frequency.
167           This function won't be called directly.
168        Args:
169            infos: SoftAp info list.
170        """
171        wlan0_freq = wutils.get_wlan0_link(ad)["freq"]
172        softap_freqs = []
173        for i in range(len(infos)):
174            softap_freqs.append(infos[i][WifiEnums.frequency_key])
175        ad.log.info("softap_freqs : {}".format(softap_freqs))
176        asserts.assert_true(int(wlan0_freq) in softap_freqs,
177                            "AP freq != SoftAp freq")
178        ad.log.info("softap freq == AP freq")
179
180    def verify_number_band_freq_of_bridged_ap(self, ad, bands,
181                                              freq_equal=False):
182        """Verify every aspect of info list from BridgedAp.
183
184        Args:
185            bands: A list of bands,
186                   e,g,. [WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G,
187                          WifiEnums.WIFI_CONFIG_SOFTAP_BAND_5G]
188            freq_equal: True if need to check SoftAp freq equals to STA freq.
189
190        Returns:
191            infos: A List of SoftAp info, e.g.,
192                [{'autoShutdownTimeoutMillis': 600000,
193                  'bandwidth': 4,
194                  'bssid': '12:dd:0b:b9:4b:cc',
195                  'frequency': 5180,
196                  'wifiStandard': 6},
197                 {'autoShutdownTimeoutMillis': 600000,
198                  'bandwidth': 2,
199                  'bssid': '12:22:f4:b9:4b:cc',
200                  'frequency': 2462,
201                  'wifiStandard': 4}]
202        """
203        callbackId = ad.droid.registerSoftApCallback()
204        infos = wutils.get_current_softap_infos(ad, callbackId, True)
205        self.verify_band_of_bridged_ap_instance(ad, infos, bands)
206        if freq_equal:
207            self.verify_softap_freq_equals_to_ap_freq(ad, infos)
208        ad.droid.unregisterSoftApCallback(callbackId)
209        return infos
210
211    def verify_expected_number_of_softap_clients(self, ad, number):
212        """Verify the number of softap clients.
213
214        Args:
215            number: expect number of client connect to SoftAp.
216        """
217        callbackId = self.dut.droid.registerSoftApCallback()
218        wutils.wait_for_expected_number_of_softap_clients(self.dut,
219                                                          callbackId, number)
220        ad.log.info("{} clients connect to soft ap".format(number))
221        self.dut.droid.unregisterSoftApCallback(callbackId)
222
223    def wait_interval(self, interval):
224        """print different messages with different intervals.
225
226        Args:
227            interval: different interval for different situation.
228        """
229        if interval == BRIDGED_AP_LAUNCH_INTERVAL_5_SECONDS:
230            logging.info("Wait {} seconds for BridgedAp launch"
231                         .format(interval))
232            time.sleep(interval)
233        elif interval == BRIDGED_AP_SHUTDOWN_INTERVAL_5_MINUTES:
234            logging.info("Wait {} minutes for BridgedAp shutdown"
235                         .format(interval/60))
236            time.sleep(interval)
237        elif interval == SOFT_AP_SHUTDOWN_INTERVAL_10_MINUTES:
238            logging.info("Wait {} minutes for SoftAp shutdown"
239                         .format(interval/60))
240            time.sleep(interval)
241        elif interval == INTERVAL_9_MINUTES:
242            logging.info("Wait {} minutes".format(interval/60))
243            time.sleep(interval)
244        elif interval == INTERVAL_2_MINUTES:
245            logging.info("Wait {} minutes".format(interval/60))
246            time.sleep(interval)
247        elif interval == INTERVAL_1_MINUTES:
248            logging.info("Wait {} minutes".format(interval/60))
249            time.sleep(interval)
250
251    def generate_softap_config(self, security):
252        """Return a soft ap config
253
254        Args:
255            security: String; represent certain security. e.g., "WPA3_SAE"
256        """
257        config = wutils.create_softap_config()
258        config[WifiEnums.SECURITY] = security
259        return config
260
261    def enable_bridged_ap(self, ad, security, bands, **kwargs):
262        """Enable BridgedAp.
263
264        Args:
265            security: String; represent certain security. e.g., "WPA3_SAE"
266            bands: specifies the band list for the soft ap.
267        """
268        self.config = self.generate_softap_config(security)
269        wutils.save_wifi_soft_ap_config(
270                                        ad,
271                                        self.config,
272                                        bands=bands,
273                                        **kwargs)
274        wutils.start_wifi_tethering_saved_config(self.dut)
275        # Wait 5 seconds for BridgedAp launch.
276        self.wait_interval(BRIDGED_AP_LAUNCH_INTERVAL_5_SECONDS)
277
278    def sniffing_bridgedap_channels(self, infos):
279        """Sniff BridgedAp channels.
280
281        Args:
282            infos: A List of SoftAp info. e.g.,
283                [{'autoShutdownTimeoutMillis': 600000,
284                  'bandwidth': 4,
285                  'bssid': '12:dd:0b:b9:4b:cc',
286                  'frequency': 5180,
287                  'wifiStandard': 6},
288                 {'autoShutdownTimeoutMillis': 600000,
289                  'bandwidth': 2,
290                  'bssid': '12:22:f4:b9:4b:cc',
291                  'frequency': 2462,
292                  'wifiStandard': 4}]
293        """
294        if hasattr(self, "packet_capture") and len(self.packet_capture) == 2:
295            # Create sniffer_config.
296            self.sniffer_config = {}
297            for i in range(len(infos)):
298                if (infos[i][WifiEnums.frequency_key] in
299                   WifiEnums.ALL_5G_FREQUENCIES):
300                    self.sniffer_config[BAND_5G] = WifiEnums.freq_to_channel[
301                        int(infos[i][WifiEnums.frequency_key])]
302                if (infos[i][WifiEnums.frequency_key] in
303                   WifiEnums.ALL_2G_FREQUENCIES):
304                    self.sniffer_config[BAND_2G] = WifiEnums.freq_to_channel[
305                        int(infos[i][WifiEnums.frequency_key])]
306            logging.info("sniffer_config : {}".format(self.sniffer_config))
307
308            # Enable sniffers.
309            self.sniffer_procs = []
310            for i in range(len(self.sniffer_config)):
311                self.packet_capture[i].log.info(
312                    "Enable packet_capture[{}]".format(i))
313                result = self.packet_capture[i].configure_monitor_mode(
314                    list(self.sniffer_config.keys())[i],
315                    list(self.sniffer_config.values())[i])
316                if not result:
317                    logging.error("Failed to enable packet_capture"
318                                  "on {}".format(self.packet_capture[i]))
319                self.pcap_procs = wutils.start_pcap(
320                    self.packet_capture[i],
321                    list(self.sniffer_config.keys())[i],
322                    self.test_name)
323                self.sniffer_procs.append(self.pcap_procs)
324            logging.info("sniffer_procs: {}".format(self.sniffer_procs))
325        else:
326            logging.warning("Packet_capture not enabled, "
327                            "because two packet_capture hardware required")
328
329    def sniffing_ap_channels(self, channel1, channel2):
330        """Sniff on two Wi-Fi channels.
331
332        Args:
333            channel1: Integer; a Wi-Fi channel, e.g., 6.
334            channel2: Integer; a Wi-Fi channel, e,g,. 36.
335        """
336        if not channel1:
337            channel1 = hostapd_constants.AP_DEFAULT_CHANNEL_2G
338        if not channel2:
339            channel2 = hostapd_constants.AP_DEFAULT_CHANNEL_5G
340
341        if hasattr(self, "packet_capture") and len(self.packet_capture) == 2:
342            # Create sniffer_config.
343            self.sniffer_config = {}
344            if channel1 in WifiEnums.channel_2G_to_freq:
345                self.sniffer_config[BAND_2G] = channel1
346            if channel1 in WifiEnums.channel_5G_to_freq:
347                self.sniffer_config[BAND_5G] = channel1
348            if channel2 in WifiEnums.channel_2G_to_freq:
349                self.sniffer_config[BAND_2G] = channel2
350            if channel2 in WifiEnums.channel_5G_to_freq:
351                self.sniffer_config[BAND_5G] = channel2
352            logging.info("sniffer_config : {}".format(self.sniffer_config))
353
354            # Enable sniffers.
355            self.sniffer_procs = []
356            for i in range(len(self.sniffer_config)):
357                self.packet_capture[i].log.info(
358                    "Enable packet_capture[{}]".format(i))
359                result = self.packet_capture[i].configure_monitor_mode(
360                    list(self.sniffer_config.keys())[i],
361                    list(self.sniffer_config.values())[i])
362                if not result:
363                    logging.error("Failed to enable packet_capture"
364                                  "on {}".format(self.packet_capture[i]))
365                self.pcap_procs = wutils.start_pcap(
366                    self.packet_capture[i],
367                    list(self.sniffer_config.keys())[i],
368                    self.test_name)
369                self.sniffer_procs.append(self.pcap_procs)
370            logging.info("sniffer_procs: {}".format(self.sniffer_procs))
371        else:
372            logging.debug("Packet_capture not enabled, "
373                          "because two packet_capture hardware required")
374
375    def start_ap(self, channel_2g, channel_5g):
376        """Enable OpenWrt AP with specific 2G/5G channels
377
378        Args:
379            channel_2g: Integer; a 2G channel, e.g., 6.
380            channel_5g: Integer; a 5G channel, e,g,. 36
381        """
382        if not channel_2g:
383            channel_2g = hostapd_constants.AP_DEFAULT_CHANNEL_2G
384        if not channel_5g:
385            channel_5g = hostapd_constants.AP_DEFAULT_CHANNEL_5G
386
387        # Enable OpenWrt AP.
388        if "OpenWrtAP" in self.user_params:
389            self.configure_openwrt_ap_and_start(wpa_network=True,
390                                                channel_2g=channel_2g,
391                                                channel_5g=channel_5g)
392
393    def two_clients_connect_to_wifi_network(self, dut1, dut2, config):
394        """Connect two clients to different BridgedAp instances.
395           This function will be called only when BridgedAp ON.
396
397        Args:
398            config: Wi-Fi config, e.g., {"SSID": "xxx", "password": "xxx"}
399        Steps:
400            Backup config.
401            Register SoftAp Callback.
402            Get SoftAp Infos.
403            Get BSSIDs from Infos.
404            Connect two clients to different BridgedAp instances.
405            Restore config.
406        """
407        # Make sure 2 instances enabled, and get BSSIDs from BridgedAp Infos.
408        callbackId = self.dut.droid.registerSoftApCallback()
409        infos = wutils.get_current_softap_infos(self.dut, callbackId, True)
410        self.dut.droid.unregisterSoftApCallback(callbackId)
411
412        if len(infos) == 0:
413            raise signals.TestFailure("No BridgedAp instance")
414        elif len(infos) == 1:
415            raise signals.TestFailure(
416                "Only one BridgedAp instance, should be two")
417        else:
418            bssid_5g = infos[0][wifi_constants.SOFTAP_INFO_BSSID_CALLBACK_KEY]
419            bssid_2g = infos[1][wifi_constants.SOFTAP_INFO_BSSID_CALLBACK_KEY]
420
421        # Two configs for BridgedAp 2G and 5G instances.
422        config_5g = config.copy()
423        config_2g = config.copy()
424        config_5g[WifiEnums.BSSID_KEY] = bssid_5g
425        config_2g[WifiEnums.BSSID_KEY] = bssid_2g
426
427        # Connect two clients to BridgedAp.
428        wutils.connect_to_wifi_network(dut1, config_5g,
429                                       check_connectivity=False)
430        wutils.connect_to_wifi_network(dut2, config_2g,
431                                       check_connectivity=False)
432
433        # Verify if Clients connect to the expected BridgedAp instances.
434        client1_bssid = wutils.get_wlan0_link(
435            self.client1)[wifi_constants.SOFTAP_INFO_BSSID_CALLBACK_KEY]
436        client2_bssid = wutils.get_wlan0_link(
437            self.client2)[wifi_constants.SOFTAP_INFO_BSSID_CALLBACK_KEY]
438        asserts.assert_true(client1_bssid == bssid_5g,
439                            "Client1 does not connect to the 5G instance")
440        asserts.assert_true(client2_bssid == bssid_2g,
441                            "Client2 does not connect to the 2G instance")
442
443    def client_connects_to_a_bridgeap(self, ad, band):
444        """One client connects to a BridgeAp instance
445
446        Args:
447            band: String; '2g' or '5g'.
448        """
449        callbackId = self.dut.droid.registerSoftApCallback()
450        infos = wutils.get_current_softap_infos(self.dut, callbackId, True)
451        self.dut.droid.unregisterSoftApCallback(callbackId)
452        # Make one client connects to 2G instance if band == '2g'.
453        if band == BAND_2G:
454            if (infos[0][wifi_constants.SOFTAP_INFO_FREQUENCY_CALLBACK_KEY]
455               in WifiEnums.ALL_2G_FREQUENCIES):
456                bssid_2g = (infos[0][wifi_constants.
457                            SOFTAP_INFO_BSSID_CALLBACK_KEY])
458            else:
459                bssid_2g = (infos[1][wifi_constants.
460                            SOFTAP_INFO_BSSID_CALLBACK_KEY])
461            config_2g = self.config.copy()
462            config_2g[WifiEnums.BSSID_KEY] = bssid_2g
463            wutils.connect_to_wifi_network(ad, config_2g,
464                                           check_connectivity=False)
465        # Make one client connects to 5G instance if band == '5g'.
466        elif band == BAND_5G:
467            if (infos[0][wifi_constants.SOFTAP_INFO_FREQUENCY_CALLBACK_KEY]
468               in WifiEnums.ALL_5G_FREQUENCIES):
469                bssid_5g = (infos[0][wifi_constants.
470                            SOFTAP_INFO_BSSID_CALLBACK_KEY])
471            else:
472                bssid_5g = (infos[1][wifi_constants.
473                            SOFTAP_INFO_BSSID_CALLBACK_KEY])
474            config_5g = self.config.copy()
475            config_5g[WifiEnums.BSSID_KEY] = bssid_5g
476            wutils.connect_to_wifi_network(ad, config_5g,
477                                           check_connectivity=False)
478
479    # Tests
480
481    @test_tracker_info(uuid="6f776b4a-b080-4b52-a330-52aa641b18f2")
482    def test_two_clients_ping_bridged_ap_5g_2g_wpa3_country_us(self):
483        """Test clients on different instances can ping each other.
484
485        Steps:
486            Backup config.
487            Make sure clients support WPA3 SAE.
488            Make sure DUT is able to enable BridgedAp.
489            Enable BridgedAp with bridged configuration.
490            RegisterSoftApCallback.
491            Check the bridged AP enabled succeed.
492            start sniffer and sniffing on BridgedAp channels.
493            Force client#1 connect to 5G.
494            Force client#2 connect to 2.4G.
495            Trigger client#1 and client#2 each other.
496            Stop sniffers.
497            Restore config.
498        """
499        # Backup config
500        original_softap_config = self.dut.droid.wifiGetApConfiguration()
501        # Make sure clients support WPA3 SAE.
502        self.verify_clients_support_wpa3_sae(self.client1, self.client2)
503        # Make sure DUT is able to enable BridgedAp.
504        is_supported = wutils.check_available_channels_in_bands_2_5(
505            self.dut, wutils.WifiEnums.CountryCode.US)
506        asserts.skip_if(not is_supported, "BridgedAp is not supported in {}"
507                        .format(wutils.WifiEnums.CountryCode.US))
508
509        # Enable BridgedAp and verify both 2G,5G instances have been enabled.
510        self.enable_bridged_ap(self.dut,
511                               WifiEnums.SoftApSecurityType.WPA3_SAE,
512                               bands=[WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G,
513                                      WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G_5G])
514        infos = self.verify_number_band_freq_of_bridged_ap(
515            self.dut, [WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G,
516                       WifiEnums.WIFI_CONFIG_SOFTAP_BAND_5G], False)
517
518        self.sniffing_bridgedap_channels(infos)
519
520        self.two_clients_connect_to_wifi_network(self.client1, self.client2,
521                                                 self.config)
522        # Trigger client#1 and client#2 ping each other.
523        wutils.validate_ping_between_two_clients(self.client1, self.client2)
524
525        # Restore config
526        wutils.save_wifi_soft_ap_config(self.dut, original_softap_config)
527    @test_tracker_info(uuid="8685a6cb-f7be-4384-b25b-23cecb4cb6dc")
528    def test_two_clients_ping_bridged_ap_5g_2g_wpa3_sae_transition_country_us(self):
529        """Test clients on different instances can ping each other.
530
531        Steps:
532            Refer to test_two_clients_ping_bridged_ap_5g_2g_wpa3_country_us,
533            but this case enable WPA3/WPA2-Personal SoftAp security type.
534        """
535        # Backup config
536        original_softap_config = self.dut.droid.wifiGetApConfiguration()
537        # Make sure clients support WPA3 SAE.
538        self.verify_clients_support_wpa3_sae(self.client1, self.client2)
539        # Make sure DUT is able to enable BridgedAp.
540        is_supported = wutils.check_available_channels_in_bands_2_5(
541            self.dut, wutils.WifiEnums.CountryCode.US)
542        asserts.skip_if(not is_supported, "BridgedAp is not supported in {}"
543                        .format(wutils.WifiEnums.CountryCode.US))
544
545        # Enable BridgedAp and verify both 2G,5G instances have been enabled.
546        self.enable_bridged_ap(self.dut,
547                               WifiEnums.SoftApSecurityType.WPA3_SAE_TRANSITION,
548                               bands=[WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G,
549                                      WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G_5G])
550        infos = self.verify_number_band_freq_of_bridged_ap(
551            self.dut, [WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G,
552                       WifiEnums.WIFI_CONFIG_SOFTAP_BAND_5G], False)
553
554        self.sniffing_bridgedap_channels(infos)
555
556        self.two_clients_connect_to_wifi_network(self.client1, self.client2,
557                                                 self.config)
558        # Trigger client#1 and client#2 ping each other.
559        wutils.validate_ping_between_two_clients(self.client1, self.client2)
560
561        # Restore config
562        wutils.save_wifi_soft_ap_config(self.dut, original_softap_config)
563
564    @test_tracker_info(uuid="b217d4de-cd09-4a8f-b27d-302ae5b86c7e")
565    def test_two_clients_ping_bridged_ap_5g_2g_wpa2_country_us(self):
566        """Test clients on different instances can ping each other.
567
568        Steps:
569            Refer to test_two_clients_ping_bridged_ap_5g_2g_wpa3_country_us,
570            but this case enable WPA2-Personal SoftAp security type.
571        """
572        # Backup config
573        original_softap_config = self.dut.droid.wifiGetApConfiguration()
574        # Make sure DUT is able to enable BridgedAp.
575        is_supported = wutils.check_available_channels_in_bands_2_5(
576            self.dut, wutils.WifiEnums.CountryCode.US)
577        asserts.skip_if(not is_supported, "BridgedAp is not supported in {}"
578                        .format(wutils.WifiEnums.CountryCode.US))
579
580        # Enable BridgedAp and verify both 2G,5G instances have been enabled.
581        self.enable_bridged_ap(self.dut,
582                               WifiEnums.SoftApSecurityType.WPA2,
583                               bands=[WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G,
584                                      WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G_5G])
585        infos = self.verify_number_band_freq_of_bridged_ap(
586            self.dut, [WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G,
587                       WifiEnums.WIFI_CONFIG_SOFTAP_BAND_5G], False)
588
589        self.sniffing_bridgedap_channels(infos)
590
591        self.two_clients_connect_to_wifi_network(self.client1, self.client2,
592                                                 self.config)
593        # Trigger client#1 and client#2 ping each other.
594        wutils.validate_ping_between_two_clients(self.client1, self.client2)
595
596        # Restore config
597        wutils.save_wifi_soft_ap_config(self.dut, original_softap_config)
598
599    @test_tracker_info(uuid="ef98a5ea-c7d5-4cc4-a2f8-e5fd44648788")
600    def test_two_clients_ping_bridged_ap_5g_2g_no_security_country_us(self):
601        """Test clients on different instances can ping each other.
602
603        Steps:
604            Refer to test_two_clients_ping_bridged_ap_5g_2g_wpa3_country_us,
605            but this case enable OPEN SoftAp security type.
606        """
607        # Backup config
608        original_softap_config = self.dut.droid.wifiGetApConfiguration()
609        # Make sure DUT is able to enable BridgedAp.
610        is_supported = wutils.check_available_channels_in_bands_2_5(
611            self.dut, wutils.WifiEnums.CountryCode.US)
612        asserts.skip_if(not is_supported, "BridgedAp is not supported in {}"
613                        .format(wutils.WifiEnums.CountryCode.US))
614
615        # Enable BridgedAp and verify both 2G,5G instances have been enabled.
616        self.enable_bridged_ap(self.dut,
617                               WifiEnums.SoftApSecurityType.OPEN,
618                               bands=[WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G,
619                                      WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G_5G])
620        infos = self.verify_number_band_freq_of_bridged_ap(
621            self.dut, [WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G,
622                       WifiEnums.WIFI_CONFIG_SOFTAP_BAND_5G], False)
623
624        self.sniffing_bridgedap_channels(infos)
625
626        self.two_clients_connect_to_wifi_network(self.client1, self.client2,
627                                                 self.config)
628        # Trigger client#1 and client#2 ping each other.
629        wutils.validate_ping_between_two_clients(self.client1, self.client2)
630
631        # Restore config
632        wutils.save_wifi_soft_ap_config(self.dut, original_softap_config)
633
634    @test_tracker_info(uuid="0325ee58-ed8e-489e-9dee-55740406f896")
635    def test_bridged_ap_5g_2g_and_sta_5g_dfs(self):
636        """Test if auto fallback to one single 2G AP mode when
637         BridgedAP enabled and STA connect to a 5G DFS channel.
638
639        Steps:
640            Backup config.
641            DUT enable BridgedAp.
642            start sniffer and sniffing on AP channels.
643            DUT connect to a 5G DFS channel Wi-Fi network.
644            Verify 5G instance is shutdown.
645            Stop sniffers.
646            Restore config.
647        """
648        # Backup config
649        original_softap_config = self.dut.droid.wifiGetApConfiguration()
650
651        # Make sure DUT is able to enable BridgedAp.
652        is_supported = wutils.check_available_channels_in_bands_2_5(
653            self.dut, wutils.WifiEnums.CountryCode.US)
654        asserts.skip_if(not is_supported, "BridgedAp is not supported in {}"
655                        .format(wutils.WifiEnums.CountryCode.US))
656
657        # Enable BridgedAp and verify both 2G,5G instances have been enabled.
658        self.enable_bridged_ap(self.dut,
659                               WifiEnums.SoftApSecurityType.WPA3_SAE,
660                               bands=[WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G,
661                                      WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G_5G])
662        self.verify_number_band_freq_of_bridged_ap(
663            self.dut, [WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G,
664                       WifiEnums.WIFI_CONFIG_SOFTAP_BAND_5G], False)
665
666        self.sniffing_ap_channels(channel1=None, channel2=132)
667        self.start_ap(channel_2g=None, channel_5g=132)
668        wutils.wifi_toggle_state(self.dut, True)
669        wutils.connect_to_wifi_network(self.dut, self.wpa_networks[0][BAND_5G])
670
671        self.verify_number_band_freq_of_bridged_ap(
672            self.dut, [WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G], False)
673
674        # Restore config
675        wutils.save_wifi_soft_ap_config(self.dut, original_softap_config)
676
677    @test_tracker_info(uuid="9a5d4ca9-67fc-412c-8114-01c43c34a76d")
678    def test_bridged_ap_5g_2g_and_sta_5g_non_dfs(self):
679        """Test 5G scc when BridgedAp enabled and 5G STA.
680
681        Steps:
682            Backup config.
683            DUT enable BridgedAp.
684            start sniffer and sniffing on AP channels.
685            DUT connect to a 5G non-DFS channel Wi-Fi network.
686            Verify STA frequency equals to 5G BridgedAp frequency.
687            Stop sniffers.
688            Restore config.
689        """
690        # Backup config
691        original_softap_config = self.dut.droid.wifiGetApConfiguration()
692
693        # Make sure DUT is able to enable BridgedAp.
694        is_supported = wutils.check_available_channels_in_bands_2_5(
695            self.dut, wutils.WifiEnums.CountryCode.US)
696        asserts.skip_if(not is_supported, "BridgedAp is not supported in {}"
697                        .format(wutils.WifiEnums.CountryCode.US))
698
699        # Enable BridgedAp and verify both 2G,5G instances have been enabled.
700        self.enable_bridged_ap(self.dut,
701                               WifiEnums.SoftApSecurityType.WPA3_SAE,
702                               bands=[WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G,
703                                      WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G_5G])
704        self.verify_number_band_freq_of_bridged_ap(
705            self.dut, [WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G,
706                       WifiEnums.WIFI_CONFIG_SOFTAP_BAND_5G], False)
707
708        self.sniffing_ap_channels(channel1=None, channel2=36)
709        self.start_ap(channel_2g=None, channel_5g=36)
710        wutils.wifi_toggle_state(self.dut, True)
711        wutils.connect_to_wifi_network(self.dut, self.wpa_networks[0][BAND_5G])
712
713        self.verify_number_band_freq_of_bridged_ap(
714            self.dut, [WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G,
715                       WifiEnums.WIFI_CONFIG_SOFTAP_BAND_5G], True)
716
717        # Restore config
718        wutils.save_wifi_soft_ap_config(self.dut, original_softap_config)
719
720    @test_tracker_info(uuid="e26e8a72-3e21-47b3-8fd8-4c4db5fb2573")
721    def test_bridged_ap_5g_2g_and_sta_2g(self):
722        """ Test 2G SCC when BridgedAp enable and 2G STA.
723
724        Steps:
725            Backup config.
726            DUT enable BridgedAp.
727            start sniffer and sniffing on AP channels.
728            STA connect to a 2G Wi-Fi network.
729            Verify STA frequency equals to 2G BridgedAp frequency.
730            Stop sniffers.
731            Restore config.
732        """
733        # Backup config
734        original_softap_config = self.dut.droid.wifiGetApConfiguration()
735
736        # Make sure DUT is able to enable BridgedAp.
737        is_supported = wutils.check_available_channels_in_bands_2_5(
738            self.dut, wutils.WifiEnums.CountryCode.US)
739        asserts.skip_if(not is_supported, "BridgedAp is not supported in {}"
740                        .format(wutils.WifiEnums.CountryCode.US))
741
742        # Enable BridgedAp and verify both 2G,5G instances have been enabled.
743        self.enable_bridged_ap(self.dut,
744                               WifiEnums.SoftApSecurityType.WPA3_SAE,
745                               bands=[WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G,
746                                      WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G_5G])
747        self.verify_number_band_freq_of_bridged_ap(
748            self.dut, [WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G,
749                       WifiEnums.WIFI_CONFIG_SOFTAP_BAND_5G], False)
750
751        self.sniffing_ap_channels(channel1=6, channel2=None)
752        self.start_ap(channel_2g=6, channel_5g=None)
753        wutils.wifi_toggle_state(self.dut, True)
754        wutils.connect_to_wifi_network(self.dut, self.wpa_networks[0][BAND_2G])
755
756        self.verify_number_band_freq_of_bridged_ap(
757            self.dut, [WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G,
758                       WifiEnums.WIFI_CONFIG_SOFTAP_BAND_5G], True)
759
760        # Restore config
761        wutils.save_wifi_soft_ap_config(self.dut, original_softap_config)
762
763    @test_tracker_info(uuid="b25f710a-2e53-456e-8280-dcdd37badd6c")
764    def test_sta_5g_dfs_and_bridged_ap_5g_2g(self):
765        """Test auto fallback to Single AP mode
766           when STA connect to a DFS channel.
767
768        Steps:
769            Backup config.
770            start sniffer and sniffing on AP channels.
771            Enable a Wi-Fi network.
772            DUT connect to a 5G DFS channel Wi-Fi network.
773            DUT enable BridgedAp.
774            Verify 5G instance is shutdown and only 2G instance enabled.
775            Stop sniffers.
776            Restore config.
777        """
778        # Backup config
779        original_softap_config = self.dut.droid.wifiGetApConfiguration()
780
781        # Make sure DUT is able to enable BridgedAp.
782        is_supported = wutils.check_available_channels_in_bands_2_5(
783            self.dut, wutils.WifiEnums.CountryCode.US)
784        asserts.skip_if(not is_supported, "BridgedAp is not supported in {}"
785                        .format(wutils.WifiEnums.CountryCode.US))
786
787        self.sniffing_ap_channels(channel1=None, channel2=132)
788        self.start_ap(channel_2g=None, channel_5g=132)
789        wutils.wifi_toggle_state(self.dut, True)
790        wutils.connect_to_wifi_network(self.dut, self.wpa_networks[0][BAND_5G])
791
792        # Enable BridgedAp
793        self.enable_bridged_ap(self.dut,
794                               WifiEnums.SoftApSecurityType.WPA3_SAE,
795                               bands=[WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G,
796                                      WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G_5G])
797        # # Verify only 2G instance enabled.
798        self.verify_number_band_freq_of_bridged_ap(
799            self.dut, [WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G], False)
800
801        # Restore config
802        wutils.save_wifi_soft_ap_config(self.dut, original_softap_config)
803
804    @test_tracker_info(uuid="6acaed3f-616f-4a03-a329-702e6cc537bd")
805    def test_sta_5g_non_dfs_and_bridged_ap_5g_2g(self):
806        """Test 5G scc when 5G STA and BridgedAp enabled.
807
808        Steps:
809            Backup config.
810            start sniffer and sniffing on AP channels.
811            Enable a Wi-Fi network.
812            DUT connect to a 5G non-DFS channel Wi-Fi network.
813            DUT enable BridgedAp.
814            Verify STA frequency equals to 5G BridgedAp frequency.
815            Stop sniffers.
816            Restore config.
817        """
818        # Backup config
819        original_softap_config = self.dut.droid.wifiGetApConfiguration()
820
821        # Make sure DUT is able to enable BridgedAp.
822        is_supported = wutils.check_available_channels_in_bands_2_5(
823            self.dut, wutils.WifiEnums.CountryCode.US)
824        asserts.skip_if(not is_supported, "BridgedAp is not supported in {}"
825                        .format(wutils.WifiEnums.CountryCode.US))
826
827        self.sniffing_ap_channels(channel1=None, channel2=36)
828        self.start_ap(channel_2g=None, channel_5g=36)
829        wutils.wifi_toggle_state(self.dut, True)
830        wutils.connect_to_wifi_network(self.dut, self.wpa_networks[0][BAND_5G])
831
832        # Enable BridgedAp and verify both 2G,5G instances have been enabled.
833        self.enable_bridged_ap(self.dut,
834                               WifiEnums.SoftApSecurityType.WPA3_SAE,
835                               bands=[WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G,
836                                      WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G_5G])
837        # Verify STA frequency equals to 5G BridgedAp frequency.
838        self.verify_number_band_freq_of_bridged_ap(
839            self.dut, [WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G,
840                       WifiEnums.WIFI_CONFIG_SOFTAP_BAND_5G], True)
841
842        # Restore config
843        wutils.save_wifi_soft_ap_config(self.dut, original_softap_config)
844
845    @test_tracker_info(uuid="e24e7f2d-f1d5-4dc7-aa6a-487677864d1d")
846    def test_sta_2g_and_bridged_ap_5g_2g(self):
847        """ Test 2G SCC when 2G STA and BridgedAp enable.
848
849        Steps:
850            Backup config.
851            start sniffer and sniffing on AP channels.
852            Enable a Wi-Fi network.
853            DUT connect to a 2G Wi-Fi network.
854            DUT enable BridgedAp.
855            Verify STA frequency equals to 2G BridgedAp frequency.
856            Stop sniffers.
857            Restore config.
858        """
859        # Backup config
860        original_softap_config = self.dut.droid.wifiGetApConfiguration()
861
862        # Make sure DUT is able to enable BridgedAp.
863        is_supported = wutils.check_available_channels_in_bands_2_5(
864            self.dut, wutils.WifiEnums.CountryCode.US)
865        asserts.skip_if(not is_supported, "BridgedAp is not supported in {}"
866                        .format(wutils.WifiEnums.CountryCode.US))
867
868        self.sniffing_ap_channels(channel1=6, channel2=None)
869        self.start_ap(channel_2g=6, channel_5g=None)
870        wutils.wifi_toggle_state(self.dut, True)
871        wutils.connect_to_wifi_network(self.dut, self.wpa_networks[0][BAND_2G])
872
873        # Enable BridgedAp and verify both 2G,5G instances have been enabled.
874        self.enable_bridged_ap(self.dut,
875                               WifiEnums.SoftApSecurityType.WPA3_SAE,
876                               bands=[WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G,
877                                      WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G_5G])
878        self.verify_number_band_freq_of_bridged_ap(
879            self.dut, [WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G,
880                       WifiEnums.WIFI_CONFIG_SOFTAP_BAND_5G], True)
881
882        # Restore config
883        wutils.save_wifi_soft_ap_config(self.dut, original_softap_config)
884
885    @test_tracker_info(uuid="927d564d-2ac4-4e6f-bb36-270efd519e0b")
886    def test_bridged_ap_5g_2g_shutdown_5g_2g_no_client(self):
887        """Test the BridgeAp shutdown mechanism with no client connect to it.
888
889        Steps:
890            Backup config.
891            DUT turns ON BridgedAp.
892            Verify no client connect to the BridgedAp.
893            Wait for 5 minutes.
894            Verify that 5G BridgedAp instance is shutdown.
895            Maks sure there is still no client connect to the BridgedAp.
896            Wait for 5 minutes.
897            Verify that 2G BridgedAp instance is shutdown.
898            Restore config.
899        """
900        # Backup config
901        original_softap_config = self.dut.droid.wifiGetApConfiguration()
902
903        # Make sure DUT is able to enable BridgedAp.
904        is_supported = wutils.check_available_channels_in_bands_2_5(
905            self.dut, wutils.WifiEnums.CountryCode.US)
906        asserts.skip_if(not is_supported, "BridgedAp is not supported in {}"
907                        .format(wutils.WifiEnums.CountryCode.US))
908
909        # Simulate the unplugged scenario
910        self.dut.adb.shell("cmd battery unplug")
911        # Enable BridgedAp and verify both 2G,5G instances have been enabled.
912        self.enable_bridged_ap(self.dut,
913                               WifiEnums.SoftApSecurityType.WPA3_SAE,
914                               bands=[WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G,
915                                      WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G_5G])
916        infos = self.verify_number_band_freq_of_bridged_ap(
917            self.dut, [WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G,
918                       WifiEnums.WIFI_CONFIG_SOFTAP_BAND_5G], False)
919
920        # No client connection, wait 5 minutes, verify 5G is shutdown.
921        self.verify_expected_number_of_softap_clients(self.dut, 0)
922        self.wait_interval(BRIDGED_AP_SHUTDOWN_INTERVAL_5_MINUTES)
923        self.verify_number_band_freq_of_bridged_ap(
924            self.dut, [WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G], False)
925        # No client connection, wait 5 minutes, verify 2G is shutdown.
926        self.verify_expected_number_of_softap_clients(self.dut, 0)
927        self.wait_interval(BRIDGED_AP_SHUTDOWN_INTERVAL_5_MINUTES)
928
929        self.verify_number_band_freq_of_bridged_ap(self.dut, [], False)
930
931        # Restore config
932        wutils.save_wifi_soft_ap_config(self.dut, original_softap_config)
933
934    @test_tracker_info(uuid="4c5b210c-412f-40e4-84b6-2a12dbffa017")
935    def test_bridged_ap_5g_2g_shutdown_5g_auto_shutdown_2g(self):
936        """Test the BridgeAp shutdown mechanism with no client connect to it.
937
938        Steps:
939            Backup config.
940            DUT turns ON BridgedAp.
941            start sniffer and sniffing on BridgedAp channels.
942            Verify no client connect to the BridgedAp.
943            Wait for 5 minutes.
944            Verify that 5G BridgedAp instance is shutdown.
945            A client connect to the 2G BridgedAp.
946            The client disconnect from 2G BridgedAp.
947            Wait for 10 minutes.
948            Verify 2G BridgedAp is shutdown, no BridgedAp instance enabled.
949            Stop sniffers.
950            Restore config.
951        """
952        # Backup config
953        original_softap_config = self.dut.droid.wifiGetApConfiguration()
954
955        # Make sure DUT is able to enable BridgedAp.
956        is_supported = wutils.check_available_channels_in_bands_2_5(
957            self.dut, wutils.WifiEnums.CountryCode.US)
958        asserts.skip_if(not is_supported, "BridgedAp is not supported in {}"
959                        .format(wutils.WifiEnums.CountryCode.US))
960
961        # Simulate the unplugged scenario
962        self.dut.adb.shell("cmd battery unplug")
963        # Enable BridgedAp and verify both 2G,5G instances have been enabled.
964        self.enable_bridged_ap(self.dut,
965                               WifiEnums.SoftApSecurityType.WPA3_SAE,
966                               bands=[WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G,
967                                      WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G_5G])
968        infos = self.verify_number_band_freq_of_bridged_ap(
969            self.dut, [WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G,
970                       WifiEnums.WIFI_CONFIG_SOFTAP_BAND_5G], False)
971
972        self.sniffing_bridgedap_channels(infos)
973
974        # Verify no connection to BridgedAp, wait for 5 mins, 5G shutdown.
975        self.verify_expected_number_of_softap_clients(self.dut, 0)
976        self.wait_interval(BRIDGED_AP_SHUTDOWN_INTERVAL_5_MINUTES)
977        self.verify_number_band_freq_of_bridged_ap(
978            self.dut, [WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G], False)
979
980        # A client connect to 2G BridgedAp instance.
981        callbackId = self.dut.droid.registerSoftApCallback()
982        infos = wutils.get_current_softap_infos(self.dut, callbackId, True)
983        self.dut.droid.unregisterSoftApCallback(callbackId)
984        bssid_2g = infos[0][wifi_constants.SOFTAP_INFO_BSSID_CALLBACK_KEY]
985        config_2g = self.config.copy()
986        config_2g[WifiEnums.BSSID_KEY] = bssid_2g
987        wutils.connect_to_wifi_network(self.client1, config_2g,
988                                       check_connectivity=False)
989        self.wait_interval(BRIDGED_AP_SHUTDOWN_INTERVAL_5_SECONDS)
990
991        # Client disconnect From 2G BridgedAp instance.
992        is_disconnect = self.client1.droid.wifiDisconnect()
993        self.client1.log.info("Disconnected from SoftAp")
994        if not is_disconnect:
995            raise signals.TestFailure("Wi-Fi is not disconnected as expect")
996        wutils.reset_wifi(self.client1)
997
998        # Verify 2G instance is still enabled.
999        self.wait_interval(INTERVAL_9_MINUTES)
1000        self.verify_number_band_freq_of_bridged_ap(
1001            self.dut, [WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G], False)
1002
1003        # Verify all BridgedAp instances are shutdown after 10 minutes.
1004        self.wait_interval(INTERVAL_1_MINUTES)
1005        self.verify_number_band_freq_of_bridged_ap(self.dut, [], False)
1006
1007        # Restore config
1008        wutils.save_wifi_soft_ap_config(self.dut, original_softap_config)
1009
1010    @test_tracker_info(uuid="2b1b4579-d610-4983-83f4-5fc34b3cdd6b")
1011    def test_bridged_ap_5g_2g_shutdown_5g_auto_shutdown_2g_after_10_mins(self):
1012        """Test the BridgeAp shutdown mechanism with no client connect to it.
1013
1014        Steps:
1015            Backup config.
1016            DUT turns ON BridgedAp.
1017            start sniffer and sniffing on BridgedAp channels.
1018            Verify no client connect to the BridgedAp.
1019            Wait for 5 minutes.
1020            Verify that 5G BridgedAp instance is shutdown.
1021            A client connect to the 2G BridgedAp at 7th minutes.
1022            The client disconnect from 2G BridgedAp at 9th minutes.
1023            Wait for 10 minutes.
1024            Verify 2G BridgedAp is shutdown, no BridgedAp instance enabled.
1025            Stop sniffers.
1026            Restore config.
1027        """
1028        # Backup config
1029        original_softap_config = self.dut.droid.wifiGetApConfiguration()
1030
1031        # Make sure DUT is able to enable BridgedAp.
1032        is_supported = wutils.check_available_channels_in_bands_2_5(
1033            self.dut, wutils.WifiEnums.CountryCode.US)
1034        asserts.skip_if(not is_supported, "BridgedAp is not supported in {}"
1035                        .format(wutils.WifiEnums.CountryCode.US))
1036
1037        # Simulate the unplugged scenario
1038        self.dut.adb.shell("cmd battery unplug")
1039        # Enable BridgedAp and verify both 2G,5G instances have been enabled.
1040        self.enable_bridged_ap(self.dut,
1041                               WifiEnums.SoftApSecurityType.WPA3_SAE,
1042                               bands=[WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G,
1043                                      WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G_5G],
1044                               bridged_opportunistic_shutdown_enabled=True,
1045                               shutdown_timeout_enable=True)
1046        infos = self.verify_number_band_freq_of_bridged_ap(
1047            self.dut, [WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G,
1048                       WifiEnums.WIFI_CONFIG_SOFTAP_BAND_5G], False)
1049
1050        self.sniffing_bridgedap_channels(infos)
1051
1052        self.verify_expected_number_of_softap_clients(self.dut, 0)
1053        self.wait_interval(BRIDGED_AP_SHUTDOWN_INTERVAL_5_MINUTES)
1054        self.verify_number_band_freq_of_bridged_ap(
1055            self.dut, [WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G], False)
1056
1057        # Client connects to 2G instance at 7th mins.
1058        self.wait_interval(INTERVAL_2_MINUTES)
1059        callbackId = self.dut.droid.registerSoftApCallback()
1060        infos = wutils.get_current_softap_infos(self.dut, callbackId, True)
1061        self.dut.droid.unregisterSoftApCallback(callbackId)
1062        bssid_2g = infos[0][wifi_constants.SOFTAP_INFO_BSSID_CALLBACK_KEY]
1063        config_2g = self.config.copy()
1064        config_2g[WifiEnums.BSSID_KEY] = bssid_2g
1065        wutils.connect_to_wifi_network(self.client1, config_2g,
1066                                       check_connectivity=False)
1067        self.wait_interval(BRIDGED_AP_SHUTDOWN_INTERVAL_5_SECONDS)
1068
1069        # Client disconnect From 2G BridgedAp instance at 9th mins.
1070        self.wait_interval(INTERVAL_2_MINUTES)
1071        is_disconnect = self.client1.droid.wifiDisconnect()
1072        self.client1.log.info("Disconnected from SoftAp")
1073        if not is_disconnect:
1074            raise signals.TestFailure("Wi-Fi is not disconnected as expect")
1075        wutils.reset_wifi(self.client1)
1076
1077        # Make sure 2G instance is still enabled.
1078        self.wait_interval(INTERVAL_9_MINUTES)
1079        self.verify_number_band_freq_of_bridged_ap(
1080            self.dut, [WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G], False)
1081
1082        self.wait_interval(INTERVAL_1_MINUTES)
1083        self.verify_number_band_freq_of_bridged_ap(self.dut, [], False)
1084
1085        # Restore config
1086        wutils.save_wifi_soft_ap_config(self.dut, original_softap_config)
1087
1088    @test_tracker_info(uuid="1785a487-dd95-4c17-852d-3c9b7b7dd4c3")
1089    def test_bridged_ap_5g_2g_fallback_2g_country_jp(self):
1090        """Test BridgedAp fallback to Single AP mode with JP country code.
1091
1092        Steps:
1093            Backup config.
1094            Set DUT country code to "JP".
1095            DUT turns ON BridgedAp.
1096            Verify only 2G BridgedAp instance is enabled.
1097            Restore config.
1098        """
1099        # Backup config
1100        original_softap_config = self.dut.droid.wifiGetApConfiguration()
1101
1102        # Set country code to JP and enable BridgedAp
1103        self.set_country_code_and_verify(self.dut, WifiEnums.CountryCode.JAPAN)
1104
1105        # Enable BridgedAp
1106        self.enable_bridged_ap(self.dut,
1107                               WifiEnums.SoftApSecurityType.WPA3_SAE,
1108                               bands=[WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G,
1109                                      WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G_5G])
1110        # Verify only 2G BridgedAp instance enabled.
1111        infos = self.verify_number_band_freq_of_bridged_ap(
1112            self.dut, [WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G], False)
1113        self.sniffing_bridgedap_channels(infos)
1114
1115        # Restore config
1116        wutils.save_wifi_soft_ap_config(self.dut, original_softap_config)
1117
1118    @test_tracker_info(uuid="b5c7c6df-b181-4bba-a7b3-48fad0d7fa98")
1119    def test_bridged_ap_5g_2g_shutdown_2g_after_5_minutes(self):
1120        """Test the BridgeAp shutdown mechanism.
1121
1122        Steps:
1123            Backup config.
1124            DUT turns ON BridgedAp.
1125            start sniffer and sniffing on BridgedAp channels.
1126            A Client connect to BridgeAp 5G instance.
1127            Wait for 5 minutes.
1128            Verify 2G instance is shutdown and only 5G instance exists.
1129            Stop sniffers.
1130            Restore config."""
1131        # Backup config
1132        original_softap_config = self.dut.droid.wifiGetApConfiguration()
1133
1134        # Make sure DUT is able to enable BridgedAp.
1135        is_supported = wutils.check_available_channels_in_bands_2_5(
1136            self.dut, wutils.WifiEnums.CountryCode.US)
1137        asserts.skip_if(not is_supported, "BridgedAp is not supported in {}"
1138                        .format(wutils.WifiEnums.CountryCode.US))
1139
1140        # Simulate the unplugged scenario
1141        self.dut.adb.shell("cmd battery unplug")
1142        # Enable BridgedAp and verify both 2G,5G instances have been enabled.
1143        self.enable_bridged_ap(self.dut,
1144                               WifiEnums.SoftApSecurityType.WPA3_SAE,
1145                               bands=[WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G,
1146                                      WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G_5G])
1147        infos = self.verify_number_band_freq_of_bridged_ap(
1148            self.dut, [WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G,
1149                       WifiEnums.WIFI_CONFIG_SOFTAP_BAND_5G], False)
1150
1151        self.sniffing_bridgedap_channels(infos)
1152
1153        # Client connects to the 5G BridgedAp instance.
1154        self.client_connects_to_a_bridgeap(self.client1, BAND_5G)
1155        self.wait_interval(BRIDGED_AP_SHUTDOWN_INTERVAL_5_MINUTES)
1156        # Verify there is only one client connects to the BridgedAp.
1157        self.verify_expected_number_of_softap_clients(self.dut, 1)
1158        # Verify the BridgedAp instance is 5G.
1159        self.verify_number_band_freq_of_bridged_ap(
1160            self.dut, [WifiEnums.WIFI_CONFIG_SOFTAP_BAND_5G], False)
1161        # Restore config
1162        wutils.save_wifi_soft_ap_config(self.dut, original_softap_config)
1163
1164    @test_tracker_info(uuid="683b2c7f-7f24-4324-be09-0b6554d5d7a8")
1165    def test_bridged_ap_5g_2g_shutdown_5g_after_5_minutes(self):
1166        """Test the BridgeAp shutdown mechanism.
1167
1168        Steps:
1169            Backup config.
1170            DUT turns ON BridgedAp.
1171            start sniffer and sniffing on BridgedAp channels.
1172            A Client connect to BridgeAp 2G instance.
1173            Wait for 5 minutes.
1174            Verify 5G instance is shutdown and only 2G instance exists.
1175            Stop sniffers.
1176            Restore config."""
1177        # Backup config
1178        original_softap_config = self.dut.droid.wifiGetApConfiguration()
1179
1180        # Make sure DUT is able to enable BridgedAp.
1181        is_supported = wutils.check_available_channels_in_bands_2_5(
1182            self.dut, wutils.WifiEnums.CountryCode.US)
1183        asserts.skip_if(not is_supported, "BridgedAp is not supported in {}"
1184                        .format(wutils.WifiEnums.CountryCode.US))
1185
1186        # Simulate the unplugged scenario
1187        self.dut.adb.shell("cmd battery unplug")
1188        # Enable BridgedAp and verify both 2G,5G instances have been enabled.
1189        self.enable_bridged_ap(self.dut,
1190                               WifiEnums.SoftApSecurityType.WPA3_SAE,
1191                               bands=[WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G,
1192                                      WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G_5G])
1193        infos = self.verify_number_band_freq_of_bridged_ap(
1194            self.dut, [WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G,
1195                       WifiEnums.WIFI_CONFIG_SOFTAP_BAND_5G], False)
1196        self.sniffing_bridgedap_channels(infos)
1197
1198        # Client connects to the 2G BridgedAp instance.
1199        self.client_connects_to_a_bridgeap(self.client1, BAND_2G)
1200        self.wait_interval(BRIDGED_AP_SHUTDOWN_INTERVAL_5_MINUTES)
1201        # Verify there is only one client connects to the BridgedAp.
1202        self.verify_expected_number_of_softap_clients(self.dut, 1)
1203        # Verify the BridgedAp instance is 2G.
1204        self.verify_number_band_freq_of_bridged_ap(
1205            self.dut, [WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G], False)
1206        # Restore config
1207        wutils.save_wifi_soft_ap_config(self.dut, original_softap_config)
1208
1209    @test_tracker_info(uuid="6de46e5b-04c3-4fba-a21d-e914a3e34e24")
1210    def test_bridged_ap_5g_2g_no_shutdown_after_5_minutes(self):
1211        """Test clients on different instances can ping each other.
1212
1213        Steps:
1214            Backup config.
1215            Make sure clients support WPA3 SAE.
1216            Make sure DUT is able to enable BridgedAp.
1217            Enable BridgedAp with bridged configuration.
1218            RegisterSoftApCallback.
1219            Check the bridged AP enabled succeed.
1220            start sniffer and sniffing on BridgedAp channels.
1221            Client#1 connect to 5G instance.
1222            Client#2 connect to 2G instance.
1223            Wait for 5 minutes.
1224            Verify both 2G/5G BridgedAp instances are exist.
1225            Stop sniffers.
1226            Restore config.
1227        """
1228        # Backup config
1229        original_softap_config = self.dut.droid.wifiGetApConfiguration()
1230        # Make sure clients support WPA3 SAE.
1231        self.verify_clients_support_wpa3_sae(self.client1, self.client2)
1232        # Make sure DUT is able to enable BridgedAp.
1233        is_supported = wutils.check_available_channels_in_bands_2_5(
1234            self.dut, wutils.WifiEnums.CountryCode.US)
1235        asserts.skip_if(not is_supported, "BridgedAp is not supported in {}"
1236                        .format(wutils.WifiEnums.CountryCode.US))
1237
1238        # Simulate the unplugged scenario
1239        self.dut.adb.shell("cmd battery unplug")
1240        # Enable BridgedAp and verify both 2G,5G instances have been enabled.
1241        self.enable_bridged_ap(self.dut,
1242                               WifiEnums.SoftApSecurityType.WPA3_SAE,
1243                               bands=[WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G,
1244                                      WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G_5G])
1245        infos = self.verify_number_band_freq_of_bridged_ap(
1246            self.dut, [WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G,
1247                       WifiEnums.WIFI_CONFIG_SOFTAP_BAND_5G], False)
1248
1249        self.sniffing_bridgedap_channels(infos)
1250
1251        self.two_clients_connect_to_wifi_network(self.client1, self.client2,
1252                                                 self.config)
1253        self.wait_interval(BRIDGED_AP_SHUTDOWN_INTERVAL_5_MINUTES)
1254        # Verify there are two clients connect to the BridgedAp.
1255        self.verify_expected_number_of_softap_clients(self.dut, 2)
1256        # Verify both 2G/5G BridgedAp instances are exist.
1257        self.verify_number_band_freq_of_bridged_ap(
1258            self.dut, [WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G,
1259                       WifiEnums.WIFI_CONFIG_SOFTAP_BAND_5G], False)
1260        # Restore config
1261        wutils.save_wifi_soft_ap_config(self.dut, original_softap_config)
1262
1263    @test_tracker_info(uuid="f8742dfb-5232-4fe8-b568-3a99a9356d59")
1264    def test_bridged_ap_5g_2g_extend_compatibility_on_no_shutdown_5g(self):
1265        """Test BridgedAp mechanism when "Extend compatibility is ON.
1266
1267        Steps:
1268            Backup config.
1269            Make sure clients support WPA3 SAE.
1270            Make sure DUT is able to enable BridgedAp.
1271            Enable BridgedAp with Extend compatibility is ON.
1272            RegisterSoftApCallback.
1273            Check the bridged AP enabled succeed.
1274            start sniffer and sniffing on BridgedAp channels.
1275            Client#1 connect to 2G.
1276            Verify both 2G/5G instances are exist.
1277            Stop sniffers.
1278            Restore config.
1279        """
1280        # Backup config
1281        original_softap_config = self.dut.droid.wifiGetApConfiguration()
1282        # Make sure clients support WPA3 SAE.
1283        self.verify_clients_support_wpa3_sae(self.client1, self.client2)
1284        # Make sure DUT is able to enable BridgedAp.
1285        is_supported = wutils.check_available_channels_in_bands_2_5(
1286            self.dut, wutils.WifiEnums.CountryCode.US)
1287        asserts.skip_if(not is_supported, "BridgedAp is not supported in {}"
1288                        .format(wutils.WifiEnums.CountryCode.US))
1289
1290        # Simulate the unplugged scenario
1291        self.dut.adb.shell("cmd battery unplug")
1292        # Enable BridgedAp with "Extend compatibility set to ON".
1293        self.enable_bridged_ap(self.dut,
1294                               WifiEnums.SoftApSecurityType.WPA3_SAE,
1295                               bands=[WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G,
1296                                      WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G_5G],
1297                               bridged_opportunistic_shutdown_enabled=False)
1298        # Client connects to the 2G BridgedAp instance and wait 5 minutes.
1299        self.client_connects_to_a_bridgeap(self.client1, BAND_2G)
1300        self.wait_interval(BRIDGED_AP_SHUTDOWN_INTERVAL_5_MINUTES)
1301        # Verify both 2G/5G BridgedAp instances exist.
1302        self.verify_number_band_freq_of_bridged_ap(
1303            self.dut, [WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G,
1304                       WifiEnums.WIFI_CONFIG_SOFTAP_BAND_5G], False)
1305        # Restore config
1306        wutils.save_wifi_soft_ap_config(self.dut, original_softap_config)
1307
1308    @test_tracker_info(uuid="050f8dd8-ed38-4f7a-87a9-9dbdade58cc7")
1309    def test_bridged_ap_5g_2g_extend_compatibility_on_no_shutdown_2g(self):
1310        """Test BridgedAp mechanism when "Extend compatibility is ON.
1311
1312        Steps:
1313            Backup config.
1314            Make sure clients support WPA3 SAE.
1315            Make sure DUT is able to enable BridgedAp.
1316            Enable BridgedAp with Extend compatibility is ON.
1317            RegisterSoftApCallback.
1318            Check the bridged AP enabled succeed.
1319            start sniffer and sniffing on BridgedAp channels.
1320            Client#1 connect to 5G.
1321            Verify both 2G/5G instances are exist.
1322            Stop sniffers.
1323            Restore config.
1324        """
1325        # Backup config
1326        original_softap_config = self.dut.droid.wifiGetApConfiguration()
1327        # Make sure clients support WPA3 SAE.
1328        self.verify_clients_support_wpa3_sae(self.client1, self.client2)
1329        # Make sure DUT is able to enable BridgedAp.
1330        is_supported = wutils.check_available_channels_in_bands_2_5(
1331            self.dut, wutils.WifiEnums.CountryCode.US)
1332        asserts.skip_if(not is_supported, "BridgedAp is not supported in {}"
1333                        .format(wutils.WifiEnums.CountryCode.US))
1334
1335        # Simulate the unplugged scenario
1336        self.dut.adb.shell("cmd battery unplug")
1337        # Enable BridgedAp with "Extend compatibility set to ON".
1338        self.enable_bridged_ap(self.dut,
1339                               WifiEnums.SoftApSecurityType.WPA3_SAE,
1340                               bands=[WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G,
1341                                      WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G_5G],
1342                               bridged_opportunistic_shutdown_enabled=False)
1343        # Client connects to the 5G BridgedAp instance and wait 5 minutes.
1344        self.client_connects_to_a_bridgeap(self.client1, BAND_5G)
1345        self.wait_interval(BRIDGED_AP_SHUTDOWN_INTERVAL_5_MINUTES)
1346        # Verify both 2G/5G BridgedAp instances exist.
1347        self.verify_number_band_freq_of_bridged_ap(
1348            self.dut, [WifiEnums.WIFI_CONFIG_SOFTAP_BAND_2G,
1349                       WifiEnums.WIFI_CONFIG_SOFTAP_BAND_5G], False)
1350        # Restore config
1351        wutils.save_wifi_soft_ap_config(self.dut, original_softap_config)
1352