matter_clusters/gen/
administrator_commissioning.rs1#![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
17pub const CLUSTER_ID: u32 = 0x003C;
19pub const CLUSTER_REVISION: u16 = 1;
21
22pub mod command_id {
24 pub const OPEN_COMMISSIONING_WINDOW: u32 = 0x00;
26 pub const OPEN_BASIC_COMMISSIONING_WINDOW: u32 = 0x01;
28 pub const REVOKE_COMMISSIONING: u32 = 0x02;
30}
31
32pub mod attribute_id {
34 pub const WINDOW_STATUS: u32 = 0x0000;
36 pub const ADMIN_FABRIC_INDEX: u32 = 0x0001;
38 pub const ADMIN_VENDOR_ID: u32 = 0x0002;
40}
41
42bitflags::bitflags! {
43 #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
45 pub struct Feature: u32 {
46 const BC = 1 << 0;
48 }
49}
50
51#[derive(Copy, Clone, Debug, PartialEq, Eq)]
53pub enum CommissioningWindowStatusEnum {
54 WindowNotOpen,
56 EnhancedWindowOpen,
58 BasicWindowOpen,
60 Unknown(u8),
62}
63
64impl CommissioningWindowStatusEnum {
65 #[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 #[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#[derive(Copy, Clone, Debug, PartialEq, Eq)]
89pub enum StatusCodeEnum {
90 Busy,
92 PakeParameterError,
94 WindowNotOpen,
96 Unknown(u8),
98}
99
100impl StatusCodeEnum {
101 #[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 #[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
123pub 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
142pub 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
166pub 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#[must_use]
192#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub 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#[must_use]
220#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub 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#[must_use]
234#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub 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}