mirror of
https://github.com/espressif/openthread.git
synced 2026-09-09 18:50:07 +00:00
[build] move spinel into src/utils (#4558)
Move spinel from src/ncp into src/utils and remove dependency on OpenThread's core configurations.
This commit is contained in:
+5
-4
@@ -41,6 +41,7 @@ OPENTHREAD_COMMON_FLAGS := \
|
||||
-DOPENTHREAD_FTD=1 \
|
||||
-DOPENTHREAD_POSIX=1 \
|
||||
-DOPENTHREAD_POSIX_RCP_UART_ENABLE=1 \
|
||||
-DOPENTHREAD_SPINEL_CONFIG_OPENTHREAD_MESSAGE_ENABLE=1 \
|
||||
-DPACKAGE=\"openthread\" \
|
||||
-DPACKAGE_BUGREPORT=\"[email protected]\" \
|
||||
-DPACKAGE_NAME=\"OPENTHREAD\" \
|
||||
@@ -233,9 +234,6 @@ LOCAL_SRC_FILES := \
|
||||
src/core/utils/parse_cmdline.cpp \
|
||||
src/core/utils/slaac_address.cpp \
|
||||
src/ncp/hdlc.cpp \
|
||||
src/ncp/spinel.c \
|
||||
src/ncp/spinel_decoder.cpp \
|
||||
src/ncp/spinel_encoder.cpp \
|
||||
src/posix/platform/alarm.cpp \
|
||||
src/posix/platform/entropy.cpp \
|
||||
src/posix/platform/hdlc_interface.cpp \
|
||||
@@ -248,6 +246,9 @@ LOCAL_SRC_FILES := \
|
||||
src/posix/platform/system.cpp \
|
||||
src/posix/platform/uart.cpp \
|
||||
src/posix/platform/udp.cpp \
|
||||
src/spinel/spinel.c \
|
||||
src/spinel/spinel_decoder.cpp \
|
||||
src/spinel/spinel_encoder.cpp \
|
||||
third_party/mbedtls/repo/library/md.c \
|
||||
third_party/mbedtls/repo/library/md_wrap.c \
|
||||
third_party/mbedtls/repo/library/memory_buffer_alloc.c \
|
||||
@@ -389,8 +390,8 @@ LOCAL_SRC_FILES := \
|
||||
src/ncp/ncp_base_mtd.cpp \
|
||||
src/ncp/ncp_base_ftd.cpp \
|
||||
src/ncp/ncp_base_dispatcher.cpp \
|
||||
src/ncp/ncp_buffer.cpp \
|
||||
src/ncp/ncp_uart.cpp \
|
||||
src/spinel/spinel_buffer.cpp \
|
||||
$(NULL)
|
||||
|
||||
include $(BUILD_STATIC_LIBRARY)
|
||||
|
||||
@@ -162,9 +162,9 @@ static_library("lib-ot-core") {
|
||||
"src/core/utils/parse_cmdline.cpp",
|
||||
"src/core/utils/slaac_address.cpp",
|
||||
"src/ncp/hdlc.cpp",
|
||||
"src/ncp/spinel.c",
|
||||
"src/ncp/spinel_decoder.cpp",
|
||||
"src/ncp/spinel_encoder.cpp",
|
||||
"src/spinel/spinel.c",
|
||||
"src/spinel/spinel_decoder.cpp",
|
||||
"src/spinel/spinel_encoder.cpp",
|
||||
"third_party/mbedtls/repo/library/md.c",
|
||||
"third_party/mbedtls/repo/library/md_wrap.c",
|
||||
"third_party/mbedtls/repo/library/memory_buffer_alloc.c",
|
||||
|
||||
@@ -1065,6 +1065,7 @@ src/ncp/Makefile
|
||||
src/core/Makefile
|
||||
src/posix/Makefile
|
||||
src/posix/platform/Makefile
|
||||
src/spinel/Makefile
|
||||
third_party/Makefile
|
||||
third_party/jlink/Makefile
|
||||
third_party/mbedtls/Makefile
|
||||
|
||||
@@ -29,3 +29,4 @@
|
||||
add_subdirectory(cli)
|
||||
add_subdirectory(core)
|
||||
add_subdirectory(ncp)
|
||||
add_subdirectory(spinel)
|
||||
|
||||
@@ -35,12 +35,14 @@ DIST_SUBDIRS = \
|
||||
cli \
|
||||
ncp \
|
||||
posix \
|
||||
spinel \
|
||||
$(NULL)
|
||||
|
||||
# Always build (e.g. for 'make all') these subdirectories.
|
||||
|
||||
SUBDIRS = \
|
||||
core \
|
||||
spinel \
|
||||
$(NULL)
|
||||
|
||||
if OPENTHREAD_ENABLE_CLI
|
||||
@@ -62,6 +64,7 @@ PRETTY_SUBDIRS = \
|
||||
core \
|
||||
ncp \
|
||||
posix \
|
||||
spinel \
|
||||
$(NULL)
|
||||
|
||||
include $(abs_top_nlbuild_autotools_dir)/automake/post.am
|
||||
|
||||
@@ -82,12 +82,8 @@ set(COMMON_SOURCES
|
||||
ncp_base_mtd.cpp
|
||||
ncp_base_radio.cpp
|
||||
ncp_base_dispatcher.cpp
|
||||
ncp_buffer.cpp
|
||||
ncp_spi.cpp
|
||||
ncp_uart.cpp
|
||||
spinel.c
|
||||
spinel_decoder.cpp
|
||||
spinel_encoder.cpp
|
||||
)
|
||||
|
||||
target_include_directories(openthread-ncp-ftd PUBLIC ${OT_PUBLIC_INCLUDES} PRIVATE ${COMMON_INCLUDES})
|
||||
@@ -97,3 +93,7 @@ target_include_directories(openthread-rcp PUBLIC ${OT_PUBLIC_INCLUDES} PRIVATE $
|
||||
target_sources(openthread-ncp-ftd PRIVATE ${COMMON_SOURCES})
|
||||
target_sources(openthread-ncp-mtd PRIVATE ${COMMON_SOURCES})
|
||||
target_sources(openthread-rcp PRIVATE ${COMMON_SOURCES})
|
||||
|
||||
target_link_libraries(openthread-ncp-ftd openthread-spinel-ncp)
|
||||
target_link_libraries(openthread-ncp-mtd openthread-spinel-ncp)
|
||||
target_link_libraries(openthread-rcp openthread-spinel-rcp)
|
||||
|
||||
+27
-45
@@ -58,27 +58,39 @@ COMMON_CPPFLAGS = \
|
||||
$(OPENTHREAD_TARGET_DEFINES) \
|
||||
$(NULL)
|
||||
|
||||
libopenthread_ncp_mtd_a_CPPFLAGS = \
|
||||
-DOPENTHREAD_RADIO=0 \
|
||||
-DOPENTHREAD_FTD=0 \
|
||||
-DOPENTHREAD_MTD=1 \
|
||||
$(COMMON_CPPFLAGS) \
|
||||
libopenthread_ncp_mtd_a_CPPFLAGS = \
|
||||
-DOPENTHREAD_RADIO=0 \
|
||||
-DOPENTHREAD_FTD=0 \
|
||||
-DOPENTHREAD_MTD=1 \
|
||||
-DOPENTHREAD_SPINEL_CONFIG_OPENTHREAD_MESSAGE_ENABLE=1 \
|
||||
$(COMMON_CPPFLAGS) \
|
||||
$(NULL)
|
||||
|
||||
libopenthread_ncp_ftd_a_CPPFLAGS = \
|
||||
-DOPENTHREAD_RADIO=0 \
|
||||
-DOPENTHREAD_FTD=1 \
|
||||
-DOPENTHREAD_MTD=0 \
|
||||
$(COMMON_CPPFLAGS) \
|
||||
libopenthread_ncp_ftd_a_CPPFLAGS = \
|
||||
-DOPENTHREAD_RADIO=0 \
|
||||
-DOPENTHREAD_FTD=1 \
|
||||
-DOPENTHREAD_MTD=0 \
|
||||
-DOPENTHREAD_SPINEL_CONFIG_OPENTHREAD_MESSAGE_ENABLE=1 \
|
||||
$(COMMON_CPPFLAGS) \
|
||||
$(NULL)
|
||||
|
||||
libopenthread_rcp_a_CPPFLAGS = \
|
||||
-DOPENTHREAD_RADIO=1 \
|
||||
-DOPENTHREAD_FTD=0 \
|
||||
-DOPENTHREAD_MTD=0 \
|
||||
$(COMMON_CPPFLAGS) \
|
||||
libopenthread_rcp_a_CPPFLAGS = \
|
||||
-DOPENTHREAD_RADIO=1 \
|
||||
-DOPENTHREAD_FTD=0 \
|
||||
-DOPENTHREAD_MTD=0 \
|
||||
-DOPENTHREAD_SPINEL_CONFIG_OPENTHREAD_MESSAGE_ENABLE=0 \
|
||||
$(COMMON_CPPFLAGS) \
|
||||
$(NULL)
|
||||
|
||||
libopenthread_ncp_mtd_a_LIBADD = \
|
||||
$(addprefix $(top_builddir)/src/spinel/,$(filter %.o,$(shell $(AR) t $(top_builddir)/src/spinel/libopenthread-spinel-ncp.a)))
|
||||
|
||||
libopenthread_ncp_ftd_a_LIBADD = \
|
||||
$(addprefix $(top_builddir)/src/spinel/,$(filter %.o,$(shell $(AR) t $(top_builddir)/src/spinel/libopenthread-spinel-ncp.a)))
|
||||
|
||||
libopenthread_rcp_a_LIBADD = \
|
||||
$(addprefix $(top_builddir)/src/spinel/,$(filter %.o,$(shell $(AR) t $(top_builddir)/src/spinel/libopenthread-spinel-rcp.a)))
|
||||
|
||||
COMMON_SOURCES = \
|
||||
changed_props_set.cpp \
|
||||
changed_props_set.hpp \
|
||||
@@ -90,20 +102,11 @@ COMMON_SOURCES = \
|
||||
ncp_base_mtd.cpp \
|
||||
ncp_base_radio.cpp \
|
||||
ncp_base_dispatcher.cpp \
|
||||
ncp_buffer.cpp \
|
||||
ncp_buffer.hpp \
|
||||
ncp_config.h \
|
||||
ncp_spi.cpp \
|
||||
ncp_spi.hpp \
|
||||
ncp_uart.cpp \
|
||||
ncp_uart.hpp \
|
||||
spinel.c \
|
||||
spinel.h \
|
||||
spinel_decoder.cpp \
|
||||
spinel_decoder.hpp \
|
||||
spinel_encoder.cpp \
|
||||
spinel_encoder.hpp \
|
||||
spinel_platform.h \
|
||||
$(NULL)
|
||||
|
||||
if OPENTHREAD_ENABLE_NCP_VENDOR_HOOK
|
||||
@@ -139,25 +142,4 @@ libopenthread_rcp_a_SOURCES = \
|
||||
include_HEADERS = \
|
||||
$(NULL)
|
||||
|
||||
if OPENTHREAD_BUILD_TESTS
|
||||
|
||||
check_PROGRAMS = spinel-test
|
||||
spinel_test_SOURCES = spinel.c
|
||||
spinel_test_CFLAGS = \
|
||||
$(COMMON_CPPFLAGS) \
|
||||
-DSPINEL_SELF_TEST=1 \
|
||||
-D_GNU_SOURCE \
|
||||
-I$(top_srcdir)/src/core \
|
||||
-I$(top_srcdir)/include \
|
||||
$(NULL)
|
||||
|
||||
TESTS = spinel-test
|
||||
|
||||
install-headers: install-includeHEADERS
|
||||
|
||||
if OPENTHREAD_BUILD_COVERAGE
|
||||
CLEANFILES = $(wildcard *.gcda *.gcno)
|
||||
endif # OPENTHREAD_BUILD_COVERAGE
|
||||
endif # OPENTHREAD_BUILD_TESTS
|
||||
|
||||
include $(abs_top_nlbuild_autotools_dir)/automake/post.am
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
|
||||
#include <openthread/error.h>
|
||||
|
||||
#include "spinel.h"
|
||||
#include "spinel/spinel.h"
|
||||
|
||||
namespace ot {
|
||||
namespace Ncp {
|
||||
|
||||
@@ -43,8 +43,7 @@ otError NcpBase::VendorCommandHandler(uint8_t aHeader, unsigned int aCommand)
|
||||
|
||||
switch (aCommand)
|
||||
{
|
||||
|
||||
// TODO: Implement your command handlers here.
|
||||
// TODO: Implement your command handlers here.
|
||||
|
||||
default:
|
||||
error = PrepareLastStatusResponse(aHeader, SPINEL_STATUS_INVALID_COMMAND);
|
||||
@@ -53,7 +52,7 @@ otError NcpBase::VendorCommandHandler(uint8_t aHeader, unsigned int aCommand)
|
||||
return error;
|
||||
}
|
||||
|
||||
void NcpBase::VendorHandleFrameRemovedFromNcpBuffer(NcpFrameBuffer::FrameTag aFrameTag)
|
||||
void NcpBase::VendorHandleFrameRemovedFromNcpBuffer(Spinel::Buffer::FrameTag aFrameTag)
|
||||
{
|
||||
// This method is a callback which mirrors `NcpBase::HandleFrameRemovedFromNcpBuffer()`.
|
||||
// It is called when a spinel frame is sent and removed from NCP buffer.
|
||||
@@ -75,13 +74,12 @@ otError NcpBase::VendorGetPropertyHandler(spinel_prop_key_t aPropKey)
|
||||
|
||||
switch (aPropKey)
|
||||
{
|
||||
|
||||
// TODO: Implement your property get handlers here.
|
||||
//
|
||||
// Get handler should retrieve the property value and then encode and write the
|
||||
// value into the NCP buffer. If the "get" operation itself fails, handler should
|
||||
// write a `LAST_STATUS` with the error status into the NCP buffer. `OT_ERROR_NO_BUFS`
|
||||
// should be returned if NCP buffer is full and response cannot be written.
|
||||
// TODO: Implement your property get handlers here.
|
||||
//
|
||||
// Get handler should retrieve the property value and then encode and write the
|
||||
// value into the NCP buffer. If the "get" operation itself fails, handler should
|
||||
// write a `LAST_STATUS` with the error status into the NCP buffer. `OT_ERROR_NO_BUFS`
|
||||
// should be returned if NCP buffer is full and response cannot be written.
|
||||
|
||||
default:
|
||||
error = OT_ERROR_NOT_FOUND;
|
||||
@@ -97,16 +95,15 @@ otError NcpBase::VendorSetPropertyHandler(spinel_prop_key_t aPropKey)
|
||||
|
||||
switch (aPropKey)
|
||||
{
|
||||
|
||||
// TODO: Implement your property set handlers here.
|
||||
//
|
||||
// Set handler should first decode the value from the input Spinel frame and then
|
||||
// perform the corresponding set operation. The handler should not prepare the
|
||||
// spinel response and therefore should not write anything to the NCP buffer.
|
||||
// The error returned from handler (other than `OT_ERROR_NOT_FOUND`) indicates the
|
||||
// error in either parsing of the input or the error of the set operation. In case
|
||||
// of a successful "set", `NcpBase` set command handler will invoke the
|
||||
// `VendorGetPropertyHandler()` for the same property key to prepare the response.
|
||||
// TODO: Implement your property set handlers here.
|
||||
//
|
||||
// Set handler should first decode the value from the input Spinel frame and then
|
||||
// perform the corresponding set operation. The handler should not prepare the
|
||||
// spinel response and therefore should not write anything to the NCP buffer.
|
||||
// The error returned from handler (other than `OT_ERROR_NOT_FOUND`) indicates the
|
||||
// error in either parsing of the input or the error of the set operation. In case
|
||||
// of a successful "set", `NcpBase` set command handler will invoke the
|
||||
// `VendorGetPropertyHandler()` for the same property key to prepare the response.
|
||||
|
||||
default:
|
||||
error = OT_ERROR_NOT_FOUND;
|
||||
@@ -116,8 +113,8 @@ otError NcpBase::VendorSetPropertyHandler(spinel_prop_key_t aPropKey)
|
||||
return error;
|
||||
}
|
||||
|
||||
} // namespace Ncp
|
||||
} // namespace ot
|
||||
} // namespace Ncp
|
||||
} // namespace ot
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------------------
|
||||
// When OPENTHREAD_ENABLE_NCP_VENDOR_HOOK is enabled, vendor code is
|
||||
@@ -135,7 +132,8 @@ class NcpVendorUart : public ot::Ncp::NcpUart
|
||||
public:
|
||||
NcpVendorUart(ot::Instance *aInstance)
|
||||
: ot::Ncp::NcpUart(aInstance)
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
// Add public/private methods or member variables
|
||||
};
|
||||
|
||||
@@ -209,7 +209,7 @@ NcpBase::NcpBase(Instance *aInstance)
|
||||
, mThreadChangedFlags(0)
|
||||
, mChangedPropsSet()
|
||||
, mHostPowerState(SPINEL_HOST_POWER_STATE_ONLINE)
|
||||
, mHostPowerReplyFrameTag(NcpFrameBuffer::kInvalidTag)
|
||||
, mHostPowerReplyFrameTag(Spinel::Buffer::kInvalidTag)
|
||||
, mHostPowerStateHeader(0)
|
||||
#if OPENTHREAD_CONFIG_NCP_ENABLE_PEEK_POKE
|
||||
, mAllowPeekDelegate(NULL)
|
||||
@@ -318,7 +318,7 @@ void NcpBase::ResetCounters(void)
|
||||
// MARK: Serial Traffic Glue
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
NcpFrameBuffer::FrameTag NcpBase::GetLastOutboundFrameTag(void)
|
||||
Spinel::Buffer::FrameTag NcpBase::GetLastOutboundFrameTag(void)
|
||||
{
|
||||
return mTxFrameBuffer.InFrameGetLastTag();
|
||||
}
|
||||
@@ -387,9 +387,9 @@ exit:
|
||||
}
|
||||
|
||||
void NcpBase::HandleFrameRemovedFromNcpBuffer(void * aContext,
|
||||
NcpFrameBuffer::FrameTag aFrameTag,
|
||||
NcpFrameBuffer::Priority aPriority,
|
||||
NcpFrameBuffer * aNcpBuffer)
|
||||
Spinel::Buffer::FrameTag aFrameTag,
|
||||
Spinel::Buffer::Priority aPriority,
|
||||
Spinel::Buffer * aNcpBuffer)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aNcpBuffer);
|
||||
OT_UNUSED_VARIABLE(aPriority);
|
||||
@@ -397,7 +397,7 @@ void NcpBase::HandleFrameRemovedFromNcpBuffer(void * aContext,
|
||||
static_cast<NcpBase *>(aContext)->HandleFrameRemovedFromNcpBuffer(aFrameTag);
|
||||
}
|
||||
|
||||
void NcpBase::HandleFrameRemovedFromNcpBuffer(NcpFrameBuffer::FrameTag aFrameTag)
|
||||
void NcpBase::HandleFrameRemovedFromNcpBuffer(Spinel::Buffer::FrameTag aFrameTag)
|
||||
{
|
||||
if (mHostPowerStateInProgress)
|
||||
{
|
||||
@@ -2040,7 +2040,7 @@ otError NcpBase::HandlePropertySet_SPINEL_PROP_HOST_POWER_STATE(uint8_t aHeader)
|
||||
}
|
||||
else
|
||||
{
|
||||
mHostPowerReplyFrameTag = NcpFrameBuffer::kInvalidTag;
|
||||
mHostPowerReplyFrameTag = Spinel::Buffer::kInvalidTag;
|
||||
}
|
||||
|
||||
mHostPowerStateInProgress = true;
|
||||
|
||||
+14
-15
@@ -51,13 +51,12 @@
|
||||
#include "changed_props_set.hpp"
|
||||
#include "common/instance.hpp"
|
||||
#include "common/tasklet.hpp"
|
||||
#include "ncp/ncp_buffer.hpp"
|
||||
#include "ncp/spinel_decoder.hpp"
|
||||
#include "ncp/spinel_encoder.hpp"
|
||||
#include "spinel/spinel.h"
|
||||
#include "spinel/spinel_buffer.hpp"
|
||||
#include "spinel/spinel_decoder.hpp"
|
||||
#include "spinel/spinel_encoder.hpp"
|
||||
#include "utils/static_assert.hpp"
|
||||
|
||||
#include "spinel.h"
|
||||
|
||||
namespace ot {
|
||||
namespace Ncp {
|
||||
|
||||
@@ -208,7 +207,7 @@ protected:
|
||||
NcpBase::PropertyHandler mHandler;
|
||||
};
|
||||
|
||||
NcpFrameBuffer::FrameTag GetLastOutboundFrameTag(void);
|
||||
Spinel::Buffer::FrameTag GetLastOutboundFrameTag(void);
|
||||
|
||||
otError HandleCommand(uint8_t aHeader);
|
||||
|
||||
@@ -259,10 +258,10 @@ protected:
|
||||
void UpdateChangedProps(void);
|
||||
|
||||
static void HandleFrameRemovedFromNcpBuffer(void * aContext,
|
||||
NcpFrameBuffer::FrameTag aFrameTag,
|
||||
NcpFrameBuffer::Priority aPriority,
|
||||
NcpFrameBuffer * aNcpBuffer);
|
||||
void HandleFrameRemovedFromNcpBuffer(NcpFrameBuffer::FrameTag aFrameTag);
|
||||
Spinel::Buffer::FrameTag aFrameTag,
|
||||
Spinel::Buffer::Priority aPriority,
|
||||
Spinel::Buffer * aNcpBuffer);
|
||||
void HandleFrameRemovedFromNcpBuffer(Spinel::Buffer::FrameTag aFrameTag);
|
||||
|
||||
otError EncodeChannelMask(uint32_t aChannelMask);
|
||||
otError DecodeChannelMask(uint32_t &aChannelMask);
|
||||
@@ -472,7 +471,7 @@ protected:
|
||||
* @param[in] aFrameTag The tag of the frame removed from NCP buffer.
|
||||
*
|
||||
*/
|
||||
void VendorHandleFrameRemovedFromNcpBuffer(NcpFrameBuffer::FrameTag aFrameTag);
|
||||
void VendorHandleFrameRemovedFromNcpBuffer(Spinel::Buffer::FrameTag aFrameTag);
|
||||
|
||||
/**
|
||||
* This method defines a vendor "get property handler" hook to process vendor spinel properties.
|
||||
@@ -520,9 +519,9 @@ protected:
|
||||
bool aDeviceType,
|
||||
bool aNetworkData);
|
||||
Instance * mInstance;
|
||||
NcpFrameBuffer mTxFrameBuffer;
|
||||
SpinelEncoder mEncoder;
|
||||
SpinelDecoder mDecoder;
|
||||
Spinel::Buffer mTxFrameBuffer;
|
||||
Spinel::Encoder mEncoder;
|
||||
Spinel::Decoder mDecoder;
|
||||
bool mHostPowerStateInProgress;
|
||||
|
||||
enum
|
||||
@@ -544,7 +543,7 @@ protected:
|
||||
ChangedPropsSet mChangedPropsSet;
|
||||
|
||||
spinel_host_power_state_t mHostPowerState;
|
||||
NcpFrameBuffer::FrameTag mHostPowerReplyFrameTag;
|
||||
Spinel::Buffer::FrameTag mHostPowerReplyFrameTag;
|
||||
uint8_t mHostPowerStateHeader;
|
||||
|
||||
#if OPENTHREAD_CONFIG_NCP_ENABLE_PEEK_POKE
|
||||
|
||||
+4
-4
@@ -241,11 +241,11 @@ void NcpSpi::SpiTransactionProcess(void)
|
||||
}
|
||||
|
||||
void NcpSpi::HandleFrameAddedToTxBuffer(void * aContext,
|
||||
NcpFrameBuffer::FrameTag aTag,
|
||||
NcpFrameBuffer::Priority aPriority,
|
||||
NcpFrameBuffer * aNcpFrameBuffer)
|
||||
Spinel::Buffer::FrameTag aTag,
|
||||
Spinel::Buffer::Priority aPriority,
|
||||
Spinel::Buffer * aBuffer)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aNcpFrameBuffer);
|
||||
OT_UNUSED_VARIABLE(aBuffer);
|
||||
OT_UNUSED_VARIABLE(aTag);
|
||||
OT_UNUSED_VARIABLE(aPriority);
|
||||
|
||||
|
||||
+3
-3
@@ -294,9 +294,9 @@ private:
|
||||
void SpiTransactionProcess(void);
|
||||
|
||||
static void HandleFrameAddedToTxBuffer(void * aContext,
|
||||
NcpFrameBuffer::FrameTag aFrameTag,
|
||||
NcpFrameBuffer::Priority aPriority,
|
||||
NcpFrameBuffer * aNcpFrameBuffer);
|
||||
Spinel::Buffer::FrameTag aFrameTag,
|
||||
Spinel::Buffer::Priority aPriority,
|
||||
Spinel::Buffer * aBuffer);
|
||||
|
||||
static void PrepareTxFrame(Tasklet &aTasklet);
|
||||
void PrepareTxFrame(void);
|
||||
|
||||
+13
-13
@@ -101,11 +101,11 @@ NcpUart::NcpUart(Instance *aInstance)
|
||||
}
|
||||
|
||||
void NcpUart::HandleFrameAddedToNcpBuffer(void * aContext,
|
||||
NcpFrameBuffer::FrameTag aTag,
|
||||
NcpFrameBuffer::Priority aPriority,
|
||||
NcpFrameBuffer * aNcpFrameBuffer)
|
||||
Spinel::Buffer::FrameTag aTag,
|
||||
Spinel::Buffer::Priority aPriority,
|
||||
Spinel::Buffer * aBuffer)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aNcpFrameBuffer);
|
||||
OT_UNUSED_VARIABLE(aBuffer);
|
||||
OT_UNUSED_VARIABLE(aTag);
|
||||
OT_UNUSED_VARIABLE(aPriority);
|
||||
|
||||
@@ -134,9 +134,9 @@ void NcpUart::EncodeAndSendToUart(void)
|
||||
uint16_t len;
|
||||
bool prevHostPowerState;
|
||||
#if OPENTHREAD_ENABLE_NCP_SPINEL_ENCRYPTER
|
||||
NcpFrameBufferEncrypterReader &txFrameBuffer = mTxFrameBufferEncrypterReader;
|
||||
Spinel::BufferEncrypterReader &txFrameBuffer = mTxFrameBufferEncrypterReader;
|
||||
#else
|
||||
NcpFrameBuffer &txFrameBuffer = mTxFrameBuffer;
|
||||
Spinel::Buffer &txFrameBuffer = mTxFrameBuffer;
|
||||
#endif // OPENTHREAD_ENABLE_NCP_SPINEL_ENCRYPTER
|
||||
|
||||
while (!txFrameBuffer.IsEmpty() || (mState == kFinalizingFrame))
|
||||
@@ -310,19 +310,19 @@ void NcpUart::HandleError(otError aError, uint8_t *aBuf, uint16_t aBufLength)
|
||||
|
||||
#if OPENTHREAD_ENABLE_NCP_SPINEL_ENCRYPTER
|
||||
|
||||
NcpUart::NcpFrameBufferEncrypterReader::NcpFrameBufferEncrypterReader(NcpFrameBuffer &aTxFrameBuffer)
|
||||
NcpUart::Spinel::BufferEncrypterReader::SpinelBufferEncrypterReader(Spinel::Buffer &aTxFrameBuffer)
|
||||
: mTxFrameBuffer(aTxFrameBuffer)
|
||||
, mDataBufferReadIndex(0)
|
||||
, mOutputDataLength(0)
|
||||
{
|
||||
}
|
||||
|
||||
bool NcpUart::NcpFrameBufferEncrypterReader::IsEmpty(void) const
|
||||
bool NcpUart::Spinel::BufferEncrypterReader::IsEmpty(void) const
|
||||
{
|
||||
return mTxFrameBuffer.IsEmpty() && !mOutputDataLength;
|
||||
}
|
||||
|
||||
otError NcpUart::NcpFrameBufferEncrypterReader::OutFrameBegin(void)
|
||||
otError NcpUart::Spinel::BufferEncrypterReader::OutFrameBegin(void)
|
||||
{
|
||||
otError status = OT_ERROR_FAILED;
|
||||
|
||||
@@ -352,22 +352,22 @@ otError NcpUart::NcpFrameBufferEncrypterReader::OutFrameBegin(void)
|
||||
return status;
|
||||
}
|
||||
|
||||
bool NcpUart::NcpFrameBufferEncrypterReader::OutFrameHasEnded(void)
|
||||
bool NcpUart::Spinel::BufferEncrypterReader::OutFrameHasEnded(void)
|
||||
{
|
||||
return (mDataBufferReadIndex >= mOutputDataLength);
|
||||
}
|
||||
|
||||
uint8_t NcpUart::NcpFrameBufferEncrypterReader::OutFrameReadByte(void)
|
||||
uint8_t NcpUart::Spinel::BufferEncrypterReader::OutFrameReadByte(void)
|
||||
{
|
||||
return mDataBuffer[mDataBufferReadIndex++];
|
||||
}
|
||||
|
||||
otError NcpUart::NcpFrameBufferEncrypterReader::OutFrameRemove(void)
|
||||
otError NcpUart::Spinel::BufferEncrypterReader::OutFrameRemove(void)
|
||||
{
|
||||
return mTxFrameBuffer.OutFrameRemove();
|
||||
}
|
||||
|
||||
void NcpUart::NcpFrameBufferEncrypterReader::Reset(void)
|
||||
void NcpUart::Spinel::BufferEncrypterReader::Reset(void)
|
||||
{
|
||||
mOutputDataLength = 0;
|
||||
mDataBufferReadIndex = 0;
|
||||
|
||||
@@ -87,17 +87,17 @@ private:
|
||||
|
||||
#if OPENTHREAD_ENABLE_NCP_SPINEL_ENCRYPTER
|
||||
/**
|
||||
* Wraps NcpFrameBuffer allowing to read data through spinel encrypter.
|
||||
* Wraps Spinel::Buffer allowing to read data through spinel encrypter.
|
||||
* Creates additional buffers to allow transforming of the whole spinel frames.
|
||||
*/
|
||||
class NcpFrameBufferEncrypterReader
|
||||
class Spinel::BufferEncrypterReader
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* C-tor.
|
||||
* Takes a reference to NcpFrameBuffer in order to read spinel frames.
|
||||
* Takes a reference to Spinel::Buffer in order to read spinel frames.
|
||||
*/
|
||||
explicit NcpFrameBufferEncrypterReader(NcpFrameBuffer &aTxFrameBuffer);
|
||||
explicit Spinel::BufferEncrypterReader(Spinel::Buffer &aTxFrameBuffer);
|
||||
bool IsEmpty(void) const;
|
||||
otError OutFrameBegin(void);
|
||||
bool OutFrameHasEnded(void);
|
||||
@@ -107,7 +107,7 @@ private:
|
||||
private:
|
||||
void Reset(void);
|
||||
|
||||
NcpFrameBuffer &mTxFrameBuffer;
|
||||
Spinel::Buffer &mTxFrameBuffer;
|
||||
uint8_t mDataBuffer[kRxBufferSize];
|
||||
size_t mDataBufferReadIndex;
|
||||
size_t mOutputDataLength;
|
||||
@@ -123,9 +123,9 @@ private:
|
||||
static void EncodeAndSendToUart(Tasklet &aTasklet);
|
||||
static void HandleFrame(void *aContext, otError aError);
|
||||
static void HandleFrameAddedToNcpBuffer(void * aContext,
|
||||
NcpFrameBuffer::FrameTag aTag,
|
||||
NcpFrameBuffer::Priority aPriority,
|
||||
NcpFrameBuffer * aNcpFrameBuffer);
|
||||
Spinel::Buffer::FrameTag aTag,
|
||||
Spinel::Buffer::Priority aPriority,
|
||||
Spinel::Buffer * aBuffer);
|
||||
|
||||
Hdlc::Encoder mFrameEncoder;
|
||||
Hdlc::Decoder mFrameDecoder;
|
||||
@@ -137,7 +137,7 @@ private:
|
||||
Tasklet mUartSendTask;
|
||||
|
||||
#if OPENTHREAD_ENABLE_NCP_SPINEL_ENCRYPTER
|
||||
NcpFrameBufferEncrypterReader mTxFrameBufferEncrypterReader;
|
||||
Spinel::BufferEncrypterReader mTxFrameBufferEncrypterReader;
|
||||
#endif // OPENTHREAD_ENABLE_NCP_SPINEL_ENCRYPTER
|
||||
};
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
#include "radio_spinel.hpp"
|
||||
|
||||
#include "platform-posix.h"
|
||||
#include "ncp/spinel_decoder.hpp"
|
||||
#include "spinel/spinel_decoder.hpp"
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
@@ -66,6 +66,8 @@
|
||||
#define TX_WAIT_US (5 * US_PER_S)
|
||||
#endif
|
||||
|
||||
using ot::Spinel::Decoder;
|
||||
|
||||
static ot::PosixApp::RadioSpinel sRadioSpinel;
|
||||
|
||||
namespace ot {
|
||||
@@ -498,7 +500,7 @@ otError RadioSpinel::ThreadDatasetHandler(const uint8_t *aBuffer, uint16_t aLeng
|
||||
otError error = OT_ERROR_NONE;
|
||||
otOperationalDataset opDataset;
|
||||
bool isActive = ((mWaitingKey == SPINEL_PROP_THREAD_ACTIVE_DATASET) ? true : false);
|
||||
Ncp::SpinelDecoder decoder;
|
||||
Spinel::Decoder decoder;
|
||||
MeshCoP::Dataset dataset(isActive ? MeshCoP::Tlv::kActiveTimestamp : MeshCoP::Tlv::kPendingTimestamp);
|
||||
|
||||
memset(&opDataset, 0, sizeof(otOperationalDataset));
|
||||
|
||||
@@ -52,7 +52,7 @@
|
||||
|
||||
#include "spinel_interface.hpp"
|
||||
#include "ncp/ncp_config.h"
|
||||
#include "ncp/spinel.h"
|
||||
#include "spinel/spinel.h"
|
||||
|
||||
namespace ot {
|
||||
namespace PosixApp {
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
#
|
||||
# Copyright (c) 2020, The OpenThread Authors.
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are met:
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in the
|
||||
# documentation and/or other materials provided with the distribution.
|
||||
# 3. Neither the name of the copyright holder nor the
|
||||
# names of its contributors may be used to endorse or promote products
|
||||
# derived from this software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
|
||||
add_library(openthread-spinel-ncp)
|
||||
add_library(openthread-spinel-rcp)
|
||||
|
||||
target_compile_definitions(openthread-spinel-ncp PRIVATE
|
||||
${OT_PRIVATE_DEFINES}
|
||||
OPENTHREAD_FTD=1
|
||||
OPENTHREAD_CONFIG_NCP_UART_ENABLE=1
|
||||
PUBLIC OPENTHREAD_SPINEL_CONFIG_OPENTHREAD_MESSAGE_ENABLE=1
|
||||
)
|
||||
|
||||
target_compile_definitions(openthread-spinel-rcp PRIVATE
|
||||
${OT_PRIVATE_DEFINES}
|
||||
OPENTHREAD_RADIO=1
|
||||
OPENTHREAD_CONFIG_NCP_UART_ENABLE=1
|
||||
PUBLIC OPENTHREAD_SPINEL_CONFIG_OPENTHREAD_MESSAGE_ENABLE=0
|
||||
)
|
||||
|
||||
target_compile_options(openthread-spinel-ncp PRIVATE
|
||||
${OT_CFLAGS}
|
||||
)
|
||||
|
||||
target_compile_options(openthread-spinel-rcp PRIVATE
|
||||
${OT_CFLAGS}
|
||||
)
|
||||
|
||||
set(COMMON_INCLUDES
|
||||
${OT_PRIVATE_INCLUDES}
|
||||
${PROJECT_SOURCE_DIR}/src
|
||||
${PROJECT_SOURCE_DIR}/src/core
|
||||
)
|
||||
|
||||
set(COMMON_SOURCES
|
||||
spinel.c
|
||||
spinel_buffer.cpp
|
||||
spinel_decoder.cpp
|
||||
spinel_encoder.cpp
|
||||
)
|
||||
|
||||
target_include_directories(openthread-spinel-ncp PUBLIC ${OT_PUBLIC_INCLUDES} PRIVATE ${COMMON_INCLUDES})
|
||||
target_include_directories(openthread-spinel-rcp PUBLIC ${OT_PUBLIC_INCLUDES} PRIVATE ${COMMON_INCLUDES})
|
||||
|
||||
target_sources(openthread-spinel-ncp PRIVATE ${COMMON_SOURCES})
|
||||
target_sources(openthread-spinel-rcp PRIVATE ${COMMON_SOURCES})
|
||||
@@ -0,0 +1,114 @@
|
||||
#
|
||||
# Copyright (c) 2020, The OpenThread Authors.
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are met:
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in the
|
||||
# documentation and/or other materials provided with the distribution.
|
||||
# 3. Neither the name of the copyright holder nor the
|
||||
# names of its contributors may be used to endorse or promote products
|
||||
# derived from this software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
|
||||
include $(abs_top_nlbuild_autotools_dir)/automake/pre.am
|
||||
|
||||
noinst_LIBRARIES =
|
||||
|
||||
if OPENTHREAD_ENABLE_FTD
|
||||
noinst_LIBRARIES += libopenthread-spinel-ncp.a
|
||||
endif
|
||||
|
||||
if OPENTHREAD_ENABLE_MTD
|
||||
noinst_LIBRARIES += libopenthread-spinel-ncp.a
|
||||
endif
|
||||
|
||||
if OPENTHREAD_ENABLE_RADIO_ONLY
|
||||
noinst_LIBRARIES += libopenthread-spinel-rcp.a
|
||||
endif
|
||||
|
||||
COMMON_CPPFLAGS = \
|
||||
-I$(top_srcdir)/include \
|
||||
-I$(top_srcdir)/src \
|
||||
-I$(top_srcdir)/src/core \
|
||||
-I$(top_srcdir)/third_party \
|
||||
-D_GNU_SOURCE \
|
||||
-DSPINEL_PLATFORM_HEADER=\"spinel_platform.h\" \
|
||||
$(OPENTHREAD_TARGET_DEFINES) \
|
||||
$(NULL)
|
||||
|
||||
COMMON_SOURCES = \
|
||||
spinel.c \
|
||||
spinel_buffer.cpp \
|
||||
spinel_decoder.cpp \
|
||||
spinel_encoder.cpp \
|
||||
$(NULL)
|
||||
|
||||
|
||||
include_HEADERS = \
|
||||
spinel.h \
|
||||
$(NULL)
|
||||
|
||||
noinst_HEADERS = \
|
||||
spinel_buffer.hpp \
|
||||
spinel_decoder.hpp \
|
||||
spinel_encoder.hpp \
|
||||
spinel_platform.h \
|
||||
openthread-spinel-config.h \
|
||||
$(NULL)
|
||||
|
||||
libopenthread_spinel_ncp_a_CPPFLAGS = \
|
||||
-DOPENTHREAD_SPINEL_CONFIG_OPENTHREAD_MESSAGE_ENABLE=1 \
|
||||
$(COMMON_CPPFLAGS) \
|
||||
$(NULL)
|
||||
|
||||
libopenthread_spinel_ncp_a_SOURCES = \
|
||||
$(COMMON_SOURCES) \
|
||||
$(NULL)
|
||||
|
||||
libopenthread_spinel_rcp_a_CPPFLAGS = \
|
||||
-DOPENTHREAD_SPINEL_CONFIG_OPENTHREAD_MESSAGE_ENABLE=0 \
|
||||
$(COMMON_CPPFLAGS) \
|
||||
$(NULL)
|
||||
|
||||
libopenthread_spinel_rcp_a_SOURCES = \
|
||||
$(COMMON_SOURCES) \
|
||||
$(NULL)
|
||||
|
||||
if OPENTHREAD_BUILD_TESTS
|
||||
|
||||
check_PROGRAMS = spinel-test
|
||||
spinel_test_SOURCES = spinel.c
|
||||
spinel_test_CFLAGS = \
|
||||
$(COMMON_CPPFLAGS) \
|
||||
-DSPINEL_SELF_TEST=1 \
|
||||
-D_GNU_SOURCE \
|
||||
-I$(top_srcdir)/src/core \
|
||||
-I$(top_srcdir)/include \
|
||||
$(NULL)
|
||||
|
||||
TESTS = spinel-test
|
||||
|
||||
install-headers: install-includeHEADERS
|
||||
|
||||
if OPENTHREAD_BUILD_COVERAGE
|
||||
CLEANFILES = $(wildcard *.gcda *.gcno)
|
||||
endif # OPENTHREAD_BUILD_COVERAGE
|
||||
endif # OPENTHREAD_BUILD_TESTS
|
||||
|
||||
include $(abs_top_nlbuild_autotools_dir)/automake/post.am
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2020, The OpenThread Authors.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* This file includes compile-time configuration constants for OpenThread.
|
||||
*/
|
||||
|
||||
#ifndef OPENTHREAD_SPINEL_CONFIG_H_
|
||||
#define OPENTHREAD_SPINEL_CONFIG_H_
|
||||
|
||||
/**
|
||||
* @def OPENTHREAD_SPINEL_CONFIG_OPENTHREAD_MESSAGE_ENABLE
|
||||
*
|
||||
* Define 1 to enable feeding an OpenThread message to encoder/decoder.
|
||||
*
|
||||
*/
|
||||
#ifndef OPENTHREAD_SPINEL_CONFIG_OPENTHREAD_MESSAGE_ENABLE
|
||||
#define OPENTHREAD_SPINEL_CONFIG_OPENTHREAD_MESSAGE_ENABLE 0
|
||||
#endif
|
||||
|
||||
#endif // OPENTHREAD_SPINEL_CONFIG_H_
|
||||
@@ -30,22 +30,22 @@
|
||||
* This file implements NCP frame buffer class.
|
||||
*/
|
||||
|
||||
#include "ncp_buffer.hpp"
|
||||
#include "spinel_buffer.hpp"
|
||||
|
||||
#include "common/code_utils.hpp"
|
||||
#include "common/debug.hpp"
|
||||
|
||||
namespace ot {
|
||||
namespace Ncp {
|
||||
namespace Spinel {
|
||||
|
||||
const NcpFrameBuffer::FrameTag NcpFrameBuffer::kInvalidTag = NULL;
|
||||
const Buffer::FrameTag Buffer::kInvalidTag = NULL;
|
||||
|
||||
NcpFrameBuffer::NcpFrameBuffer(uint8_t *aBuffer, uint16_t aBufferLength)
|
||||
Buffer::Buffer(uint8_t *aBuffer, uint16_t aBufferLength)
|
||||
: mBuffer(aBuffer)
|
||||
, mBufferEnd(aBuffer + aBufferLength)
|
||||
, mBufferLength(aBufferLength)
|
||||
{
|
||||
#if OPENTHREAD_MTD || OPENTHREAD_FTD
|
||||
#if OPENTHREAD_SPINEL_CONFIG_OPENTHREAD_MESSAGE_ENABLE
|
||||
for (uint8_t priority = 0; priority < kNumPrios; priority++)
|
||||
{
|
||||
otMessageQueueInit(&mMessageQueue[priority]);
|
||||
@@ -59,9 +59,9 @@ NcpFrameBuffer::NcpFrameBuffer(uint8_t *aBuffer, uint16_t aBufferLength)
|
||||
Clear();
|
||||
}
|
||||
|
||||
void NcpFrameBuffer::Clear(void)
|
||||
void Buffer::Clear(void)
|
||||
{
|
||||
#if OPENTHREAD_MTD || OPENTHREAD_FTD
|
||||
#if OPENTHREAD_SPINEL_CONFIG_OPENTHREAD_MESSAGE_ENABLE
|
||||
otMessage *message;
|
||||
#endif
|
||||
|
||||
@@ -84,7 +84,7 @@ void NcpFrameBuffer::Clear(void)
|
||||
mReadSegmentTail = mBuffer;
|
||||
mReadPointer = mBuffer;
|
||||
|
||||
#if OPENTHREAD_MTD || OPENTHREAD_FTD
|
||||
#if OPENTHREAD_SPINEL_CONFIG_OPENTHREAD_MESSAGE_ENABLE
|
||||
mReadMessage = NULL;
|
||||
mReadMessageOffset = 0;
|
||||
mReadMessageTail = mMessageBuffer;
|
||||
@@ -96,7 +96,7 @@ void NcpFrameBuffer::Clear(void)
|
||||
otMessageQueueDequeue(&mWriteFrameMessageQueue, message);
|
||||
|
||||
// Note that messages associated with current (unfinished) input frame
|
||||
// are not yet owned by the `NcpFrameBuffer` and therefore should not
|
||||
// are not yet owned by the `Buffer` and therefore should not
|
||||
// be freed.
|
||||
}
|
||||
|
||||
@@ -111,13 +111,13 @@ void NcpFrameBuffer::Clear(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
void NcpFrameBuffer::SetFrameAddedCallback(BufferCallback aFrameAddedCallback, void *aFrameAddedContext)
|
||||
void Buffer::SetFrameAddedCallback(BufferCallback aFrameAddedCallback, void *aFrameAddedContext)
|
||||
{
|
||||
mFrameAddedCallback = aFrameAddedCallback;
|
||||
mFrameAddedContext = aFrameAddedContext;
|
||||
}
|
||||
|
||||
void NcpFrameBuffer::SetFrameRemovedCallback(BufferCallback aFrameRemovedCallback, void *aFrameRemovedContext)
|
||||
void Buffer::SetFrameRemovedCallback(BufferCallback aFrameRemovedCallback, void *aFrameRemovedContext)
|
||||
{
|
||||
mFrameRemovedCallback = aFrameRemovedCallback;
|
||||
mFrameRemovedContext = aFrameRemovedContext;
|
||||
@@ -125,7 +125,7 @@ void NcpFrameBuffer::SetFrameRemovedCallback(BufferCallback aFrameRemovedCallbac
|
||||
|
||||
// Returns an updated buffer pointer by moving forward/backward (based on `aDirection`) from `aBufPtr` by a given
|
||||
// offset. The resulting buffer pointer is ensured to stay within the `mBuffer` boundaries.
|
||||
uint8_t *NcpFrameBuffer::GetUpdatedBufPtr(uint8_t *aBufPtr, uint16_t aOffset, Direction aDirection) const
|
||||
uint8_t *Buffer::GetUpdatedBufPtr(uint8_t *aBufPtr, uint16_t aOffset, Direction aDirection) const
|
||||
{
|
||||
uint8_t *ptr = aBufPtr;
|
||||
|
||||
@@ -160,7 +160,7 @@ uint8_t *NcpFrameBuffer::GetUpdatedBufPtr(uint8_t *aBufPtr, uint16_t aOffset, Di
|
||||
}
|
||||
|
||||
// Gets the distance between two buffer pointers (adjusts for the wrap-around) given a direction (forward or backward).
|
||||
uint16_t NcpFrameBuffer::GetDistance(const uint8_t *aStartPtr, const uint8_t *aEndPtr, Direction aDirection) const
|
||||
uint16_t Buffer::GetDistance(const uint8_t *aStartPtr, const uint8_t *aEndPtr, Direction aDirection) const
|
||||
{
|
||||
size_t distance = 0;
|
||||
|
||||
@@ -203,14 +203,14 @@ uint16_t NcpFrameBuffer::GetDistance(const uint8_t *aStartPtr, const uint8_t *aE
|
||||
}
|
||||
|
||||
// Writes a uint16 value at the given buffer pointer (big-endian style).
|
||||
void NcpFrameBuffer::WriteUint16At(uint8_t *aBufPtr, uint16_t aValue, Direction aDirection)
|
||||
void Buffer::WriteUint16At(uint8_t *aBufPtr, uint16_t aValue, Direction aDirection)
|
||||
{
|
||||
*aBufPtr = (aValue >> 8);
|
||||
*GetUpdatedBufPtr(aBufPtr, 1, aDirection) = (aValue & 0xff);
|
||||
}
|
||||
|
||||
// Reads a uint16 value at the given buffer pointer (big-endian style).
|
||||
uint16_t NcpFrameBuffer::ReadUint16At(uint8_t *aBufPtr, Direction aDirection)
|
||||
uint16_t Buffer::ReadUint16At(uint8_t *aBufPtr, Direction aDirection)
|
||||
{
|
||||
uint16_t value;
|
||||
|
||||
@@ -221,7 +221,7 @@ uint16_t NcpFrameBuffer::ReadUint16At(uint8_t *aBufPtr, Direction aDirection)
|
||||
}
|
||||
|
||||
// Appends a byte at the write tail and updates the tail, discards the frame if buffer gets full.
|
||||
otError NcpFrameBuffer::InFrameAppend(uint8_t aByte)
|
||||
otError Buffer::InFrameAppend(uint8_t aByte)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
uint8_t *newTail;
|
||||
@@ -246,7 +246,7 @@ otError NcpFrameBuffer::InFrameAppend(uint8_t aByte)
|
||||
}
|
||||
|
||||
// This method begins a new segment (if one is not already open).
|
||||
otError NcpFrameBuffer::InFrameBeginSegment(void)
|
||||
otError Buffer::InFrameBeginSegment(void)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
uint16_t headerFlags = kSegmentHeaderNoFlag;
|
||||
@@ -274,7 +274,7 @@ exit:
|
||||
}
|
||||
|
||||
// This function closes/ends the current segment.
|
||||
void NcpFrameBuffer::InFrameEndSegment(uint16_t aSegmentHeaderFlags)
|
||||
void Buffer::InFrameEndSegment(uint16_t aSegmentHeaderFlags)
|
||||
{
|
||||
uint16_t segmentLength;
|
||||
uint16_t header;
|
||||
@@ -303,9 +303,9 @@ void NcpFrameBuffer::InFrameEndSegment(uint16_t aSegmentHeaderFlags)
|
||||
}
|
||||
|
||||
// This method discards the current frame being written.
|
||||
void NcpFrameBuffer::InFrameDiscard(void)
|
||||
void Buffer::InFrameDiscard(void)
|
||||
{
|
||||
#if OPENTHREAD_MTD || OPENTHREAD_FTD
|
||||
#if OPENTHREAD_SPINEL_CONFIG_OPENTHREAD_MESSAGE_ENABLE
|
||||
otMessage *message;
|
||||
#endif
|
||||
|
||||
@@ -314,13 +314,13 @@ void NcpFrameBuffer::InFrameDiscard(void)
|
||||
// Move the write segment head and tail pointers back to frame start.
|
||||
mWriteSegmentHead = mWriteSegmentTail = mWriteFrameStart[mWriteDirection];
|
||||
|
||||
#if OPENTHREAD_MTD || OPENTHREAD_FTD
|
||||
#if OPENTHREAD_SPINEL_CONFIG_OPENTHREAD_MESSAGE_ENABLE
|
||||
while ((message = otMessageQueueGetHead(&mWriteFrameMessageQueue)) != NULL)
|
||||
{
|
||||
otMessageQueueDequeue(&mWriteFrameMessageQueue, message);
|
||||
|
||||
// Note that messages associated with current (unfinished) input frame
|
||||
// being discarded, are not yet owned by the `NcpFrameBuffer` and
|
||||
// being discarded, are not yet owned by the `Buffer` and
|
||||
// therefore should not be freed.
|
||||
}
|
||||
#endif
|
||||
@@ -332,12 +332,12 @@ exit:
|
||||
}
|
||||
|
||||
// Returns `true` if in middle of writing a frame with given priority.
|
||||
bool NcpFrameBuffer::InFrameIsWriting(Priority aPriority) const
|
||||
bool Buffer::InFrameIsWriting(Priority aPriority) const
|
||||
{
|
||||
return (mWriteDirection == static_cast<Direction>(aPriority));
|
||||
}
|
||||
|
||||
void NcpFrameBuffer::InFrameBegin(Priority aPriority)
|
||||
void Buffer::InFrameBegin(Priority aPriority)
|
||||
{
|
||||
// Discard any previous unfinished frame.
|
||||
InFrameDiscard();
|
||||
@@ -357,7 +357,7 @@ void NcpFrameBuffer::InFrameBegin(Priority aPriority)
|
||||
mWriteSegmentHead = mWriteSegmentTail = mWriteFrameStart[mWriteDirection];
|
||||
}
|
||||
|
||||
otError NcpFrameBuffer::InFrameFeedByte(uint8_t aByte)
|
||||
otError Buffer::InFrameFeedByte(uint8_t aByte)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
@@ -372,7 +372,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError NcpFrameBuffer::InFrameFeedData(const uint8_t *aDataBuffer, uint16_t aDataBufferLength)
|
||||
otError Buffer::InFrameFeedData(const uint8_t *aDataBuffer, uint16_t aDataBufferLength)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
@@ -391,8 +391,8 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
#if OPENTHREAD_MTD || OPENTHREAD_FTD
|
||||
otError NcpFrameBuffer::InFrameFeedMessage(otMessage *aMessage)
|
||||
#if OPENTHREAD_SPINEL_CONFIG_OPENTHREAD_MESSAGE_ENABLE
|
||||
otError Buffer::InFrameFeedMessage(otMessage *aMessage)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
@@ -413,7 +413,7 @@ exit:
|
||||
}
|
||||
#endif
|
||||
|
||||
otError NcpFrameBuffer::InFrameGetPosition(WritePosition &aPosition)
|
||||
otError Buffer::InFrameGetPosition(WritePosition &aPosition)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
@@ -429,9 +429,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError NcpFrameBuffer::InFrameOverwrite(const WritePosition &aPosition,
|
||||
const uint8_t * aDataBuffer,
|
||||
uint16_t aDataBufferLength)
|
||||
otError Buffer::InFrameOverwrite(const WritePosition &aPosition, const uint8_t *aDataBuffer, uint16_t aDataBufferLength)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
uint8_t *bufPtr;
|
||||
@@ -462,7 +460,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
uint16_t NcpFrameBuffer::InFrameGetDistance(const WritePosition &aPosition) const
|
||||
uint16_t Buffer::InFrameGetDistance(const WritePosition &aPosition) const
|
||||
{
|
||||
uint16_t distance = 0;
|
||||
uint16_t segmentLength;
|
||||
@@ -481,7 +479,7 @@ exit:
|
||||
return distance;
|
||||
}
|
||||
|
||||
otError NcpFrameBuffer::InFrameReset(const WritePosition &aPosition)
|
||||
otError Buffer::InFrameReset(const WritePosition &aPosition)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
uint16_t segmentLength;
|
||||
@@ -500,9 +498,9 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError NcpFrameBuffer::InFrameEnd(void)
|
||||
otError Buffer::InFrameEnd(void)
|
||||
{
|
||||
#if OPENTHREAD_MTD || OPENTHREAD_FTD
|
||||
#if OPENTHREAD_SPINEL_CONFIG_OPENTHREAD_MESSAGE_ENABLE
|
||||
otMessage *message;
|
||||
#endif
|
||||
otError error = OT_ERROR_NONE;
|
||||
@@ -518,7 +516,7 @@ otError NcpFrameBuffer::InFrameEnd(void)
|
||||
// Update the frame start pointer to current segment head to be ready for next frame.
|
||||
mWriteFrameStart[mWriteDirection] = mWriteSegmentHead;
|
||||
|
||||
#if OPENTHREAD_MTD || OPENTHREAD_FTD
|
||||
#if OPENTHREAD_SPINEL_CONFIG_OPENTHREAD_MESSAGE_ENABLE
|
||||
// Move all the messages from the frame queue to the main queue.
|
||||
while ((message = otMessageQueueGetHead(&mWriteFrameMessageQueue)) != NULL)
|
||||
{
|
||||
@@ -538,22 +536,22 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
NcpFrameBuffer::FrameTag NcpFrameBuffer::InFrameGetLastTag(void) const
|
||||
Buffer::FrameTag Buffer::InFrameGetLastTag(void) const
|
||||
{
|
||||
return mWriteFrameTag;
|
||||
}
|
||||
|
||||
bool NcpFrameBuffer::HasFrame(Priority aPriority) const
|
||||
bool Buffer::HasFrame(Priority aPriority) const
|
||||
{
|
||||
return mReadFrameStart[aPriority] != mWriteFrameStart[aPriority];
|
||||
}
|
||||
|
||||
bool NcpFrameBuffer::IsEmpty(void) const
|
||||
bool Buffer::IsEmpty(void) const
|
||||
{
|
||||
return !HasFrame(kPriorityHigh) && !HasFrame(kPriorityLow);
|
||||
}
|
||||
|
||||
void NcpFrameBuffer::OutFrameSelectReadDirection(void)
|
||||
void Buffer::OutFrameSelectReadDirection(void)
|
||||
{
|
||||
if (mReadState == kReadStateNotActive)
|
||||
{
|
||||
@@ -562,7 +560,7 @@ void NcpFrameBuffer::OutFrameSelectReadDirection(void)
|
||||
}
|
||||
|
||||
// Start/Prepare a new segment for reading.
|
||||
otError NcpFrameBuffer::OutFramePrepareSegment(void)
|
||||
otError Buffer::OutFramePrepareSegment(void)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
uint16_t header;
|
||||
@@ -601,7 +599,7 @@ otError NcpFrameBuffer::OutFramePrepareSegment(void)
|
||||
ExitNow();
|
||||
}
|
||||
|
||||
#if OPENTHREAD_MTD || OPENTHREAD_FTD
|
||||
#if OPENTHREAD_SPINEL_CONFIG_OPENTHREAD_MESSAGE_ENABLE
|
||||
// No data in this segment, prepare any appended/associated message of this segment.
|
||||
if (OutFramePrepareMessage() == OT_ERROR_NONE)
|
||||
{
|
||||
@@ -622,10 +620,10 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
#if OPENTHREAD_MTD || OPENTHREAD_FTD
|
||||
#if OPENTHREAD_SPINEL_CONFIG_OPENTHREAD_MESSAGE_ENABLE
|
||||
// This method prepares an associated message in current segment and fills the message buffer. It returns
|
||||
// ThreadError_NotFound if there is no message or if the message has no content.
|
||||
otError NcpFrameBuffer::OutFramePrepareMessage(void)
|
||||
otError Buffer::OutFramePrepareMessage(void)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
uint16_t header;
|
||||
@@ -657,7 +655,7 @@ exit:
|
||||
|
||||
// This method fills content from current message into the message buffer. It returns OT_ERROR_NOT_FOUND if no more
|
||||
// content in the current message.
|
||||
otError NcpFrameBuffer::OutFrameFillMessageBuffer(void)
|
||||
otError Buffer::OutFrameFillMessageBuffer(void)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
int readLength;
|
||||
@@ -682,9 +680,9 @@ otError NcpFrameBuffer::OutFrameFillMessageBuffer(void)
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
#endif // #if OPENTHREAD_MTD || OPENTHREAD_FTD
|
||||
#endif // #if OPENTHREAD_SPINEL_CONFIG_OPENTHREAD_MESSAGE_ENABLE
|
||||
|
||||
otError NcpFrameBuffer::OutFrameBegin(void)
|
||||
otError Buffer::OutFrameBegin(void)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
@@ -695,7 +693,7 @@ otError NcpFrameBuffer::OutFrameBegin(void)
|
||||
// Move the segment head and tail to start of frame.
|
||||
mReadSegmentHead = mReadSegmentTail = mReadFrameStart[mReadDirection];
|
||||
|
||||
#if OPENTHREAD_MTD || OPENTHREAD_FTD
|
||||
#if OPENTHREAD_SPINEL_CONFIG_OPENTHREAD_MESSAGE_ENABLE
|
||||
mReadMessage = NULL;
|
||||
#endif
|
||||
|
||||
@@ -706,12 +704,12 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
bool NcpFrameBuffer::OutFrameHasEnded(void)
|
||||
bool Buffer::OutFrameHasEnded(void)
|
||||
{
|
||||
return (mReadState == kReadStateDone) || (mReadState == kReadStateNotActive);
|
||||
}
|
||||
|
||||
uint8_t NcpFrameBuffer::OutFrameReadByte(void)
|
||||
uint8_t Buffer::OutFrameReadByte(void)
|
||||
{
|
||||
otError error;
|
||||
uint8_t retval = kReadByteAfterFrameHasEnded;
|
||||
@@ -737,7 +735,7 @@ uint8_t NcpFrameBuffer::OutFrameReadByte(void)
|
||||
// Check if at end of current segment.
|
||||
if (mReadPointer == mReadSegmentTail)
|
||||
{
|
||||
#if OPENTHREAD_MTD || OPENTHREAD_FTD
|
||||
#if OPENTHREAD_SPINEL_CONFIG_OPENTHREAD_MESSAGE_ENABLE
|
||||
// Prepare any message associated with this segment.
|
||||
error = OutFramePrepareMessage();
|
||||
#else
|
||||
@@ -754,7 +752,7 @@ uint8_t NcpFrameBuffer::OutFrameReadByte(void)
|
||||
break;
|
||||
|
||||
case kReadStateInMessage:
|
||||
#if OPENTHREAD_MTD || OPENTHREAD_FTD
|
||||
#if OPENTHREAD_SPINEL_CONFIG_OPENTHREAD_MESSAGE_ENABLE
|
||||
// Read a byte from current read pointer and move the read pointer by 1 byte.
|
||||
retval = *mReadPointer;
|
||||
mReadPointer++;
|
||||
@@ -778,7 +776,7 @@ uint8_t NcpFrameBuffer::OutFrameReadByte(void)
|
||||
return retval;
|
||||
}
|
||||
|
||||
uint16_t NcpFrameBuffer::OutFrameRead(uint16_t aReadLength, uint8_t *aDataBuffer)
|
||||
uint16_t Buffer::OutFrameRead(uint16_t aReadLength, uint8_t *aDataBuffer)
|
||||
{
|
||||
uint16_t bytesRead = 0;
|
||||
|
||||
@@ -790,7 +788,7 @@ uint16_t NcpFrameBuffer::OutFrameRead(uint16_t aReadLength, uint8_t *aDataBuffer
|
||||
return bytesRead;
|
||||
}
|
||||
|
||||
otError NcpFrameBuffer::OutFrameRemove(void)
|
||||
otError Buffer::OutFrameRemove(void)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
uint8_t *bufPtr;
|
||||
@@ -825,7 +823,7 @@ otError NcpFrameBuffer::OutFrameRemove(void)
|
||||
}
|
||||
}
|
||||
|
||||
#if OPENTHREAD_MTD || OPENTHREAD_FTD
|
||||
#if OPENTHREAD_SPINEL_CONFIG_OPENTHREAD_MESSAGE_ENABLE
|
||||
// If current segment has an appended message, remove it from message queue and free it.
|
||||
if (header & kSegmentHeaderMessageIndicatorFlag)
|
||||
{
|
||||
@@ -865,7 +863,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
void NcpFrameBuffer::UpdateReadWriteStartPointers(void)
|
||||
void Buffer::UpdateReadWriteStartPointers(void)
|
||||
{
|
||||
// If there is no fully written high priority frame, and not in middle of writing a new frame either.
|
||||
if (!HasFrame(kPriorityHigh) && !InFrameIsWriting(kPriorityHigh))
|
||||
@@ -888,13 +886,13 @@ exit:
|
||||
return;
|
||||
}
|
||||
|
||||
uint16_t NcpFrameBuffer::OutFrameGetLength(void)
|
||||
uint16_t Buffer::OutFrameGetLength(void)
|
||||
{
|
||||
uint16_t frameLength = 0;
|
||||
uint16_t header;
|
||||
uint8_t *bufPtr;
|
||||
uint8_t numSegments;
|
||||
#if OPENTHREAD_MTD || OPENTHREAD_FTD
|
||||
#if OPENTHREAD_SPINEL_CONFIG_OPENTHREAD_MESSAGE_ENABLE
|
||||
otMessage *message = NULL;
|
||||
#endif
|
||||
|
||||
@@ -925,7 +923,7 @@ uint16_t NcpFrameBuffer::OutFrameGetLength(void)
|
||||
}
|
||||
}
|
||||
|
||||
#if OPENTHREAD_MTD || OPENTHREAD_FTD
|
||||
#if OPENTHREAD_SPINEL_CONFIG_OPENTHREAD_MESSAGE_ENABLE
|
||||
// If current segment has an associated message, add its length to frame length.
|
||||
if (header & kSegmentHeaderMessageIndicatorFlag)
|
||||
{
|
||||
@@ -962,7 +960,7 @@ exit:
|
||||
return frameLength;
|
||||
}
|
||||
|
||||
NcpFrameBuffer::FrameTag NcpFrameBuffer::OutFrameGetTag(void)
|
||||
Buffer::FrameTag Buffer::OutFrameGetTag(void)
|
||||
{
|
||||
OutFrameSelectReadDirection();
|
||||
|
||||
@@ -972,5 +970,5 @@ NcpFrameBuffer::FrameTag NcpFrameBuffer::OutFrameGetTag(void)
|
||||
return IsEmpty() ? kInvalidTag : mReadFrameStart[mReadDirection];
|
||||
}
|
||||
|
||||
} // namespace Ncp
|
||||
} // namespace Spinel
|
||||
} // namespace ot
|
||||
@@ -33,25 +33,25 @@
|
||||
#ifndef NCP_FRAME_BUFFER_HPP_
|
||||
#define NCP_FRAME_BUFFER_HPP_
|
||||
|
||||
#include "openthread-core-config.h"
|
||||
#include "openthread-spinel-config.h"
|
||||
|
||||
#include <openthread/message.h>
|
||||
|
||||
namespace ot {
|
||||
namespace Ncp {
|
||||
namespace Spinel {
|
||||
|
||||
/**
|
||||
* This class implements a buffer/queue for storing NCP frames.
|
||||
* This class implements a buffer/queue for storing Ncp frames.
|
||||
*
|
||||
* A frame can consist of a sequence of data bytes and/or the content of an `otMessage` or a combination of the two.
|
||||
* `NcpFrameBuffer` implements priority FIFO logic for storing and reading frames. Two priority levels of high and low
|
||||
* `Buffer` implements priority FIFO logic for storing and reading frames. Two priority levels of high and low
|
||||
* are supported. Within same priority level first-in-first-out order is preserved. High priority frames are read
|
||||
* ahead of any low priority ones.
|
||||
*
|
||||
*/
|
||||
class NcpFrameBuffer
|
||||
class Buffer
|
||||
{
|
||||
friend class SpinelEncoder;
|
||||
friend class Encoder;
|
||||
|
||||
public:
|
||||
/**
|
||||
@@ -67,7 +67,7 @@ public:
|
||||
|
||||
/**
|
||||
* Defines the (abstract) frame tag type. The tag is a unique value (within currently queued frames) associated
|
||||
* with a frame in the `NcpFrameBuffer`. Frame tags can be compared with one another using operator `==`.
|
||||
* with a frame in the `Buffer`. Frame tags can be compared with one another using operator `==`.
|
||||
*
|
||||
*/
|
||||
typedef const void *FrameTag;
|
||||
@@ -81,7 +81,7 @@ public:
|
||||
/**
|
||||
* Defines the structure to hold a write position for an input frame (frame being written).
|
||||
*
|
||||
* It should be considered as an opaque data structure to users of `NcpFrameBuffer`.
|
||||
* It should be considered as an opaque data structure to users of `Buffer`.
|
||||
*
|
||||
*/
|
||||
struct WritePosition
|
||||
@@ -101,20 +101,20 @@ public:
|
||||
uint8_t *mPosition; //< Pointer into buffer corresponding to saved write position.
|
||||
uint8_t *mSegmentHead; //< Pointer to segment head.
|
||||
|
||||
friend class NcpFrameBuffer;
|
||||
friend class Buffer;
|
||||
};
|
||||
|
||||
/**
|
||||
* Defines a function pointer callback which is invoked to inform a change in `NcpFrameBuffer` either when a new
|
||||
* frame is added/written to `NcpFrameBuffer` or when a frame is removed from `NcpFrameBuffer`.
|
||||
* Defines a function pointer callback which is invoked to inform a change in `Buffer` either when a new
|
||||
* frame is added/written to `Buffer` or when a frame is removed from `Buffer`.
|
||||
*
|
||||
* @param[in] aContext A pointer to arbitrary context information.
|
||||
* @param[in] aTag The tag associated with the frame which is added or removed.
|
||||
* @param[in] aPriority The priority of frame.
|
||||
* @param[in] aNcpFrameBuffer A pointer to the `NcpFrameBuffer`.
|
||||
* @param[in] aBuffer A pointer to the `Buffer`.
|
||||
*
|
||||
*/
|
||||
typedef void (*BufferCallback)(void *aContext, FrameTag aTag, Priority aPriority, NcpFrameBuffer *aNcpFrameBuffer);
|
||||
typedef void (*BufferCallback)(void *aContext, FrameTag aTag, Priority aPriority, Buffer *aBuffer);
|
||||
|
||||
/**
|
||||
* This constructor initializes an NCP frame buffer.
|
||||
@@ -123,7 +123,7 @@ public:
|
||||
* @param[in] aBufferLength The buffer size (in bytes).
|
||||
*
|
||||
*/
|
||||
NcpFrameBuffer(uint8_t *aBuffer, uint16_t aBufferLength);
|
||||
Buffer(uint8_t *aBuffer, uint16_t aBufferLength);
|
||||
|
||||
/**
|
||||
* This method clears the NCP frame buffer. All the frames are cleared/removed.
|
||||
@@ -201,7 +201,7 @@ public:
|
||||
*/
|
||||
otError InFrameFeedData(const uint8_t *aDataBuffer, uint16_t aDataBufferLength);
|
||||
|
||||
#if OPENTHREAD_MTD || OPENTHREAD_FTD
|
||||
#if OPENTHREAD_SPINEL_CONFIG_OPENTHREAD_MESSAGE_ENABLE
|
||||
/**
|
||||
* This method adds a message to the current input frame.
|
||||
*
|
||||
@@ -211,7 +211,7 @@ public:
|
||||
* If no buffer space is available, this method will discard and clear the frame and return error status
|
||||
* `OT_ERROR_NO_BUFS`.
|
||||
*
|
||||
* The ownership of the passed-in message @p aMessage changes to `NcpFrameBuffer` ONLY when the entire frame is
|
||||
* The ownership of the passed-in message @p aMessage changes to `Buffer` ONLY when the entire frame is
|
||||
* successfully finished (i.e., with a successful call to `InFrameEnd()` for the current input frame), and in this
|
||||
* case the `otMessage` instance will be freed once the frame is removed (using `OutFrameRemove()`) from NCP buffer.
|
||||
* However, if the input frame gets discarded before it is finished (e.g., running out of buffer space), the
|
||||
@@ -318,7 +318,7 @@ public:
|
||||
/**
|
||||
* This method returns the tag assigned to last successfully written/added frame to NcpBuffer (i.e., last input
|
||||
* frame for which `InFrameEnd()` was called and returned success status). The tag is a unique value (within
|
||||
* currently queued frames) associated with a frame in the `NcpFrameBuffer`. The tag can be used to identify the
|
||||
* currently queued frames) associated with a frame in the `Buffer`. The tag can be used to identify the
|
||||
* same frame when it is read and removed from the NcpBuffer. Tags can be compared using operator `==`.
|
||||
*
|
||||
* @returns The tag of the last successfully written frame, or `kInvalidTag` if no frame is written so far.
|
||||
@@ -445,10 +445,10 @@ public:
|
||||
|
||||
private:
|
||||
/*
|
||||
* `NcpFrameBuffer` Implementation
|
||||
* `Buffer` Implementation
|
||||
* -------------------------------
|
||||
*
|
||||
* `NcpFrameBuffer` internally stores a frame as a sequence of data segments. Each segment stores a portion of
|
||||
* `Buffer` internally stores a frame as a sequence of data segments. Each segment stores a portion of
|
||||
* frame. The data segments are stored in the main buffer `mBuffer`. `mBuffer` is utilized as a circular buffer.
|
||||
|
||||
* The content of messages (which are added using `InFrameFeedMessage()`) are not directly copied in the `mBuffer`
|
||||
@@ -491,7 +491,7 @@ private:
|
||||
* Segment #1 Header Segment #2 Header
|
||||
*
|
||||
*
|
||||
* `NcpFrameBuffer` uses the `mBuffer` as a circular/ring buffer. To support two frame priorities the buffer is
|
||||
* `Buffer` uses the `mBuffer` as a circular/ring buffer. To support two frame priorities the buffer is
|
||||
* divided into two high-priority and low-priority regions. The high priority frames are stored in buffer in
|
||||
* backward direction while the low-priority frames use the buffer in forward direction. This model ensures the
|
||||
* available buffer space is utilized efficiently between all frame types.
|
||||
@@ -515,7 +515,7 @@ private:
|
||||
* When frames are removed, if possible, the `mReadFrameStart` and `mWriteFrameStart` pointers of the two priority
|
||||
* levels are moved closer to avoid gaps.
|
||||
*
|
||||
* For an output frame (frame being read), NcpFrameBuffer maintains a `ReadState` along with a set of pointers
|
||||
* For an output frame (frame being read), Buffer maintains a `ReadState` along with a set of pointers
|
||||
* into the buffer:
|
||||
*
|
||||
* mReadFrameStart[priority]: Start of the current/front frame.
|
||||
@@ -615,7 +615,7 @@ private:
|
||||
otError OutFramePrepareSegment(void);
|
||||
void OutFrameMoveToNextSegment(void);
|
||||
|
||||
#if OPENTHREAD_MTD || OPENTHREAD_FTD
|
||||
#if OPENTHREAD_SPINEL_CONFIG_OPENTHREAD_MESSAGE_ENABLE
|
||||
otError OutFramePrepareMessage(void);
|
||||
otError OutFrameFillMessageBuffer(void);
|
||||
#endif
|
||||
@@ -644,7 +644,7 @@ private:
|
||||
uint8_t *mReadSegmentTail; // Pointer to end of current segment in the frame being read.
|
||||
uint8_t *mReadPointer; // Pointer to next byte to read (either in segment or in msg buffer).
|
||||
|
||||
#if OPENTHREAD_MTD || OPENTHREAD_FTD
|
||||
#if OPENTHREAD_SPINEL_CONFIG_OPENTHREAD_MESSAGE_ENABLE
|
||||
otMessageQueue mWriteFrameMessageQueue; // Message queue for the current frame being written.
|
||||
otMessageQueue mMessageQueue[kNumPrios]; // Main message queues.
|
||||
otMessage * mReadMessage; // Current Message in the frame being read.
|
||||
@@ -654,7 +654,7 @@ private:
|
||||
#endif
|
||||
};
|
||||
|
||||
} // namespace Ncp
|
||||
} // namespace Spinel
|
||||
} // namespace ot
|
||||
|
||||
#endif // NCP_FRAME_BUFFER_HPP_
|
||||
@@ -30,17 +30,15 @@
|
||||
* This file implements a spinel decoder.
|
||||
*/
|
||||
|
||||
#include <openthread/config.h>
|
||||
|
||||
#include "spinel_decoder.hpp"
|
||||
|
||||
#include "common/code_utils.hpp"
|
||||
#include "common/string.hpp"
|
||||
|
||||
namespace ot {
|
||||
namespace Ncp {
|
||||
namespace Spinel {
|
||||
|
||||
SpinelDecoder::SpinelDecoder(void)
|
||||
Decoder::Decoder(void)
|
||||
: mFrame(NULL)
|
||||
, mLength(0)
|
||||
, mIndex(0)
|
||||
@@ -52,7 +50,7 @@ SpinelDecoder::SpinelDecoder(void)
|
||||
{
|
||||
}
|
||||
|
||||
void SpinelDecoder::Init(const uint8_t *aFrame, uint16_t aLength)
|
||||
void Decoder::Init(const uint8_t *aFrame, uint16_t aLength)
|
||||
{
|
||||
mFrame = aFrame;
|
||||
mLength = (mFrame != NULL) ? aLength : 0;
|
||||
@@ -61,7 +59,7 @@ void SpinelDecoder::Init(const uint8_t *aFrame, uint16_t aLength)
|
||||
ClearSavedPosition();
|
||||
}
|
||||
|
||||
void SpinelDecoder::Reset(void)
|
||||
void Decoder::Reset(void)
|
||||
{
|
||||
mIndex = 0;
|
||||
mEnd = mLength;
|
||||
@@ -69,7 +67,7 @@ void SpinelDecoder::Reset(void)
|
||||
ClearSavedPosition();
|
||||
}
|
||||
|
||||
otError SpinelDecoder::ReadBool(bool &aBool)
|
||||
otError Decoder::ReadBool(bool &aBool)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
uint8_t byte;
|
||||
@@ -94,7 +92,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError SpinelDecoder::ReadUint8(uint8_t &aUint8)
|
||||
otError Decoder::ReadUint8(uint8_t &aUint8)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
@@ -106,7 +104,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError SpinelDecoder::ReadInt8(int8_t &aInt8)
|
||||
otError Decoder::ReadInt8(int8_t &aInt8)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
uint8_t byte;
|
||||
@@ -118,7 +116,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError SpinelDecoder::ReadUint16(uint16_t &aUint16)
|
||||
otError Decoder::ReadUint16(uint16_t &aUint16)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
@@ -132,7 +130,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError SpinelDecoder::ReadInt16(int16_t &aInt16)
|
||||
otError Decoder::ReadInt16(int16_t &aInt16)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
uint16_t u16;
|
||||
@@ -144,7 +142,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError SpinelDecoder::ReadUint32(uint32_t &aUint32)
|
||||
otError Decoder::ReadUint32(uint32_t &aUint32)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
@@ -159,7 +157,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError SpinelDecoder::ReadInt32(int32_t &aInt32)
|
||||
otError Decoder::ReadInt32(int32_t &aInt32)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
uint32_t u32;
|
||||
@@ -171,7 +169,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError SpinelDecoder::ReadUint64(uint64_t &aUint64)
|
||||
otError Decoder::ReadUint64(uint64_t &aUint64)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
@@ -188,7 +186,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError SpinelDecoder::ReadInt64(int64_t &aInt64)
|
||||
otError Decoder::ReadInt64(int64_t &aInt64)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
uint64_t u64;
|
||||
@@ -200,7 +198,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError SpinelDecoder::ReadUintPacked(unsigned int &aUint)
|
||||
otError Decoder::ReadUintPacked(unsigned int &aUint)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
spinel_ssize_t parsedLen;
|
||||
@@ -217,7 +215,7 @@ exit:
|
||||
}
|
||||
|
||||
// Reads an item of given size and updates the pointer `aPtr`.
|
||||
otError SpinelDecoder::ReadItem(const uint8_t **aPtr, uint16_t aSize)
|
||||
otError Decoder::ReadItem(const uint8_t **aPtr, uint16_t aSize)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
@@ -231,7 +229,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError SpinelDecoder::ReadIp6Address(spinel_ipv6addr_t &aIp6Addr)
|
||||
otError Decoder::ReadIp6Address(spinel_ipv6addr_t &aIp6Addr)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
const spinel_ipv6addr_t *ipv6AddrPtr;
|
||||
@@ -243,7 +241,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError SpinelDecoder::ReadIp6Address(otIp6Address &aIp6Addr)
|
||||
otError Decoder::ReadIp6Address(otIp6Address &aIp6Addr)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
const otIp6Address *ipv6AddrPtr;
|
||||
@@ -255,7 +253,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError SpinelDecoder::ReadEui64(spinel_eui64_t &aEui64)
|
||||
otError Decoder::ReadEui64(spinel_eui64_t &aEui64)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
const spinel_eui64_t *eui64Ptr;
|
||||
@@ -267,7 +265,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError SpinelDecoder::ReadEui64(otExtAddress &aEui64)
|
||||
otError Decoder::ReadEui64(otExtAddress &aEui64)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
const otExtAddress *eui64Ptr;
|
||||
@@ -279,7 +277,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError SpinelDecoder::ReadEui48(spinel_eui48_t &aEui48)
|
||||
otError Decoder::ReadEui48(spinel_eui48_t &aEui48)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
const spinel_eui48_t *eui48Ptr;
|
||||
@@ -291,7 +289,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError SpinelDecoder::ReadUtf8(const char *&aUtf8)
|
||||
otError Decoder::ReadUtf8(const char *&aUtf8)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
size_t len;
|
||||
@@ -311,14 +309,14 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError SpinelDecoder::ReadData(const uint8_t *&aData, uint16_t &aDataLen)
|
||||
otError Decoder::ReadData(const uint8_t *&aData, uint16_t &aDataLen)
|
||||
{
|
||||
aDataLen = mEnd - mIndex;
|
||||
|
||||
return ReadItem(&aData, aDataLen);
|
||||
}
|
||||
|
||||
otError SpinelDecoder::ReadDataWithLen(const uint8_t *&aData, uint16_t &aDataLen)
|
||||
otError Decoder::ReadDataWithLen(const uint8_t *&aData, uint16_t &aDataLen)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
uint16_t len;
|
||||
@@ -331,7 +329,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError SpinelDecoder::OpenStruct(void)
|
||||
otError Decoder::OpenStruct(void)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
uint16_t structLen;
|
||||
@@ -349,7 +347,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError SpinelDecoder::CloseStruct(void)
|
||||
otError Decoder::CloseStruct(void)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
@@ -373,14 +371,14 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
void SpinelDecoder::SavePosition(void)
|
||||
void Decoder::SavePosition(void)
|
||||
{
|
||||
mSavedIndex = mIndex;
|
||||
mSavedEnd = mEnd;
|
||||
mSavedNumOpenStructs = mNumOpenStructs;
|
||||
}
|
||||
|
||||
otError SpinelDecoder::ResetToSaved(void)
|
||||
otError Decoder::ResetToSaved(void)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
@@ -394,5 +392,5 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
} // namespace Ncp
|
||||
} // namespace Spinel
|
||||
} // namespace ot
|
||||
@@ -33,22 +33,21 @@
|
||||
#ifndef SPINEL_DECODER_HPP_
|
||||
#define SPINEL_DECODER_HPP_
|
||||
|
||||
#include <openthread/config.h>
|
||||
#include "openthread-spinel-config.h"
|
||||
|
||||
#include <openthread/ip6.h>
|
||||
#include <openthread/ncp.h>
|
||||
|
||||
#include "openthread-core-config.h"
|
||||
#include "ncp/spinel.h"
|
||||
#include "spinel.h"
|
||||
|
||||
namespace ot {
|
||||
namespace Ncp {
|
||||
namespace Spinel {
|
||||
|
||||
/**
|
||||
* This class defines a spinel decoder.
|
||||
*
|
||||
*/
|
||||
class SpinelDecoder
|
||||
class Decoder
|
||||
{
|
||||
public:
|
||||
enum
|
||||
@@ -57,10 +56,10 @@ public:
|
||||
};
|
||||
|
||||
/**
|
||||
* This constructor initializes a `SpinelDecoder` object.
|
||||
* This constructor initializes a `Decoder` object.
|
||||
*
|
||||
*/
|
||||
SpinelDecoder(void);
|
||||
Decoder(void);
|
||||
|
||||
/**
|
||||
* This method initializes the decoder to start decoding a new frame.
|
||||
@@ -586,7 +585,7 @@ private:
|
||||
uint16_t mPrevEnd[kMaxNestedStructs];
|
||||
};
|
||||
|
||||
} // namespace Ncp
|
||||
} // namespace Spinel
|
||||
} // namespace ot
|
||||
|
||||
#endif // SPINEL_DECODER_HPP_
|
||||
@@ -37,16 +37,16 @@
|
||||
#include "common/code_utils.hpp"
|
||||
|
||||
namespace ot {
|
||||
namespace Ncp {
|
||||
namespace Spinel {
|
||||
|
||||
otError SpinelEncoder::BeginFrame(NcpFrameBuffer::Priority aPriority)
|
||||
otError Encoder::BeginFrame(Spinel::Buffer::Priority aPriority)
|
||||
{
|
||||
mNumOpenStructs = 0;
|
||||
mNcpBuffer.InFrameBegin(aPriority);
|
||||
return OT_ERROR_NONE;
|
||||
}
|
||||
|
||||
otError SpinelEncoder::BeginFrame(uint8_t aHeader, unsigned int aCommand)
|
||||
otError Encoder::BeginFrame(uint8_t aHeader, unsigned int aCommand)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
@@ -54,11 +54,11 @@ otError SpinelEncoder::BeginFrame(uint8_t aHeader, unsigned int aCommand)
|
||||
|
||||
if (SPINEL_HEADER_GET_TID(aHeader) != 0)
|
||||
{
|
||||
SuccessOrExit(error = BeginFrame(NcpFrameBuffer::kPriorityHigh));
|
||||
SuccessOrExit(error = BeginFrame(Spinel::Buffer::kPriorityHigh));
|
||||
}
|
||||
else
|
||||
{
|
||||
SuccessOrExit(error = BeginFrame(NcpFrameBuffer::kPriorityLow));
|
||||
SuccessOrExit(error = BeginFrame(Spinel::Buffer::kPriorityLow));
|
||||
}
|
||||
|
||||
SuccessOrExit(error = WriteUint8(aHeader));
|
||||
@@ -68,7 +68,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError SpinelEncoder::BeginFrame(uint8_t aHeader, unsigned int aCommand, spinel_prop_key_t aKey)
|
||||
otError Encoder::BeginFrame(uint8_t aHeader, unsigned int aCommand, spinel_prop_key_t aKey)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
@@ -87,7 +87,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError SpinelEncoder::OverwriteWithLastStatusError(spinel_status_t aStatus)
|
||||
otError Encoder::OverwriteWithLastStatusError(spinel_status_t aStatus)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
@@ -99,7 +99,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError SpinelEncoder::EndFrame(void)
|
||||
otError Encoder::EndFrame(void)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
@@ -114,7 +114,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError SpinelEncoder::WriteUint16(uint16_t aUint16)
|
||||
otError Encoder::WriteUint16(uint16_t aUint16)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
@@ -125,7 +125,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError SpinelEncoder::WriteUint32(uint32_t aUint32)
|
||||
otError Encoder::WriteUint32(uint32_t aUint32)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
@@ -138,7 +138,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError SpinelEncoder::WriteUint64(uint64_t aUint64)
|
||||
otError Encoder::WriteUint64(uint64_t aUint64)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
@@ -155,7 +155,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError SpinelEncoder::WriteUintPacked(unsigned int aUint)
|
||||
otError Encoder::WriteUintPacked(unsigned int aUint)
|
||||
{
|
||||
uint8_t buffer[6];
|
||||
spinel_ssize_t len;
|
||||
@@ -165,7 +165,7 @@ otError SpinelEncoder::WriteUintPacked(unsigned int aUint)
|
||||
return WriteData(buffer, static_cast<uint16_t>(len));
|
||||
}
|
||||
|
||||
otError SpinelEncoder::WriteDataWithLen(const uint8_t *aData, uint16_t aDataLen)
|
||||
otError Encoder::WriteDataWithLen(const uint8_t *aData, uint16_t aDataLen)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
@@ -176,7 +176,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError SpinelEncoder::WriteUtf8(const char *aUtf8)
|
||||
otError Encoder::WriteUtf8(const char *aUtf8)
|
||||
{
|
||||
otError error;
|
||||
size_t len = strlen(aUtf8);
|
||||
@@ -193,7 +193,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError SpinelEncoder::OpenStruct(void)
|
||||
otError Encoder::OpenStruct(void)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
@@ -210,7 +210,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError SpinelEncoder::CloseStruct(void)
|
||||
otError Encoder::CloseStruct(void)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
uint16_t len;
|
||||
@@ -234,7 +234,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError SpinelEncoder::SavePosition(void)
|
||||
otError Encoder::SavePosition(void)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
@@ -245,7 +245,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError SpinelEncoder::ResetToSaved(void)
|
||||
otError Encoder::ResetToSaved(void)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
@@ -256,7 +256,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError SpinelEncoder::WritePacked(const char *aPackFormat, ...)
|
||||
otError Encoder::WritePacked(const char *aPackFormat, ...)
|
||||
{
|
||||
uint8_t buf[kPackFormatBufferSize];
|
||||
otError error = OT_ERROR_NONE;
|
||||
@@ -276,7 +276,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError SpinelEncoder::WriteVPacked(const char *aPackFormat, va_list aArgs)
|
||||
otError Encoder::WriteVPacked(const char *aPackFormat, va_list aArgs)
|
||||
{
|
||||
uint8_t buf[kPackFormatBufferSize];
|
||||
otError error = OT_ERROR_NONE;
|
||||
@@ -291,5 +291,5 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
} // namespace Ncp
|
||||
} // namespace Spinel
|
||||
} // namespace ot
|
||||
@@ -33,33 +33,32 @@
|
||||
#ifndef SPINEL_ENCODER_HPP_
|
||||
#define SPINEL_ENCODER_HPP_
|
||||
|
||||
#include "openthread-core-config.h"
|
||||
#include "openthread-spinel-config.h"
|
||||
|
||||
#include <openthread/ip6.h>
|
||||
#include <openthread/message.h>
|
||||
#include <openthread/ncp.h>
|
||||
|
||||
#include "openthread-core-config.h"
|
||||
#include "ncp/ncp_buffer.hpp"
|
||||
#include "ncp/spinel.h"
|
||||
#include "spinel.h"
|
||||
#include "spinel_buffer.hpp"
|
||||
|
||||
namespace ot {
|
||||
namespace Ncp {
|
||||
namespace Spinel {
|
||||
|
||||
/**
|
||||
* This class defines a spinel encoder.
|
||||
*
|
||||
*/
|
||||
class SpinelEncoder
|
||||
class Encoder
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* This constructor initializes a `SpinelEncoder` object.
|
||||
* This constructor initializes a `Encoder` object.
|
||||
*
|
||||
* @param[in] aNcpBuffer A reference to a `NcpFrameBuffer` where the frames are written.
|
||||
* @param[in] aNcpBuffer A reference to a `Spinel::Buffer` where the frames are written.
|
||||
*
|
||||
*/
|
||||
explicit SpinelEncoder(NcpFrameBuffer &aNcpBuffer)
|
||||
explicit Encoder(Spinel::Buffer &aNcpBuffer)
|
||||
: mNcpBuffer(aNcpBuffer)
|
||||
, mNumOpenStructs(0)
|
||||
, mSavedNumOpenStructs(0)
|
||||
@@ -79,7 +78,7 @@ public:
|
||||
* @retval OT_ERROR_NO_BUFS Insufficient buffer space available to start a new frame.
|
||||
*
|
||||
*/
|
||||
otError BeginFrame(NcpFrameBuffer::Priority aPriority);
|
||||
otError BeginFrame(Spinel::Buffer::Priority aPriority);
|
||||
|
||||
/**
|
||||
* This method begins a new spinel command frame to be added/written to the frame buffer.
|
||||
@@ -541,7 +540,7 @@ public:
|
||||
*/
|
||||
otError WriteDataWithLen(const uint8_t *aData, uint16_t aDataLen);
|
||||
|
||||
#if OPENTHREAD_MTD || OPENTHREAD_FTD
|
||||
#if OPENTHREAD_SPINEL_CONFIG_OPENTHREAD_MESSAGE_ENABLE
|
||||
/**
|
||||
* This method adds a message to the current input frame.
|
||||
*
|
||||
@@ -551,10 +550,10 @@ public:
|
||||
* If no buffer space is available, this method will discard and clear the frame and return error status
|
||||
* `OT_ERROR_NO_BUFS`.
|
||||
*
|
||||
* The ownership of the passed-in message @p aMessage changes to underlying `NcpFrameBuffer` ONLY when the entire
|
||||
* The ownership of the passed-in message @p aMessage changes to underlying `Spinel::Buffer` ONLY when the entire
|
||||
* frame is successfully finished (i.e., with a successful call to `EndFrame()` for the current frame being
|
||||
* written), and in this case the `otMessage` instance will be freed once the frame is removed from the
|
||||
* `NcpFrameBuffer`. However, if the frame gets discarded before it is finished (e.g., running out of buffer space),
|
||||
* `Spinel::Buffer`. However, if the frame gets discarded before it is finished (e.g., running out of buffer space),
|
||||
* the `otMessage` instance remains unchanged.
|
||||
*
|
||||
* @param[in] aMessage A message to be added to current frame.
|
||||
@@ -685,15 +684,15 @@ private:
|
||||
kMaxNestedStructs = 4, ///< Maximum number of nested structs.
|
||||
};
|
||||
|
||||
NcpFrameBuffer & mNcpBuffer;
|
||||
NcpFrameBuffer::WritePosition mStructPosition[kMaxNestedStructs];
|
||||
Spinel::Buffer & mNcpBuffer;
|
||||
Spinel::Buffer::WritePosition mStructPosition[kMaxNestedStructs];
|
||||
uint8_t mNumOpenStructs;
|
||||
|
||||
uint8_t mSavedNumOpenStructs;
|
||||
NcpFrameBuffer::WritePosition mSavedPosition;
|
||||
Spinel::Buffer::WritePosition mSavedPosition;
|
||||
};
|
||||
|
||||
} // namespace Ncp
|
||||
} // namespace Spinel
|
||||
} // namespace ot
|
||||
|
||||
#endif // SPINEL_ENCODER_HPP_
|
||||
@@ -49,8 +49,6 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "openthread-core-config.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
@@ -53,6 +53,7 @@ AM_CPPFLAGS = \
|
||||
-DOPENTHREAD_FTD=1 \
|
||||
-DOPENTHREAD_MTD=0 \
|
||||
-DOPENTHREAD_RADIO=0 \
|
||||
-DOPENTHREAD_SPINEL_CONFIG_OPENTHREAD_MESSAGE_ENABLE=1 \
|
||||
-I$(top_srcdir)/include \
|
||||
-I$(top_srcdir)/src \
|
||||
-I$(top_srcdir)/src/core \
|
||||
@@ -128,7 +129,7 @@ check_PROGRAMS += \
|
||||
if OPENTHREAD_ENABLE_NCP
|
||||
check_PROGRAMS += \
|
||||
test-hdlc \
|
||||
test-ncp-buffer \
|
||||
test-spinel-buffer \
|
||||
test-spinel-decoder \
|
||||
test-spinel-encoder \
|
||||
$(NULL)
|
||||
@@ -202,8 +203,8 @@ test_message_SOURCES = $(COMMON_SOURCES) test_message.cpp
|
||||
test_message_queue_LDADD = $(COMMON_LDADD)
|
||||
test_message_queue_SOURCES = $(COMMON_SOURCES) test_message_queue.cpp
|
||||
|
||||
test_ncp_buffer_LDADD = $(COMMON_LDADD)
|
||||
test_ncp_buffer_SOURCES = $(COMMON_SOURCES) test_ncp_buffer.cpp
|
||||
test_spinel_buffer_LDADD = $(COMMON_LDADD)
|
||||
test_spinel_buffer_SOURCES = $(COMMON_SOURCES) test_spinel_buffer.cpp
|
||||
|
||||
test_netif_LDADD = $(COMMON_LDADD)
|
||||
test_netif_SOURCES = $(COMMON_SOURCES) test_netif.cpp
|
||||
@@ -247,7 +248,7 @@ PRETTY_FILES = \
|
||||
$(test_mac_frame_SOURCES) \
|
||||
$(test_message_queue_SOURCES) \
|
||||
$(test_message_SOURCES) \
|
||||
$(test_ncp_buffer_SOURCES) \
|
||||
$(test_spinel_buffer_SOURCES) \
|
||||
$(test_netif_SOURCES) \
|
||||
$(test_network_data_SOURCES) \
|
||||
$(test_priority_queue_SOURCES) \
|
||||
|
||||
@@ -32,15 +32,15 @@
|
||||
#include "common/instance.hpp"
|
||||
#include "common/message.hpp"
|
||||
#include "common/random.hpp"
|
||||
#include "ncp/ncp_buffer.hpp"
|
||||
#include "spinel/spinel_buffer.hpp"
|
||||
|
||||
#include "test_platform.h"
|
||||
#include "test_util.hpp"
|
||||
|
||||
namespace ot {
|
||||
namespace Ncp {
|
||||
namespace Spinel {
|
||||
|
||||
// This module implements unit-test for NcpFrameBuffer class.
|
||||
// This module implements unit-test for Spinel::Buffer class.
|
||||
|
||||
// Test related constants:
|
||||
enum
|
||||
@@ -78,10 +78,10 @@ enum
|
||||
kTestFrame4Size = sizeof(sOpenThreadText),
|
||||
};
|
||||
|
||||
NcpFrameBuffer::FrameTag sTagHistoryArray[kNumPrios][kTagArraySize];
|
||||
Spinel::Buffer::FrameTag sTagHistoryArray[kNumPrios][kTagArraySize];
|
||||
uint32_t sTagHistoryHead[kNumPrios] = {0};
|
||||
uint32_t sTagHistoryTail[kNumPrios] = {0};
|
||||
NcpFrameBuffer::FrameTag sExpectedRemovedTag = NcpFrameBuffer::kInvalidTag;
|
||||
Spinel::Buffer::FrameTag sExpectedRemovedTag = Spinel::Buffer::kInvalidTag;
|
||||
|
||||
void ClearTagHistory(void)
|
||||
{
|
||||
@@ -91,7 +91,7 @@ void ClearTagHistory(void)
|
||||
}
|
||||
}
|
||||
|
||||
void AddTagToHistory(NcpFrameBuffer::FrameTag aTag, NcpFrameBuffer::Priority aPriority)
|
||||
void AddTagToHistory(Spinel::Buffer::FrameTag aTag, Spinel::Buffer::Priority aPriority)
|
||||
{
|
||||
uint8_t priority = static_cast<uint8_t>(aPriority);
|
||||
|
||||
@@ -106,7 +106,7 @@ void AddTagToHistory(NcpFrameBuffer::FrameTag aTag, NcpFrameBuffer::Priority aPr
|
||||
"Ran out of space in `TagHistoryArray`, increase its size.");
|
||||
}
|
||||
|
||||
void VerifyAndRemoveTagFromHistory(NcpFrameBuffer::FrameTag aTag, NcpFrameBuffer::Priority aPriority)
|
||||
void VerifyAndRemoveTagFromHistory(Spinel::Buffer::FrameTag aTag, Spinel::Buffer::Priority aPriority)
|
||||
{
|
||||
uint8_t priority = static_cast<uint8_t>(aPriority);
|
||||
|
||||
@@ -119,23 +119,23 @@ void VerifyAndRemoveTagFromHistory(NcpFrameBuffer::FrameTag aTag, NcpFrameBuffer
|
||||
sTagHistoryHead[priority] = 0;
|
||||
}
|
||||
|
||||
if (sExpectedRemovedTag != NcpFrameBuffer::kInvalidTag)
|
||||
if (sExpectedRemovedTag != Spinel::Buffer::kInvalidTag)
|
||||
{
|
||||
VerifyOrQuit(sExpectedRemovedTag == aTag, "Removed tag does match the previous OutFrameGetTag()");
|
||||
sExpectedRemovedTag = NcpFrameBuffer::kInvalidTag;
|
||||
sExpectedRemovedTag = Spinel::Buffer::kInvalidTag;
|
||||
}
|
||||
}
|
||||
|
||||
void FrameAddedCallback(void * aContext,
|
||||
NcpFrameBuffer::FrameTag aTag,
|
||||
NcpFrameBuffer::Priority aPriority,
|
||||
NcpFrameBuffer * aNcpBuffer)
|
||||
Spinel::Buffer::FrameTag aTag,
|
||||
Spinel::Buffer::Priority aPriority,
|
||||
Spinel::Buffer * aNcpBuffer)
|
||||
{
|
||||
CallbackContext *callbackContext = reinterpret_cast<CallbackContext *>(aContext);
|
||||
|
||||
VerifyOrQuit(aNcpBuffer != NULL, "Null NcpFrameBuffer in the callback");
|
||||
VerifyOrQuit(aNcpBuffer != NULL, "Null Spinel::Buffer in the callback");
|
||||
VerifyOrQuit(callbackContext != NULL, "Null context in the callback");
|
||||
VerifyOrQuit(aTag != NcpFrameBuffer::kInvalidTag, "Invalid tag in the callback");
|
||||
VerifyOrQuit(aTag != Spinel::Buffer::kInvalidTag, "Invalid tag in the callback");
|
||||
VerifyOrQuit(aTag == aNcpBuffer->InFrameGetLastTag(), "InFrameGetLastTag() does not match the tag from callback");
|
||||
|
||||
AddTagToHistory(aTag, aPriority);
|
||||
@@ -144,15 +144,15 @@ void FrameAddedCallback(void * aContext,
|
||||
}
|
||||
|
||||
void FrameRemovedCallback(void * aContext,
|
||||
NcpFrameBuffer::FrameTag aTag,
|
||||
NcpFrameBuffer::Priority aPriority,
|
||||
NcpFrameBuffer * aNcpBuffer)
|
||||
Spinel::Buffer::FrameTag aTag,
|
||||
Spinel::Buffer::Priority aPriority,
|
||||
Spinel::Buffer * aNcpBuffer)
|
||||
{
|
||||
CallbackContext *callbackContext = reinterpret_cast<CallbackContext *>(aContext);
|
||||
|
||||
VerifyOrQuit(aNcpBuffer != NULL, "Null NcpFrameBuffer in the callback");
|
||||
VerifyOrQuit(aNcpBuffer != NULL, "Null Spinel::Buffer in the callback");
|
||||
VerifyOrQuit(callbackContext != NULL, "Null context in the callback");
|
||||
VerifyOrQuit(aTag != NcpFrameBuffer::kInvalidTag, "Invalid tag in the callback");
|
||||
VerifyOrQuit(aTag != Spinel::Buffer::kInvalidTag, "Invalid tag in the callback");
|
||||
|
||||
VerifyAndRemoveTagFromHistory(aTag, aPriority);
|
||||
|
||||
@@ -160,7 +160,7 @@ void FrameRemovedCallback(void * aContext,
|
||||
}
|
||||
|
||||
// Reads bytes from the ncp buffer, and verifies that it matches with the given content buffer.
|
||||
void ReadAndVerifyContent(NcpFrameBuffer &aNcpBuffer, const uint8_t *aContentBuffer, uint16_t aBufferLength)
|
||||
void ReadAndVerifyContent(Spinel::Buffer &aNcpBuffer, const uint8_t *aContentBuffer, uint16_t aBufferLength)
|
||||
{
|
||||
while (aBufferLength--)
|
||||
{
|
||||
@@ -171,7 +171,7 @@ void ReadAndVerifyContent(NcpFrameBuffer &aNcpBuffer, const uint8_t *aContentBuf
|
||||
}
|
||||
}
|
||||
|
||||
void WriteTestFrame1(NcpFrameBuffer &aNcpBuffer, NcpFrameBuffer::Priority aPriority)
|
||||
void WriteTestFrame1(Spinel::Buffer &aNcpBuffer, Spinel::Buffer::Priority aPriority)
|
||||
{
|
||||
Message * message;
|
||||
CallbackContext oldContext;
|
||||
@@ -192,7 +192,7 @@ void WriteTestFrame1(NcpFrameBuffer &aNcpBuffer, NcpFrameBuffer::Priority aPrior
|
||||
VerifyOrQuit(oldContext.mFrameRemovedCount == sContext.mFrameRemovedCount, "FrameRemovedCallback failed.");
|
||||
}
|
||||
|
||||
void VerifyAndRemoveFrame1(NcpFrameBuffer &aNcpBuffer)
|
||||
void VerifyAndRemoveFrame1(Spinel::Buffer &aNcpBuffer)
|
||||
{
|
||||
CallbackContext oldContext = sContext;
|
||||
|
||||
@@ -214,7 +214,7 @@ void VerifyAndRemoveFrame1(NcpFrameBuffer &aNcpBuffer)
|
||||
VerifyOrQuit(oldContext.mFrameRemovedCount + 1 == sContext.mFrameRemovedCount, "FrameRemovedCallback failed.");
|
||||
}
|
||||
|
||||
void WriteTestFrame2(NcpFrameBuffer &aNcpBuffer, NcpFrameBuffer::Priority aPriority)
|
||||
void WriteTestFrame2(Spinel::Buffer &aNcpBuffer, Spinel::Buffer::Priority aPriority)
|
||||
{
|
||||
Message * message1;
|
||||
Message * message2;
|
||||
@@ -240,7 +240,7 @@ void WriteTestFrame2(NcpFrameBuffer &aNcpBuffer, NcpFrameBuffer::Priority aPrior
|
||||
VerifyOrQuit(oldContext.mFrameRemovedCount == sContext.mFrameRemovedCount, "FrameRemovedCallback failed.");
|
||||
}
|
||||
|
||||
void VerifyAndRemoveFrame2(NcpFrameBuffer &aNcpBuffer)
|
||||
void VerifyAndRemoveFrame2(Spinel::Buffer &aNcpBuffer)
|
||||
{
|
||||
CallbackContext oldContext = sContext;
|
||||
|
||||
@@ -260,7 +260,7 @@ void VerifyAndRemoveFrame2(NcpFrameBuffer &aNcpBuffer)
|
||||
VerifyOrQuit(oldContext.mFrameRemovedCount + 1 == sContext.mFrameRemovedCount, "FrameRemovedCallback failed.");
|
||||
}
|
||||
|
||||
void WriteTestFrame3(NcpFrameBuffer &aNcpBuffer, NcpFrameBuffer::Priority aPriority)
|
||||
void WriteTestFrame3(Spinel::Buffer &aNcpBuffer, Spinel::Buffer::Priority aPriority)
|
||||
{
|
||||
Message * message1;
|
||||
CallbackContext oldContext = sContext;
|
||||
@@ -280,7 +280,7 @@ void WriteTestFrame3(NcpFrameBuffer &aNcpBuffer, NcpFrameBuffer::Priority aPrior
|
||||
VerifyOrQuit(oldContext.mFrameRemovedCount == sContext.mFrameRemovedCount, "FrameRemovedCallback failed.");
|
||||
}
|
||||
|
||||
void VerifyAndRemoveFrame3(NcpFrameBuffer &aNcpBuffer)
|
||||
void VerifyAndRemoveFrame3(Spinel::Buffer &aNcpBuffer)
|
||||
{
|
||||
CallbackContext oldContext = sContext;
|
||||
|
||||
@@ -298,7 +298,7 @@ void VerifyAndRemoveFrame3(NcpFrameBuffer &aNcpBuffer)
|
||||
VerifyOrQuit(oldContext.mFrameRemovedCount + 1 == sContext.mFrameRemovedCount, "FrameRemovedCallback failed.");
|
||||
}
|
||||
|
||||
void WriteTestFrame4(NcpFrameBuffer &aNcpBuffer, NcpFrameBuffer::Priority aPriority)
|
||||
void WriteTestFrame4(Spinel::Buffer &aNcpBuffer, Spinel::Buffer::Priority aPriority)
|
||||
{
|
||||
CallbackContext oldContext = sContext;
|
||||
|
||||
@@ -310,7 +310,7 @@ void WriteTestFrame4(NcpFrameBuffer &aNcpBuffer, NcpFrameBuffer::Priority aPrior
|
||||
VerifyOrQuit(oldContext.mFrameRemovedCount == sContext.mFrameRemovedCount, "FrameRemovedCallback failed.");
|
||||
}
|
||||
|
||||
void VerifyAndRemoveFrame4(NcpFrameBuffer &aNcpBuffer)
|
||||
void VerifyAndRemoveFrame4(Spinel::Buffer &aNcpBuffer)
|
||||
{
|
||||
CallbackContext oldContext = sContext;
|
||||
|
||||
@@ -328,17 +328,17 @@ void VerifyAndRemoveFrame4(NcpFrameBuffer &aNcpBuffer)
|
||||
VerifyOrQuit(oldContext.mFrameRemovedCount + 1 == sContext.mFrameRemovedCount, "FrameRemovedCallback failed.");
|
||||
}
|
||||
|
||||
// This function implements the NcpFrameBuffer tests
|
||||
void TestNcpFrameBuffer(void)
|
||||
// This function implements the Spinel::Buffer tests
|
||||
void TestBuffer(void)
|
||||
{
|
||||
unsigned i, j;
|
||||
uint8_t buffer[kTestBufferSize];
|
||||
NcpFrameBuffer ncpBuffer(buffer, kTestBufferSize);
|
||||
Spinel::Buffer ncpBuffer(buffer, kTestBufferSize);
|
||||
|
||||
Message * message;
|
||||
uint8_t readBuffer[16];
|
||||
uint16_t readLen, readOffset;
|
||||
NcpFrameBuffer::WritePosition pos1, pos2;
|
||||
Spinel::Buffer::WritePosition pos1, pos2;
|
||||
|
||||
sInstance = testInitInstance();
|
||||
sMessagePool = &sInstance->Get<MessagePool>();
|
||||
@@ -360,18 +360,18 @@ void TestNcpFrameBuffer(void)
|
||||
printf("\nTest 1: Check initial buffer state");
|
||||
|
||||
VerifyOrQuit(ncpBuffer.IsEmpty() == true, "Not empty after init.");
|
||||
VerifyOrQuit(ncpBuffer.InFrameGetLastTag() == NcpFrameBuffer::kInvalidTag, "Incorrect tag after init.");
|
||||
VerifyOrQuit(ncpBuffer.OutFrameGetTag() == NcpFrameBuffer::kInvalidTag, "Incorrect OutFrameTag after init.");
|
||||
VerifyOrQuit(ncpBuffer.InFrameGetLastTag() == Spinel::Buffer::kInvalidTag, "Incorrect tag after init.");
|
||||
VerifyOrQuit(ncpBuffer.OutFrameGetTag() == Spinel::Buffer::kInvalidTag, "Incorrect OutFrameTag after init.");
|
||||
|
||||
printf("\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -");
|
||||
printf("\nTest 2: Write and read a single frame");
|
||||
|
||||
WriteTestFrame1(ncpBuffer, NcpFrameBuffer::kPriorityLow);
|
||||
WriteTestFrame1(ncpBuffer, Spinel::Buffer::kPriorityLow);
|
||||
DumpBuffer("\nBuffer after frame1 (low priority)", buffer, kTestBufferSize);
|
||||
printf("\nFrameLen is %u", ncpBuffer.OutFrameGetLength());
|
||||
VerifyAndRemoveFrame1(ncpBuffer);
|
||||
|
||||
WriteTestFrame1(ncpBuffer, NcpFrameBuffer::kPriorityHigh);
|
||||
WriteTestFrame1(ncpBuffer, Spinel::Buffer::kPriorityHigh);
|
||||
DumpBuffer("\nBuffer after frame1 (high priority)", buffer, kTestBufferSize);
|
||||
printf("\nFrameLen is %u", ncpBuffer.OutFrameGetLength());
|
||||
VerifyAndRemoveFrame1(ncpBuffer);
|
||||
@@ -382,7 +382,7 @@ void TestNcpFrameBuffer(void)
|
||||
for (j = 0; j < kTestIterationAttemps; j++)
|
||||
{
|
||||
printf("*");
|
||||
WriteTestFrame1(ncpBuffer, NcpFrameBuffer::kPriorityLow);
|
||||
WriteTestFrame1(ncpBuffer, Spinel::Buffer::kPriorityLow);
|
||||
VerifyOrQuit(ncpBuffer.IsEmpty() == false, "IsEmpty() is incorrect when buffer is non-empty");
|
||||
|
||||
VerifyAndRemoveFrame1(ncpBuffer);
|
||||
@@ -393,7 +393,7 @@ void TestNcpFrameBuffer(void)
|
||||
for (j = 0; j < kTestIterationAttemps; j++)
|
||||
{
|
||||
printf("*");
|
||||
WriteTestFrame1(ncpBuffer, NcpFrameBuffer::kPriorityHigh);
|
||||
WriteTestFrame1(ncpBuffer, Spinel::Buffer::kPriorityHigh);
|
||||
VerifyOrQuit(ncpBuffer.IsEmpty() == false, "IsEmpty() is incorrect when buffer is non-empty");
|
||||
|
||||
VerifyAndRemoveFrame1(ncpBuffer);
|
||||
@@ -404,7 +404,7 @@ void TestNcpFrameBuffer(void)
|
||||
for (j = 0; j < kTestIterationAttemps; j++)
|
||||
{
|
||||
printf("*");
|
||||
WriteTestFrame1(ncpBuffer, ((j % 5) == 0) ? NcpFrameBuffer::kPriorityHigh : NcpFrameBuffer::kPriorityLow);
|
||||
WriteTestFrame1(ncpBuffer, ((j % 5) == 0) ? Spinel::Buffer::kPriorityHigh : Spinel::Buffer::kPriorityLow);
|
||||
VerifyOrQuit(ncpBuffer.IsEmpty() == false, "IsEmpty() is incorrect when buffer is non-empty");
|
||||
|
||||
VerifyAndRemoveFrame1(ncpBuffer);
|
||||
@@ -416,10 +416,10 @@ void TestNcpFrameBuffer(void)
|
||||
printf("\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -");
|
||||
printf("\nTest 3: Multiple frames write and read (same priority)");
|
||||
|
||||
WriteTestFrame2(ncpBuffer, NcpFrameBuffer::kPriorityLow);
|
||||
WriteTestFrame3(ncpBuffer, NcpFrameBuffer::kPriorityLow);
|
||||
WriteTestFrame2(ncpBuffer, NcpFrameBuffer::kPriorityLow);
|
||||
WriteTestFrame2(ncpBuffer, NcpFrameBuffer::kPriorityLow);
|
||||
WriteTestFrame2(ncpBuffer, Spinel::Buffer::kPriorityLow);
|
||||
WriteTestFrame3(ncpBuffer, Spinel::Buffer::kPriorityLow);
|
||||
WriteTestFrame2(ncpBuffer, Spinel::Buffer::kPriorityLow);
|
||||
WriteTestFrame2(ncpBuffer, Spinel::Buffer::kPriorityLow);
|
||||
|
||||
DumpBuffer("\nBuffer after multiple frames", buffer, kTestBufferSize);
|
||||
|
||||
@@ -435,15 +435,15 @@ void TestNcpFrameBuffer(void)
|
||||
{
|
||||
printf("*");
|
||||
|
||||
WriteTestFrame2(ncpBuffer, NcpFrameBuffer::kPriorityLow);
|
||||
WriteTestFrame3(ncpBuffer, NcpFrameBuffer::kPriorityLow);
|
||||
WriteTestFrame2(ncpBuffer, NcpFrameBuffer::kPriorityLow);
|
||||
WriteTestFrame2(ncpBuffer, Spinel::Buffer::kPriorityLow);
|
||||
WriteTestFrame3(ncpBuffer, Spinel::Buffer::kPriorityLow);
|
||||
WriteTestFrame2(ncpBuffer, Spinel::Buffer::kPriorityLow);
|
||||
|
||||
VerifyAndRemoveFrame2(ncpBuffer);
|
||||
VerifyAndRemoveFrame3(ncpBuffer);
|
||||
|
||||
WriteTestFrame2(ncpBuffer, NcpFrameBuffer::kPriorityLow);
|
||||
WriteTestFrame3(ncpBuffer, NcpFrameBuffer::kPriorityLow);
|
||||
WriteTestFrame2(ncpBuffer, Spinel::Buffer::kPriorityLow);
|
||||
WriteTestFrame3(ncpBuffer, Spinel::Buffer::kPriorityLow);
|
||||
|
||||
VerifyAndRemoveFrame2(ncpBuffer);
|
||||
VerifyAndRemoveFrame2(ncpBuffer);
|
||||
@@ -457,52 +457,52 @@ void TestNcpFrameBuffer(void)
|
||||
printf("\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -");
|
||||
printf("\nTest 4: Multiple frames write and read (mixed priority)");
|
||||
|
||||
WriteTestFrame2(ncpBuffer, NcpFrameBuffer::kPriorityLow);
|
||||
WriteTestFrame3(ncpBuffer, NcpFrameBuffer::kPriorityHigh);
|
||||
WriteTestFrame2(ncpBuffer, Spinel::Buffer::kPriorityLow);
|
||||
WriteTestFrame3(ncpBuffer, Spinel::Buffer::kPriorityHigh);
|
||||
VerifyAndRemoveFrame3(ncpBuffer);
|
||||
VerifyAndRemoveFrame2(ncpBuffer);
|
||||
|
||||
WriteTestFrame1(ncpBuffer, NcpFrameBuffer::kPriorityLow);
|
||||
WriteTestFrame2(ncpBuffer, NcpFrameBuffer::kPriorityLow);
|
||||
WriteTestFrame3(ncpBuffer, NcpFrameBuffer::kPriorityHigh);
|
||||
WriteTestFrame4(ncpBuffer, NcpFrameBuffer::kPriorityHigh);
|
||||
WriteTestFrame1(ncpBuffer, Spinel::Buffer::kPriorityLow);
|
||||
WriteTestFrame2(ncpBuffer, Spinel::Buffer::kPriorityLow);
|
||||
WriteTestFrame3(ncpBuffer, Spinel::Buffer::kPriorityHigh);
|
||||
WriteTestFrame4(ncpBuffer, Spinel::Buffer::kPriorityHigh);
|
||||
VerifyAndRemoveFrame3(ncpBuffer);
|
||||
VerifyAndRemoveFrame4(ncpBuffer);
|
||||
VerifyAndRemoveFrame1(ncpBuffer);
|
||||
VerifyAndRemoveFrame2(ncpBuffer);
|
||||
|
||||
WriteTestFrame1(ncpBuffer, NcpFrameBuffer::kPriorityLow);
|
||||
WriteTestFrame2(ncpBuffer, NcpFrameBuffer::kPriorityHigh);
|
||||
WriteTestFrame3(ncpBuffer, NcpFrameBuffer::kPriorityLow);
|
||||
WriteTestFrame4(ncpBuffer, NcpFrameBuffer::kPriorityHigh);
|
||||
WriteTestFrame1(ncpBuffer, Spinel::Buffer::kPriorityLow);
|
||||
WriteTestFrame2(ncpBuffer, Spinel::Buffer::kPriorityHigh);
|
||||
WriteTestFrame3(ncpBuffer, Spinel::Buffer::kPriorityLow);
|
||||
WriteTestFrame4(ncpBuffer, Spinel::Buffer::kPriorityHigh);
|
||||
VerifyAndRemoveFrame2(ncpBuffer);
|
||||
VerifyAndRemoveFrame4(ncpBuffer);
|
||||
VerifyAndRemoveFrame1(ncpBuffer);
|
||||
VerifyAndRemoveFrame3(ncpBuffer);
|
||||
|
||||
WriteTestFrame1(ncpBuffer, NcpFrameBuffer::kPriorityLow);
|
||||
WriteTestFrame2(ncpBuffer, NcpFrameBuffer::kPriorityHigh);
|
||||
WriteTestFrame3(ncpBuffer, NcpFrameBuffer::kPriorityLow);
|
||||
WriteTestFrame4(ncpBuffer, NcpFrameBuffer::kPriorityHigh);
|
||||
WriteTestFrame1(ncpBuffer, Spinel::Buffer::kPriorityLow);
|
||||
WriteTestFrame2(ncpBuffer, Spinel::Buffer::kPriorityHigh);
|
||||
WriteTestFrame3(ncpBuffer, Spinel::Buffer::kPriorityLow);
|
||||
WriteTestFrame4(ncpBuffer, Spinel::Buffer::kPriorityHigh);
|
||||
VerifyAndRemoveFrame2(ncpBuffer);
|
||||
VerifyAndRemoveFrame4(ncpBuffer);
|
||||
VerifyAndRemoveFrame1(ncpBuffer);
|
||||
VerifyAndRemoveFrame3(ncpBuffer);
|
||||
|
||||
WriteTestFrame1(ncpBuffer, NcpFrameBuffer::kPriorityHigh);
|
||||
WriteTestFrame2(ncpBuffer, NcpFrameBuffer::kPriorityHigh);
|
||||
WriteTestFrame3(ncpBuffer, NcpFrameBuffer::kPriorityLow);
|
||||
WriteTestFrame4(ncpBuffer, NcpFrameBuffer::kPriorityLow);
|
||||
WriteTestFrame1(ncpBuffer, Spinel::Buffer::kPriorityHigh);
|
||||
WriteTestFrame2(ncpBuffer, Spinel::Buffer::kPriorityHigh);
|
||||
WriteTestFrame3(ncpBuffer, Spinel::Buffer::kPriorityLow);
|
||||
WriteTestFrame4(ncpBuffer, Spinel::Buffer::kPriorityLow);
|
||||
VerifyAndRemoveFrame1(ncpBuffer);
|
||||
VerifyAndRemoveFrame2(ncpBuffer);
|
||||
VerifyAndRemoveFrame3(ncpBuffer);
|
||||
VerifyAndRemoveFrame4(ncpBuffer);
|
||||
|
||||
WriteTestFrame1(ncpBuffer, NcpFrameBuffer::kPriorityLow);
|
||||
WriteTestFrame2(ncpBuffer, NcpFrameBuffer::kPriorityHigh);
|
||||
WriteTestFrame3(ncpBuffer, NcpFrameBuffer::kPriorityHigh);
|
||||
WriteTestFrame1(ncpBuffer, Spinel::Buffer::kPriorityLow);
|
||||
WriteTestFrame2(ncpBuffer, Spinel::Buffer::kPriorityHigh);
|
||||
WriteTestFrame3(ncpBuffer, Spinel::Buffer::kPriorityHigh);
|
||||
VerifyAndRemoveFrame2(ncpBuffer);
|
||||
WriteTestFrame4(ncpBuffer, NcpFrameBuffer::kPriorityHigh);
|
||||
WriteTestFrame4(ncpBuffer, Spinel::Buffer::kPriorityHigh);
|
||||
VerifyAndRemoveFrame3(ncpBuffer);
|
||||
VerifyAndRemoveFrame4(ncpBuffer);
|
||||
VerifyAndRemoveFrame1(ncpBuffer);
|
||||
@@ -520,10 +520,10 @@ void TestNcpFrameBuffer(void)
|
||||
|
||||
printf("*");
|
||||
|
||||
WriteTestFrame2(ncpBuffer, NcpFrameBuffer::kPriorityLow);
|
||||
WriteTestFrame3(ncpBuffer, NcpFrameBuffer::kPriorityHigh);
|
||||
WriteTestFrame2(ncpBuffer, Spinel::Buffer::kPriorityLow);
|
||||
WriteTestFrame3(ncpBuffer, Spinel::Buffer::kPriorityHigh);
|
||||
|
||||
ncpBuffer.InFrameBegin((j % 2) == 0 ? NcpFrameBuffer::kPriorityHigh : NcpFrameBuffer::kPriorityLow);
|
||||
ncpBuffer.InFrameBegin((j % 2) == 0 ? Spinel::Buffer::kPriorityHigh : Spinel::Buffer::kPriorityLow);
|
||||
ncpBuffer.InFrameFeedData(sHelloText, sizeof(sHelloText));
|
||||
|
||||
message = sMessagePool->New(Message::kTypeIp6, 0);
|
||||
@@ -534,7 +534,7 @@ void TestNcpFrameBuffer(void)
|
||||
ncpBuffer.InFrameFeedMessage(message);
|
||||
|
||||
// Start writing a new frame in middle of an unfinished frame. Ensure the first one is discarded.
|
||||
WriteTestFrame1(ncpBuffer, frame1IsHighPriority ? NcpFrameBuffer::kPriorityHigh : NcpFrameBuffer::kPriorityLow);
|
||||
WriteTestFrame1(ncpBuffer, frame1IsHighPriority ? Spinel::Buffer::kPriorityHigh : Spinel::Buffer::kPriorityLow);
|
||||
|
||||
// Note that message will not be freed by the NCP buffer since the frame associated with it was discarded and
|
||||
// not yet finished/ended.
|
||||
@@ -568,13 +568,13 @@ void TestNcpFrameBuffer(void)
|
||||
printf("\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -");
|
||||
printf("\nTest 6: Clear() and empty buffer method tests");
|
||||
|
||||
WriteTestFrame1(ncpBuffer, NcpFrameBuffer::kPriorityLow);
|
||||
WriteTestFrame1(ncpBuffer, Spinel::Buffer::kPriorityLow);
|
||||
|
||||
ncpBuffer.Clear();
|
||||
ClearTagHistory();
|
||||
|
||||
VerifyOrQuit(ncpBuffer.InFrameGetLastTag() == NcpFrameBuffer::kInvalidTag, "Incorrect last tag after Clear().");
|
||||
VerifyOrQuit(ncpBuffer.OutFrameGetTag() == NcpFrameBuffer::kInvalidTag, "Incorrect OutFrameTag after Clear().");
|
||||
VerifyOrQuit(ncpBuffer.InFrameGetLastTag() == Spinel::Buffer::kInvalidTag, "Incorrect last tag after Clear().");
|
||||
VerifyOrQuit(ncpBuffer.OutFrameGetTag() == Spinel::Buffer::kInvalidTag, "Incorrect OutFrameTag after Clear().");
|
||||
VerifyOrQuit(ncpBuffer.IsEmpty() == true, "IsEmpty() is incorrect when buffer is empty.");
|
||||
VerifyOrQuit(ncpBuffer.OutFrameHasEnded() == true, "OutFrameHasEnded() is incorrect when no data in buffer.");
|
||||
VerifyOrQuit(ncpBuffer.OutFrameRemove() == OT_ERROR_NOT_FOUND,
|
||||
@@ -582,7 +582,7 @@ void TestNcpFrameBuffer(void)
|
||||
VerifyOrQuit(ncpBuffer.OutFrameGetLength() == 0,
|
||||
"OutFrameGetLength() returned non-zero length when buffer is empty.");
|
||||
|
||||
WriteTestFrame1(ncpBuffer, NcpFrameBuffer::kPriorityLow);
|
||||
WriteTestFrame1(ncpBuffer, Spinel::Buffer::kPriorityLow);
|
||||
VerifyAndRemoveFrame1(ncpBuffer);
|
||||
|
||||
VerifyOrQuit(ncpBuffer.IsEmpty() == true, "IsEmpty() is incorrect when buffer is empty.");
|
||||
@@ -597,7 +597,7 @@ void TestNcpFrameBuffer(void)
|
||||
printf("\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -");
|
||||
printf("\nTest 7: OutFrameRead() in parts\n");
|
||||
|
||||
ncpBuffer.InFrameBegin(NcpFrameBuffer::kPriorityLow);
|
||||
ncpBuffer.InFrameBegin(Spinel::Buffer::kPriorityLow);
|
||||
ncpBuffer.InFrameFeedData(sMottoText, sizeof(sMottoText));
|
||||
ncpBuffer.InFrameEnd();
|
||||
|
||||
@@ -623,8 +623,8 @@ void TestNcpFrameBuffer(void)
|
||||
printf("\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -");
|
||||
printf("\nTest 8: Remove a frame without reading it first");
|
||||
|
||||
WriteTestFrame1(ncpBuffer, NcpFrameBuffer::kPriorityLow);
|
||||
WriteTestFrame2(ncpBuffer, NcpFrameBuffer::kPriorityLow);
|
||||
WriteTestFrame1(ncpBuffer, Spinel::Buffer::kPriorityLow);
|
||||
WriteTestFrame2(ncpBuffer, Spinel::Buffer::kPriorityLow);
|
||||
VerifyOrQuit(ncpBuffer.OutFrameGetLength() == kTestFrame1Size, "GetLength() is incorrect.");
|
||||
SuccessOrQuit(ncpBuffer.OutFrameRemove(), "Remove() failed.");
|
||||
VerifyAndRemoveFrame2(ncpBuffer);
|
||||
@@ -632,9 +632,9 @@ void TestNcpFrameBuffer(void)
|
||||
|
||||
printf("\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -");
|
||||
printf("\nTest 9: Check length when front frame gets changed (a higher priority frame is added)");
|
||||
WriteTestFrame1(ncpBuffer, NcpFrameBuffer::kPriorityLow);
|
||||
WriteTestFrame1(ncpBuffer, Spinel::Buffer::kPriorityLow);
|
||||
VerifyOrQuit(ncpBuffer.OutFrameGetLength() == kTestFrame1Size, "GetLength() is incorrect.");
|
||||
WriteTestFrame3(ncpBuffer, NcpFrameBuffer::kPriorityHigh);
|
||||
WriteTestFrame3(ncpBuffer, Spinel::Buffer::kPriorityHigh);
|
||||
VerifyOrQuit(ncpBuffer.OutFrameGetLength() == kTestFrame3Size, "GetLength() is incorrect.");
|
||||
VerifyAndRemoveFrame3(ncpBuffer);
|
||||
VerifyAndRemoveFrame1(ncpBuffer);
|
||||
@@ -642,12 +642,12 @@ void TestNcpFrameBuffer(void)
|
||||
|
||||
printf("\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -");
|
||||
printf("\nTest 10: Active out frame remaining unchanged when a higher priority frame is written while reading it");
|
||||
WriteTestFrame1(ncpBuffer, NcpFrameBuffer::kPriorityLow);
|
||||
WriteTestFrame1(ncpBuffer, Spinel::Buffer::kPriorityLow);
|
||||
VerifyOrQuit(ncpBuffer.OutFrameGetLength() == kTestFrame1Size, "GetLength() is incorrect.");
|
||||
SuccessOrQuit(ncpBuffer.OutFrameBegin(), "OutFrameBegin() failed unexpectedly.");
|
||||
VerifyOrQuit(ncpBuffer.OutFrameGetLength() == kTestFrame1Size, "GetLength() is incorrect.");
|
||||
ReadAndVerifyContent(ncpBuffer, sMottoText, sizeof(sMottoText));
|
||||
WriteTestFrame2(ncpBuffer, NcpFrameBuffer::kPriorityHigh);
|
||||
WriteTestFrame2(ncpBuffer, Spinel::Buffer::kPriorityHigh);
|
||||
VerifyOrQuit(ncpBuffer.OutFrameGetLength() == kTestFrame1Size, "GetLength() is incorrect.");
|
||||
ReadAndVerifyContent(ncpBuffer, sMysteryText, sizeof(sMysteryText));
|
||||
SuccessOrQuit(ncpBuffer.OutFrameBegin(), "OutFrameBegin() failed unexpectedly.");
|
||||
@@ -657,20 +657,20 @@ void TestNcpFrameBuffer(void)
|
||||
ReadAndVerifyContent(ncpBuffer, sMottoText, sizeof(sMottoText));
|
||||
ReadAndVerifyContent(ncpBuffer, sHelloText, sizeof(sHelloText));
|
||||
VerifyOrQuit(ncpBuffer.OutFrameHasEnded() == true, "Frame longer than expected.");
|
||||
WriteTestFrame3(ncpBuffer, NcpFrameBuffer::kPriorityHigh);
|
||||
WriteTestFrame4(ncpBuffer, NcpFrameBuffer::kPriorityLow);
|
||||
WriteTestFrame3(ncpBuffer, Spinel::Buffer::kPriorityHigh);
|
||||
WriteTestFrame4(ncpBuffer, Spinel::Buffer::kPriorityLow);
|
||||
VerifyOrQuit(ncpBuffer.OutFrameGetLength() == kTestFrame1Size, "GetLength() is incorrect.");
|
||||
VerifyAndRemoveFrame1(ncpBuffer);
|
||||
VerifyAndRemoveFrame2(ncpBuffer);
|
||||
VerifyAndRemoveFrame3(ncpBuffer);
|
||||
VerifyAndRemoveFrame4(ncpBuffer);
|
||||
// Repeat test reversing frame priority orders.
|
||||
WriteTestFrame1(ncpBuffer, NcpFrameBuffer::kPriorityHigh);
|
||||
WriteTestFrame1(ncpBuffer, Spinel::Buffer::kPriorityHigh);
|
||||
VerifyOrQuit(ncpBuffer.OutFrameGetLength() == kTestFrame1Size, "GetLength() is incorrect.");
|
||||
SuccessOrQuit(ncpBuffer.OutFrameBegin(), "OutFrameBegin() failed unexpectedly.");
|
||||
VerifyOrQuit(ncpBuffer.OutFrameGetLength() == kTestFrame1Size, "GetLength() is incorrect.");
|
||||
ReadAndVerifyContent(ncpBuffer, sMottoText, sizeof(sMottoText));
|
||||
WriteTestFrame2(ncpBuffer, NcpFrameBuffer::kPriorityLow);
|
||||
WriteTestFrame2(ncpBuffer, Spinel::Buffer::kPriorityLow);
|
||||
VerifyOrQuit(ncpBuffer.OutFrameGetLength() == kTestFrame1Size, "GetLength() is incorrect.");
|
||||
ReadAndVerifyContent(ncpBuffer, sMysteryText, sizeof(sMysteryText));
|
||||
SuccessOrQuit(ncpBuffer.OutFrameBegin(), "OutFrameBegin() failed unexpectedly.");
|
||||
@@ -680,8 +680,8 @@ void TestNcpFrameBuffer(void)
|
||||
ReadAndVerifyContent(ncpBuffer, sMottoText, sizeof(sMottoText));
|
||||
ReadAndVerifyContent(ncpBuffer, sHelloText, sizeof(sHelloText));
|
||||
VerifyOrQuit(ncpBuffer.OutFrameHasEnded() == true, "Frame longer than expected.");
|
||||
WriteTestFrame3(ncpBuffer, NcpFrameBuffer::kPriorityHigh);
|
||||
WriteTestFrame4(ncpBuffer, NcpFrameBuffer::kPriorityLow);
|
||||
WriteTestFrame3(ncpBuffer, Spinel::Buffer::kPriorityHigh);
|
||||
WriteTestFrame4(ncpBuffer, Spinel::Buffer::kPriorityLow);
|
||||
VerifyOrQuit(ncpBuffer.OutFrameGetLength() == kTestFrame1Size, "GetLength() is incorrect.");
|
||||
VerifyAndRemoveFrame1(ncpBuffer);
|
||||
VerifyAndRemoveFrame3(ncpBuffer);
|
||||
@@ -691,24 +691,24 @@ void TestNcpFrameBuffer(void)
|
||||
|
||||
printf("\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -");
|
||||
printf("\n Test 11: Read and remove in middle of an active input frame write");
|
||||
WriteTestFrame1(ncpBuffer, NcpFrameBuffer::kPriorityLow);
|
||||
ncpBuffer.InFrameBegin(NcpFrameBuffer::kPriorityHigh);
|
||||
WriteTestFrame1(ncpBuffer, Spinel::Buffer::kPriorityLow);
|
||||
ncpBuffer.InFrameBegin(Spinel::Buffer::kPriorityHigh);
|
||||
SuccessOrQuit(ncpBuffer.InFrameFeedData(sOpenThreadText, sizeof(sOpenThreadText)), "InFrameFeedData() failed.");
|
||||
VerifyAndRemoveFrame1(ncpBuffer);
|
||||
VerifyOrQuit(ncpBuffer.IsEmpty() == true, "IsEmpty() failed.");
|
||||
SuccessOrQuit(ncpBuffer.InFrameEnd(), "InFrameEnd() failed.");
|
||||
VerifyAndRemoveFrame4(ncpBuffer);
|
||||
// Repeat the test reversing priorities
|
||||
WriteTestFrame1(ncpBuffer, NcpFrameBuffer::kPriorityHigh);
|
||||
ncpBuffer.InFrameBegin(NcpFrameBuffer::kPriorityLow);
|
||||
WriteTestFrame1(ncpBuffer, Spinel::Buffer::kPriorityHigh);
|
||||
ncpBuffer.InFrameBegin(Spinel::Buffer::kPriorityLow);
|
||||
SuccessOrQuit(ncpBuffer.InFrameFeedData(sOpenThreadText, sizeof(sOpenThreadText)), "InFrameFeedData() failed.");
|
||||
VerifyAndRemoveFrame1(ncpBuffer);
|
||||
VerifyOrQuit(ncpBuffer.IsEmpty() == true, "IsEmpty() failed.");
|
||||
SuccessOrQuit(ncpBuffer.InFrameEnd(), "InFrameEnd() failed.");
|
||||
VerifyAndRemoveFrame4(ncpBuffer);
|
||||
// Repeat the test with same priorities
|
||||
WriteTestFrame1(ncpBuffer, NcpFrameBuffer::kPriorityHigh);
|
||||
ncpBuffer.InFrameBegin(NcpFrameBuffer::kPriorityHigh);
|
||||
WriteTestFrame1(ncpBuffer, Spinel::Buffer::kPriorityHigh);
|
||||
ncpBuffer.InFrameBegin(Spinel::Buffer::kPriorityHigh);
|
||||
SuccessOrQuit(ncpBuffer.InFrameFeedData(sOpenThreadText, sizeof(sOpenThreadText)), "InFrameFeedData() failed.");
|
||||
VerifyAndRemoveFrame1(ncpBuffer);
|
||||
VerifyOrQuit(ncpBuffer.IsEmpty() == true, "IsEmpty() failed.");
|
||||
@@ -718,14 +718,14 @@ void TestNcpFrameBuffer(void)
|
||||
|
||||
printf("\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -");
|
||||
printf("\n Test 12: Check returned error status");
|
||||
WriteTestFrame1(ncpBuffer, NcpFrameBuffer::kPriorityLow);
|
||||
ncpBuffer.InFrameBegin(NcpFrameBuffer::kPriorityHigh);
|
||||
WriteTestFrame1(ncpBuffer, Spinel::Buffer::kPriorityLow);
|
||||
ncpBuffer.InFrameBegin(Spinel::Buffer::kPriorityHigh);
|
||||
VerifyOrQuit(ncpBuffer.InFrameFeedData(buffer, sizeof(buffer)) == OT_ERROR_NO_BUFS, "Incorrect error status");
|
||||
VerifyAndRemoveFrame1(ncpBuffer);
|
||||
VerifyOrQuit(ncpBuffer.IsEmpty() == true, "IsEmpty() failed.");
|
||||
|
||||
WriteTestFrame1(ncpBuffer, NcpFrameBuffer::kPriorityLow);
|
||||
WriteTestFrame2(ncpBuffer, NcpFrameBuffer::kPriorityHigh);
|
||||
WriteTestFrame1(ncpBuffer, Spinel::Buffer::kPriorityLow);
|
||||
WriteTestFrame2(ncpBuffer, Spinel::Buffer::kPriorityHigh);
|
||||
// Ensure writes with starting `InFrameBegin()` fail
|
||||
VerifyOrQuit(ncpBuffer.InFrameFeedData(sOpenThreadText, 1) == OT_ERROR_INVALID_STATE, "Incorrect error status");
|
||||
VerifyOrQuit(ncpBuffer.InFrameFeedData(sOpenThreadText, 0) == OT_ERROR_INVALID_STATE, "Incorrect error status");
|
||||
@@ -742,25 +742,25 @@ void TestNcpFrameBuffer(void)
|
||||
VerifyAndRemoveFrame1(ncpBuffer);
|
||||
VerifyOrQuit(ncpBuffer.IsEmpty(), "IsEmpty() failed");
|
||||
VerifyOrQuit(ncpBuffer.OutFrameBegin() == OT_ERROR_NOT_FOUND, "OutFrameBegin() failed on empty queue");
|
||||
WriteTestFrame1(ncpBuffer, NcpFrameBuffer::kPriorityHigh);
|
||||
WriteTestFrame1(ncpBuffer, Spinel::Buffer::kPriorityHigh);
|
||||
VerifyAndRemoveFrame1(ncpBuffer);
|
||||
VerifyOrQuit(ncpBuffer.IsEmpty(), "IsEmpty() failed");
|
||||
printf(" -- PASS\n");
|
||||
|
||||
printf("\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -");
|
||||
printf("\n Test 13: Ensure we can utilize the full buffer size when frames removed during write");
|
||||
WriteTestFrame1(ncpBuffer, NcpFrameBuffer::kPriorityHigh);
|
||||
WriteTestFrame2(ncpBuffer, NcpFrameBuffer::kPriorityLow);
|
||||
ncpBuffer.InFrameBegin(NcpFrameBuffer::kPriorityHigh);
|
||||
WriteTestFrame1(ncpBuffer, Spinel::Buffer::kPriorityHigh);
|
||||
WriteTestFrame2(ncpBuffer, Spinel::Buffer::kPriorityLow);
|
||||
ncpBuffer.InFrameBegin(Spinel::Buffer::kPriorityHigh);
|
||||
VerifyAndRemoveFrame1(ncpBuffer);
|
||||
VerifyAndRemoveFrame2(ncpBuffer);
|
||||
SuccessOrQuit(ncpBuffer.InFrameFeedData(buffer, sizeof(buffer) - 4), "InFrameFeedData() failed.");
|
||||
SuccessOrQuit(ncpBuffer.InFrameEnd(), "InFrameEnd() failed.");
|
||||
SuccessOrQuit(ncpBuffer.OutFrameRemove(), "OutFrameRemove() failed.");
|
||||
// Repeat the test with a low priority buffer write
|
||||
WriteTestFrame1(ncpBuffer, NcpFrameBuffer::kPriorityHigh);
|
||||
WriteTestFrame2(ncpBuffer, NcpFrameBuffer::kPriorityLow);
|
||||
ncpBuffer.InFrameBegin(NcpFrameBuffer::kPriorityLow);
|
||||
WriteTestFrame1(ncpBuffer, Spinel::Buffer::kPriorityHigh);
|
||||
WriteTestFrame2(ncpBuffer, Spinel::Buffer::kPriorityLow);
|
||||
ncpBuffer.InFrameBegin(Spinel::Buffer::kPriorityLow);
|
||||
VerifyAndRemoveFrame1(ncpBuffer);
|
||||
VerifyAndRemoveFrame2(ncpBuffer);
|
||||
SuccessOrQuit(ncpBuffer.InFrameFeedData(buffer, sizeof(buffer) - 4), "InFrameFeedData() failed.");
|
||||
@@ -776,10 +776,10 @@ void TestNcpFrameBuffer(void)
|
||||
{
|
||||
uint16_t index;
|
||||
bool addExtra = ((j % 7) != 0);
|
||||
NcpFrameBuffer::Priority priority;
|
||||
Spinel::Buffer::Priority priority;
|
||||
|
||||
printf("*");
|
||||
priority = ((j % 3) == 0) ? NcpFrameBuffer::kPriorityHigh : NcpFrameBuffer::kPriorityLow;
|
||||
priority = ((j % 3) == 0) ? Spinel::Buffer::kPriorityHigh : Spinel::Buffer::kPriorityLow;
|
||||
index = static_cast<uint16_t>(j % sizeof(sHexText));
|
||||
ncpBuffer.InFrameBegin(priority);
|
||||
SuccessOrQuit(ncpBuffer.InFrameFeedData(sHexText, index), "InFrameFeedData() failed.");
|
||||
@@ -822,10 +822,10 @@ void TestNcpFrameBuffer(void)
|
||||
{
|
||||
uint16_t index;
|
||||
bool addExtra = ((j % 7) != 0);
|
||||
NcpFrameBuffer::Priority priority;
|
||||
Spinel::Buffer::Priority priority;
|
||||
|
||||
printf("*");
|
||||
priority = ((j % 3) == 0) ? NcpFrameBuffer::kPriorityHigh : NcpFrameBuffer::kPriorityLow;
|
||||
priority = ((j % 3) == 0) ? Spinel::Buffer::kPriorityHigh : Spinel::Buffer::kPriorityLow;
|
||||
index = static_cast<uint16_t>(j % sizeof(sHexText));
|
||||
ncpBuffer.InFrameBegin(priority);
|
||||
SuccessOrQuit(ncpBuffer.InFrameFeedData(sHexText, index), "InFrameFeedData() failed.");
|
||||
@@ -903,7 +903,7 @@ uint32_t GetRandom(uint32_t max)
|
||||
return value % max;
|
||||
}
|
||||
|
||||
otError WriteRandomFrame(uint32_t aLength, NcpFrameBuffer &aNcpBuffer, NcpFrameBuffer::Priority aPriority)
|
||||
otError WriteRandomFrame(uint32_t aLength, Spinel::Buffer &aNcpBuffer, Spinel::Buffer::Priority aPriority)
|
||||
{
|
||||
otError error;
|
||||
uint8_t byte;
|
||||
@@ -932,7 +932,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError ReadRandomFrame(uint32_t aLength, NcpFrameBuffer &aNcpBuffer, uint8_t priority)
|
||||
otError ReadRandomFrame(uint32_t aLength, Spinel::Buffer &aNcpBuffer, uint8_t priority)
|
||||
{
|
||||
CallbackContext oldContext = sContext;
|
||||
|
||||
@@ -956,10 +956,10 @@ otError ReadRandomFrame(uint32_t aLength, NcpFrameBuffer &aNcpBuffer, uint8_t pr
|
||||
}
|
||||
|
||||
// This runs a fuzz test of NCP buffer
|
||||
void TestFuzzNcpFrameBuffer(void)
|
||||
void TestFuzzBuffer(void)
|
||||
{
|
||||
uint8_t buffer[kFuzTestBufferSize];
|
||||
NcpFrameBuffer ncpBuffer(buffer, kFuzTestBufferSize);
|
||||
Spinel::Buffer ncpBuffer(buffer, kFuzTestBufferSize);
|
||||
|
||||
uint32_t lensArray[kNumPrios][kLensArraySize]; // Keeps track of length of written frames so far
|
||||
uint32_t lensArrayStart[kNumPrios];
|
||||
@@ -1004,29 +1004,29 @@ void TestFuzzNcpFrameBuffer(void)
|
||||
uint32_t len;
|
||||
uint8_t priority;
|
||||
|
||||
priority = (lensArrayCount[NcpFrameBuffer::kPriorityHigh] != 0) ? NcpFrameBuffer::kPriorityHigh
|
||||
: NcpFrameBuffer::kPriorityLow;
|
||||
priority = (lensArrayCount[Spinel::Buffer::kPriorityHigh] != 0) ? Spinel::Buffer::kPriorityHigh
|
||||
: Spinel::Buffer::kPriorityLow;
|
||||
|
||||
len = lensArray[priority][lensArrayStart[priority]];
|
||||
lensArrayStart[priority] = (lensArrayStart[priority] + 1) % kLensArraySize;
|
||||
lensArrayCount[priority]--;
|
||||
|
||||
printf("R%c%d ", priority == NcpFrameBuffer::kPriorityHigh ? 'H' : 'L', len);
|
||||
printf("R%c%d ", priority == Spinel::Buffer::kPriorityHigh ? 'H' : 'L', len);
|
||||
|
||||
SuccessOrQuit(ReadRandomFrame(len, ncpBuffer, priority), "Failed to read random frame.");
|
||||
}
|
||||
else
|
||||
{
|
||||
uint32_t len = GetRandom(kMaxFrameLen) + 1;
|
||||
NcpFrameBuffer::Priority priority;
|
||||
Spinel::Buffer::Priority priority;
|
||||
|
||||
if (GetRandom(100) < kHighPriorityProbablity)
|
||||
{
|
||||
priority = NcpFrameBuffer::kPriorityHigh;
|
||||
priority = Spinel::Buffer::kPriorityHigh;
|
||||
}
|
||||
else
|
||||
{
|
||||
priority = NcpFrameBuffer::kPriorityLow;
|
||||
priority = Spinel::Buffer::kPriorityLow;
|
||||
}
|
||||
|
||||
if (WriteRandomFrame(len, ncpBuffer, priority) == OT_ERROR_NONE)
|
||||
@@ -1034,7 +1034,7 @@ void TestFuzzNcpFrameBuffer(void)
|
||||
lensArray[priority][(lensArrayStart[priority] + lensArrayCount[priority]) % kLensArraySize] = len;
|
||||
lensArrayCount[priority]++;
|
||||
|
||||
printf("W%c%d ", priority == NcpFrameBuffer::kPriorityHigh ? 'H' : 'L', len);
|
||||
printf("W%c%d ", priority == Spinel::Buffer::kPriorityHigh ? 'H' : 'L', len);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1054,13 +1054,13 @@ void TestFuzzNcpFrameBuffer(void)
|
||||
testFreeInstance(sInstance);
|
||||
}
|
||||
|
||||
} // namespace Ncp
|
||||
} // namespace Spinel
|
||||
} // namespace ot
|
||||
|
||||
int main(void)
|
||||
{
|
||||
ot::Ncp::TestNcpFrameBuffer();
|
||||
ot::Ncp::TestFuzzNcpFrameBuffer();
|
||||
ot::Spinel::TestBuffer();
|
||||
ot::Spinel::TestFuzzBuffer();
|
||||
printf("\nAll tests passed.\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -28,22 +28,22 @@
|
||||
|
||||
#include "common/code_utils.hpp"
|
||||
#include "common/instance.hpp"
|
||||
#include "ncp/spinel_decoder.hpp"
|
||||
#include "spinel/spinel_decoder.hpp"
|
||||
|
||||
#include "test_util.hpp"
|
||||
|
||||
namespace ot {
|
||||
namespace Ncp {
|
||||
namespace Spinel {
|
||||
|
||||
enum
|
||||
{
|
||||
kTestBufferSize = 800,
|
||||
};
|
||||
|
||||
void TestSpinelDecoder(void)
|
||||
void TestDecoder(void)
|
||||
{
|
||||
uint8_t buffer[kTestBufferSize];
|
||||
SpinelDecoder decoder;
|
||||
uint8_t buffer[kTestBufferSize];
|
||||
Spinel::Decoder decoder;
|
||||
|
||||
spinel_ssize_t frameLen;
|
||||
|
||||
@@ -638,12 +638,12 @@ void TestSpinelDecoder(void)
|
||||
printf(" -- PASS\n");
|
||||
}
|
||||
|
||||
} // namespace Ncp
|
||||
} // namespace Spinel
|
||||
} // namespace ot
|
||||
|
||||
int main(void)
|
||||
{
|
||||
ot::Ncp::TestSpinelDecoder();
|
||||
ot::Spinel::Decoder();
|
||||
printf("\nAll tests passed.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -28,19 +28,19 @@
|
||||
|
||||
#include "common/code_utils.hpp"
|
||||
#include "common/instance.hpp"
|
||||
#include "ncp/spinel_encoder.hpp"
|
||||
#include "spinel/spinel_encoder.hpp"
|
||||
|
||||
#include "test_util.hpp"
|
||||
|
||||
namespace ot {
|
||||
namespace Ncp {
|
||||
namespace Spinel {
|
||||
|
||||
enum
|
||||
{
|
||||
kTestBufferSize = 800,
|
||||
};
|
||||
|
||||
otError ReadFrame(NcpFrameBuffer &aNcpBuffer, uint8_t *aFrame, uint16_t &aFrameLen)
|
||||
otError ReadFrame(Spinel::Buffer &aNcpBuffer, uint8_t *aFrame, uint16_t &aFrameLen)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
@@ -53,11 +53,11 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
void TestSpinelEncoder(void)
|
||||
void TestEncoder(void)
|
||||
{
|
||||
uint8_t buffer[kTestBufferSize];
|
||||
NcpFrameBuffer ncpBuffer(buffer, kTestBufferSize);
|
||||
SpinelEncoder encoder(ncpBuffer);
|
||||
uint8_t buffer[kTestBufferSize];
|
||||
Spinel::Buffer ncpBuffer(buffer, kTestBufferSize);
|
||||
Spinel::Encoder encoder(ncpBuffer);
|
||||
|
||||
uint8_t frame[kTestBufferSize];
|
||||
uint16_t frameLen;
|
||||
@@ -117,7 +117,7 @@ void TestSpinelEncoder(void)
|
||||
printf("\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -");
|
||||
printf("\nTest 1: Encoding of simple types");
|
||||
|
||||
SuccessOrQuit(encoder.BeginFrame(NcpFrameBuffer::kPriorityLow), "BeginFrame() failed.");
|
||||
SuccessOrQuit(encoder.BeginFrame(Spinel::Buffer::kPriorityLow), "BeginFrame() failed.");
|
||||
SuccessOrQuit(encoder.WriteBool(kBool_1), "WriteBool() failed.");
|
||||
SuccessOrQuit(encoder.WriteBool(kBool_2), "WriteBool() failed.");
|
||||
SuccessOrQuit(encoder.WriteUint8(kUint8), "WriteUint8() failed.");
|
||||
@@ -183,7 +183,7 @@ void TestSpinelEncoder(void)
|
||||
printf("\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -");
|
||||
printf("\nTest 2: Test a single simple struct.");
|
||||
|
||||
SuccessOrQuit(encoder.BeginFrame(NcpFrameBuffer::kPriorityLow), "BeginFrame() failed.");
|
||||
SuccessOrQuit(encoder.BeginFrame(Spinel::Buffer::kPriorityLow), "BeginFrame() failed.");
|
||||
SuccessOrQuit(encoder.WriteUint8(kUint8), "WriteUint8() failed.");
|
||||
SuccessOrQuit(encoder.OpenStruct(), "OpenStruct() failed.");
|
||||
{
|
||||
@@ -230,7 +230,7 @@ void TestSpinelEncoder(void)
|
||||
printf("\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -");
|
||||
printf("\nTest 3: Test multiple structs and struct within struct.");
|
||||
|
||||
SuccessOrQuit(encoder.BeginFrame(NcpFrameBuffer::kPriorityLow), "BeginFrame() failed.");
|
||||
SuccessOrQuit(encoder.BeginFrame(Spinel::Buffer::kPriorityLow), "BeginFrame() failed.");
|
||||
SuccessOrQuit(encoder.OpenStruct(), "OpenStruct() failed.");
|
||||
{
|
||||
SuccessOrQuit(encoder.WriteUint8(kUint8), "WriteUint8() failed.");
|
||||
@@ -279,7 +279,7 @@ void TestSpinelEncoder(void)
|
||||
printf("\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -");
|
||||
printf("\nTest 4: Test unclosed struct.");
|
||||
|
||||
SuccessOrQuit(encoder.BeginFrame(NcpFrameBuffer::kPriorityLow), "BeginFrame() failed.");
|
||||
SuccessOrQuit(encoder.BeginFrame(Spinel::Buffer::kPriorityLow), "BeginFrame() failed.");
|
||||
SuccessOrQuit(encoder.WriteUint8(kUint8), "WriteUint8() failed.");
|
||||
SuccessOrQuit(encoder.OpenStruct(), "OpenStruct() failed.");
|
||||
{
|
||||
@@ -312,7 +312,7 @@ void TestSpinelEncoder(void)
|
||||
printf("\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -");
|
||||
printf("\nTest 5: Test saving position and reseting back to a saved position");
|
||||
|
||||
SuccessOrQuit(encoder.BeginFrame(NcpFrameBuffer::kPriorityLow), "BeginFrame() failed.");
|
||||
SuccessOrQuit(encoder.BeginFrame(Spinel::Buffer::kPriorityLow), "BeginFrame() failed.");
|
||||
SuccessOrQuit(encoder.WriteUint8(kUint8), "WriteUint8() failed.");
|
||||
SuccessOrQuit(encoder.OpenStruct(), "OpenStruct() failed.");
|
||||
{
|
||||
@@ -357,12 +357,12 @@ void TestSpinelEncoder(void)
|
||||
printf(" -- PASS\n");
|
||||
}
|
||||
|
||||
} // namespace Ncp
|
||||
} // namespace Spinel
|
||||
} // namespace ot
|
||||
|
||||
int main(void)
|
||||
{
|
||||
ot::Ncp::TestSpinelEncoder();
|
||||
ot::Spinel::TestEncoder();
|
||||
printf("\nAll tests passed.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user