| #!/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. |
| |
| from enum import unique |
| |
| from antlion.controllers.ap_lib.hostapd_security import FuchsiaSecurityType |
| from antlion.controllers.fuchsia_lib.base_lib import BaseLib |
| from antlion.typing import StrEnum |
| |
| |
| @unique |
| class ConnectivityMode(StrEnum): |
| LOCAL_ONLY = "local_only" |
| UNRESTRICTED = "unrestricted" |
| |
| |
| @unique |
| class OperatingBand(StrEnum): |
| ANY = "any" |
| ONLY_2G = "only_2_4_ghz" |
| ONLY_5G = "only_5_ghz" |
| |
| |
| class FuchsiaWlanApPolicyLib(BaseLib): |
| def __init__(self, addr: str) -> None: |
| super().__init__(addr, "wlan_ap_policy") |
| |
| def wlanStartAccessPoint( |
| self, |
| target_ssid: str, |
| security_type: FuchsiaSecurityType, |
| target_pwd: str | None, |
| connectivity_mode: ConnectivityMode, |
| operating_band: OperatingBand, |
| ): |
| """Start an Access Point. |
| Args: |
| target_ssid: the network to attempt a connection to |
| security_type: the security protocol of the network |
| target_pwd: Credential being saved with the network. None is equivalent to |
| empty string. |
| connectivity_mode: the connectivity mode to use |
| operating_band: The operating band to use |
| |
| Returns: |
| boolean indicating if the action was successful |
| """ |
| |
| test_cmd = "wlan_ap_policy.start_access_point" |
| |
| # The SoftAP API uses "open" security instead of None and "" password |
| # instead of None. |
| test_args = { |
| "target_ssid": target_ssid, |
| "security_type": str(security_type), |
| "target_pwd": target_pwd or "", |
| "connectivity_mode": str(connectivity_mode), |
| "operating_band": str(operating_band), |
| } |
| |
| return self.send_command(test_cmd, test_args) |
| |
| def wlanStopAccessPoint( |
| self, target_ssid: str, security_type: FuchsiaSecurityType, target_pwd: str = "" |
| ): |
| """Stops an active Access Point. |
| Args: |
| target_ssid: the network to attempt a connection to |
| security_type: the security protocol of the network |
| target_pwd: (optional) credential being saved with the network. No password |
| is equivalent to empty string. |
| |
| Returns: |
| boolean indicating if the action was successful |
| """ |
| |
| test_cmd = "wlan_ap_policy.stop_access_point" |
| |
| test_args = { |
| "target_ssid": target_ssid, |
| "security_type": str(security_type), |
| "target_pwd": target_pwd, |
| } |
| |
| return self.send_command(test_cmd, test_args) |
| |
| def wlanStopAllAccessPoint(self): |
| """Stops all Access Points |
| |
| Returns: |
| boolean indicating if the actions were successful |
| """ |
| |
| test_cmd = "wlan_ap_policy.stop_all_access_points" |
| |
| return self.send_command(test_cmd, {}) |
| |
| def wlanSetNewListener(self): |
| """Sets the update listener stream of the facade to a new stream so that updates will be |
| reset. Intended to be used between tests so that the behaviour of updates in a test is |
| independent from previous tests. |
| """ |
| test_cmd = "wlan_ap_policy.set_new_update_listener" |
| |
| return self.send_command(test_cmd, {}) |
| |
| def wlanGetUpdate(self, timeout=30): |
| """Gets a list of AP state updates. This call will return with an update immediately the |
| first time the update listener is initialized by setting a new listener or by creating |
| a client controller before setting a new listener. Subsequent calls will hang until |
| there is an update. |
| Returns: |
| A list of AP state updated. If there is no error, the result is a list with a |
| structure that matches the FIDL AccessPointState struct given for updates. |
| """ |
| test_cmd = "wlan_ap_policy.get_update" |
| |
| return self.send_command(test_cmd, {}, response_timeout=timeout) |