#![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 = 0x050F;
pub const REVISION: u16 = 1;
pub const PICS: &str = "CONCON";
pub mod feature {
pub const SCREEN_TIME: u32 = 1 << 0;
pub const PIN_MANAGEMENT: u32 = 1 << 1;
pub const BLOCK_UNRATED: u32 = 1 << 2;
pub const ON_DEMAND_CONTENT_RATING: u32 = 1 << 3;
pub const SCHEDULED_CONTENT_RATING: u32 = 1 << 4;
pub const BLOCK_CHANNELS: u32 = 1 << 5;
pub const BLOCK_APPLICATIONS: u32 = 1 << 6;
pub const BLOCK_CONTENT_TIME_WINDOW: u32 = 1 << 7;
}
pub const FEATURES: &[Feature] = &[
Feature {
bit: 0,
code: "ST",
name: "ScreenTime",
conform: Conform::OPTIONAL,
},
Feature {
bit: 1,
code: "PM",
name: "PINManagement",
conform: Conform::OPTIONAL,
},
Feature {
bit: 2,
code: "BU",
name: "BlockUnrated",
conform: Conform::OPTIONAL,
},
Feature {
bit: 3,
code: "OCR",
name: "OnDemandContentRating",
conform: Conform::OPTIONAL,
},
Feature {
bit: 4,
code: "SCR",
name: "ScheduledContentRating",
conform: Conform::OPTIONAL,
},
Feature {
bit: 5,
code: "BC",
name: "BlockChannels",
conform: Conform::OPTIONAL,
},
Feature {
bit: 6,
code: "BA",
name: "BlockApplications",
conform: Conform::OPTIONAL,
},
Feature {
bit: 7,
code: "BTW",
name: "BlockContentTimeWindow",
conform: Conform::OPTIONAL,
},
];
pub mod attribute {
use crate::im::AttributeId;
pub const ENABLED: AttributeId = 0x00;
pub const ON_DEMAND_RATINGS: AttributeId = 0x01;
pub const ON_DEMAND_RATING_THRESHOLD: AttributeId = 0x02;
pub const SCHEDULED_CONTENT_RATINGS: AttributeId = 0x03;
pub const SCHEDULED_CONTENT_RATING_THRESHOLD: AttributeId = 0x04;
pub const SCREEN_DAILY_TIME: AttributeId = 0x05;
pub const REMAINING_SCREEN_TIME: AttributeId = 0x06;
pub const BLOCK_UNRATED: AttributeId = 0x07;
pub const BLOCK_CHANNEL_LIST: AttributeId = 0x08;
pub const BLOCK_APPLICATION_LIST: AttributeId = 0x09;
pub const BLOCK_CONTENT_TIME_WINDOW: AttributeId = 0x0A;
}
pub mod command {
use crate::im::CommandId;
pub const UPDATE_PIN: CommandId = 0x00;
pub const RESET_PIN: CommandId = 0x01;
pub const RESET_PIN_RESPONSE: CommandId = 0x02;
pub const ENABLE: CommandId = 0x03;
pub const DISABLE: CommandId = 0x04;
pub const ADD_BONUS_TIME: CommandId = 0x05;
pub const SET_SCREEN_DAILY_TIME: CommandId = 0x06;
pub const BLOCK_UNRATED_CONTENT: CommandId = 0x07;
pub const UNBLOCK_UNRATED_CONTENT: CommandId = 0x08;
pub const SET_ON_DEMAND_RATING_THRESHOLD: CommandId = 0x09;
pub const SET_SCHEDULED_CONTENT_RATING_THRESHOLD: CommandId = 0x0A;
pub const ADD_BLOCK_CHANNELS: CommandId = 0x0B;
pub const REMOVE_BLOCK_CHANNELS: CommandId = 0x0C;
pub const ADD_BLOCK_APPLICATIONS: CommandId = 0x0D;
pub const REMOVE_BLOCK_APPLICATIONS: CommandId = 0x0E;
pub const SET_BLOCK_CONTENT_TIME_WINDOW: CommandId = 0x0F;
pub const REMOVE_BLOCK_CONTENT_TIME_WINDOW: CommandId = 0x10;
}
pub mod event {
use crate::im::EventId;
pub const REMAINING_SCREEN_TIME_EXPIRED: EventId = 0x00;
pub const ENTERING_BLOCK_CONTENT_TIME_WINDOW: EventId = 0x01;
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(u8)]
pub enum StatusCodeEnum {
InvalidPINCode = 2,
InvalidRating = 3,
InvalidChannel = 4,
ChannelAlreadyExist = 5,
ChannelNotExist = 6,
UnidentifiableApplication = 7,
ApplicationAlreadyExist = 8,
ApplicationNotExist = 9,
TimeWindowAlreadyExist = 10,
TimeWindowNotExist = 11,
}
impl StatusCodeEnum {
#[must_use]
pub const fn from_value(value: u8) -> Option<Self> {
match value {
2 => Some(Self::InvalidPINCode),
3 => Some(Self::InvalidRating),
4 => Some(Self::InvalidChannel),
5 => Some(Self::ChannelAlreadyExist),
6 => Some(Self::ChannelNotExist),
7 => Some(Self::UnidentifiableApplication),
8 => Some(Self::ApplicationAlreadyExist),
9 => Some(Self::ApplicationNotExist),
10 => Some(Self::TimeWindowAlreadyExist),
11 => Some(Self::TimeWindowNotExist),
_ => 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))
}
}
bitflags::bitflags! {
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub struct DayOfWeekBitmap: u8 {
const SUNDAY = 1 << 0;
const MONDAY = 1 << 1;
const TUESDAY = 1 << 2;
const WEDNESDAY = 1 << 3;
const THURSDAY = 1 << 4;
const FRIDAY = 1 << 5;
const SATURDAY = 1 << 6;
}
}
impl ToTlv for DayOfWeekBitmap {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
self.bits().to_tlv(w, tag)
}
}
impl<'a> FromTlv<'a> for DayOfWeekBitmap {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
let bits = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
Self::from_bits(bits).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct AppInfoStruct<'a> {
pub catalog_vendor_id: u16,
pub application_id: &'a str,
}
impl<'a> ToTlv for AppInfoStruct<'a> {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.catalog_vendor_id.to_tlv(w, Tag::Context(0))?;
self.application_id.to_tlv(w, Tag::Context(1))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for AppInfoStruct<'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 catalog_vendor_id = None;
let mut application_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) => catalog_vendor_id = Some(<u16>::from_tlv(reader, &field)?),
Some(1) => application_id = Some(<&'a str>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
catalog_vendor_id: catalog_vendor_id
.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
application_id: application_id
.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct BlockChannelStruct<'a> {
pub block_channel_index: Nullable<u16>,
pub major_number: u16,
pub minor_number: u16,
pub identifier: Option<&'a str>,
}
impl<'a> ToTlv for BlockChannelStruct<'a> {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.block_channel_index.to_tlv(w, Tag::Context(0))?;
self.major_number.to_tlv(w, Tag::Context(1))?;
self.minor_number.to_tlv(w, Tag::Context(2))?;
if let Some(value) = &self.identifier {
value.to_tlv(w, Tag::Context(3))?;
}
w.end_container()
}
}
impl<'a> FromTlv<'a> for BlockChannelStruct<'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 block_channel_index = None;
let mut major_number = None;
let mut minor_number = None;
let mut 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) => block_channel_index = Some(<Nullable<u16>>::from_tlv(reader, &field)?),
Some(1) => major_number = Some(<u16>::from_tlv(reader, &field)?),
Some(2) => minor_number = Some(<u16>::from_tlv(reader, &field)?),
Some(3) => identifier = Some(<&'a str>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
block_channel_index: block_channel_index
.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
major_number: major_number.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
minor_number: minor_number.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
identifier,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct RatingNameStruct<'a> {
pub rating_name: &'a str,
pub rating_name_desc: Option<&'a str>,
}
impl<'a> ToTlv for RatingNameStruct<'a> {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.rating_name.to_tlv(w, Tag::Context(0))?;
if let Some(value) = &self.rating_name_desc {
value.to_tlv(w, Tag::Context(1))?;
}
w.end_container()
}
}
impl<'a> FromTlv<'a> for RatingNameStruct<'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 rating_name = None;
let mut rating_name_desc = 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) => rating_name = Some(<&'a str>::from_tlv(reader, &field)?),
Some(1) => rating_name_desc = Some(<&'a str>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
rating_name: rating_name.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
rating_name_desc,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct TimePeriodStruct {
pub start_hour: u8,
pub start_minute: u8,
pub end_hour: u8,
pub end_minute: u8,
}
impl ToTlv for TimePeriodStruct {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.start_hour.to_tlv(w, Tag::Context(0))?;
self.start_minute.to_tlv(w, Tag::Context(1))?;
self.end_hour.to_tlv(w, Tag::Context(2))?;
self.end_minute.to_tlv(w, Tag::Context(3))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for TimePeriodStruct {
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 start_hour = None;
let mut start_minute = None;
let mut end_hour = None;
let mut end_minute = 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) => start_hour = Some(<u8>::from_tlv(reader, &field)?),
Some(1) => start_minute = Some(<u8>::from_tlv(reader, &field)?),
Some(2) => end_hour = Some(<u8>::from_tlv(reader, &field)?),
Some(3) => end_minute = Some(<u8>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
start_hour: start_hour.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
start_minute: start_minute.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
end_hour: end_hour.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
end_minute: end_minute.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct TimeWindowStruct<'a> {
pub time_window_index: Nullable<u16>,
pub day_of_week: DayOfWeekBitmap,
pub time_period: TlvList<'a, TimePeriodStruct>,
}
impl<'a> ToTlv for TimeWindowStruct<'a> {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.time_window_index.to_tlv(w, Tag::Context(0))?;
self.day_of_week.to_tlv(w, Tag::Context(1))?;
self.time_period.to_tlv(w, Tag::Context(2))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for TimeWindowStruct<'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 time_window_index = None;
let mut day_of_week = None;
let mut time_period = 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) => time_window_index = Some(<Nullable<u16>>::from_tlv(reader, &field)?),
Some(1) => day_of_week = Some(<DayOfWeekBitmap>::from_tlv(reader, &field)?),
Some(2) => {
time_period = Some(<TlvList<'a, TimePeriodStruct>>::from_tlv(reader, &field)?)
}
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
time_window_index: time_window_index
.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
day_of_week: day_of_week.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
time_period: time_period.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct UpdatePINFields<'a> {
pub old_pin: &'a str,
pub new_pin: &'a str,
}
impl<'a> ToTlv for UpdatePINFields<'a> {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.old_pin.to_tlv(w, Tag::Context(0))?;
self.new_pin.to_tlv(w, Tag::Context(1))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for UpdatePINFields<'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 old_pin = None;
let mut new_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) => old_pin = Some(<&'a str>::from_tlv(reader, &field)?),
Some(1) => new_pin = Some(<&'a str>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
old_pin: old_pin.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
new_pin: new_pin.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct ResetPINResponseFields<'a> {
pub pin_code: &'a str,
}
impl<'a> ToTlv for ResetPINResponseFields<'a> {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.pin_code.to_tlv(w, Tag::Context(0))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for ResetPINResponseFields<'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 pin_code = 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) => pin_code = Some(<&'a str>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
pin_code: pin_code.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct AddBonusTimeFields<'a> {
pub pin_code: Option<&'a str>,
pub bonus_time: u32,
}
impl<'a> ToTlv for AddBonusTimeFields<'a> {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
if let Some(value) = &self.pin_code {
value.to_tlv(w, Tag::Context(0))?;
}
self.bonus_time.to_tlv(w, Tag::Context(1))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for AddBonusTimeFields<'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 pin_code = None;
let mut bonus_time = 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) => pin_code = Some(<&'a str>::from_tlv(reader, &field)?),
Some(1) => bonus_time = Some(<u32>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
pin_code,
bonus_time: bonus_time.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct SetScreenDailyTimeFields {
pub screen_time: u32,
}
impl ToTlv for SetScreenDailyTimeFields {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.screen_time.to_tlv(w, Tag::Context(0))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for SetScreenDailyTimeFields {
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 screen_time = 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) => screen_time = Some(<u32>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
screen_time: screen_time.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct SetOnDemandRatingThresholdFields<'a> {
pub rating: &'a str,
}
impl<'a> ToTlv for SetOnDemandRatingThresholdFields<'a> {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.rating.to_tlv(w, Tag::Context(0))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for SetOnDemandRatingThresholdFields<'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 rating = 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) => rating = Some(<&'a str>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
rating: rating.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct SetScheduledContentRatingThresholdFields<'a> {
pub rating: &'a str,
}
impl<'a> ToTlv for SetScheduledContentRatingThresholdFields<'a> {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.rating.to_tlv(w, Tag::Context(0))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for SetScheduledContentRatingThresholdFields<'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 rating = 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) => rating = Some(<&'a str>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
rating: rating.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct AddBlockChannelsFields<'a> {
pub channels: TlvList<'a, BlockChannelStruct<'a>>,
}
impl<'a> ToTlv for AddBlockChannelsFields<'a> {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.channels.to_tlv(w, Tag::Context(0))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for AddBlockChannelsFields<'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 channels = 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) => {
channels = Some(<TlvList<'a, BlockChannelStruct<'a>>>::from_tlv(
reader, &field,
)?)
}
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
channels: channels.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct RemoveBlockChannelsFields<'a> {
pub channel_indexes: TlvList<'a, u16>,
}
impl<'a> ToTlv for RemoveBlockChannelsFields<'a> {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.channel_indexes.to_tlv(w, Tag::Context(0))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for RemoveBlockChannelsFields<'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 channel_indexes = 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) => channel_indexes = Some(<TlvList<'a, u16>>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
channel_indexes: channel_indexes
.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct AddBlockApplicationsFields<'a> {
pub applications: TlvList<'a, AppInfoStruct<'a>>,
}
impl<'a> ToTlv for AddBlockApplicationsFields<'a> {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.applications.to_tlv(w, Tag::Context(0))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for AddBlockApplicationsFields<'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 applications = 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) => {
applications = Some(<TlvList<'a, AppInfoStruct<'a>>>::from_tlv(reader, &field)?)
}
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
applications: applications.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct RemoveBlockApplicationsFields<'a> {
pub applications: TlvList<'a, AppInfoStruct<'a>>,
}
impl<'a> ToTlv for RemoveBlockApplicationsFields<'a> {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.applications.to_tlv(w, Tag::Context(0))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for RemoveBlockApplicationsFields<'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 applications = 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) => {
applications = Some(<TlvList<'a, AppInfoStruct<'a>>>::from_tlv(reader, &field)?)
}
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
applications: applications.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct SetBlockContentTimeWindowFields<'a> {
pub time_window: TimeWindowStruct<'a>,
}
impl<'a> ToTlv for SetBlockContentTimeWindowFields<'a> {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.time_window.to_tlv(w, Tag::Context(0))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for SetBlockContentTimeWindowFields<'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 time_window = 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) => time_window = Some(<TimeWindowStruct<'a>>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
time_window: time_window.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct RemoveBlockContentTimeWindowFields<'a> {
pub time_window_indexes: TlvList<'a, u16>,
}
impl<'a> ToTlv for RemoveBlockContentTimeWindowFields<'a> {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.time_window_indexes.to_tlv(w, Tag::Context(0))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for RemoveBlockContentTimeWindowFields<'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 time_window_indexes = 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) => {
time_window_indexes = Some(<TlvList<'a, u16>>::from_tlv(reader, &field)?)
}
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
time_window_indexes: time_window_indexes
.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
pub const ATTRIBUTES: &[Attribute] = &[
Attribute {
id: 0x0000,
name: "Enabled",
kind: "bool",
access: Access::read_only(Privilege::View),
qualities: AttributeQualities::empty(),
reporting: Reporting::OnChange,
conform: Conform::MANDATORY,
},
Attribute {
id: 0x0001,
name: "OnDemandRatings",
kind: "list[RatingNameStruct]",
access: Access::read_only(Privilege::View),
qualities: AttributeQualities::empty(),
reporting: Reporting::OnChange,
conform: Conform {
clauses: &[Clause {
verdict: Conformance::Mandatory,
when: Condition::Feature(3),
}],
},
},
Attribute {
id: 0x0002,
name: "OnDemandRatingThreshold",
kind: "string",
access: Access::read_only(Privilege::View),
qualities: AttributeQualities::empty(),
reporting: Reporting::OnChange,
conform: Conform {
clauses: &[Clause {
verdict: Conformance::Mandatory,
when: Condition::Feature(3),
}],
},
},
Attribute {
id: 0x0003,
name: "ScheduledContentRatings",
kind: "list[RatingNameStruct]",
access: Access::read_only(Privilege::View),
qualities: AttributeQualities::empty(),
reporting: Reporting::OnChange,
conform: Conform {
clauses: &[Clause {
verdict: Conformance::Mandatory,
when: Condition::Feature(4),
}],
},
},
Attribute {
id: 0x0004,
name: "ScheduledContentRatingThreshold",
kind: "string",
access: Access::read_only(Privilege::View),
qualities: AttributeQualities::empty(),
reporting: Reporting::OnChange,
conform: Conform {
clauses: &[Clause {
verdict: Conformance::Mandatory,
when: Condition::Feature(4),
}],
},
},
Attribute {
id: 0x0005,
name: "ScreenDailyTime",
kind: "elapsed-s",
access: Access::read_only(Privilege::View),
qualities: AttributeQualities::empty(),
reporting: Reporting::OnChange,
conform: Conform {
clauses: &[Clause {
verdict: Conformance::Mandatory,
when: Condition::Feature(0),
}],
},
},
Attribute {
id: 0x0006,
name: "RemainingScreenTime",
kind: "elapsed-s",
access: Access::read_only(Privilege::View),
qualities: AttributeQualities::empty(),
reporting: Reporting::OnChange,
conform: Conform {
clauses: &[Clause {
verdict: Conformance::Mandatory,
when: Condition::Feature(0),
}],
},
},
Attribute {
id: 0x0007,
name: "BlockUnrated",
kind: "bool",
access: Access::read_only(Privilege::View),
qualities: AttributeQualities::empty(),
reporting: Reporting::OnChange,
conform: Conform {
clauses: &[Clause {
verdict: Conformance::Mandatory,
when: Condition::Feature(2),
}],
},
},
Attribute {
id: 0x0008,
name: "BlockChannelList",
kind: "list[BlockChannelStruct]",
access: Access::read_only(Privilege::View),
qualities: AttributeQualities::empty(),
reporting: Reporting::OnChange,
conform: Conform {
clauses: &[Clause {
verdict: Conformance::Mandatory,
when: Condition::Feature(5),
}],
},
},
Attribute {
id: 0x0009,
name: "BlockApplicationList",
kind: "list[AppInfoStruct]",
access: Access::read_only(Privilege::View),
qualities: AttributeQualities::empty(),
reporting: Reporting::OnChange,
conform: Conform {
clauses: &[Clause {
verdict: Conformance::Mandatory,
when: Condition::Feature(6),
}],
},
},
Attribute {
id: 0x000A,
name: "BlockContentTimeWindow",
kind: "list[TimeWindowStruct]",
access: Access::read_only(Privilege::View),
qualities: AttributeQualities::empty(),
reporting: Reporting::OnChange,
conform: Conform {
clauses: &[Clause {
verdict: Conformance::Mandatory,
when: Condition::Feature(7),
}],
},
},
];
pub const COMMANDS: &[Command] = &[
Command {
id: 0x00,
name: "UpdatePIN",
to_server: true,
response: None,
access: Access::invoke(Privilege::Manage).with_qualities(AccessQualities::TIMED),
conform: Conform {
clauses: &[Clause {
verdict: Conformance::Mandatory,
when: Condition::Feature(1),
}],
},
},
Command {
id: 0x01,
name: "ResetPIN",
to_server: true,
response: Some(0x02),
access: Access::invoke(Privilege::Administer).with_qualities(AccessQualities::TIMED),
conform: Conform {
clauses: &[Clause {
verdict: Conformance::Mandatory,
when: Condition::Feature(1),
}],
},
},
Command {
id: 0x02,
name: "ResetPINResponse",
to_server: false,
response: None,
access: Access::invoke(Privilege::Operate),
conform: Conform {
clauses: &[Clause {
verdict: Conformance::Mandatory,
when: Condition::Feature(1),
}],
},
},
Command {
id: 0x03,
name: "Enable",
to_server: true,
response: None,
access: Access::invoke(Privilege::Manage).with_qualities(AccessQualities::TIMED),
conform: Conform::MANDATORY,
},
Command {
id: 0x04,
name: "Disable",
to_server: true,
response: None,
access: Access::invoke(Privilege::Manage).with_qualities(AccessQualities::TIMED),
conform: Conform::MANDATORY,
},
Command {
id: 0x05,
name: "AddBonusTime",
to_server: true,
response: None,
access: Access::invoke(Privilege::Operate),
conform: Conform {
clauses: &[Clause {
verdict: Conformance::Mandatory,
when: Condition::Feature(0),
}],
},
},
Command {
id: 0x06,
name: "SetScreenDailyTime",
to_server: true,
response: None,
access: Access::invoke(Privilege::Manage),
conform: Conform {
clauses: &[Clause {
verdict: Conformance::Mandatory,
when: Condition::Feature(0),
}],
},
},
Command {
id: 0x07,
name: "BlockUnratedContent",
to_server: true,
response: None,
access: Access::invoke(Privilege::Manage),
conform: Conform {
clauses: &[Clause {
verdict: Conformance::Mandatory,
when: Condition::Feature(2),
}],
},
},
Command {
id: 0x08,
name: "UnblockUnratedContent",
to_server: true,
response: None,
access: Access::invoke(Privilege::Manage),
conform: Conform {
clauses: &[Clause {
verdict: Conformance::Mandatory,
when: Condition::Feature(2),
}],
},
},
Command {
id: 0x09,
name: "SetOnDemandRatingThreshold",
to_server: true,
response: None,
access: Access::invoke(Privilege::Manage),
conform: Conform {
clauses: &[Clause {
verdict: Conformance::Mandatory,
when: Condition::Feature(3),
}],
},
},
Command {
id: 0x0A,
name: "SetScheduledContentRatingThreshold",
to_server: true,
response: None,
access: Access::invoke(Privilege::Manage),
conform: Conform {
clauses: &[Clause {
verdict: Conformance::Mandatory,
when: Condition::Feature(4),
}],
},
},
Command {
id: 0x0B,
name: "AddBlockChannels",
to_server: true,
response: None,
access: Access::invoke(Privilege::Manage),
conform: Conform {
clauses: &[Clause {
verdict: Conformance::Mandatory,
when: Condition::Feature(5),
}],
},
},
Command {
id: 0x0C,
name: "RemoveBlockChannels",
to_server: true,
response: None,
access: Access::invoke(Privilege::Manage),
conform: Conform {
clauses: &[Clause {
verdict: Conformance::Mandatory,
when: Condition::Feature(5),
}],
},
},
Command {
id: 0x0D,
name: "AddBlockApplications",
to_server: true,
response: None,
access: Access::invoke(Privilege::Manage),
conform: Conform {
clauses: &[Clause {
verdict: Conformance::Mandatory,
when: Condition::Feature(6),
}],
},
},
Command {
id: 0x0E,
name: "RemoveBlockApplications",
to_server: true,
response: None,
access: Access::invoke(Privilege::Manage),
conform: Conform {
clauses: &[Clause {
verdict: Conformance::Mandatory,
when: Condition::Feature(6),
}],
},
},
Command {
id: 0x0F,
name: "SetBlockContentTimeWindow",
to_server: true,
response: None,
access: Access::invoke(Privilege::Manage),
conform: Conform {
clauses: &[Clause {
verdict: Conformance::Mandatory,
when: Condition::Feature(7),
}],
},
},
Command {
id: 0x10,
name: "RemoveBlockContentTimeWindow",
to_server: true,
response: None,
access: Access::invoke(Privilege::Manage),
conform: Conform {
clauses: &[Clause {
verdict: Conformance::Mandatory,
when: Condition::Feature(7),
}],
},
},
];
pub const EVENTS: &[Event] = &[
Event {
id: 0x00,
name: "RemainingScreenTimeExpired",
priority: EventPriority::Info,
access: Access::read_only(Privilege::View),
conform: Conform {
clauses: &[Clause {
verdict: Conformance::Mandatory,
when: Condition::Feature(0),
}],
},
},
Event {
id: 0x01,
name: "EnteringBlockContentTimeWindow",
priority: EventPriority::Info,
access: Access::read_only(Privilege::View),
conform: Conform {
clauses: &[Clause {
verdict: Conformance::Mandatory,
when: Condition::Feature(7),
}],
},
},
];
pub const CLUSTER: Cluster = Cluster {
id: ID,
name: "Content Control",
revision: REVISION,
pics: "CONCON",
derived_from: None,
features: FEATURES,
attributes: ATTRIBUTES,
commands: COMMANDS,
events: EVENTS,
};