matter_msg.c
Matter message and protocol header codec.
Overview
Matter message and protocol header codec.
depends on matter_msg.h
API
Fstatic uint16_t rd16(const uint8_t *p)
Read a little-endian 16-bit unsigned integer from buffer p.
matter_msg_header_decode, matter_proto_header_decodeFstatic uint32_t rd32(const uint8_t *p)
Read a little-endian 32-bit unsigned integer from buffer p.
matter_msg_header_decode, matter_proto_header_decode, rd64Fstatic uint64_t rd64(const uint8_t *p)
Read a little-endian 64-bit unsigned integer by reading two 32-bit halves and combining them.
matter_msg_header_decode · calls rd32Fstatic void wr16(uint8_t *p, uint16_t v)
Write a little-endian 16-bit unsigned integer v to buffer p.
matter_msg_header_encode, matter_proto_header_encodeFstatic void wr32(uint8_t *p, uint32_t v)
Write a little-endian 32-bit unsigned integer v to buffer p.
matter_msg_header_encode, matter_proto_header_encode, wr64Fstatic void wr64(uint8_t *p, uint64_t v)
Write a little-endian 64-bit unsigned integer by writing two 32-bit halves.
matter_msg_header_encode · calls wr32Fstatic size_t msg_header_len(uint8_t flags)
Header length implied by a message flags byte, or 0 if the byte is invalid. Rejecting DSIZ 3 here rather than treating it as "no destination" matters: it is reserved, so a peer using it is either broken or probing, and silently accepting would put this decoder's idea of the payload offset out of step with the sender's.
matter_msg_header_decode, matter_msg_header_encodeFstatic size_t proto_header_len(uint8_t exchange_flags)
Calculate the encoded length of a protocol header given the exchange flags; adds 2 bytes if the V flag (vendor ID) is set and 4 bytes if the A flag (ack) is set.
matter_proto_header_decode, matter_proto_header_encodeFbool matter_msg_is_secure(const struct matter_msg_header *h)
Return true if this message is encrypted; session ID 0 is unsecured unicast, all group sessions are secured regardless of ID.
Fvoid matter_counter_init(struct matter_counter *c, uint32_t entropy, enum matter_counter_kind kind)
Initialize a counter to track message sequence numbers; the first value handed out will be one higher than the entropy seed to ensure it is never zero.
Fint matter_counter_next(struct matter_counter *c, uint32_t *out)
Retrieve the next counter value and increment it; for session counters, returns MATTER_E_STATE if the counter has wrapped to UINT32_MAX to prevent AEAD nonce reuse.
Fint matter_proto_header_decode(const uint8_t *buf, size_t len, struct matter_proto_header *h, size_t *consumed)
Decode a Matter protocol exchange header from a buffer: extract flags, opcode, exchange ID, and conditional fields (vendor ID, protocol ID, ack counter). Calculate consumed bytes and validate truncation. Return an error code.
proto_header_len, rd16, rd32Fint matter_proto_header_encode(const struct matter_proto_header *h, uint8_t *buf, size_t cap, size_t *written)
Encode a Matter protocol exchange header into a buffer with the given flags, opcode, exchange ID, and conditional fields (vendor ID, protocol ID, ack counter). Return an error code.
proto_header_len, wr16, wr32Undocumented (2)
matter_msg_header_decode, matter_msg_header_encode