matc/clusters/codec/
wifi_network_management.rs1use crate::tlv;
7use anyhow;
8use serde_json;
9
10
11pub fn decode_ssid(inp: &tlv::TlvItemValue) -> anyhow::Result<Option<Vec<u8>>> {
17 if let tlv::TlvItemValue::OctetString(v) = inp {
18 Ok(Some(v.clone()))
19 } else {
20 Ok(None)
21 }
22}
23
24pub fn decode_passphrase_surrogate(inp: &tlv::TlvItemValue) -> anyhow::Result<Option<u64>> {
26 if let tlv::TlvItemValue::Int(v) = inp {
27 Ok(Some(*v))
28 } else {
29 Ok(None)
30 }
31}
32
33
34pub fn decode_attribute_json(cluster_id: u32, attribute_id: u32, tlv_value: &crate::tlv::TlvItemValue) -> String {
46 if cluster_id != 0x0451 {
48 return format!("{{\"error\": \"Invalid cluster ID. Expected 0x0451, got {}\"}}", cluster_id);
49 }
50
51 match attribute_id {
52 0x0000 => {
53 match decode_ssid(tlv_value) {
54 Ok(value) => serde_json::to_string(&value).unwrap_or_else(|_| "null".to_string()),
55 Err(e) => format!("{{\"error\": \"{}\"}}", e),
56 }
57 }
58 0x0001 => {
59 match decode_passphrase_surrogate(tlv_value) {
60 Ok(value) => serde_json::to_string(&value).unwrap_or_else(|_| "null".to_string()),
61 Err(e) => format!("{{\"error\": \"{}\"}}", e),
62 }
63 }
64 _ => format!("{{\"error\": \"Unknown attribute ID: {}\"}}", attribute_id),
65 }
66}
67
68pub fn get_attribute_list() -> Vec<(u32, &'static str)> {
73 vec![
74 (0x0000, "SSID"),
75 (0x0001, "PassphraseSurrogate"),
76 ]
77}
78