From 09a523fc508455f9502f09b8ba58e1627258ea51 Mon Sep 17 00:00:00 2001 From: ivmarkov Date: Fri, 28 Apr 2023 05:26:36 +0000 Subject: [PATCH] TX packets are reused; need way to reset them --- matter/src/interaction_model/core.rs | 2 ++ matter/src/transport/packet.rs | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/matter/src/interaction_model/core.rs b/matter/src/interaction_model/core.rs index 1e9827b..abf76a4 100644 --- a/matter/src/interaction_model/core.rs +++ b/matter/src/interaction_model/core.rs @@ -271,6 +271,8 @@ impl<'a> Interaction<'a> { transaction: &mut Transaction, ) -> Result, Error> { if let Some(interaction) = Self::new(rx, transaction)? { + tx.reset(); + let initiated = match &interaction { Interaction::Read(req) => req.initiate(tx, transaction)?, Interaction::Write(req) => req.initiate(tx, transaction)?, diff --git a/matter/src/transport/packet.rs b/matter/src/transport/packet.rs index a86bf69..d56485f 100644 --- a/matter/src/transport/packet.rs +++ b/matter/src/transport/packet.rs @@ -78,6 +78,19 @@ impl<'a> Packet<'a> { } } + pub fn reset(&mut self) -> () { + if let Direction::Tx(wb) = &mut self.data { + wb.reset(); + wb.reserve(Packet::HDR_RESERVE).unwrap(); + + self.plain = Default::default(); + self.proto = Default::default(); + self.peer = Address::default(); + + self.proto.set_reliable(); + } + } + pub fn as_slice(&self) -> &[u8] { match &self.data { Direction::Rx(pb, _) => pb.as_slice(),