diff --git a/src/lib/core/CHIPError.cpp b/src/lib/core/CHIPError.cpp index fc6623e608ab53..3934a35bcb12be 100644 --- a/src/lib/core/CHIPError.cpp +++ b/src/lib/core/CHIPError.cpp @@ -389,8 +389,8 @@ bool FormatCHIPError(char * buf, uint16_t bufSize, CHIP_ERROR err) case CHIP_ERROR_RETRANS_TABLE_FULL.AsInteger(): desc = "Retransmit Table is already full"; break; - case CHIP_ERROR_INVALID_ACK_ID.AsInteger(): - desc = "Invalid Acknowledgment Id"; + case CHIP_ERROR_INVALID_ACK_MESSAGE_COUNTER.AsInteger(): + desc = "Invalid acknowledged message counter"; break; case CHIP_ERROR_SEND_THROTTLED.AsInteger(): desc = "Sending to peer is throttled on this Exchange"; diff --git a/src/lib/core/CHIPError.h b/src/lib/core/CHIPError.h index a50be6da4d441a..29590431aacb79 100644 --- a/src/lib/core/CHIPError.h +++ b/src/lib/core/CHIPError.h @@ -1316,13 +1316,13 @@ using CHIP_ERROR = ::chip::ChipError; #define CHIP_ERROR_RETRANS_TABLE_FULL CHIP_CORE_ERROR(0x64) /** - * @def CHIP_ERROR_INVALID_ACK_ID + * @def CHIP_ERROR_INVALID_ACK_MESSAGE_COUNTER * * @brief * An acknowledgment id is invalid. * */ -#define CHIP_ERROR_INVALID_ACK_ID CHIP_CORE_ERROR(0x65) +#define CHIP_ERROR_INVALID_ACK_MESSAGE_COUNTER CHIP_CORE_ERROR(0x65) /** * @def CHIP_ERROR_SEND_THROTTLED @@ -2177,7 +2177,7 @@ using CHIP_ERROR = ::chip::ChipError; * @def CHIP_ERROR_MESSAGE_ID_OUT_OF_WINDOW * * @brief - * The message id of the received message is out of receiving window + * The message counter of the received message is out of receiving window */ #define CHIP_ERROR_MESSAGE_ID_OUT_OF_WINDOW CHIP_CORE_ERROR(0xc7) diff --git a/src/lib/core/tests/TestCHIPErrorStr.cpp b/src/lib/core/tests/TestCHIPErrorStr.cpp index 7198448344b08d..b268ebfcf0f05a 100644 --- a/src/lib/core/tests/TestCHIPErrorStr.cpp +++ b/src/lib/core/tests/TestCHIPErrorStr.cpp @@ -150,7 +150,7 @@ static const CHIP_ERROR kTestElements[] = CHIP_ERROR_DEVICE_AUTH_TIMEOUT, CHIP_ERROR_MESSAGE_NOT_ACKNOWLEDGED, CHIP_ERROR_RETRANS_TABLE_FULL, - CHIP_ERROR_INVALID_ACK_ID, + CHIP_ERROR_INVALID_ACK_MESSAGE_COUNTER, CHIP_ERROR_SEND_THROTTLED, CHIP_ERROR_WRONG_MSG_VERSION_FOR_EXCHANGE, CHIP_ERROR_TRANSACTION_CANCELED, diff --git a/src/lib/support/CHIPFaultInjection.cpp b/src/lib/support/CHIPFaultInjection.cpp index e837a08817fafc..ec4a286cefc8e0 100644 --- a/src/lib/support/CHIPFaultInjection.cpp +++ b/src/lib/support/CHIPFaultInjection.cpp @@ -78,7 +78,7 @@ DLL_EXPORT void FuzzExchangeHeader(uint8_t * p, int32_t arg) 1, // MessageType 2, // ExchangeId 4, // ProfileId - 8 // AckMsgId + 8 // AckMessageCounter }; const uint8_t values[CHIP_FAULT_INJECTION_NUM_FUZZ_VALUES] = { 0x1, 0x2, 0xFF }; size_t offsetIndex = 0; diff --git a/src/messaging/ExchangeMessageDispatch.cpp b/src/messaging/ExchangeMessageDispatch.cpp index ab810af354810c..6788651581d33b 100644 --- a/src/messaging/ExchangeMessageDispatch.cpp +++ b/src/messaging/ExchangeMessageDispatch.cpp @@ -52,12 +52,13 @@ CHIP_ERROR ExchangeMessageDispatch::SendMessage(SessionHandle session, uint16_t // If there is a pending acknowledgment piggyback it on this message. if (reliableMessageContext->IsAckPending()) { - payloadHeader.SetAckId(reliableMessageContext->TakePendingPeerAckId()); + payloadHeader.SetAckMessageCounter(reliableMessageContext->TakePendingPeerAckMessageCounter()); #if !defined(NDEBUG) if (!payloadHeader.HasMessageType(Protocols::SecureChannel::MsgType::StandaloneAck)) { - ChipLogDetail(ExchangeManager, "Piggybacking Ack for MsgId:%08" PRIX32 " with msg", payloadHeader.GetAckId().Value()); + ChipLogDetail(ExchangeManager, "Piggybacking Ack for MessageCounter:%08" PRIX32 " with msg", + payloadHeader.GetAckMessageCounter().Value()); } #endif } @@ -103,9 +104,10 @@ CHIP_ERROR ExchangeMessageDispatch::OnMessageReceived(uint32_t messageCounter, c if (IsReliableTransmissionAllowed()) { - if (!msgFlags.Has(MessageFlagValues::kDuplicateMessage) && payloadHeader.IsAckMsg() && payloadHeader.GetAckId().HasValue()) + if (!msgFlags.Has(MessageFlagValues::kDuplicateMessage) && payloadHeader.IsAckMsg() && + payloadHeader.GetAckMessageCounter().HasValue()) { - ReturnErrorOnFailure(reliableMessageContext->HandleRcvdAck(payloadHeader.GetAckId().Value())); + ReturnErrorOnFailure(reliableMessageContext->HandleRcvdAck(payloadHeader.GetAckMessageCounter().Value())); } if (payloadHeader.NeedsAck()) diff --git a/src/messaging/ExchangeMgr.cpp b/src/messaging/ExchangeMgr.cpp index 2e0a1733bb0419..73869298434d24 100644 --- a/src/messaging/ExchangeMgr.cpp +++ b/src/messaging/ExchangeMgr.cpp @@ -224,7 +224,7 @@ void ExchangeManager::OnMessageReceived(const PacketHeader & packetHeader, const } // Matched ExchangeContext; send to message handler. - ec->HandleMessage(packetHeader.GetMessageId(), payloadHeader, source, msgFlags, std::move(msgBuf)); + ec->HandleMessage(packetHeader.GetMessageCounter(), payloadHeader, source, msgFlags, std::move(msgBuf)); found = true; return false; } @@ -297,7 +297,7 @@ void ExchangeManager::OnMessageReceived(const PacketHeader & packetHeader, const return; } - CHIP_ERROR err = ec->HandleMessage(packetHeader.GetMessageId(), payloadHeader, source, msgFlags, std::move(msgBuf)); + CHIP_ERROR err = ec->HandleMessage(packetHeader.GetMessageCounter(), payloadHeader, source, msgFlags, std::move(msgBuf)); if (err != CHIP_NO_ERROR) { // Using same error message for all errors to reduce code size. diff --git a/src/messaging/Flags.h b/src/messaging/Flags.h index be3849ce2b3132..11d86d3c4cce83 100644 --- a/src/messaging/Flags.h +++ b/src/messaging/Flags.h @@ -46,7 +46,7 @@ enum class MessageFlagValues : uint32_t /**< Indicates that the message is a duplicate of a previously received message. */ kDuplicateMessage = 0x00004000, /**< Indicates that the peer's group key message counter is not synchronized. */ - kPeerGroupMsgIdNotSynchronized = 0x00008000, + kPeerGroupMessageCounterNotSynchronized = 0x00008000, /**< Indicates that the source of the message is the initiator of the CHIP exchange. */ kFromInitiator = 0x00010000, /**< Indicates that message is being sent/received via the local ephemeral UDP port. */ diff --git a/src/messaging/ReliableMessageContext.cpp b/src/messaging/ReliableMessageContext.cpp index b48c47b9ed5fe6..79809a12e36d7d 100644 --- a/src/messaging/ReliableMessageContext.cpp +++ b/src/messaging/ReliableMessageContext.cpp @@ -40,7 +40,7 @@ namespace chip { namespace Messaging { ReliableMessageContext::ReliableMessageContext() : - mConfig(gDefaultReliableMessageProtocolConfig), mNextAckTimeTick(0), mPendingPeerAckId(0) + mConfig(gDefaultReliableMessageProtocolConfig), mNextAckTimeTick(0), mPendingPeerAckMessageCounter(0) {} void ReliableMessageContext::RetainContext() @@ -125,7 +125,7 @@ CHIP_ERROR ReliableMessageContext::FlushAcks() if (err == CHIP_NO_ERROR) { #if !defined(NDEBUG) - ChipLogDetail(ExchangeManager, "Flushed pending ack for MsgId:%08" PRIX32, mPendingPeerAckId); + ChipLogDetail(ExchangeManager, "Flushed pending ack for MessageCounter:%08" PRIX32, mPendingPeerAckMessageCounter); #endif } } @@ -150,36 +150,37 @@ uint64_t ReliableMessageContext::GetActiveRetransmitTimeoutTick() * @note * This message is part of the CHIP Reliable Messaging protocol. * - * @param[in] AckMsgId The msgId of incoming Ack message. + * @param[in] ackMessageCounter The messageCounter of incoming Ack message. * - * @retval #CHIP_ERROR_INVALID_ACK_ID if the msgId of received Ack is not in the RetransTable. + * @retval #CHIP_ERROR_INVALID_ACK_MESSAGE_COUNTER if the messageCounter of received Ack is not in the + * RetransTable. * @retval #CHIP_NO_ERROR if the context was removed. * */ -CHIP_ERROR ReliableMessageContext::HandleRcvdAck(uint32_t AckMsgId) +CHIP_ERROR ReliableMessageContext::HandleRcvdAck(uint32_t ackMessageCounter) { CHIP_ERROR err = CHIP_NO_ERROR; // Msg is an Ack; Check Retrans Table and remove message context - if (!GetReliableMessageMgr()->CheckAndRemRetransTable(this, AckMsgId)) + if (!GetReliableMessageMgr()->CheckAndRemRetransTable(this, ackMessageCounter)) { #if !defined(NDEBUG) - ChipLogError(ExchangeManager, "CHIP MsgId:%08" PRIX32 " not in RetransTable", AckMsgId); + ChipLogError(ExchangeManager, "CHIP MessageCounter:%08" PRIX32 " not in RetransTable", ackMessageCounter); #endif - err = CHIP_ERROR_INVALID_ACK_ID; + err = CHIP_ERROR_INVALID_ACK_MESSAGE_COUNTER; // Optionally call an application callback with this error. } else { #if !defined(NDEBUG) - ChipLogDetail(ExchangeManager, "Removed CHIP MsgId:%08" PRIX32 " from RetransTable", AckMsgId); + ChipLogDetail(ExchangeManager, "Removed CHIP MessageCounter:%08" PRIX32 " from RetransTable", ackMessageCounter); #endif } return err; } -CHIP_ERROR ReliableMessageContext::HandleNeedsAck(uint32_t messageId, BitFlags messageFlags) +CHIP_ERROR ReliableMessageContext::HandleNeedsAck(uint32_t messageCounter, BitFlags messageFlags) { // Skip processing ack if drop ack debug is enabled. @@ -189,7 +190,7 @@ CHIP_ERROR ReliableMessageContext::HandleNeedsAck(uint32_t messageId, BitFlagsExpireTicks(); - CHIP_ERROR err = HandleNeedsAckInner(messageId, messageFlags); + CHIP_ERROR err = HandleNeedsAckInner(messageCounter, messageFlags); // Schedule next physical wakeup on function exit GetReliableMessageMgr()->StartTimer(); @@ -197,7 +198,7 @@ CHIP_ERROR ReliableMessageContext::HandleNeedsAck(uint32_t messageId, BitFlags messageFlags) +CHIP_ERROR ReliableMessageContext::HandleNeedsAckInner(uint32_t messageCounter, BitFlags messageFlags) { // If the message IS a duplicate there will never be a response to it, so we @@ -205,25 +206,25 @@ CHIP_ERROR ReliableMessageContext::HandleNeedsAckInner(uint32_t messageId, BitFl if (messageFlags.Has(MessageFlagValues::kDuplicateMessage)) { #if !defined(NDEBUG) - ChipLogDetail(ExchangeManager, "Forcing tx of solitary ack for duplicate MsgId:%08" PRIX32, messageId); + ChipLogDetail(ExchangeManager, "Forcing tx of solitary ack for duplicate MessageCounter:%08" PRIX32, messageCounter); #endif - // Is there pending ack for a different message id. - bool wasAckPending = IsAckPending() && mPendingPeerAckId != messageId; + // Is there pending ack for a different message counter. + bool wasAckPending = IsAckPending() && mPendingPeerAckMessageCounter != messageCounter; - // Temporary store currently pending ack id (even if there is none). - uint32_t tempAckId = mPendingPeerAckId; + // Temporary store currently pending ack message counter (even if there is none). + uint32_t tempAckMessageCounter = mPendingPeerAckMessageCounter; - // Set the pending ack id. - SetPendingPeerAckId(messageId); + // Set the pending ack message counter. + SetPendingPeerAckMessageCounter(messageCounter); // Send the Ack for the duplication message in a SecureChannel::StandaloneAck message. CHIP_ERROR err = SendStandaloneAckMessage(); - // If there was pending ack for a different message id. + // If there was pending ack for a different message counter. if (wasAckPending) { - // Restore previously pending ack id. - SetPendingPeerAckId(tempAckId); + // Restore previously pending ack message counter. + SetPendingPeerAckMessageCounter(tempAckMessageCounter); } return err; @@ -234,15 +235,15 @@ CHIP_ERROR ReliableMessageContext::HandleNeedsAckInner(uint32_t messageId, BitFl if (IsAckPending()) { #if !defined(NDEBUG) - ChipLogDetail(ExchangeManager, "Pending ack queue full; forcing tx of solitary ack for MsgId:%08" PRIX32, - mPendingPeerAckId); + ChipLogDetail(ExchangeManager, "Pending ack queue full; forcing tx of solitary ack for MessageCounter:%08" PRIX32, + mPendingPeerAckMessageCounter); #endif // Send the Ack for the currently pending Ack in a SecureChannel::StandaloneAck message. ReturnErrorOnFailure(SendStandaloneAckMessage()); } - // Replace the Pending ack id. - SetPendingPeerAckId(messageId); + // Replace the Pending ack message counter. + SetPendingPeerAckMessageCounter(messageCounter); mNextAckTimeTick = static_cast(CHIP_CONFIG_RMP_DEFAULT_ACK_TIMEOUT_TICK + GetReliableMessageMgr()->GetTickCounterFromTimeDelta(System::Clock::GetMonotonicMilliseconds())); @@ -261,7 +262,7 @@ CHIP_ERROR ReliableMessageContext::SendStandaloneAckMessage() // Send the null message #if !defined(NDEBUG) - ChipLogDetail(ExchangeManager, "Sending Standalone Ack for MsgId:%08" PRIX32, mPendingPeerAckId); + ChipLogDetail(ExchangeManager, "Sending Standalone Ack for MessageCounter:%08" PRIX32, mPendingPeerAckMessageCounter); #endif CHIP_ERROR err = GetExchangeContext()->SendMessage(Protocols::SecureChannel::MsgType::StandaloneAck, std::move(msgBuf), @@ -273,16 +274,16 @@ CHIP_ERROR ReliableMessageContext::SendStandaloneAckMessage() } if (err != CHIP_NO_ERROR) { - ChipLogError(ExchangeManager, "Failed to send Solitary ack for MsgId:%08" PRIX32 ":%" CHIP_ERROR_FORMAT, mPendingPeerAckId, - err.Format()); + ChipLogError(ExchangeManager, "Failed to send Solitary ack for MessageCounter:%08" PRIX32 ":%" CHIP_ERROR_FORMAT, + mPendingPeerAckMessageCounter, err.Format()); } return err; } -void ReliableMessageContext::SetPendingPeerAckId(uint32_t aPeerAckId) +void ReliableMessageContext::SetPendingPeerAckMessageCounter(uint32_t aPeerAckMessageCounter) { - mPendingPeerAckId = aPeerAckId; + mPendingPeerAckMessageCounter = aPeerAckMessageCounter; SetAckPending(true); } diff --git a/src/messaging/ReliableMessageContext.h b/src/messaging/ReliableMessageContext.h index 099afb5b2bcd8a..de013761d71b8a 100644 --- a/src/messaging/ReliableMessageContext.h +++ b/src/messaging/ReliableMessageContext.h @@ -58,14 +58,14 @@ class ReliableMessageContext CHIP_ERROR FlushAcks(); /** - * Take the pending peer ack id from the context. This must only be called + * Take the pending peer ack message counter from the context. This must only be called * when IsAckPending() is true. After this call, IsAckPending() will be * false; it's the caller's responsibility to send the ack. */ - uint32_t TakePendingPeerAckId() + uint32_t TakePendingPeerAckMessageCounter() { SetAckPending(false); - return mPendingPeerAckId; + return mPendingPeerAckMessageCounter; } /** @@ -217,9 +217,9 @@ class ReliableMessageContext private: void RetainContext(); void ReleaseContext(); - CHIP_ERROR HandleRcvdAck(uint32_t AckMsgId); - CHIP_ERROR HandleNeedsAck(uint32_t messageId, BitFlags messageFlags); - CHIP_ERROR HandleNeedsAckInner(uint32_t messageId, BitFlags messageFlags); + CHIP_ERROR HandleRcvdAck(uint32_t ackMessageCounter); + CHIP_ERROR HandleNeedsAck(uint32_t messageCounter, BitFlags messageFlags); + CHIP_ERROR HandleNeedsAckInner(uint32_t messageCounter, BitFlags messageFlags); ExchangeContext * GetExchangeContext(); /** @@ -231,9 +231,9 @@ class ReliableMessageContext */ void SetAckPending(bool inAckPending); - // Set our pending peer ack id and any other state needed to ensure that we + // Set our pending peer ack message counter and any other state needed to ensure that we // will send that ack at some point. - void SetPendingPeerAckId(uint32_t aPeerAckId); + void SetPendingPeerAckMessageCounter(uint32_t aPeerAckMessageCounter); private: friend class ReliableMessageMgr; @@ -242,7 +242,7 @@ class ReliableMessageContext ReliableMessageProtocolConfig mConfig; uint16_t mNextAckTimeTick; // Next time for triggering Solo Ack - uint32_t mPendingPeerAckId; + uint32_t mPendingPeerAckMessageCounter; }; } // namespace Messaging diff --git a/src/messaging/ReliableMessageMgr.cpp b/src/messaging/ReliableMessageMgr.cpp index 41b8baa60975f0..ad99c66354d071 100644 --- a/src/messaging/ReliableMessageMgr.cpp +++ b/src/messaging/ReliableMessageMgr.cpp @@ -88,8 +88,8 @@ void ReliableMessageMgr::TicklessDebugDumpRetransTable(const char * log) { if (entry.rc) { - ChipLogDetail(ExchangeManager, "EC:%04" PRIX16 " MsgId:%08" PRIX32 " NextRetransTimeCtr:%04" PRIX16, entry.rc, - entry.msgId, entry.nextRetransTimeTick); + ChipLogDetail(ExchangeManager, "EC:%04" PRIX16 " MessageCounter:%08" PRIX32 " NextRetransTimeCtr:%04" PRIX16, entry.rc, + entry.messageCounter, entry.nextRetransTimeTick); } } } @@ -143,15 +143,15 @@ void ReliableMessageMgr::ExecuteActions() continue; } - uint8_t sendCount = entry.sendCount; - uint32_t msgId = entry.retainedBuf.GetMsgId(); + uint8_t sendCount = entry.sendCount; + uint32_t messageCounter = entry.retainedBuf.GetMessageCounter(); if (sendCount == CHIP_CONFIG_RMP_DEFAULT_MAX_RETRANS) { err = CHIP_ERROR_MESSAGE_NOT_ACKNOWLEDGED; - ChipLogError(ExchangeManager, "Failed to Send CHIP MsgId:%08" PRIX32 " sendCount: %" PRIu8 " max retries: %d", msgId, - sendCount, CHIP_CONFIG_RMP_DEFAULT_MAX_RETRANS); + ChipLogError(ExchangeManager, "Failed to Send CHIP MessageCounter:%08" PRIX32 " sendCount: %" PRIu8 " max retries: %d", + messageCounter, sendCount, CHIP_CONFIG_RMP_DEFAULT_MAX_RETRANS); // Remove from Table ClearRetransTable(entry); @@ -166,7 +166,7 @@ void ReliableMessageMgr::ExecuteActions() // If the retransmission was successful, update the passive timer entry.nextRetransTimeTick = static_cast(rc->GetActiveRetransmitTimeoutTick()); #if !defined(NDEBUG) - ChipLogDetail(ExchangeManager, "Retransmit MsgId:%08" PRIX32 " Send Cnt %d", msgId, entry.sendCount); + ChipLogDetail(ExchangeManager, "Retransmit MessageCounter:%08" PRIX32 " Send Cnt %d", messageCounter, entry.sendCount); #endif } } @@ -329,17 +329,17 @@ void ReliableMessageMgr::ResumeRetransmision(ReliableMessageContext * rc) } } -bool ReliableMessageMgr::CheckAndRemRetransTable(ReliableMessageContext * rc, uint32_t ackMsgId) +bool ReliableMessageMgr::CheckAndRemRetransTable(ReliableMessageContext * rc, uint32_t ackMessageCounter) { for (RetransTableEntry & entry : mRetransTable) { - if ((entry.rc == rc) && entry.retainedBuf.GetMsgId() == ackMsgId) + if ((entry.rc == rc) && entry.retainedBuf.GetMessageCounter() == ackMessageCounter) { // Clear the entry from the retransmision table. ClearRetransTable(entry); #if !defined(NDEBUG) - ChipLogDetail(ExchangeManager, "Rxd Ack; Removing MsgId:%08" PRIX32 " from Retrans Table", ackMsgId); + ChipLogDetail(ExchangeManager, "Rxd Ack; Removing MessageCounter:%08" PRIX32 " from Retrans Table", ackMessageCounter); #endif return true; } @@ -360,8 +360,9 @@ CHIP_ERROR ReliableMessageMgr::SendFromRetransTable(RetransTableEntry * entry) if (dispatcher == nullptr || !rc->GetExchangeContext()->HasSecureSession()) { // Using same error message for all errors to reduce code size. - ChipLogError(ExchangeManager, "Crit-err %" CHIP_ERROR_FORMAT " when sending CHIP MsgId:%08" PRIX32 ", send tries: %d", - CHIP_ERROR_INCORRECT_STATE.Format(), entry->retainedBuf.GetMsgId(), entry->sendCount); + ChipLogError(ExchangeManager, + "Crit-err %" CHIP_ERROR_FORMAT " when sending CHIP MessageCounter:%08" PRIX32 ", send tries: %d", + CHIP_ERROR_INCORRECT_STATE.Format(), entry->retainedBuf.GetMessageCounter(), entry->sendCount); ClearRetransTable(*entry); return CHIP_ERROR_INCORRECT_STATE; } @@ -377,8 +378,9 @@ CHIP_ERROR ReliableMessageMgr::SendFromRetransTable(RetransTableEntry * entry) { // Remove from table // Using same error message for all errors to reduce code size. - ChipLogError(ExchangeManager, "Crit-err %" CHIP_ERROR_FORMAT " when sending CHIP MsgId:%08" PRIX32 ", send tries: %d", - err.Format(), entry->retainedBuf.GetMsgId(), entry->sendCount); + ChipLogError(ExchangeManager, + "Crit-err %" CHIP_ERROR_FORMAT " when sending CHIP MessageCounter:%08" PRIX32 ", send tries: %d", err.Format(), + entry->retainedBuf.GetMessageCounter(), entry->sendCount); ClearRetransTable(*entry); } diff --git a/src/messaging/ReliableMessageMgr.h b/src/messaging/ReliableMessageMgr.h index fd7adae2a708c3..933f651185d75e 100644 --- a/src/messaging/ReliableMessageMgr.h +++ b/src/messaging/ReliableMessageMgr.h @@ -151,11 +151,11 @@ class ReliableMessageMgr * * @param[in] rc A pointer to the ExchangeContext object. * - * @param[in] msgId message ID which has been acked. + * @param[in] messageCounter message ID which has been acked. * * @retval #CHIP_NO_ERROR On success. */ - bool CheckAndRemRetransTable(ReliableMessageContext * rc, uint32_t msgId); + bool CheckAndRemRetransTable(ReliableMessageContext * rc, uint32_t messageCounter); /** * Send the specified entry from the retransmission table. diff --git a/src/messaging/tests/TestReliableMessageProtocol.cpp b/src/messaging/tests/TestReliableMessageProtocol.cpp index 6f8874a9a1d702..34d6ef108256af 100644 --- a/src/messaging/tests/TestReliableMessageProtocol.cpp +++ b/src/messaging/tests/TestReliableMessageProtocol.cpp @@ -78,7 +78,7 @@ class MockAppDelegate : public ExchangeDelegate auto * rc = ec->GetReliableMessageContext(); if (rc->IsAckPending()) { - (void) rc->TakePendingPeerAckId(); + (void) rc->TakePendingPeerAckMessageCounter(); } } diff --git a/src/transport/SecureMessageCodec.cpp b/src/transport/SecureMessageCodec.cpp index d49dfef267cfee..05bf96085797bd 100644 --- a/src/transport/SecureMessageCodec.cpp +++ b/src/transport/SecureMessageCodec.cpp @@ -43,13 +43,13 @@ CHIP_ERROR Encode(Transport::PeerConnectionState * state, PayloadHeader & payloa VerifyOrReturnError(!msgBuf->HasChainedBuffer(), CHIP_ERROR_INVALID_MESSAGE_LENGTH); VerifyOrReturnError(msgBuf->TotalLength() <= kMaxAppMessageLen, CHIP_ERROR_MESSAGE_TOO_LONG); - uint32_t msgId = counter.Value(); + uint32_t messageCounter = counter.Value(); static_assert(std::is_sameTotalLength()), uint16_t>::value, "Addition to generate payloadLength might overflow"); packetHeader - .SetMessageId(msgId) // + .SetMessageCounter(messageCounter) // .SetEncryptionKeyID(state->GetPeerKeyID()); packetHeader.GetFlags().Set(Header::FlagValues::kEncryptedMessage); @@ -68,7 +68,7 @@ CHIP_ERROR Encode(Transport::PeerConnectionState * state, PayloadHeader & payloa VerifyOrReturnError(CanCastTo(totalLen + taglen), CHIP_ERROR_INTERNAL); msgBuf->SetDataLength(static_cast(totalLen + taglen)); - ChipLogDetail(Inet, "Secure message was encrypted: Msg ID %" PRIu32, msgId); + ChipLogDetail(Inet, "Secure message was encrypted: Msg ID %" PRIu32, messageCounter); ReturnErrorOnFailure(counter.Advance()); return CHIP_NO_ERROR; diff --git a/src/transport/SecureSession.cpp b/src/transport/SecureSession.cpp index 0c78ca0ae61bb2..dea77b794cf517 100644 --- a/src/transport/SecureSession.cpp +++ b/src/transport/SecureSession.cpp @@ -102,7 +102,7 @@ CHIP_ERROR SecureSession::GetIV(const PacketHeader & header, uint8_t * iv, size_ Encoding::LittleEndian::BufferWriter bbuf(iv, len); bbuf.Put64(header.GetSourceNodeId().ValueOr(0)); - bbuf.Put32(header.GetMessageId()); + bbuf.Put32(header.GetMessageCounter()); return bbuf.Fit() ? CHIP_NO_ERROR : CHIP_ERROR_NO_MEMORY; } diff --git a/src/transport/SecureSessionMgr.cpp b/src/transport/SecureSessionMgr.cpp index 54ef62b6d4ba9f..b7092cf592838b 100644 --- a/src/transport/SecureSessionMgr.cpp +++ b/src/transport/SecureSessionMgr.cpp @@ -48,7 +48,7 @@ using System::PacketBufferHandle; using Transport::PeerAddress; using Transport::PeerConnectionState; -uint32_t EncryptedPacketBufferHandle::GetMsgId() const +uint32_t EncryptedPacketBufferHandle::GetMessageCounter() const { PacketHeader header; uint16_t headerSize = 0; @@ -56,7 +56,7 @@ uint32_t EncryptedPacketBufferHandle::GetMsgId() const if (err == CHIP_NO_ERROR) { - return header.GetMessageId(); + return header.GetMessageCounter(); } ChipLogError(Inet, "Failed to decode EncryptedPacketBufferHandle header with error: %s", ErrorStr(err)); @@ -124,27 +124,27 @@ CHIP_ERROR SecureSessionMgr::PrepareMessage(SessionHandle session, PayloadHeader ChipLogProgress(Inet, "Build %s message %p to 0x" ChipLogFormatX64 " of type %d and protocolId %" PRIu32 - " on exchange %d with MessageId %" PRIu32 ".", + " on exchange %d with MessageCounter %" PRIu32 ".", "encrypted", &preparedMessage, ChipLogValueX64(state->GetPeerNodeId()), payloadHeader.GetMessageType(), payloadHeader.GetProtocolID().ToFullyQualifiedSpecForm(), payloadHeader.GetExchangeID(), - packetHeader.GetMessageId()); + packetHeader.GetMessageCounter()); } else { ReturnErrorOnFailure(payloadHeader.EncodeBeforeData(message)); MessageCounter & counter = session.GetUnauthenticatedSession()->GetLocalMessageCounter(); - uint32_t messageId = counter.Value(); + uint32_t messageCounter = counter.Value(); ReturnErrorOnFailure(counter.Advance()); - packetHeader.SetMessageId(messageId); + packetHeader.SetMessageCounter(messageCounter); ChipLogProgress(Inet, "Build %s message %p to 0x" ChipLogFormatX64 " of type %d and protocolId %" PRIu32 - " on exchange %d with MessageId %" PRIu32 ".", + " on exchange %d with MessageCounter %" PRIu32 ".", "plaintext", &preparedMessage, ChipLogValueX64(kUndefinedNodeId), payloadHeader.GetMessageType(), payloadHeader.GetProtocolID().ToFullyQualifiedSpecForm(), payloadHeader.GetExchangeID(), - packetHeader.GetMessageId()); + packetHeader.GetMessageCounter()); } ReturnErrorOnFailure(packetHeader.EncodeBeforeData(message)); @@ -339,10 +339,10 @@ void SecureSessionMgr::MessageDispatch(const PacketHeader & packetHeader, const SecureSessionMgrDelegate::DuplicateMessage isDuplicate = SecureSessionMgrDelegate::DuplicateMessage::No; // Verify message counter - CHIP_ERROR err = session->GetPeerMessageCounter().VerifyOrTrustFirst(packetHeader.GetMessageId()); + CHIP_ERROR err = session->GetPeerMessageCounter().VerifyOrTrustFirst(packetHeader.GetMessageCounter()); if (err == CHIP_ERROR_DUPLICATE_MESSAGE_RECEIVED) { - ChipLogDetail(Inet, "Received a duplicate message with MessageId: %" PRIu32, packetHeader.GetMessageId()); + ChipLogDetail(Inet, "Received a duplicate message with MessageCounter: %" PRIu32, packetHeader.GetMessageCounter()); isDuplicate = SecureSessionMgrDelegate::DuplicateMessage::Yes; err = CHIP_NO_ERROR; } @@ -353,7 +353,7 @@ void SecureSessionMgr::MessageDispatch(const PacketHeader & packetHeader, const PayloadHeader payloadHeader; ReturnOnFailure(payloadHeader.DecodeAndConsume(msg)); - session->GetPeerMessageCounter().Commit(packetHeader.GetMessageId()); + session->GetPeerMessageCounter().Commit(packetHeader.GetMessageCounter()); if (mCB != nullptr) { @@ -411,10 +411,10 @@ void SecureSessionMgr::SecureMessageDispatch(const PacketHeader & packetHeader, return; } - err = state->GetSessionMessageCounter().GetPeerMessageCounter().Verify(packetHeader.GetMessageId()); + err = state->GetSessionMessageCounter().GetPeerMessageCounter().Verify(packetHeader.GetMessageCounter()); if (err == CHIP_ERROR_DUPLICATE_MESSAGE_RECEIVED) { - ChipLogDetail(Inet, "Received a duplicate message with MessageId: %" PRIu32, packetHeader.GetMessageId()); + ChipLogDetail(Inet, "Received a duplicate message with MessageCounter: %" PRIu32, packetHeader.GetMessageCounter()); isDuplicate = SecureSessionMgrDelegate::DuplicateMessage::Yes; err = CHIP_NO_ERROR; } @@ -444,7 +444,7 @@ void SecureSessionMgr::SecureMessageDispatch(const PacketHeader & packetHeader, } else { - state->GetSessionMessageCounter().GetPeerMessageCounter().Commit(packetHeader.GetMessageId()); + state->GetSessionMessageCounter().GetPeerMessageCounter().Commit(packetHeader.GetMessageCounter()); } // TODO: once mDNS address resolution is available reconsider if this is required diff --git a/src/transport/SecureSessionMgr.h b/src/transport/SecureSessionMgr.h index f5d5ca82d7e7c9..942f05f374ac6d 100644 --- a/src/transport/SecureSessionMgr.h +++ b/src/transport/SecureSessionMgr.h @@ -67,7 +67,7 @@ class EncryptedPacketBufferHandle final : private System::PacketBufferHandle // exposing operator-> bool HasChainedBuffer() const { return (*this)->HasChainedBuffer(); } - uint32_t GetMsgId() const; + uint32_t GetMessageCounter() const; /** * Creates a copy of the data in this packet. diff --git a/src/transport/raw/MessageHeader.cpp b/src/transport/raw/MessageHeader.cpp index 0a526432208986..b0c377a908004c 100644 --- a/src/transport/raw/MessageHeader.cpp +++ b/src/transport/raw/MessageHeader.cpp @@ -74,8 +74,8 @@ constexpr size_t kNodeIdSizeBytes = 8; /// size of a serialized vendor id inside a header constexpr size_t kVendorIdSizeBytes = 2; -/// size of a serialized ack id inside a header -constexpr size_t kAckIdSizeBytes = 4; +/// size of a serialized ack message counter inside a header +constexpr size_t kAckMessageCounterSizeBytes = 4; /// Mask to extract just the version part from a 16bit header prefix. constexpr uint16_t kVersionMask = 0x00F0; @@ -117,12 +117,12 @@ uint16_t PayloadHeader::EncodeSizeBytes() const size += kVendorIdSizeBytes; } - if (mAckId.HasValue()) + if (mAckMessageCounter.HasValue()) { - size += kAckIdSizeBytes; + size += kAckMessageCounterSizeBytes; } - static_assert(kEncryptedHeaderSizeBytes + kVendorIdSizeBytes + kAckIdSizeBytes <= UINT16_MAX, + static_assert(kEncryptedHeaderSizeBytes + kVendorIdSizeBytes + kAckMessageCounterSizeBytes <= UINT16_MAX, "Header size does not fit in uint16_t"); return static_cast(size); } @@ -156,7 +156,7 @@ CHIP_ERROR PacketHeader::Decode(const uint8_t * const data, uint16_t size, uint1 mFlags.SetRaw(header); mEncryptionType = static_cast((header & kEncryptionTypeMask) >> kEncryptionTypeShift); - err = reader.Read32(&mMessageId).StatusCode(); + err = reader.Read32(&mMessageCounter).StatusCode(); SuccessOrExit(err); if (mFlags.Has(Header::FlagValues::kSourceNodeIdPresent)) @@ -236,14 +236,14 @@ CHIP_ERROR PayloadHeader::Decode(const uint8_t * const data, uint16_t size, uint if (mExchangeFlags.Has(Header::ExFlagValues::kExchangeFlag_AckMsg)) { - uint32_t ack_id; - err = reader.Read32(&ack_id).StatusCode(); + uint32_t ack_message_counter; + err = reader.Read32(&ack_message_counter).StatusCode(); SuccessOrExit(err); - mAckId.SetValue(ack_id); + mAckMessageCounter.SetValue(ack_message_counter); } else { - mAckId.ClearValue(); + mAckMessageCounter.ClearValue(); } octets_read = static_cast(reader.OctetsRead()); @@ -276,7 +276,7 @@ CHIP_ERROR PacketHeader::Encode(uint8_t * data, uint16_t size, uint16_t * encode uint8_t * p = data; LittleEndian::Write16(p, header); - LittleEndian::Write32(p, mMessageId); + LittleEndian::Write32(p, mMessageCounter); if (mSourceNodeId.HasValue()) { LittleEndian::Write64(p, mSourceNodeId.Value()); @@ -323,9 +323,9 @@ CHIP_ERROR PayloadHeader::Encode(uint8_t * data, uint16_t size, uint16_t * encod LittleEndian::Write16(p, to_underlying(mProtocolID.GetVendorId())); } LittleEndian::Write16(p, mProtocolID.GetProtocolId()); - if (mAckId.HasValue()) + if (mAckMessageCounter.HasValue()) { - LittleEndian::Write32(p, mAckId.Value()); + LittleEndian::Write32(p, mAckMessageCounter.Value()); } // Written data size provided to caller on success diff --git a/src/transport/raw/MessageHeader.h b/src/transport/raw/MessageHeader.h index c4c223f5c761d1..854fa6d1720c33 100644 --- a/src/transport/raw/MessageHeader.h +++ b/src/transport/raw/MessageHeader.h @@ -113,12 +113,12 @@ class PacketHeader { public: /** - * Gets the message id set in the header. + * Gets the message counter set in the header. * * Message IDs are expecte to monotonically increase by one for each mesage * that has been sent. */ - uint32_t GetMessageId() const { return mMessageId; } + uint32_t GetMessageCounter() const { return mMessageCounter; } /** * Gets the source node id in the current message. @@ -198,9 +198,9 @@ class PacketHeader return *this; } - PacketHeader & SetMessageId(uint32_t id) + PacketHeader & SetMessageCounter(uint32_t id) { - mMessageId = id; + mMessageCounter = id; return *this; } @@ -295,7 +295,7 @@ class PacketHeader static constexpr int kHeaderVersion = 2; /// Value expected to be incremented for each message sent. - uint32_t mMessageId = 0; + uint32_t mMessageCounter = 0; /// What node the message originated from Optional mSourceNodeId; @@ -350,7 +350,7 @@ class PayloadHeader * * NOTE: the Acknowledged Message Counter is optional and may be missing. */ - const Optional & GetAckId() const { return mAckId; } + const Optional & GetAckMessageCounter() const { return mAckMessageCounter; } /** * Set the message type for this header. This requires setting the protocol @@ -391,17 +391,17 @@ class PayloadHeader return *this; } - PayloadHeader & SetAckId(uint32_t id) + PayloadHeader & SetAckMessageCounter(uint32_t id) { - mAckId.SetValue(id); + mAckMessageCounter.SetValue(id); mExchangeFlags.Set(Header::ExFlagValues::kExchangeFlag_AckMsg); return *this; } /** Set the AckMsg flag bit. */ - PayloadHeader & SetAckId(Optional id) + PayloadHeader & SetAckMessageCounter(Optional id) { - mAckId = id; + mAckMessageCounter = id; mExchangeFlags.Set(Header::ExFlagValues::kExchangeFlag_AckMsg, id.HasValue()); return *this; } @@ -540,7 +540,7 @@ class PayloadHeader Header::ExFlags mExchangeFlags; /// Message counter of a previous message that is being acknowledged by the current message - Optional mAckId; + Optional mAckMessageCounter; }; /** Handles encoding/decoding of CHIP message headers */ diff --git a/src/transport/raw/tests/TestMessageHeader.cpp b/src/transport/raw/tests/TestMessageHeader.cpp index 7138a29f4bde6e..e946a546277049 100644 --- a/src/transport/raw/tests/TestMessageHeader.cpp +++ b/src/transport/raw/tests/TestMessageHeader.cpp @@ -39,7 +39,7 @@ void TestPacketHeaderInitialState(nlTestSuite * inSuite, void * inContext) PacketHeader header; NL_TEST_ASSERT(inSuite, !header.IsSecureSessionControlMsg()); - NL_TEST_ASSERT(inSuite, header.GetMessageId() == 0); + NL_TEST_ASSERT(inSuite, header.GetMessageCounter() == 0); NL_TEST_ASSERT(inSuite, header.GetEncryptionKeyID() == 0); NL_TEST_ASSERT(inSuite, !header.GetDestinationNodeId().HasValue()); NL_TEST_ASSERT(inSuite, !header.GetSourceNodeId().HasValue()); @@ -61,26 +61,26 @@ void TestPacketHeaderEncodeDecode(nlTestSuite * inSuite, void * inContext) uint16_t encodeLen; uint16_t decodeLen; - header.SetMessageId(123); + header.SetMessageCounter(123); NL_TEST_ASSERT(inSuite, header.Encode(buffer, &encodeLen) == CHIP_NO_ERROR); // change it to verify decoding - header.SetMessageId(222).SetSourceNodeId(1).SetDestinationNodeId(2); + header.SetMessageCounter(222).SetSourceNodeId(1).SetDestinationNodeId(2); NL_TEST_ASSERT(inSuite, header.Decode(buffer, &decodeLen) == CHIP_NO_ERROR); NL_TEST_ASSERT(inSuite, encodeLen == decodeLen); - NL_TEST_ASSERT(inSuite, header.GetMessageId() == 123); + NL_TEST_ASSERT(inSuite, header.GetMessageCounter() == 123); NL_TEST_ASSERT(inSuite, !header.GetDestinationNodeId().HasValue()); header.SetSourceNodeId(55); NL_TEST_ASSERT(inSuite, header.Encode(buffer, &encodeLen) == CHIP_NO_ERROR); // change it to verify decoding - header.SetMessageId(222).SetSourceNodeId(1).SetDestinationNodeId(2); + header.SetMessageCounter(222).SetSourceNodeId(1).SetDestinationNodeId(2); NL_TEST_ASSERT(inSuite, header.Decode(buffer, &decodeLen) == CHIP_NO_ERROR); NL_TEST_ASSERT(inSuite, encodeLen == decodeLen); - NL_TEST_ASSERT(inSuite, header.GetMessageId() == 123); + NL_TEST_ASSERT(inSuite, header.GetMessageCounter() == 123); NL_TEST_ASSERT(inSuite, !header.GetDestinationNodeId().HasValue()); NL_TEST_ASSERT(inSuite, header.GetSourceNodeId() == Optional::Value(55ull)); @@ -88,53 +88,53 @@ void TestPacketHeaderEncodeDecode(nlTestSuite * inSuite, void * inContext) NL_TEST_ASSERT(inSuite, header.Encode(buffer, &encodeLen) == CHIP_NO_ERROR); // change it to verify decoding - header.SetMessageId(222).SetSourceNodeId(1).SetDestinationNodeId(2); + header.SetMessageCounter(222).SetSourceNodeId(1).SetDestinationNodeId(2); NL_TEST_ASSERT(inSuite, header.Decode(buffer, &decodeLen) == CHIP_NO_ERROR); NL_TEST_ASSERT(inSuite, encodeLen == decodeLen); - NL_TEST_ASSERT(inSuite, header.GetMessageId() == 123); + NL_TEST_ASSERT(inSuite, header.GetMessageCounter() == 123); NL_TEST_ASSERT(inSuite, header.GetDestinationNodeId() == Optional::Value(11ull)); NL_TEST_ASSERT(inSuite, !header.GetSourceNodeId().HasValue()); - header.SetMessageId(234).SetSourceNodeId(77).SetDestinationNodeId(88); + header.SetMessageCounter(234).SetSourceNodeId(77).SetDestinationNodeId(88); NL_TEST_ASSERT(inSuite, header.Encode(buffer, &encodeLen) == CHIP_NO_ERROR); // change it to verify decoding - header.SetMessageId(222).SetSourceNodeId(1).SetDestinationNodeId(2); + header.SetMessageCounter(222).SetSourceNodeId(1).SetDestinationNodeId(2); NL_TEST_ASSERT(inSuite, header.Decode(buffer, &decodeLen) == CHIP_NO_ERROR); NL_TEST_ASSERT(inSuite, encodeLen == decodeLen); - NL_TEST_ASSERT(inSuite, header.GetMessageId() == 234); + NL_TEST_ASSERT(inSuite, header.GetMessageCounter() == 234); NL_TEST_ASSERT(inSuite, header.GetDestinationNodeId() == Optional::Value(88ull)); NL_TEST_ASSERT(inSuite, header.GetSourceNodeId() == Optional::Value(77ull)); - header.SetMessageId(234).SetSourceNodeId(77).SetDestinationNodeId(88).SetSecureSessionControlMsg(true); + header.SetMessageCounter(234).SetSourceNodeId(77).SetDestinationNodeId(88).SetSecureSessionControlMsg(true); NL_TEST_ASSERT(inSuite, header.Encode(buffer, &encodeLen) == CHIP_NO_ERROR); // change it to verify decoding - header.SetMessageId(222).SetSourceNodeId(1).SetDestinationNodeId(2); + header.SetMessageCounter(222).SetSourceNodeId(1).SetDestinationNodeId(2); NL_TEST_ASSERT(inSuite, header.Decode(buffer, &decodeLen) == CHIP_NO_ERROR); - NL_TEST_ASSERT(inSuite, header.GetMessageId() == 234); + NL_TEST_ASSERT(inSuite, header.GetMessageCounter() == 234); NL_TEST_ASSERT(inSuite, header.GetDestinationNodeId() == Optional::Value(88ull)); NL_TEST_ASSERT(inSuite, header.GetSourceNodeId() == Optional::Value(77ull)); NL_TEST_ASSERT(inSuite, header.IsSecureSessionControlMsg()); - header.SetMessageId(234).SetSourceNodeId(77).SetDestinationNodeId(88).SetEncryptionKeyID(2); + header.SetMessageCounter(234).SetSourceNodeId(77).SetDestinationNodeId(88).SetEncryptionKeyID(2); NL_TEST_ASSERT(inSuite, header.Encode(buffer, &encodeLen) == CHIP_NO_ERROR); // change it to verify decoding - header.SetMessageId(222).SetSourceNodeId(1).SetDestinationNodeId(2); + header.SetMessageCounter(222).SetSourceNodeId(1).SetDestinationNodeId(2); NL_TEST_ASSERT(inSuite, header.Decode(buffer, &decodeLen) == CHIP_NO_ERROR); - NL_TEST_ASSERT(inSuite, header.GetMessageId() == 234); + NL_TEST_ASSERT(inSuite, header.GetMessageCounter() == 234); NL_TEST_ASSERT(inSuite, header.GetDestinationNodeId() == Optional::Value(88ull)); NL_TEST_ASSERT(inSuite, header.GetSourceNodeId() == Optional::Value(77ull)); NL_TEST_ASSERT(inSuite, header.GetEncryptionKeyID() == 2); - header.SetMessageId(234).SetSourceNodeId(77).SetDestinationNodeId(88); + header.SetMessageCounter(234).SetSourceNodeId(77).SetDestinationNodeId(88); NL_TEST_ASSERT(inSuite, header.Encode(buffer, &encodeLen) == CHIP_NO_ERROR); // change it to verify decoding - header.SetMessageId(222).SetSourceNodeId(1).SetDestinationNodeId(2); + header.SetMessageCounter(222).SetSourceNodeId(1).SetDestinationNodeId(2); NL_TEST_ASSERT(inSuite, header.Decode(buffer, &decodeLen) == CHIP_NO_ERROR); - NL_TEST_ASSERT(inSuite, header.GetMessageId() == 234); + NL_TEST_ASSERT(inSuite, header.GetMessageCounter() == 234); NL_TEST_ASSERT(inSuite, header.GetDestinationNodeId() == Optional::Value(88ull)); NL_TEST_ASSERT(inSuite, header.GetSourceNodeId() == Optional::Value(77ull)); } diff --git a/src/transport/raw/tests/TestTCP.cpp b/src/transport/raw/tests/TestTCP.cpp index 85e38a7d35bd25..31324bd457a71f 100644 --- a/src/transport/raw/tests/TestTCP.cpp +++ b/src/transport/raw/tests/TestTCP.cpp @@ -67,7 +67,7 @@ using TCPImpl = Transport::TCP(static_cast(PAYLOAD))); @@ -243,7 +243,7 @@ bool TestData::Init(const uint16_t sizes[]) Free(); PacketHeader header; - header.SetSourceNodeId(kSourceNodeId).SetDestinationNodeId(kDestinationNodeId).SetMessageId(kMessageId); + header.SetSourceNodeId(kSourceNodeId).SetDestinationNodeId(kDestinationNodeId).SetMessageCounter(kMessageCounter); const size_t headerLength = header.EncodeSizeBytes(); // Determine the total length. diff --git a/src/transport/raw/tests/TestUDP.cpp b/src/transport/raw/tests/TestUDP.cpp index fc33af368b63c4..3a9aadf58012fc 100644 --- a/src/transport/raw/tests/TestUDP.cpp +++ b/src/transport/raw/tests/TestUDP.cpp @@ -44,7 +44,7 @@ namespace { constexpr NodeId kSourceNodeId = 123654; constexpr NodeId kDestinationNodeId = 111222333; -constexpr uint32_t kMessageId = 18; +constexpr uint32_t kMessageCounter = 18; using TestContext = chip::Test::IOContext; TestContext sContext; @@ -67,7 +67,7 @@ class MockTransportMgrDelegate : public TransportMgrDelegate NL_TEST_ASSERT(mSuite, packetHeader.GetSourceNodeId() == Optional::Value(kSourceNodeId)); NL_TEST_ASSERT(mSuite, packetHeader.GetDestinationNodeId() == Optional::Value(kDestinationNodeId)); - NL_TEST_ASSERT(mSuite, packetHeader.GetMessageId() == kMessageId); + NL_TEST_ASSERT(mSuite, packetHeader.GetMessageCounter() == kMessageCounter); size_t data_len = msgBuf->DataLength(); int compare = memcmp(msgBuf->Start(), PAYLOAD, data_len); @@ -133,7 +133,7 @@ void CheckMessageTest(nlTestSuite * inSuite, void * inContext, const IPAddress & ReceiveHandlerCallCount = 0; PacketHeader header; - header.SetSourceNodeId(kSourceNodeId).SetDestinationNodeId(kDestinationNodeId).SetMessageId(kMessageId); + header.SetSourceNodeId(kSourceNodeId).SetDestinationNodeId(kDestinationNodeId).SetMessageCounter(kMessageCounter); err = header.EncodeBeforeData(buffer); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); diff --git a/src/transport/tests/TestSecureSessionMgr.cpp b/src/transport/tests/TestSecureSessionMgr.cpp index 69e745d562faf5..de5dd54e2051e7 100644 --- a/src/transport/tests/TestSecureSessionMgr.cpp +++ b/src/transport/tests/TestSecureSessionMgr.cpp @@ -362,14 +362,14 @@ void SendBadEncryptedPacketTest(nlTestSuite * inSuite, void * inContext) state->GetSessionMessageCounter().GetPeerMessageCounter().SetCounter(1); // Change Message ID - EncryptedPacketBufferHandle badMessageIdMsg = preparedMessage.CloneData(); - NL_TEST_ASSERT(inSuite, badMessageIdMsg.ExtractPacketHeader(packetHeader) == CHIP_NO_ERROR); + EncryptedPacketBufferHandle badMessageCounterMsg = preparedMessage.CloneData(); + NL_TEST_ASSERT(inSuite, badMessageCounterMsg.ExtractPacketHeader(packetHeader) == CHIP_NO_ERROR); - uint32_t msgID = packetHeader.GetMessageId(); - packetHeader.SetMessageId(msgID + 1); - NL_TEST_ASSERT(inSuite, badMessageIdMsg.InsertPacketHeader(packetHeader) == CHIP_NO_ERROR); + uint32_t messageCounter = packetHeader.GetMessageCounter(); + packetHeader.SetMessageCounter(messageCounter + 1); + NL_TEST_ASSERT(inSuite, badMessageCounterMsg.InsertPacketHeader(packetHeader) == CHIP_NO_ERROR); - err = secureSessionMgr.SendPreparedMessage(localToRemoteSession, badMessageIdMsg); + err = secureSessionMgr.SendPreparedMessage(localToRemoteSession, badMessageCounterMsg); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); NL_TEST_ASSERT(inSuite, callback.ReceiveHandlerCallCount == 1);