diff --git a/src/include/Makefile.am b/src/include/Makefile.am index 17f79ca915..4091825c29 100644 --- a/src/include/Makefile.am +++ b/src/include/Makefile.am @@ -379,6 +379,7 @@ $(nl_public_WeaveSupport_source_dirstem)/FibonacciUtils.h \ $(nl_public_WeaveSupport_source_dirstem)/FlagUtils.hpp \ $(nl_public_WeaveSupport_source_dirstem)/ManagedNamespace.hpp \ $(nl_public_WeaveSupport_source_dirstem)/MathUtils.h \ +$(nl_public_WeaveSupport_source_dirstem)/ProfileUtils.h \ $(nl_public_WeaveSupport_source_dirstem)/NLDLLUtil.h \ $(nl_public_WeaveSupport_source_dirstem)/NestCerts.h \ $(nl_public_WeaveSupport_source_dirstem)/PersistedCounter.h \ diff --git a/src/lib/core/ExchangeContext.cpp b/src/lib/core/ExchangeContext.cpp index 8cb0299f1b..9e4356ac26 100644 --- a/src/lib/core/ExchangeContext.cpp +++ b/src/lib/core/ExchangeContext.cpp @@ -631,9 +631,12 @@ WEAVE_ERROR ExchangeContext::SendMessage(uint32_t profileId, uint8_t msgType, Pa exit: if (sendCalled) { - WeaveLogRetain(ExchangeManager, "Msg %s %08" PRIX32 ":%d %d %016" PRIX64 " %04" PRIX16 " %04" PRIX16 " %ld MsgId:%08" PRIX32, + if(!nl::Weave::Platform::IsProfileSilenced(static_cast(profileId))) + { + WeaveLogRetain(ExchangeManager, "Msg %s %08" PRIX32 ":%d %d %016" PRIX64 " %04" PRIX16 " %04" PRIX16 " %ld MsgId:%08" PRIX32, "sent", profileId, msgType, (int)payloadLen, msgInfo->DestNodeId, (Con ? Con->LogId() : 0), ExchangeId, (long)err, msgInfo->MessageId); + } } if (err != WEAVE_NO_ERROR && IsResponseExpected()) { diff --git a/src/lib/core/WeaveExchangeMgr.cpp b/src/lib/core/WeaveExchangeMgr.cpp index 845861bda0..209c0293fb 100644 --- a/src/lib/core/WeaveExchangeMgr.cpp +++ b/src/lib/core/WeaveExchangeMgr.cpp @@ -664,10 +664,13 @@ void WeaveExchangeManager::DispatchMessage(WeaveMessageInfo *msgInfo, PacketBuff msgCon = msgInfo->InCon; - WeaveLogRetain(ExchangeManager, "Msg %s %08" PRIX32 ":%d %d %016" PRIX64 " %04" PRIX16 " %04" PRIX16 " %ld MsgId:%08" PRIX32, - "rcvd", exchangeHeader.ProfileId, exchangeHeader.MessageType, - (int)msgBuf->DataLength(), msgInfo->SourceNodeId, msgCon->LogId(), exchangeHeader.ExchangeId, - (long)err, msgInfo->MessageId); + if(!nl::Weave::Platform::IsProfileSilenced(static_cast(exchangeHeader.ProfileId))) + { + WeaveLogRetain(ExchangeManager, "Msg %s %08" PRIX32 ":%d %d %016" PRIX64 " %04" PRIX16 " %04" PRIX16 " %ld MsgId:%08" PRIX32, + "rcvd", exchangeHeader.ProfileId, exchangeHeader.MessageType, + (int)msgBuf->DataLength(), msgInfo->SourceNodeId, msgCon->LogId(), exchangeHeader.ExchangeId, + (long)err, msgInfo->MessageId); + } #if WEAVE_CONFIG_USE_APP_GROUP_KEYS_FOR_MSG_ENC isMsgCounterSyncResp = exchangeHeader.ProfileId == nl::Weave::Profiles::kWeaveProfile_Security && diff --git a/src/lib/core/WeaveExchangeMgr.h b/src/lib/core/WeaveExchangeMgr.h index 957d6c07b5..60b94bcb26 100644 --- a/src/lib/core/WeaveExchangeMgr.h +++ b/src/lib/core/WeaveExchangeMgr.h @@ -31,6 +31,7 @@ #define WEAVE_EXCHANGE_MGR_H #include +#include #include #include diff --git a/src/lib/support/ProfileUtils.cpp b/src/lib/support/ProfileUtils.cpp new file mode 100644 index 0000000000..d13ac435c0 --- /dev/null +++ b/src/lib/support/ProfileUtils.cpp @@ -0,0 +1,90 @@ +/* + * + * Copyright (c) 2020 Google, Inc. + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file + * This file implements default platform-specific profile utility functions. + * + */ + +#ifndef __STDC_FORMAT_MACROS +#define __STDC_FORMAT_MACROS +#endif + +#include +#include + +#include "ProfileUtils.h" + +namespace nl { +namespace Weave { +namespace Platform { + +uint64_t local_common_profile; +uint64_t local_nest_profile; + +void SilenceProfilePrints(nl::Weave::Profiles::WeaveProfileId aProfileId) +{ + if((0x235A0000 & aProfileId) != 0) + { + uint64_t interm_val = (0x0000FFFF & aProfileId); + local_nest_profile |= (1 << interm_val); + } + else + { + local_common_profile |= (1 << aProfileId); + } +} +bool IsProfileSilenced(nl::Weave::Profiles::WeaveProfileId aProfileId) +{ + bool retVal = false; + if((0x235A0000 & aProfileId) != 0) + { + uint64_t interm_val = (0x0000FFFF & aProfileId); + if((local_nest_profile & (1 << interm_val)) != 0) + { + retVal = true; + } + } + else + { + if((local_common_profile & (1 << aProfileId)) != 0) + { + retVal = true; + } + } + return retVal; +} + +void UnSilenceProfile(nl::Weave::Profiles::WeaveProfileId aProfileId) +{ + if((0x235A0000 & aProfileId) != 0) + { + uint64_t interm_val = (0x0000FFFF & aProfileId); + local_nest_profile &= (~(1 << interm_val)); + } + else + { + local_common_profile &= (~(1 << aProfileId)); + } + +} + +} // namespace Platform +} // namespace Weave +} // namespace nl diff --git a/src/lib/support/ProfileUtils.h b/src/lib/support/ProfileUtils.h new file mode 100644 index 0000000000..d9aa17f8d2 --- /dev/null +++ b/src/lib/support/ProfileUtils.h @@ -0,0 +1,57 @@ +/* + * + * Copyright (c) 2020 Google, Inc. + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file + * This file defines platform-specific profile utility functions. + * + */ + +#ifndef PROFILEUTILS_H_ +#define PROFILEUTILS_H_ + +#include +#include + +namespace nl { +namespace Weave { +namespace Platform { + +/** + * @brief + * Reads in a profile type and stores it to be compared for silencing. + */ +void SilenceProfilePrints(nl::Weave::Profiles::WeaveProfileId aProfileId); + +/** + * @brief + * Returns if the profile has been silenced. + */ +bool IsProfileSilenced(nl::Weave::Profiles::WeaveProfileId aProfileId); + +/** + * @brief + * Clears a profile type ( unsilences the profile type) + */ +NL_DLL_EXPORT void UnSilenceProfile(nl::Weave::Profiles::WeaveProfileId); + +} // namespace Platform +} // namespace Weave +} // namespace nl + +#endif /* PROFILEUTILS_H_ */ diff --git a/src/lib/support/WeaveSupport.am b/src/lib/support/WeaveSupport.am index 3992730f73..96bc9c9d79 100644 --- a/src/lib/support/WeaveSupport.am +++ b/src/lib/support/WeaveSupport.am @@ -34,6 +34,7 @@ nl_WeaveSupport_sources @top_builddir@/src/lib/support/ErrorStr.cpp \ @top_builddir@/src/lib/support/FibonacciUtils.cpp \ @top_builddir@/src/lib/support/MathUtils.cpp \ + @top_builddir@/src/lib/support/ProfileUtils.cpp \ @top_builddir@/src/lib/support/NestCerts.cpp \ @top_builddir@/src/lib/support/NonProductionMarker.cpp \ @top_builddir@/src/lib/support/PersistedCounter.cpp \