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 = 0x0028;
28
29pub const REVISION: u16 = 6;
32
33pub const PICS: &str = "BINFO";
35
36pub const FEATURES: &[Feature] = &[];
38
39pub mod attribute {
41 use crate::im::AttributeId;
42
43 pub const DATA_MODEL_REVISION: AttributeId = 0x00;
45 pub const VENDOR_NAME: AttributeId = 0x01;
47 pub const VENDOR_ID: AttributeId = 0x02;
49 pub const PRODUCT_NAME: AttributeId = 0x03;
51 pub const PRODUCT_ID: AttributeId = 0x04;
53 pub const NODE_LABEL: AttributeId = 0x05;
55 pub const LOCATION: AttributeId = 0x06;
57 pub const HARDWARE_VERSION: AttributeId = 0x07;
59 pub const HARDWARE_VERSION_STRING: AttributeId = 0x08;
61 pub const SOFTWARE_VERSION: AttributeId = 0x09;
63 pub const SOFTWARE_VERSION_STRING: AttributeId = 0x0A;
65 pub const MANUFACTURING_DATE: AttributeId = 0x0B;
67 pub const PART_NUMBER: AttributeId = 0x0C;
69 pub const PRODUCT_URL: AttributeId = 0x0D;
71 pub const PRODUCT_LABEL: AttributeId = 0x0E;
73 pub const SERIAL_NUMBER: AttributeId = 0x0F;
75 pub const LOCAL_CONFIG_DISABLED: AttributeId = 0x10;
77 pub const REACHABLE: AttributeId = 0x11;
79 pub const UNIQUE_ID: AttributeId = 0x12;
81 pub const CAPABILITY_MINIMA: AttributeId = 0x13;
83 pub const PRODUCT_APPEARANCE: AttributeId = 0x14;
85 pub const SPECIFICATION_VERSION: AttributeId = 0x15;
87 pub const MAX_PATHS_PER_INVOKE: AttributeId = 0x16;
89 pub const CONFIGURATION_VERSION: AttributeId = 0x18;
91}
92
93pub mod event {
95 use crate::im::EventId;
96
97 pub const START_UP: EventId = 0x00;
99 pub const SHUT_DOWN: EventId = 0x01;
101 pub const LEAVE: EventId = 0x02;
103 pub const REACHABLE_CHANGED: EventId = 0x03;
105}
106
107#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
109#[repr(u8)]
110pub enum ColorEnum {
111 Black = 0,
113 Navy = 1,
115 Green = 2,
117 Teal = 3,
119 Maroon = 4,
121 Purple = 5,
123 Olive = 6,
125 Gray = 7,
127 Blue = 8,
129 Lime = 9,
131 Aqua = 10,
133 Red = 11,
135 Fuchsia = 12,
137 Yellow = 13,
139 White = 14,
141 Nickel = 15,
143 Chrome = 16,
145 Brass = 17,
147 Copper = 18,
149 Silver = 19,
151 Gold = 20,
153}
154
155impl ColorEnum {
156 #[must_use]
158 pub const fn from_value(value: u8) -> Option<Self> {
159 match value {
160 0 => Some(Self::Black),
161 1 => Some(Self::Navy),
162 2 => Some(Self::Green),
163 3 => Some(Self::Teal),
164 4 => Some(Self::Maroon),
165 5 => Some(Self::Purple),
166 6 => Some(Self::Olive),
167 7 => Some(Self::Gray),
168 8 => Some(Self::Blue),
169 9 => Some(Self::Lime),
170 10 => Some(Self::Aqua),
171 11 => Some(Self::Red),
172 12 => Some(Self::Fuchsia),
173 13 => Some(Self::Yellow),
174 14 => Some(Self::White),
175 15 => Some(Self::Nickel),
176 16 => Some(Self::Chrome),
177 17 => Some(Self::Brass),
178 18 => Some(Self::Copper),
179 19 => Some(Self::Silver),
180 20 => Some(Self::Gold),
181 _ => None,
182 }
183 }
184
185 #[must_use]
187 pub const fn value(self) -> u8 {
188 self as u8
189 }
190}
191
192impl ToTlv for ColorEnum {
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 ColorEnum {
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#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
207#[repr(u8)]
208pub enum ProductFinishEnum {
209 Other = 0,
211 Matte = 1,
213 Satin = 2,
215 Polished = 3,
217 Rugged = 4,
219 Fabric = 5,
221}
222
223impl ProductFinishEnum {
224 #[must_use]
226 pub const fn from_value(value: u8) -> Option<Self> {
227 match value {
228 0 => Some(Self::Other),
229 1 => Some(Self::Matte),
230 2 => Some(Self::Satin),
231 3 => Some(Self::Polished),
232 4 => Some(Self::Rugged),
233 5 => Some(Self::Fabric),
234 _ => None,
235 }
236 }
237
238 #[must_use]
240 pub const fn value(self) -> u8 {
241 self as u8
242 }
243}
244
245impl ToTlv for ProductFinishEnum {
246 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
247 self.value().to_tlv(w, tag)
248 }
249}
250
251impl<'a> FromTlv<'a> for ProductFinishEnum {
252 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
253 let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
254 Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
255 }
256}
257
258#[derive(Debug, Clone, Copy, PartialEq)]
260pub struct CapabilityMinimaStruct {
261 pub case_sessions_per_fabric: u16,
263 pub subscriptions_per_fabric: u16,
265 pub simultaneous_invocations_supported: Option<u16>,
267 pub simultaneous_writes_supported: Option<u16>,
269 pub read_paths_supported: Option<u16>,
271 pub subscribe_paths_supported: Option<u16>,
273}
274
275impl ToTlv for CapabilityMinimaStruct {
276 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
277 w.start_structure(tag)?;
278 self.case_sessions_per_fabric.to_tlv(w, Tag::Context(0))?;
279 self.subscriptions_per_fabric.to_tlv(w, Tag::Context(1))?;
280 if let Some(value) = &self.simultaneous_invocations_supported {
281 value.to_tlv(w, Tag::Context(2))?;
282 }
283 if let Some(value) = &self.simultaneous_writes_supported {
284 value.to_tlv(w, Tag::Context(3))?;
285 }
286 if let Some(value) = &self.read_paths_supported {
287 value.to_tlv(w, Tag::Context(4))?;
288 }
289 if let Some(value) = &self.subscribe_paths_supported {
290 value.to_tlv(w, Tag::Context(5))?;
291 }
292 w.end_container()
293 }
294}
295
296impl<'a> FromTlv<'a> for CapabilityMinimaStruct {
297 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
298 if element.value.container() != Some(ContainerKind::Structure) {
299 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
300 }
301 let mut case_sessions_per_fabric = None;
302 let mut subscriptions_per_fabric = None;
303 let mut simultaneous_invocations_supported = None;
304 let mut simultaneous_writes_supported = None;
305 let mut read_paths_supported = None;
306 let mut subscribe_paths_supported = None;
307 loop {
308 let Some(field) = reader.next_element()? else {
309 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
310 };
311 if field.value == Value::EndOfContainer {
312 break;
313 }
314 match field.tag.context() {
315 Some(0) => case_sessions_per_fabric = Some(<u16>::from_tlv(reader, &field)?),
316 Some(1) => subscriptions_per_fabric = Some(<u16>::from_tlv(reader, &field)?),
317 Some(2) => {
318 simultaneous_invocations_supported = Some(<u16>::from_tlv(reader, &field)?)
319 }
320 Some(3) => simultaneous_writes_supported = Some(<u16>::from_tlv(reader, &field)?),
321 Some(4) => read_paths_supported = Some(<u16>::from_tlv(reader, &field)?),
322 Some(5) => subscribe_paths_supported = Some(<u16>::from_tlv(reader, &field)?),
323 _ => reader.skip_value(&field)?,
327 }
328 }
329 Ok(Self {
330 case_sessions_per_fabric: case_sessions_per_fabric
331 .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
332 subscriptions_per_fabric: subscriptions_per_fabric
333 .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
334 simultaneous_invocations_supported,
335 simultaneous_writes_supported,
336 read_paths_supported,
337 subscribe_paths_supported,
338 })
339 }
340}
341
342#[derive(Debug, Clone, Copy, PartialEq)]
344pub struct ProductAppearanceStruct {
345 pub finish: ProductFinishEnum,
347 pub primary_color: Nullable<ColorEnum>,
349}
350
351impl ToTlv for ProductAppearanceStruct {
352 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
353 w.start_structure(tag)?;
354 self.finish.to_tlv(w, Tag::Context(0))?;
355 self.primary_color.to_tlv(w, Tag::Context(1))?;
356 w.end_container()
357 }
358}
359
360impl<'a> FromTlv<'a> for ProductAppearanceStruct {
361 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
362 if element.value.container() != Some(ContainerKind::Structure) {
363 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
364 }
365 let mut finish = None;
366 let mut primary_color = 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) => finish = Some(<ProductFinishEnum>::from_tlv(reader, &field)?),
376 Some(1) => primary_color = Some(<Nullable<ColorEnum>>::from_tlv(reader, &field)?),
377 _ => reader.skip_value(&field)?,
381 }
382 }
383 Ok(Self {
384 finish: finish.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
385 primary_color: primary_color.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
386 })
387 }
388}
389
390pub const ATTRIBUTES: &[Attribute] = &[
392 Attribute {
393 id: 0x0000,
394 name: "DataModelRevision",
395 kind: "uint16",
396 access: Access::read_only(Privilege::View),
397 qualities: AttributeQualities::FIXED,
398 reporting: Reporting::OnChange,
399 conform: Conform::MANDATORY,
400 },
401 Attribute {
402 id: 0x0001,
403 name: "VendorName",
404 kind: "string",
405 access: Access::read_only(Privilege::View),
406 qualities: AttributeQualities::FIXED,
407 reporting: Reporting::OnChange,
408 conform: Conform::MANDATORY,
409 },
410 Attribute {
411 id: 0x0002,
412 name: "VendorID",
413 kind: "vendor-id",
414 access: Access::read_only(Privilege::View),
415 qualities: AttributeQualities::FIXED,
416 reporting: Reporting::OnChange,
417 conform: Conform::MANDATORY,
418 },
419 Attribute {
420 id: 0x0003,
421 name: "ProductName",
422 kind: "string",
423 access: Access::read_only(Privilege::View),
424 qualities: AttributeQualities::FIXED,
425 reporting: Reporting::OnChange,
426 conform: Conform::MANDATORY,
427 },
428 Attribute {
429 id: 0x0004,
430 name: "ProductID",
431 kind: "uint16",
432 access: Access::read_only(Privilege::View),
433 qualities: AttributeQualities::FIXED,
434 reporting: Reporting::OnChange,
435 conform: Conform::MANDATORY,
436 },
437 Attribute {
438 id: 0x0005,
439 name: "NodeLabel",
440 kind: "string",
441 access: Access::read_write_with(Privilege::View, Privilege::Manage),
442 qualities: AttributeQualities::NON_VOLATILE,
443 reporting: Reporting::OnChange,
444 conform: Conform::MANDATORY,
445 },
446 Attribute {
447 id: 0x0006,
448 name: "Location",
449 kind: "string",
450 access: Access::read_write_with(Privilege::View, Privilege::Administer),
451 qualities: AttributeQualities::NON_VOLATILE,
452 reporting: Reporting::OnChange,
453 conform: Conform::MANDATORY,
454 },
455 Attribute {
456 id: 0x0007,
457 name: "HardwareVersion",
458 kind: "uint16",
459 access: Access::read_only(Privilege::View),
460 qualities: AttributeQualities::FIXED,
461 reporting: Reporting::OnChange,
462 conform: Conform::MANDATORY,
463 },
464 Attribute {
465 id: 0x0008,
466 name: "HardwareVersionString",
467 kind: "string",
468 access: Access::read_only(Privilege::View),
469 qualities: AttributeQualities::FIXED,
470 reporting: Reporting::OnChange,
471 conform: Conform::MANDATORY,
472 },
473 Attribute {
474 id: 0x0009,
475 name: "SoftwareVersion",
476 kind: "uint32",
477 access: Access::read_only(Privilege::View),
478 qualities: AttributeQualities::FIXED,
479 reporting: Reporting::OnChange,
480 conform: Conform::MANDATORY,
481 },
482 Attribute {
483 id: 0x000A,
484 name: "SoftwareVersionString",
485 kind: "string",
486 access: Access::read_only(Privilege::View),
487 qualities: AttributeQualities::FIXED,
488 reporting: Reporting::OnChange,
489 conform: Conform::MANDATORY,
490 },
491 Attribute {
492 id: 0x000B,
493 name: "ManufacturingDate",
494 kind: "string",
495 access: Access::read_only(Privilege::View),
496 qualities: AttributeQualities::FIXED,
497 reporting: Reporting::OnChange,
498 conform: Conform::OPTIONAL,
499 },
500 Attribute {
501 id: 0x000C,
502 name: "PartNumber",
503 kind: "string",
504 access: Access::read_only(Privilege::View),
505 qualities: AttributeQualities::FIXED,
506 reporting: Reporting::OnChange,
507 conform: Conform::OPTIONAL,
508 },
509 Attribute {
510 id: 0x000D,
511 name: "ProductURL",
512 kind: "string",
513 access: Access::read_only(Privilege::View),
514 qualities: AttributeQualities::FIXED,
515 reporting: Reporting::OnChange,
516 conform: Conform::OPTIONAL,
517 },
518 Attribute {
519 id: 0x000E,
520 name: "ProductLabel",
521 kind: "string",
522 access: Access::read_only(Privilege::View),
523 qualities: AttributeQualities::FIXED,
524 reporting: Reporting::OnChange,
525 conform: Conform::OPTIONAL,
526 },
527 Attribute {
528 id: 0x000F,
529 name: "SerialNumber",
530 kind: "string",
531 access: Access::read_only(Privilege::View),
532 qualities: AttributeQualities::FIXED,
533 reporting: Reporting::OnChange,
534 conform: Conform::OPTIONAL,
535 },
536 Attribute {
537 id: 0x0010,
538 name: "LocalConfigDisabled",
539 kind: "bool",
540 access: Access::read_write_with(Privilege::View, Privilege::Manage),
541 qualities: AttributeQualities::NON_VOLATILE,
542 reporting: Reporting::OnChange,
543 conform: Conform::OPTIONAL,
544 },
545 Attribute {
546 id: 0x0011,
547 name: "Reachable",
548 kind: "bool",
549 access: Access::read_only(Privilege::View),
550 qualities: AttributeQualities::empty(),
551 reporting: Reporting::OnChange,
552 conform: Conform::OPTIONAL,
553 },
554 Attribute {
555 id: 0x0012,
556 name: "UniqueID",
557 kind: "string",
558 access: Access::read_only(Privilege::View),
559 qualities: AttributeQualities::FIXED,
560 reporting: Reporting::OnChange,
561 conform: Conform {
562 clauses: &[
563 Clause {
564 verdict: Conformance::Described,
565 when: Condition::Named("comparison"),
566 },
567 Clause {
568 verdict: Conformance::Optional,
569 when: Condition::Always,
570 },
571 ],
572 },
573 },
574 Attribute {
575 id: 0x0013,
576 name: "CapabilityMinima",
577 kind: "CapabilityMinimaStruct",
578 access: Access::read_only(Privilege::View),
579 qualities: AttributeQualities::FIXED,
580 reporting: Reporting::OnChange,
581 conform: Conform::MANDATORY,
582 },
583 Attribute {
584 id: 0x0014,
585 name: "ProductAppearance",
586 kind: "ProductAppearanceStruct",
587 access: Access::read_only(Privilege::View),
588 qualities: AttributeQualities::FIXED,
589 reporting: Reporting::OnChange,
590 conform: Conform {
591 clauses: &[Clause {
592 verdict: Conformance::Described,
593 when: Condition::Named("comparison"),
594 }],
595 },
596 },
597 Attribute {
598 id: 0x0015,
599 name: "SpecificationVersion",
600 kind: "uint32",
601 access: Access::read_only(Privilege::View),
602 qualities: AttributeQualities::FIXED,
603 reporting: Reporting::OnChange,
604 conform: Conform {
605 clauses: &[Clause {
606 verdict: Conformance::Described,
607 when: Condition::Named("comparison"),
608 }],
609 },
610 },
611 Attribute {
612 id: 0x0016,
613 name: "MaxPathsPerInvoke",
614 kind: "uint16",
615 access: Access::read_only(Privilege::View),
616 qualities: AttributeQualities::FIXED,
617 reporting: Reporting::OnChange,
618 conform: Conform {
619 clauses: &[Clause {
620 verdict: Conformance::Described,
621 when: Condition::Named("comparison"),
622 }],
623 },
624 },
625 Attribute {
626 id: 0x0018,
627 name: "ConfigurationVersion",
628 kind: "uint32",
629 access: Access::read_only(Privilege::View),
630 qualities: AttributeQualities::NON_VOLATILE,
631 reporting: Reporting::OnChange,
632 conform: Conform {
633 clauses: &[Clause {
634 verdict: Conformance::Described,
635 when: Condition::Named("comparison"),
636 }],
637 },
638 },
639];
640
641pub const COMMANDS: &[Command] = &[];
643
644pub const EVENTS: &[Event] = &[
646 Event {
647 id: 0x00,
648 name: "StartUp",
649 priority: EventPriority::Critical,
650 access: Access::read_only(Privilege::View),
651 conform: Conform::MANDATORY,
652 },
653 Event {
654 id: 0x01,
655 name: "ShutDown",
656 priority: EventPriority::Critical,
657 access: Access::read_only(Privilege::View),
658 conform: Conform::OPTIONAL,
659 },
660 Event {
661 id: 0x02,
662 name: "Leave",
663 priority: EventPriority::Info,
664 access: Access::read_only(Privilege::View),
665 conform: Conform::OPTIONAL,
666 },
667 Event {
668 id: 0x03,
669 name: "ReachableChanged",
670 priority: EventPriority::Info,
671 access: Access::read_only(Privilege::View),
672 conform: Conform {
673 clauses: &[Clause {
674 verdict: Conformance::Mandatory,
675 when: Condition::Attribute(0x0011),
676 }],
677 },
678 },
679];
680
681pub const CLUSTER: Cluster = Cluster {
683 id: ID,
684 name: "Basic Information",
685 revision: REVISION,
686 pics: "BINFO",
687 derived_from: None,
688 features: FEATURES,
689 attributes: ATTRIBUTES,
690 commands: COMMANDS,
691 events: EVENTS,
692};