module Matter::Protocol::IMHandler

Overview

Helper module for Interaction Model message handling

Defined in:

matter/protocol/im_handler.cr

Constant Summary

Log = ::Log.for("matter.im")
MAX_REPORT_PAYLOAD_SIZE = 1100

Maximum TLV payload size per message (conservative value to stay under IPv6 MTU of 1280) Overhead: UDP header (8) + IPv6 header (40) + Matter packet header (~12) + Matter payload header (~13) + MAC tag (16) = ~89 bytes overhead 1280 - 89 = ~1191 bytes available for TLV payload, use 1100 for safety margin

MSG_INVOKE_REQUEST = 8_u8
MSG_INVOKE_RESPONSE = 9_u8
MSG_READ_REQUEST = 2_u8
MSG_REPORT_DATA = 5_u8
MSG_STATUS_RESPONSE = 1_u8

IM message types

MSG_SUBSCRIBE_REQUEST = 3_u8
MSG_SUBSCRIBE_RESPONSE = 4_u8
MSG_TIMED_REQUEST = 10_u8
MSG_WRITE_REQUEST = 6_u8
MSG_WRITE_RESPONSE = 7_u8

Class Method Summary

Class Method Detail

def self.encode_chunked_report_data(response : InteractionModel::ReadResponse, subscription_id : UInt32 | Nil = nil) : Array(Tuple(Bytes, Bool)) #

Chunk attributes into multiple ReportData messages that fit within MTU Returns an array of (encoded_bytes, is_last_chunk) tuples


[View source]
def self.encode_invoke_response(response : InteractionModel::InvokeResponse) : Bytes #

Encode InvokeResponse using TLV::Serializable


[View source]
def self.encode_read_response(response : InteractionModel::ReadResponse) : Bytes #

Encode ReadResponse using TLV::Serializable structs


[View source]
def self.encode_report_data(response : InteractionModel::ReadResponse, subscription_id : UInt32 | Nil = nil) : Bytes #

Encode ReportData (used for both ReadResponse and initial subscription data)


[View source]
def self.encode_subscribe_response(subscription_id : UInt32, max_interval : UInt16) : Bytes #

Encode SubscribeResponse


[View source]
def self.encode_write_response(response : InteractionModel::WriteResponse) : Bytes #

Encode WriteResponse using TLV::Serializable


[View source]
def self.invoke_commands(invoke_requests : Array(InteractionModel::CommandDataIB), clusters : Hash(Tuple(UInt16, UInt32), Cluster::Base), session_id : UInt64 | Nil = nil, is_case_session : Bool = false, fabric_index : UInt8 | Nil = nil) : InteractionModel::InvokeResponse #

Execute commands from invoke requests


[View source]
def self.parse_invoke_request(payload : Bytes) : InteractionModel::InvokeRequest | Nil #

Parse InvokeRequest from decrypted TLV payload


[View source]
def self.parse_read_request(payload : Bytes) : InteractionModel::ReadRequest | Nil #

Parse ReadRequest from decrypted TLV payload


[View source]
def self.parse_subscribe_request(payload : Bytes) : InteractionModel::SubscribeRequest | Nil #

Parse SubscribeRequest from decrypted TLV payload


[View source]
def self.parse_write_request(payload : Bytes) : InteractionModel::WriteRequest | Nil #

Parse WriteRequest from decrypted TLV payload


[View source]
def self.read_attributes(attribute_requests : Array(InteractionModel::AttributePath), clusters : Hash(Tuple(UInt16, UInt32), Cluster::Base), fabric_index : UInt8 | Nil = nil) : InteractionModel::ReadResponse #

Read attributes from clusters The fabric_index parameter is used for fabric-scoped attributes like CurrentFabricIndex


[View source]
def self.write_attributes(write_requests : Array(InteractionModel::AttributeWriteRequest), clusters : Hash(Tuple(UInt16, UInt32), Cluster::Base)) : InteractionModel::WriteResponse #

Write attributes to clusters


[View source]