1#!/usr/bin/env python3.4
2#
3#   Copyright 2024 - 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
17from acts.controllers.ap_lib import hostapd_constants
18import acts.signals as signals
19import acts_contrib.test_utils.wifi.wifi_test_utils as wutils
20from acts_contrib.test_utils.wifi.WifiBaseTest import WifiBaseTest
21
22
23class WifiEdgeChannelsTest(WifiBaseTest):
24  """Tests for Wifi Edge Channel Connection.
25
26  Test Bed Requirement:
27  * One Android devices and an AP.
28  * 2GHz and 5GHz Wi-Fi network visible to the device.
29  """
30
31  def setup_class(self):
32    super().setup_class()
33
34    self.dut = self.android_devices[0]
35    wutils.wifi_test_device_init(self.dut)
36    wutils.wifi_toggle_state(self.dut, True)
37    req_params = ["wifi6_models",]
38    opt_param = ["reference_networks", "pixel_models"]
39    self.unpack_userparams(req_param_names=req_params,
40                           opt_param_names=opt_param)
41
42  def setup_test(self):
43    self.dut.droid.wakeLockAcquireBright()
44    self.dut.droid.wakeUpNow()
45
46  def teardown_test(self):
47    super().teardown_test()
48    self.dut.droid.wakeLockRelease()
49    self.dut.droid.goToSleepNow()
50
51  def configure_ap(self, channel_2g=None, channel_5g=None):
52    """Configure and bring up AP on required channel.
53
54    Args:
55        channel_2g: The channel number to use for 2GHz network.
56        channel_5g: The channel number to use for 5GHz network.
57
58    """
59    if not channel_2g:
60      channel_2g = hostapd_constants.AP_DEFAULT_CHANNEL_2G
61    if not channel_5g:
62      channel_5g = hostapd_constants.AP_DEFAULT_CHANNEL_5G
63    if "OpenWrtAP" in self.user_params:
64      self.openwrt = self.access_points[0]
65      self.configure_openwrt_ap_and_start(
66          wpa_network=True,
67          channel_2g=channel_2g,
68          channel_5g=channel_5g)
69
70  def verify_wifi_connection(self, channel_2g=None, channel_5g=None):
71    """Verify wifi connection on given channel.
72    Args:
73        channel_2g: The channel number to use for 2GHz network.
74        channel_5g: The channel number to use for 5GHz network.
75    """
76    self.configure_ap(channel_2g=channel_2g, channel_5g=channel_5g)
77    if channel_2g:
78      network = self.reference_networks[0]["2g"]
79    elif channel_5g:
80      network = self.reference_networks[0]["5g"]
81    else :
82      raise signals.TestError("No channel specified")
83
84    wutils.connect_to_wifi_network(self.dut, network)
85    wutils.verify_11ax_wifi_connection(self.dut, self.wifi6_models,
86                                       "wifi6_ap" in self.user_params)
87    self.dut.log.info("Current network = %s" %
88                       self.dut.droid.wifiGetConnectionInfo())
89    try:
90      self.dut.ed.clear_all_events()
91      wutils.wait_for_disconnect(self.dut, timeout=180)
92    except:
93      self.dut.log.info("Disconnection not happened (as expected)")
94    else:
95      self.dut.log.info("Unexpected disconnection happened")
96      raise signals.TestFailure("Unexpected disconnection happened")
97
98  def test_wifi_connect_edge_channel_64(self):
99    """Test to connect 5G edge channel 64."""
100    self.verify_wifi_connection(channel_5g=64)
101
102  def test_wifi_connect_edge_channel_144(self):
103    """Test to connect 5G edge channel 144."""
104    self.verify_wifi_connection(channel_5g=144)
105