#![allow(unused_imports)]
use crate::dm::conformance::{Clause, Condition, Conform, Conformance};
use crate::dm::meta::{EventPriority, Reporting};
use crate::dm::spec::{Attribute, Cluster, Command, Event, Feature};
use crate::dm::{Access, AccessQualities, AttributeQualities, Privilege};
use crate::error::Result;
use crate::im::{AttributeId, ClusterId, CommandId, EventId};
use crate::tlv::{
ContainerKind, Element, FromTlv, Nullable, Tag, TlvList, TlvReader, TlvWriter, ToTlv, Value,
};
pub const ID: ClusterId = 0x0802;
pub const REVISION: u16 = 1;
pub const PICS: &str = "TLSCLIENT";
pub const FEATURES: &[Feature] = &[];
pub mod attribute {
use crate::im::AttributeId;
pub const MAX_PROVISIONED: AttributeId = 0x00;
pub const PROVISIONED_ENDPOINTS: AttributeId = 0x01;
}
pub mod command {
use crate::im::CommandId;
pub const PROVISION_ENDPOINT: CommandId = 0x00;
pub const PROVISION_ENDPOINT_RESPONSE: CommandId = 0x01;
pub const FIND_ENDPOINT: CommandId = 0x02;
pub const FIND_ENDPOINT_RESPONSE: CommandId = 0x03;
pub const REMOVE_ENDPOINT: CommandId = 0x04;
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(u8)]
pub enum StatusCodeEnum {
EndpointAlreadyInstalled = 2,
RootCertificateNotFound = 3,
ClientCertificateNotFound = 4,
EndpointInUse = 5,
InvalidTime = 6,
}
impl StatusCodeEnum {
#[must_use]
pub const fn from_value(value: u8) -> Option<Self> {
match value {
2 => Some(Self::EndpointAlreadyInstalled),
3 => Some(Self::RootCertificateNotFound),
4 => Some(Self::ClientCertificateNotFound),
5 => Some(Self::EndpointInUse),
6 => Some(Self::InvalidTime),
_ => None,
}
}
#[must_use]
pub const fn value(self) -> u8 {
self as u8
}
}
impl ToTlv for StatusCodeEnum {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
self.value().to_tlv(w, tag)
}
}
impl<'a> FromTlv<'a> for StatusCodeEnum {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct TLSEndpointStruct<'a> {
pub endpoint_id: u16,
pub hostname: &'a [u8],
pub port: u16,
pub caid: u16,
pub ccdid: Nullable<u16>,
pub reference_count: u8,
pub fabric_index: crate::msg::FabricIndex,
}
impl<'a> ToTlv for TLSEndpointStruct<'a> {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.endpoint_id.to_tlv(w, Tag::Context(0))?;
self.hostname.to_tlv(w, Tag::Context(1))?;
self.port.to_tlv(w, Tag::Context(2))?;
self.caid.to_tlv(w, Tag::Context(3))?;
self.ccdid.to_tlv(w, Tag::Context(4))?;
self.reference_count.to_tlv(w, Tag::Context(5))?;
self.fabric_index.to_tlv(w, Tag::Context(254))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for TLSEndpointStruct<'a> {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
if element.value.container() != Some(ContainerKind::Structure) {
return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
}
let mut endpoint_id = None;
let mut hostname = None;
let mut port = None;
let mut caid = None;
let mut ccdid = None;
let mut reference_count = None;
let mut fabric_index = None;
loop {
let Some(field) = reader.next_element()? else {
return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
};
if field.value == Value::EndOfContainer {
break;
}
match field.tag.context() {
Some(0) => endpoint_id = Some(<u16>::from_tlv(reader, &field)?),
Some(1) => hostname = Some(<&'a [u8]>::from_tlv(reader, &field)?),
Some(2) => port = Some(<u16>::from_tlv(reader, &field)?),
Some(3) => caid = Some(<u16>::from_tlv(reader, &field)?),
Some(4) => ccdid = Some(<Nullable<u16>>::from_tlv(reader, &field)?),
Some(5) => reference_count = Some(<u8>::from_tlv(reader, &field)?),
Some(254) => {
fabric_index = Some(<crate::msg::FabricIndex>::from_tlv(reader, &field)?)
}
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
endpoint_id: endpoint_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
hostname: hostname.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
port: port.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
caid: caid.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
ccdid: ccdid.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
reference_count: reference_count
.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
fabric_index: fabric_index.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct ProvisionEndpointFields<'a> {
pub hostname: &'a [u8],
pub port: u16,
pub caid: u16,
pub ccdid: Nullable<u16>,
pub endpoint_id: Nullable<u16>,
}
impl<'a> ToTlv for ProvisionEndpointFields<'a> {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.hostname.to_tlv(w, Tag::Context(0))?;
self.port.to_tlv(w, Tag::Context(1))?;
self.caid.to_tlv(w, Tag::Context(2))?;
self.ccdid.to_tlv(w, Tag::Context(3))?;
self.endpoint_id.to_tlv(w, Tag::Context(4))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for ProvisionEndpointFields<'a> {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
if element.value.container() != Some(ContainerKind::Structure) {
return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
}
let mut hostname = None;
let mut port = None;
let mut caid = None;
let mut ccdid = None;
let mut endpoint_id = None;
loop {
let Some(field) = reader.next_element()? else {
return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
};
if field.value == Value::EndOfContainer {
break;
}
match field.tag.context() {
Some(0) => hostname = Some(<&'a [u8]>::from_tlv(reader, &field)?),
Some(1) => port = Some(<u16>::from_tlv(reader, &field)?),
Some(2) => caid = Some(<u16>::from_tlv(reader, &field)?),
Some(3) => ccdid = Some(<Nullable<u16>>::from_tlv(reader, &field)?),
Some(4) => endpoint_id = Some(<Nullable<u16>>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
hostname: hostname.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
port: port.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
caid: caid.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
ccdid: ccdid.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
endpoint_id: endpoint_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct ProvisionEndpointResponseFields {
pub endpoint_id: u16,
}
impl ToTlv for ProvisionEndpointResponseFields {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.endpoint_id.to_tlv(w, Tag::Context(0))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for ProvisionEndpointResponseFields {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
if element.value.container() != Some(ContainerKind::Structure) {
return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
}
let mut endpoint_id = None;
loop {
let Some(field) = reader.next_element()? else {
return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
};
if field.value == Value::EndOfContainer {
break;
}
match field.tag.context() {
Some(0) => endpoint_id = Some(<u16>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
endpoint_id: endpoint_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct FindEndpointFields {
pub endpoint_id: u16,
}
impl ToTlv for FindEndpointFields {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.endpoint_id.to_tlv(w, Tag::Context(0))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for FindEndpointFields {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
if element.value.container() != Some(ContainerKind::Structure) {
return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
}
let mut endpoint_id = None;
loop {
let Some(field) = reader.next_element()? else {
return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
};
if field.value == Value::EndOfContainer {
break;
}
match field.tag.context() {
Some(0) => endpoint_id = Some(<u16>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
endpoint_id: endpoint_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct FindEndpointResponseFields<'a> {
pub endpoint: TLSEndpointStruct<'a>,
}
impl<'a> ToTlv for FindEndpointResponseFields<'a> {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.endpoint.to_tlv(w, Tag::Context(0))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for FindEndpointResponseFields<'a> {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
if element.value.container() != Some(ContainerKind::Structure) {
return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
}
let mut endpoint = None;
loop {
let Some(field) = reader.next_element()? else {
return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
};
if field.value == Value::EndOfContainer {
break;
}
match field.tag.context() {
Some(0) => endpoint = Some(<TLSEndpointStruct<'a>>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
endpoint: endpoint.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct RemoveEndpointFields {
pub endpoint_id: u16,
}
impl ToTlv for RemoveEndpointFields {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.endpoint_id.to_tlv(w, Tag::Context(0))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for RemoveEndpointFields {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
if element.value.container() != Some(ContainerKind::Structure) {
return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
}
let mut endpoint_id = None;
loop {
let Some(field) = reader.next_element()? else {
return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
};
if field.value == Value::EndOfContainer {
break;
}
match field.tag.context() {
Some(0) => endpoint_id = Some(<u16>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
endpoint_id: endpoint_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
pub const ATTRIBUTES: &[Attribute] = &[
Attribute {
id: 0x0000,
name: "MaxProvisioned",
kind: "uint8",
access: Access::read_only(Privilege::View),
qualities: AttributeQualities::FIXED,
reporting: Reporting::OnChange,
conform: Conform::MANDATORY,
},
Attribute {
id: 0x0001,
name: "ProvisionedEndpoints",
kind: "list[TLSEndpointStruct]",
access: Access::read_only(Privilege::View)
.with_qualities(AccessQualities::FABRIC_SENSITIVE),
qualities: AttributeQualities::NON_VOLATILE,
reporting: Reporting::OnChange,
conform: Conform::MANDATORY,
},
];
pub const COMMANDS: &[Command] = &[
Command {
id: 0x00,
name: "ProvisionEndpoint",
to_server: true,
response: Some(0x01),
access: Access::invoke(Privilege::Administer)
.with_qualities(AccessQualities::FABRIC_SCOPED.union(AccessQualities::LARGE)),
conform: Conform::MANDATORY,
},
Command {
id: 0x01,
name: "ProvisionEndpointResponse",
to_server: false,
response: None,
access: Access::invoke(Privilege::Operate).with_qualities(AccessQualities::LARGE),
conform: Conform::MANDATORY,
},
Command {
id: 0x02,
name: "FindEndpoint",
to_server: true,
response: Some(0x03),
access: Access::invoke(Privilege::Operate)
.with_qualities(AccessQualities::FABRIC_SCOPED.union(AccessQualities::LARGE)),
conform: Conform::MANDATORY,
},
Command {
id: 0x03,
name: "FindEndpointResponse",
to_server: false,
response: None,
access: Access::invoke(Privilege::Operate).with_qualities(AccessQualities::LARGE),
conform: Conform::MANDATORY,
},
Command {
id: 0x04,
name: "RemoveEndpoint",
to_server: true,
response: None,
access: Access::invoke(Privilege::Administer)
.with_qualities(AccessQualities::FABRIC_SCOPED.union(AccessQualities::LARGE)),
conform: Conform::MANDATORY,
},
];
pub const EVENTS: &[Event] = &[];
pub const CLUSTER: Cluster = Cluster {
id: ID,
name: "TLS Client Management",
revision: REVISION,
pics: "TLSCLIENT",
derived_from: None,
features: FEATURES,
attributes: ATTRIBUTES,
commands: COMMANDS,
events: EVENTS,
};