Skip to main content

matter_kit/clusters/generated/
groupcast.rs

1// Generated by `cargo xtask` from the CSA data model 1.6. Do not edit.
2//
3// Groupcast — cluster 0x0065.
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//! Groupcast (cluster `0x0065`, revision 1).
10//!
11//! 12 identifiers, 3 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 = 0x0065;
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 = "GC";
35
36/// The `FeatureMap` bits (Core §7.13.2).
37///
38/// A feature has conformance of its own: a device may not claim one the
39/// specification forbids it alongside another.
40pub mod feature {
41    /// Supports joining a multicast group of nodes as a listener.
42    ///
43    /// Code `LN`, bit 0.
44    pub const LISTENER: u32 = 1 << 0;
45    /// Supports sending multicast message to a targeted group of nodes.
46    ///
47    /// Code `SD`, bit 1.
48    pub const SENDER: u32 = 1 << 1;
49    /// Supports PerGroup multicast addresses.
50    ///
51    /// Code `PGA`, bit 2.
52    pub const PER_GROUP: u32 = 1 << 2;
53}
54
55/// Every feature bit, with its conformance.
56pub const FEATURES: &[Feature] = &[
57    Feature {
58        bit: 0,
59        code: "LN",
60        name: "Listener",
61        conform: Conform {
62            clauses: &[
63                Clause {
64                    verdict: Conformance::Provisional,
65                    when: Condition::Always,
66                },
67                Clause {
68                    verdict: Conformance::Optional,
69                    when: Condition::Always,
70                },
71            ],
72        },
73    },
74    Feature {
75        bit: 1,
76        code: "SD",
77        name: "Sender",
78        conform: Conform {
79            clauses: &[
80                Clause {
81                    verdict: Conformance::Provisional,
82                    when: Condition::Always,
83                },
84                Clause {
85                    verdict: Conformance::Optional,
86                    when: Condition::Always,
87                },
88            ],
89        },
90    },
91    Feature {
92        bit: 2,
93        code: "PGA",
94        name: "PerGroup",
95        conform: Conform {
96            clauses: &[
97                Clause {
98                    verdict: Conformance::Provisional,
99                    when: Condition::Always,
100                },
101                Clause {
102                    verdict: Conformance::Optional,
103                    when: Condition::Always,
104                },
105            ],
106        },
107    },
108];
109
110/// The attribute ids.
111pub mod attribute {
112    use crate::im::AttributeId;
113
114    /// `Membership`.
115    pub const MEMBERSHIP: AttributeId = 0x00;
116    /// `MaxMembershipCount`.
117    pub const MAX_MEMBERSHIP_COUNT: AttributeId = 0x01;
118    /// `MaxMcastAddrCount`.
119    pub const MAX_MCAST_ADDR_COUNT: AttributeId = 0x02;
120    /// `UsedMcastAddrCount`.
121    pub const USED_MCAST_ADDR_COUNT: AttributeId = 0x03;
122    /// `FabricUnderTest`.
123    pub const FABRIC_UNDER_TEST: AttributeId = 0x04;
124}
125
126/// The command ids.
127pub mod command {
128    use crate::im::CommandId;
129
130    /// `JoinGroup`.
131    pub const JOIN_GROUP: CommandId = 0x00;
132    /// `LeaveGroup`.
133    pub const LEAVE_GROUP: CommandId = 0x01;
134    /// `LeaveGroupResponse`.
135    pub const LEAVE_GROUP_RESPONSE: CommandId = 0x02;
136    /// `UpdateGroupKey`.
137    pub const UPDATE_GROUP_KEY: CommandId = 0x03;
138    /// `ConfigureAuxiliaryACL`.
139    pub const CONFIGURE_AUXILIARY_ACL: CommandId = 0x04;
140    /// `GroupcastTesting`.
141    pub const GROUPCAST_TESTING: CommandId = 0x05;
142}
143
144/// The event ids.
145pub mod event {
146    use crate::im::EventId;
147
148    /// `GroupcastTesting`.
149    pub const GROUPCAST_TESTING: EventId = 0x00;
150}
151
152/// `GroupcastTestResultEnum`.
153#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
154#[repr(u8)]
155pub enum GroupcastTestResultEnum {
156    /// There was no failure
157    Success = 0,
158    /// Other error during processing not otherwise covered
159    GeneralError = 1,
160    /// Message counter was <= counter from last received
161    MessageReplay = 2,
162    /// Message authentication failed
163    FailedAuth = 3,
164    /// No key was found to process the message
165    NoAvailableKey = 4,
166    /// Issue with attempting to send a multicast IPv6 message
167    SendFailure = 5,
168}
169
170impl GroupcastTestResultEnum {
171    /// Reads a wire value, or `None` for one this revision does not define.
172    #[must_use]
173    pub const fn from_value(value: u8) -> Option<Self> {
174        match value {
175            0 => Some(Self::Success),
176            1 => Some(Self::GeneralError),
177            2 => Some(Self::MessageReplay),
178            3 => Some(Self::FailedAuth),
179            4 => Some(Self::NoAvailableKey),
180            5 => Some(Self::SendFailure),
181            _ => None,
182        }
183    }
184
185    /// Its wire value.
186    #[must_use]
187    pub const fn value(self) -> u8 {
188        self as u8
189    }
190}
191
192impl ToTlv for GroupcastTestResultEnum {
193    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
194        self.value().to_tlv(w, tag)
195    }
196}
197
198impl<'a> FromTlv<'a> for GroupcastTestResultEnum {
199    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
200        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
201        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
202    }
203}
204
205/// `GroupcastTestingEnum`.
206#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
207#[repr(u8)]
208pub enum GroupcastTestingEnum {
209    /// Disable all test event generation
210    DisableTesting = 0,
211    /// Enable Listener test event generation
212    EnableListenerTesting = 1,
213    /// Enable Sender test event generation
214    EnableSenderTesting = 2,
215}
216
217impl GroupcastTestingEnum {
218    /// Reads a wire value, or `None` for one this revision does not define.
219    #[must_use]
220    pub const fn from_value(value: u8) -> Option<Self> {
221        match value {
222            0 => Some(Self::DisableTesting),
223            1 => Some(Self::EnableListenerTesting),
224            2 => Some(Self::EnableSenderTesting),
225            _ => None,
226        }
227    }
228
229    /// Its wire value.
230    #[must_use]
231    pub const fn value(self) -> u8 {
232        self as u8
233    }
234}
235
236impl ToTlv for GroupcastTestingEnum {
237    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
238        self.value().to_tlv(w, tag)
239    }
240}
241
242impl<'a> FromTlv<'a> for GroupcastTestingEnum {
243    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
244        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
245        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
246    }
247}
248
249/// `MulticastAddrPolicyEnum`.
250#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
251#[repr(u8)]
252pub enum MulticastAddrPolicyEnum {
253    /// Indicates group uses the IANA-assigned multicast address (default)
254    IanaAddr = 0,
255    /// Group uses multicast address scoped to Fabric ID and Group ID
256    PerGroup = 1,
257}
258
259impl MulticastAddrPolicyEnum {
260    /// Reads a wire value, or `None` for one this revision does not define.
261    #[must_use]
262    pub const fn from_value(value: u8) -> Option<Self> {
263        match value {
264            0 => Some(Self::IanaAddr),
265            1 => Some(Self::PerGroup),
266            _ => None,
267        }
268    }
269
270    /// Its wire value.
271    #[must_use]
272    pub const fn value(self) -> u8 {
273        self as u8
274    }
275}
276
277impl ToTlv for MulticastAddrPolicyEnum {
278    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
279        self.value().to_tlv(w, tag)
280    }
281}
282
283impl<'a> FromTlv<'a> for MulticastAddrPolicyEnum {
284    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
285        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
286        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
287    }
288}
289
290/// `MembershipStruct`, fabric-scoped — §7.19.1.9's `FabricIndex` is field 254.
291#[derive(Debug, Clone, Copy, PartialEq)]
292pub struct MembershipStruct<'a> {
293    /// `GroupID`, field 0.
294    pub group_id: crate::msg::GroupId,
295    /// `Endpoints`, field 1.
296    pub endpoints: Option<TlvList<'a, u16>>,
297    /// `KeySetID`, field 2.
298    pub key_set_id: u16,
299    /// `HasAuxiliaryACL`, field 3.
300    pub has_auxiliary_acl: Option<bool>,
301    /// `McastAddrPolicy`, field 4.
302    pub mcast_addr_policy: MulticastAddrPolicyEnum,
303    /// `FabricIndex`, field 254.
304    pub fabric_index: crate::msg::FabricIndex,
305}
306
307impl<'a> ToTlv for MembershipStruct<'a> {
308    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
309        w.start_structure(tag)?;
310        self.group_id.to_tlv(w, Tag::Context(0))?;
311        if let Some(value) = &self.endpoints {
312            value.to_tlv(w, Tag::Context(1))?;
313        }
314        self.key_set_id.to_tlv(w, Tag::Context(2))?;
315        if let Some(value) = &self.has_auxiliary_acl {
316            value.to_tlv(w, Tag::Context(3))?;
317        }
318        self.mcast_addr_policy.to_tlv(w, Tag::Context(4))?;
319        self.fabric_index.to_tlv(w, Tag::Context(254))?;
320        w.end_container()
321    }
322}
323
324impl<'a> FromTlv<'a> for MembershipStruct<'a> {
325    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
326        if element.value.container() != Some(ContainerKind::Structure) {
327            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
328        }
329        let mut group_id = None;
330        let mut endpoints = None;
331        let mut key_set_id = None;
332        let mut has_auxiliary_acl = None;
333        let mut mcast_addr_policy = None;
334        let mut fabric_index = None;
335        loop {
336            let Some(field) = reader.next_element()? else {
337                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
338            };
339            if field.value == Value::EndOfContainer {
340                break;
341            }
342            match field.tag.context() {
343                Some(0) => group_id = Some(<crate::msg::GroupId>::from_tlv(reader, &field)?),
344                Some(1) => endpoints = Some(<TlvList<'a, u16>>::from_tlv(reader, &field)?),
345                Some(2) => key_set_id = Some(<u16>::from_tlv(reader, &field)?),
346                Some(3) => has_auxiliary_acl = Some(<bool>::from_tlv(reader, &field)?),
347                Some(4) => {
348                    mcast_addr_policy = Some(<MulticastAddrPolicyEnum>::from_tlv(reader, &field)?)
349                }
350                Some(254) => {
351                    fabric_index = Some(<crate::msg::FabricIndex>::from_tlv(reader, &field)?)
352                }
353                // A field this revision does not define. §7.19.2: a receiver
354                // ignores what it does not know rather than refusing the whole
355                // structure, which is what lets a newer peer talk to an older one.
356                _ => reader.skip_value(&field)?,
357            }
358        }
359        Ok(Self {
360            group_id: group_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
361            endpoints,
362            key_set_id: key_set_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
363            has_auxiliary_acl,
364            mcast_addr_policy: mcast_addr_policy
365                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
366            fabric_index: fabric_index.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
367        })
368    }
369}
370
371/// The fields of `JoinGroup` (command `0x00`).
372#[derive(Debug, Clone, Copy, PartialEq)]
373pub struct JoinGroupFields<'a> {
374    /// `GroupID`, field 0.
375    pub group_id: crate::msg::GroupId,
376    /// `Endpoints`, field 1.
377    pub endpoints: TlvList<'a, u16>,
378    /// `KeySetID`, field 2.
379    pub key_set_id: u16,
380    /// `Key`, field 3.
381    pub key: Option<&'a [u8]>,
382    /// `UseAuxiliaryACL`, field 4.
383    pub use_auxiliary_acl: Option<bool>,
384    /// `ReplaceEndpoints`, field 5.
385    pub replace_endpoints: Option<bool>,
386    /// `McastAddrPolicy`, field 6.
387    pub mcast_addr_policy: Option<MulticastAddrPolicyEnum>,
388}
389
390impl<'a> ToTlv for JoinGroupFields<'a> {
391    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
392        w.start_structure(tag)?;
393        self.group_id.to_tlv(w, Tag::Context(0))?;
394        self.endpoints.to_tlv(w, Tag::Context(1))?;
395        self.key_set_id.to_tlv(w, Tag::Context(2))?;
396        if let Some(value) = &self.key {
397            value.to_tlv(w, Tag::Context(3))?;
398        }
399        if let Some(value) = &self.use_auxiliary_acl {
400            value.to_tlv(w, Tag::Context(4))?;
401        }
402        if let Some(value) = &self.replace_endpoints {
403            value.to_tlv(w, Tag::Context(5))?;
404        }
405        if let Some(value) = &self.mcast_addr_policy {
406            value.to_tlv(w, Tag::Context(6))?;
407        }
408        w.end_container()
409    }
410}
411
412impl<'a> FromTlv<'a> for JoinGroupFields<'a> {
413    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
414        if element.value.container() != Some(ContainerKind::Structure) {
415            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
416        }
417        let mut group_id = None;
418        let mut endpoints = None;
419        let mut key_set_id = None;
420        let mut key = None;
421        let mut use_auxiliary_acl = None;
422        let mut replace_endpoints = None;
423        let mut mcast_addr_policy = None;
424        loop {
425            let Some(field) = reader.next_element()? else {
426                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
427            };
428            if field.value == Value::EndOfContainer {
429                break;
430            }
431            match field.tag.context() {
432                Some(0) => group_id = Some(<crate::msg::GroupId>::from_tlv(reader, &field)?),
433                Some(1) => endpoints = Some(<TlvList<'a, u16>>::from_tlv(reader, &field)?),
434                Some(2) => key_set_id = Some(<u16>::from_tlv(reader, &field)?),
435                Some(3) => key = Some(<&'a [u8]>::from_tlv(reader, &field)?),
436                Some(4) => use_auxiliary_acl = Some(<bool>::from_tlv(reader, &field)?),
437                Some(5) => replace_endpoints = Some(<bool>::from_tlv(reader, &field)?),
438                Some(6) => {
439                    mcast_addr_policy = Some(<MulticastAddrPolicyEnum>::from_tlv(reader, &field)?)
440                }
441                // A field this revision does not define. §7.19.2: a receiver
442                // ignores what it does not know rather than refusing the whole
443                // structure, which is what lets a newer peer talk to an older one.
444                _ => reader.skip_value(&field)?,
445            }
446        }
447        Ok(Self {
448            group_id: group_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
449            endpoints: endpoints.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
450            key_set_id: key_set_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
451            key,
452            use_auxiliary_acl,
453            replace_endpoints,
454            mcast_addr_policy,
455        })
456    }
457}
458
459/// The fields of `LeaveGroup` (command `0x01`).
460#[derive(Debug, Clone, Copy, PartialEq)]
461pub struct LeaveGroupFields<'a> {
462    /// `GroupID`, field 0.
463    pub group_id: crate::msg::GroupId,
464    /// `Endpoints`, field 1.
465    pub endpoints: Option<TlvList<'a, u16>>,
466}
467
468impl<'a> ToTlv for LeaveGroupFields<'a> {
469    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
470        w.start_structure(tag)?;
471        self.group_id.to_tlv(w, Tag::Context(0))?;
472        if let Some(value) = &self.endpoints {
473            value.to_tlv(w, Tag::Context(1))?;
474        }
475        w.end_container()
476    }
477}
478
479impl<'a> FromTlv<'a> for LeaveGroupFields<'a> {
480    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
481        if element.value.container() != Some(ContainerKind::Structure) {
482            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
483        }
484        let mut group_id = None;
485        let mut endpoints = None;
486        loop {
487            let Some(field) = reader.next_element()? else {
488                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
489            };
490            if field.value == Value::EndOfContainer {
491                break;
492            }
493            match field.tag.context() {
494                Some(0) => group_id = Some(<crate::msg::GroupId>::from_tlv(reader, &field)?),
495                Some(1) => endpoints = Some(<TlvList<'a, u16>>::from_tlv(reader, &field)?),
496                // A field this revision does not define. §7.19.2: a receiver
497                // ignores what it does not know rather than refusing the whole
498                // structure, which is what lets a newer peer talk to an older one.
499                _ => reader.skip_value(&field)?,
500            }
501        }
502        Ok(Self {
503            group_id: group_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
504            endpoints,
505        })
506    }
507}
508
509/// The fields of `LeaveGroupResponse` (command `0x02`).
510#[derive(Debug, Clone, Copy, PartialEq)]
511pub struct LeaveGroupResponseFields<'a> {
512    /// `GroupID`, field 0.
513    pub group_id: crate::msg::GroupId,
514    /// `Endpoints`, field 1.
515    pub endpoints: TlvList<'a, u16>,
516}
517
518impl<'a> ToTlv for LeaveGroupResponseFields<'a> {
519    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
520        w.start_structure(tag)?;
521        self.group_id.to_tlv(w, Tag::Context(0))?;
522        self.endpoints.to_tlv(w, Tag::Context(1))?;
523        w.end_container()
524    }
525}
526
527impl<'a> FromTlv<'a> for LeaveGroupResponseFields<'a> {
528    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
529        if element.value.container() != Some(ContainerKind::Structure) {
530            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
531        }
532        let mut group_id = None;
533        let mut endpoints = None;
534        loop {
535            let Some(field) = reader.next_element()? else {
536                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
537            };
538            if field.value == Value::EndOfContainer {
539                break;
540            }
541            match field.tag.context() {
542                Some(0) => group_id = Some(<crate::msg::GroupId>::from_tlv(reader, &field)?),
543                Some(1) => endpoints = Some(<TlvList<'a, u16>>::from_tlv(reader, &field)?),
544                // A field this revision does not define. §7.19.2: a receiver
545                // ignores what it does not know rather than refusing the whole
546                // structure, which is what lets a newer peer talk to an older one.
547                _ => reader.skip_value(&field)?,
548            }
549        }
550        Ok(Self {
551            group_id: group_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
552            endpoints: endpoints.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
553        })
554    }
555}
556
557/// The fields of `UpdateGroupKey` (command `0x03`).
558#[derive(Debug, Clone, Copy, PartialEq)]
559pub struct UpdateGroupKeyFields<'a> {
560    /// `GroupID`, field 0.
561    pub group_id: crate::msg::GroupId,
562    /// `KeySetID`, field 1.
563    pub key_set_id: u16,
564    /// `Key`, field 2.
565    pub key: Option<&'a [u8]>,
566}
567
568impl<'a> ToTlv for UpdateGroupKeyFields<'a> {
569    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
570        w.start_structure(tag)?;
571        self.group_id.to_tlv(w, Tag::Context(0))?;
572        self.key_set_id.to_tlv(w, Tag::Context(1))?;
573        if let Some(value) = &self.key {
574            value.to_tlv(w, Tag::Context(2))?;
575        }
576        w.end_container()
577    }
578}
579
580impl<'a> FromTlv<'a> for UpdateGroupKeyFields<'a> {
581    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
582        if element.value.container() != Some(ContainerKind::Structure) {
583            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
584        }
585        let mut group_id = None;
586        let mut key_set_id = None;
587        let mut key = None;
588        loop {
589            let Some(field) = reader.next_element()? else {
590                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
591            };
592            if field.value == Value::EndOfContainer {
593                break;
594            }
595            match field.tag.context() {
596                Some(0) => group_id = Some(<crate::msg::GroupId>::from_tlv(reader, &field)?),
597                Some(1) => key_set_id = Some(<u16>::from_tlv(reader, &field)?),
598                Some(2) => key = Some(<&'a [u8]>::from_tlv(reader, &field)?),
599                // A field this revision does not define. §7.19.2: a receiver
600                // ignores what it does not know rather than refusing the whole
601                // structure, which is what lets a newer peer talk to an older one.
602                _ => reader.skip_value(&field)?,
603            }
604        }
605        Ok(Self {
606            group_id: group_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
607            key_set_id: key_set_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
608            key,
609        })
610    }
611}
612
613/// The fields of `ConfigureAuxiliaryACL` (command `0x04`).
614#[derive(Debug, Clone, Copy, PartialEq)]
615pub struct ConfigureAuxiliaryACLFields {
616    /// `GroupID`, field 0.
617    pub group_id: crate::msg::GroupId,
618    /// `UseAuxiliaryACL`, field 1.
619    pub use_auxiliary_acl: bool,
620}
621
622impl ToTlv for ConfigureAuxiliaryACLFields {
623    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
624        w.start_structure(tag)?;
625        self.group_id.to_tlv(w, Tag::Context(0))?;
626        self.use_auxiliary_acl.to_tlv(w, Tag::Context(1))?;
627        w.end_container()
628    }
629}
630
631impl<'a> FromTlv<'a> for ConfigureAuxiliaryACLFields {
632    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
633        if element.value.container() != Some(ContainerKind::Structure) {
634            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
635        }
636        let mut group_id = None;
637        let mut use_auxiliary_acl = None;
638        loop {
639            let Some(field) = reader.next_element()? else {
640                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
641            };
642            if field.value == Value::EndOfContainer {
643                break;
644            }
645            match field.tag.context() {
646                Some(0) => group_id = Some(<crate::msg::GroupId>::from_tlv(reader, &field)?),
647                Some(1) => use_auxiliary_acl = Some(<bool>::from_tlv(reader, &field)?),
648                // A field this revision does not define. §7.19.2: a receiver
649                // ignores what it does not know rather than refusing the whole
650                // structure, which is what lets a newer peer talk to an older one.
651                _ => reader.skip_value(&field)?,
652            }
653        }
654        Ok(Self {
655            group_id: group_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
656            use_auxiliary_acl: use_auxiliary_acl
657                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
658        })
659    }
660}
661
662/// The fields of `GroupcastTesting` (command `0x05`).
663#[derive(Debug, Clone, Copy, PartialEq)]
664pub struct GroupcastTestingFields {
665    /// `TestOperation`, field 0.
666    pub test_operation: GroupcastTestingEnum,
667    /// `DurationSeconds`, field 1.
668    pub duration_seconds: Option<u16>,
669}
670
671impl ToTlv for GroupcastTestingFields {
672    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
673        w.start_structure(tag)?;
674        self.test_operation.to_tlv(w, Tag::Context(0))?;
675        if let Some(value) = &self.duration_seconds {
676            value.to_tlv(w, Tag::Context(1))?;
677        }
678        w.end_container()
679    }
680}
681
682impl<'a> FromTlv<'a> for GroupcastTestingFields {
683    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
684        if element.value.container() != Some(ContainerKind::Structure) {
685            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
686        }
687        let mut test_operation = None;
688        let mut duration_seconds = None;
689        loop {
690            let Some(field) = reader.next_element()? else {
691                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
692            };
693            if field.value == Value::EndOfContainer {
694                break;
695            }
696            match field.tag.context() {
697                Some(0) => test_operation = Some(<GroupcastTestingEnum>::from_tlv(reader, &field)?),
698                Some(1) => duration_seconds = Some(<u16>::from_tlv(reader, &field)?),
699                // A field this revision does not define. §7.19.2: a receiver
700                // ignores what it does not know rather than refusing the whole
701                // structure, which is what lets a newer peer talk to an older one.
702                _ => reader.skip_value(&field)?,
703            }
704        }
705        Ok(Self {
706            test_operation: test_operation
707                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
708            duration_seconds,
709        })
710    }
711}
712
713/// Every attribute the specification defines, with its conformance.
714pub const ATTRIBUTES: &[Attribute] = &[
715    Attribute {
716        id: 0x0000,
717        name: "Membership",
718        kind: "list[MembershipStruct]",
719        access: Access::read_only(Privilege::View).with_qualities(AccessQualities::FABRIC_SCOPED),
720        qualities: AttributeQualities::NON_VOLATILE,
721        reporting: Reporting::OnChange,
722        conform: Conform {
723            clauses: &[
724                Clause {
725                    verdict: Conformance::Provisional,
726                    when: Condition::Always,
727                },
728                Clause {
729                    verdict: Conformance::Mandatory,
730                    when: Condition::Always,
731                },
732            ],
733        },
734    },
735    Attribute {
736        id: 0x0001,
737        name: "MaxMembershipCount",
738        kind: "uint16",
739        access: Access::read_only(Privilege::View),
740        qualities: AttributeQualities::FIXED,
741        reporting: Reporting::OnChange,
742        conform: Conform {
743            clauses: &[
744                Clause {
745                    verdict: Conformance::Provisional,
746                    when: Condition::Always,
747                },
748                Clause {
749                    verdict: Conformance::Mandatory,
750                    when: Condition::Always,
751                },
752            ],
753        },
754    },
755    Attribute {
756        id: 0x0002,
757        name: "MaxMcastAddrCount",
758        kind: "uint16",
759        access: Access::read_only(Privilege::View),
760        qualities: AttributeQualities::FIXED,
761        reporting: Reporting::OnChange,
762        conform: Conform {
763            clauses: &[
764                Clause {
765                    verdict: Conformance::Provisional,
766                    when: Condition::Always,
767                },
768                Clause {
769                    verdict: Conformance::Mandatory,
770                    when: Condition::Always,
771                },
772            ],
773        },
774    },
775    Attribute {
776        id: 0x0003,
777        name: "UsedMcastAddrCount",
778        kind: "uint16",
779        access: Access::read_only(Privilege::View),
780        qualities: AttributeQualities::FIXED,
781        reporting: Reporting::OnChange,
782        conform: Conform {
783            clauses: &[
784                Clause {
785                    verdict: Conformance::Provisional,
786                    when: Condition::Always,
787                },
788                Clause {
789                    verdict: Conformance::Mandatory,
790                    when: Condition::Always,
791                },
792            ],
793        },
794    },
795    Attribute {
796        id: 0x0004,
797        name: "FabricUnderTest",
798        kind: "fabric-idx",
799        access: Access::read_only(Privilege::View),
800        qualities: AttributeQualities::empty(),
801        reporting: Reporting::OnChange,
802        conform: Conform {
803            clauses: &[
804                Clause {
805                    verdict: Conformance::Provisional,
806                    when: Condition::Always,
807                },
808                Clause {
809                    verdict: Conformance::Mandatory,
810                    when: Condition::Always,
811                },
812            ],
813        },
814    },
815];
816
817/// Every command, with its conformance.
818pub const COMMANDS: &[Command] = &[
819    Command {
820        id: 0x00,
821        name: "JoinGroup",
822        to_server: true,
823        response: None,
824        access: Access::invoke(Privilege::Manage).with_qualities(AccessQualities::FABRIC_SCOPED),
825        conform: Conform {
826            clauses: &[
827                Clause {
828                    verdict: Conformance::Provisional,
829                    when: Condition::Always,
830                },
831                Clause {
832                    verdict: Conformance::Mandatory,
833                    when: Condition::Always,
834                },
835            ],
836        },
837    },
838    Command {
839        id: 0x01,
840        name: "LeaveGroup",
841        to_server: true,
842        response: Some(0x02),
843        access: Access::invoke(Privilege::Manage).with_qualities(AccessQualities::FABRIC_SCOPED),
844        conform: Conform {
845            clauses: &[
846                Clause {
847                    verdict: Conformance::Provisional,
848                    when: Condition::Always,
849                },
850                Clause {
851                    verdict: Conformance::Mandatory,
852                    when: Condition::Always,
853                },
854            ],
855        },
856    },
857    Command {
858        id: 0x02,
859        name: "LeaveGroupResponse",
860        to_server: false,
861        response: None,
862        access: Access::invoke(Privilege::Operate).with_qualities(AccessQualities::FABRIC_SCOPED),
863        conform: Conform {
864            clauses: &[
865                Clause {
866                    verdict: Conformance::Provisional,
867                    when: Condition::Always,
868                },
869                Clause {
870                    verdict: Conformance::Mandatory,
871                    when: Condition::Always,
872                },
873            ],
874        },
875    },
876    Command {
877        id: 0x03,
878        name: "UpdateGroupKey",
879        to_server: true,
880        response: None,
881        access: Access::invoke(Privilege::Manage).with_qualities(AccessQualities::FABRIC_SCOPED),
882        conform: Conform {
883            clauses: &[
884                Clause {
885                    verdict: Conformance::Provisional,
886                    when: Condition::Always,
887                },
888                Clause {
889                    verdict: Conformance::Mandatory,
890                    when: Condition::Always,
891                },
892            ],
893        },
894    },
895    Command {
896        id: 0x04,
897        name: "ConfigureAuxiliaryACL",
898        to_server: true,
899        response: None,
900        access: Access::invoke(Privilege::Administer)
901            .with_qualities(AccessQualities::FABRIC_SCOPED),
902        conform: Conform {
903            clauses: &[
904                Clause {
905                    verdict: Conformance::Provisional,
906                    when: Condition::Always,
907                },
908                Clause {
909                    verdict: Conformance::Mandatory,
910                    when: Condition::Feature(0),
911                },
912            ],
913        },
914    },
915    Command {
916        id: 0x05,
917        name: "GroupcastTesting",
918        to_server: true,
919        response: None,
920        access: Access::invoke(Privilege::Administer)
921            .with_qualities(AccessQualities::FABRIC_SCOPED),
922        conform: Conform {
923            clauses: &[
924                Clause {
925                    verdict: Conformance::Provisional,
926                    when: Condition::Always,
927                },
928                Clause {
929                    verdict: Conformance::Mandatory,
930                    when: Condition::Always,
931                },
932            ],
933        },
934    },
935];
936
937/// Every event, with its conformance.
938pub const EVENTS: &[Event] = &[Event {
939    id: 0x00,
940    name: "GroupcastTesting",
941    priority: EventPriority::Info,
942    access: Access::read_only(Privilege::Administer)
943        .with_qualities(AccessQualities::FABRIC_SENSITIVE),
944    conform: Conform {
945        clauses: &[
946            Clause {
947                verdict: Conformance::Provisional,
948                when: Condition::Always,
949            },
950            Clause {
951                verdict: Conformance::Mandatory,
952                when: Condition::Always,
953            },
954        ],
955    },
956}];
957
958/// The whole cluster, as the specification defines it.
959pub const CLUSTER: Cluster = Cluster {
960    id: ID,
961    name: "Groupcast",
962    revision: REVISION,
963    pics: "GC",
964    derived_from: None,
965    features: FEATURES,
966    attributes: ATTRIBUTES,
967    commands: COMMANDS,
968    events: EVENTS,
969};