| #!/usr/bin/env python3 |
| # |
| # Copyright 2022 The Fuchsia Authors |
| # |
| # Licensed under the Apache License, Version 2.0 (the "License"); |
| # you may not use this file except in compliance with the License. |
| # You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| # See the License for the specific language governing permissions and |
| # limitations under the License. |
| |
| import logging |
| |
| from mobly import asserts, test_runner |
| |
| from antlion import utils |
| from antlion.controllers.ap_lib.hostapd_security import FuchsiaSecurityType |
| from antlion.controllers.fuchsia_lib.wlan_ap_policy_lib import ( |
| ConnectivityMode, |
| OperatingBand, |
| ) |
| from antlion.controllers.fuchsia_lib.wlan_lib import WlanMacRole |
| from antlion.test_utils.abstract_devices.wlan_device import ( |
| AssociationMode, |
| create_wlan_device, |
| ) |
| from antlion.test_utils.wifi import base_test |
| |
| AP_ROLE = "Ap" |
| DEFAULT_SSID = "testssid" |
| TEST_MAC_ADDR = "12:34:56:78:9a:bc" |
| TEST_MAC_ADDR_SECONDARY = "bc:9a:78:56:34:12" |
| |
| |
| class WlanDeprecatedConfigurationTest(base_test.WifiBaseTest): |
| """Tests for WlanDeprecatedConfigurationFacade""" |
| |
| def setup_class(self): |
| super().setup_class() |
| self.log = logging.getLogger() |
| self.fuchsia_device = self.fuchsia_devices[0] |
| self.dut = create_wlan_device(self.fuchsia_device, AssociationMode.POLICY) |
| |
| def setup_test(self): |
| super().setup_test() |
| self._stop_soft_aps() |
| |
| def teardown_test(self): |
| self._stop_soft_aps() |
| super().teardown_test() |
| |
| def _get_ap_interface_mac_address(self): |
| """Retrieves mac address from wlan interface with role ap |
| |
| Returns: |
| string, the mac address of the AP interface |
| |
| Raises: |
| ConnectionError, if SL4F calls fail |
| AttributeError, if no interface has role 'Ap' |
| """ |
| for wlan_iface in self.dut.get_wlan_interface_id_list(): |
| result = self.fuchsia_device.sl4f.wlan_lib.query_iface(wlan_iface) |
| if result.role is WlanMacRole.AP: |
| return utils.mac_address_list_to_str(bytes(result.sta_addr)) |
| raise AttributeError( |
| "Failed to get ap interface mac address. No AP interface found." |
| ) |
| |
| def _start_soft_ap(self): |
| """Starts SoftAP on DUT. |
| |
| Raises: |
| ConnectionError, if SL4F call fails. |
| """ |
| self.log.info(f"Starting SoftAP on device {self.dut.identifier}") |
| response = self.fuchsia_device.sl4f.wlan_ap_policy_lib.wlanStartAccessPoint( |
| DEFAULT_SSID, |
| FuchsiaSecurityType.NONE, |
| None, |
| ConnectivityMode.LOCAL_ONLY, |
| OperatingBand.ANY, |
| ) |
| if response.get("error"): |
| raise ConnectionError(f"Failed to setup SoftAP: {response['error']}") |
| |
| def _stop_soft_aps(self): |
| """Stops SoftAP on DUT. |
| |
| Raises: |
| ConnectionError, if SL4F call fails. |
| """ |
| self.log.info("Stopping SoftAP.") |
| response = self.fuchsia_device.sl4f.wlan_ap_policy_lib.wlanStopAllAccessPoint() |
| if response.get("error"): |
| raise ConnectionError(f"Failed to stop SoftAP: {response['error']}") |
| |
| def _suggest_ap_mac_addr(self, mac_addr): |
| """Suggests mac address for AP interface. |
| Args: |
| mac_addr: string, mac address to suggest. |
| |
| Raises: |
| TestFailure, if SL4F call fails. |
| """ |
| self.log.info( |
| f"Suggesting AP mac addr ({mac_addr}) via wlan_deprecated_configuration_lib." |
| ) |
| response = self.fuchsia_device.sl4f.wlan_deprecated_configuration_lib.wlanSuggestAccessPointMacAddress( |
| mac_addr |
| ) |
| if response.get("error"): |
| asserts.fail( |
| f"Failed to suggest AP mac address ({mac_addr}): {response['error']}" |
| ) |
| |
| def _verify_mac_addr(self, expected_addr): |
| """Verifies mac address of ap interface is set to expected mac address. |
| |
| Args: |
| Args: |
| expected_addr: string, expected mac address |
| |
| Raises: |
| TestFailure, if actual mac address is not expected mac address. |
| """ |
| set_mac_addr = self._get_ap_interface_mac_address() |
| if set_mac_addr != expected_addr: |
| asserts.fail( |
| f"Failed to set AP mac address via wlan_deprecated_configuration_lib. " |
| f"Expected mac addr: {expected_addr}, Actual mac addr: {set_mac_addr}" |
| ) |
| else: |
| self.log.info(f"AP mac address successfully set to {expected_addr}") |
| |
| def test_suggest_ap_mac_address(self): |
| """Tests suggest ap mac address SL4F call |
| |
| 1. Get initial mac address |
| 2. Suggest new mac address |
| 3. Verify new mac address is set successfully |
| 4. Reset to initial mac address |
| 5. Verify initial mac address is reset successfully |
| |
| |
| Raises: |
| TestFailure, if wlanSuggestAccessPointMacAddress call fails or |
| of mac address is not the suggest value |
| ConnectionError, if other SL4F calls fail |
| """ |
| # Retrieve initial ap mac address |
| self._start_soft_ap() |
| |
| self.log.info("Getting initial mac address.") |
| initial_mac_addr = self._get_ap_interface_mac_address() |
| self.log.info(f"Initial mac address: {initial_mac_addr}") |
| |
| if initial_mac_addr != TEST_MAC_ADDR: |
| suggested_mac_addr = TEST_MAC_ADDR |
| else: |
| suggested_mac_addr = TEST_MAC_ADDR_SECONDARY |
| |
| self._stop_soft_aps() |
| |
| # Suggest and verify new mac address |
| self._suggest_ap_mac_addr(suggested_mac_addr) |
| |
| self._start_soft_ap() |
| |
| self._verify_mac_addr(suggested_mac_addr) |
| |
| self._stop_soft_aps() |
| |
| # Reset to initial mac address and verify |
| self.log.info(f"Resetting to initial mac address ({initial_mac_addr}).") |
| self._suggest_ap_mac_addr(initial_mac_addr) |
| |
| self._start_soft_ap() |
| |
| self._verify_mac_addr(initial_mac_addr) |
| |
| |
| if __name__ == "__main__": |
| test_runner.main() |