Skip to main content

matter_kit/clusters/generated/
tls_client_management.rs

1// Generated by `cargo xtask` from the CSA data model 1.6. Do not edit.
2//
3// TLS Client Management — cluster 0x0802.
4//
5// Regenerate with `cargo xtask clusters --dm <checkout>/data_model/1.6`; `cargo xtask check`
6// is the CI gate that keeps this file honest. The XML itself is not vendored here — it
7// carries the CSA's own copyright notice and is not redistributable.
8
9//! TLS Client Management (cluster `0x0802`, revision 1).
10//!
11//! 7 identifiers, 0 feature bits, and the specification's own conformance for
12//! every element. `CLUSTER` is the whole table.
13
14#![allow(unused_imports)]
15
16use crate::dm::conformance::{Clause, Condition, Conform, Conformance};
17use crate::dm::meta::{EventPriority, Reporting};
18use crate::dm::spec::{Attribute, Cluster, Command, Event, Feature};
19use crate::dm::{Access, AccessQualities, AttributeQualities, Privilege};
20use crate::error::Result;
21use crate::im::{AttributeId, ClusterId, CommandId, EventId};
22use crate::tlv::{
23    ContainerKind, Element, FromTlv, Nullable, Tag, TlvList, TlvReader, TlvWriter, ToTlv, Value,
24};
25
26/// The cluster id.
27pub const ID: ClusterId = 0x0802;
28
29/// The highest revision the specification's history defines — what `ClusterRevision`
30/// must report (Core §7.13.1).
31pub const REVISION: u16 = 1;
32
33/// The PICS code, which a certification declaration names the cluster by.
34pub const PICS: &str = "TLSCLIENT";
35
36/// This cluster defines no features, so its `FeatureMap` is always zero.
37pub const FEATURES: &[Feature] = &[];
38
39/// The attribute ids.
40pub mod attribute {
41    use crate::im::AttributeId;
42
43    /// `MaxProvisioned`.
44    pub const MAX_PROVISIONED: AttributeId = 0x00;
45    /// `ProvisionedEndpoints`.
46    pub const PROVISIONED_ENDPOINTS: AttributeId = 0x01;
47}
48
49/// The command ids.
50pub mod command {
51    use crate::im::CommandId;
52
53    /// `ProvisionEndpoint`.
54    pub const PROVISION_ENDPOINT: CommandId = 0x00;
55    /// `ProvisionEndpointResponse`.
56    pub const PROVISION_ENDPOINT_RESPONSE: CommandId = 0x01;
57    /// `FindEndpoint`.
58    pub const FIND_ENDPOINT: CommandId = 0x02;
59    /// `FindEndpointResponse`.
60    pub const FIND_ENDPOINT_RESPONSE: CommandId = 0x03;
61    /// `RemoveEndpoint`.
62    pub const REMOVE_ENDPOINT: CommandId = 0x04;
63}
64
65/// `StatusCodeEnum`.
66#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
67#[repr(u8)]
68pub enum StatusCodeEnum {
69    /// The endpoint is already installed.
70    EndpointAlreadyInstalled = 2,
71    /// No root certificate exists for this CAID.
72    RootCertificateNotFound = 3,
73    /// No client certificate exists for this CCDID.
74    ClientCertificateNotFound = 4,
75    /// The endpoint is in use and cannot be removed.
76    EndpointInUse = 5,
77    /// Time sync has not yet occurred.
78    InvalidTime = 6,
79}
80
81impl StatusCodeEnum {
82    /// Reads a wire value, or `None` for one this revision does not define.
83    #[must_use]
84    pub const fn from_value(value: u8) -> Option<Self> {
85        match value {
86            2 => Some(Self::EndpointAlreadyInstalled),
87            3 => Some(Self::RootCertificateNotFound),
88            4 => Some(Self::ClientCertificateNotFound),
89            5 => Some(Self::EndpointInUse),
90            6 => Some(Self::InvalidTime),
91            _ => None,
92        }
93    }
94
95    /// Its wire value.
96    #[must_use]
97    pub const fn value(self) -> u8 {
98        self as u8
99    }
100}
101
102impl ToTlv for StatusCodeEnum {
103    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
104        self.value().to_tlv(w, tag)
105    }
106}
107
108impl<'a> FromTlv<'a> for StatusCodeEnum {
109    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
110        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
111        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
112    }
113}
114
115/// `TLSEndpointStruct`, fabric-scoped — §7.19.1.9's `FabricIndex` is field 254.
116#[derive(Debug, Clone, Copy, PartialEq)]
117pub struct TLSEndpointStruct<'a> {
118    /// `EndpointID`, field 0.
119    pub endpoint_id: u16,
120    /// `Hostname`, field 1.
121    pub hostname: &'a [u8],
122    /// `Port`, field 2.
123    pub port: u16,
124    /// `CAID`, field 3.
125    pub caid: u16,
126    /// `CCDID`, field 4.
127    pub ccdid: Nullable<u16>,
128    /// `ReferenceCount`, field 5.
129    pub reference_count: u8,
130    /// `FabricIndex`, field 254.
131    pub fabric_index: crate::msg::FabricIndex,
132}
133
134impl<'a> ToTlv for TLSEndpointStruct<'a> {
135    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
136        w.start_structure(tag)?;
137        self.endpoint_id.to_tlv(w, Tag::Context(0))?;
138        self.hostname.to_tlv(w, Tag::Context(1))?;
139        self.port.to_tlv(w, Tag::Context(2))?;
140        self.caid.to_tlv(w, Tag::Context(3))?;
141        self.ccdid.to_tlv(w, Tag::Context(4))?;
142        self.reference_count.to_tlv(w, Tag::Context(5))?;
143        self.fabric_index.to_tlv(w, Tag::Context(254))?;
144        w.end_container()
145    }
146}
147
148impl<'a> FromTlv<'a> for TLSEndpointStruct<'a> {
149    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
150        if element.value.container() != Some(ContainerKind::Structure) {
151            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
152        }
153        let mut endpoint_id = None;
154        let mut hostname = None;
155        let mut port = None;
156        let mut caid = None;
157        let mut ccdid = None;
158        let mut reference_count = None;
159        let mut fabric_index = None;
160        loop {
161            let Some(field) = reader.next_element()? else {
162                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
163            };
164            if field.value == Value::EndOfContainer {
165                break;
166            }
167            match field.tag.context() {
168                Some(0) => endpoint_id = Some(<u16>::from_tlv(reader, &field)?),
169                Some(1) => hostname = Some(<&'a [u8]>::from_tlv(reader, &field)?),
170                Some(2) => port = Some(<u16>::from_tlv(reader, &field)?),
171                Some(3) => caid = Some(<u16>::from_tlv(reader, &field)?),
172                Some(4) => ccdid = Some(<Nullable<u16>>::from_tlv(reader, &field)?),
173                Some(5) => reference_count = Some(<u8>::from_tlv(reader, &field)?),
174                Some(254) => {
175                    fabric_index = Some(<crate::msg::FabricIndex>::from_tlv(reader, &field)?)
176                }
177                // A field this revision does not define. §7.19.2: a receiver
178                // ignores what it does not know rather than refusing the whole
179                // structure, which is what lets a newer peer talk to an older one.
180                _ => reader.skip_value(&field)?,
181            }
182        }
183        Ok(Self {
184            endpoint_id: endpoint_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
185            hostname: hostname.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
186            port: port.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
187            caid: caid.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
188            ccdid: ccdid.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
189            reference_count: reference_count
190                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
191            fabric_index: fabric_index.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
192        })
193    }
194}
195
196/// The fields of `ProvisionEndpoint` (command `0x00`).
197#[derive(Debug, Clone, Copy, PartialEq)]
198pub struct ProvisionEndpointFields<'a> {
199    /// `Hostname`, field 0.
200    pub hostname: &'a [u8],
201    /// `Port`, field 1.
202    pub port: u16,
203    /// `CAID`, field 2.
204    pub caid: u16,
205    /// `CCDID`, field 3.
206    pub ccdid: Nullable<u16>,
207    /// `EndpointID`, field 4.
208    pub endpoint_id: Nullable<u16>,
209}
210
211impl<'a> ToTlv for ProvisionEndpointFields<'a> {
212    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
213        w.start_structure(tag)?;
214        self.hostname.to_tlv(w, Tag::Context(0))?;
215        self.port.to_tlv(w, Tag::Context(1))?;
216        self.caid.to_tlv(w, Tag::Context(2))?;
217        self.ccdid.to_tlv(w, Tag::Context(3))?;
218        self.endpoint_id.to_tlv(w, Tag::Context(4))?;
219        w.end_container()
220    }
221}
222
223impl<'a> FromTlv<'a> for ProvisionEndpointFields<'a> {
224    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
225        if element.value.container() != Some(ContainerKind::Structure) {
226            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
227        }
228        let mut hostname = None;
229        let mut port = None;
230        let mut caid = None;
231        let mut ccdid = None;
232        let mut endpoint_id = None;
233        loop {
234            let Some(field) = reader.next_element()? else {
235                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
236            };
237            if field.value == Value::EndOfContainer {
238                break;
239            }
240            match field.tag.context() {
241                Some(0) => hostname = Some(<&'a [u8]>::from_tlv(reader, &field)?),
242                Some(1) => port = Some(<u16>::from_tlv(reader, &field)?),
243                Some(2) => caid = Some(<u16>::from_tlv(reader, &field)?),
244                Some(3) => ccdid = Some(<Nullable<u16>>::from_tlv(reader, &field)?),
245                Some(4) => endpoint_id = Some(<Nullable<u16>>::from_tlv(reader, &field)?),
246                // A field this revision does not define. §7.19.2: a receiver
247                // ignores what it does not know rather than refusing the whole
248                // structure, which is what lets a newer peer talk to an older one.
249                _ => reader.skip_value(&field)?,
250            }
251        }
252        Ok(Self {
253            hostname: hostname.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
254            port: port.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
255            caid: caid.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
256            ccdid: ccdid.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
257            endpoint_id: endpoint_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
258        })
259    }
260}
261
262/// The fields of `ProvisionEndpointResponse` (command `0x01`).
263#[derive(Debug, Clone, Copy, PartialEq)]
264pub struct ProvisionEndpointResponseFields {
265    /// `EndpointID`, field 0.
266    pub endpoint_id: u16,
267}
268
269impl ToTlv for ProvisionEndpointResponseFields {
270    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
271        w.start_structure(tag)?;
272        self.endpoint_id.to_tlv(w, Tag::Context(0))?;
273        w.end_container()
274    }
275}
276
277impl<'a> FromTlv<'a> for ProvisionEndpointResponseFields {
278    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
279        if element.value.container() != Some(ContainerKind::Structure) {
280            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
281        }
282        let mut endpoint_id = None;
283        loop {
284            let Some(field) = reader.next_element()? else {
285                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
286            };
287            if field.value == Value::EndOfContainer {
288                break;
289            }
290            match field.tag.context() {
291                Some(0) => endpoint_id = Some(<u16>::from_tlv(reader, &field)?),
292                // A field this revision does not define. §7.19.2: a receiver
293                // ignores what it does not know rather than refusing the whole
294                // structure, which is what lets a newer peer talk to an older one.
295                _ => reader.skip_value(&field)?,
296            }
297        }
298        Ok(Self {
299            endpoint_id: endpoint_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
300        })
301    }
302}
303
304/// The fields of `FindEndpoint` (command `0x02`).
305#[derive(Debug, Clone, Copy, PartialEq)]
306pub struct FindEndpointFields {
307    /// `EndpointID`, field 0.
308    pub endpoint_id: u16,
309}
310
311impl ToTlv for FindEndpointFields {
312    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
313        w.start_structure(tag)?;
314        self.endpoint_id.to_tlv(w, Tag::Context(0))?;
315        w.end_container()
316    }
317}
318
319impl<'a> FromTlv<'a> for FindEndpointFields {
320    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
321        if element.value.container() != Some(ContainerKind::Structure) {
322            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
323        }
324        let mut endpoint_id = None;
325        loop {
326            let Some(field) = reader.next_element()? else {
327                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
328            };
329            if field.value == Value::EndOfContainer {
330                break;
331            }
332            match field.tag.context() {
333                Some(0) => endpoint_id = Some(<u16>::from_tlv(reader, &field)?),
334                // A field this revision does not define. §7.19.2: a receiver
335                // ignores what it does not know rather than refusing the whole
336                // structure, which is what lets a newer peer talk to an older one.
337                _ => reader.skip_value(&field)?,
338            }
339        }
340        Ok(Self {
341            endpoint_id: endpoint_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
342        })
343    }
344}
345
346/// The fields of `FindEndpointResponse` (command `0x03`).
347#[derive(Debug, Clone, Copy, PartialEq)]
348pub struct FindEndpointResponseFields<'a> {
349    /// `Endpoint`, field 0.
350    pub endpoint: TLSEndpointStruct<'a>,
351}
352
353impl<'a> ToTlv for FindEndpointResponseFields<'a> {
354    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
355        w.start_structure(tag)?;
356        self.endpoint.to_tlv(w, Tag::Context(0))?;
357        w.end_container()
358    }
359}
360
361impl<'a> FromTlv<'a> for FindEndpointResponseFields<'a> {
362    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
363        if element.value.container() != Some(ContainerKind::Structure) {
364            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
365        }
366        let mut endpoint = None;
367        loop {
368            let Some(field) = reader.next_element()? else {
369                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
370            };
371            if field.value == Value::EndOfContainer {
372                break;
373            }
374            match field.tag.context() {
375                Some(0) => endpoint = Some(<TLSEndpointStruct<'a>>::from_tlv(reader, &field)?),
376                // A field this revision does not define. §7.19.2: a receiver
377                // ignores what it does not know rather than refusing the whole
378                // structure, which is what lets a newer peer talk to an older one.
379                _ => reader.skip_value(&field)?,
380            }
381        }
382        Ok(Self {
383            endpoint: endpoint.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
384        })
385    }
386}
387
388/// The fields of `RemoveEndpoint` (command `0x04`).
389#[derive(Debug, Clone, Copy, PartialEq)]
390pub struct RemoveEndpointFields {
391    /// `EndpointID`, field 0.
392    pub endpoint_id: u16,
393}
394
395impl ToTlv for RemoveEndpointFields {
396    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
397        w.start_structure(tag)?;
398        self.endpoint_id.to_tlv(w, Tag::Context(0))?;
399        w.end_container()
400    }
401}
402
403impl<'a> FromTlv<'a> for RemoveEndpointFields {
404    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
405        if element.value.container() != Some(ContainerKind::Structure) {
406            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
407        }
408        let mut endpoint_id = None;
409        loop {
410            let Some(field) = reader.next_element()? else {
411                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
412            };
413            if field.value == Value::EndOfContainer {
414                break;
415            }
416            match field.tag.context() {
417                Some(0) => endpoint_id = Some(<u16>::from_tlv(reader, &field)?),
418                // A field this revision does not define. §7.19.2: a receiver
419                // ignores what it does not know rather than refusing the whole
420                // structure, which is what lets a newer peer talk to an older one.
421                _ => reader.skip_value(&field)?,
422            }
423        }
424        Ok(Self {
425            endpoint_id: endpoint_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
426        })
427    }
428}
429
430/// Every attribute the specification defines, with its conformance.
431pub const ATTRIBUTES: &[Attribute] = &[
432    Attribute {
433        id: 0x0000,
434        name: "MaxProvisioned",
435        kind: "uint8",
436        access: Access::read_only(Privilege::View),
437        qualities: AttributeQualities::FIXED,
438        reporting: Reporting::OnChange,
439        conform: Conform::MANDATORY,
440    },
441    Attribute {
442        id: 0x0001,
443        name: "ProvisionedEndpoints",
444        kind: "list[TLSEndpointStruct]",
445        access: Access::read_only(Privilege::View)
446            .with_qualities(AccessQualities::FABRIC_SENSITIVE),
447        qualities: AttributeQualities::NON_VOLATILE,
448        reporting: Reporting::OnChange,
449        conform: Conform::MANDATORY,
450    },
451];
452
453/// Every command, with its conformance.
454pub const COMMANDS: &[Command] = &[
455    Command {
456        id: 0x00,
457        name: "ProvisionEndpoint",
458        to_server: true,
459        response: Some(0x01),
460        access: Access::invoke(Privilege::Administer)
461            .with_qualities(AccessQualities::FABRIC_SCOPED.union(AccessQualities::LARGE)),
462        conform: Conform::MANDATORY,
463    },
464    Command {
465        id: 0x01,
466        name: "ProvisionEndpointResponse",
467        to_server: false,
468        response: None,
469        access: Access::invoke(Privilege::Operate).with_qualities(AccessQualities::LARGE),
470        conform: Conform::MANDATORY,
471    },
472    Command {
473        id: 0x02,
474        name: "FindEndpoint",
475        to_server: true,
476        response: Some(0x03),
477        access: Access::invoke(Privilege::Operate)
478            .with_qualities(AccessQualities::FABRIC_SCOPED.union(AccessQualities::LARGE)),
479        conform: Conform::MANDATORY,
480    },
481    Command {
482        id: 0x03,
483        name: "FindEndpointResponse",
484        to_server: false,
485        response: None,
486        access: Access::invoke(Privilege::Operate).with_qualities(AccessQualities::LARGE),
487        conform: Conform::MANDATORY,
488    },
489    Command {
490        id: 0x04,
491        name: "RemoveEndpoint",
492        to_server: true,
493        response: None,
494        access: Access::invoke(Privilege::Administer)
495            .with_qualities(AccessQualities::FABRIC_SCOPED.union(AccessQualities::LARGE)),
496        conform: Conform::MANDATORY,
497    },
498];
499
500/// Every event, with its conformance.
501pub const EVENTS: &[Event] = &[];
502
503/// The whole cluster, as the specification defines it.
504pub const CLUSTER: Cluster = Cluster {
505    id: ID,
506    name: "TLS Client Management",
507    revision: REVISION,
508    pics: "TLSCLIENT",
509    derived_from: None,
510    features: FEATURES,
511    attributes: ATTRIBUTES,
512    commands: COMMANDS,
513    events: EVENTS,
514};