Skip to main content

sl4f_lib/wlan/
facade.rs

1// Copyright 2018 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5use crate::wlan::types;
6use anyhow::{Context as _, Error};
7use fidl_fuchsia_wlan_device_service::{DeviceMonitorMarker, DeviceMonitorProxy};
8use fuchsia_component::client::connect_to_protocol;
9use fuchsia_sync::RwLock;
10
11// WlanFacade: proxies commands from sl4f test to proper fidl APIs
12//
13// This object is shared among all threads created by server.  The inner object is the facade
14// itself.  Callers interact with a wrapped version of the facade that enforces read/write
15// protection.
16//
17// Use: Create once per server instantiation.
18#[derive(Debug)]
19struct InnerWlanFacade {
20    // TODO(https://fxbug.dev/42165549)
21    #[allow(unused)]
22    scan_results: bool,
23}
24
25#[derive(Debug)]
26pub(crate) struct WlanFacade {
27    monitor_svc: DeviceMonitorProxy,
28    // TODO(https://fxbug.dev/42165549)
29    #[allow(unused)]
30    inner: RwLock<InnerWlanFacade>,
31}
32
33impl WlanFacade {
34    pub fn new() -> Result<WlanFacade, Error> {
35        let monitor_svc = connect_to_protocol::<DeviceMonitorMarker>()?;
36
37        Ok(WlanFacade { monitor_svc, inner: RwLock::new(InnerWlanFacade { scan_results: false }) })
38    }
39
40    pub async fn status(&self) -> Result<types::ClientStatusResponseDef, Error> {
41        // get the first client interface
42        let sme_proxy = wlan_service_util::client::get_first_sme(&self.monitor_svc)
43            .await
44            .context("Status: failed to get iface sme proxy")?;
45
46        let rsp = sme_proxy.status().await.context("failed to get status from sme_proxy")?;
47
48        Ok(rsp.into())
49    }
50}