#![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 = 0x050E;
pub const REVISION: u16 = 2;
pub const PICS: &str = "ALOGIN";
pub const FEATURES: &[Feature] = &[];
pub mod command {
use crate::im::CommandId;
pub const GET_SETUP_PIN: CommandId = 0x00;
pub const GET_SETUP_PIN_RESPONSE: CommandId = 0x01;
pub const LOGIN: CommandId = 0x02;
pub const LOGOUT: CommandId = 0x03;
}
pub mod event {
use crate::im::EventId;
pub const LOGGED_OUT: EventId = 0x00;
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct GetSetupPINFields<'a> {
pub temp_account_identifier: &'a str,
}
impl<'a> ToTlv for GetSetupPINFields<'a> {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.temp_account_identifier.to_tlv(w, Tag::Context(0))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for GetSetupPINFields<'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 temp_account_identifier = 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) => temp_account_identifier = Some(<&'a str>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
temp_account_identifier: temp_account_identifier
.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct GetSetupPINResponseFields<'a> {
pub setup_pin: &'a str,
}
impl<'a> ToTlv for GetSetupPINResponseFields<'a> {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.setup_pin.to_tlv(w, Tag::Context(0))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for GetSetupPINResponseFields<'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 setup_pin = 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) => setup_pin = Some(<&'a str>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
setup_pin: setup_pin.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct LoginFields<'a> {
pub temp_account_identifier: &'a str,
pub setup_pin: &'a str,
pub node: Option<crate::msg::NodeId>,
}
impl<'a> ToTlv for LoginFields<'a> {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.temp_account_identifier.to_tlv(w, Tag::Context(0))?;
self.setup_pin.to_tlv(w, Tag::Context(1))?;
if let Some(value) = &self.node {
value.to_tlv(w, Tag::Context(2))?;
}
w.end_container()
}
}
impl<'a> FromTlv<'a> for LoginFields<'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 temp_account_identifier = None;
let mut setup_pin = None;
let mut node = 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) => temp_account_identifier = Some(<&'a str>::from_tlv(reader, &field)?),
Some(1) => setup_pin = Some(<&'a str>::from_tlv(reader, &field)?),
Some(2) => node = Some(<crate::msg::NodeId>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
temp_account_identifier: temp_account_identifier
.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
setup_pin: setup_pin.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
node,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct LogoutFields {
pub node: Option<crate::msg::NodeId>,
}
impl ToTlv for LogoutFields {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
if let Some(value) = &self.node {
value.to_tlv(w, Tag::Context(0))?;
}
w.end_container()
}
}
impl<'a> FromTlv<'a> for LogoutFields {
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 node = 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) => node = Some(<crate::msg::NodeId>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self { node })
}
}
pub const ATTRIBUTES: &[Attribute] = &[];
pub const COMMANDS: &[Command] = &[
Command {
id: 0x00,
name: "GetSetupPIN",
to_server: true,
response: Some(0x01),
access: Access::invoke(Privilege::Administer)
.with_qualities(AccessQualities::FABRIC_SCOPED.union(AccessQualities::TIMED)),
conform: Conform::MANDATORY,
},
Command {
id: 0x01,
name: "GetSetupPINResponse",
to_server: false,
response: None,
access: Access::invoke(Privilege::Operate).with_qualities(AccessQualities::FABRIC_SCOPED),
conform: Conform::MANDATORY,
},
Command {
id: 0x02,
name: "Login",
to_server: true,
response: None,
access: Access::invoke(Privilege::Administer)
.with_qualities(AccessQualities::FABRIC_SCOPED.union(AccessQualities::TIMED)),
conform: Conform::MANDATORY,
},
Command {
id: 0x03,
name: "Logout",
to_server: true,
response: None,
access: Access::invoke(Privilege::Operate)
.with_qualities(AccessQualities::FABRIC_SCOPED.union(AccessQualities::TIMED)),
conform: Conform::MANDATORY,
},
];
pub const EVENTS: &[Event] = &[Event {
id: 0x00,
name: "LoggedOut",
priority: EventPriority::Critical,
access: Access::read_only(Privilege::Administer)
.with_qualities(AccessQualities::FABRIC_SENSITIVE),
conform: Conform::OPTIONAL,
}];
pub const CLUSTER: Cluster = Cluster {
id: ID,
name: "Account Login",
revision: REVISION,
pics: "ALOGIN",
derived_from: None,
features: FEATURES,
attributes: ATTRIBUTES,
commands: COMMANDS,
events: EVENTS,
};