sl4f_lib/wlan_deprecated/
facade.rs1use anyhow::{format_err, Error};
6use fidl_fuchsia_wlan_product_deprecatedconfiguration as fidl_deprecated;
7use fuchsia_component::client::connect_to_protocol;
8use fuchsia_sync::RwLock;
9use std::fmt::Debug;
10
11#[derive(Debug)]
12struct InnerWlanDeprecatedConfigurationFacade {
13 controller: fidl_deprecated::DeprecatedConfiguratorProxy,
14}
15
16#[derive(Debug)]
17pub struct WlanDeprecatedConfigurationFacade {
18 inner: RwLock<InnerWlanDeprecatedConfigurationFacade>,
19}
20
21impl WlanDeprecatedConfigurationFacade {
22 pub fn new() -> Result<WlanDeprecatedConfigurationFacade, Error> {
26 let controller = connect_to_protocol::<fidl_deprecated::DeprecatedConfiguratorMarker>()?;
27 Ok(Self {
28 inner: RwLock::new(InnerWlanDeprecatedConfigurationFacade { controller: controller }),
29 })
30 }
31
32 pub async fn suggest_access_point_mac_address(
40 &self,
41 mac: eui48::MacAddress,
42 ) -> Result<(), Error> {
43 let inner_guard = self.inner.read();
44 let controller = &inner_guard.controller;
45
46 let mac = fidl_fuchsia_net::MacAddress { octets: mac.to_array() };
47 let result = controller.suggest_access_point_mac_address(&mac).await?;
48 result.map_err(|e| format_err!("could not set preferred MAC: {:?}", e))
49 }
50
51 pub fn parse_mac_argument(&self, args: serde_json::Value) -> Result<eui48::MacAddress, Error> {
58 let mac = match args.get("mac") {
59 Some(mac) => match mac.as_str() {
60 Some(mac) => eui48::MacAddress::parse_str(mac)?,
61 None => {
62 return Err(format_err!(
63 "MAC address could not be interpreted as a string: {:?}",
64 mac
65 ))
66 }
67 },
68 None => return Err(format_err!("Please provide a preferred MAC")),
69 };
70 Ok(mac)
71 }
72}