Add support for create_iface support in wlan_lib
This change implements the newly introduced (https://fxrev.dev/919754)
wlanCreateIface() method in wlan_lib, which allows us to create
interfaces manually in WLAN sl4f tests.
Change-Id: I1fb4caf85cf5c566af790cf7427b1634488a4690
Reviewed-on: https://fuchsia-review.googlesource.com/c/antlion/+/919834
Reviewed-by: Kevin Sakuma <sakuma@google.com>
Reviewed-by: Sam Balana <sbalana@google.com>
Commit-Queue: Zhiyi Chen <zhiyichen@google.com>
diff --git a/packages/antlion/controllers/fuchsia_lib/wlan_lib.py b/packages/antlion/controllers/fuchsia_lib/wlan_lib.py
index 48bc43e..ae9fe55 100644
--- a/packages/antlion/controllers/fuchsia_lib/wlan_lib.py
+++ b/packages/antlion/controllers/fuchsia_lib/wlan_lib.py
@@ -28,6 +28,7 @@
COMMAND_STATUS = "wlan.status"
COMMAND_GET_IFACE_ID_LIST = "wlan.get_iface_id_list"
COMMAND_GET_PHY_ID_LIST = "wlan.get_phy_id_list"
+COMMAND_CREATE_IFACE = "wlan.create_iface"
COMMAND_DESTROY_IFACE = "wlan.destroy_iface"
COMMAND_GET_COUNTRY = "wlan_phy.get_country"
COMMAND_GET_DEV_PATH = "wlan_phy.get_dev_path"
@@ -52,6 +53,11 @@
@dataclass(frozen=True)
+class CreateIfaceResult:
+ interface_id: int
+
+
+@dataclass(frozen=True)
class QueryIfaceResult:
"""Result of the wlan.query_iface command.
@@ -120,6 +126,38 @@
return self.send_command(test_cmd, {})
+ def wlanCreateIface(
+ self, phy_id: int, role: WlanMacRole, sta_addr: str | None = None
+ ) -> CreateIfaceResult:
+ """Create a new WLAN interface.
+ Args:
+ phy_id: the interface id.
+ role: the role of new interface.
+ sta_addr: MAC address for softAP interface only.
+
+ Returns:
+ Dictionary, service id if success, error if error.
+
+ Raises:
+ WlanError: Device responded with an error.
+ """
+ test_cmd = COMMAND_CREATE_IFACE
+ test_args = {
+ "phy_id": phy_id,
+ "role": role,
+ "sta_addr": sta_addr,
+ }
+
+ resp = MapValidator(self.send_command(test_cmd, test_args))
+ err = resp.get(str, "error", None)
+ if err is not None:
+ raise WlanError(f'Failed to create wlan iface: "{err}"')
+
+ iface_id = resp.get(int, "result")
+ return CreateIfaceResult(
+ interface_id=iface_id,
+ )
+
def wlanDestroyIface(self, iface_id):
"""Destroy WLAN interface by ID.
Args: