From 26f95a9ee24ca59d9bc17368369726ebc174624b Mon Sep 17 00:00:00 2001 From: Trevor Holbrook Date: Fri, 16 Jul 2021 06:45:47 -0700 Subject: [PATCH] Don't prepend header in BDX messages (#8234) * Don't prepend header in BDX messages - remove code in BdxTransferSession that prepended PayloadHeaders to outgoing messages - add MessageTypeData to convey message type and protocol * use Protocols::Id instead of uint32_t * add PayloadHeader argument to message handler methods - ExchangeDelegate already consumes PayloadHeader from the message, so this needs to be removed from HandleMessageReceived() --- src/protocols/bdx/BdxTransferSession.cpp | 78 +++++++++---------- src/protocols/bdx/BdxTransferSession.h | 36 ++++++--- .../bdx/tests/TestBdxTransferSession.cpp | 72 ++++++++--------- 3 files changed, 100 insertions(+), 86 deletions(-) diff --git a/src/protocols/bdx/BdxTransferSession.cpp b/src/protocols/bdx/BdxTransferSession.cpp index a9d3280640062b..a055f34e10a3e2 100644 --- a/src/protocols/bdx/BdxTransferSession.cpp +++ b/src/protocols/bdx/BdxTransferSession.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -42,22 +43,17 @@ CHIP_ERROR WriteToPacketBuffer(const ::chip::bdx::BdxMessage & msgStruct, ::chip return CHIP_NO_ERROR; } -// We could make this whole method a template, but it's probably smaller code to -// share the implementation across all message types. -CHIP_ERROR AttachHeader(chip::Protocols::Id protocolId, uint8_t msgType, ::chip::System::PacketBufferHandle & msgBuf) +template +void PrepareOutgoingMessageEvent(MessageType messageType, chip::bdx::TransferSession::OutputEventType & pendingOutput, + chip::bdx::TransferSession::MessageTypeData & outputMsgType) { - ::chip::PayloadHeader payloadHeader; - - payloadHeader.SetMessageType(protocolId, msgType); + static_assert(std::is_same, uint8_t>::value, "Cast is not safe"); - return payloadHeader.EncodeBeforeData(msgBuf); + pendingOutput = chip::bdx::TransferSession::OutputEventType::kMsgToSend; + outputMsgType.ProtocolId = chip::Protocols::MessageTypeTraits::ProtocolId(); + outputMsgType.MessageType = static_cast(messageType); } -template -inline CHIP_ERROR AttachHeader(MessageType msgType, ::chip::System::PacketBufferHandle & msgBuf) -{ - return AttachHeader(chip::Protocols::MessageTypeTraits::ProtocolId(), static_cast(msgType), msgBuf); -} } // anonymous namespace namespace chip { @@ -98,8 +94,7 @@ void TransferSession::PollOutput(OutputEvent & event, uint64_t curTimeMs) event = OutputEvent::StatusReportEvent(OutputEventType::kStatusReceived, mStatusReportData); break; case OutputEventType::kMsgToSend: - event = OutputEvent(OutputEventType::kMsgToSend); - event.MsgData = std::move(mPendingMsgHandle); + event = OutputEvent::MsgToSendEvent(mMsgTypeData, std::move(mPendingMsgHandle)); mTimeoutStartTimeMs = curTimeMs; break; case OutputEventType::kInitReceived: @@ -164,12 +159,11 @@ CHIP_ERROR TransferSession::StartTransfer(TransferRole role, const TransferInitD ReturnErrorOnFailure(WriteToPacketBuffer(initMsg, mPendingMsgHandle)); const MessageType msgType = (mRole == TransferRole::kSender) ? MessageType::SendInit : MessageType::ReceiveInit; - ReturnErrorOnFailure(AttachHeader(msgType, mPendingMsgHandle)); mState = TransferState::kAwaitingAccept; mAwaitingResponse = true; - mPendingOutput = OutputEventType::kMsgToSend; + PrepareOutgoingMessageEvent(msgType, mPendingOutput, mMsgTypeData); return CHIP_NO_ERROR; } @@ -192,6 +186,8 @@ CHIP_ERROR TransferSession::WaitForTransfer(TransferRole role, BitFlags proposedControlOpts(mTransferRequestData.TransferCtlFlags); VerifyOrReturnError(mState == TransferState::kNegotiateTransferParams, CHIP_ERROR_INCORRECT_STATE); @@ -219,8 +215,7 @@ CHIP_ERROR TransferSession::AcceptTransfer(const TransferAcceptData & acceptData acceptMsg.MetadataLength = acceptData.MetadataLength; ReturnErrorOnFailure(WriteToPacketBuffer(acceptMsg, mPendingMsgHandle)); - - ReturnErrorOnFailure(AttachHeader(MessageType::ReceiveAccept, mPendingMsgHandle)); + msgType = MessageType::ReceiveAccept; } else { @@ -232,12 +227,9 @@ CHIP_ERROR TransferSession::AcceptTransfer(const TransferAcceptData & acceptData acceptMsg.MetadataLength = acceptData.MetadataLength; ReturnErrorOnFailure(WriteToPacketBuffer(acceptMsg, mPendingMsgHandle)); - - ReturnErrorOnFailure(AttachHeader(MessageType::SendAccept, mPendingMsgHandle)); + msgType = MessageType::SendAccept; } - mPendingOutput = OutputEventType::kMsgToSend; - mState = TransferState::kTransferInProgress; if ((mRole == TransferRole::kReceiver && mControlMode == TransferControlFlags::kSenderDrive) || @@ -246,11 +238,15 @@ CHIP_ERROR TransferSession::AcceptTransfer(const TransferAcceptData & acceptData mAwaitingResponse = true; } + PrepareOutgoingMessageEvent(msgType, mPendingOutput, mMsgTypeData); + return CHIP_NO_ERROR; } CHIP_ERROR TransferSession::PrepareBlockQuery() { + const MessageType msgType = MessageType::BlockQuery; + VerifyOrReturnError(mState == TransferState::kTransferInProgress, CHIP_ERROR_INCORRECT_STATE); VerifyOrReturnError(mRole == TransferRole::kReceiver, CHIP_ERROR_INCORRECT_STATE); VerifyOrReturnError(mPendingOutput == OutputEventType::kNone, CHIP_ERROR_INCORRECT_STATE); @@ -261,13 +257,11 @@ CHIP_ERROR TransferSession::PrepareBlockQuery() ReturnErrorOnFailure(WriteToPacketBuffer(queryMsg, mPendingMsgHandle)); - ReturnErrorOnFailure(AttachHeader(MessageType::BlockQuery, mPendingMsgHandle)); - - mPendingOutput = OutputEventType::kMsgToSend; - mAwaitingResponse = true; mLastQueryNum = mNextQueryNum++; + PrepareOutgoingMessageEvent(msgType, mPendingOutput, mMsgTypeData); + return CHIP_NO_ERROR; } @@ -289,9 +283,6 @@ CHIP_ERROR TransferSession::PrepareBlock(const BlockData & inData) ReturnErrorOnFailure(WriteToPacketBuffer(blockMsg, mPendingMsgHandle)); const MessageType msgType = inData.IsEof ? MessageType::BlockEOF : MessageType::Block; - ReturnErrorOnFailure(AttachHeader(msgType, mPendingMsgHandle)); - - mPendingOutput = OutputEventType::kMsgToSend; if (msgType == MessageType::BlockEOF) { @@ -301,6 +292,8 @@ CHIP_ERROR TransferSession::PrepareBlock(const BlockData & inData) mAwaitingResponse = true; mLastBlockNum = mNextBlockNum++; + PrepareOutgoingMessageEvent(msgType, mPendingOutput, mMsgTypeData); + return CHIP_NO_ERROR; } @@ -317,8 +310,6 @@ CHIP_ERROR TransferSession::PrepareBlockAck() ReturnErrorOnFailure(WriteToPacketBuffer(ackMsg, mPendingMsgHandle)); - ReturnErrorOnFailure(AttachHeader(msgType, mPendingMsgHandle)); - if (mState == TransferState::kTransferInProgress) { if (mControlMode == TransferControlFlags::kSenderDrive) @@ -335,7 +326,7 @@ CHIP_ERROR TransferSession::PrepareBlockAck() mAwaitingResponse = false; } - mPendingOutput = OutputEventType::kMsgToSend; + PrepareOutgoingMessageEvent(msgType, mPendingOutput, mMsgTypeData); return CHIP_NO_ERROR; } @@ -376,13 +367,11 @@ void TransferSession::Reset() mAwaitingResponse = false; } -CHIP_ERROR TransferSession::HandleMessageReceived(System::PacketBufferHandle msg, uint64_t curTimeMs) +CHIP_ERROR TransferSession::HandleMessageReceived(const PayloadHeader & payloadHeader, System::PacketBufferHandle msg, + uint64_t curTimeMs) { VerifyOrReturnError(!msg.IsNull(), CHIP_ERROR_INVALID_ARGUMENT); - PayloadHeader payloadHeader; - ReturnErrorOnFailure(payloadHeader.DecodeAndConsume(msg)); - if (payloadHeader.HasProtocol(Protocols::BDX::Id)) { ReturnErrorOnFailure(HandleBdxMessage(payloadHeader, std::move(msg))); @@ -402,7 +391,7 @@ CHIP_ERROR TransferSession::HandleMessageReceived(System::PacketBufferHandle msg } // Return CHIP_ERROR only if there was a problem decoding the message. Otherwise, call PrepareStatusReport(). -CHIP_ERROR TransferSession::HandleBdxMessage(PayloadHeader & header, System::PacketBufferHandle msg) +CHIP_ERROR TransferSession::HandleBdxMessage(const PayloadHeader & header, System::PacketBufferHandle msg) { VerifyOrReturnError(!msg.IsNull(), CHIP_ERROR_INVALID_ARGUMENT); VerifyOrReturnError(mPendingOutput == OutputEventType::kNone, CHIP_ERROR_INCORRECT_STATE); @@ -450,7 +439,7 @@ CHIP_ERROR TransferSession::HandleBdxMessage(PayloadHeader & header, System::Pac * NOTE: BDX does not currently expect to ever use a "Success" general code, so it will be treated as an error along with any * other code. */ -CHIP_ERROR TransferSession::HandleStatusReportMessage(PayloadHeader & header, System::PacketBufferHandle msg) +CHIP_ERROR TransferSession::HandleStatusReportMessage(const PayloadHeader & header, System::PacketBufferHandle msg) { VerifyOrReturnError(!msg.IsNull(), CHIP_ERROR_INVALID_ARGUMENT); @@ -767,13 +756,12 @@ void TransferSession::PrepareStatusReport(StatusCode code) mPendingMsgHandle = bbuf.Finalize(); if (mPendingMsgHandle.IsNull()) { + ChipLogError(BDX, "%s: error preparing message: %s", __FUNCTION__, ErrorStr(CHIP_ERROR_NO_MEMORY)); mPendingOutput = OutputEventType::kInternalError; } else { - CHIP_ERROR err = AttachHeader(Protocols::SecureChannel::MsgType::StatusReport, mPendingMsgHandle); - VerifyOrExit(err == CHIP_NO_ERROR, mPendingOutput = OutputEventType::kInternalError); - mPendingOutput = OutputEventType::kMsgToSend; + PrepareOutgoingMessageEvent(Protocols::SecureChannel::MsgType::StatusReport, mPendingOutput, mMsgTypeData); } exit: @@ -835,5 +823,13 @@ TransferSession::OutputEvent TransferSession::OutputEvent::StatusReportEvent(Out return event; } +TransferSession::OutputEvent TransferSession::OutputEvent::MsgToSendEvent(MessageTypeData typeData, System::PacketBufferHandle msg) +{ + OutputEvent event(OutputEventType::kMsgToSend); + event.MsgData = std::move(msg); + event.msgTypeData = typeData; + return event; +} + } // namespace bdx } // namespace chip diff --git a/src/protocols/bdx/BdxTransferSession.h b/src/protocols/bdx/BdxTransferSession.h index 871f38b75fe770..0e2b4a9bd5309f 100644 --- a/src/protocols/bdx/BdxTransferSession.h +++ b/src/protocols/bdx/BdxTransferSession.h @@ -80,12 +80,24 @@ class DLL_EXPORT TransferSession bool IsEof = false; }; + struct MessageTypeData + { + Protocols::Id ProtocolId; // Should only ever be SecureChannel or BDX + uint8_t MessageType; + + MessageTypeData() : ProtocolId(Protocols::NotSpecified), MessageType(0) {} + }; + /** * @brief * All output data processed by the TransferSession object will be passed to the caller using this struct via PollOutput(). * - * NOTE: Some sub-structs may contain pointers to data in a PacketBuffer. In this case, the MsgData field MUST be populated - * with a PacketBufferHandle that encapsulates the respective PacketBuffer, in order to ensure valid memory access. + * NOTE: Some sub-structs may contain pointers to data in a PacketBuffer (see Blockdata). In this case, the MsgData field MUST + * be populated with a PacketBufferHandle that encapsulates the respective PacketBuffer, in order to ensure valid memory + * access. + * + * NOTE: MsgData can contain messages that have been received or messages that should be sent by the caller. The underlying + * buffer will always start at the data, never at the payload header. Outgoing messages do not have a header prepended. */ struct OutputEvent { @@ -97,6 +109,7 @@ class DLL_EXPORT TransferSession TransferAcceptData transferAcceptData; BlockData blockdata; StatusReportData statusData; + MessageTypeData msgTypeData; }; OutputEvent() : EventType(OutputEventType::kNone) { statusData = { StatusCode::kNone }; } @@ -107,6 +120,7 @@ class DLL_EXPORT TransferSession static OutputEvent TransferAcceptEvent(TransferAcceptData data, System::PacketBufferHandle msg); static OutputEvent BlockDataEvent(BlockData data, System::PacketBufferHandle msg); static OutputEvent StatusReportEvent(OutputEventType type, StatusReportData data); + static OutputEvent MsgToSendEvent(MessageTypeData typeData, System::PacketBufferHandle msg); }; /** @@ -119,8 +133,8 @@ class DLL_EXPORT TransferSession * It is possible that consecutive calls to this method may emit different outputs depending on the state of the * TransferSession object. * - * Note that if the type outputted is kMsgToSend, it is assumed that the message will be send immediately, and the - * session timeout timer will begin at curTimeMs. + * Note that if the type outputted is kMsgToSend, the caller is expected to send the message immediately, and the session + * timeout timer will begin at curTimeMs. * * See OutputEventType for all possible output event types. * @@ -236,13 +250,15 @@ class DLL_EXPORT TransferSession * @brief * Process a message intended for this TransferSession object. * - * @param msg A PacketBufferHandle pointing to the message buffer to process. May be BDX or StatusReport protocol. - * @param curTimeMs Current time indicated by the number of milliseconds since some epoch defined by the platform + * @param payloadHeader A PayloadHeader containing the Protocol type and Message Type + * @param msg A PacketBufferHandle pointing to the message buffer to process. May be BDX or StatusReport protocol. + * Buffer is expected to start at data (not header). + * @param curTimeMs Current time indicated by the number of milliseconds since some epoch defined by the platform * * @return CHIP_ERROR Indicates any problems in decoding the message, or if the message is not of the BDX or StatusReport * protocols. */ - CHIP_ERROR HandleMessageReceived(System::PacketBufferHandle msg, uint64_t curTimeMs); + CHIP_ERROR HandleMessageReceived(const PayloadHeader & payloadHeader, System::PacketBufferHandle msg, uint64_t curTimeMs); TransferControlFlags GetControlMode() const { return mControlMode; } uint64_t GetStartOffset() const { return mStartOffset; } @@ -266,8 +282,8 @@ class DLL_EXPORT TransferSession }; // Incoming message handlers - CHIP_ERROR HandleBdxMessage(PayloadHeader & header, System::PacketBufferHandle msg); - CHIP_ERROR HandleStatusReportMessage(PayloadHeader & header, System::PacketBufferHandle msg); + CHIP_ERROR HandleBdxMessage(const PayloadHeader & header, System::PacketBufferHandle msg); + CHIP_ERROR HandleStatusReportMessage(const PayloadHeader & header, System::PacketBufferHandle msg); void HandleTransferInit(MessageType msgType, System::PacketBufferHandle msgData); void HandleReceiveAccept(System::PacketBufferHandle msgData); void HandleSendAccept(System::PacketBufferHandle msgData); @@ -308,11 +324,13 @@ class DLL_EXPORT TransferSession uint64_t mTransferLength = 0; ///< 0 represents indefinite length uint16_t mTransferMaxBlockSize = 0; + // Used to store event data before it is emitted via PollOutput() System::PacketBufferHandle mPendingMsgHandle; StatusReportData mStatusReportData; TransferInitData mTransferRequestData; TransferAcceptData mTransferAcceptData; BlockData mBlockEventData; + MessageTypeData mMsgTypeData; uint32_t mNumBytesProcessed = 0; diff --git a/src/protocols/bdx/tests/TestBdxTransferSession.cpp b/src/protocols/bdx/tests/TestBdxTransferSession.cpp index b7ac4fd009e49a..07f6d0a50c58e8 100644 --- a/src/protocols/bdx/tests/TestBdxTransferSession.cpp +++ b/src/protocols/bdx/tests/TestBdxTransferSession.cpp @@ -80,29 +80,32 @@ CHIP_ERROR ReadAndVerifyTLVString(nlTestSuite * inSuite, void * inContext, const return err; } -// Helper method for verifying that a PacketBufferHandle contains a valid BDX header and message type matches expected. -void VerifyBdxMessageType(nlTestSuite * inSuite, void * inContext, const System::PacketBufferHandle & msg, MessageType expected) +CHIP_ERROR AttachHeaderAndSend(TransferSession::MessageTypeData typeData, chip::System::PacketBufferHandle msgBuf, + TransferSession & receiver) { - CHIP_ERROR err = CHIP_NO_ERROR; - uint16_t headerSize = 0; - PayloadHeader payloadHeader; + chip::PayloadHeader payloadHeader; + payloadHeader.SetMessageType(typeData.ProtocolId, typeData.MessageType); - if (msg.IsNull()) - { - NL_TEST_ASSERT(inSuite, false); - return; - } + ReturnErrorOnFailure(receiver.HandleMessageReceived(payloadHeader, std::move(msgBuf), kNoAdvanceTime)); + return CHIP_NO_ERROR; +} - err = payloadHeader.Decode(msg->Start(), msg->DataLength(), &headerSize); - NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); - NL_TEST_ASSERT(inSuite, payloadHeader.HasMessageType(expected)); +// Helper method for verifying that a PacketBufferHandle contains a valid BDX header and message type matches expected. +void VerifyBdxMessageToSend(nlTestSuite * inSuite, void * inContext, const TransferSession::OutputEvent & outEvent, + MessageType expected) +{ + static_assert(std::is_same, uint8_t>::value, "Cast is not safe"); + NL_TEST_ASSERT(inSuite, outEvent.EventType == TransferSession::OutputEventType::kMsgToSend); + NL_TEST_ASSERT(inSuite, !outEvent.MsgData.IsNull()); + NL_TEST_ASSERT(inSuite, outEvent.msgTypeData.ProtocolId == Protocols::BDX::Id); + NL_TEST_ASSERT(inSuite, outEvent.msgTypeData.MessageType == static_cast(expected)); } // Helper method for verifying that a PacketBufferHandle contains a valid StatusReport message and contains a specific StatusCode. -void VerifyStatusReport(nlTestSuite * inSuite, void * inContext, const System::PacketBufferHandle & msg, StatusCode code) +// The msg argument is expected to begin at the message data start, not at the PayloadHeader. +void VerifyStatusReport(nlTestSuite * inSuite, void * inContext, const System::PacketBufferHandle & msg, StatusCode expectedCode) { CHIP_ERROR err = CHIP_NO_ERROR; - PayloadHeader payloadHeader; if (msg.IsNull()) { @@ -117,16 +120,12 @@ void VerifyStatusReport(nlTestSuite * inSuite, void * inContext, const System::P return; } - err = payloadHeader.DecodeAndConsume(msgCopy); - NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); - NL_TEST_ASSERT(inSuite, payloadHeader.HasMessageType(SecureChannel::MsgType::StatusReport)); - SecureChannel::StatusReport report; err = report.Parse(std::move(msgCopy)); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); NL_TEST_ASSERT(inSuite, report.GetGeneralCode() == SecureChannel::GeneralStatusCode::kFailure); NL_TEST_ASSERT(inSuite, report.GetProtocolId() == Protocols::BDX::Id.ToFullyQualifiedSpecForm()); - NL_TEST_ASSERT(inSuite, report.GetProtocolCode() == static_cast(code)); + NL_TEST_ASSERT(inSuite, report.GetProtocolCode() == static_cast(expectedCode)); } void VerifyNoMoreOutput(nlTestSuite * inSuite, void * inContext, TransferSession & transferSession) @@ -157,11 +156,11 @@ void SendAndVerifyTransferInit(nlTestSuite * inSuite, void * inContext, Transfer NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); initiator.PollOutput(outEvent, kNoAdvanceTime); NL_TEST_ASSERT(inSuite, outEvent.EventType == TransferSession::OutputEventType::kMsgToSend); - VerifyBdxMessageType(inSuite, inContext, outEvent.MsgData, expectedInitMsg); + VerifyBdxMessageToSend(inSuite, inContext, outEvent, expectedInitMsg); VerifyNoMoreOutput(inSuite, inContext, initiator); // Verify that all parsed TransferInit fields match what was sent by the initiator - err = responder.HandleMessageReceived(std::move(outEvent.MsgData), kNoAdvanceTime); + err = AttachHeaderAndSend(outEvent.msgTypeData, std::move(outEvent.MsgData), responder); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); responder.PollOutput(outEvent, kNoAdvanceTime); VerifyNoMoreOutput(inSuite, inContext, responder); @@ -219,10 +218,10 @@ void SendAndVerifyAcceptMsg(nlTestSuite * inSuite, void * inContext, TransferSes acceptSender.PollOutput(outEvent, kNoAdvanceTime); VerifyNoMoreOutput(inSuite, inContext, acceptSender); NL_TEST_ASSERT(inSuite, outEvent.EventType == TransferSession::OutputEventType::kMsgToSend); - VerifyBdxMessageType(inSuite, inContext, outEvent.MsgData, expectedMsg); + VerifyBdxMessageToSend(inSuite, inContext, outEvent, expectedMsg); // Pass Accept message to acceptReceiver - err = acceptReceiver.HandleMessageReceived(std::move(outEvent.MsgData), kNoAdvanceTime); + err = AttachHeaderAndSend(outEvent.msgTypeData, std::move(outEvent.MsgData), acceptReceiver); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); // Verify received ReceiveAccept. @@ -265,11 +264,11 @@ void SendAndVerifyQuery(nlTestSuite * inSuite, void * inContext, TransferSession NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); querySender.PollOutput(outEvent, kNoAdvanceTime); NL_TEST_ASSERT(inSuite, outEvent.EventType == TransferSession::OutputEventType::kMsgToSend); - VerifyBdxMessageType(inSuite, inContext, outEvent.MsgData, MessageType::BlockQuery); + VerifyBdxMessageToSend(inSuite, inContext, outEvent, MessageType::BlockQuery); VerifyNoMoreOutput(inSuite, inContext, querySender); // Pass BlockQuery to queryReceiver and verify queryReceiver emits QueryReceived event - err = queryReceiver.HandleMessageReceived(std::move(outEvent.MsgData), kNoAdvanceTime); + err = AttachHeaderAndSend(outEvent.msgTypeData, std::move(outEvent.MsgData), queryReceiver); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); queryReceiver.PollOutput(outEvent, kNoAdvanceTime); NL_TEST_ASSERT(inSuite, outEvent.EventType == TransferSession::OutputEventType::kQueryReceived); @@ -308,11 +307,11 @@ void SendAndVerifyArbitraryBlock(nlTestSuite * inSuite, void * inContext, Transf NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); sender.PollOutput(outEvent, kNoAdvanceTime); NL_TEST_ASSERT(inSuite, outEvent.EventType == TransferSession::OutputEventType::kMsgToSend); - VerifyBdxMessageType(inSuite, inContext, outEvent.MsgData, expected); + VerifyBdxMessageToSend(inSuite, inContext, outEvent, expected); VerifyNoMoreOutput(inSuite, inContext, sender); // Pass Block message to receiver and verify matching Block is received - err = receiver.HandleMessageReceived(std::move(outEvent.MsgData), kNoAdvanceTime); + err = AttachHeaderAndSend(outEvent.msgTypeData, std::move(outEvent.MsgData), receiver); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); receiver.PollOutput(outEvent, kNoAdvanceTime); NL_TEST_ASSERT(inSuite, outEvent.EventType == TransferSession::OutputEventType::kBlockReceived); @@ -337,11 +336,11 @@ void SendAndVerifyBlockAck(nlTestSuite * inSuite, void * inContext, TransferSess NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); ackSender.PollOutput(outEvent, kNoAdvanceTime); NL_TEST_ASSERT(inSuite, outEvent.EventType == TransferSession::OutputEventType::kMsgToSend); - VerifyBdxMessageType(inSuite, inContext, outEvent.MsgData, expectedMsgType); + VerifyBdxMessageToSend(inSuite, inContext, outEvent, expectedMsgType); VerifyNoMoreOutput(inSuite, inContext, ackSender); // Pass BlockAck to ackReceiver and verify it was received - err = ackReceiver.HandleMessageReceived(std::move(outEvent.MsgData), kNoAdvanceTime); + err = AttachHeaderAndSend(outEvent.msgTypeData, std::move(outEvent.MsgData), ackReceiver); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); ackReceiver.PollOutput(outEvent, kNoAdvanceTime); NL_TEST_ASSERT(inSuite, outEvent.EventType == expectedEventType); @@ -606,7 +605,7 @@ void TestTimeout(nlTestSuite * inSuite, void * inContext) initiator.PollOutput(outEvent, startTimeMs); NL_TEST_ASSERT(inSuite, outEvent.EventType == TransferSession::OutputEventType::kMsgToSend); MessageType expectedInitMsg = (role == TransferRole::kSender) ? MessageType::SendInit : MessageType::ReceiveInit; - VerifyBdxMessageType(inSuite, inContext, outEvent.MsgData, expectedInitMsg); + VerifyBdxMessageToSend(inSuite, inContext, outEvent, expectedInitMsg); // Second PollOutput() with no call to HandleMessageReceived() should result in a timeout. initiator.PollOutput(outEvent, endTimeMs); @@ -674,13 +673,13 @@ void TestDuplicateBlockError(nlTestSuite * inSuite, void * inContext) NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); respondingSender.PollOutput(eventWithBlock, kNoAdvanceTime); NL_TEST_ASSERT(inSuite, eventWithBlock.EventType == TransferSession::OutputEventType::kMsgToSend); - VerifyBdxMessageType(inSuite, inContext, eventWithBlock.MsgData, MessageType::Block); + VerifyBdxMessageToSend(inSuite, inContext, eventWithBlock, MessageType::Block); VerifyNoMoreOutput(inSuite, inContext, respondingSender); System::PacketBufferHandle blockCopy = System::PacketBufferHandle::NewWithData(eventWithBlock.MsgData->Start(), eventWithBlock.MsgData->DataLength()); // Pass Block message to receiver and verify matching Block is received - err = initiatingReceiver.HandleMessageReceived(std::move(eventWithBlock.MsgData), kNoAdvanceTime); + err = AttachHeaderAndSend(eventWithBlock.msgTypeData, std::move(eventWithBlock.MsgData), initiatingReceiver); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); initiatingReceiver.PollOutput(outEvent, kNoAdvanceTime); NL_TEST_ASSERT(inSuite, outEvent.EventType == TransferSession::OutputEventType::kBlockReceived); @@ -690,11 +689,12 @@ void TestDuplicateBlockError(nlTestSuite * inSuite, void * inContext) SendAndVerifyQuery(inSuite, inContext, respondingSender, initiatingReceiver, outEvent); // Verify receiving same Block twice fails and results in StatusReport event, and then InternalError event - err = initiatingReceiver.HandleMessageReceived(std::move(blockCopy), kNoAdvanceTime); + err = AttachHeaderAndSend(eventWithBlock.msgTypeData, std::move(blockCopy), initiatingReceiver); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); initiatingReceiver.PollOutput(outEvent, kNoAdvanceTime); NL_TEST_ASSERT(inSuite, outEvent.EventType == TransferSession::OutputEventType::kMsgToSend); - System::PacketBufferHandle statusReportMsg = outEvent.MsgData.Retain(); + System::PacketBufferHandle statusReportMsg = outEvent.MsgData.Retain(); + TransferSession::MessageTypeData statusReportMsgTypeData = outEvent.msgTypeData; VerifyStatusReport(inSuite, inContext, std::move(outEvent.MsgData), StatusCode::kBadBlockCounter); // All subsequent PollOutput() calls should return kInternalError @@ -705,7 +705,7 @@ void TestDuplicateBlockError(nlTestSuite * inSuite, void * inContext) NL_TEST_ASSERT(inSuite, outEvent.statusData.statusCode == StatusCode::kBadBlockCounter); } - err = respondingSender.HandleMessageReceived(std::move(statusReportMsg), kNoAdvanceTime); + err = AttachHeaderAndSend(statusReportMsgTypeData, std::move(statusReportMsg), respondingSender); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); respondingSender.PollOutput(outEvent, kNoAdvanceTime); NL_TEST_ASSERT(inSuite, outEvent.EventType == TransferSession::OutputEventType::kStatusReceived);