1#![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
26pub const ID: ClusterId = 0x0039;
28
29pub const REVISION: u16 = 6;
32
33pub const PICS: &str = "BRBINFO";
35
36pub mod feature {
41 pub const BRIDGED_ICD_SUPPORT: u32 = 1 << 20;
45}
46
47pub const FEATURES: &[Feature] = &[Feature {
49 bit: 20,
50 code: "BIS",
51 name: "BridgedICDSupport",
52 conform: Conform {
53 clauses: &[Clause {
54 verdict: Conformance::Described,
55 when: Condition::Named("comparison"),
56 }],
57 },
58}];
59
60pub mod attribute {
62 use crate::im::AttributeId;
63
64 pub const DATA_MODEL_REVISION: AttributeId = 0x00;
66 pub const VENDOR_NAME: AttributeId = 0x01;
68 pub const VENDOR_ID: AttributeId = 0x02;
70 pub const PRODUCT_NAME: AttributeId = 0x03;
72 pub const PRODUCT_ID: AttributeId = 0x04;
74 pub const NODE_LABEL: AttributeId = 0x05;
76 pub const LOCATION: AttributeId = 0x06;
78 pub const HARDWARE_VERSION: AttributeId = 0x07;
80 pub const HARDWARE_VERSION_STRING: AttributeId = 0x08;
82 pub const SOFTWARE_VERSION: AttributeId = 0x09;
84 pub const SOFTWARE_VERSION_STRING: AttributeId = 0x0A;
86 pub const MANUFACTURING_DATE: AttributeId = 0x0B;
88 pub const PART_NUMBER: AttributeId = 0x0C;
90 pub const PRODUCT_URL: AttributeId = 0x0D;
92 pub const PRODUCT_LABEL: AttributeId = 0x0E;
94 pub const SERIAL_NUMBER: AttributeId = 0x0F;
96 pub const LOCAL_CONFIG_DISABLED: AttributeId = 0x10;
98 pub const REACHABLE: AttributeId = 0x11;
100 pub const UNIQUE_ID: AttributeId = 0x12;
102 pub const CAPABILITY_MINIMA: AttributeId = 0x13;
104 pub const PRODUCT_APPEARANCE: AttributeId = 0x14;
106 pub const SPECIFICATION_VERSION: AttributeId = 0x15;
108 pub const MAX_PATHS_PER_INVOKE: AttributeId = 0x16;
110 pub const CONFIGURATION_VERSION: AttributeId = 0x18;
112}
113
114pub mod command {
116 use crate::im::CommandId;
117
118 pub const KEEP_ACTIVE: CommandId = 0x80;
120}
121
122pub mod event {
124 use crate::im::EventId;
125
126 pub const START_UP: EventId = 0x00;
128 pub const SHUT_DOWN: EventId = 0x01;
130 pub const LEAVE: EventId = 0x02;
132 pub const REACHABLE_CHANGED: EventId = 0x03;
134 pub const ACTIVE_CHANGED: EventId = 0x80;
136}
137
138#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
140#[repr(u8)]
141pub enum ColorEnum {
142 Black = 0,
144 Navy = 1,
146 Green = 2,
148 Teal = 3,
150 Maroon = 4,
152 Purple = 5,
154 Olive = 6,
156 Gray = 7,
158 Blue = 8,
160 Lime = 9,
162 Aqua = 10,
164 Red = 11,
166 Fuchsia = 12,
168 Yellow = 13,
170 White = 14,
172 Nickel = 15,
174 Chrome = 16,
176 Brass = 17,
178 Copper = 18,
180 Silver = 19,
182 Gold = 20,
184}
185
186impl ColorEnum {
187 #[must_use]
189 pub const fn from_value(value: u8) -> Option<Self> {
190 match value {
191 0 => Some(Self::Black),
192 1 => Some(Self::Navy),
193 2 => Some(Self::Green),
194 3 => Some(Self::Teal),
195 4 => Some(Self::Maroon),
196 5 => Some(Self::Purple),
197 6 => Some(Self::Olive),
198 7 => Some(Self::Gray),
199 8 => Some(Self::Blue),
200 9 => Some(Self::Lime),
201 10 => Some(Self::Aqua),
202 11 => Some(Self::Red),
203 12 => Some(Self::Fuchsia),
204 13 => Some(Self::Yellow),
205 14 => Some(Self::White),
206 15 => Some(Self::Nickel),
207 16 => Some(Self::Chrome),
208 17 => Some(Self::Brass),
209 18 => Some(Self::Copper),
210 19 => Some(Self::Silver),
211 20 => Some(Self::Gold),
212 _ => None,
213 }
214 }
215
216 #[must_use]
218 pub const fn value(self) -> u8 {
219 self as u8
220 }
221}
222
223impl ToTlv for ColorEnum {
224 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
225 self.value().to_tlv(w, tag)
226 }
227}
228
229impl<'a> FromTlv<'a> for ColorEnum {
230 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
231 let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
232 Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
233 }
234}
235
236#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
238#[repr(u8)]
239pub enum ProductFinishEnum {
240 Other = 0,
242 Matte = 1,
244 Satin = 2,
246 Polished = 3,
248 Rugged = 4,
250 Fabric = 5,
252}
253
254impl ProductFinishEnum {
255 #[must_use]
257 pub const fn from_value(value: u8) -> Option<Self> {
258 match value {
259 0 => Some(Self::Other),
260 1 => Some(Self::Matte),
261 2 => Some(Self::Satin),
262 3 => Some(Self::Polished),
263 4 => Some(Self::Rugged),
264 5 => Some(Self::Fabric),
265 _ => None,
266 }
267 }
268
269 #[must_use]
271 pub const fn value(self) -> u8 {
272 self as u8
273 }
274}
275
276impl ToTlv for ProductFinishEnum {
277 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
278 self.value().to_tlv(w, tag)
279 }
280}
281
282impl<'a> FromTlv<'a> for ProductFinishEnum {
283 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
284 let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
285 Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
286 }
287}
288
289#[derive(Debug, Clone, Copy, PartialEq)]
291pub struct CapabilityMinimaStruct {
292 pub case_sessions_per_fabric: u16,
294 pub subscriptions_per_fabric: u16,
296 pub simultaneous_invocations_supported: Option<u16>,
298 pub simultaneous_writes_supported: Option<u16>,
300 pub read_paths_supported: Option<u16>,
302 pub subscribe_paths_supported: Option<u16>,
304}
305
306impl ToTlv for CapabilityMinimaStruct {
307 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
308 w.start_structure(tag)?;
309 self.case_sessions_per_fabric.to_tlv(w, Tag::Context(0))?;
310 self.subscriptions_per_fabric.to_tlv(w, Tag::Context(1))?;
311 if let Some(value) = &self.simultaneous_invocations_supported {
312 value.to_tlv(w, Tag::Context(2))?;
313 }
314 if let Some(value) = &self.simultaneous_writes_supported {
315 value.to_tlv(w, Tag::Context(3))?;
316 }
317 if let Some(value) = &self.read_paths_supported {
318 value.to_tlv(w, Tag::Context(4))?;
319 }
320 if let Some(value) = &self.subscribe_paths_supported {
321 value.to_tlv(w, Tag::Context(5))?;
322 }
323 w.end_container()
324 }
325}
326
327impl<'a> FromTlv<'a> for CapabilityMinimaStruct {
328 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
329 if element.value.container() != Some(ContainerKind::Structure) {
330 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
331 }
332 let mut case_sessions_per_fabric = None;
333 let mut subscriptions_per_fabric = None;
334 let mut simultaneous_invocations_supported = None;
335 let mut simultaneous_writes_supported = None;
336 let mut read_paths_supported = None;
337 let mut subscribe_paths_supported = None;
338 loop {
339 let Some(field) = reader.next_element()? else {
340 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
341 };
342 if field.value == Value::EndOfContainer {
343 break;
344 }
345 match field.tag.context() {
346 Some(0) => case_sessions_per_fabric = Some(<u16>::from_tlv(reader, &field)?),
347 Some(1) => subscriptions_per_fabric = Some(<u16>::from_tlv(reader, &field)?),
348 Some(2) => {
349 simultaneous_invocations_supported = Some(<u16>::from_tlv(reader, &field)?)
350 }
351 Some(3) => simultaneous_writes_supported = Some(<u16>::from_tlv(reader, &field)?),
352 Some(4) => read_paths_supported = Some(<u16>::from_tlv(reader, &field)?),
353 Some(5) => subscribe_paths_supported = Some(<u16>::from_tlv(reader, &field)?),
354 _ => reader.skip_value(&field)?,
358 }
359 }
360 Ok(Self {
361 case_sessions_per_fabric: case_sessions_per_fabric
362 .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
363 subscriptions_per_fabric: subscriptions_per_fabric
364 .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
365 simultaneous_invocations_supported,
366 simultaneous_writes_supported,
367 read_paths_supported,
368 subscribe_paths_supported,
369 })
370 }
371}
372
373#[derive(Debug, Clone, Copy, PartialEq)]
375pub struct ProductAppearanceStruct {
376 pub finish: ProductFinishEnum,
378 pub primary_color: Nullable<ColorEnum>,
380}
381
382impl ToTlv for ProductAppearanceStruct {
383 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
384 w.start_structure(tag)?;
385 self.finish.to_tlv(w, Tag::Context(0))?;
386 self.primary_color.to_tlv(w, Tag::Context(1))?;
387 w.end_container()
388 }
389}
390
391impl<'a> FromTlv<'a> for ProductAppearanceStruct {
392 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
393 if element.value.container() != Some(ContainerKind::Structure) {
394 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
395 }
396 let mut finish = None;
397 let mut primary_color = None;
398 loop {
399 let Some(field) = reader.next_element()? else {
400 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
401 };
402 if field.value == Value::EndOfContainer {
403 break;
404 }
405 match field.tag.context() {
406 Some(0) => finish = Some(<ProductFinishEnum>::from_tlv(reader, &field)?),
407 Some(1) => primary_color = Some(<Nullable<ColorEnum>>::from_tlv(reader, &field)?),
408 _ => reader.skip_value(&field)?,
412 }
413 }
414 Ok(Self {
415 finish: finish.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
416 primary_color: primary_color.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
417 })
418 }
419}
420
421#[derive(Debug, Clone, Copy, PartialEq)]
423pub struct KeepActiveFields {
424 pub stay_active_duration: u32,
426 pub timeout_ms: u32,
428}
429
430impl ToTlv for KeepActiveFields {
431 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
432 w.start_structure(tag)?;
433 self.stay_active_duration.to_tlv(w, Tag::Context(0))?;
434 self.timeout_ms.to_tlv(w, Tag::Context(1))?;
435 w.end_container()
436 }
437}
438
439impl<'a> FromTlv<'a> for KeepActiveFields {
440 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
441 if element.value.container() != Some(ContainerKind::Structure) {
442 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
443 }
444 let mut stay_active_duration = None;
445 let mut timeout_ms = None;
446 loop {
447 let Some(field) = reader.next_element()? else {
448 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
449 };
450 if field.value == Value::EndOfContainer {
451 break;
452 }
453 match field.tag.context() {
454 Some(0) => stay_active_duration = Some(<u32>::from_tlv(reader, &field)?),
455 Some(1) => timeout_ms = Some(<u32>::from_tlv(reader, &field)?),
456 _ => reader.skip_value(&field)?,
460 }
461 }
462 Ok(Self {
463 stay_active_duration: stay_active_duration
464 .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
465 timeout_ms: timeout_ms.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
466 })
467 }
468}
469
470pub const ATTRIBUTES: &[Attribute] = &[
472 Attribute {
473 id: 0x0000,
474 name: "DataModelRevision",
475 kind: "uint16",
476 access: Access::read_only(Privilege::View),
477 qualities: AttributeQualities::FIXED,
478 reporting: Reporting::OnChange,
479 conform: Conform::DISALLOWED,
480 },
481 Attribute {
482 id: 0x0001,
483 name: "VendorName",
484 kind: "string",
485 access: Access::read_only(Privilege::View),
486 qualities: AttributeQualities::FIXED,
487 reporting: Reporting::OnChange,
488 conform: Conform::DESCRIBED,
489 },
490 Attribute {
491 id: 0x0002,
492 name: "VendorID",
493 kind: "vendor-id",
494 access: Access::read_only(Privilege::View),
495 qualities: AttributeQualities::FIXED,
496 reporting: Reporting::OnChange,
497 conform: Conform::DESCRIBED,
498 },
499 Attribute {
500 id: 0x0003,
501 name: "ProductName",
502 kind: "string",
503 access: Access::read_only(Privilege::View),
504 qualities: AttributeQualities::FIXED,
505 reporting: Reporting::OnChange,
506 conform: Conform::OPTIONAL,
507 },
508 Attribute {
509 id: 0x0004,
510 name: "ProductID",
511 kind: "uint16",
512 access: Access::read_only(Privilege::View),
513 qualities: AttributeQualities::FIXED,
514 reporting: Reporting::OnChange,
515 conform: Conform::DESCRIBED,
516 },
517 Attribute {
518 id: 0x0005,
519 name: "NodeLabel",
520 kind: "string",
521 access: Access::read_write_with(Privilege::View, Privilege::Manage),
522 qualities: AttributeQualities::NON_VOLATILE,
523 reporting: Reporting::OnChange,
524 conform: Conform::OPTIONAL,
525 },
526 Attribute {
527 id: 0x0006,
528 name: "Location",
529 kind: "string",
530 access: Access::read_write_with(Privilege::View, Privilege::Administer),
531 qualities: AttributeQualities::NON_VOLATILE,
532 reporting: Reporting::OnChange,
533 conform: Conform::DISALLOWED,
534 },
535 Attribute {
536 id: 0x0007,
537 name: "HardwareVersion",
538 kind: "uint16",
539 access: Access::read_only(Privilege::View),
540 qualities: AttributeQualities::FIXED,
541 reporting: Reporting::OnChange,
542 conform: Conform::OPTIONAL,
543 },
544 Attribute {
545 id: 0x0008,
546 name: "HardwareVersionString",
547 kind: "string",
548 access: Access::read_only(Privilege::View),
549 qualities: AttributeQualities::FIXED,
550 reporting: Reporting::OnChange,
551 conform: Conform::OPTIONAL,
552 },
553 Attribute {
554 id: 0x0009,
555 name: "SoftwareVersion",
556 kind: "uint32",
557 access: Access::read_only(Privilege::View),
558 qualities: AttributeQualities::FIXED,
559 reporting: Reporting::OnChange,
560 conform: Conform::OPTIONAL,
561 },
562 Attribute {
563 id: 0x000A,
564 name: "SoftwareVersionString",
565 kind: "string",
566 access: Access::read_only(Privilege::View),
567 qualities: AttributeQualities::FIXED,
568 reporting: Reporting::OnChange,
569 conform: Conform::OPTIONAL,
570 },
571 Attribute {
572 id: 0x000B,
573 name: "ManufacturingDate",
574 kind: "string",
575 access: Access::read_only(Privilege::View),
576 qualities: AttributeQualities::FIXED,
577 reporting: Reporting::OnChange,
578 conform: Conform::OPTIONAL,
579 },
580 Attribute {
581 id: 0x000C,
582 name: "PartNumber",
583 kind: "string",
584 access: Access::read_only(Privilege::View),
585 qualities: AttributeQualities::FIXED,
586 reporting: Reporting::OnChange,
587 conform: Conform::OPTIONAL,
588 },
589 Attribute {
590 id: 0x000D,
591 name: "ProductURL",
592 kind: "string",
593 access: Access::read_only(Privilege::View),
594 qualities: AttributeQualities::FIXED,
595 reporting: Reporting::OnChange,
596 conform: Conform::OPTIONAL,
597 },
598 Attribute {
599 id: 0x000E,
600 name: "ProductLabel",
601 kind: "string",
602 access: Access::read_only(Privilege::View),
603 qualities: AttributeQualities::FIXED,
604 reporting: Reporting::OnChange,
605 conform: Conform::OPTIONAL,
606 },
607 Attribute {
608 id: 0x000F,
609 name: "SerialNumber",
610 kind: "string",
611 access: Access::read_only(Privilege::View),
612 qualities: AttributeQualities::FIXED,
613 reporting: Reporting::OnChange,
614 conform: Conform::OPTIONAL,
615 },
616 Attribute {
617 id: 0x0010,
618 name: "LocalConfigDisabled",
619 kind: "bool",
620 access: Access::read_write_with(Privilege::View, Privilege::Manage),
621 qualities: AttributeQualities::NON_VOLATILE,
622 reporting: Reporting::OnChange,
623 conform: Conform::DISALLOWED,
624 },
625 Attribute {
626 id: 0x0011,
627 name: "Reachable",
628 kind: "bool",
629 access: Access::read_only(Privilege::View),
630 qualities: AttributeQualities::empty(),
631 reporting: Reporting::OnChange,
632 conform: Conform::MANDATORY,
633 },
634 Attribute {
635 id: 0x0012,
636 name: "UniqueID",
637 kind: "string",
638 access: Access::read_only(Privilege::View),
639 qualities: AttributeQualities::FIXED,
640 reporting: Reporting::OnChange,
641 conform: Conform {
642 clauses: &[
643 Clause {
644 verdict: Conformance::Described,
645 when: Condition::Named("comparison"),
646 },
647 Clause {
648 verdict: Conformance::Optional,
649 when: Condition::Always,
650 },
651 ],
652 },
653 },
654 Attribute {
655 id: 0x0013,
656 name: "CapabilityMinima",
657 kind: "CapabilityMinimaStruct",
658 access: Access::read_only(Privilege::View),
659 qualities: AttributeQualities::FIXED,
660 reporting: Reporting::OnChange,
661 conform: Conform::DISALLOWED,
662 },
663 Attribute {
664 id: 0x0014,
665 name: "ProductAppearance",
666 kind: "ProductAppearanceStruct",
667 access: Access::read_only(Privilege::View),
668 qualities: AttributeQualities::FIXED,
669 reporting: Reporting::OnChange,
670 conform: Conform {
671 clauses: &[Clause {
672 verdict: Conformance::Described,
673 when: Condition::Named("comparison"),
674 }],
675 },
676 },
677 Attribute {
678 id: 0x0015,
679 name: "SpecificationVersion",
680 kind: "uint32",
681 access: Access::read_only(Privilege::View),
682 qualities: AttributeQualities::FIXED,
683 reporting: Reporting::OnChange,
684 conform: Conform::DISALLOWED,
685 },
686 Attribute {
687 id: 0x0016,
688 name: "MaxPathsPerInvoke",
689 kind: "uint16",
690 access: Access::read_only(Privilege::View),
691 qualities: AttributeQualities::FIXED,
692 reporting: Reporting::OnChange,
693 conform: Conform::DISALLOWED,
694 },
695 Attribute {
696 id: 0x0018,
697 name: "ConfigurationVersion",
698 kind: "uint32",
699 access: Access::read_only(Privilege::View),
700 qualities: AttributeQualities::NON_VOLATILE,
701 reporting: Reporting::OnChange,
702 conform: Conform {
703 clauses: &[Clause {
704 verdict: Conformance::Described,
705 when: Condition::Named("comparison"),
706 }],
707 },
708 },
709];
710
711pub const COMMANDS: &[Command] = &[Command {
713 id: 0x80,
714 name: "KeepActive",
715 to_server: true,
716 response: None,
717 access: Access::invoke(Privilege::Operate),
718 conform: Conform {
719 clauses: &[Clause {
720 verdict: Conformance::Mandatory,
721 when: Condition::Feature(20),
722 }],
723 },
724}];
725
726pub const EVENTS: &[Event] = &[
728 Event {
729 id: 0x00,
730 name: "StartUp",
731 priority: EventPriority::Critical,
732 access: Access::read_only(Privilege::View),
733 conform: Conform::OPTIONAL,
734 },
735 Event {
736 id: 0x01,
737 name: "ShutDown",
738 priority: EventPriority::Critical,
739 access: Access::read_only(Privilege::View),
740 conform: Conform::OPTIONAL,
741 },
742 Event {
743 id: 0x02,
744 name: "Leave",
745 priority: EventPriority::Info,
746 access: Access::read_only(Privilege::View),
747 conform: Conform::OPTIONAL,
748 },
749 Event {
750 id: 0x03,
751 name: "ReachableChanged",
752 priority: EventPriority::Info,
753 access: Access::read_only(Privilege::View),
754 conform: Conform::MANDATORY,
755 },
756 Event {
757 id: 0x80,
758 name: "ActiveChanged",
759 priority: EventPriority::Info,
760 access: Access::read_only(Privilege::View),
761 conform: Conform {
762 clauses: &[Clause {
763 verdict: Conformance::Mandatory,
764 when: Condition::Feature(20),
765 }],
766 },
767 },
768];
769
770pub const CLUSTER: Cluster = Cluster {
772 id: ID,
773 name: "Bridged Device Basic Information",
774 revision: REVISION,
775 pics: "BRBINFO",
776 derived_from: Some("Basic Information"),
777 features: FEATURES,
778 attributes: ATTRIBUTES,
779 commands: COMMANDS,
780 events: EVENTS,
781};