wlancfg_config/
wlancfg-config_rust_config_lib_source.rs

1use fidl::unpersist;
2use fidl_cf_sc_internal_wlancfgconfig::Config as FidlConfig;
3use fuchsia_inspect::Node;
4use fuchsia_runtime::{take_startup_handle, HandleInfo, HandleType};
5#[derive(Debug)]
6pub struct Config {
7    pub recovery_enabled: bool,
8    pub recovery_profile: String,
9    pub roaming_policy: String,
10}
11impl Config {
12    pub fn take_from_startup_handle() -> Self {
13        let config_vmo: zx::Vmo =
14            take_startup_handle(HandleInfo::new(HandleType::ComponentConfigVmo, 0))
15                .expect("Config VMO handle must be provided and cannot already have been taken.")
16                .into();
17        let config_size =
18            config_vmo.get_content_size().expect("must be able to read config vmo content size");
19        assert_ne!(config_size, 0, "config vmo must be non-empty");
20        let config_bytes =
21            config_vmo.read_to_vec(0, config_size).expect("must be able to read config vmo");
22        let checksum_length = u16::from_le_bytes([config_bytes[0], config_bytes[1]]) as usize;
23        let fidl_start = 2 + checksum_length;
24        let observed_checksum = &config_bytes[2..fidl_start];
25        let expected_checksum = vec![
26            0x2d, 0xa1, 0x23, 0x8f, 0xed, 0x4c, 0x12, 0xcc, 0x54, 0x65, 0x24, 0x69, 0xda, 0xde,
27            0x03, 0x98, 0xc3, 0x0e, 0x9b, 0x91, 0xbf, 0xc2, 0x7c, 0x23, 0x1b, 0x2c, 0xa6, 0x4f,
28            0xe8, 0xef, 0x62, 0x45,
29        ];
30        assert_eq!(
31            observed_checksum, expected_checksum,
32            "checksum from config VMO does not match expected checksum"
33        );
34        let fidl_config: FidlConfig = unpersist(&config_bytes[fidl_start..])
35            .expect("must be able to parse bytes as config FIDL");
36        Self {
37            recovery_enabled: fidl_config.recovery_enabled,
38            recovery_profile: fidl_config.recovery_profile,
39            roaming_policy: fidl_config.roaming_policy,
40        }
41    }
42    pub fn record_inspect(&self, inspector_node: &Node) {
43        inspector_node.record_bool("recovery_enabled", self.recovery_enabled);
44        inspector_node.record_string("recovery_profile", &self.recovery_profile);
45        inspector_node.record_string("roaming_policy", &self.roaming_policy);
46    }
47}