matter-kit 0.3.0

Matter (CSA smart-home standard) protocol implementation in Rust: no_std, no-alloc, executor-agnostic
Documentation
// Generated by `cargo xtask` from the CSA data model 1.6. Do not edit.
//
// Wi-Fi Network Management — cluster 0x0451.
//
// Regenerate with `cargo xtask clusters --dm <checkout>/data_model/1.6`; `cargo xtask check`
// is the CI gate that keeps this file honest. The XML itself is not vendored here — it
// carries the CSA's own copyright notice and is not redistributable.

//! Wi-Fi Network Management (cluster `0x0451`, revision 1).
//!
//! 4 identifiers, 0 feature bits, and the specification's own conformance for
//! every element. `CLUSTER` is the whole table.

#![allow(unused_imports)]

use crate::dm::conformance::{Clause, Condition, Conform, Conformance};
use crate::dm::meta::{EventPriority, Reporting};
use crate::dm::spec::{Attribute, Cluster, Command, Event, Feature};
use crate::dm::{Access, AccessQualities, AttributeQualities, Privilege};
use crate::error::Result;
use crate::im::{AttributeId, ClusterId, CommandId, EventId};
use crate::tlv::{
    ContainerKind, Element, FromTlv, Nullable, Tag, TlvList, TlvReader, TlvWriter, ToTlv, Value,
};

/// The cluster id.
pub const ID: ClusterId = 0x0451;

/// The highest revision the specification's history defines — what `ClusterRevision`
/// must report (Core §7.13.1).
pub const REVISION: u16 = 1;

/// The PICS code, which a certification declaration names the cluster by.
pub const PICS: &str = "WIFINM";

/// This cluster defines no features, so its `FeatureMap` is always zero.
pub const FEATURES: &[Feature] = &[];

/// The attribute ids.
pub mod attribute {
    use crate::im::AttributeId;

    /// `SSID`.
    pub const SSID: AttributeId = 0x00;
    /// `PassphraseSurrogate`.
    pub const PASSPHRASE_SURROGATE: AttributeId = 0x01;
}

/// The command ids.
pub mod command {
    use crate::im::CommandId;

    /// `NetworkPassphraseRequest`.
    pub const NETWORK_PASSPHRASE_REQUEST: CommandId = 0x00;
    /// `NetworkPassphraseResponse`.
    pub const NETWORK_PASSPHRASE_RESPONSE: CommandId = 0x01;
}

/// The fields of `NetworkPassphraseResponse` (command `0x01`).
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct NetworkPassphraseResponseFields<'a> {
    /// `Passphrase`, field 0.
    pub passphrase: &'a [u8],
}

impl<'a> ToTlv for NetworkPassphraseResponseFields<'a> {
    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
        w.start_structure(tag)?;
        self.passphrase.to_tlv(w, Tag::Context(0))?;
        w.end_container()
    }
}

impl<'a> FromTlv<'a> for NetworkPassphraseResponseFields<'a> {
    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
        if element.value.container() != Some(ContainerKind::Structure) {
            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
        }
        let mut passphrase = None;
        loop {
            let Some(field) = reader.next_element()? else {
                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
            };
            if field.value == Value::EndOfContainer {
                break;
            }
            match field.tag.context() {
                Some(0) => passphrase = Some(<&'a [u8]>::from_tlv(reader, &field)?),
                // A field this revision does not define. §7.19.2: a receiver
                // ignores what it does not know rather than refusing the whole
                // structure, which is what lets a newer peer talk to an older one.
                _ => reader.skip_value(&field)?,
            }
        }
        Ok(Self {
            passphrase: passphrase.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
        })
    }
}

/// Every attribute the specification defines, with its conformance.
pub const ATTRIBUTES: &[Attribute] = &[
    Attribute {
        id: 0x0000,
        name: "SSID",
        kind: "octstr",
        access: Access::read_only(Privilege::View),
        qualities: AttributeQualities::NULLABLE.union(AttributeQualities::NON_VOLATILE),
        reporting: Reporting::OnChange,
        conform: Conform::MANDATORY,
    },
    Attribute {
        id: 0x0001,
        name: "PassphraseSurrogate",
        kind: "uint64",
        access: Access::read_only(Privilege::Manage),
        qualities: AttributeQualities::NULLABLE.union(AttributeQualities::NON_VOLATILE),
        reporting: Reporting::OnChange,
        conform: Conform::MANDATORY,
    },
];

/// Every command, with its conformance.
pub const COMMANDS: &[Command] = &[
    Command {
        id: 0x00,
        name: "NetworkPassphraseRequest",
        to_server: true,
        response: Some(0x01),
        access: Access::invoke(Privilege::Manage),
        conform: Conform::MANDATORY,
    },
    Command {
        id: 0x01,
        name: "NetworkPassphraseResponse",
        to_server: false,
        response: None,
        access: Access::invoke(Privilege::Operate),
        conform: Conform::MANDATORY,
    },
];

/// Every event, with its conformance.
pub const EVENTS: &[Event] = &[];

/// The whole cluster, as the specification defines it.
pub const CLUSTER: Cluster = Cluster {
    id: ID,
    name: "Wi-Fi Network Management",
    revision: REVISION,
    pics: "WIFINM",
    derived_from: None,
    features: FEATURES,
    attributes: ATTRIBUTES,
    commands: COMMANDS,
    events: EVENTS,
};