From 782ce52a6ee75e46668e5cd417a7531053033922 Mon Sep 17 00:00:00 2001 From: Zhanglong Xia Date: Tue, 4 Jun 2019 22:29:18 +0800 Subject: [PATCH] [ncp] update static checking for diag output buffer size (#3891) --- src/ncp/ncp_base.hpp | 9 ++++++++- src/ncp/ncp_spi.cpp | 4 +++- src/ncp/ncp_uart.cpp | 5 +++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/ncp/ncp_base.hpp b/src/ncp/ncp_base.hpp index 105cbf724..4f332c205 100644 --- a/src/ncp/ncp_base.hpp +++ b/src/ncp/ncp_base.hpp @@ -62,6 +62,12 @@ namespace Ncp { class NcpBase { public: + enum + { + kSpinelCmdHeaderSize = 2, ///< Size of spinel command header (in bytes). + kSpinelPropIdSize = 3, ///< Size of spinel property identifier (in bytes). + }; + /** * This constructor creates and initializes an NcpBase instance. * @@ -400,7 +406,8 @@ protected: otError HandlePropertySet_SPINEL_PROP_HOST_POWER_STATE(uint8_t aHeader); #if OPENTHREAD_ENABLE_DIAG - OT_STATIC_ASSERT(OPENTHREAD_CONFIG_DIAG_OUTPUT_BUFFER_SIZE <= OPENTHREAD_CONFIG_NCP_TX_BUFFER_SIZE, + OT_STATIC_ASSERT(OPENTHREAD_CONFIG_DIAG_OUTPUT_BUFFER_SIZE <= + OPENTHREAD_CONFIG_NCP_TX_BUFFER_SIZE - kSpinelCmdHeaderSize - kSpinelPropIdSize, "diag output buffer should be smaller than NCP UART tx buffer"); otError HandlePropertySet_SPINEL_PROP_NEST_STREAM_MFG(uint8_t aHeader); diff --git a/src/ncp/ncp_spi.cpp b/src/ncp/ncp_spi.cpp index bdb0f4d43..931f7a9fa 100644 --- a/src/ncp/ncp_spi.cpp +++ b/src/ncp/ncp_spi.cpp @@ -47,7 +47,9 @@ #if OPENTHREAD_ENABLE_NCP_SPI #if OPENTHREAD_ENABLE_DIAG -OT_STATIC_ASSERT(OPENTHREAD_CONFIG_DIAG_OUTPUT_BUFFER_SIZE <= OPENTHREAD_CONFIG_NCP_SPI_BUFFER_SIZE, +OT_STATIC_ASSERT(OPENTHREAD_CONFIG_DIAG_OUTPUT_BUFFER_SIZE <= + OPENTHREAD_CONFIG_NCP_SPI_BUFFER_SIZE - ot::Ncp::NcpBase::kSpinelCmdHeaderSize - + ot::Ncp::NcpBase::kSpinelPropIdSize - ot::Ncp::SpiFrame::kHeaderSize, "diag output should be smaller than NCP SPI tx buffer"); OT_STATIC_ASSERT(OPENTHREAD_CONFIG_DIAG_CMD_LINE_BUFFER_SIZE <= OPENTHREAD_CONFIG_NCP_SPI_BUFFER_SIZE, "diag command line should be smaller than NCP SPI rx buffer"); diff --git a/src/ncp/ncp_uart.cpp b/src/ncp/ncp_uart.cpp index 41d920d97..8eb16ae50 100644 --- a/src/ncp/ncp_uart.cpp +++ b/src/ncp/ncp_uart.cpp @@ -50,6 +50,11 @@ #if OPENTHREAD_ENABLE_NCP_UART #if OPENTHREAD_ENABLE_DIAG +OT_STATIC_ASSERT(OPENTHREAD_CONFIG_DIAG_OUTPUT_BUFFER_SIZE <= OPENTHREAD_CONFIG_NCP_UART_RX_BUFFER_SIZE - + ot::Ncp::NcpBase::kSpinelCmdHeaderSize - + ot::Ncp::NcpBase::kSpinelPropIdSize, + "diag output should be smaller than NCP UART rx buffer"); + OT_STATIC_ASSERT(OPENTHREAD_CONFIG_DIAG_CMD_LINE_BUFFER_SIZE <= OPENTHREAD_CONFIG_NCP_UART_RX_BUFFER_SIZE, "diag command line should be smaller than NCP UART rx buffer"); #endif