From 395a392ccaf1e3f82428bfe5afeded0ddb5e86fc Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Tue, 6 Jun 2023 09:56:14 -0400 Subject: [PATCH] Log payloads for unsolicited reports even when we fail to dispatch them. This makes it easier to see what the other side thinks it's doing. --- src/app/InteractionModelEngine.cpp | 4 ++++ src/app/ReadClient.cpp | 11 +++++++---- src/app/ReadClient.h | 2 +- src/app/tests/TestReadInteraction.cpp | 6 +++--- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/app/InteractionModelEngine.cpp b/src/app/InteractionModelEngine.cpp index 2a5dd2f3216932..e48a4ef4330b6d 100644 --- a/src/app/InteractionModelEngine.cpp +++ b/src/app/InteractionModelEngine.cpp @@ -647,6 +647,10 @@ Status InteractionModelEngine::OnUnsolicitedReportData(Messaging::ExchangeContex ReportDataMessage::Parser report; VerifyOrReturnError(report.Init(reader) == CHIP_NO_ERROR, Status::InvalidAction); +#if CHIP_CONFIG_IM_PRETTY_PRINT + report.PrettyPrint(); +#endif + SubscriptionId subscriptionId = 0; VerifyOrReturnError(report.GetSubscriptionId(&subscriptionId) == CHIP_NO_ERROR, Status::InvalidAction); VerifyOrReturnError(report.ExitContainer() == CHIP_NO_ERROR, Status::InvalidAction); diff --git a/src/app/ReadClient.cpp b/src/app/ReadClient.cpp index acfa30a5e0701d..791371176fe879 100644 --- a/src/app/ReadClient.cpp +++ b/src/app/ReadClient.cpp @@ -433,7 +433,7 @@ CHIP_ERROR ReadClient::OnMessageReceived(Messaging::ExchangeContext * apExchange if (aPayloadHeader.HasMessageType(Protocols::InteractionModel::MsgType::ReportData)) { - err = ProcessReportData(std::move(aPayload)); + err = ProcessReportData(std::move(aPayload), /* aIsUnsolicitedReport = */ false); } else if (aPayloadHeader.HasMessageType(Protocols::InteractionModel::MsgType::SubscribeResponse)) { @@ -487,7 +487,7 @@ void ReadClient::OnUnsolicitedReportData(Messaging::ExchangeContext * apExchange // mReadPrepareParams.mSessionHolder.Grab(mExchange->GetSessionHandle()); - CHIP_ERROR err = ProcessReportData(std::move(aPayload)); + CHIP_ERROR err = ProcessReportData(std::move(aPayload), /* aIsUnsolicitedReport = */ true); if (err != CHIP_NO_ERROR) { if (err == CHIP_ERROR_INVALID_SUBSCRIPTION) @@ -504,7 +504,7 @@ void ReadClient::OnUnsolicitedReportData(Messaging::ExchangeContext * apExchange } } -CHIP_ERROR ReadClient::ProcessReportData(System::PacketBufferHandle && aPayload) +CHIP_ERROR ReadClient::ProcessReportData(System::PacketBufferHandle && aPayload, bool aIsUnsolicitedReport) { CHIP_ERROR err = CHIP_NO_ERROR; ReportDataMessage::Parser report; @@ -518,7 +518,10 @@ CHIP_ERROR ReadClient::ProcessReportData(System::PacketBufferHandle && aPayload) SuccessOrExit(err); #if CHIP_CONFIG_IM_PRETTY_PRINT - report.PrettyPrint(); + if (!aIsUnsolicitedReport) + { + report.PrettyPrint(); + } #endif err = report.GetSuppressResponse(&suppressResponse); diff --git a/src/app/ReadClient.h b/src/app/ReadClient.h index 0fa98b02b6e7dc..1dfca8697da63c 100644 --- a/src/app/ReadClient.h +++ b/src/app/ReadClient.h @@ -486,7 +486,7 @@ class ReadClient : public Messaging::ExchangeDelegate void CancelResubscribeTimer(); void MoveToState(const ClientState aTargetState); CHIP_ERROR ProcessAttributePath(AttributePathIB::Parser & aAttributePath, ConcreteDataAttributePath & aClusterInfo); - CHIP_ERROR ProcessReportData(System::PacketBufferHandle && aPayload); + CHIP_ERROR ProcessReportData(System::PacketBufferHandle && aPayload, bool aIsUnsolicitedReport); const char * GetStateStr() const; /* diff --git a/src/app/tests/TestReadInteraction.cpp b/src/app/tests/TestReadInteraction.cpp index 249e5e991f83fa..e5fcc0d6da55eb 100644 --- a/src/app/tests/TestReadInteraction.cpp +++ b/src/app/tests/TestReadInteraction.cpp @@ -468,7 +468,7 @@ void TestReadInteraction::TestReadClient(nlTestSuite * apSuite, void * apContext ctx.DrainAndServiceIO(); GenerateReportData(apSuite, apContext, buf, false /*aNeedInvalidReport*/, true /* aSuppressResponse*/); - err = readClient.ProcessReportData(std::move(buf)); + err = readClient.ProcessReportData(std::move(buf), false /* aIsUnsolicitedReport */); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); } @@ -494,7 +494,7 @@ void TestReadInteraction::TestReadUnexpectedSubscriptionId(nlTestSuite * apSuite // For read, we don't expect there is subscription id in report data. GenerateReportData(apSuite, apContext, buf, false /*aNeedInvalidReport*/, true /* aSuppressResponse*/, true /*aHasSubscriptionId*/); - err = readClient.ProcessReportData(std::move(buf)); + err = readClient.ProcessReportData(std::move(buf), false /* aIsUnsolicitedReport */); NL_TEST_ASSERT(apSuite, err == CHIP_ERROR_INVALID_ARGUMENT); } @@ -637,7 +637,7 @@ void TestReadInteraction::TestReadClientInvalidReport(nlTestSuite * apSuite, voi GenerateReportData(apSuite, apContext, buf, true /*aNeedInvalidReport*/, true /* aSuppressResponse*/); - err = readClient.ProcessReportData(std::move(buf)); + err = readClient.ProcessReportData(std::move(buf), false /* aIsUnsolicitedReport */); NL_TEST_ASSERT(apSuite, err == CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_PATH_IB); }