[style] converge some common utils (#10982)

This commit converges common utils in core and lib to avoid duplicate
code and conflicts caused by two common utils are included by some
units.
This commit is contained in:
Yakun Xu
2024-12-04 08:39:44 -08:00
committed by GitHub
parent 2868c9ce6b
commit f0d6007cc3
24 changed files with 408 additions and 556 deletions
+1
View File
@@ -38,6 +38,7 @@ config("openthread_config") {
include_dirs += [
"${root_gen_dir}/include",
"include",
"src/include",
]
}
+1
View File
@@ -55,6 +55,7 @@ target_include_directories(ot-config INTERFACE
${PROJECT_SOURCE_DIR}/include
${PROJECT_SOURCE_DIR}/src
${PROJECT_SOURCE_DIR}/src/core
${PROJECT_SOURCE_DIR}/src/include
)
include(TestBigEndian)
-3
View File
@@ -386,7 +386,6 @@ openthread_core_files = [
"coap/coap_secure.hpp",
"common/appender.cpp",
"common/appender.hpp",
"common/arg_macros.hpp",
"common/array.hpp",
"common/as_core_type.hpp",
"common/binary_search.cpp",
@@ -394,7 +393,6 @@ openthread_core_files = [
"common/bit_set.hpp",
"common/callback.hpp",
"common/clearable.hpp",
"common/code_utils.hpp",
"common/const_cast.hpp",
"common/crc16.cpp",
"common/crc16.hpp",
@@ -425,7 +423,6 @@ openthread_core_files = [
"common/logging.hpp",
"common/message.cpp",
"common/message.hpp",
"common/new.hpp",
"common/non_copyable.hpp",
"common/notifier.cpp",
"common/notifier.hpp",
@@ -31,8 +31,8 @@
* This file includes macros for parsing variadic arguments.
*/
#ifndef OT_ARG_MACROS_HPP_
#define OT_ARG_MACROS_HPP_
#ifndef OT_INCLUDE_COMMON_ARG_MACROS_HPP_
#define OT_INCLUDE_COMMON_ARG_MACROS_HPP_
/**
* Returns the first argument in a list of input arguments.
@@ -97,4 +97,4 @@
#define _OT_SELECT_20(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, ...) \
a20
#endif // OT_ARG_MACROS_HPP_
#endif // OT_INCLUDE_COMMON_ARG_MACROS_HPP_
@@ -31,14 +31,12 @@
* This file includes macros for validating runtime conditions.
*/
#ifndef CODE_UTILS_HPP_
#define CODE_UTILS_HPP_
#include <stdbool.h>
#ifndef OT_INCLUDE_COMMON_UTILS_CODE_UTILS_HPP_
#define OT_INCLUDE_COMMON_UTILS_CODE_UTILS_HPP_
#include <openthread/error.h>
#include "common/arg_macros.hpp"
#include "arg_macros.hpp"
/**
* Calculates the number of elements in an array.
@@ -162,4 +160,4 @@
*/
static inline void IgnoreError(otError aError) { OT_UNUSED_VARIABLE(aError); }
#endif // CODE_UTILS_HPP_
#endif // OT_INCLUDE_COMMON_UTILS_CODE_UTILS_HPP_
@@ -31,10 +31,8 @@
* This file defines the new operator used by OpenThread.
*/
#ifndef OT_CORE_COMMON_NEW_HPP_
#define OT_CORE_COMMON_NEW_HPP_
#include "openthread-core-config.h"
#ifndef OT_INCLUDE_COMMON_NEW_HPP_
#define OT_INCLUDE_COMMON_NEW_HPP_
#include <stddef.h>
@@ -42,4 +40,4 @@
inline void *operator new(size_t, void *p) throw() { return p; }
#endif // OT_CORE_COMMON_NEW_HPP_
#endif // OT_INCLUDE_COMMON_NEW_HPP_
-29
View File
@@ -1,29 +0,0 @@
#
# Copyright (c) 2020, The OpenThread Authors.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. Neither the name of the copyright holder nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
ot_list_objects = $(addprefix $(dir $(1)),$(filter %.o,$(shell $(AR) t $(1))))
+11 -11
View File
@@ -34,7 +34,7 @@
#include <stdlib.h>
#include "lib/utils/utils.hpp"
#include "common/code_utils.hpp"
namespace ot {
namespace Hdlc {
@@ -134,14 +134,14 @@ otError Encoder::Encode(uint8_t aByte)
if (HdlcByteNeedsEscape(aByte))
{
EXPECT(mWritePointer.CanWrite(2), error = OT_ERROR_NO_BUFS);
VerifyOrExit(mWritePointer.CanWrite(2), error = OT_ERROR_NO_BUFS);
IGNORE_RETURN(mWritePointer.WriteByte(kEscapeSequence));
IGNORE_RETURN(mWritePointer.WriteByte(aByte ^ 0x20));
IgnoreReturnValue(mWritePointer.WriteByte(kEscapeSequence));
IgnoreReturnValue(mWritePointer.WriteByte(aByte ^ 0x20));
}
else
{
EXPECT_NO_ERROR(error = mWritePointer.WriteByte(aByte));
SuccessOrExit(error = mWritePointer.WriteByte(aByte));
}
mFcs = UpdateFcs(mFcs, aByte);
@@ -158,7 +158,7 @@ otError Encoder::Encode(const uint8_t *aData, uint16_t aLength)
while (aLength--)
{
EXPECT_NO_ERROR(error = Encode(*aData++));
SuccessOrExit(error = Encode(*aData++));
}
exit:
@@ -181,10 +181,10 @@ otError Encoder::EndFrame(void)
fcs ^= 0xffff;
EXPECT_NO_ERROR(error = Encode(fcs & 0xff));
EXPECT_NO_ERROR(error = Encode(fcs >> 8));
SuccessOrExit(error = Encode(fcs & 0xff));
SuccessOrExit(error = Encode(fcs >> 8));
EXPECT_NO_ERROR(error = mWritePointer.WriteByte(kFlagSequence));
SuccessOrExit(error = mWritePointer.WriteByte(kFlagSequence));
exit:
@@ -274,7 +274,7 @@ void Decoder::Decode(const uint8_t *aData, uint16_t aLength)
if (mWritePointer->CanWrite(sizeof(uint8_t)))
{
mFcs = UpdateFcs(mFcs, byte);
IGNORE_RETURN(mWritePointer->WriteByte(byte));
IgnoreReturnValue(mWritePointer->WriteByte(byte));
mDecodedLength++;
}
else
@@ -293,7 +293,7 @@ void Decoder::Decode(const uint8_t *aData, uint16_t aLength)
{
byte ^= 0x20;
mFcs = UpdateFcs(mFcs, byte);
IGNORE_RETURN(mWritePointer->WriteByte(byte));
IgnoreReturnValue(mWritePointer->WriteByte(byte));
mDecodedLength++;
mState = kStateSync;
}
+34 -34
View File
@@ -38,9 +38,9 @@
#include <openthread/logging.h>
#include <openthread/platform/radio.h>
#include "common/code_utils.hpp"
#include "lib/spinel/spinel.h"
#include "lib/utils/math.hpp"
#include "lib/utils/utils.hpp"
namespace ot {
namespace Spinel {
@@ -134,19 +134,19 @@ void Logger::LogSpinelFrame(const uint8_t *aFrame, uint16_t aLength, bool aTx)
char *start = buf;
char *end = buf + sizeof(buf);
EXPECT(otLoggingGetLevel() >= OT_LOG_LEVEL_DEBG, NO_ACTION);
VerifyOrExit(otLoggingGetLevel() >= OT_LOG_LEVEL_DEBG);
prefix = aTx ? "Sent spinel frame" : "Received spinel frame";
unpacked = spinel_datatype_unpack(aFrame, aLength, "CiiD", &header, &cmd, &key, &data, &len);
EXPECT(unpacked > 0, error = OT_ERROR_PARSE);
VerifyOrExit(unpacked > 0, error = OT_ERROR_PARSE);
start += Snprintf(start, static_cast<uint32_t>(end - start), "%s, flg:0x%x, iid:%d, tid:%u, cmd:%s", prefix,
SPINEL_HEADER_GET_FLAG(header), SPINEL_HEADER_GET_IID(header), SPINEL_HEADER_GET_TID(header),
spinel_command_to_cstr(cmd));
EXPECT(cmd != SPINEL_CMD_RESET, NO_ACTION);
VerifyOrExit(cmd != SPINEL_CMD_RESET);
start += Snprintf(start, static_cast<uint32_t>(end - start), ", key:%s", spinel_prop_key_to_cstr(key));
EXPECT(cmd != SPINEL_CMD_PROP_VALUE_GET, NO_ACTION);
VerifyOrExit(cmd != SPINEL_CMD_PROP_VALUE_GET);
switch (key)
{
@@ -155,7 +155,7 @@ void Logger::LogSpinelFrame(const uint8_t *aFrame, uint16_t aLength, bool aTx)
spinel_status_t status;
unpacked = spinel_datatype_unpack(data, len, SPINEL_DATATYPE_UINT_PACKED_S, &status);
EXPECT(unpacked > 0, error = OT_ERROR_PARSE);
VerifyOrExit(unpacked > 0, error = OT_ERROR_PARSE);
start += Snprintf(start, static_cast<uint32_t>(end - start), ", status:%s", spinel_status_to_cstr(status));
}
break;
@@ -168,7 +168,7 @@ void Logger::LogSpinelFrame(const uint8_t *aFrame, uint16_t aLength, bool aTx)
bool enabled;
unpacked = spinel_datatype_unpack(data, len, SPINEL_DATATYPE_BOOL_S, &enabled);
EXPECT(unpacked > 0, error = OT_ERROR_PARSE);
VerifyOrExit(unpacked > 0, error = OT_ERROR_PARSE);
start += Snprintf(start, static_cast<uint32_t>(end - start), ", enabled:%u", enabled);
}
break;
@@ -183,7 +183,7 @@ void Logger::LogSpinelFrame(const uint8_t *aFrame, uint16_t aLength, bool aTx)
int8_t value;
unpacked = spinel_datatype_unpack(data, len, SPINEL_DATATYPE_INT8_S, &value);
EXPECT(unpacked > 0, error = OT_ERROR_PARSE);
VerifyOrExit(unpacked > 0, error = OT_ERROR_PARSE);
switch (key)
{
@@ -218,7 +218,7 @@ void Logger::LogSpinelFrame(const uint8_t *aFrame, uint16_t aLength, bool aTx)
uint8_t value;
unpacked = spinel_datatype_unpack(data, len, SPINEL_DATATYPE_UINT8_S, &value);
EXPECT(unpacked > 0, error = OT_ERROR_PARSE);
VerifyOrExit(unpacked > 0, error = OT_ERROR_PARSE);
switch (key)
{
@@ -252,7 +252,7 @@ void Logger::LogSpinelFrame(const uint8_t *aFrame, uint16_t aLength, bool aTx)
uint16_t value;
unpacked = spinel_datatype_unpack(data, len, SPINEL_DATATYPE_UINT16_S, &value);
EXPECT(unpacked > 0, error = OT_ERROR_PARSE);
VerifyOrExit(unpacked > 0, error = OT_ERROR_PARSE);
switch (key)
{
@@ -292,7 +292,7 @@ void Logger::LogSpinelFrame(const uint8_t *aFrame, uint16_t aLength, bool aTx)
while (len >= sizeof(saddr))
{
unpacked = spinel_datatype_unpack(data, len, SPINEL_DATATYPE_UINT16_S, &saddr);
EXPECT(unpacked > 0, error = OT_ERROR_PARSE);
VerifyOrExit(unpacked > 0, error = OT_ERROR_PARSE);
data += unpacked;
len -= static_cast<spinel_size_t>(unpacked);
start += Snprintf(start, static_cast<uint32_t>(end - start), "0x%04x ", saddr);
@@ -308,7 +308,7 @@ void Logger::LogSpinelFrame(const uint8_t *aFrame, uint16_t aLength, bool aTx)
uint32_t value;
unpacked = spinel_datatype_unpack(data, len, SPINEL_DATATYPE_UINT32_S, &value);
EXPECT(unpacked > 0, error = OT_ERROR_PARSE);
VerifyOrExit(unpacked > 0, error = OT_ERROR_PARSE);
name = (key == SPINEL_PROP_RCP_TIMESTAMP) ? "timestamp" : "counter";
start += Snprintf(start, static_cast<uint32_t>(end - start), ", %s:%u", name, value);
@@ -323,7 +323,7 @@ void Logger::LogSpinelFrame(const uint8_t *aFrame, uint16_t aLength, bool aTx)
unsigned int value;
unpacked = spinel_datatype_unpack(data, len, SPINEL_DATATYPE_UINT_PACKED_S, &value);
EXPECT(unpacked > 0, error = OT_ERROR_PARSE);
VerifyOrExit(unpacked > 0, error = OT_ERROR_PARSE);
switch (key)
{
@@ -362,7 +362,7 @@ void Logger::LogSpinelFrame(const uint8_t *aFrame, uint16_t aLength, bool aTx)
int8_t value;
unpacked = spinel_datatype_unpack(data, len, SPINEL_DATATYPE_UINT8_S SPINEL_DATATYPE_INT8_S, &channel, &value);
EXPECT(unpacked > 0, error = OT_ERROR_PARSE);
VerifyOrExit(unpacked > 0, error = OT_ERROR_PARSE);
name = (key == SPINEL_PROP_MAC_ENERGY_SCAN_RESULT) ? "rssi" : "power";
start += Snprintf(start, static_cast<uint32_t>(end - start), ", channel:%u, %s:%d", channel, name, value);
@@ -378,7 +378,7 @@ void Logger::LogSpinelFrame(const uint8_t *aFrame, uint16_t aLength, bool aTx)
while (len > 0)
{
unpacked = spinel_datatype_unpack(data, len, SPINEL_DATATYPE_UINT_PACKED_S, &capability);
EXPECT(unpacked > 0, error = OT_ERROR_PARSE);
VerifyOrExit(unpacked > 0, error = OT_ERROR_PARSE);
data += unpacked;
len -= static_cast<spinel_size_t>(unpacked);
start += Snprintf(start, static_cast<uint32_t>(end - start), "%s ", spinel_capability_to_cstr(capability));
@@ -393,7 +393,7 @@ void Logger::LogSpinelFrame(const uint8_t *aFrame, uint16_t aLength, bool aTx)
unpacked = spinel_datatype_unpack(data, len, SPINEL_DATATYPE_UINT_PACKED_S SPINEL_DATATYPE_UINT_PACKED_S,
&major, &minor);
EXPECT(unpacked > 0, error = OT_ERROR_PARSE);
VerifyOrExit(unpacked > 0, error = OT_ERROR_PARSE);
start += Snprintf(start, static_cast<uint32_t>(end - start), ", major:%u, minor:%u", major, minor);
}
break;
@@ -407,15 +407,15 @@ void Logger::LogSpinelFrame(const uint8_t *aFrame, uint16_t aLength, bool aTx)
spinel_size_t maskLength = sizeof(maskBuffer);
unpacked = spinel_datatype_unpack_in_place(data, len, SPINEL_DATATYPE_DATA_S, maskBuffer, &maskLength);
EXPECT(unpacked > 0, error = OT_ERROR_PARSE);
VerifyOrExit(unpacked > 0, error = OT_ERROR_PARSE);
while (maskLength > 0)
{
uint8_t channel;
unpacked = spinel_datatype_unpack(maskData, maskLength, SPINEL_DATATYPE_UINT8_S, &channel);
EXPECT(unpacked > 0, error = OT_ERROR_PARSE);
EXPECT(channel < kChannelMaskBufferSize, error = OT_ERROR_PARSE);
VerifyOrExit(unpacked > 0, error = OT_ERROR_PARSE);
VerifyOrExit(channel < kChannelMaskBufferSize, error = OT_ERROR_PARSE);
channelMask |= (1UL << channel);
maskData += unpacked;
@@ -431,7 +431,7 @@ void Logger::LogSpinelFrame(const uint8_t *aFrame, uint16_t aLength, bool aTx)
const char *version;
unpacked = spinel_datatype_unpack(data, len, SPINEL_DATATYPE_UTF8_S, &version);
EXPECT(unpacked >= 0, error = OT_ERROR_PARSE);
VerifyOrExit(unpacked >= 0, error = OT_ERROR_PARSE);
start += Snprintf(start, static_cast<uint32_t>(end - start), ", version:%s", version);
}
break;
@@ -461,7 +461,7 @@ void Logger::LogSpinelFrame(const uint8_t *aFrame, uint16_t aLength, bool aTx)
&frame.mPsdu, &frame.mLength, &frame.mInfo.mRxInfo.mRssi, &noiseFloor,
&flags, &frame.mChannel, &frame.mInfo.mRxInfo.mLqi,
&frame.mInfo.mRxInfo.mTimestamp, &receiveError);
EXPECT(unpacked > 0, error = OT_ERROR_PARSE);
VerifyOrExit(unpacked > 0, error = OT_ERROR_PARSE);
start += Snprintf(start, static_cast<uint32_t>(end - start), ", len:%u, rssi:%d ...", frame.mLength,
frame.mInfo.mRxInfo.mRssi);
OT_UNUSED_VARIABLE(start); // Avoid static analysis error
@@ -496,7 +496,7 @@ void Logger::LogSpinelFrame(const uint8_t *aFrame, uint16_t aLength, bool aTx)
&frame.mInfo.mTxInfo.mMaxFrameRetries, &csmaCaEnabled, &isHeaderUpdated, &isARetx, &skipAes,
&frame.mInfo.mTxInfo.mTxDelay, &frame.mInfo.mTxInfo.mTxDelayBaseTime);
EXPECT(unpacked > 0, error = OT_ERROR_PARSE);
VerifyOrExit(unpacked > 0, error = OT_ERROR_PARSE);
start += Snprintf(start, static_cast<uint32_t>(end - start),
", len:%u, channel:%u, maxbackoffs:%u, maxretries:%u ...", frame.mLength, frame.mChannel,
frame.mInfo.mTxInfo.mMaxCsmaBackoffs, frame.mInfo.mTxInfo.mMaxFrameRetries);
@@ -520,7 +520,7 @@ void Logger::LogSpinelFrame(const uint8_t *aFrame, uint16_t aLength, bool aTx)
unpacked = spinel_datatype_unpack_in_place(data, len, SPINEL_DATATYPE_DATA_S, debugString, &stringLength);
assert(stringLength < sizeof(debugString));
EXPECT(unpacked > 0, error = OT_ERROR_PARSE);
VerifyOrExit(unpacked > 0, error = OT_ERROR_PARSE);
debugString[stringLength] = '\0';
start += Snprintf(start, static_cast<uint32_t>(end - start), ", debug:%s", debugString);
}
@@ -532,12 +532,12 @@ void Logger::LogSpinelFrame(const uint8_t *aFrame, uint16_t aLength, bool aTx)
uint8_t logLevel;
unpacked = spinel_datatype_unpack(data, len, SPINEL_DATATYPE_UTF8_S, &logString);
EXPECT(unpacked >= 0, error = OT_ERROR_PARSE);
VerifyOrExit(unpacked >= 0, error = OT_ERROR_PARSE);
data += unpacked;
len -= static_cast<spinel_size_t>(unpacked);
unpacked = spinel_datatype_unpack(data, len, SPINEL_DATATYPE_UINT8_S, &logLevel);
EXPECT(unpacked > 0, error = OT_ERROR_PARSE);
VerifyOrExit(unpacked > 0, error = OT_ERROR_PARSE);
start += Snprintf(start, static_cast<uint32_t>(end - start), ", level:%u, log:%s", logLevel, logString);
}
break;
@@ -548,7 +548,7 @@ void Logger::LogSpinelFrame(const uint8_t *aFrame, uint16_t aLength, bool aTx)
size_t outputLen;
unpacked = spinel_datatype_unpack(data, len, SPINEL_DATATYPE_UTF8_S, &output, &outputLen);
EXPECT(unpacked > 0, error = OT_ERROR_PARSE);
VerifyOrExit(unpacked > 0, error = OT_ERROR_PARSE);
start += Snprintf(start, static_cast<uint32_t>(end - start), ", diag:%s", output);
}
break;
@@ -569,7 +569,7 @@ void Logger::LogSpinelFrame(const uint8_t *aFrame, uint16_t aLength, bool aTx)
SPINEL_DATATYPE_DATA_WLEN_S SPINEL_DATATYPE_DATA_WLEN_S,
&keyIdMode, &keyId, prevKey.m8, &prevKeyLen, currKey.m8, &currKeyLen,
nextKey.m8, &nextKeyLen);
EXPECT(unpacked > 0, error = OT_ERROR_PARSE);
VerifyOrExit(unpacked > 0, error = OT_ERROR_PARSE);
start += Snprintf(start, static_cast<uint32_t>(end - start),
", keyIdMode:%u, keyId:%u, prevKey:***, currKey:***, nextKey:***", keyIdMode, keyId);
}
@@ -582,7 +582,7 @@ void Logger::LogSpinelFrame(const uint8_t *aFrame, uint16_t aLength, bool aTx)
uint8_t m8[OT_EXT_ADDRESS_SIZE] = {0};
unpacked = spinel_datatype_unpack_in_place(data, len, SPINEL_DATATYPE_EUI64_S, &m8[0]);
EXPECT(unpacked > 0, error = OT_ERROR_PARSE);
VerifyOrExit(unpacked > 0, error = OT_ERROR_PARSE);
name = (key == SPINEL_PROP_HWADDR) ? "eui64" : "laddr";
start += Snprintf(start, static_cast<uint32_t>(end - start), ", %s:%02x%02x%02x%02x%02x%02x%02x%02x", name,
@@ -605,7 +605,7 @@ void Logger::LogSpinelFrame(const uint8_t *aFrame, uint16_t aLength, bool aTx)
while (len >= sizeof(m8))
{
unpacked = spinel_datatype_unpack_in_place(data, len, SPINEL_DATATYPE_EUI64_S, m8);
EXPECT(unpacked > 0, error = OT_ERROR_PARSE);
VerifyOrExit(unpacked > 0, error = OT_ERROR_PARSE);
data += unpacked;
len -= static_cast<spinel_size_t>(unpacked);
start += Snprintf(start, static_cast<uint32_t>(end - start), "%02x%02x%02x%02x%02x%02x%02x%02x ", m8[0],
@@ -649,7 +649,7 @@ void Logger::LogSpinelFrame(const uint8_t *aFrame, uint16_t aLength, bool aTx)
&metrics.mNumRxGrantDeactivatedDuringRequest, &metrics.mNumRxDelayedGrant,
&metrics.mAvgRxRequestToGrantTime, &metrics.mNumRxGrantNone, &metrics.mStopped, &metrics.mNumGrantGlitch);
EXPECT(unpacked > 0, error = OT_ERROR_PARSE);
VerifyOrExit(unpacked > 0, error = OT_ERROR_PARSE);
LogDebg("%s ...", buf);
LogDebg(" txRequest:%lu", ToUlong(metrics.mNumTxRequest));
@@ -683,7 +683,7 @@ void Logger::LogSpinelFrame(const uint8_t *aFrame, uint16_t aLength, bool aTx)
spinel_size_t size;
unpacked = spinel_datatype_unpack(data, len, SPINEL_DATATYPE_DATA_S, channels, &size);
EXPECT(unpacked > 0, error = OT_ERROR_PARSE);
VerifyOrExit(unpacked > 0, error = OT_ERROR_PARSE);
start += Snprintf(start, static_cast<uint32_t>(end - start), ", channels:");
for (spinel_size_t i = 0; i < size; i++)
@@ -702,7 +702,7 @@ void Logger::LogSpinelFrame(const uint8_t *aFrame, uint16_t aLength, bool aTx)
unpacked = spinel_datatype_unpack(
data, len, SPINEL_DATATYPE_UINT16_S SPINEL_DATATYPE_EUI64_S SPINEL_DATATYPE_UINT8_S, &saddr, m8, &flags);
EXPECT(unpacked > 0, error = OT_ERROR_PARSE);
VerifyOrExit(unpacked > 0, error = OT_ERROR_PARSE);
start += Snprintf(start, static_cast<uint32_t>(end - start),
", saddr:%04x, extaddr:%02x%02x%02x%02x%02x%02x%02x%02x, flags:0x%02x", saddr, m8[0], m8[1],
m8[2], m8[3], m8[4], m8[5], m8[6], m8[7], flags);
@@ -721,7 +721,7 @@ void Logger::LogSpinelFrame(const uint8_t *aFrame, uint16_t aLength, bool aTx)
unpacked = spinel_datatype_unpack(
data, len, SPINEL_DATATYPE_UINT8_S SPINEL_DATATYPE_INT16_S SPINEL_DATATYPE_DATA_WLEN_S, &channel,
&actualPower, &rawPowerSetting, &rawPowerSettingLength);
EXPECT(unpacked > 0, error = OT_ERROR_PARSE);
VerifyOrExit(unpacked > 0, error = OT_ERROR_PARSE);
start += Snprintf(start, static_cast<uint32_t>(end - start),
", ch:%u, actualPower:%d, rawPowerSetting:", channel, actualPower);
@@ -740,7 +740,7 @@ void Logger::LogSpinelFrame(const uint8_t *aFrame, uint16_t aLength, bool aTx)
unpacked =
spinel_datatype_unpack(data, len, SPINEL_DATATYPE_UINT8_S SPINEL_DATATYPE_INT16_S, &channel, &targetPower);
EXPECT(unpacked > 0, error = OT_ERROR_PARSE);
VerifyOrExit(unpacked > 0, error = OT_ERROR_PARSE);
start += Snprintf(start, static_cast<uint32_t>(end - start), ", ch:%u, targetPower:%d", channel, targetPower);
}
break;
+120 -120
View File
@@ -34,7 +34,6 @@
#include "radio_spinel.hpp"
#include <assert.h>
#include <errno.h>
#include <stdarg.h>
#include <stdlib.h>
@@ -43,12 +42,12 @@
#include <openthread/platform/diag.h>
#include <openthread/platform/time.h>
#include "common/code_utils.hpp"
#include "common/new.hpp"
#include "lib/platform/exit_code.h"
#include "lib/spinel/logger.hpp"
#include "lib/spinel/spinel_decoder.hpp"
#include "lib/spinel/spinel_driver.hpp"
#include "lib/spinel/spinel_helper.hpp"
#include "lib/utils/utils.hpp"
namespace ot {
namespace Spinel {
@@ -150,13 +149,13 @@ void RadioSpinel::Init(bool aSkipRcpVersionCheck,
mTxRadioFrame.mInfo.mTxInfo.mIeInfo = &mTxIeInfo;
#endif
EXPECT_NO_ERROR(error = Get(SPINEL_PROP_HWADDR, SPINEL_DATATYPE_EUI64_S, sIeeeEui64.m8));
SuccessOrExit(error = Get(SPINEL_PROP_HWADDR, SPINEL_DATATYPE_EUI64_S, sIeeeEui64.m8));
InitializeCaps(supportsRcpApiVersion, supportsRcpMinHostApiVersion);
if (sSupportsLogCrashDump)
{
LogDebg("RCP supports crash dump logging. Requesting crash dump.");
EXPECT_NO_ERROR(error = Set(SPINEL_PROP_RCP_LOG_CRASH_DUMP, nullptr));
SuccessOrExit(error = Set(SPINEL_PROP_RCP_LOG_CRASH_DUMP, nullptr));
}
if (!aSkipRcpVersionCheck)
@@ -194,9 +193,9 @@ otError RadioSpinel::CheckSpinelVersion(void)
unsigned int versionMajor;
unsigned int versionMinor;
EXPECT_NO_ERROR(error =
Get(SPINEL_PROP_PROTOCOL_VERSION, (SPINEL_DATATYPE_UINT_PACKED_S SPINEL_DATATYPE_UINT_PACKED_S),
&versionMajor, &versionMinor));
SuccessOrExit(error =
Get(SPINEL_PROP_PROTOCOL_VERSION, (SPINEL_DATATYPE_UINT_PACKED_S SPINEL_DATATYPE_UINT_PACKED_S),
&versionMajor, &versionMinor));
if ((versionMajor != SPINEL_PROTOCOL_VERSION_THREAD_MAJOR) ||
(versionMinor != SPINEL_PROTOCOL_VERSION_THREAD_MINOR))
@@ -240,7 +239,7 @@ otError RadioSpinel::CheckRadioCapabilities(otRadioCaps aRequiredRadioCaps)
otError error = OT_ERROR_NONE;
unsigned int radioCaps;
EXPECT_NO_ERROR(error = Get(SPINEL_PROP_RADIO_CAPS, SPINEL_DATATYPE_UINT_PACKED_S, &radioCaps));
SuccessOrExit(error = Get(SPINEL_PROP_RADIO_CAPS, SPINEL_DATATYPE_UINT_PACKED_S, &radioCaps));
sRadioCaps = static_cast<otRadioCaps>(radioCaps);
if ((sRadioCaps & aRequiredRadioCaps) != aRequiredRadioCaps)
@@ -277,7 +276,7 @@ otError RadioSpinel::CheckRcpApiVersion(bool aSupportsRcpApiVersion, bool aSuppo
unsigned int rcpApiVersion;
EXPECT_NO_ERROR(error = Get(SPINEL_PROP_RCP_API_VERSION, SPINEL_DATATYPE_UINT_PACKED_S, &rcpApiVersion));
SuccessOrExit(error = Get(SPINEL_PROP_RCP_API_VERSION, SPINEL_DATATYPE_UINT_PACKED_S, &rcpApiVersion));
if (rcpApiVersion < SPINEL_MIN_HOST_SUPPORTED_RCP_API_VERSION)
{
@@ -296,7 +295,7 @@ otError RadioSpinel::CheckRcpApiVersion(bool aSupportsRcpApiVersion, bool aSuppo
unsigned int minHostRcpApiVersion;
EXPECT_NO_ERROR(
SuccessOrExit(
error = Get(SPINEL_PROP_RCP_MIN_HOST_API_VERSION, SPINEL_DATATYPE_UINT_PACKED_S, &minHostRcpApiVersion));
if (SPINEL_RCP_API_VERSION < minHostRcpApiVersion)
@@ -332,8 +331,8 @@ void RadioSpinel::HandleNotification(const uint8_t *aFrame, uint16_t aLength, bo
unpacked = spinel_datatype_unpack(aFrame, aLength, "CiiD", &header, &cmd, &key, &data, &len);
EXPECT(unpacked > 0, error = OT_ERROR_PARSE);
EXPECT(SPINEL_HEADER_GET_TID(header) == 0, error = OT_ERROR_PARSE);
VerifyOrExit(unpacked > 0, error = OT_ERROR_PARSE);
VerifyOrExit(SPINEL_HEADER_GET_TID(header) == 0, error = OT_ERROR_PARSE);
switch (cmd)
{
@@ -344,7 +343,7 @@ void RadioSpinel::HandleNotification(const uint8_t *aFrame, uint16_t aLength, bo
if (!IsSafeToHandleNow(key))
{
EXIT_NOW(aShouldSaveFrame = true);
ExitNow(aShouldSaveFrame = true);
}
HandleValueIs(key, data, static_cast<uint16_t>(len));
@@ -356,7 +355,7 @@ void RadioSpinel::HandleNotification(const uint8_t *aFrame, uint16_t aLength, bo
break;
default:
EXIT_NOW(error = OT_ERROR_PARSE);
ExitNow(error = OT_ERROR_PARSE);
}
exit:
@@ -376,9 +375,9 @@ void RadioSpinel::HandleNotification(const uint8_t *aFrame, uint16_t aLength)
otError error = OT_ERROR_NONE;
unpacked = spinel_datatype_unpack(aFrame, aLength, "CiiD", &header, &cmd, &key, &data, &len);
EXPECT(unpacked > 0, error = OT_ERROR_PARSE);
EXPECT(SPINEL_HEADER_GET_TID(header) == 0, error = OT_ERROR_PARSE);
EXPECT(cmd == SPINEL_CMD_PROP_VALUE_IS, NO_ACTION);
VerifyOrExit(unpacked > 0, error = OT_ERROR_PARSE);
VerifyOrExit(SPINEL_HEADER_GET_TID(header) == 0, error = OT_ERROR_PARSE);
VerifyOrExit(cmd == SPINEL_CMD_PROP_VALUE_IS);
HandleValueIs(key, data, static_cast<uint16_t>(len));
exit:
@@ -397,7 +396,8 @@ void RadioSpinel::HandleResponse(const uint8_t *aBuffer, uint16_t aLength)
otError error = OT_ERROR_NONE;
rval = spinel_datatype_unpack(aBuffer, aLength, "CiiD", &header, &cmd, &key, &data, &len);
EXPECT(rval > 0 && cmd >= SPINEL_CMD_PROP_VALUE_IS && cmd <= SPINEL_CMD_PROP_VALUE_REMOVED, error = OT_ERROR_PARSE);
VerifyOrExit(rval > 0 && cmd >= SPINEL_CMD_PROP_VALUE_IS && cmd <= SPINEL_CMD_PROP_VALUE_REMOVED,
error = OT_ERROR_PARSE);
if (mWaitingTid == SPINEL_HEADER_GET_TID(header))
{
@@ -436,7 +436,7 @@ void RadioSpinel::HandleWaitingResponse(uint32_t aCommand,
spinel_status_t status;
spinel_ssize_t unpacked = spinel_datatype_unpack(aBuffer, aLength, "i", &status);
EXPECT(unpacked > 0, mError = OT_ERROR_PARSE);
VerifyOrExit(unpacked > 0, mError = OT_ERROR_PARSE);
mError = SpinelStatusToOtError(status);
}
#if OPENTHREAD_CONFIG_DIAG_ENABLE
@@ -446,9 +446,9 @@ void RadioSpinel::HandleWaitingResponse(uint32_t aCommand,
const char *diagOutput;
mError = OT_ERROR_NONE;
EXPECT(mOutputCallback != nullptr, NO_ACTION);
VerifyOrExit(mOutputCallback != nullptr);
unpacked = spinel_datatype_unpack(aBuffer, aLength, SPINEL_DATATYPE_UTF8_S, &diagOutput);
EXPECT(unpacked > 0, mError = OT_ERROR_PARSE);
VerifyOrExit(unpacked > 0, mError = OT_ERROR_PARSE);
PlatDiagOutput("%s", diagOutput);
}
#endif
@@ -469,7 +469,7 @@ void RadioSpinel::HandleWaitingResponse(uint32_t aCommand,
spinel_ssize_t unpacked =
spinel_datatype_vunpack_in_place(aBuffer, aLength, mPropertyFormat, mPropertyArgs);
EXPECT(unpacked > 0, mError = OT_ERROR_PARSE);
VerifyOrExit(unpacked > 0, mError = OT_ERROR_PARSE);
mError = OT_ERROR_NONE;
}
}
@@ -502,7 +502,7 @@ void RadioSpinel::HandleValueIs(spinel_prop_key_t aKey, const uint8_t *aBuffer,
if (aKey == SPINEL_PROP_STREAM_RAW)
{
EXPECT_NO_ERROR(error = ParseRadioFrame(mRxRadioFrame, aBuffer, aLength, unpacked));
SuccessOrExit(error = ParseRadioFrame(mRxRadioFrame, aBuffer, aLength, unpacked));
RadioReceive();
}
else if (aKey == SPINEL_PROP_LAST_STATUS)
@@ -510,14 +510,14 @@ void RadioSpinel::HandleValueIs(spinel_prop_key_t aKey, const uint8_t *aBuffer,
spinel_status_t status = SPINEL_STATUS_OK;
unpacked = spinel_datatype_unpack(aBuffer, aLength, "i", &status);
EXPECT(unpacked > 0, error = OT_ERROR_PARSE);
VerifyOrExit(unpacked > 0, error = OT_ERROR_PARSE);
if (status >= SPINEL_STATUS_RESET__BEGIN && status <= SPINEL_STATUS_RESET__END)
{
if (IsEnabled())
{
HandleRcpUnexpectedReset(status);
EXIT_NOW();
ExitNow();
}
// this clear is necessary in case the RCP has sent messages between disable and reset
@@ -545,7 +545,7 @@ void RadioSpinel::HandleValueIs(spinel_prop_key_t aKey, const uint8_t *aBuffer,
unpacked = spinel_datatype_unpack(aBuffer, aLength, "Cc", &scanChannel, &maxRssi);
EXPECT(unpacked > 0, error = OT_ERROR_PARSE);
VerifyOrExit(unpacked > 0, error = OT_ERROR_PARSE);
#if OPENTHREAD_SPINEL_CONFIG_RCP_RESTORATION_MAX_COUNT > 0
mEnergyScanning = false;
@@ -560,7 +560,7 @@ void RadioSpinel::HandleValueIs(spinel_prop_key_t aKey, const uint8_t *aBuffer,
unpacked = spinel_datatype_unpack_in_place(aBuffer, aLength, SPINEL_DATATYPE_DATA_S, logStream, &len);
assert(len < sizeof(logStream));
EXPECT(unpacked > 0, error = OT_ERROR_PARSE);
VerifyOrExit(unpacked > 0, error = OT_ERROR_PARSE);
logStream[len] = '\0';
LogDebg("RCP => %s", logStream);
}
@@ -570,12 +570,12 @@ void RadioSpinel::HandleValueIs(spinel_prop_key_t aKey, const uint8_t *aBuffer,
uint8_t logLevel;
unpacked = spinel_datatype_unpack(aBuffer, aLength, SPINEL_DATATYPE_UTF8_S, &logString);
EXPECT(unpacked >= 0, error = OT_ERROR_PARSE);
VerifyOrExit(unpacked >= 0, error = OT_ERROR_PARSE);
aBuffer += unpacked;
aLength -= unpacked;
unpacked = spinel_datatype_unpack(aBuffer, aLength, SPINEL_DATATYPE_UINT8_S, &logLevel);
EXPECT(unpacked > 0, error = OT_ERROR_PARSE);
VerifyOrExit(unpacked > 0, error = OT_ERROR_PARSE);
switch (logLevel)
{
@@ -609,9 +609,9 @@ void RadioSpinel::HandleValueIs(spinel_prop_key_t aKey, const uint8_t *aBuffer,
{
const char *diagOutput;
EXPECT(mOutputCallback != nullptr, NO_ACTION);
VerifyOrExit(mOutputCallback != nullptr);
unpacked = spinel_datatype_unpack(aBuffer, aLength, SPINEL_DATATYPE_UTF8_S, &diagOutput);
EXPECT(unpacked > 0, error = OT_ERROR_PARSE);
VerifyOrExit(unpacked > 0, error = OT_ERROR_PARSE);
PlatDiagOutput("%s", diagOutput);
}
#endif
@@ -648,7 +648,7 @@ otError RadioSpinel::SendReset(uint8_t aResetType)
if ((aResetType == SPINEL_RESET_BOOTLOADER) && !sSupportsResetToBootloader)
{
EXIT_NOW(error = OT_ERROR_NOT_CAPABLE);
ExitNow(error = OT_ERROR_NOT_CAPABLE);
}
error = GetSpinelDriver().SendReset(aResetType);
@@ -668,7 +668,7 @@ otError RadioSpinel::ParseRadioFrame(otRadioFrame &aFrame,
unsigned int receiveError = 0;
spinel_ssize_t unpacked;
EXPECT(aLength > 0, aFrame.mLength = 0);
VerifyOrExit(aLength > 0, aFrame.mLength = 0);
unpacked = spinel_datatype_unpack_in_place(aBuffer, aLength,
SPINEL_DATATYPE_DATA_WLEN_S // Frame
@@ -686,7 +686,7 @@ otError RadioSpinel::ParseRadioFrame(otRadioFrame &aFrame,
&aFrame.mChannel, &aFrame.mInfo.mRxInfo.mLqi,
&aFrame.mInfo.mRxInfo.mTimestamp, &receiveError);
EXPECT(unpacked > 0, error = OT_ERROR_PARSE);
VerifyOrExit(unpacked > 0, error = OT_ERROR_PARSE);
aUnpacked = unpacked;
aBuffer += unpacked;
@@ -702,7 +702,7 @@ otError RadioSpinel::ParseRadioFrame(otRadioFrame &aFrame,
),
&aFrame.mInfo.mRxInfo.mAckKeyId, &aFrame.mInfo.mRxInfo.mAckFrameCounter);
EXPECT(unpacked > 0, error = OT_ERROR_PARSE);
VerifyOrExit(unpacked > 0, error = OT_ERROR_PARSE);
aUnpacked += unpacked;
#if OPENTHREAD_SPINEL_CONFIG_RCP_RESTORATION_MAX_COUNT > 0
@@ -743,7 +743,7 @@ void RadioSpinel::RadioReceive(void)
{
case kStateDisabled:
case kStateSleep:
EXIT_NOW();
ExitNow();
case kStateReceive:
case kStateTransmitting:
@@ -815,7 +815,7 @@ otError RadioSpinel::SetPromiscuous(bool aEnable)
otError error;
uint8_t mode = (aEnable ? SPINEL_MAC_PROMISCUOUS_MODE_NETWORK : SPINEL_MAC_PROMISCUOUS_MODE_OFF);
EXPECT_NO_ERROR(error = Set(SPINEL_PROP_MAC_PROMISCUOUS_MODE, SPINEL_DATATYPE_UINT8_S, mode));
SuccessOrExit(error = Set(SPINEL_PROP_MAC_PROMISCUOUS_MODE, SPINEL_DATATYPE_UINT8_S, mode));
mIsPromiscuous = aEnable;
exit:
@@ -826,8 +826,8 @@ otError RadioSpinel::SetRxOnWhenIdle(bool aEnable)
{
otError error = OT_ERROR_NONE;
EXPECT(mRxOnWhenIdle != aEnable, NO_ACTION);
EXPECT_NO_ERROR(error = Set(SPINEL_PROP_MAC_RX_ON_WHEN_IDLE_MODE, SPINEL_DATATYPE_BOOL_S, aEnable));
VerifyOrExit(mRxOnWhenIdle != aEnable);
SuccessOrExit(error = Set(SPINEL_PROP_MAC_RX_ON_WHEN_IDLE_MODE, SPINEL_DATATYPE_BOOL_S, aEnable));
mRxOnWhenIdle = aEnable;
exit:
@@ -838,8 +838,8 @@ otError RadioSpinel::SetShortAddress(uint16_t aAddress)
{
otError error = OT_ERROR_NONE;
EXPECT(mShortAddress != aAddress, NO_ACTION);
EXPECT_NO_ERROR(error = Set(SPINEL_PROP_MAC_15_4_SADDR, SPINEL_DATATYPE_UINT16_S, aAddress));
VerifyOrExit(mShortAddress != aAddress);
SuccessOrExit(error = Set(SPINEL_PROP_MAC_15_4_SADDR, SPINEL_DATATYPE_UINT16_S, aAddress));
mShortAddress = aAddress;
exit:
@@ -864,8 +864,8 @@ otError RadioSpinel::ReadMacKey(const otMacKeyMaterial &aKeyMaterial, otMacKey &
size_t keySize;
otError error = otPlatCryptoExportKey(aKeyMaterial.mKeyMaterial.mKeyRef, aKey.m8, sizeof(aKey), &keySize);
EXPECT_NO_ERROR(error);
EXPECT(keySize == sizeof(otMacKey), error = OT_ERROR_FAILED);
SuccessOrExit(error);
VerifyOrExit(keySize == sizeof(otMacKey), error = OT_ERROR_FAILED);
exit:
return error;
@@ -882,9 +882,9 @@ otError RadioSpinel::SetMacKey(uint8_t aKeyIdMode,
otMacKey currKey;
otMacKey nextKey;
EXPECT_NO_ERROR(error = ReadMacKey(*aPrevKey, prevKey));
EXPECT_NO_ERROR(error = ReadMacKey(*aCurrKey, currKey));
EXPECT_NO_ERROR(error = ReadMacKey(*aNextKey, nextKey));
SuccessOrExit(error = ReadMacKey(*aPrevKey, prevKey));
SuccessOrExit(error = ReadMacKey(*aCurrKey, currKey));
SuccessOrExit(error = ReadMacKey(*aNextKey, nextKey));
error = SetMacKey(aKeyIdMode, aKeyId, prevKey, currKey, nextKey);
exit:
@@ -913,11 +913,11 @@ otError RadioSpinel::SetMacKey(uint8_t aKeyIdMode,
{
otError error;
EXPECT_NO_ERROR(error = Set(SPINEL_PROP_RCP_MAC_KEY,
SPINEL_DATATYPE_UINT8_S SPINEL_DATATYPE_UINT8_S SPINEL_DATATYPE_DATA_WLEN_S
SPINEL_DATATYPE_DATA_WLEN_S SPINEL_DATATYPE_DATA_WLEN_S,
aKeyIdMode, aKeyId, aPrevKey.m8, sizeof(aPrevKey), aCurrKey.m8, sizeof(aCurrKey),
aNextKey.m8, sizeof(aNextKey)));
SuccessOrExit(error = Set(SPINEL_PROP_RCP_MAC_KEY,
SPINEL_DATATYPE_UINT8_S SPINEL_DATATYPE_UINT8_S SPINEL_DATATYPE_DATA_WLEN_S
SPINEL_DATATYPE_DATA_WLEN_S SPINEL_DATATYPE_DATA_WLEN_S,
aKeyIdMode, aKeyId, aPrevKey.m8, sizeof(aPrevKey), aCurrKey.m8, sizeof(aCurrKey),
aNextKey.m8, sizeof(aNextKey)));
#if OPENTHREAD_SPINEL_CONFIG_RCP_RESTORATION_MAX_COUNT > 0
mKeyIdMode = aKeyIdMode;
@@ -938,8 +938,8 @@ otError RadioSpinel::SetMacFrameCounter(uint32_t aMacFrameCounter, bool aSetIfLa
{
otError error;
EXPECT_NO_ERROR(error = Set(SPINEL_PROP_RCP_MAC_FRAME_COUNTER, SPINEL_DATATYPE_UINT32_S SPINEL_DATATYPE_BOOL_S,
aMacFrameCounter, aSetIfLarger));
SuccessOrExit(error = Set(SPINEL_PROP_RCP_MAC_FRAME_COUNTER, SPINEL_DATATYPE_UINT32_S SPINEL_DATATYPE_BOOL_S,
aMacFrameCounter, aSetIfLarger));
#if OPENTHREAD_SPINEL_CONFIG_RCP_RESTORATION_MAX_COUNT > 0
mMacFrameCounterSet = true;
#endif
@@ -959,7 +959,7 @@ otError RadioSpinel::SetExtendedAddress(const otExtAddress &aExtAddress)
{
otError error;
EXPECT_NO_ERROR(error = Set(SPINEL_PROP_MAC_15_4_LADDR, SPINEL_DATATYPE_EUI64_S, aExtAddress.m8));
SuccessOrExit(error = Set(SPINEL_PROP_MAC_15_4_LADDR, SPINEL_DATATYPE_EUI64_S, aExtAddress.m8));
mExtendedAddress = aExtAddress;
exit:
@@ -970,8 +970,8 @@ otError RadioSpinel::SetPanId(uint16_t aPanId)
{
otError error = OT_ERROR_NONE;
EXPECT(mPanId != aPanId, NO_ACTION);
EXPECT_NO_ERROR(error = Set(SPINEL_PROP_MAC_15_4_PANID, SPINEL_DATATYPE_UINT16_S, aPanId));
VerifyOrExit(mPanId != aPanId);
SuccessOrExit(error = Set(SPINEL_PROP_MAC_15_4_PANID, SPINEL_DATATYPE_UINT16_S, aPanId));
mPanId = aPanId;
exit:
@@ -982,7 +982,7 @@ otError RadioSpinel::EnableSrcMatch(bool aEnable)
{
otError error;
EXPECT_NO_ERROR(error = Set(SPINEL_PROP_MAC_SRC_MATCH_ENABLED, SPINEL_DATATYPE_BOOL_S, aEnable));
SuccessOrExit(error = Set(SPINEL_PROP_MAC_SRC_MATCH_ENABLED, SPINEL_DATATYPE_BOOL_S, aEnable));
#if OPENTHREAD_SPINEL_CONFIG_RCP_RESTORATION_MAX_COUNT > 0
mSrcMatchSet = true;
@@ -998,10 +998,10 @@ otError RadioSpinel::AddSrcMatchShortEntry(uint16_t aShortAddress)
otError error;
#if OPENTHREAD_SPINEL_CONFIG_RCP_RESTORATION_MAX_COUNT > 0
EXPECT(mSrcMatchShortEntryCount < OPENTHREAD_SPINEL_CONFIG_MAX_SRC_MATCH_ENTRIES, error = OT_ERROR_NO_BUFS);
VerifyOrExit(mSrcMatchShortEntryCount < OPENTHREAD_SPINEL_CONFIG_MAX_SRC_MATCH_ENTRIES, error = OT_ERROR_NO_BUFS);
#endif
EXPECT_NO_ERROR(error = Insert(SPINEL_PROP_MAC_SRC_MATCH_SHORT_ADDRESSES, SPINEL_DATATYPE_UINT16_S, aShortAddress));
SuccessOrExit(error = Insert(SPINEL_PROP_MAC_SRC_MATCH_SHORT_ADDRESSES, SPINEL_DATATYPE_UINT16_S, aShortAddress));
#if OPENTHREAD_SPINEL_CONFIG_RCP_RESTORATION_MAX_COUNT > 0
@@ -1009,7 +1009,7 @@ otError RadioSpinel::AddSrcMatchShortEntry(uint16_t aShortAddress)
{
if (mSrcMatchShortEntries[i] == aShortAddress)
{
EXIT_NOW();
ExitNow();
}
}
mSrcMatchShortEntries[mSrcMatchShortEntryCount] = aShortAddress;
@@ -1025,11 +1025,11 @@ otError RadioSpinel::AddSrcMatchExtEntry(const otExtAddress &aExtAddress)
otError error;
#if OPENTHREAD_SPINEL_CONFIG_RCP_RESTORATION_MAX_COUNT > 0
EXPECT(mSrcMatchExtEntryCount < OPENTHREAD_SPINEL_CONFIG_MAX_SRC_MATCH_ENTRIES, error = OT_ERROR_NO_BUFS);
VerifyOrExit(mSrcMatchExtEntryCount < OPENTHREAD_SPINEL_CONFIG_MAX_SRC_MATCH_ENTRIES, error = OT_ERROR_NO_BUFS);
#endif
EXPECT_NO_ERROR(error =
Insert(SPINEL_PROP_MAC_SRC_MATCH_EXTENDED_ADDRESSES, SPINEL_DATATYPE_EUI64_S, aExtAddress.m8));
SuccessOrExit(error =
Insert(SPINEL_PROP_MAC_SRC_MATCH_EXTENDED_ADDRESSES, SPINEL_DATATYPE_EUI64_S, aExtAddress.m8));
#if OPENTHREAD_SPINEL_CONFIG_RCP_RESTORATION_MAX_COUNT > 0
@@ -1037,7 +1037,7 @@ otError RadioSpinel::AddSrcMatchExtEntry(const otExtAddress &aExtAddress)
{
if (memcmp(aExtAddress.m8, mSrcMatchExtEntries[i].m8, OT_EXT_ADDRESS_SIZE) == 0)
{
EXIT_NOW();
ExitNow();
}
}
mSrcMatchExtEntries[mSrcMatchExtEntryCount] = aExtAddress;
@@ -1052,7 +1052,7 @@ otError RadioSpinel::ClearSrcMatchShortEntry(uint16_t aShortAddress)
{
otError error;
EXPECT_NO_ERROR(error = Remove(SPINEL_PROP_MAC_SRC_MATCH_SHORT_ADDRESSES, SPINEL_DATATYPE_UINT16_S, aShortAddress));
SuccessOrExit(error = Remove(SPINEL_PROP_MAC_SRC_MATCH_SHORT_ADDRESSES, SPINEL_DATATYPE_UINT16_S, aShortAddress));
#if OPENTHREAD_SPINEL_CONFIG_RCP_RESTORATION_MAX_COUNT > 0
for (int i = 0; i < mSrcMatchShortEntryCount; ++i)
@@ -1074,8 +1074,8 @@ otError RadioSpinel::ClearSrcMatchExtEntry(const otExtAddress &aExtAddress)
{
otError error;
EXPECT_NO_ERROR(error =
Remove(SPINEL_PROP_MAC_SRC_MATCH_EXTENDED_ADDRESSES, SPINEL_DATATYPE_EUI64_S, aExtAddress.m8));
SuccessOrExit(error =
Remove(SPINEL_PROP_MAC_SRC_MATCH_EXTENDED_ADDRESSES, SPINEL_DATATYPE_EUI64_S, aExtAddress.m8));
#if OPENTHREAD_SPINEL_CONFIG_RCP_RESTORATION_MAX_COUNT > 0
for (int i = 0; i < mSrcMatchExtEntryCount; ++i)
@@ -1097,7 +1097,7 @@ otError RadioSpinel::ClearSrcMatchShortEntries(void)
{
otError error;
EXPECT_NO_ERROR(error = Set(SPINEL_PROP_MAC_SRC_MATCH_SHORT_ADDRESSES, nullptr));
SuccessOrExit(error = Set(SPINEL_PROP_MAC_SRC_MATCH_SHORT_ADDRESSES, nullptr));
#if OPENTHREAD_SPINEL_CONFIG_RCP_RESTORATION_MAX_COUNT > 0
mSrcMatchShortEntryCount = 0;
@@ -1111,7 +1111,7 @@ otError RadioSpinel::ClearSrcMatchExtEntries(void)
{
otError error;
EXPECT_NO_ERROR(error = Set(SPINEL_PROP_MAC_SRC_MATCH_EXTENDED_ADDRESSES, nullptr));
SuccessOrExit(error = Set(SPINEL_PROP_MAC_SRC_MATCH_EXTENDED_ADDRESSES, nullptr));
#if OPENTHREAD_SPINEL_CONFIG_RCP_RESTORATION_MAX_COUNT > 0
mSrcMatchExtEntryCount = 0;
@@ -1159,7 +1159,7 @@ otError RadioSpinel::SetCoexEnabled(bool aEnabled)
{
otError error;
EXPECT_NO_ERROR(error = Set(SPINEL_PROP_RADIO_COEX_ENABLE, SPINEL_DATATYPE_BOOL_S, aEnabled));
SuccessOrExit(error = Set(SPINEL_PROP_RADIO_COEX_ENABLE, SPINEL_DATATYPE_BOOL_S, aEnabled));
#if OPENTHREAD_SPINEL_CONFIG_RCP_RESTORATION_MAX_COUNT > 0
mCoexEnabled = aEnabled;
@@ -1223,7 +1223,7 @@ otError RadioSpinel::SetTransmitPower(int8_t aPower)
{
otError error;
EXPECT_NO_ERROR(error = Set(SPINEL_PROP_PHY_TX_POWER, SPINEL_DATATYPE_INT8_S, aPower));
SuccessOrExit(error = Set(SPINEL_PROP_PHY_TX_POWER, SPINEL_DATATYPE_INT8_S, aPower));
#if OPENTHREAD_SPINEL_CONFIG_RCP_RESTORATION_MAX_COUNT > 0
mTransmitPower = aPower;
@@ -1239,7 +1239,7 @@ otError RadioSpinel::SetCcaEnergyDetectThreshold(int8_t aThreshold)
{
otError error;
EXPECT_NO_ERROR(error = Set(SPINEL_PROP_PHY_CCA_THRESHOLD, SPINEL_DATATYPE_INT8_S, aThreshold));
SuccessOrExit(error = Set(SPINEL_PROP_PHY_CCA_THRESHOLD, SPINEL_DATATYPE_INT8_S, aThreshold));
#if OPENTHREAD_SPINEL_CONFIG_RCP_RESTORATION_MAX_COUNT > 0
mCcaEnergyDetectThreshold = aThreshold;
@@ -1255,7 +1255,7 @@ otError RadioSpinel::SetFemLnaGain(int8_t aGain)
{
otError error;
EXPECT_NO_ERROR(error = Set(SPINEL_PROP_PHY_FEM_LNA_GAIN, SPINEL_DATATYPE_INT8_S, aGain));
SuccessOrExit(error = Set(SPINEL_PROP_PHY_FEM_LNA_GAIN, SPINEL_DATATYPE_INT8_S, aGain));
#if OPENTHREAD_SPINEL_CONFIG_RCP_RESTORATION_MAX_COUNT > 0
mFemLnaGain = aGain;
@@ -1271,7 +1271,7 @@ otError RadioSpinel::EnergyScan(uint8_t aScanChannel, uint16_t aScanDuration)
{
otError error;
EXPECT(sRadioCaps & OT_RADIO_CAPS_ENERGY_SCAN, error = OT_ERROR_NOT_CAPABLE);
VerifyOrExit(sRadioCaps & OT_RADIO_CAPS_ENERGY_SCAN, error = OT_ERROR_NOT_CAPABLE);
#if OPENTHREAD_SPINEL_CONFIG_RCP_RESTORATION_MAX_COUNT > 0
mScanChannel = aScanChannel;
@@ -1279,9 +1279,9 @@ otError RadioSpinel::EnergyScan(uint8_t aScanChannel, uint16_t aScanDuration)
mEnergyScanning = true;
#endif
EXPECT_NO_ERROR(error = Set(SPINEL_PROP_MAC_SCAN_MASK, SPINEL_DATATYPE_DATA_S, &aScanChannel, sizeof(uint8_t)));
EXPECT_NO_ERROR(error = Set(SPINEL_PROP_MAC_SCAN_PERIOD, SPINEL_DATATYPE_UINT16_S, aScanDuration));
EXPECT_NO_ERROR(error = Set(SPINEL_PROP_MAC_SCAN_STATE, SPINEL_DATATYPE_UINT8_S, SPINEL_SCAN_STATE_ENERGY));
SuccessOrExit(error = Set(SPINEL_PROP_MAC_SCAN_MASK, SPINEL_DATATYPE_DATA_S, &aScanChannel, sizeof(uint8_t)));
SuccessOrExit(error = Set(SPINEL_PROP_MAC_SCAN_PERIOD, SPINEL_DATATYPE_UINT16_S, aScanDuration));
SuccessOrExit(error = Set(SPINEL_PROP_MAC_SCAN_STATE, SPINEL_DATATYPE_UINT8_S, SPINEL_SCAN_STATE_ENERGY));
mChannel = aScanChannel;
@@ -1421,7 +1421,7 @@ otError RadioSpinel::WaitResponse(bool aHandleRcpTimeout)
{
HandleRcpTimeout();
}
EXIT_NOW(mError = OT_ERROR_RESPONSE_TIMEOUT);
ExitNow(mError = OT_ERROR_RESPONSE_TIMEOUT);
}
} while (mWaitingTid);
@@ -1446,7 +1446,7 @@ spinel_tid_t RadioSpinel::GetNextTid(void)
// We looped back to `mCmdNextTid` indicating that all
// TIDs are in-use.
EXIT_NOW(tid = 0);
ExitNow(tid = 0);
}
}
@@ -1462,16 +1462,16 @@ otError RadioSpinel::RequestV(uint32_t command, spinel_prop_key_t aKey, const ch
otError error = OT_ERROR_NONE;
spinel_tid_t tid = GetNextTid();
EXPECT(tid > 0, error = OT_ERROR_BUSY);
VerifyOrExit(tid > 0, error = OT_ERROR_BUSY);
error = GetSpinelDriver().SendCommand(command, aKey, tid, aFormat, aArgs);
EXPECT_NO_ERROR(error);
SuccessOrExit(error);
if (aKey == SPINEL_PROP_STREAM_RAW)
{
// not allowed to send another frame before the last frame is done.
assert(mTxRadioTid == 0);
EXPECT(mTxRadioTid == 0, error = OT_ERROR_BUSY);
VerifyOrExit(mTxRadioTid == 0, error = OT_ERROR_BUSY);
mTxRadioTid = tid;
}
else
@@ -1551,29 +1551,29 @@ void RadioSpinel::HandleTransmitDone(uint32_t aCommand,
bool headerUpdated = false;
spinel_ssize_t unpacked;
EXPECT(aCommand == SPINEL_CMD_PROP_VALUE_IS && aKey == SPINEL_PROP_LAST_STATUS, error = OT_ERROR_FAILED);
VerifyOrExit(aCommand == SPINEL_CMD_PROP_VALUE_IS && aKey == SPINEL_PROP_LAST_STATUS, error = OT_ERROR_FAILED);
unpacked = spinel_datatype_unpack(aBuffer, aLength, SPINEL_DATATYPE_UINT_PACKED_S, &status);
EXPECT(unpacked > 0, error = OT_ERROR_PARSE);
VerifyOrExit(unpacked > 0, error = OT_ERROR_PARSE);
aBuffer += unpacked;
aLength -= static_cast<uint16_t>(unpacked);
unpacked = spinel_datatype_unpack(aBuffer, aLength, SPINEL_DATATYPE_BOOL_S, &framePending);
EXPECT(unpacked > 0, error = OT_ERROR_PARSE);
VerifyOrExit(unpacked > 0, error = OT_ERROR_PARSE);
aBuffer += unpacked;
aLength -= static_cast<uint16_t>(unpacked);
unpacked = spinel_datatype_unpack(aBuffer, aLength, SPINEL_DATATYPE_BOOL_S, &headerUpdated);
EXPECT(unpacked > 0, error = OT_ERROR_PARSE);
VerifyOrExit(unpacked > 0, error = OT_ERROR_PARSE);
aBuffer += unpacked;
aLength -= static_cast<uint16_t>(unpacked);
if (status == SPINEL_STATUS_OK)
{
EXPECT_NO_ERROR(error = ParseRadioFrame(mAckRadioFrame, aBuffer, aLength, unpacked));
SuccessOrExit(error = ParseRadioFrame(mAckRadioFrame, aBuffer, aLength, unpacked));
aBuffer += unpacked;
aLength -= static_cast<uint16_t>(unpacked);
}
@@ -1593,7 +1593,7 @@ void RadioSpinel::HandleTransmitDone(uint32_t aCommand,
// Replace transmit frame security key index and frame counter with the one filled by RCP
unpacked = spinel_datatype_unpack(aBuffer, aLength, SPINEL_DATATYPE_UINT8_S SPINEL_DATATYPE_UINT32_S, &keyId,
&frameCounter);
EXPECT(unpacked > 0, error = OT_ERROR_PARSE);
VerifyOrExit(unpacked > 0, error = OT_ERROR_PARSE);
static_cast<Mac::TxFrame *>(mTransmitFrame)->SetKeyId(keyId);
static_cast<Mac::TxFrame *>(mTransmitFrame)->SetFrameCounter(frameCounter);
@@ -1623,7 +1623,7 @@ otError RadioSpinel::Transmit(otRadioFrame &aFrame)
{
otError error = OT_ERROR_INVALID_STATE;
EXPECT(mState == kStateReceive || (mState == kStateSleep && (sRadioCaps & OT_RADIO_CAPS_SLEEP_TO_TX)), NO_ACTION);
VerifyOrExit(mState == kStateReceive || (mState == kStateSleep && (sRadioCaps & OT_RADIO_CAPS_SLEEP_TO_TX)));
mTransmitFrame = &aFrame;
@@ -1706,19 +1706,19 @@ otError RadioSpinel::Receive(uint8_t aChannel)
{
otError error = OT_ERROR_NONE;
EXPECT(mState != kStateDisabled, error = OT_ERROR_INVALID_STATE);
VerifyOrExit(mState != kStateDisabled, error = OT_ERROR_INVALID_STATE);
if (mChannel != aChannel)
{
error = Set(SPINEL_PROP_PHY_CHAN, SPINEL_DATATYPE_UINT8_S, aChannel);
EXPECT_NO_ERROR(error);
SuccessOrExit(error);
mChannel = aChannel;
}
if (mState == kStateSleep)
{
error = Set(SPINEL_PROP_MAC_RAW_STREAM_ENABLED, SPINEL_DATATYPE_BOOL_S, true);
EXPECT_NO_ERROR(error);
SuccessOrExit(error);
}
if (mTxRadioTid != 0)
@@ -1737,11 +1737,11 @@ otError RadioSpinel::ReceiveAt(uint64_t aWhen, uint32_t aDuration, uint8_t aChan
{
otError error = OT_ERROR_NONE;
EXPECT(mState != kStateDisabled, error = OT_ERROR_INVALID_STATE);
VerifyOrExit(mState != kStateDisabled, error = OT_ERROR_INVALID_STATE);
error = Set(SPINEL_PROP_MAC_RX_AT, SPINEL_DATATYPE_UINT64_S SPINEL_DATATYPE_UINT32_S SPINEL_DATATYPE_UINT8_S, aWhen,
aDuration, aChannel);
EXPECT_NO_ERROR(error);
SuccessOrExit(error);
exit:
return error;
@@ -1755,7 +1755,7 @@ otError RadioSpinel::Sleep(void)
{
case kStateReceive:
error = Set(SPINEL_PROP_MAC_RAW_STREAM_ENABLED, SPINEL_DATATYPE_BOOL_S, false);
EXPECT_NO_ERROR(error);
SuccessOrExit(error);
mState = kStateSleep;
break;
@@ -1776,14 +1776,14 @@ otError RadioSpinel::Enable(otInstance *aInstance)
{
otError error = OT_ERROR_NONE;
EXPECT(!IsEnabled(), NO_ACTION);
VerifyOrExit(!IsEnabled());
mInstance = aInstance;
EXPECT_NO_ERROR(error = Set(SPINEL_PROP_PHY_ENABLED, SPINEL_DATATYPE_BOOL_S, true));
EXPECT_NO_ERROR(error = Set(SPINEL_PROP_MAC_15_4_PANID, SPINEL_DATATYPE_UINT16_S, mPanId));
EXPECT_NO_ERROR(error = Set(SPINEL_PROP_MAC_15_4_SADDR, SPINEL_DATATYPE_UINT16_S, mShortAddress));
EXPECT_NO_ERROR(error = Get(SPINEL_PROP_PHY_RX_SENSITIVITY, SPINEL_DATATYPE_INT8_S, &mRxSensitivity));
SuccessOrExit(error = Set(SPINEL_PROP_PHY_ENABLED, SPINEL_DATATYPE_BOOL_S, true));
SuccessOrExit(error = Set(SPINEL_PROP_MAC_15_4_PANID, SPINEL_DATATYPE_UINT16_S, mPanId));
SuccessOrExit(error = Set(SPINEL_PROP_MAC_15_4_SADDR, SPINEL_DATATYPE_UINT16_S, mShortAddress));
SuccessOrExit(error = Get(SPINEL_PROP_PHY_RX_SENSITIVITY, SPINEL_DATATYPE_INT8_S, &mRxSensitivity));
mState = kStateSleep;
@@ -1801,8 +1801,8 @@ otError RadioSpinel::Disable(void)
{
otError error = OT_ERROR_NONE;
EXPECT(IsEnabled(), NO_ACTION);
EXPECT(mState == kStateSleep, error = OT_ERROR_INVALID_STATE);
VerifyOrExit(IsEnabled());
VerifyOrExit(mState == kStateSleep, error = OT_ERROR_INVALID_STATE);
SuccessOrDie(Set(SPINEL_PROP_PHY_ENABLED, SPINEL_DATATYPE_BOOL_S, false));
mState = kStateDisabled;
@@ -1898,8 +1898,8 @@ uint32_t RadioSpinel::GetRadioChannelMask(bool aPreferred)
spinel_ssize_t unpacked;
unpacked = spinel_datatype_unpack(maskData, maskLength, SPINEL_DATATYPE_UINT8_S, &channel);
EXPECT(unpacked > 0, error = OT_ERROR_FAILED);
EXPECT(channel < kChannelMaskBufferSize, error = OT_ERROR_PARSE);
VerifyOrExit(unpacked > 0, error = OT_ERROR_FAILED);
VerifyOrExit(channel < kChannelMaskBufferSize, error = OT_ERROR_PARSE);
channelMask |= (1UL << channel);
maskData += unpacked;
@@ -1958,13 +1958,13 @@ void RadioSpinel::CalcRcpTimeOffset(void)
* D = T1' - ((T0 + T2)/ 2)
*/
EXPECT(mTimeSyncOn, NO_ACTION);
EXPECT(!mIsTimeSynced || (otPlatTimeGet() >= GetNextRadioTimeRecalcStart()), NO_ACTION);
VerifyOrExit(mTimeSyncOn);
VerifyOrExit(!mIsTimeSynced || (otPlatTimeGet() >= GetNextRadioTimeRecalcStart()));
LogDebg("Trying to get RCP time offset");
packed = spinel_datatype_pack(buffer, sizeof(buffer), SPINEL_DATATYPE_UINT64_S, remoteTimestamp);
EXPECT(packed > 0 && static_cast<size_t>(packed) <= sizeof(buffer), error = OT_ERROR_NO_BUFS);
VerifyOrExit(packed > 0 && static_cast<size_t>(packed) <= sizeof(buffer), error = OT_ERROR_NO_BUFS);
localTxTimestamp = otPlatTimeGet();
@@ -1974,7 +1974,7 @@ void RadioSpinel::CalcRcpTimeOffset(void)
localRxTimestamp = otPlatTimeGet();
EXPECT(error == OT_ERROR_NONE, mRadioTimeRecalcStart = localRxTimestamp);
VerifyOrExit(error == OT_ERROR_NONE, mRadioTimeRecalcStart = localRxTimestamp);
mRadioTimeOffset = (remoteTimestamp - ((localRxTimestamp / 2) + (localTxTimestamp / 2)));
mIsTimeSynced = true;
@@ -2041,7 +2041,7 @@ void RadioSpinel::RecoverFromRcpFailure(void)
if (mRcpFailure == kRcpFailureNone)
{
EXIT_NOW();
ExitNow();
}
#if OPENTHREAD_CONFIG_MULTIPAN_RCP_ENABLE
@@ -2096,7 +2096,7 @@ void RadioSpinel::RecoverFromRcpFailure(void)
case kStateReceive:
#if OPENTHREAD_CONFIG_MULTIPAN_RCP_ENABLE
// In case multiple PANs are running, don't force RCP to receive state.
IGNORE_RETURN(Set(SPINEL_PROP_MAC_RAW_STREAM_ENABLED, SPINEL_DATATYPE_BOOL_S, true));
IgnoreReturnValue(Set(SPINEL_PROP_MAC_RAW_STREAM_ENABLED, SPINEL_DATATYPE_BOOL_S, true));
#else
SuccessOrDie(Set(SPINEL_PROP_MAC_RAW_STREAM_ENABLED, SPINEL_DATATYPE_BOOL_S, true));
#endif
@@ -2106,7 +2106,7 @@ void RadioSpinel::RecoverFromRcpFailure(void)
case kStateTransmitDone:
#if OPENTHREAD_CONFIG_MULTIPAN_RCP_ENABLE
// In case multiple PANs are running, don't force RCP to receive state.
IGNORE_RETURN(Set(SPINEL_PROP_MAC_RAW_STREAM_ENABLED, SPINEL_DATATYPE_BOOL_S, true));
IgnoreReturnValue(Set(SPINEL_PROP_MAC_RAW_STREAM_ENABLED, SPINEL_DATATYPE_BOOL_S, true));
#else
SuccessOrDie(Set(SPINEL_PROP_MAC_RAW_STREAM_ENABLED, SPINEL_DATATYPE_BOOL_S, true));
#endif
@@ -2172,7 +2172,7 @@ void RadioSpinel::RestoreProperties(void)
SuccessOrDie(Set(SPINEL_PROP_MAC_15_4_LADDR, SPINEL_DATATYPE_EUI64_S, mExtendedAddress.m8));
#if OPENTHREAD_CONFIG_MULTIPAN_RCP_ENABLE
// In case multiple PANs are running, don't force RCP to change channel.
IGNORE_RETURN(Set(SPINEL_PROP_PHY_CHAN, SPINEL_DATATYPE_UINT8_S, mChannel));
IgnoreReturnValue(Set(SPINEL_PROP_PHY_CHAN, SPINEL_DATATYPE_UINT8_S, mChannel));
#else
SuccessOrDie(Set(SPINEL_PROP_PHY_CHAN, SPINEL_DATATYPE_UINT8_S, mChannel));
#endif
@@ -2290,7 +2290,7 @@ otError RadioSpinel::SetMultipanActiveInterface(spinel_iid_t aIid, bool aComplet
otError error;
uint8_t value;
EXPECT(aIid == (aIid & SPINEL_MULTIPAN_INTERFACE_ID_MASK), error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(aIid == (aIid & SPINEL_MULTIPAN_INTERFACE_ID_MASK), error = OT_ERROR_INVALID_ARGS);
value = static_cast<uint8_t>(aIid);
if (aCompletePending)
@@ -2307,7 +2307,7 @@ exit:
otError RadioSpinel::SetChannelMaxTransmitPower(uint8_t aChannel, int8_t aMaxPower)
{
otError error = OT_ERROR_NONE;
EXPECT(aChannel >= Radio::kChannelMin && aChannel <= Radio::kChannelMax, error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(aChannel >= Radio::kChannelMin && aChannel <= Radio::kChannelMax, error = OT_ERROR_INVALID_ARGS);
mMaxPowerTable.SetTransmitPower(aChannel, aMaxPower);
error = Set(SPINEL_PROP_PHY_CHAN_MAX_POWER, SPINEL_DATATYPE_UINT8_S SPINEL_DATATYPE_INT8_S, aChannel, aMaxPower);
@@ -2339,7 +2339,7 @@ otError RadioSpinel::GetRadioRegion(uint16_t *aRegionCode)
{
otError error = OT_ERROR_NONE;
EXPECT(aRegionCode != nullptr, error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(aRegionCode != nullptr, error = OT_ERROR_INVALID_ARGS);
error = Get(SPINEL_PROP_PHY_REGION_CODE, SPINEL_DATATYPE_UINT16_S, aRegionCode);
exit:
@@ -2413,9 +2413,9 @@ otError RadioSpinel::AddCalibratedPower(uint8_t aChannel,
otError error;
assert(aRawPowerSetting != nullptr);
EXPECT_NO_ERROR(error = Insert(SPINEL_PROP_PHY_CALIBRATED_POWER,
SPINEL_DATATYPE_UINT8_S SPINEL_DATATYPE_INT16_S SPINEL_DATATYPE_DATA_WLEN_S,
aChannel, aActualPower, aRawPowerSetting, aRawPowerSettingLength));
SuccessOrExit(error = Insert(SPINEL_PROP_PHY_CALIBRATED_POWER,
SPINEL_DATATYPE_UINT8_S SPINEL_DATATYPE_INT16_S SPINEL_DATATYPE_DATA_WLEN_S, aChannel,
aActualPower, aRawPowerSetting, aRawPowerSettingLength));
exit:
return error;
@@ -2426,7 +2426,7 @@ otError RadioSpinel::ClearCalibratedPowers(void) { return Set(SPINEL_PROP_PHY_CA
otError RadioSpinel::SetChannelTargetPower(uint8_t aChannel, int16_t aTargetPower)
{
otError error = OT_ERROR_NONE;
EXPECT(aChannel >= Radio::kChannelMin && aChannel <= Radio::kChannelMax, error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(aChannel >= Radio::kChannelMin && aChannel <= Radio::kChannelMax, error = OT_ERROR_INVALID_ARGS);
error =
Set(SPINEL_PROP_PHY_CHAN_TARGET_POWER, SPINEL_DATATYPE_UINT8_S SPINEL_DATATYPE_INT16_S, aChannel, aTargetPower);
+41 -41
View File
@@ -34,7 +34,7 @@
#include <assert.h>
#include "lib/utils/utils.hpp"
#include "common/code_utils.hpp"
namespace ot {
namespace Spinel {
@@ -253,7 +253,7 @@ otError Buffer::InFrameBeginSegment(void)
uint16_t headerFlags = kSegmentHeaderNoFlag;
// Verify that segment is not yet started (i.e., head and tail are the same).
EXPECT(mWriteSegmentHead == mWriteSegmentTail, NO_ACTION);
VerifyOrExit(mWriteSegmentHead == mWriteSegmentTail);
// Check if this is the start of a new frame (i.e., frame start is same as segment head).
if (mWriteFrameStart[mWriteDirection] == mWriteSegmentHead)
@@ -264,7 +264,7 @@ otError Buffer::InFrameBeginSegment(void)
// Reserve space for the segment header.
for (uint16_t i = kSegmentHeaderSize; i; i--)
{
EXPECT_NO_ERROR(error = InFrameAppend(0));
SuccessOrExit(error = InFrameAppend(0));
}
// Write the flags at the segment head.
@@ -310,7 +310,7 @@ void Buffer::InFrameDiscard(void)
otMessage *message;
#endif
EXPECT(mWriteDirection != kUnknown, NO_ACTION);
VerifyOrExit(mWriteDirection != kUnknown);
// Move the write segment head and tail pointers back to frame start.
mWriteSegmentHead = mWriteSegmentTail = mWriteFrameStart[mWriteDirection];
@@ -362,10 +362,10 @@ otError Buffer::InFrameFeedByte(uint8_t aByte)
{
otError error = OT_ERROR_NONE;
EXPECT(mWriteDirection != kUnknown, error = OT_ERROR_INVALID_STATE);
VerifyOrExit(mWriteDirection != kUnknown, error = OT_ERROR_INVALID_STATE);
// Begin a new segment (if we are not in middle of segment already).
EXPECT_NO_ERROR(error = InFrameBeginSegment());
SuccessOrExit(error = InFrameBeginSegment());
error = InFrameAppend(aByte);
@@ -377,15 +377,15 @@ otError Buffer::InFrameFeedData(const uint8_t *aDataBuffer, uint16_t aDataBuffer
{
otError error = OT_ERROR_NONE;
EXPECT(mWriteDirection != kUnknown, error = OT_ERROR_INVALID_STATE);
VerifyOrExit(mWriteDirection != kUnknown, error = OT_ERROR_INVALID_STATE);
// Begin a new segment (if we are not in middle of segment already).
EXPECT_NO_ERROR(error = InFrameBeginSegment());
SuccessOrExit(error = InFrameBeginSegment());
// Write the data buffer
while (aDataBufferLength--)
{
EXPECT_NO_ERROR(error = InFrameAppend(*aDataBuffer++));
SuccessOrExit(error = InFrameAppend(*aDataBuffer++));
}
exit:
@@ -397,11 +397,11 @@ otError Buffer::InFrameFeedMessage(otMessage *aMessage)
{
otError error = OT_ERROR_NONE;
EXPECT(aMessage != nullptr, error = OT_ERROR_INVALID_ARGS);
EXPECT(mWriteDirection != kUnknown, error = OT_ERROR_INVALID_STATE);
VerifyOrExit(aMessage != nullptr, error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(mWriteDirection != kUnknown, error = OT_ERROR_INVALID_STATE);
// Begin a new segment (if we are not in middle of segment already).
EXPECT_NO_ERROR(error = InFrameBeginSegment());
SuccessOrExit(error = InFrameBeginSegment());
// Enqueue the message in the current write frame queue.
otMessageQueueEnqueue(&mWriteFrameMessageQueue, aMessage);
@@ -418,10 +418,10 @@ otError Buffer::InFrameGetPosition(WritePosition &aPosition)
{
otError error = OT_ERROR_NONE;
EXPECT(mWriteDirection != kUnknown, error = OT_ERROR_INVALID_STATE);
VerifyOrExit(mWriteDirection != kUnknown, error = OT_ERROR_INVALID_STATE);
// Begin a new segment (if we are not in middle of segment already).
EXPECT_NO_ERROR(error = InFrameBeginSegment());
SuccessOrExit(error = InFrameBeginSegment());
aPosition.mPosition = mWriteSegmentTail;
aPosition.mSegmentHead = mWriteSegmentHead;
@@ -437,14 +437,14 @@ otError Buffer::InFrameOverwrite(const WritePosition &aPosition, const uint8_t *
uint16_t segmentLength;
uint16_t distance;
EXPECT(mWriteDirection != kUnknown, error = OT_ERROR_INVALID_STATE);
VerifyOrExit(mWriteDirection != kUnknown, error = OT_ERROR_INVALID_STATE);
EXPECT(aPosition.mSegmentHead == mWriteSegmentHead, error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(aPosition.mSegmentHead == mWriteSegmentHead, error = OT_ERROR_INVALID_ARGS);
// Ensure the overwrite does not go beyond current segment tail.
segmentLength = GetDistance(mWriteSegmentHead, mWriteSegmentTail, mWriteDirection);
distance = GetDistance(mWriteSegmentHead, aPosition.mPosition, mWriteDirection);
EXPECT(distance + aDataBufferLength <= segmentLength, error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(distance + aDataBufferLength <= segmentLength, error = OT_ERROR_INVALID_ARGS);
bufPtr = aPosition.mPosition;
while (aDataBufferLength > 0)
@@ -467,12 +467,12 @@ uint16_t Buffer::InFrameGetDistance(const WritePosition &aPosition) const
uint16_t segmentLength;
uint16_t offset;
EXPECT(mWriteDirection != kUnknown, NO_ACTION);
EXPECT(aPosition.mSegmentHead == mWriteSegmentHead, NO_ACTION);
VerifyOrExit(mWriteDirection != kUnknown);
VerifyOrExit(aPosition.mSegmentHead == mWriteSegmentHead);
segmentLength = GetDistance(mWriteSegmentHead, mWriteSegmentTail, mWriteDirection);
offset = GetDistance(mWriteSegmentHead, aPosition.mPosition, mWriteDirection);
EXPECT(offset < segmentLength, NO_ACTION);
VerifyOrExit(offset < segmentLength);
distance = GetDistance(aPosition.mPosition, mWriteSegmentTail, mWriteDirection);
@@ -486,12 +486,12 @@ otError Buffer::InFrameReset(const WritePosition &aPosition)
uint16_t segmentLength;
uint16_t offset;
EXPECT(mWriteDirection != kUnknown, error = OT_ERROR_INVALID_STATE);
EXPECT(aPosition.mSegmentHead == mWriteSegmentHead, error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(mWriteDirection != kUnknown, error = OT_ERROR_INVALID_STATE);
VerifyOrExit(aPosition.mSegmentHead == mWriteSegmentHead, error = OT_ERROR_INVALID_ARGS);
segmentLength = GetDistance(mWriteSegmentHead, mWriteSegmentTail, mWriteDirection);
offset = GetDistance(mWriteSegmentHead, aPosition.mPosition, mWriteDirection);
EXPECT(offset < segmentLength, error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(offset < segmentLength, error = OT_ERROR_INVALID_ARGS);
mWriteSegmentTail = aPosition.mPosition;
@@ -506,7 +506,7 @@ otError Buffer::InFrameEnd(void)
#endif
otError error = OT_ERROR_NONE;
EXPECT(mWriteDirection != kUnknown, error = OT_ERROR_INVALID_STATE);
VerifyOrExit(mWriteDirection != kUnknown, error = OT_ERROR_INVALID_STATE);
// End/Close the current segment (if any).
InFrameEndSegment(kSegmentHeaderNoFlag);
@@ -563,7 +563,7 @@ otError Buffer::OutFramePrepareSegment(void)
mReadSegmentHead = mReadSegmentTail;
// Ensure there is something to read (i.e. segment head is not at start of frame being written).
EXPECT(mReadSegmentHead != mWriteFrameStart[mReadDirection], error = OT_ERROR_NOT_FOUND);
VerifyOrExit(mReadSegmentHead != mWriteFrameStart[mReadDirection], error = OT_ERROR_NOT_FOUND);
// Read the segment header.
header = ReadUint16At(mReadSegmentHead, mReadDirection);
@@ -572,7 +572,7 @@ otError Buffer::OutFramePrepareSegment(void)
if (header & kSegmentHeaderNewFrameFlag)
{
// Ensure that this segment is start of current frame, otherwise the current frame is finished.
EXPECT(mReadSegmentHead == mReadFrameStart[mReadDirection], error = OT_ERROR_NOT_FOUND);
VerifyOrExit(mReadSegmentHead == mReadFrameStart[mReadDirection], error = OT_ERROR_NOT_FOUND);
}
// Find tail/end of current segment.
@@ -588,14 +588,14 @@ otError Buffer::OutFramePrepareSegment(void)
// Update the state to `InSegment` and return.
mReadState = kReadStateInSegment;
EXIT_NOW();
ExitNow();
}
#if OPENTHREAD_SPINEL_CONFIG_OPENTHREAD_MESSAGE_ENABLE
// No data in this segment, prepare any appended/associated message of this segment.
if (OutFramePrepareMessage() == OT_ERROR_NONE)
{
EXIT_NOW();
ExitNow();
}
// If there is no message (`PrepareMessage()` returned an error), loop back to prepare the next segment.
@@ -624,19 +624,19 @@ otError Buffer::OutFramePrepareMessage(void)
header = ReadUint16At(mReadSegmentHead, mReadDirection);
// Ensure that the segment header indicates that there is an associated message or return `NotFound` error.
EXPECT((header & kSegmentHeaderMessageIndicatorFlag) != 0, error = OT_ERROR_NOT_FOUND);
VerifyOrExit((header & kSegmentHeaderMessageIndicatorFlag) != 0, error = OT_ERROR_NOT_FOUND);
// Update the current message from the queue.
mReadMessage = (mReadMessage == nullptr) ? otMessageQueueGetHead(&mMessageQueue[mReadDirection])
: otMessageQueueGetNext(&mMessageQueue[mReadDirection], mReadMessage);
EXPECT(mReadMessage != nullptr, error = OT_ERROR_NOT_FOUND);
VerifyOrExit(mReadMessage != nullptr, error = OT_ERROR_NOT_FOUND);
// Reset the offset for reading the message.
mReadMessageOffset = 0;
// Fill the content from current message into the message buffer.
EXPECT_NO_ERROR(error = OutFrameFillMessageBuffer());
SuccessOrExit(error = OutFrameFillMessageBuffer());
// If all successful, set the state to `InMessage`.
mReadState = kReadStateInMessage;
@@ -652,14 +652,14 @@ otError Buffer::OutFrameFillMessageBuffer(void)
otError error = OT_ERROR_NONE;
int readLength;
EXPECT(mReadMessage != nullptr, error = OT_ERROR_NOT_FOUND);
VerifyOrExit(mReadMessage != nullptr, error = OT_ERROR_NOT_FOUND);
EXPECT(mReadMessageOffset < otMessageGetLength(mReadMessage), error = OT_ERROR_NOT_FOUND);
VerifyOrExit(mReadMessageOffset < otMessageGetLength(mReadMessage), error = OT_ERROR_NOT_FOUND);
// Read portion of current message from the offset into message buffer.
readLength = otMessageRead(mReadMessage, mReadMessageOffset, mMessageBuffer, sizeof(mMessageBuffer));
EXPECT(readLength > 0, error = OT_ERROR_NOT_FOUND);
VerifyOrExit(readLength > 0, error = OT_ERROR_NOT_FOUND);
// Update the message offset, set up the message tail, and set read pointer to start of message buffer.
@@ -678,7 +678,7 @@ otError Buffer::OutFrameBegin(void)
{
otError error = OT_ERROR_NONE;
EXPECT(!IsEmpty(), error = OT_ERROR_NOT_FOUND);
VerifyOrExit(!IsEmpty(), error = OT_ERROR_NOT_FOUND);
OutFrameSelectReadDirection();
@@ -733,7 +733,7 @@ uint8_t Buffer::OutFrameReadByte(void)
// If there is no message, move to next segment (if any).
if (error != OT_ERROR_NONE)
{
IGNORE_RETURN(OutFramePrepareSegment());
IgnoreReturnValue(OutFramePrepareSegment());
}
}
@@ -754,7 +754,7 @@ uint8_t Buffer::OutFrameReadByte(void)
// If no more bytes in the message, move to next segment (if any).
if (error != OT_ERROR_NONE)
{
IGNORE_RETURN(OutFramePrepareSegment());
IgnoreReturnValue(OutFramePrepareSegment());
}
}
#endif
@@ -786,7 +786,7 @@ otError Buffer::OutFrameRemove(void)
OT_UNUSED_VARIABLE(numSegments);
EXPECT(!IsEmpty(), error = OT_ERROR_NOT_FOUND);
VerifyOrExit(!IsEmpty(), error = OT_ERROR_NOT_FOUND);
OutFrameSelectReadDirection();
@@ -861,7 +861,7 @@ void Buffer::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];
EXIT_NOW();
ExitNow();
}
// If there is no fully written low priority frame, and not in middle of writing a new frame either.
@@ -889,9 +889,9 @@ uint16_t Buffer::OutFrameGetLength(void)
OT_UNUSED_VARIABLE(numSegments);
// If the frame length was calculated before, return the previously calculated length.
EXPECT(mReadFrameLength == kUnknownFrameLength, frameLength = mReadFrameLength);
VerifyOrExit(mReadFrameLength == kUnknownFrameLength, frameLength = mReadFrameLength);
EXPECT(!IsEmpty(), frameLength = 0);
VerifyOrExit(!IsEmpty(), frameLength = 0);
OutFrameSelectReadDirection();
+31 -31
View File
@@ -32,8 +32,8 @@
#include "spinel_decoder.hpp"
#include "common/code_utils.hpp"
#include "common/string.hpp"
#include "lib/utils/utils.hpp"
namespace ot {
namespace Spinel {
@@ -72,7 +72,7 @@ otError Decoder::ReadBool(bool &aBool)
otError error = OT_ERROR_NONE;
uint8_t byte;
EXPECT_NO_ERROR(error = ReadUint8(byte));
SuccessOrExit(error = ReadUint8(byte));
// Boolean value are encoded in 8-bits as either 0x00 or 0x01. All other values are illegal.
if (byte == 0x00)
@@ -96,7 +96,7 @@ otError Decoder::ReadUint8(uint8_t &aUint8)
{
otError error = OT_ERROR_NONE;
EXPECT(mIndex + sizeof(uint8_t) <= mEnd, error = OT_ERROR_PARSE);
VerifyOrExit(mIndex + sizeof(uint8_t) <= mEnd, error = OT_ERROR_PARSE);
aUint8 = mFrame[mIndex];
mIndex += sizeof(uint8_t);
@@ -109,7 +109,7 @@ otError Decoder::ReadInt8(int8_t &aInt8)
otError error = OT_ERROR_NONE;
uint8_t byte;
EXPECT_NO_ERROR(error = ReadUint8(byte));
SuccessOrExit(error = ReadUint8(byte));
aInt8 = static_cast<int8_t>(byte);
exit:
@@ -120,7 +120,7 @@ otError Decoder::ReadUint16(uint16_t &aUint16)
{
otError error = OT_ERROR_NONE;
EXPECT(mIndex + sizeof(uint16_t) <= mEnd, error = OT_ERROR_PARSE);
VerifyOrExit(mIndex + sizeof(uint16_t) <= mEnd, error = OT_ERROR_PARSE);
aUint16 = static_cast<uint16_t>(mFrame[mIndex] | (mFrame[mIndex + 1] << 8));
@@ -135,7 +135,7 @@ otError Decoder::ReadInt16(int16_t &aInt16)
otError error = OT_ERROR_NONE;
uint16_t u16;
EXPECT_NO_ERROR(error = ReadUint16(u16));
SuccessOrExit(error = ReadUint16(u16));
aInt16 = static_cast<int16_t>(u16);
exit:
@@ -146,7 +146,7 @@ otError Decoder::ReadUint32(uint32_t &aUint32)
{
otError error = OT_ERROR_NONE;
EXPECT(mIndex + sizeof(uint32_t) <= mEnd, error = OT_ERROR_PARSE);
VerifyOrExit(mIndex + sizeof(uint32_t) <= mEnd, error = OT_ERROR_PARSE);
aUint32 = ((static_cast<uint32_t>(mFrame[mIndex + 0]) << 0) | (static_cast<uint32_t>(mFrame[mIndex + 1]) << 8) |
(static_cast<uint32_t>(mFrame[mIndex + 2]) << 16) | (static_cast<uint32_t>(mFrame[mIndex + 3]) << 24));
@@ -162,7 +162,7 @@ otError Decoder::ReadInt32(int32_t &aInt32)
otError error = OT_ERROR_NONE;
uint32_t u32;
EXPECT_NO_ERROR(error = ReadUint32(u32));
SuccessOrExit(error = ReadUint32(u32));
aInt32 = static_cast<int32_t>(u32);
exit:
@@ -173,7 +173,7 @@ otError Decoder::ReadUint64(uint64_t &aUint64)
{
otError error = OT_ERROR_NONE;
EXPECT(mIndex + sizeof(uint64_t) <= mEnd, error = OT_ERROR_PARSE);
VerifyOrExit(mIndex + sizeof(uint64_t) <= mEnd, error = OT_ERROR_PARSE);
aUint64 = ((static_cast<uint64_t>(mFrame[mIndex + 0]) << 0) | (static_cast<uint64_t>(mFrame[mIndex + 1]) << 8) |
(static_cast<uint64_t>(mFrame[mIndex + 2]) << 16) | (static_cast<uint64_t>(mFrame[mIndex + 3]) << 24) |
@@ -191,7 +191,7 @@ otError Decoder::ReadInt64(int64_t &aInt64)
otError error = OT_ERROR_NONE;
uint64_t u64;
EXPECT_NO_ERROR(error = ReadUint64(u64));
SuccessOrExit(error = ReadUint64(u64));
aInt64 = static_cast<int64_t>(u64);
exit:
@@ -205,7 +205,7 @@ otError Decoder::ReadUintPacked(unsigned int &aUint)
unsigned int uint;
parsedLen = spinel_packed_uint_decode(&mFrame[mIndex], mEnd - mIndex, &uint);
EXPECT(parsedLen > 0, error = OT_ERROR_PARSE);
VerifyOrExit(parsedLen > 0, error = OT_ERROR_PARSE);
mIndex += parsedLen;
aUint = uint;
@@ -219,7 +219,7 @@ otError Decoder::ReadItem(const uint8_t **aPtr, uint16_t aSize)
{
otError error = OT_ERROR_NONE;
EXPECT(mIndex + aSize <= mEnd, error = OT_ERROR_PARSE);
VerifyOrExit(mIndex + aSize <= mEnd, error = OT_ERROR_PARSE);
*aPtr = &mFrame[mIndex];
@@ -234,8 +234,8 @@ otError Decoder::ReadIp6Address(spinel_ipv6addr_t &aIp6Addr)
otError error = OT_ERROR_NONE;
const spinel_ipv6addr_t *ipv6AddrPtr = nullptr;
EXPECT_NO_ERROR(error = ReadIp6Address(ipv6AddrPtr));
EXPECT(ipv6AddrPtr != nullptr, error = OT_ERROR_PARSE);
SuccessOrExit(error = ReadIp6Address(ipv6AddrPtr));
VerifyOrExit(ipv6AddrPtr != nullptr, error = OT_ERROR_PARSE);
aIp6Addr = *ipv6AddrPtr;
exit:
@@ -247,8 +247,8 @@ otError Decoder::ReadIp6Address(otIp6Address &aIp6Addr)
otError error = OT_ERROR_NONE;
const otIp6Address *ipv6AddrPtr = nullptr;
EXPECT_NO_ERROR(error = ReadIp6Address(ipv6AddrPtr));
EXPECT(ipv6AddrPtr != nullptr, error = OT_ERROR_PARSE);
SuccessOrExit(error = ReadIp6Address(ipv6AddrPtr));
VerifyOrExit(ipv6AddrPtr != nullptr, error = OT_ERROR_PARSE);
aIp6Addr = *ipv6AddrPtr;
exit:
@@ -260,8 +260,8 @@ otError Decoder::ReadEui64(spinel_eui64_t &aEui64)
otError error = OT_ERROR_NONE;
const spinel_eui64_t *eui64Ptr = nullptr;
EXPECT_NO_ERROR(error = ReadEui64(eui64Ptr));
EXPECT(eui64Ptr != nullptr, error = OT_ERROR_PARSE);
SuccessOrExit(error = ReadEui64(eui64Ptr));
VerifyOrExit(eui64Ptr != nullptr, error = OT_ERROR_PARSE);
aEui64 = *eui64Ptr;
exit:
@@ -273,8 +273,8 @@ otError Decoder::ReadEui64(otExtAddress &aEui64)
otError error = OT_ERROR_NONE;
const otExtAddress *eui64Ptr = nullptr;
EXPECT_NO_ERROR(error = ReadEui64(eui64Ptr));
EXPECT(eui64Ptr != nullptr, error = OT_ERROR_PARSE);
SuccessOrExit(error = ReadEui64(eui64Ptr));
VerifyOrExit(eui64Ptr != nullptr, error = OT_ERROR_PARSE);
aEui64 = *eui64Ptr;
exit:
@@ -286,8 +286,8 @@ otError Decoder::ReadEui48(spinel_eui48_t &aEui48)
otError error = OT_ERROR_NONE;
const spinel_eui48_t *eui48Ptr = nullptr;
EXPECT_NO_ERROR(error = ReadEui48(eui48Ptr));
EXPECT(eui48Ptr != nullptr, error = OT_ERROR_PARSE);
SuccessOrExit(error = ReadEui48(eui48Ptr));
VerifyOrExit(eui48Ptr != nullptr, error = OT_ERROR_PARSE);
aEui48 = *eui48Ptr;
exit:
@@ -300,10 +300,10 @@ otError Decoder::ReadUtf8(const char *&aUtf8)
size_t len;
// Ensure there is at least one byte (for null character).
EXPECT(mIndex + sizeof(uint8_t) <= mEnd, error = OT_ERROR_PARSE);
VerifyOrExit(mIndex + sizeof(uint8_t) <= mEnd, error = OT_ERROR_PARSE);
len = StringLength(reinterpret_cast<const char *>(&mFrame[mIndex]), mEnd - mIndex);
EXPECT(len < static_cast<uint16_t>(mEnd - mIndex), error = OT_ERROR_PARSE);
VerifyOrExit(len < static_cast<uint16_t>(mEnd - mIndex), error = OT_ERROR_PARSE);
aUtf8 = reinterpret_cast<const char *>(&mFrame[mIndex]);
@@ -326,8 +326,8 @@ otError Decoder::ReadDataWithLen(const uint8_t *&aData, uint16_t &aDataLen)
otError error = OT_ERROR_NONE;
uint16_t len;
EXPECT_NO_ERROR(error = ReadUint16(len));
EXPECT_NO_ERROR(error = ReadItem(&aData, len));
SuccessOrExit(error = ReadUint16(len));
SuccessOrExit(error = ReadItem(&aData, len));
aDataLen = len;
exit:
@@ -339,10 +339,10 @@ otError Decoder::OpenStruct(void)
otError error = OT_ERROR_NONE;
uint16_t structLen;
EXPECT(mNumOpenStructs < kMaxNestedStructs, error = OT_ERROR_INVALID_STATE);
VerifyOrExit(mNumOpenStructs < kMaxNestedStructs, error = OT_ERROR_INVALID_STATE);
EXPECT_NO_ERROR(error = ReadUint16(structLen));
EXPECT(structLen <= mEnd - mIndex, error = OT_ERROR_PARSE);
SuccessOrExit(error = ReadUint16(structLen));
VerifyOrExit(structLen <= mEnd - mIndex, error = OT_ERROR_PARSE);
mPrevEnd[mNumOpenStructs] = mEnd;
mEnd = (mIndex + structLen);
@@ -356,7 +356,7 @@ otError Decoder::CloseStruct(void)
{
otError error = OT_ERROR_NONE;
EXPECT(mNumOpenStructs > 0, error = OT_ERROR_INVALID_STATE);
VerifyOrExit(mNumOpenStructs > 0, error = OT_ERROR_INVALID_STATE);
// If there is a saved position and it is contained
// within the current struct being closed, the saved
@@ -387,7 +387,7 @@ otError Decoder::ResetToSaved(void)
{
otError error = OT_ERROR_NONE;
EXPECT(IsSavedPositionValid(), error = OT_ERROR_INVALID_STATE);
VerifyOrExit(IsSavedPositionValid(), error = OT_ERROR_INVALID_STATE);
mIndex = mSavedIndex;
mEnd = mSavedEnd;
+33 -31
View File
@@ -32,10 +32,11 @@
#include <openthread/platform/time.h>
#include "common/code_utils.hpp"
#include "common/new.hpp"
#include "lib/platform/exit_code.h"
#include "lib/spinel/spinel.h"
#include "lib/utils/math.hpp"
#include "lib/utils/utils.hpp"
namespace ot {
namespace Spinel {
@@ -109,9 +110,9 @@ otError SpinelDriver::SendReset(uint8_t aResetType)
packed = spinel_datatype_pack(buffer, sizeof(buffer), SPINEL_DATATYPE_COMMAND_S SPINEL_DATATYPE_UINT8_S,
SPINEL_HEADER_FLAG | SPINEL_HEADER_IID(mIid), SPINEL_CMD_RESET, aResetType);
EXPECT(packed > 0 && static_cast<size_t>(packed) <= sizeof(buffer), error = OT_ERROR_NO_BUFS);
VerifyOrExit(packed > 0 && static_cast<size_t>(packed) <= sizeof(buffer), error = OT_ERROR_NO_BUFS);
EXPECT_NO_ERROR(error = mSpinelInterface->SendFrame(buffer, static_cast<uint16_t>(packed)));
SuccessOrExit(error = mSpinelInterface->SendFrame(buffer, static_cast<uint16_t>(packed)));
LogSpinelFrame(buffer, static_cast<uint16_t>(packed), true /* aTx */);
exit:
@@ -124,22 +125,22 @@ void SpinelDriver::ResetCoprocessor(bool aSoftwareReset)
bool resetDone = false;
// Avoid resetting the device twice in a row in Multipan RCP architecture
EXPECT(!mIsCoprocessorReady, resetDone = true);
VerifyOrExit(!mIsCoprocessorReady, resetDone = true);
mWaitingKey = SPINEL_PROP_LAST_STATUS;
if (aSoftwareReset && (SendReset(SPINEL_RESET_STACK) == OT_ERROR_NONE) && (WaitResponse() == OT_ERROR_NONE))
{
EXPECT(mIsCoprocessorReady, resetDone = false);
VerifyOrExit(mIsCoprocessorReady, resetDone = false);
LogCrit("Software reset co-processor successfully");
EXIT_NOW(resetDone = true);
ExitNow(resetDone = true);
}
hardwareReset = (mSpinelInterface->HardwareReset() == OT_ERROR_NONE);
if (hardwareReset)
{
EXPECT_NO_ERROR(WaitResponse());
SuccessOrExit(WaitResponse());
}
resetDone = true;
@@ -187,11 +188,11 @@ otError SpinelDriver::SendCommand(uint32_t aCommand, spinel_prop_key_t aKey, spi
packed = spinel_datatype_pack(buffer, sizeof(buffer), "Cii", SPINEL_HEADER_FLAG | SPINEL_HEADER_IID(mIid) | aTid,
aCommand, aKey);
EXPECT(packed > 0 && static_cast<size_t>(packed) <= sizeof(buffer), error = OT_ERROR_NO_BUFS);
VerifyOrExit(packed > 0 && static_cast<size_t>(packed) <= sizeof(buffer), error = OT_ERROR_NO_BUFS);
offset = static_cast<uint16_t>(packed);
EXPECT_NO_ERROR(error = mSpinelInterface->SendFrame(buffer, offset));
SuccessOrExit(error = mSpinelInterface->SendFrame(buffer, offset));
LogSpinelFrame(buffer, offset, true /* aTx */);
exit:
@@ -213,7 +214,7 @@ otError SpinelDriver::SendCommand(uint32_t aCommand,
packed = spinel_datatype_pack(buffer, sizeof(buffer), "Cii", SPINEL_HEADER_FLAG | SPINEL_HEADER_IID(mIid) | aTid,
aCommand, aKey);
EXPECT(packed > 0 && static_cast<size_t>(packed) <= sizeof(buffer), error = OT_ERROR_NO_BUFS);
VerifyOrExit(packed > 0 && static_cast<size_t>(packed) <= sizeof(buffer), error = OT_ERROR_NO_BUFS);
offset = static_cast<uint16_t>(packed);
@@ -221,12 +222,12 @@ otError SpinelDriver::SendCommand(uint32_t aCommand,
if (aFormat)
{
packed = spinel_datatype_vpack(buffer + offset, sizeof(buffer) - offset, aFormat, aArgs);
EXPECT(packed > 0 && static_cast<size_t>(packed + offset) <= sizeof(buffer), error = OT_ERROR_NO_BUFS);
VerifyOrExit(packed > 0 && static_cast<size_t>(packed + offset) <= sizeof(buffer), error = OT_ERROR_NO_BUFS);
offset += static_cast<uint16_t>(packed);
}
EXPECT_NO_ERROR(error = mSpinelInterface->SendFrame(buffer, offset));
SuccessOrExit(error = mSpinelInterface->SendFrame(buffer, offset));
LogSpinelFrame(buffer, offset, true /* aTx */);
exit:
@@ -256,7 +257,7 @@ otError SpinelDriver::WaitResponse(void)
if ((end <= now) || (mSpinelInterface->WaitForFrame(end - now) != OT_ERROR_NONE))
{
LogWarn("Wait for response timeout");
EXIT_NOW(error = OT_ERROR_RESPONSE_TIMEOUT);
ExitNow(error = OT_ERROR_RESPONSE_TIMEOUT);
}
} while (mIsWaitingForResponse || !mIsCoprocessorReady);
@@ -285,10 +286,10 @@ void SpinelDriver::HandleReceivedFrame(void)
if (!mIidList.Contains(iid))
{
mRxFrameBuffer.DiscardFrame();
EXIT_NOW();
ExitNow();
}
EXPECT(unpacked > 0 && (header & SPINEL_HEADER_FLAG) == SPINEL_HEADER_FLAG, error = OT_ERROR_PARSE);
VerifyOrExit(unpacked > 0 && (header & SPINEL_HEADER_FLAG) == SPINEL_HEADER_FLAG, error = OT_ERROR_PARSE);
assert(mReceivedFrameHandler != nullptr && mFrameHandlerContext != nullptr);
mReceivedFrameHandler(mRxFrameBuffer.GetFrame(), mRxFrameBuffer.GetLength(), header, shouldSave,
@@ -334,16 +335,17 @@ void SpinelDriver::HandleInitialFrame(const uint8_t *aFrame, uint16_t aLength, u
OT_UNUSED_VARIABLE(aHeader);
rval = spinel_datatype_unpack(aFrame, aLength, "CiiD", &header, &cmd, &key, &data, &len);
EXPECT(rval > 0 && cmd >= SPINEL_CMD_PROP_VALUE_IS && cmd <= SPINEL_CMD_PROP_VALUE_REMOVED, error = OT_ERROR_PARSE);
VerifyOrExit(rval > 0 && cmd >= SPINEL_CMD_PROP_VALUE_IS && cmd <= SPINEL_CMD_PROP_VALUE_REMOVED,
error = OT_ERROR_PARSE);
EXPECT(cmd == SPINEL_CMD_PROP_VALUE_IS, error = OT_ERROR_DROP);
VerifyOrExit(cmd == SPINEL_CMD_PROP_VALUE_IS, error = OT_ERROR_DROP);
if (key == SPINEL_PROP_LAST_STATUS)
{
spinel_status_t status = SPINEL_STATUS_OK;
unpacked = spinel_datatype_unpack(data, len, "i", &status);
EXPECT(unpacked > 0, error = OT_ERROR_PARSE);
VerifyOrExit(unpacked > 0, error = OT_ERROR_PARSE);
if (status >= SPINEL_STATUS_RESET__BEGIN && status <= SPINEL_STATUS_RESET__END)
{
@@ -356,26 +358,26 @@ void SpinelDriver::HandleInitialFrame(const uint8_t *aFrame, uint16_t aLength, u
else
{
LogInfo("co-processor last status: %s", spinel_status_to_cstr(status));
EXIT_NOW();
ExitNow();
}
}
else
{
// Drop other frames when the key isn't waiting key.
EXPECT(mWaitingKey == key, error = OT_ERROR_DROP);
VerifyOrExit(mWaitingKey == key, error = OT_ERROR_DROP);
if (key == SPINEL_PROP_PROTOCOL_VERSION)
{
unpacked = spinel_datatype_unpack(data, len, (SPINEL_DATATYPE_UINT_PACKED_S SPINEL_DATATYPE_UINT_PACKED_S),
&mSpinelVersionMajor, &mSpinelVersionMinor);
EXPECT(unpacked > 0, error = OT_ERROR_PARSE);
VerifyOrExit(unpacked > 0, error = OT_ERROR_PARSE);
}
else if (key == SPINEL_PROP_NCP_VERSION)
{
unpacked = spinel_datatype_unpack_in_place(data, len, SPINEL_DATATYPE_UTF8_S, mVersion, sizeof(mVersion));
EXPECT(unpacked > 0, error = OT_ERROR_PARSE);
VerifyOrExit(unpacked > 0, error = OT_ERROR_PARSE);
}
else if (key == SPINEL_PROP_CAPS)
{
@@ -385,16 +387,16 @@ void SpinelDriver::HandleInitialFrame(const uint8_t *aFrame, uint16_t aLength, u
unpacked = spinel_datatype_unpack_in_place(data, len, SPINEL_DATATYPE_DATA_S, capsBuffer, &capsLength);
EXPECT(unpacked > 0, error = OT_ERROR_PARSE);
VerifyOrExit(unpacked > 0, error = OT_ERROR_PARSE);
while (capsLength > 0)
{
unsigned int capability;
unpacked = spinel_datatype_unpack(capsData, capsLength, SPINEL_DATATYPE_UINT_PACKED_S, &capability);
EXPECT(unpacked > 0, error = OT_ERROR_PARSE);
VerifyOrExit(unpacked > 0, error = OT_ERROR_PARSE);
EXPECT_NO_ERROR(error = mCoprocessorCaps.PushBack(capability));
SuccessOrExit(error = mCoprocessorCaps.PushBack(capability));
capsData += unpacked;
capsLength -= static_cast<spinel_size_t>(unpacked);
@@ -413,11 +415,11 @@ otError SpinelDriver::CheckSpinelVersion(void)
{
otError error = OT_ERROR_NONE;
EXPECT_NO_ERROR(error = SendCommand(SPINEL_CMD_PROP_VALUE_GET, SPINEL_PROP_PROTOCOL_VERSION, sTid));
SuccessOrExit(error = SendCommand(SPINEL_CMD_PROP_VALUE_GET, SPINEL_PROP_PROTOCOL_VERSION, sTid));
mIsWaitingForResponse = true;
mWaitingKey = SPINEL_PROP_PROTOCOL_VERSION;
EXPECT_NO_ERROR(error = WaitResponse());
SuccessOrExit(error = WaitResponse());
if ((mSpinelVersionMajor != SPINEL_PROTOCOL_VERSION_THREAD_MAJOR) ||
(mSpinelVersionMinor != SPINEL_PROTOCOL_VERSION_THREAD_MINOR))
@@ -435,11 +437,11 @@ otError SpinelDriver::GetCoprocessorVersion(void)
{
otError error = OT_ERROR_NONE;
EXPECT_NO_ERROR(error = SendCommand(SPINEL_CMD_PROP_VALUE_GET, SPINEL_PROP_NCP_VERSION, sTid));
SuccessOrExit(error = SendCommand(SPINEL_CMD_PROP_VALUE_GET, SPINEL_PROP_NCP_VERSION, sTid));
mIsWaitingForResponse = true;
mWaitingKey = SPINEL_PROP_NCP_VERSION;
EXPECT_NO_ERROR(error = WaitResponse());
SuccessOrExit(error = WaitResponse());
exit:
return error;
}
@@ -448,11 +450,11 @@ otError SpinelDriver::GetCoprocessorCaps(void)
{
otError error = OT_ERROR_NONE;
EXPECT_NO_ERROR(error = SendCommand(SPINEL_CMD_PROP_VALUE_GET, SPINEL_PROP_CAPS, sTid));
SuccessOrExit(error = SendCommand(SPINEL_CMD_PROP_VALUE_GET, SPINEL_PROP_CAPS, sTid));
mIsWaitingForResponse = true;
mWaitingKey = SPINEL_PROP_CAPS;
EXPECT_NO_ERROR(error = WaitResponse());
SuccessOrExit(error = WaitResponse());
exit:
return error;
}
+41 -41
View File
@@ -34,7 +34,7 @@
#include <string.h>
#include "lib/utils/utils.hpp"
#include "common/code_utils.hpp"
namespace ot {
namespace Spinel {
@@ -54,15 +54,15 @@ otError Encoder::BeginFrame(uint8_t aHeader, unsigned int aCommand)
if (SPINEL_HEADER_GET_TID(aHeader) != 0)
{
EXPECT_NO_ERROR(error = BeginFrame(Spinel::Buffer::kPriorityHigh));
SuccessOrExit(error = BeginFrame(Spinel::Buffer::kPriorityHigh));
}
else
{
EXPECT_NO_ERROR(error = BeginFrame(Spinel::Buffer::kPriorityLow));
SuccessOrExit(error = BeginFrame(Spinel::Buffer::kPriorityLow));
}
EXPECT_NO_ERROR(error = WriteUint8(aHeader));
EXPECT_NO_ERROR(error = WriteUintPacked(aCommand));
SuccessOrExit(error = WriteUint8(aHeader));
SuccessOrExit(error = WriteUintPacked(aCommand));
exit:
return error;
@@ -72,7 +72,7 @@ otError Encoder::BeginFrame(uint8_t aHeader, unsigned int aCommand, spinel_prop_
{
otError error = OT_ERROR_NONE;
EXPECT_NO_ERROR(error = BeginFrame(aHeader, aCommand));
SuccessOrExit(error = BeginFrame(aHeader, aCommand));
// The write position is saved before writing the property key,
// so that if fetching the property fails and we need to
@@ -80,8 +80,8 @@ otError Encoder::BeginFrame(uint8_t aHeader, unsigned int aCommand, spinel_prop_
// this saved write position and update the property key.
// (Also see `OverwriteWithLastStatusError()`).
EXPECT_NO_ERROR(error = SavePosition());
EXPECT_NO_ERROR(error = WriteUintPacked(aKey));
SuccessOrExit(error = SavePosition());
SuccessOrExit(error = WriteUintPacked(aKey));
exit:
return error;
@@ -91,9 +91,9 @@ otError Encoder::OverwriteWithLastStatusError(spinel_status_t aStatus)
{
otError error = OT_ERROR_NONE;
EXPECT_NO_ERROR(error = ResetToSaved());
EXPECT_NO_ERROR(error = WriteUintPacked(SPINEL_PROP_LAST_STATUS));
EXPECT_NO_ERROR(error = WriteUintPacked(aStatus));
SuccessOrExit(error = ResetToSaved());
SuccessOrExit(error = WriteUintPacked(SPINEL_PROP_LAST_STATUS));
SuccessOrExit(error = WriteUintPacked(aStatus));
exit:
return error;
@@ -105,7 +105,7 @@ otError Encoder::EndFrame(void)
while (mNumOpenStructs > 0)
{
EXPECT_NO_ERROR(error = CloseStruct());
SuccessOrExit(error = CloseStruct());
}
error = mNcpBuffer.InFrameEnd();
@@ -118,8 +118,8 @@ otError Encoder::WriteUint16(uint16_t aUint16)
{
otError error = OT_ERROR_NONE;
EXPECT_NO_ERROR(error = mNcpBuffer.InFrameFeedByte((aUint16 >> 0) & 0xff));
EXPECT_NO_ERROR(error = mNcpBuffer.InFrameFeedByte((aUint16 >> 8) & 0xff));
SuccessOrExit(error = mNcpBuffer.InFrameFeedByte((aUint16 >> 0) & 0xff));
SuccessOrExit(error = mNcpBuffer.InFrameFeedByte((aUint16 >> 8) & 0xff));
exit:
return error;
@@ -129,10 +129,10 @@ otError Encoder::WriteUint32(uint32_t aUint32)
{
otError error = OT_ERROR_NONE;
EXPECT_NO_ERROR(error = mNcpBuffer.InFrameFeedByte((aUint32 >> 0) & 0xff));
EXPECT_NO_ERROR(error = mNcpBuffer.InFrameFeedByte((aUint32 >> 8) & 0xff));
EXPECT_NO_ERROR(error = mNcpBuffer.InFrameFeedByte((aUint32 >> 16) & 0xff));
EXPECT_NO_ERROR(error = mNcpBuffer.InFrameFeedByte((aUint32 >> 24) & 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));
exit:
return error;
@@ -142,14 +142,14 @@ otError Encoder::WriteUint64(uint64_t aUint64)
{
otError error = OT_ERROR_NONE;
EXPECT_NO_ERROR(error = mNcpBuffer.InFrameFeedByte((aUint64 >> 0) & 0xff));
EXPECT_NO_ERROR(error = mNcpBuffer.InFrameFeedByte((aUint64 >> 8) & 0xff));
EXPECT_NO_ERROR(error = mNcpBuffer.InFrameFeedByte((aUint64 >> 16) & 0xff));
EXPECT_NO_ERROR(error = mNcpBuffer.InFrameFeedByte((aUint64 >> 24) & 0xff));
EXPECT_NO_ERROR(error = mNcpBuffer.InFrameFeedByte((aUint64 >> 32) & 0xff));
EXPECT_NO_ERROR(error = mNcpBuffer.InFrameFeedByte((aUint64 >> 40) & 0xff));
EXPECT_NO_ERROR(error = mNcpBuffer.InFrameFeedByte((aUint64 >> 48) & 0xff));
EXPECT_NO_ERROR(error = mNcpBuffer.InFrameFeedByte((aUint64 >> 56) & 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));
SuccessOrExit(error = mNcpBuffer.InFrameFeedByte((aUint64 >> 40) & 0xff));
SuccessOrExit(error = mNcpBuffer.InFrameFeedByte((aUint64 >> 48) & 0xff));
SuccessOrExit(error = mNcpBuffer.InFrameFeedByte((aUint64 >> 56) & 0xff));
exit:
return error;
@@ -169,8 +169,8 @@ otError Encoder::WriteDataWithLen(const uint8_t *aData, uint16_t aDataLen)
{
otError error = OT_ERROR_NONE;
EXPECT_NO_ERROR(error = WriteUint16(aDataLen));
EXPECT_NO_ERROR(error = WriteData(aData, aDataLen));
SuccessOrExit(error = WriteUint16(aDataLen));
SuccessOrExit(error = WriteData(aData, aDataLen));
exit:
return error;
@@ -186,8 +186,8 @@ otError Encoder::WriteUtf8(const char *aUtf8)
len = 0xffff;
}
EXPECT_NO_ERROR(error = WriteData(reinterpret_cast<const uint8_t *>(aUtf8), static_cast<uint16_t>(len)));
EXPECT_NO_ERROR(error = mNcpBuffer.InFrameFeedByte(0));
SuccessOrExit(error = WriteData(reinterpret_cast<const uint8_t *>(aUtf8), static_cast<uint16_t>(len)));
SuccessOrExit(error = mNcpBuffer.InFrameFeedByte(0));
exit:
return error;
@@ -197,12 +197,12 @@ otError Encoder::OpenStruct(void)
{
otError error = OT_ERROR_NONE;
EXPECT(mNumOpenStructs < kMaxNestedStructs, error = OT_ERROR_INVALID_STATE);
EXPECT_NO_ERROR(error = mNcpBuffer.InFrameGetPosition(mStructPosition[mNumOpenStructs]));
VerifyOrExit(mNumOpenStructs < kMaxNestedStructs, error = OT_ERROR_INVALID_STATE);
SuccessOrExit(error = mNcpBuffer.InFrameGetPosition(mStructPosition[mNumOpenStructs]));
// Reserve bytes for the length to be filled when the struct gets closed.
EXPECT_NO_ERROR(error = mNcpBuffer.InFrameFeedByte(0));
EXPECT_NO_ERROR(error = mNcpBuffer.InFrameFeedByte(0));
SuccessOrExit(error = mNcpBuffer.InFrameFeedByte(0));
SuccessOrExit(error = mNcpBuffer.InFrameFeedByte(0));
mNumOpenStructs++;
@@ -216,19 +216,19 @@ otError Encoder::CloseStruct(void)
uint16_t len;
uint8_t buffer[sizeof(uint16_t)];
EXPECT(mNumOpenStructs > 0, error = OT_ERROR_INVALID_STATE);
VerifyOrExit(mNumOpenStructs > 0, error = OT_ERROR_INVALID_STATE);
mNumOpenStructs--;
len = mNcpBuffer.InFrameGetDistance(mStructPosition[mNumOpenStructs]);
EXPECT(len >= sizeof(uint16_t), error = OT_ERROR_INVALID_STATE);
VerifyOrExit(len >= sizeof(uint16_t), error = OT_ERROR_INVALID_STATE);
len -= sizeof(uint16_t);
buffer[0] = (len >> 0 & 0xff);
buffer[1] = (len >> 8 & 0xff);
EXPECT_NO_ERROR(error = mNcpBuffer.InFrameOverwrite(mStructPosition[mNumOpenStructs], buffer, sizeof(buffer)));
SuccessOrExit(error = mNcpBuffer.InFrameOverwrite(mStructPosition[mNumOpenStructs], buffer, sizeof(buffer)));
exit:
return error;
@@ -238,7 +238,7 @@ otError Encoder::SavePosition(void)
{
otError error = OT_ERROR_NONE;
EXPECT_NO_ERROR(error = mNcpBuffer.InFrameGetPosition(mSavedPosition));
SuccessOrExit(error = mNcpBuffer.InFrameGetPosition(mSavedPosition));
mSavedNumOpenStructs = mNumOpenStructs;
exit:
@@ -249,7 +249,7 @@ otError Encoder::ResetToSaved(void)
{
otError error = OT_ERROR_NONE;
EXPECT_NO_ERROR(error = mNcpBuffer.InFrameReset(mSavedPosition));
SuccessOrExit(error = mNcpBuffer.InFrameReset(mSavedPosition));
mNumOpenStructs = mSavedNumOpenStructs;
exit:
@@ -266,7 +266,7 @@ otError Encoder::WritePacked(const char *aPackFormat, ...)
va_start(args, aPackFormat);
packedLen = spinel_datatype_vpack(buf, sizeof(buf), aPackFormat, args);
EXPECT((packedLen > 0) && (packedLen <= static_cast<spinel_ssize_t>(sizeof(buf))), error = OT_ERROR_NO_BUFS);
VerifyOrExit((packedLen > 0) && (packedLen <= static_cast<spinel_ssize_t>(sizeof(buf))), error = OT_ERROR_NO_BUFS);
error = mNcpBuffer.InFrameFeedData(buf, static_cast<uint16_t>(packedLen));
@@ -283,7 +283,7 @@ otError Encoder::WriteVPacked(const char *aPackFormat, va_list aArgs)
spinel_ssize_t packedLen;
packedLen = spinel_datatype_vpack(buf, sizeof(buf), aPackFormat, aArgs);
EXPECT((packedLen > 0) && (packedLen <= static_cast<spinel_ssize_t>(sizeof(buf))), error = OT_ERROR_NO_BUFS);
VerifyOrExit((packedLen > 0) && (packedLen <= static_cast<spinel_ssize_t>(sizeof(buf))), error = OT_ERROR_NO_BUFS);
error = mNcpBuffer.InFrameFeedData(buf, static_cast<uint16_t>(packedLen));
+59 -59
View File
@@ -31,7 +31,7 @@
*/
#include "lib/spinel/spinel_prop_codec.hpp"
#include "lib/utils/utils.hpp"
#include "common/code_utils.hpp"
namespace ot {
namespace Spinel {
@@ -44,15 +44,15 @@ otError EncodeDnssd<otPlatDnssdHost>(Encoder &aEncoder,
{
otError error = OT_ERROR_NONE;
EXPECT_NO_ERROR(error = aEncoder.WriteUintPacked(SPINEL_PROP_DNSSD_HOST));
EXPECT_NO_ERROR(error = aEncoder.WriteUtf8(aObj.mHostName == nullptr ? "" : aObj.mHostName));
EXPECT_NO_ERROR(error = aEncoder.WriteUint16(aObj.mAddressesLength));
SuccessOrExit(error = aEncoder.WriteUintPacked(SPINEL_PROP_DNSSD_HOST));
SuccessOrExit(error = aEncoder.WriteUtf8(aObj.mHostName == nullptr ? "" : aObj.mHostName));
SuccessOrExit(error = aEncoder.WriteUint16(aObj.mAddressesLength));
for (uint16_t i = 0; i < aObj.mAddressesLength; i++)
{
EXPECT_NO_ERROR(error = aEncoder.WriteIp6Address(aObj.mAddresses[i]));
SuccessOrExit(error = aEncoder.WriteIp6Address(aObj.mAddresses[i]));
}
EXPECT_NO_ERROR(error = aEncoder.WriteUint32(aRequestId));
EXPECT_NO_ERROR(error = aEncoder.WriteData(reinterpret_cast<const uint8_t *>(&aCallback), sizeof(aCallback)));
SuccessOrExit(error = aEncoder.WriteUint32(aRequestId));
SuccessOrExit(error = aEncoder.WriteData(reinterpret_cast<const uint8_t *>(&aCallback), sizeof(aCallback)));
exit:
return error;
@@ -66,23 +66,23 @@ otError EncodeDnssd<otPlatDnssdService>(Encoder &aEncoder,
{
otError error = OT_ERROR_NONE;
EXPECT_NO_ERROR(error = aEncoder.WriteUintPacked(SPINEL_PROP_DNSSD_SERVICE));
EXPECT_NO_ERROR(error = aEncoder.WriteUtf8(aObj.mHostName == nullptr ? "" : aObj.mHostName));
EXPECT_NO_ERROR(error = aEncoder.WriteUtf8(aObj.mServiceInstance == nullptr ? "" : aObj.mServiceInstance));
EXPECT_NO_ERROR(error = aEncoder.WriteUtf8(aObj.mServiceType == nullptr ? "" : aObj.mServiceType));
EXPECT_NO_ERROR(error = aEncoder.OpenStruct());
SuccessOrExit(error = aEncoder.WriteUintPacked(SPINEL_PROP_DNSSD_SERVICE));
SuccessOrExit(error = aEncoder.WriteUtf8(aObj.mHostName == nullptr ? "" : aObj.mHostName));
SuccessOrExit(error = aEncoder.WriteUtf8(aObj.mServiceInstance == nullptr ? "" : aObj.mServiceInstance));
SuccessOrExit(error = aEncoder.WriteUtf8(aObj.mServiceType == nullptr ? "" : aObj.mServiceType));
SuccessOrExit(error = aEncoder.OpenStruct());
for (uint16_t i = 0; i < aObj.mSubTypeLabelsLength; i++)
{
EXPECT_NO_ERROR(error = aEncoder.WriteUtf8(aObj.mSubTypeLabels[i]));
SuccessOrExit(error = aEncoder.WriteUtf8(aObj.mSubTypeLabels[i]));
}
EXPECT_NO_ERROR(error = aEncoder.CloseStruct());
EXPECT_NO_ERROR(error = aEncoder.WriteDataWithLen(aObj.mTxtData, aObj.mTxtDataLength));
EXPECT_NO_ERROR(error = aEncoder.WriteUint16(aObj.mPort));
EXPECT_NO_ERROR(error = aEncoder.WriteUint16(aObj.mPriority));
EXPECT_NO_ERROR(error = aEncoder.WriteUint16(aObj.mWeight));
EXPECT_NO_ERROR(error = aEncoder.WriteUint32(aObj.mTtl));
EXPECT_NO_ERROR(error = aEncoder.WriteUint32(aRequestId));
EXPECT_NO_ERROR(error = aEncoder.WriteData(reinterpret_cast<const uint8_t *>(&aCallback), sizeof(aCallback)));
SuccessOrExit(error = aEncoder.CloseStruct());
SuccessOrExit(error = aEncoder.WriteDataWithLen(aObj.mTxtData, aObj.mTxtDataLength));
SuccessOrExit(error = aEncoder.WriteUint16(aObj.mPort));
SuccessOrExit(error = aEncoder.WriteUint16(aObj.mPriority));
SuccessOrExit(error = aEncoder.WriteUint16(aObj.mWeight));
SuccessOrExit(error = aEncoder.WriteUint32(aObj.mTtl));
SuccessOrExit(error = aEncoder.WriteUint32(aRequestId));
SuccessOrExit(error = aEncoder.WriteData(reinterpret_cast<const uint8_t *>(&aCallback), sizeof(aCallback)));
exit:
return error;
@@ -96,19 +96,19 @@ otError EncodeDnssd<otPlatDnssdKey>(Encoder &aEncoder,
{
otError error = OT_ERROR_NONE;
EXPECT_NO_ERROR(error = aEncoder.WriteUintPacked(SPINEL_PROP_DNSSD_KEY_RECORD));
EXPECT_NO_ERROR(error = aEncoder.WriteUtf8(aObj.mName == nullptr ? "" : aObj.mName));
EXPECT_NO_ERROR(error = aEncoder.OpenStruct());
SuccessOrExit(error = aEncoder.WriteUintPacked(SPINEL_PROP_DNSSD_KEY_RECORD));
SuccessOrExit(error = aEncoder.WriteUtf8(aObj.mName == nullptr ? "" : aObj.mName));
SuccessOrExit(error = aEncoder.OpenStruct());
if (aObj.mServiceType != nullptr)
{
EXPECT_NO_ERROR(error = aEncoder.WriteUtf8(aObj.mServiceType));
SuccessOrExit(error = aEncoder.WriteUtf8(aObj.mServiceType));
}
EXPECT_NO_ERROR(error = aEncoder.CloseStruct());
EXPECT_NO_ERROR(error = aEncoder.WriteDataWithLen(aObj.mKeyData, aObj.mKeyDataLength));
EXPECT_NO_ERROR(error = aEncoder.WriteUint16(aObj.mClass));
EXPECT_NO_ERROR(error = aEncoder.WriteUint32(aObj.mTtl));
EXPECT_NO_ERROR(error = aEncoder.WriteUint32(aRequestId));
EXPECT_NO_ERROR(error = aEncoder.WriteData(reinterpret_cast<const uint8_t *>(&aCallback), sizeof(aCallback)));
SuccessOrExit(error = aEncoder.CloseStruct());
SuccessOrExit(error = aEncoder.WriteDataWithLen(aObj.mKeyData, aObj.mKeyDataLength));
SuccessOrExit(error = aEncoder.WriteUint16(aObj.mClass));
SuccessOrExit(error = aEncoder.WriteUint32(aObj.mTtl));
SuccessOrExit(error = aEncoder.WriteUint32(aRequestId));
SuccessOrExit(error = aEncoder.WriteData(reinterpret_cast<const uint8_t *>(&aCallback), sizeof(aCallback)));
exit:
return error;
@@ -122,11 +122,11 @@ otError DecodeDnssdHost(Decoder &aDecoder,
{
otError error = OT_ERROR_NONE;
EXPECT_NO_ERROR(error = aDecoder.ReadUtf8(aHost.mHostName));
EXPECT_NO_ERROR(error = aDecoder.ReadUint16(aHost.mAddressesLength));
EXPECT_NO_ERROR(error = aDecoder.ReadIp6Address(aHost.mAddresses));
EXPECT_NO_ERROR(error = aDecoder.ReadUint32(aRequestId));
EXPECT_NO_ERROR(error = aDecoder.ReadData(aCallbackData, aCallbackDataLen));
SuccessOrExit(error = aDecoder.ReadUtf8(aHost.mHostName));
SuccessOrExit(error = aDecoder.ReadUint16(aHost.mAddressesLength));
SuccessOrExit(error = aDecoder.ReadIp6Address(aHost.mAddresses));
SuccessOrExit(error = aDecoder.ReadUint32(aRequestId));
SuccessOrExit(error = aDecoder.ReadData(aCallbackData, aCallbackDataLen));
exit:
return error;
@@ -143,25 +143,25 @@ otError DecodeDnssdService(Decoder &aDecoder,
otError error = OT_ERROR_NONE;
uint8_t index = 0;
EXPECT_NO_ERROR(error = aDecoder.ReadUtf8(aService.mHostName));
EXPECT_NO_ERROR(error = aDecoder.ReadUtf8(aService.mServiceInstance));
EXPECT_NO_ERROR(error = aDecoder.ReadUtf8(aService.mServiceType));
EXPECT_NO_ERROR(error = aDecoder.OpenStruct());
SuccessOrExit(error = aDecoder.ReadUtf8(aService.mHostName));
SuccessOrExit(error = aDecoder.ReadUtf8(aService.mServiceInstance));
SuccessOrExit(error = aDecoder.ReadUtf8(aService.mServiceType));
SuccessOrExit(error = aDecoder.OpenStruct());
while (!aDecoder.IsAllReadInStruct())
{
EXPECT(index < aSubTypeLabelsCount, error = OT_ERROR_NO_BUFS);
EXPECT_NO_ERROR(error = aDecoder.ReadUtf8(aSubTypeLabels[index]));
VerifyOrExit(index < aSubTypeLabelsCount, error = OT_ERROR_NO_BUFS);
SuccessOrExit(error = aDecoder.ReadUtf8(aSubTypeLabels[index]));
index++;
}
aSubTypeLabelsCount = index;
EXPECT_NO_ERROR(error = aDecoder.CloseStruct());
EXPECT_NO_ERROR(error = aDecoder.ReadDataWithLen(aService.mTxtData, aService.mTxtDataLength));
EXPECT_NO_ERROR(error = aDecoder.ReadUint16(aService.mPort));
EXPECT_NO_ERROR(error = aDecoder.ReadUint16(aService.mPriority));
EXPECT_NO_ERROR(error = aDecoder.ReadUint16(aService.mWeight));
EXPECT_NO_ERROR(error = aDecoder.ReadUint32(aService.mTtl));
EXPECT_NO_ERROR(error = aDecoder.ReadUint32(aRequestId));
EXPECT_NO_ERROR(error = aDecoder.ReadData(aCallbackData, aCallbackDataLen));
SuccessOrExit(error = aDecoder.CloseStruct());
SuccessOrExit(error = aDecoder.ReadDataWithLen(aService.mTxtData, aService.mTxtDataLength));
SuccessOrExit(error = aDecoder.ReadUint16(aService.mPort));
SuccessOrExit(error = aDecoder.ReadUint16(aService.mPriority));
SuccessOrExit(error = aDecoder.ReadUint16(aService.mWeight));
SuccessOrExit(error = aDecoder.ReadUint32(aService.mTtl));
SuccessOrExit(error = aDecoder.ReadUint32(aRequestId));
SuccessOrExit(error = aDecoder.ReadData(aCallbackData, aCallbackDataLen));
exit:
return error;
@@ -175,22 +175,22 @@ otError DecodeDnssdKey(Decoder &aDecoder,
{
otError error = OT_ERROR_NONE;
EXPECT_NO_ERROR(error = aDecoder.ReadUtf8(aKey.mName));
EXPECT_NO_ERROR(error = aDecoder.OpenStruct());
SuccessOrExit(error = aDecoder.ReadUtf8(aKey.mName));
SuccessOrExit(error = aDecoder.OpenStruct());
if (!aDecoder.IsAllReadInStruct())
{
EXPECT_NO_ERROR(error = aDecoder.ReadUtf8(aKey.mServiceType));
SuccessOrExit(error = aDecoder.ReadUtf8(aKey.mServiceType));
}
else
{
aKey.mServiceType = nullptr;
}
EXPECT_NO_ERROR(error = aDecoder.CloseStruct());
EXPECT_NO_ERROR(error = aDecoder.ReadDataWithLen(aKey.mKeyData, aKey.mKeyDataLength));
EXPECT_NO_ERROR(error = aDecoder.ReadUint16(aKey.mClass));
EXPECT_NO_ERROR(error = aDecoder.ReadUint32(aKey.mTtl));
EXPECT_NO_ERROR(error = aDecoder.ReadUint32(aRequestId));
EXPECT_NO_ERROR(error = aDecoder.ReadData(aCallbackData, aCallbackDataLen));
SuccessOrExit(error = aDecoder.CloseStruct());
SuccessOrExit(error = aDecoder.ReadDataWithLen(aKey.mKeyData, aKey.mKeyDataLength));
SuccessOrExit(error = aDecoder.ReadUint16(aKey.mClass));
SuccessOrExit(error = aDecoder.ReadUint32(aKey.mTtl));
SuccessOrExit(error = aDecoder.ReadUint32(aRequestId));
SuccessOrExit(error = aDecoder.ReadData(aCallbackData, aCallbackDataLen));
exit:
return error;
+17 -17
View File
@@ -32,7 +32,7 @@
#include <stdlib.h>
#include <string.h>
#include "lib/utils/utils.hpp"
#include "common/code_utils.hpp"
namespace ot {
namespace Url {
@@ -54,7 +54,7 @@ otError Url::Init(char *aUrl)
mProtocol = aUrl;
url = strstr(aUrl, "://");
EXPECT(url != nullptr, error = OT_ERROR_PARSE);
VerifyOrExit(url != nullptr, error = OT_ERROR_PARSE);
*url = '\0';
url += sizeof("://") - 1;
mPath = url;
@@ -91,7 +91,7 @@ const char *Url::GetValue(const char *aName, const char *aLastValue) const
}
else
{
EXPECT(aLastValue > mQuery && aLastValue < mEnd, NO_ACTION);
VerifyOrExit(aLastValue > mQuery && aLastValue < mEnd);
start = aLastValue + strlen(aLastValue) + 1;
}
@@ -103,11 +103,11 @@ const char *Url::GetValue(const char *aName, const char *aLastValue) const
{
if (start[len] == '=')
{
EXIT_NOW(rval = &start[len + 1]);
ExitNow(rval = &start[len + 1]);
}
else if (start[len] == '\0')
{
EXIT_NOW(rval = &start[len]);
ExitNow(rval = &start[len]);
}
}
last = start;
@@ -124,10 +124,10 @@ otError Url::ParseUint32(const char *aName, uint32_t &aValue) const
const char *str;
long long value;
EXPECT((str = GetValue(aName)) != nullptr, error = OT_ERROR_NOT_FOUND);
VerifyOrExit((str = GetValue(aName)) != nullptr, error = OT_ERROR_NOT_FOUND);
value = strtoll(str, nullptr, 0);
EXPECT(0 <= value && value <= UINT32_MAX, error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(0 <= value && value <= UINT32_MAX, error = OT_ERROR_INVALID_ARGS);
aValue = static_cast<uint32_t>(value);
exit:
@@ -139,8 +139,8 @@ otError Url::ParseUint16(const char *aName, uint16_t &aValue) const
otError error = OT_ERROR_NONE;
uint32_t value;
EXPECT_NO_ERROR(error = ParseUint32(aName, value));
EXPECT(value <= UINT16_MAX, error = OT_ERROR_INVALID_ARGS);
SuccessOrExit(error = ParseUint32(aName, value));
VerifyOrExit(value <= UINT16_MAX, error = OT_ERROR_INVALID_ARGS);
aValue = static_cast<uint16_t>(value);
exit:
@@ -152,8 +152,8 @@ otError Url::ParseUint8(const char *aName, uint8_t &aValue) const
otError error = OT_ERROR_NONE;
uint32_t value;
EXPECT_NO_ERROR(error = ParseUint32(aName, value));
EXPECT(value <= UINT8_MAX, error = OT_ERROR_INVALID_ARGS);
SuccessOrExit(error = ParseUint32(aName, value));
VerifyOrExit(value <= UINT8_MAX, error = OT_ERROR_INVALID_ARGS);
aValue = static_cast<uint8_t>(value);
exit:
@@ -166,10 +166,10 @@ otError Url::ParseInt32(const char *aName, int32_t &aValue) const
const char *str;
long long value;
EXPECT((str = GetValue(aName)) != nullptr, error = OT_ERROR_NOT_FOUND);
VerifyOrExit((str = GetValue(aName)) != nullptr, error = OT_ERROR_NOT_FOUND);
value = strtoll(str, nullptr, 0);
EXPECT(INT32_MIN <= value && value <= INT32_MAX, error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(INT32_MIN <= value && value <= INT32_MAX, error = OT_ERROR_INVALID_ARGS);
aValue = static_cast<int32_t>(value);
exit:
@@ -181,8 +181,8 @@ otError Url::ParseInt16(const char *aName, int16_t &aValue) const
otError error = OT_ERROR_NONE;
int32_t value;
EXPECT_NO_ERROR(error = ParseInt32(aName, value));
EXPECT(INT16_MIN <= value && value <= INT16_MAX, error = OT_ERROR_INVALID_ARGS);
SuccessOrExit(error = ParseInt32(aName, value));
VerifyOrExit(INT16_MIN <= value && value <= INT16_MAX, error = OT_ERROR_INVALID_ARGS);
aValue = static_cast<int16_t>(value);
exit:
@@ -194,8 +194,8 @@ otError Url::ParseInt8(const char *aName, int8_t &aValue) const
otError error = OT_ERROR_NONE;
int32_t value;
EXPECT_NO_ERROR(error = ParseInt32(aName, value));
EXPECT(INT8_MIN <= value && value <= INT8_MAX, error = OT_ERROR_INVALID_ARGS);
SuccessOrExit(error = ParseInt32(aName, value));
VerifyOrExit(INT8_MIN <= value && value <= INT8_MAX, error = OT_ERROR_INVALID_ARGS);
aValue = static_cast<int8_t>(value);
exit:
-119
View File
@@ -1,119 +0,0 @@
/*
* Copyright (c) 2024, The OpenThread Authors.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file
* This file includes macros for validating runtime conditions.
*
* The macros in this file should be exclusively used by code under 'lib'. It's RECOMMENDED that only
* include this file in sources under 'lib' and not include this file in headers under 'lib'. Because
* headers under 'lib' may be included externally and the common macros may cause redefinition.
*/
#ifndef LIB_UTILS_CODE_UTILS_HPP_
#define LIB_UTILS_CODE_UTILS_HPP_
#include <stdbool.h>
#include <stddef.h>
/**
* Checks for the specified status, which is expected to commonly be successful, and branches to the local
* label 'exit' if the status is unsuccessful.
*
* @param[in] aStatus A scalar status to be evaluated against zero (0).
*/
#define EXPECT_NO_ERROR(aStatus) \
do \
{ \
if ((aStatus) != 0) \
{ \
goto exit; \
} \
} while (false)
/**
* Does nothing. This is passed to EXPECT when there is no action to do.
*/
#define NO_ACTION
/**
* Checks for the specified condition, which is expected to commonly be true, and both executes @a ... and
* branches to the local label 'exit' if the condition is false.
*
* @param[in] aCondition A Boolean expression to be evaluated.
* @param[in] aAction An optional expression or block to execute when the assertion fails.
*/
#define EXPECT(aCondition, aAction) \
do \
{ \
if (!(aCondition)) \
{ \
aAction; \
goto exit; \
} \
} while (false)
/**
* Unconditionally executes @a ... and branches to the local label 'exit'.
*
* @note The use of this interface implies neither success nor failure for the overall exit status of the enclosing
* function body.
*
* @param[in] ... An optional expression or block to execute when the assertion fails.
*/
#define EXIT_NOW(...) \
do \
{ \
__VA_ARGS__; \
goto exit; \
} while (false)
/**
* Executes the `statement` and ignores the return value.
*
* This is primarily used to indicate the intention of developer that the return value of a function/method can be
* safely ignored.
*
* @param[in] aStatement The function/method to execute.
*/
#define IGNORE_RETURN(aStatement) \
do \
{ \
if (aStatement) \
{ \
} \
} while (false)
/**
* Overload the new operator to new an object at a specific address.
*
* @param[in] p The pointer of the address.
*/
inline void *operator new(size_t, void *p) throw() { return p; }
#endif // LIB_UTILS_CODE_UTILS_HPP_
+1
View File
@@ -216,6 +216,7 @@ target_include_directories(ot-posix-test-settings
${PROJECT_SOURCE_DIR}/include
${PROJECT_SOURCE_DIR}/src
${PROJECT_SOURCE_DIR}/src/core
${PROJECT_SOURCE_DIR}/src/include
${PROJECT_SOURCE_DIR}/src/posix/platform/include
)
add_test(NAME ot-posix-test-settings COMMAND ot-posix-test-settings)
+1 -1
View File
@@ -30,7 +30,7 @@
#include <assert.h>
#include "core/common/code_utils.hpp"
#include "common/code_utils.hpp"
namespace ot {
namespace Posix {
+1 -1
View File
@@ -48,7 +48,7 @@
#include <openthread/backbone_router_ftd.h>
#include <openthread/logging.h>
#include "core/common/arg_macros.hpp"
#include "common/arg_macros.hpp"
#include "core/common/debug.hpp"
namespace ot {
+1 -1
View File
@@ -32,7 +32,7 @@
#include <openthread/openthread-system.h>
#include "core/common/code_utils.hpp"
#include "common/code_utils.hpp"
#include "posix/platform/platform-posix.h"
const char *otSysGetRadioUrlHelpString(void)
+2 -1
View File
@@ -32,7 +32,7 @@ set(OT_POSIX_CONFIG_RCP_VENDOR_INTERFACE "vendor_interface_example.cpp"
set(OT_POSIX_CONFIG_RCP_VENDOR_DEPS_PACKAGE "" CACHE STRING
"path to CMake file to define and link posix vendor extension")
set(OT_POSIX_RCP_VENDOR_TARGET "" CACHE STRING
set(OT_POSIX_RCP_VENDOR_TARGET "" CACHE STRING
"name of vendor extension CMake target to link with posix library")
if(OT_POSIX_RCP_VENDOR_BUS)
@@ -47,6 +47,7 @@ if(OT_POSIX_RCP_VENDOR_BUS)
${PROJECT_SOURCE_DIR}/include
${PROJECT_SOURCE_DIR}/src
${PROJECT_SOURCE_DIR}/src/core
${PROJECT_SOURCE_DIR}/src/include
${PROJECT_SOURCE_DIR}/src/posix/platform/include
)
+1 -1
View File
@@ -27,7 +27,7 @@
*/
// Disable OpenThread's own new implementation to avoid duplicate definition
#define OT_CORE_COMMON_NEW_HPP_
#define OT_INCLUDE_COMMON_NEW_HPP_
#include "test_platform.h"
#include <map>
+2 -1
View File
@@ -34,9 +34,10 @@ include_directories(
${OPENTHREAD_DIR}/include
${OPENTHREAD_DIR}/src
${OPENTHREAD_DIR}/src/core
${OPENTHREAD_DIR}/src/include
${OPENTHREAD_DIR}/src/posix/platform
)
add_executable(ot-fct
cli.cpp
main.cpp