diff --git a/src/core/api/message_api.cpp b/src/core/api/message_api.cpp index 8a36fd945..79f11210c 100644 --- a/src/core/api/message_api.cpp +++ b/src/core/api/message_api.cpp @@ -174,7 +174,7 @@ void otMessageGetBufferInfo(otInstance *aInstance, otBufferInfo *aBufferInfo) uint16_t messages, buffers; Instance &instance = *static_cast(aInstance); - aBufferInfo->mTotalBuffers = OPENTHREAD_CONFIG_NUM_MESSAGE_BUFFERS; + aBufferInfo->mTotalBuffers = instance.Get().GetTotalBufferCount(); aBufferInfo->mFreeBuffers = instance.Get().GetFreeBufferCount(); diff --git a/src/core/common/message.cpp b/src/core/common/message.cpp index 1f1bfe9cb..a1115baed 100644 --- a/src/core/common/message.cpp +++ b/src/core/common/message.cpp @@ -42,6 +42,11 @@ #include "net/ip6.hpp" #if OPENTHREAD_MTD || OPENTHREAD_FTD + +#if OPENTHREAD_CONFIG_MESSAGE_USE_HEAP_ENABLE && !OPENTHREAD_CONFIG_DTLS_ENABLE +#error "OPENTHREAD_CONFIG_MESSAGE_USE_HEAP_ENABLE is strongly discouraged when OPENTHREAD_CONFIG_DTLS_ENABLE is off." +#endif + namespace ot { MessagePool::MessagePool(Instance &aInstance) @@ -169,6 +174,15 @@ uint16_t MessagePool::GetFreeBufferCount(void) const return rval; } +uint16_t MessagePool::GetTotalBufferCount(void) const +{ +#if OPENTHREAD_CONFIG_MESSAGE_USE_HEAP_ENABLE + return static_cast(GetInstance().GetHeap().GetCapacity() / sizeof(Buffer)); +#else + return OPENTHREAD_CONFIG_NUM_MESSAGE_BUFFERS; +#endif +} + const Message::Settings Message::Settings::kDefault(Message::kWithLinkSecurity, Message::kPriorityNormal); Message::Settings::Settings(LinkSecurityMode aSecurityMode, Priority aPriority) diff --git a/src/core/common/message.hpp b/src/core/common/message.hpp index e98072dae..03979c067 100644 --- a/src/core/common/message.hpp +++ b/src/core/common/message.hpp @@ -1468,6 +1468,14 @@ public: */ uint16_t GetFreeBufferCount(void) const; + /** + * This method returns the total number of buffers. + * + * @returns The total number of buffers. + * + */ + uint16_t GetTotalBufferCount(void) const; + private: Buffer *NewBuffer(Message::Priority aPriority); void FreeBuffers(Buffer *aBuffer); diff --git a/src/core/config/openthread-core-config-check.h b/src/core/config/openthread-core-config-check.h index aefd661df..308bd5265 100644 --- a/src/core/config/openthread-core-config-check.h +++ b/src/core/config/openthread-core-config-check.h @@ -546,13 +546,8 @@ "(and OPENTHREAD_CONFIG_LOG_DEFINE_AS_MACRO_ONLY)" #endif -#if OPENTHREAD_CONFIG_MESSAGE_USE_HEAP_ENABLE -#if !OPENTHREAD_CONFIG_DTLS_ENABLE -#error "OPENTHREAD_CONFIG_MESSAGE_USE_HEAP_ENABLE is strongly discouraged when OPENTHREAD_CONFIG_DTLS_ENABLE is off." -#endif -#if OPENTHREAD_CONFIG_PLATFORM_MESSAGE_MANAGEMENT +#if OPENTHREAD_CONFIG_MESSAGE_USE_HEAP_ENABLE && OPENTHREAD_CONFIG_PLATFORM_MESSAGE_MANAGEMENT #error "OPENTHREAD_CONFIG_MESSAGE_USE_HEAP_ENABLE conflicts with OPENTHREAD_CONFIG_PLATFORM_MESSAGE_MANAGEMENT." #endif -#endif #endif // OPENTHREAD_CORE_CONFIG_CHECK_H_