From b8333732fa543b32ecf10cd8eec2f8988821436e Mon Sep 17 00:00:00 2001 From: Yakun Xu Date: Thu, 21 Jun 2018 04:15:13 +0800 Subject: [PATCH] [ncp] make NCP sources pretty (#2811) --- src/Makefile.am | 1 + src/ncp/changed_props_set.cpp | 72 +- src/ncp/changed_props_set.hpp | 28 +- src/ncp/hdlc.cpp | 125 ++-- src/ncp/hdlc.hpp | 24 +- src/ncp/ncp_base.cpp | 319 +++++---- src/ncp/ncp_base.hpp | 165 +++-- src/ncp/ncp_base_ftd.cpp | 148 ++-- src/ncp/ncp_base_mtd.cpp | 467 ++++++------- src/ncp/ncp_base_radio.cpp | 84 +-- src/ncp/ncp_buffer.cpp | 123 ++-- src/ncp/ncp_buffer.hpp | 137 ++-- src/ncp/ncp_spi.hpp | 38 +- src/ncp/ncp_uart.cpp | 56 +- src/ncp/ncp_uart.hpp | 69 +- src/ncp/spinel.c | 297 ++++---- src/ncp/spinel.h | 1240 ++++++++++++++++----------------- src/ncp/spinel_decoder.cpp | 88 ++- src/ncp/spinel_decoder.hpp | 59 +- src/ncp/spinel_encoder.cpp | 32 +- src/ncp/spinel_encoder.hpp | 37 +- src/ncp/spinel_platform.h | 4 +- 22 files changed, 1752 insertions(+), 1861 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index dd2b58c5c..b4ae2bce5 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -60,6 +60,7 @@ endif PRETTY_SUBDIRS = \ cli \ core \ + ncp \ $(NULL) include $(abs_top_nlbuild_autotools_dir)/automake/post.am diff --git a/src/ncp/changed_props_set.cpp b/src/ncp/changed_props_set.cpp index 1c70593ee..59540ba5e 100644 --- a/src/ncp/changed_props_set.cpp +++ b/src/ncp/changed_props_set.cpp @@ -25,7 +25,6 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - #include "changed_props_set.hpp" #include "common/code_utils.hpp" @@ -45,44 +44,43 @@ namespace Ncp { // Since a `uint32_t` is used as bit-mask to track which entries are in the changed set, we should ensure that the // number of entries in the list is always less than or equal to 32. // -const ChangedPropsSet::Entry ChangedPropsSet::mSupportedProps[] = -{ +const ChangedPropsSet::Entry ChangedPropsSet::mSupportedProps[] = { // Spinel property Status (if prop is `LAST_STATUS`) IsFilterable? - { SPINEL_PROP_LAST_STATUS, SPINEL_STATUS_RESET_UNKNOWN, false }, // 0 - { SPINEL_PROP_STREAM_DEBUG, SPINEL_STATUS_OK, true }, // 1 - { SPINEL_PROP_IPV6_ADDRESS_TABLE, SPINEL_STATUS_OK, true }, // 2 - { SPINEL_PROP_NET_ROLE, SPINEL_STATUS_OK, true }, // 3 - { SPINEL_PROP_IPV6_LL_ADDR, SPINEL_STATUS_OK, true }, // 4 - { SPINEL_PROP_IPV6_ML_ADDR, SPINEL_STATUS_OK, true }, // 5 - { SPINEL_PROP_NET_PARTITION_ID, SPINEL_STATUS_OK, true }, // 6 - { SPINEL_PROP_NET_KEY_SEQUENCE_COUNTER, SPINEL_STATUS_OK, true }, // 7 - { SPINEL_PROP_THREAD_LEADER_NETWORK_DATA, SPINEL_STATUS_OK, true }, // 8 - { SPINEL_PROP_THREAD_CHILD_TABLE, SPINEL_STATUS_OK, true }, // 9 - { SPINEL_PROP_THREAD_ON_MESH_NETS, SPINEL_STATUS_OK, true }, // 10 - { SPINEL_PROP_THREAD_OFF_MESH_ROUTES, SPINEL_STATUS_OK, true }, // 11 - { SPINEL_PROP_NET_STACK_UP, SPINEL_STATUS_OK, true }, // 12 - { SPINEL_PROP_NET_REQUIRE_JOIN_EXISTING, SPINEL_STATUS_OK, true }, // 13 - { SPINEL_PROP_LAST_STATUS, SPINEL_STATUS_NOMEM, true }, // 14 - { SPINEL_PROP_LAST_STATUS, SPINEL_STATUS_DROPPED, true }, // 15 + {SPINEL_PROP_LAST_STATUS, SPINEL_STATUS_RESET_UNKNOWN, false}, // 0 + {SPINEL_PROP_STREAM_DEBUG, SPINEL_STATUS_OK, true}, // 1 + {SPINEL_PROP_IPV6_ADDRESS_TABLE, SPINEL_STATUS_OK, true}, // 2 + {SPINEL_PROP_NET_ROLE, SPINEL_STATUS_OK, true}, // 3 + {SPINEL_PROP_IPV6_LL_ADDR, SPINEL_STATUS_OK, true}, // 4 + {SPINEL_PROP_IPV6_ML_ADDR, SPINEL_STATUS_OK, true}, // 5 + {SPINEL_PROP_NET_PARTITION_ID, SPINEL_STATUS_OK, true}, // 6 + {SPINEL_PROP_NET_KEY_SEQUENCE_COUNTER, SPINEL_STATUS_OK, true}, // 7 + {SPINEL_PROP_THREAD_LEADER_NETWORK_DATA, SPINEL_STATUS_OK, true}, // 8 + {SPINEL_PROP_THREAD_CHILD_TABLE, SPINEL_STATUS_OK, true}, // 9 + {SPINEL_PROP_THREAD_ON_MESH_NETS, SPINEL_STATUS_OK, true}, // 10 + {SPINEL_PROP_THREAD_OFF_MESH_ROUTES, SPINEL_STATUS_OK, true}, // 11 + {SPINEL_PROP_NET_STACK_UP, SPINEL_STATUS_OK, true}, // 12 + {SPINEL_PROP_NET_REQUIRE_JOIN_EXISTING, SPINEL_STATUS_OK, true}, // 13 + {SPINEL_PROP_LAST_STATUS, SPINEL_STATUS_NOMEM, true}, // 14 + {SPINEL_PROP_LAST_STATUS, SPINEL_STATUS_DROPPED, true}, // 15 #if OPENTHREAD_ENABLE_JAM_DETECTION - { SPINEL_PROP_JAM_DETECTED, SPINEL_STATUS_OK, true }, // 16 + {SPINEL_PROP_JAM_DETECTED, SPINEL_STATUS_OK, true}, // 16 #endif #if OPENTHREAD_ENABLE_LEGACY - { SPINEL_PROP_NEST_LEGACY_ULA_PREFIX, SPINEL_STATUS_OK, true }, // 17 - { SPINEL_PROP_NEST_LEGACY_LAST_NODE_JOINED, SPINEL_STATUS_OK, true }, // 18 + {SPINEL_PROP_NEST_LEGACY_ULA_PREFIX, SPINEL_STATUS_OK, true}, // 17 + {SPINEL_PROP_NEST_LEGACY_LAST_NODE_JOINED, SPINEL_STATUS_OK, true}, // 18 #endif - { SPINEL_PROP_LAST_STATUS, SPINEL_STATUS_JOIN_FAILURE, false }, // 19 - { SPINEL_PROP_MAC_SCAN_STATE, SPINEL_STATUS_OK, false }, // 20 - { SPINEL_PROP_IPV6_MULTICAST_ADDRESS_TABLE, SPINEL_STATUS_OK, true }, // 21 - { SPINEL_PROP_PHY_CHAN, SPINEL_STATUS_OK, true }, // 22 - { SPINEL_PROP_MAC_15_4_PANID, SPINEL_STATUS_OK, true }, // 23 - { SPINEL_PROP_NET_NETWORK_NAME, SPINEL_STATUS_OK, true }, // 24 - { SPINEL_PROP_NET_XPANID, SPINEL_STATUS_OK, true }, // 25 - { SPINEL_PROP_NET_MASTER_KEY, SPINEL_STATUS_OK, true }, // 26 - { SPINEL_PROP_NET_PSKC, SPINEL_STATUS_OK, true }, // 27 + {SPINEL_PROP_LAST_STATUS, SPINEL_STATUS_JOIN_FAILURE, false}, // 19 + {SPINEL_PROP_MAC_SCAN_STATE, SPINEL_STATUS_OK, false}, // 20 + {SPINEL_PROP_IPV6_MULTICAST_ADDRESS_TABLE, SPINEL_STATUS_OK, true}, // 21 + {SPINEL_PROP_PHY_CHAN, SPINEL_STATUS_OK, true}, // 22 + {SPINEL_PROP_MAC_15_4_PANID, SPINEL_STATUS_OK, true}, // 23 + {SPINEL_PROP_NET_NETWORK_NAME, SPINEL_STATUS_OK, true}, // 24 + {SPINEL_PROP_NET_XPANID, SPINEL_STATUS_OK, true}, // 25 + {SPINEL_PROP_NET_MASTER_KEY, SPINEL_STATUS_OK, true}, // 26 + {SPINEL_PROP_NET_PSKC, SPINEL_STATUS_OK, true}, // 27 #if OPENTHREAD_ENABLE_CHANNEL_MANAGER - { SPINEL_PROP_CHANNEL_MANAGER_NEW_CHANNEL, SPINEL_STATUS_OK, true }, // 28 + {SPINEL_PROP_CHANNEL_MANAGER_NEW_CHANNEL, SPINEL_STATUS_OK, true}, // 28 #endif }; @@ -94,7 +92,7 @@ uint8_t ChangedPropsSet::GetNumEntries(void) const void ChangedPropsSet::Add(spinel_prop_key_t aPropKey, spinel_status_t aStatus) { - uint8_t numEntries; + uint8_t numEntries; const Entry *entry; entry = GetSupportedEntries(numEntries); @@ -115,9 +113,9 @@ void ChangedPropsSet::Add(spinel_prop_key_t aPropKey, spinel_status_t aStatus) otError ChangedPropsSet::EnablePropertyFilter(spinel_prop_key_t aPropKey, bool aEnable) { - uint8_t numEntries; + uint8_t numEntries; const Entry *entry; - bool didFind = false; + bool didFind = false; entry = GetSupportedEntries(numEntries); @@ -157,8 +155,8 @@ otError ChangedPropsSet::EnablePropertyFilter(spinel_prop_key_t aPropKey, bool a bool ChangedPropsSet::IsPropertyFiltered(spinel_prop_key_t aPropKey) const { - bool isFiltered = false; - uint8_t numEntries; + bool isFiltered = false; + uint8_t numEntries; const Entry *entry; entry = GetSupportedEntries(numEntries); diff --git a/src/ncp/changed_props_set.hpp b/src/ncp/changed_props_set.hpp index 0747ef218..a55d0fdae 100644 --- a/src/ncp/changed_props_set.hpp +++ b/src/ncp/changed_props_set.hpp @@ -68,16 +68,17 @@ public: * This constructor initializes the set. * */ - ChangedPropsSet(void): - mChangedSet(0), - mFilterSet(0) - { } + ChangedPropsSet(void) + : mChangedSet(0) + , mFilterSet(0) + { + } /** * This method clears the set. * */ - void Clear(void) { mChangedSet = 0; } + void Clear(void) { mChangedSet = 0; } /** * This method indicates if the set is empty or not. @@ -104,7 +105,7 @@ public: * @param[in] aStatus The spinel status update to be added to set. * */ - void AddLastStatus(spinel_status_t aStatus) { Add(SPINEL_PROP_LAST_STATUS, aStatus); } + void AddLastStatus(spinel_status_t aStatus) { Add(SPINEL_PROP_LAST_STATUS, aStatus); } /** * This method returns a pointer to array of entries of supported property/status updates. The list includes @@ -115,7 +116,8 @@ public: * @returns A pointer to the supported entries array. * */ - const Entry *GetSupportedEntries(uint8_t &aNumEntries) const { + const Entry *GetSupportedEntries(uint8_t &aNumEntries) const + { aNumEntries = GetNumEntries(); return &mSupportedProps[0]; } @@ -128,9 +130,7 @@ public: * @returns A pointer to the entry associated with @p aIndex, or NULL if the index is beyond end of array. * */ - const Entry *GetEntry(uint8_t aIndex) const { - return (aIndex < GetNumEntries()) ? &mSupportedProps[aIndex] : NULL; - } + const Entry *GetEntry(uint8_t aIndex) const { return (aIndex < GetNumEntries()) ? &mSupportedProps[aIndex] : NULL; } /** * This method indicates if the entry associated with an index is in the set (i.e., it has been changed and @@ -194,11 +194,11 @@ public: private: uint8_t GetNumEntries(void) const; - void Add(spinel_prop_key_t aPropKey, spinel_status_t aStatus); + void Add(spinel_prop_key_t aPropKey, spinel_status_t aStatus); - static void SetBit (uint32_t &aBitset, uint8_t aBitIndex) { aBitset |= (1U << aBitIndex); } - static void ClearBit(uint32_t &aBitset, uint8_t aBitIndex) { aBitset &= ~(1U << aBitIndex); } - static bool IsBitSet(uint32_t aBitset, uint8_t aBitIndex) { return (aBitset & (1U << aBitIndex)) != 0; } + static void SetBit(uint32_t &aBitset, uint8_t aBitIndex) { aBitset |= (1U << aBitIndex); } + static void ClearBit(uint32_t &aBitset, uint8_t aBitIndex) { aBitset &= ~(1U << aBitIndex); } + static bool IsBitSet(uint32_t aBitset, uint8_t aBitIndex) { return (aBitset & (1U << aBitIndex)) != 0; } static const Entry mSupportedProps[]; diff --git a/src/ncp/hdlc.cpp b/src/ncp/hdlc.cpp index 8e6b3f7f7..b0cb6931a 100644 --- a/src/ncp/hdlc.cpp +++ b/src/ncp/hdlc.cpp @@ -56,8 +56,8 @@ enum { kFlagXOn = 0x11, kFlagXOff = 0x13, - kFlagSequence = 0x7e, ///< HDLC Flag value - kEscapeSequence = 0x7d, ///< HDLC Escape value + kFlagSequence = 0x7e, ///< HDLC Flag value + kEscapeSequence = 0x7d, ///< HDLC Escape value kFlagSpecial = 0xf8, }; @@ -67,47 +67,32 @@ enum */ enum { - kInitFcs = 0xffff, ///< Initial FCS value. - kGoodFcs = 0xf0b8, ///< Good FCS value. + kInitFcs = 0xffff, ///< Initial FCS value. + kGoodFcs = 0xf0b8, ///< Good FCS value. }; uint16_t UpdateFcs(uint16_t aFcs, uint8_t aByte) { - static const uint16_t sFcsTable[256] = - { - 0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf, - 0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7, - 0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e, - 0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876, - 0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd, - 0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5, - 0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c, - 0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974, - 0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb, - 0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3, - 0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a, - 0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72, - 0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9, - 0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1, - 0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738, - 0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70, - 0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7, - 0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff, - 0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036, - 0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e, - 0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5, - 0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd, - 0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134, - 0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c, - 0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3, - 0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb, - 0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232, - 0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a, - 0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1, - 0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9, - 0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330, - 0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78 - }; + static const uint16_t sFcsTable[256] = { + 0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf, 0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, + 0xe97e, 0xf8f7, 0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e, 0x9cc9, 0x8d40, 0xbfdb, 0xae52, + 0xdaed, 0xcb64, 0xf9ff, 0xe876, 0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd, 0xad4a, 0xbcc3, + 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5, 0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c, + 0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974, 0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, + 0x2732, 0x36bb, 0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3, 0x5285, 0x430c, 0x7197, 0x601e, + 0x14a1, 0x0528, 0x37b3, 0x263a, 0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72, 0x6306, 0x728f, + 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9, 0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1, + 0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738, 0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, + 0x9af9, 0x8b70, 0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7, 0x0840, 0x19c9, 0x2b52, 0x3adb, + 0x4e64, 0x5fed, 0x6d76, 0x7cff, 0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036, 0x18c1, 0x0948, + 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e, 0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5, + 0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd, 0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, + 0xd0bd, 0xc134, 0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c, 0xc60c, 0xd785, 0xe51e, 0xf497, + 0x8028, 0x91a1, 0xa33a, 0xb2b3, 0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb, 0xd68d, 0xc704, + 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232, 0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a, + 0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1, 0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, + 0x0e70, 0x1ff9, 0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330, 0x7bc7, 0x6a4e, 0x58d5, 0x495c, + 0x3de3, 0x2c6a, 0x1ef1, 0x0f78}; return (aFcs >> 8) ^ sFcsTable[(aFcs ^ aByte) & 0xff]; } @@ -129,7 +114,7 @@ bool HdlcByteNeedsEscape(uint8_t aByte) Encoder::BufferWriteIterator::BufferWriteIterator(void) { - mWritePointer = NULL; + mWritePointer = NULL; mRemainingLength = 0; } @@ -151,8 +136,8 @@ bool Encoder::BufferWriteIterator::CanWrite(uint16_t aWriteLength) const return (mRemainingLength >= aWriteLength); } -Encoder::Encoder(void): - mFcs(0) +Encoder::Encoder(void) + : mFcs(0) { } @@ -169,7 +154,7 @@ otError Encoder::Encode(uint8_t aInByte, BufferWriteIterator &aIterator) if (HdlcByteNeedsEscape(aInByte)) { - VerifyOrExit(aIterator.CanWrite(2) , error = OT_ERROR_NO_BUFS); + VerifyOrExit(aIterator.CanWrite(2), error = OT_ERROR_NO_BUFS); aIterator.WriteByte(kEscapeSequence); aIterator.WriteByte(aInByte ^ 0x20); @@ -187,9 +172,9 @@ exit: otError Encoder::Encode(const uint8_t *aInBuf, uint16_t aInLength, BufferWriteIterator &aIterator) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; BufferWriteIterator oldIterator(aIterator); - uint16_t oldFcs = mFcs; + uint16_t oldFcs = mFcs; for (int i = 0; i < aInLength; i++) { @@ -201,7 +186,7 @@ exit: if (error != OT_ERROR_NONE) { aIterator = oldIterator; - mFcs = oldFcs; + mFcs = oldFcs; } return error; @@ -209,10 +194,10 @@ exit: otError Encoder::Finalize(BufferWriteIterator &aIterator) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; BufferWriteIterator oldIterator(aIterator); - uint16_t oldFcs = mFcs; - uint16_t fcs = mFcs; + uint16_t oldFcs = mFcs; + uint16_t fcs = mFcs; fcs ^= 0xffff; @@ -226,22 +211,25 @@ exit: if (error != OT_ERROR_NONE) { aIterator = oldIterator; - mFcs = oldFcs; + mFcs = oldFcs; } return error; } -Decoder::Decoder(uint8_t *aOutBuf, uint16_t aOutLength, FrameHandler aFrameHandler, ErrorHandler aErrorHandler, - void *aContext): - mState(kStateNoSync), - mFrameHandler(aFrameHandler), - mErrorHandler(aErrorHandler), - mContext(aContext), - mOutBuf(aOutBuf), - mOutOffset(0), - mOutLength(aOutLength), - mFcs(0) +Decoder::Decoder(uint8_t * aOutBuf, + uint16_t aOutLength, + FrameHandler aFrameHandler, + ErrorHandler aErrorHandler, + void * aContext) + : mState(kStateNoSync) + , mFrameHandler(aFrameHandler) + , mErrorHandler(aErrorHandler) + , mContext(aContext) + , mOutBuf(aOutBuf) + , mOutOffset(0) + , mOutLength(aOutLength) + , mFcs(0) { } @@ -258,9 +246,9 @@ void Decoder::Decode(const uint8_t *aInBuf, uint16_t aInLength) case kStateNoSync: if (byte == kFlagSequence) { - mState = kStateSync; + mState = kStateSync; mOutOffset = 0; - mFcs = kInitFcs; + mFcs = kInitFcs; } break; @@ -289,14 +277,14 @@ void Decoder::Decode(const uint8_t *aInBuf, uint16_t aInLength) } mOutOffset = 0; - mFcs = kInitFcs; + mFcs = kInitFcs; break; default: if (mOutOffset < mOutLength) { - mFcs = UpdateFcs(mFcs, byte); + mFcs = UpdateFcs(mFcs, byte); mOutBuf[mOutOffset++] = byte; } else @@ -318,9 +306,9 @@ void Decoder::Decode(const uint8_t *aInBuf, uint16_t aInLength) if (mOutOffset < mOutLength) { byte ^= 0x20; - mFcs = UpdateFcs(mFcs, byte); + mFcs = UpdateFcs(mFcs, byte); mOutBuf[mOutOffset++] = byte; - mState = kStateSync; + mState = kStateSync; } else { @@ -332,13 +320,12 @@ void Decoder::Decode(const uint8_t *aInBuf, uint16_t aInLength) mState = kStateNoSync; } - break; } } } -} // namespace Hdlc -} // namespace ot +} // namespace Hdlc +} // namespace ot #endif // OPENTHREAD_ENABLE_NCP_UART diff --git a/src/ncp/hdlc.hpp b/src/ncp/hdlc.hpp index 4624ce5d4..7b5fba5a7 100644 --- a/src/ncp/hdlc.hpp +++ b/src/ncp/hdlc.hpp @@ -55,7 +55,6 @@ namespace Hdlc { class Encoder { public: - /** * This class defines a write iterator into a buffer used by Encoder. * @@ -64,7 +63,6 @@ public: class BufferWriteIterator { public: - /** * This method writes a byte to the buffer and updates the iterator (if space is available). * @@ -86,11 +84,10 @@ public: bool CanWrite(uint16_t aWriteLength) const; protected: + BufferWriteIterator(void); ///< Protected constructor to ensure no direct instantiation. - BufferWriteIterator(void); ///< Protected constructor to ensure no direct instantiation. - - uint8_t *mWritePointer; ///< A pointer to current write position in the buffer. - uint16_t mRemainingLength; ///< Number of remaining bytes available to write. + uint8_t *mWritePointer; ///< A pointer to current write position in the buffer. + uint16_t mRemainingLength; ///< Number of remaining bytes available to write. }; /** @@ -192,8 +189,11 @@ public: * @param[in] aContext A pointer to arbitrary context information. * */ - Decoder(uint8_t *aOutBuf, uint16_t aOutLength, FrameHandler aFrameHandler, ErrorHandler aErrorHandler, - void *aContext); + Decoder(uint8_t * aOutBuf, + uint16_t aOutLength, + FrameHandler aFrameHandler, + ErrorHandler aErrorHandler, + void * aContext); /** * This method streams bytes into the decoder. @@ -215,7 +215,7 @@ private: FrameHandler mFrameHandler; ErrorHandler mErrorHandler; - void *mContext; + void * mContext; uint8_t *mOutBuf; uint16_t mOutOffset; @@ -224,7 +224,7 @@ private: uint16_t mFcs; }; -} // namespace Hdlc -} // namespace ot +} // namespace Hdlc +} // namespace ot -#endif // HDLC_HPP_ +#endif // HDLC_HPP_ diff --git a/src/ncp/ncp_base.cpp b/src/ncp/ncp_base.cpp index 6988e529c..b66f04f66 100644 --- a/src/ncp/ncp_base.cpp +++ b/src/ncp/ncp_base.cpp @@ -53,10 +53,12 @@ namespace Ncp { // MARK: Property Handler Jump Tables and Methods // ---------------------------------------------------------------------------- -#define NCP_GET_PROP_HANDLER_ENTRY(name) { SPINEL_PROP_##name, &NcpBase::GetPropertyHandler_##name } +#define NCP_GET_PROP_HANDLER_ENTRY(name) \ + { \ + SPINEL_PROP_##name, &NcpBase::GetPropertyHandler_##name \ + } -const NcpBase::PropertyHandlerEntry NcpBase::mGetPropertyHandlerTable[] = -{ +const NcpBase::PropertyHandlerEntry NcpBase::mGetPropertyHandlerTable[] = { NCP_GET_PROP_HANDLER_ENTRY(CAPS), NCP_GET_PROP_HANDLER_ENTRY(DEBUG_TEST_ASSERT), NCP_GET_PROP_HANDLER_ENTRY(DEBUG_TEST_WATCHDOG), @@ -258,10 +260,12 @@ const NcpBase::PropertyHandlerEntry NcpBase::mGetPropertyHandlerTable[] = #endif }; -#define NCP_SET_PROP_HANDLER_ENTRY(name) { SPINEL_PROP_##name, &NcpBase::SetPropertyHandler_##name } +#define NCP_SET_PROP_HANDLER_ENTRY(name) \ + { \ + SPINEL_PROP_##name, &NcpBase::SetPropertyHandler_##name \ + } -const NcpBase::PropertyHandlerEntry NcpBase::mSetPropertyHandlerTable[] = -{ +const NcpBase::PropertyHandlerEntry NcpBase::mSetPropertyHandlerTable[] = { #if OPENTHREAD_RADIO || OPENTHREAD_ENABLE_RAW_LINK_API NCP_SET_PROP_HANDLER_ENTRY(MAC_15_4_SADDR), NCP_SET_PROP_HANDLER_ENTRY(MAC_SRC_MATCH_ENABLED), @@ -360,10 +364,12 @@ const NcpBase::PropertyHandlerEntry NcpBase::mSetPropertyHandlerTable[] = #endif // #if OPENTHREAD_FTD }; -#define NCP_INSERT_PROP_HANDLER_ENTRY(name) { SPINEL_PROP_##name, &NcpBase::InsertPropertyHandler_##name } +#define NCP_INSERT_PROP_HANDLER_ENTRY(name) \ + { \ + SPINEL_PROP_##name, &NcpBase::InsertPropertyHandler_##name \ + } -const NcpBase::PropertyHandlerEntry NcpBase::mInsertPropertyHandlerTable[] = -{ +const NcpBase::PropertyHandlerEntry NcpBase::mInsertPropertyHandlerTable[] = { NCP_INSERT_PROP_HANDLER_ENTRY(UNSOL_UPDATE_FILTER), #if OPENTHREAD_RADIO || OPENTHREAD_ENABLE_RAW_LINK_API NCP_INSERT_PROP_HANDLER_ENTRY(MAC_SRC_MATCH_SHORT_ADDRESSES), @@ -390,10 +396,12 @@ const NcpBase::PropertyHandlerEntry NcpBase::mInsertPropertyHandlerTable[] = #endif // OPENTHREAD_FTD }; -#define NCP_REMOVE_PROP_HANDLER_ENTRY(name) { SPINEL_PROP_##name, &NcpBase::RemovePropertyHandler_##name } +#define NCP_REMOVE_PROP_HANDLER_ENTRY(name) \ + { \ + SPINEL_PROP_##name, &NcpBase::RemovePropertyHandler_##name \ + } -const NcpBase::PropertyHandlerEntry NcpBase::mRemovePropertyHandlerTable[] = -{ +const NcpBase::PropertyHandlerEntry NcpBase::mRemovePropertyHandlerTable[] = { NCP_REMOVE_PROP_HANDLER_ENTRY(UNSOL_UPDATE_FILTER), #if OPENTHREAD_RADIO || OPENTHREAD_ENABLE_RAW_LINK_API NCP_REMOVE_PROP_HANDLER_ENTRY(MAC_SRC_MATCH_SHORT_ADDRESSES), @@ -545,58 +553,65 @@ static spinel_status_t ResetReasonToSpinelStatus(otPlatResetReason aReason) NcpBase *NcpBase::sNcpInstance = NULL; -NcpBase::NcpBase(Instance *aInstance): - mInstance(aInstance), - mTxFrameBuffer(mTxBuffer, sizeof(mTxBuffer)), - mEncoder(mTxFrameBuffer), - mDecoder(), - mHostPowerStateInProgress(false), - mLastStatus(SPINEL_STATUS_OK), - mSupportedChannelMask(OT_RADIO_SUPPORTED_CHANNELS), - mChannelMask(OT_RADIO_SUPPORTED_CHANNELS), - mScanPeriod(200), // ms - mDiscoveryScanJoinerFlag(false), - mDiscoveryScanEnableFiltering(false), - mDiscoveryScanPanId(0xffff), - mUpdateChangedPropsTask(*aInstance, &NcpBase::UpdateChangedProps, this), - mThreadChangedFlags(0), - mChangedPropsSet(), - mHostPowerState(SPINEL_HOST_POWER_STATE_ONLINE), - mHostPowerReplyFrameTag(NcpFrameBuffer::kInvalidTag), - mHostPowerStateHeader(0), +NcpBase::NcpBase(Instance *aInstance) + : mInstance(aInstance) + , mTxFrameBuffer(mTxBuffer, sizeof(mTxBuffer)) + , mEncoder(mTxFrameBuffer) + , mDecoder() + , mHostPowerStateInProgress(false) + , mLastStatus(SPINEL_STATUS_OK) + , mSupportedChannelMask(OT_RADIO_SUPPORTED_CHANNELS) + , mChannelMask(OT_RADIO_SUPPORTED_CHANNELS) + , mScanPeriod(200) + , // ms + mDiscoveryScanJoinerFlag(false) + , mDiscoveryScanEnableFiltering(false) + , mDiscoveryScanPanId(0xffff) + , mUpdateChangedPropsTask(*aInstance, &NcpBase::UpdateChangedProps, this) + , mThreadChangedFlags(0) + , mChangedPropsSet() + , mHostPowerState(SPINEL_HOST_POWER_STATE_ONLINE) + , mHostPowerReplyFrameTag(NcpFrameBuffer::kInvalidTag) + , mHostPowerStateHeader(0) + , #if OPENTHREAD_CONFIG_NCP_ENABLE_PEEK_POKE - mAllowPeekDelegate(NULL), - mAllowPokeDelegate(NULL), + mAllowPeekDelegate(NULL) + , mAllowPokeDelegate(NULL) + , #endif - mNextExpectedTid(0), - mResponseQueueHead(0), - mResponseQueueTail(0), - mAllowLocalNetworkDataChange(false), - mRequireJoinExistingNetwork(false), - mIsRawStreamEnabled(false), - mDisableStreamWrite(false), - mShouldEmitChildTableUpdate(false), + mNextExpectedTid(0) + , mResponseQueueHead(0) + , mResponseQueueTail(0) + , mAllowLocalNetworkDataChange(false) + , mRequireJoinExistingNetwork(false) + , mIsRawStreamEnabled(false) + , mDisableStreamWrite(false) + , mShouldEmitChildTableUpdate(false) + , #if OPENTHREAD_FTD - mPreferredRouteId(0), + mPreferredRouteId(0) + , #endif #if OPENTHREAD_RADIO || OPENTHREAD_ENABLE_RAW_LINK_API - mCurTransmitTID(0), - mCurScanChannel(kInvalidScanChannel), - mSrcMatchEnabled(false), + mCurTransmitTID(0) + , mCurScanChannel(kInvalidScanChannel) + , mSrcMatchEnabled(false) + , #endif // OPENTHREAD_RADIO || OPENTHREAD_ENABLE_RAW_LINK_API #if OPENTHREAD_MTD || OPENTHREAD_FTD - mInboundSecureIpFrameCounter(0), - mInboundInsecureIpFrameCounter(0), - mOutboundSecureIpFrameCounter(0), - mOutboundInsecureIpFrameCounter(0), - mDroppedOutboundIpFrameCounter(0), - mDroppedInboundIpFrameCounter(0), + mInboundSecureIpFrameCounter(0) + , mInboundInsecureIpFrameCounter(0) + , mOutboundSecureIpFrameCounter(0) + , mOutboundInsecureIpFrameCounter(0) + , mDroppedOutboundIpFrameCounter(0) + , mDroppedInboundIpFrameCounter(0) + , #endif // OPENTHREAD_MTD || OPENTHREAD_FTD - mFramingErrorCounter(0), - mRxSpinelFrameCounter(0), - mRxSpinelOutOfOrderTidCounter(0), - mTxSpinelFrameCounter(0), - mDidInitialUpdates(false) + mFramingErrorCounter(0) + , mRxSpinelFrameCounter(0) + , mRxSpinelOutOfOrderTidCounter(0) + , mTxSpinelFrameCounter(0) + , mDidInitialUpdates(false) { assert(mInstance != NULL); @@ -621,7 +636,7 @@ NcpBase::NcpBase(Instance *aInstance): #endif // OPENTHREAD_FTD #if OPENTHREAD_ENABLE_LEGACY mLegacyNodeDidJoin = false; - mLegacyHandlers = NULL; + mLegacyHandlers = NULL; memset(mLegacyUlaPrefix, 0, sizeof(mLegacyUlaPrefix)); memset(&mLegacyLastJoinedNode, 0, sizeof(mLegacyLastJoinedNode)); #endif @@ -646,9 +661,9 @@ NcpFrameBuffer::FrameTag NcpBase::GetLastOutboundFrameTag(void) void NcpBase::HandleReceive(const uint8_t *aBuf, uint16_t aBufLength) { - otError error = OT_ERROR_NONE; - uint8_t header = 0; - spinel_tid_t tid = 0; + otError error = OT_ERROR_NONE; + uint8_t header = 0; + spinel_tid_t tid = 0; mDisableStreamWrite = true; @@ -656,7 +671,7 @@ void NcpBase::HandleReceive(const uint8_t *aBuf, uint16_t aBufLength) mDecoder.Init(aBuf, aBufLength); // Receiving any message from the host has the side effect of transitioning the host power state to online. - mHostPowerState = SPINEL_HOST_POWER_STATE_ONLINE; + mHostPowerState = SPINEL_HOST_POWER_STATE_ONLINE; mHostPowerStateInProgress = false; // Skip if there is no header byte to read or this isn't a spinel frame. @@ -707,8 +722,10 @@ exit: mDisableStreamWrite = false; } -void NcpBase::HandleFrameRemovedFromNcpBuffer(void *aContext, NcpFrameBuffer::FrameTag aFrameTag, - NcpFrameBuffer::Priority aPriority, NcpFrameBuffer *aNcpBuffer) +void NcpBase::HandleFrameRemovedFromNcpBuffer(void * aContext, + NcpFrameBuffer::FrameTag aFrameTag, + NcpFrameBuffer::Priority aPriority, + NcpFrameBuffer * aNcpBuffer) { OT_UNUSED_VARIABLE(aNcpBuffer); OT_UNUSED_VARIABLE(aPriority); @@ -750,12 +767,11 @@ void NcpBase::HandleFrameRemovedFromNcpBuffer(NcpFrameBuffer::FrameTag aFrameTag if (mHostPowerState != SPINEL_HOST_POWER_STATE_ONLINE) { - mHostPowerReplyFrameTag = GetLastOutboundFrameTag(); + mHostPowerReplyFrameTag = GetLastOutboundFrameTag(); mHostPowerStateInProgress = true; } } - #if OPENTHREAD_MTD || OPENTHREAD_FTD // Send any queued IPv6 datagram message. @@ -788,8 +804,8 @@ void NcpBase::IncrementFrameErrorCounter(void) otError NcpBase::StreamWrite(int aStreamId, const uint8_t *aDataPtr, int aDataLen) { - otError error = OT_ERROR_NONE; - uint8_t header = SPINEL_HEADER_FLAG | SPINEL_HEADER_IID_0; + otError error = OT_ERROR_NONE; + uint8_t header = SPINEL_HEADER_FLAG | SPINEL_HEADER_IID_0; spinel_prop_key_t streamPropKey; if (aStreamId == 0) @@ -865,7 +881,6 @@ unsigned int NcpBase::ConvertLogRegion(otLogRegion aLogRegion) switch (aLogRegion) { - case OT_LOG_REGION_API: spinelLogRegion = SPINEL_NCP_LOG_REGION_OT_API; break; @@ -936,7 +951,7 @@ unsigned int NcpBase::ConvertLogRegion(otLogRegion aLogRegion) void NcpBase::Log(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aLogString) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; uint8_t header = SPINEL_HEADER_FLAG | SPINEL_HEADER_IID_0; VerifyOrExit(!mDisableStreamWrite); @@ -985,8 +1000,8 @@ void NcpBase::HandleRawFrame(const otRadioFrame *aFrame, void *aContext) void NcpBase::HandleRawFrame(const otRadioFrame *aFrame) { - uint16_t flags = 0; - uint8_t header = SPINEL_HEADER_FLAG | SPINEL_HEADER_IID_0; + uint16_t flags = 0; + uint8_t header = SPINEL_HEADER_FLAG | SPINEL_HEADER_IID_0; if (!mIsRawStreamEnabled) { @@ -1006,15 +1021,15 @@ void NcpBase::HandleRawFrame(const otRadioFrame *aFrame) SuccessOrExit(mEncoder.WriteData(aFrame->mPsdu, aFrame->mLength)); // Append metadata (rssi, etc) - SuccessOrExit(mEncoder.WriteInt8(aFrame->mInfo.mRxInfo.mRssi)); // RSSI - SuccessOrExit(mEncoder.WriteInt8(-128)); // Noise floor (Currently unused) - SuccessOrExit(mEncoder.WriteUint16(flags)); // Flags + SuccessOrExit(mEncoder.WriteInt8(aFrame->mInfo.mRxInfo.mRssi)); // RSSI + SuccessOrExit(mEncoder.WriteInt8(-128)); // Noise floor (Currently unused) + SuccessOrExit(mEncoder.WriteUint16(flags)); // Flags - SuccessOrExit(mEncoder.OpenStruct()); // PHY-data + SuccessOrExit(mEncoder.OpenStruct()); // PHY-data // Empty for now SuccessOrExit(mEncoder.CloseStruct()); - SuccessOrExit(mEncoder.OpenStruct()); // Vendor-data + SuccessOrExit(mEncoder.OpenStruct()); // Vendor-data // Empty for now SuccessOrExit(mEncoder.CloseStruct()); @@ -1040,8 +1055,8 @@ uint8_t NcpBase::GetWrappedResponseQueueIndex(uint8_t aPosition) otError NcpBase::PrepareResponse(uint8_t aHeader, bool aIsLastStatus, bool aIsGetResponse, unsigned int aKeyOrStatus) { - otError error = OT_ERROR_NONE; - spinel_tid_t tid = SPINEL_HEADER_GET_TID(aHeader); + otError error = OT_ERROR_NONE; + spinel_tid_t tid = SPINEL_HEADER_GET_TID(aHeader); ResponseEntry *entry; if (tid == 0) @@ -1094,10 +1109,10 @@ otError NcpBase::PrepareResponse(uint8_t aHeader, bool aIsLastStatus, bool aIsGe entry = &mResponseQueue[GetWrappedResponseQueueIndex(mResponseQueueTail)]; - entry->mTid = tid; - entry->mIsInUse = true; - entry->mIsLastStatus = aIsLastStatus; - entry->mIsGetResponse = aIsGetResponse; + entry->mTid = tid; + entry->mIsInUse = true; + entry->mIsLastStatus = aIsLastStatus; + entry->mIsGetResponse = aIsGetResponse; entry->mPropKeyOrStatus = aKeyOrStatus; mResponseQueueTail++; @@ -1169,8 +1184,8 @@ void NcpBase::UpdateChangedProps(Tasklet &aTasklet) void NcpBase::UpdateChangedProps(void) { - uint8_t numEntries; - spinel_prop_key_t propKey; + uint8_t numEntries; + spinel_prop_key_t propKey; const ChangedPropsSet::Entry *entry; #if OPENTHREAD_MTD || OPENTHREAD_FTD @@ -1221,7 +1236,7 @@ exit: otError NcpBase::HandleCommand(uint8_t aHeader) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; unsigned int command; SuccessOrExit(error = mDecoder.ReadUintPacked(command)); @@ -1289,8 +1304,9 @@ exit: // MARK: Property Get/Set/Insert/Remove Commands // ---------------------------------------------------------------------------- -NcpBase::PropertyHandler NcpBase::FindPropertyHandler(spinel_prop_key_t aKey, const PropertyHandlerEntry *aTableEntry, - size_t aTableLen) +NcpBase::PropertyHandler NcpBase::FindPropertyHandler(spinel_prop_key_t aKey, + const PropertyHandlerEntry *aTableEntry, + size_t aTableLen) { PropertyHandler handler = NULL; @@ -1320,7 +1336,7 @@ NcpBase::PropertyHandler NcpBase::FindSetPropertyHandler(spinel_prop_key_t aKey) NcpBase::PropertyHandler NcpBase::FindInsertPropertyHandler(spinel_prop_key_t aKey) { - return FindPropertyHandler(aKey, mInsertPropertyHandlerTable, OT_ARRAY_LENGTH(mInsertPropertyHandlerTable)); + return FindPropertyHandler(aKey, mInsertPropertyHandlerTable, OT_ARRAY_LENGTH(mInsertPropertyHandlerTable)); } NcpBase::PropertyHandler NcpBase::FindRemovePropertyHandler(spinel_prop_key_t aKey) @@ -1368,13 +1384,13 @@ exit: otError NcpBase::HandleCommandPropertySet(uint8_t aHeader, spinel_prop_key_t aKey) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; PropertyHandler handler = FindSetPropertyHandler(aKey); if (handler != NULL) { mDisableStreamWrite = false; - error = (this->*handler)(); + error = (this->*handler)(); mDisableStreamWrite = true; } else @@ -1390,7 +1406,7 @@ otError NcpBase::HandleCommandPropertySet(uint8_t aHeader, spinel_prop_key_t aKe if (aKey >= SPINEL_PROP_VENDOR__BEGIN && aKey < SPINEL_PROP_VENDOR__END) { mDisableStreamWrite = false; - error = VendorSetPropertyHandler(aKey); + error = VendorSetPropertyHandler(aKey); mDisableStreamWrite = true; // An `OT_ERROR_NOT_FOUND` status from vendor handler indicates @@ -1421,21 +1437,21 @@ exit: otError NcpBase::HandleCommandPropertyInsertRemove(uint8_t aHeader, spinel_prop_key_t aKey, unsigned int aCommand) { - otError error = OT_ERROR_NONE; - PropertyHandler handler = NULL; - unsigned int responseCommand = 0; - const uint8_t *valuePtr; - uint16_t valueLen; + otError error = OT_ERROR_NONE; + PropertyHandler handler = NULL; + unsigned int responseCommand = 0; + const uint8_t * valuePtr; + uint16_t valueLen; switch (aCommand) { case SPINEL_CMD_PROP_VALUE_INSERT: - handler = FindInsertPropertyHandler(aKey); + handler = FindInsertPropertyHandler(aKey); responseCommand = SPINEL_CMD_PROP_VALUE_INSERTED; break; case SPINEL_CMD_PROP_VALUE_REMOVE: - handler = FindRemovePropertyHandler(aKey); + handler = FindRemovePropertyHandler(aKey); responseCommand = SPINEL_CMD_PROP_VALUE_REMOVED; break; @@ -1500,7 +1516,7 @@ exit: otError NcpBase::WritePropertyValueIsFrame(uint8_t aHeader, spinel_prop_key_t aPropKey, bool aIsGetResponse) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; PropertyHandler handler = FindGetPropertyHandler(aPropKey); if (handler != NULL) @@ -1545,9 +1561,11 @@ exit: return error; } -otError NcpBase::WritePropertyValueInsertedRemovedFrame(uint8_t aHeader, unsigned int aResponseCommand, - spinel_prop_key_t aPropKey, const uint8_t *aValuePtr, - uint16_t aValueLen) +otError NcpBase::WritePropertyValueInsertedRemovedFrame(uint8_t aHeader, + unsigned int aResponseCommand, + spinel_prop_key_t aPropKey, + const uint8_t * aValuePtr, + uint16_t aValueLen) { otError error = OT_ERROR_NONE; @@ -1600,7 +1618,7 @@ otError NcpBase::CommandHandler_RESET(uint8_t aHeader) otError NcpBase::CommandHandler_PROP_VALUE_update(uint8_t aHeader, unsigned int aCommand) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; unsigned int propKey = 0; error = mDecoder.ReadUintPacked(propKey); @@ -1634,8 +1652,8 @@ exit: otError NcpBase::CommandHandler_PEEK(uint8_t aHeader) { - otError parseError = OT_ERROR_NONE; - otError responseError = OT_ERROR_NONE; + otError parseError = OT_ERROR_NONE; + otError responseError = OT_ERROR_NONE; uint32_t address; uint16_t count; @@ -1666,11 +1684,11 @@ exit: otError NcpBase::CommandHandler_POKE(uint8_t aHeader) { - otError parseError = OT_ERROR_NONE; - uint32_t address; - uint16_t count; + otError parseError = OT_ERROR_NONE; + uint32_t address; + uint16_t count; const uint8_t *dataPtr = NULL; - uint16_t dataLen; + uint16_t dataLen; SuccessOrExit(parseError = mDecoder.ReadUint32(address)); SuccessOrExit(parseError = mDecoder.ReadUint16(count)); @@ -1692,10 +1710,9 @@ exit: #endif // OPENTHREAD_CONFIG_NCP_ENABLE_PEEK_POKE - -// ---------------------------------------------------------------------------- -// MARK: Individual Property Getters and Setters -// ---------------------------------------------------------------------------- + // ---------------------------------------------------------------------------- + // MARK: Individual Property Getters and Setters + // ---------------------------------------------------------------------------- #if OPENTHREAD_ENABLE_DIAG @@ -1703,7 +1720,7 @@ otError NcpBase::SetPropertyHandler_NEST_STREAM_MFG(uint8_t aHeader) { const char *string = NULL; const char *output = NULL; - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; error = mDecoder.ReadUtf8(string); @@ -1725,9 +1742,9 @@ exit: otError NcpBase::GetPropertyHandler_PHY_ENABLED(void) { #if OPENTHREAD_RADIO || OPENTHREAD_ENABLE_RAW_LINK_API - return mEncoder.WriteBool(otLinkRawIsEnabled(mInstance)); + return mEncoder.WriteBool(otLinkRawIsEnabled(mInstance)); #else - return mEncoder.WriteBool(false); + return mEncoder.WriteBool(false); #endif } @@ -1739,7 +1756,7 @@ otError NcpBase::GetPropertyHandler_PHY_CHAN(void) otError NcpBase::SetPropertyHandler_PHY_CHAN(void) { unsigned int channel = 0; - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; SuccessOrExit(error = mDecoder.ReadUintPacked(channel)); @@ -1764,15 +1781,13 @@ exit: otError NcpBase::GetPropertyHandler_MAC_PROMISCUOUS_MODE(void) { - return mEncoder.WriteUint8(otPlatRadioGetPromiscuous(mInstance) - ? SPINEL_MAC_PROMISCUOUS_MODE_FULL - : SPINEL_MAC_PROMISCUOUS_MODE_OFF - ); + return mEncoder.WriteUint8(otPlatRadioGetPromiscuous(mInstance) ? SPINEL_MAC_PROMISCUOUS_MODE_FULL + : SPINEL_MAC_PROMISCUOUS_MODE_OFF); } otError NcpBase::SetPropertyHandler_MAC_PROMISCUOUS_MODE(void) { - uint8_t mode = 0; + uint8_t mode = 0; otError error = OT_ERROR_NONE; SuccessOrExit(error = mDecoder.ReadUint8(mode)); @@ -1805,7 +1820,7 @@ otError NcpBase::GetPropertyHandler_MAC_15_4_PANID(void) otError NcpBase::SetPropertyHandler_MAC_15_4_PANID(void) { uint16_t panid; - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; SuccessOrExit(error = mDecoder.ReadUint16(panid)); @@ -1823,7 +1838,7 @@ otError NcpBase::GetPropertyHandler_MAC_15_4_LADDR(void) otError NcpBase::SetPropertyHandler_MAC_15_4_LADDR(void) { const otExtAddress *extAddress; - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; SuccessOrExit(error = mDecoder.ReadEui64(extAddress)); @@ -1845,8 +1860,8 @@ otError NcpBase::GetPropertyHandler_MAC_RAW_STREAM_ENABLED(void) otError NcpBase::SetPropertyHandler_MAC_RAW_STREAM_ENABLED(void) { - bool enabled = false; - otError error = OT_ERROR_NONE; + bool enabled = false; + otError error = OT_ERROR_NONE; SuccessOrExit(error = mDecoder.ReadBool(enabled)); @@ -1874,8 +1889,8 @@ exit: otError NcpBase::GetPropertyHandler_UNSOL_UPDATE_FILTER(void) { - otError error = OT_ERROR_NONE; - uint8_t numEntries; + otError error = OT_ERROR_NONE; + uint8_t numEntries; const ChangedPropsSet::Entry *entry; entry = mChangedPropsSet.GetSupportedEntries(numEntries); @@ -1895,7 +1910,7 @@ exit: otError NcpBase::SetPropertyHandler_UNSOL_UPDATE_FILTER(void) { unsigned int propKey; - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; // First clear the current filter. mChangedPropsSet.ClearFilter(); @@ -1923,7 +1938,7 @@ exit: otError NcpBase::InsertPropertyHandler_UNSOL_UPDATE_FILTER(void) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; unsigned int propKey; SuccessOrExit(error = mDecoder.ReadUintPacked(propKey)); @@ -1936,7 +1951,7 @@ exit: otError NcpBase::RemovePropertyHandler_UNSOL_UPDATE_FILTER(void) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; unsigned int propKey; SuccessOrExit(error = mDecoder.ReadUintPacked(propKey)); @@ -1970,7 +1985,7 @@ otError NcpBase::GetPropertyHandler_INTERFACE_TYPE(void) otError NcpBase::GetPropertyHandler_VENDOR_ID(void) { - return mEncoder.WriteUintPacked(0); // Vendor ID. Zero for unknown. + return mEncoder.WriteUintPacked(0); // Vendor ID. Zero for unknown. } otError NcpBase::GetPropertyHandler_CAPS(void) @@ -2082,9 +2097,9 @@ otError NcpBase::GetPropertyHandler_MCU_POWER_STATE(void) otError NcpBase::SetPropertyHandler_MCU_POWER_STATE(void) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; otPlatMcuPowerState powerState; - uint8_t state; + uint8_t state; SuccessOrExit(error = mDecoder.ReadUint8(state)); @@ -2251,8 +2266,8 @@ otError NcpBase::SetPropertyHandler_HOST_POWER_STATE(uint8_t aHeader) otError NcpBase::GetPropertyHandler_UNSOL_UPDATE_LIST(void) { - otError error = OT_ERROR_NONE; - uint8_t numEntries; + otError error = OT_ERROR_NONE; + uint8_t numEntries; const ChangedPropsSet::Entry *entry; entry = mChangedPropsSet.GetSupportedEntries(numEntries); @@ -2276,7 +2291,7 @@ otError NcpBase::GetPropertyHandler_PHY_RX_SENSITIVITY(void) otError NcpBase::GetPropertyHandler_PHY_TX_POWER(void) { - int8_t power; + int8_t power; otError error; error = otPlatRadioGetTransmitPower(mInstance, &power); @@ -2295,8 +2310,8 @@ otError NcpBase::GetPropertyHandler_PHY_TX_POWER(void) otError NcpBase::SetPropertyHandler_PHY_TX_POWER(void) { - int8_t txPower = 0; - otError error = OT_ERROR_NONE; + int8_t txPower = 0; + otError error = OT_ERROR_NONE; SuccessOrExit(error = mDecoder.ReadInt8(txPower)); error = otPlatRadioSetTransmitPower(mInstance, txPower); @@ -2314,9 +2329,7 @@ otError NcpBase::GetPropertyHandler_DEBUG_TEST_ASSERT(void) // In such a case we return `false` as the // property value to indicate this. - OT_UNREACHABLE_CODE( - return mEncoder.WriteBool(false); - ) + OT_UNREACHABLE_CODE(return mEncoder.WriteBool(false);) } otError NcpBase::GetPropertyHandler_DEBUG_TEST_WATCHDOG(void) @@ -2324,9 +2337,7 @@ otError NcpBase::GetPropertyHandler_DEBUG_TEST_WATCHDOG(void) while (true) ; - OT_UNREACHABLE_CODE( - return OT_ERROR_NONE; - ) + OT_UNREACHABLE_CODE(return OT_ERROR_NONE;) } otError NcpBase::GetPropertyHandler_DEBUG_NCP_LOG_LEVEL(void) @@ -2336,9 +2347,9 @@ otError NcpBase::GetPropertyHandler_DEBUG_NCP_LOG_LEVEL(void) otError NcpBase::SetPropertyHandler_DEBUG_NCP_LOG_LEVEL(void) { - uint8_t spinelNcpLogLevel = 0; + uint8_t spinelNcpLogLevel = 0; otLogLevel logLevel; - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; SuccessOrExit(error = mDecoder.ReadUint8(spinelNcpLogLevel)); @@ -2381,8 +2392,8 @@ exit: return error; } -} // namespace Ncp -} // namespace ot +} // namespace Ncp +} // namespace ot // ---------------------------------------------------------------------------- // MARK: Peek/Poke delegate API @@ -2417,8 +2428,8 @@ otError otNcpRegisterPeekPokeDelagates(otNcpDelegateAllowPeekPoke aAllowPeekDele otError otNcpStreamWrite(int aStreamId, const uint8_t *aDataPtr, int aDataLen) { - otError error = OT_ERROR_INVALID_STATE; - ot::Ncp::NcpBase *ncp = ot::Ncp::NcpBase::GetNcpInstance(); + otError error = OT_ERROR_INVALID_STATE; + ot::Ncp::NcpBase *ncp = ot::Ncp::NcpBase::GetNcpInstance(); if (ncp != NULL) { @@ -2431,7 +2442,7 @@ otError otNcpStreamWrite(int aStreamId, const uint8_t *aDataPtr, int aDataLen) extern "C" void otNcpPlatLogv(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, va_list aArgs) { char logString[OPENTHREAD_CONFIG_NCP_SPINEL_LOG_MAX_SIZE]; - int charsWritten; + int charsWritten; if ((charsWritten = vsnprintf(logString, sizeof(logString), aFormat, aArgs)) > 0) { @@ -2451,8 +2462,8 @@ extern "C" void otNcpPlatLogv(otLogLevel aLogLevel, otLogRegion aLogRegion, cons extern "C" void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, ...) { - va_list args; - char logString[OPENTHREAD_CONFIG_NCP_SPINEL_LOG_MAX_SIZE]; + va_list args; + char logString[OPENTHREAD_CONFIG_NCP_SPINEL_LOG_MAX_SIZE]; ot::Ncp::NcpBase *ncp = ot::Ncp::NcpBase::GetNcpInstance(); va_start(args, aFormat); diff --git a/src/ncp/ncp_base.hpp b/src/ncp/ncp_base.hpp index b38037c18..220a88978 100644 --- a/src/ncp/ncp_base.hpp +++ b/src/ncp/ncp_base.hpp @@ -59,15 +59,14 @@ namespace ot { namespace Ncp { -#define NCP_GET_PROP_HANDLER(name) otError GetPropertyHandler_##name(void) -#define NCP_SET_PROP_HANDLER(name) otError SetPropertyHandler_##name(void) +#define NCP_GET_PROP_HANDLER(name) otError GetPropertyHandler_##name(void) +#define NCP_SET_PROP_HANDLER(name) otError SetPropertyHandler_##name(void) #define NCP_INSERT_PROP_HANDLER(name) otError InsertPropertyHandler_##name(void) #define NCP_REMOVE_PROP_HANDLER(name) otError RemovePropertyHandler_##name(void) class NcpBase { public: - /** * This constructor creates and initializes an NcpBase instance. * @@ -112,7 +111,6 @@ public: */ void Log(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aLogString); - #if OPENTHREAD_CONFIG_NCP_ENABLE_PEEK_POKE /** * This method registers peek/poke delegate functions with NCP module. @@ -184,7 +182,7 @@ protected: struct PropertyHandlerEntry { spinel_prop_key_t mPropKey; - PropertyHandler mHandler; + PropertyHandler mHandler; }; /** @@ -196,11 +194,11 @@ protected: */ struct ResponseEntry { - uint8_t mTid : 4; ///< Spinel transaction id. - bool mIsInUse : 1; ///< `true` if this entry is in use, `false` otherwise. - bool mIsLastStatus : 1; ///< `true` if entry is a `LAST_STATUS`, otherwise it is a property update. - bool mIsGetResponse : 1; ///< `true` if response is for `VALUE_GET`, 'false` otherwise. - uint32_t mPropKeyOrStatus : 24; ///< 3 bytes for either property key or spinel status. + uint8_t mTid : 4; ///< Spinel transaction id. + bool mIsInUse : 1; ///< `true` if this entry is in use, `false` otherwise. + bool mIsLastStatus : 1; ///< `true` if entry is a `LAST_STATUS`, otherwise it is a property update. + bool mIsGetResponse : 1; ///< `true` if response is for `VALUE_GET`, 'false` otherwise. + uint32_t mPropKeyOrStatus : 24; ///< 3 bytes for either property key or spinel status. }; NcpFrameBuffer::FrameTag GetLastOutboundFrameTag(void); @@ -213,79 +211,89 @@ protected: PropertyHandler FindInsertPropertyHandler(spinel_prop_key_t aKey); PropertyHandler FindRemovePropertyHandler(spinel_prop_key_t aKey); - bool HandlePropertySetForSpecialProperties(uint8_t aHeader, spinel_prop_key_t aKey, otError &aError); + bool HandlePropertySetForSpecialProperties(uint8_t aHeader, spinel_prop_key_t aKey, otError &aError); otError HandleCommandPropertySet(uint8_t aHeader, spinel_prop_key_t aKey); otError HandleCommandPropertyInsertRemove(uint8_t aHeader, spinel_prop_key_t aKey, unsigned int aCommand); otError WriteLastStatusFrame(uint8_t aHeader, spinel_status_t aLastStatus); otError WritePropertyValueIsFrame(uint8_t aHeader, spinel_prop_key_t aPropKey, bool aIsGetResponse = true); - otError WritePropertyValueInsertedRemovedFrame(uint8_t aHeader, unsigned int aResponseCommand, - spinel_prop_key_t aPropKey, const uint8_t *aValuePtr, - uint16_t aValueLen); + otError WritePropertyValueInsertedRemovedFrame(uint8_t aHeader, + unsigned int aResponseCommand, + spinel_prop_key_t aPropKey, + const uint8_t * aValuePtr, + uint16_t aValueLen); otError SendQueuedResponses(void); - bool IsResponseQueueEmpty(void) { return (mResponseQueueHead == mResponseQueueTail); } + bool IsResponseQueueEmpty(void) { return (mResponseQueueHead == mResponseQueueTail); } otError PrepareResponse(uint8_t aHeader, bool aIsLastStatus, bool aIsGetResponse, unsigned int aPropKeyOrStatus); - otError PrepareGetResponse(uint8_t aHeader, spinel_prop_key_t aPropKey) { + otError PrepareGetResponse(uint8_t aHeader, spinel_prop_key_t aPropKey) + { return PrepareResponse(aHeader, false /* aIsLastStatus */, true /* aIsGetResponse*/, aPropKey); } - otError PrepareSetResponse(uint8_t aHeader, spinel_prop_key_t aPropKey) { + otError PrepareSetResponse(uint8_t aHeader, spinel_prop_key_t aPropKey) + { return PrepareResponse(aHeader, false /* aIsLastStatus */, false /* aIsGetResponse*/, aPropKey); } - otError PrepareLastStatusResponse(uint8_t aHeader, spinel_status_t aStatus) { + otError PrepareLastStatusResponse(uint8_t aHeader, spinel_status_t aStatus) + { return PrepareResponse(aHeader, true /*aIsLastStatus */, false, aStatus); } static uint8_t GetWrappedResponseQueueIndex(uint8_t aPosition); static void UpdateChangedProps(Tasklet &aTasklet); - void UpdateChangedProps(void); + void UpdateChangedProps(void); - static void HandleFrameRemovedFromNcpBuffer(void *aContext, NcpFrameBuffer::FrameTag aFrameTag, - NcpFrameBuffer::Priority aPriority, NcpFrameBuffer *aNcpBuffer); - void HandleFrameRemovedFromNcpBuffer(NcpFrameBuffer::FrameTag aFrameTag); + static void HandleFrameRemovedFromNcpBuffer(void * aContext, + NcpFrameBuffer::FrameTag aFrameTag, + NcpFrameBuffer::Priority aPriority, + NcpFrameBuffer * aNcpBuffer); + void HandleFrameRemovedFromNcpBuffer(NcpFrameBuffer::FrameTag aFrameTag); static void HandleRawFrame(const otRadioFrame *aFrame, void *aContext); - void HandleRawFrame(const otRadioFrame *aFrame); + void HandleRawFrame(const otRadioFrame *aFrame); #if OPENTHREAD_RADIO || OPENTHREAD_ENABLE_RAW_LINK_API static void LinkRawReceiveDone(otInstance *aInstance, otRadioFrame *aFrame, otError aError); - void LinkRawReceiveDone(otRadioFrame *aFrame, otError aError); + void LinkRawReceiveDone(otRadioFrame *aFrame, otError aError); - static void LinkRawTransmitDone(otInstance *aInstance, otRadioFrame *aFrame, otRadioFrame *aAckFrame, otError aError); - void LinkRawTransmitDone(otRadioFrame *aFrame, otRadioFrame *aAckFrame, otError aError); + static void LinkRawTransmitDone(otInstance * aInstance, + otRadioFrame *aFrame, + otRadioFrame *aAckFrame, + otError aError); + void LinkRawTransmitDone(otRadioFrame *aFrame, otRadioFrame *aAckFrame, otError aError); static void LinkRawEnergyScanDone(otInstance *aInstance, int8_t aEnergyScanMaxRssi); - void LinkRawEnergyScanDone(int8_t aEnergyScanMaxRssi); + void LinkRawEnergyScanDone(int8_t aEnergyScanMaxRssi); #endif // OPENTHREAD_RADIO || OPENTHREAD_ENABLE_RAW_LINK_API #if OPENTHREAD_MTD || OPENTHREAD_FTD static void HandleStateChanged(uint32_t aFlags, void *aContext); - void ProcessThreadChangedFlags(void); + void ProcessThreadChangedFlags(void); #if OPENTHREAD_FTD static void HandleChildTableChanged(otThreadChildTableEvent aEvent, const otChildInfo *aChildInfo); - void HandleChildTableChanged(otThreadChildTableEvent aEvent, const otChildInfo &aChildInfo); + void HandleChildTableChanged(otThreadChildTableEvent aEvent, const otChildInfo &aChildInfo); #endif static void HandleDatagramFromStack(otMessage *aMessage, void *aContext); - void HandleDatagramFromStack(otMessage *aMessage); + void HandleDatagramFromStack(otMessage *aMessage); otError SendQueuedDatagramMessages(void); otError SendDatagramMessage(otMessage *aMessage); static void HandleActiveScanResult_Jump(otActiveScanResult *aResult, void *aContext); - void HandleActiveScanResult(otActiveScanResult *aResult); + void HandleActiveScanResult(otActiveScanResult *aResult); static void HandleEnergyScanResult_Jump(otEnergyScanResult *aResult, void *aContext); - void HandleEnergyScanResult(otEnergyScanResult *aResult); + void HandleEnergyScanResult(otEnergyScanResult *aResult); static void HandleJamStateChange_Jump(bool aJamState, void *aContext); - void HandleJamStateChange(bool aJamState); + void HandleJamStateChange(bool aJamState); static void SendDoneTask(void *aContext); - void SendDoneTask(void); + void SendDoneTask(void); otError EncodeChannelMask(uint32_t aChannelMask); otError DecodeChannelMask(uint32_t &aChannelMask); @@ -300,7 +308,7 @@ protected: #if OPENTHREAD_FTD && OPENTHREAD_ENABLE_TMF_PROXY static void HandleTmfProxyStream(otMessage *aMessage, uint16_t aLocator, uint16_t aPort, void *aContext); - void HandleTmfProxyStream(otMessage *aMessage, uint16_t aLocator, uint16_t aPort); + void HandleTmfProxyStream(otMessage *aMessage, uint16_t aLocator, uint16_t aPort); #endif // OPENTHREAD_FTD && OPENTHREAD_ENABLE_TMF_PROXY otError CommandHandler_NOOP(uint8_t aHeader); @@ -712,11 +720,11 @@ protected: void StartLegacy(void); void StopLegacy(void); #else - void StartLegacy(void) { } - void StopLegacy(void) { } + void StartLegacy(void) {} + void StopLegacy(void) {} #endif - static uint8_t ConvertLogLevel(otLogLevel aLogLevel); + static uint8_t ConvertLogLevel(otLogLevel aLogLevel); static unsigned int ConvertLogRegion(otLogRegion aLogRegion); #if OPENTHREAD_ENABLE_NCP_VENDOR_HOOK @@ -786,20 +794,23 @@ protected: #endif // OPENTHREAD_ENABLE_NCP_VENDOR_HOOK protected: - static NcpBase *sNcpInstance; + static NcpBase * sNcpInstance; static spinel_status_t ThreadErrorToSpinelStatus(otError aError); - static uint8_t LinkFlagsToFlagByte(bool aRxOnWhenIdle, bool aSecureDataRequests, bool aDeviceType, bool aNetworkData); - Instance *mInstance; - NcpFrameBuffer mTxFrameBuffer; - SpinelEncoder mEncoder; - SpinelDecoder mDecoder; - bool mHostPowerStateInProgress; + static uint8_t LinkFlagsToFlagByte(bool aRxOnWhenIdle, + bool aSecureDataRequests, + bool aDeviceType, + bool aNetworkData); + Instance * mInstance; + NcpFrameBuffer mTxFrameBuffer; + SpinelEncoder mEncoder; + SpinelDecoder mDecoder; + bool mHostPowerStateInProgress; enum { - kTxBufferSize = OPENTHREAD_CONFIG_NCP_TX_BUFFER_SIZE, // Tx Buffer size (used by mTxFrameBuffer). - kResponseQueueSize = OPENTHREAD_CONFIG_NCP_SPINEL_RESPONSE_QUEUE_SIZE, - kInvalidScanChannel = -1, // Invalid scan channel. + kTxBufferSize = OPENTHREAD_CONFIG_NCP_TX_BUFFER_SIZE, // Tx Buffer size (used by mTxFrameBuffer). + kResponseQueueSize = OPENTHREAD_CONFIG_NCP_SPINEL_RESPONSE_QUEUE_SIZE, + kInvalidScanChannel = -1, // Invalid scan channel. }; // Command Handlers @@ -809,20 +820,20 @@ protected: static const PropertyHandlerEntry mRemovePropertyHandlerTable[]; spinel_status_t mLastStatus; - uint32_t mSupportedChannelMask; - uint32_t mChannelMask; - uint16_t mScanPeriod; - bool mDiscoveryScanJoinerFlag; - bool mDiscoveryScanEnableFiltering; - uint16_t mDiscoveryScanPanId; + uint32_t mSupportedChannelMask; + uint32_t mChannelMask; + uint16_t mScanPeriod; + bool mDiscoveryScanJoinerFlag; + bool mDiscoveryScanEnableFiltering; + uint16_t mDiscoveryScanPanId; - Tasklet mUpdateChangedPropsTask; - uint32_t mThreadChangedFlags; + Tasklet mUpdateChangedPropsTask; + uint32_t mThreadChangedFlags; ChangedPropsSet mChangedPropsSet; spinel_host_power_state_t mHostPowerState; - NcpFrameBuffer::FrameTag mHostPowerReplyFrameTag; - uint8_t mHostPowerStateHeader; + NcpFrameBuffer::FrameTag mHostPowerReplyFrameTag; + uint8_t mHostPowerStateHeader; #if OPENTHREAD_CONFIG_NCP_ENABLE_PEEK_POKE otNcpDelegateAllowPeekPoke mAllowPeekDelegate; @@ -833,8 +844,8 @@ protected: spinel_tid_t mNextExpectedTid; - uint8_t mResponseQueueHead; - uint8_t mResponseQueueTail; + uint8_t mResponseQueueHead; + uint8_t mResponseQueueTail; ResponseEntry mResponseQueue[kResponseQueueSize]; bool mAllowLocalNetworkDataChange; @@ -859,29 +870,29 @@ protected: #if OPENTHREAD_MTD || OPENTHREAD_FTD otMessageQueue mMessageQueue; - uint32_t mInboundSecureIpFrameCounter; // Number of secure inbound data/IP frames. - uint32_t mInboundInsecureIpFrameCounter; // Number of insecure inbound data/IP frames. - uint32_t mOutboundSecureIpFrameCounter; // Number of secure outbound data/IP frames. - uint32_t mOutboundInsecureIpFrameCounter; // Number of insecure outbound data/IP frames. - uint32_t mDroppedOutboundIpFrameCounter; // Number of dropped outbound data/IP frames. - uint32_t mDroppedInboundIpFrameCounter; // Number of dropped inbound data/IP frames. -#endif // OPENTHREAD_MTD || OPENTHREAD_FTD - uint32_t mFramingErrorCounter; // Number of improperly formed received spinel frames. - uint32_t mRxSpinelFrameCounter; // Number of received (inbound) spinel frames. - uint32_t mRxSpinelOutOfOrderTidCounter; // Number of out of order received spinel frames (tid increase > 1). - uint32_t mTxSpinelFrameCounter; // Number of sent (outbound) spinel frames. + uint32_t mInboundSecureIpFrameCounter; // Number of secure inbound data/IP frames. + uint32_t mInboundInsecureIpFrameCounter; // Number of insecure inbound data/IP frames. + uint32_t mOutboundSecureIpFrameCounter; // Number of secure outbound data/IP frames. + uint32_t mOutboundInsecureIpFrameCounter; // Number of insecure outbound data/IP frames. + uint32_t mDroppedOutboundIpFrameCounter; // Number of dropped outbound data/IP frames. + uint32_t mDroppedInboundIpFrameCounter; // Number of dropped inbound data/IP frames. +#endif // OPENTHREAD_MTD || OPENTHREAD_FTD + uint32_t mFramingErrorCounter; // Number of improperly formed received spinel frames. + uint32_t mRxSpinelFrameCounter; // Number of received (inbound) spinel frames. + uint32_t mRxSpinelOutOfOrderTidCounter; // Number of out of order received spinel frames (tid increase > 1). + uint32_t mTxSpinelFrameCounter; // Number of sent (outbound) spinel frames. #if OPENTHREAD_ENABLE_LEGACY const otNcpLegacyHandlers *mLegacyHandlers; - uint8_t mLegacyUlaPrefix[OT_NCP_LEGACY_ULA_PREFIX_LENGTH]; - otExtAddress mLegacyLastJoinedNode; - bool mLegacyNodeDidJoin; + uint8_t mLegacyUlaPrefix[OT_NCP_LEGACY_ULA_PREFIX_LENGTH]; + otExtAddress mLegacyLastJoinedNode; + bool mLegacyNodeDidJoin; #endif bool mDidInitialUpdates; }; -} // namespace Ncp -} // namespace ot +} // namespace Ncp +} // namespace ot -#endif // NCP_BASE_HPP_ +#endif // NCP_BASE_HPP_ diff --git a/src/ncp/ncp_base_ftd.cpp b/src/ncp/ncp_base_ftd.cpp index 1a2ecc246..674dc2028 100644 --- a/src/ncp/ncp_base_ftd.cpp +++ b/src/ncp/ncp_base_ftd.cpp @@ -30,8 +30,8 @@ * This file implements full thread device specified Spinel interface to the OpenThread stack. */ -#include #include "ncp_base.hpp" +#include #if OPENTHREAD_ENABLE_CHANNEL_MANAGER #include @@ -41,8 +41,8 @@ #include #include #include -#include #include +#include #if OPENTHREAD_ENABLE_TMF_PROXY #include @@ -64,12 +64,8 @@ otError NcpBase::EncodeChildInfo(const otChildInfo &aChildInfo) otError error = OT_ERROR_NONE; uint8_t modeFlags; - modeFlags = LinkFlagsToFlagByte( - aChildInfo.mRxOnWhenIdle, - aChildInfo.mSecureDataRequest, - aChildInfo.mFullFunction, - aChildInfo.mFullNetworkData - ); + modeFlags = LinkFlagsToFlagByte(aChildInfo.mRxOnWhenIdle, aChildInfo.mSecureDataRequest, aChildInfo.mFullFunction, + aChildInfo.mFullNetworkData); SuccessOrExit(error = mEncoder.WriteEui64(aChildInfo.mExtAddress)); SuccessOrExit(error = mEncoder.WriteUint16(aChildInfo.mRloc16)); @@ -96,8 +92,8 @@ void NcpBase::HandleChildTableChanged(otThreadChildTableEvent aEvent, const otCh void NcpBase::HandleChildTableChanged(otThreadChildTableEvent aEvent, const otChildInfo &aChildInfo) { - otError error = OT_ERROR_NONE; - uint8_t header = SPINEL_HEADER_FLAG | SPINEL_HEADER_IID_0; + otError error = OT_ERROR_NONE; + uint8_t header = SPINEL_HEADER_FLAG | SPINEL_HEADER_IID_0; unsigned int command = 0; VerifyOrExit(!mChangedPropsSet.IsPropertyFiltered(SPINEL_PROP_THREAD_CHILD_TABLE)); @@ -155,16 +151,15 @@ otError NcpBase::GetPropertyHandler_THREAD_LEADER_WEIGHT(void) otError NcpBase::GetPropertyHandler_THREAD_CHILD_TABLE(void) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; otChildInfo childInfo; - uint8_t maxChildren; + uint8_t maxChildren; maxChildren = otThreadGetMaxAllowedChildren(mInstance); for (uint8_t index = 0; index < maxChildren; index++) { - if ((otThreadGetChildInfoByIndex(mInstance, index, &childInfo) != OT_ERROR_NONE) || - childInfo.mIsStateRestoring) + if ((otThreadGetChildInfoByIndex(mInstance, index, &childInfo) != OT_ERROR_NONE) || childInfo.mIsStateRestoring) { continue; } @@ -180,9 +175,9 @@ exit: otError NcpBase::GetPropertyHandler_THREAD_ROUTER_TABLE(void) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; otRouterInfo routerInfo; - uint8_t maxRouterId; + uint8_t maxRouterId; maxRouterId = otThreadGetMaxRouterId(mInstance); @@ -214,10 +209,10 @@ exit: otError NcpBase::GetPropertyHandler_THREAD_CHILD_TABLE_ADDRESSES(void) { - otError error = OT_ERROR_NONE; - otChildInfo childInfo; - uint8_t maxChildren; - otIp6Address ip6Address; + otError error = OT_ERROR_NONE; + otChildInfo childInfo; + uint8_t maxChildren; + otIp6Address ip6Address; otChildIp6AddressIterator iterator = OT_CHILD_IP6_ADDRESS_ITERATOR_INIT; maxChildren = otThreadGetMaxAllowedChildren(mInstance); @@ -256,7 +251,7 @@ otError NcpBase::GetPropertyHandler_THREAD_ROUTER_ROLE_ENABLED(void) otError NcpBase::SetPropertyHandler_THREAD_ROUTER_ROLE_ENABLED(void) { - bool enabled; + bool enabled; otError error = OT_ERROR_NONE; SuccessOrExit(error = mDecoder.ReadBool(enabled)); @@ -275,8 +270,8 @@ otError NcpBase::GetPropertyHandler_NET_PSKC(void) otError NcpBase::SetPropertyHandler_NET_PSKC(void) { const uint8_t *ptr = NULL; - uint16_t len; - otError error = OT_ERROR_NONE; + uint16_t len; + otError error = OT_ERROR_NONE; SuccessOrExit(error = mDecoder.ReadData(ptr, len)); @@ -296,7 +291,7 @@ otError NcpBase::GetPropertyHandler_THREAD_CHILD_COUNT_MAX(void) otError NcpBase::SetPropertyHandler_THREAD_CHILD_COUNT_MAX(void) { uint8_t maxChildren = 0; - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; SuccessOrExit(error = mDecoder.ReadUint8(maxChildren)); @@ -314,7 +309,7 @@ otError NcpBase::GetPropertyHandler_THREAD_ROUTER_UPGRADE_THRESHOLD(void) otError NcpBase::SetPropertyHandler_THREAD_ROUTER_UPGRADE_THRESHOLD(void) { uint8_t threshold = 0; - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; SuccessOrExit(error = mDecoder.ReadUint8(threshold)); @@ -332,7 +327,7 @@ otError NcpBase::GetPropertyHandler_THREAD_ROUTER_DOWNGRADE_THRESHOLD(void) otError NcpBase::SetPropertyHandler_THREAD_ROUTER_DOWNGRADE_THRESHOLD(void) { uint8_t threshold = 0; - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; SuccessOrExit(error = mDecoder.ReadUint8(threshold)); @@ -350,7 +345,7 @@ otError NcpBase::GetPropertyHandler_THREAD_ROUTER_SELECTION_JITTER(void) otError NcpBase::SetPropertyHandler_THREAD_ROUTER_SELECTION_JITTER(void) { uint8_t jitter = 0; - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; SuccessOrExit(error = mDecoder.ReadUint8(jitter)); @@ -368,13 +363,13 @@ otError NcpBase::GetPropertyHandler_THREAD_CONTEXT_REUSE_DELAY(void) otError NcpBase::SetPropertyHandler_THREAD_CONTEXT_REUSE_DELAY(void) { uint32_t delay = 0; - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; SuccessOrExit(error = mDecoder.ReadUint32(delay)); otThreadSetContextIdReuseDelay(mInstance, delay); - exit: +exit: return error; } @@ -386,13 +381,13 @@ otError NcpBase::GetPropertyHandler_THREAD_NETWORK_ID_TIMEOUT(void) otError NcpBase::SetPropertyHandler_THREAD_NETWORK_ID_TIMEOUT(void) { uint8_t timeout = 0; - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; SuccessOrExit(error = mDecoder.ReadUint8(timeout)); otThreadSetNetworkIdTimeout(mInstance, timeout); - exit: +exit: return error; } @@ -404,8 +399,8 @@ otError NcpBase::GetPropertyHandler_THREAD_COMMISSIONER_ENABLED(void) otError NcpBase::SetPropertyHandler_THREAD_COMMISSIONER_ENABLED(uint8_t aHeader) { - bool enabled = false; - otError error = OT_ERROR_NONE; + bool enabled = false; + otError error = OT_ERROR_NONE; SuccessOrExit(error = mDecoder.ReadBool(enabled)); @@ -424,10 +419,10 @@ exit: otError NcpBase::InsertPropertyHandler_THREAD_JOINERS(void) { - otError error = OT_ERROR_NONE; - const otExtAddress *eui64 = NULL; - const char *aPSKd = NULL; - uint32_t joinerTimeout = 0; + otError error = OT_ERROR_NONE; + const otExtAddress *eui64 = NULL; + const char * aPSKd = NULL; + uint32_t joinerTimeout = 0; SuccessOrExit(error = mDecoder.ReadUtf8(aPSKd)); SuccessOrExit(error = mDecoder.ReadUint32(joinerTimeout)); @@ -480,7 +475,7 @@ exit: otError NcpBase::SetPropertyHandler_THREAD_CHILD_TIMEOUT(void) { uint32_t timeout = 0; - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; SuccessOrExit(error = mDecoder.ReadUint32(timeout)); @@ -533,7 +528,7 @@ otError NcpBase::GetPropertyHandler_THREAD_ADDRESS_CACHE_TABLE(void) otError error = OT_ERROR_NONE; otEidCacheEntry entry; - for (uint8_t index = 0; ; index++) + for (uint8_t index = 0;; index++) { SuccessOrExit(otThreadGetEidCacheEntry(mInstance, index, &entry)); @@ -562,11 +557,11 @@ otError NcpBase::GetPropertyHandler_THREAD_TMF_PROXY_ENABLED(void) otError NcpBase::SetPropertyHandler_THREAD_TMF_PROXY_STREAM(void) { const uint8_t *framePtr = NULL; - uint16_t frameLen = 0; - uint16_t locator; - uint16_t port; - otMessage *message; - otError error = OT_ERROR_NONE; + uint16_t frameLen = 0; + uint16_t locator; + uint16_t port; + otMessage * message; + otError error = OT_ERROR_NONE; // THREAD_TMF_PROXY_STREAM requires layer 2 security. message = otIp6NewMessage(mInstance, true); @@ -596,7 +591,7 @@ exit: otError NcpBase::SetPropertyHandler_THREAD_TMF_PROXY_ENABLED(void) { - bool enabled; + bool enabled; otError error = OT_ERROR_NONE; SuccessOrExit(error = mDecoder.ReadBool(enabled)); @@ -621,15 +616,11 @@ void NcpBase::HandleTmfProxyStream(otMessage *aMessage, uint16_t aLocator, uint1 void NcpBase::HandleTmfProxyStream(otMessage *aMessage, uint16_t aLocator, uint16_t aPort) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; uint16_t length = otMessageGetLength(aMessage); - uint8_t header = SPINEL_HEADER_FLAG | SPINEL_HEADER_IID_0; + uint8_t header = SPINEL_HEADER_FLAG | SPINEL_HEADER_IID_0; - SuccessOrExit(error = mEncoder.BeginFrame( - header, - SPINEL_CMD_PROP_VALUE_IS, - SPINEL_PROP_THREAD_TMF_PROXY_STREAM - )); + SuccessOrExit(error = mEncoder.BeginFrame(header, SPINEL_CMD_PROP_VALUE_IS, SPINEL_PROP_THREAD_TMF_PROXY_STREAM)); SuccessOrExit(error = mEncoder.WriteUint16(length)); SuccessOrExit(error = mEncoder.WriteMessage(aMessage)); @@ -696,7 +687,7 @@ otError NcpBase::DecodeOperationalDataset(otOperationalDataset &aDataset, const case SPINEL_PROP_NET_MASTER_KEY: { const uint8_t *key; - uint16_t len; + uint16_t len; SuccessOrExit(error = mDecoder.ReadData(key, len)); VerifyOrExit(len == OT_MASTER_KEY_SIZE, error = OT_ERROR_INVALID_ARGS); @@ -708,7 +699,7 @@ otError NcpBase::DecodeOperationalDataset(otOperationalDataset &aDataset, const case SPINEL_PROP_NET_NETWORK_NAME: { const char *name; - size_t len; + size_t len; SuccessOrExit(error = mDecoder.ReadUtf8(name)); len = strlen(name); @@ -721,7 +712,7 @@ otError NcpBase::DecodeOperationalDataset(otOperationalDataset &aDataset, const case SPINEL_PROP_NET_XPANID: { const uint8_t *xpanid; - uint16_t len; + uint16_t len; SuccessOrExit(error = mDecoder.ReadData(xpanid, len)); VerifyOrExit(len == OT_EXT_PAN_ID_SIZE, error = OT_ERROR_INVALID_ARGS); @@ -733,7 +724,7 @@ otError NcpBase::DecodeOperationalDataset(otOperationalDataset &aDataset, const case SPINEL_PROP_IPV6_ML_PREFIX: { const otIp6Address *addr; - uint8_t prefixLen; + uint8_t prefixLen; SuccessOrExit(error = mDecoder.ReadIp6Address(addr)); SuccessOrExit(error = mDecoder.ReadUint8(prefixLen)); @@ -758,7 +749,7 @@ otError NcpBase::DecodeOperationalDataset(otOperationalDataset &aDataset, const uint8_t channel; SuccessOrExit(error = mDecoder.ReadUint8(channel)); - aDataset.mChannel = channel; + aDataset.mChannel = channel; aDataset.mIsChannelSet = true; break; } @@ -766,7 +757,7 @@ otError NcpBase::DecodeOperationalDataset(otOperationalDataset &aDataset, const case SPINEL_PROP_NET_PSKC: { const uint8_t *psk; - uint16_t len; + uint16_t len; SuccessOrExit(error = mDecoder.ReadData(psk, len)); VerifyOrExit(len == OT_PSKC_MAX_SIZE, error = OT_ERROR_INVALID_ARGS); @@ -801,7 +792,7 @@ otError NcpBase::DecodeOperationalDataset(otOperationalDataset &aDataset, const case SPINEL_PROP_DATASET_RAW_TLVS: { const uint8_t *tlvs; - uint16_t len; + uint16_t len; SuccessOrExit(error = mDecoder.ReadData(tlvs, len)); VerifyOrExit(len <= 255, error = OT_ERROR_INVALID_ARGS); @@ -832,7 +823,7 @@ exit: otError NcpBase::SetPropertyHandler_THREAD_ACTIVE_DATASET(void) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; otOperationalDataset dataset; SuccessOrExit(error = DecodeOperationalDataset(dataset, NULL, NULL)); @@ -844,7 +835,7 @@ exit: otError NcpBase::SetPropertyHandler_THREAD_PENDING_DATASET(void) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; otOperationalDataset dataset; SuccessOrExit(error = DecodeOperationalDataset(dataset, NULL, NULL)); @@ -856,25 +847,24 @@ exit: otError NcpBase::SetPropertyHandler_THREAD_MGMT_ACTIVE_DATASET(void) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; otOperationalDataset dataset; - const uint8_t *extraTlvs; - uint8_t extraTlvsLength; + const uint8_t * extraTlvs; + uint8_t extraTlvsLength; SuccessOrExit(error = DecodeOperationalDataset(dataset, &extraTlvs, &extraTlvsLength)); error = otDatasetSendMgmtActiveSet(mInstance, &dataset, extraTlvs, extraTlvsLength); exit: return error; - } otError NcpBase::SetPropertyHandler_THREAD_MGMT_PENDING_DATASET(void) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; otOperationalDataset dataset; - const uint8_t *extraTlvs; - uint8_t extraTlvsLength; + const uint8_t * extraTlvs; + uint8_t extraTlvsLength; SuccessOrExit(error = DecodeOperationalDataset(dataset, &extraTlvs, &extraTlvsLength)); error = otDatasetSendMgmtPendingSet(mInstance, &dataset, extraTlvs, extraTlvsLength); @@ -911,7 +901,7 @@ otError NcpBase::GetPropertyHandler_CHANNEL_MANAGER_DELAY(void) otError NcpBase::SetPropertyHandler_CHANNEL_MANAGER_DELAY(void) { uint16_t delay; - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; SuccessOrExit(error = mDecoder.ReadUint16(delay)); @@ -929,7 +919,7 @@ otError NcpBase::GetPropertyHandler_CHANNEL_MANAGER_SUPPORTED_CHANNELS(void) otError NcpBase::SetPropertyHandler_CHANNEL_MANAGER_SUPPORTED_CHANNELS(void) { uint32_t channelMask = 0; - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; SuccessOrExit(error = DecodeChannelMask(channelMask)); otChannelManagerSetSupportedChannels(mInstance, channelMask); @@ -946,7 +936,7 @@ otError NcpBase::GetPropertyHandler_CHANNEL_MANAGER_FAVORED_CHANNELS(void) otError NcpBase::SetPropertyHandler_CHANNEL_MANAGER_FAVORED_CHANNELS(void) { uint32_t channelMask = 0; - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; SuccessOrExit(error = DecodeChannelMask(channelMask)); otChannelManagerSetFavoredChannels(mInstance, channelMask); @@ -962,8 +952,8 @@ otError NcpBase::GetPropertyHandler_CHANNEL_MANAGER_CHANNEL_SELECT(void) otError NcpBase::SetPropertyHandler_CHANNEL_MANAGER_CHANNEL_SELECT(void) { - bool skipQualityCheck = false; - otError error = OT_ERROR_NONE; + bool skipQualityCheck = false; + otError error = OT_ERROR_NONE; SuccessOrExit(error = mDecoder.ReadBool(skipQualityCheck)); error = otChannelManagerRequestChannelSelect(mInstance, skipQualityCheck); @@ -979,8 +969,8 @@ otError NcpBase::GetPropertyHandler_CHANNEL_MANAGER_AUTO_SELECT_ENABLED(void) otError NcpBase::SetPropertyHandler_CHANNEL_MANAGER_AUTO_SELECT_ENABLED(void) { - bool enabled = false; - otError error = OT_ERROR_NONE; + bool enabled = false; + otError error = OT_ERROR_NONE; SuccessOrExit(error = mDecoder.ReadBool(enabled)); otChannelManagerSetAutoChannelSelectionEnabled(mInstance, enabled); @@ -997,7 +987,7 @@ otError NcpBase::GetPropertyHandler_CHANNEL_MANAGER_AUTO_SELECT_INTERVAL(void) otError NcpBase::SetPropertyHandler_CHANNEL_MANAGER_AUTO_SELECT_INTERVAL(void) { uint32_t interval; - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; SuccessOrExit(error = mDecoder.ReadUint32(interval)); error = otChannelManagerSetAutoChannelSelectionInterval(mInstance, interval); @@ -1008,7 +998,7 @@ exit: #endif // OPENTHREAD_ENABLE_CHANNEL_MANAGER -} // namespace Ncp -} // namespace ot +} // namespace Ncp +} // namespace ot -#endif // OPENTHREAD_FTD +#endif // OPENTHREAD_FTD diff --git a/src/ncp/ncp_base_mtd.cpp b/src/ncp/ncp_base_mtd.cpp index 73462f91c..a2964e6a5 100644 --- a/src/ncp/ncp_base_mtd.cpp +++ b/src/ncp/ncp_base_mtd.cpp @@ -184,7 +184,7 @@ otError NcpBase::GetPropertyHandler_MAC_DATA_POLL_PERIOD(void) otError NcpBase::SetPropertyHandler_MAC_DATA_POLL_PERIOD(void) { uint32_t pollPeriod; - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; SuccessOrExit(error = mDecoder.ReadUint32(pollPeriod)); @@ -201,7 +201,7 @@ otError NcpBase::GetPropertyHandler_MAC_EXTENDED_ADDR(void) otError NcpBase::GetPropertyHandler_PHY_FREQ(void) { - uint32_t freq_khz(0); + uint32_t freq_khz(0); const uint8_t chan(otLinkGetChannel(mInstance)); if (chan == 0) @@ -257,8 +257,8 @@ otError NcpBase::GetPropertyHandler_NET_IF_UP(void) otError NcpBase::SetPropertyHandler_NET_IF_UP(void) { - bool enabled = false; - otError error = OT_ERROR_NONE; + bool enabled = false; + otError error = OT_ERROR_NONE; SuccessOrExit(error = mDecoder.ReadBool(enabled)); @@ -275,8 +275,8 @@ otError NcpBase::GetPropertyHandler_NET_STACK_UP(void) otError NcpBase::SetPropertyHandler_NET_STACK_UP(void) { - bool enabled = false; - otError error = OT_ERROR_NONE; + bool enabled = false; + otError error = OT_ERROR_NONE; SuccessOrExit(error = mDecoder.ReadBool(enabled)); @@ -328,8 +328,8 @@ otError NcpBase::GetPropertyHandler_NET_ROLE(void) otError NcpBase::SetPropertyHandler_NET_ROLE(void) { - unsigned int role = 0; - otError error = OT_ERROR_NONE; + unsigned int role = 0; + otError error = OT_ERROR_NONE; SuccessOrExit(error = mDecoder.ReadUintPacked(role)); @@ -347,7 +347,7 @@ otError NcpBase::SetPropertyHandler_NET_ROLE(void) case SPINEL_NET_ROLE_LEADER: error = otThreadBecomeLeader(mInstance); break; -#endif // OPENTHREAD_FTD +#endif // OPENTHREAD_FTD case SPINEL_NET_ROLE_CHILD: error = otThreadBecomeChild(mInstance); @@ -366,7 +366,7 @@ otError NcpBase::GetPropertyHandler_NET_NETWORK_NAME(void) otError NcpBase::SetPropertyHandler_NET_NETWORK_NAME(void) { const char *string = NULL; - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; SuccessOrExit(mDecoder.ReadUtf8(string)); @@ -384,8 +384,8 @@ otError NcpBase::GetPropertyHandler_NET_XPANID(void) otError NcpBase::SetPropertyHandler_NET_XPANID(void) { const uint8_t *ptr = NULL; - uint16_t len; - otError error = OT_ERROR_NONE; + uint16_t len; + otError error = OT_ERROR_NONE; SuccessOrExit(error = mDecoder.ReadData(ptr, len)); @@ -405,8 +405,8 @@ otError NcpBase::GetPropertyHandler_NET_MASTER_KEY(void) otError NcpBase::SetPropertyHandler_NET_MASTER_KEY(void) { const uint8_t *ptr = NULL; - uint16_t len; - otError error = OT_ERROR_NONE; + uint16_t len; + otError error = OT_ERROR_NONE; SuccessOrExit(error = mDecoder.ReadData(ptr, len)); @@ -426,7 +426,7 @@ otError NcpBase::GetPropertyHandler_NET_KEY_SEQUENCE_COUNTER(void) otError NcpBase::SetPropertyHandler_NET_KEY_SEQUENCE_COUNTER(void) { uint32_t keySeqCounter; - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; SuccessOrExit(error = mDecoder.ReadUint32(keySeqCounter)); @@ -449,7 +449,7 @@ otError NcpBase::GetPropertyHandler_NET_KEY_SWITCH_GUARDTIME(void) otError NcpBase::SetPropertyHandler_NET_KEY_SWITCH_GUARDTIME(void) { uint32_t keyGuardTime; - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; SuccessOrExit(error = mDecoder.ReadUint32(keyGuardTime)); @@ -475,12 +475,9 @@ otError NcpBase::GetPropertyHandler_THREAD_NETWORK_DATA(void) uint8_t networkData[255]; uint8_t networkDataLen = 255; - otBorderRouterGetNetData( - mInstance, - false, // Stable? - networkData, - &networkDataLen - ); + otBorderRouterGetNetData(mInstance, + false, // Stable? + networkData, &networkDataLen); return mEncoder.WriteData(networkData, networkDataLen); } @@ -490,12 +487,9 @@ otError NcpBase::GetPropertyHandler_THREAD_STABLE_NETWORK_DATA(void) uint8_t networkData[255]; uint8_t networkDataLen = 255; - otBorderRouterGetNetData( - mInstance, - true, // Stable? - networkData, - &networkDataLen - ); + otBorderRouterGetNetData(mInstance, + true, // Stable? + networkData, &networkDataLen); return mEncoder.WriteData(networkData, networkDataLen); } @@ -506,12 +500,9 @@ otError NcpBase::GetPropertyHandler_THREAD_LEADER_NETWORK_DATA(void) uint8_t networkData[255]; uint8_t networkDataLen = 255; - otNetDataGet( - mInstance, - false, // Stable? - networkData, - &networkDataLen - ); + otNetDataGet(mInstance, + false, // Stable? + networkData, &networkDataLen); return mEncoder.WriteData(networkData, networkDataLen); } @@ -521,12 +512,9 @@ otError NcpBase::GetPropertyHandler_THREAD_STABLE_LEADER_NETWORK_DATA(void) uint8_t networkData[255]; uint8_t networkDataLen = 255; - otNetDataGet( - mInstance, - true, // Stable? - networkData, - &networkDataLen - ); + otNetDataGet(mInstance, + true, // Stable? + networkData, &networkDataLen); return mEncoder.WriteData(networkData, networkDataLen); } @@ -538,7 +526,7 @@ otError NcpBase::GetPropertyHandler_THREAD_LEADER_RID(void) otError NcpBase::GetPropertyHandler_THREAD_LEADER_ADDR(void) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; otIp6Address address; error = otThreadGetLeaderRloc(mInstance, &address); @@ -579,19 +567,15 @@ exit: otError NcpBase::GetPropertyHandler_THREAD_NEIGHBOR_TABLE(void) { - otError error = OT_ERROR_NONE; - otNeighborInfoIterator iter = OT_NEIGHBOR_INFO_ITERATOR_INIT; - otNeighborInfo neighInfo; - uint8_t modeFlags; + otError error = OT_ERROR_NONE; + otNeighborInfoIterator iter = OT_NEIGHBOR_INFO_ITERATOR_INIT; + otNeighborInfo neighInfo; + uint8_t modeFlags; while (otThreadGetNextNeighborInfo(mInstance, &iter, &neighInfo) == OT_ERROR_NONE) { - modeFlags = LinkFlagsToFlagByte( - neighInfo.mRxOnWhenIdle, - neighInfo.mSecureDataRequest, - neighInfo.mFullFunction, - neighInfo.mFullNetworkData - ); + modeFlags = LinkFlagsToFlagByte(neighInfo.mRxOnWhenIdle, neighInfo.mSecureDataRequest, neighInfo.mFullFunction, + neighInfo.mFullNetworkData); SuccessOrExit(error = mEncoder.OpenStruct()); @@ -617,9 +601,9 @@ exit: otError NcpBase::GetPropertyHandler_THREAD_NEIGHBOR_TABLE_ERROR_RATES(void) { - otError error = OT_ERROR_NONE; - otNeighborInfoIterator iter = OT_NEIGHBOR_INFO_ITERATOR_INIT; - otNeighborInfo neighInfo; + otError error = OT_ERROR_NONE; + otNeighborInfoIterator iter = OT_NEIGHBOR_INFO_ITERATOR_INIT; + otNeighborInfo neighInfo; while (otThreadGetNextNeighborInfo(mInstance, &iter, &neighInfo) == OT_ERROR_NONE) { @@ -643,9 +627,9 @@ exit: otError NcpBase::GetPropertyHandler_THREAD_ASSISTING_PORTS(void) { - otError error = OT_ERROR_NONE; - uint8_t numEntries = 0; - const uint16_t *ports = otIp6GetUnsecurePorts(mInstance, &numEntries); + otError error = OT_ERROR_NONE; + uint8_t numEntries = 0; + const uint16_t *ports = otIp6GetUnsecurePorts(mInstance, &numEntries); for (; numEntries != 0; ports++, numEntries--) { @@ -658,9 +642,9 @@ exit: otError NcpBase::SetPropertyHandler_THREAD_ASSISTING_PORTS(void) { - uint8_t numEntries = 0; - const uint16_t *ports = otIp6GetUnsecurePorts(mInstance, &numEntries); - otError error = OT_ERROR_NONE; + uint8_t numEntries = 0; + const uint16_t *ports = otIp6GetUnsecurePorts(mInstance, &numEntries); + otError error = OT_ERROR_NONE; // First, we need to remove all of the current assisting ports. for (; numEntries != 0; ports++, numEntries--) @@ -699,9 +683,9 @@ otError NcpBase::GetPropertyHandler_THREAD_ALLOW_LOCAL_NET_DATA_CHANGE(void) #if OPENTHREAD_ENABLE_BORDER_ROUTER otError NcpBase::SetPropertyHandler_THREAD_ALLOW_LOCAL_NET_DATA_CHANGE(void) { - bool value = false; - otError error = OT_ERROR_NONE; - bool shouldRegisterWithLeader = false; + bool value = false; + otError error = OT_ERROR_NONE; + bool shouldRegisterWithLeader = false; SuccessOrExit(error = mDecoder.ReadBool(value)); @@ -723,8 +707,8 @@ exit: otError NcpBase::GetPropertyHandler_THREAD_ON_MESH_NETS(void) { - otError error = OT_ERROR_NONE; - otBorderRouterConfig borderRouterConfig; + otError error = OT_ERROR_NONE; + otBorderRouterConfig borderRouterConfig; otNetworkDataIterator iter = OT_NETWORK_DATA_ITERATOR_INIT; // Fill from non-local network data first @@ -736,7 +720,7 @@ otError NcpBase::GetPropertyHandler_THREAD_ON_MESH_NETS(void) SuccessOrExit(error = mEncoder.WriteUint8(borderRouterConfig.mPrefix.mLength)); SuccessOrExit(error = mEncoder.WriteBool(borderRouterConfig.mStable)); SuccessOrExit(error = mEncoder.WriteUint8(BorderRouterConfigToFlagByte(borderRouterConfig))); - SuccessOrExit(error = mEncoder.WriteBool(false)); // isLocal + SuccessOrExit(error = mEncoder.WriteBool(false)); // isLocal SuccessOrExit(error = mEncoder.WriteUint16(borderRouterConfig.mRloc16)); SuccessOrExit(error = mEncoder.CloseStruct()); @@ -755,7 +739,7 @@ otError NcpBase::GetPropertyHandler_THREAD_ON_MESH_NETS(void) SuccessOrExit(error = mEncoder.WriteUint8(borderRouterConfig.mPrefix.mLength)); SuccessOrExit(error = mEncoder.WriteBool(borderRouterConfig.mStable)); SuccessOrExit(error = mEncoder.WriteUint8(BorderRouterConfigToFlagByte(borderRouterConfig))); - SuccessOrExit(error = mEncoder.WriteBool(true)); // isLocal + SuccessOrExit(error = mEncoder.WriteBool(true)); // isLocal SuccessOrExit(error = mEncoder.WriteUint16(borderRouterConfig.mRloc16)); SuccessOrExit(error = mEncoder.CloseStruct()); @@ -769,11 +753,11 @@ exit: #if OPENTHREAD_ENABLE_BORDER_ROUTER otError NcpBase::InsertPropertyHandler_THREAD_ON_MESH_NETS(void) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; otBorderRouterConfig borderRouterConfig; - bool stable = false; - uint8_t flags = 0; - uint8_t prefixLength; + bool stable = false; + uint8_t flags = 0; + uint8_t prefixLength; memset(&borderRouterConfig, 0, sizeof(otBorderRouterConfig)); @@ -785,15 +769,14 @@ otError NcpBase::InsertPropertyHandler_THREAD_ON_MESH_NETS(void) SuccessOrExit(error = mDecoder.ReadUint8(flags)); borderRouterConfig.mPrefix.mLength = prefixLength; - borderRouterConfig.mStable = stable; - borderRouterConfig.mPreference = - ((flags & SPINEL_NET_FLAG_PREFERENCE_MASK) >> SPINEL_NET_FLAG_PREFERENCE_OFFSET); - borderRouterConfig.mPreferred = ((flags & SPINEL_NET_FLAG_PREFERRED) != 0); - borderRouterConfig.mSlaac = ((flags & SPINEL_NET_FLAG_SLAAC) != 0); - borderRouterConfig.mDhcp = ((flags & SPINEL_NET_FLAG_DHCP) != 0); - borderRouterConfig.mConfigure = ((flags & SPINEL_NET_FLAG_CONFIGURE) != 0); + borderRouterConfig.mStable = stable; + borderRouterConfig.mPreference = ((flags & SPINEL_NET_FLAG_PREFERENCE_MASK) >> SPINEL_NET_FLAG_PREFERENCE_OFFSET); + borderRouterConfig.mPreferred = ((flags & SPINEL_NET_FLAG_PREFERRED) != 0); + borderRouterConfig.mSlaac = ((flags & SPINEL_NET_FLAG_SLAAC) != 0); + borderRouterConfig.mDhcp = ((flags & SPINEL_NET_FLAG_DHCP) != 0); + borderRouterConfig.mConfigure = ((flags & SPINEL_NET_FLAG_CONFIGURE) != 0); borderRouterConfig.mDefaultRoute = ((flags & SPINEL_NET_FLAG_DEFAULT_ROUTE) != 0); - borderRouterConfig.mOnMesh = ((flags & SPINEL_NET_FLAG_ON_MESH) != 0); + borderRouterConfig.mOnMesh = ((flags & SPINEL_NET_FLAG_ON_MESH) != 0); error = otBorderRouterAddOnMeshPrefix(mInstance, &borderRouterConfig); @@ -803,9 +786,9 @@ exit: otError NcpBase::RemovePropertyHandler_THREAD_ON_MESH_NETS(void) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; otIp6Prefix ip6Prefix; - uint8_t prefixLength; + uint8_t prefixLength; memset(&ip6Prefix, 0, sizeof(otIp6Prefix)); @@ -858,7 +841,7 @@ otError NcpBase::GetPropertyHandler_THREAD_DISCOVERY_SCAN_PANID(void) otError NcpBase::SetPropertyHandler_THREAD_DISCOVERY_SCAN_PANID(void) { - return mDecoder.ReadUint16(mDiscoveryScanPanId); + return mDecoder.ReadUint16(mDiscoveryScanPanId); } otError NcpBase::EncodeOperationalDataset(const otOperationalDataset &aDataset) @@ -910,12 +893,12 @@ otError NcpBase::EncodeOperationalDataset(const otOperationalDataset &aDataset) otIp6Address addr; memcpy(addr.mFields.m8, aDataset.mMeshLocalPrefix.m8, 8); - memset(addr.mFields.m8 + 8, 0, 8); // Zero out the last 8 bytes. + memset(addr.mFields.m8 + 8, 0, 8); // Zero out the last 8 bytes. SuccessOrExit(mEncoder.OpenStruct()); SuccessOrExit(mEncoder.WriteUintPacked(SPINEL_PROP_IPV6_ML_PREFIX)); - SuccessOrExit(error = mEncoder.WriteIp6Address(addr)); // Mesh local prefix - SuccessOrExit(error = mEncoder.WriteUint8(64)); // Prefix length (in bits) + SuccessOrExit(error = mEncoder.WriteIp6Address(addr)); // Mesh local prefix + SuccessOrExit(error = mEncoder.WriteUint8(64)); // Prefix length (in bits) SuccessOrExit(mEncoder.CloseStruct()); } @@ -996,9 +979,9 @@ otError NcpBase::GetPropertyHandler_THREAD_PENDING_DATASET(void) otError NcpBase::GetPropertyHandler_IPV6_ML_PREFIX(void) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; const uint8_t *mlPrefix = otThreadGetMeshLocalPrefix(mInstance); - otIp6Address addr; + otIp6Address addr; VerifyOrExit(mlPrefix != NULL); // If `mlPrefix` is NULL send empty response. @@ -1007,8 +990,8 @@ otError NcpBase::GetPropertyHandler_IPV6_ML_PREFIX(void) // Zero out the last 8 bytes. memset(addr.mFields.m8 + 8, 0, 8); - SuccessOrExit(error = mEncoder.WriteIp6Address(addr)); // Mesh local prefix - SuccessOrExit(error = mEncoder.WriteUint8(64)); // Prefix length (in bits) + SuccessOrExit(error = mEncoder.WriteIp6Address(addr)); // Mesh local prefix + SuccessOrExit(error = mEncoder.WriteUint8(64)); // Prefix length (in bits) exit: return error; @@ -1016,9 +999,9 @@ exit: otError NcpBase::SetPropertyHandler_IPV6_ML_PREFIX(void) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; const uint8_t *meshLocalPrefix; - uint8_t prefixLength; + uint8_t prefixLength; SuccessOrExit(error = mDecoder.ReadIp6Address(meshLocalPrefix)); SuccessOrExit(error = mDecoder.ReadUint8(prefixLength)); @@ -1032,8 +1015,8 @@ exit: otError NcpBase::GetPropertyHandler_IPV6_ML_ADDR(void) { - otError error = OT_ERROR_NONE; - const otIp6Address *ml64 = otThreadGetMeshLocalEid(mInstance); + otError error = OT_ERROR_NONE; + const otIp6Address *ml64 = otThreadGetMeshLocalEid(mInstance); VerifyOrExit(ml64 != NULL); SuccessOrExit(error = mEncoder.WriteIp6Address(*ml64)); @@ -1044,7 +1027,7 @@ exit: otError NcpBase::GetPropertyHandler_IPV6_LL_ADDR(void) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; const otIp6Address *address = otThreadGetLinkLocalIp6Address(mInstance); VerifyOrExit(address != NULL); @@ -1076,10 +1059,10 @@ exit: otError NcpBase::InsertPropertyHandler_IPV6_ADDRESS_TABLE(void) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; otNetifAddress netifAddr; - uint32_t preferredLifetime; - uint32_t validLifetime; + uint32_t preferredLifetime; + uint32_t validLifetime; SuccessOrExit(error = mDecoder.ReadIp6Address(netifAddr.mAddress)); SuccessOrExit(error = mDecoder.ReadUint8(netifAddr.mPrefixLength)); @@ -1087,7 +1070,7 @@ otError NcpBase::InsertPropertyHandler_IPV6_ADDRESS_TABLE(void) SuccessOrExit(error = mDecoder.ReadUint32(validLifetime)); netifAddr.mPreferred = (preferredLifetime != 0); - netifAddr.mValid = (validLifetime != 0); + netifAddr.mValid = (validLifetime != 0); error = otIp6AddUnicastAddress(mInstance, &netifAddr); @@ -1097,7 +1080,7 @@ exit: otError NcpBase::RemovePropertyHandler_IPV6_ADDRESS_TABLE(void) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; const otIp6Address *addrPtr; SuccessOrExit(error = mDecoder.ReadIp6Address(addrPtr)); @@ -1127,8 +1110,8 @@ otError NcpBase::GetPropertyHandler_IPV6_ICMP_PING_OFFLOAD(void) otError NcpBase::SetPropertyHandler_IPV6_ICMP_PING_OFFLOAD(void) { - bool enabled = false; - otError error = OT_ERROR_NONE; + bool enabled = false; + otError error = OT_ERROR_NONE; SuccessOrExit(error = mDecoder.ReadBool(enabled)); @@ -1140,7 +1123,7 @@ exit: otError NcpBase::GetPropertyHandler_IPV6_MULTICAST_ADDRESS_TABLE(void) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; const otNetifMulticastAddress *address; for (address = otIp6GetMulticastAddresses(mInstance); address; address = address->mNext) @@ -1156,7 +1139,7 @@ exit: otError NcpBase::InsertPropertyHandler_IPV6_MULTICAST_ADDRESS_TABLE(void) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; const otIp6Address *addrPtr; SuccessOrExit(error = mDecoder.ReadIp6Address(addrPtr)); @@ -1174,7 +1157,7 @@ exit: otError NcpBase::RemovePropertyHandler_IPV6_MULTICAST_ADDRESS_TABLE(void) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; const otIp6Address *addrPtr; SuccessOrExit(error = mDecoder.ReadIp6Address(addrPtr)); @@ -1217,9 +1200,9 @@ otError NcpBase::GetPropertyHandler_IPV6_ICMP_PING_OFFLOAD_MODE(void) otError NcpBase::SetPropertyHandler_IPV6_ICMP_PING_OFFLOAD_MODE(void) { - otError error = OT_ERROR_NONE; - otIcmp6EchoMode mode = OT_ICMP6_ECHO_HANDLER_DISABLED; - uint8_t spinelMode; + otError error = OT_ERROR_NONE; + otIcmp6EchoMode mode = OT_ICMP6_ECHO_HANDLER_DISABLED; + uint8_t spinelMode; SuccessOrExit(error = mDecoder.ReadUint8(spinelMode)); @@ -1253,8 +1236,8 @@ otError NcpBase::GetPropertyHandler_THREAD_RLOC16_DEBUG_PASSTHRU(void) otError NcpBase::SetPropertyHandler_THREAD_RLOC16_DEBUG_PASSTHRU(void) { - bool enabled = false; - otError error = OT_ERROR_NONE; + bool enabled = false; + otError error = OT_ERROR_NONE; SuccessOrExit(error = mDecoder.ReadBool(enabled)); @@ -1267,7 +1250,7 @@ exit: otError NcpBase::GetPropertyHandler_THREAD_OFF_MESH_ROUTES(void) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; otExternalRouteConfig routeConfig; otNetworkDataIterator iter = OT_NETWORK_DATA_ITERATOR_INIT; @@ -1279,7 +1262,7 @@ otError NcpBase::GetPropertyHandler_THREAD_OFF_MESH_ROUTES(void) SuccessOrExit(error = mEncoder.WriteUint8(routeConfig.mPrefix.mLength)); SuccessOrExit(error = mEncoder.WriteBool(routeConfig.mStable)); SuccessOrExit(error = mEncoder.WriteUint8(ExternalRoutePreferenceToFlagByte(routeConfig.mPreference))); - SuccessOrExit(error = mEncoder.WriteBool(false)); // IsLocal + SuccessOrExit(error = mEncoder.WriteBool(false)); // IsLocal SuccessOrExit(error = mEncoder.WriteBool(routeConfig.mNextHopIsThisDevice)); SuccessOrExit(error = mEncoder.WriteUint16(routeConfig.mRloc16)); @@ -1298,7 +1281,7 @@ otError NcpBase::GetPropertyHandler_THREAD_OFF_MESH_ROUTES(void) SuccessOrExit(error = mEncoder.WriteUint8(routeConfig.mPrefix.mLength)); SuccessOrExit(error = mEncoder.WriteBool(routeConfig.mStable)); SuccessOrExit(error = mEncoder.WriteUint8(ExternalRoutePreferenceToFlagByte(routeConfig.mPreference))); - SuccessOrExit(error = mEncoder.WriteBool(true)); // IsLocal + SuccessOrExit(error = mEncoder.WriteBool(true)); // IsLocal SuccessOrExit(error = mEncoder.WriteBool(routeConfig.mNextHopIsThisDevice)); SuccessOrExit(error = mEncoder.WriteUint16(routeConfig.mRloc16)); @@ -1335,11 +1318,11 @@ static int FlagByteToExternalRoutePreference(uint8_t aFlags) otError NcpBase::InsertPropertyHandler_THREAD_OFF_MESH_ROUTES(void) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; otExternalRouteConfig routeConfig; - bool stable = false; - uint8_t flags = 0; - uint8_t prefixLength; + bool stable = false; + uint8_t flags = 0; + uint8_t prefixLength; memset(&routeConfig, 0, sizeof(otExternalRouteConfig)); @@ -1351,8 +1334,8 @@ otError NcpBase::InsertPropertyHandler_THREAD_OFF_MESH_ROUTES(void) SuccessOrExit(error = mDecoder.ReadUint8(flags)); routeConfig.mPrefix.mLength = prefixLength; - routeConfig.mStable = stable; - routeConfig.mPreference = FlagByteToExternalRoutePreference(flags); + routeConfig.mStable = stable; + routeConfig.mPreference = FlagByteToExternalRoutePreference(flags); error = otBorderRouterAddRoute(mInstance, &routeConfig); @@ -1362,9 +1345,9 @@ exit: otError NcpBase::RemovePropertyHandler_THREAD_OFF_MESH_ROUTES(void) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; otIp6Prefix ip6Prefix; - uint8_t prefixLength; + uint8_t prefixLength; memset(&ip6Prefix, 0, sizeof(otIp6Prefix)); @@ -1391,11 +1374,11 @@ exit: otError NcpBase::SetPropertyHandler_STREAM_NET(void) { const uint8_t *framePtr = NULL; - uint16_t frameLen = 0; - const uint8_t *metaPtr = NULL; - uint16_t metaLen = 0; - otMessage *message = NULL; - otError error = OT_ERROR_NONE; + uint16_t frameLen = 0; + const uint8_t *metaPtr = NULL; + uint16_t metaLen = 0; + otMessage * message = NULL; + otError error = OT_ERROR_NONE; // STREAM_NET requires layer 2 security. message = otIp6NewMessage(mInstance, true); @@ -1471,7 +1454,7 @@ otError NcpBase::GetPropertyHandler_JAM_DETECT_HISTORY_BITMAP(void) otError NcpBase::SetPropertyHandler_JAM_DETECT_ENABLE(void) { - bool enabled; + bool enabled; otError error = OT_ERROR_NONE; SuccessOrExit(error = mDecoder.ReadBool(enabled)); @@ -1491,8 +1474,8 @@ exit: otError NcpBase::SetPropertyHandler_JAM_DETECT_RSSI_THRESHOLD(void) { - int8_t threshold = 0; - otError error = OT_ERROR_NONE; + int8_t threshold = 0; + otError error = OT_ERROR_NONE; SuccessOrExit(error = mDecoder.ReadInt8(threshold)); @@ -1505,7 +1488,7 @@ exit: otError NcpBase::SetPropertyHandler_JAM_DETECT_WINDOW(void) { uint8_t window = 0; - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; SuccessOrExit(error = mDecoder.ReadUint8(window)); @@ -1517,7 +1500,7 @@ exit: otError NcpBase::SetPropertyHandler_JAM_DETECT_BUSY(void) { - uint8_t busy = 0; + uint8_t busy = 0; otError error = OT_ERROR_NONE; SuccessOrExit(error = mDecoder.ReadUint8(busy)); @@ -1817,7 +1800,7 @@ otError NcpBase::GetPropertyHandler_CNTR_IP_RX_FAILURE(void) otError NcpBase::GetPropertyHandler_MSG_BUFFER_COUNTERS(void) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; otBufferInfo bufferInfo; otMessageGetBufferInfo(mInstance, &bufferInfo); @@ -1845,7 +1828,7 @@ exit: otError NcpBase::GetPropertyHandler_CNTR_ALL_MAC_COUNTERS(void) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; const otMacCounters *counters = otLinkGetCounters(mInstance); if (counters == NULL) @@ -1902,9 +1885,9 @@ exit: otError NcpBase::GetPropertyHandler_MAC_WHITELIST(void) { - otMacFilterEntry entry; + otMacFilterEntry entry; otMacFilterIterator iterator = OT_MAC_FILTER_ITERATOR_INIT; - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; while (otLinkFilterGetNextAddress(mInstance, &iterator, &entry) == OT_ERROR_NONE) { @@ -1927,9 +1910,9 @@ otError NcpBase::GetPropertyHandler_MAC_WHITELIST_ENABLED(void) otError NcpBase::GetPropertyHandler_MAC_BLACKLIST(void) { - otMacFilterEntry entry; + otMacFilterEntry entry; otMacFilterIterator iterator = OT_MAC_FILTER_ITERATOR_INIT; - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; while (otLinkFilterGetNextAddress(mInstance, &iterator, &entry) == OT_ERROR_NONE) { @@ -1949,9 +1932,9 @@ otError NcpBase::GetPropertyHandler_MAC_BLACKLIST_ENABLED(void) otError NcpBase::GetPropertyHandler_MAC_FIXED_RSS(void) { - otMacFilterEntry entry; + otMacFilterEntry entry; otMacFilterIterator iterator = OT_MAC_FILTER_ITERATOR_INIT; - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; while (otLinkFilterGetNextRssIn(mInstance, &iterator, &entry) == OT_ERROR_NONE) { @@ -1977,7 +1960,7 @@ otError NcpBase::SetPropertyHandler_MAC_WHITELIST(void) while (mDecoder.GetRemainingLengthInStruct() > 0) { const otExtAddress *extAddress = NULL; - int8_t rss; + int8_t rss; SuccessOrExit(error = mDecoder.OpenStruct()); SuccessOrExit(error = mDecoder.ReadEui64(extAddress)); @@ -2024,9 +2007,9 @@ exit: otError NcpBase::SetPropertyHandler_MAC_WHITELIST_ENABLED(void) { - bool enabled; - otError error = OT_ERROR_NONE; - otMacFilterAddressMode mode = OT_MAC_FILTER_ADDRESS_MODE_DISABLED; + bool enabled; + otError error = OT_ERROR_NONE; + otMacFilterAddressMode mode = OT_MAC_FILTER_ADDRESS_MODE_DISABLED; SuccessOrExit(error = mDecoder.ReadBool(enabled)); @@ -2074,7 +2057,7 @@ exit: if (error != OT_ERROR_NONE) { - WritePropertyValueIsFrame(SPINEL_HEADER_FLAG | SPINEL_HEADER_IID_0, SPINEL_PROP_MAC_BLACKLIST); + WritePropertyValueIsFrame(SPINEL_HEADER_FLAG | SPINEL_HEADER_IID_0, SPINEL_PROP_MAC_BLACKLIST); } return error; @@ -2082,9 +2065,9 @@ exit: otError NcpBase::SetPropertyHandler_MAC_BLACKLIST_ENABLED(void) { - bool enabled; - otError error = OT_ERROR_NONE; - otMacFilterAddressMode mode = OT_MAC_FILTER_ADDRESS_MODE_DISABLED; + bool enabled; + otError error = OT_ERROR_NONE; + otMacFilterAddressMode mode = OT_MAC_FILTER_ADDRESS_MODE_DISABLED; SuccessOrExit(error = mDecoder.ReadBool(enabled)); @@ -2109,7 +2092,7 @@ otError NcpBase::SetPropertyHandler_MAC_FIXED_RSS(void) while (mDecoder.GetRemainingLengthInStruct() > 0) { const otExtAddress *extAddress; - int8_t rss; + int8_t rss; SuccessOrExit(error = mDecoder.OpenStruct()); @@ -2146,32 +2129,31 @@ exit: otError NcpBase::GetPropertyHandler_THREAD_MODE(void) { - uint8_t numericMode; + uint8_t numericMode; otLinkModeConfig modeConfig = otThreadGetLinkMode(mInstance); - numericMode = LinkFlagsToFlagByte( - modeConfig.mRxOnWhenIdle, - modeConfig.mSecureDataRequests, - modeConfig.mDeviceType, - modeConfig.mNetworkData - ); + numericMode = LinkFlagsToFlagByte(modeConfig.mRxOnWhenIdle, modeConfig.mSecureDataRequests, modeConfig.mDeviceType, + modeConfig.mNetworkData); return mEncoder.WriteUint8(numericMode); } otError NcpBase::SetPropertyHandler_THREAD_MODE(void) { - uint8_t numericMode = 0; + uint8_t numericMode = 0; otLinkModeConfig modeConfig; - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; SuccessOrExit(mDecoder.ReadUint8(numericMode)); - modeConfig.mRxOnWhenIdle = ((numericMode & SPINEL_THREAD_MODE_RX_ON_WHEN_IDLE) == SPINEL_THREAD_MODE_RX_ON_WHEN_IDLE); + modeConfig.mRxOnWhenIdle = + ((numericMode & SPINEL_THREAD_MODE_RX_ON_WHEN_IDLE) == SPINEL_THREAD_MODE_RX_ON_WHEN_IDLE); modeConfig.mSecureDataRequests = ((numericMode & SPINEL_THREAD_MODE_SECURE_DATA_REQUEST) == SPINEL_THREAD_MODE_SECURE_DATA_REQUEST); - modeConfig.mDeviceType = ((numericMode & SPINEL_THREAD_MODE_FULL_FUNCTION_DEV) == SPINEL_THREAD_MODE_FULL_FUNCTION_DEV); - modeConfig.mNetworkData = ((numericMode & SPINEL_THREAD_MODE_FULL_NETWORK_DATA) == SPINEL_THREAD_MODE_FULL_NETWORK_DATA); + modeConfig.mDeviceType = + ((numericMode & SPINEL_THREAD_MODE_FULL_FUNCTION_DEV) == SPINEL_THREAD_MODE_FULL_FUNCTION_DEV); + modeConfig.mNetworkData = + ((numericMode & SPINEL_THREAD_MODE_FULL_NETWORK_DATA) == SPINEL_THREAD_MODE_FULL_NETWORK_DATA); error = otThreadSetLinkMode(mInstance, modeConfig); @@ -2202,11 +2184,11 @@ otError NcpBase::SetPropertyHandler_NET_REQUIRE_JOIN_EXISTING(void) otError NcpBase::SetPropertyHandler_STREAM_NET_INSECURE(void) { const uint8_t *framePtr = NULL; - uint16_t frameLen = 0; - const uint8_t *metaPtr = NULL; - uint16_t metaLen = 0; - otMessage *message = NULL; - otError error = OT_ERROR_NONE; + uint16_t frameLen = 0; + const uint8_t *metaPtr = NULL; + uint16_t metaLen = 0; + otMessage * message = NULL; + otError error = OT_ERROR_NONE; // STREAM_NET_INSECURE packets are not secured at layer 2. message = otIp6NewMessage(mInstance, false); @@ -2241,7 +2223,6 @@ exit: if (error == OT_ERROR_NONE) { mInboundInsecureIpFrameCounter++; - } else { @@ -2269,7 +2250,7 @@ exit: otError NcpBase::InsertPropertyHandler_THREAD_ASSISTING_PORTS(void) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; uint16_t port; SuccessOrExit(error = mDecoder.ReadUint16(port)); @@ -2283,9 +2264,9 @@ exit: otError NcpBase::InsertPropertyHandler_MAC_WHITELIST(void) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; const otExtAddress *extAddress = NULL; - int8_t rss = OT_MAC_FILTER_FIXED_RSS_DISABLED; + int8_t rss = OT_MAC_FILTER_FIXED_RSS_DISABLED; SuccessOrExit(error = mDecoder.ReadEui64(extAddress)); @@ -2314,7 +2295,7 @@ exit: otError NcpBase::InsertPropertyHandler_MAC_BLACKLIST(void) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; const otExtAddress *extAddress = NULL; SuccessOrExit(error = mDecoder.ReadEui64(extAddress)); @@ -2332,9 +2313,9 @@ exit: otError NcpBase::InsertPropertyHandler_MAC_FIXED_RSS(void) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; const otExtAddress *extAddress = NULL; - int8_t rss = OT_MAC_FILTER_FIXED_RSS_DISABLED; + int8_t rss = OT_MAC_FILTER_FIXED_RSS_DISABLED; if (mDecoder.GetRemainingLength() > sizeof(int8_t)) { @@ -2353,7 +2334,7 @@ exit: otError NcpBase::RemovePropertyHandler_THREAD_ASSISTING_PORTS(void) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; uint16_t port; SuccessOrExit(error = mDecoder.ReadUint16(port)); @@ -2374,7 +2355,7 @@ exit: otError NcpBase::RemovePropertyHandler_MAC_WHITELIST(void) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; const otExtAddress *extAddress = NULL; SuccessOrExit(error = mDecoder.ReadEui64(extAddress)); @@ -2392,7 +2373,7 @@ exit: otError NcpBase::RemovePropertyHandler_MAC_BLACKLIST(void) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; const otExtAddress *extAddress = NULL; SuccessOrExit(error = mDecoder.ReadEui64(extAddress)); @@ -2410,7 +2391,7 @@ exit: otError NcpBase::RemovePropertyHandler_MAC_FIXED_RSS(void) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; const otExtAddress *extAddress = NULL; if (mDecoder.GetRemainingLength() > 0) @@ -2475,7 +2456,7 @@ void NcpBase::HandleDidReceiveNewLegacyUlaPrefix(const uint8_t *aUlaPrefix) void NcpBase::HandleLegacyNodeDidJoin(const otExtAddress *aExtAddr) { - mLegacyNodeDidJoin = true; + mLegacyNodeDidJoin = true; mLegacyLastJoinedNode = *aExtAddr; mChangedPropsSet.AddProperty(SPINEL_PROP_NEST_LEGACY_LAST_NODE_JOINED); mUpdateChangedPropsTask.Post(); @@ -2489,8 +2470,8 @@ otError NcpBase::GetPropertyHandler_NEST_LEGACY_ULA_PREFIX(void) otError NcpBase::SetPropertyHandler_NEST_LEGACY_ULA_PREFIX(void) { const uint8_t *ptr = NULL; - uint16_t len; - otError error = OT_ERROR_NONE; + uint16_t len; + otError error = OT_ERROR_NONE; SuccessOrExit(error = mDecoder.ReadData(ptr, len)); @@ -2510,7 +2491,6 @@ exit: otError NcpBase::GetPropertyHandler_NEST_LEGACY_LAST_NODE_JOINED(void) { - if (!mLegacyNodeDidJoin) { memset(&mLegacyLastJoinedNode, 0, sizeof(mLegacyLastJoinedNode)); @@ -2583,7 +2563,7 @@ otError NcpBase::GetPropertyHandler_MAC_SCAN_MASK(void) otError NcpBase::SetPropertyHandler_MAC_SCAN_MASK(void) { uint32_t newMask = 0; - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; SuccessOrExit(error = DecodeChannelMask(newMask)); VerifyOrExit((~mSupportedChannelMask & newMask) == 0, error = OT_ERROR_INVALID_ARGS); @@ -2622,7 +2602,6 @@ otError NcpBase::GetPropertyHandler_MAC_SCAN_STATE(void) if (otLinkIsActiveScanInProgress(mInstance)) { scanState = SPINEL_SCAN_STATE_BEACON; - } else if (otLinkIsEnergyScanInProgress(mInstance)) { @@ -2663,13 +2642,7 @@ otError NcpBase::SetPropertyHandler_MAC_SCAN_STATE(void) else #endif // OPENTHREAD_RADIO || OPENTHREAD_ENABLE_RAW_LINK_API { - error = otLinkActiveScan( - mInstance, - mChannelMask, - mScanPeriod, - &HandleActiveScanResult_Jump, - this - ); + error = otLinkActiveScan(mInstance, mChannelMask, mScanPeriod, &HandleActiveScanResult_Jump, this); } SuccessOrExit(error); @@ -2686,41 +2659,23 @@ otError NcpBase::SetPropertyHandler_MAC_SCAN_STATE(void) VerifyOrExit(mCurScanChannel == kInvalidScanChannel, error = OT_ERROR_INVALID_STATE); VerifyOrExit(HasOnly1BitSet(mChannelMask), error = OT_ERROR_INVALID_ARGS); - scanChannel = IndexOfMSB(mChannelMask); + scanChannel = IndexOfMSB(mChannelMask); mCurScanChannel = (int8_t)scanChannel; - error = otLinkRawEnergyScan( - mInstance, - scanChannel, - mScanPeriod, - LinkRawEnergyScanDone - ); + error = otLinkRawEnergyScan(mInstance, scanChannel, mScanPeriod, LinkRawEnergyScanDone); } else #endif // OPENTHREAD_RADIO || OPENTHREAD_ENABLE_RAW_LINK_API { - error = otLinkEnergyScan( - mInstance, - mChannelMask, - mScanPeriod, - &HandleEnergyScanResult_Jump, - this - ); + error = otLinkEnergyScan(mInstance, mChannelMask, mScanPeriod, &HandleEnergyScanResult_Jump, this); } SuccessOrExit(error); break; case SPINEL_SCAN_STATE_DISCOVER: - error = otThreadDiscover( - mInstance, - mChannelMask, - mDiscoveryScanPanId, - mDiscoveryScanJoinerFlag, - mDiscoveryScanEnableFiltering, - &HandleActiveScanResult_Jump, - this - ); + error = otThreadDiscover(mInstance, mChannelMask, mDiscoveryScanPanId, mDiscoveryScanJoinerFlag, + mDiscoveryScanEnableFiltering, &HandleActiveScanResult_Jump, this); SuccessOrExit(error); break; @@ -2761,23 +2716,20 @@ void NcpBase::HandleActiveScanResult(otActiveScanResult *aResult) flags |= SPINEL_BEACON_THREAD_FLAG_NATIVE; } - SuccessOrExit(error = mEncoder.BeginFrame( - SPINEL_HEADER_FLAG | SPINEL_HEADER_IID_0, - SPINEL_CMD_PROP_VALUE_INSERTED, - SPINEL_PROP_MAC_SCAN_BEACON - )); + SuccessOrExit(error = mEncoder.BeginFrame(SPINEL_HEADER_FLAG | SPINEL_HEADER_IID_0, + SPINEL_CMD_PROP_VALUE_INSERTED, SPINEL_PROP_MAC_SCAN_BEACON)); SuccessOrExit(error = mEncoder.WriteUint8(aResult->mChannel)); SuccessOrExit(error = mEncoder.WriteInt8(aResult->mRssi)); - SuccessOrExit(error = mEncoder.OpenStruct()); // "mac-layer data" + SuccessOrExit(error = mEncoder.OpenStruct()); // "mac-layer data" SuccessOrExit(error = mEncoder.WriteEui64(aResult->mExtAddress)); - SuccessOrExit(error = mEncoder.WriteUint16(0xffff)); // short address, not given + SuccessOrExit(error = mEncoder.WriteUint16(0xffff)); // short address, not given SuccessOrExit(error = mEncoder.WriteUint16(aResult->mPanId)); SuccessOrExit(error = mEncoder.WriteUint8(aResult->mLqi)); SuccessOrExit(error = mEncoder.CloseStruct()); - SuccessOrExit(error = mEncoder.OpenStruct()); // "net-layer data" - SuccessOrExit(error = mEncoder.WriteUintPacked(SPINEL_PROTOCOL_TYPE_THREAD)); // type + SuccessOrExit(error = mEncoder.OpenStruct()); // "net-layer data" + SuccessOrExit(error = mEncoder.WriteUintPacked(SPINEL_PROTOCOL_TYPE_THREAD)); // type SuccessOrExit(error = mEncoder.WriteUint8(flags)); SuccessOrExit(error = mEncoder.WriteUtf8(aResult->mNetworkName.m8)); SuccessOrExit(error = mEncoder.WriteDataWithLen(aResult->mExtendedPanId.m8, OT_EXT_PAN_ID_SIZE)); @@ -2817,11 +2769,8 @@ void NcpBase::HandleEnergyScanResult(otEnergyScanResult *aResult) if (aResult) { - SuccessOrExit(error = mEncoder.BeginFrame( - SPINEL_HEADER_FLAG | SPINEL_HEADER_IID_0, - SPINEL_CMD_PROP_VALUE_INSERTED, - SPINEL_PROP_MAC_ENERGY_SCAN_RESULT - )); + SuccessOrExit(error = mEncoder.BeginFrame(SPINEL_HEADER_FLAG | SPINEL_HEADER_IID_0, + SPINEL_CMD_PROP_VALUE_INSERTED, SPINEL_PROP_MAC_ENERGY_SCAN_RESULT)); SuccessOrExit(error = mEncoder.WriteUint8(aResult->mChannel)); SuccessOrExit(error = mEncoder.WriteInt8(aResult->mMaxRssi)); SuccessOrExit(error = mEncoder.EndFrame()); @@ -2876,10 +2825,10 @@ exit: otError NcpBase::SendDatagramMessage(otMessage *aMessage) { - otError error = OT_ERROR_NONE; - uint8_t header = SPINEL_HEADER_FLAG | SPINEL_HEADER_IID_0; - bool isSecure = otMessageIsLinkSecurityEnabled(aMessage); - spinel_prop_key_t propKey = isSecure ? SPINEL_PROP_STREAM_NET : SPINEL_PROP_STREAM_NET_INSECURE; + otError error = OT_ERROR_NONE; + uint8_t header = SPINEL_HEADER_FLAG | SPINEL_HEADER_IID_0; + bool isSecure = otMessageIsLinkSecurityEnabled(aMessage); + spinel_prop_key_t propKey = isSecure ? SPINEL_PROP_STREAM_NET : SPINEL_PROP_STREAM_NET_INSECURE; SuccessOrExit(error = mEncoder.BeginFrame(header, SPINEL_CMD_PROP_VALUE_IS, propKey)); SuccessOrExit(error = mEncoder.WriteUint16(otMessageGetLength(aMessage))); @@ -2904,7 +2853,7 @@ exit: otError NcpBase::SendQueuedDatagramMessages(void) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; otMessage *message; while ((message = otMessageQueueGetHead(&mMessageQueue)) != NULL) @@ -2947,29 +2896,28 @@ void NcpBase::ProcessThreadChangedFlags(void) { static const struct { - uint32_t mThreadFlag; + uint32_t mThreadFlag; spinel_prop_key_t mPropKey; - } kFlags[] = - { - { OT_CHANGED_IP6_ADDRESS_ADDED, SPINEL_PROP_IPV6_ADDRESS_TABLE }, - { OT_CHANGED_IP6_ADDRESS_REMOVED, SPINEL_PROP_IPV6_ADDRESS_TABLE }, - { OT_CHANGED_THREAD_ROLE, SPINEL_PROP_NET_ROLE }, - { OT_CHANGED_THREAD_LL_ADDR, SPINEL_PROP_IPV6_LL_ADDR }, - { OT_CHANGED_THREAD_ML_ADDR, SPINEL_PROP_IPV6_ML_ADDR }, - { OT_CHANGED_THREAD_PARTITION_ID, SPINEL_PROP_NET_PARTITION_ID }, - { OT_CHANGED_THREAD_KEY_SEQUENCE_COUNTER, SPINEL_PROP_NET_KEY_SEQUENCE_COUNTER }, - { OT_CHANGED_THREAD_NETDATA, SPINEL_PROP_THREAD_LEADER_NETWORK_DATA }, - { OT_CHANGED_THREAD_CHILD_ADDED, SPINEL_PROP_THREAD_CHILD_TABLE }, - { OT_CHANGED_THREAD_CHILD_REMOVED, SPINEL_PROP_THREAD_CHILD_TABLE }, - { OT_CHANGED_IP6_MULTICAST_SUBSRCRIBED, SPINEL_PROP_IPV6_MULTICAST_ADDRESS_TABLE }, - { OT_CHANGED_IP6_MULTICAST_UNSUBSRCRIBED, SPINEL_PROP_IPV6_MULTICAST_ADDRESS_TABLE }, - { OT_CHANGED_THREAD_CHANNEL, SPINEL_PROP_PHY_CHAN }, - { OT_CHANGED_THREAD_PANID, SPINEL_PROP_MAC_15_4_PANID }, - { OT_CHANGED_THREAD_NETWORK_NAME, SPINEL_PROP_NET_NETWORK_NAME }, - { OT_CHANGED_THREAD_EXT_PANID, SPINEL_PROP_NET_XPANID }, - { OT_CHANGED_MASTER_KEY, SPINEL_PROP_NET_MASTER_KEY }, - { OT_CHANGED_PSKC, SPINEL_PROP_NET_PSKC }, - { OT_CHANGED_CHANNEL_MANAGER_NEW_CHANNEL, SPINEL_PROP_CHANNEL_MANAGER_NEW_CHANNEL }, + } kFlags[] = { + {OT_CHANGED_IP6_ADDRESS_ADDED, SPINEL_PROP_IPV6_ADDRESS_TABLE}, + {OT_CHANGED_IP6_ADDRESS_REMOVED, SPINEL_PROP_IPV6_ADDRESS_TABLE}, + {OT_CHANGED_THREAD_ROLE, SPINEL_PROP_NET_ROLE}, + {OT_CHANGED_THREAD_LL_ADDR, SPINEL_PROP_IPV6_LL_ADDR}, + {OT_CHANGED_THREAD_ML_ADDR, SPINEL_PROP_IPV6_ML_ADDR}, + {OT_CHANGED_THREAD_PARTITION_ID, SPINEL_PROP_NET_PARTITION_ID}, + {OT_CHANGED_THREAD_KEY_SEQUENCE_COUNTER, SPINEL_PROP_NET_KEY_SEQUENCE_COUNTER}, + {OT_CHANGED_THREAD_NETDATA, SPINEL_PROP_THREAD_LEADER_NETWORK_DATA}, + {OT_CHANGED_THREAD_CHILD_ADDED, SPINEL_PROP_THREAD_CHILD_TABLE}, + {OT_CHANGED_THREAD_CHILD_REMOVED, SPINEL_PROP_THREAD_CHILD_TABLE}, + {OT_CHANGED_IP6_MULTICAST_SUBSRCRIBED, SPINEL_PROP_IPV6_MULTICAST_ADDRESS_TABLE}, + {OT_CHANGED_IP6_MULTICAST_UNSUBSRCRIBED, SPINEL_PROP_IPV6_MULTICAST_ADDRESS_TABLE}, + {OT_CHANGED_THREAD_CHANNEL, SPINEL_PROP_PHY_CHAN}, + {OT_CHANGED_THREAD_PANID, SPINEL_PROP_MAC_15_4_PANID}, + {OT_CHANGED_THREAD_NETWORK_NAME, SPINEL_PROP_NET_NETWORK_NAME}, + {OT_CHANGED_THREAD_EXT_PANID, SPINEL_PROP_NET_XPANID}, + {OT_CHANGED_MASTER_KEY, SPINEL_PROP_NET_MASTER_KEY}, + {OT_CHANGED_PSKC, SPINEL_PROP_NET_PSKC}, + {OT_CHANGED_CHANNEL_MANAGER_NEW_CHANNEL, SPINEL_PROP_CHANNEL_MANAGER_NEW_CHANNEL}, }; VerifyOrExit(mThreadChangedFlags != 0); @@ -2992,12 +2940,11 @@ void NcpBase::ProcessThreadChangedFlags(void) break; } - if ((otThreadGetDeviceRole(mInstance) == OT_DEVICE_ROLE_LEADER) - && otThreadIsSingleton(mInstance) + if ((otThreadGetDeviceRole(mInstance) == OT_DEVICE_ROLE_LEADER) && otThreadIsSingleton(mInstance) #if OPENTHREAD_ENABLE_LEGACY && !mLegacyNodeDidJoin #endif - ) + ) { mThreadChangedFlags &= ~static_cast(OT_CHANGED_THREAD_PARTITION_ID); otThreadSetEnabled(mInstance, false); @@ -3016,8 +2963,8 @@ void NcpBase::ProcessThreadChangedFlags(void) if (mThreadChangedFlags & threadFlag) { - spinel_prop_key_t propKey = kFlags[i].mPropKey; - bool shouldAddProperty = true; + spinel_prop_key_t propKey = kFlags[i].mPropKey; + bool shouldAddProperty = true; // Child table changes are reported using the `HandleChildAdded()` and // `HandleChildRemoved()` callbacks emitting spinel `VALUE_INSERTED` and @@ -3028,7 +2975,7 @@ void NcpBase::ProcessThreadChangedFlags(void) if (propKey == SPINEL_PROP_THREAD_CHILD_TABLE) { - shouldAddProperty = mShouldEmitChildTableUpdate; + shouldAddProperty = mShouldEmitChildTableUpdate; mShouldEmitChildTableUpdate = false; } @@ -3057,8 +3004,8 @@ exit: return; } -} // namespace Ncp -} // namespace ot +} // namespace Ncp +} // namespace ot // ---------------------------------------------------------------------------- // MARK: Legacy network APIs diff --git a/src/ncp/ncp_base_radio.cpp b/src/ncp/ncp_base_radio.cpp index b5d6cbb19..1882ddef8 100644 --- a/src/ncp/ncp_base_radio.cpp +++ b/src/ncp/ncp_base_radio.cpp @@ -59,8 +59,8 @@ void NcpBase::LinkRawReceiveDone(otInstance *, otRadioFrame *aFrame, otError aEr void NcpBase::LinkRawReceiveDone(otRadioFrame *aFrame, otError aError) { - uint16_t flags = 0; - uint8_t header = SPINEL_HEADER_FLAG | SPINEL_HEADER_IID_0; + uint16_t flags = 0; + uint8_t header = SPINEL_HEADER_FLAG | SPINEL_HEADER_IID_0; if (aFrame->mDidTx) { @@ -78,19 +78,19 @@ void NcpBase::LinkRawReceiveDone(otRadioFrame *aFrame, otError aError) } // Append metadata (rssi, etc) - SuccessOrExit(mEncoder.WriteInt8(aFrame->mInfo.mRxInfo.mRssi)); // RSSI - SuccessOrExit(mEncoder.WriteInt8(-128)); // Noise Floor (Currently unused) - SuccessOrExit(mEncoder.WriteUint16(flags)); // Flags + SuccessOrExit(mEncoder.WriteInt8(aFrame->mInfo.mRxInfo.mRssi)); // RSSI + SuccessOrExit(mEncoder.WriteInt8(-128)); // Noise Floor (Currently unused) + SuccessOrExit(mEncoder.WriteUint16(flags)); // Flags - SuccessOrExit(mEncoder.OpenStruct()); // PHY-data - SuccessOrExit(mEncoder.WriteUint8(aFrame->mChannel)); // 802.15.4 channel (Receive channel) - SuccessOrExit(mEncoder.WriteUint8(aFrame->mInfo.mRxInfo.mLqi)); // 802.15.4 LQI - SuccessOrExit(mEncoder.WriteUint32(aFrame->mInfo.mRxInfo.mMsec)); // The timestamp milliseconds - SuccessOrExit(mEncoder.WriteUint16(aFrame->mInfo.mRxInfo.mUsec)); // The timestamp microseconds, offset to mMsec + SuccessOrExit(mEncoder.OpenStruct()); // PHY-data + SuccessOrExit(mEncoder.WriteUint8(aFrame->mChannel)); // 802.15.4 channel (Receive channel) + SuccessOrExit(mEncoder.WriteUint8(aFrame->mInfo.mRxInfo.mLqi)); // 802.15.4 LQI + SuccessOrExit(mEncoder.WriteUint32(aFrame->mInfo.mRxInfo.mMsec)); // The timestamp milliseconds + SuccessOrExit(mEncoder.WriteUint16(aFrame->mInfo.mRxInfo.mUsec)); // The timestamp microseconds, offset to mMsec SuccessOrExit(mEncoder.CloseStruct()); - SuccessOrExit(mEncoder.OpenStruct()); // Vendor-data - SuccessOrExit(mEncoder.WriteUintPacked(aError)); // Receive error + SuccessOrExit(mEncoder.OpenStruct()); // Vendor-data + SuccessOrExit(mEncoder.WriteUintPacked(aError)); // Receive error SuccessOrExit(mEncoder.CloseStruct()); SuccessOrExit(mEncoder.EndFrame()); @@ -99,8 +99,7 @@ exit: return; } -void NcpBase::LinkRawTransmitDone(otInstance *, otRadioFrame *aFrame, - otRadioFrame *aAckFrame, otError aError) +void NcpBase::LinkRawTransmitDone(otInstance *, otRadioFrame *aFrame, otRadioFrame *aAckFrame, otError aError) { sNcpInstance->LinkRawTransmitDone(aFrame, aAckFrame, aError); } @@ -109,8 +108,8 @@ void NcpBase::LinkRawTransmitDone(otRadioFrame *aFrame, otRadioFrame *aAckFrame, { if (mCurTransmitTID) { - uint8_t header = SPINEL_HEADER_FLAG | SPINEL_HEADER_IID_0 | mCurTransmitTID; - bool framePending = (aAckFrame != NULL && static_cast(aAckFrame)->GetFramePending()); + uint8_t header = SPINEL_HEADER_FLAG | SPINEL_HEADER_IID_0 | mCurTransmitTID; + bool framePending = (aAckFrame != NULL && static_cast(aAckFrame)->GetFramePending()); // Clear cached transmit TID mCurTransmitTID = 0; @@ -124,14 +123,14 @@ void NcpBase::LinkRawTransmitDone(otRadioFrame *aFrame, otRadioFrame *aAckFrame, SuccessOrExit(mEncoder.WriteUint16(aAckFrame->mLength)); SuccessOrExit(mEncoder.WriteData(aAckFrame->mPsdu, aAckFrame->mLength)); - SuccessOrExit(mEncoder.WriteInt8(aAckFrame->mInfo.mRxInfo.mRssi)); // RSSI - SuccessOrExit(mEncoder.WriteInt8(-128)); // Noise Floor (Currently unused) - SuccessOrExit(mEncoder.WriteUint16(0)); // Flags + SuccessOrExit(mEncoder.WriteInt8(aAckFrame->mInfo.mRxInfo.mRssi)); // RSSI + SuccessOrExit(mEncoder.WriteInt8(-128)); // Noise Floor (Currently unused) + SuccessOrExit(mEncoder.WriteUint16(0)); // Flags - SuccessOrExit(mEncoder.OpenStruct()); // PHY-data + SuccessOrExit(mEncoder.OpenStruct()); // PHY-data - SuccessOrExit(mEncoder.WriteUint8(aAckFrame->mChannel)); // Receive channel - SuccessOrExit(mEncoder.WriteUint8(aAckFrame->mInfo.mRxInfo.mLqi)); // Link Quality Indicator + SuccessOrExit(mEncoder.WriteUint8(aAckFrame->mChannel)); // Receive channel + SuccessOrExit(mEncoder.WriteUint8(aAckFrame->mInfo.mRxInfo.mLqi)); // Link Quality Indicator SuccessOrExit(mEncoder.CloseStruct()); } @@ -160,12 +159,8 @@ void NcpBase::LinkRawEnergyScanDone(int8_t aEnergyScanMaxRssi) // since the energy scan could have been on a different channel. otLinkRawReceive(mInstance, &NcpBase::LinkRawReceiveDone); - SuccessOrExit( - mEncoder.BeginFrame( - SPINEL_HEADER_FLAG | SPINEL_HEADER_IID_0, - SPINEL_CMD_PROP_VALUE_IS, - SPINEL_PROP_MAC_ENERGY_SCAN_RESULT - )); + SuccessOrExit(mEncoder.BeginFrame(SPINEL_HEADER_FLAG | SPINEL_HEADER_IID_0, SPINEL_CMD_PROP_VALUE_IS, + SPINEL_PROP_MAC_ENERGY_SCAN_RESULT)); SuccessOrExit(mEncoder.WriteUint8(static_cast(scanChannel))); SuccessOrExit(mEncoder.WriteInt8(aEnergyScanMaxRssi)); @@ -173,12 +168,8 @@ void NcpBase::LinkRawEnergyScanDone(int8_t aEnergyScanMaxRssi) // We are finished with the scan, so send out // a property update indicating such. - SuccessOrExit( - mEncoder.BeginFrame( - SPINEL_HEADER_FLAG | SPINEL_HEADER_IID_0, - SPINEL_CMD_PROP_VALUE_IS, - SPINEL_PROP_MAC_SCAN_STATE - )); + SuccessOrExit(mEncoder.BeginFrame(SPINEL_HEADER_FLAG | SPINEL_HEADER_IID_0, SPINEL_CMD_PROP_VALUE_IS, + SPINEL_PROP_MAC_SCAN_STATE)); SuccessOrExit(mEncoder.WriteUint8(SPINEL_SCAN_STATE_IDLE)); SuccessOrExit(mEncoder.EndFrame()); @@ -249,7 +240,7 @@ exit: otError NcpBase::RemovePropertyHandler_MAC_SRC_MATCH_SHORT_ADDRESSES(void) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; uint16_t shortAddress; SuccessOrExit(error = mDecoder.ReadUint16(shortAddress)); @@ -262,10 +253,11 @@ exit: otError NcpBase::RemovePropertyHandler_MAC_SRC_MATCH_EXTENDED_ADDRESSES(void) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; const otExtAddress *extAddress; - SuccessOrExit(error = mDecoder.ReadEui64(extAddress));; + SuccessOrExit(error = mDecoder.ReadEui64(extAddress)); + ; error = otLinkRawSrcMatchClearExtEntry(mInstance, extAddress); @@ -275,7 +267,7 @@ exit: otError NcpBase::InsertPropertyHandler_MAC_SRC_MATCH_SHORT_ADDRESSES(void) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; uint16_t shortAddress; SuccessOrExit(error = mDecoder.ReadUint16(shortAddress)); @@ -288,7 +280,7 @@ exit: otError NcpBase::InsertPropertyHandler_MAC_SRC_MATCH_EXTENDED_ADDRESSES(void) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; const otExtAddress *extAddress = NULL; SuccessOrExit(error = mDecoder.ReadEui64(extAddress)); @@ -301,7 +293,7 @@ exit: otError NcpBase::SetPropertyHandler_PHY_ENABLED(void) { - bool value = false; + bool value = false; otError error = OT_ERROR_NONE; SuccessOrExit(error = mDecoder.ReadBool(value)); @@ -334,7 +326,7 @@ exit: otError NcpBase::SetPropertyHandler_MAC_15_4_SADDR(void) { uint16_t shortAddress; - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; SuccessOrExit(error = mDecoder.ReadUint16(shortAddress)); @@ -347,9 +339,9 @@ exit: otError NcpBase::SetPropertyHandler_STREAM_RAW(uint8_t aHeader) { const uint8_t *frameBuffer = NULL; - otRadioFrame *frame; - uint16_t frameLen = 0; - otError error = OT_ERROR_NONE; + otRadioFrame * frame; + uint16_t frameLen = 0; + otError error = OT_ERROR_NONE; VerifyOrExit(otLinkRawIsEnabled(mInstance), error = OT_ERROR_INVALID_STATE); @@ -388,7 +380,7 @@ exit: return error; } -} // namespace Ncp -} // namespace ot +} // namespace Ncp +} // namespace ot #endif // OPENTHREAD_RADIO || OPENTHREAD_ENABLE_RAW_LINK_API diff --git a/src/ncp/ncp_buffer.cpp b/src/ncp/ncp_buffer.cpp index 6097628cb..a631dd65f 100644 --- a/src/ncp/ncp_buffer.cpp +++ b/src/ncp/ncp_buffer.cpp @@ -32,19 +32,19 @@ #include "ncp_buffer.hpp" -#include "utils/wrap_string.h" #include "common/code_utils.hpp" #include "common/debug.hpp" +#include "utils/wrap_string.h" namespace ot { namespace Ncp { const NcpFrameBuffer::FrameTag NcpFrameBuffer::kInvalidTag = NULL; -NcpFrameBuffer::NcpFrameBuffer(uint8_t *aBuffer, uint16_t aBufferLen) : - mBuffer(aBuffer), - mBufferEnd(aBuffer + aBufferLen), - mBufferLength(aBufferLen) +NcpFrameBuffer::NcpFrameBuffer(uint8_t *aBuffer, uint16_t aBufferLen) + : mBuffer(aBuffer) + , mBufferEnd(aBuffer + aBufferLen) + , mBufferLength(aBufferLen) { for (uint8_t priority = 0; priority < kNumPrios; priority++) { @@ -62,27 +62,27 @@ void NcpFrameBuffer::Clear(void) otMessage *message; // Write (InFrame) related variables - mWriteFrameStart[kPriorityLow] = mBuffer; + mWriteFrameStart[kPriorityLow] = mBuffer; mWriteFrameStart[kPriorityHigh] = GetUpdatedBufPtr(mBuffer, 1, kBackward); - mWriteDirection = kUnknown; - mWriteSegmentHead = mBuffer; - mWriteSegmentTail = mBuffer; - mWriteFrameTag = kInvalidTag; + mWriteDirection = kUnknown; + mWriteSegmentHead = mBuffer; + mWriteSegmentTail = mBuffer; + mWriteFrameTag = kInvalidTag; // Read (OutFrame) related variables - mReadDirection = kForward; - mReadState = kReadStateNotActive; + mReadDirection = kForward; + mReadState = kReadStateNotActive; mReadFrameLength = kUnknownFrameLength; - mReadFrameStart[kPriorityLow] = mBuffer; + mReadFrameStart[kPriorityLow] = mBuffer; mReadFrameStart[kPriorityHigh] = GetUpdatedBufPtr(mBuffer, 1, kBackward); - mReadSegmentHead = mBuffer; - mReadSegmentTail = mBuffer; - mReadPointer = mBuffer; + mReadSegmentHead = mBuffer; + mReadSegmentTail = mBuffer; + mReadPointer = mBuffer; - mReadMessage = NULL; + mReadMessage = NULL; mReadMessageOffset = 0; - mReadMessageTail = mMessageBuffer; + mReadMessageTail = mMessageBuffer; // Free all messages in the queues. @@ -108,13 +108,13 @@ void NcpFrameBuffer::Clear(void) void NcpFrameBuffer::SetFrameAddedCallback(BufferCallback aFrameAddedCallback, void *aFrameAddedContext) { mFrameAddedCallback = aFrameAddedCallback; - mFrameAddedContext = aFrameAddedContext; + mFrameAddedContext = aFrameAddedContext; } void NcpFrameBuffer::SetFrameRemovedCallback(BufferCallback aFrameRemovedCallback, void *aFrameRemovedContext) { mFrameRemovedCallback = aFrameRemovedCallback; - mFrameRemovedContext = aFrameRemovedContext; + mFrameRemovedContext = aFrameRemovedContext; } // Returns an updated buffer pointer by moving forward/backward (based on `aDirection`) from `aBufPtr` by a given @@ -168,7 +168,7 @@ uint16_t NcpFrameBuffer::GetDistance(uint8_t *aStartPtr, uint8_t *aEndPtr, Direc } else { - distance = static_cast(mBufferEnd - aStartPtr); + distance = static_cast(mBufferEnd - aStartPtr); distance += static_cast(aEndPtr - mBuffer); } @@ -182,7 +182,7 @@ uint16_t NcpFrameBuffer::GetDistance(uint8_t *aStartPtr, uint8_t *aEndPtr, Direc } else { - distance = static_cast(mBufferEnd - aEndPtr); + distance = static_cast(mBufferEnd - aEndPtr); distance += static_cast(aStartPtr - mBuffer); } @@ -199,7 +199,7 @@ uint16_t NcpFrameBuffer::GetDistance(uint8_t *aStartPtr, uint8_t *aEndPtr, Direc // Writes a uint16 value at the given buffer pointer (big-endian style). void NcpFrameBuffer::WriteUint16At(uint8_t *aBufPtr, uint16_t aValue, Direction aDirection) { - *aBufPtr = (aValue >> 8); + *aBufPtr = (aValue >> 8); *GetUpdatedBufPtr(aBufPtr, 1, aDirection) = (aValue & 0xff); } @@ -217,7 +217,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 error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; uint8_t *newTail; assert(mWriteDirection != kUnknown); @@ -228,7 +228,7 @@ otError NcpFrameBuffer::InFrameAppend(uint8_t aByte) if (newTail != mWriteFrameStart[(mWriteDirection == kForward) ? kBackward : kForward]) { *mWriteSegmentTail = aByte; - mWriteSegmentTail = newTail; + mWriteSegmentTail = newTail; } else { @@ -242,7 +242,7 @@ otError NcpFrameBuffer::InFrameAppend(uint8_t aByte) // This method begins a new segment (if one is not already open). otError NcpFrameBuffer::InFrameBeginSegment(void) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; uint16_t headerFlags = kSegmentHeaderNoFlag; // Verify that segment is not yet started (i.e., head and tail are the same). @@ -412,17 +412,18 @@ otError NcpFrameBuffer::InFrameGetPosition(WritePosition &aPosition) // Begin a new segment (if we are not in middle of segment already). SuccessOrExit(error = InFrameBeginSegment()); - aPosition.mPosition = mWriteSegmentTail; + aPosition.mPosition = mWriteSegmentTail; aPosition.mSegmentHead = mWriteSegmentHead; exit: return error; } -otError NcpFrameBuffer::InFrameOverwrite(const WritePosition &aPosition, const uint8_t *aDataBuffer, - uint16_t aDataBufferLength) +otError NcpFrameBuffer::InFrameOverwrite(const WritePosition &aPosition, + const uint8_t * aDataBuffer, + uint16_t aDataBufferLength) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; uint8_t *bufPtr; uint16_t segmentLength; uint16_t distance; @@ -433,7 +434,7 @@ otError NcpFrameBuffer::InFrameOverwrite(const WritePosition &aPosition, const u // Ensure the overwrite does not go beyond current sgement tail. segmentLength = GetDistance(mWriteSegmentHead, mWriteSegmentTail, mWriteDirection); - distance = GetDistance(mWriteSegmentHead, aPosition.mPosition, mWriteDirection); + distance = GetDistance(mWriteSegmentHead, aPosition.mPosition, mWriteDirection); VerifyOrExit(distance + aDataBufferLength <= segmentLength, error = OT_ERROR_INVALID_ARGS); bufPtr = aPosition.mPosition; @@ -461,7 +462,7 @@ uint16_t NcpFrameBuffer::InFrameGetDistance(const WritePosition &aPosition) cons VerifyOrExit(aPosition.mSegmentHead == mWriteSegmentHead); segmentLength = GetDistance(mWriteSegmentHead, mWriteSegmentTail, mWriteDirection); - offset = GetDistance(mWriteSegmentHead, aPosition.mPosition, mWriteDirection); + offset = GetDistance(mWriteSegmentHead, aPosition.mPosition, mWriteDirection); VerifyOrExit(offset < segmentLength); distance = GetDistance(aPosition.mPosition, mWriteSegmentTail, mWriteDirection); @@ -472,7 +473,7 @@ exit: otError NcpFrameBuffer::InFrameReset(const WritePosition &aPosition) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; uint16_t segmentLength; uint16_t offset; @@ -480,7 +481,7 @@ otError NcpFrameBuffer::InFrameReset(const WritePosition &aPosition) VerifyOrExit(aPosition.mSegmentHead == mWriteSegmentHead, error = OT_ERROR_INVALID_ARGS); segmentLength = GetDistance(mWriteSegmentHead, mWriteSegmentTail, mWriteDirection); - offset = GetDistance(mWriteSegmentHead, aPosition.mPosition, mWriteDirection); + offset = GetDistance(mWriteSegmentHead, aPosition.mPosition, mWriteDirection); VerifyOrExit(offset < segmentLength, error = OT_ERROR_INVALID_ARGS); mWriteSegmentTail = aPosition.mPosition; @@ -492,7 +493,7 @@ exit: otError NcpFrameBuffer::InFrameEnd(void) { otMessage *message; - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; VerifyOrExit(mWriteDirection != kUnknown, error = OT_ERROR_INVALID_STATE); @@ -549,7 +550,7 @@ void NcpFrameBuffer::OutFrameSelectReadDirection(void) // Start/Prepare a new segment for reading. otError NcpFrameBuffer::OutFramePrepareSegment(void) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; uint16_t header; while (true) @@ -572,7 +573,7 @@ otError NcpFrameBuffer::OutFramePrepareSegment(void) // Find tail/end of current segment. mReadSegmentTail = GetUpdatedBufPtr(mReadSegmentHead, kSegmentHeaderSize + (header & kSegmentHeaderLengthMask), - mReadDirection); + mReadDirection); // Update the current read pointer to skip the segment header. mReadPointer = GetUpdatedBufPtr(mReadSegmentHead, kSegmentHeaderSize, mReadDirection); @@ -609,7 +610,7 @@ exit: // ThreadError_NotFound if there is no message or if the message has no content. otError NcpFrameBuffer::OutFramePrepareMessage(void) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; uint16_t header; // Read the segment header @@ -619,9 +620,8 @@ otError NcpFrameBuffer::OutFramePrepareMessage(void) VerifyOrExit((header & kSegmentHeaderMessageIndicatorFlag) != 0, error = OT_ERROR_NOT_FOUND); // Update the current message from the queue. - mReadMessage = (mReadMessage == NULL) ? - otMessageQueueGetHead(&mMessageQueue[mReadDirection]) : - otMessageQueueGetNext(&mMessageQueue[mReadDirection], mReadMessage); + mReadMessage = (mReadMessage == NULL) ? otMessageQueueGetHead(&mMessageQueue[mReadDirection]) + : otMessageQueueGetNext(&mMessageQueue[mReadDirection], mReadMessage); VerifyOrExit(mReadMessage != NULL, error = OT_ERROR_NOT_FOUND); @@ -643,7 +643,7 @@ exit: otError NcpFrameBuffer::OutFrameFillMessageBuffer(void) { otError error = OT_ERROR_NONE; - int readLength; + int readLength; VerifyOrExit(mReadMessage != NULL, error = OT_ERROR_NOT_FOUND); @@ -711,7 +711,7 @@ uint8_t NcpFrameBuffer::OutFrameReadByte(void) case kReadStateInSegment: // Read a byte from current read pointer and move the read pointer by 1 byte in the read direction. - retval = *mReadPointer; + retval = *mReadPointer; mReadPointer = GetUpdatedBufPtr(mReadPointer, 1, mReadDirection); // Check if at end of current segment. @@ -768,12 +768,12 @@ uint16_t NcpFrameBuffer::OutFrameRead(uint16_t aReadLength, uint8_t *aDataBuffer otError NcpFrameBuffer::OutFrameRemove(void) { - otError error = OT_ERROR_NONE; - uint8_t *bufPtr; + otError error = OT_ERROR_NONE; + uint8_t * bufPtr; otMessage *message; - uint16_t header; - uint8_t numSegments; - FrameTag tag; + uint16_t header; + uint8_t numSegments; + FrameTag tag; VerifyOrExit(!IsEmpty(), error = OT_ERROR_NOT_FOUND); @@ -784,7 +784,7 @@ otError NcpFrameBuffer::OutFrameRemove(void) // Begin at the start of current frame and move through all segments. - bufPtr = mReadFrameStart[mReadDirection]; + bufPtr = mReadFrameStart[mReadDirection]; numSegments = 0; while (bufPtr != mWriteFrameStart[mReadDirection]) @@ -826,7 +826,7 @@ otError NcpFrameBuffer::OutFrameRemove(void) UpdateReadWriteStartPointers(); - mReadState = kReadStateNotActive; + mReadState = kReadStateNotActive; mReadFrameLength = kUnknownFrameLength; if (mFrameRemovedCallback != NULL) @@ -845,7 +845,7 @@ void NcpFrameBuffer::UpdateReadWriteStartPointers(void) { // Move the high priority pointers to be right behind the low priority start. mWriteFrameStart[kPriorityHigh] = GetUpdatedBufPtr(mReadFrameStart[kPriorityLow], 1, kBackward); - mReadFrameStart[kPriorityHigh] = mWriteFrameStart[kPriorityHigh]; + mReadFrameStart[kPriorityHigh] = mWriteFrameStart[kPriorityHigh]; ExitNow(); } @@ -854,7 +854,7 @@ void NcpFrameBuffer::UpdateReadWriteStartPointers(void) { // Move the low priority pointers to be 1 byte after the high priority start. mWriteFrameStart[kPriorityLow] = GetUpdatedBufPtr(mReadFrameStart[kPriorityHigh], 1, kForward); - mReadFrameStart[kPriorityLow] = mWriteFrameStart[kPriorityLow]; + mReadFrameStart[kPriorityLow] = mWriteFrameStart[kPriorityLow]; } exit: @@ -863,10 +863,10 @@ exit: uint16_t NcpFrameBuffer::OutFrameGetLength(void) { - uint16_t frameLength = 0; - uint16_t header; - uint8_t *bufPtr; - uint8_t numSegments; + uint16_t frameLength = 0; + uint16_t header; + uint8_t * bufPtr; + uint8_t numSegments; otMessage *message = NULL; // If the frame length was calculated before, return the previously calculated length. @@ -878,7 +878,7 @@ uint16_t NcpFrameBuffer::OutFrameGetLength(void) // Calculate frame length by adding length of all segments and messages within the current frame. - bufPtr = mReadFrameStart[mReadDirection]; + bufPtr = mReadFrameStart[mReadDirection]; numSegments = 0; while (bufPtr != mWriteFrameStart[mReadDirection]) @@ -899,9 +899,8 @@ uint16_t NcpFrameBuffer::OutFrameGetLength(void) // If current segment has an associated message, add its length to frame length. if (header & kSegmentHeaderMessageIndicatorFlag) { - message = (message == NULL) ? - otMessageQueueGetHead(&mMessageQueue[mReadDirection]) : - otMessageQueueGetNext(&mMessageQueue[mReadDirection], message); + message = (message == NULL) ? otMessageQueueGetHead(&mMessageQueue[mReadDirection]) + : otMessageQueueGetNext(&mMessageQueue[mReadDirection], message); if (message != NULL) { @@ -942,5 +941,5 @@ NcpFrameBuffer::FrameTag NcpFrameBuffer::OutFrameGetTag(void) return IsEmpty() ? kInvalidTag : mReadFrameStart[mReadDirection]; } -} // namespace Ncp -} // namespace ot +} // namespace Ncp +} // namespace ot diff --git a/src/ncp/ncp_buffer.hpp b/src/ncp/ncp_buffer.hpp index f199bb058..6dc9a3ead 100644 --- a/src/ncp/ncp_buffer.hpp +++ b/src/ncp/ncp_buffer.hpp @@ -53,8 +53,8 @@ namespace Ncp { class NcpFrameBuffer { friend class SpinelEncoder; -public: +public: /** * Defines the priority of a frame. High priority frames are read before low priority frames. Within same priority * level FIFO order is preserved. @@ -62,8 +62,8 @@ public: */ enum Priority { - kPriorityLow = 0, //< Indicates low/normal priority for a frame. - kPriorityHigh = 1, //< Indicates high priority for a frame. + kPriorityLow = 0, //< Indicates low/normal priority for a frame. + kPriorityHigh = 1, //< Indicates high priority for a frame. }; /** @@ -92,11 +92,15 @@ public: * The constructor for a `WritePosition` object. * */ - WritePosition(void): mPosition(0), mSegmentHead(0) { } + WritePosition(void) + : mPosition(0) + , mSegmentHead(0) + { + } private: - uint8_t *mPosition; //< Pointer into buffer corresponding to saved write position. - uint8_t *mSegmentHead; //< Pointer to segment head. + uint8_t *mPosition; //< Pointer into buffer corresponding to saved write position. + uint8_t *mSegmentHead; //< Pointer to segment head. friend class NcpFrameBuffer; }; @@ -442,7 +446,6 @@ public: FrameTag OutFrameGetTag(void); private: - /* * `NcpFrameBuffer` Implementation * ------------------------------- @@ -566,91 +569,91 @@ private: enum { - kReadByteAfterFrameHasEnded = 0, // Value returned by ReadByte() when frame has ended. - kMessageReadBufferSize = 16, // Size of message buffer array `mMessageBuffer`. - kUnknownFrameLength = 0xffff, // Value used when frame length is unknown. - kSegmentHeaderSize = 2, // Length of the segment header. - kSegmentHeaderLengthMask = 0x3fff, // Bit mask to get the length from the segment header - kMaxSegments = 10, // Max number of segments allowed in a frame + kReadByteAfterFrameHasEnded = 0, // Value returned by ReadByte() when frame has ended. + kMessageReadBufferSize = 16, // Size of message buffer array `mMessageBuffer`. + kUnknownFrameLength = 0xffff, // Value used when frame length is unknown. + kSegmentHeaderSize = 2, // Length of the segment header. + kSegmentHeaderLengthMask = 0x3fff, // Bit mask to get the length from the segment header + kMaxSegments = 10, // Max number of segments allowed in a frame - kSegmentHeaderNoFlag = 0, // No flags are set. - kSegmentHeaderNewFrameFlag = (1 << 15), // Indicates that this segment starts a new frame. - kSegmentHeaderMessageIndicatorFlag = (1 << 14), // Indicates this segment ends with a Message. + kSegmentHeaderNoFlag = 0, // No flags are set. + kSegmentHeaderNewFrameFlag = (1 << 15), // Indicates that this segment starts a new frame. + kSegmentHeaderMessageIndicatorFlag = (1 << 14), // Indicates this segment ends with a Message. - kNumPrios = (kPriorityHigh + 1), // Number of priorities. + kNumPrios = (kPriorityHigh + 1), // Number of priorities. }; enum ReadState { - kReadStateNotActive, // No current prepared output frame. - kReadStateInSegment, // In middle of a data segment while reading current frame. - kReadStateInMessage, // In middle of a message while reading current frame. - kReadStateDone, // Current output frame is read fully. + kReadStateNotActive, // No current prepared output frame. + kReadStateInSegment, // In middle of a data segment while reading current frame. + kReadStateInMessage, // In middle of a message while reading current frame. + kReadStateDone, // Current output frame is read fully. }; enum Direction { - kForward = kPriorityLow, - kBackward = kPriorityHigh, + kForward = kPriorityLow, + kBackward = kPriorityHigh, kUnknown, }; - uint8_t * GetUpdatedBufPtr(uint8_t *aBufPtr, uint16_t aOffset, Direction aDirection) const; - uint16_t GetDistance(uint8_t *aStartPtr, uint8_t *aEndPtr, Direction aDirection) const; + uint8_t *GetUpdatedBufPtr(uint8_t *aBufPtr, uint16_t aOffset, Direction aDirection) const; + uint16_t GetDistance(uint8_t *aStartPtr, uint8_t *aEndPtr, Direction aDirection) const; - uint16_t ReadUint16At(uint8_t *aBufPtr, Direction aDirection); - void WriteUint16At(uint8_t *aBufPtr, uint16_t aValue, Direction aDirection); + uint16_t ReadUint16At(uint8_t *aBufPtr, Direction aDirection); + void WriteUint16At(uint8_t *aBufPtr, uint16_t aValue, Direction aDirection); - bool HasFrame(Priority aPriority) const; - void UpdateReadWriteStartPointers(void); + bool HasFrame(Priority aPriority) const; + void UpdateReadWriteStartPointers(void); - otError InFrameAppend(uint8_t aByte); - otError InFrameBeginSegment(void); - void InFrameEndSegment(uint16_t aSegmentHeaderFlags); - void InFrameDiscard(void); - bool InFrameIsWriting(Priority aPriority) const; + otError InFrameAppend(uint8_t aByte); + otError InFrameBeginSegment(void); + void InFrameEndSegment(uint16_t aSegmentHeaderFlags); + void InFrameDiscard(void); + bool InFrameIsWriting(Priority aPriority) const; - void OutFrameSelectReadDirection(void); - otError OutFramePrepareSegment(void); - void OutFrameMoveToNextSegment(void); - otError OutFramePrepareMessage(void); - otError OutFrameFillMessageBuffer(void); + void OutFrameSelectReadDirection(void); + otError OutFramePrepareSegment(void); + void OutFrameMoveToNextSegment(void); + otError OutFramePrepareMessage(void); + otError OutFrameFillMessageBuffer(void); - uint8_t * const mBuffer; // Pointer to the buffer used to store the data. - uint8_t * const mBufferEnd; // Points to after the end of buffer. - const uint16_t mBufferLength; // Length of the the buffer. + uint8_t *const mBuffer; // Pointer to the buffer used to store the data. + uint8_t *const mBufferEnd; // Points to after the end of buffer. + const uint16_t mBufferLength; // Length of the the buffer. - BufferCallback mFrameAddedCallback; // Callback to signal when a new frame is added - void * mFrameAddedContext; // Context passed to `mFrameAddedCallback`. - BufferCallback mFrameRemovedCallback; // Callback to signal when a frame is removed. - void * mFrameRemovedContext; // Context passed to `mFrameRemovedCallback`. + BufferCallback mFrameAddedCallback; // Callback to signal when a new frame is added + void * mFrameAddedContext; // Context passed to `mFrameAddedCallback`. + BufferCallback mFrameRemovedCallback; // Callback to signal when a frame is removed. + void * mFrameRemovedContext; // Context passed to `mFrameRemovedCallback`. - otMessageQueue mMessageQueue[kNumPrios]; // Main message queues. + otMessageQueue mMessageQueue[kNumPrios]; // Main message queues. - Direction mWriteDirection; // Direction (priority) for current frame being read. - otMessageQueue mWriteFrameMessageQueue; // Message queue for the current frame being written. - uint8_t * mWriteFrameStart[kNumPrios]; // Pointer to start of current frame being written. - uint8_t * mWriteSegmentHead; // Pointer to start of current segment in the frame being written. - uint8_t * mWriteSegmentTail; // Pointer to end of current segment in the frame being written. - FrameTag mWriteFrameTag; // Tag associated with last successfully written frame. + Direction mWriteDirection; // Direction (priority) for current frame being read. + otMessageQueue mWriteFrameMessageQueue; // Message queue for the current frame being written. + uint8_t * mWriteFrameStart[kNumPrios]; // Pointer to start of current frame being written. + uint8_t * mWriteSegmentHead; // Pointer to start of current segment in the frame being written. + uint8_t * mWriteSegmentTail; // Pointer to end of current segment in the frame being written. + FrameTag mWriteFrameTag; // Tag associated with last successfully written frame. - Direction mReadDirection; // Direction (priority) for current frame being read. - ReadState mReadState; // Read state. - uint16_t mReadFrameLength; // Length of current frame being read. + Direction mReadDirection; // Direction (priority) for current frame being read. + ReadState mReadState; // Read state. + uint16_t mReadFrameLength; // Length of current frame being read. - uint8_t * mReadFrameStart[kNumPrios]; // Pointer to start of current frame being read. - uint8_t * mReadSegmentHead; // Pointer to start of current segment in the frame being read. - 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). + uint8_t *mReadFrameStart[kNumPrios]; // Pointer to start of current frame being read. + uint8_t *mReadSegmentHead; // Pointer to start of current segment in the frame being read. + 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). - otMessage * mReadMessage; // Current Message in the frame being read. - uint16_t mReadMessageOffset; // Offset within current message being read. + otMessage *mReadMessage; // Current Message in the frame being read. + uint16_t mReadMessageOffset; // Offset within current message being read. - uint8_t mMessageBuffer[kMessageReadBufferSize]; // Buffer to hold part of current message being read. - uint8_t * mReadMessageTail; // Pointer to end of current part in mMessageBuffer. + uint8_t mMessageBuffer[kMessageReadBufferSize]; // Buffer to hold part of current message being read. + uint8_t *mReadMessageTail; // Pointer to end of current part in mMessageBuffer. }; -} // namespace Ncp -} // namespace ot +} // namespace Ncp +} // namespace ot -#endif // NCP_FRAME_BUFFER_HPP_ +#endif // NCP_FRAME_BUFFER_HPP_ diff --git a/src/ncp/ncp_spi.hpp b/src/ncp/ncp_spi.hpp index 486544609..1fe6ae0bc 100644 --- a/src/ncp/ncp_spi.hpp +++ b/src/ncp/ncp_spi.hpp @@ -49,7 +49,7 @@ class SpiFrame public: enum { - kHeaderSize = 5, ///< SPI header size (in bytes). + kHeaderSize = 5, ///< SPI header size (in bytes). }; /** @@ -58,7 +58,10 @@ public: * @param[in] aBuffer Pointer to buffer containing the frame. * */ - SpiFrame(uint8_t *aBuffer) : mBuffer(aBuffer) { } + SpiFrame(uint8_t *aBuffer) + : mBuffer(aBuffer) + { + } /** * This method gets a pointer to data portion in the SPI frame skipping the header. @@ -76,10 +79,7 @@ public: * @returns TRUE if the frame is valid, FALSE otherwise. * */ - bool IsValid(void) const - { - return ((mBuffer[kIndexFlagByte] & kFlagPatternMask) == kFlagPattern); - } + bool IsValid(void) const { return ((mBuffer[kIndexFlagByte] & kFlagPatternMask) == kFlagPattern); } /** * This method sets the "flag byte" field in the SPI frame header. @@ -87,10 +87,7 @@ public: * @param[in] aResetFalg The status of reset flag (TRUE to set the flag, FALSE to clear flag). * */ - void SetHeaderFlagByte(bool aResetFlag) - { - mBuffer[kIndexFlagByte] = kFlagPattern | (aResetFlag ? kFlagReset : 0); - } + void SetHeaderFlagByte(bool aResetFlag) { mBuffer[kIndexFlagByte] = kFlagPattern | (aResetFlag ? kFlagReset : 0); } /** * This method sets the "accept len" field in the SPI frame header. @@ -111,10 +108,7 @@ public: * @returns The accept length in bytes. * */ - uint16_t GetHeaderAcceptLen(void) const - { - return Encoding::LittleEndian::ReadUint16(mBuffer + kIndexAcceptLen); - } + uint16_t GetHeaderAcceptLen(void) const { return Encoding::LittleEndian::ReadUint16(mBuffer + kIndexAcceptLen); } /** * This method sets the "data len" field in the SPI frame header. @@ -124,10 +118,7 @@ public: * @param[in] aDataLen The data length in bytes. * */ - void SetHeaderDataLen(uint16_t aDataLen) - { - Encoding::LittleEndian::WriteUint16(aDataLen, mBuffer + kIndexDataLen); - } + void SetHeaderDataLen(uint16_t aDataLen) { Encoding::LittleEndian::WriteUint16(aDataLen, mBuffer + kIndexDataLen); } /** * This method gets the "data len" field in the SPI frame header. @@ -135,10 +126,7 @@ public: * @returns The data length in bytes. * */ - uint16_t GetHeaderDataLen(void) const - { - return Encoding::LittleEndian::ReadUint16(mBuffer + kIndexDataLen); - } + uint16_t GetHeaderDataLen(void) const { return Encoding::LittleEndian::ReadUint16(mBuffer + kIndexDataLen); } private: enum @@ -147,9 +135,9 @@ private: kIndexAcceptLen = 1, // accept len (uint16_t little-endian encoding). kIndexDataLen = 3, // data len (uint16_t little-endian encoding). - kFlagReset = (1 << 7), // Flag byte RESET bit. - kFlagPattern = 0x02, // Flag byte PATTERN bits. - kFlagPatternMask = 0x03, // Flag byte PATTERN mask. + kFlagReset = (1 << 7), // Flag byte RESET bit. + kFlagPattern = 0x02, // Flag byte PATTERN bits. + kFlagPatternMask = 0x03, // Flag byte PATTERN mask. }; uint8_t *mBuffer; diff --git a/src/ncp/ncp_uart.cpp b/src/ncp/ncp_uart.cpp index 52427288d..3d3c97063 100644 --- a/src/ncp/ncp_uart.cpp +++ b/src/ncp/ncp_uart.cpp @@ -36,14 +36,14 @@ #include #include -#include #include +#include #include "openthread-core-config.h" #include "common/code_utils.hpp" -#include "common/new.hpp" #include "common/debug.hpp" #include "common/instance.hpp" +#include "common/new.hpp" #include "net/ip6.hpp" #if OPENTHREAD_ENABLE_NCP_UART @@ -57,10 +57,10 @@ static otDEFINE_ALIGNED_VAR(sNcpRaw, sizeof(NcpUart), uint64_t); extern "C" void otNcpInit(otInstance *aInstance) { - NcpUart *ncpUart = NULL; + NcpUart * ncpUart = NULL; Instance *instance = static_cast(aInstance); - ncpUart = new(&sNcpRaw) NcpUart(instance); + ncpUart = new (&sNcpRaw) NcpUart(instance); if (ncpUart == NULL || ncpUart != NcpBase::GetNcpInstance()) { @@ -78,7 +78,7 @@ NcpUart::UartTxBuffer::UartTxBuffer(void) void NcpUart::UartTxBuffer::Clear(void) { - mWritePointer = mBuffer; + mWritePointer = mBuffer; mRemainingLength = sizeof(mBuffer); } @@ -97,14 +97,14 @@ const uint8_t *NcpUart::UartTxBuffer::GetBuffer(void) const return mBuffer; } -NcpUart::NcpUart(Instance *aInstance): - NcpBase(aInstance), - mFrameDecoder(mRxBuffer, sizeof(mRxBuffer), &NcpUart::HandleFrame, &NcpUart::HandleError, this), - mUartBuffer(), - mState(kStartingFrame), - mByte(0), - mUartSendImmediate(false), - mUartSendTask(*aInstance, EncodeAndSendToUart, this) +NcpUart::NcpUart(Instance *aInstance) + : NcpBase(aInstance) + , mFrameDecoder(mRxBuffer, sizeof(mRxBuffer), &NcpUart::HandleFrame, &NcpUart::HandleError, this) + , mUartBuffer() + , mState(kStartingFrame) + , mByte(0) + , mUartSendImmediate(false) + , mUartSendTask(*aInstance, EncodeAndSendToUart, this) #if OPENTHREAD_ENABLE_NCP_SPINEL_ENCRYPTER , mTxFrameBufferEncrypterReader(mTxFrameBuffer) #endif // OPENTHREAD_ENABLE_NCP_SPINEL_ENCRYPTER @@ -114,8 +114,10 @@ NcpUart::NcpUart(Instance *aInstance): otPlatUartEnable(); } -void NcpUart::HandleFrameAddedToNcpBuffer(void *aContext, NcpFrameBuffer::FrameTag aTag, - NcpFrameBuffer::Priority aPriority, NcpFrameBuffer *aNcpFrameBuffer) +void NcpUart::HandleFrameAddedToNcpBuffer(void * aContext, + NcpFrameBuffer::FrameTag aTag, + NcpFrameBuffer::Priority aPriority, + NcpFrameBuffer * aNcpFrameBuffer) { OT_UNUSED_VARIABLE(aNcpFrameBuffer); OT_UNUSED_VARIABLE(aTag); @@ -144,7 +146,7 @@ void NcpUart::EncodeAndSendToUart(Tasklet &aTasklet) void NcpUart::EncodeAndSendToUart(void) { uint16_t len; - bool prevHostPowerState; + bool prevHostPowerState; #if OPENTHREAD_ENABLE_NCP_SPINEL_ENCRYPTER NcpFrameBufferEncrypterReader &txFrameBuffer = mTxFrameBufferEncrypterReader; #else @@ -173,7 +175,7 @@ void NcpUart::EncodeAndSendToUart(void) { mByte = txFrameBuffer.OutFrameReadByte(); - case kEncodingFrame: + case kEncodingFrame: SuccessOrExit(mFrameEncoder.Encode(mByte, mUartBuffer)); } @@ -282,7 +284,7 @@ void NcpUart::HandleError(void *aContext, otError aError, uint8_t *aBuf, uint16_ void NcpUart::HandleError(otError aError, uint8_t *aBuf, uint16_t aBufLength) { - char hexbuf[128]; + char hexbuf[128]; uint16_t i = 0; super_t::IncrementFrameErrorCounter(); @@ -315,10 +317,12 @@ void NcpUart::HandleError(otError aError, uint8_t *aBuf, uint16_t aBufLength) #if OPENTHREAD_ENABLE_NCP_SPINEL_ENCRYPTER -NcpUart::NcpFrameBufferEncrypterReader::NcpFrameBufferEncrypterReader(NcpFrameBuffer &aTxFrameBuffer) : - mTxFrameBuffer(aTxFrameBuffer), - mDataBufferReadIndex(0), - mOutputDataLength(0) {} +NcpUart::NcpFrameBufferEncrypterReader::NcpFrameBufferEncrypterReader(NcpFrameBuffer &aTxFrameBuffer) + : mTxFrameBuffer(aTxFrameBuffer) + , mDataBufferReadIndex(0) + , mOutputDataLength(0) +{ +} bool NcpUart::NcpFrameBufferEncrypterReader::IsEmpty(void) const { @@ -343,7 +347,7 @@ otError NcpUart::NcpFrameBufferEncrypterReader::OutFrameBegin(void) if (!SpinelEncrypter::EncryptOutbound(mDataBuffer, sizeof(mDataBuffer), &mOutputDataLength)) { mOutputDataLength = 0; - status = OT_ERROR_FAILED; + status = OT_ERROR_FAILED; } } else @@ -372,13 +376,13 @@ otError NcpUart::NcpFrameBufferEncrypterReader::OutFrameRemove(void) void NcpUart::NcpFrameBufferEncrypterReader::Reset(void) { - mOutputDataLength = 0; + mOutputDataLength = 0; mDataBufferReadIndex = 0; } #endif // OPENTHREAD_ENABLE_NCP_SPINEL_ENCRYPTER -} // namespace Ncp -} // namespace ot +} // namespace Ncp +} // namespace ot #endif // OPENTHREAD_ENABLE_NCP_UART diff --git a/src/ncp/ncp_uart.hpp b/src/ncp/ncp_uart.hpp index 5c653e587..87895659e 100644 --- a/src/ncp/ncp_uart.hpp +++ b/src/ncp/ncp_uart.hpp @@ -71,19 +71,18 @@ public: void HandleUartReceiveDone(const uint8_t *aBuf, uint16_t aBufLength); private: - enum { - kUartTxBufferSize = OPENTHREAD_CONFIG_NCP_UART_TX_CHUNK_SIZE, // Uart tx buffer size. - kRxBufferSize = OPENTHREAD_CONFIG_NCP_UART_RX_BUFFER_SIZE + // Rx buffer size (should be large enough to fit + kUartTxBufferSize = OPENTHREAD_CONFIG_NCP_UART_TX_CHUNK_SIZE, // Uart tx buffer size. + kRxBufferSize = OPENTHREAD_CONFIG_NCP_UART_RX_BUFFER_SIZE + // Rx buffer size (should be large enough to fit OPENTHREAD_CONFIG_NCP_SPINEL_ENCRYPTER_EXTRA_DATA_SIZE, // one whole (decoded) received frame). }; enum UartTxState { - kStartingFrame, // Starting a new frame. - kEncodingFrame, // In middle of encoding a frame. - kFinalizingFrame, // Finalizing a frame. + kStartingFrame, // Starting a new frame. + kEncodingFrame, // In middle of encoding a frame. + kFinalizingFrame, // Finalizing a frame. }; class UartTxBuffer : public Hdlc::Encoder::BufferWriteIterator @@ -97,7 +96,7 @@ private: const uint8_t *GetBuffer(void) const; private: - uint8_t mBuffer[kUartTxBufferSize]; + uint8_t mBuffer[kUartTxBufferSize]; }; #if OPENTHREAD_ENABLE_NCP_SPINEL_ENCRYPTER @@ -113,9 +112,9 @@ private: * Takes a reference to NcpFrameBuffer in order to read spinel frames. */ explicit NcpFrameBufferEncrypterReader(NcpFrameBuffer &aTxFrameBuffer); - bool IsEmpty(void) const; + bool IsEmpty(void) const; otError OutFrameBegin(void); - bool OutFrameHasEnded(void); + bool OutFrameHasEnded(void); uint8_t OutFrameReadByte(void); otError OutFrameRemove(void); @@ -123,39 +122,41 @@ private: void Reset(void); NcpFrameBuffer &mTxFrameBuffer; - uint8_t mDataBuffer[kRxBufferSize]; - size_t mDataBufferReadIndex; - size_t mOutputDataLength; + uint8_t mDataBuffer[kRxBufferSize]; + size_t mDataBufferReadIndex; + size_t mOutputDataLength; }; #endif // OPENTHREAD_ENABLE_NCP_SPINEL_ENCRYPTER - void EncodeAndSendToUart(void); - void HandleFrame(uint8_t *aBuf, uint16_t aBufLength); - void HandleError(otError aError, uint8_t *aBuf, uint16_t aBufLength); - void TxFrameBufferHasData(void); - void HandleFrameAddedToNcpBuffer(void); + void EncodeAndSendToUart(void); + void HandleFrame(uint8_t *aBuf, uint16_t aBufLength); + void HandleError(otError aError, uint8_t *aBuf, uint16_t aBufLength); + void TxFrameBufferHasData(void); + void HandleFrameAddedToNcpBuffer(void); - static void EncodeAndSendToUart(Tasklet &aTasklet); - static void HandleFrame(void *context, uint8_t *aBuf, uint16_t aBufLength); - static void HandleError(void *context, otError aError, uint8_t *aBuf, uint16_t aBufLength); - static void HandleFrameAddedToNcpBuffer(void *aContext, NcpFrameBuffer::FrameTag aTag, - NcpFrameBuffer::Priority aPriority, NcpFrameBuffer *aNcpFrameBuffer); + static void EncodeAndSendToUart(Tasklet &aTasklet); + static void HandleFrame(void *context, uint8_t *aBuf, uint16_t aBufLength); + static void HandleError(void *context, otError aError, uint8_t *aBuf, uint16_t aBufLength); + static void HandleFrameAddedToNcpBuffer(void * aContext, + NcpFrameBuffer::FrameTag aTag, + NcpFrameBuffer::Priority aPriority, + NcpFrameBuffer * aNcpFrameBuffer); - Hdlc::Encoder mFrameEncoder; - Hdlc::Decoder mFrameDecoder; - UartTxBuffer mUartBuffer; - UartTxState mState; - uint8_t mByte; - uint8_t mRxBuffer[kRxBufferSize]; - bool mUartSendImmediate; - Tasklet mUartSendTask; + Hdlc::Encoder mFrameEncoder; + Hdlc::Decoder mFrameDecoder; + UartTxBuffer mUartBuffer; + UartTxState mState; + uint8_t mByte; + uint8_t mRxBuffer[kRxBufferSize]; + bool mUartSendImmediate; + Tasklet mUartSendTask; #if OPENTHREAD_ENABLE_NCP_SPINEL_ENCRYPTER - NcpFrameBufferEncrypterReader mTxFrameBufferEncrypterReader; + NcpFrameBufferEncrypterReader mTxFrameBufferEncrypterReader; #endif // OPENTHREAD_ENABLE_NCP_SPINEL_ENCRYPTER }; -} // namespace Ncp -} // namespace ot +} // namespace Ncp +} // namespace ot -#endif // NCP_UART_HPP_ +#endif // NCP_UART_HPP_ diff --git a/src/ncp/spinel.c b/src/ncp/spinel.c index 43ba7186a..d81454622 100644 --- a/src/ncp/spinel.c +++ b/src/ncp/spinel.c @@ -101,51 +101,55 @@ static int spinel_errno_workaround_; #ifndef assert_printf #if SPINEL_PLATFORM_DOESNT_IMPLEMENT_FPRINTF -#define assert_printf(fmt, ...) \ - printf(__FILE__ ":%d: " fmt "\n", __LINE__, __VA_ARGS__) +#define assert_printf(fmt, ...) printf(__FILE__ ":%d: " fmt "\n", __LINE__, __VA_ARGS__) #else // if SPINEL_PLATFORM_DOESNT_IMPLEMENT_FPRINTF -#define assert_printf(fmt, ...) \ - fprintf(stderr, __FILE__ ":%d: " fmt "\n", __LINE__, __VA_ARGS__) +#define assert_printf(fmt, ...) fprintf(stderr, __FILE__ ":%d: " fmt "\n", __LINE__, __VA_ARGS__) #endif // else SPINEL_PLATFORM_DOESNT_IMPLEMENT_FPRINTF #endif - #ifndef require_action #if SPINEL_PLATFORM_SHOULD_LOG_ASSERTS -#define require_action(c, l, a) \ - do { if (!(c)) { \ - assert_printf("Requirement Failed (%s)", # c); \ - a; \ - goto l; \ - } } while (0) +#define require_action(c, l, a) \ + do \ + { \ + if (!(c)) \ + { \ + assert_printf("Requirement Failed (%s)", #c); \ + a; \ + goto l; \ + } \ + } while (0) #else // if DEBUG #define require_action(c, l, a) \ - do { if (!(c)) { \ - a; \ - goto l; \ - } } while (0) + do \ + { \ + if (!(c)) \ + { \ + a; \ + goto l; \ + } \ + } while (0) #endif // else DEBUG #endif // ifndef require_action #ifndef require -#define require(c, l) require_action(c, l, {}) +#define require(c, l) require_action(c, l, {}) #endif - -typedef struct { +typedef struct +{ va_list obj; } va_list_obj; -#define SPINEL_MAX_PACK_LENGTH 32767 +#define SPINEL_MAX_PACK_LENGTH 32767 // ---------------------------------------------------------------------------- // MARK: - -spinel_ssize_t -spinel_packed_uint_decode(const uint8_t *bytes, spinel_size_t len, unsigned int *value_ptr) +spinel_ssize_t spinel_packed_uint_decode(const uint8_t *bytes, spinel_size_t len, unsigned int *value_ptr) { - spinel_ssize_t ret = 0; - unsigned int value = 0; + spinel_ssize_t ret = 0; + unsigned int value = 0; int i = 0; @@ -162,8 +166,7 @@ spinel_packed_uint_decode(const uint8_t *bytes, spinel_size_t len, unsigned int ret += sizeof(uint8_t); bytes += sizeof(uint8_t); len -= sizeof(uint8_t); - } - while ((bytes[-1] & 0x80) == 0x80); + } while ((bytes[-1] & 0x80) == 0x80); if ((ret > 0) && (value_ptr != NULL)) { @@ -173,8 +176,7 @@ spinel_packed_uint_decode(const uint8_t *bytes, spinel_size_t len, unsigned int return ret; } -spinel_ssize_t -spinel_packed_uint_size(unsigned int value) +spinel_ssize_t spinel_packed_uint_size(unsigned int value) { spinel_ssize_t ret; @@ -202,8 +204,7 @@ spinel_packed_uint_size(unsigned int value) return ret; } -spinel_ssize_t -spinel_packed_uint_encode(uint8_t *bytes, spinel_size_t len, unsigned int value) +spinel_ssize_t spinel_packed_uint_encode(uint8_t *bytes, spinel_size_t len, unsigned int value) { const spinel_ssize_t encoded_size = spinel_packed_uint_size(value); @@ -214,7 +215,7 @@ spinel_packed_uint_encode(uint8_t *bytes, spinel_size_t len, unsigned int value) for (i = 0; i != encoded_size - 1; ++i) { *bytes++ = (value & 0x7F) | 0x80; - value = (value >> 7); + value = (value >> 7); } *bytes++ = (value & 0x7F); @@ -223,8 +224,7 @@ spinel_packed_uint_encode(uint8_t *bytes, spinel_size_t len, unsigned int value) return encoded_size; } -const char * -spinel_next_packed_datatype(const char *pack_format) +const char *spinel_next_packed_datatype(const char *pack_format) { int depth = 0; @@ -246,14 +246,16 @@ spinel_next_packed_datatype(const char *pack_format) break; } - } - while ((depth > 0) && *pack_format != 0); + } while ((depth > 0) && *pack_format != 0); return pack_format; } -static spinel_ssize_t -spinel_datatype_vunpack_(bool in_place, const uint8_t *data_ptr, spinel_size_t data_len, const char *pack_format, va_list_obj *args) +static spinel_ssize_t spinel_datatype_vunpack_(bool in_place, + const uint8_t *data_ptr, + spinel_size_t data_len, + const char * pack_format, + va_list_obj * args) { spinel_ssize_t ret = 0; @@ -440,7 +442,7 @@ spinel_datatype_vunpack_(bool in_place, const uint8_t *data_ptr, spinel_size_t d case SPINEL_DATATYPE_UINT_PACKED_C: { - unsigned int *arg_ptr = va_arg(args->obj, unsigned int *); + unsigned int * arg_ptr = va_arg(args->obj, unsigned int *); spinel_ssize_t pui_len = spinel_packed_uint_decode(data_ptr, data_len, arg_ptr); // Range check @@ -473,7 +475,7 @@ spinel_datatype_vunpack_(bool in_place, const uint8_t *data_ptr, spinel_size_t d if (in_place) { - char *arg = va_arg(args->obj, char *); + char * arg = va_arg(args->obj, char *); size_t len_arg = va_arg(args->obj, size_t); if (arg) { @@ -499,16 +501,15 @@ spinel_datatype_vunpack_(bool in_place, const uint8_t *data_ptr, spinel_size_t d case SPINEL_DATATYPE_DATA_C: case SPINEL_DATATYPE_DATA_WLEN_C: { - spinel_ssize_t pui_len = 0; - uint16_t block_len = 0; - const uint8_t *block_ptr = data_ptr; - void *arg_ptr = va_arg(args->obj, void *); - unsigned int *block_len_ptr = va_arg(args->obj, unsigned int *); - char nextformat = *spinel_next_packed_datatype(pack_format); + spinel_ssize_t pui_len = 0; + uint16_t block_len = 0; + const uint8_t *block_ptr = data_ptr; + void * arg_ptr = va_arg(args->obj, void *); + unsigned int * block_len_ptr = va_arg(args->obj, unsigned int *); + char nextformat = *spinel_next_packed_datatype(pack_format); - if ( (pack_format[0] == SPINEL_DATATYPE_DATA_WLEN_C) - || ( (nextformat != 0) && (nextformat != ')') ) - ) { + if ((pack_format[0] == SPINEL_DATATYPE_DATA_WLEN_C) || ((nextformat != 0) && (nextformat != ')'))) + { pui_len = spinel_datatype_unpack(data_ptr, data_len, SPINEL_DATATYPE_UINT16_S, &block_len); block_ptr += pui_len; @@ -518,20 +519,19 @@ spinel_datatype_vunpack_(bool in_place, const uint8_t *data_ptr, spinel_size_t d else { block_len = (uint16_t)data_len; - pui_len = 0; + pui_len = 0; } require_action((spinel_ssize_t)data_len >= (block_len + pui_len), bail, (ret = -1, errno = EOVERFLOW)); if (in_place) { - require_action(NULL != block_len_ptr && *block_len_ptr >= block_len, - bail, (ret = -1, errno = EINVAL)); + require_action(NULL != block_len_ptr && *block_len_ptr >= block_len, bail, (ret = -1, errno = EINVAL)); memcpy(arg_ptr, block_ptr, block_len); } else { - const uint8_t **block_ptr_ptr = (const uint8_t **)arg_ptr; + const uint8_t **block_ptr_ptr = (const uint8_t **)arg_ptr; if (NULL != block_ptr_ptr) { *block_ptr_ptr = block_ptr; @@ -550,19 +550,17 @@ spinel_datatype_vunpack_(bool in_place, const uint8_t *data_ptr, spinel_size_t d break; } - case 'T': case SPINEL_DATATYPE_STRUCT_C: { - spinel_ssize_t pui_len = 0; - uint16_t block_len = 0; + spinel_ssize_t pui_len = 0; + uint16_t block_len = 0; spinel_ssize_t actual_len = 0; - const uint8_t *block_ptr = data_ptr; - char nextformat = *spinel_next_packed_datatype(pack_format); + const uint8_t *block_ptr = data_ptr; + char nextformat = *spinel_next_packed_datatype(pack_format); - if ( (pack_format[0] == SPINEL_DATATYPE_STRUCT_C) - || ( (nextformat != 0) && (nextformat != ')') ) - ) { + if ((pack_format[0] == SPINEL_DATATYPE_STRUCT_C) || ((nextformat != 0) && (nextformat != ')'))) + { pui_len = spinel_datatype_unpack(data_ptr, data_len, SPINEL_DATATYPE_UINT16_S, &block_len); block_ptr += pui_len; @@ -572,7 +570,7 @@ spinel_datatype_vunpack_(bool in_place, const uint8_t *data_ptr, spinel_size_t d else { block_len = (uint16_t)data_len; - pui_len = 0; + pui_len = 0; } require_action((spinel_ssize_t)data_len >= (block_len + pui_len), bail, (ret = -1, errno = EOVERFLOW)); @@ -603,7 +601,7 @@ spinel_datatype_vunpack_(bool in_place, const uint8_t *data_ptr, spinel_size_t d case SPINEL_DATATYPE_ARRAY_C: default: // Unsupported Type! - ret = -1; + ret = -1; errno = EINVAL; goto bail; } @@ -615,11 +613,13 @@ bail: return ret; } -spinel_ssize_t -spinel_datatype_unpack_in_place(const uint8_t *data_ptr, spinel_size_t data_len, const char *pack_format, ...) +spinel_ssize_t spinel_datatype_unpack_in_place(const uint8_t *data_ptr, + spinel_size_t data_len, + const char * pack_format, + ...) { spinel_ssize_t ret; - va_list_obj args; + va_list_obj args; va_start(args.obj, pack_format); ret = spinel_datatype_vunpack_(true, data_ptr, data_len, pack_format, &args); @@ -628,11 +628,10 @@ spinel_datatype_unpack_in_place(const uint8_t *data_ptr, spinel_size_t data_len, return ret; } -spinel_ssize_t -spinel_datatype_unpack(const uint8_t *data_ptr, spinel_size_t data_len, const char *pack_format, ...) +spinel_ssize_t spinel_datatype_unpack(const uint8_t *data_ptr, spinel_size_t data_len, const char *pack_format, ...) { spinel_ssize_t ret; - va_list_obj args; + va_list_obj args; va_start(args.obj, pack_format); ret = spinel_datatype_vunpack_(false, data_ptr, data_len, pack_format, &args); @@ -641,11 +640,13 @@ spinel_datatype_unpack(const uint8_t *data_ptr, spinel_size_t data_len, const ch return ret; } -spinel_ssize_t -spinel_datatype_vunpack_in_place(const uint8_t *data_ptr, spinel_size_t data_len, const char *pack_format, va_list args) +spinel_ssize_t spinel_datatype_vunpack_in_place(const uint8_t *data_ptr, + spinel_size_t data_len, + const char * pack_format, + va_list args) { spinel_ssize_t ret; - va_list_obj args_obj; + va_list_obj args_obj; va_copy(args_obj.obj, args); ret = spinel_datatype_vunpack_(true, data_ptr, data_len, pack_format, &args_obj); @@ -654,11 +655,13 @@ spinel_datatype_vunpack_in_place(const uint8_t *data_ptr, spinel_size_t data_len return ret; } -spinel_ssize_t -spinel_datatype_vunpack(const uint8_t *data_ptr, spinel_size_t data_len, const char *pack_format, va_list args) +spinel_ssize_t spinel_datatype_vunpack(const uint8_t *data_ptr, + spinel_size_t data_len, + const char * pack_format, + va_list args) { spinel_ssize_t ret; - va_list_obj args_obj; + va_list_obj args_obj; va_copy(args_obj.obj, args); ret = spinel_datatype_vunpack_(false, data_ptr, data_len, pack_format, &args_obj); @@ -667,8 +670,10 @@ spinel_datatype_vunpack(const uint8_t *data_ptr, spinel_size_t data_len, const c return ret; } -static spinel_ssize_t -spinel_datatype_vpack_(uint8_t *data_ptr, spinel_size_t data_len_max, const char *pack_format, va_list_obj *args) +static spinel_ssize_t spinel_datatype_vpack_(uint8_t * data_ptr, + spinel_size_t data_len_max, + const char * pack_format, + va_list_obj * args) { spinel_ssize_t ret = 0; @@ -855,11 +860,14 @@ spinel_datatype_vpack_(uint8_t *data_ptr, spinel_size_t data_len_max, const char case SPINEL_DATATYPE_UINT_PACKED_C: { - uint32_t arg = va_arg(args->obj, uint32_t); + uint32_t arg = va_arg(args->obj, uint32_t); spinel_ssize_t encoded_size; // Range Check - require_action(arg < SPINEL_MAX_UINT_PACKED, bail, {ret = -1; errno = EINVAL;}); + require_action(arg < SPINEL_MAX_UINT_PACKED, bail, { + ret = -1; + errno = EINVAL; + }); encoded_size = spinel_packed_uint_encode(data_ptr, data_len_max, arg); ret += encoded_size; @@ -879,8 +887,8 @@ spinel_datatype_vpack_(uint8_t *data_ptr, spinel_size_t data_len_max, const char case SPINEL_DATATYPE_UTF8_C: { - const char *string_arg = va_arg(args->obj, const char *); - size_t string_arg_len = 0; + const char *string_arg = va_arg(args->obj, const char *); + size_t string_arg_len = 0; if (string_arg) { @@ -888,7 +896,7 @@ spinel_datatype_vpack_(uint8_t *data_ptr, spinel_size_t data_len_max, const char } else { - string_arg = ""; + string_arg = ""; string_arg_len = 1; } @@ -912,16 +920,18 @@ spinel_datatype_vpack_(uint8_t *data_ptr, spinel_size_t data_len_max, const char case SPINEL_DATATYPE_DATA_WLEN_C: case SPINEL_DATATYPE_DATA_C: { - const uint8_t *arg = va_arg(args->obj, const uint8_t *); - uint32_t data_size_arg = va_arg(args->obj, uint32_t); - spinel_ssize_t size_len = 0; - char nextformat = *spinel_next_packed_datatype(pack_format); + const uint8_t *arg = va_arg(args->obj, const uint8_t *); + uint32_t data_size_arg = va_arg(args->obj, uint32_t); + spinel_ssize_t size_len = 0; + char nextformat = *spinel_next_packed_datatype(pack_format); - if ( (pack_format[0] == SPINEL_DATATYPE_DATA_WLEN_C) - || ( (nextformat != 0) && (nextformat != ')') ) - ) { + if ((pack_format[0] == SPINEL_DATATYPE_DATA_WLEN_C) || ((nextformat != 0) && (nextformat != ')'))) + { size_len = spinel_datatype_pack(data_ptr, data_len_max, SPINEL_DATATYPE_UINT16_S, data_size_arg); - require_action(size_len > 0, bail, {ret = -1; errno = EINVAL;}); + require_action(size_len > 0, bail, { + ret = -1; + errno = EINVAL; + }); } ret += (spinel_size_t)size_len + data_size_arg; @@ -948,10 +958,13 @@ spinel_datatype_vpack_(uint8_t *data_ptr, spinel_size_t data_len_max, const char case SPINEL_DATATYPE_STRUCT_C: { spinel_ssize_t struct_len = 0; - spinel_ssize_t size_len = 0; - char nextformat = *spinel_next_packed_datatype(pack_format); + spinel_ssize_t size_len = 0; + char nextformat = *spinel_next_packed_datatype(pack_format); - require_action(pack_format[1] == '(', bail, {ret = -1; errno = EINVAL;}); + require_action(pack_format[1] == '(', bail, { + ret = -1; + errno = EINVAL; + }); // First we figure out the size of the struct { @@ -961,11 +974,13 @@ spinel_datatype_vpack_(uint8_t *data_ptr, spinel_size_t data_len_max, const char va_end(subargs.obj); } - if ( (pack_format[0] == SPINEL_DATATYPE_STRUCT_C) - || ( (nextformat != 0) && (nextformat != ')') ) - ) { + if ((pack_format[0] == SPINEL_DATATYPE_STRUCT_C) || ((nextformat != 0) && (nextformat != ')'))) + { size_len = spinel_datatype_pack(data_ptr, data_len_max, SPINEL_DATATYPE_UINT16_S, struct_len); - require_action(size_len > 0, bail, {ret = -1; errno = EINVAL;}); + require_action(size_len > 0, bail, { + ret = -1; + errno = EINVAL; + }); } ret += size_len + struct_len; @@ -994,10 +1009,9 @@ spinel_datatype_vpack_(uint8_t *data_ptr, spinel_size_t data_len_max, const char default: // Unsupported Type! - ret = -1; + ret = -1; errno = EINVAL; goto bail; - } } @@ -1005,10 +1019,9 @@ bail: return ret; } -spinel_ssize_t -spinel_datatype_pack(uint8_t *data_ptr, spinel_size_t data_len_max, const char *pack_format, ...) +spinel_ssize_t spinel_datatype_pack(uint8_t *data_ptr, spinel_size_t data_len_max, const char *pack_format, ...) { - int ret; + int ret; va_list_obj args; va_start(args.obj, pack_format); @@ -1018,11 +1031,12 @@ spinel_datatype_pack(uint8_t *data_ptr, spinel_size_t data_len_max, const char * return ret; } - -spinel_ssize_t -spinel_datatype_vpack(uint8_t *data_ptr, spinel_size_t data_len_max, const char *pack_format, va_list args) +spinel_ssize_t spinel_datatype_vpack(uint8_t * data_ptr, + spinel_size_t data_len_max, + const char * pack_format, + va_list args) { - int ret; + int ret; va_list_obj args_obj; va_copy(args_obj.obj, args); @@ -1032,14 +1046,12 @@ spinel_datatype_vpack(uint8_t *data_ptr, spinel_size_t data_len_max, const char return ret; } - // ---------------------------------------------------------------------------- // MARK: - // **** LCOV_EXCL_START **** -const char * -spinel_prop_key_to_cstr(spinel_prop_key_t prop_key) +const char *spinel_prop_key_to_cstr(spinel_prop_key_t prop_key) { const char *ret = "UNKNOWN"; @@ -2245,22 +2257,22 @@ const char *spinel_capability_to_cstr(unsigned int capability) return ret; } -// **** LCOV_EXCL_STOP **** + // **** LCOV_EXCL_STOP **** -/* -------------------------------------------------------------------------- */ + /* -------------------------------------------------------------------------- */ #if SPINEL_SELF_TEST -int -main(void) +int main(void) { - int ret = -1; - const spinel_eui64_t static_eui64 = { {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 } }; - const char static_string[] = "static_string"; - uint8_t buffer[1024]; - ssize_t len; + int ret = -1; + const spinel_eui64_t static_eui64 = {{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}}; + const char static_string[] = "static_string"; + uint8_t buffer[1024]; + ssize_t len; - len = spinel_datatype_pack(buffer, sizeof(buffer), "CiiLUE", 0x88, 9, 0xA3, 0xDEADBEEF, static_string, &static_eui64); + len = + spinel_datatype_pack(buffer, sizeof(buffer), "CiiLUE", 0x88, 9, 0xA3, 0xDEADBEEF, static_string, &static_eui64); if (len != 30) { @@ -2290,11 +2302,11 @@ main(void) len = 30; { - uint8_t c = 0; - unsigned int i1 = 0; - unsigned int i2 = 0; - uint32_t l = 0; - const char *str = NULL; + uint8_t c = 0; + unsigned int i1 = 0; + unsigned int i2 = 0; + uint32_t l = 0; + const char * str = NULL; const spinel_eui64_t *eui64 = NULL; len = spinel_datatype_unpack(buffer, (spinel_size_t)len, "CiiLUE", &c, &i1, &i2, &l, &str, &eui64); @@ -2343,14 +2355,15 @@ main(void) } { - uint8_t c = 0; - unsigned int i1 = 0; - unsigned int i2 = 0; - uint32_t l = 0; - char str[sizeof(static_string)]; + uint8_t c = 0; + unsigned int i1 = 0; + unsigned int i2 = 0; + uint32_t l = 0; + char str[sizeof(static_string)]; spinel_eui64_t eui64 = {{0}}; - len = spinel_datatype_unpack_in_place(buffer, (spinel_size_t)len, "CiiLUE", &c, &i1, &i2, &l, &str, sizeof(str), &eui64); + len = spinel_datatype_unpack_in_place(buffer, (spinel_size_t)len, "CiiLUE", &c, &i1, &i2, &l, &str, sizeof(str), + &eui64); if (len != 30) { @@ -2399,7 +2412,8 @@ main(void) memset(buffer, 0xAA, sizeof(buffer)); - len = spinel_datatype_pack(buffer, sizeof(buffer), "Cit(iL)UE", 0x88, 9, 0xA3, 0xDEADBEEF, static_string, &static_eui64); + len = spinel_datatype_pack(buffer, sizeof(buffer), "Cit(iL)UE", 0x88, 9, 0xA3, 0xDEADBEEF, static_string, + &static_eui64); if (len != 32) { @@ -2407,14 +2421,12 @@ main(void) goto bail; } - - { - uint8_t c = 0; - unsigned int i1 = 0; - unsigned int i2 = 0; - uint32_t l = 0; - const char *str = NULL; + uint8_t c = 0; + unsigned int i1 = 0; + unsigned int i2 = 0; + uint32_t l = 0; + const char * str = NULL; spinel_eui64_t *eui64 = NULL; len = spinel_datatype_unpack(buffer, (spinel_size_t)len, "Cit(iL)UE", &c, &i1, &i2, &l, &str, &eui64); @@ -2463,14 +2475,15 @@ main(void) } { - uint8_t c = 0; - unsigned int i1 = 0; - unsigned int i2 = 0; - uint32_t l = 0; - char str[sizeof(static_string)]; + uint8_t c = 0; + unsigned int i1 = 0; + unsigned int i2 = 0; + uint32_t l = 0; + char str[sizeof(static_string)]; spinel_eui64_t eui64 = {{0}}; - len = spinel_datatype_unpack_in_place(buffer, (spinel_size_t)len, "Cit(iL)UE", &c, &i1, &i2, &l, &str, sizeof(str), &eui64); + len = spinel_datatype_unpack_in_place(buffer, (spinel_size_t)len, "Cit(iL)UE", &c, &i1, &i2, &l, &str, + sizeof(str), &eui64); if (len != 32) { diff --git a/src/ncp/spinel.h b/src/ncp/spinel.h index ce6969627..02089593b 100644 --- a/src/ncp/spinel.h +++ b/src/ncp/spinel.h @@ -45,42 +45,42 @@ #ifndef DOXYGEN_SHOULD_SKIP_THIS -# if defined(__GNUC__) -# define SPINEL_API_EXTERN extern __attribute__ ((visibility ("default"))) -# define SPINEL_API_NONNULL_ALL __attribute__((nonnull)) -# define SPINEL_API_WARN_UNUSED_RESULT __attribute__((warn_unused_result)) -# endif // ifdef __GNUC__ +#if defined(__GNUC__) +#define SPINEL_API_EXTERN extern __attribute__((visibility("default"))) +#define SPINEL_API_NONNULL_ALL __attribute__((nonnull)) +#define SPINEL_API_WARN_UNUSED_RESULT __attribute__((warn_unused_result)) +#endif // ifdef __GNUC__ -# if !defined(__BEGIN_DECLS) || !defined(__END_DECLS) -# if defined(__cplusplus) -# define __BEGIN_DECLS extern "C" { -# define __END_DECLS } -# else // if defined(__cplusplus) -# define __BEGIN_DECLS -# define __END_DECLS -# endif // else defined(__cplusplus) -# endif // if !defined(__BEGIN_DECLS) || !defined(__END_DECLS) +#if !defined(__BEGIN_DECLS) || !defined(__END_DECLS) +#if defined(__cplusplus) +#define __BEGIN_DECLS extern "C" { +#define __END_DECLS } +#else // if defined(__cplusplus) +#define __BEGIN_DECLS +#define __END_DECLS +#endif // else defined(__cplusplus) +#endif // if !defined(__BEGIN_DECLS) || !defined(__END_DECLS) #endif // ifndef DOXYGEN_SHOULD_SKIP_THIS #ifndef SPINEL_API_EXTERN -# define SPINEL_API_EXTERN extern +#define SPINEL_API_EXTERN extern #endif #ifndef SPINEL_API_NONNULL_ALL -# define SPINEL_API_NONNULL_ALL +#define SPINEL_API_NONNULL_ALL #endif #ifndef SPINEL_API_WARN_UNUSED_RESULT -# define SPINEL_API_WARN_UNUSED_RESULT +#define SPINEL_API_WARN_UNUSED_RESULT #endif // ---------------------------------------------------------------------------- -#define SPINEL_PROTOCOL_VERSION_THREAD_MAJOR 4 -#define SPINEL_PROTOCOL_VERSION_THREAD_MINOR 3 +#define SPINEL_PROTOCOL_VERSION_THREAD_MAJOR 4 +#define SPINEL_PROTOCOL_VERSION_THREAD_MINOR 3 -#define SPINEL_FRAME_MAX_SIZE 1300 +#define SPINEL_FRAME_MAX_SIZE 1300 /** * @def SPINEL_ENCRYPTER_EXTRA_DATA_SIZE @@ -89,7 +89,7 @@ * needed by Spinel Encrypter. * */ -#define SPINEL_ENCRYPTER_EXTRA_DATA_SIZE 0 +#define SPINEL_ENCRYPTER_EXTRA_DATA_SIZE 0 /** * @def SPINEL_FRAME_BUFFER_SIZE @@ -98,44 +98,41 @@ * needed by Spinel Encrypter. * */ -#define SPINEL_FRAME_BUFFER_SIZE (SPINEL_FRAME_MAX_SIZE + SPINEL_ENCRYPTER_EXTRA_DATA_SIZE) +#define SPINEL_FRAME_BUFFER_SIZE (SPINEL_FRAME_MAX_SIZE + SPINEL_ENCRYPTER_EXTRA_DATA_SIZE) /// Macro for generating bit masks using bit index from the spec -#define SPINEL_BIT_MASK(bit_index,field_bit_count) \ - ( (1 << ((field_bit_count) - 1)) >> (bit_index) ) +#define SPINEL_BIT_MASK(bit_index, field_bit_count) ((1 << ((field_bit_count)-1)) >> (bit_index)) // ---------------------------------------------------------------------------- __BEGIN_DECLS -typedef enum -{ - SPINEL_STATUS_OK = 0, ///< Operation has completed successfully. - SPINEL_STATUS_FAILURE = 1, ///< Operation has failed for some undefined reason. +typedef enum { + SPINEL_STATUS_OK = 0, ///< Operation has completed successfully. + SPINEL_STATUS_FAILURE = 1, ///< Operation has failed for some undefined reason. - SPINEL_STATUS_UNIMPLEMENTED = 2, ///< Given operation has not been implemented. - SPINEL_STATUS_INVALID_ARGUMENT = 3, ///< An argument to the operation is invalid. - SPINEL_STATUS_INVALID_STATE = 4, ///< This operation is invalid for the current device state. - SPINEL_STATUS_INVALID_COMMAND = 5, ///< This command is not recognized. - SPINEL_STATUS_INVALID_INTERFACE = 6, ///< This interface is not supported. - SPINEL_STATUS_INTERNAL_ERROR = 7, ///< An internal runtime error has occured. - SPINEL_STATUS_SECURITY_ERROR = 8, ///< A security/authentication error has occured. - SPINEL_STATUS_PARSE_ERROR = 9, ///< A error has occured while parsing the command. - SPINEL_STATUS_IN_PROGRESS = 10, ///< This operation is in progress. - SPINEL_STATUS_NOMEM = 11, ///< Operation prevented due to memory pressure. - SPINEL_STATUS_BUSY = 12, ///< The device is currently performing a mutually exclusive operation - SPINEL_STATUS_PROP_NOT_FOUND = 13, ///< The given property is not recognized. - SPINEL_STATUS_DROPPED = 14, ///< A/The packet was dropped. - SPINEL_STATUS_EMPTY = 15, ///< The result of the operation is empty. - SPINEL_STATUS_CMD_TOO_BIG = 16, ///< The command was too large to fit in the internal buffer. - SPINEL_STATUS_NO_ACK = 17, ///< The packet was not acknowledged. - SPINEL_STATUS_CCA_FAILURE = 18, ///< The packet was not sent due to a CCA failure. - SPINEL_STATUS_ALREADY = 19, ///< The operation is already in progress. - SPINEL_STATUS_ITEM_NOT_FOUND = 20, ///< The given item could not be found. - SPINEL_STATUS_INVALID_COMMAND_FOR_PROP - = 21, ///< The given command cannot be performed on this property. + SPINEL_STATUS_UNIMPLEMENTED = 2, ///< Given operation has not been implemented. + SPINEL_STATUS_INVALID_ARGUMENT = 3, ///< An argument to the operation is invalid. + SPINEL_STATUS_INVALID_STATE = 4, ///< This operation is invalid for the current device state. + SPINEL_STATUS_INVALID_COMMAND = 5, ///< This command is not recognized. + SPINEL_STATUS_INVALID_INTERFACE = 6, ///< This interface is not supported. + SPINEL_STATUS_INTERNAL_ERROR = 7, ///< An internal runtime error has occured. + SPINEL_STATUS_SECURITY_ERROR = 8, ///< A security/authentication error has occured. + SPINEL_STATUS_PARSE_ERROR = 9, ///< A error has occured while parsing the command. + SPINEL_STATUS_IN_PROGRESS = 10, ///< This operation is in progress. + SPINEL_STATUS_NOMEM = 11, ///< Operation prevented due to memory pressure. + SPINEL_STATUS_BUSY = 12, ///< The device is currently performing a mutually exclusive operation + SPINEL_STATUS_PROP_NOT_FOUND = 13, ///< The given property is not recognized. + SPINEL_STATUS_DROPPED = 14, ///< A/The packet was dropped. + SPINEL_STATUS_EMPTY = 15, ///< The result of the operation is empty. + SPINEL_STATUS_CMD_TOO_BIG = 16, ///< The command was too large to fit in the internal buffer. + SPINEL_STATUS_NO_ACK = 17, ///< The packet was not acknowledged. + SPINEL_STATUS_CCA_FAILURE = 18, ///< The packet was not sent due to a CCA failure. + SPINEL_STATUS_ALREADY = 19, ///< The operation is already in progress. + SPINEL_STATUS_ITEM_NOT_FOUND = 20, ///< The given item could not be found. + SPINEL_STATUS_INVALID_COMMAND_FOR_PROP = 21, ///< The given command cannot be performed on this property. - SPINEL_STATUS_JOIN__BEGIN = 104, + SPINEL_STATUS_JOIN__BEGIN = 104, /// Generic failure to associate with other peers. /** @@ -145,7 +142,7 @@ typedef enum * * \sa SPINEL_PROP_NET_REQUIRE_JOIN_EXISTING */ - SPINEL_STATUS_JOIN_FAILURE = SPINEL_STATUS_JOIN__BEGIN + 0, + SPINEL_STATUS_JOIN_FAILURE = SPINEL_STATUS_JOIN__BEGIN + 0, /// The node found other peers but was unable to decode their packets. /** @@ -154,142 +151,136 @@ typedef enum * * \sa SPINEL_PROP_NET_REQUIRE_JOIN_EXISTING */ - SPINEL_STATUS_JOIN_SECURITY = SPINEL_STATUS_JOIN__BEGIN + 1, + SPINEL_STATUS_JOIN_SECURITY = SPINEL_STATUS_JOIN__BEGIN + 1, /// The node was unable to find any other peers on the network. /** * \sa SPINEL_PROP_NET_REQUIRE_JOIN_EXISTING */ - SPINEL_STATUS_JOIN_NO_PEERS = SPINEL_STATUS_JOIN__BEGIN + 2, + SPINEL_STATUS_JOIN_NO_PEERS = SPINEL_STATUS_JOIN__BEGIN + 2, /// The only potential peer nodes found are incompatible. /** * \sa SPINEL_PROP_NET_REQUIRE_JOIN_EXISTING */ - SPINEL_STATUS_JOIN_INCOMPATIBLE = SPINEL_STATUS_JOIN__BEGIN + 3, + SPINEL_STATUS_JOIN_INCOMPATIBLE = SPINEL_STATUS_JOIN__BEGIN + 3, - SPINEL_STATUS_JOIN__END = 112, + SPINEL_STATUS_JOIN__END = 112, - SPINEL_STATUS_RESET__BEGIN = 112, - SPINEL_STATUS_RESET_POWER_ON = SPINEL_STATUS_RESET__BEGIN + 0, - SPINEL_STATUS_RESET_EXTERNAL = SPINEL_STATUS_RESET__BEGIN + 1, - SPINEL_STATUS_RESET_SOFTWARE = SPINEL_STATUS_RESET__BEGIN + 2, - SPINEL_STATUS_RESET_FAULT = SPINEL_STATUS_RESET__BEGIN + 3, - SPINEL_STATUS_RESET_CRASH = SPINEL_STATUS_RESET__BEGIN + 4, - SPINEL_STATUS_RESET_ASSERT = SPINEL_STATUS_RESET__BEGIN + 5, - SPINEL_STATUS_RESET_OTHER = SPINEL_STATUS_RESET__BEGIN + 6, - SPINEL_STATUS_RESET_UNKNOWN = SPINEL_STATUS_RESET__BEGIN + 7, - SPINEL_STATUS_RESET_WATCHDOG = SPINEL_STATUS_RESET__BEGIN + 8, - SPINEL_STATUS_RESET__END = 128, + SPINEL_STATUS_RESET__BEGIN = 112, + SPINEL_STATUS_RESET_POWER_ON = SPINEL_STATUS_RESET__BEGIN + 0, + SPINEL_STATUS_RESET_EXTERNAL = SPINEL_STATUS_RESET__BEGIN + 1, + SPINEL_STATUS_RESET_SOFTWARE = SPINEL_STATUS_RESET__BEGIN + 2, + SPINEL_STATUS_RESET_FAULT = SPINEL_STATUS_RESET__BEGIN + 3, + SPINEL_STATUS_RESET_CRASH = SPINEL_STATUS_RESET__BEGIN + 4, + SPINEL_STATUS_RESET_ASSERT = SPINEL_STATUS_RESET__BEGIN + 5, + SPINEL_STATUS_RESET_OTHER = SPINEL_STATUS_RESET__BEGIN + 6, + SPINEL_STATUS_RESET_UNKNOWN = SPINEL_STATUS_RESET__BEGIN + 7, + SPINEL_STATUS_RESET_WATCHDOG = SPINEL_STATUS_RESET__BEGIN + 8, + SPINEL_STATUS_RESET__END = 128, - SPINEL_STATUS_VENDOR__BEGIN = 15360, - SPINEL_STATUS_VENDOR__END = 16384, + SPINEL_STATUS_VENDOR__BEGIN = 15360, + SPINEL_STATUS_VENDOR__END = 16384, - SPINEL_STATUS_STACK_NATIVE__BEGIN = 16384, - SPINEL_STATUS_STACK_NATIVE__END = 81920, + SPINEL_STATUS_STACK_NATIVE__BEGIN = 16384, + SPINEL_STATUS_STACK_NATIVE__END = 81920, - SPINEL_STATUS_EXPERIMENTAL__BEGIN = 2000000, - SPINEL_STATUS_EXPERIMENTAL__END = 2097152, + SPINEL_STATUS_EXPERIMENTAL__BEGIN = 2000000, + SPINEL_STATUS_EXPERIMENTAL__END = 2097152, } spinel_status_t; -typedef enum -{ - SPINEL_NET_ROLE_DETACHED = 0, - SPINEL_NET_ROLE_CHILD = 1, - SPINEL_NET_ROLE_ROUTER = 2, - SPINEL_NET_ROLE_LEADER = 3, +typedef enum { + SPINEL_NET_ROLE_DETACHED = 0, + SPINEL_NET_ROLE_CHILD = 1, + SPINEL_NET_ROLE_ROUTER = 2, + SPINEL_NET_ROLE_LEADER = 3, } spinel_net_role_t; -typedef enum -{ +typedef enum { SPINEL_IPV6_ICMP_PING_OFFLOAD_DISABLED = 0, SPINEL_IPV6_ICMP_PING_OFFLOAD_UNICAST_ONLY = 1, SPINEL_IPV6_ICMP_PING_OFFLOAD_MULTICAST_ONLY = 2, SPINEL_IPV6_ICMP_PING_OFFLOAD_ALL = 3, } spinel_ipv6_icmp_ping_offload_mode_t; -typedef enum -{ - SPINEL_SCAN_STATE_IDLE = 0, - SPINEL_SCAN_STATE_BEACON = 1, - SPINEL_SCAN_STATE_ENERGY = 2, - SPINEL_SCAN_STATE_DISCOVER = 3, +typedef enum { + SPINEL_SCAN_STATE_IDLE = 0, + SPINEL_SCAN_STATE_BEACON = 1, + SPINEL_SCAN_STATE_ENERGY = 2, + SPINEL_SCAN_STATE_DISCOVER = 3, } spinel_scan_state_t; -typedef enum -{ - SPINEL_MCU_POWER_STATE_ON = 0, - SPINEL_MCU_POWER_STATE_LOW_POWER = 1, - SPINEL_MCU_POWER_STATE_OFF = 2, +typedef enum { + SPINEL_MCU_POWER_STATE_ON = 0, + SPINEL_MCU_POWER_STATE_LOW_POWER = 1, + SPINEL_MCU_POWER_STATE_OFF = 2, } spinel_mcu_power_state_t; // The `spinel_power_state_t` enumeration and `POWER_STATE` // property are deprecated. Please use `MCU_POWER_STATE` // instead. -typedef enum -{ - SPINEL_POWER_STATE_OFFLINE = 0, - SPINEL_POWER_STATE_DEEP_SLEEP = 1, - SPINEL_POWER_STATE_STANDBY = 2, - SPINEL_POWER_STATE_LOW_POWER = 3, - SPINEL_POWER_STATE_ONLINE = 4, +typedef enum { + SPINEL_POWER_STATE_OFFLINE = 0, + SPINEL_POWER_STATE_DEEP_SLEEP = 1, + SPINEL_POWER_STATE_STANDBY = 2, + SPINEL_POWER_STATE_LOW_POWER = 3, + SPINEL_POWER_STATE_ONLINE = 4, } spinel_power_state_t; -typedef enum -{ - SPINEL_HOST_POWER_STATE_OFFLINE = 0, - SPINEL_HOST_POWER_STATE_DEEP_SLEEP = 1, - SPINEL_HOST_POWER_STATE_RESERVED = 2, - SPINEL_HOST_POWER_STATE_LOW_POWER = 3, - SPINEL_HOST_POWER_STATE_ONLINE = 4, +typedef enum { + SPINEL_HOST_POWER_STATE_OFFLINE = 0, + SPINEL_HOST_POWER_STATE_DEEP_SLEEP = 1, + SPINEL_HOST_POWER_STATE_RESERVED = 2, + SPINEL_HOST_POWER_STATE_LOW_POWER = 3, + SPINEL_HOST_POWER_STATE_ONLINE = 4, } spinel_host_power_state_t; enum { - SPINEL_NET_FLAG_ON_MESH = (1 << 0), - SPINEL_NET_FLAG_DEFAULT_ROUTE = (1 << 1), - SPINEL_NET_FLAG_CONFIGURE = (1 << 2), - SPINEL_NET_FLAG_DHCP = (1 << 3), - SPINEL_NET_FLAG_SLAAC = (1 << 4), - SPINEL_NET_FLAG_PREFERRED = (1 << 5), + SPINEL_NET_FLAG_ON_MESH = (1 << 0), + SPINEL_NET_FLAG_DEFAULT_ROUTE = (1 << 1), + SPINEL_NET_FLAG_CONFIGURE = (1 << 2), + SPINEL_NET_FLAG_DHCP = (1 << 3), + SPINEL_NET_FLAG_SLAAC = (1 << 4), + SPINEL_NET_FLAG_PREFERRED = (1 << 5), - SPINEL_NET_FLAG_PREFERENCE_OFFSET = 6, - SPINEL_NET_FLAG_PREFERENCE_MASK = (3 << SPINEL_NET_FLAG_PREFERENCE_OFFSET), + SPINEL_NET_FLAG_PREFERENCE_OFFSET = 6, + SPINEL_NET_FLAG_PREFERENCE_MASK = (3 << SPINEL_NET_FLAG_PREFERENCE_OFFSET), }; enum { - SPINEL_ROUTE_PREFERENCE_HIGH = (1 << SPINEL_NET_FLAG_PREFERENCE_OFFSET), - SPINEL_ROUTE_PREFERENCE_MEDIUM = (0 << SPINEL_NET_FLAG_PREFERENCE_OFFSET), - SPINEL_ROUTE_PREFERENCE_LOW = (3 << SPINEL_NET_FLAG_PREFERENCE_OFFSET), + SPINEL_ROUTE_PREFERENCE_HIGH = (1 << SPINEL_NET_FLAG_PREFERENCE_OFFSET), + SPINEL_ROUTE_PREFERENCE_MEDIUM = (0 << SPINEL_NET_FLAG_PREFERENCE_OFFSET), + SPINEL_ROUTE_PREFERENCE_LOW = (3 << SPINEL_NET_FLAG_PREFERENCE_OFFSET), }; enum { - SPINEL_THREAD_MODE_FULL_NETWORK_DATA = (1 << 0), - SPINEL_THREAD_MODE_FULL_FUNCTION_DEV = (1 << 1), - SPINEL_THREAD_MODE_SECURE_DATA_REQUEST = (1 << 2), - SPINEL_THREAD_MODE_RX_ON_WHEN_IDLE = (1 << 3), -}; - -enum { - SPINEL_GPIO_FLAG_DIR_INPUT = 0, - SPINEL_GPIO_FLAG_DIR_OUTPUT = SPINEL_BIT_MASK(0, 8), - SPINEL_GPIO_FLAG_PULL_UP = SPINEL_BIT_MASK(1, 8), - SPINEL_GPIO_FLAG_PULL_DOWN = SPINEL_BIT_MASK(2, 8), - SPINEL_GPIO_FLAG_OPEN_DRAIN = SPINEL_BIT_MASK(2, 8), - SPINEL_GPIO_FLAG_TRIGGER_NONE = 0, - SPINEL_GPIO_FLAG_TRIGGER_RISING = SPINEL_BIT_MASK(3, 8), - SPINEL_GPIO_FLAG_TRIGGER_FALLING = SPINEL_BIT_MASK(4, 8), - SPINEL_GPIO_FLAG_TRIGGER_ANY = SPINEL_GPIO_FLAG_TRIGGER_RISING - | SPINEL_GPIO_FLAG_TRIGGER_FALLING, + SPINEL_THREAD_MODE_FULL_NETWORK_DATA = (1 << 0), + SPINEL_THREAD_MODE_FULL_FUNCTION_DEV = (1 << 1), + SPINEL_THREAD_MODE_SECURE_DATA_REQUEST = (1 << 2), + SPINEL_THREAD_MODE_RX_ON_WHEN_IDLE = (1 << 3), }; enum { - SPINEL_PROTOCOL_TYPE_BOOTLOADER = 0, - SPINEL_PROTOCOL_TYPE_ZIGBEE_IP = 2, - SPINEL_PROTOCOL_TYPE_THREAD = 3, + SPINEL_GPIO_FLAG_DIR_INPUT = 0, + SPINEL_GPIO_FLAG_DIR_OUTPUT = SPINEL_BIT_MASK(0, 8), + SPINEL_GPIO_FLAG_PULL_UP = SPINEL_BIT_MASK(1, 8), + SPINEL_GPIO_FLAG_PULL_DOWN = SPINEL_BIT_MASK(2, 8), + SPINEL_GPIO_FLAG_OPEN_DRAIN = SPINEL_BIT_MASK(2, 8), + SPINEL_GPIO_FLAG_TRIGGER_NONE = 0, + SPINEL_GPIO_FLAG_TRIGGER_RISING = SPINEL_BIT_MASK(3, 8), + SPINEL_GPIO_FLAG_TRIGGER_FALLING = SPINEL_BIT_MASK(4, 8), + SPINEL_GPIO_FLAG_TRIGGER_ANY = SPINEL_GPIO_FLAG_TRIGGER_RISING | SPINEL_GPIO_FLAG_TRIGGER_FALLING, +}; + +enum +{ + SPINEL_PROTOCOL_TYPE_BOOTLOADER = 0, + SPINEL_PROTOCOL_TYPE_ZIGBEE_IP = 2, + SPINEL_PROTOCOL_TYPE_THREAD = 3, }; enum @@ -301,35 +292,35 @@ enum enum { - SPINEL_NCP_LOG_LEVEL_EMERG = 0, - SPINEL_NCP_LOG_LEVEL_ALERT = 1, - SPINEL_NCP_LOG_LEVEL_CRIT = 2, - SPINEL_NCP_LOG_LEVEL_ERR = 3, - SPINEL_NCP_LOG_LEVEL_WARN = 4, - SPINEL_NCP_LOG_LEVEL_NOTICE = 5, - SPINEL_NCP_LOG_LEVEL_INFO = 6, - SPINEL_NCP_LOG_LEVEL_DEBUG = 7, + SPINEL_NCP_LOG_LEVEL_EMERG = 0, + SPINEL_NCP_LOG_LEVEL_ALERT = 1, + SPINEL_NCP_LOG_LEVEL_CRIT = 2, + SPINEL_NCP_LOG_LEVEL_ERR = 3, + SPINEL_NCP_LOG_LEVEL_WARN = 4, + SPINEL_NCP_LOG_LEVEL_NOTICE = 5, + SPINEL_NCP_LOG_LEVEL_INFO = 6, + SPINEL_NCP_LOG_LEVEL_DEBUG = 7, }; enum { - SPINEL_NCP_LOG_REGION_NONE = 0, - SPINEL_NCP_LOG_REGION_OT_API = 1, - SPINEL_NCP_LOG_REGION_OT_MLE = 2, - SPINEL_NCP_LOG_REGION_OT_ARP = 3, - SPINEL_NCP_LOG_REGION_OT_NET_DATA = 4, - SPINEL_NCP_LOG_REGION_OT_ICMP = 5, - SPINEL_NCP_LOG_REGION_OT_IP6 = 6, - SPINEL_NCP_LOG_REGION_OT_MAC = 7, - SPINEL_NCP_LOG_REGION_OT_MEM = 8, - SPINEL_NCP_LOG_REGION_OT_NCP = 9, - SPINEL_NCP_LOG_REGION_OT_MESH_COP = 10, - SPINEL_NCP_LOG_REGION_OT_NET_DIAG = 11, - SPINEL_NCP_LOG_REGION_OT_PLATFORM = 12, - SPINEL_NCP_LOG_REGION_OT_COAP = 13, - SPINEL_NCP_LOG_REGION_OT_CLI = 14, - SPINEL_NCP_LOG_REGION_OT_CORE = 15, - SPINEL_NCP_LOG_REGION_OT_UTIL = 16, + SPINEL_NCP_LOG_REGION_NONE = 0, + SPINEL_NCP_LOG_REGION_OT_API = 1, + SPINEL_NCP_LOG_REGION_OT_MLE = 2, + SPINEL_NCP_LOG_REGION_OT_ARP = 3, + SPINEL_NCP_LOG_REGION_OT_NET_DATA = 4, + SPINEL_NCP_LOG_REGION_OT_ICMP = 5, + SPINEL_NCP_LOG_REGION_OT_IP6 = 6, + SPINEL_NCP_LOG_REGION_OT_MAC = 7, + SPINEL_NCP_LOG_REGION_OT_MEM = 8, + SPINEL_NCP_LOG_REGION_OT_NCP = 9, + SPINEL_NCP_LOG_REGION_OT_MESH_COP = 10, + SPINEL_NCP_LOG_REGION_OT_NET_DIAG = 11, + SPINEL_NCP_LOG_REGION_OT_PLATFORM = 12, + SPINEL_NCP_LOG_REGION_OT_COAP = 13, + SPINEL_NCP_LOG_REGION_OT_CLI = 14, + SPINEL_NCP_LOG_REGION_OT_CORE = 15, + SPINEL_NCP_LOG_REGION_OT_UTIL = 16, }; typedef struct @@ -357,148 +348,147 @@ typedef struct uint8_t bytes[16]; } spinel_ipv6addr_t; -typedef int spinel_ssize_t; +typedef int spinel_ssize_t; typedef unsigned int spinel_size_t; -typedef uint8_t spinel_tid_t; +typedef uint8_t spinel_tid_t; typedef unsigned int spinel_cid_t; enum { - SPINEL_MD_FLAG_TX = 0x0001, //!< Packet was transmitted, not received. - SPINEL_MD_FLAG_BAD_FCS = 0x0004, //!< Packet was received with bad FCS - SPINEL_MD_FLAG_DUPE = 0x0008, //!< Packet seems to be a duplicate - SPINEL_MD_FLAG_RESERVED = 0xFFF2, //!< Flags reserved for future use. + SPINEL_MD_FLAG_TX = 0x0001, //!< Packet was transmitted, not received. + SPINEL_MD_FLAG_BAD_FCS = 0x0004, //!< Packet was received with bad FCS + SPINEL_MD_FLAG_DUPE = 0x0008, //!< Packet seems to be a duplicate + SPINEL_MD_FLAG_RESERVED = 0xFFF2, //!< Flags reserved for future use. }; enum { - SPINEL_CMD_NOOP = 0, - SPINEL_CMD_RESET = 1, - SPINEL_CMD_PROP_VALUE_GET = 2, - SPINEL_CMD_PROP_VALUE_SET = 3, - SPINEL_CMD_PROP_VALUE_INSERT = 4, - SPINEL_CMD_PROP_VALUE_REMOVE = 5, - SPINEL_CMD_PROP_VALUE_IS = 6, - SPINEL_CMD_PROP_VALUE_INSERTED = 7, - SPINEL_CMD_PROP_VALUE_REMOVED = 8, + SPINEL_CMD_NOOP = 0, + SPINEL_CMD_RESET = 1, + SPINEL_CMD_PROP_VALUE_GET = 2, + SPINEL_CMD_PROP_VALUE_SET = 3, + SPINEL_CMD_PROP_VALUE_INSERT = 4, + SPINEL_CMD_PROP_VALUE_REMOVE = 5, + SPINEL_CMD_PROP_VALUE_IS = 6, + SPINEL_CMD_PROP_VALUE_INSERTED = 7, + SPINEL_CMD_PROP_VALUE_REMOVED = 8, - SPINEL_CMD_NET_SAVE = 9, - SPINEL_CMD_NET_CLEAR = 10, - SPINEL_CMD_NET_RECALL = 11, + SPINEL_CMD_NET_SAVE = 9, + SPINEL_CMD_NET_CLEAR = 10, + SPINEL_CMD_NET_RECALL = 11, - SPINEL_CMD_HBO_OFFLOAD = 12, - SPINEL_CMD_HBO_RECLAIM = 13, - SPINEL_CMD_HBO_DROP = 14, - SPINEL_CMD_HBO_OFFLOADED = 15, - SPINEL_CMD_HBO_RECLAIMED = 16, - SPINEL_CMD_HBO_DROPED = 17, + SPINEL_CMD_HBO_OFFLOAD = 12, + SPINEL_CMD_HBO_RECLAIM = 13, + SPINEL_CMD_HBO_DROP = 14, + SPINEL_CMD_HBO_OFFLOADED = 15, + SPINEL_CMD_HBO_RECLAIMED = 16, + SPINEL_CMD_HBO_DROPED = 17, - SPINEL_CMD_PEEK = 18, - SPINEL_CMD_PEEK_RET = 19, - SPINEL_CMD_POKE = 20, + SPINEL_CMD_PEEK = 18, + SPINEL_CMD_PEEK_RET = 19, + SPINEL_CMD_POKE = 20, - SPINEL_CMD_PROP_VALUE_MULTI_GET = 21, - SPINEL_CMD_PROP_VALUE_MULTI_SET = 22, - SPINEL_CMD_PROP_VALUES_ARE = 23, + SPINEL_CMD_PROP_VALUE_MULTI_GET = 21, + SPINEL_CMD_PROP_VALUE_MULTI_SET = 22, + SPINEL_CMD_PROP_VALUES_ARE = 23, - SPINEL_CMD_NEST__BEGIN = 15296, - SPINEL_CMD_NEST__END = 15360, + SPINEL_CMD_NEST__BEGIN = 15296, + SPINEL_CMD_NEST__END = 15360, - SPINEL_CMD_VENDOR__BEGIN = 15360, - SPINEL_CMD_VENDOR__END = 16384, + SPINEL_CMD_VENDOR__BEGIN = 15360, + SPINEL_CMD_VENDOR__END = 16384, - SPINEL_CMD_EXPERIMENTAL__BEGIN = 2000000, - SPINEL_CMD_EXPERIMENTAL__END = 2097152, + SPINEL_CMD_EXPERIMENTAL__BEGIN = 2000000, + SPINEL_CMD_EXPERIMENTAL__END = 2097152, }; enum { - SPINEL_CAP_LOCK = 1, - SPINEL_CAP_NET_SAVE = 2, - SPINEL_CAP_HBO = 3, - SPINEL_CAP_POWER_SAVE = 4, + SPINEL_CAP_LOCK = 1, + SPINEL_CAP_NET_SAVE = 2, + SPINEL_CAP_HBO = 3, + SPINEL_CAP_POWER_SAVE = 4, - SPINEL_CAP_COUNTERS = 5, - SPINEL_CAP_JAM_DETECT = 6, + SPINEL_CAP_COUNTERS = 5, + SPINEL_CAP_JAM_DETECT = 6, - SPINEL_CAP_PEEK_POKE = 7, + SPINEL_CAP_PEEK_POKE = 7, - SPINEL_CAP_WRITABLE_RAW_STREAM = 8, - SPINEL_CAP_GPIO = 9, - SPINEL_CAP_TRNG = 10, - SPINEL_CAP_CMD_MULTI = 11, - SPINEL_CAP_UNSOL_UPDATE_FILTER = 12, - SPINEL_CAP_MCU_POWER_STATE = 13, + SPINEL_CAP_WRITABLE_RAW_STREAM = 8, + SPINEL_CAP_GPIO = 9, + SPINEL_CAP_TRNG = 10, + SPINEL_CAP_CMD_MULTI = 11, + SPINEL_CAP_UNSOL_UPDATE_FILTER = 12, + SPINEL_CAP_MCU_POWER_STATE = 13, - SPINEL_CAP_802_15_4__BEGIN = 16, - SPINEL_CAP_802_15_4_2003 = (SPINEL_CAP_802_15_4__BEGIN + 0), - SPINEL_CAP_802_15_4_2006 = (SPINEL_CAP_802_15_4__BEGIN + 1), - SPINEL_CAP_802_15_4_2011 = (SPINEL_CAP_802_15_4__BEGIN + 2), - SPINEL_CAP_802_15_4_PIB = (SPINEL_CAP_802_15_4__BEGIN + 5), - SPINEL_CAP_802_15_4_2450MHZ_OQPSK = (SPINEL_CAP_802_15_4__BEGIN + 8), - SPINEL_CAP_802_15_4_915MHZ_OQPSK = (SPINEL_CAP_802_15_4__BEGIN + 9), - SPINEL_CAP_802_15_4_868MHZ_OQPSK = (SPINEL_CAP_802_15_4__BEGIN + 10), - SPINEL_CAP_802_15_4_915MHZ_BPSK = (SPINEL_CAP_802_15_4__BEGIN + 11), - SPINEL_CAP_802_15_4_868MHZ_BPSK = (SPINEL_CAP_802_15_4__BEGIN + 12), - SPINEL_CAP_802_15_4_915MHZ_ASK = (SPINEL_CAP_802_15_4__BEGIN + 13), - SPINEL_CAP_802_15_4_868MHZ_ASK = (SPINEL_CAP_802_15_4__BEGIN + 14), - SPINEL_CAP_802_15_4__END = 32, + SPINEL_CAP_802_15_4__BEGIN = 16, + SPINEL_CAP_802_15_4_2003 = (SPINEL_CAP_802_15_4__BEGIN + 0), + SPINEL_CAP_802_15_4_2006 = (SPINEL_CAP_802_15_4__BEGIN + 1), + SPINEL_CAP_802_15_4_2011 = (SPINEL_CAP_802_15_4__BEGIN + 2), + SPINEL_CAP_802_15_4_PIB = (SPINEL_CAP_802_15_4__BEGIN + 5), + SPINEL_CAP_802_15_4_2450MHZ_OQPSK = (SPINEL_CAP_802_15_4__BEGIN + 8), + SPINEL_CAP_802_15_4_915MHZ_OQPSK = (SPINEL_CAP_802_15_4__BEGIN + 9), + SPINEL_CAP_802_15_4_868MHZ_OQPSK = (SPINEL_CAP_802_15_4__BEGIN + 10), + SPINEL_CAP_802_15_4_915MHZ_BPSK = (SPINEL_CAP_802_15_4__BEGIN + 11), + SPINEL_CAP_802_15_4_868MHZ_BPSK = (SPINEL_CAP_802_15_4__BEGIN + 12), + SPINEL_CAP_802_15_4_915MHZ_ASK = (SPINEL_CAP_802_15_4__BEGIN + 13), + SPINEL_CAP_802_15_4_868MHZ_ASK = (SPINEL_CAP_802_15_4__BEGIN + 14), + SPINEL_CAP_802_15_4__END = 32, - SPINEL_CAP_ROLE__BEGIN = 48, - SPINEL_CAP_ROLE_ROUTER = (SPINEL_CAP_ROLE__BEGIN + 0), - SPINEL_CAP_ROLE_SLEEPY = (SPINEL_CAP_ROLE__BEGIN + 1), - SPINEL_CAP_ROLE__END = 52, + SPINEL_CAP_ROLE__BEGIN = 48, + SPINEL_CAP_ROLE_ROUTER = (SPINEL_CAP_ROLE__BEGIN + 0), + SPINEL_CAP_ROLE_SLEEPY = (SPINEL_CAP_ROLE__BEGIN + 1), + SPINEL_CAP_ROLE__END = 52, - SPINEL_CAP_NET__BEGIN = 52, - SPINEL_CAP_NET_THREAD_1_0 = (SPINEL_CAP_NET__BEGIN + 0), - SPINEL_CAP_NET__END = 64, + SPINEL_CAP_NET__BEGIN = 52, + SPINEL_CAP_NET_THREAD_1_0 = (SPINEL_CAP_NET__BEGIN + 0), + SPINEL_CAP_NET__END = 64, - SPINEL_CAP_OPENTHREAD__BEGIN = 512, - SPINEL_CAP_MAC_WHITELIST = (SPINEL_CAP_OPENTHREAD__BEGIN + 0), - SPINEL_CAP_MAC_RAW = (SPINEL_CAP_OPENTHREAD__BEGIN + 1), - SPINEL_CAP_OOB_STEERING_DATA = (SPINEL_CAP_OPENTHREAD__BEGIN + 2), - SPINEL_CAP_CHANNEL_MONITOR = (SPINEL_CAP_OPENTHREAD__BEGIN + 3), - SPINEL_CAP_ERROR_RATE_TRACKING = (SPINEL_CAP_OPENTHREAD__BEGIN + 4), - SPINEL_CAP_CHANNEL_MANAGER = (SPINEL_CAP_OPENTHREAD__BEGIN + 5), - SPINEL_CAP_OPENTHREAD_LOG_METADATA = (SPINEL_CAP_OPENTHREAD__BEGIN + 6), - SPINEL_CAP_OPENTHREAD__END = 640, + SPINEL_CAP_OPENTHREAD__BEGIN = 512, + SPINEL_CAP_MAC_WHITELIST = (SPINEL_CAP_OPENTHREAD__BEGIN + 0), + SPINEL_CAP_MAC_RAW = (SPINEL_CAP_OPENTHREAD__BEGIN + 1), + SPINEL_CAP_OOB_STEERING_DATA = (SPINEL_CAP_OPENTHREAD__BEGIN + 2), + SPINEL_CAP_CHANNEL_MONITOR = (SPINEL_CAP_OPENTHREAD__BEGIN + 3), + SPINEL_CAP_ERROR_RATE_TRACKING = (SPINEL_CAP_OPENTHREAD__BEGIN + 4), + SPINEL_CAP_CHANNEL_MANAGER = (SPINEL_CAP_OPENTHREAD__BEGIN + 5), + SPINEL_CAP_OPENTHREAD_LOG_METADATA = (SPINEL_CAP_OPENTHREAD__BEGIN + 6), + SPINEL_CAP_OPENTHREAD__END = 640, - SPINEL_CAP_THREAD__BEGIN = 1024, - SPINEL_CAP_THREAD_COMMISSIONER = (SPINEL_CAP_THREAD__BEGIN + 0), - SPINEL_CAP_THREAD_TMF_PROXY = (SPINEL_CAP_THREAD__BEGIN + 1), - SPINEL_CAP_THREAD__END = 1152, + SPINEL_CAP_THREAD__BEGIN = 1024, + SPINEL_CAP_THREAD_COMMISSIONER = (SPINEL_CAP_THREAD__BEGIN + 0), + SPINEL_CAP_THREAD_TMF_PROXY = (SPINEL_CAP_THREAD__BEGIN + 1), + SPINEL_CAP_THREAD__END = 1152, - SPINEL_CAP_NEST__BEGIN = 15296, - SPINEL_CAP_NEST_LEGACY_INTERFACE = (SPINEL_CAP_NEST__BEGIN + 0), - SPINEL_CAP_NEST_LEGACY_NET_WAKE = (SPINEL_CAP_NEST__BEGIN + 1), - SPINEL_CAP_NEST_TRANSMIT_HOOK = (SPINEL_CAP_NEST__BEGIN + 2), - SPINEL_CAP_NEST__END = 15360, + SPINEL_CAP_NEST__BEGIN = 15296, + SPINEL_CAP_NEST_LEGACY_INTERFACE = (SPINEL_CAP_NEST__BEGIN + 0), + SPINEL_CAP_NEST_LEGACY_NET_WAKE = (SPINEL_CAP_NEST__BEGIN + 1), + SPINEL_CAP_NEST_TRANSMIT_HOOK = (SPINEL_CAP_NEST__BEGIN + 2), + SPINEL_CAP_NEST__END = 15360, - SPINEL_CAP_VENDOR__BEGIN = 15360, - SPINEL_CAP_VENDOR__END = 16384, + SPINEL_CAP_VENDOR__BEGIN = 15360, + SPINEL_CAP_VENDOR__END = 16384, - SPINEL_CAP_EXPERIMENTAL__BEGIN = 2000000, - SPINEL_CAP_EXPERIMENTAL__END = 2097152, + SPINEL_CAP_EXPERIMENTAL__BEGIN = 2000000, + SPINEL_CAP_EXPERIMENTAL__END = 2097152, }; -typedef enum -{ - SPINEL_PROP_LAST_STATUS = 0, ///< status [i] - SPINEL_PROP_PROTOCOL_VERSION = 1, ///< major, minor [i,i] - SPINEL_PROP_NCP_VERSION = 2, ///< version string [U] - SPINEL_PROP_INTERFACE_TYPE = 3, ///< [i] - SPINEL_PROP_VENDOR_ID = 4, ///< [i] - SPINEL_PROP_CAPS = 5, ///< capability list [A(i)] - SPINEL_PROP_INTERFACE_COUNT = 6, ///< Interface count [C] - SPINEL_PROP_POWER_STATE = 7, ///< PowerState [C] (deprecated, use `MCU_POWER_STATE` instead). - SPINEL_PROP_HWADDR = 8, ///< PermEUI64 [E] - SPINEL_PROP_LOCK = 9, ///< PropLock [b] - SPINEL_PROP_HBO_MEM_MAX = 10, ///< Max offload mem [S] - SPINEL_PROP_HBO_BLOCK_MAX = 11, ///< Max offload block [S] - SPINEL_PROP_HOST_POWER_STATE = 12, ///< Host MCU power state [C] - SPINEL_PROP_MCU_POWER_STATE = 13, ///< NCP's MCU power state [c] +typedef enum { + SPINEL_PROP_LAST_STATUS = 0, ///< status [i] + SPINEL_PROP_PROTOCOL_VERSION = 1, ///< major, minor [i,i] + SPINEL_PROP_NCP_VERSION = 2, ///< version string [U] + SPINEL_PROP_INTERFACE_TYPE = 3, ///< [i] + SPINEL_PROP_VENDOR_ID = 4, ///< [i] + SPINEL_PROP_CAPS = 5, ///< capability list [A(i)] + SPINEL_PROP_INTERFACE_COUNT = 6, ///< Interface count [C] + SPINEL_PROP_POWER_STATE = 7, ///< PowerState [C] (deprecated, use `MCU_POWER_STATE` instead). + SPINEL_PROP_HWADDR = 8, ///< PermEUI64 [E] + SPINEL_PROP_LOCK = 9, ///< PropLock [b] + SPINEL_PROP_HBO_MEM_MAX = 10, ///< Max offload mem [S] + SPINEL_PROP_HBO_BLOCK_MAX = 11, ///< Max offload block [S] + SPINEL_PROP_HOST_POWER_STATE = 12, ///< Host MCU power state [C] + SPINEL_PROP_MCU_POWER_STATE = 13, ///< NCP's MCU power state [c] - SPINEL_PROP_BASE_EXT__BEGIN = 0x1000, + SPINEL_PROP_BASE_EXT__BEGIN = 0x1000, /// GPIO Configuration /** Format: `A(CCU)` @@ -543,7 +533,7 @@ typedef enum * configuration of GPIOs which are already exposed---it cannot be used * by the host to add additional GPIOs. */ - SPINEL_PROP_GPIO_CONFIG = SPINEL_PROP_BASE_EXT__BEGIN + 0, + SPINEL_PROP_GPIO_CONFIG = SPINEL_PROP_BASE_EXT__BEGIN + 0, /// GPIO State Bitmask /** Format: `D` @@ -580,7 +570,7 @@ typedef enum * * When writing, unspecified bits are assumed to be zero. */ - SPINEL_PROP_GPIO_STATE = SPINEL_PROP_BASE_EXT__BEGIN + 2, + SPINEL_PROP_GPIO_STATE = SPINEL_PROP_BASE_EXT__BEGIN + 2, /// GPIO State Set-Only Bitmask /** Format: `D` @@ -594,7 +584,7 @@ typedef enum * any bits for GPIOs which are not specified in `PROP_GPIO_CONFIG` MUST * be ignored. */ - SPINEL_PROP_GPIO_STATE_SET = SPINEL_PROP_BASE_EXT__BEGIN + 3, + SPINEL_PROP_GPIO_STATE_SET = SPINEL_PROP_BASE_EXT__BEGIN + 3, /// GPIO State Clear-Only Bitmask /** Format: `D` @@ -608,17 +598,16 @@ typedef enum * any bits for GPIOs which are not specified in `PROP_GPIO_CONFIG` MUST * be ignored. */ - SPINEL_PROP_GPIO_STATE_CLEAR = SPINEL_PROP_BASE_EXT__BEGIN + 4, + SPINEL_PROP_GPIO_STATE_CLEAR = SPINEL_PROP_BASE_EXT__BEGIN + 4, /// 32-bit random number from TRNG, ready-to-use. - SPINEL_PROP_TRNG_32 = SPINEL_PROP_BASE_EXT__BEGIN + 5, + SPINEL_PROP_TRNG_32 = SPINEL_PROP_BASE_EXT__BEGIN + 5, /// 16 random bytes from TRNG, ready-to-use. - SPINEL_PROP_TRNG_128 = SPINEL_PROP_BASE_EXT__BEGIN + 6, + SPINEL_PROP_TRNG_128 = SPINEL_PROP_BASE_EXT__BEGIN + 6, /// Raw samples from TRNG entropy source representing 32 bits of entropy. - SPINEL_PROP_TRNG_RAW_32 = SPINEL_PROP_BASE_EXT__BEGIN + 7, - + SPINEL_PROP_TRNG_RAW_32 = SPINEL_PROP_BASE_EXT__BEGIN + 7, /// NCP Unsolicited update filter /** Format: `A(I)` @@ -633,7 +622,7 @@ typedef enum * present in `PROP_UNSOL_UPDATE_LIST`. If such properties are added, * the NCP ignores the unsupported properties. */ - SPINEL_PROP_UNSOL_UPDATE_FILTER = SPINEL_PROP_BASE_EXT__BEGIN + 8, + SPINEL_PROP_UNSOL_UPDATE_FILTER = SPINEL_PROP_BASE_EXT__BEGIN + 8, /// List of properties capable of generating unsolicited value update. /** Format: `A(I)` @@ -648,22 +637,22 @@ typedef enum * This property is intended to effectively behave as a constant * for a given NCP firmware. */ - SPINEL_PROP_UNSOL_UPDATE_LIST = SPINEL_PROP_BASE_EXT__BEGIN + 9, + SPINEL_PROP_UNSOL_UPDATE_LIST = SPINEL_PROP_BASE_EXT__BEGIN + 9, - SPINEL_PROP_BASE_EXT__END = 0x1100, + SPINEL_PROP_BASE_EXT__END = 0x1100, - SPINEL_PROP_PHY__BEGIN = 0x20, - SPINEL_PROP_PHY_ENABLED = SPINEL_PROP_PHY__BEGIN + 0, ///< [b] - SPINEL_PROP_PHY_CHAN = SPINEL_PROP_PHY__BEGIN + 1, ///< [C] - SPINEL_PROP_PHY_CHAN_SUPPORTED = SPINEL_PROP_PHY__BEGIN + 2, ///< [A(C)] - SPINEL_PROP_PHY_FREQ = SPINEL_PROP_PHY__BEGIN + 3, ///< kHz [L] - SPINEL_PROP_PHY_CCA_THRESHOLD = SPINEL_PROP_PHY__BEGIN + 4, ///< dBm [c] - SPINEL_PROP_PHY_TX_POWER = SPINEL_PROP_PHY__BEGIN + 5, ///< [c] - SPINEL_PROP_PHY_RSSI = SPINEL_PROP_PHY__BEGIN + 6, ///< dBm [c] - SPINEL_PROP_PHY_RX_SENSITIVITY = SPINEL_PROP_PHY__BEGIN + 7, ///< dBm [c] - SPINEL_PROP_PHY__END = 0x30, + SPINEL_PROP_PHY__BEGIN = 0x20, + SPINEL_PROP_PHY_ENABLED = SPINEL_PROP_PHY__BEGIN + 0, ///< [b] + SPINEL_PROP_PHY_CHAN = SPINEL_PROP_PHY__BEGIN + 1, ///< [C] + SPINEL_PROP_PHY_CHAN_SUPPORTED = SPINEL_PROP_PHY__BEGIN + 2, ///< [A(C)] + SPINEL_PROP_PHY_FREQ = SPINEL_PROP_PHY__BEGIN + 3, ///< kHz [L] + SPINEL_PROP_PHY_CCA_THRESHOLD = SPINEL_PROP_PHY__BEGIN + 4, ///< dBm [c] + SPINEL_PROP_PHY_TX_POWER = SPINEL_PROP_PHY__BEGIN + 5, ///< [c] + SPINEL_PROP_PHY_RSSI = SPINEL_PROP_PHY__BEGIN + 6, ///< dBm [c] + SPINEL_PROP_PHY_RX_SENSITIVITY = SPINEL_PROP_PHY__BEGIN + 7, ///< dBm [c] + SPINEL_PROP_PHY__END = 0x30, - SPINEL_PROP_PHY_EXT__BEGIN = 0x1200, + SPINEL_PROP_PHY_EXT__BEGIN = 0x1200, /// Signal Jamming Detection Enable /** Format: `b` @@ -671,7 +660,7 @@ typedef enum * Indicates if jamming detection is enabled or disabled. Set to true * to enable jamming detection. */ - SPINEL_PROP_JAM_DETECT_ENABLE = SPINEL_PROP_PHY_EXT__BEGIN + 0, + SPINEL_PROP_JAM_DETECT_ENABLE = SPINEL_PROP_PHY_EXT__BEGIN + 0, /// Signal Jamming Detected Indicator /** Format: `b` (Read-Only) @@ -681,7 +670,7 @@ typedef enum * When jamming detection is enabled, changes to the value of this * property are emitted asynchronously via `CMD_PROP_VALUE_IS`. */ - SPINEL_PROP_JAM_DETECTED = SPINEL_PROP_PHY_EXT__BEGIN + 1, + SPINEL_PROP_JAM_DETECTED = SPINEL_PROP_PHY_EXT__BEGIN + 1, /// Jamming detection RSSI threshold /** Format: `c` @@ -691,8 +680,7 @@ typedef enum * dBm) above which the jamming detection will consider the * channel blocked. */ - SPINEL_PROP_JAM_DETECT_RSSI_THRESHOLD - = SPINEL_PROP_PHY_EXT__BEGIN + 2, + SPINEL_PROP_JAM_DETECT_RSSI_THRESHOLD = SPINEL_PROP_PHY_EXT__BEGIN + 2, /// Jamming detection window size /** Format: `C` @@ -701,7 +689,7 @@ typedef enum * This parameter describes the window period for signal jamming * detection. */ - SPINEL_PROP_JAM_DETECT_WINDOW = SPINEL_PROP_PHY_EXT__BEGIN + 3, + SPINEL_PROP_JAM_DETECT_WINDOW = SPINEL_PROP_PHY_EXT__BEGIN + 3, /// Jamming detection busy period /** Format: `C` @@ -714,7 +702,7 @@ typedef enum * The behavior of the jamming detection feature when `PROP_JAM_DETECT_BUSY` * is larger than `PROP_JAM_DETECT_WINDOW` is undefined. */ - SPINEL_PROP_JAM_DETECT_BUSY = SPINEL_PROP_PHY_EXT__BEGIN + 4, + SPINEL_PROP_JAM_DETECT_BUSY = SPINEL_PROP_PHY_EXT__BEGIN + 4, /// Jamming detection history bitmap (for debugging) /** Format: `X` (read-only) @@ -727,8 +715,7 @@ typedef enum * high signal level during the corresponding one second interval. * */ - SPINEL_PROP_JAM_DETECT_HISTORY_BITMAP - = SPINEL_PROP_PHY_EXT__BEGIN + 5, + SPINEL_PROP_JAM_DETECT_HISTORY_BITMAP = SPINEL_PROP_PHY_EXT__BEGIN + 5, /// Channel monitoring sample interval /** Format: `L` (read-only) @@ -742,8 +729,7 @@ typedef enum * threshold. * */ - SPINEL_PROP_CHANNEL_MONITOR_SAMPLE_INTERVAL - = SPINEL_PROP_PHY_EXT__BEGIN + 6, + SPINEL_PROP_CHANNEL_MONITOR_SAMPLE_INTERVAL = SPINEL_PROP_PHY_EXT__BEGIN + 6, /// Channel monitoring RSSI threshold /** Format: `c` (read-only) @@ -757,8 +743,7 @@ typedef enum * of samples (sample window). * */ - SPINEL_PROP_CHANNEL_MONITOR_RSSI_THRESHOLD - = SPINEL_PROP_PHY_EXT__BEGIN + 7, + SPINEL_PROP_CHANNEL_MONITOR_RSSI_THRESHOLD = SPINEL_PROP_PHY_EXT__BEGIN + 7, /// Channel monitoring sample window /** Format: `L` (read-only) @@ -773,8 +758,7 @@ typedef enum * the sample window. * */ - SPINEL_PROP_CHANNEL_MONITOR_SAMPLE_WINDOW - = SPINEL_PROP_PHY_EXT__BEGIN + 8, + SPINEL_PROP_CHANNEL_MONITOR_SAMPLE_WINDOW = SPINEL_PROP_PHY_EXT__BEGIN + 8, /// Channel monitoring sample count /** Format: `L` (read-only) @@ -787,8 +771,7 @@ typedef enum * was enabled). * */ - SPINEL_PROP_CHANNEL_MONITOR_SAMPLE_COUNT - = SPINEL_PROP_PHY_EXT__BEGIN + 9, + SPINEL_PROP_CHANNEL_MONITOR_SAMPLE_COUNT = SPINEL_PROP_PHY_EXT__BEGIN + 9, /// Channel monitoring channel occupancy /** Format: `A(t(CU))` (read-only) @@ -808,26 +791,25 @@ typedef enum * threshold (i.e. 100% of samples were "bad"). * */ - SPINEL_PROP_CHANNEL_MONITOR_CHANNEL_OCCUPANCY - = SPINEL_PROP_PHY_EXT__BEGIN + 10, + SPINEL_PROP_CHANNEL_MONITOR_CHANNEL_OCCUPANCY = SPINEL_PROP_PHY_EXT__BEGIN + 10, - SPINEL_PROP_PHY_EXT__END = 0x1300, + SPINEL_PROP_PHY_EXT__END = 0x1300, - SPINEL_PROP_MAC__BEGIN = 0x30, - SPINEL_PROP_MAC_SCAN_STATE = SPINEL_PROP_MAC__BEGIN + 0, ///< [C] - SPINEL_PROP_MAC_SCAN_MASK = SPINEL_PROP_MAC__BEGIN + 1, ///< [A(C)] - SPINEL_PROP_MAC_SCAN_PERIOD = SPINEL_PROP_MAC__BEGIN + 2, ///< ms-per-channel [S] - SPINEL_PROP_MAC_SCAN_BEACON = SPINEL_PROP_MAC__BEGIN + 3, ///< chan,rssi,mac_data,net_data [CcdD] - SPINEL_PROP_MAC_15_4_LADDR = SPINEL_PROP_MAC__BEGIN + 4, ///< [E] - SPINEL_PROP_MAC_15_4_SADDR = SPINEL_PROP_MAC__BEGIN + 5, ///< [S] - SPINEL_PROP_MAC_15_4_PANID = SPINEL_PROP_MAC__BEGIN + 6, ///< [S] - SPINEL_PROP_MAC_RAW_STREAM_ENABLED = SPINEL_PROP_MAC__BEGIN + 7, ///< [C] - SPINEL_PROP_MAC_PROMISCUOUS_MODE = SPINEL_PROP_MAC__BEGIN + 8, ///< [C] - SPINEL_PROP_MAC_ENERGY_SCAN_RESULT = SPINEL_PROP_MAC__BEGIN + 9, ///< chan,maxRssi [Cc] - SPINEL_PROP_MAC_DATA_POLL_PERIOD = SPINEL_PROP_MAC__BEGIN + 10, ///< pollPeriod (in ms) [L] - SPINEL_PROP_MAC__END = 0x40, + SPINEL_PROP_MAC__BEGIN = 0x30, + SPINEL_PROP_MAC_SCAN_STATE = SPINEL_PROP_MAC__BEGIN + 0, ///< [C] + SPINEL_PROP_MAC_SCAN_MASK = SPINEL_PROP_MAC__BEGIN + 1, ///< [A(C)] + SPINEL_PROP_MAC_SCAN_PERIOD = SPINEL_PROP_MAC__BEGIN + 2, ///< ms-per-channel [S] + SPINEL_PROP_MAC_SCAN_BEACON = SPINEL_PROP_MAC__BEGIN + 3, ///< chan,rssi,mac_data,net_data [CcdD] + SPINEL_PROP_MAC_15_4_LADDR = SPINEL_PROP_MAC__BEGIN + 4, ///< [E] + SPINEL_PROP_MAC_15_4_SADDR = SPINEL_PROP_MAC__BEGIN + 5, ///< [S] + SPINEL_PROP_MAC_15_4_PANID = SPINEL_PROP_MAC__BEGIN + 6, ///< [S] + SPINEL_PROP_MAC_RAW_STREAM_ENABLED = SPINEL_PROP_MAC__BEGIN + 7, ///< [C] + SPINEL_PROP_MAC_PROMISCUOUS_MODE = SPINEL_PROP_MAC__BEGIN + 8, ///< [C] + SPINEL_PROP_MAC_ENERGY_SCAN_RESULT = SPINEL_PROP_MAC__BEGIN + 9, ///< chan,maxRssi [Cc] + SPINEL_PROP_MAC_DATA_POLL_PERIOD = SPINEL_PROP_MAC__BEGIN + 10, ///< pollPeriod (in ms) [L] + SPINEL_PROP_MAC__END = 0x40, - SPINEL_PROP_MAC_EXT__BEGIN = 0x1300, + SPINEL_PROP_MAC_EXT__BEGIN = 0x1300, /// MAC Whitelist /** Format: `A(t(Ec))` * @@ -836,36 +818,34 @@ typedef enum * * `E`: EUI64 address of node * * `c`: Optional fixed RSSI. 127 means not set. */ - SPINEL_PROP_MAC_WHITELIST = SPINEL_PROP_MAC_EXT__BEGIN + 0, + SPINEL_PROP_MAC_WHITELIST = SPINEL_PROP_MAC_EXT__BEGIN + 0, /// MAC Whitelist Enabled Flag /** Format: `b` */ - SPINEL_PROP_MAC_WHITELIST_ENABLED = SPINEL_PROP_MAC_EXT__BEGIN + 1, + SPINEL_PROP_MAC_WHITELIST_ENABLED = SPINEL_PROP_MAC_EXT__BEGIN + 1, /// MAC Extended Address /** Format: `E` * * Specified by Thread. Randomly-chosen, but non-volatile EUI-64. */ - SPINEL_PROP_MAC_EXTENDED_ADDR = SPINEL_PROP_MAC_EXT__BEGIN + 2, + SPINEL_PROP_MAC_EXTENDED_ADDR = SPINEL_PROP_MAC_EXT__BEGIN + 2, /// MAC Source Match Enabled Flag /** Format: `b` */ - SPINEL_PROP_MAC_SRC_MATCH_ENABLED = SPINEL_PROP_MAC_EXT__BEGIN + 3, + SPINEL_PROP_MAC_SRC_MATCH_ENABLED = SPINEL_PROP_MAC_EXT__BEGIN + 3, /// MAC Source Match Short Address List /** Format: `A(S)` */ - SPINEL_PROP_MAC_SRC_MATCH_SHORT_ADDRESSES - = SPINEL_PROP_MAC_EXT__BEGIN + 4, + SPINEL_PROP_MAC_SRC_MATCH_SHORT_ADDRESSES = SPINEL_PROP_MAC_EXT__BEGIN + 4, /// MAC Source Match Extended Address List /** Format: `A(E)` */ - SPINEL_PROP_MAC_SRC_MATCH_EXTENDED_ADDRESSES - = SPINEL_PROP_MAC_EXT__BEGIN + 5, + SPINEL_PROP_MAC_SRC_MATCH_EXTENDED_ADDRESSES = SPINEL_PROP_MAC_EXT__BEGIN + 5, /// MAC Blacklist /** Format: `A(t(E))` @@ -874,12 +854,12 @@ typedef enum * * * `E`: EUI64 address of node */ - SPINEL_PROP_MAC_BLACKLIST = SPINEL_PROP_MAC_EXT__BEGIN + 6, + SPINEL_PROP_MAC_BLACKLIST = SPINEL_PROP_MAC_EXT__BEGIN + 6, /// MAC Blacklist Enabled Flag /** Format: `b` */ - SPINEL_PROP_MAC_BLACKLIST_ENABLED = SPINEL_PROP_MAC_EXT__BEGIN + 7, + SPINEL_PROP_MAC_BLACKLIST_ENABLED = SPINEL_PROP_MAC_EXT__BEGIN + 7, /// MAC Received Signal Strength Filter /** Format: `A(t(Ec))` @@ -889,7 +869,7 @@ typedef enum * * `E`: Optional EUI64 address of node. Set default RSS if not included. * * `c`: Fixed RSS. OT_MAC_FILTER_FIXED_RSS_OVERRIDE_DISABLED(127) means not set. */ - SPINEL_PROP_MAC_FIXED_RSS = SPINEL_PROP_MAC_EXT__BEGIN + 8, + SPINEL_PROP_MAC_FIXED_RSS = SPINEL_PROP_MAC_EXT__BEGIN + 8, /// The CCA failure rate /** Format: `S` @@ -899,21 +879,20 @@ typedef enum * Maximum value `0xffff` corresponding to 100% failure rate. * */ - SPINEL_PROP_MAC_CCA_FAILURE_RATE = SPINEL_PROP_MAC_EXT__BEGIN + 9, + SPINEL_PROP_MAC_CCA_FAILURE_RATE = SPINEL_PROP_MAC_EXT__BEGIN + 9, - SPINEL_PROP_MAC_EXT__END = 0x1400, + SPINEL_PROP_MAC_EXT__END = 0x1400, - SPINEL_PROP_NET__BEGIN = 0x40, - SPINEL_PROP_NET_SAVED = SPINEL_PROP_NET__BEGIN + 0, ///< [b] - SPINEL_PROP_NET_IF_UP = SPINEL_PROP_NET__BEGIN + 1, ///< [b] - SPINEL_PROP_NET_STACK_UP = SPINEL_PROP_NET__BEGIN + 2, ///< [b] - SPINEL_PROP_NET_ROLE = SPINEL_PROP_NET__BEGIN + 3, ///< [C] - SPINEL_PROP_NET_NETWORK_NAME = SPINEL_PROP_NET__BEGIN + 4, ///< [U] - SPINEL_PROP_NET_XPANID = SPINEL_PROP_NET__BEGIN + 5, ///< [D] - SPINEL_PROP_NET_MASTER_KEY = SPINEL_PROP_NET__BEGIN + 6, ///< [D] - SPINEL_PROP_NET_KEY_SEQUENCE_COUNTER - = SPINEL_PROP_NET__BEGIN + 7, ///< [L] - SPINEL_PROP_NET_PARTITION_ID = SPINEL_PROP_NET__BEGIN + 8, ///< [L] + SPINEL_PROP_NET__BEGIN = 0x40, + SPINEL_PROP_NET_SAVED = SPINEL_PROP_NET__BEGIN + 0, ///< [b] + SPINEL_PROP_NET_IF_UP = SPINEL_PROP_NET__BEGIN + 1, ///< [b] + SPINEL_PROP_NET_STACK_UP = SPINEL_PROP_NET__BEGIN + 2, ///< [b] + SPINEL_PROP_NET_ROLE = SPINEL_PROP_NET__BEGIN + 3, ///< [C] + SPINEL_PROP_NET_NETWORK_NAME = SPINEL_PROP_NET__BEGIN + 4, ///< [U] + SPINEL_PROP_NET_XPANID = SPINEL_PROP_NET__BEGIN + 5, ///< [D] + SPINEL_PROP_NET_MASTER_KEY = SPINEL_PROP_NET__BEGIN + 6, ///< [D] + SPINEL_PROP_NET_KEY_SEQUENCE_COUNTER = SPINEL_PROP_NET__BEGIN + 7, ///< [L] + SPINEL_PROP_NET_PARTITION_ID = SPINEL_PROP_NET__BEGIN + 8, ///< [L] /// Require Join Existing /** Format: `b` @@ -933,19 +912,17 @@ typedef enum * The behavior of this property being set to `true` when * `PROP_NET_STACK_UP` is already set to `true` is undefined. */ - SPINEL_PROP_NET_REQUIRE_JOIN_EXISTING - = SPINEL_PROP_NET__BEGIN + 9, + SPINEL_PROP_NET_REQUIRE_JOIN_EXISTING = SPINEL_PROP_NET__BEGIN + 9, - SPINEL_PROP_NET_KEY_SWITCH_GUARDTIME - = SPINEL_PROP_NET__BEGIN + 10, ///< [L] + SPINEL_PROP_NET_KEY_SWITCH_GUARDTIME = SPINEL_PROP_NET__BEGIN + 10, ///< [L] - SPINEL_PROP_NET_PSKC = SPINEL_PROP_NET__BEGIN + 11, ///< [D] + SPINEL_PROP_NET_PSKC = SPINEL_PROP_NET__BEGIN + 11, ///< [D] - SPINEL_PROP_NET__END = 0x50, + SPINEL_PROP_NET__END = 0x50, - SPINEL_PROP_THREAD__BEGIN = 0x50, - SPINEL_PROP_THREAD_LEADER_ADDR = SPINEL_PROP_THREAD__BEGIN + 0, ///< [6] - SPINEL_PROP_THREAD_PARENT = SPINEL_PROP_THREAD__BEGIN + 1, ///< LADDR, SADDR [ES] + SPINEL_PROP_THREAD__BEGIN = 0x50, + SPINEL_PROP_THREAD_LEADER_ADDR = SPINEL_PROP_THREAD__BEGIN + 0, ///< [6] + SPINEL_PROP_THREAD_PARENT = SPINEL_PROP_THREAD__BEGIN + 1, ///< LADDR, SADDR [ES] /// Thread Child Table /** Format: [A(t(ESLLCCcCc)] - Read only @@ -963,18 +940,14 @@ typedef enum * `c`: Last RSSI (in dBm) * */ - SPINEL_PROP_THREAD_CHILD_TABLE = SPINEL_PROP_THREAD__BEGIN + 2, - SPINEL_PROP_THREAD_LEADER_RID = SPINEL_PROP_THREAD__BEGIN + 3, ///< [C] - SPINEL_PROP_THREAD_LEADER_WEIGHT = SPINEL_PROP_THREAD__BEGIN + 4, ///< [C] - SPINEL_PROP_THREAD_LOCAL_LEADER_WEIGHT - = SPINEL_PROP_THREAD__BEGIN + 5, ///< [C] - SPINEL_PROP_THREAD_NETWORK_DATA = SPINEL_PROP_THREAD__BEGIN + 6, ///< [D] - SPINEL_PROP_THREAD_NETWORK_DATA_VERSION - = SPINEL_PROP_THREAD__BEGIN + 7, ///< [S] - SPINEL_PROP_THREAD_STABLE_NETWORK_DATA - = SPINEL_PROP_THREAD__BEGIN + 8, ///< [D] - SPINEL_PROP_THREAD_STABLE_NETWORK_DATA_VERSION - = SPINEL_PROP_THREAD__BEGIN + 9, ///< [S] + SPINEL_PROP_THREAD_CHILD_TABLE = SPINEL_PROP_THREAD__BEGIN + 2, + SPINEL_PROP_THREAD_LEADER_RID = SPINEL_PROP_THREAD__BEGIN + 3, ///< [C] + SPINEL_PROP_THREAD_LEADER_WEIGHT = SPINEL_PROP_THREAD__BEGIN + 4, ///< [C] + SPINEL_PROP_THREAD_LOCAL_LEADER_WEIGHT = SPINEL_PROP_THREAD__BEGIN + 5, ///< [C] + SPINEL_PROP_THREAD_NETWORK_DATA = SPINEL_PROP_THREAD__BEGIN + 6, ///< [D] + SPINEL_PROP_THREAD_NETWORK_DATA_VERSION = SPINEL_PROP_THREAD__BEGIN + 7, ///< [S] + SPINEL_PROP_THREAD_STABLE_NETWORK_DATA = SPINEL_PROP_THREAD__BEGIN + 8, ///< [D] + SPINEL_PROP_THREAD_STABLE_NETWORK_DATA_VERSION = SPINEL_PROP_THREAD__BEGIN + 9, ///< [S] /// On-Mesh Prefixes /** Format: `A(t(6CbCbS))` @@ -992,7 +965,7 @@ typedef enum * This value is not used and ignored when adding an on-mesh prefix. * */ - SPINEL_PROP_THREAD_ON_MESH_NETS = SPINEL_PROP_THREAD__BEGIN + 10, + SPINEL_PROP_THREAD_ON_MESH_NETS = SPINEL_PROP_THREAD__BEGIN + 10, /// Off-mesh routes /** Format: [A(t(6CbCbb))] @@ -1015,11 +988,10 @@ typedef enum * This value is not used and ignored when adding a route. * */ - SPINEL_PROP_THREAD_OFF_MESH_ROUTES = SPINEL_PROP_THREAD__BEGIN + 11, + SPINEL_PROP_THREAD_OFF_MESH_ROUTES = SPINEL_PROP_THREAD__BEGIN + 11, - SPINEL_PROP_THREAD_ASSISTING_PORTS = SPINEL_PROP_THREAD__BEGIN + 12, ///< array(portn) [A(S)] - SPINEL_PROP_THREAD_ALLOW_LOCAL_NET_DATA_CHANGE - = SPINEL_PROP_THREAD__BEGIN + 13, ///< [b] + SPINEL_PROP_THREAD_ASSISTING_PORTS = SPINEL_PROP_THREAD__BEGIN + 12, ///< array(portn) [A(S)] + SPINEL_PROP_THREAD_ALLOW_LOCAL_NET_DATA_CHANGE = SPINEL_PROP_THREAD__BEGIN + 13, ///< [b] /// Thread Mode /** Format: `C` @@ -1029,40 +1001,37 @@ typedef enum * bitfield are defined by section 4.5.2 of the Thread * specification. */ - SPINEL_PROP_THREAD_MODE = SPINEL_PROP_THREAD__BEGIN + 14, - SPINEL_PROP_THREAD__END = 0x60, + SPINEL_PROP_THREAD_MODE = SPINEL_PROP_THREAD__BEGIN + 14, + SPINEL_PROP_THREAD__END = 0x60, - SPINEL_PROP_THREAD_EXT__BEGIN = 0x1500, + SPINEL_PROP_THREAD_EXT__BEGIN = 0x1500, /// Thread Child Timeout /** Format: `L` * * Used when operating in the Child role. */ - SPINEL_PROP_THREAD_CHILD_TIMEOUT = SPINEL_PROP_THREAD_EXT__BEGIN + 0, + SPINEL_PROP_THREAD_CHILD_TIMEOUT = SPINEL_PROP_THREAD_EXT__BEGIN + 0, /// Thread RLOC16 /** Format: `S` */ - SPINEL_PROP_THREAD_RLOC16 = SPINEL_PROP_THREAD_EXT__BEGIN + 1, + SPINEL_PROP_THREAD_RLOC16 = SPINEL_PROP_THREAD_EXT__BEGIN + 1, /// Thread Router Upgrade Threshold /** Format: `C` */ - SPINEL_PROP_THREAD_ROUTER_UPGRADE_THRESHOLD - = SPINEL_PROP_THREAD_EXT__BEGIN + 2, + SPINEL_PROP_THREAD_ROUTER_UPGRADE_THRESHOLD = SPINEL_PROP_THREAD_EXT__BEGIN + 2, /// Thread Context Reuse Delay /** Format: `L` */ - SPINEL_PROP_THREAD_CONTEXT_REUSE_DELAY - = SPINEL_PROP_THREAD_EXT__BEGIN + 3, + SPINEL_PROP_THREAD_CONTEXT_REUSE_DELAY = SPINEL_PROP_THREAD_EXT__BEGIN + 3, /// Thread Network ID Timeout /** Format: `C` */ - SPINEL_PROP_THREAD_NETWORK_ID_TIMEOUT - = SPINEL_PROP_THREAD_EXT__BEGIN + 4, + SPINEL_PROP_THREAD_NETWORK_ID_TIMEOUT = SPINEL_PROP_THREAD_EXT__BEGIN + 4, /// List of active thread router ids /** Format: `A(C)` @@ -1071,38 +1040,32 @@ typedef enum * routerids, but may support CMD_REMOVE_VALUE when the node is * a leader. */ - SPINEL_PROP_THREAD_ACTIVE_ROUTER_IDS - = SPINEL_PROP_THREAD_EXT__BEGIN + 5, + SPINEL_PROP_THREAD_ACTIVE_ROUTER_IDS = SPINEL_PROP_THREAD_EXT__BEGIN + 5, /// Forward IPv6 packets that use RLOC16 addresses to HOST. /** Format: `b` */ - SPINEL_PROP_THREAD_RLOC16_DEBUG_PASSTHRU - = SPINEL_PROP_THREAD_EXT__BEGIN + 6, + SPINEL_PROP_THREAD_RLOC16_DEBUG_PASSTHRU = SPINEL_PROP_THREAD_EXT__BEGIN + 6, /// This property indicates whether or not the `Router Role` is enabled. /** Format `b` */ - SPINEL_PROP_THREAD_ROUTER_ROLE_ENABLED - = SPINEL_PROP_THREAD_EXT__BEGIN + 7, + SPINEL_PROP_THREAD_ROUTER_ROLE_ENABLED = SPINEL_PROP_THREAD_EXT__BEGIN + 7, /// Thread Router Downgrade Threshold /** Format: `C` */ - SPINEL_PROP_THREAD_ROUTER_DOWNGRADE_THRESHOLD - = SPINEL_PROP_THREAD_EXT__BEGIN + 8, + SPINEL_PROP_THREAD_ROUTER_DOWNGRADE_THRESHOLD = SPINEL_PROP_THREAD_EXT__BEGIN + 8, /// Thread Router Selection Jitter /** Format: `C` */ - SPINEL_PROP_THREAD_ROUTER_SELECTION_JITTER - = SPINEL_PROP_THREAD_EXT__BEGIN + 9, + SPINEL_PROP_THREAD_ROUTER_SELECTION_JITTER = SPINEL_PROP_THREAD_EXT__BEGIN + 9, /// Thread Preferred Router Id /** Format: `C` - Write only */ - SPINEL_PROP_THREAD_PREFERRED_ROUTER_ID - = SPINEL_PROP_THREAD_EXT__BEGIN + 10, + SPINEL_PROP_THREAD_PREFERRED_ROUTER_ID = SPINEL_PROP_THREAD_EXT__BEGIN + 10, /// Thread Neighbor Table /** Format: `A(t(ESLCcCbLLc))` - Read only @@ -1121,46 +1084,42 @@ typedef enum * `c`: The last RSSI (in dBm) * */ - SPINEL_PROP_THREAD_NEIGHBOR_TABLE = SPINEL_PROP_THREAD_EXT__BEGIN + 11, + SPINEL_PROP_THREAD_NEIGHBOR_TABLE = SPINEL_PROP_THREAD_EXT__BEGIN + 11, /// Thread Max Child Count /** Format: `C` */ - SPINEL_PROP_THREAD_CHILD_COUNT_MAX = SPINEL_PROP_THREAD_EXT__BEGIN + 12, + SPINEL_PROP_THREAD_CHILD_COUNT_MAX = SPINEL_PROP_THREAD_EXT__BEGIN + 12, /// Leader network data /** Format: `D` - Read only */ - SPINEL_PROP_THREAD_LEADER_NETWORK_DATA - = SPINEL_PROP_THREAD_EXT__BEGIN + 13, + SPINEL_PROP_THREAD_LEADER_NETWORK_DATA = SPINEL_PROP_THREAD_EXT__BEGIN + 13, /// Stable leader network data /** Format: `D` - Read only */ - SPINEL_PROP_THREAD_STABLE_LEADER_NETWORK_DATA - = SPINEL_PROP_THREAD_EXT__BEGIN + 14, + SPINEL_PROP_THREAD_STABLE_LEADER_NETWORK_DATA = SPINEL_PROP_THREAD_EXT__BEGIN + 14, /// Thread joiner data /** Format `A(T(ULE))` - * PSKd, joiner timeout, eui64 (optional) - */ - SPINEL_PROP_THREAD_JOINERS = SPINEL_PROP_THREAD_EXT__BEGIN + 15, + * PSKd, joiner timeout, eui64 (optional) + */ + SPINEL_PROP_THREAD_JOINERS = SPINEL_PROP_THREAD_EXT__BEGIN + 15, /// Thread commissioner enable /** Format `b` * * Default value is `false`. */ - SPINEL_PROP_THREAD_COMMISSIONER_ENABLED - = SPINEL_PROP_THREAD_EXT__BEGIN + 16, + SPINEL_PROP_THREAD_COMMISSIONER_ENABLED = SPINEL_PROP_THREAD_EXT__BEGIN + 16, /// Thread TMF proxy enable /** Format `b` * * Default value is `false`. */ - SPINEL_PROP_THREAD_TMF_PROXY_ENABLED - = SPINEL_PROP_THREAD_EXT__BEGIN + 17, + SPINEL_PROP_THREAD_TMF_PROXY_ENABLED = SPINEL_PROP_THREAD_EXT__BEGIN + 17, /// Thread TMF proxy stream /** Format `dSS` @@ -1174,16 +1133,14 @@ typedef enum * * Default value is `false`. */ - SPINEL_PROP_THREAD_DISCOVERY_SCAN_JOINER_FLAG - = SPINEL_PROP_THREAD_EXT__BEGIN + 19, + SPINEL_PROP_THREAD_DISCOVERY_SCAN_JOINER_FLAG = SPINEL_PROP_THREAD_EXT__BEGIN + 19, /// Enable EUI64 filtering for discovery scan operation. /** Format `b` * * Default value is `false` */ - SPINEL_PROP_THREAD_DISCOVERY_SCAN_ENABLE_FILTERING - = SPINEL_PROP_THREAD_EXT__BEGIN + 20, + SPINEL_PROP_THREAD_DISCOVERY_SCAN_ENABLE_FILTERING = SPINEL_PROP_THREAD_EXT__BEGIN + 20, /// PANID used for Discovery scan operation (used for PANID filtering). /** Format: `S` @@ -1191,8 +1148,7 @@ typedef enum * Default value is 0xffff (Broadcast PAN) to disable PANID filtering * */ - SPINEL_PROP_THREAD_DISCOVERY_SCAN_PANID - = SPINEL_PROP_THREAD_EXT__BEGIN + 21, + SPINEL_PROP_THREAD_DISCOVERY_SCAN_PANID = SPINEL_PROP_THREAD_EXT__BEGIN + 21, /// Thread (out of band) steering data for MLE Discovery Response. /** Format `E` - Write only @@ -1206,7 +1162,7 @@ typedef enum * - A specific EUI64 which is then added to current steering data/bloom filter. * */ - SPINEL_PROP_THREAD_STEERING_DATA = SPINEL_PROP_THREAD_EXT__BEGIN + 22, + SPINEL_PROP_THREAD_STEERING_DATA = SPINEL_PROP_THREAD_EXT__BEGIN + 22, /// Thread Router Table. /** Format: `A(t(ESCCCCCCb)` - Read only @@ -1224,7 +1180,7 @@ typedef enum * `b`: Link established with Router ID or not. * */ - SPINEL_PROP_THREAD_ROUTER_TABLE = SPINEL_PROP_THREAD_EXT__BEGIN + 23, + SPINEL_PROP_THREAD_ROUTER_TABLE = SPINEL_PROP_THREAD_EXT__BEGIN + 23, /// Thread Active Operational Dataset /** Format: `A(t(iD))` - Read-Write @@ -1255,7 +1211,7 @@ typedef enum * SPINEL_PROP_DATASET_SECURITY_POLICY * */ - SPINEL_PROP_THREAD_ACTIVE_DATASET = SPINEL_PROP_THREAD_EXT__BEGIN + 24, + SPINEL_PROP_THREAD_ACTIVE_DATASET = SPINEL_PROP_THREAD_EXT__BEGIN + 24, /// Thread Pending Operational Dataset /** Format: `A(t(iD))` - Read-Write @@ -1271,7 +1227,7 @@ typedef enum * SPINEL_PROP_DATASET_DELAY_TIMER * */ - SPINEL_PROP_THREAD_PENDING_DATASET = SPINEL_PROP_THREAD_EXT__BEGIN + 25, + SPINEL_PROP_THREAD_PENDING_DATASET = SPINEL_PROP_THREAD_EXT__BEGIN + 25, /// Thread Active Operational Dataset (MGMT send) /** Format: `A(t(iD))` - Write only @@ -1288,8 +1244,7 @@ typedef enum * SPINEL_PROP_DATASET_RAW_TLVS * */ - SPINEL_PROP_THREAD_MGMT_ACTIVE_DATASET - = SPINEL_PROP_THREAD_EXT__BEGIN + 26, + SPINEL_PROP_THREAD_MGMT_ACTIVE_DATASET = SPINEL_PROP_THREAD_EXT__BEGIN + 26, /// Thread Pending Operational Dataset (MGMT send) /** Format: `A(t(iD))` - Write only @@ -1302,8 +1257,7 @@ typedef enum * SPINEL_PROP_DATASET_RAW_TLVS * */ - SPINEL_PROP_THREAD_MGMT_PENDING_DATASET - = SPINEL_PROP_THREAD_EXT__BEGIN + 27, + SPINEL_PROP_THREAD_MGMT_PENDING_DATASET = SPINEL_PROP_THREAD_EXT__BEGIN + 27, /// Operational Dataset Active Timestamp /** Format: `X` - No direct read or write @@ -1316,8 +1270,7 @@ typedef enum * SPINEL_PROP_THREAD_MGMT_PENDING_DATASET * */ - SPINEL_PROP_DATASET_ACTIVE_TIMESTAMP - = SPINEL_PROP_THREAD_EXT__BEGIN + 28, + SPINEL_PROP_DATASET_ACTIVE_TIMESTAMP = SPINEL_PROP_THREAD_EXT__BEGIN + 28, /// Operational Dataset Pending Timestamp /** Format: `X` - No direct read or write @@ -1328,8 +1281,7 @@ typedef enum * SPINEL_PROP_THREAD_MGMT_PENDING_DATASET * */ - SPINEL_PROP_DATASET_PENDING_TIMESTAMP - = SPINEL_PROP_THREAD_EXT__BEGIN + 29, + SPINEL_PROP_DATASET_PENDING_TIMESTAMP = SPINEL_PROP_THREAD_EXT__BEGIN + 29, /// Operational Dataset Delay Timer /** Format: `L` - No direct read or write @@ -1343,7 +1295,7 @@ typedef enum * SPINEL_PROP_THREAD_MGMT_PENDING_DATASET * */ - SPINEL_PROP_DATASET_DELAY_TIMER = SPINEL_PROP_THREAD_EXT__BEGIN + 30, + SPINEL_PROP_DATASET_DELAY_TIMER = SPINEL_PROP_THREAD_EXT__BEGIN + 30, /// Operational Dataset Security Policy /** Format: `SC` - No direct read or write @@ -1373,7 +1325,7 @@ typedef enum * SPINEL_PROP_THREAD_MGMT_PENDING_DATASET * */ - SPINEL_PROP_DATASET_RAW_TLVS = SPINEL_PROP_THREAD_EXT__BEGIN + 32, + SPINEL_PROP_DATASET_RAW_TLVS = SPINEL_PROP_THREAD_EXT__BEGIN + 32, /// Child table addresses /** Format: `A(t(ESA(6)))` - Read only @@ -1388,8 +1340,7 @@ typedef enum * `A(6)`: List of IPv6 addresses registered by the child (if any) * */ - SPINEL_PROP_THREAD_CHILD_TABLE_ADDRESSES - = SPINEL_PROP_THREAD_EXT__BEGIN + 33, + SPINEL_PROP_THREAD_CHILD_TABLE_ADDRESSES = SPINEL_PROP_THREAD_EXT__BEGIN + 33, /// Neighbor Table Frame and Message Error Rates /** Format: `A(t(ESSScc))` @@ -1413,8 +1364,7 @@ typedef enum * `c`: Last RSSI (in dBm) * */ - SPINEL_PROP_THREAD_NEIGHBOR_TABLE_ERROR_RATES - = SPINEL_PROP_THREAD_EXT__BEGIN + 34, + SPINEL_PROP_THREAD_NEIGHBOR_TABLE_ERROR_RATES = SPINEL_PROP_THREAD_EXT__BEGIN + 34, /// EID (Endpoint Identifier) IPv6 Address Cache Table /** Format `A(t(6SC))` @@ -1428,15 +1378,14 @@ typedef enum * `C` : Age (order of use, 0 indicates most recently used entry) * */ - SPINEL_PROP_THREAD_ADDRESS_CACHE_TABLE - = SPINEL_PROP_THREAD_EXT__BEGIN + 35, + SPINEL_PROP_THREAD_ADDRESS_CACHE_TABLE = SPINEL_PROP_THREAD_EXT__BEGIN + 35, - SPINEL_PROP_THREAD_EXT__END = 0x1600, + SPINEL_PROP_THREAD_EXT__END = 0x1600, - SPINEL_PROP_IPV6__BEGIN = 0x60, - SPINEL_PROP_IPV6_LL_ADDR = SPINEL_PROP_IPV6__BEGIN + 0, ///< [6] - SPINEL_PROP_IPV6_ML_ADDR = SPINEL_PROP_IPV6__BEGIN + 1, ///< [6C] - SPINEL_PROP_IPV6_ML_PREFIX = SPINEL_PROP_IPV6__BEGIN + 2, ///< [6C] + SPINEL_PROP_IPV6__BEGIN = 0x60, + SPINEL_PROP_IPV6_LL_ADDR = SPINEL_PROP_IPV6__BEGIN + 0, ///< [6] + SPINEL_PROP_IPV6_ML_ADDR = SPINEL_PROP_IPV6__BEGIN + 1, ///< [6C] + SPINEL_PROP_IPV6_ML_PREFIX = SPINEL_PROP_IPV6__BEGIN + 2, ///< [6C] /// IPv6 Address Table /** Format: `A(t(6CLLC))` @@ -1452,9 +1401,10 @@ typedef enum * `C`: Flags * */ - SPINEL_PROP_IPV6_ADDRESS_TABLE = SPINEL_PROP_IPV6__BEGIN + 3, + SPINEL_PROP_IPV6_ADDRESS_TABLE = SPINEL_PROP_IPV6__BEGIN + 3, - SPINEL_PROP_IPV6_ROUTE_TABLE = SPINEL_PROP_IPV6__BEGIN + 4, ///< array(ipv6prefix,prefixlen,iface,flags) [A(t(6CCC))] + SPINEL_PROP_IPV6_ROUTE_TABLE = + SPINEL_PROP_IPV6__BEGIN + 4, ///< array(ipv6prefix,prefixlen,iface,flags) [A(t(6CCC))] /// IPv6 ICMP Ping Offload /** Format: `b` @@ -1464,10 +1414,9 @@ typedef enum * * Default value is `false`. */ - SPINEL_PROP_IPV6_ICMP_PING_OFFLOAD = SPINEL_PROP_IPV6__BEGIN + 5, ///< [b] + SPINEL_PROP_IPV6_ICMP_PING_OFFLOAD = SPINEL_PROP_IPV6__BEGIN + 5, ///< [b] - SPINEL_PROP_IPV6_MULTICAST_ADDRESS_TABLE - = SPINEL_PROP_IPV6__BEGIN + 6, ///< [A(t(6))] + SPINEL_PROP_IPV6_MULTICAST_ADDRESS_TABLE = SPINEL_PROP_IPV6__BEGIN + 6, ///< [A(t(6))] /// IPv6 ICMP Ping Offload /** Format: `C` @@ -1480,16 +1429,15 @@ typedef enum * * Default value is `NET_IPV6_ICMP_PING_OFFLOAD_DISABLED`. */ - SPINEL_PROP_IPV6_ICMP_PING_OFFLOAD_MODE - = SPINEL_PROP_IPV6__BEGIN + 7, ///< [b] + SPINEL_PROP_IPV6_ICMP_PING_OFFLOAD_MODE = SPINEL_PROP_IPV6__BEGIN + 7, ///< [b] - SPINEL_PROP_IPV6__END = 0x70, + SPINEL_PROP_IPV6__END = 0x70, - SPINEL_PROP_STREAM__BEGIN = 0x70, - SPINEL_PROP_STREAM_DEBUG = SPINEL_PROP_STREAM__BEGIN + 0, ///< [U] - SPINEL_PROP_STREAM_RAW = SPINEL_PROP_STREAM__BEGIN + 1, ///< [dD] - SPINEL_PROP_STREAM_NET = SPINEL_PROP_STREAM__BEGIN + 2, ///< [dD] - SPINEL_PROP_STREAM_NET_INSECURE = SPINEL_PROP_STREAM__BEGIN + 3, ///< [dD] + SPINEL_PROP_STREAM__BEGIN = 0x70, + SPINEL_PROP_STREAM_DEBUG = SPINEL_PROP_STREAM__BEGIN + 0, ///< [U] + SPINEL_PROP_STREAM_RAW = SPINEL_PROP_STREAM__BEGIN + 1, ///< [dD] + SPINEL_PROP_STREAM_NET = SPINEL_PROP_STREAM__BEGIN + 2, ///< [dD] + SPINEL_PROP_STREAM_NET_INSECURE = SPINEL_PROP_STREAM__BEGIN + 3, ///< [dD] /// Log Stream /** Format: `UD` (stream, read only) @@ -1513,10 +1461,10 @@ typedef enum * `SPINEL_NCP_LOG_REGION_). * */ - SPINEL_PROP_STREAM_LOG = SPINEL_PROP_STREAM__BEGIN + 4, - SPINEL_PROP_STREAM__END = 0x80, + SPINEL_PROP_STREAM_LOG = SPINEL_PROP_STREAM__BEGIN + 4, + SPINEL_PROP_STREAM__END = 0x80, - SPINEL_PROP_OPENTHREAD__BEGIN = 0x1900, + SPINEL_PROP_OPENTHREAD__BEGIN = 0x1900, /// Channel Manager - Channel Change New Channel /** Format: `C` (read-write) @@ -1531,8 +1479,7 @@ typedef enum * (previously requested) channel change. * */ - SPINEL_PROP_CHANNEL_MANAGER_NEW_CHANNEL - = SPINEL_PROP_OPENTHREAD__BEGIN + 0, + SPINEL_PROP_CHANNEL_MANAGER_NEW_CHANNEL = SPINEL_PROP_OPENTHREAD__BEGIN + 0, /// Channel Manager - Channel Change Delay /** Format 'S' @@ -1548,7 +1495,7 @@ typedef enum * network. * */ - SPINEL_PROP_CHANNEL_MANAGER_DELAY = SPINEL_PROP_OPENTHREAD__BEGIN + 1, + SPINEL_PROP_CHANNEL_MANAGER_DELAY = SPINEL_PROP_OPENTHREAD__BEGIN + 1, /// Channel Manager Supported Channels /** Format 'A(C)' @@ -1558,8 +1505,7 @@ typedef enum * This property specifies the list of supported channels. * */ - SPINEL_PROP_CHANNEL_MANAGER_SUPPORTED_CHANNELS - = SPINEL_PROP_OPENTHREAD__BEGIN + 2, + SPINEL_PROP_CHANNEL_MANAGER_SUPPORTED_CHANNELS = SPINEL_PROP_OPENTHREAD__BEGIN + 2, /// Channel Manager Favored Channels /** Format 'A(C)' @@ -1569,8 +1515,7 @@ typedef enum * This property specifies the list of favored channels (when `ChannelManager` is asked to select channel) * */ - SPINEL_PROP_CHANNEL_MANAGER_FAVORED_CHANNELS - = SPINEL_PROP_OPENTHREAD__BEGIN + 3, + SPINEL_PROP_CHANNEL_MANAGER_FAVORED_CHANNELS = SPINEL_PROP_OPENTHREAD__BEGIN + 3, /// Channel Manager Channel Select Trigger /** Format 'b' @@ -1596,8 +1541,7 @@ typedef enum * Reading this property always yields `false`. * */ - SPINEL_PROP_CHANNEL_MANAGER_CHANNEL_SELECT - = SPINEL_PROP_OPENTHREAD__BEGIN + 4, + SPINEL_PROP_CHANNEL_MANAGER_CHANNEL_SELECT = SPINEL_PROP_OPENTHREAD__BEGIN + 4, /// Channel Manager Auto Channel Selection Enabled /** Format 'b' @@ -1610,8 +1554,7 @@ typedef enum * is specified by `SPINEL_PROP_CHANNEL_MANAGER_AUTO_SELECT_INTERVAL`. * */ - SPINEL_PROP_CHANNEL_MANAGER_AUTO_SELECT_ENABLED - = SPINEL_PROP_OPENTHREAD__BEGIN + 5, + SPINEL_PROP_CHANNEL_MANAGER_AUTO_SELECT_ENABLED = SPINEL_PROP_OPENTHREAD__BEGIN + 5, /// Channel Manager Auto Channel Selection Interval /** Format 'L' @@ -1622,10 +1565,9 @@ typedef enum * This property specifies the auto-channel-selection check interval (in seconds). * */ - SPINEL_PROP_CHANNEL_MANAGER_AUTO_SELECT_INTERVAL - = SPINEL_PROP_OPENTHREAD__BEGIN + 6, + SPINEL_PROP_CHANNEL_MANAGER_AUTO_SELECT_INTERVAL = SPINEL_PROP_OPENTHREAD__BEGIN + 6, - SPINEL_PROP_OPENTHREAD__END = 0x2000, + SPINEL_PROP_OPENTHREAD__END = 0x2000, /// UART Bitrate /** Format: `L` @@ -1649,7 +1591,7 @@ typedef enum * the host, all further frames will be transmitted at the new * bitrate. */ - SPINEL_PROP_UART_BITRATE = 0x100, + SPINEL_PROP_UART_BITRATE = 0x100, /// UART Software Flow Control /** Format: `b` @@ -1662,9 +1604,9 @@ typedef enum * This property is only implemented when a UART is being * used for Spinel. This property is optional. */ - SPINEL_PROP_UART_XON_XOFF = 0x101, + SPINEL_PROP_UART_XON_XOFF = 0x101, - SPINEL_PROP_15_4_PIB__BEGIN = 1024, + SPINEL_PROP_15_4_PIB__BEGIN = 1024, // For direct access to the 802.15.4 PID. // Individual registers are fetched using // `SPINEL_PROP_15_4_PIB__BEGIN+[PIB_IDENTIFIER]` @@ -1673,202 +1615,198 @@ typedef enum // For brevity, the entire 802.15.4 PIB space is // not defined here, but a few choice attributes // are defined for illustration and convenience. - SPINEL_PROP_15_4_PIB_PHY_CHANNELS_SUPPORTED - = SPINEL_PROP_15_4_PIB__BEGIN + 0x01, ///< [A(L)] - SPINEL_PROP_15_4_PIB_MAC_PROMISCUOUS_MODE - = SPINEL_PROP_15_4_PIB__BEGIN + 0x51, ///< [b] - SPINEL_PROP_15_4_PIB_MAC_SECURITY_ENABLED - = SPINEL_PROP_15_4_PIB__BEGIN + 0x5d, ///< [b] - SPINEL_PROP_15_4_PIB__END = 1280, + SPINEL_PROP_15_4_PIB_PHY_CHANNELS_SUPPORTED = SPINEL_PROP_15_4_PIB__BEGIN + 0x01, ///< [A(L)] + SPINEL_PROP_15_4_PIB_MAC_PROMISCUOUS_MODE = SPINEL_PROP_15_4_PIB__BEGIN + 0x51, ///< [b] + SPINEL_PROP_15_4_PIB_MAC_SECURITY_ENABLED = SPINEL_PROP_15_4_PIB__BEGIN + 0x5d, ///< [b] + SPINEL_PROP_15_4_PIB__END = 1280, - SPINEL_PROP_CNTR__BEGIN = 1280, + SPINEL_PROP_CNTR__BEGIN = 1280, /// Counter reset behavior /** Format: `C` * Writing a '1' to this property will reset * all of the counters to zero. */ - SPINEL_PROP_CNTR_RESET = SPINEL_PROP_CNTR__BEGIN + 0, + SPINEL_PROP_CNTR_RESET = SPINEL_PROP_CNTR__BEGIN + 0, /// The total number of transmissions. /** Format: `L` (Read-only) */ - SPINEL_PROP_CNTR_TX_PKT_TOTAL = SPINEL_PROP_CNTR__BEGIN + 1, + SPINEL_PROP_CNTR_TX_PKT_TOTAL = SPINEL_PROP_CNTR__BEGIN + 1, /// The number of transmissions with ack request. /** Format: `L` (Read-only) */ - SPINEL_PROP_CNTR_TX_PKT_ACK_REQ = SPINEL_PROP_CNTR__BEGIN + 2, + SPINEL_PROP_CNTR_TX_PKT_ACK_REQ = SPINEL_PROP_CNTR__BEGIN + 2, /// The number of transmissions that were acked. /** Format: `L` (Read-only) */ - SPINEL_PROP_CNTR_TX_PKT_ACKED = SPINEL_PROP_CNTR__BEGIN + 3, + SPINEL_PROP_CNTR_TX_PKT_ACKED = SPINEL_PROP_CNTR__BEGIN + 3, /// The number of transmissions without ack request. /** Format: `L` (Read-only) */ - SPINEL_PROP_CNTR_TX_PKT_NO_ACK_REQ = SPINEL_PROP_CNTR__BEGIN + 4, + SPINEL_PROP_CNTR_TX_PKT_NO_ACK_REQ = SPINEL_PROP_CNTR__BEGIN + 4, /// The number of transmitted data. /** Format: `L` (Read-only) */ - SPINEL_PROP_CNTR_TX_PKT_DATA = SPINEL_PROP_CNTR__BEGIN + 5, + SPINEL_PROP_CNTR_TX_PKT_DATA = SPINEL_PROP_CNTR__BEGIN + 5, /// The number of transmitted data poll. /** Format: `L` (Read-only) */ - SPINEL_PROP_CNTR_TX_PKT_DATA_POLL = SPINEL_PROP_CNTR__BEGIN + 6, + SPINEL_PROP_CNTR_TX_PKT_DATA_POLL = SPINEL_PROP_CNTR__BEGIN + 6, /// The number of transmitted beacon. /** Format: `L` (Read-only) */ - SPINEL_PROP_CNTR_TX_PKT_BEACON = SPINEL_PROP_CNTR__BEGIN + 7, + SPINEL_PROP_CNTR_TX_PKT_BEACON = SPINEL_PROP_CNTR__BEGIN + 7, /// The number of transmitted beacon request. /** Format: `L` (Read-only) */ - SPINEL_PROP_CNTR_TX_PKT_BEACON_REQ = SPINEL_PROP_CNTR__BEGIN + 8, + SPINEL_PROP_CNTR_TX_PKT_BEACON_REQ = SPINEL_PROP_CNTR__BEGIN + 8, /// The number of transmitted other types of frames. /** Format: `L` (Read-only) */ - SPINEL_PROP_CNTR_TX_PKT_OTHER = SPINEL_PROP_CNTR__BEGIN + 9, + SPINEL_PROP_CNTR_TX_PKT_OTHER = SPINEL_PROP_CNTR__BEGIN + 9, /// The number of retransmission times. /** Format: `L` (Read-only) */ - SPINEL_PROP_CNTR_TX_PKT_RETRY = SPINEL_PROP_CNTR__BEGIN + 10, + SPINEL_PROP_CNTR_TX_PKT_RETRY = SPINEL_PROP_CNTR__BEGIN + 10, /// The number of CCA failure times. /** Format: `L` (Read-only) */ - SPINEL_PROP_CNTR_TX_ERR_CCA = SPINEL_PROP_CNTR__BEGIN + 11, + SPINEL_PROP_CNTR_TX_ERR_CCA = SPINEL_PROP_CNTR__BEGIN + 11, /// The number of unicast packets transmitted. /** Format: `L` (Read-only) */ - SPINEL_PROP_CNTR_TX_PKT_UNICAST = SPINEL_PROP_CNTR__BEGIN + 12, + SPINEL_PROP_CNTR_TX_PKT_UNICAST = SPINEL_PROP_CNTR__BEGIN + 12, /// The number of broadcast packets transmitted. /** Format: `L` (Read-only) */ - SPINEL_PROP_CNTR_TX_PKT_BROADCAST = SPINEL_PROP_CNTR__BEGIN + 13, + SPINEL_PROP_CNTR_TX_PKT_BROADCAST = SPINEL_PROP_CNTR__BEGIN + 13, /// The number of frame transmission failures due to abort error. /** Format: `L` (Read-only) */ - SPINEL_PROP_CNTR_TX_ERR_ABORT = SPINEL_PROP_CNTR__BEGIN + 14, + SPINEL_PROP_CNTR_TX_ERR_ABORT = SPINEL_PROP_CNTR__BEGIN + 14, /// The total number of received packets. /** Format: `L` (Read-only) */ - SPINEL_PROP_CNTR_RX_PKT_TOTAL = SPINEL_PROP_CNTR__BEGIN + 100, + SPINEL_PROP_CNTR_RX_PKT_TOTAL = SPINEL_PROP_CNTR__BEGIN + 100, /// The number of received data. /** Format: `L` (Read-only) */ - SPINEL_PROP_CNTR_RX_PKT_DATA = SPINEL_PROP_CNTR__BEGIN + 101, + SPINEL_PROP_CNTR_RX_PKT_DATA = SPINEL_PROP_CNTR__BEGIN + 101, /// The number of received data poll. /** Format: `L` (Read-only) */ - SPINEL_PROP_CNTR_RX_PKT_DATA_POLL = SPINEL_PROP_CNTR__BEGIN + 102, + SPINEL_PROP_CNTR_RX_PKT_DATA_POLL = SPINEL_PROP_CNTR__BEGIN + 102, /// The number of received beacon. /** Format: `L` (Read-only) */ - SPINEL_PROP_CNTR_RX_PKT_BEACON = SPINEL_PROP_CNTR__BEGIN + 103, + SPINEL_PROP_CNTR_RX_PKT_BEACON = SPINEL_PROP_CNTR__BEGIN + 103, /// The number of received beacon request. /** Format: `L` (Read-only) */ - SPINEL_PROP_CNTR_RX_PKT_BEACON_REQ = SPINEL_PROP_CNTR__BEGIN + 104, + SPINEL_PROP_CNTR_RX_PKT_BEACON_REQ = SPINEL_PROP_CNTR__BEGIN + 104, /// The number of received other types of frames. /** Format: `L` (Read-only) */ - SPINEL_PROP_CNTR_RX_PKT_OTHER = SPINEL_PROP_CNTR__BEGIN + 105, + SPINEL_PROP_CNTR_RX_PKT_OTHER = SPINEL_PROP_CNTR__BEGIN + 105, /// The number of received packets filtered by whitelist. /** Format: `L` (Read-only) */ - SPINEL_PROP_CNTR_RX_PKT_FILT_WL = SPINEL_PROP_CNTR__BEGIN + 106, + SPINEL_PROP_CNTR_RX_PKT_FILT_WL = SPINEL_PROP_CNTR__BEGIN + 106, /// The number of received packets filtered by destination check. /** Format: `L` (Read-only) */ - SPINEL_PROP_CNTR_RX_PKT_FILT_DA = SPINEL_PROP_CNTR__BEGIN + 107, + SPINEL_PROP_CNTR_RX_PKT_FILT_DA = SPINEL_PROP_CNTR__BEGIN + 107, /// The number of received packets that are empty. /** Format: `L` (Read-only) */ - SPINEL_PROP_CNTR_RX_ERR_EMPTY = SPINEL_PROP_CNTR__BEGIN + 108, + SPINEL_PROP_CNTR_RX_ERR_EMPTY = SPINEL_PROP_CNTR__BEGIN + 108, /// The number of received packets from an unknown neighbor. /** Format: `L` (Read-only) */ - SPINEL_PROP_CNTR_RX_ERR_UKWN_NBR = SPINEL_PROP_CNTR__BEGIN + 109, + SPINEL_PROP_CNTR_RX_ERR_UKWN_NBR = SPINEL_PROP_CNTR__BEGIN + 109, /// The number of received packets whose source address is invalid. /** Format: `L` (Read-only) */ - SPINEL_PROP_CNTR_RX_ERR_NVLD_SADDR = SPINEL_PROP_CNTR__BEGIN + 110, + SPINEL_PROP_CNTR_RX_ERR_NVLD_SADDR = SPINEL_PROP_CNTR__BEGIN + 110, /// The number of received packets with a security error. /** Format: `L` (Read-only) */ - SPINEL_PROP_CNTR_RX_ERR_SECURITY = SPINEL_PROP_CNTR__BEGIN + 111, + SPINEL_PROP_CNTR_RX_ERR_SECURITY = SPINEL_PROP_CNTR__BEGIN + 111, /// The number of received packets with a checksum error. /** Format: `L` (Read-only) */ - SPINEL_PROP_CNTR_RX_ERR_BAD_FCS = SPINEL_PROP_CNTR__BEGIN + 112, + SPINEL_PROP_CNTR_RX_ERR_BAD_FCS = SPINEL_PROP_CNTR__BEGIN + 112, /// The number of received packets with other errors. /** Format: `L` (Read-only) */ - SPINEL_PROP_CNTR_RX_ERR_OTHER = SPINEL_PROP_CNTR__BEGIN + 113, + SPINEL_PROP_CNTR_RX_ERR_OTHER = SPINEL_PROP_CNTR__BEGIN + 113, /// The number of received duplicated. /** Format: `L` (Read-only) */ - SPINEL_PROP_CNTR_RX_PKT_DUP = SPINEL_PROP_CNTR__BEGIN + 114, + SPINEL_PROP_CNTR_RX_PKT_DUP = SPINEL_PROP_CNTR__BEGIN + 114, /// The number of unicast packets received. /** Format: `L` (Read-only) */ - SPINEL_PROP_CNTR_RX_PKT_UNICAST = SPINEL_PROP_CNTR__BEGIN + 115, + SPINEL_PROP_CNTR_RX_PKT_UNICAST = SPINEL_PROP_CNTR__BEGIN + 115, /// The number of broadcast packets received. /** Format: `L` (Read-only) */ - SPINEL_PROP_CNTR_RX_PKT_BROADCAST = SPINEL_PROP_CNTR__BEGIN + 116, + SPINEL_PROP_CNTR_RX_PKT_BROADCAST = SPINEL_PROP_CNTR__BEGIN + 116, /// The total number of secure transmitted IP messages. /** Format: `L` (Read-only) */ - SPINEL_PROP_CNTR_TX_IP_SEC_TOTAL = SPINEL_PROP_CNTR__BEGIN + 200, + SPINEL_PROP_CNTR_TX_IP_SEC_TOTAL = SPINEL_PROP_CNTR__BEGIN + 200, /// The total number of insecure transmitted IP messages. /** Format: `L` (Read-only) */ - SPINEL_PROP_CNTR_TX_IP_INSEC_TOTAL = SPINEL_PROP_CNTR__BEGIN + 201, + SPINEL_PROP_CNTR_TX_IP_INSEC_TOTAL = SPINEL_PROP_CNTR__BEGIN + 201, /// The number of dropped (not transmitted) IP messages. /** Format: `L` (Read-only) */ - SPINEL_PROP_CNTR_TX_IP_DROPPED = SPINEL_PROP_CNTR__BEGIN + 202, + SPINEL_PROP_CNTR_TX_IP_DROPPED = SPINEL_PROP_CNTR__BEGIN + 202, /// The total number of secure received IP message. /** Format: `L` (Read-only) */ - SPINEL_PROP_CNTR_RX_IP_SEC_TOTAL = SPINEL_PROP_CNTR__BEGIN + 203, + SPINEL_PROP_CNTR_RX_IP_SEC_TOTAL = SPINEL_PROP_CNTR__BEGIN + 203, /// The total number of insecure received IP message. /** Format: `L` (Read-only) */ - SPINEL_PROP_CNTR_RX_IP_INSEC_TOTAL = SPINEL_PROP_CNTR__BEGIN + 204, + SPINEL_PROP_CNTR_RX_IP_INSEC_TOTAL = SPINEL_PROP_CNTR__BEGIN + 204, /// The number of dropped received IP messages. /** Format: `L` (Read-only) */ - SPINEL_PROP_CNTR_RX_IP_DROPPED = SPINEL_PROP_CNTR__BEGIN + 205, + SPINEL_PROP_CNTR_RX_IP_DROPPED = SPINEL_PROP_CNTR__BEGIN + 205, /// The number of transmitted spinel frames. /** Format: `L` (Read-only) */ - SPINEL_PROP_CNTR_TX_SPINEL_TOTAL = SPINEL_PROP_CNTR__BEGIN + 300, + SPINEL_PROP_CNTR_TX_SPINEL_TOTAL = SPINEL_PROP_CNTR__BEGIN + 300, /// The number of received spinel frames. /** Format: `L` (Read-only) */ - SPINEL_PROP_CNTR_RX_SPINEL_TOTAL = SPINEL_PROP_CNTR__BEGIN + 301, + SPINEL_PROP_CNTR_RX_SPINEL_TOTAL = SPINEL_PROP_CNTR__BEGIN + 301, /// The number of received spinel frames with error. /** Format: `L` (Read-only) */ - SPINEL_PROP_CNTR_RX_SPINEL_ERR = SPINEL_PROP_CNTR__BEGIN + 302, + SPINEL_PROP_CNTR_RX_SPINEL_ERR = SPINEL_PROP_CNTR__BEGIN + 302, /// Number of out of order received spinel frames (tid increase by more than 1). /** Format: `L` (Read-only) */ - SPINEL_PROP_CNTR_RX_SPINEL_OUT_OF_ORDER_TID - = SPINEL_PROP_CNTR__BEGIN + 303, + SPINEL_PROP_CNTR_RX_SPINEL_OUT_OF_ORDER_TID = SPINEL_PROP_CNTR__BEGIN + 303, /// The number of successful Tx IP packets /** Format: `L` (Read-only) */ - SPINEL_PROP_CNTR_IP_TX_SUCCESS = SPINEL_PROP_CNTR__BEGIN + 304, + SPINEL_PROP_CNTR_IP_TX_SUCCESS = SPINEL_PROP_CNTR__BEGIN + 304, /// The number of successful Rx IP packets /** Format: `L` (Read-only) */ - SPINEL_PROP_CNTR_IP_RX_SUCCESS = SPINEL_PROP_CNTR__BEGIN + 305, + SPINEL_PROP_CNTR_IP_RX_SUCCESS = SPINEL_PROP_CNTR__BEGIN + 305, /// The number of failed Tx IP packets /** Format: `L` (Read-only) */ - SPINEL_PROP_CNTR_IP_TX_FAILURE = SPINEL_PROP_CNTR__BEGIN + 306, + SPINEL_PROP_CNTR_IP_TX_FAILURE = SPINEL_PROP_CNTR__BEGIN + 306, /// The number of failed Rx IP packets /** Format: `L` (Read-only) */ - SPINEL_PROP_CNTR_IP_RX_FAILURE = SPINEL_PROP_CNTR__BEGIN + 307, + SPINEL_PROP_CNTR_IP_RX_FAILURE = SPINEL_PROP_CNTR__BEGIN + 307, /// The message buffer counter info /** Format: `SSSSSSSSSSSSSSSS` (Read-only) @@ -1889,7 +1827,7 @@ typedef enum * `S`, (CoapMessages) The number of messages in the CoAP send queue. * `S`, (CoapBuffers) The number of buffers in the CoAP send queue. */ - SPINEL_PROP_MSG_BUFFER_COUNTERS = SPINEL_PROP_CNTR__BEGIN + 400, + SPINEL_PROP_MSG_BUFFER_COUNTERS = SPINEL_PROP_CNTR__BEGIN + 400, /// All MAC related counters. /** Format: t(A(L))t(A(L)) (Read-only) @@ -1936,28 +1874,27 @@ typedef enum * 'L': RxErrFcs (The number of received packets with FCS error). * 'L': RxErrOther (The number of received packets with other error). */ - SPINEL_PROP_CNTR_ALL_MAC_COUNTERS = SPINEL_PROP_CNTR__BEGIN + 401, + SPINEL_PROP_CNTR_ALL_MAC_COUNTERS = SPINEL_PROP_CNTR__BEGIN + 401, - SPINEL_PROP_CNTR__END = 2048, + SPINEL_PROP_CNTR__END = 2048, - SPINEL_PROP_NEST__BEGIN = 15296, - SPINEL_PROP_NEST_STREAM_MFG = SPINEL_PROP_NEST__BEGIN + 0, + SPINEL_PROP_NEST__BEGIN = 15296, + SPINEL_PROP_NEST_STREAM_MFG = SPINEL_PROP_NEST__BEGIN + 0, /// The legacy network ULA prefix (8 bytes) /** Format: 'D' */ - SPINEL_PROP_NEST_LEGACY_ULA_PREFIX = SPINEL_PROP_NEST__BEGIN + 1, + SPINEL_PROP_NEST_LEGACY_ULA_PREFIX = SPINEL_PROP_NEST__BEGIN + 1, /// The EUI64 of last node joined using legacy protocol (if none, all zero EUI64 is returned). /** Format: 'E' */ - SPINEL_PROP_NEST_LEGACY_LAST_NODE_JOINED - = SPINEL_PROP_NEST__BEGIN + 2, + SPINEL_PROP_NEST_LEGACY_LAST_NODE_JOINED = SPINEL_PROP_NEST__BEGIN + 2, - SPINEL_PROP_NEST__END = 15360, + SPINEL_PROP_NEST__END = 15360, - SPINEL_PROP_VENDOR__BEGIN = 15360, - SPINEL_PROP_VENDOR__END = 16384, + SPINEL_PROP_VENDOR__BEGIN = 15360, + SPINEL_PROP_VENDOR__END = 16384, - SPINEL_PROP_DEBUG__BEGIN = 16384, + SPINEL_PROP_DEBUG__BEGIN = 16384, /// Testing platform assert /** Format: 'b' (read-only) @@ -1967,11 +1904,11 @@ typedef enum * boolean is returned in response. * */ - SPINEL_PROP_DEBUG_TEST_ASSERT = SPINEL_PROP_DEBUG__BEGIN + 0, + SPINEL_PROP_DEBUG_TEST_ASSERT = SPINEL_PROP_DEBUG__BEGIN + 0, /// The NCP log level. /** Format: `C` */ - SPINEL_PROP_DEBUG_NCP_LOG_LEVEL = SPINEL_PROP_DEBUG__BEGIN + 1, + SPINEL_PROP_DEBUG_NCP_LOG_LEVEL = SPINEL_PROP_DEBUG__BEGIN + 1, /// Testing platform watchdog /** Format: Empty (read-only) @@ -1981,136 +1918,138 @@ typedef enum * This is intended for testing the watchdog functionality on the underlying platform/NCP. * */ - SPINEL_PROP_DEBUG_TEST_WATCHDOG = SPINEL_PROP_DEBUG__BEGIN + 2, + SPINEL_PROP_DEBUG_TEST_WATCHDOG = SPINEL_PROP_DEBUG__BEGIN + 2, - SPINEL_PROP_DEBUG__END = 17408, + SPINEL_PROP_DEBUG__END = 17408, - SPINEL_PROP_EXPERIMENTAL__BEGIN = 2000000, - SPINEL_PROP_EXPERIMENTAL__END = 2097152, + SPINEL_PROP_EXPERIMENTAL__BEGIN = 2000000, + SPINEL_PROP_EXPERIMENTAL__END = 2097152, } spinel_prop_key_t; // ---------------------------------------------------------------------------- -#define SPINEL_HEADER_FLAG 0x80 +#define SPINEL_HEADER_FLAG 0x80 -#define SPINEL_HEADER_TID_SHIFT 0 -#define SPINEL_HEADER_TID_MASK (15 << SPINEL_HEADER_TID_SHIFT) +#define SPINEL_HEADER_TID_SHIFT 0 +#define SPINEL_HEADER_TID_MASK (15 << SPINEL_HEADER_TID_SHIFT) -#define SPINEL_HEADER_IID_SHIFT 4 -#define SPINEL_HEADER_IID_MASK (3 << SPINEL_HEADER_IID_SHIFT) +#define SPINEL_HEADER_IID_SHIFT 4 +#define SPINEL_HEADER_IID_MASK (3 << SPINEL_HEADER_IID_SHIFT) -#define SPINEL_HEADER_IID_0 (0 << SPINEL_HEADER_IID_SHIFT) -#define SPINEL_HEADER_IID_1 (1 << SPINEL_HEADER_IID_SHIFT) -#define SPINEL_HEADER_IID_2 (2 << SPINEL_HEADER_IID_SHIFT) -#define SPINEL_HEADER_IID_3 (3 << SPINEL_HEADER_IID_SHIFT) +#define SPINEL_HEADER_IID_0 (0 << SPINEL_HEADER_IID_SHIFT) +#define SPINEL_HEADER_IID_1 (1 << SPINEL_HEADER_IID_SHIFT) +#define SPINEL_HEADER_IID_2 (2 << SPINEL_HEADER_IID_SHIFT) +#define SPINEL_HEADER_IID_3 (3 << SPINEL_HEADER_IID_SHIFT) -#define SPINEL_HEADER_GET_IID(x) (((x) & SPINEL_HEADER_IID_MASK) >> SPINEL_HEADER_IID_SHIFT) -#define SPINEL_HEADER_GET_TID(x) (spinel_tid_t)(((x)&SPINEL_HEADER_TID_MASK)>>SPINEL_HEADER_TID_SHIFT) +#define SPINEL_HEADER_GET_IID(x) (((x)&SPINEL_HEADER_IID_MASK) >> SPINEL_HEADER_IID_SHIFT) +#define SPINEL_HEADER_GET_TID(x) (spinel_tid_t)(((x)&SPINEL_HEADER_TID_MASK) >> SPINEL_HEADER_TID_SHIFT) -#define SPINEL_GET_NEXT_TID(x) (spinel_tid_t)((x)>=0xF?1:(x)+1) +#define SPINEL_GET_NEXT_TID(x) (spinel_tid_t)((x) >= 0xF ? 1 : (x) + 1) -#define SPINEL_BEACON_THREAD_FLAG_VERSION_SHIFT \ - 4 +#define SPINEL_BEACON_THREAD_FLAG_VERSION_SHIFT 4 -#define SPINEL_BEACON_THREAD_FLAG_VERSION_MASK \ - (0xf << SPINEL_BEACON_THREAD_FLAG_VERSION_SHIFT) +#define SPINEL_BEACON_THREAD_FLAG_VERSION_MASK (0xf << SPINEL_BEACON_THREAD_FLAG_VERSION_SHIFT) -#define SPINEL_BEACON_THREAD_FLAG_JOINABLE \ - (1 << 0) +#define SPINEL_BEACON_THREAD_FLAG_JOINABLE (1 << 0) -#define SPINEL_BEACON_THREAD_FLAG_NATIVE \ - (1 << 3) +#define SPINEL_BEACON_THREAD_FLAG_NATIVE (1 << 3) // ---------------------------------------------------------------------------- enum { - SPINEL_DATATYPE_NULL_C = 0, - SPINEL_DATATYPE_VOID_C = '.', - SPINEL_DATATYPE_BOOL_C = 'b', - SPINEL_DATATYPE_UINT8_C = 'C', - SPINEL_DATATYPE_INT8_C = 'c', - SPINEL_DATATYPE_UINT16_C = 'S', - SPINEL_DATATYPE_INT16_C = 's', - SPINEL_DATATYPE_UINT32_C = 'L', - SPINEL_DATATYPE_INT32_C = 'l', - SPINEL_DATATYPE_UINT64_C = 'X', - SPINEL_DATATYPE_INT64_C = 'x', - SPINEL_DATATYPE_UINT_PACKED_C = 'i', - SPINEL_DATATYPE_IPv6ADDR_C = '6', - SPINEL_DATATYPE_EUI64_C = 'E', - SPINEL_DATATYPE_EUI48_C = 'e', - SPINEL_DATATYPE_DATA_WLEN_C = 'd', - SPINEL_DATATYPE_DATA_C = 'D', - SPINEL_DATATYPE_UTF8_C = 'U', //!< Zero-Terminated UTF8-Encoded String - SPINEL_DATATYPE_STRUCT_C = 't', - SPINEL_DATATYPE_ARRAY_C = 'A', + SPINEL_DATATYPE_NULL_C = 0, + SPINEL_DATATYPE_VOID_C = '.', + SPINEL_DATATYPE_BOOL_C = 'b', + SPINEL_DATATYPE_UINT8_C = 'C', + SPINEL_DATATYPE_INT8_C = 'c', + SPINEL_DATATYPE_UINT16_C = 'S', + SPINEL_DATATYPE_INT16_C = 's', + SPINEL_DATATYPE_UINT32_C = 'L', + SPINEL_DATATYPE_INT32_C = 'l', + SPINEL_DATATYPE_UINT64_C = 'X', + SPINEL_DATATYPE_INT64_C = 'x', + SPINEL_DATATYPE_UINT_PACKED_C = 'i', + SPINEL_DATATYPE_IPv6ADDR_C = '6', + SPINEL_DATATYPE_EUI64_C = 'E', + SPINEL_DATATYPE_EUI48_C = 'e', + SPINEL_DATATYPE_DATA_WLEN_C = 'd', + SPINEL_DATATYPE_DATA_C = 'D', + SPINEL_DATATYPE_UTF8_C = 'U', //!< Zero-Terminated UTF8-Encoded String + SPINEL_DATATYPE_STRUCT_C = 't', + SPINEL_DATATYPE_ARRAY_C = 'A', }; typedef char spinel_datatype_t; -#define SPINEL_DATATYPE_NULL_S "" -#define SPINEL_DATATYPE_VOID_S "." -#define SPINEL_DATATYPE_BOOL_S "b" -#define SPINEL_DATATYPE_UINT8_S "C" -#define SPINEL_DATATYPE_INT8_S "c" -#define SPINEL_DATATYPE_UINT16_S "S" -#define SPINEL_DATATYPE_INT16_S "s" -#define SPINEL_DATATYPE_UINT32_S "L" -#define SPINEL_DATATYPE_INT32_S "l" -#define SPINEL_DATATYPE_UINT64_S "X" -#define SPINEL_DATATYPE_INT64_S "x" -#define SPINEL_DATATYPE_UINT_PACKED_S "i" -#define SPINEL_DATATYPE_IPv6ADDR_S "6" -#define SPINEL_DATATYPE_EUI64_S "E" -#define SPINEL_DATATYPE_EUI48_S "e" -#define SPINEL_DATATYPE_DATA_WLEN_S "d" -#define SPINEL_DATATYPE_DATA_S "D" -#define SPINEL_DATATYPE_UTF8_S "U" //!< Zero-Terminated UTF8-Encoded String +#define SPINEL_DATATYPE_NULL_S "" +#define SPINEL_DATATYPE_VOID_S "." +#define SPINEL_DATATYPE_BOOL_S "b" +#define SPINEL_DATATYPE_UINT8_S "C" +#define SPINEL_DATATYPE_INT8_S "c" +#define SPINEL_DATATYPE_UINT16_S "S" +#define SPINEL_DATATYPE_INT16_S "s" +#define SPINEL_DATATYPE_UINT32_S "L" +#define SPINEL_DATATYPE_INT32_S "l" +#define SPINEL_DATATYPE_UINT64_S "X" +#define SPINEL_DATATYPE_INT64_S "x" +#define SPINEL_DATATYPE_UINT_PACKED_S "i" +#define SPINEL_DATATYPE_IPv6ADDR_S "6" +#define SPINEL_DATATYPE_EUI64_S "E" +#define SPINEL_DATATYPE_EUI48_S "e" +#define SPINEL_DATATYPE_DATA_WLEN_S "d" +#define SPINEL_DATATYPE_DATA_S "D" +#define SPINEL_DATATYPE_UTF8_S "U" //!< Zero-Terminated UTF8-Encoded String -#define SPINEL_DATATYPE_ARRAY_S(x) "A(" x ")" -#define SPINEL_DATATYPE_STRUCT_S(x) "t(" x ")" +#define SPINEL_DATATYPE_ARRAY_S(x) "A(" x ")" +#define SPINEL_DATATYPE_STRUCT_S(x) "t(" x ")" -#define SPINEL_DATATYPE_ARRAY_STRUCT_S(x) \ - SPINEL_DATATYPE_ARRAY_S(SPINEL_DATATYPE_STRUCT_WLEN_S(x)) +#define SPINEL_DATATYPE_ARRAY_STRUCT_S(x) SPINEL_DATATYPE_ARRAY_S(SPINEL_DATATYPE_STRUCT_WLEN_S(x)) -#define SPINEL_DATATYPE_COMMAND_S SPINEL_DATATYPE_UINT8_S /* header */ \ - SPINEL_DATATYPE_UINT_PACKED_S /* command */ +#define SPINEL_DATATYPE_COMMAND_S \ + SPINEL_DATATYPE_UINT8_S /* header */ \ + SPINEL_DATATYPE_UINT_PACKED_S /* command */ -#define SPINEL_DATATYPE_COMMAND_PROP_S SPINEL_DATATYPE_COMMAND_S /* prop command */ \ - SPINEL_DATATYPE_UINT_PACKED_S /* property id */ +#define SPINEL_DATATYPE_COMMAND_PROP_S \ + SPINEL_DATATYPE_COMMAND_S /* prop command */ \ + SPINEL_DATATYPE_UINT_PACKED_S /* property id */ -#define SPINEL_DATATYPE_MAC_SCAN_RESULT_S(mac_format_str, net_format_str) \ - SPINEL_DATATYPE_UINT8_S /* Channel */ \ - SPINEL_DATATYPE_INT8_S /* RSSI */ \ - SPINEL_DATATYPE_STRUCT_S(mac_format_str) /* mac-layer data */ \ - SPINEL_DATATYPE_STRUCT_S(net_format_str) /* net-layer data */ +#define SPINEL_DATATYPE_MAC_SCAN_RESULT_S(mac_format_str, net_format_str) \ + SPINEL_DATATYPE_UINT8_S /* Channel */ \ + SPINEL_DATATYPE_INT8_S /* RSSI */ \ + SPINEL_DATATYPE_STRUCT_S(mac_format_str) /* mac-layer data */ \ + SPINEL_DATATYPE_STRUCT_S(net_format_str) /* net-layer data */ -#define SPINEL_802_15_4_DATATYPE_MAC_SCAN_RESULT_V1_S \ - SPINEL_DATATYPE_EUI64_S /* laddr */ \ - SPINEL_DATATYPE_UINT16_S /* saddr */ \ - SPINEL_DATATYPE_UINT16_S /* panid */ \ - SPINEL_DATATYPE_UINT8_S /* lqi */ +#define SPINEL_802_15_4_DATATYPE_MAC_SCAN_RESULT_V1_S \ + SPINEL_DATATYPE_EUI64_S /* laddr */ \ + SPINEL_DATATYPE_UINT16_S /* saddr */ \ + SPINEL_DATATYPE_UINT16_S /* panid */ \ + SPINEL_DATATYPE_UINT8_S /* lqi */ -#define SPINEL_NET_DATATYPE_MAC_SCAN_RESULT_V1_S \ - SPINEL_DATATYPE_UINT_PACKED_S /* type */ \ - SPINEL_DATATYPE_UINT8_S /* flags */ \ - SPINEL_DATATYPE_UTF8_S /* network name */ \ - SPINEL_DATATYPE_DATA_WLEN_S /* xpanid */ +#define SPINEL_NET_DATATYPE_MAC_SCAN_RESULT_V1_S \ + SPINEL_DATATYPE_UINT_PACKED_S /* type */ \ + SPINEL_DATATYPE_UINT8_S /* flags */ \ + SPINEL_DATATYPE_UTF8_S /* network name */ \ + SPINEL_DATATYPE_DATA_WLEN_S /* xpanid */ -#define SPINEL_NET_DATATYPE_MAC_SCAN_RESULT_V2_S \ - SPINEL_NET_DATATYPE_MAC_SCAN_RESULT_V1_S \ - SPINEL_DATATYPE_DATA_WLEN_S /* steering data */ +#define SPINEL_NET_DATATYPE_MAC_SCAN_RESULT_V2_S \ + SPINEL_NET_DATATYPE_MAC_SCAN_RESULT_V1_S \ + SPINEL_DATATYPE_DATA_WLEN_S /* steering data */ +#define SPINEL_MAX_UINT_PACKED 2097151 -#define SPINEL_MAX_UINT_PACKED 2097151 - -SPINEL_API_EXTERN spinel_ssize_t spinel_datatype_pack(uint8_t *data_out, spinel_size_t data_len, - const char *pack_format, ...); -SPINEL_API_EXTERN spinel_ssize_t spinel_datatype_vpack(uint8_t *data_out, spinel_size_t data_len, - const char *pack_format, va_list args); -SPINEL_API_EXTERN spinel_ssize_t spinel_datatype_unpack(const uint8_t *data_in, spinel_size_t data_len, - const char *pack_format, ...); +SPINEL_API_EXTERN spinel_ssize_t spinel_datatype_pack(uint8_t * data_out, + spinel_size_t data_len, + const char * pack_format, + ...); +SPINEL_API_EXTERN spinel_ssize_t spinel_datatype_vpack(uint8_t * data_out, + spinel_size_t data_len, + const char * pack_format, + va_list args); +SPINEL_API_EXTERN spinel_ssize_t spinel_datatype_unpack(const uint8_t *data_in, + spinel_size_t data_len, + const char * pack_format, + ...); /** * This function parses spinel data similar to sscanf(). * @@ -2135,10 +2074,14 @@ SPINEL_API_EXTERN spinel_ssize_t spinel_datatype_unpack(const uint8_t *data_in, * @sa spinel_datatype_vunpack_in_place() * */ -SPINEL_API_EXTERN spinel_ssize_t spinel_datatype_unpack_in_place(const uint8_t *data_in, spinel_size_t data_len, - const char *pack_format, ...); -SPINEL_API_EXTERN spinel_ssize_t spinel_datatype_vunpack(const uint8_t *data_in, spinel_size_t data_len, - const char *pack_format, va_list args); +SPINEL_API_EXTERN spinel_ssize_t spinel_datatype_unpack_in_place(const uint8_t *data_in, + spinel_size_t data_len, + const char * pack_format, + ...); +SPINEL_API_EXTERN spinel_ssize_t spinel_datatype_vunpack(const uint8_t *data_in, + spinel_size_t data_len, + const char * pack_format, + va_list args); /** * This function parses spinel data similar to vsscanf(). * @@ -2161,11 +2104,14 @@ SPINEL_API_EXTERN spinel_ssize_t spinel_datatype_vunpack(const uint8_t *data_in, * @sa spinel_datatype_unpack_in_place() * */ -SPINEL_API_EXTERN spinel_ssize_t spinel_datatype_vunpack_in_place(const uint8_t *data_in, spinel_size_t data_len, - const char *pack_format, va_list args); +SPINEL_API_EXTERN spinel_ssize_t spinel_datatype_vunpack_in_place(const uint8_t *data_in, + spinel_size_t data_len, + const char * pack_format, + va_list args); -SPINEL_API_EXTERN spinel_ssize_t spinel_packed_uint_decode(const uint8_t *bytes, spinel_size_t len, - unsigned int *value); +SPINEL_API_EXTERN spinel_ssize_t spinel_packed_uint_decode(const uint8_t *bytes, + spinel_size_t len, + unsigned int * value); SPINEL_API_EXTERN spinel_ssize_t spinel_packed_uint_encode(uint8_t *bytes, spinel_size_t len, unsigned int value); SPINEL_API_EXTERN spinel_ssize_t spinel_packed_uint_size(unsigned int value); diff --git a/src/ncp/spinel_decoder.cpp b/src/ncp/spinel_decoder.cpp index 2811481d4..060a3ac15 100644 --- a/src/ncp/spinel_decoder.cpp +++ b/src/ncp/spinel_decoder.cpp @@ -39,21 +39,21 @@ namespace ot { namespace Ncp { -SpinelDecoder::SpinelDecoder(void) : - mFrame(NULL), - mLength(0), - mIndex(0), - mEnd(0), - mNumOpenStructs(0), - mSavedNumOpenStructs(0), - mSavedIndex(0), - mSavedEnd(0) +SpinelDecoder::SpinelDecoder(void) + : mFrame(NULL) + , mLength(0) + , mIndex(0) + , mEnd(0) + , mNumOpenStructs(0) + , mSavedNumOpenStructs(0) + , mSavedIndex(0) + , mSavedEnd(0) { } void SpinelDecoder::Init(const uint8_t *aFrame, uint16_t aLength) { - mFrame = aFrame; + mFrame = aFrame; mLength = (mFrame != NULL) ? aLength : 0; Reset(); @@ -62,8 +62,8 @@ void SpinelDecoder::Init(const uint8_t *aFrame, uint16_t aLength) void SpinelDecoder::Reset(void) { - mIndex = 0; - mEnd = mLength; + mIndex = 0; + mEnd = mLength; mNumOpenStructs = 0; ClearSavedPosition(); } @@ -133,7 +133,7 @@ exit: otError SpinelDecoder::ReadInt16(int16_t &aInt16) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; uint16_t u16; SuccessOrExit(error = ReadUint16(u16)); @@ -149,10 +149,8 @@ otError SpinelDecoder::ReadUint32(uint32_t &aUint32) VerifyOrExit(mIndex + sizeof(uint32_t) <= mEnd, error = OT_ERROR_PARSE); - aUint32 = ((static_cast(mFrame[mIndex + 0]) << 0) | - (static_cast(mFrame[mIndex + 1]) << 8) | - (static_cast(mFrame[mIndex + 2]) << 16) | - (static_cast(mFrame[mIndex + 3]) << 24)); + aUint32 = ((static_cast(mFrame[mIndex + 0]) << 0) | (static_cast(mFrame[mIndex + 1]) << 8) | + (static_cast(mFrame[mIndex + 2]) << 16) | (static_cast(mFrame[mIndex + 3]) << 24)); mIndex += sizeof(uint32_t); @@ -162,7 +160,7 @@ exit: otError SpinelDecoder::ReadInt32(int32_t &aInt32) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; uint32_t u32; SuccessOrExit(error = ReadUint32(u32)); @@ -178,14 +176,10 @@ otError SpinelDecoder::ReadUint64(uint64_t &aUint64) VerifyOrExit(mIndex + sizeof(uint64_t) <= mEnd, error = OT_ERROR_PARSE); - aUint64 = ((static_cast(mFrame[mIndex + 0]) << 0) | - (static_cast(mFrame[mIndex + 1]) << 8) | - (static_cast(mFrame[mIndex + 2]) << 16) | - (static_cast(mFrame[mIndex + 3]) << 24) | - (static_cast(mFrame[mIndex + 4]) << 32) | - (static_cast(mFrame[mIndex + 5]) << 40) | - (static_cast(mFrame[mIndex + 6]) << 48) | - (static_cast(mFrame[mIndex + 7]) << 56)); + aUint64 = ((static_cast(mFrame[mIndex + 0]) << 0) | (static_cast(mFrame[mIndex + 1]) << 8) | + (static_cast(mFrame[mIndex + 2]) << 16) | (static_cast(mFrame[mIndex + 3]) << 24) | + (static_cast(mFrame[mIndex + 4]) << 32) | (static_cast(mFrame[mIndex + 5]) << 40) | + (static_cast(mFrame[mIndex + 6]) << 48) | (static_cast(mFrame[mIndex + 7]) << 56)); mIndex += sizeof(uint64_t); @@ -195,7 +189,7 @@ exit: otError SpinelDecoder::ReadInt64(int64_t &aInt64) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; uint64_t u64; SuccessOrExit(error = ReadUint64(u64)); @@ -207,9 +201,9 @@ exit: otError SpinelDecoder::ReadUintPacked(unsigned int &aUint) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; spinel_ssize_t parsedLen; - unsigned int uint; + unsigned int uint; parsedLen = spinel_packed_uint_decode(&mFrame[mIndex], mEnd - mIndex, &uint); VerifyOrExit(parsedLen > 0, error = OT_ERROR_PARSE); @@ -238,7 +232,7 @@ exit: otError SpinelDecoder::ReadIp6Address(spinel_ipv6addr_t &aIp6Addr) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; const spinel_ipv6addr_t *ipv6AddrPtr; SuccessOrExit(error = ReadIp6Address(ipv6AddrPtr)); @@ -250,7 +244,7 @@ exit: otError SpinelDecoder::ReadIp6Address(otIp6Address &aIp6Addr) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; const otIp6Address *ipv6AddrPtr; SuccessOrExit(error = ReadIp6Address(ipv6AddrPtr)); @@ -262,7 +256,7 @@ exit: otError SpinelDecoder::ReadEui64(spinel_eui64_t &aEui64) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; const spinel_eui64_t *eui64Ptr; SuccessOrExit(error = ReadEui64(eui64Ptr)); @@ -274,7 +268,7 @@ exit: otError SpinelDecoder::ReadEui64(otExtAddress &aEui64) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; const otExtAddress *eui64Ptr; SuccessOrExit(error = ReadEui64(eui64Ptr)); @@ -286,7 +280,7 @@ exit: otError SpinelDecoder::ReadEui48(spinel_eui48_t &aEui48) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; const spinel_eui48_t *eui48Ptr; SuccessOrExit(error = ReadEui48(eui48Ptr)); @@ -299,7 +293,7 @@ exit: otError SpinelDecoder::ReadUtf8(const char *&aUtf8) { otError error = OT_ERROR_NONE; - size_t len; + size_t len; // Ensure there is at least one byte (for null character). VerifyOrExit(mIndex + sizeof(uint8_t) <= mEnd, error = OT_ERROR_PARSE); @@ -309,7 +303,7 @@ otError SpinelDecoder::ReadUtf8(const char *&aUtf8) aUtf8 = reinterpret_cast(&mFrame[mIndex]); - mIndex += (len + sizeof(uint8_t)); // `sizeof(uint8_t)` is added for the terminating null character. + mIndex += (len + sizeof(uint8_t)); // `sizeof(uint8_t)` is added for the terminating null character. exit: return error; @@ -324,7 +318,7 @@ otError SpinelDecoder::ReadData(const uint8_t *&aData, uint16_t &aDataLen) otError SpinelDecoder::ReadDataWithLen(const uint8_t *&aData, uint16_t &aDataLen) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; uint16_t len; SuccessOrExit(error = ReadUint16(len)); @@ -337,7 +331,7 @@ exit: otError SpinelDecoder::OpenStruct(void) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; uint16_t structLen; VerifyOrExit(mNumOpenStructs < kMaxNestedStructs, error = OT_ERROR_INVALID_STATE); @@ -346,7 +340,7 @@ otError SpinelDecoder::OpenStruct(void) VerifyOrExit(structLen <= mEnd - mIndex, error = OT_ERROR_PARSE); mPrevEnd[mNumOpenStructs] = mEnd; - mEnd = (mIndex + structLen); + mEnd = (mIndex + structLen); mNumOpenStructs++; exit: @@ -371,7 +365,7 @@ otError SpinelDecoder::CloseStruct(void) mNumOpenStructs--; mIndex = mEnd; - mEnd = mPrevEnd[mNumOpenStructs]; + mEnd = mPrevEnd[mNumOpenStructs]; exit: return error; @@ -379,8 +373,8 @@ exit: void SpinelDecoder::SavePosition(void) { - mSavedIndex = mIndex; - mSavedEnd = mEnd; + mSavedIndex = mIndex; + mSavedEnd = mEnd; mSavedNumOpenStructs = mNumOpenStructs; } @@ -390,13 +384,13 @@ otError SpinelDecoder::ResetToSaved(void) VerifyOrExit(IsSavedPositionValid(), error = OT_ERROR_INVALID_STATE); - mIndex = mSavedIndex; - mEnd = mSavedEnd; - mNumOpenStructs = mSavedNumOpenStructs; + mIndex = mSavedIndex; + mEnd = mSavedEnd; + mNumOpenStructs = mSavedNumOpenStructs; exit: return error; } -} // namespace Ncp -} // namespace ot +} // namespace Ncp +} // namespace ot diff --git a/src/ncp/spinel_decoder.hpp b/src/ncp/spinel_decoder.hpp index 46faa0208..d267c7c70 100644 --- a/src/ncp/spinel_decoder.hpp +++ b/src/ncp/spinel_decoder.hpp @@ -51,7 +51,6 @@ namespace Ncp { class SpinelDecoder { public: - /** * This constructor initializes a `SpinelDecoder` object * @@ -259,7 +258,8 @@ public: * @retval OT_ERROR_PARSE Failed to parse/decode the value. * */ - otError ReadIp6Address(const spinel_ipv6addr_t *&aIp6AddrPtr) { + otError ReadIp6Address(const spinel_ipv6addr_t *&aIp6AddrPtr) + { return ReadItem(reinterpret_cast(&aIp6AddrPtr), sizeof(spinel_ipv6addr_t)); } @@ -275,7 +275,8 @@ public: * @retval OT_ERROR_PARSE Failed to parse/decode the value. * */ - otError ReadIp6Address(const otIp6Address *&aIp6AddrPtr) { + otError ReadIp6Address(const otIp6Address *&aIp6AddrPtr) + { return ReadItem(reinterpret_cast(&aIp6AddrPtr), sizeof(spinel_ipv6addr_t)); } @@ -291,7 +292,8 @@ public: * @retval OT_ERROR_PARSE Failed to parse/decode the value. * */ - otError ReadIp6Address(const uint8_t *&aIp6AddrBufPtr) { + otError ReadIp6Address(const uint8_t *&aIp6AddrBufPtr) + { return ReadItem(&aIp6AddrBufPtr, sizeof(spinel_ipv6addr_t)); } @@ -335,7 +337,8 @@ public: * @retval OT_ERROR_PARSE Failed to parse/decode the value. * */ - otError ReadEui64(const spinel_eui64_t *&aEui64Ptr) { + otError ReadEui64(const spinel_eui64_t *&aEui64Ptr) + { return ReadItem(reinterpret_cast(&aEui64Ptr), sizeof(spinel_eui64_t)); } @@ -351,7 +354,8 @@ public: * @retval OT_ERROR_PARSE Failed to parse/decode the value. * */ - otError ReadEui64(const otExtAddress *&aEui64Ptr) { + otError ReadEui64(const otExtAddress *&aEui64Ptr) + { return ReadItem(reinterpret_cast(&aEui64Ptr), sizeof(spinel_eui64_t)); } @@ -367,9 +371,7 @@ public: * @retval OT_ERROR_PARSE Failed to parse/decode the value. * */ - otError ReadEui64(const uint8_t *&aEui64BufPtr) { - return ReadItem(&aEui64BufPtr, sizeof(spinel_eui64_t)); - } + otError ReadEui64(const uint8_t *&aEui64BufPtr) { return ReadItem(&aEui64BufPtr, sizeof(spinel_eui64_t)); } /** * This method decodes and reads an EUI64 value form the frame. @@ -411,7 +413,8 @@ public: * @retval OT_ERROR_PARSE Failed to parse/decode the value. * */ - otError ReadEui48(const spinel_eui48_t *&aEui48Ptr) { + otError ReadEui48(const spinel_eui48_t *&aEui48Ptr) + { return ReadItem(reinterpret_cast(&aEui48Ptr), sizeof(spinel_eui48_t)); } @@ -427,9 +430,7 @@ public: * @retval OT_ERROR_PARSE Failed to parse/decode the value. * */ - otError ReadEui48(const uint8_t *&aEui48BufPtr) { - return ReadItem(&aEui48BufPtr, sizeof(spinel_eui48_t)); - } + otError ReadEui48(const uint8_t *&aEui48BufPtr) { return ReadItem(&aEui48BufPtr, sizeof(spinel_eui48_t)); } /** * This method decodes and reads an EUI48 value form the frame. @@ -459,7 +460,7 @@ public: */ otError ReadUtf8(const char *&aUt8); - /** + /** * This method decodes and reads a data blob (sequence of bytes) form the frame. * * On success, the read position gets updated. @@ -549,7 +550,7 @@ public: */ void SavePosition(void); - /** + /** * This method resets/moves the read position to a previously saved position. * * The saved position remembers its enclosing structure. When `ResetToSaved()` is called, the current open @@ -564,28 +565,28 @@ public: private: otError ReadItem(const uint8_t **aPtr, size_t aSize); - void ClearSavedPosition(void) { mSavedIndex = mLength; } - bool IsSavedPositionValid(void) const { return (mSavedIndex < mLength); } + void ClearSavedPosition(void) { mSavedIndex = mLength; } + bool IsSavedPositionValid(void) const { return (mSavedIndex < mLength); } enum { - kMaxNestedStructs = 4, ///< Maximum number of nested structs. + kMaxNestedStructs = 4, ///< Maximum number of nested structs. }; - const uint8_t *mFrame; // Frame buffer - uint16_t mLength; // Total length of the buffer. - uint16_t mIndex; // Current read index. - uint16_t mEnd; // Current end index (end of struct if in a struct, or end of buffer otherwise). - uint8_t mNumOpenStructs; // Number of open structs. + const uint8_t *mFrame; // Frame buffer + uint16_t mLength; // Total length of the buffer. + uint16_t mIndex; // Current read index. + uint16_t mEnd; // Current end index (end of struct if in a struct, or end of buffer otherwise). + uint8_t mNumOpenStructs; // Number of open structs. - uint8_t mSavedNumOpenStructs; // Number of open structs when read position was saved. - uint16_t mSavedIndex; // Read index when position was saved. - uint16_t mSavedEnd; // End index when position was saved. + uint8_t mSavedNumOpenStructs; // Number of open structs when read position was saved. + uint16_t mSavedIndex; // Read index when position was saved. + uint16_t mSavedEnd; // End index when position was saved. uint16_t mPrevEnd[kMaxNestedStructs]; }; -} // namespace Ncp -} // namespace ot +} // namespace Ncp +} // namespace ot -#endif // SPINEL_DECODER_HPP_ +#endif // SPINEL_DECODER_HPP_ diff --git a/src/ncp/spinel_encoder.cpp b/src/ncp/spinel_encoder.cpp index ab1074d9f..7d5ff90e1 100644 --- a/src/ncp/spinel_encoder.cpp +++ b/src/ncp/spinel_encoder.cpp @@ -126,8 +126,8 @@ otError SpinelEncoder::WriteUint32(uint32_t aUint32) { otError error = OT_ERROR_NONE; - SuccessOrExit(error = mNcpBuffer.InFrameFeedByte((aUint32 >> 0) & 0xff)); - SuccessOrExit(error = mNcpBuffer.InFrameFeedByte((aUint32 >> 8) & 0xff)); + SuccessOrExit(error = mNcpBuffer.InFrameFeedByte((aUint32 >> 0) & 0xff)); + SuccessOrExit(error = mNcpBuffer.InFrameFeedByte((aUint32 >> 8) & 0xff)); SuccessOrExit(error = mNcpBuffer.InFrameFeedByte((aUint32 >> 16) & 0xff)); SuccessOrExit(error = mNcpBuffer.InFrameFeedByte((aUint32 >> 24) & 0xff)); @@ -139,8 +139,8 @@ otError SpinelEncoder::WriteUint64(uint64_t aUint64) { otError error = OT_ERROR_NONE; - SuccessOrExit(error = mNcpBuffer.InFrameFeedByte((aUint64 >> 0) & 0xff)); - SuccessOrExit(error = mNcpBuffer.InFrameFeedByte((aUint64 >> 8) & 0xff)); + SuccessOrExit(error = mNcpBuffer.InFrameFeedByte((aUint64 >> 0) & 0xff)); + SuccessOrExit(error = mNcpBuffer.InFrameFeedByte((aUint64 >> 8) & 0xff)); SuccessOrExit(error = mNcpBuffer.InFrameFeedByte((aUint64 >> 16) & 0xff)); SuccessOrExit(error = mNcpBuffer.InFrameFeedByte((aUint64 >> 24) & 0xff)); SuccessOrExit(error = mNcpBuffer.InFrameFeedByte((aUint64 >> 32) & 0xff)); @@ -154,7 +154,7 @@ exit: otError SpinelEncoder::WriteUintPacked(unsigned int aUint) { - uint8_t buffer[6]; + uint8_t buffer[6]; spinel_ssize_t len; len = spinel_packed_uint_encode(buffer, sizeof(buffer), aUint); @@ -176,7 +176,7 @@ exit: otError SpinelEncoder::WriteUtf8(const char *aUtf8) { otError error; - size_t len = strlen(aUtf8); + size_t len = strlen(aUtf8); if (len >= 0xffff) { @@ -209,9 +209,9 @@ exit: otError SpinelEncoder::CloseStruct(void) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; uint16_t len; - uint8_t buffer[sizeof(uint16_t)]; + uint8_t buffer[sizeof(uint16_t)]; VerifyOrExit(mNumOpenStructs > 0, error = OT_ERROR_INVALID_STATE); @@ -246,7 +246,7 @@ otError SpinelEncoder::ResetToSaved(void) { otError error = OT_ERROR_NONE; - SuccessOrExit(error = mNcpBuffer.InFrameReset(mSavedPosition)); + SuccessOrExit(error = mNcpBuffer.InFrameReset(mSavedPosition)); mNumOpenStructs = mSavedNumOpenStructs; exit: @@ -255,10 +255,10 @@ exit: otError SpinelEncoder::WritePacked(const char *aPackFormat, ...) { - uint8_t buf[kPackFormatBufferSize]; - otError error = OT_ERROR_NONE; + uint8_t buf[kPackFormatBufferSize]; + otError error = OT_ERROR_NONE; spinel_ssize_t packedLen; - va_list args; + va_list args; va_start(args, aPackFormat); @@ -275,8 +275,8 @@ exit: otError SpinelEncoder::WriteVPacked(const char *aPackFormat, va_list aArgs) { - uint8_t buf[kPackFormatBufferSize]; - otError error = OT_ERROR_NONE; + uint8_t buf[kPackFormatBufferSize]; + otError error = OT_ERROR_NONE; spinel_ssize_t packedLen; packedLen = spinel_datatype_vpack(buf, sizeof(buf), aPackFormat, aArgs); @@ -288,5 +288,5 @@ exit: return error; } -} // namespace Ncp -} // namespace ot +} // namespace Ncp +} // namespace ot diff --git a/src/ncp/spinel_encoder.hpp b/src/ncp/spinel_encoder.hpp index 45e8e5cf0..c729107d7 100644 --- a/src/ncp/spinel_encoder.hpp +++ b/src/ncp/spinel_encoder.hpp @@ -40,8 +40,8 @@ #include #include "openthread-core-config.h" -#include "ncp/spinel.h" #include "ncp/ncp_buffer.hpp" +#include "ncp/spinel.h" namespace ot { namespace Ncp { @@ -59,8 +59,13 @@ public: * @param[in] aNcpBuffer A reference to a `NcpFrameBuffer` where the frames are written. * */ - SpinelEncoder(NcpFrameBuffer &aNcpBuffer): - mNcpBuffer(aNcpBuffer), mNumOpenStructs(0), mSavedNumOpenStructs(0), mSavedPosition() { } + SpinelEncoder(NcpFrameBuffer &aNcpBuffer) + : mNcpBuffer(aNcpBuffer) + , mNumOpenStructs(0) + , mSavedNumOpenStructs(0) + , mSavedPosition() + { + } /** * This method begins a new frame to be added/written to the frame buffer. @@ -169,7 +174,7 @@ public: * @retval OT_ERROR_INVALID_STATE `BeginFrame()` has not been called earlier to start the frame. * */ - otError WriteBool(bool aBool) { return mNcpBuffer.InFrameFeedByte( aBool ? 0x01: 0x00); } + otError WriteBool(bool aBool) { return mNcpBuffer.InFrameFeedByte(aBool ? 0x01 : 0x00); } /** * This method encodes and writes a `uint8_t` value to current input frame. @@ -546,10 +551,10 @@ public: * `OT_ERROR_NO_BUFS`. * * The ownership of the passed-in message @p aMessage changes to underlying `NcpFrameBuffer` 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), the `otMessage` - * instance remains unchanged. + * 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), + * the `otMessage` instance remains unchanged. * * @param[in] aMessage A message to be added to current frame. * @@ -674,19 +679,19 @@ public: private: enum { - kPackFormatBufferSize = 96, ///< Size of buffer used when encoding using `WritePacked()` or `WriteVPacked()`. - kMaxNestedStructs = 4, ///< Maximum number of nested structs. + kPackFormatBufferSize = 96, ///< Size of buffer used when encoding using `WritePacked()` or `WriteVPacked()`. + kMaxNestedStructs = 4, ///< Maximum number of nested structs. }; - NcpFrameBuffer &mNcpBuffer; + NcpFrameBuffer & mNcpBuffer; NcpFrameBuffer::WritePosition mStructPosition[kMaxNestedStructs]; - uint8_t mNumOpenStructs; + uint8_t mNumOpenStructs; - uint8_t mSavedNumOpenStructs; + uint8_t mSavedNumOpenStructs; NcpFrameBuffer::WritePosition mSavedPosition; }; -} // namespace Ncp -} // namespace ot +} // namespace Ncp +} // namespace ot -#endif // SPINEL_ENCODER_HPP_ +#endif // SPINEL_ENCODER_HPP_ diff --git a/src/ncp/spinel_platform.h b/src/ncp/spinel_platform.h index 404f287e0..1cc88a7fa 100644 --- a/src/ncp/spinel_platform.h +++ b/src/ncp/spinel_platform.h @@ -52,10 +52,10 @@ #include "openthread-core-config.h" #include -#include "utils/wrap_stdbool.h" -#include "utils/wrap_stdint.h" #include #include +#include "utils/wrap_stdbool.h" +#include "utils/wrap_stdint.h" #include "utils/wrap_string.h" #endif // SPINEL_PLATFORM_OPENTHREAD_H_