matc/clusters/codec/
wifi_network_management.rs

1//! Generated Matter TLV encoders and decoders for Wi-Fi Network Management Cluster
2//! Cluster ID: 0x0451
3//! 
4//! This file is automatically generated from WiFiNetworkManagement.xml
5
6use crate::tlv;
7use anyhow;
8use serde_json;
9
10
11// Command encoders
12
13// Attribute decoders
14
15/// Decode SSID attribute (0x0000)
16pub 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
24/// Decode PassphraseSurrogate attribute (0x0001)
25pub 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
34// JSON dispatcher function
35
36/// Decode attribute value and return as JSON string
37/// 
38/// # Parameters
39/// * `cluster_id` - The cluster identifier
40/// * `attribute_id` - The attribute identifier
41/// * `tlv_value` - The TLV value to decode
42/// 
43/// # Returns
44/// JSON string representation of the decoded value or error
45pub fn decode_attribute_json(cluster_id: u32, attribute_id: u32, tlv_value: &crate::tlv::TlvItemValue) -> String {
46    // Verify this is the correct cluster
47    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
68/// Get list of all attributes supported by this cluster
69/// 
70/// # Returns
71/// Vector of tuples containing (attribute_id, attribute_name)
72pub fn get_attribute_list() -> Vec<(u32, &'static str)> {
73    vec![
74        (0x0000, "SSID"),
75        (0x0001, "PassphraseSurrogate"),
76    ]
77}
78