blob: 0981d953bcc183e7caec417943c4e739819e5aa7 [file] [log] [blame]
#!/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 StrEnum, auto, unique
from antlion.controllers.ap_lib.hostapd_security import FuchsiaSecurityType
from antlion.controllers.fuchsia_lib.base_lib import BaseLib
@unique
class ConnectivityMode(StrEnum):
"""Connectivity operating mode for the AP.
Defined by the fuchsia.wlan.policy FIDL and mapped by the SL4F wlan_policy facade.
https://cs.opensource.google/fuchsia/fuchsia/+/48dd18fe663ad902ecb7f70a45ce19fa605e96b6:sdk/fidl/fuchsia.wlan.policy/access_point_provider.fidl;l=100
https://cs.opensource.google/fuchsia/fuchsia/+/48dd18fe663ad902ecb7f70a45ce19fa605e96b6:src/testing/sl4f/src/wlan_policy/commands.rs;l=200
"""
LOCAL_ONLY = "local_only"
"""Allows for connectivity between co-located devices; does not forward traffic to
other network connections."""
UNRESTRICTED = "unrestricted"
"""Allows for full connectivity with traffic potentially being forwarded
to other network connections (e.g. tethering mode)."""
@unique
class OperatingBand(StrEnum):
"""Operating band for wlan control request and status updates.
Defined by the fuchsia.wlan.policy FIDL and mapped by the SL4F wlan_policy facade.
https://cs.opensource.google/fuchsia/fuchsia/+/48dd18fe663ad902ecb7f70a45ce19fa605e96b6:sdk/fidl/fuchsia.wlan.policy/types.fidl;l=54
https://cs.opensource.google/fuchsia/fuchsia/+/48dd18fe663ad902ecb7f70a45ce19fa605e96b6:src/testing/sl4f/src/wlan_policy/commands.rs;l=183
"""
ANY = "any"
"""Allows for band switching depending on device operating mode and environment."""
ONLY_2G = "only_2_4_ghz"
"""Restricted to 2.4 GHz bands only."""
ONLY_5G = "only_5_ghz"
"""Restricted to 5 GHz bands only."""
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)