diff --git a/examples/shell/shell_common/cmd_send.cpp b/examples/shell/shell_common/cmd_send.cpp index 9587d5218d2aad..45bdeb6ef68df7 100644 --- a/examples/shell/shell_common/cmd_send.cpp +++ b/examples/shell/shell_common/cmd_send.cpp @@ -100,8 +100,8 @@ class SendArguments class MockAppDelegate : public Messaging::ExchangeDelegate { public: - void OnMessageReceived(Messaging::ExchangeContext * ec, const PacketHeader & packetHeader, const PayloadHeader & payloadHeader, - System::PacketBufferHandle && buffer) override + CHIP_ERROR OnMessageReceived(Messaging::ExchangeContext * ec, const PacketHeader & packetHeader, + const PayloadHeader & payloadHeader, System::PacketBufferHandle && buffer) override { uint32_t respTime = System::Timer::GetCurrentEpoch(); uint32_t transitTime = respTime - gSendArguments.GetLastSendTime(); @@ -112,6 +112,7 @@ class MockAppDelegate : public Messaging::ExchangeDelegate gExchangeCtx->Close(); gExchangeCtx = nullptr; + return CHIP_NO_ERROR; } void OnResponseTimeout(Messaging::ExchangeContext * ec) override diff --git a/src/app/CommandHandler.cpp b/src/app/CommandHandler.cpp index 7ff93cf3cd2884..6379cb2ca177b3 100644 --- a/src/app/CommandHandler.cpp +++ b/src/app/CommandHandler.cpp @@ -33,8 +33,8 @@ using GeneralStatusCode = chip::Protocols::SecureChannel::GeneralStatusCode; namespace chip { namespace app { -void CommandHandler::OnMessageReceived(Messaging::ExchangeContext * ec, const PacketHeader & packetHeader, - const PayloadHeader & payloadHeader, System::PacketBufferHandle && payload) +CHIP_ERROR CommandHandler::OnInvokeCommandRequest(Messaging::ExchangeContext * ec, const PacketHeader & packetHeader, + const PayloadHeader & payloadHeader, System::PacketBufferHandle && payload) { CHIP_ERROR err = CHIP_NO_ERROR; System::PacketBufferHandle response; @@ -51,6 +51,7 @@ void CommandHandler::OnMessageReceived(Messaging::ExchangeContext * ec, const Pa exit: ChipLogFunctError(err); + return err; } CHIP_ERROR CommandHandler::SendCommandResponse() diff --git a/src/app/CommandHandler.h b/src/app/CommandHandler.h index f9bf6b95ab4b53..1466f80f211b0a 100644 --- a/src/app/CommandHandler.h +++ b/src/app/CommandHandler.h @@ -42,8 +42,8 @@ namespace app { class CommandHandler : public Command { public: - void OnMessageReceived(Messaging::ExchangeContext * ec, const PacketHeader & packetHeader, const PayloadHeader & payloadHeader, - System::PacketBufferHandle && payload); + CHIP_ERROR OnInvokeCommandRequest(Messaging::ExchangeContext * ec, const PacketHeader & packetHeader, + const PayloadHeader & payloadHeader, System::PacketBufferHandle && payload); CHIP_ERROR AddStatusCode(const CommandPathParams & aCommandPathParams, const Protocols::SecureChannel::GeneralStatusCode aGeneralCode, const Protocols::Id aProtocolId, const Protocols::InteractionModel::ProtocolCode aProtocolCode) override; diff --git a/src/app/CommandSender.cpp b/src/app/CommandSender.cpp index 76a34594dd1aa1..ebd67421110960 100644 --- a/src/app/CommandSender.cpp +++ b/src/app/CommandSender.cpp @@ -77,8 +77,8 @@ CHIP_ERROR CommandSender::SendCommandRequest(NodeId aNodeId, Transport::AdminId return err; } -void CommandSender::OnMessageReceived(Messaging::ExchangeContext * apExchangeContext, const PacketHeader & aPacketHeader, - const PayloadHeader & aPayloadHeader, System::PacketBufferHandle && aPayload) +CHIP_ERROR CommandSender::OnMessageReceived(Messaging::ExchangeContext * apExchangeContext, const PacketHeader & aPacketHeader, + const PayloadHeader & aPayloadHeader, System::PacketBufferHandle && aPayload) { CHIP_ERROR err = CHIP_NO_ERROR; @@ -110,6 +110,7 @@ void CommandSender::OnMessageReceived(Messaging::ExchangeContext * apExchangeCon } Shutdown(); + return err; } void CommandSender::OnResponseTimeout(Messaging::ExchangeContext * apExchangeContext) diff --git a/src/app/CommandSender.h b/src/app/CommandSender.h index aa0a47e7d2366f..c7f84137ea0a05 100644 --- a/src/app/CommandSender.h +++ b/src/app/CommandSender.h @@ -58,8 +58,8 @@ class CommandSender : public Command, public Messaging::ExchangeDelegate // ExchangeDelegate interface implementation. Private so people won't // accidentally call it on us when we're not being treated as an actual // ExchangeDelegate. - void OnMessageReceived(Messaging::ExchangeContext * apExchangeContext, const PacketHeader & aPacketHeader, - const PayloadHeader & aPayloadHeader, System::PacketBufferHandle && aPayload) override; + CHIP_ERROR OnMessageReceived(Messaging::ExchangeContext * apExchangeContext, const PacketHeader & aPacketHeader, + const PayloadHeader & aPayloadHeader, System::PacketBufferHandle && aPayload) override; void OnResponseTimeout(Messaging::ExchangeContext * apExchangeContext) override; CHIP_ERROR ProcessCommandDataElement(CommandDataElement::Parser & aCommandElement) override; diff --git a/src/app/InteractionModelEngine.cpp b/src/app/InteractionModelEngine.cpp index 32def91f2397c8..fdd740b24ab8d9 100644 --- a/src/app/InteractionModelEngine.cpp +++ b/src/app/InteractionModelEngine.cpp @@ -178,8 +178,9 @@ CHIP_ERROR InteractionModelEngine::NewWriteClient(WriteClient ** const apWriteCl return CHIP_ERROR_NO_MEMORY; } -void InteractionModelEngine::OnUnknownMsgType(Messaging::ExchangeContext * apExchangeContext, const PacketHeader & aPacketHeader, - const PayloadHeader & aPayloadHeader, System::PacketBufferHandle && aPayload) +CHIP_ERROR InteractionModelEngine::OnUnknownMsgType(Messaging::ExchangeContext * apExchangeContext, + const PacketHeader & aPacketHeader, const PayloadHeader & aPayloadHeader, + System::PacketBufferHandle && aPayload) { CHIP_ERROR err = CHIP_NO_ERROR; @@ -199,11 +200,12 @@ void InteractionModelEngine::OnUnknownMsgType(Messaging::ExchangeContext * apExc { apExchangeContext->Abort(); } + return err; } -void InteractionModelEngine::OnInvokeCommandRequest(Messaging::ExchangeContext * apExchangeContext, - const PacketHeader & aPacketHeader, const PayloadHeader & aPayloadHeader, - System::PacketBufferHandle && aPayload) +CHIP_ERROR InteractionModelEngine::OnInvokeCommandRequest(Messaging::ExchangeContext * apExchangeContext, + const PacketHeader & aPacketHeader, const PayloadHeader & aPayloadHeader, + System::PacketBufferHandle && aPayload) { CHIP_ERROR err = CHIP_NO_ERROR; @@ -213,7 +215,7 @@ void InteractionModelEngine::OnInvokeCommandRequest(Messaging::ExchangeContext * { err = commandHandler.Init(mpExchangeMgr, mpDelegate); SuccessOrExit(err); - commandHandler.OnMessageReceived(apExchangeContext, aPacketHeader, aPayloadHeader, std::move(aPayload)); + err = commandHandler.OnInvokeCommandRequest(apExchangeContext, aPacketHeader, aPayloadHeader, std::move(aPayload)); apExchangeContext = nullptr; break; } @@ -226,10 +228,11 @@ void InteractionModelEngine::OnInvokeCommandRequest(Messaging::ExchangeContext * { apExchangeContext->Abort(); } + return err; } -void InteractionModelEngine::OnReadRequest(Messaging::ExchangeContext * apExchangeContext, const PacketHeader & aPacketHeader, - const PayloadHeader & aPayloadHeader, System::PacketBufferHandle && aPayload) +CHIP_ERROR InteractionModelEngine::OnReadRequest(Messaging::ExchangeContext * apExchangeContext, const PacketHeader & aPacketHeader, + const PayloadHeader & aPayloadHeader, System::PacketBufferHandle && aPayload) { CHIP_ERROR err = CHIP_NO_ERROR; @@ -241,8 +244,7 @@ void InteractionModelEngine::OnReadRequest(Messaging::ExchangeContext * apExchan { err = readHandler.Init(mpDelegate); SuccessOrExit(err); - err = readHandler.OnReadRequest(apExchangeContext, std::move(aPayload)); - SuccessOrExit(err); + err = readHandler.OnReadRequest(apExchangeContext, std::move(aPayload)); apExchangeContext = nullptr; break; } @@ -255,10 +257,12 @@ void InteractionModelEngine::OnReadRequest(Messaging::ExchangeContext * apExchan { apExchangeContext->Abort(); } + return err; } -void InteractionModelEngine::OnWriteRequest(Messaging::ExchangeContext * apExchangeContext, const PacketHeader & aPacketHeader, - const PayloadHeader & aPayloadHeader, System::PacketBufferHandle && aPayload) +CHIP_ERROR InteractionModelEngine::OnWriteRequest(Messaging::ExchangeContext * apExchangeContext, + const PacketHeader & aPacketHeader, const PayloadHeader & aPayloadHeader, + System::PacketBufferHandle && aPayload) { CHIP_ERROR err = CHIP_NO_ERROR; @@ -270,8 +274,7 @@ void InteractionModelEngine::OnWriteRequest(Messaging::ExchangeContext * apExcha { err = writeHandler.Init(mpDelegate); SuccessOrExit(err); - err = writeHandler.OnWriteRequest(apExchangeContext, std::move(aPayload)); - SuccessOrExit(err); + err = writeHandler.OnWriteRequest(apExchangeContext, std::move(aPayload)); apExchangeContext = nullptr; break; } @@ -284,28 +287,31 @@ void InteractionModelEngine::OnWriteRequest(Messaging::ExchangeContext * apExcha { apExchangeContext->Abort(); } + return err; } -void InteractionModelEngine::OnMessageReceived(Messaging::ExchangeContext * apExchangeContext, const PacketHeader & aPacketHeader, - const PayloadHeader & aPayloadHeader, System::PacketBufferHandle && aPayload) +CHIP_ERROR InteractionModelEngine::OnMessageReceived(Messaging::ExchangeContext * apExchangeContext, + const PacketHeader & aPacketHeader, const PayloadHeader & aPayloadHeader, + System::PacketBufferHandle && aPayload) { + CHIP_ERROR err = CHIP_NO_ERROR; if (aPayloadHeader.HasMessageType(Protocols::InteractionModel::MsgType::InvokeCommandRequest)) { - - OnInvokeCommandRequest(apExchangeContext, aPacketHeader, aPayloadHeader, std::move(aPayload)); + err = OnInvokeCommandRequest(apExchangeContext, aPacketHeader, aPayloadHeader, std::move(aPayload)); } else if (aPayloadHeader.HasMessageType(Protocols::InteractionModel::MsgType::ReadRequest)) { - OnReadRequest(apExchangeContext, aPacketHeader, aPayloadHeader, std::move(aPayload)); + err = OnReadRequest(apExchangeContext, aPacketHeader, aPayloadHeader, std::move(aPayload)); } else if (aPayloadHeader.HasMessageType(Protocols::InteractionModel::MsgType::WriteRequest)) { - OnWriteRequest(apExchangeContext, aPacketHeader, aPayloadHeader, std::move(aPayload)); + err = OnWriteRequest(apExchangeContext, aPacketHeader, aPayloadHeader, std::move(aPayload)); } else { - OnUnknownMsgType(apExchangeContext, aPacketHeader, aPayloadHeader, std::move(aPayload)); + err = OnUnknownMsgType(apExchangeContext, aPacketHeader, aPayloadHeader, std::move(aPayload)); } + return err; } void InteractionModelEngine::OnResponseTimeout(Messaging::ExchangeContext * ec) diff --git a/src/app/InteractionModelEngine.h b/src/app/InteractionModelEngine.h index f950f8cc064f25..9ae4af8e491ef3 100644 --- a/src/app/InteractionModelEngine.h +++ b/src/app/InteractionModelEngine.h @@ -155,27 +155,27 @@ class InteractionModelEngine : public Messaging::ExchangeDelegate private: friend class reporting::Engine; - void OnUnknownMsgType(Messaging::ExchangeContext * apExchangeContext, const PacketHeader & aPacketHeader, - const PayloadHeader & aPayloadHeader, System::PacketBufferHandle && aPayload); - void OnInvokeCommandRequest(Messaging::ExchangeContext * apExchangeContext, const PacketHeader & aPacketHeader, + CHIP_ERROR OnUnknownMsgType(Messaging::ExchangeContext * apExchangeContext, const PacketHeader & aPacketHeader, const PayloadHeader & aPayloadHeader, System::PacketBufferHandle && aPayload); - void OnMessageReceived(Messaging::ExchangeContext * apExchangeContext, const PacketHeader & aPacketHeader, - const PayloadHeader & aPayloadHeader, System::PacketBufferHandle && aPayload); + CHIP_ERROR OnInvokeCommandRequest(Messaging::ExchangeContext * apExchangeContext, const PacketHeader & aPacketHeader, + const PayloadHeader & aPayloadHeader, System::PacketBufferHandle && aPayload); + CHIP_ERROR OnMessageReceived(Messaging::ExchangeContext * apExchangeContext, const PacketHeader & aPacketHeader, + const PayloadHeader & aPayloadHeader, System::PacketBufferHandle && aPayload); void OnResponseTimeout(Messaging::ExchangeContext * ec); /** * Called when Interaction Model receives a Read Request message. Errors processing * the Read Request are handled entirely within this function. */ - void OnReadRequest(Messaging::ExchangeContext * apExchangeContext, const PacketHeader & aPacketHeader, - const PayloadHeader & aPayloadHeader, System::PacketBufferHandle && aPayload); + CHIP_ERROR OnReadRequest(Messaging::ExchangeContext * apExchangeContext, const PacketHeader & aPacketHeader, + const PayloadHeader & aPayloadHeader, System::PacketBufferHandle && aPayload); /** * Called when Interaction Model receives a Write Request message. Errors processing * the Write Request are handled entirely within this function. */ - void OnWriteRequest(Messaging::ExchangeContext * apExchangeContext, const PacketHeader & aPacketHeader, - const PayloadHeader & aPayloadHeader, System::PacketBufferHandle && aPayload); + CHIP_ERROR OnWriteRequest(Messaging::ExchangeContext * apExchangeContext, const PacketHeader & aPacketHeader, + const PayloadHeader & aPayloadHeader, System::PacketBufferHandle && aPayload); Messaging::ExchangeManager * mpExchangeMgr = nullptr; InteractionModelDelegate * mpDelegate = nullptr; diff --git a/src/app/ReadClient.cpp b/src/app/ReadClient.cpp index ecc64641ddb212..475b57985b31cf 100644 --- a/src/app/ReadClient.cpp +++ b/src/app/ReadClient.cpp @@ -194,8 +194,8 @@ CHIP_ERROR ReadClient::GenerateAttributePathList(ReadRequest::Builder & aRequest return attributePathListBuilder.GetError(); } -void ReadClient::OnMessageReceived(Messaging::ExchangeContext * apExchangeContext, const PacketHeader & aPacketHeader, - const PayloadHeader & aPayloadHeader, System::PacketBufferHandle && aPayload) +CHIP_ERROR ReadClient::OnMessageReceived(Messaging::ExchangeContext * apExchangeContext, const PacketHeader & aPacketHeader, + const PayloadHeader & aPayloadHeader, System::PacketBufferHandle && aPayload) { CHIP_ERROR err = CHIP_NO_ERROR; @@ -224,7 +224,7 @@ void ReadClient::OnMessageReceived(Messaging::ExchangeContext * apExchangeContex } } - return; + return err; } CHIP_ERROR ReadClient::AbortExistingExchangeContext() diff --git a/src/app/ReadClient.h b/src/app/ReadClient.h index e26263525da5af..bfdb4aa56e5cf6 100644 --- a/src/app/ReadClient.h +++ b/src/app/ReadClient.h @@ -101,8 +101,8 @@ class ReadClient : public Messaging::ExchangeDelegate virtual ~ReadClient() = default; - void OnMessageReceived(Messaging::ExchangeContext * apExchangeContext, const PacketHeader & aPacketHeader, - const PayloadHeader & aPayloadHeader, System::PacketBufferHandle && aPayload) override; + CHIP_ERROR OnMessageReceived(Messaging::ExchangeContext * apExchangeContext, const PacketHeader & aPacketHeader, + const PayloadHeader & aPayloadHeader, System::PacketBufferHandle && aPayload) override; void OnResponseTimeout(Messaging::ExchangeContext * apExchangeContext) override; /** diff --git a/src/app/WriteClient.cpp b/src/app/WriteClient.cpp index 85572131a0a20e..79b1eed4a2d6f5 100644 --- a/src/app/WriteClient.cpp +++ b/src/app/WriteClient.cpp @@ -284,8 +284,8 @@ CHIP_ERROR WriteClient::SendWriteRequest(NodeId aNodeId, Transport::AdminId aAdm return err; } -void WriteClient::OnMessageReceived(Messaging::ExchangeContext * apExchangeContext, const PacketHeader & aPacketHeader, - const PayloadHeader & aPayloadHeader, System::PacketBufferHandle && aPayload) +CHIP_ERROR WriteClient::OnMessageReceived(Messaging::ExchangeContext * apExchangeContext, const PacketHeader & aPacketHeader, + const PayloadHeader & aPayloadHeader, System::PacketBufferHandle && aPayload) { CHIP_ERROR err = CHIP_NO_ERROR; // Assert that the exchange context matches the client's current context. @@ -324,6 +324,7 @@ void WriteClient::OnMessageReceived(Messaging::ExchangeContext * apExchangeConte } } Shutdown(); + return err; } void WriteClient::OnResponseTimeout(Messaging::ExchangeContext * apExchangeContext) diff --git a/src/app/WriteClient.h b/src/app/WriteClient.h index cdd651ed0b4113..a8d496d497201a 100644 --- a/src/app/WriteClient.h +++ b/src/app/WriteClient.h @@ -94,8 +94,8 @@ class WriteClient : public Messaging::ExchangeDelegate virtual ~WriteClient() = default; - void OnMessageReceived(Messaging::ExchangeContext * apExchangeContext, const PacketHeader & aPacketHeader, - const PayloadHeader & aPayloadHeader, System::PacketBufferHandle && aPayload) override; + CHIP_ERROR OnMessageReceived(Messaging::ExchangeContext * apExchangeContext, const PacketHeader & aPacketHeader, + const PayloadHeader & aPayloadHeader, System::PacketBufferHandle && aPayload) override; void OnResponseTimeout(Messaging::ExchangeContext * apExchangeContext) override; /** diff --git a/src/app/server/Server.cpp b/src/app/server/Server.cpp index b1beb043c45773..d2515294dedf0f 100644 --- a/src/app/server/Server.cpp +++ b/src/app/server/Server.cpp @@ -323,9 +323,10 @@ static CHIP_ERROR OpenPairingWindowUsingVerifier(uint16_t discriminator, PASEVer class ServerCallback : public ExchangeDelegate { public: - void OnMessageReceived(Messaging::ExchangeContext * exchangeContext, const PacketHeader & packetHeader, - const PayloadHeader & payloadHeader, System::PacketBufferHandle && buffer) override + CHIP_ERROR OnMessageReceived(Messaging::ExchangeContext * exchangeContext, const PacketHeader & packetHeader, + const PayloadHeader & payloadHeader, System::PacketBufferHandle && buffer) override { + CHIP_ERROR err = CHIP_NO_ERROR; // as soon as a client connects, assume it is connected VerifyOrExit(!buffer.IsNull(), ChipLogError(AppServer, "Received data but couldn't process it...")); VerifyOrExit(packetHeader.GetSourceNodeId().HasValue(), ChipLogError(AppServer, "Unknown source for received message")); @@ -342,7 +343,6 @@ class ServerCallback : public ExchangeDelegate // Issue: https://github.com/project-chip/connectedhomeip/issues/4725 if (payloadHeader.HasProtocol(chip::Protocols::ServiceProvisioning::Id)) { - CHIP_ERROR err = CHIP_NO_ERROR; uint32_t timeout; uint16_t discriminator; PASEVerifier verifier; @@ -388,6 +388,7 @@ class ServerCallback : public ExchangeDelegate exit: exchangeContext->Close(); + return err; } void OnResponseTimeout(ExchangeContext * ec) override diff --git a/src/app/tests/TestCommandInteraction.cpp b/src/app/tests/TestCommandInteraction.cpp index 83b60e9eba7941..9a406a78d7c885 100644 --- a/src/app/tests/TestCommandInteraction.cpp +++ b/src/app/tests/TestCommandInteraction.cpp @@ -112,9 +112,11 @@ class TestCommandInteraction class TestExchangeDelegate : public Messaging::ExchangeDelegate { - void OnMessageReceived(Messaging::ExchangeContext * ec, const PacketHeader & packetHeader, const PayloadHeader & payloadHeader, - System::PacketBufferHandle && payload) override - {} + CHIP_ERROR OnMessageReceived(Messaging::ExchangeContext * ec, const PacketHeader & packetHeader, + const PayloadHeader & payloadHeader, System::PacketBufferHandle && payload) override + { + return CHIP_NO_ERROR; + } void OnResponseTimeout(Messaging::ExchangeContext * ec) override {} }; diff --git a/src/app/tests/TestReportingEngine.cpp b/src/app/tests/TestReportingEngine.cpp index 448feb27575ed9..48c13531893bdd 100644 --- a/src/app/tests/TestReportingEngine.cpp +++ b/src/app/tests/TestReportingEngine.cpp @@ -89,9 +89,11 @@ class TestReportingEngine class TestExchangeDelegate : public Messaging::ExchangeDelegate { - void OnMessageReceived(Messaging::ExchangeContext * ec, const PacketHeader & packetHeader, const PayloadHeader & payloadHeader, - System::PacketBufferHandle && payload) override - {} + CHIP_ERROR OnMessageReceived(Messaging::ExchangeContext * ec, const PacketHeader & packetHeader, + const PayloadHeader & payloadHeader, System::PacketBufferHandle && payload) override + { + return CHIP_NO_ERROR; + } void OnResponseTimeout(Messaging::ExchangeContext * ec) override {} }; diff --git a/src/app/tests/TestWriteInteraction.cpp b/src/app/tests/TestWriteInteraction.cpp index e550dae012fe6e..33967869fadc20 100644 --- a/src/app/tests/TestWriteInteraction.cpp +++ b/src/app/tests/TestWriteInteraction.cpp @@ -61,9 +61,11 @@ class TestWriteInteraction class TestExchangeDelegate : public Messaging::ExchangeDelegate { - void OnMessageReceived(Messaging::ExchangeContext * ec, const PacketHeader & packetHeader, const PayloadHeader & payloadHeader, - System::PacketBufferHandle && payload) override - {} + CHIP_ERROR OnMessageReceived(Messaging::ExchangeContext * ec, const PacketHeader & packetHeader, + const PayloadHeader & payloadHeader, System::PacketBufferHandle && payload) override + { + return CHIP_NO_ERROR; + } void OnResponseTimeout(Messaging::ExchangeContext * ec) override {} }; diff --git a/src/app/util/chip-message-send.cpp b/src/app/util/chip-message-send.cpp index ff43a94491dad5..ad6bbeb7c34eff 100644 --- a/src/app/util/chip-message-send.cpp +++ b/src/app/util/chip-message-send.cpp @@ -43,9 +43,11 @@ namespace chip { // Delete this class when Device::SendMessage() is obsoleted. class DeviceExchangeDelegate : public Messaging::ExchangeDelegate { - void OnMessageReceived(Messaging::ExchangeContext * ec, const PacketHeader & packetHeader, const PayloadHeader & payloadHeader, - System::PacketBufferHandle && payload) override - {} + CHIP_ERROR OnMessageReceived(Messaging::ExchangeContext * ec, const PacketHeader & packetHeader, + const PayloadHeader & payloadHeader, System::PacketBufferHandle && payload) override + { + return CHIP_NO_ERROR; + } void OnResponseTimeout(Messaging::ExchangeContext * ec) override {} }; diff --git a/src/channel/tests/TestChannel.cpp b/src/channel/tests/TestChannel.cpp index fe5447cd92d897..abda1c765349bc 100644 --- a/src/channel/tests/TestChannel.cpp +++ b/src/channel/tests/TestChannel.cpp @@ -71,10 +71,11 @@ TransportMgr gTransportMgr; class MockAppDelegate : public ExchangeDelegate { public: - void OnMessageReceived(ExchangeContext * ec, const PacketHeader & packetHeader, const PayloadHeader & payloadHeader, - System::PacketBufferHandle && buffer) override + CHIP_ERROR OnMessageReceived(ExchangeContext * ec, const PacketHeader & packetHeader, const PayloadHeader & payloadHeader, + System::PacketBufferHandle && buffer) override { IsOnMessageReceivedCalled = true; + return CHIP_NO_ERROR; } void OnResponseTimeout(ExchangeContext * ec) override {} diff --git a/src/controller/CHIPDevice.cpp b/src/controller/CHIPDevice.cpp index b08d9d1cb46524..e39c17366ade35 100644 --- a/src/controller/CHIPDevice.cpp +++ b/src/controller/CHIPDevice.cpp @@ -324,8 +324,8 @@ void Device::OnConnectionExpired(SecureSessionHandle session) mSecureSession = SecureSessionHandle{}; } -void Device::OnMessageReceived(Messaging::ExchangeContext * exchange, const PacketHeader & header, - const PayloadHeader & payloadHeader, System::PacketBufferHandle && msgBuf) +CHIP_ERROR Device::OnMessageReceived(Messaging::ExchangeContext * exchange, const PacketHeader & header, + const PayloadHeader & payloadHeader, System::PacketBufferHandle && msgBuf) { if (mState == ConnectionState::SecureConnected) { @@ -339,6 +339,7 @@ void Device::OnMessageReceived(Messaging::ExchangeContext * exchange, const Pack } } exchange->Close(); + return CHIP_NO_ERROR; } void Device::OnResponseTimeout(Messaging::ExchangeContext * ec) diff --git a/src/controller/CHIPDevice.h b/src/controller/CHIPDevice.h index e5f8eda3ed6471..7a97c143ab3fe5 100644 --- a/src/controller/CHIPDevice.h +++ b/src/controller/CHIPDevice.h @@ -268,8 +268,8 @@ class DLL_EXPORT Device : public Messaging::ExchangeDelegate, public SessionEsta * @param[in] payloadHeader Reference to payload header in the message * @param[in] msgBuf The message buffer */ - void OnMessageReceived(Messaging::ExchangeContext * exchange, const PacketHeader & header, const PayloadHeader & payloadHeader, - System::PacketBufferHandle && msgBuf) override; + CHIP_ERROR OnMessageReceived(Messaging::ExchangeContext * exchange, const PacketHeader & header, + const PayloadHeader & payloadHeader, System::PacketBufferHandle && msgBuf) override; /** * @brief ExchangeDelegate implementation of OnResponseTimeout. diff --git a/src/controller/CHIPDeviceController.cpp b/src/controller/CHIPDeviceController.cpp index 9993f1827f4663..bc46075bb24302 100644 --- a/src/controller/CHIPDeviceController.cpp +++ b/src/controller/CHIPDeviceController.cpp @@ -551,8 +551,8 @@ CHIP_ERROR DeviceController::GetFabricId(uint64_t & fabricId) return CHIP_NO_ERROR; } -void DeviceController::OnMessageReceived(Messaging::ExchangeContext * ec, const PacketHeader & packetHeader, - const PayloadHeader & payloadHeader, System::PacketBufferHandle && msgBuf) +CHIP_ERROR DeviceController::OnMessageReceived(Messaging::ExchangeContext * ec, const PacketHeader & packetHeader, + const PayloadHeader & payloadHeader, System::PacketBufferHandle && msgBuf) { uint16_t index; bool needClose = true; @@ -573,6 +573,7 @@ void DeviceController::OnMessageReceived(Messaging::ExchangeContext * ec, const { ec->Close(); } + return CHIP_NO_ERROR; } void DeviceController::OnResponseTimeout(Messaging::ExchangeContext * ec) diff --git a/src/controller/CHIPDeviceController.h b/src/controller/CHIPDeviceController.h index dbc38d6d5dfb02..f9c8f7d8d2746d 100644 --- a/src/controller/CHIPDeviceController.h +++ b/src/controller/CHIPDeviceController.h @@ -356,8 +356,8 @@ class DLL_EXPORT DeviceController : public Messaging::ExchangeDelegate, private: //////////// ExchangeDelegate Implementation /////////////// - void OnMessageReceived(Messaging::ExchangeContext * ec, const PacketHeader & packetHeader, const PayloadHeader & payloadHeader, - System::PacketBufferHandle && msgBuf) override; + CHIP_ERROR OnMessageReceived(Messaging::ExchangeContext * ec, const PacketHeader & packetHeader, + const PayloadHeader & payloadHeader, System::PacketBufferHandle && msgBuf) override; void OnResponseTimeout(Messaging::ExchangeContext * ec) override; //////////// ExchangeMgrDelegate Implementation /////////////// diff --git a/src/messaging/ExchangeContext.cpp b/src/messaging/ExchangeContext.cpp index 29024fc7615eef..22b55dcac13a46 100644 --- a/src/messaging/ExchangeContext.cpp +++ b/src/messaging/ExchangeContext.cpp @@ -397,7 +397,7 @@ CHIP_ERROR ExchangeContext::HandleMessage(const PacketHeader & packetHeader, con if (mDelegate != nullptr) { - mDelegate->OnMessageReceived(this, packetHeader, payloadHeader, std::move(msgBuf)); + err = mDelegate->OnMessageReceived(this, packetHeader, payloadHeader, std::move(msgBuf)); } else { diff --git a/src/messaging/ExchangeDelegate.h b/src/messaging/ExchangeDelegate.h index 7656e83c460de1..9d623baffa791a 100644 --- a/src/messaging/ExchangeDelegate.h +++ b/src/messaging/ExchangeDelegate.h @@ -56,8 +56,8 @@ class DLL_EXPORT ExchangeDelegate * @param[in] payloadHeader A reference to the PayloadHeader object. * @param[in] payload A handle to the PacketBuffer object holding the message payload. */ - virtual void OnMessageReceived(ExchangeContext * ec, const PacketHeader & packetHeader, const PayloadHeader & payloadHeader, - System::PacketBufferHandle && payload) = 0; + virtual CHIP_ERROR OnMessageReceived(ExchangeContext * ec, const PacketHeader & packetHeader, + const PayloadHeader & payloadHeader, System::PacketBufferHandle && payload) = 0; /** * @brief diff --git a/src/messaging/tests/TestExchangeMgr.cpp b/src/messaging/tests/TestExchangeMgr.cpp index c4b18d04286ee1..b3ae773a5f756a 100644 --- a/src/messaging/tests/TestExchangeMgr.cpp +++ b/src/messaging/tests/TestExchangeMgr.cpp @@ -77,11 +77,12 @@ TransportMgr gTransportMgr; class MockAppDelegate : public ExchangeDelegate { public: - void OnMessageReceived(ExchangeContext * ec, const PacketHeader & packetHeader, const PayloadHeader & payloadHeader, - System::PacketBufferHandle && buffer) override + CHIP_ERROR OnMessageReceived(ExchangeContext * ec, const PacketHeader & packetHeader, const PayloadHeader & payloadHeader, + System::PacketBufferHandle && buffer) override { IsOnMessageReceivedCalled = true; ec->Close(); + return CHIP_NO_ERROR; } void OnResponseTimeout(ExchangeContext * ec) override {} @@ -92,9 +93,11 @@ class MockAppDelegate : public ExchangeDelegate class WaitForTimeoutDelegate : public ExchangeDelegate { public: - void OnMessageReceived(ExchangeContext * ec, const PacketHeader & packetHeader, const PayloadHeader & payloadHeader, - System::PacketBufferHandle && buffer) override - {} + CHIP_ERROR OnMessageReceived(ExchangeContext * ec, const PacketHeader & packetHeader, const PayloadHeader & payloadHeader, + System::PacketBufferHandle && buffer) override + { + return CHIP_NO_ERROR; + } void OnResponseTimeout(ExchangeContext * ec) override { diff --git a/src/messaging/tests/TestReliableMessageProtocol.cpp b/src/messaging/tests/TestReliableMessageProtocol.cpp index 580f21578b6674..7f511ae0286d8e 100644 --- a/src/messaging/tests/TestReliableMessageProtocol.cpp +++ b/src/messaging/tests/TestReliableMessageProtocol.cpp @@ -91,8 +91,8 @@ OutgoingTransport gLoopback; class MockAppDelegate : public ExchangeDelegate { public: - void OnMessageReceived(ExchangeContext * ec, const PacketHeader & packetHeader, const PayloadHeader & payloadHeader, - System::PacketBufferHandle && buffer) override + CHIP_ERROR OnMessageReceived(ExchangeContext * ec, const PacketHeader & packetHeader, const PayloadHeader & payloadHeader, + System::PacketBufferHandle && buffer) override { IsOnMessageReceivedCalled = true; if (mDropAckResponse) @@ -105,6 +105,7 @@ class MockAppDelegate : public ExchangeDelegate NL_TEST_ASSERT(mTestSuite, buffer->TotalLength() == sizeof(PAYLOAD)); NL_TEST_ASSERT(mTestSuite, memcmp(buffer->Start(), PAYLOAD, buffer->TotalLength()) == 0); } + return CHIP_NO_ERROR; } void OnResponseTimeout(ExchangeContext * ec) override {} @@ -144,8 +145,8 @@ class MockSessionEstablishmentExchangeDispatch : public Messaging::ExchangeMessa class MockSessionEstablishmentDelegate : public ExchangeDelegate { public: - void OnMessageReceived(ExchangeContext * ec, const PacketHeader & packetHeader, const PayloadHeader & payloadHeader, - System::PacketBufferHandle && buffer) override + CHIP_ERROR OnMessageReceived(ExchangeContext * ec, const PacketHeader & packetHeader, const PayloadHeader & payloadHeader, + System::PacketBufferHandle && buffer) override { IsOnMessageReceivedCalled = true; ec->Close(); @@ -154,6 +155,7 @@ class MockSessionEstablishmentDelegate : public ExchangeDelegate NL_TEST_ASSERT(mTestSuite, buffer->TotalLength() == sizeof(PAYLOAD)); NL_TEST_ASSERT(mTestSuite, memcmp(buffer->Start(), PAYLOAD, buffer->TotalLength()) == 0); } + return CHIP_NO_ERROR; } void OnResponseTimeout(ExchangeContext * ec) override {} diff --git a/src/protocols/echo/Echo.h b/src/protocols/echo/Echo.h index 9a095aaf374325..70bae0ba8178ac 100644 --- a/src/protocols/echo/Echo.h +++ b/src/protocols/echo/Echo.h @@ -103,8 +103,8 @@ class DLL_EXPORT EchoClient : public Messaging::ExchangeDelegate EchoFunct OnEchoResponseReceived = nullptr; SecureSessionHandle mSecureSession; - void OnMessageReceived(Messaging::ExchangeContext * ec, const PacketHeader & packetHeader, const PayloadHeader & payloadHeader, - System::PacketBufferHandle && payload) override; + CHIP_ERROR OnMessageReceived(Messaging::ExchangeContext * ec, const PacketHeader & packetHeader, + const PayloadHeader & payloadHeader, System::PacketBufferHandle && payload) override; void OnResponseTimeout(Messaging::ExchangeContext * ec) override; }; @@ -145,8 +145,8 @@ class DLL_EXPORT EchoServer : public Messaging::ExchangeDelegate Messaging::ExchangeManager * mExchangeMgr = nullptr; EchoFunct OnEchoRequestReceived = nullptr; - void OnMessageReceived(Messaging::ExchangeContext * ec, const PacketHeader & packetHeader, const PayloadHeader & payloadHeader, - System::PacketBufferHandle && payload) override; + CHIP_ERROR OnMessageReceived(Messaging::ExchangeContext * ec, const PacketHeader & packetHeader, + const PayloadHeader & payloadHeader, System::PacketBufferHandle && payload) override; void OnResponseTimeout(Messaging::ExchangeContext * ec) override {} }; diff --git a/src/protocols/echo/EchoClient.cpp b/src/protocols/echo/EchoClient.cpp index aae35841ee9431..fe14851805303b 100644 --- a/src/protocols/echo/EchoClient.cpp +++ b/src/protocols/echo/EchoClient.cpp @@ -86,8 +86,8 @@ CHIP_ERROR EchoClient::SendEchoRequest(System::PacketBufferHandle && payload, co return err; } -void EchoClient::OnMessageReceived(Messaging::ExchangeContext * ec, const PacketHeader & packetHeader, - const PayloadHeader & payloadHeader, System::PacketBufferHandle && payload) +CHIP_ERROR EchoClient::OnMessageReceived(Messaging::ExchangeContext * ec, const PacketHeader & packetHeader, + const PayloadHeader & payloadHeader, System::PacketBufferHandle && payload) { // Assert that the exchange context matches the client's current context. // This should never fail because even if SendEchoRequest is called @@ -101,7 +101,7 @@ void EchoClient::OnMessageReceived(Messaging::ExchangeContext * ec, const Packet { ec->Close(); mExchangeCtx = nullptr; - return; + return CHIP_ERROR_INVALID_ARGUMENT; } // Remove the EC from the app state now. OnEchoResponseReceived can call @@ -116,6 +116,7 @@ void EchoClient::OnMessageReceived(Messaging::ExchangeContext * ec, const Packet { OnEchoResponseReceived(ec, std::move(payload)); } + return CHIP_NO_ERROR; } void EchoClient::OnResponseTimeout(Messaging::ExchangeContext * ec) diff --git a/src/protocols/echo/EchoServer.cpp b/src/protocols/echo/EchoServer.cpp index 5f3a6ec525dc9d..0c6be56e11ee5c 100644 --- a/src/protocols/echo/EchoServer.cpp +++ b/src/protocols/echo/EchoServer.cpp @@ -53,9 +53,10 @@ void EchoServer::Shutdown() } } -void EchoServer::OnMessageReceived(Messaging::ExchangeContext * ec, const PacketHeader & packetHeader, - const PayloadHeader & payloadHeader, System::PacketBufferHandle && payload) +CHIP_ERROR EchoServer::OnMessageReceived(Messaging::ExchangeContext * ec, const PacketHeader & packetHeader, + const PayloadHeader & payloadHeader, System::PacketBufferHandle && payload) { + CHIP_ERROR err = CHIP_NO_ERROR; System::PacketBufferHandle response; // NOTE: we already know this is an Echo Request message because we explicitly registered with the @@ -81,10 +82,11 @@ void EchoServer::OnMessageReceived(Messaging::ExchangeContext * ec, const Packet } // Send an Echo Response back to the sender. - ec->SendMessage(MsgType::EchoResponse, std::move(response)); + err = ec->SendMessage(MsgType::EchoResponse, std::move(response)); // Discard the exchange context. ec->Close(); + return err; } } // namespace Echo diff --git a/src/protocols/secure_channel/CASEServer.cpp b/src/protocols/secure_channel/CASEServer.cpp index 74c6d09e6bb770..60ab662cade625 100644 --- a/src/protocols/secure_channel/CASEServer.cpp +++ b/src/protocols/secure_channel/CASEServer.cpp @@ -86,14 +86,15 @@ CHIP_ERROR CASEServer::InitCASEHandshake(Messaging::ExchangeContext * ec) return CHIP_NO_ERROR; } -void CASEServer::OnMessageReceived(Messaging::ExchangeContext * ec, const PacketHeader & packetHeader, - const PayloadHeader & payloadHeader, System::PacketBufferHandle && payload) +CHIP_ERROR CASEServer::OnMessageReceived(Messaging::ExchangeContext * ec, const PacketHeader & packetHeader, + const PayloadHeader & payloadHeader, System::PacketBufferHandle && payload) { ChipLogProgress(Inet, "CASE Server received SigmaR1 message. Starting handshake. EC %p", ec); - ReturnOnFailure(InitCASEHandshake(ec)); + ReturnErrorOnFailure(InitCASEHandshake(ec)); mPairingSession.OnMessageReceived(ec, packetHeader, payloadHeader, std::move(payload)); + return CHIP_NO_ERROR; // TODO - Enable multiple concurrent CASE session establishment } diff --git a/src/protocols/secure_channel/CASEServer.h b/src/protocols/secure_channel/CASEServer.h index 54c1f5db2f7b61..7052cce81ce565 100644 --- a/src/protocols/secure_channel/CASEServer.h +++ b/src/protocols/secure_channel/CASEServer.h @@ -47,8 +47,8 @@ class CASEServer : public SessionEstablishmentDelegate, public Messaging::Exchan void OnSessionEstablished() override; //// ExchangeDelegate Implementation //// - void OnMessageReceived(Messaging::ExchangeContext * ec, const PacketHeader & packetHeader, const PayloadHeader & payloadHeader, - System::PacketBufferHandle && payload) override; + CHIP_ERROR OnMessageReceived(Messaging::ExchangeContext * ec, const PacketHeader & packetHeader, + const PayloadHeader & payloadHeader, System::PacketBufferHandle && payload) override; void OnResponseTimeout(Messaging::ExchangeContext * ec) override {} Messaging::ExchangeMessageDispatch * GetMessageDispatch(Messaging::ReliableMessageMgr * reliableMessageManager, SecureSessionMgr * sessionMgr) override diff --git a/src/protocols/secure_channel/CASESession.cpp b/src/protocols/secure_channel/CASESession.cpp index be3bf1664bf374..00a84342892bd9 100644 --- a/src/protocols/secure_channel/CASESession.cpp +++ b/src/protocols/secure_channel/CASESession.cpp @@ -1189,8 +1189,8 @@ CHIP_ERROR CASESession::ValidateReceivedMessage(ExchangeContext * ec, const Pack return CHIP_NO_ERROR; } -void CASESession::OnMessageReceived(ExchangeContext * ec, const PacketHeader & packetHeader, const PayloadHeader & payloadHeader, - System::PacketBufferHandle && msg) +CHIP_ERROR CASESession::OnMessageReceived(ExchangeContext * ec, const PacketHeader & packetHeader, + const PayloadHeader & payloadHeader, System::PacketBufferHandle && msg) { CHIP_ERROR err = ValidateReceivedMessage(ec, packetHeader, payloadHeader, msg); SuccessOrExit(err); @@ -1229,6 +1229,7 @@ void CASESession::OnMessageReceived(ExchangeContext * ec, const PacketHeader & p Clear(); mDelegate->OnSessionEstablishmentError(err); } + return err; } } // namespace chip diff --git a/src/protocols/secure_channel/CASESession.h b/src/protocols/secure_channel/CASESession.h index 67e9bf7d86a8b5..350c49292c711e 100644 --- a/src/protocols/secure_channel/CASESession.h +++ b/src/protocols/secure_channel/CASESession.h @@ -179,8 +179,8 @@ class DLL_EXPORT CASESession : public Messaging::ExchangeDelegate, public Pairin SessionEstablishmentExchangeDispatch & MessageDispatch() { return mMessageDispatch; } //// ExchangeDelegate Implementation //// - void OnMessageReceived(Messaging::ExchangeContext * ec, const PacketHeader & packetHeader, const PayloadHeader & payloadHeader, - System::PacketBufferHandle && payload) override; + CHIP_ERROR OnMessageReceived(Messaging::ExchangeContext * ec, const PacketHeader & packetHeader, + const PayloadHeader & payloadHeader, System::PacketBufferHandle && payload) override; void OnResponseTimeout(Messaging::ExchangeContext * ec) override; Messaging::ExchangeMessageDispatch * GetMessageDispatch(Messaging::ReliableMessageMgr * rmMgr, SecureSessionMgr * sessionMgr) override diff --git a/src/protocols/secure_channel/MessageCounterManager.cpp b/src/protocols/secure_channel/MessageCounterManager.cpp index eff8b77b770095..264801d5be5868 100644 --- a/src/protocols/secure_channel/MessageCounterManager.cpp +++ b/src/protocols/secure_channel/MessageCounterManager.cpp @@ -85,17 +85,18 @@ CHIP_ERROR MessageCounterManager::QueueReceivedMessageAndStartSync(const PacketH return CHIP_NO_ERROR; } -void MessageCounterManager::OnMessageReceived(Messaging::ExchangeContext * exchangeContext, const PacketHeader & packetHeader, - const PayloadHeader & payloadHeader, System::PacketBufferHandle && msgBuf) +CHIP_ERROR MessageCounterManager::OnMessageReceived(Messaging::ExchangeContext * exchangeContext, const PacketHeader & packetHeader, + const PayloadHeader & payloadHeader, System::PacketBufferHandle && msgBuf) { if (payloadHeader.HasMessageType(Protocols::SecureChannel::MsgType::MsgCounterSyncReq)) { - HandleMsgCounterSyncReq(exchangeContext, packetHeader, std::move(msgBuf)); + return HandleMsgCounterSyncReq(exchangeContext, packetHeader, std::move(msgBuf)); } else if (payloadHeader.HasMessageType(Protocols::SecureChannel::MsgType::MsgCounterSyncRsp)) { - HandleMsgCounterSyncResp(exchangeContext, packetHeader, std::move(msgBuf)); + return HandleMsgCounterSyncResp(exchangeContext, packetHeader, std::move(msgBuf)); } + return CHIP_NO_ERROR; } void MessageCounterManager::OnResponseTimeout(Messaging::ExchangeContext * exchangeContext) @@ -253,8 +254,8 @@ CHIP_ERROR MessageCounterManager::SendMsgCounterSyncResp(Messaging::ExchangeCont return err; } -void MessageCounterManager::HandleMsgCounterSyncReq(Messaging::ExchangeContext * exchangeContext, const PacketHeader & packetHeader, - System::PacketBufferHandle && msgBuf) +CHIP_ERROR MessageCounterManager::HandleMsgCounterSyncReq(Messaging::ExchangeContext * exchangeContext, + const PacketHeader & packetHeader, System::PacketBufferHandle && msgBuf) { CHIP_ERROR err = CHIP_NO_ERROR; @@ -277,11 +278,11 @@ void MessageCounterManager::HandleMsgCounterSyncReq(Messaging::ExchangeContext * } exchangeContext->Close(); - return; + return err; } -void MessageCounterManager::HandleMsgCounterSyncResp(Messaging::ExchangeContext * exchangeContext, - const PacketHeader & packetHeader, System::PacketBufferHandle && msgBuf) +CHIP_ERROR MessageCounterManager::HandleMsgCounterSyncResp(Messaging::ExchangeContext * exchangeContext, + const PacketHeader & packetHeader, System::PacketBufferHandle && msgBuf) { CHIP_ERROR err = CHIP_NO_ERROR; @@ -324,7 +325,7 @@ void MessageCounterManager::HandleMsgCounterSyncResp(Messaging::ExchangeContext } exchangeContext->Close(); - return; + return err; } } // namespace secure_channel diff --git a/src/protocols/secure_channel/MessageCounterManager.h b/src/protocols/secure_channel/MessageCounterManager.h index 42672564983a83..c748f1d1e1eccc 100644 --- a/src/protocols/secure_channel/MessageCounterManager.h +++ b/src/protocols/secure_channel/MessageCounterManager.h @@ -103,14 +103,14 @@ class MessageCounterManager : public Messaging::ExchangeDelegate, public Transpo CHIP_ERROR SendMsgCounterSyncResp(Messaging::ExchangeContext * exchangeContext, FixedByteSpan challenge); - void HandleMsgCounterSyncReq(Messaging::ExchangeContext * exchangeContext, const PacketHeader & packetHeader, - System::PacketBufferHandle && msgBuf); + CHIP_ERROR HandleMsgCounterSyncReq(Messaging::ExchangeContext * exchangeContext, const PacketHeader & packetHeader, + System::PacketBufferHandle && msgBuf); - void HandleMsgCounterSyncResp(Messaging::ExchangeContext * exchangeContext, const PacketHeader & packetHeader, - System::PacketBufferHandle && msgBuf); + CHIP_ERROR HandleMsgCounterSyncResp(Messaging::ExchangeContext * exchangeContext, const PacketHeader & packetHeader, + System::PacketBufferHandle && msgBuf); - void OnMessageReceived(Messaging::ExchangeContext * exchangeContext, const PacketHeader & packetHeader, - const PayloadHeader & payloadHeader, System::PacketBufferHandle && payload) override; + CHIP_ERROR OnMessageReceived(Messaging::ExchangeContext * exchangeContext, const PacketHeader & packetHeader, + const PayloadHeader & payloadHeader, System::PacketBufferHandle && payload) override; void OnResponseTimeout(Messaging::ExchangeContext * exchangeContext) override; }; diff --git a/src/protocols/secure_channel/PASESession.cpp b/src/protocols/secure_channel/PASESession.cpp index d445a6f6445d92..8676bb93277c99 100644 --- a/src/protocols/secure_channel/PASESession.cpp +++ b/src/protocols/secure_channel/PASESession.cpp @@ -783,8 +783,8 @@ CHIP_ERROR PASESession::ValidateReceivedMessage(ExchangeContext * exchange, cons return CHIP_NO_ERROR; } -void PASESession::OnMessageReceived(ExchangeContext * exchange, const PacketHeader & packetHeader, - const PayloadHeader & payloadHeader, System::PacketBufferHandle && msg) +CHIP_ERROR PASESession::OnMessageReceived(ExchangeContext * exchange, const PacketHeader & packetHeader, + const PayloadHeader & payloadHeader, System::PacketBufferHandle && msg) { CHIP_ERROR err = ValidateReceivedMessage(exchange, packetHeader, payloadHeader, std::move(msg)); SuccessOrExit(err); @@ -831,6 +831,7 @@ void PASESession::OnMessageReceived(ExchangeContext * exchange, const PacketHead ChipLogError(SecureChannel, "Failed during PASE session setup. %s", ErrorStr(err)); mDelegate->OnSessionEstablishmentError(err); } + return err; } } // namespace chip diff --git a/src/protocols/secure_channel/PASESession.h b/src/protocols/secure_channel/PASESession.h index 03f0f5736996a2..b2ec8e4f755ac2 100644 --- a/src/protocols/secure_channel/PASESession.h +++ b/src/protocols/secure_channel/PASESession.h @@ -216,8 +216,8 @@ class DLL_EXPORT PASESession : public Messaging::ExchangeDelegate, public Pairin * @param[in] payloadHeader A reference to the PayloadHeader object. * @param[in] payload A handle to the PacketBuffer object holding the message payload. */ - void OnMessageReceived(Messaging::ExchangeContext * ec, const PacketHeader & packetHeader, const PayloadHeader & payloadHeader, - System::PacketBufferHandle && payload) override; + CHIP_ERROR OnMessageReceived(Messaging::ExchangeContext * ec, const PacketHeader & packetHeader, + const PayloadHeader & payloadHeader, System::PacketBufferHandle && payload) override; /** * @brief diff --git a/src/protocols/secure_channel/tests/TestMessageCounterManager.cpp b/src/protocols/secure_channel/tests/TestMessageCounterManager.cpp index 3010fd3a8237a1..f957d22a5df964 100644 --- a/src/protocols/secure_channel/tests/TestMessageCounterManager.cpp +++ b/src/protocols/secure_channel/tests/TestMessageCounterManager.cpp @@ -73,11 +73,12 @@ const char PAYLOAD[] = "Hello!"; class MockAppDelegate : public ExchangeDelegate { public: - void OnMessageReceived(ExchangeContext * ec, const PacketHeader & packetHeader, const PayloadHeader & payloadHeader, - System::PacketBufferHandle && msgBuf) override + CHIP_ERROR OnMessageReceived(ExchangeContext * ec, const PacketHeader & packetHeader, const PayloadHeader & payloadHeader, + System::PacketBufferHandle && msgBuf) override { ++ReceiveHandlerCallCount; ec->Close(); + return CHIP_NO_ERROR; } void OnResponseTimeout(ExchangeContext * ec) override {} diff --git a/src/protocols/secure_channel/tests/TestPASESession.cpp b/src/protocols/secure_channel/tests/TestPASESession.cpp index 2176b7c328f98f..67a52954193f01 100644 --- a/src/protocols/secure_channel/tests/TestPASESession.cpp +++ b/src/protocols/secure_channel/tests/TestPASESession.cpp @@ -120,10 +120,11 @@ class TestSecurePairingDelegate : public SessionEstablishmentDelegate class MockAppDelegate : public ExchangeDelegate { public: - void OnMessageReceived(ExchangeContext * ec, const PacketHeader & packetHeader, const PayloadHeader & payloadHeader, - System::PacketBufferHandle && buffer) override + CHIP_ERROR OnMessageReceived(ExchangeContext * ec, const PacketHeader & packetHeader, const PayloadHeader & payloadHeader, + System::PacketBufferHandle && buffer) override { ec->Close(); + return CHIP_NO_ERROR; } void OnResponseTimeout(ExchangeContext * ec) override {}