Skip to main content

matter_clusters/gen/
administrator_commissioning.rs

1//! AdministratorCommissioning cluster (0x003C).
2//! @generated by `cargo xtask codegen` — do not edit.
3
4#![allow(
5    clippy::all,
6    clippy::pedantic,
7    dead_code,
8    unreachable_pub,
9    unused_imports
10)]
11
12use crate::datatypes::SemanticTagStruct;
13use crate::error::ClusterError;
14use crate::types::Nullable;
15use matter_codec::{ContainerKind, Element, Tag, TlvReader, TlvWriter, Value};
16
17/// Cluster ID.
18pub const CLUSTER_ID: u32 = 0x003C;
19/// Cluster revision.
20pub const CLUSTER_REVISION: u16 = 1;
21
22/// Command IDs (requests and responses).
23pub mod command_id {
24    /// `OpenCommissioningWindow` (request).
25    pub const OPEN_COMMISSIONING_WINDOW: u32 = 0x00;
26    /// `OpenBasicCommissioningWindow` (request).
27    pub const OPEN_BASIC_COMMISSIONING_WINDOW: u32 = 0x01;
28    /// `RevokeCommissioning` (request).
29    pub const REVOKE_COMMISSIONING: u32 = 0x02;
30}
31
32/// Attribute IDs (cluster-specific).
33pub mod attribute_id {
34    /// `WindowStatus`.
35    pub const WINDOW_STATUS: u32 = 0x0000;
36    /// `AdminFabricIndex`.
37    pub const ADMIN_FABRIC_INDEX: u32 = 0x0001;
38    /// `AdminVendorId`.
39    pub const ADMIN_VENDOR_ID: u32 = 0x0002;
40}
41
42bitflags::bitflags! {
43    /// `AdministratorCommissioning` feature bits (FeatureMap).
44    #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
45    pub struct Feature: u32 {
46        /// Basic (BC).
47        const BC = 1 << 0;
48    }
49}
50
51/// `CommissioningWindowStatusEnum` (enum8).
52#[derive(Copy, Clone, Debug, PartialEq, Eq)]
53pub enum CommissioningWindowStatusEnum {
54    /// WindowNotOpen = 0.
55    WindowNotOpen,
56    /// EnhancedWindowOpen = 1.
57    EnhancedWindowOpen,
58    /// BasicWindowOpen = 2.
59    BasicWindowOpen,
60    /// A value not known to this codegen revision.
61    Unknown(u8),
62}
63
64impl CommissioningWindowStatusEnum {
65    /// Decode from its raw discriminant (unknown → `Unknown`).
66    #[must_use]
67    pub fn from_raw(v: u8) -> Self {
68        match v {
69            0 => Self::WindowNotOpen,
70            1 => Self::EnhancedWindowOpen,
71            2 => Self::BasicWindowOpen,
72            other => Self::Unknown(other),
73        }
74    }
75    /// The raw discriminant.
76    #[must_use]
77    pub fn to_raw(self) -> u8 {
78        match self {
79            Self::WindowNotOpen => 0,
80            Self::EnhancedWindowOpen => 1,
81            Self::BasicWindowOpen => 2,
82            Self::Unknown(v) => v,
83        }
84    }
85}
86
87/// `StatusCodeEnum` (enum8).
88#[derive(Copy, Clone, Debug, PartialEq, Eq)]
89pub enum StatusCodeEnum {
90    /// Busy = 2.
91    Busy,
92    /// PakeParameterError = 3.
93    PakeParameterError,
94    /// WindowNotOpen = 4.
95    WindowNotOpen,
96    /// A value not known to this codegen revision.
97    Unknown(u8),
98}
99
100impl StatusCodeEnum {
101    /// Decode from its raw discriminant (unknown → `Unknown`).
102    #[must_use]
103    pub fn from_raw(v: u8) -> Self {
104        match v {
105            2 => Self::Busy,
106            3 => Self::PakeParameterError,
107            4 => Self::WindowNotOpen,
108            other => Self::Unknown(other),
109        }
110    }
111    /// The raw discriminant.
112    #[must_use]
113    pub fn to_raw(self) -> u8 {
114        match self {
115            Self::Busy => 2,
116            Self::PakeParameterError => 3,
117            Self::WindowNotOpen => 4,
118            Self::Unknown(v) => v,
119        }
120    }
121}
122
123/// Decode the `WindowStatus` attribute value.
124///
125/// # Errors
126/// Returns [`ClusterError`] on a type mismatch or out-of-range value.
127pub fn decode_window_status(tlv: &[u8]) -> Result<CommissioningWindowStatusEnum, ClusterError> {
128    let mut r = TlvReader::new(tlv);
129    match r.next()? {
130        Some(Element::Scalar {
131            value: Value::Uint(v),
132            ..
133        }) => Ok(CommissioningWindowStatusEnum::from_raw(
134            u8::try_from(v).map_err(|_| ClusterError::InvalidLength("WindowStatus"))?,
135        )),
136        _ => Err(ClusterError::UnexpectedType {
137            context: "WindowStatus",
138        }),
139    }
140}
141
142/// Decode the `AdminFabricIndex` attribute value.
143///
144/// # Errors
145/// Returns [`ClusterError`] on a type mismatch or out-of-range value.
146pub fn decode_admin_fabric_index(tlv: &[u8]) -> Result<Nullable<u8>, ClusterError> {
147    let mut r = TlvReader::new(tlv);
148    match r.next()? {
149        Some(Element::Scalar {
150            value: Value::Null, ..
151        }) => Ok(Nullable::Null),
152        Some(Element::Scalar {
153            value: Value::Uint(v),
154            ..
155        }) => {
156            Ok(Nullable::Value(u8::try_from(v).map_err(|_| {
157                ClusterError::InvalidLength("AdminFabricIndex")
158            })?))
159        }
160        _ => Err(ClusterError::UnexpectedType {
161            context: "AdminFabricIndex",
162        }),
163    }
164}
165
166/// Decode the `AdminVendorId` attribute value.
167///
168/// # Errors
169/// Returns [`ClusterError`] on a type mismatch or out-of-range value.
170pub fn decode_admin_vendor_id(tlv: &[u8]) -> Result<Nullable<u16>, ClusterError> {
171    let mut r = TlvReader::new(tlv);
172    match r.next()? {
173        Some(Element::Scalar {
174            value: Value::Null, ..
175        }) => Ok(Nullable::Null),
176        Some(Element::Scalar {
177            value: Value::Uint(v),
178            ..
179        }) => {
180            Ok(Nullable::Value(u16::try_from(v).map_err(|_| {
181                ClusterError::InvalidLength("AdminVendorId")
182            })?))
183        }
184        _ => Err(ClusterError::UnexpectedType {
185            context: "AdminVendorId",
186        }),
187    }
188}
189
190/// Encode the `OpenCommissioningWindow` command request payload.
191#[must_use]
192#[allow(clippy::expect_used, clippy::missing_panics_doc)] // Vec-backed TlvWriter is infallible.
193pub fn encode_open_commissioning_window(
194    commissioning_timeout: u16,
195    pake_passcode_verifier: &Vec<u8>,
196    discriminator: u16,
197    iterations: u32,
198    salt: &Vec<u8>,
199) -> Vec<u8> {
200    let mut buf = Vec::new();
201    let mut w = TlvWriter::new(&mut buf);
202    w.start_structure(Tag::Anonymous)
203        .expect("infallible: vec writer");
204    w.put_uint(Tag::Context(0), u64::from(commissioning_timeout))
205        .expect("infallible: vec writer");
206    w.put_bytes(Tag::Context(1), &pake_passcode_verifier)
207        .expect("infallible: vec writer");
208    w.put_uint(Tag::Context(2), u64::from(discriminator))
209        .expect("infallible: vec writer");
210    w.put_uint(Tag::Context(3), u64::from(iterations))
211        .expect("infallible: vec writer");
212    w.put_bytes(Tag::Context(4), &salt)
213        .expect("infallible: vec writer");
214    w.end_container().expect("infallible: vec writer");
215    buf
216}
217
218/// Encode the `OpenBasicCommissioningWindow` command request payload.
219#[must_use]
220#[allow(clippy::expect_used, clippy::missing_panics_doc)] // Vec-backed TlvWriter is infallible.
221pub fn encode_open_basic_commissioning_window(commissioning_timeout: u16) -> Vec<u8> {
222    let mut buf = Vec::new();
223    let mut w = TlvWriter::new(&mut buf);
224    w.start_structure(Tag::Anonymous)
225        .expect("infallible: vec writer");
226    w.put_uint(Tag::Context(0), u64::from(commissioning_timeout))
227        .expect("infallible: vec writer");
228    w.end_container().expect("infallible: vec writer");
229    buf
230}
231
232/// Encode the `RevokeCommissioning` command request payload.
233#[must_use]
234#[allow(clippy::expect_used, clippy::missing_panics_doc)] // Vec-backed TlvWriter is infallible.
235pub fn encode_revoke_commissioning() -> Vec<u8> {
236    let mut buf = Vec::new();
237    let mut w = TlvWriter::new(&mut buf);
238    w.start_structure(Tag::Anonymous)
239        .expect("infallible: vec writer");
240    w.end_container().expect("infallible: vec writer");
241    buf
242}