[error] add 'ot::Error' and 'kError{Name}' for use by core modules (#6237)

This commit adds a new core header files `common/error.hpp` which
defines `ot::Error` (mirroring `otError`) and `kError{Name}` constants
(mirroring the public `OT_ERROR_{NAME}` definitions). The new (C++
style) definitions are used by core modules. This commit also moves
`otThreadErrorToString()` (from `logging.hpp` to `error.hpp`) and
renames it to `ErrorToString()` which is used as the internal (to
core) function to covert an `Error` to a string.
This commit is contained in:
Abtin Keshavarzian
2021-03-15 21:07:07 -07:00
committed by GitHub
parent e992b8461c
commit 7dca56e982
255 changed files with 7171 additions and 7057 deletions
+2
View File
@@ -172,6 +172,7 @@ LOCAL_SRC_FILES := \
src/core/api/diags_api.cpp \
src/core/api/dns_api.cpp \
src/core/api/entropy_api.cpp \
src/core/api/error_api.cpp \
src/core/api/heap_api.cpp \
src/core/api/icmp6_api.cpp \
src/core/api/instance_api.cpp \
@@ -210,6 +211,7 @@ LOCAL_SRC_FILES := \
src/core/coap/coap_message.cpp \
src/core/coap/coap_secure.cpp \
src/core/common/crc16.cpp \
src/core/common/error.cpp \
src/core/common/instance.cpp \
src/core/common/logging.cpp \
src/core/common/message.cpp \
+5
View File
@@ -300,6 +300,7 @@ openthread_core_files = [
"api/diags_api.cpp",
"api/dns_api.cpp",
"api/entropy_api.cpp",
"api/error_api.cpp",
"api/heap_api.cpp",
"api/icmp6_api.cpp",
"api/instance_api.cpp",
@@ -357,6 +358,8 @@ openthread_core_files = [
"common/debug.hpp",
"common/encoding.hpp",
"common/equatable.hpp",
"common/error.cpp",
"common/error.hpp",
"common/extension.hpp",
"common/instance.cpp",
"common/instance.hpp",
@@ -618,11 +621,13 @@ openthread_core_files = [
openthread_radio_sources = [
"api/diags_api.cpp",
"api/error_api.cpp",
"api/instance_api.cpp",
"api/link_raw_api.cpp",
"api/logging_api.cpp",
"api/random_noncrypto_api.cpp",
"api/tasklet_api.cpp",
"common/error.hpp",
"common/instance.cpp",
"common/logging.cpp",
"common/random_manager.cpp",
+2
View File
@@ -48,6 +48,7 @@ set(COMMON_SOURCES
api/diags_api.cpp
api/dns_api.cpp
api/entropy_api.cpp
api/error_api.cpp
api/heap_api.cpp
api/icmp6_api.cpp
api/instance_api.cpp
@@ -86,6 +87,7 @@ set(COMMON_SOURCES
coap/coap_message.cpp
coap/coap_secure.cpp
common/crc16.cpp
common/error.cpp
common/instance.cpp
common/logging.cpp
common/message.cpp
+5
View File
@@ -125,6 +125,7 @@ SOURCES_COMMON = \
api/diags_api.cpp \
api/dns_api.cpp \
api/entropy_api.cpp \
api/error_api.cpp \
api/heap_api.cpp \
api/icmp6_api.cpp \
api/instance_api.cpp \
@@ -163,6 +164,7 @@ SOURCES_COMMON = \
coap/coap_message.cpp \
coap/coap_secure.cpp \
common/crc16.cpp \
common/error.cpp \
common/instance.cpp \
common/logging.cpp \
common/message.cpp \
@@ -291,12 +293,14 @@ EXTRA_DIST = \
libopenthread_radio_a_SOURCES = \
api/diags_api.cpp \
api/error_api.cpp \
api/heap_api.cpp \
api/instance_api.cpp \
api/link_raw_api.cpp \
api/logging_api.cpp \
api/random_noncrypto_api.cpp \
api/tasklet_api.cpp \
common/error.cpp \
common/instance.cpp \
common/logging.cpp \
common/random_manager.cpp \
@@ -369,6 +373,7 @@ HEADERS_COMMON = \
common/debug.hpp \
common/encoding.hpp \
common/equatable.hpp \
common/error.hpp \
common/extension.hpp \
common/instance.hpp \
common/iterator_utils.hpp \
+4 -4
View File
@@ -74,7 +74,7 @@ otError otBorderRouterGetNetData(otInstance *aInstance, bool aStable, uint8_t *a
otError otBorderRouterAddOnMeshPrefix(otInstance *aInstance, const otBorderRouterConfig *aConfig)
{
otError error;
Error error;
Instance & instance = *static_cast<Instance *>(aInstance);
const NetworkData::OnMeshPrefixConfig *config = static_cast<const NetworkData::OnMeshPrefixConfig *>(aConfig);
@@ -99,7 +99,7 @@ exit:
otError otBorderRouterRemoveOnMeshPrefix(otInstance *aInstance, const otIp6Prefix *aPrefix)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Instance & instance = *static_cast<Instance *>(aInstance);
const Ip6::Prefix *prefix = static_cast<const Ip6::Prefix *>(aPrefix);
@@ -108,7 +108,7 @@ otError otBorderRouterRemoveOnMeshPrefix(otInstance *aInstance, const otIp6Prefi
#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE
error = instance.Get<BackboneRouter::Local>().RemoveDomainPrefix(*prefix);
if (error == OT_ERROR_NOT_FOUND)
if (error == kErrorNotFound)
#endif
{
error = instance.Get<NetworkData::Local>().RemoveOnMeshPrefix(*prefix);
@@ -166,7 +166,7 @@ otError otBorderRouterRegister(otInstance *aInstance)
instance.Get<NetworkData::Notifier>().HandleServerDataUpdated();
return OT_ERROR_NONE;
return kErrorNone;
}
#endif // OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE
+4 -4
View File
@@ -224,13 +224,13 @@ otError otCoapSendRequestBlockWiseWithParameters(otInstance * aIn
otCoapBlockwiseTransmitHook aTransmitHook,
otCoapBlockwiseReceiveHook aReceiveHook)
{
otError error;
Error error;
Instance & instance = *static_cast<Instance *>(aInstance);
const Coap::TxParameters &txParameters = Coap::TxParameters::From(aTxParameters);
if (aTxParameters != nullptr)
{
VerifyOrExit(txParameters.IsValid(), error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(txParameters.IsValid(), error = kErrorInvalidArgs);
}
error = instance.GetApplicationCoap().SendMessage(*static_cast<Coap::Message *>(aMessage),
@@ -249,13 +249,13 @@ otError otCoapSendRequestWithParameters(otInstance * aInstance,
void * aContext,
const otCoapTxParameters *aTxParameters)
{
otError error;
Error error;
Instance & instance = *static_cast<Instance *>(aInstance);
const Coap::TxParameters &txParameters = Coap::TxParameters::From(aTxParameters);
if (aTxParameters != nullptr)
{
VerifyOrExit(txParameters.IsValid(), error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(txParameters.IsValid(), error = kErrorInvalidArgs);
}
error = instance.GetApplicationCoap().SendMessage(*static_cast<Coap::Message *>(aMessage),
+2 -2
View File
@@ -60,7 +60,7 @@ otError otCommissionerStop(otInstance *aInstance)
otError otCommissionerAddJoiner(otInstance *aInstance, const otExtAddress *aEui64, const char *aPskd, uint32_t aTimeout)
{
otError error;
Error error;
MeshCoP::Commissioner &commissioner = static_cast<Instance *>(aInstance)->Get<MeshCoP::Commissioner>();
if (aEui64 == nullptr)
@@ -95,7 +95,7 @@ otError otCommissionerGetNextJoinerInfo(otInstance *aInstance, uint16_t *aIterat
otError otCommissionerRemoveJoiner(otInstance *aInstance, const otExtAddress *aEui64)
{
otError error;
Error error;
MeshCoP::Commissioner &commissioner = static_cast<Instance *>(aInstance)->Get<MeshCoP::Commissioner>();
if (aEui64 == nullptr)
+43
View File
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2017-2021, 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 implements the OpenThread error code functions.
*/
#include "openthread-core-config.h"
#include "common/error.hpp"
using namespace ot;
const char *otThreadErrorToString(otError aError)
{
return ErrorToString(aError);
}
+4 -4
View File
@@ -46,11 +46,11 @@ using namespace ot;
otError otIp6SetEnabled(otInstance *aInstance, bool aEnabled)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Instance &instance = *static_cast<Instance *>(aInstance);
#if OPENTHREAD_CONFIG_LINK_RAW_ENABLE
VerifyOrExit(!instance.Get<Mac::LinkRaw>().IsEnabled(), error = OT_ERROR_INVALID_STATE);
VerifyOrExit(!instance.Get<Mac::LinkRaw>().IsEnabled(), error = kErrorInvalidState);
#endif
if (aEnabled)
@@ -246,12 +246,12 @@ bool otIp6IsAddressUnspecified(const otIp6Address *aAddress)
otError otIp6SelectSourceAddress(otInstance *aInstance, otMessageInfo *aMessageInfo)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Instance & instance = *static_cast<Instance *>(aInstance);
const Ip6::NetifUnicastAddress *netifAddr;
netifAddr = instance.Get<Ip6::Ip6>().SelectSourceAddress(*static_cast<Ip6::MessageInfo *>(aMessageInfo));
VerifyOrExit(netifAddr != nullptr, error = OT_ERROR_NOT_FOUND);
VerifyOrExit(netifAddr != nullptr, error = kErrorNotFound);
aMessageInfo->mSockAddr = netifAddr->GetAddress();
exit:
+1 -1
View File
@@ -48,7 +48,7 @@ otError otJamDetectionSetRssiThreshold(otInstance *aInstance, int8_t aRssiThresh
instance.Get<Utils::JamDetector>().SetRssiThreshold(aRssiThreshold);
return OT_ERROR_NONE;
return kErrorNone;
}
int8_t otJamDetectionGetRssiThreshold(otInstance *aInstance)
+1 -1
View File
@@ -80,7 +80,7 @@ const otExtAddress *otJoinerGetId(otInstance *aInstance)
otError otJoinerSetDiscerner(otInstance *aInstance, otJoinerDiscerner *aDiscerner)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
MeshCoP::Joiner &joiner = static_cast<Instance *>(aInstance)->Get<MeshCoP::Joiner>();
if (aDiscerner != nullptr)
+18 -18
View File
@@ -63,7 +63,7 @@ uint8_t otLinkGetChannel(otInstance *aInstance)
otError otLinkSetChannel(otInstance *aInstance, uint8_t aChannel)
{
otError error;
Error error;
Instance &instance = *static_cast<Instance *>(aInstance);
#if OPENTHREAD_CONFIG_LINK_RAW_ENABLE
@@ -74,7 +74,7 @@ otError otLinkSetChannel(otInstance *aInstance, uint8_t aChannel)
}
#endif
VerifyOrExit(instance.Get<Mle::MleRouter>().IsDisabled(), error = OT_ERROR_INVALID_STATE);
VerifyOrExit(instance.Get<Mle::MleRouter>().IsDisabled(), error = kErrorInvalidState);
SuccessOrExit(error = instance.Get<Mac::Mac>().SetPanChannel(aChannel));
instance.Get<MeshCoP::ActiveDataset>().Clear();
@@ -93,10 +93,10 @@ uint32_t otLinkGetSupportedChannelMask(otInstance *aInstance)
otError otLinkSetSupportedChannelMask(otInstance *aInstance, uint32_t aChannelMask)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Instance &instance = *static_cast<Instance *>(aInstance);
VerifyOrExit(instance.Get<Mle::MleRouter>().IsDisabled(), error = OT_ERROR_INVALID_STATE);
VerifyOrExit(instance.Get<Mle::MleRouter>().IsDisabled(), error = kErrorInvalidState);
instance.Get<Mac::Mac>().SetSupportedChannelMask(static_cast<Mac::ChannelMask>(aChannelMask));
@@ -113,11 +113,11 @@ const otExtAddress *otLinkGetExtendedAddress(otInstance *aInstance)
otError otLinkSetExtendedAddress(otInstance *aInstance, const otExtAddress *aExtAddress)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Instance &instance = *static_cast<Instance *>(aInstance);
OT_ASSERT(aExtAddress != nullptr);
VerifyOrExit(instance.Get<Mle::MleRouter>().IsDisabled(), error = OT_ERROR_INVALID_STATE);
VerifyOrExit(instance.Get<Mle::MleRouter>().IsDisabled(), error = kErrorInvalidState);
instance.Get<Mac::Mac>().SetExtAddress(*static_cast<const Mac::ExtAddress *>(aExtAddress));
@@ -143,10 +143,10 @@ otPanId otLinkGetPanId(otInstance *aInstance)
otError otLinkSetPanId(otInstance *aInstance, otPanId aPanId)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Instance &instance = *static_cast<Instance *>(aInstance);
VerifyOrExit(instance.Get<Mle::MleRouter>().IsDisabled(), error = OT_ERROR_INVALID_STATE);
VerifyOrExit(instance.Get<Mle::MleRouter>().IsDisabled(), error = kErrorInvalidState);
instance.Get<Mac::Mac>().SetPanId(aPanId);
instance.Get<MeshCoP::ActiveDataset>().Clear();
@@ -378,11 +378,11 @@ bool otLinkIsPromiscuous(otInstance *aInstance)
otError otLinkSetPromiscuous(otInstance *aInstance, bool aPromiscuous)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Instance &instance = *static_cast<Instance *>(aInstance);
// cannot enable IEEE 802.15.4 promiscuous mode if the Thread interface is enabled
VerifyOrExit(!instance.Get<ThreadNetif>().IsUp(), error = OT_ERROR_INVALID_STATE);
VerifyOrExit(!instance.Get<ThreadNetif>().IsUp(), error = kErrorInvalidState);
instance.Get<Mac::Mac>().SetPromiscuous(aPromiscuous);
@@ -392,11 +392,11 @@ exit:
otError otLinkSetEnabled(otInstance *aInstance, bool aEnable)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Instance &instance = *static_cast<Instance *>(aInstance);
// cannot disable the link layer if the Thread interface is enabled
VerifyOrExit(!instance.Get<ThreadNetif>().IsUp(), error = OT_ERROR_INVALID_STATE);
VerifyOrExit(!instance.Get<ThreadNetif>().IsUp(), error = kErrorInvalidState);
instance.Get<Mac::Mac>().SetEnabled(aEnable);
@@ -490,10 +490,10 @@ uint8_t otLinkCslGetChannel(otInstance *aInstance)
otError otLinkCslSetChannel(otInstance *aInstance, uint8_t aChannel)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Instance &instance = *static_cast<Instance *>(aInstance);
VerifyOrExit(Radio::IsCslChannelValid(aChannel), error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(Radio::IsCslChannelValid(aChannel), error = kErrorInvalidArgs);
instance.Get<Mac::Mac>().SetCslChannel(aChannel);
@@ -508,10 +508,10 @@ uint16_t otLinkCslGetPeriod(otInstance *aInstance)
otError otLinkCslSetPeriod(otInstance *aInstance, uint16_t aPeriod)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Instance &instance = *static_cast<Instance *>(aInstance);
VerifyOrExit((aPeriod == 0 || kMinCslPeriod <= aPeriod), error = OT_ERROR_INVALID_ARGS);
VerifyOrExit((aPeriod == 0 || kMinCslPeriod <= aPeriod), error = kErrorInvalidArgs);
instance.Get<Mac::Mac>().SetCslPeriod(aPeriod);
exit:
@@ -525,10 +525,10 @@ uint32_t otLinkCslGetTimeout(otInstance *aInstance)
otError otLinkCslSetTimeout(otInstance *aInstance, uint32_t aTimeout)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Instance &instance = *static_cast<Instance *>(aInstance);
VerifyOrExit(kMaxCslTimeout >= aTimeout, error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(kMaxCslTimeout >= aTimeout, error = kErrorInvalidArgs);
instance.Get<Mac::Mac>().SetCslTimeout(aTimeout);
exit:
+18 -18
View File
@@ -71,10 +71,10 @@ bool otLinkRawGetPromiscuous(otInstance *aInstance)
otError otLinkRawSetPromiscuous(otInstance *aInstance, bool aEnable)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Instance &instance = *static_cast<Instance *>(aInstance);
VerifyOrExit(instance.Get<Mac::LinkRaw>().IsEnabled(), error = OT_ERROR_INVALID_STATE);
VerifyOrExit(instance.Get<Mac::LinkRaw>().IsEnabled(), error = kErrorInvalidState);
instance.Get<Radio>().SetPromiscuous(aEnable);
exit:
@@ -83,10 +83,10 @@ exit:
otError otLinkRawSleep(otInstance *aInstance)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Instance &instance = *static_cast<Instance *>(aInstance);
VerifyOrExit(instance.Get<Mac::LinkRaw>().IsEnabled(), error = OT_ERROR_INVALID_STATE);
VerifyOrExit(instance.Get<Mac::LinkRaw>().IsEnabled(), error = kErrorInvalidState);
error = instance.Get<Radio>().Sleep();
@@ -129,10 +129,10 @@ otError otLinkRawEnergyScan(otInstance * aInstance,
otError otLinkRawSrcMatchEnable(otInstance *aInstance, bool aEnable)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Instance &instance = *static_cast<Instance *>(aInstance);
VerifyOrExit(instance.Get<Mac::LinkRaw>().IsEnabled(), error = OT_ERROR_INVALID_STATE);
VerifyOrExit(instance.Get<Mac::LinkRaw>().IsEnabled(), error = kErrorInvalidState);
instance.Get<Radio>().EnableSrcMatch(aEnable);
@@ -142,10 +142,10 @@ exit:
otError otLinkRawSrcMatchAddShortEntry(otInstance *aInstance, uint16_t aShortAddress)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Instance &instance = *static_cast<Instance *>(aInstance);
VerifyOrExit(instance.Get<Mac::LinkRaw>().IsEnabled(), error = OT_ERROR_INVALID_STATE);
VerifyOrExit(instance.Get<Mac::LinkRaw>().IsEnabled(), error = kErrorInvalidState);
error = instance.Get<Radio>().AddSrcMatchShortEntry(aShortAddress);
@@ -156,10 +156,10 @@ exit:
otError otLinkRawSrcMatchAddExtEntry(otInstance *aInstance, const otExtAddress *aExtAddress)
{
Mac::ExtAddress address;
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Instance & instance = *static_cast<Instance *>(aInstance);
VerifyOrExit(instance.Get<Mac::LinkRaw>().IsEnabled(), error = OT_ERROR_INVALID_STATE);
VerifyOrExit(instance.Get<Mac::LinkRaw>().IsEnabled(), error = kErrorInvalidState);
address.Set(aExtAddress->m8, Mac::ExtAddress::kReverseByteOrder);
error = instance.Get<Radio>().AddSrcMatchExtEntry(address);
@@ -170,10 +170,10 @@ exit:
otError otLinkRawSrcMatchClearShortEntry(otInstance *aInstance, uint16_t aShortAddress)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Instance &instance = *static_cast<Instance *>(aInstance);
VerifyOrExit(instance.Get<Mac::LinkRaw>().IsEnabled(), error = OT_ERROR_INVALID_STATE);
VerifyOrExit(instance.Get<Mac::LinkRaw>().IsEnabled(), error = kErrorInvalidState);
error = instance.Get<Radio>().ClearSrcMatchShortEntry(aShortAddress);
exit:
@@ -183,10 +183,10 @@ exit:
otError otLinkRawSrcMatchClearExtEntry(otInstance *aInstance, const otExtAddress *aExtAddress)
{
Mac::ExtAddress address;
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Instance & instance = *static_cast<Instance *>(aInstance);
VerifyOrExit(instance.Get<Mac::LinkRaw>().IsEnabled(), error = OT_ERROR_INVALID_STATE);
VerifyOrExit(instance.Get<Mac::LinkRaw>().IsEnabled(), error = kErrorInvalidState);
address.Set(aExtAddress->m8, Mac::ExtAddress::kReverseByteOrder);
error = instance.Get<Radio>().ClearSrcMatchExtEntry(address);
@@ -197,10 +197,10 @@ exit:
otError otLinkRawSrcMatchClearShortEntries(otInstance *aInstance)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Instance &instance = *static_cast<Instance *>(aInstance);
VerifyOrExit(instance.Get<Mac::LinkRaw>().IsEnabled(), error = OT_ERROR_INVALID_STATE);
VerifyOrExit(instance.Get<Mac::LinkRaw>().IsEnabled(), error = kErrorInvalidState);
instance.Get<Radio>().ClearSrcMatchShortEntries();
@@ -210,10 +210,10 @@ exit:
otError otLinkRawSrcMatchClearExtEntries(otInstance *aInstance)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Instance &instance = *static_cast<Instance *>(aInstance);
VerifyOrExit(instance.Get<Mac::LinkRaw>().IsEnabled(), error = OT_ERROR_INVALID_STATE);
VerifyOrExit(instance.Get<Mac::LinkRaw>().IsEnabled(), error = kErrorInvalidState);
instance.Get<Radio>().ClearSrcMatchExtEntries();
+2 -2
View File
@@ -51,7 +51,7 @@ otLogLevel otLoggingGetLevel(void)
#if OPENTHREAD_CONFIG_LOG_LEVEL_DYNAMIC_ENABLE
otError otLoggingSetLevel(otLogLevel aLogLevel)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
if (aLogLevel <= OT_LOG_LEVEL_DEBG && aLogLevel >= OT_LOG_LEVEL_NONE)
{
@@ -59,7 +59,7 @@ otError otLoggingSetLevel(otLogLevel aLogLevel)
}
else
{
error = OT_ERROR_INVALID_ARGS;
error = kErrorInvalidArgs;
}
return error;
+2 -2
View File
@@ -49,13 +49,13 @@ otError otMultiRadioGetNeighborInfo(otInstance * aInstance,
const otExtAddress * aExtAddress,
otMultiRadioNeighborInfo *aInfo)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Instance &instance = *static_cast<Instance *>(aInstance);
Neighbor *neighbor;
neighbor = instance.Get<NeighborTable>().FindNeighbor(*static_cast<const Mac::ExtAddress *>(aExtAddress),
Neighbor::kInStateAnyExceptInvalid);
VerifyOrExit(neighbor != NULL, error = OT_ERROR_NOT_FOUND);
VerifyOrExit(neighbor != NULL, error = kErrorNotFound);
neighbor->PopulateMultiRadioInfo(*aInfo);
+6 -6
View File
@@ -53,11 +53,11 @@ otError otNetDataGetNextOnMeshPrefix(otInstance * aInstance,
otNetworkDataIterator *aIterator,
otBorderRouterConfig * aConfig)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Instance & instance = *static_cast<Instance *>(aInstance);
NetworkData::OnMeshPrefixConfig *config = static_cast<NetworkData::OnMeshPrefixConfig *>(aConfig);
VerifyOrExit(aIterator && aConfig, error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(aIterator && aConfig, error = kErrorInvalidArgs);
error = instance.Get<NetworkData::Leader>().GetNextOnMeshPrefix(*aIterator, *config);
@@ -67,10 +67,10 @@ exit:
otError otNetDataGetNextRoute(otInstance *aInstance, otNetworkDataIterator *aIterator, otExternalRouteConfig *aConfig)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Instance &instance = *static_cast<Instance *>(aInstance);
VerifyOrExit(aIterator && aConfig, error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(aIterator && aConfig, error = kErrorInvalidArgs);
error = instance.Get<NetworkData::Leader>().GetNextExternalRoute(
*aIterator, *static_cast<NetworkData::ExternalRouteConfig *>(aConfig));
@@ -81,10 +81,10 @@ exit:
otError otNetDataGetNextService(otInstance *aInstance, otNetworkDataIterator *aIterator, otServiceConfig *aConfig)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Instance &instance = *static_cast<Instance *>(aInstance);
VerifyOrExit(aIterator && aConfig, error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(aIterator && aConfig, error = kErrorInvalidArgs);
error = instance.Get<NetworkData::Leader>().GetNextService(*aIterator,
*static_cast<NetworkData::ServiceConfig *>(aConfig));
+4 -4
View File
@@ -51,10 +51,10 @@ otNetworkTimeStatus otNetworkTimeGet(otInstance *aInstance, uint64_t *aNetworkTi
otError otNetworkTimeSetSyncPeriod(otInstance *aInstance, uint16_t aTimeSyncPeriod)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Instance &instance = *static_cast<Instance *>(aInstance);
VerifyOrExit(instance.Get<Mle::MleRouter>().IsDisabled(), error = OT_ERROR_INVALID_STATE);
VerifyOrExit(instance.Get<Mle::MleRouter>().IsDisabled(), error = kErrorInvalidState);
instance.Get<TimeSync>().SetTimeSyncPeriod(aTimeSyncPeriod);
@@ -71,10 +71,10 @@ uint16_t otNetworkTimeGetSyncPeriod(otInstance *aInstance)
otError otNetworkTimeSetXtalThreshold(otInstance *aInstance, uint16_t aXtalThreshold)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Instance &instance = *static_cast<Instance *>(aInstance);
VerifyOrExit(instance.Get<Mle::MleRouter>().IsDisabled(), error = OT_ERROR_INVALID_STATE);
VerifyOrExit(instance.Get<Mle::MleRouter>().IsDisabled(), error = kErrorInvalidState);
instance.Get<TimeSync>().SetXtalThreshold(aXtalThreshold);
+3 -3
View File
@@ -73,10 +73,10 @@ otError otServerRemoveService(otInstance * aInstance,
otError otServerGetNextService(otInstance *aInstance, otNetworkDataIterator *aIterator, otServiceConfig *aConfig)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Instance &instance = *static_cast<Instance *>(aInstance);
VerifyOrExit(aIterator && aConfig, error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(aIterator && aConfig, error = kErrorInvalidArgs);
error = instance.Get<NetworkData::Local>().GetNextService(*aIterator,
*static_cast<NetworkData::ServiceConfig *>(aConfig));
@@ -91,7 +91,7 @@ otError otServerRegister(otInstance *aInstance)
instance.Get<NetworkData::Notifier>().HandleServerDataUpdated();
return OT_ERROR_NONE;
return kErrorNone;
}
#endif // OPENTHREAD_CONFIG_TMF_NETDATA_SERVICE_ENABLE
+20 -20
View File
@@ -66,12 +66,12 @@ const otExtendedPanId *otThreadGetExtendedPanId(otInstance *aInstance)
otError otThreadSetExtendedPanId(otInstance *aInstance, const otExtendedPanId *aExtendedPanId)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Instance & instance = *static_cast<Instance *>(aInstance);
const Mac::ExtendedPanId &extPanId = *static_cast<const Mac::ExtendedPanId *>(aExtendedPanId);
Mle::MeshLocalPrefix prefix;
VerifyOrExit(instance.Get<Mle::MleRouter>().IsDisabled(), error = OT_ERROR_INVALID_STATE);
VerifyOrExit(instance.Get<Mle::MleRouter>().IsDisabled(), error = kErrorInvalidState);
instance.Get<Mac::Mac>().SetExtendedPanId(extPanId);
@@ -120,12 +120,12 @@ const otMasterKey *otThreadGetMasterKey(otInstance *aInstance)
otError otThreadSetMasterKey(otInstance *aInstance, const otMasterKey *aKey)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Instance &instance = *static_cast<Instance *>(aInstance);
OT_ASSERT(aKey != nullptr);
VerifyOrExit(instance.Get<Mle::MleRouter>().IsDisabled(), error = OT_ERROR_INVALID_STATE);
VerifyOrExit(instance.Get<Mle::MleRouter>().IsDisabled(), error = kErrorInvalidState);
error = instance.Get<KeyManager>().SetMasterKey(*static_cast<const MasterKey *>(aKey));
instance.Get<MeshCoP::ActiveDataset>().Clear();
@@ -158,10 +158,10 @@ const otMeshLocalPrefix *otThreadGetMeshLocalPrefix(otInstance *aInstance)
otError otThreadSetMeshLocalPrefix(otInstance *aInstance, const otMeshLocalPrefix *aMeshLocalPrefix)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Instance &instance = *static_cast<Instance *>(aInstance);
VerifyOrExit(instance.Get<Mle::MleRouter>().IsDisabled(), error = OT_ERROR_INVALID_STATE);
VerifyOrExit(instance.Get<Mle::MleRouter>().IsDisabled(), error = kErrorInvalidState);
instance.Get<Mle::MleRouter>().SetMeshLocalPrefix(*static_cast<const Mle::MeshLocalPrefix *>(aMeshLocalPrefix));
instance.Get<MeshCoP::ActiveDataset>().Clear();
@@ -187,10 +187,10 @@ const char *otThreadGetNetworkName(otInstance *aInstance)
otError otThreadSetNetworkName(otInstance *aInstance, const char *aNetworkName)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Instance &instance = *static_cast<Instance *>(aInstance);
VerifyOrExit(instance.Get<Mle::MleRouter>().IsDisabled(), error = OT_ERROR_INVALID_STATE);
VerifyOrExit(instance.Get<Mle::MleRouter>().IsDisabled(), error = kErrorInvalidState);
error = instance.Get<Mac::Mac>().SetNetworkName(aNetworkName);
instance.Get<MeshCoP::ActiveDataset>().Clear();
@@ -210,10 +210,10 @@ const char *otThreadGetDomainName(otInstance *aInstance)
otError otThreadSetDomainName(otInstance *aInstance, const char *aDomainName)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Instance &instance = *static_cast<Instance *>(aInstance);
VerifyOrExit(instance.Get<Mle::MleRouter>().IsDisabled(), error = OT_ERROR_INVALID_STATE);
VerifyOrExit(instance.Get<Mle::MleRouter>().IsDisabled(), error = kErrorInvalidState);
error = instance.Get<Mac::Mac>().SetDomainName(aDomainName);
@@ -225,7 +225,7 @@ exit:
otError otThreadSetFixedDuaInterfaceIdentifier(otInstance *aInstance, const otIp6InterfaceIdentifier *aIid)
{
Instance &instance = *static_cast<Instance *>(aInstance);
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
if (aIid)
{
@@ -317,11 +317,11 @@ otDeviceRole otThreadGetDeviceRole(otInstance *aInstance)
otError otThreadGetLeaderData(otInstance *aInstance, otLeaderData *aLeaderData)
{
Instance &instance = *static_cast<Instance *>(aInstance);
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
OT_ASSERT(aLeaderData != nullptr);
VerifyOrExit(instance.Get<Mle::MleRouter>().IsAttached(), error = OT_ERROR_DETACHED);
VerifyOrExit(instance.Get<Mle::MleRouter>().IsAttached(), error = kErrorDetached);
*aLeaderData = instance.Get<Mle::MleRouter>().GetLeaderData();
exit:
@@ -359,14 +359,14 @@ uint16_t otThreadGetRloc16(otInstance *aInstance)
otError otThreadGetParentInfo(otInstance *aInstance, otRouterInfo *aParentInfo)
{
Instance &instance = *static_cast<Instance *>(aInstance);
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Router * parent;
OT_ASSERT(aParentInfo != nullptr);
// Reference device needs get the original parent's info even after the node state changed.
#if !OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE
VerifyOrExit(instance.Get<Mle::MleRouter>().IsChild(), error = OT_ERROR_INVALID_STATE);
VerifyOrExit(instance.Get<Mle::MleRouter>().IsChild(), error = kErrorInvalidState);
#endif
parent = &instance.Get<Mle::MleRouter>().GetParent();
@@ -390,14 +390,14 @@ exit:
otError otThreadGetParentAverageRssi(otInstance *aInstance, int8_t *aParentRssi)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Instance &instance = *static_cast<Instance *>(aInstance);
OT_ASSERT(aParentRssi != nullptr);
*aParentRssi = instance.Get<Mle::MleRouter>().GetParent().GetLinkInfo().GetAverageRss();
VerifyOrExit(*aParentRssi != OT_RADIO_RSSI_INVALID, error = OT_ERROR_FAILED);
VerifyOrExit(*aParentRssi != OT_RADIO_RSSI_INVALID, error = kErrorFailed);
exit:
return error;
@@ -405,14 +405,14 @@ exit:
otError otThreadGetParentLastRssi(otInstance *aInstance, int8_t *aLastRssi)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Instance &instance = *static_cast<Instance *>(aInstance);
OT_ASSERT(aLastRssi != nullptr);
*aLastRssi = instance.Get<Mle::MleRouter>().GetParent().GetLinkInfo().GetLastRss();
VerifyOrExit(*aLastRssi != OT_RADIO_RSSI_INVALID, error = OT_ERROR_FAILED);
VerifyOrExit(*aLastRssi != OT_RADIO_RSSI_INVALID, error = kErrorFailed);
exit:
return error;
@@ -420,7 +420,7 @@ exit:
otError otThreadSetEnabled(otInstance *aInstance, bool aEnabled)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Instance &instance = *static_cast<Instance *>(aInstance);
if (aEnabled)
+11 -11
View File
@@ -139,7 +139,7 @@ otError otThreadSetJoinerUdpPort(otInstance *aInstance, uint16_t aJoinerUdpPort)
instance.Get<MeshCoP::JoinerRouter>().SetJoinerUdpPort(aJoinerUdpPort);
return OT_ERROR_NONE;
return kErrorNone;
}
uint32_t otThreadGetContextIdReuseDelay(otInstance *aInstance)
@@ -186,10 +186,10 @@ void otThreadSetRouterUpgradeThreshold(otInstance *aInstance, uint8_t aThreshold
otError otThreadReleaseRouterId(otInstance *aInstance, uint8_t aRouterId)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Instance &instance = *static_cast<Instance *>(aInstance);
VerifyOrExit(aRouterId <= Mle::kMaxRouterId, error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(aRouterId <= Mle::kMaxRouterId, error = kErrorInvalidArgs);
error = instance.Get<RouterTable>().Release(aRouterId);
@@ -199,7 +199,7 @@ exit:
otError otThreadBecomeRouter(otInstance *aInstance)
{
otError error = OT_ERROR_INVALID_STATE;
Error error = kErrorInvalidState;
Instance &instance = *static_cast<Instance *>(aInstance);
switch (instance.Get<Mle::MleRouter>().GetRole())
@@ -214,7 +214,7 @@ otError otThreadBecomeRouter(otInstance *aInstance)
case Mle::kRoleRouter:
case Mle::kRoleLeader:
error = OT_ERROR_NONE;
error = kErrorNone;
break;
}
@@ -279,20 +279,20 @@ otError otThreadGetChildNextIp6Address(otInstance * aInstance,
otChildIp6AddressIterator *aIterator,
otIp6Address * aAddress)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Instance & instance = *static_cast<Instance *>(aInstance);
const Child *child;
OT_ASSERT(aIterator != nullptr && aAddress != nullptr);
child = instance.Get<ChildTable>().GetChildAtIndex(aChildIndex);
VerifyOrExit(child != nullptr, error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(child->IsStateValidOrRestoring(), error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(child != nullptr, error = kErrorInvalidArgs);
VerifyOrExit(child->IsStateValidOrRestoring(), error = kErrorInvalidArgs);
{
Child::AddressIterator iter(*child, *aIterator);
VerifyOrExit(!iter.IsDone(), error = OT_ERROR_NOT_FOUND);
VerifyOrExit(!iter.IsDone(), error = kErrorNotFound);
*aAddress = *iter.GetAddress();
iter++;
@@ -352,10 +352,10 @@ const otPskc *otThreadGetPskc(otInstance *aInstance)
otError otThreadSetPskc(otInstance *aInstance, const otPskc *aPskc)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Instance &instance = *static_cast<Instance *>(aInstance);
VerifyOrExit(instance.Get<Mle::MleRouter>().IsDisabled(), error = OT_ERROR_INVALID_STATE);
VerifyOrExit(instance.Get<Mle::MleRouter>().IsDisabled(), error = kErrorInvalidState);
instance.Get<KeyManager>().SetPskc(*static_cast<const Pskc *>(aPskc));
instance.Get<MeshCoP::ActiveDataset>().Clear();
+6 -9
View File
@@ -41,9 +41,9 @@
namespace ot {
namespace BackboneRouter {
otError BackboneTmfAgent::Start(void)
Error BackboneTmfAgent::Start(void)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
SuccessOrExit(error = Coap::Start(kBackboneUdpPort, OT_NETIF_BACKBONE));
SubscribeMulticast(Get<Local>().GetAllNetworkBackboneRoutersAddress());
@@ -52,14 +52,11 @@ exit:
return error;
}
otError BackboneTmfAgent::Filter(const ot::Coap::Message &aMessage,
const Ip6::MessageInfo & aMessageInfo,
void * aContext)
Error BackboneTmfAgent::Filter(const ot::Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo, void *aContext)
{
OT_UNUSED_VARIABLE(aMessage);
return static_cast<BackboneTmfAgent *>(aContext)->IsBackboneTmfMessage(aMessageInfo) ? OT_ERROR_NONE
: OT_ERROR_NOT_TMF;
return static_cast<BackboneTmfAgent *>(aContext)->IsBackboneTmfMessage(aMessageInfo) ? kErrorNone : kErrorNotTmf;
}
bool BackboneTmfAgent::IsBackboneTmfMessage(const Ip6::MessageInfo &aMessageInfo) const
@@ -80,7 +77,7 @@ bool BackboneTmfAgent::IsBackboneTmfMessage(const Ip6::MessageInfo &aMessageInfo
void BackboneTmfAgent::SubscribeMulticast(const Ip6::Address &aAddress)
{
otError error;
Error error;
error = mSocket.JoinNetifMulticastGroup(OT_NETIF_BACKBONE, aAddress);
@@ -89,7 +86,7 @@ void BackboneTmfAgent::SubscribeMulticast(const Ip6::Address &aAddress)
void BackboneTmfAgent::UnsubscribeMulticast(const Ip6::Address &aAddress)
{
otError error;
Error error;
error = mSocket.LeaveNetifMulticastGroup(OT_NETIF_BACKBONE, aAddress);
+4 -4
View File
@@ -66,11 +66,11 @@ public:
/**
* This method starts the Backbone TMF agent.
*
* @retval OT_ERROR_NONE Successfully started the CoAP service.
* @retval OT_ERROR_FAILED Failed to start the Backbone TMF agent.
* @retval kErrorNone Successfully started the CoAP service.
* @retval kErrorFailed Failed to start the Backbone TMF agent.
*
*/
otError Start(void);
Error Start(void);
/**
* This method returns whether @p aMessageInfo meets Backbone Thread Management Framework Addressing Rules.
@@ -98,7 +98,7 @@ public:
void UnsubscribeMulticast(const Ip6::Address &aAddress);
private:
static otError Filter(const ot::Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo, void *aContext);
static Error Filter(const ot::Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo, void *aContext);
};
} // namespace BackboneRouter
+7 -7
View File
@@ -57,11 +57,11 @@ void Leader::Reset(void)
mDomainPrefix.SetLength(0);
}
otError Leader::GetConfig(BackboneRouterConfig &aConfig) const
Error Leader::GetConfig(BackboneRouterConfig &aConfig) const
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
VerifyOrExit(HasPrimary(), error = OT_ERROR_NOT_FOUND);
VerifyOrExit(HasPrimary(), error = kErrorNotFound);
aConfig = mConfig;
@@ -69,11 +69,11 @@ exit:
return error;
}
otError Leader::GetServiceId(uint8_t &aServiceId) const
Error Leader::GetServiceId(uint8_t &aServiceId) const
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
VerifyOrExit(HasPrimary(), error = OT_ERROR_NOT_FOUND);
VerifyOrExit(HasPrimary(), error = kErrorNotFound);
error = Get<NetworkData::Service::Manager>().GetServiceId<NetworkData::Service::BackboneRouter>(
/* aServerStable */ true, aServiceId);
@@ -256,7 +256,7 @@ void Leader::UpdateDomainPrefixConfig(void)
DomainPrefixState state;
bool found = false;
while (Get<NetworkData::Leader>().GetNextOnMeshPrefix(iterator, config) == OT_ERROR_NONE)
while (Get<NetworkData::Leader>().GetNextOnMeshPrefix(iterator, config) == kErrorNone)
{
if (config.mDp)
{
+6 -6
View File
@@ -106,22 +106,22 @@ public:
*
* @param[out] aConfig The Primary Backbone Router information.
*
* @retval OT_ERROR_NONE Successfully got the Primary Backbone Router information.
* @retval OT_ERROR_NOT_FOUND No Backbone Router in the Thread Network.
* @retval kErrorNone Successfully got the Primary Backbone Router information.
* @retval kErrorNotFound No Backbone Router in the Thread Network.
*
*/
otError GetConfig(BackboneRouterConfig &aConfig) const;
Error GetConfig(BackboneRouterConfig &aConfig) const;
/**
* This method gets the Backbone Router Service ID.
*
* @param[out] aServiceId The reference whether to put the Backbone Router Service ID.
*
* @retval OT_ERROR_NONE Successfully got the Backbone Router Service ID.
* @retval OT_ERROR_NOT_FOUND Backbone Router service doesn't exist.
* @retval kErrorNone Successfully got the Backbone Router Service ID.
* @retval kErrorNotFound Backbone Router service doesn't exist.
*
*/
otError GetServiceId(uint8_t &aServiceId) const;
Error GetServiceId(uint8_t &aServiceId) const;
/**
* This method gets the short address of the Primary Backbone Router.
+24 -24
View File
@@ -125,19 +125,19 @@ void Local::GetConfig(BackboneRouterConfig &aConfig) const
aConfig.mMlrTimeout = mMlrTimeout;
}
otError Local::SetConfig(const BackboneRouterConfig &aConfig)
Error Local::SetConfig(const BackboneRouterConfig &aConfig)
{
otError error = OT_ERROR_NONE;
bool update = false;
Error error = kErrorNone;
bool update = false;
VerifyOrExit(aConfig.mMlrTimeout >= Mle::kMlrTimeoutMin && aConfig.mMlrTimeout <= Mle::kMlrTimeoutMax,
error = OT_ERROR_INVALID_ARGS);
error = kErrorInvalidArgs);
// Validate configuration according to Thread 1.2.1 Specification 5.21.3.3:
// "The Reregistration Delay in seconds MUST be lower than (0.5 * MLR Timeout). It MUST be at least 1."
VerifyOrExit(aConfig.mReregistrationDelay >= 1, error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(aConfig.mReregistrationDelay >= 1, error = kErrorInvalidArgs);
static_assert(sizeof(aConfig.mReregistrationDelay) < sizeof(aConfig.mMlrTimeout),
"the calculation below might overflow");
VerifyOrExit(aConfig.mReregistrationDelay * 2 < aConfig.mMlrTimeout, error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(aConfig.mReregistrationDelay * 2 < aConfig.mMlrTimeout, error = kErrorInvalidArgs);
if (aConfig.mReregistrationDelay != mReregistrationDelay)
{
@@ -169,9 +169,9 @@ exit:
return error;
}
otError Local::AddService(bool aForce)
Error Local::AddService(bool aForce)
{
otError error = OT_ERROR_INVALID_STATE;
Error error = kErrorInvalidState;
NetworkData::Service::BackboneRouter::ServerData serverData;
VerifyOrExit(mState != OT_BACKBONE_ROUTER_STATE_DISABLED && Get<Mle::Mle>().IsAttached());
@@ -196,7 +196,7 @@ exit:
void Local::RemoveService(void)
{
otError error;
Error error;
SuccessOrExit(error = Get<NetworkData::Service::Manager>().Remove<NetworkData::Service::BackboneRouter>());
mIsServiceAdded = false;
@@ -266,7 +266,7 @@ void Local::HandleBackboneRouterPrimaryUpdate(Leader::State aState, const Backbo
mReregistrationDelay = aConfig.mReregistrationDelay;
mMlrTimeout = aConfig.mMlrTimeout;
Get<Notifier>().Signal(kEventThreadBackboneRouterLocalChanged);
if (AddService(true /* Force registration to refresh and restore Primary state */) == OT_ERROR_NONE)
if (AddService(true /* Force registration to refresh and restore Primary state */) == kErrorNone)
{
Get<NetworkData::Notifier>().HandleServerDataUpdated();
}
@@ -280,11 +280,11 @@ exit:
return;
}
otError Local::GetDomainPrefix(NetworkData::OnMeshPrefixConfig &aConfig)
Error Local::GetDomainPrefix(NetworkData::OnMeshPrefixConfig &aConfig)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
VerifyOrExit(mDomainPrefixConfig.GetPrefix().GetLength() > 0, error = OT_ERROR_NOT_FOUND);
VerifyOrExit(mDomainPrefixConfig.GetPrefix().GetLength() > 0, error = kErrorNotFound);
aConfig = mDomainPrefixConfig;
@@ -292,12 +292,12 @@ exit:
return error;
}
otError Local::RemoveDomainPrefix(const Ip6::Prefix &aPrefix)
Error Local::RemoveDomainPrefix(const Ip6::Prefix &aPrefix)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
VerifyOrExit(aPrefix.GetLength() > 0, error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(mDomainPrefixConfig.GetPrefix() == aPrefix, error = OT_ERROR_NOT_FOUND);
VerifyOrExit(aPrefix.GetLength() > 0, error = kErrorInvalidArgs);
VerifyOrExit(mDomainPrefixConfig.GetPrefix() == aPrefix, error = kErrorNotFound);
if (IsEnabled())
{
@@ -318,7 +318,7 @@ void Local::SetDomainPrefix(const NetworkData::OnMeshPrefixConfig &aConfig)
}
mDomainPrefixConfig = aConfig;
LogDomainPrefix("Set", OT_ERROR_NONE);
LogDomainPrefix("Set", kErrorNone);
if (IsEnabled())
{
@@ -390,7 +390,7 @@ exit:
void Local::RemoveDomainPrefixFromNetworkData(void)
{
otError error = OT_ERROR_NOT_FOUND; // only used for logging.
Error error = kErrorNotFound; // only used for logging.
if (mDomainPrefixConfig.mPrefix.mLength > 0)
{
@@ -402,7 +402,7 @@ void Local::RemoveDomainPrefixFromNetworkData(void)
void Local::AddDomainPrefixToNetworkData(void)
{
otError error = OT_ERROR_NOT_FOUND; // only used for logging.
Error error = kErrorNotFound; // only used for logging.
if (mDomainPrefixConfig.GetPrefix().GetLength() > 0)
{
@@ -413,16 +413,16 @@ void Local::AddDomainPrefixToNetworkData(void)
}
#if (OPENTHREAD_CONFIG_LOG_LEVEL >= OT_LOG_LEVEL_INFO) && (OPENTHREAD_CONFIG_LOG_BBR == 1)
void Local::LogDomainPrefix(const char *aAction, otError aError)
void Local::LogDomainPrefix(const char *aAction, Error aError)
{
otLogInfoBbr("%s Domain Prefix: %s, %s", aAction, mDomainPrefixConfig.GetPrefix().ToString().AsCString(),
otThreadErrorToString(aError));
ErrorToString(aError));
}
void Local::LogBackboneRouterService(const char *aAction, otError aError)
void Local::LogBackboneRouterService(const char *aAction, Error aError)
{
otLogInfoBbr("%s BBR Service: seqno (%d), delay (%ds), timeout (%ds), %s", aAction, mSequenceNumber,
mReregistrationDelay, mMlrTimeout, otThreadErrorToString(aError));
mReregistrationDelay, mMlrTimeout, ErrorToString(aError));
}
#endif
+18 -18
View File
@@ -114,11 +114,11 @@ public:
*
* @param[in] aConfig The configuration to set.
*
* @retval OT_ERROR_NONE Successfully updated configuration.
* @retval OT_ERROR_INVALID_ARGS The configuration in @p aConfig is invalid.
* @retval kErrorNone Successfully updated configuration.
* @retval kErrorInvalidArgs The configuration in @p aConfig is invalid.
*
*/
otError SetConfig(const BackboneRouterConfig &aConfig);
Error SetConfig(const BackboneRouterConfig &aConfig);
/**
* This method registers Backbone Router Dataset to Leader.
@@ -127,12 +127,12 @@ public:
* False to decide based on current BackboneRouterState.
*
*
* @retval OT_ERROR_NONE Successfully added the Service entry.
* @retval OT_ERROR_INVALID_STATE Not in the ready state to register.
* @retval OT_ERROR_NO_BUFS Insufficient space to add the Service entry.
* @retval kErrorNone Successfully added the Service entry.
* @retval kErrorInvalidState Not in the ready state to register.
* @retval kErrorNoBufs Insufficient space to add the Service entry.
*
*/
otError AddService(bool aForce = false);
Error AddService(bool aForce = false);
/**
* This method indicates whether or not the Backbone Router is Primary.
@@ -182,23 +182,23 @@ public:
*
* @param[out] aConfig A reference to the Domain Prefix configuration.
*
* @retval OT_ERROR_NONE Successfully got the Domain Prefix configuration.
* @retval OT_ERROR_NOT_FOUND No Domain Prefix was configured.
* @retval kErrorNone Successfully got the Domain Prefix configuration.
* @retval kErrorNotFound No Domain Prefix was configured.
*
*/
otError GetDomainPrefix(NetworkData::OnMeshPrefixConfig &aConfig);
Error GetDomainPrefix(NetworkData::OnMeshPrefixConfig &aConfig);
/**
* This method removes the local Domain Prefix configuration.
*
* @param[in] aPrefix A reference to the IPv6 Domain Prefix.
*
* @retval OT_ERROR_NONE Successfully removed the Domain Prefix.
* @retval OT_ERROR_INVALID_ARGS @p aPrefix is invalid.
* @retval OT_ERROR_NOT_FOUND No Domain Prefix was configured or @p aPrefix doesn't match.
* @retval kErrorNone Successfully removed the Domain Prefix.
* @retval kErrorInvalidArgs @p aPrefix is invalid.
* @retval kErrorNotFound No Domain Prefix was configured or @p aPrefix doesn't match.
*
*/
otError RemoveDomainPrefix(const Ip6::Prefix &aPrefix);
Error RemoveDomainPrefix(const Ip6::Prefix &aPrefix);
/**
* This method sets the local Domain Prefix configuration.
@@ -253,11 +253,11 @@ private:
void AddDomainPrefixToNetworkData(void);
void RemoveDomainPrefixFromNetworkData(void);
#if (OPENTHREAD_CONFIG_LOG_LEVEL >= OT_LOG_LEVEL_INFO) && (OPENTHREAD_CONFIG_LOG_BBR == 1)
void LogBackboneRouterService(const char *aAction, otError aError);
void LogDomainPrefix(const char *aAction, otError aError);
void LogBackboneRouterService(const char *aAction, Error aError);
void LogDomainPrefix(const char *aAction, Error aError);
#else
void LogBackboneRouterService(const char *, otError) {}
void LogDomainPrefix(const char *, otError) {}
void LogBackboneRouterService(const char *, Error) {}
void LogDomainPrefix(const char *, Error) {}
#endif
BackboneRouterState mState;
+74 -75
View File
@@ -88,7 +88,7 @@ Manager::Manager(Instance &aInstance)
void Manager::HandleNotifierEvents(Events aEvents)
{
otError error;
Error error;
if (aEvents.Contains(kEventThreadBackboneRouterStateChanged))
{
@@ -105,13 +105,13 @@ void Manager::HandleNotifierEvents(Events aEvents)
error = mBackboneTmfAgent.Stop();
if (error != OT_ERROR_NONE)
if (error != kErrorNone)
{
otLogWarnBbr("Stop Backbone TMF agent: %s", otThreadErrorToString(error));
otLogWarnBbr("Stop Backbone TMF agent: %s", ErrorToString(error));
}
else
{
otLogInfoBbr("Stop Backbone TMF agent: %s", otThreadErrorToString(error));
otLogInfoBbr("Stop Backbone TMF agent: %s", ErrorToString(error));
}
}
else
@@ -155,7 +155,7 @@ void Manager::HandleTimer(void)
#if OPENTHREAD_CONFIG_BACKBONE_ROUTER_MULTICAST_ROUTING_ENABLE
void Manager::HandleMulticastListenerRegistration(const Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
bool isPrimary = Get<BackboneRouter::Local>().IsPrimary();
ThreadStatusTlv::MlrStatus status = ThreadStatusTlv::kMlrSuccess;
BackboneRouterConfig config;
@@ -171,7 +171,7 @@ void Manager::HandleMulticastListenerRegistration(const Coap::Message &aMessage,
bool hasCommissionerSessionIdTlv = false;
bool processTimeoutTlv = false;
VerifyOrExit(aMessage.IsConfirmablePostRequest(), error = OT_ERROR_PARSE);
VerifyOrExit(aMessage.IsConfirmablePostRequest(), error = kErrorParse);
#if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE
// Required by Test Specification 5.10.22 DUA-TC-26, only for certification purpose
@@ -186,7 +186,7 @@ void Manager::HandleMulticastListenerRegistration(const Coap::Message &aMessage,
// TODO: (MLR) send configured MLR response for Reference Device
if (Tlv::Find<ThreadCommissionerSessionIdTlv>(aMessage, commissionerSessionId) == OT_ERROR_NONE)
if (Tlv::Find<ThreadCommissionerSessionIdTlv>(aMessage, commissionerSessionId) == kErrorNone)
{
const MeshCoP::CommissionerSessionIdTlv *commissionerSessionIdTlv =
static_cast<const MeshCoP::CommissionerSessionIdTlv *>(
@@ -199,12 +199,11 @@ void Manager::HandleMulticastListenerRegistration(const Coap::Message &aMessage,
hasCommissionerSessionIdTlv = true;
}
processTimeoutTlv =
hasCommissionerSessionIdTlv && (Tlv::Find<ThreadTimeoutTlv>(aMessage, timeout) == OT_ERROR_NONE);
processTimeoutTlv = hasCommissionerSessionIdTlv && (Tlv::Find<ThreadTimeoutTlv>(aMessage, timeout) == kErrorNone);
VerifyOrExit(Tlv::FindTlvValueOffset(aMessage, IPv6AddressesTlv::kIPv6Addresses, addressesOffset,
addressesLength) == OT_ERROR_NONE,
error = OT_ERROR_PARSE);
addressesLength) == kErrorNone,
error = kErrorParse);
VerifyOrExit(addressesLength % sizeof(Ip6::Address) == 0, status = ThreadStatusTlv::kMlrGeneralFailure);
VerifyOrExit(addressesLength / sizeof(Ip6::Address) <= kIPv6AddressesNumMax,
status = ThreadStatusTlv::kMlrGeneralFailure);
@@ -249,16 +248,16 @@ void Manager::HandleMulticastListenerRegistration(const Coap::Message &aMessage,
switch (mMulticastListenersTable.Add(address, expireTime))
{
case OT_ERROR_NONE:
case kErrorNone:
failed = false;
break;
case OT_ERROR_INVALID_ARGS:
case kErrorInvalidArgs:
if (status == ThreadStatusTlv::kMlrSuccess)
{
status = ThreadStatusTlv::kMlrInvalid;
}
break;
case OT_ERROR_NO_BUFS:
case kErrorNoBufs:
if (status == ThreadStatusTlv::kMlrSuccess)
{
status = ThreadStatusTlv::kMlrNoResources;
@@ -281,7 +280,7 @@ void Manager::HandleMulticastListenerRegistration(const Coap::Message &aMessage,
}
exit:
if (error == OT_ERROR_NONE)
if (error == kErrorNone)
{
SendMulticastListenerRegistrationResponse(aMessage, aMessageInfo, status, addresses, failedAddressNum);
}
@@ -299,10 +298,10 @@ void Manager::SendMulticastListenerRegistrationResponse(const Coap::Message &
Ip6::Address * aFailedAddresses,
uint8_t aFailedAddressNum)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Coap::Message *message = nullptr;
VerifyOrExit((message = Get<Tmf::TmfAgent>().NewMessage()) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((message = Get<Tmf::TmfAgent>().NewMessage()) != nullptr, error = kErrorNoBufs);
SuccessOrExit(message->SetDefaultResponseHeader(aMessage));
SuccessOrExit(message->SetPayloadMarker());
@@ -327,14 +326,14 @@ void Manager::SendMulticastListenerRegistrationResponse(const Coap::Message &
exit:
FreeMessageOnError(message, error);
otLogInfoBbr("Sent MLR.rsp (status=%d): %s", aStatus, otThreadErrorToString(error));
otLogInfoBbr("Sent MLR.rsp (status=%d): %s", aStatus, ErrorToString(error));
}
void Manager::SendBackboneMulticastListenerRegistration(const Ip6::Address *aAddresses,
uint8_t aAddressNum,
uint32_t aTimeout)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Coap::Message * message = nullptr;
Ip6::MessageInfo messageInfo;
IPv6AddressesTlv addressesTlv;
@@ -342,7 +341,7 @@ void Manager::SendBackboneMulticastListenerRegistration(const Ip6::Address *aAdd
OT_ASSERT(aAddressNum >= kIPv6AddressesNumMin && aAddressNum <= kIPv6AddressesNumMax);
VerifyOrExit((message = backboneTmf.NewMessage()) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((message = backboneTmf.NewMessage()) != nullptr, error = kErrorNoBufs);
SuccessOrExit(error = message->InitAsNonConfirmablePost(UriPath::kBackboneMlr));
SuccessOrExit(error = message->SetPayloadMarker());
@@ -364,14 +363,14 @@ void Manager::SendBackboneMulticastListenerRegistration(const Ip6::Address *aAdd
exit:
FreeMessageOnError(message, error);
otLogInfoBbr("Sent BMLR.ntf: %s", otThreadErrorToString(error));
otLogInfoBbr("Sent BMLR.ntf: %s", ErrorToString(error));
}
#endif // OPENTHREAD_CONFIG_BACKBONE_ROUTER_MULTICAST_ROUTING_ENABLE
#if OPENTHREAD_CONFIG_BACKBONE_ROUTER_DUA_NDPROXYING_ENABLE
void Manager::HandleDuaRegistration(const Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
ThreadStatusTlv::DuaStatus status = ThreadStatusTlv::kDuaSuccess;
bool isPrimary = Get<BackboneRouter::Local>().IsPrimary();
uint32_t lastTransactionTime;
@@ -382,8 +381,8 @@ void Manager::HandleDuaRegistration(const Coap::Message &aMessage, const Ip6::Me
Coap::Code duaRespCoapCode = Coap::kCodeEmpty;
#endif
VerifyOrExit(aMessageInfo.GetPeerAddr().GetIid().IsRoutingLocator(), error = OT_ERROR_DROP);
VerifyOrExit(aMessage.IsConfirmablePostRequest(), error = OT_ERROR_PARSE);
VerifyOrExit(aMessageInfo.GetPeerAddr().GetIid().IsRoutingLocator(), error = kErrorDrop);
VerifyOrExit(aMessage.IsConfirmablePostRequest(), error = kErrorParse);
SuccessOrExit(error = Tlv::Find<ThreadTargetTlv>(aMessage, target));
SuccessOrExit(error = Tlv::Find<ThreadMeshLocalEidTlv>(aMessage, meshLocalIid));
@@ -408,19 +407,19 @@ void Manager::HandleDuaRegistration(const Coap::Message &aMessage, const Ip6::Me
VerifyOrExit(Get<BackboneRouter::Leader>().HasDomainPrefix(), status = ThreadStatusTlv::kDuaGeneralFailure);
VerifyOrExit(Get<BackboneRouter::Leader>().IsDomainUnicast(target), status = ThreadStatusTlv::kDuaInvalid);
hasLastTransactionTime = (Tlv::Find<ThreadLastTransactionTimeTlv>(aMessage, lastTransactionTime) == OT_ERROR_NONE);
hasLastTransactionTime = (Tlv::Find<ThreadLastTransactionTimeTlv>(aMessage, lastTransactionTime) == kErrorNone);
switch (mNdProxyTable.Register(target.GetIid(), meshLocalIid, aMessageInfo.GetPeerAddr().GetIid().GetLocator(),
hasLastTransactionTime ? &lastTransactionTime : nullptr))
{
case OT_ERROR_NONE:
case kErrorNone:
// TODO: update its EID-to-RLOC Map Cache based on the pair {DUA, RLOC16-source} which is gleaned from the
// DUA.req packet according to Thread Spec. 5.23.3.6.2
break;
case OT_ERROR_DUPLICATED:
case kErrorDuplicated:
status = ThreadStatusTlv::kDuaDuplicate;
break;
case OT_ERROR_NO_BUFS:
case kErrorNoBufs:
status = ThreadStatusTlv::kDuaNoResources;
break;
default:
@@ -429,9 +428,9 @@ void Manager::HandleDuaRegistration(const Coap::Message &aMessage, const Ip6::Me
}
exit:
otLogInfoBbr("Received DUA.req on %s: %s", (isPrimary ? "PBBR" : "SBBR"), otThreadErrorToString(error));
otLogInfoBbr("Received DUA.req on %s: %s", (isPrimary ? "PBBR" : "SBBR"), ErrorToString(error));
if (error == OT_ERROR_NONE)
if (error == kErrorNone)
{
#if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE
if (duaRespCoapCode != Coap::kCodeEmpty)
@@ -451,10 +450,10 @@ void Manager::SendDuaRegistrationResponse(const Coap::Message & aMessage,
const Ip6::Address & aTarget,
ThreadStatusTlv::DuaStatus aStatus)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Coap::Message *message = nullptr;
VerifyOrExit((message = Get<Tmf::TmfAgent>().NewMessage()) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((message = Get<Tmf::TmfAgent>().NewMessage()) != nullptr, error = kErrorNoBufs);
SuccessOrExit(message->SetDefaultResponseHeader(aMessage));
SuccessOrExit(message->SetPayloadMarker());
@@ -467,7 +466,7 @@ void Manager::SendDuaRegistrationResponse(const Coap::Message & aMessage,
exit:
FreeMessageOnError(message, error);
otLogInfoBbr("Sent DUA.rsp for DUA %s, status %d %s", aTarget.ToString().AsCString(), aStatus,
otThreadErrorToString(error));
ErrorToString(error));
}
#endif // OPENTHREAD_CONFIG_BACKBONE_ROUTER_DUA_NDPROXYING_ENABLE
@@ -509,7 +508,7 @@ bool Manager::ShouldForwardDuaToBackbone(const Ip6::Address &aAddress)
{
bool forwardToBackbone = false;
Mac::ShortAddress rloc16;
otError error;
Error error;
VerifyOrExit(Get<Local>().IsPrimary());
VerifyOrExit(Get<Leader>().IsDomainUnicast(aAddress));
@@ -517,7 +516,7 @@ bool Manager::ShouldForwardDuaToBackbone(const Ip6::Address &aAddress)
VerifyOrExit(!mNdProxyTable.IsRegistered(aAddress.GetIid()));
error = Get<AddressResolver>().Resolve(aAddress, rloc16, /* aAllowAddressQuery */ false);
VerifyOrExit(error != OT_ERROR_NONE || rloc16 == Get<Mle::MleRouter>().GetRloc16());
VerifyOrExit(error != kErrorNone || rloc16 == Get<Mle::MleRouter>().GetRloc16());
// TODO: check if the DUA is an address of any Child?
forwardToBackbone = true;
@@ -526,15 +525,15 @@ exit:
return forwardToBackbone;
}
otError Manager::SendBackboneQuery(const Ip6::Address &aDua, uint16_t aRloc16)
Error Manager::SendBackboneQuery(const Ip6::Address &aDua, uint16_t aRloc16)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Coap::Message * message = nullptr;
Ip6::MessageInfo messageInfo;
VerifyOrExit(Get<BackboneRouter::Local>().IsPrimary(), error = OT_ERROR_INVALID_STATE);
VerifyOrExit(Get<BackboneRouter::Local>().IsPrimary(), error = kErrorInvalidState);
VerifyOrExit((message = mBackboneTmfAgent.NewPriorityMessage()) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((message = mBackboneTmfAgent.NewPriorityMessage()) != nullptr, error = kErrorNoBufs);
SuccessOrExit(error = message->InitAsNonConfirmablePost(UriPath::kBackboneQuery));
SuccessOrExit(error = message->SetPayloadMarker());
@@ -556,7 +555,7 @@ otError Manager::SendBackboneQuery(const Ip6::Address &aDua, uint16_t aRloc16)
exit:
otLogInfoBbr("SendBackboneQuery for %s (rloc16=%04x): %s", aDua.ToString().AsCString(), aRloc16,
otThreadErrorToString(error));
ErrorToString(error));
FreeMessageOnError(message, error);
return error;
}
@@ -569,31 +568,31 @@ void Manager::HandleBackboneQuery(void *aContext, otMessage *aMessage, const otM
void Manager::HandleBackboneQuery(const Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Ip6::Address dua;
uint16_t rloc16 = Mac::kShortAddrInvalid;
NdProxyTable::NdProxy *ndProxy;
VerifyOrExit(aMessageInfo.IsHostInterface(), error = OT_ERROR_DROP);
VerifyOrExit(aMessageInfo.IsHostInterface(), error = kErrorDrop);
VerifyOrExit(Get<Local>().IsPrimary(), error = OT_ERROR_INVALID_STATE);
VerifyOrExit(aMessage.IsNonConfirmablePostRequest(), error = OT_ERROR_PARSE);
VerifyOrExit(Get<Local>().IsPrimary(), error = kErrorInvalidState);
VerifyOrExit(aMessage.IsNonConfirmablePostRequest(), error = kErrorParse);
SuccessOrExit(error = Tlv::Find<ThreadTargetTlv>(aMessage, dua));
error = Tlv::Find<ThreadRloc16Tlv>(aMessage, rloc16);
VerifyOrExit(error == OT_ERROR_NONE || error == OT_ERROR_NOT_FOUND);
VerifyOrExit(error == kErrorNone || error == kErrorNotFound);
otLogInfoBbr("Received BB.qry from %s for %s (rloc16=%04x)", aMessageInfo.GetPeerAddr().ToString().AsCString(),
dua.ToString().AsCString(), rloc16);
ndProxy = mNdProxyTable.ResolveDua(dua);
VerifyOrExit(ndProxy != nullptr && !ndProxy->GetDadFlag(), error = OT_ERROR_NOT_FOUND);
VerifyOrExit(ndProxy != nullptr && !ndProxy->GetDadFlag(), error = kErrorNotFound);
error = SendBackboneAnswer(aMessageInfo, dua, rloc16, *ndProxy);
exit:
otLogInfoBbr("HandleBackboneQuery: %s", otThreadErrorToString(error));
otLogInfoBbr("HandleBackboneQuery: %s", ErrorToString(error));
}
void Manager::HandleBackboneAnswer(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo)
@@ -604,7 +603,7 @@ void Manager::HandleBackboneAnswer(void *aContext, otMessage *aMessage, const ot
void Manager::HandleBackboneAnswer(const Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
bool proactive;
Ip6::Address dua;
Ip6::InterfaceIdentifier meshLocalIid;
@@ -612,10 +611,10 @@ void Manager::HandleBackboneAnswer(const Coap::Message &aMessage, const Ip6::Mes
uint32_t timeSinceLastTransaction;
uint16_t srcRloc16 = Mac::kShortAddrInvalid;
VerifyOrExit(aMessageInfo.IsHostInterface(), error = OT_ERROR_DROP);
VerifyOrExit(aMessageInfo.IsHostInterface(), error = kErrorDrop);
VerifyOrExit(Get<Local>().IsPrimary(), error = OT_ERROR_INVALID_STATE);
VerifyOrExit(aMessage.IsPostRequest(), error = OT_ERROR_PARSE);
VerifyOrExit(Get<Local>().IsPrimary(), error = kErrorInvalidState);
VerifyOrExit(aMessage.IsPostRequest(), error = kErrorParse);
proactive = !aMessage.IsConfirmable();
@@ -627,7 +626,7 @@ void Manager::HandleBackboneAnswer(const Coap::Message &aMessage, const Ip6::Mes
Tlv::FindTlvValueOffset(aMessage, ThreadTlv::kNetworkName, networkNameOffset, networkNameLength));
error = Tlv::Find<ThreadRloc16Tlv>(aMessage, srcRloc16);
VerifyOrExit(error == OT_ERROR_NONE || error == OT_ERROR_NOT_FOUND);
VerifyOrExit(error == kErrorNone || error == kErrorNotFound);
if (proactive)
{
@@ -645,40 +644,40 @@ void Manager::HandleBackboneAnswer(const Coap::Message &aMessage, const Ip6::Mes
SuccessOrExit(error = mBackboneTmfAgent.SendEmptyAck(aMessage, aMessageInfo));
exit:
otLogInfoBbr("HandleBackboneAnswer: %s", otThreadErrorToString(error));
otLogInfoBbr("HandleBackboneAnswer: %s", ErrorToString(error));
}
otError Manager::SendProactiveBackboneNotification(const Ip6::Address & aDua,
const Ip6::InterfaceIdentifier &aMeshLocalIid,
uint32_t aTimeSinceLastTransaction)
Error Manager::SendProactiveBackboneNotification(const Ip6::Address & aDua,
const Ip6::InterfaceIdentifier &aMeshLocalIid,
uint32_t aTimeSinceLastTransaction)
{
return SendBackboneAnswer(Get<BackboneRouter::Local>().GetAllDomainBackboneRoutersAddress(),
BackboneRouter::kBackboneUdpPort, aDua, aMeshLocalIid, aTimeSinceLastTransaction,
Mac::kShortAddrInvalid);
}
otError Manager::SendBackboneAnswer(const Ip6::MessageInfo & aQueryMessageInfo,
const Ip6::Address & aDua,
uint16_t aSrcRloc16,
const NdProxyTable::NdProxy &aNdProxy)
Error Manager::SendBackboneAnswer(const Ip6::MessageInfo & aQueryMessageInfo,
const Ip6::Address & aDua,
uint16_t aSrcRloc16,
const NdProxyTable::NdProxy &aNdProxy)
{
return SendBackboneAnswer(aQueryMessageInfo.GetPeerAddr(), aQueryMessageInfo.GetPeerPort(), aDua,
aNdProxy.GetMeshLocalIid(), aNdProxy.GetTimeSinceLastTransaction(), aSrcRloc16);
}
otError Manager::SendBackboneAnswer(const Ip6::Address & aDstAddr,
uint16_t aDstPort,
const Ip6::Address & aDua,
const Ip6::InterfaceIdentifier &aMeshLocalIid,
uint32_t aTimeSinceLastTransaction,
uint16_t aSrcRloc16)
Error Manager::SendBackboneAnswer(const Ip6::Address & aDstAddr,
uint16_t aDstPort,
const Ip6::Address & aDua,
const Ip6::InterfaceIdentifier &aMeshLocalIid,
uint32_t aTimeSinceLastTransaction,
uint16_t aSrcRloc16)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Coap::Message * message = nullptr;
Ip6::MessageInfo messageInfo;
bool proactive = aDstAddr.IsMulticast();
VerifyOrExit((message = mBackboneTmfAgent.NewPriorityMessage()) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((message = mBackboneTmfAgent.NewPriorityMessage()) != nullptr, error = kErrorNoBufs);
SuccessOrExit(error = message->Init(proactive ? Coap::kTypeNonConfirmable : Coap::kTypeConfirmable, Coap::kCodePost,
UriPath::kBackboneAnswer));
@@ -711,7 +710,7 @@ otError Manager::SendBackboneAnswer(const Ip6::Address & aDstAddr,
exit:
otLogInfoBbr("Send %s for %s (rloc16=%04x): %s", proactive ? "PRO_BB.ntf" : "BB.ans", aDua.ToString().AsCString(),
aSrcRloc16, otThreadErrorToString(error));
aSrcRloc16, ErrorToString(error));
FreeMessageOnError(message, error);
return error;
@@ -719,13 +718,13 @@ exit:
void Manager::HandleDadBackboneAnswer(const Ip6::Address &aDua, const Ip6::InterfaceIdentifier &aMeshLocalIid)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
NdProxyTable::NdProxy *ndProxy = mNdProxyTable.ResolveDua(aDua);
bool duplicate = false;
OT_UNUSED_VARIABLE(error);
VerifyOrExit(ndProxy != nullptr, error = OT_ERROR_NOT_FOUND);
VerifyOrExit(ndProxy != nullptr, error = kErrorNotFound);
duplicate = ndProxy->GetMeshLocalIid() != aMeshLocalIid;
@@ -740,7 +739,7 @@ void Manager::HandleDadBackboneAnswer(const Ip6::Address &aDua, const Ip6::Inter
ot::BackboneRouter::NdProxyTable::NotifyDadComplete(*ndProxy, duplicate);
exit:
otLogInfoBbr("HandleDadBackboneAnswer: %s, target=%s, mliid=%s, duplicate=%s", otThreadErrorToString(error),
otLogInfoBbr("HandleDadBackboneAnswer: %s, target=%s, mliid=%s, duplicate=%s", ErrorToString(error),
aDua.ToString().AsCString(), aMeshLocalIid.ToString().AsCString(), duplicate ? "Y" : "N");
}
@@ -763,12 +762,12 @@ void Manager::HandleProactiveBackboneNotification(const Ip6::Address &
const Ip6::InterfaceIdentifier &aMeshLocalIid,
uint32_t aTimeSinceLastTransaction)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
NdProxyTable::NdProxy *ndProxy = mNdProxyTable.ResolveDua(aDua);
OT_UNUSED_VARIABLE(error);
VerifyOrExit(ndProxy != nullptr, error = OT_ERROR_NOT_FOUND);
VerifyOrExit(ndProxy != nullptr, error = kErrorNotFound);
if (ndProxy->GetMeshLocalIid() == aMeshLocalIid)
{
@@ -792,7 +791,7 @@ void Manager::HandleProactiveBackboneNotification(const Ip6::Address &
}
exit:
otLogInfoBbr("HandleProactiveBackboneNotification: %s, target=%s, mliid=%s, LTT=%lds", otThreadErrorToString(error),
otLogInfoBbr("HandleProactiveBackboneNotification: %s, target=%s, mliid=%s, LTT=%lds", ErrorToString(error),
aDua.ToString().AsCString(), aMeshLocalIid.ToString().AsCString(), aTimeSinceLastTransaction);
}
#endif // OPENTHREAD_CONFIG_BACKBONE_ROUTER_DUA_NDPROXYING_ENABLE
+11 -11
View File
@@ -145,12 +145,12 @@ public:
* @param[in] aRloc16 The short address of the address resolution initiator or `Mac::kShortAddrInvalid` for
* DUA DAD.
*
* @retval OT_ERROR_NONE Successfully sent BB.qry on backbone link.
* @retval OT_ERROR_INVALID_STATE If the Backbone Router is not primary, or not enabled.
* @retval OT_ERROR_NO_BUFS If insufficient message buffers available.
* @retval kErrorNone Successfully sent BB.qry on backbone link.
* @retval kErrorInvalidState If the Backbone Router is not primary, or not enabled.
* @retval kErrorNoBufs If insufficient message buffers available.
*
*/
otError SendBackboneQuery(const Ip6::Address &aDua, uint16_t aRloc16 = Mac::kShortAddrInvalid);
Error SendBackboneQuery(const Ip6::Address &aDua, uint16_t aRloc16 = Mac::kShortAddrInvalid);
/**
* This method send a Proactive Backbone Notification (PRO_BB.ntf) on the Backbone link.
@@ -159,13 +159,13 @@ public:
* @param[in] aMeshLocalIid The Mesh-Local IID to notify.
* @param[in] aTimeSinceLastTransaction Time since last transaction (in seconds).
*
* @retval OT_ERROR_NONE Successfully sent PRO_BB.ntf on backbone link.
* @retval OT_ERROR_NO_BUFS If insufficient message buffers available.
* @retval kErrorNone Successfully sent PRO_BB.ntf on backbone link.
* @retval kErrorNoBufs If insufficient message buffers available.
*
*/
otError SendProactiveBackboneNotification(const Ip6::Address & aDua,
const Ip6::InterfaceIdentifier &aMeshLocalIid,
uint32_t aTimeSinceLastTransaction);
Error SendProactiveBackboneNotification(const Ip6::Address & aDua,
const Ip6::InterfaceIdentifier &aMeshLocalIid,
uint32_t aTimeSinceLastTransaction);
private:
enum
@@ -204,11 +204,11 @@ private:
void HandleBackboneQuery(const Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
static void HandleBackboneAnswer(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo);
void HandleBackboneAnswer(const Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
otError SendBackboneAnswer(const Ip6::MessageInfo & aQueryMessageInfo,
Error SendBackboneAnswer(const Ip6::MessageInfo & aQueryMessageInfo,
const Ip6::Address & aDua,
uint16_t aSrcRloc16,
const NdProxyTable::NdProxy &aNdProxy);
otError SendBackboneAnswer(const Ip6::Address & aDstAddr,
Error SendBackboneAnswer(const Ip6::Address & aDstAddr,
uint16_t aDstPort,
const Ip6::Address & aDua,
const Ip6::InterfaceIdentifier &aMeshLocalIid,
@@ -48,11 +48,11 @@ namespace ot {
namespace BackboneRouter {
otError MulticastListenersTable::Add(const Ip6::Address &aAddress, Time aExpireTime)
Error MulticastListenersTable::Add(const Ip6::Address &aAddress, Time aExpireTime)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
VerifyOrExit(aAddress.IsMulticastLargerThanRealmLocal(), error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(aAddress.IsMulticastLargerThanRealmLocal(), error = kErrorInvalidArgs);
for (uint16_t i = 0; i < mNumValidListeners; i++)
{
@@ -66,7 +66,7 @@ otError MulticastListenersTable::Add(const Ip6::Address &aAddress, Time aExpireT
}
}
VerifyOrExit(mNumValidListeners < OT_ARRAY_LENGTH(mListeners), error = OT_ERROR_NO_BUFS);
VerifyOrExit(mNumValidListeners < OT_ARRAY_LENGTH(mListeners), error = kErrorNoBufs);
mListeners[mNumValidListeners].SetAddress(aAddress);
mListeners[mNumValidListeners].SetExpireTime(aExpireTime);
@@ -87,7 +87,7 @@ exit:
void MulticastListenersTable::Remove(const Ip6::Address &aAddress)
{
otError error = OT_ERROR_NOT_FOUND;
Error error = kErrorNotFound;
for (uint16_t i = 0; i < mNumValidListeners; i++)
{
@@ -108,7 +108,7 @@ void MulticastListenersTable::Remove(const Ip6::Address &aAddress)
mCallback(mCallbackContext, OT_BACKBONE_ROUTER_MULTICAST_LISTENER_REMOVED, &aAddress);
}
ExitNow(error = OT_ERROR_NONE);
ExitNow(error = kErrorNone);
}
}
@@ -124,7 +124,7 @@ void MulticastListenersTable::Expire(void)
while (mNumValidListeners > 0 && now >= mListeners[0].GetExpireTime())
{
LogMulticastListenersTable("Expire", mListeners[0].GetAddress(), mListeners[0].GetExpireTime(), OT_ERROR_NONE);
LogMulticastListenersTable("Expire", mListeners[0].GetAddress(), mListeners[0].GetExpireTime(), kErrorNone);
address = mListeners[0].GetAddress();
mNumValidListeners--;
@@ -147,7 +147,7 @@ void MulticastListenersTable::Expire(void)
void MulticastListenersTable::LogMulticastListenersTable(const char * aAction,
const Ip6::Address &aAddress,
TimeMilli aExpireTime,
otError aError)
Error aError)
{
OT_UNUSED_VARIABLE(aAction);
OT_UNUSED_VARIABLE(aAddress);
@@ -155,7 +155,7 @@ void MulticastListenersTable::LogMulticastListenersTable(const char * aAc
OT_UNUSED_VARIABLE(aError);
otLogDebgBbr("MulticastListenersTable: %s %s expire %u: %s", aAction, aAddress.ToString().AsCString(),
aExpireTime.GetValue(), otThreadErrorToString(aError));
aExpireTime.GetValue(), ErrorToString(aError));
}
void MulticastListenersTable::FixHeap(uint16_t aIndex)
@@ -287,13 +287,13 @@ void MulticastListenersTable::SetCallback(otBackboneRouterMulticastListenerCallb
}
}
otError MulticastListenersTable::GetNext(otBackboneRouterMulticastListenerIterator &aIterator,
otBackboneRouterMulticastListenerInfo & aListenerInfo)
Error MulticastListenersTable::GetNext(otBackboneRouterMulticastListenerIterator &aIterator,
otBackboneRouterMulticastListenerInfo & aListenerInfo)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
TimeMilli now;
VerifyOrExit(aIterator < mNumValidListeners, error = OT_ERROR_NOT_FOUND);
VerifyOrExit(aIterator < mNumValidListeners, error = kErrorNotFound);
now = TimerMilli::GetNow();
@@ -119,12 +119,12 @@ public:
* @param[in] aAddress The Multicast Listener address.
* @param[in] aExpireTime The Multicast Listener expire time.
*
* @retval OT_ERROR_NONE If the Multicast Listener was successfully added.
* @retval OT_ERROR_INVALID_ARGS If the Multicast Listener address was invalid.
* @retval OT_ERROR_NO_BUFS No space available to save the Multicast Listener.
* @retval kErrorNone If the Multicast Listener was successfully added.
* @retval kErrorInvalidArgs If the Multicast Listener address was invalid.
* @retval kErrorNoBufs No space available to save the Multicast Listener.
*
*/
otError Add(const Ip6::Address &aAddress, TimeMilli aExpireTime);
Error Add(const Ip6::Address &aAddress, TimeMilli aExpireTime);
/**
* This method removes a given Multicast Listener.
@@ -181,12 +181,12 @@ public:
* @param[in] aIterator A pointer to the Multicast Listener Iterator.
* @param[out] aListenerInfo A pointer to where the Multicast Listener info is placed.
*
* @retval OT_ERROR_NONE Successfully found the next Multicast Listener info.
* @retval OT_ERROR_NOT_FOUND No subsequent Multicast Listener was found.
* @retval kErrorNone Successfully found the next Multicast Listener info.
* @retval kErrorNotFound No subsequent Multicast Listener was found.
*
*/
otError GetNext(otBackboneRouterMulticastListenerIterator &aIterator,
otBackboneRouterMulticastListenerInfo & aListenerInfo);
Error GetNext(otBackboneRouterMulticastListenerIterator &aIterator,
otBackboneRouterMulticastListenerInfo & aListenerInfo);
private:
enum
@@ -213,7 +213,7 @@ private:
void LogMulticastListenersTable(const char * aAction,
const Ip6::Address &aAddress,
TimeMilli aExpireTime,
otError aError);
Error aError);
void FixHeap(uint16_t aIndex);
bool SiftHeapElemDown(uint16_t aIndex);
+13 -13
View File
@@ -149,18 +149,18 @@ void NdProxyTable::Clear(void)
otLogNoteBbr("NdProxyTable::Clear!");
}
otError NdProxyTable::Register(const Ip6::InterfaceIdentifier &aAddressIid,
const Ip6::InterfaceIdentifier &aMeshLocalIid,
uint16_t aRloc16,
const uint32_t * aTimeSinceLastTransaction)
Error NdProxyTable::Register(const Ip6::InterfaceIdentifier &aAddressIid,
const Ip6::InterfaceIdentifier &aMeshLocalIid,
uint16_t aRloc16,
const uint32_t * aTimeSinceLastTransaction)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
NdProxy *proxy = FindByAddressIid(aAddressIid);
uint32_t timeSinceLastTransaction = aTimeSinceLastTransaction == nullptr ? 0 : *aTimeSinceLastTransaction;
if (proxy != nullptr)
{
VerifyOrExit(proxy->mMeshLocalIid == aMeshLocalIid, error = OT_ERROR_DUPLICATED);
VerifyOrExit(proxy->mMeshLocalIid == aMeshLocalIid, error = kErrorDuplicated);
proxy->Update(aRloc16, timeSinceLastTransaction);
NotifyDuaRegistrationOnBackboneLink(*proxy, /* aIsRenew */ true);
@@ -178,7 +178,7 @@ otError NdProxyTable::Register(const Ip6::InterfaceIdentifier &aAddressIid,
proxy = FindInvalid();
// TODO: evict stale DUA entries to have room for this new DUA.
VerifyOrExit(proxy != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit(proxy != nullptr, error = kErrorNoBufs);
}
proxy->Init(aAddressIid, aMeshLocalIid, aRloc16, timeSinceLastTransaction);
@@ -186,7 +186,7 @@ otError NdProxyTable::Register(const Ip6::InterfaceIdentifier &aAddressIid,
exit:
otLogInfoBbr("NdProxyTable::Register %s MLIID %s RLOC16 %04x LTT %u => %s", aAddressIid.ToString().AsCString(),
aMeshLocalIid.ToString().AsCString(), aRloc16, timeSinceLastTransaction, otThreadErrorToString(error));
aMeshLocalIid.ToString().AsCString(), aRloc16, timeSinceLastTransaction, ErrorToString(error));
return error;
}
@@ -257,7 +257,7 @@ void NdProxyTable::HandleTimer(void)
{
mIsAnyDadInProcess = true;
if (Get<BackboneRouter::Manager>().SendBackboneQuery(GetDua(proxy)) == OT_ERROR_NONE)
if (Get<BackboneRouter::Manager>().SendBackboneQuery(GetDua(proxy)) == kErrorNone)
{
proxy.IncreaseDadAttampts();
}
@@ -335,11 +335,11 @@ void NdProxyTable::NotifyDuaRegistrationOnBackboneLink(NdProxyTable::NdProxy &aN
}
}
otError NdProxyTable::GetInfo(const Ip6::Address &aDua, otBackboneRouterNdProxyInfo &aNdProxyInfo)
Error NdProxyTable::GetInfo(const Ip6::Address &aDua, otBackboneRouterNdProxyInfo &aNdProxyInfo)
{
otError error = OT_ERROR_NOT_FOUND;
Error error = kErrorNotFound;
VerifyOrExit(Get<Leader>().IsDomainUnicast(aDua), error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(Get<Leader>().IsDomainUnicast(aDua), error = kErrorInvalidArgs);
for (NdProxy &proxy : Iterate(kFilterValid))
{
@@ -349,7 +349,7 @@ otError NdProxyTable::GetInfo(const Ip6::Address &aDua, otBackboneRouterNdProxyI
aNdProxyInfo.mTimeSinceLastTransaction = proxy.GetTimeSinceLastTransaction();
aNdProxyInfo.mRloc16 = proxy.mRloc16;
ExitNow(error = OT_ERROR_NONE);
ExitNow(error = kErrorNone);
}
}
+10 -10
View File
@@ -147,15 +147,15 @@ public:
* @param[in] aRloc16 The RLOC16.
* @param[in] aTimeSinceLastTransaction Time since last transaction (in seconds).
*
* @retval OT_ERROR_NONE If registered successfully.
* @retval OT_ERROR_DUPLICATED If the Ip6 address IID is a duplicate.
* @retval OT_ERROR_NO_BUFS Insufficient buffer space available to register.
* @retval kErrorNone If registered successfully.
* @retval kErrorDuplicated If the Ip6 address IID is a duplicate.
* @retval kErrorNoBufs Insufficient buffer space available to register.
*
*/
otError Register(const Ip6::InterfaceIdentifier &aAddressIid,
const Ip6::InterfaceIdentifier &aMeshLocalIid,
uint16_t aRloc16,
const uint32_t * aTimeSinceLastTransaction);
Error Register(const Ip6::InterfaceIdentifier &aAddressIid,
const Ip6::InterfaceIdentifier &aMeshLocalIid,
uint16_t aRloc16,
const uint32_t * aTimeSinceLastTransaction);
/**
* This method checks if a given Ip6 address IID was registered.
@@ -224,11 +224,11 @@ public:
* @param[in] aDua The Domain Unicast Address to get info.
* @param[in] aNdProxyInfo A pointer to the ND Proxy info.
*
* @retval OT_ERROR_NONE Successfully retrieve the ND Proxy info.
* @retval OT_ERROR_NOT_FOUND Failed to find the Domain Unicast Address in the ND Proxy table.
* @retval kErrorNone Successfully retrieve the ND Proxy info.
* @retval kErrorNotFound Failed to find the Domain Unicast Address in the ND Proxy table.
*
*/
otError GetInfo(const Ip6::Address &aDua, otBackboneRouterNdProxyInfo &aNdProxyInfo);
Error GetInfo(const Ip6::Address &aDua, otBackboneRouterNdProxyInfo &aNdProxyInfo);
private:
enum
+54 -61
View File
@@ -82,14 +82,12 @@ RoutingManager::RoutingManager(Instance &aInstance)
memset(mDiscoveredPrefixes, 0, sizeof(mDiscoveredPrefixes));
}
otError RoutingManager::Init(uint32_t aInfraIfIndex,
bool aInfraIfIsRunning,
const Ip6::Address *aInfraIfLinkLocalAddress)
Error RoutingManager::Init(uint32_t aInfraIfIndex, bool aInfraIfIsRunning, const Ip6::Address *aInfraIfLinkLocalAddress)
{
otError error;
Error error;
VerifyOrExit(!IsInitialized(), error = OT_ERROR_INVALID_STATE);
VerifyOrExit(aInfraIfIndex > 0, error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(!IsInitialized(), error = kErrorInvalidState);
VerifyOrExit(aInfraIfIndex > 0, error = kErrorInvalidArgs);
SuccessOrExit(error = LoadOrGenerateRandomOmrPrefix());
SuccessOrExit(error = LoadOrGenerateRandomOnLinkPrefix());
@@ -100,18 +98,18 @@ otError RoutingManager::Init(uint32_t aInfraIfIndex,
SuccessOrExit(error = HandleInfraIfStateChanged(mInfraIfIndex, aInfraIfIsRunning, aInfraIfLinkLocalAddress));
exit:
if (error != OT_ERROR_NONE)
if (error != kErrorNone)
{
mInfraIfIndex = 0;
}
return error;
}
otError RoutingManager::SetEnabled(bool aEnabled)
Error RoutingManager::SetEnabled(bool aEnabled)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
VerifyOrExit(IsInitialized(), error = OT_ERROR_INVALID_STATE);
VerifyOrExit(IsInitialized(), error = kErrorInvalidState);
VerifyOrExit(aEnabled != mIsEnabled);
@@ -122,18 +120,18 @@ exit:
return error;
}
otError RoutingManager::LoadOrGenerateRandomOmrPrefix(void)
Error RoutingManager::LoadOrGenerateRandomOmrPrefix(void)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
if (Get<Settings>().ReadOmrPrefix(mLocalOmrPrefix) != OT_ERROR_NONE || !IsValidOmrPrefix(mLocalOmrPrefix))
if (Get<Settings>().ReadOmrPrefix(mLocalOmrPrefix) != kErrorNone || !IsValidOmrPrefix(mLocalOmrPrefix))
{
Ip6::NetworkPrefix randomOmrPrefix;
otLogNoteBr("no valid OMR prefix found in settings, generating new one");
error = randomOmrPrefix.GenerateRandomUla();
if (error != OT_ERROR_NONE)
if (error != kErrorNone)
{
otLogCritBr("failed to generate random OMR prefix");
ExitNow();
@@ -147,19 +145,18 @@ exit:
return error;
}
otError RoutingManager::LoadOrGenerateRandomOnLinkPrefix(void)
Error RoutingManager::LoadOrGenerateRandomOnLinkPrefix(void)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
if (Get<Settings>().ReadOnLinkPrefix(mLocalOnLinkPrefix) != OT_ERROR_NONE ||
!IsValidOnLinkPrefix(mLocalOnLinkPrefix))
if (Get<Settings>().ReadOnLinkPrefix(mLocalOnLinkPrefix) != kErrorNone || !IsValidOnLinkPrefix(mLocalOnLinkPrefix))
{
Ip6::NetworkPrefix randomOnLinkPrefix;
otLogNoteBr("no valid on-link prefix found in settings, generating new one");
error = randomOnLinkPrefix.GenerateRandomUla();
if (error != OT_ERROR_NONE)
if (error != kErrorNone)
{
otLogCritBr("failed to generate random on-link prefix");
ExitNow();
@@ -241,19 +238,19 @@ void RoutingManager::RecvIcmp6Message(uint32_t aInfraIfIndex,
const uint8_t * aBuffer,
uint16_t aBufferLength)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
const Ip6::Icmp::Header *icmp6Header;
const Ip6::Address * infraLinkLocalAddr;
VerifyOrExit(IsInitialized() && mIsRunning, error = OT_ERROR_DROP);
VerifyOrExit(IsInitialized() && mIsRunning, error = kErrorDrop);
VerifyOrExit(aInfraIfIndex == mInfraIfIndex, error = OT_ERROR_DROP);
VerifyOrExit(aInfraIfIndex == mInfraIfIndex, error = kErrorDrop);
infraLinkLocalAddr = static_cast<const Ip6::Address *>(&mInfraIfLinkLocalAddress);
// Drop any ICMPv6 messages sent from myself.
VerifyOrExit(infraLinkLocalAddr != nullptr && aSrcAddress != *infraLinkLocalAddr, error = OT_ERROR_DROP);
VerifyOrExit(infraLinkLocalAddr != nullptr && aSrcAddress != *infraLinkLocalAddr, error = kErrorDrop);
VerifyOrExit(aBuffer != nullptr && aBufferLength >= sizeof(*icmp6Header), error = OT_ERROR_PARSE);
VerifyOrExit(aBuffer != nullptr && aBufferLength >= sizeof(*icmp6Header), error = kErrorParse);
icmp6Header = reinterpret_cast<const Ip6::Icmp::Header *>(aBuffer);
@@ -270,21 +267,21 @@ void RoutingManager::RecvIcmp6Message(uint32_t aInfraIfIndex,
}
exit:
if (error != OT_ERROR_NONE)
if (error != kErrorNone)
{
otLogDebgBr("drop ICMPv6 message: %s", otThreadErrorToString(error));
otLogDebgBr("drop ICMPv6 message: %s", ErrorToString(error));
}
}
otError RoutingManager::HandleInfraIfStateChanged(uint32_t aInfraIfIndex,
bool aIsRunning,
const Ip6::Address *aLinkLocalAddress)
Error RoutingManager::HandleInfraIfStateChanged(uint32_t aInfraIfIndex,
bool aIsRunning,
const Ip6::Address *aLinkLocalAddress)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
VerifyOrExit(IsInitialized(), error = OT_ERROR_INVALID_STATE);
VerifyOrExit(aInfraIfIndex == mInfraIfIndex, error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(aLinkLocalAddress == nullptr || aLinkLocalAddress->IsLinkLocal(), error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(IsInitialized(), error = kErrorInvalidState);
VerifyOrExit(aInfraIfIndex == mInfraIfIndex, error = kErrorInvalidArgs);
VerifyOrExit(aLinkLocalAddress == nullptr || aLinkLocalAddress->IsLinkLocal(), error = kErrorInvalidArgs);
otLogInfoBr("infra interface state changed: %s, link-local-addr=%s", aIsRunning ? "RUNNING" : "NOT RUNNING",
(aLinkLocalAddress != nullptr) ? aLinkLocalAddress->ToString().AsCString() : "(null)");
@@ -333,7 +330,7 @@ uint8_t RoutingManager::EvaluateOmrPrefix(Ip6::Prefix *aNewOmrPrefixes, uint8_t
OT_ASSERT(mIsRunning);
while (Get<NetworkData::Leader>().GetNextOnMeshPrefix(iterator, onMeshPrefixConfig) == OT_ERROR_NONE)
while (Get<NetworkData::Leader>().GetNextOnMeshPrefix(iterator, onMeshPrefixConfig) == kErrorNone)
{
uint8_t newPrefixIndex;
@@ -377,7 +374,7 @@ uint8_t RoutingManager::EvaluateOmrPrefix(Ip6::Prefix *aNewOmrPrefixes, uint8_t
if (newOmrPrefixNum == 0)
{
otLogInfoBr("EvaluateOmrPrefix: no valid OMR prefixes found in Thread network");
if (PublishLocalOmrPrefix() == OT_ERROR_NONE)
if (PublishLocalOmrPrefix() == kErrorNone)
{
aNewOmrPrefixes[newOmrPrefixNum++] = mLocalOmrPrefix;
}
@@ -397,9 +394,9 @@ uint8_t RoutingManager::EvaluateOmrPrefix(Ip6::Prefix *aNewOmrPrefixes, uint8_t
return newOmrPrefixNum;
}
otError RoutingManager::PublishLocalOmrPrefix(void)
Error RoutingManager::PublishLocalOmrPrefix(void)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
NetworkData::OnMeshPrefixConfig omrPrefixConfig;
OT_ASSERT(mIsRunning);
@@ -414,10 +411,10 @@ otError RoutingManager::PublishLocalOmrPrefix(void)
omrPrefixConfig.mPreference = OT_ROUTE_PREFERENCE_MED;
error = Get<NetworkData::Local>().AddOnMeshPrefix(omrPrefixConfig);
if (error != OT_ERROR_NONE)
if (error != kErrorNone)
{
otLogWarnBr("failed to publish local OMR prefix %s in Thread network: %s",
mLocalOmrPrefix.ToString().AsCString(), otThreadErrorToString(error));
mLocalOmrPrefix.ToString().AsCString(), ErrorToString(error));
}
else
{
@@ -430,7 +427,7 @@ otError RoutingManager::PublishLocalOmrPrefix(void)
void RoutingManager::UnpublishLocalOmrPrefix(void)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
VerifyOrExit(mIsRunning);
@@ -440,16 +437,16 @@ void RoutingManager::UnpublishLocalOmrPrefix(void)
otLogInfoBr("unpublished local OMR prefix %s from Thread network", mLocalOmrPrefix.ToString().AsCString());
exit:
if (error != OT_ERROR_NONE)
if (error != kErrorNone)
{
otLogWarnBr("failed to unpublish local OMR prefix %s from Thread network: %s",
mLocalOmrPrefix.ToString().AsCString(), otThreadErrorToString(error));
mLocalOmrPrefix.ToString().AsCString(), ErrorToString(error));
}
}
otError RoutingManager::AddExternalRoute(const Ip6::Prefix &aPrefix, otRoutePreference aRoutePreference)
Error RoutingManager::AddExternalRoute(const Ip6::Prefix &aPrefix, otRoutePreference aRoutePreference)
{
otError error;
Error error;
NetworkData::ExternalRouteConfig routeConfig;
OT_ASSERT(mIsRunning);
@@ -460,10 +457,9 @@ otError RoutingManager::AddExternalRoute(const Ip6::Prefix &aPrefix, otRoutePref
routeConfig.mPreference = aRoutePreference;
error = Get<NetworkData::Local>().AddHasRoutePrefix(routeConfig);
if (error != OT_ERROR_NONE)
if (error != kErrorNone)
{
otLogWarnBr("failed to add external route %s: %s", aPrefix.ToString().AsCString(),
otThreadErrorToString(error));
otLogWarnBr("failed to add external route %s: %s", aPrefix.ToString().AsCString(), ErrorToString(error));
}
else
{
@@ -476,7 +472,7 @@ otError RoutingManager::AddExternalRoute(const Ip6::Prefix &aPrefix, otRoutePref
void RoutingManager::RemoveExternalRoute(const Ip6::Prefix &aPrefix)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
VerifyOrExit(mIsRunning);
@@ -486,10 +482,9 @@ void RoutingManager::RemoveExternalRoute(const Ip6::Prefix &aPrefix)
otLogInfoBr("removed external route %s", aPrefix.ToString().AsCString());
exit:
if (error != OT_ERROR_NONE)
if (error != kErrorNone)
{
otLogWarnBr("failed to remove external route %s: %s", aPrefix.ToString().AsCString(),
otThreadErrorToString(error));
otLogWarnBr("failed to remove external route %s: %s", aPrefix.ToString().AsCString(), ErrorToString(error));
}
}
@@ -539,7 +534,7 @@ const Ip6::Prefix *RoutingManager::EvaluateOnLinkPrefix(void)
{
newOnLinkPrefix = mAdvertisedOnLinkPrefix;
}
else if (AddExternalRoute(mLocalOnLinkPrefix, OT_ROUTE_PREFERENCE_MED) == OT_ERROR_NONE)
else if (AddExternalRoute(mLocalOnLinkPrefix, OT_ROUTE_PREFERENCE_MED) == kErrorNone)
{
newOnLinkPrefix = &mLocalOnLinkPrefix;
}
@@ -641,7 +636,7 @@ void RoutingManager::StartRouterSolicitation(void)
mRouterSolicitTimer.Start(randomDelay);
}
otError RoutingManager::SendRouterSolicitation(void)
Error RoutingManager::SendRouterSolicitation(void)
{
Ip6::Address destAddress;
RouterAdv::RouterSolicitMessage routerSolicit;
@@ -761,7 +756,7 @@ void RoutingManager::SendRouterAdvertisement(const Ip6::Prefix *aNewOmrPrefixes,
// Send the message only when there are options.
if (bufferLength > sizeof(routerAdv))
{
otError error;
Error error;
Ip6::Address destAddress;
++mRouterAdvertisementCount;
@@ -769,14 +764,13 @@ void RoutingManager::SendRouterAdvertisement(const Ip6::Prefix *aNewOmrPrefixes,
destAddress.SetToLinkLocalAllNodesMulticast();
error = otPlatInfraIfSendIcmp6Nd(mInfraIfIndex, &destAddress, buffer, bufferLength);
if (error == OT_ERROR_NONE)
if (error == kErrorNone)
{
otLogInfoBr("sent Router Advertisement on interface %u", mInfraIfIndex);
}
else
{
otLogWarnBr("failed to send Router Advertisement on interface %u: %s", mInfraIfIndex,
otThreadErrorToString(error));
otLogWarnBr("failed to send Router Advertisement on interface %u: %s", mInfraIfIndex, ErrorToString(error));
}
}
}
@@ -832,19 +826,18 @@ void RoutingManager::HandleRouterSolicitTimer(void)
if (mRouterSolicitCount < kMaxRtrSolicitations)
{
uint32_t nextSolicitationDelay;
otError error;
Error error;
error = SendRouterSolicitation();
++mRouterSolicitCount;
if (error == OT_ERROR_NONE)
if (error == kErrorNone)
{
otLogDebgBr("successfully sent %uth Router Solicitation", mRouterSolicitCount);
}
else
{
otLogCritBr("failed to send %uth Router Solicitation: %s", mRouterSolicitCount,
otThreadErrorToString(error));
otLogCritBr("failed to send %uth Router Solicitation: %s", mRouterSolicitCount, ErrorToString(error));
}
nextSolicitationDelay =
+24 -24
View File
@@ -47,11 +47,11 @@
#error "OPENTHREAD_CONFIG_IP6_SLAAC_ENABLE is required for OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE."
#endif
#include <openthread/error.h>
#include <openthread/netdata.h>
#include <openthread/platform/infra_if.h>
#include "border_router/router_advertisement.hpp"
#include "common/error.hpp"
#include "common/locator.hpp"
#include "common/notifier.hpp"
#include "common/timer.hpp"
@@ -92,11 +92,11 @@ public:
* @param[in] aInfraIfLinkLocalAddress A pointer to the IPv6 link-local address of the infrastructure
* interface. NULL if the IPv6 link-local address is missing.
*
* @retval OT_ERROR_NONE Successfully started the routing manager.
* @retval OT_ERROR_INVALID_ARGS The index of the infra interface is not valid.
* @retval kErrorNone Successfully started the routing manager.
* @retval kErrorInvalidArgs The index of the infra interface is not valid.
*
*/
otError Init(uint32_t aInfraIfIndex, bool aInfraIfIsRunning, const Ip6::Address *aInfraIfLinkLocalAddress);
Error Init(uint32_t aInfraIfIndex, bool aInfraIfIsRunning, const Ip6::Address *aInfraIfLinkLocalAddress);
/**
* This method enables/disables the Border Routing Manager.
@@ -105,11 +105,11 @@ public:
*
* @param[in] aEnabled A boolean to enable/disable the Border Routing Manager.
*
* @retval OT_ERROR_INVALID_STATE The Border Routing Manager is not initialized yet.
* @retval OT_ERROR_NONE Successfully enabled/disabled the Border Routing Manager.
* @retval kErrorInvalidState The Border Routing Manager is not initialized yet.
* @retval kErrorNone Successfully enabled/disabled the Border Routing Manager.
*
*/
otError SetEnabled(bool aEnabled);
Error SetEnabled(bool aEnabled);
/**
* This method receives an ICMPv6 message on the infrastructure interface.
@@ -136,14 +136,14 @@ public:
* @param[in] aLinkLocalAddress A pointer to the IPv6 link local address of the infrastructure
* interface. NULL if the IPv6 link local address is lost.
*
* @retval OT_ERROR_NONE Successfully updated the infra interface status.
* @retval OT_ERROR_INVALID_STATE The Routing Manager is not initialized.
* @retval OT_ERROR_INVALID_ARGS The @p aInfraIfIndex doesn't match the infra interface the
* Routing Manager are initialized with, or the @p aLinkLocalAddress
* is not a valid IPv6 link-local address.
* @retval kErrorNone Successfully updated the infra interface status.
* @retval kErrorInvalidState The Routing Manager is not initialized.
* @retval kErrorInvalidArgs The @p aInfraIfIndex doesn't match the infra interface the Routing Manager are
* initialized with, or the @p aLinkLocalAddress is not a valid IPv6 link-local
* address.
*
*/
otError HandleInfraIfStateChanged(uint32_t aInfraIfIndex, bool aIsRunning, const Ip6::Address *aLinkLocalAddress);
Error HandleInfraIfStateChanged(uint32_t aInfraIfIndex, bool aIsRunning, const Ip6::Address *aLinkLocalAddress);
private:
enum : uint16_t
@@ -191,25 +191,25 @@ private:
bool mIsOnLinkPrefix;
};
void EvaluateState(void);
void Start(void);
void Stop(void);
void HandleNotifierEvents(Events aEvents);
bool IsInitialized(void) const { return mInfraIfIndex != 0; }
bool IsEnabled(void) const { return mIsEnabled; }
otError LoadOrGenerateRandomOmrPrefix(void);
otError LoadOrGenerateRandomOnLinkPrefix(void);
void EvaluateState(void);
void Start(void);
void Stop(void);
void HandleNotifierEvents(Events aEvents);
bool IsInitialized(void) const { return mInfraIfIndex != 0; }
bool IsEnabled(void) const { return mIsEnabled; }
Error LoadOrGenerateRandomOmrPrefix(void);
Error LoadOrGenerateRandomOnLinkPrefix(void);
const Ip6::Prefix *EvaluateOnLinkPrefix(void);
void EvaluateRoutingPolicy(void);
uint8_t EvaluateOmrPrefix(Ip6::Prefix *aNewOmrPrefixes, uint8_t aMaxOmrPrefixNum);
otError PublishLocalOmrPrefix(void);
Error PublishLocalOmrPrefix(void);
void UnpublishLocalOmrPrefix(void);
otError AddExternalRoute(const Ip6::Prefix &aPrefix, otRoutePreference aRoutePreference);
Error AddExternalRoute(const Ip6::Prefix &aPrefix, otRoutePreference aRoutePreference);
void RemoveExternalRoute(const Ip6::Prefix &aPrefix);
void StartRouterSolicitation(void);
otError SendRouterSolicitation(void);
Error SendRouterSolicitation(void);
void SendRouterAdvertisement(const Ip6::Prefix *aNewOmrPrefixes,
uint8_t aNewOmrPrefixNum,
const Ip6::Prefix *aNewOnLinkPrefix);
+150 -152
View File
@@ -86,7 +86,7 @@ void CoapBase::ClearRequests(const Ip6::Address *aAddress)
if ((aAddress == nullptr) || (metadata.mSourceAddress == *aAddress))
{
FinalizeCoapTransaction(*message, metadata, nullptr, nullptr, OT_ERROR_ABORT);
FinalizeCoapTransaction(*message, metadata, nullptr, nullptr, kErrorAbort);
}
}
}
@@ -138,9 +138,9 @@ exit:
return message;
}
otError CoapBase::Send(ot::Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
Error CoapBase::Send(ot::Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
{
otError error;
Error error;
#if OPENTHREAD_CONFIG_OTNS_ENABLE
Get<Utils::Otns>().EmitCoapSend(static_cast<Message &>(aMessage), aMessageInfo);
@@ -149,7 +149,7 @@ otError CoapBase::Send(ot::Message &aMessage, const Ip6::MessageInfo &aMessageIn
error = mSender(*this, aMessage, aMessageInfo);
#if OPENTHREAD_CONFIG_OTNS_ENABLE
if (error != OT_ERROR_NONE)
if (error != kErrorNone)
{
Get<Utils::Otns>().EmitCoapSendFailure(error, static_cast<Message &>(aMessage), aMessageInfo);
}
@@ -158,22 +158,22 @@ otError CoapBase::Send(ot::Message &aMessage, const Ip6::MessageInfo &aMessageIn
}
#if OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
otError CoapBase::SendMessage(Message & aMessage,
const Ip6::MessageInfo & aMessageInfo,
const TxParameters & aTxParameters,
ResponseHandler aHandler,
void * aContext,
otCoapBlockwiseTransmitHook aTransmitHook,
otCoapBlockwiseReceiveHook aReceiveHook)
Error CoapBase::SendMessage(Message & aMessage,
const Ip6::MessageInfo & aMessageInfo,
const TxParameters & aTxParameters,
ResponseHandler aHandler,
void * aContext,
otCoapBlockwiseTransmitHook aTransmitHook,
otCoapBlockwiseReceiveHook aReceiveHook)
#else
otError CoapBase::SendMessage(Message & aMessage,
const Ip6::MessageInfo &aMessageInfo,
const TxParameters & aTxParameters,
ResponseHandler aHandler,
void * aContext)
Error CoapBase::SendMessage(Message & aMessage,
const Ip6::MessageInfo &aMessageInfo,
const TxParameters & aTxParameters,
ResponseHandler aHandler,
void * aContext)
#endif
{
otError error;
Error error;
Message *storedCopy = nullptr;
uint16_t copyLength = 0;
#if OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
@@ -187,12 +187,12 @@ otError CoapBase::SendMessage(Message & aMessage,
case kTypeAck:
#if OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
// Check for block-wise transfer
if ((aTransmitHook != nullptr) && (aMessage.ReadBlockOptionValues(kOptionBlock2) == OT_ERROR_NONE) &&
if ((aTransmitHook != nullptr) && (aMessage.ReadBlockOptionValues(kOptionBlock2) == kErrorNone) &&
(aMessage.GetBlockWiseBlockNumber() == 0))
{
// Set payload for first block of the transfer
VerifyOrExit((bufLen = otCoapBlockSizeFromExponent(aMessage.GetBlockWiseBlockSize())) <= kMaxBlockLength,
error = OT_ERROR_NO_BUFS);
error = kErrorNoBufs);
SuccessOrExit(error = aTransmitHook(aContext, buf, aMessage.GetBlockWiseBlockNumber() * bufLen, &bufLen,
&moreBlocks));
SuccessOrExit(error = aMessage.AppendBytes(buf, bufLen));
@@ -209,12 +209,12 @@ otError CoapBase::SendMessage(Message & aMessage,
default:
#if OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
// Check for block-wise transfer
if ((aTransmitHook != nullptr) && (aMessage.ReadBlockOptionValues(kOptionBlock1) == OT_ERROR_NONE) &&
if ((aTransmitHook != nullptr) && (aMessage.ReadBlockOptionValues(kOptionBlock1) == kErrorNone) &&
(aMessage.GetBlockWiseBlockNumber() == 0))
{
// Set payload for first block of the transfer
VerifyOrExit((bufLen = otCoapBlockSizeFromExponent(aMessage.GetBlockWiseBlockSize())) <= kMaxBlockLength,
error = OT_ERROR_NO_BUFS);
error = kErrorNoBufs);
SuccessOrExit(error = aTransmitHook(aContext, buf, aMessage.GetBlockWiseBlockNumber() * bufLen, &bufLen,
&moreBlocks));
SuccessOrExit(error = aMessage.AppendBytes(buf, bufLen));
@@ -275,7 +275,7 @@ otError CoapBase::SendMessage(Message & aMessage,
Message *origRequest = FindRelatedRequest(aMessage, aMessageInfo, handlerMetadata);
if (origRequest != nullptr)
{
FinalizeCoapTransaction(*origRequest, handlerMetadata, nullptr, nullptr, OT_ERROR_NONE);
FinalizeCoapTransaction(*origRequest, handlerMetadata, nullptr, nullptr, kErrorNone);
}
}
}
@@ -307,14 +307,14 @@ otError CoapBase::SendMessage(Message & aMessage,
(metadata.mConfirmable ? metadata.mRetransmissionTimeout : aTxParameters.CalculateMaxTransmitWait());
storedCopy = CopyAndEnqueueMessage(aMessage, copyLength, metadata);
VerifyOrExit(storedCopy != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit(storedCopy != nullptr, error = kErrorNoBufs);
}
SuccessOrExit(error = Send(aMessage, aMessageInfo));
exit:
if (error != OT_ERROR_NONE && storedCopy != nullptr)
if (error != kErrorNone && storedCopy != nullptr)
{
DequeueMessage(*storedCopy);
}
@@ -322,10 +322,10 @@ exit:
return error;
}
otError CoapBase::SendMessage(Message & aMessage,
const Ip6::MessageInfo &aMessageInfo,
ResponseHandler aHandler,
void * aContext)
Error CoapBase::SendMessage(Message & aMessage,
const Ip6::MessageInfo &aMessageInfo,
ResponseHandler aHandler,
void * aContext)
{
#if OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
return SendMessage(aMessage, aMessageInfo, TxParameters::GetDefault(), aHandler, aContext, nullptr, nullptr);
@@ -334,34 +334,34 @@ otError CoapBase::SendMessage(Message & aMessage,
#endif
}
otError CoapBase::SendReset(Message &aRequest, const Ip6::MessageInfo &aMessageInfo)
Error CoapBase::SendReset(Message &aRequest, const Ip6::MessageInfo &aMessageInfo)
{
return SendEmptyMessage(kTypeReset, aRequest, aMessageInfo);
}
otError CoapBase::SendAck(const Message &aRequest, const Ip6::MessageInfo &aMessageInfo)
Error CoapBase::SendAck(const Message &aRequest, const Ip6::MessageInfo &aMessageInfo)
{
return SendEmptyMessage(kTypeAck, aRequest, aMessageInfo);
}
otError CoapBase::SendEmptyAck(const Message &aRequest, const Ip6::MessageInfo &aMessageInfo, Code aCode)
Error CoapBase::SendEmptyAck(const Message &aRequest, const Ip6::MessageInfo &aMessageInfo, Code aCode)
{
return (aRequest.IsConfirmable() ? SendHeaderResponse(aCode, aRequest, aMessageInfo) : OT_ERROR_INVALID_ARGS);
return (aRequest.IsConfirmable() ? SendHeaderResponse(aCode, aRequest, aMessageInfo) : kErrorInvalidArgs);
}
otError CoapBase::SendNotFound(const Message &aRequest, const Ip6::MessageInfo &aMessageInfo)
Error CoapBase::SendNotFound(const Message &aRequest, const Ip6::MessageInfo &aMessageInfo)
{
return SendHeaderResponse(kCodeNotFound, aRequest, aMessageInfo);
}
otError CoapBase::SendEmptyMessage(Type aType, const Message &aRequest, const Ip6::MessageInfo &aMessageInfo)
Error CoapBase::SendEmptyMessage(Type aType, const Message &aRequest, const Ip6::MessageInfo &aMessageInfo)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Message *message = nullptr;
VerifyOrExit(aRequest.IsConfirmable(), error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(aRequest.IsConfirmable(), error = kErrorInvalidArgs);
VerifyOrExit((message = NewMessage()) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((message = NewMessage()) != nullptr, error = kErrorNoBufs);
message->Init(aType, kCodeEmpty);
message->SetMessageId(aRequest.GetMessageId());
@@ -374,13 +374,13 @@ exit:
return error;
}
otError CoapBase::SendHeaderResponse(Message::Code aCode, const Message &aRequest, const Ip6::MessageInfo &aMessageInfo)
Error CoapBase::SendHeaderResponse(Message::Code aCode, const Message &aRequest, const Ip6::MessageInfo &aMessageInfo)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Message *message = nullptr;
VerifyOrExit(aRequest.IsRequest(), error = OT_ERROR_INVALID_ARGS);
VerifyOrExit((message = NewMessage()) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit(aRequest.IsRequest(), error = kErrorInvalidArgs);
VerifyOrExit((message = NewMessage()) != nullptr, error = kErrorNoBufs);
switch (aRequest.GetType())
{
@@ -394,7 +394,7 @@ otError CoapBase::SendHeaderResponse(Message::Code aCode, const Message &aReques
break;
default:
ExitNow(error = OT_ERROR_INVALID_ARGS);
ExitNow(error = kErrorInvalidArgs);
OT_UNREACHABLE_CODE(break);
}
@@ -439,7 +439,7 @@ void CoapBase::HandleRetransmissionTimer(void)
if (!metadata.mConfirmable || (metadata.mRetransmissionsRemaining == 0))
{
// No expected response or acknowledgment.
FinalizeCoapTransaction(*message, metadata, nullptr, nullptr, OT_ERROR_RESPONSE_TIMEOUT);
FinalizeCoapTransaction(*message, metadata, nullptr, nullptr, kErrorResponseTimeout);
continue;
}
@@ -481,7 +481,7 @@ void CoapBase::FinalizeCoapTransaction(Message & aRequest,
const Metadata & aMetadata,
Message * aResponse,
const Ip6::MessageInfo *aMessageInfo,
otError aResult)
Error aResult)
{
DequeueMessage(aRequest);
@@ -491,9 +491,9 @@ void CoapBase::FinalizeCoapTransaction(Message & aRequest,
}
}
otError CoapBase::AbortTransaction(ResponseHandler aHandler, void *aContext)
Error CoapBase::AbortTransaction(ResponseHandler aHandler, void *aContext)
{
otError error = OT_ERROR_NOT_FOUND;
Error error = kErrorNotFound;
Message *nextMessage;
Metadata metadata;
@@ -504,8 +504,8 @@ otError CoapBase::AbortTransaction(ResponseHandler aHandler, void *aContext)
if (metadata.mResponseHandler == aHandler && metadata.mResponseContext == aContext)
{
FinalizeCoapTransaction(*message, metadata, nullptr, nullptr, OT_ERROR_ABORT);
error = OT_ERROR_NONE;
FinalizeCoapTransaction(*message, metadata, nullptr, nullptr, kErrorAbort);
error = kErrorNone;
}
}
@@ -514,10 +514,10 @@ otError CoapBase::AbortTransaction(ResponseHandler aHandler, void *aContext)
Message *CoapBase::CopyAndEnqueueMessage(const Message &aMessage, uint16_t aCopyLength, const Metadata &aMetadata)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Message *messageCopy = nullptr;
VerifyOrExit((messageCopy = aMessage.Clone(aCopyLength)) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((messageCopy = aMessage.Clone(aCopyLength)) != nullptr, error = kErrorNoBufs);
SuccessOrExit(error = aMetadata.AppendTo(*messageCopy));
@@ -555,27 +555,27 @@ void CoapBase::FreeLastBlockResponse(void)
}
}
otError CoapBase::CacheLastBlockResponse(Message *aResponse)
Error CoapBase::CacheLastBlockResponse(Message *aResponse)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
// Save last response for block-wise transfer
FreeLastBlockResponse();
if ((mLastResponse = aResponse->Clone()) == nullptr)
{
error = OT_ERROR_NO_BUFS;
error = kErrorNoBufs;
}
return error;
}
otError CoapBase::PrepareNextBlockRequest(Message::BlockType aType,
bool aMoreBlocks,
Message & aRequestOld,
Message & aRequest,
Message & aMessage)
Error CoapBase::PrepareNextBlockRequest(Message::BlockType aType,
bool aMoreBlocks,
Message & aRequestOld,
Message & aRequest,
Message & aMessage)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
bool isOptionSet = false;
uint64_t optionBuf = 0;
uint16_t blockOption = 0;
@@ -633,12 +633,12 @@ exit:
return error;
}
otError CoapBase::SendNextBlock1Request(Message & aRequest,
Message & aMessage,
const Ip6::MessageInfo &aMessageInfo,
const Metadata & aCoapMetadata)
Error CoapBase::SendNextBlock1Request(Message & aRequest,
Message & aMessage,
const Ip6::MessageInfo &aMessageInfo,
const Metadata & aCoapMetadata)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Message *request = nullptr;
bool moreBlocks = false;
uint8_t buf[kMaxBlockLength] = {0};
@@ -650,13 +650,13 @@ otError CoapBase::SendNextBlock1Request(Message & aRequest,
// Conclude block-wise transfer if last block has been received
if (!aRequest.IsMoreBlocksFlagSet())
{
FinalizeCoapTransaction(aRequest, aCoapMetadata, &aMessage, &aMessageInfo, OT_ERROR_NONE);
FinalizeCoapTransaction(aRequest, aCoapMetadata, &aMessage, &aMessageInfo, kErrorNone);
ExitNow();
}
// Get next block
VerifyOrExit((bufLen = otCoapBlockSizeFromExponent(aMessage.GetBlockWiseBlockSize())) <= kMaxBlockLength,
error = OT_ERROR_NO_BUFS);
error = kErrorNoBufs);
SuccessOrExit(
error = aCoapMetadata.mBlockwiseTransmitHook(aCoapMetadata.mResponseContext, buf,
@@ -665,11 +665,10 @@ otError CoapBase::SendNextBlock1Request(Message & aRequest,
&bufLen, &moreBlocks));
// Check if block length is valid
VerifyOrExit(bufLen <= otCoapBlockSizeFromExponent(aMessage.GetBlockWiseBlockSize()),
error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(bufLen <= otCoapBlockSizeFromExponent(aMessage.GetBlockWiseBlockSize()), error = kErrorInvalidArgs);
// Init request for next block
VerifyOrExit((request = NewMessage()) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((request = NewMessage()) != nullptr, error = kErrorNoBufs);
SuccessOrExit(error = PrepareNextBlockRequest(Message::kBlockType1, moreBlocks, aRequest, *request, aMessage));
SuccessOrExit(error = request->SetPayloadMarker());
@@ -691,14 +690,14 @@ exit:
return error;
}
otError CoapBase::SendNextBlock2Request(Message & aRequest,
Message & aMessage,
const Ip6::MessageInfo &aMessageInfo,
const Metadata & aCoapMetadata,
uint32_t aTotalLength,
bool aBeginBlock1Transfer)
Error CoapBase::SendNextBlock2Request(Message & aRequest,
Message & aMessage,
const Ip6::MessageInfo &aMessageInfo,
const Metadata & aCoapMetadata,
uint32_t aTotalLength,
bool aBeginBlock1Transfer)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Message *request = nullptr;
uint8_t buf[kMaxBlockLength] = {0};
uint16_t bufLen = kMaxBlockLength;
@@ -709,7 +708,7 @@ otError CoapBase::SendNextBlock2Request(Message & aRequest,
VerifyOrExit((aMessage.GetLength() - aMessage.GetOffset()) <=
otCoapBlockSizeFromExponent(aMessage.GetBlockWiseBlockSize()) &&
(aMessage.GetLength() - aMessage.GetOffset()) <= kMaxBlockLength,
error = OT_ERROR_NO_BUFS);
error = kErrorNoBufs);
// Read and then forward payload to receive hook function
bufLen = aMessage.ReadBytes(aMessage.GetOffset(), buf, aMessage.GetLength() - aMessage.GetOffset());
@@ -726,12 +725,12 @@ otError CoapBase::SendNextBlock2Request(Message & aRequest,
// Conclude block-wise transfer if last block has been received
if (!aMessage.IsMoreBlocksFlagSet())
{
FinalizeCoapTransaction(aRequest, aCoapMetadata, &aMessage, &aMessageInfo, OT_ERROR_NONE);
FinalizeCoapTransaction(aRequest, aCoapMetadata, &aMessage, &aMessageInfo, kErrorNone);
ExitNow();
}
// Init request for next block
VerifyOrExit((request = NewMessage()) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((request = NewMessage()) != nullptr, error = kErrorNoBufs);
SuccessOrExit(error = PrepareNextBlockRequest(Message::kBlockType2, aMessage.IsMoreBlocksFlagSet(), aRequest,
*request, aMessage));
@@ -753,12 +752,12 @@ exit:
return error;
}
otError CoapBase::ProcessBlock1Request(Message & aMessage,
const Ip6::MessageInfo & aMessageInfo,
const ResourceBlockWise &aResource,
uint32_t aTotalLength)
Error CoapBase::ProcessBlock1Request(Message & aMessage,
const Ip6::MessageInfo & aMessageInfo,
const ResourceBlockWise &aResource,
uint32_t aTotalLength)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Message *response = nullptr;
uint8_t buf[kMaxBlockLength] = {0};
uint16_t bufLen = kMaxBlockLength;
@@ -766,7 +765,7 @@ otError CoapBase::ProcessBlock1Request(Message & aMessage,
SuccessOrExit(error = aMessage.ReadBlockOptionValues(kOptionBlock1));
// Read and then forward payload to receive hook function
VerifyOrExit((aMessage.GetLength() - aMessage.GetOffset()) <= kMaxBlockLength, error = OT_ERROR_NO_BUFS);
VerifyOrExit((aMessage.GetLength() - aMessage.GetOffset()) <= kMaxBlockLength, error = kErrorNoBufs);
bufLen = aMessage.ReadBytes(aMessage.GetOffset(), buf, aMessage.GetLength() - aMessage.GetOffset());
SuccessOrExit(error = aResource.HandleBlockReceive(buf,
otCoapBlockSizeFromExponent(aMessage.GetBlockWiseBlockSize()) *
@@ -776,7 +775,7 @@ otError CoapBase::ProcessBlock1Request(Message & aMessage,
if (aMessage.IsMoreBlocksFlagSet())
{
// Set up next response
VerifyOrExit((response = NewMessage()) != nullptr, error = OT_ERROR_FAILED);
VerifyOrExit((response = NewMessage()) != nullptr, error = kErrorFailed);
response->Init(kTypeAck, kCodeContinue);
response->SetMessageId(aMessage.GetMessageId());
IgnoreReturnValue(
@@ -797,17 +796,17 @@ otError CoapBase::ProcessBlock1Request(Message & aMessage,
SuccessOrExit(error = SendMessage(*response, aMessageInfo));
error = OT_ERROR_BUSY;
error = kErrorBusy;
}
else
{
// Conclude block-wise transfer if last block has been received
FreeLastBlockResponse();
error = OT_ERROR_NONE;
error = kErrorNone;
}
exit:
if (error != OT_ERROR_NONE && error != OT_ERROR_BUSY && response != nullptr)
if (error != kErrorNone && error != kErrorBusy && response != nullptr)
{
response->Free();
}
@@ -815,11 +814,11 @@ exit:
return error;
}
otError CoapBase::ProcessBlock2Request(Message & aMessage,
const Ip6::MessageInfo & aMessageInfo,
const ResourceBlockWise &aResource)
Error CoapBase::ProcessBlock2Request(Message & aMessage,
const Ip6::MessageInfo & aMessageInfo,
const ResourceBlockWise &aResource)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Message * response = nullptr;
uint8_t buf[kMaxBlockLength] = {0};
uint16_t bufLen = kMaxBlockLength;
@@ -839,12 +838,12 @@ otError CoapBase::ProcessBlock2Request(Message & aMessage,
}
// Set up next response
VerifyOrExit((response = NewMessage()) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((response = NewMessage()) != nullptr, error = kErrorNoBufs);
response->Init(kTypeAck, kCodeContent);
response->SetMessageId(aMessage.GetMessageId());
VerifyOrExit((bufLen = otCoapBlockSizeFromExponent(aMessage.GetBlockWiseBlockSize())) <= kMaxBlockLength,
error = OT_ERROR_NO_BUFS);
error = kErrorNoBufs);
SuccessOrExit(error = aResource.HandleBlockTransmit(buf,
otCoapBlockSizeFromExponent(aMessage.GetBlockWiseBlockSize()) *
aMessage.GetBlockWiseBlockNumber(),
@@ -877,7 +876,7 @@ otError CoapBase::ProcessBlock2Request(Message & aMessage,
response->SetBlockWiseBlockSize(OT_COAP_OPTION_BLOCK_SZX_16);
break;
default:
error = OT_ERROR_INVALID_ARGS;
error = kErrorInvalidArgs;
ExitNow();
break;
}
@@ -886,7 +885,7 @@ otError CoapBase::ProcessBlock2Request(Message & aMessage,
{
// Verify that buffer length is not larger than requested block size
VerifyOrExit(bufLen <= otCoapBlockSizeFromExponent(aMessage.GetBlockWiseBlockSize()),
error = OT_ERROR_INVALID_ARGS);
error = kErrorInvalidArgs);
response->SetBlockWiseBlockSize(aMessage.GetBlockWiseBlockSize());
}
@@ -943,20 +942,20 @@ exit:
void CoapBase::SendCopy(const Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
{
otError error;
Error error;
Message *messageCopy = nullptr;
// Create a message copy for lower layers.
messageCopy = aMessage.Clone(aMessage.GetLength() - sizeof(Metadata));
VerifyOrExit(messageCopy != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit(messageCopy != nullptr, error = kErrorNoBufs);
SuccessOrExit(error = Send(*messageCopy, aMessageInfo));
exit:
if (error != OT_ERROR_NONE)
if (error != kErrorNone)
{
otLogWarnCoap("Failed to send copy: %s", otThreadErrorToString(error));
otLogWarnCoap("Failed to send copy: %s", ErrorToString(error));
FreeMessage(messageCopy);
}
}
@@ -1007,7 +1006,7 @@ void CoapBase::Receive(ot::Message &aMessage, const Ip6::MessageInfo &aMessageIn
{
Message &message = static_cast<Message &>(aMessage);
if (message.ParseHeader() != OT_ERROR_NONE)
if (message.ParseHeader() != kErrorNone)
{
otLogDebgCoap("Failed to parse CoAP header");
@@ -1034,7 +1033,7 @@ void CoapBase::ProcessReceivedResponse(Message &aMessage, const Ip6::MessageInfo
{
Metadata metadata;
Message *request = nullptr;
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
#if OPENTHREAD_CONFIG_COAP_OBSERVE_API_ENABLE
bool responseObserve = false;
#endif
@@ -1062,7 +1061,7 @@ void CoapBase::ProcessReceivedResponse(Message &aMessage, const Ip6::MessageInfo
case kTypeReset:
if (aMessage.IsEmpty())
{
FinalizeCoapTransaction(*request, metadata, nullptr, nullptr, OT_ERROR_ABORT);
FinalizeCoapTransaction(*request, metadata, nullptr, nullptr, kErrorAbort);
}
// Silently ignore non-empty reset messages (RFC 7252, p. 4.2).
@@ -1078,7 +1077,7 @@ void CoapBase::ProcessReceivedResponse(Message &aMessage, const Ip6::MessageInfo
// This is the ACK to our RFC7641 notification. There will be no
// "separate" response so pass it back as if it were a piggy-backed
// response so we can stop re-sending and the application can move on.
FinalizeCoapTransaction(*request, metadata, &aMessage, &aMessageInfo, OT_ERROR_NONE);
FinalizeCoapTransaction(*request, metadata, &aMessage, &aMessageInfo, kErrorNone);
}
else
#endif
@@ -1109,7 +1108,7 @@ void CoapBase::ProcessReceivedResponse(Message &aMessage, const Ip6::MessageInfo
if (metadata.mObserve && responseObserve && (metadata.mResponseHandler != nullptr))
{
// This is a RFC7641 notification. The request is *not* done!
metadata.mResponseHandler(metadata.mResponseContext, &aMessage, &aMessageInfo, OT_ERROR_NONE);
metadata.mResponseHandler(metadata.mResponseContext, &aMessage, &aMessageInfo, kErrorNone);
// Consider the message acknowledged at this point.
metadata.mAcknowledged = true;
@@ -1153,7 +1152,7 @@ void CoapBase::ProcessReceivedResponse(Message &aMessage, const Ip6::MessageInfo
{
case 0:
// Piggybacked response.
FinalizeCoapTransaction(*request, metadata, &aMessage, &aMessageInfo, OT_ERROR_NONE);
FinalizeCoapTransaction(*request, metadata, &aMessage, &aMessageInfo, kErrorNone);
break;
case 1: // Block1 option
if (aMessage.GetCode() == kCodeContinue && metadata.mBlockwiseTransmitHook != nullptr)
@@ -1162,7 +1161,7 @@ void CoapBase::ProcessReceivedResponse(Message &aMessage, const Ip6::MessageInfo
}
if (aMessage.GetCode() != kCodeContinue || metadata.mBlockwiseTransmitHook == nullptr ||
error != OT_ERROR_NONE)
error != kErrorNone)
{
FinalizeCoapTransaction(*request, metadata, &aMessage, &aMessageInfo, error);
}
@@ -1175,7 +1174,7 @@ void CoapBase::ProcessReceivedResponse(Message &aMessage, const Ip6::MessageInfo
}
if (aMessage.GetCode() >= kCodeBadRequest || metadata.mBlockwiseReceiveHook == nullptr ||
error != OT_ERROR_NONE)
error != kErrorNone)
{
FinalizeCoapTransaction(*request, metadata, &aMessage, &aMessageInfo, error);
}
@@ -1190,14 +1189,14 @@ void CoapBase::ProcessReceivedResponse(Message &aMessage, const Ip6::MessageInfo
FinalizeCoapTransaction(*request, metadata, &aMessage, &aMessageInfo, error);
break;
default:
error = OT_ERROR_ABORT;
error = kErrorAbort;
FinalizeCoapTransaction(*request, metadata, &aMessage, &aMessageInfo, error);
break;
}
}
#else // OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
{
FinalizeCoapTransaction(*request, metadata, &aMessage, &aMessageInfo, OT_ERROR_NONE);
FinalizeCoapTransaction(*request, metadata, &aMessage, &aMessageInfo, kErrorNone);
}
#endif // OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
}
@@ -1223,11 +1222,11 @@ void CoapBase::ProcessReceivedResponse(Message &aMessage, const Ip6::MessageInfo
))
{
// If multicast non-confirmable request, allow multiple responses
metadata.mResponseHandler(metadata.mResponseContext, &aMessage, &aMessageInfo, OT_ERROR_NONE);
metadata.mResponseHandler(metadata.mResponseContext, &aMessage, &aMessageInfo, kErrorNone);
}
else
{
FinalizeCoapTransaction(*request, metadata, &aMessage, &aMessageInfo, OT_ERROR_NONE);
FinalizeCoapTransaction(*request, metadata, &aMessage, &aMessageInfo, kErrorNone);
}
break;
@@ -1235,7 +1234,7 @@ void CoapBase::ProcessReceivedResponse(Message &aMessage, const Ip6::MessageInfo
exit:
if (error == OT_ERROR_NONE && request == nullptr)
if (error == kErrorNone && request == nullptr)
{
if (aMessage.IsConfirmable() || aMessage.IsNonConfirmable())
{
@@ -1250,7 +1249,7 @@ void CoapBase::ProcessReceivedRequest(Message &aMessage, const Ip6::MessageInfo
{
char uriPath[Message::kMaxReceivedUriPath + 1];
Message *cachedResponse = nullptr;
otError error = OT_ERROR_NOT_FOUND;
Error error = kErrorNotFound;
#if OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
Option::Iterator iterator;
char * curUriPath = uriPath;
@@ -1265,16 +1264,16 @@ void CoapBase::ProcessReceivedRequest(Message &aMessage, const Ip6::MessageInfo
switch (mResponsesQueue.GetMatchedResponseCopy(aMessage, aMessageInfo, &cachedResponse))
{
case OT_ERROR_NONE:
case kErrorNone:
cachedResponse->Finish();
error = Send(*cachedResponse, aMessageInfo);
OT_FALL_THROUGH;
case OT_ERROR_NO_BUFS:
case kErrorNoBufs:
ExitNow();
case OT_ERROR_NOT_FOUND:
case kErrorNotFound:
default:
break;
}
@@ -1292,8 +1291,7 @@ void CoapBase::ProcessReceivedRequest(Message &aMessage, const Ip6::MessageInfo
*curUriPath++ = '/';
}
VerifyOrExit(curUriPath + iterator.GetOption()->GetLength() < OT_ARRAY_END(uriPath),
error = OT_ERROR_PARSE);
VerifyOrExit(curUriPath + iterator.GetOption()->GetLength() < OT_ARRAY_END(uriPath), error = kErrorParse);
IgnoreError(iterator.ReadOptionValue(curUriPath));
curUriPath += iterator.GetOption()->GetLength();
@@ -1337,23 +1335,23 @@ void CoapBase::ProcessReceivedRequest(Message &aMessage, const Ip6::MessageInfo
{
switch (ProcessBlock1Request(aMessage, aMessageInfo, *resource, totalTransfereSize))
{
case OT_ERROR_NONE:
case kErrorNone:
resource->HandleRequest(aMessage, aMessageInfo);
// Fall through
case OT_ERROR_BUSY:
error = OT_ERROR_NONE;
case kErrorBusy:
error = kErrorNone;
break;
case OT_ERROR_NO_BUFS:
case kErrorNoBufs:
IgnoreReturnValue(SendHeaderResponse(kCodeRequestTooLarge, aMessage, aMessageInfo));
error = OT_ERROR_DROP;
error = kErrorDrop;
break;
case OT_ERROR_NO_FRAME_RECEIVED:
case kErrorNoFrameReceived:
IgnoreReturnValue(SendHeaderResponse(kCodeRequestIncomplete, aMessage, aMessageInfo));
error = OT_ERROR_DROP;
error = kErrorDrop;
break;
default:
IgnoreReturnValue(SendHeaderResponse(kCodeInternalError, aMessage, aMessageInfo));
error = OT_ERROR_DROP;
error = kErrorDrop;
break;
}
}
@@ -1361,10 +1359,10 @@ void CoapBase::ProcessReceivedRequest(Message &aMessage, const Ip6::MessageInfo
case 2:
if (resource->mTransmitHook != nullptr)
{
if ((error = ProcessBlock2Request(aMessage, aMessageInfo, *resource)) != OT_ERROR_NONE)
if ((error = ProcessBlock2Request(aMessage, aMessageInfo, *resource)) != kErrorNone)
{
IgnoreReturnValue(SendHeaderResponse(kCodeInternalError, aMessage, aMessageInfo));
error = OT_ERROR_DROP;
error = kErrorDrop;
}
}
break;
@@ -1374,7 +1372,7 @@ void CoapBase::ProcessReceivedRequest(Message &aMessage, const Ip6::MessageInfo
else
{
resource->HandleRequest(aMessage, aMessageInfo);
error = OT_ERROR_NONE;
error = kErrorNone;
ExitNow();
}
}
@@ -1387,7 +1385,7 @@ void CoapBase::ProcessReceivedRequest(Message &aMessage, const Ip6::MessageInfo
if (strcmp(resource->mUriPath, uriPath) == 0)
{
resource->HandleRequest(aMessage, aMessageInfo);
error = OT_ERROR_NONE;
error = kErrorNone;
ExitNow();
}
}
@@ -1395,16 +1393,16 @@ void CoapBase::ProcessReceivedRequest(Message &aMessage, const Ip6::MessageInfo
if (mDefaultHandler)
{
mDefaultHandler(mDefaultHandlerContext, &aMessage, &aMessageInfo);
error = OT_ERROR_NONE;
error = kErrorNone;
}
exit:
if (error != OT_ERROR_NONE)
if (error != kErrorNone)
{
otLogInfoCoap("Failed to process request: %s", otThreadErrorToString(error));
otLogInfoCoap("Failed to process request: %s", ErrorToString(error));
if (error == OT_ERROR_NOT_FOUND && !aMessageInfo.GetSockAddr().IsMulticast())
if (error == kErrorNotFound && !aMessageInfo.GetSockAddr().IsMulticast())
{
IgnoreError(SendNotFound(aMessage, aMessageInfo));
}
@@ -1431,18 +1429,18 @@ ResponsesQueue::ResponsesQueue(Instance &aInstance)
{
}
otError ResponsesQueue::GetMatchedResponseCopy(const Message & aRequest,
const Ip6::MessageInfo &aMessageInfo,
Message ** aResponse)
Error ResponsesQueue::GetMatchedResponseCopy(const Message & aRequest,
const Ip6::MessageInfo &aMessageInfo,
Message ** aResponse)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
const Message *cacheResponse;
cacheResponse = FindMatchedResponse(aRequest, aMessageInfo);
VerifyOrExit(cacheResponse != nullptr, error = OT_ERROR_NOT_FOUND);
VerifyOrExit(cacheResponse != nullptr, error = kErrorNotFound);
*aResponse = cacheResponse->Clone(cacheResponse->GetLength() - sizeof(ResponseMetadata));
VerifyOrExit(*aResponse != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit(*aResponse != nullptr, error = kErrorNoBufs);
exit:
return error;
@@ -1487,7 +1485,7 @@ void ResponsesQueue::EnqueueResponse(Message & aMessage,
VerifyOrExit((responseCopy = aMessage.Clone()) != nullptr);
VerifyOrExit(metadata.AppendTo(*responseCopy) == OT_ERROR_NONE, responseCopy->Free());
VerifyOrExit(metadata.AppendTo(*responseCopy) == kErrorNone, responseCopy->Free());
mQueue.Enqueue(*responseCopy);
@@ -1658,10 +1656,10 @@ Coap::Coap(Instance &aInstance)
{
}
otError Coap::Start(uint16_t aPort, otNetifIdentifier aNetifIdentifier)
Error Coap::Start(uint16_t aPort, otNetifIdentifier aNetifIdentifier)
{
otError error = OT_ERROR_NONE;
bool socketOpened = false;
Error error = kErrorNone;
bool socketOpened = false;
VerifyOrExit(!mSocket.IsBound());
@@ -1672,7 +1670,7 @@ otError Coap::Start(uint16_t aPort, otNetifIdentifier aNetifIdentifier)
SuccessOrExit(error = mSocket.Bind(aPort));
exit:
if (error != OT_ERROR_NONE && socketOpened)
if (error != kErrorNone && socketOpened)
{
IgnoreError(mSocket.Close());
}
@@ -1680,9 +1678,9 @@ exit:
return error;
}
otError Coap::Stop(void)
Error Coap::Stop(void)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
VerifyOrExit(mSocket.IsBound());
@@ -1699,14 +1697,14 @@ void Coap::HandleUdpReceive(void *aContext, otMessage *aMessage, const otMessage
*static_cast<const Ip6::MessageInfo *>(aMessageInfo));
}
otError Coap::Send(CoapBase &aCoapBase, ot::Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
Error Coap::Send(CoapBase &aCoapBase, ot::Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
{
return static_cast<Coap &>(aCoapBase).Send(aMessage, aMessageInfo);
}
otError Coap::Send(ot::Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
Error Coap::Send(ot::Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
{
return mSocket.IsBound() ? mSocket.SendTo(aMessage, aMessageInfo) : OT_ERROR_INVALID_STATE;
return mSocket.IsBound() ? mSocket.SendTo(aMessage, aMessageInfo) : kErrorInvalidState;
}
} // namespace Coap
+109 -110
View File
@@ -211,16 +211,16 @@ public:
mNext = nullptr;
}
otError HandleBlockReceive(const uint8_t *aBlock,
uint32_t aPosition,
uint16_t aBlockLength,
bool aMore,
uint32_t aTotalLength) const
Error HandleBlockReceive(const uint8_t *aBlock,
uint32_t aPosition,
uint16_t aBlockLength,
bool aMore,
uint32_t aTotalLength) const
{
return mReceiveHook(otCoapBlockwiseResource::mContext, aBlock, aPosition, aBlockLength, aMore, aTotalLength);
}
otError HandleBlockTransmit(uint8_t *aBlock, uint32_t aPosition, uint16_t *aBlockLength, bool *aMore) const
Error HandleBlockTransmit(uint8_t *aBlock, uint32_t aPosition, uint16_t *aBlockLength, bool *aMore) const
{
return mTransmitHook(otCoapBlockwiseResource::mContext, aBlock, aPosition, aBlockLength, aMore);
}
@@ -314,12 +314,12 @@ public:
* @param[in] aMessageInfo The message info containing source endpoint address and port.
* @param[out] aResponse A pointer to return a copy of a cached CoAP response matching given arguments.
*
* @retval OT_ERROR_NONE Matching response found and successfully created a copy.
* @retval OT_ERROR_NO_BUFS Matching response found but there is not sufficient buffer to create a copy.
* @retval OT_ERROR_NOT_FOUND Matching response not found.
* @retval kErrorNone Matching response found and successfully created a copy.
* @retval kErrorNoBufs Matching response found but there is not sufficient buffer to create a copy.
* @retval kErrorNotFound Matching response not found.
*
*/
otError GetMatchedResponseCopy(const Message &aRequest, const Ip6::MessageInfo &aMessageInfo, Message **aResponse);
Error GetMatchedResponseCopy(const Message &aRequest, const Ip6::MessageInfo &aMessageInfo, Message **aResponse);
/**
* This method gets a reference to the cached CoAP responses queue.
@@ -337,8 +337,8 @@ private:
struct ResponseMetadata
{
otError AppendTo(Message &aMessage) const { return aMessage.Append(*this); }
void ReadFrom(const Message &aMessage);
Error AppendTo(Message &aMessage) const { return aMessage.Append(*this); }
void ReadFrom(const Message &aMessage);
TimeMilli mDequeueTime;
Ip6::MessageInfo mMessageInfo;
@@ -377,13 +377,12 @@ public:
@ @param[in] aMessageInfo A reference to the message info associated with @p aMessage.
* @param[in] aContext A pointer to arbitrary context information.
*
* @retval OT_ERROR_NONE Server should continue processing this message, other
* return values indicates the server should stop processing
* this message.
* @retval OT_ERROR_NOT_TMF The message is not a TMF message.
* @retval kErrorNone Server should continue processing this message, other return values indicates the
* server should stop processing this message.
* @retval kErrorNotTmf The message is not a TMF message.
*
*/
typedef otError (*Interceptor)(const Message &aMessage, const Ip6::MessageInfo &aMessageInfo, void *aContext);
typedef Error (*Interceptor)(const Message &aMessage, const Ip6::MessageInfo &aMessageInfo, void *aContext);
/**
* This method clears requests and responses used by this CoAP agent.
@@ -479,17 +478,17 @@ public:
* @param[in] aTransmitHook A pointer to a hook function for outgoing block-wise transfer.
* @param[in] aReceiveHook A pointer to a hook function for incoming block-wise transfer.
*
* @retval OT_ERROR_NONE Successfully sent CoAP message.
* @retval OT_ERROR_NO_BUFS Failed to allocate retransmission data.
* @retval kErrorNone Successfully sent CoAP message.
* @retval kErrorNoBufs Failed to allocate retransmission data.
*
*/
otError SendMessage(Message & aMessage,
const Ip6::MessageInfo & aMessageInfo,
const TxParameters & aTxParameters,
otCoapResponseHandler aHandler = nullptr,
void * aContext = nullptr,
otCoapBlockwiseTransmitHook aTransmitHook = nullptr,
otCoapBlockwiseReceiveHook aReceiveHook = nullptr);
Error SendMessage(Message & aMessage,
const Ip6::MessageInfo & aMessageInfo,
const TxParameters & aTxParameters,
otCoapResponseHandler aHandler = nullptr,
void * aContext = nullptr,
otCoapBlockwiseTransmitHook aTransmitHook = nullptr,
otCoapBlockwiseReceiveHook aReceiveHook = nullptr);
#else // OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
/**
@@ -505,15 +504,15 @@ public:
* @param[in] aHandler A function pointer that shall be called on response reception or time-out.
* @param[in] aContext A pointer to arbitrary context information.
*
* @retval OT_ERROR_NONE Successfully sent CoAP message.
* @retval OT_ERROR_NO_BUFS Insufficient buffers available to send the CoAP message.
* @retval kErrorNone Successfully sent CoAP message.
* @retval kErrorNoBufs Insufficient buffers available to send the CoAP message.
*
*/
otError SendMessage(Message & aMessage,
const Ip6::MessageInfo &aMessageInfo,
const TxParameters & aTxParameters,
ResponseHandler aHandler = nullptr,
void * aContext = nullptr);
Error SendMessage(Message & aMessage,
const Ip6::MessageInfo &aMessageInfo,
const TxParameters & aTxParameters,
ResponseHandler aHandler = nullptr,
void * aContext = nullptr);
#endif // OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
/**
@@ -528,14 +527,14 @@ public:
* @param[in] aHandler A function pointer that shall be called on response reception or time-out.
* @param[in] aContext A pointer to arbitrary context information.
*
* @retval OT_ERROR_NONE Successfully sent CoAP message.
* @retval OT_ERROR_NO_BUFS Insufficient buffers available to send the CoAP response.
* @retval kErrorNone Successfully sent CoAP message.
* @retval kErrorNoBufs Insufficient buffers available to send the CoAP response.
*
*/
otError SendMessage(Message & aMessage,
const Ip6::MessageInfo &aMessageInfo,
ResponseHandler aHandler = nullptr,
void * aContext = nullptr);
Error SendMessage(Message & aMessage,
const Ip6::MessageInfo &aMessageInfo,
ResponseHandler aHandler = nullptr,
void * aContext = nullptr);
/**
* This method sends a CoAP reset message.
@@ -543,12 +542,12 @@ public:
* @param[in] aRequest A reference to the CoAP Message that was used in CoAP request.
* @param[in] aMessageInfo The message info corresponding to the CoAP request.
*
* @retval OT_ERROR_NONE Successfully enqueued the CoAP response message.
* @retval OT_ERROR_NO_BUFS Insufficient buffers available to send the CoAP response.
* @retval OT_ERROR_INVALID_ARGS The @p aRequest is not of confirmable type.
* @retval kErrorNone Successfully enqueued the CoAP response message.
* @retval kErrorNoBufs Insufficient buffers available to send the CoAP response.
* @retval kErrorInvalidArgs The @p aRequest is not of confirmable type.
*
*/
otError SendReset(Message &aRequest, const Ip6::MessageInfo &aMessageInfo);
Error SendReset(Message &aRequest, const Ip6::MessageInfo &aMessageInfo);
/**
* This method sends header-only CoAP response message.
@@ -557,12 +556,12 @@ public:
* @param[in] aRequest A reference to the CoAP Message that was used in CoAP request.
* @param[in] aMessageInfo The message info corresponding to the CoAP request.
*
* @retval OT_ERROR_NONE Successfully enqueued the CoAP response message.
* @retval OT_ERROR_NO_BUFS Insufficient buffers available to send the CoAP response.
* @retval OT_ERROR_INVALID_ARGS The @p aRequest header is not of confirmable type.
* @retval kErrorNone Successfully enqueued the CoAP response message.
* @retval kErrorNoBufs Insufficient buffers available to send the CoAP response.
* @retval kErrorInvalidArgs The @p aRequest header is not of confirmable type.
*
*/
otError SendHeaderResponse(Message::Code aCode, const Message &aRequest, const Ip6::MessageInfo &aMessageInfo);
Error SendHeaderResponse(Message::Code aCode, const Message &aRequest, const Ip6::MessageInfo &aMessageInfo);
/**
* This method sends a CoAP ACK empty message which is used in Separate Response for confirmable requests.
@@ -570,12 +569,12 @@ public:
* @param[in] aRequest A reference to the CoAP Message that was used in CoAP request.
* @param[in] aMessageInfo The message info corresponding to the CoAP request.
*
* @retval OT_ERROR_NONE Successfully enqueued the CoAP response message.
* @retval OT_ERROR_NO_BUFS Insufficient buffers available to send the CoAP response.
* @retval OT_ERROR_INVALID_ARGS The @p aRequest header is not of confirmable type.
* @retval kErrorNone Successfully enqueued the CoAP response message.
* @retval kErrorNoBufs Insufficient buffers available to send the CoAP response.
* @retval kErrorInvalidArgs The @p aRequest header is not of confirmable type.
*
*/
otError SendAck(const Message &aRequest, const Ip6::MessageInfo &aMessageInfo);
Error SendAck(const Message &aRequest, const Ip6::MessageInfo &aMessageInfo);
/**
* This method sends a CoAP ACK message on which a dummy CoAP response is piggybacked.
@@ -584,24 +583,24 @@ public:
* @param[in] aMessageInfo The message info corresponding to the CoAP request.
* @param[in] aCode The CoAP code of the dummy CoAP response.
*
* @retval OT_ERROR_NONE Successfully enqueued the CoAP response message.
* @retval OT_ERROR_NO_BUFS Insufficient buffers available to send the CoAP response.
* @retval OT_ERROR_INVALID_ARGS The @p aRequest header is not of confirmable type.
* @retval kErrorNone Successfully enqueued the CoAP response message.
* @retval kErrorNoBufs Insufficient buffers available to send the CoAP response.
* @retval kErrorInvalidArgs The @p aRequest header is not of confirmable type.
*
*/
otError SendEmptyAck(const Message &aRequest, const Ip6::MessageInfo &aMessageInfo, Code aCode = kCodeChanged);
Error SendEmptyAck(const Message &aRequest, const Ip6::MessageInfo &aMessageInfo, Code aCode = kCodeChanged);
/**
* This method sends a header-only CoAP message to indicate no resource matched for the request.
*
* @param[in] aRequest A reference to the CoAP Message that was used in CoAP request.
* @param[in] aMessageInfo The message info corresponding to the CoAP request.
* @param[in] aMessageInfo The message info corresponding to the CoAP request.
*
* @retval OT_ERROR_NONE Successfully enqueued the CoAP response message.
* @retval OT_ERROR_NO_BUFS Insufficient buffers available to send the CoAP response.
* @retval kErrorNone Successfully enqueued the CoAP response message.
* @retval kErrorNoBufs Insufficient buffers available to send the CoAP response.
*
*/
otError SendNotFound(const Message &aRequest, const Ip6::MessageInfo &aMessageInfo);
Error SendNotFound(const Message &aRequest, const Ip6::MessageInfo &aMessageInfo);
#if OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
/**
@@ -609,13 +608,13 @@ public:
* were sent out of order.
*
* @param[in] aRequest A reference to the CoAP Message that was used in CoAP request.
* @param[in] aMessageInfo The message info corresponding to the CoAP request.
* @param[in] aMessageInfo The message info corresponding to the CoAP request.
*
* @retval OT_ERROR_NONE Successfully enqueued the CoAP response message.
* @retval OT_ERROR_NO_BUFS Insufficient buffers available to send the CoAP response.
* @retval kErrorNone Successfully enqueued the CoAP response message.
* @retval kErrorNoBufs Insufficient buffers available to send the CoAP response.
*
*/
otError SendRequestEntityIncomplete(const Message &aRequest, const Ip6::MessageInfo &aMessageInfo)
Error SendRequestEntityIncomplete(const Message &aRequest, const Ip6::MessageInfo &aMessageInfo)
{
return SendHeaderResponse(kCodeRequestIncomplete, aRequest, aMessageInfo);
}
@@ -624,16 +623,16 @@ public:
/**
* This method aborts CoAP transactions associated with given handler and context.
*
* The associated response handler will be called with OT_ERROR_ABORT.
* The associated response handler will be called with kErrorAbort.
*
* @param[in] aHandler A function pointer that should be called when the transaction ends.
* @param[in] aContext A pointer to arbitrary context information.
*
* @retval OT_ERROR_NONE Successfully aborted CoAP transactions.
* @retval OT_ERROR_NOT_FOUND CoAP transaction associated with given handler was not found.
* @retval kErrorNone Successfully aborted CoAP transactions.
* @retval kErrorNotFound CoAP transaction associated with given handler was not found.
*
*/
otError AbortTransaction(ResponseHandler aHandler, void *aContext);
Error AbortTransaction(ResponseHandler aHandler, void *aContext);
/**
* This method sets interceptor to be called before processing a CoAP packet.
@@ -668,11 +667,11 @@ protected:
* @param[in] aMessage A reference to the message to send.
* @param[in] aMessageInfo A reference to the message info associated with @p aMessage.
*
* @retval OT_ERROR_NONE Successfully sent CoAP message.
* @retval OT_ERROR_NO_BUFS Failed to allocate retransmission data.
* @retval kErrorNone Successfully sent CoAP message.
* @retval kErrorNoBufs Failed to allocate retransmission data.
*
*/
typedef otError (*Sender)(CoapBase &aCoapBase, ot::Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
typedef Error (*Sender)(CoapBase &aCoapBase, ot::Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
/**
* This constructor initializes the object.
@@ -696,9 +695,9 @@ protected:
private:
struct Metadata
{
otError AppendTo(Message &aMessage) const { return aMessage.Append(*this); }
void ReadFrom(const Message &aMessage);
void UpdateIn(Message &aMessage) const;
Error AppendTo(Message &aMessage) const { return aMessage.Append(*this); }
void ReadFrom(const Message &aMessage);
void UpdateIn(Message &aMessage) const;
Ip6::Address mSourceAddress; // IPv6 address of the message source.
Ip6::Address mDestinationAddress; // IPv6 address of the message destination.
@@ -739,44 +738,44 @@ private:
const Metadata & aMetadata,
Message * aResponse,
const Ip6::MessageInfo *aMessageInfo,
otError aResult);
Error aResult);
#if OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
void FreeLastBlockResponse(void);
otError CacheLastBlockResponse(Message *aResponse);
void FreeLastBlockResponse(void);
Error CacheLastBlockResponse(Message *aResponse);
otError PrepareNextBlockRequest(Message::BlockType aType,
bool aMoreBlocks,
Message & aRequestOld,
Message & aRequest,
Message & aMessage);
otError ProcessBlock1Request(Message & aMessage,
const Ip6::MessageInfo & aMessageInfo,
const ResourceBlockWise &aResource,
uint32_t aTotalLength);
otError ProcessBlock2Request(Message & aMessage,
const Ip6::MessageInfo & aMessageInfo,
const ResourceBlockWise &aResource);
Error PrepareNextBlockRequest(Message::BlockType aType,
bool aMoreBlocks,
Message & aRequestOld,
Message & aRequest,
Message & aMessage);
Error ProcessBlock1Request(Message & aMessage,
const Ip6::MessageInfo & aMessageInfo,
const ResourceBlockWise &aResource,
uint32_t aTotalLength);
Error ProcessBlock2Request(Message & aMessage,
const Ip6::MessageInfo & aMessageInfo,
const ResourceBlockWise &aResource);
#endif
void ProcessReceivedRequest(Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
void ProcessReceivedResponse(Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
#if OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
otError SendNextBlock1Request(Message & aRequest,
Message & aMessage,
const Ip6::MessageInfo &aMessageInfo,
const Metadata & aCoapMetadata);
otError SendNextBlock2Request(Message & aRequest,
Message & aMessage,
const Ip6::MessageInfo &aMessageInfo,
const Metadata & aCoapMetadata,
uint32_t aTotalLength,
bool aBeginBlock1Transfer);
Error SendNextBlock1Request(Message & aRequest,
Message & aMessage,
const Ip6::MessageInfo &aMessageInfo,
const Metadata & aCoapMetadata);
Error SendNextBlock2Request(Message & aRequest,
Message & aMessage,
const Ip6::MessageInfo &aMessageInfo,
const Metadata & aCoapMetadata,
uint32_t aTotalLength,
bool aBeginBlock1Transfer);
#endif
void SendCopy(const Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
otError SendEmptyMessage(Type aType, const Message &aRequest, const Ip6::MessageInfo &aMessageInfo);
void SendCopy(const Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
Error SendEmptyMessage(Type aType, const Message &aRequest, const Ip6::MessageInfo &aMessageInfo);
otError Send(ot::Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
Error Send(ot::Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
MessageQueue mPendingRequests;
uint16_t mMessageId;
@@ -820,28 +819,28 @@ public:
* @param[in] aPort The local UDP port to bind to.
* @param[in] aNetifIdentifier The network interface identifier to bind.
*
* @retval OT_ERROR_NONE Successfully started the CoAP service.
* @retval OT_ERROR_FAILED Failed to start CoAP agent.
* @retval kErrorNone Successfully started the CoAP service.
* @retval kErrorFailed Failed to start CoAP agent.
*
*/
otError Start(uint16_t aPort, otNetifIdentifier aNetifIdentifier = OT_NETIF_UNSPECIFIED);
Error Start(uint16_t aPort, otNetifIdentifier aNetifIdentifier = OT_NETIF_UNSPECIFIED);
/**
* This method stops the CoAP service.
*
* @retval OT_ERROR_NONE Successfully stopped the CoAP service.
* @retval OT_ERROR_FAILED Failed to stop CoAP agent.
* @retval kErrorNone Successfully stopped the CoAP service.
* @retval kErrorFailed Failed to stop CoAP agent.
*
*/
otError Stop(void);
Error Stop(void);
protected:
Ip6::Udp::Socket mSocket;
private:
static otError Send(CoapBase &aCoapBase, ot::Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
static void HandleUdpReceive(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo);
otError Send(ot::Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
static Error Send(CoapBase &aCoapBase, ot::Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
static void HandleUdpReceive(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo);
Error Send(ot::Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
};
} // namespace Coap
+60 -61
View File
@@ -65,9 +65,9 @@ void Message::Init(Type aType, Code aCode)
SetCode(aCode);
}
otError Message::Init(Type aType, Code aCode, const char *aUriPath)
Error Message::Init(Type aType, Code aCode, const char *aUriPath)
{
otError error;
Error error;
Init(aType, aCode);
SuccessOrExit(error = GenerateRandomToken(kDefaultTokenLength));
@@ -87,17 +87,17 @@ void Message::InitAsNonConfirmablePost(void)
Init(kTypeNonConfirmable, kCodePost);
}
otError Message::InitAsConfirmablePost(const char *aUriPath)
Error Message::InitAsConfirmablePost(const char *aUriPath)
{
return Init(kTypeConfirmable, kCodePost, aUriPath);
}
otError Message::InitAsNonConfirmablePost(const char *aUriPath)
Error Message::InitAsNonConfirmablePost(const char *aUriPath)
{
return Init(kTypeNonConfirmable, kCodePost, aUriPath);
}
otError Message::InitAsPost(const Ip6::Address &aDestination, const char *aUriPath)
Error Message::InitAsPost(const Ip6::Address &aDestination, const char *aUriPath)
{
return Init(aDestination.IsMulticast() ? kTypeNonConfirmable : kTypeConfirmable, kCodePost, aUriPath);
}
@@ -160,15 +160,15 @@ uint8_t Message::WriteExtendedOptionField(uint16_t aValue, uint8_t *&aBuffer)
return rval;
}
otError Message::AppendOption(uint16_t aNumber, uint16_t aLength, const void *aValue)
Error Message::AppendOption(uint16_t aNumber, uint16_t aLength, const void *aValue)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
uint16_t delta;
uint8_t header[kMaxOptionHeaderSize];
uint16_t headerLength;
uint8_t *cur;
VerifyOrExit(aNumber >= GetHelpData().mOptionLast, error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(aNumber >= GetHelpData().mOptionLast, error = kErrorInvalidArgs);
delta = aNumber - GetHelpData().mOptionLast;
cur = &header[1];
@@ -178,8 +178,7 @@ otError Message::AppendOption(uint16_t aNumber, uint16_t aLength, const void *aV
headerLength = static_cast<uint16_t>(cur - header);
VerifyOrExit(static_cast<uint32_t>(GetLength()) + headerLength + aLength < kMaxHeaderLength,
error = OT_ERROR_NO_BUFS);
VerifyOrExit(static_cast<uint32_t>(GetLength()) + headerLength + aLength < kMaxHeaderLength, error = kErrorNoBufs);
SuccessOrExit(error = AppendBytes(header, headerLength));
SuccessOrExit(error = AppendBytes(aValue, aLength));
@@ -192,7 +191,7 @@ exit:
return error;
}
otError Message::AppendUintOption(uint16_t aNumber, uint32_t aValue)
Error Message::AppendUintOption(uint16_t aNumber, uint32_t aValue)
{
uint8_t buffer[sizeof(uint32_t)];
const uint8_t *value = &buffer[0];
@@ -209,14 +208,14 @@ otError Message::AppendUintOption(uint16_t aNumber, uint32_t aValue)
return AppendOption(aNumber, length, value);
}
otError Message::AppendStringOption(uint16_t aNumber, const char *aValue)
Error Message::AppendStringOption(uint16_t aNumber, const char *aValue)
{
return AppendOption(aNumber, static_cast<uint16_t>(strlen(aValue)), aValue);
}
otError Message::AppendUriPathOptions(const char *aUriPath)
Error Message::AppendUriPathOptions(const char *aUriPath)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
const char *cur = aUriPath;
const char *end;
@@ -232,10 +231,10 @@ exit:
return error;
}
otError Message::ReadUriPathOptions(char (&aUriPath)[kMaxReceivedUriPath + 1]) const
Error Message::ReadUriPathOptions(char (&aUriPath)[kMaxReceivedUriPath + 1]) const
{
char * curUriPath = aUriPath;
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Option::Iterator iterator;
SuccessOrExit(error = iterator.Init(*this, kOptionUriPath));
@@ -249,7 +248,7 @@ otError Message::ReadUriPathOptions(char (&aUriPath)[kMaxReceivedUriPath + 1]) c
*curUriPath++ = '/';
}
VerifyOrExit(curUriPath + optionLength < OT_ARRAY_END(aUriPath), error = OT_ERROR_PARSE);
VerifyOrExit(curUriPath + optionLength < OT_ARRAY_END(aUriPath), error = kErrorParse);
IgnoreError(iterator.ReadOptionValue(curUriPath));
curUriPath += optionLength;
@@ -263,14 +262,14 @@ exit:
return error;
}
otError Message::AppendBlockOption(Message::BlockType aType, uint32_t aNum, bool aMore, otCoapBlockSzx aSize)
Error Message::AppendBlockOption(Message::BlockType aType, uint32_t aNum, bool aMore, otCoapBlockSzx aSize)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
uint32_t encoded = aSize;
VerifyOrExit(aType == kBlockType1 || aType == kBlockType2, error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(aSize <= OT_COAP_OPTION_BLOCK_SZX_1024, error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(aNum < kBlockNumMax, error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(aType == kBlockType1 || aType == kBlockType2, error = kErrorInvalidArgs);
VerifyOrExit(aSize <= OT_COAP_OPTION_BLOCK_SZX_1024, error = kErrorInvalidArgs);
VerifyOrExit(aNum < kBlockNumMax, error = kErrorInvalidArgs);
encoded |= static_cast<uint32_t>(aMore << kBlockMOffset);
encoded |= aNum << kBlockNumOffset;
@@ -282,13 +281,13 @@ exit:
}
#if OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
otError Message::ReadBlockOptionValues(uint16_t aBlockType)
Error Message::ReadBlockOptionValues(uint16_t aBlockType)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
uint8_t buf[kMaxOptionHeaderSize] = {0};
Option::Iterator iterator;
VerifyOrExit((aBlockType == kOptionBlock1) || (aBlockType == kOptionBlock2), error = OT_ERROR_INVALID_ARGS);
VerifyOrExit((aBlockType == kOptionBlock1) || (aBlockType == kOptionBlock2), error = kErrorInvalidArgs);
SuccessOrExit(error = iterator.Init(*this, aBlockType));
SuccessOrExit(error = iterator.ReadOptionValue(buf));
@@ -315,7 +314,7 @@ otError Message::ReadBlockOptionValues(uint16_t aBlockType)
SetBlockWiseBlockSize(static_cast<otCoapBlockSzx>(buf[2] & 0x07));
break;
default:
error = OT_ERROR_INVALID_ARGS;
error = kErrorInvalidArgs;
break;
}
@@ -324,12 +323,12 @@ exit:
}
#endif // OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
otError Message::SetPayloadMarker(void)
Error Message::SetPayloadMarker(void)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
uint8_t marker = kPayloadMarker;
VerifyOrExit(GetLength() < kMaxHeaderLength, error = OT_ERROR_NO_BUFS);
VerifyOrExit(GetLength() < kMaxHeaderLength, error = kErrorNoBufs);
SuccessOrExit(error = Append(marker));
GetHelpData().mHeaderLength = GetLength();
@@ -340,9 +339,9 @@ exit:
return error;
}
otError Message::ParseHeader(void)
Error Message::ParseHeader(void)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Option::Iterator iterator;
OT_ASSERT(mBuffer.mHead.mMetadata.mReserved >=
@@ -354,7 +353,7 @@ otError Message::ParseHeader(void)
GetHelpData().mHeaderOffset = GetOffset();
IgnoreError(Read(GetHelpData().mHeaderOffset, GetHelpData().mHeader));
VerifyOrExit(GetTokenLength() <= kMaxTokenLength, error = OT_ERROR_PARSE);
VerifyOrExit(GetTokenLength() <= kMaxTokenLength, error = kErrorParse);
SuccessOrExit(error = iterator.Init(*this));
@@ -370,7 +369,7 @@ exit:
return error;
}
otError Message::SetToken(const uint8_t *aToken, uint8_t aTokenLength)
Error Message::SetToken(const uint8_t *aToken, uint8_t aTokenLength)
{
OT_ASSERT(aTokenLength <= kMaxTokenLength);
@@ -381,7 +380,7 @@ otError Message::SetToken(const uint8_t *aToken, uint8_t aTokenLength)
return SetLength(GetHelpData().mHeaderLength);
}
otError Message::GenerateRandomToken(uint8_t aTokenLength)
Error Message::GenerateRandomToken(uint8_t aTokenLength)
{
uint8_t token[kMaxTokenLength];
@@ -392,7 +391,7 @@ otError Message::GenerateRandomToken(uint8_t aTokenLength)
return SetToken(token, aTokenLength);
}
otError Message::SetTokenFromMessage(const Message &aMessage)
Error Message::SetTokenFromMessage(const Message &aMessage)
{
return SetToken(aMessage.GetToken(), aMessage.GetTokenLength());
}
@@ -404,7 +403,7 @@ bool Message::IsTokenEqual(const Message &aMessage) const
return ((tokenLength == aMessage.GetTokenLength()) && (memcmp(GetToken(), aMessage.GetToken(), tokenLength) == 0));
}
otError Message::SetDefaultResponseHeader(const Message &aRequest)
Error Message::SetDefaultResponseHeader(const Message &aRequest)
{
Init(kTypeAck, kCodeChanged);
@@ -525,9 +524,9 @@ const char *Message::CodeToString(void) const
}
#endif // OPENTHREAD_CONFIG_COAP_API_ENABLE
otError Option::Iterator::Init(const Message &aMessage)
Error Option::Iterator::Init(const Message &aMessage)
{
otError error = OT_ERROR_PARSE;
Error error = kErrorParse;
uint32_t offset = static_cast<uint32_t>(aMessage.GetHelpData().mHeaderOffset) + aMessage.GetOptionStart();
// Note that the case where `offset == aMessage.GetLength())` is
@@ -547,9 +546,9 @@ exit:
return error;
}
otError Option::Iterator::Advance(void)
Error Option::Iterator::Advance(void)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
uint8_t headerByte;
uint16_t optionDelta;
uint16_t optionLength;
@@ -558,22 +557,22 @@ otError Option::Iterator::Advance(void)
error = Read(sizeof(uint8_t), &headerByte);
if ((error != OT_ERROR_NONE) || (headerByte == Message::kPayloadMarker))
if ((error != kErrorNone) || (headerByte == Message::kPayloadMarker))
{
// Payload Marker indicates end of options and start of payload.
// Absence of a Payload Marker indicates a zero-length payload.
MarkAsDone();
if (error == OT_ERROR_NONE)
if (error == kErrorNone)
{
// The presence of a marker followed by a zero-length payload
// MUST be processed as a message format error.
VerifyOrExit(mNextOptionOffset < GetMessage().GetLength(), error = OT_ERROR_PARSE);
VerifyOrExit(mNextOptionOffset < GetMessage().GetLength(), error = kErrorParse);
}
ExitNow(error = OT_ERROR_NONE);
ExitNow(error = kErrorNone);
}
optionDelta = (headerByte & Message::kOptionDeltaMask) >> Message::kOptionDeltaOffset;
@@ -582,14 +581,14 @@ otError Option::Iterator::Advance(void)
optionLength = (headerByte & Message::kOptionLengthMask) >> Message::kOptionLengthOffset;
SuccessOrExit(error = ReadExtendedOptionField(optionLength));
VerifyOrExit(optionLength <= GetMessage().GetLength() - mNextOptionOffset, error = OT_ERROR_PARSE);
VerifyOrExit(optionLength <= GetMessage().GetLength() - mNextOptionOffset, error = kErrorParse);
mNextOptionOffset += optionLength;
mOption.mNumber += optionDelta;
mOption.mLength = optionLength;
exit:
if (error != OT_ERROR_NONE)
if (error != kErrorNone)
{
MarkAsParseErrored();
}
@@ -597,25 +596,25 @@ exit:
return error;
}
otError Option::Iterator::ReadOptionValue(void *aValue) const
Error Option::Iterator::ReadOptionValue(void *aValue) const
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
VerifyOrExit(!IsDone(), error = OT_ERROR_NOT_FOUND);
VerifyOrExit(!IsDone(), error = kErrorNotFound);
GetMessage().ReadBytes(mNextOptionOffset - mOption.mLength, aValue, mOption.mLength);
exit:
return error;
}
otError Option::Iterator::ReadOptionValue(uint64_t &aUintValue) const
Error Option::Iterator::ReadOptionValue(uint64_t &aUintValue) const
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
uint8_t buffer[sizeof(uint64_t)];
VerifyOrExit(!IsDone(), error = OT_ERROR_NOT_FOUND);
VerifyOrExit(!IsDone(), error = kErrorNotFound);
VerifyOrExit(mOption.mLength <= sizeof(uint64_t), error = OT_ERROR_NO_BUFS);
VerifyOrExit(mOption.mLength <= sizeof(uint64_t), error = kErrorNoBufs);
IgnoreError(ReadOptionValue(buffer));
aUintValue = 0;
@@ -630,13 +629,13 @@ exit:
return error;
}
otError Option::Iterator::Read(uint16_t aLength, void *aBuffer)
Error Option::Iterator::Read(uint16_t aLength, void *aBuffer)
{
// Reads `aLength` bytes from the message into `aBuffer` at
// `mNextOptionOffset` and updates the `mNextOptionOffset` on a
// successful read (i.e., when entire `aLength` bytes can be read).
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
SuccessOrExit(error = GetMessage().Read(mNextOptionOffset, aBuffer, aLength));
mNextOptionOffset += aLength;
@@ -645,9 +644,9 @@ exit:
return error;
}
otError Option::Iterator::ReadExtendedOptionField(uint16_t &aValue)
Error Option::Iterator::ReadExtendedOptionField(uint16_t &aValue)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
VerifyOrExit(aValue >= Message::kOption1ByteExtension);
@@ -668,18 +667,18 @@ otError Option::Iterator::ReadExtendedOptionField(uint16_t &aValue)
}
else
{
error = OT_ERROR_PARSE;
error = kErrorParse;
}
exit:
return error;
}
otError Option::Iterator::InitOrAdvance(const Message *aMessage, uint16_t aNumber)
Error Option::Iterator::InitOrAdvance(const Message *aMessage, uint16_t aNumber)
{
otError error = (aMessage != nullptr) ? Init(*aMessage) : Advance();
Error error = (aMessage != nullptr) ? Init(*aMessage) : Advance();
while ((error == OT_ERROR_NONE) && !IsDone() && (GetOption()->GetNumber() != aNumber))
while ((error == kErrorNone) && !IsDone() && (GetOption()->GetNumber() != aNumber))
{
error = Advance();
}
+102 -102
View File
@@ -223,33 +223,33 @@ public:
* @param[in] aCode The Code value.
* @param[in] aUriPath A pointer to a null-terminated string.
*
* @retval OT_ERROR_NONE Successfully appended the option.
* @retval OT_ERROR_NO_BUFS The option length exceeds the buffer size.
* @retval kErrorNone Successfully appended the option.
* @retval kErrorNoBufs The option length exceeds the buffer size.
*
*/
otError Init(Type aType, Code aCode, const char *aUriPath);
Error Init(Type aType, Code aCode, const char *aUriPath);
/**
* This method initializes the CoAP header as `kTypeConfirmable` and `kCodePost` with a given URI Path.
*
* @param[in] aUriPath A pointer to a null-terminated string.
*
* @retval OT_ERROR_NONE Successfully appended the option.
* @retval OT_ERROR_NO_BUFS The option length exceeds the buffer size.
* @retval kErrorNone Successfully appended the option.
* @retval kErrorNoBufs The option length exceeds the buffer size.
*
*/
otError InitAsConfirmablePost(const char *aUriPath);
Error InitAsConfirmablePost(const char *aUriPath);
/**
* This method initializes the CoAP header as `kTypeNonConfirmable` and `kCodePost` with a given URI Path.
*
* @param[in] aUriPath A pointer to a null-terminated string.
*
* @retval OT_ERROR_NONE Successfully appended the option.
* @retval OT_ERROR_NO_BUFS The option length exceeds the buffer size.
* @retval kErrorNone Successfully appended the option.
* @retval kErrorNoBufs The option length exceeds the buffer size.
*
*/
otError InitAsNonConfirmablePost(const char *aUriPath);
Error InitAsNonConfirmablePost(const char *aUriPath);
/**
* This method initializes the CoAP header as `kCodePost` with a given URI Path with its type determined from a
@@ -259,11 +259,11 @@ public:
* `kTypeNonConfirmable` if multicast address, `kTypeConfirmable` otherwise.
* @param[in] aUriPath A pointer to a null-terminated string.
*
* @retval OT_ERROR_NONE Successfully appended the option.
* @retval OT_ERROR_NO_BUFS The option length exceeds the buffer size.
* @retval kErrorNone Successfully appended the option.
* @retval kErrorNoBufs The option length exceeds the buffer size.
*
*/
otError InitAsPost(const Ip6::Address &aDestination, const char *aUriPath);
Error InitAsPost(const Ip6::Address &aDestination, const char *aUriPath);
/**
* This method writes header to the message. This must be called before sending the message.
@@ -381,33 +381,33 @@ public:
* @param[in] aToken A pointer to the Token value.
* @param[in] aTokenLength The Length of @p aToken.
*
* @retval OT_ERROR_NONE Successfully set the token value.
* @retval OT_ERROR_NO_BUFS Insufficient message buffers available to set the token value.
* @retval kErrorNone Successfully set the token value.
* @retval kErrorNoBufs Insufficient message buffers available to set the token value.
*
*/
otError SetToken(const uint8_t *aToken, uint8_t aTokenLength);
Error SetToken(const uint8_t *aToken, uint8_t aTokenLength);
/**
* This method sets the Token value and length by copying it from another given message.
*
* @param[in] aMessage The message to copy the Token from.
*
* @retval OT_ERROR_NONE Successfully set the token value.
* @retval OT_ERROR_NO_BUFS Insufficient message buffers available to set the token value.
* @retval kErrorNone Successfully set the token value.
* @retval kErrorNoBufs Insufficient message buffers available to set the token value.
*
*/
otError SetTokenFromMessage(const Message &aMessage);
Error SetTokenFromMessage(const Message &aMessage);
/**
* This method sets the Token length and randomizes its value.
*
* @param[in] aTokenLength The Length of a Token to set.
*
* @retval OT_ERROR_NONE Successfully set the token value.
* @retval OT_ERROR_NO_BUFS Insufficient message buffers available to set the token value.
* @retval kErrorNone Successfully set the token value.
* @retval kErrorNoBufs Insufficient message buffers available to set the token value.
*
*/
otError GenerateRandomToken(uint8_t aTokenLength);
Error GenerateRandomToken(uint8_t aTokenLength);
/**
* This method checks if Tokens in two CoAP headers are equal.
@@ -427,12 +427,12 @@ public:
* @param[in] aLength The CoAP Option length.
* @param[in] aValue A pointer to the CoAP Option value (@p aLength bytes are used as Option value).
*
* @retval OT_ERROR_NONE Successfully appended the option.
* @retval OT_ERROR_INVALID_ARGS The option type is not equal or greater than the last option type.
* @retval OT_ERROR_NO_BUFS The option length exceeds the buffer size.
* @retval kErrorNone Successfully appended the option.
* @retval kErrorInvalidArgs The option type is not equal or greater than the last option type.
* @retval kErrorNoBufs The option length exceeds the buffer size.
*
*/
otError AppendOption(uint16_t aNumber, uint16_t aLength, const void *aValue);
Error AppendOption(uint16_t aNumber, uint16_t aLength, const void *aValue);
/**
* This method appends an unsigned integer CoAP option as specified in RFC-7252 section-3.2
@@ -440,12 +440,12 @@ public:
* @param[in] aNumber The CoAP Option number.
* @param[in] aValue The CoAP Option unsigned integer value.
*
* @retval OT_ERROR_NONE Successfully appended the option.
* @retval OT_ERROR_INVALID_ARGS The option type is not equal or greater than the last option type.
* @retval OT_ERROR_NO_BUFS The option length exceeds the buffer size.
* @retval kErrorNone Successfully appended the option.
* @retval kErrorInvalidArgs The option type is not equal or greater than the last option type.
* @retval kErrorNoBufs The option length exceeds the buffer size.
*
*/
otError AppendUintOption(uint16_t aNumber, uint32_t aValue);
Error AppendUintOption(uint16_t aNumber, uint32_t aValue);
/**
* This method appends a string CoAP option.
@@ -453,35 +453,35 @@ public:
* @param[in] aNumber The CoAP Option number.
* @param[in] aValue The CoAP Option string value.
*
* @retval OT_ERROR_NONE Successfully appended the option.
* @retval OT_ERROR_INVALID_ARGS The option type is not equal or greater than the last option type.
* @retval OT_ERROR_NO_BUFS The option length exceeds the buffer size.
* @retval kErrorNone Successfully appended the option.
* @retval kErrorInvalidArgs The option type is not equal or greater than the last option type.
* @retval kErrorNoBufs The option length exceeds the buffer size.
*
*/
otError AppendStringOption(uint16_t aNumber, const char *aValue);
Error AppendStringOption(uint16_t aNumber, const char *aValue);
/**
* This method appends an Observe option.
*
* @param[in] aObserve Observe field value.
*
* @retval OT_ERROR_NONE Successfully appended the option.
* @retval OT_ERROR_INVALID_ARGS The option type is not equal or greater than the last option type.
* @retval OT_ERROR_NO_BUFS The option length exceeds the buffer size.
* @retval kErrorNone Successfully appended the option.
* @retval kErrorInvalidArgs The option type is not equal or greater than the last option type.
* @retval kErrorNoBufs The option length exceeds the buffer size.
*/
otError AppendObserveOption(uint32_t aObserve) { return AppendUintOption(kOptionObserve, aObserve & kObserveMask); }
Error AppendObserveOption(uint32_t aObserve) { return AppendUintOption(kOptionObserve, aObserve & kObserveMask); }
/**
* This method appends a Uri-Path option.
*
* @param[in] aUriPath A pointer to a null-terminated string.
*
* @retval OT_ERROR_NONE Successfully appended the option.
* @retval OT_ERROR_INVALID_ARGS The option type is not equal or greater than the last option type.
* @retval OT_ERROR_NO_BUFS The option length exceeds the buffer size.
* @retval kErrorNone Successfully appended the option.
* @retval kErrorInvalidArgs The option type is not equal or greater than the last option type.
* @retval kErrorNoBufs The option length exceeds the buffer size.
*
*/
otError AppendUriPathOptions(const char *aUriPath);
Error AppendUriPathOptions(const char *aUriPath);
/**
* This method reads the Uri-Path options and constructs the URI path in the buffer referenced by @p `aUriPath`.
@@ -489,11 +489,11 @@ public:
* @param[in] aUriPath A reference to the buffer for storing URI path.
* NOTE: The buffer size must be `kMaxReceivedUriPath + 1`.
*
* @retval OT_ERROR_NONE Successfully read the Uri-Path options.
* @retval OT_ERROR_PARSE CoAP Option header not well-formed.
* @retval kErrorNone Successfully read the Uri-Path options.
* @retval kErrorParse CoAP Option header not well-formed.
*
*/
otError ReadUriPathOptions(char (&aUriPath)[kMaxReceivedUriPath + 1]) const;
Error ReadUriPathOptions(char (&aUriPath)[kMaxReceivedUriPath + 1]) const;
/**
* This method appends a Block option
@@ -503,36 +503,36 @@ public:
* @param[in] aMore Boolean to indicate more blocks are to be sent.
* @param[in] aSize Maximum block size.
*
* @retval OT_ERROR_NONE Successfully appended the option.
* @retval OT_ERROR_INVALID_ARGS The option type is not equal or greater than the last option type.
* @retval OT_ERROR_NO_BUFS The option length exceeds the buffer size.
* @retval kErrorNone Successfully appended the option.
* @retval kErrorInvalidArgs The option type is not equal or greater than the last option type.
* @retval kErrorNoBufs The option length exceeds the buffer size.
*
*/
otError AppendBlockOption(BlockType aType, uint32_t aNum, bool aMore, otCoapBlockSzx aSize);
Error AppendBlockOption(BlockType aType, uint32_t aNum, bool aMore, otCoapBlockSzx aSize);
/**
* This method appends a Proxy-Uri option.
*
* @param[in] aProxyUri A pointer to a null-terminated string.
*
* @retval OT_ERROR_NONE Successfully appended the option.
* @retval OT_ERROR_INVALID_ARGS The option type is not equal or greater than the last option type.
* @retval OT_ERROR_NO_BUFS The option length exceeds the buffer size.
* @retval kErrorNone Successfully appended the option.
* @retval kErrorInvalidArgs The option type is not equal or greater than the last option type.
* @retval kErrorNoBufs The option length exceeds the buffer size.
*
*/
otError AppendProxyUriOption(const char *aProxyUri) { return AppendStringOption(kOptionProxyUri, aProxyUri); }
Error AppendProxyUriOption(const char *aProxyUri) { return AppendStringOption(kOptionProxyUri, aProxyUri); }
/**
* This method appends a Content-Format option.
*
* @param[in] aContentFormat The Content Format value.
*
* @retval OT_ERROR_NONE Successfully appended the option.
* @retval OT_ERROR_INVALID_ARGS The option type is not equal or greater than the last option type.
* @retval OT_ERROR_NO_BUFS The option length exceeds the buffer size.
* @retval kErrorNone Successfully appended the option.
* @retval kErrorInvalidArgs The option type is not equal or greater than the last option type.
* @retval kErrorNoBufs The option length exceeds the buffer size.
*
*/
otError AppendContentFormatOption(otCoapOptionContentFormat aContentFormat)
Error AppendContentFormatOption(otCoapOptionContentFormat aContentFormat)
{
return AppendUintOption(kOptionContentFormat, static_cast<uint32_t>(aContentFormat));
}
@@ -542,22 +542,22 @@ public:
*
* @param[in] aMaxAge The Max-Age value.
*
* @retval OT_ERROR_NONE Successfully appended the option.
* @retval OT_ERROR_INVALID_ARGS The option type is not equal or greater than the last option type.
* @retval OT_ERROR_NO_BUFS The option length exceeds the buffer size.
* @retval kErrorNone Successfully appended the option.
* @retval kErrorInvalidArgs The option type is not equal or greater than the last option type.
* @retval kErrorNoBufs The option length exceeds the buffer size.
*/
otError AppendMaxAgeOption(uint32_t aMaxAge) { return AppendUintOption(kOptionMaxAge, aMaxAge); }
Error AppendMaxAgeOption(uint32_t aMaxAge) { return AppendUintOption(kOptionMaxAge, aMaxAge); }
/**
* This method appends a single Uri-Query option.
*
* @param[in] aUriQuery A pointer to null-terminated string, which should contain a single key=value pair.
*
* @retval OT_ERROR_NONE Successfully appended the option.
* @retval OT_ERROR_INVALID_ARGS The option type is not equal or greater than the last option type.
* @retval OT_ERROR_NO_BUFS The option length exceeds the buffer size.
* @retval kErrorNone Successfully appended the option.
* @retval kErrorInvalidArgs The option type is not equal or greater than the last option type.
* @retval kErrorNoBufs The option length exceeds the buffer size.
*/
otError AppendUriQueryOption(const char *aUriQuery) { return AppendStringOption(kOptionUriQuery, aUriQuery); }
Error AppendUriQueryOption(const char *aUriQuery) { return AppendStringOption(kOptionUriQuery, aUriQuery); }
#if OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
/**
@@ -566,11 +566,11 @@ public:
*
* @param[in] aBlockType Block1 or Block2 option value.
*
* @retval OT_ERROR_NONE The option has been found and is valid.
* @retval OT_ERROR_NOT_FOUND The option has not been found.
* @retval OT_ERROR_INVALID_ARGS The option is invalid.
* @retval kErrorNone The option has been found and is valid.
* @retval kErrorNotFound The option has not been found.
* @retval kErrorInvalidArgs The option is invalid.
*/
otError ReadBlockOptionValues(uint16_t aBlockType);
Error ReadBlockOptionValues(uint16_t aBlockType);
/**
* This method returns the current header length of a message.
@@ -609,22 +609,22 @@ public:
/**
* This function reads and reassembles the URI path string and fills it into @p aUriPath.
*
* @retval OT_ERROR_NONE URI path string has been reassembled.
* @retval OT_ERROR_NO_BUFS URI path string is too long.
* @retval kErrorNone URI path string has been reassembled.
* @retval kErrorNoBufs URI path string is too long.
*
*/
otError GetUriPath(char *aUriPath) const;
Error GetUriPath(char *aUriPath) const;
/**
* This method adds Payload Marker indicating beginning of the payload to the CoAP header.
*
* It also set offset to the start of payload.
*
* @retval OT_ERROR_NONE Payload Marker successfully added.
* @retval OT_ERROR_NO_BUFS Message Payload Marker exceeds the buffer size.
* @retval kErrorNone Payload Marker successfully added.
* @retval kErrorNoBufs Message Payload Marker exceeds the buffer size.
*
*/
otError SetPayloadMarker(void);
Error SetPayloadMarker(void);
/**
* This method returns the offset of the first CoAP option.
@@ -637,22 +637,22 @@ public:
/**
* This method parses CoAP header and moves offset end of CoAP header.
*
* @retval OT_ERROR_NONE Successfully parsed CoAP header from the message.
* @retval OT_ERROR_PARSE Failed to parse the CoAP header.
* @retval kErrorNone Successfully parsed CoAP header from the message.
* @retval kErrorParse Failed to parse the CoAP header.
*
*/
otError ParseHeader(void);
Error ParseHeader(void);
/**
* This method sets a default response header based on request header.
*
* @param[in] aRequest The request message.
*
* @retval OT_ERROR_NONE Successfully set the default response header.
* @retval OT_ERROR_NO_BUFS Insufficient message buffers available to set the default response header.
* @retval kErrorNone Successfully set the default response header.
* @retval kErrorNoBufs Insufficient message buffers available to set the default response header.
*
*/
otError SetDefaultResponseHeader(const Message &aRequest);
Error SetDefaultResponseHeader(const Message &aRequest);
#if OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
@@ -1058,11 +1058,11 @@ public:
*
* @param[in] aMessage The CoAP message.
*
* @retval OT_ERROR_NONE Successfully initialized. Iterator is either at the first option or done.
* @retval OT_ERROR_PARSE CoAP Option header in @p aMessage is not well-formed.
* @retval kErrorNone Successfully initialized. Iterator is either at the first option or done.
* @retval kErrorParse CoAP Option header in @p aMessage is not well-formed.
*
*/
otError Init(const Message &aMessage);
Error Init(const Message &aMessage);
/**
* This method initializes the iterator to iterate over CoAP Options in a CoAP message matching a given Option
@@ -1077,11 +1077,11 @@ public:
* @param[in] aMessage The CoAP message.
* @param[in] aNumber The CoAP Option Number.
*
* @retval OT_ERROR_NONE Successfully initialized. Iterator is either at the first matching option or done.
* @retval OT_ERROR_PARSE CoAP Option header in @p aMessage is not well-formed.
* @retval kErrorNone Successfully initialized. Iterator is either at the first matching option or done.
* @retval kErrorParse CoAP Option header in @p aMessage is not well-formed.
*
*/
otError Init(const Message &aMessage, uint16_t aNumber) { return InitOrAdvance(&aMessage, aNumber); }
Error Init(const Message &aMessage, uint16_t aNumber) { return InitOrAdvance(&aMessage, aNumber); }
/**
* This method indicates whether or not the iterator is done (i.e., has reached the end of CoAP Option Header).
@@ -1108,11 +1108,11 @@ public:
*
* The iterator is updated to point to the next option or marked as done when there are no more options.
*
* @retval OT_ERROR_NONE Successfully advanced the iterator.
* @retval OT_ERROR_PARSE CoAP Option header is not well-formed.
* @retval kErrorNone Successfully advanced the iterator.
* @retval kErrorParse CoAP Option header is not well-formed.
*
*/
otError Advance(void);
Error Advance(void);
/**
* This method advances the iterator to the next CoAP Option in the header matching a given Option Number value.
@@ -1122,11 +1122,11 @@ public:
*
* @param[in] aNumber The CoAP Option Number.
*
* @retval OT_ERROR_NONE Successfully advanced the iterator.
* @retval OT_ERROR_PARSE CoAP Option header is not well-formed.
* @retval kErrorNone Successfully advanced the iterator.
* @retval kErrorParse CoAP Option header is not well-formed.
*
*/
otError Advance(uint16_t aNumber) { return InitOrAdvance(nullptr, aNumber); }
Error Advance(uint16_t aNumber) { return InitOrAdvance(nullptr, aNumber); }
/**
* This method gets the CoAP message associated with the iterator.
@@ -1151,23 +1151,23 @@ public:
* @param[out] aValue The pointer to a buffer to copy the Option Value. The buffer is assumed to be
* sufficiently large (i.e. at least `GetOption()->GetLength()` bytes).
*
* @retval OT_ERROR_NONE Successfully read and copied the Option Value into given buffer.
* @retval OT_ERROR_NOT_FOUND Iterator is done (not pointing to any option).
* @retval kErrorNone Successfully read and copied the Option Value into given buffer.
* @retval kErrorNotFound Iterator is done (not pointing to any option).
*
*/
otError ReadOptionValue(void *aValue) const;
Error ReadOptionValue(void *aValue) const;
/**
* This method read the current Option Value which is assumed to be an unsigned integer.
*
* @param[out] aUintValue A reference to `uint64_t` to output the read Option Value.
*
* @retval OT_ERROR_NONE Successfully read the Option value.
* @retval OT_ERROR_NO_BUFS Value is too long to fit in an `uint64_t`.
* @retval OT_ERROR_NOT_FOUND Iterator is done (not pointing to any option).
* @retval kErrorNone Successfully read the Option value.
* @retval kErrorNoBufs Value is too long to fit in an `uint64_t`.
* @retval kErrorNotFound Iterator is done (not pointing to any option).
*
*/
otError ReadOptionValue(uint64_t &aUintValue) const;
Error ReadOptionValue(uint64_t &aUintValue) const;
/**
* This method gets the offset of beginning of the CoAP message payload (after the CoAP header).
@@ -1189,9 +1189,9 @@ public:
void MarkAsDone(void) { mOption.mLength = kIteratorDoneLength; }
void MarkAsParseErrored(void) { MarkAsDone(), mNextOptionOffset = kNextOptionOffsetParseError; }
otError Read(uint16_t aLength, void *aBuffer);
otError ReadExtendedOptionField(uint16_t &aValue);
otError InitOrAdvance(const Message *aMessage, uint16_t aNumber);
Error Read(uint16_t aLength, void *aBuffer);
Error ReadExtendedOptionField(uint16_t &aValue);
Error InitOrAdvance(const Message *aMessage, uint16_t aNumber);
};
/**
+33 -33
View File
@@ -54,9 +54,9 @@ CoapSecure::CoapSecure(Instance &aInstance, bool aLayerTwoSecurity)
{
}
otError CoapSecure::Start(uint16_t aPort)
Error CoapSecure::Start(uint16_t aPort)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
mConnectedCallback = nullptr;
mConnectedContext = nullptr;
@@ -68,9 +68,9 @@ exit:
return error;
}
otError CoapSecure::Start(MeshCoP::Dtls::TransportCallback aCallback, void *aContext)
Error CoapSecure::Start(MeshCoP::Dtls::TransportCallback aCallback, void *aContext)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
mConnectedCallback = nullptr;
mConnectedContext = nullptr;
@@ -95,7 +95,7 @@ void CoapSecure::Stop(void)
ClearRequestsAndResponses();
}
otError CoapSecure::Connect(const Ip6::SockAddr &aSockAddr, ConnectedCallback aCallback, void *aContext)
Error CoapSecure::Connect(const Ip6::SockAddr &aSockAddr, ConnectedCallback aCallback, void *aContext)
{
mConnectedCallback = aCallback;
mConnectedContext = aContext;
@@ -105,7 +105,7 @@ otError CoapSecure::Connect(const Ip6::SockAddr &aSockAddr, ConnectedCallback aC
void CoapSecure::SetPsk(const MeshCoP::JoinerPskd &aPskd)
{
otError error;
Error error;
OT_UNUSED_VARIABLE(error);
@@ -115,19 +115,19 @@ void CoapSecure::SetPsk(const MeshCoP::JoinerPskd &aPskd)
error = mDtls.SetPsk(reinterpret_cast<const uint8_t *>(aPskd.GetAsCString()), aPskd.GetLength());
OT_ASSERT(error == OT_ERROR_NONE);
OT_ASSERT(error == kErrorNone);
}
#if OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
otError CoapSecure::SendMessage(Message & aMessage,
ResponseHandler aHandler,
void * aContext,
otCoapBlockwiseTransmitHook aTransmitHook,
otCoapBlockwiseReceiveHook aReceiveHook)
Error CoapSecure::SendMessage(Message & aMessage,
ResponseHandler aHandler,
void * aContext,
otCoapBlockwiseTransmitHook aTransmitHook,
otCoapBlockwiseReceiveHook aReceiveHook)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
VerifyOrExit(IsConnected(), error = OT_ERROR_INVALID_STATE);
VerifyOrExit(IsConnected(), error = kErrorInvalidState);
error = CoapBase::SendMessage(aMessage, mDtls.GetMessageInfo(), TxParameters::GetDefault(), aHandler, aContext,
aTransmitHook, aReceiveHook);
@@ -136,22 +136,22 @@ exit:
return error;
}
otError CoapSecure::SendMessage(Message & aMessage,
const Ip6::MessageInfo & aMessageInfo,
ResponseHandler aHandler,
void * aContext,
otCoapBlockwiseTransmitHook aTransmitHook,
otCoapBlockwiseReceiveHook aReceiveHook)
Error CoapSecure::SendMessage(Message & aMessage,
const Ip6::MessageInfo & aMessageInfo,
ResponseHandler aHandler,
void * aContext,
otCoapBlockwiseTransmitHook aTransmitHook,
otCoapBlockwiseReceiveHook aReceiveHook)
{
return CoapBase::SendMessage(aMessage, aMessageInfo, TxParameters::GetDefault(), aHandler, aContext, aTransmitHook,
aReceiveHook);
}
#else // OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
otError CoapSecure::SendMessage(Message &aMessage, ResponseHandler aHandler, void *aContext)
Error CoapSecure::SendMessage(Message &aMessage, ResponseHandler aHandler, void *aContext)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
VerifyOrExit(IsConnected(), error = OT_ERROR_INVALID_STATE);
VerifyOrExit(IsConnected(), error = kErrorInvalidState);
error = CoapBase::SendMessage(aMessage, mDtls.GetMessageInfo(), aHandler, aContext);
@@ -159,23 +159,23 @@ exit:
return error;
}
otError CoapSecure::SendMessage(Message & aMessage,
const Ip6::MessageInfo &aMessageInfo,
ResponseHandler aHandler,
void * aContext)
Error CoapSecure::SendMessage(Message & aMessage,
const Ip6::MessageInfo &aMessageInfo,
ResponseHandler aHandler,
void * aContext)
{
return CoapBase::SendMessage(aMessage, aMessageInfo, aHandler, aContext);
}
#endif // OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
otError CoapSecure::Send(ot::Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
Error CoapSecure::Send(ot::Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
{
OT_UNUSED_VARIABLE(aMessageInfo);
mTransmitQueue.Enqueue(aMessage);
mTransmitTask.Post();
return OT_ERROR_NONE;
return kErrorNone;
}
void CoapSecure::HandleDtlsConnected(void *aContext, bool aConnected)
@@ -216,7 +216,7 @@ void CoapSecure::HandleTransmit(Tasklet &aTasklet)
void CoapSecure::HandleTransmit(void)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
ot::Message *message = mTransmitQueue.GetHead();
VerifyOrExit(message != nullptr);
@@ -230,14 +230,14 @@ void CoapSecure::HandleTransmit(void)
SuccessOrExit(error = mDtls.Send(*message, message->GetLength()));
exit:
if (error != OT_ERROR_NONE)
if (error != kErrorNone)
{
otLogNoteMeshCoP("CoapSecure Transmit: %s", otThreadErrorToString(error));
otLogNoteMeshCoP("CoapSecure Transmit: %s", ErrorToString(error));
message->Free();
}
else
{
otLogDebgMeshCoP("CoapSecure Transmit: %s", otThreadErrorToString(error));
otLogDebgMeshCoP("CoapSecure Transmit: %s", ErrorToString(error));
}
}
+44 -44
View File
@@ -72,11 +72,11 @@ public:
*
* @param[in] aPort The local UDP port to bind to.
*
* @retval OT_ERROR_NONE Successfully started the CoAP agent.
* @retval OT_ERROR_ALREADY Already started.
* @retval kErrorNone Successfully started the CoAP agent.
* @retval kErrorAlready Already started.
*
*/
otError Start(uint16_t aPort);
Error Start(uint16_t aPort);
/**
* This method starts the secure CoAP agent, but do not use socket to transmit/receive messages.
@@ -84,11 +84,11 @@ public:
* @param[in] aCallback A pointer to a function for sending messages.
* @param[in] aContext A pointer to arbitrary context information.
*
* @retval OT_ERROR_NONE Successfully started the CoAP agent.
* @retval OT_ERROR_ALREADY Already started.
* @retval kErrorNone Successfully started the CoAP agent.
* @retval kErrorAlready Already started.
*
*/
otError Start(MeshCoP::Dtls::TransportCallback aCallback, void *aContext);
Error Start(MeshCoP::Dtls::TransportCallback aCallback, void *aContext);
/**
* This method sets connected callback of this secure CoAP agent.
@@ -116,10 +116,10 @@ public:
* @param[in] aCallback A pointer to a function that will be called once DTLS connection is
* established.
*
* @retval OT_ERROR_NONE Successfully started DTLS connection.
* @retval kErrorNone Successfully started DTLS connection.
*
*/
otError Connect(const Ip6::SockAddr &aSockAddr, ConnectedCallback aCallback, void *aContext);
Error Connect(const Ip6::SockAddr &aSockAddr, ConnectedCallback aCallback, void *aContext);
/**
* This method indicates whether or not the DTLS session is active.
@@ -159,11 +159,11 @@ public:
* @param[in] aPsk A pointer to the PSK.
* @param[in] aPskLength The PSK length.
*
* @retval OT_ERROR_NONE Successfully set the PSK.
* @retval OT_ERROR_INVALID_ARGS The PSK is invalid.
* @retval kErrorNone Successfully set the PSK.
* @retval kErrorInvalidArgs The PSK is invalid.
*
*/
otError SetPsk(const uint8_t *aPsk, uint8_t aPskLength) { return mDtls.SetPsk(aPsk, aPskLength); }
Error SetPsk(const uint8_t *aPsk, uint8_t aPskLength) { return mDtls.SetPsk(aPsk, aPskLength); }
/**
* This method sets the PSK.
@@ -238,11 +238,11 @@ public:
* @param[out] aCertLength The length of the base64 encoded peer certificate.
* @param[in] aCertBufferSize The buffer size of aPeerCert.
*
* @retval OT_ERROR_NONE Successfully get the peer certificate.
* @retval OT_ERROR_NO_BUFS Can't allocate memory for certificate.
* @retval kErrorNone Successfully get the peer certificate.
* @retval kErrorNoBufs Can't allocate memory for certificate.
*
*/
otError GetPeerCertificateBase64(unsigned char *aPeerCert, size_t *aCertLength, size_t aCertBufferSize)
Error GetPeerCertificateBase64(unsigned char *aPeerCert, size_t *aCertLength, size_t aCertBufferSize)
{
return mDtls.GetPeerCertificateBase64(aPeerCert, aCertLength, aCertBufferSize);
}
@@ -286,16 +286,16 @@ public:
* @param[in] aTransmitHook A pointer to a hook function for outgoing block-wise transfer.
* @param[in] aReceiveHook A pointer to a hook function for incoming block-wise transfer.
*
* @retval OT_ERROR_NONE Successfully sent CoAP message.
* @retval OT_ERROR_NO_BUFS Failed to allocate retransmission data.
* @retval OT_ERROR_INVALID_STATE DTLS connection was not initialized.
* @retval kErrorNone Successfully sent CoAP message.
* @retval kErrorNoBufs Failed to allocate retransmission data.
* @retval kErrorInvalidState DTLS connection was not initialized.
*
*/
otError SendMessage(Message & aMessage,
ResponseHandler aHandler = nullptr,
void * aContext = nullptr,
otCoapBlockwiseTransmitHook aTransmitHook = nullptr,
otCoapBlockwiseReceiveHook aReceiveHook = nullptr);
Error SendMessage(Message & aMessage,
ResponseHandler aHandler = nullptr,
void * aContext = nullptr,
otCoapBlockwiseTransmitHook aTransmitHook = nullptr,
otCoapBlockwiseReceiveHook aReceiveHook = nullptr);
/**
* This method sends a CoAP message over secure DTLS connection.
@@ -311,17 +311,17 @@ public:
* @param[in] aTransmitHook A pointer to a hook function for outgoing block-wise transfer.
* @param[in] aReceiveHook A pointer to a hook function for incoming block-wise transfer.
*
* @retval OT_ERROR_NONE Successfully sent CoAP message.
* @retval OT_ERROR_NO_BUFS Failed to allocate retransmission data.
* @retval OT_ERROR_INVALID_STATE DTLS connection was not initialized.
* @retval kErrorNone Successfully sent CoAP message.
* @retval kErrorNoBufs Failed to allocate retransmission data.
* @retval kErrorInvalidState DTLS connection was not initialized.
*
*/
otError SendMessage(Message & aMessage,
const Ip6::MessageInfo & aMessageInfo,
ResponseHandler aHandler = nullptr,
void * aContext = nullptr,
otCoapBlockwiseTransmitHook aTransmitHook = nullptr,
otCoapBlockwiseReceiveHook aReceiveHook = nullptr);
Error SendMessage(Message & aMessage,
const Ip6::MessageInfo & aMessageInfo,
ResponseHandler aHandler = nullptr,
void * aContext = nullptr,
otCoapBlockwiseTransmitHook aTransmitHook = nullptr,
otCoapBlockwiseReceiveHook aReceiveHook = nullptr);
#else // OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
/**
* This method sends a CoAP message over secure DTLS connection.
@@ -334,12 +334,12 @@ public:
* @param[in] aHandler A function pointer that shall be called on response reception or time-out.
* @param[in] aContext A pointer to arbitrary context information.
*
* @retval OT_ERROR_NONE Successfully sent CoAP message.
* @retval OT_ERROR_NO_BUFS Failed to allocate retransmission data.
* @retval OT_ERROR_INVALID_STATE DTLS connection was not initialized.
* @retval kErrorNone Successfully sent CoAP message.
* @retval kErrorNoBufs Failed to allocate retransmission data.
* @retval kErrorInvalidState DTLS connection was not initialized.
*
*/
otError SendMessage(Message &aMessage, ResponseHandler aHandler = nullptr, void *aContext = nullptr);
Error SendMessage(Message &aMessage, ResponseHandler aHandler = nullptr, void *aContext = nullptr);
/**
* This method sends a CoAP message over secure DTLS connection.
@@ -353,15 +353,15 @@ public:
* @param[in] aHandler A function pointer that shall be called on response reception or time-out.
* @param[in] aContext A pointer to arbitrary context information.
*
* @retval OT_ERROR_NONE Successfully sent CoAP message.
* @retval OT_ERROR_NO_BUFS Failed to allocate retransmission data.
* @retval OT_ERROR_INVALID_STATE DTLS connection was not initialized.
* @retval kErrorNone Successfully sent CoAP message.
* @retval kErrorNoBufs Failed to allocate retransmission data.
* @retval kErrorInvalidState DTLS connection was not initialized.
*
*/
otError SendMessage(Message & aMessage,
const Ip6::MessageInfo &aMessageInfo,
ResponseHandler aHandler = nullptr,
void * aContext = nullptr);
Error SendMessage(Message & aMessage,
const Ip6::MessageInfo &aMessageInfo,
ResponseHandler aHandler = nullptr,
void * aContext = nullptr);
#endif // OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
/**
@@ -385,11 +385,11 @@ public:
const Ip6::MessageInfo &GetMessageInfo(void) const { return mDtls.GetMessageInfo(); }
private:
static otError Send(CoapBase &aCoapBase, ot::Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
static Error Send(CoapBase &aCoapBase, ot::Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
{
return static_cast<CoapSecure &>(aCoapBase).Send(aMessage, aMessageInfo);
}
otError Send(ot::Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
Error Send(ot::Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
static void HandleDtlsConnected(void *aContext, bool aConnected);
void HandleDtlsConnected(bool aConnected);
+85
View File
@@ -0,0 +1,85 @@
/*
* Copyright (c) 2016-2021, 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 implements the error code functions used by OpenThread core modules.
*/
#include "error.hpp"
#include "common/code_utils.hpp"
namespace ot {
const char *ErrorToString(Error aError)
{
static const char *const kErrorStrings[kNumErrors] = {
"OK", // (0) kErrorNone
"Failed", // (1) kErrorFailed
"Drop", // (2) kErrorDrop
"NoBufs", // (3) kErrorNoBufs
"NoRoute", // (4) kErrorNoRoute
"Busy", // (5) kErrorBusy
"Parse", // (6) kErrorParse
"InvalidArgs", // (7) kErrorInvalidArgs
"Security", // (8) kErrorSecurity
"AddressQuery", // (9) kErrorAddressQuery
"NoAddress", // (10) kErrorNoAddress
"Abort", // (11) kErrorAbort
"NotImplemented", // (12) kErrorNotImplemented
"InvalidState", // (13) kErrorInvalidState
"NoAck", // (14) kErrorNoAck
"ChannelAccessFailure", // (15) kErrorChannelAccessFailure
"Detached", // (16) kErrorDetached
"FcsErr", // (17) kErrorFcs
"NoFrameReceived", // (18) kErrorNoFrameReceived
"UnknownNeighbor", // (19) kErrorUnknownNeighbor
"InvalidSourceAddress", // (20) kErrorInvalidSourceAddress
"AddressFiltered", // (21) kErrorAddressFiltered
"DestinationAddressFiltered", // (22) kErrorDestinationAddressFiltered
"NotFound", // (23) kErrorNotFound
"Already", // (24) kErrorAlready
"ReservedError25", // (25) Error 25 is reserved
"Ipv6AddressCreationFailure", // (26) kErrorIp6AddressCreationFailure
"NotCapable", // (27) kErrorNotCapable
"ResponseTimeout", // (28) kErrorResponseTimeout
"Duplicated", // (29) kErrorDuplicated
"ReassemblyTimeout", // (30) kErrorReassemblyTimeout
"NotTmf", // (31) kErrorNotTmf
"NonLowpanDataFrame", // (32) kErrorNotLowpanDataFrame
"ReservedError33", // (33) Error 33 is reserved
"LinkMarginLow", // (34) kErrorLinkMarginLow
"InvalidCommand", // (35) kErrorInvalidCommand
"Pending", // (36) kErrorPending
};
return aError < OT_ARRAY_LENGTH(kErrorStrings) ? kErrorStrings[aError] : "UnknownErrorType";
}
} // namespace ot
+107
View File
@@ -0,0 +1,107 @@
/*
* Copyright (c) 2021, 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 defines the errors used by OpenThread core.
*/
#ifndef ERROR_HPP_
#define ERROR_HPP_
#include "openthread-core-config.h"
#include <openthread/error.h>
#include <stdint.h>
namespace ot {
/**
* This type represents error codes used by OpenThread core modules.
*
*/
typedef otError Error;
/*
* The `OT_ERROR_*` enumeration values are re-defined using `kError` style format.
* See `openthread/error.h` for more details about each error.
*
*/
constexpr Error kErrorNone = OT_ERROR_NONE;
constexpr Error kErrorFailed = OT_ERROR_FAILED;
constexpr Error kErrorDrop = OT_ERROR_DROP;
constexpr Error kErrorNoBufs = OT_ERROR_NO_BUFS;
constexpr Error kErrorNoRoute = OT_ERROR_NO_ROUTE;
constexpr Error kErrorBusy = OT_ERROR_BUSY;
constexpr Error kErrorParse = OT_ERROR_PARSE;
constexpr Error kErrorInvalidArgs = OT_ERROR_INVALID_ARGS;
constexpr Error kErrorSecurity = OT_ERROR_SECURITY;
constexpr Error kErrorAddressQuery = OT_ERROR_ADDRESS_QUERY;
constexpr Error kErrorNoAddress = OT_ERROR_NO_ADDRESS;
constexpr Error kErrorAbort = OT_ERROR_ABORT;
constexpr Error kErrorNotImplemented = OT_ERROR_NOT_IMPLEMENTED;
constexpr Error kErrorInvalidState = OT_ERROR_INVALID_STATE;
constexpr Error kErrorNoAck = OT_ERROR_NO_ACK;
constexpr Error kErrorChannelAccessFailure = OT_ERROR_CHANNEL_ACCESS_FAILURE;
constexpr Error kErrorDetached = OT_ERROR_DETACHED;
constexpr Error kErrorFcs = OT_ERROR_FCS;
constexpr Error kErrorNoFrameReceived = OT_ERROR_NO_FRAME_RECEIVED;
constexpr Error kErrorUnknownNeighbor = OT_ERROR_UNKNOWN_NEIGHBOR;
constexpr Error kErrorInvalidSourceAddress = OT_ERROR_INVALID_SOURCE_ADDRESS;
constexpr Error kErrorAddressFiltered = OT_ERROR_ADDRESS_FILTERED;
constexpr Error kErrorDestinationAddressFiltered = OT_ERROR_DESTINATION_ADDRESS_FILTERED;
constexpr Error kErrorNotFound = OT_ERROR_NOT_FOUND;
constexpr Error kErrorAlready = OT_ERROR_ALREADY;
constexpr Error kErrorIp6AddressCreationFailure = OT_ERROR_IP6_ADDRESS_CREATION_FAILURE;
constexpr Error kErrorNotCapable = OT_ERROR_NOT_CAPABLE;
constexpr Error kErrorResponseTimeout = OT_ERROR_RESPONSE_TIMEOUT;
constexpr Error kErrorDuplicated = OT_ERROR_DUPLICATED;
constexpr Error kErrorReassemblyTimeout = OT_ERROR_REASSEMBLY_TIMEOUT;
constexpr Error kErrorNotTmf = OT_ERROR_NOT_TMF;
constexpr Error kErrorNotLowpanDataFrame = OT_ERROR_NOT_LOWPAN_DATA_FRAME;
constexpr Error kErrorLinkMarginLow = OT_ERROR_LINK_MARGIN_LOW;
constexpr Error kErrorInvalidCommand = OT_ERROR_INVALID_COMMAND;
constexpr Error kErrorPending = OT_ERROR_PENDING;
constexpr Error kErrorGeneric = OT_ERROR_GENERIC;
constexpr uint8_t kNumErrors = OT_NUM_ERRORS;
/**
* This function converts an `Error` into a string.
*
* @param[in] aError An error.
*
* @returns A string representation of @p aError.
*
*/
const char *ErrorToString(Error aError);
} // namespace ot
#endif // ERROR_HPP_
+3 -3
View File
@@ -214,11 +214,11 @@ void Instance::FactoryReset(void)
otPlatReset(this);
}
otError Instance::ErasePersistentInfo(void)
Error Instance::ErasePersistentInfo(void)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
VerifyOrExit(Get<Mle::MleRouter>().IsDisabled(), error = OT_ERROR_INVALID_STATE);
VerifyOrExit(Get<Mle::MleRouter>().IsDisabled(), error = kErrorInvalidState);
Get<Settings>().Wipe();
exit:
+4 -4
View File
@@ -39,13 +39,13 @@
#include <stdbool.h>
#include <stdint.h>
#include <openthread/error.h>
#include <openthread/heap.h>
#include <openthread/platform/logging.h>
#if OPENTHREAD_CONFIG_HEAP_EXTERNAL_ENABLE
#include <openthread/platform/memory.h>
#endif
#include "common/error.hpp"
#include "common/non_copyable.hpp"
#include "common/random_manager.hpp"
#include "common/tasklet.hpp"
@@ -238,11 +238,11 @@ public:
*
* Erase is successful/allowed only if the device is in `disabled` state/role.
*
* @retval OT_ERROR_NONE All persistent info/state was erased successfully.
* @retval OT_ERROR_INVALID_STATE Device is not in `disabled` state/role.
* @retval kErrorNone All persistent info/state was erased successfully.
* @retval kErrorInvalidState Device is not in `disabled` state/role.
*
*/
otError ErasePersistentInfo(void);
Error ErasePersistentInfo(void);
#if OPENTHREAD_CONFIG_HEAP_EXTERNAL_ENABLE
static void HeapFree(void *aPointer) { otPlatFree(aPointer); }
+22 -21
View File
@@ -37,7 +37,8 @@
#include "openthread-core-config.h"
#include <stdio.h>
#include <openthread/error.h>
#include "common/error.hpp"
namespace ot {
@@ -239,7 +240,7 @@ public:
{
const Type *prev;
return Find(aEntry, prev) == OT_ERROR_NONE;
return Find(aEntry, prev) == kErrorNone;
}
/**
@@ -267,17 +268,17 @@ public:
*
* @param[in] aEntry A reference to an entry to add.
*
* @retval OT_ERROR_NONE The entry was successfully added at the head of the list.
* @retval OT_ERROR_ALREADY The entry is already in the list.
* @retval kErrorNone The entry was successfully added at the head of the list.
* @retval kErrorAlready The entry is already in the list.
*
*/
otError Add(Type &aEntry)
Error Add(Type &aEntry)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
if (Contains(aEntry))
{
error = OT_ERROR_ALREADY;
error = kErrorAlready;
}
else
{
@@ -295,16 +296,16 @@ public:
*
* @param[in] aEntry A reference to an entry to remove.
*
* @retval OT_ERROR_NONE The entry was successfully removed from the list.
* @retval OT_ERROR_NOT_FOUND Could not find the entry in the list.
* @retval kErrorNone The entry was successfully removed from the list.
* @retval kErrorNotFound Could not find the entry in the list.
*
*/
otError Remove(const Type &aEntry)
Error Remove(const Type &aEntry)
{
Type * prev;
otError error = Find(aEntry, prev);
Type *prev;
Error error = Find(aEntry, prev);
if (error == OT_ERROR_NONE)
if (error == kErrorNone)
{
PopAfter(prev);
}
@@ -351,13 +352,13 @@ public:
* @p aPrevEntry is set to nullptr if @p aEntry is the head of the list. Otherwise it is
* updated to point to the previous entry before @p aEntry in the list.
*
* @retval OT_ERROR_NONE The entry was found in the list and @p aPrevEntry was updated successfully.
* @retval OT_ERROR_NOT_FOUND The entry was not found in the list.
* @retval kErrorNone The entry was found in the list and @p aPrevEntry was updated successfully.
* @retval kErrorNotFound The entry was not found in the list.
*
*/
otError Find(const Type &aEntry, const Type *&aPrevEntry) const
Error Find(const Type &aEntry, const Type *&aPrevEntry) const
{
otError error = OT_ERROR_NOT_FOUND;
Error error = kErrorNotFound;
aPrevEntry = nullptr;
@@ -365,7 +366,7 @@ public:
{
if (entry == &aEntry)
{
error = OT_ERROR_NONE;
error = kErrorNone;
break;
}
}
@@ -381,11 +382,11 @@ public:
* @p aPrevEntry is set to nullptr if @p aEntry is the head of the list. Otherwise it is
* updated to point to the previous entry before @p aEntry in the list.
*
* @retval OT_ERROR_NONE The entry was found in the list and @p aPrevEntry was updated successfully.
* @retval OT_ERROR_NOT_FOUND The entry was not found in the list.
* @retval kErrorNone The entry was found in the list and @p aPrevEntry was updated successfully.
* @retval kErrorNotFound The entry was not found in the list.
*
*/
otError Find(const Type &aEntry, Type *&aPrevEntry)
Error Find(const Type &aEntry, Type *&aPrevEntry)
{
return const_cast<const LinkedList *>(this)->Find(aEntry, const_cast<const Type *&>(aPrevEntry));
}
+1 -46
View File
@@ -101,7 +101,7 @@ static void Log(otLogLevel aLogLevel,
#endif // OPENTHREAD_CONFIG_LOG_PREPEND_LEVEL
IgnoreError(logString.Append("%s", aRegionPrefix));
VerifyOrExit(logString.AppendVarArgs(aFormat, aArgs) != OT_ERROR_INVALID_ARGS);
VerifyOrExit(logString.AppendVarArgs(aFormat, aArgs) != ot::kErrorInvalidArgs);
otPlatLog(aLogLevel, aLogRegion, "%s" OPENTHREAD_CONFIG_LOG_SUFFIX, logString.AsCString());
exit:
@@ -318,51 +318,6 @@ void otDump(otLogLevel, otLogRegion, const char *, const void *, const size_t)
}
#endif // OPENTHREAD_CONFIG_LOG_PKT_DUMP
static const char *const sThreadErrorStrings[OT_NUM_ERRORS] = {
"OK", // OT_ERROR_NONE = 0
"Failed", // OT_ERROR_FAILED = 1
"Drop", // OT_ERROR_DROP = 2
"NoBufs", // OT_ERROR_NO_BUFS = 3
"NoRoute", // OT_ERROR_NO_ROUTE = 4
"Busy", // OT_ERROR_BUSY = 5
"Parse", // OT_ERROR_PARSE = 6
"InvalidArgs", // OT_ERROR_INVALID_ARGS = 7
"Security", // OT_ERROR_SECURITY = 8
"AddressQuery", // OT_ERROR_ADDRESS_QUERY = 9
"NoAddress", // OT_ERROR_NO_ADDRESS = 10
"Abort", // OT_ERROR_ABORT = 11
"NotImplemented", // OT_ERROR_NOT_IMPLEMENTED = 12
"InvalidState", // OT_ERROR_INVALID_STATE = 13
"NoAck", // OT_ERROR_NO_ACK = 14
"ChannelAccessFailure", // OT_ERROR_CHANNEL_ACCESS_FAILURE = 15
"Detached", // OT_ERROR_DETACHED = 16
"FcsErr", // OT_ERROR_FCS = 17
"NoFrameReceived", // OT_ERROR_NO_FRAME_RECEIVED = 18
"UnknownNeighbor", // OT_ERROR_UNKNOWN_NEIGHBOR = 19
"InvalidSourceAddress", // OT_ERROR_INVALID_SOURCE_ADDRESS = 20
"AddressFiltered", // OT_ERROR_ADDRESS_FILTERED = 21
"DestinationAddressFiltered", // OT_ERROR_DESTINATION_ADDRESS_FILTERED = 22
"NotFound", // OT_ERROR_NOT_FOUND = 23
"Already", // OT_ERROR_ALREADY = 24
"ReservedError25", // otError 25 is reserved
"Ipv6AddressCreationFailure", // OT_ERROR_IP6_ADDRESS_CREATION_FAILURE = 26
"NotCapable", // OT_ERROR_NOT_CAPABLE = 27
"ResponseTimeout", // OT_ERROR_RESPONSE_TIMEOUT = 28
"Duplicated", // OT_ERROR_DUPLICATED = 29
"ReassemblyTimeout", // OT_ERROR_REASSEMBLY_TIMEOUT = 30
"NotTmf", // OT_ERROR_NOT_TMF = 31
"NonLowpanDataFrame", // OT_ERROR_NOT_LOWPAN_DATA_FRAME = 32
"ReservedError33", // otError 33 is reserved
"LinkMarginLow", // OT_ERROR_LINK_MARGIN_LOW = 34
"InvalidCommand", // OT_ERROR_INVALID_COMMAND = 35
"Pending", // OT_ERROR_PENDING = 36
};
const char *otThreadErrorToString(otError aError)
{
return aError < OT_ARRAY_LENGTH(sThreadErrorStrings) ? sThreadErrorStrings[aError] : "UnknownErrorType";
}
#if OPENTHREAD_CONFIG_LOG_DEFINE_AS_MACRO_ONLY
const char *otLogLevelToPrefixString(otLogLevel aLogLevel)
+1 -1
View File
@@ -2558,7 +2558,7 @@ const char *otLogLevelToPrefixString(otLogLevel aLogLevel);
/**
* @def otLogResultPlat
*
* This function generates a log for the Plat region according to the error result. If @p aError is `OT_ERROR_NONE`, the
* This function generates a log for the Plat region according to the error result. If @p aError is `kErrorNone`, the
* log level is info. Otherwise the log level is warn.
*
* @param[in] aError The error result.
+21 -21
View File
@@ -66,7 +66,7 @@ MessagePool::MessagePool(Instance &aInstance)
Message *MessagePool::New(Message::Type aType, uint16_t aReserveHeader, Message::Priority aPriority)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Message *message;
VerifyOrExit((message = static_cast<Message *>(NewBuffer(aPriority))) != nullptr);
@@ -81,7 +81,7 @@ Message *MessagePool::New(Message::Type aType, uint16_t aReserveHeader, Message:
SuccessOrExit(error = message->SetLength(0));
exit:
if (error != OT_ERROR_NONE)
if (error != kErrorNone)
{
Free(message);
message = nullptr;
@@ -158,7 +158,7 @@ void MessagePool::FreeBuffers(Buffer *aBuffer)
}
}
otError MessagePool::ReclaimBuffers(Message::Priority aPriority)
Error MessagePool::ReclaimBuffers(Message::Priority aPriority)
{
return Get<MeshForwarder>().EvictMessage(aPriority);
}
@@ -201,9 +201,9 @@ Message::Settings::Settings(const otMessageSettings *aSettings)
{
}
otError Message::ResizeMessage(uint16_t aLength)
Error Message::ResizeMessage(uint16_t aLength)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
// add buffers
Buffer * curBuffer = this;
@@ -215,7 +215,7 @@ otError Message::ResizeMessage(uint16_t aLength)
if (curBuffer->GetNextBuffer() == nullptr)
{
curBuffer->SetNextBuffer(GetMessagePool()->NewBuffer(GetPriority()));
VerifyOrExit(curBuffer->GetNextBuffer() != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit(curBuffer->GetNextBuffer() != nullptr, error = kErrorNoBufs);
}
curBuffer = curBuffer->GetNextBuffer();
@@ -262,12 +262,12 @@ exit:
return next;
}
otError Message::SetLength(uint16_t aLength)
Error Message::SetLength(uint16_t aLength)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
uint16_t totalLengthRequest = GetReserved() + aLength;
VerifyOrExit(totalLengthRequest >= GetReserved(), error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(totalLengthRequest >= GetReserved(), error = kErrorInvalidArgs);
SuccessOrExit(error = ResizeMessage(totalLengthRequest));
GetMetadata().mLength = aLength;
@@ -331,13 +331,13 @@ bool Message::IsSubTypeMle(void) const
return rval;
}
otError Message::SetPriority(Priority aPriority)
Error Message::SetPriority(Priority aPriority)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
uint8_t priority = static_cast<uint8_t>(aPriority);
PriorityQueue *priorityQueue = nullptr;
VerifyOrExit(priority < kNumPriorities, error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(priority < kNumPriorities, error = kErrorInvalidArgs);
VerifyOrExit(IsInAQueue(), GetMetadata().mPriority = priority);
VerifyOrExit(GetMetadata().mPriority != priority);
@@ -376,9 +376,9 @@ const char *Message::PriorityToString(Priority aPriority)
return kPriorityStrings[aPriority];
}
otError Message::AppendBytes(const void *aBuf, uint16_t aLength)
Error Message::AppendBytes(const void *aBuf, uint16_t aLength)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
uint16_t oldLength = GetLength();
SuccessOrExit(error = SetLength(GetLength() + aLength));
@@ -388,14 +388,14 @@ exit:
return error;
}
otError Message::PrependBytes(const void *aBuf, uint16_t aLength)
Error Message::PrependBytes(const void *aBuf, uint16_t aLength)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Buffer *newBuffer = nullptr;
while (aLength > GetReserved())
{
VerifyOrExit((newBuffer = GetMessagePool()->NewBuffer(GetPriority())) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((newBuffer = GetMessagePool()->NewBuffer(GetPriority())) != nullptr, error = kErrorNoBufs);
newBuffer->SetNextBuffer(GetNextBuffer());
SetNextBuffer(newBuffer);
@@ -541,9 +541,9 @@ uint16_t Message::ReadBytes(uint16_t aOffset, void *aBuf, uint16_t aLength) cons
return static_cast<uint16_t>(bufPtr - reinterpret_cast<uint8_t *>(aBuf));
}
otError Message::Read(uint16_t aOffset, void *aBuf, uint16_t aLength) const
Error Message::Read(uint16_t aOffset, void *aBuf, uint16_t aLength) const
{
return (ReadBytes(aOffset, aBuf, aLength) == aLength) ? OT_ERROR_NONE : OT_ERROR_PARSE;
return (ReadBytes(aOffset, aBuf, aLength) == aLength) ? kErrorNone : kErrorParse;
}
bool Message::CompareBytes(uint16_t aOffset, const void *aBuf, uint16_t aLength) const
@@ -632,12 +632,12 @@ uint16_t Message::CopyTo(uint16_t aSourceOffset, uint16_t aDestinationOffset, ui
Message *Message::Clone(uint16_t aLength) const
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Message *messageCopy;
uint16_t offset;
VerifyOrExit((messageCopy = GetMessagePool()->New(GetType(), GetReserved(), GetPriority())) != nullptr,
error = OT_ERROR_NO_BUFS);
error = kErrorNoBufs);
SuccessOrExit(error = messageCopy->SetLength(aLength));
CopyTo(0, 0, aLength, *messageCopy);
+49 -49
View File
@@ -100,38 +100,38 @@ class HmacSha256;
} while (false)
/**
* This macro frees a given message buffer if a given `otError` indicates an error.
* This macro frees a given message buffer if a given `Error` indicates an error.
*
* The parameter @p aMessage can be nullptr in which case this macro does nothing.
*
* @param[in] aMessage A pointer to a `Message` to free (can be nullptr).
* @param[in] aError The `otError` to check.
* @param[in] aError The `Error` to check.
*
*/
#define FreeMessageOnError(aMessage, aError) \
do \
{ \
if (((aError) != OT_ERROR_NONE) && ((aMessage) != nullptr)) \
{ \
(aMessage)->Free(); \
} \
#define FreeMessageOnError(aMessage, aError) \
do \
{ \
if (((aError) != kErrorNone) && ((aMessage) != nullptr)) \
{ \
(aMessage)->Free(); \
} \
} while (false)
/**
* This macro frees a given message buffer if a given `otError` indicates an error and sets the `aMessage` to `nullptr`.
* This macro frees a given message buffer if a given `Error` indicates an error and sets the `aMessage` to `nullptr`.
*
* @param[in] aMessage A pointer to a `Message` to free (can be nullptr).
* @param[in] aError The `otError` to check.
* @param[in] aError The `Error` to check.
*
*/
#define FreeAndNullMessageOnError(aMessage, aError) \
do \
{ \
if (((aError) != OT_ERROR_NONE) && ((aMessage) != nullptr)) \
{ \
(aMessage)->Free(); \
(aMessage) = nullptr; \
} \
#define FreeAndNullMessageOnError(aMessage, aError) \
do \
{ \
if (((aError) != kErrorNone) && ((aMessage) != nullptr)) \
{ \
(aMessage)->Free(); \
(aMessage) = nullptr; \
} \
} while (false)
enum
@@ -477,11 +477,11 @@ public:
*
* @param[in] aLength Requested number of bytes in the message.
*
* @retval OT_ERROR_NONE Successfully set the length of the message.
* @retval OT_ERROR_NO_BUFS Failed to grow the size of the message because insufficient buffers were available.
* @retval kErrorNone Successfully set the length of the message.
* @retval kErrorNoBufs Failed to grow the size of the message because insufficient buffers were available.
*
*/
otError SetLength(uint16_t aLength);
Error SetLength(uint16_t aLength);
/**
* This method returns the number of buffers in the message.
@@ -586,11 +586,11 @@ public:
*
* @param[in] aPriority The message priority level.
*
* @retval OT_ERROR_NONE Successfully set the priority for the message.
* @retval OT_ERROR_INVALID_ARGS Priority level is not invalid.
* @retval kErrorNone Successfully set the priority for the message.
* @retval kErrorInvalidArgs Priority level is not invalid.
*
*/
otError SetPriority(Priority aPriority);
Error SetPriority(Priority aPriority);
/**
* This static method convert a `Priority` to a string.
@@ -610,11 +610,11 @@ public:
* @param[in] aBuf A pointer to a data buffer (can be `nullptr` to grow message without writing bytes).
* @param[in] aLength The number of bytes to prepend.
*
* @retval OT_ERROR_NONE Successfully prepended the bytes.
* @retval OT_ERROR_NO_BUFS Not enough reserved bytes in the message.
* @retval kErrorNone Successfully prepended the bytes.
* @retval kErrorNoBufs Not enough reserved bytes in the message.
*
*/
otError PrependBytes(const void *aBuf, uint16_t aLength);
Error PrependBytes(const void *aBuf, uint16_t aLength);
/**
* This method prepends an object to the front of the message.
@@ -625,11 +625,11 @@ public:
*
* @param[in] aObject A reference to the object to prepend to the message.
*
* @retval OT_ERROR_NONE Successfully prepended the object.
* @retval OT_ERROR_NO_BUFS Not enough reserved bytes in the message.
* @retval kErrorNone Successfully prepended the object.
* @retval kErrorNoBufs Not enough reserved bytes in the message.
*
*/
template <typename ObjectType> otError Prepend(const ObjectType &aObject)
template <typename ObjectType> Error Prepend(const ObjectType &aObject)
{
static_assert(!TypeTraits::IsPointer<ObjectType>::kValue, "ObjectType must not be a pointer");
@@ -652,11 +652,11 @@ public:
* @param[in] aBuf A pointer to a data buffer (MUST not be `nullptr`).
* @param[in] aLength The number of bytes to append.
*
* @retval OT_ERROR_NONE Successfully appended the bytes.
* @retval OT_ERROR_NO_BUFS Insufficient available buffers to grow the message.
* @retval kErrorNone Successfully appended the bytes.
* @retval kErrorNoBufs Insufficient available buffers to grow the message.
*
*/
otError AppendBytes(const void *aBuf, uint16_t aLength);
Error AppendBytes(const void *aBuf, uint16_t aLength);
/**
* This method appends an object to the end of the message.
@@ -667,11 +667,11 @@ public:
*
* @param[in] aObject A reference to the object to append to the message.
*
* @retval OT_ERROR_NONE Successfully appended the object.
* @retval OT_ERROR_NO_BUFS Insufficient available buffers to grow the message.
* @retval kErrorNone Successfully appended the object.
* @retval kErrorNoBufs Insufficient available buffers to grow the message.
*
*/
template <typename ObjectType> otError Append(const ObjectType &aObject)
template <typename ObjectType> Error Append(const ObjectType &aObject)
{
static_assert(!TypeTraits::IsPointer<ObjectType>::kValue, "ObjectType must not be a pointer");
@@ -694,23 +694,23 @@ public:
* This method reads a given number of bytes from the message.
*
* If there are fewer bytes available in the message than the requested read length, the available bytes will be
* read and copied into @p aBuf. In this case `OT_ERROR_PARSE` will be returned.
* read and copied into @p aBuf. In this case `kErrorParse` will be returned.
*
* @param[in] aOffset Byte offset within the message to begin reading.
* @param[out] aBuf A pointer to a data buffer to copy the read bytes into.
* @param[in] aLength Number of bytes to read.
*
* @retval OT_ERROR_NONE @p aLength bytes were successfully read from message.
* @retval OT_ERROR_PARSE Not enough bytes remaining in message to read the entire object.
* @retval kErrorNone @p aLength bytes were successfully read from message.
* @retval kErrorParse Not enough bytes remaining in message to read the entire object.
*
*/
otError Read(uint16_t aOffset, void *aBuf, uint16_t aLength) const;
Error Read(uint16_t aOffset, void *aBuf, uint16_t aLength) const;
/**
* This method reads an object from the message.
*
* If there are fewer bytes available in the message than the requested object size, the available bytes will be
* read and copied into @p aObject (@p aObject will be read partially). In this case `OT_ERROR_PARSE` will
* read and copied into @p aObject (@p aObject will be read partially). In this case `kErrorParse` will
* be returned.
*
* @tparam ObjectType The object type to read from the message.
@@ -718,11 +718,11 @@ public:
* @param[in] aOffset Byte offset within the message to begin reading.
* @param[out] aObject A reference to the object to read into.
*
* @retval OT_ERROR_NONE Object @p aObject was successfully read from message.
* @retval OT_ERROR_PARSE Not enough bytes remaining in message to read the entire object.
* @retval kErrorNone Object @p aObject was successfully read from message.
* @retval kErrorParse Not enough bytes remaining in message to read the entire object.
*
*/
template <typename ObjectType> otError Read(uint16_t aOffset, ObjectType &aObject) const
template <typename ObjectType> Error Read(uint16_t aOffset, ObjectType &aObject) const
{
static_assert(!TypeTraits::IsPointer<ObjectType>::kValue, "ObjectType must not be a pointer");
@@ -1333,11 +1333,11 @@ private:
*
* @param[in] aLength The number of bytes that the message buffer needs to handle.
*
* @retval OT_ERROR_NONE Successfully resized the message.
* @retval OT_ERROR_NO_BUFS Could not grow the message due to insufficient available message buffers.
* @retval kErrorNone Successfully resized the message.
* @retval kErrorNoBufs Could not grow the message due to insufficient available message buffers.
*
*/
otError ResizeMessage(uint16_t aLength);
Error ResizeMessage(uint16_t aLength);
private:
struct Chunk
@@ -1627,7 +1627,7 @@ public:
private:
Buffer *NewBuffer(Message::Priority aPriority);
void FreeBuffers(Buffer *aBuffer);
otError ReclaimBuffers(Message::Priority aPriority);
Error ReclaimBuffers(Message::Priority aPriority);
#if !OPENTHREAD_CONFIG_PLATFORM_MESSAGE_MANAGEMENT && !OPENTHREAD_CONFIG_MESSAGE_USE_HEAP_ENABLE
uint16_t mNumFreeBuffers;
+4 -4
View File
@@ -52,9 +52,9 @@ Notifier::Notifier(Instance &aInstance)
}
}
otError Notifier::RegisterCallback(otStateChangedCallback aCallback, void *aContext)
Error Notifier::RegisterCallback(otStateChangedCallback aCallback, void *aContext)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
ExternalCallback *unusedCallback = nullptr;
VerifyOrExit(aCallback != nullptr);
@@ -71,10 +71,10 @@ otError Notifier::RegisterCallback(otStateChangedCallback aCallback, void *aCont
continue;
}
VerifyOrExit((callback.mHandler != aCallback) || (callback.mContext != aContext), error = OT_ERROR_ALREADY);
VerifyOrExit((callback.mHandler != aCallback) || (callback.mContext != aContext), error = kErrorAlready);
}
VerifyOrExit(unusedCallback != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit(unusedCallback != nullptr, error = kErrorNoBufs);
unusedCallback->mHandler = aCallback;
unusedCallback->mContext = aContext;
+11 -10
View File
@@ -42,6 +42,7 @@
#include <openthread/instance.h>
#include <openthread/platform/toolchain.h>
#include "common/error.hpp"
#include "common/locator.hpp"
#include "common/non_copyable.hpp"
#include "common/tasklet.hpp"
@@ -210,12 +211,12 @@ public:
* @param[in] aCallback A pointer to the handler function that is called to notify of the changes.
* @param[in] aContext A pointer to arbitrary context information.
*
* @retval OT_ERROR_NONE Successfully registered the callback.
* @retval OT_ERROR_ALREADY The callback was already registered.
* @retval OT_ERROR_NO_BUFS Could not add the callback due to resource constraints.
* @retval kErrorNone Successfully registered the callback.
* @retval kErrorAlready The callback was already registered.
* @retval kErrorNoBufs Could not add the callback due to resource constraints.
*
*/
otError RegisterCallback(otStateChangedCallback aCallback, void *aContext);
Error RegisterCallback(otStateChangedCallback aCallback, void *aContext);
/**
* This method removes/unregisters a previously registered `otStateChangedCallback` handler.
@@ -264,7 +265,7 @@ public:
/**
* This template method updates a variable of a type `Type` with a new value and signals the given event.
*
* If the variable is already set to the same value, this method returns `OT_ERROR_ALREADY` and the event is
* If the variable is already set to the same value, this method returns `kErrorAlready` and the event is
* signaled using `SignalIfFirst()` (i.e., signal is scheduled only if event has not been signaled before).
*
* The template `Type` should support comparison operator `==` and assignment operator `=`.
@@ -273,18 +274,18 @@ public:
* @param[in] aNewValue The new value.
* @param[in] aEvent The event to signal.
*
* @retval OT_ERROR_NONE The variable was update successfully and @p aEvent was signaled.
* @retval OT_ERROR_ALREADY The variable was already set to the same value.
* @retval kErrorNone The variable was update successfully and @p aEvent was signaled.
* @retval kErrorAlready The variable was already set to the same value.
*
*/
template <typename Type> otError Update(Type &aVariable, const Type &aNewValue, Event aEvent)
template <typename Type> Error Update(Type &aVariable, const Type &aNewValue, Event aEvent)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
if (aVariable == aNewValue)
{
SignalIfFirst(aEvent);
error = OT_ERROR_ALREADY;
error = kErrorAlready;
}
else
{
+3 -4
View File
@@ -38,9 +38,8 @@
#include <stdint.h>
#include <openthread/error.h>
#include "common/debug.hpp"
#include "common/error.hpp"
#include "common/random_manager.hpp"
namespace ot {
@@ -170,10 +169,10 @@ namespace Crypto {
* @param[out] aBuffer A pointer to a buffer to fill with the random bytes.
* @param[in] aSize Size of buffer (number of bytes to fill).
*
* @retval OT_ERROR_NONE Successfully filled buffer with random values.
* @retval kErrorNone Successfully filled buffer with random values.
*
*/
inline otError FillBuffer(uint8_t *aBuffer, uint16_t aSize)
inline Error FillBuffer(uint8_t *aBuffer, uint16_t aSize)
{
return RandomManager::CryptoFillBuffer(aBuffer, aSize);
}
+4 -4
View File
@@ -58,7 +58,7 @@ RandomManager::CryptoCtrDrbg RandomManager::sCtrDrbg;
RandomManager::RandomManager(void)
{
uint32_t seed;
otError error;
Error error;
OT_UNUSED_VARIABLE(error);
@@ -71,10 +71,10 @@ RandomManager::RandomManager(void)
sCtrDrbg.Init();
error = Random::Crypto::FillBuffer(reinterpret_cast<uint8_t *>(&seed), sizeof(seed));
OT_ASSERT(error == OT_ERROR_NONE);
OT_ASSERT(error == kErrorNone);
#else
error = otPlatEntropyGet(reinterpret_cast<uint8_t *>(&seed), sizeof(seed));
OT_ASSERT(error == OT_ERROR_NONE);
OT_ASSERT(error == kErrorNone);
#endif
sPrng.Init(seed);
@@ -211,7 +211,7 @@ void RandomManager::CryptoCtrDrbg::Deinit(void)
mbedtls_ctr_drbg_free(&mCtrDrbg);
}
otError RandomManager::CryptoCtrDrbg::FillBuffer(uint8_t *aBuffer, uint16_t aSize)
Error RandomManager::CryptoCtrDrbg::FillBuffer(uint8_t *aBuffer, uint16_t aSize)
{
return ot::Crypto::MbedTls::MapError(
mbedtls_ctr_drbg_random(&mCtrDrbg, static_cast<unsigned char *>(aBuffer), static_cast<size_t>(aSize)));
+6 -6
View File
@@ -37,13 +37,13 @@
#include "openthread-core-config.h"
#include <stdint.h>
#include <openthread/error.h>
#if !OPENTHREAD_RADIO
#include <mbedtls/ctr_drbg.h>
#include <mbedtls/entropy.h>
#endif
#include "common/error.hpp"
#include "common/non_copyable.hpp"
#if (!defined(MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES) && \
@@ -94,10 +94,10 @@ public:
* @param[out] aBuffer A pointer to a buffer to fill with the random bytes.
* @param[in] aSize Size of buffer (number of bytes to fill).
*
* @retval OT_ERROR_NONE Successfully filled buffer with random values.
* @retval kErrorNone Successfully filled buffer with random values.
*
*/
static otError CryptoFillBuffer(uint8_t *aBuffer, uint16_t aSize) { return sCtrDrbg.FillBuffer(aBuffer, aSize); }
static Error CryptoFillBuffer(uint8_t *aBuffer, uint16_t aSize) { return sCtrDrbg.FillBuffer(aBuffer, aSize); }
/**
* This static method returns the initialized mbedtls_ctr_drbg_context.
@@ -139,9 +139,9 @@ private:
class CryptoCtrDrbg
{
public:
void Init(void);
void Deinit(void);
otError FillBuffer(uint8_t *aBuffer, uint16_t aSize);
void Init(void);
void Deinit(void);
Error FillBuffer(uint8_t *aBuffer, uint16_t aSize);
mbedtls_ctr_drbg_context *GetContext(void) { return &mCtrDrbg; }
+69 -69
View File
@@ -95,11 +95,11 @@ void SettingsBase::LogPrefix(const char *aAction, const char *aPrefixName, const
#if (OPENTHREAD_CONFIG_LOG_LEVEL >= OT_LOG_LEVEL_WARN)
void SettingsBase::LogFailure(otError error, const char *aText, bool aIsDelete) const
void SettingsBase::LogFailure(Error error, const char *aText, bool aIsDelete) const
{
if ((error != OT_ERROR_NONE) && (!aIsDelete || (error != OT_ERROR_NOT_FOUND)))
if ((error != kErrorNone) && (!aIsDelete || (error != kErrorNotFound)))
{
otLogWarnCore("Non-volatile: Error %s %s", otThreadErrorToString(error), aText);
otLogWarnCore("Non-volatile: Error %s %s", ErrorToString(error), aText);
}
}
@@ -130,22 +130,22 @@ void SettingsDriver::SetCriticalKeys(const uint16_t *aKeys, uint16_t aKeysLength
otPlatSettingsSetCriticalKeys(&GetInstance(), aKeys, aKeysLength);
}
otError SettingsDriver::Add(uint16_t aKey, const uint8_t *aValue, uint16_t aValueLength)
Error SettingsDriver::Add(uint16_t aKey, const uint8_t *aValue, uint16_t aValueLength)
{
return otPlatSettingsAdd(&GetInstance(), aKey, aValue, aValueLength);
}
otError SettingsDriver::Delete(uint16_t aKey, int aIndex)
Error SettingsDriver::Delete(uint16_t aKey, int aIndex)
{
return otPlatSettingsDelete(&GetInstance(), aKey, aIndex);
}
otError SettingsDriver::Get(uint16_t aKey, int aIndex, uint8_t *aValue, uint16_t *aValueLength) const
Error SettingsDriver::Get(uint16_t aKey, int aIndex, uint8_t *aValue, uint16_t *aValueLength) const
{
return otPlatSettingsGet(&GetInstance(), aKey, aIndex, aValue, aValueLength);
}
otError SettingsDriver::Set(uint16_t aKey, const uint8_t *aValue, uint16_t aValueLength)
Error SettingsDriver::Set(uint16_t aKey, const uint8_t *aValue, uint16_t aValueLength)
{
return otPlatSettingsSet(&GetInstance(), aKey, aValue, aValueLength);
}
@@ -178,22 +178,22 @@ void SettingsDriver::SetCriticalKeys(const uint16_t *aKeys, uint16_t aKeysLength
OT_UNUSED_VARIABLE(aKeysLength);
}
otError SettingsDriver::Add(uint16_t aKey, const uint8_t *aValue, uint16_t aValueLength)
Error SettingsDriver::Add(uint16_t aKey, const uint8_t *aValue, uint16_t aValueLength)
{
return mFlash.Add(aKey, aValue, aValueLength);
}
otError SettingsDriver::Delete(uint16_t aKey, int aIndex)
Error SettingsDriver::Delete(uint16_t aKey, int aIndex)
{
return mFlash.Delete(aKey, aIndex);
}
otError SettingsDriver::Get(uint16_t aKey, int aIndex, uint8_t *aValue, uint16_t *aValueLength) const
Error SettingsDriver::Get(uint16_t aKey, int aIndex, uint8_t *aValue, uint16_t *aValueLength) const
{
return mFlash.Get(aKey, aIndex, aValue, aValueLength);
}
otError SettingsDriver::Set(uint16_t aKey, const uint8_t *aValue, uint16_t aValueLength)
Error SettingsDriver::Set(uint16_t aKey, const uint8_t *aValue, uint16_t aValueLength)
{
return mFlash.Set(aKey, aValue, aValueLength);
}
@@ -222,21 +222,21 @@ void Settings::Wipe(void)
otLogInfoCore("Non-volatile: Wiped all info");
}
otError Settings::SaveOperationalDataset(bool aIsActive, const MeshCoP::Dataset &aDataset)
Error Settings::SaveOperationalDataset(bool aIsActive, const MeshCoP::Dataset &aDataset)
{
otError error = Save(aIsActive ? kKeyActiveDataset : kKeyPendingDataset, aDataset.GetBytes(), aDataset.GetSize());
Error error = Save(aIsActive ? kKeyActiveDataset : kKeyPendingDataset, aDataset.GetBytes(), aDataset.GetSize());
LogFailure(error, "saving OperationalDataset", false);
return error;
}
otError Settings::ReadOperationalDataset(bool aIsActive, MeshCoP::Dataset &aDataset) const
Error Settings::ReadOperationalDataset(bool aIsActive, MeshCoP::Dataset &aDataset) const
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
uint16_t length = MeshCoP::Dataset::kMaxSize;
SuccessOrExit(error = Read(aIsActive ? kKeyActiveDataset : kKeyPendingDataset, aDataset.GetBytes(), length));
VerifyOrExit(length <= MeshCoP::Dataset::kMaxSize, error = OT_ERROR_NOT_FOUND);
VerifyOrExit(length <= MeshCoP::Dataset::kMaxSize, error = kErrorNotFound);
aDataset.SetSize(length);
@@ -244,18 +244,18 @@ exit:
return error;
}
otError Settings::DeleteOperationalDataset(bool aIsActive)
Error Settings::DeleteOperationalDataset(bool aIsActive)
{
otError error = Delete(aIsActive ? kKeyActiveDataset : kKeyPendingDataset);
Error error = Delete(aIsActive ? kKeyActiveDataset : kKeyPendingDataset);
LogFailure(error, "deleting OperationalDataset", true);
return error;
}
otError Settings::ReadNetworkInfo(NetworkInfo &aNetworkInfo) const
Error Settings::ReadNetworkInfo(NetworkInfo &aNetworkInfo) const
{
otError error;
Error error;
uint16_t length = sizeof(NetworkInfo);
aNetworkInfo.Init();
@@ -266,13 +266,13 @@ exit:
return error;
}
otError Settings::SaveNetworkInfo(const NetworkInfo &aNetworkInfo)
Error Settings::SaveNetworkInfo(const NetworkInfo &aNetworkInfo)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
NetworkInfo prevNetworkInfo;
uint16_t length = sizeof(prevNetworkInfo);
if ((Read(kKeyNetworkInfo, &prevNetworkInfo, length) == OT_ERROR_NONE) && (length == sizeof(NetworkInfo)) &&
if ((Read(kKeyNetworkInfo, &prevNetworkInfo, length) == kErrorNone) && (length == sizeof(NetworkInfo)) &&
(prevNetworkInfo == aNetworkInfo))
{
LogNetworkInfo("Re-saved", aNetworkInfo);
@@ -287,9 +287,9 @@ exit:
return error;
}
otError Settings::DeleteNetworkInfo(void)
Error Settings::DeleteNetworkInfo(void)
{
otError error;
Error error;
SuccessOrExit(error = Delete(kKeyNetworkInfo));
otLogInfoCore("Non-volatile: Deleted NetworkInfo");
@@ -299,9 +299,9 @@ exit:
return error;
}
otError Settings::ReadParentInfo(ParentInfo &aParentInfo) const
Error Settings::ReadParentInfo(ParentInfo &aParentInfo) const
{
otError error;
Error error;
uint16_t length = sizeof(ParentInfo);
aParentInfo.Init();
@@ -312,13 +312,13 @@ exit:
return error;
}
otError Settings::SaveParentInfo(const ParentInfo &aParentInfo)
Error Settings::SaveParentInfo(const ParentInfo &aParentInfo)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
ParentInfo prevParentInfo;
uint16_t length = sizeof(ParentInfo);
if ((Read(kKeyParentInfo, &prevParentInfo, length) == OT_ERROR_NONE) && (length == sizeof(ParentInfo)) &&
if ((Read(kKeyParentInfo, &prevParentInfo, length) == kErrorNone) && (length == sizeof(ParentInfo)) &&
(prevParentInfo == aParentInfo))
{
LogParentInfo("Re-saved", aParentInfo);
@@ -333,9 +333,9 @@ exit:
return error;
}
otError Settings::DeleteParentInfo(void)
Error Settings::DeleteParentInfo(void)
{
otError error;
Error error;
SuccessOrExit(error = Delete(kKeyParentInfo));
otLogInfoCore("Non-volatile: Deleted ParentInfo");
@@ -345,9 +345,9 @@ exit:
return error;
}
otError Settings::AddChildInfo(const ChildInfo &aChildInfo)
Error Settings::AddChildInfo(const ChildInfo &aChildInfo)
{
otError error;
Error error;
SuccessOrExit(error = Add(kKeyChildInfo, &aChildInfo, sizeof(aChildInfo)));
LogChildInfo("Added", aChildInfo);
@@ -357,9 +357,9 @@ exit:
return error;
}
otError Settings::DeleteAllChildInfo(void)
Error Settings::DeleteAllChildInfo(void)
{
otError error;
Error error;
SuccessOrExit(error = Delete(kKeyChildInfo));
otLogInfoCore("Non-volatile: Deleted all ChildInfo");
@@ -386,11 +386,11 @@ void Settings::ChildInfoIterator::Advance(void)
}
}
otError Settings::ChildInfoIterator::Delete(void)
Error Settings::ChildInfoIterator::Delete(void)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
VerifyOrExit(!mIsDone, error = OT_ERROR_INVALID_STATE);
VerifyOrExit(!mIsDone, error = kErrorInvalidState);
SuccessOrExit(error = Get<SettingsDriver>().Delete(kKeyChildInfo, mIndex));
LogChildInfo("Removed", mChildInfo);
@@ -402,7 +402,7 @@ exit:
void Settings::ChildInfoIterator::Read(void)
{
uint16_t length = sizeof(ChildInfo);
otError error;
Error error;
mChildInfo.Init();
SuccessOrExit(
@@ -410,13 +410,13 @@ void Settings::ChildInfoIterator::Read(void)
LogChildInfo("Read", mChildInfo);
exit:
mIsDone = (error != OT_ERROR_NONE);
mIsDone = (error != kErrorNone);
}
#if OPENTHREAD_CONFIG_DUA_ENABLE
otError Settings::ReadDadInfo(DadInfo &aDadInfo) const
Error Settings::ReadDadInfo(DadInfo &aDadInfo) const
{
otError error;
Error error;
uint16_t length = sizeof(DadInfo);
aDadInfo.Init();
@@ -427,13 +427,13 @@ exit:
return error;
}
otError Settings::SaveDadInfo(const DadInfo &aDadInfo)
Error Settings::SaveDadInfo(const DadInfo &aDadInfo)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
DadInfo prevDadInfo;
uint16_t length = sizeof(DadInfo);
if ((Read(kKeyDadInfo, &prevDadInfo, length) == OT_ERROR_NONE) && (length == sizeof(DadInfo)) &&
if ((Read(kKeyDadInfo, &prevDadInfo, length) == kErrorNone) && (length == sizeof(DadInfo)) &&
(prevDadInfo == aDadInfo))
{
LogDadInfo("Re-saved", aDadInfo);
@@ -448,9 +448,9 @@ exit:
return error;
}
otError Settings::DeleteDadInfo(void)
Error Settings::DeleteDadInfo(void)
{
otError error;
Error error;
SuccessOrExit(error = Delete(kKeyDadInfo));
otLogInfoCore("Non-volatile: Deleted DadInfo");
@@ -462,13 +462,13 @@ exit:
#endif // OPENTHREAD_CONFIG_DUA_ENABLE
#if OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE
otError Settings::SaveOmrPrefix(const Ip6::Prefix &aOmrPrefix)
Error Settings::SaveOmrPrefix(const Ip6::Prefix &aOmrPrefix)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Ip6::Prefix prevOmrPrefix;
uint16_t length = sizeof(prevOmrPrefix);
if ((Read(kKeyOmrPrefix, &prevOmrPrefix, length) == OT_ERROR_NONE) && (length == sizeof(prevOmrPrefix)) &&
if ((Read(kKeyOmrPrefix, &prevOmrPrefix, length) == kErrorNone) && (length == sizeof(prevOmrPrefix)) &&
(prevOmrPrefix == aOmrPrefix))
{
LogPrefix("Re-saved", "OMR prefix", aOmrPrefix);
@@ -483,9 +483,9 @@ exit:
return error;
}
otError Settings::ReadOmrPrefix(Ip6::Prefix &aOmrPrefix) const
Error Settings::ReadOmrPrefix(Ip6::Prefix &aOmrPrefix) const
{
otError error;
Error error;
uint16_t length = sizeof(aOmrPrefix);
aOmrPrefix.Clear();
@@ -496,13 +496,13 @@ exit:
return error;
}
otError Settings::SaveOnLinkPrefix(const Ip6::Prefix &aOnLinkPrefix)
Error Settings::SaveOnLinkPrefix(const Ip6::Prefix &aOnLinkPrefix)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Ip6::Prefix prevOnLinkPrefix;
uint16_t length = sizeof(prevOnLinkPrefix);
if ((Read(kKeyOnLinkPrefix, &prevOnLinkPrefix, length) == OT_ERROR_NONE) && (length == sizeof(prevOnLinkPrefix)) &&
if ((Read(kKeyOnLinkPrefix, &prevOnLinkPrefix, length) == kErrorNone) && (length == sizeof(prevOnLinkPrefix)) &&
(prevOnLinkPrefix == aOnLinkPrefix))
{
LogPrefix("Re-saved", "on-link prefix", aOnLinkPrefix);
@@ -517,9 +517,9 @@ exit:
return error;
}
otError Settings::ReadOnLinkPrefix(Ip6::Prefix &aOnLinkPrefix) const
Error Settings::ReadOnLinkPrefix(Ip6::Prefix &aOnLinkPrefix) const
{
otError error;
Error error;
uint16_t length = sizeof(aOnLinkPrefix);
aOnLinkPrefix.Clear();
@@ -533,9 +533,9 @@ exit:
#if OPENTHREAD_CONFIG_SRP_CLIENT_ENABLE
otError Settings::SaveSrpKey(const Crypto::Ecdsa::P256::KeyPair &aKeyPair)
Error Settings::SaveSrpKey(const Crypto::Ecdsa::P256::KeyPair &aKeyPair)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
SuccessOrExit(error = Save(kKeySrpEcdsaKey, aKeyPair.GetDerBytes(), aKeyPair.GetDerLength()));
otLogInfoCore("Non-volatile: Saved SRP key");
@@ -545,13 +545,13 @@ exit:
return error;
}
otError Settings::ReadSrpKey(Crypto::Ecdsa::P256::KeyPair &aKeyPair) const
Error Settings::ReadSrpKey(Crypto::Ecdsa::P256::KeyPair &aKeyPair) const
{
otError error;
Error error;
uint16_t length = Crypto::Ecdsa::P256::KeyPair::kMaxDerSize;
SuccessOrExit(error = Read(kKeySrpEcdsaKey, aKeyPair.GetDerBytes(), length));
VerifyOrExit(length <= Crypto::Ecdsa::P256::KeyPair::kMaxDerSize, error = OT_ERROR_NOT_FOUND);
VerifyOrExit(length <= Crypto::Ecdsa::P256::KeyPair::kMaxDerSize, error = kErrorNotFound);
aKeyPair.SetDerLength(static_cast<uint8_t>(length));
otLogInfoCore("Non-volatile: Read SRP key");
@@ -559,9 +559,9 @@ exit:
return error;
}
otError Settings::DeleteSrpKey(void)
Error Settings::DeleteSrpKey(void)
{
otError error;
Error error;
SuccessOrExit(error = Delete(kKeySrpEcdsaKey));
otLogInfoCore("Non-volatile: Deleted SRP key");
@@ -573,22 +573,22 @@ exit:
#endif // OPENTHREAD_CONFIG_SRP_CLIENT_ENABLE
otError Settings::Read(Key aKey, void *aBuffer, uint16_t &aSize) const
Error Settings::Read(Key aKey, void *aBuffer, uint16_t &aSize) const
{
return Get<SettingsDriver>().Get(aKey, 0, reinterpret_cast<uint8_t *>(aBuffer), &aSize);
}
otError Settings::Save(Key aKey, const void *aValue, uint16_t aSize)
Error Settings::Save(Key aKey, const void *aValue, uint16_t aSize)
{
return Get<SettingsDriver>().Set(aKey, reinterpret_cast<const uint8_t *>(aValue), aSize);
}
otError Settings::Add(Key aKey, const void *aValue, uint16_t aSize)
Error Settings::Add(Key aKey, const void *aValue, uint16_t aSize)
{
return Get<SettingsDriver>().Add(aKey, reinterpret_cast<const uint8_t *>(aValue), aSize);
}
otError Settings::Delete(Key aKey)
Error Settings::Delete(Key aKey)
{
return Get<SettingsDriver>().Delete(aKey, -1);
}
+102 -102
View File
@@ -96,11 +96,11 @@ public:
* MUST NOT be nullptr if @p aValueLength is non-zero.
* @param[in] aValueLength The length of the data pointed to by @p aValue. May be zero.
*
* @retval OT_ERROR_NONE The value was added.
* @retval OT_ERROR_NO_BUFS Not enough space to store the value.
* @retval kErrorNone The value was added.
* @retval kErrorNoBufs Not enough space to store the value.
*
*/
otError Add(uint16_t aKey, const uint8_t *aValue, uint16_t aValueLength);
Error Add(uint16_t aKey, const uint8_t *aValue, uint16_t aValueLength);
/**
* This method removes a value from @p aKey.
@@ -109,11 +109,11 @@ public:
* @param[in] aIndex The index of the value to be removed.
* If set to -1, all values for @p aKey will be removed.
*
* @retval OT_ERROR_NONE The given key and index was found and removed successfully.
* @retval OT_ERROR_NOT_FOUND The given key or index was not found.
* @retval kErrorNone The given key and index was found and removed successfully.
* @retval kErrorNotFound The given key or index was not found.
*
*/
otError Delete(uint16_t aKey, int aIndex);
Error Delete(uint16_t aKey, int aIndex);
/**
* This method fetches the value identified by @p aKey.
@@ -128,11 +128,11 @@ public:
* At return, the actual length of the setting is written.
* May be nullptr if performing a presence check.
*
* @retval OT_ERROR_NONE The value was fetched successfully.
* @retval OT_ERROR_NOT_FOUND The key was not found.
* @retval kErrorNone The value was fetched successfully.
* @retval kErrorNotFound The key was not found.
*
*/
otError Get(uint16_t aKey, int aIndex, uint8_t *aValue, uint16_t *aValueLength) const;
Error Get(uint16_t aKey, int aIndex, uint8_t *aValue, uint16_t *aValueLength) const;
/**
* This method sets or replaces the value identified by @p aKey.
@@ -145,11 +145,11 @@ public:
* MUST NOT be nullptr if @p aValueLength is non-zero.
* @param[in] aValueLength The length of the data pointed to by @p aValue. May be zero.
*
* @retval OT_ERROR_NONE The value was changed.
* @retval OT_ERROR_NO_BUFS Not enough space to store the value.
* @retval kErrorNone The value was changed.
* @retval kErrorNoBufs Not enough space to store the value.
*
*/
otError Set(uint16_t aKey, const uint8_t *aValue, uint16_t aValueLength);
Error Set(uint16_t aKey, const uint8_t *aValue, uint16_t aValueLength);
/**
* This method remves all values.
@@ -637,9 +637,9 @@ protected:
#endif // (OPENTHREAD_CONFIG_LOG_LEVEL >= OT_LOG_LEVEL_INFO) && (OPENTHREAD_CONFIG_LOG_UTIL != 0)
#if (OPENTHREAD_CONFIG_LOG_LEVEL >= OT_LOG_LEVEL_WARN) && (OPENTHREAD_CONFIG_LOG_UTIL != 0)
void LogFailure(otError aError, const char *aAction, bool aIsDelete) const;
void LogFailure(Error aError, const char *aAction, bool aIsDelete) const;
#else
void LogFailure(otError, const char *, bool) const {}
void LogFailure(Error, const char *, bool) const {}
#endif
};
@@ -691,11 +691,11 @@ public:
* @param[in] aIsActive Indicates whether Dataset is active or pending.
* @param[in] aDataset A reference to a `Dataset` object to be saved.
*
* @retval OT_ERROR_NONE Successfully saved the Dataset.
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
* @retval kErrorNone Successfully saved the Dataset.
* @retval kErrorNotImplemented The platform does not implement settings functionality.
*
*/
otError SaveOperationalDataset(bool aIsActive, const MeshCoP::Dataset &aDataset);
Error SaveOperationalDataset(bool aIsActive, const MeshCoP::Dataset &aDataset);
/**
* This method reads the Operational Dataset (active or pending).
@@ -703,87 +703,87 @@ public:
* @param[in] aIsActive Indicates whether Dataset is active or pending.
* @param[out] aDataset A reference to a `Dataset` object to output the read content.
*
* @retval OT_ERROR_NONE Successfully read the Dataset.
* @retval OT_ERROR_NOT_FOUND No corresponding value in the setting store.
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
* @retval kErrorNone Successfully read the Dataset.
* @retval kErrorNotFound No corresponding value in the setting store.
* @retval kErrorNotImplemented The platform does not implement settings functionality.
*
*/
otError ReadOperationalDataset(bool aIsActive, MeshCoP::Dataset &aDataset) const;
Error ReadOperationalDataset(bool aIsActive, MeshCoP::Dataset &aDataset) const;
/**
* This method deletes the Operational Dataset (active/pending) from settings.
*
* @param[in] aIsActive Indicates whether Dataset is active or pending.
*
* @retval OT_ERROR_NONE Successfully deleted the Dataset.
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
* @retval kErrorNone Successfully deleted the Dataset.
* @retval kErrorNotImplemented The platform does not implement settings functionality.
*
*/
otError DeleteOperationalDataset(bool aIsActive);
Error DeleteOperationalDataset(bool aIsActive);
/**
* This method saves Network Info.
*
* @param[in] aNetworkInfo A reference to a `NetworkInfo` structure to be saved.
*
* @retval OT_ERROR_NONE Successfully saved Network Info in settings.
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
* @retval kErrorNone Successfully saved Network Info in settings.
* @retval kErrorNotImplemented The platform does not implement settings functionality.
*
*/
otError SaveNetworkInfo(const NetworkInfo &aNetworkInfo);
Error SaveNetworkInfo(const NetworkInfo &aNetworkInfo);
/**
* This method reads Network Info.
*
* @param[out] aNetworkInfo A reference to a `NetworkInfo` structure to output the read content.
*
* @retval OT_ERROR_NONE Successfully read the Network Info.
* @retval OT_ERROR_NOT_FOUND No corresponding value in the setting store.
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
* @retval kErrorNone Successfully read the Network Info.
* @retval kErrorNotFound No corresponding value in the setting store.
* @retval kErrorNotImplemented The platform does not implement settings functionality.
*
*/
otError ReadNetworkInfo(NetworkInfo &aNetworkInfo) const;
Error ReadNetworkInfo(NetworkInfo &aNetworkInfo) const;
/**
* This method deletes Network Info from settings.
*
* @retval OT_ERROR_NONE Successfully deleted the value.
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
* @retval kErrorNone Successfully deleted the value.
* @retval kErrorNotImplemented The platform does not implement settings functionality.
*
*/
otError DeleteNetworkInfo(void);
Error DeleteNetworkInfo(void);
/**
* This method saves Parent Info.
*
* @param[in] aParentInfo A reference to a `ParentInfo` structure to be saved.
*
* @retval OT_ERROR_NONE Successfully saved Parent Info in settings.
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
* @retval kErrorNone Successfully saved Parent Info in settings.
* @retval kErrorNotImplemented The platform does not implement settings functionality.
*
*/
otError SaveParentInfo(const ParentInfo &aParentInfo);
Error SaveParentInfo(const ParentInfo &aParentInfo);
/**
* This method reads Parent Info.
*
* @param[out] aParentInfo A reference to a `ParentInfo` structure to output the read content.
*
* @retval OT_ERROR_NONE Successfully read the Parent Info.
* @retval OT_ERROR_NOT_FOUND No corresponding value in the setting store.
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
* @retval kErrorNone Successfully read the Parent Info.
* @retval kErrorNotFound No corresponding value in the setting store.
* @retval kErrorNotImplemented The platform does not implement settings functionality.
*
*/
otError ReadParentInfo(ParentInfo &aParentInfo) const;
Error ReadParentInfo(ParentInfo &aParentInfo) const;
/**
* This method deletes Parent Info from settings.
*
* @retval OT_ERROR_NONE Successfully deleted the value.
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
* @retval kErrorNone Successfully deleted the value.
* @retval kErrorNotImplemented The platform does not implement settings functionality.
*
*/
otError DeleteParentInfo(void);
Error DeleteParentInfo(void);
#if OPENTHREAD_CONFIG_IP6_SLAAC_ENABLE
@@ -792,11 +792,11 @@ public:
*
* @param[in] aKey The SLAAC IID secret key.
*
* @retval OT_ERROR_NONE Successfully saved the value.
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
* @retval kErrorNone Successfully saved the value.
* @retval kErrorNotImplemented The platform does not implement settings functionality.
*
*/
otError SaveSlaacIidSecretKey(const Utils::Slaac::IidSecretKey &aKey)
Error SaveSlaacIidSecretKey(const Utils::Slaac::IidSecretKey &aKey)
{
return Save(kKeySlaacIidSecretKey, &aKey, sizeof(Utils::Slaac::IidSecretKey));
}
@@ -806,12 +806,12 @@ public:
*
* @param[out] aKey A reference to a SLAAC IID secret key to output the read value.
*
* @retval OT_ERROR_NONE Successfully read the value.
* @retval OT_ERROR_NOT_FOUND No corresponding value in the setting store.
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
* @retval kErrorNone Successfully read the value.
* @retval kErrorNotFound No corresponding value in the setting store.
* @retval kErrorNotImplemented The platform does not implement settings functionality.
*
*/
otError ReadSlaacIidSecretKey(Utils::Slaac::IidSecretKey &aKey)
Error ReadSlaacIidSecretKey(Utils::Slaac::IidSecretKey &aKey)
{
uint16_t length = sizeof(aKey);
@@ -821,11 +821,11 @@ public:
/**
* This method deletes the SLAAC IID secret key value from settings.
*
* @retval OT_ERROR_NONE Successfully deleted the value.
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
* @retval kErrorNone Successfully deleted the value.
* @retval kErrorNotImplemented The platform does not implement settings functionality.
*
*/
otError DeleteSlaacIidSecretKey(void) { return Delete(kKeySlaacIidSecretKey); }
Error DeleteSlaacIidSecretKey(void) { return Delete(kKeySlaacIidSecretKey); }
#endif // OPENTHREAD_CONFIG_IP6_SLAAC_ENABLE
@@ -836,22 +836,22 @@ public:
*
* @param[in] aChildInfo A reference to a `ChildInfo` structure to be saved/added.
*
* @retval OT_ERROR_NONE Successfully saved the Child Info in settings.
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
* @retval kErrorNone Successfully saved the Child Info in settings.
* @retval kErrorNotImplemented The platform does not implement settings functionality.
*
*/
otError AddChildInfo(const ChildInfo &aChildInfo);
Error AddChildInfo(const ChildInfo &aChildInfo);
/**
* This method deletes all Child Info entries from the settings.
*
* @note Child Info is a list-based settings property and can contain multiple entries.
*
* @retval OT_ERROR_NONE Successfully deleted the value.
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
* @retval kErrorNone Successfully deleted the value.
* @retval kErrorNotImplemented The platform does not implement settings functionality.
*
*/
otError DeleteAllChildInfo(void);
Error DeleteAllChildInfo(void);
/**
* This method enables range-based `for` loop iteration over all child info entries in the `Settings`.
@@ -921,12 +921,12 @@ public:
/**
* This method deletes the current Child Info entry.
*
* @retval OT_ERROR_NONE The entry was deleted successfully.
* @retval OT_ERROR_INVALID_STATE The entry is not valid (iterator has reached end of list).
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
* @retval kErrorNone The entry was deleted successfully.
* @retval kErrorInvalidState The entry is not valid (iterator has reached end of list).
* @retval kErrorNotImplemented The platform does not implement settings functionality.
*
*/
otError Delete(void);
Error Delete(void);
/**
* This method overloads the `*` dereference operator and gets a reference to `ChildInfo` entry to which the
@@ -994,32 +994,32 @@ public:
*
* @param[in] aDadInfo A reference to a `DadInfo` structure to be saved.
*
* @retval OT_ERROR_NONE Successfully saved duplicate address detection information in settings.
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
* @retval kErrorNone Successfully saved duplicate address detection information in settings.
* @retval kErrorNotImplemented The platform does not implement settings functionality.
*
*/
otError SaveDadInfo(const DadInfo &aDadInfo);
Error SaveDadInfo(const DadInfo &aDadInfo);
/**
* This method reads duplicate address detection information.
*
* @param[out] aDadInfo A reference to a `DadInfo` structure to output the read content.
*
* @retval OT_ERROR_NONE Successfully read the duplicate address detection information.
* @retval OT_ERROR_NOT_FOUND No corresponding value in the setting store.
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
* @retval kErrorNone Successfully read the duplicate address detection information.
* @retval kErrorNotFound No corresponding value in the setting store.
* @retval kErrorNotImplemented The platform does not implement settings functionality.
*
*/
otError ReadDadInfo(DadInfo &aDadInfo) const;
Error ReadDadInfo(DadInfo &aDadInfo) const;
/**
* This method deletes duplicate address detection information from settings.
*
* @retval OT_ERROR_NONE Successfully deleted the value.
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
* @retval kErrorNone Successfully deleted the value.
* @retval kErrorNotImplemented The platform does not implement settings functionality.
*
*/
otError DeleteDadInfo(void);
Error DeleteDadInfo(void);
#endif // OPENTHREAD_CONFIG_DUA_ENABLE
@@ -1029,46 +1029,46 @@ public:
*
* @param[in] aOmrPrefix An OMR prefix to be saved.
*
* @retval OT_ERROR_NONE Successfully saved the OMR prefix in settings.
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
* @retval kErrorNone Successfully saved the OMR prefix in settings.
* @retval kErrorNotImplemented The platform does not implement settings functionality.
*
*/
otError SaveOmrPrefix(const Ip6::Prefix &aOmrPrefix);
Error SaveOmrPrefix(const Ip6::Prefix &aOmrPrefix);
/**
* This method reads OMR prefix.
*
* @param[out] aOmrPrefix A reference to a `Ip6::Prefix` structure to output the OMR prefix.
*
* @retval OT_ERROR_NONE Successfully read the OMR prefix.
* @retval OT_ERROR_NOT_FOUND No corresponding value in the setting store.
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
* @retval kErrorNone Successfully read the OMR prefix.
* @retval kErrorNotFound No corresponding value in the setting store.
* @retval kErrorNotImplemented The platform does not implement settings functionality.
*
*/
otError ReadOmrPrefix(Ip6::Prefix &aOmrPrefix) const;
Error ReadOmrPrefix(Ip6::Prefix &aOmrPrefix) const;
/**
* This method saves on-link prefix.
*
* @param[in] aOnLinkPrefix An on-link prefix to be saved.
*
* @retval OT_ERROR_NONE Successfully saved the on-link prefix in settings.
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
* @retval kErrorNone Successfully saved the on-link prefix in settings.
* @retval kErrorNotImplemented The platform does not implement settings functionality.
*
*/
otError SaveOnLinkPrefix(const Ip6::Prefix &aOnLinkPrefix);
Error SaveOnLinkPrefix(const Ip6::Prefix &aOnLinkPrefix);
/**
* This method reads on-link prefix.
*
* @param[out] aOnLinkPrefix A reference to a `Ip6::Prefix` structure to output the on-link prefix.
*
* @retval OT_ERROR_NONE Successfully read the on-link prefix.
* @retval OT_ERROR_NOT_FOUND No corresponding value in the setting store.
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
* @retval kErrorNone Successfully read the on-link prefix.
* @retval kErrorNotFound No corresponding value in the setting store.
* @retval kErrorNotImplemented The platform does not implement settings functionality.
*
*/
otError ReadOnLinkPrefix(Ip6::Prefix &aOnLinkPrefix) const;
Error ReadOnLinkPrefix(Ip6::Prefix &aOnLinkPrefix) const;
#endif // OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE
#if OPENTHREAD_CONFIG_SRP_CLIENT_ENABLE
@@ -1077,32 +1077,32 @@ public:
*
* @param[in] aKeyPair A reference to an SRP ECDSA key-pair to save.
*
* @retval OT_ERROR_NONE Successfully saved key-pair information in settings.
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
* @retval kErrorNone Successfully saved key-pair information in settings.
* @retval kErrorNotImplemented The platform does not implement settings functionality.
*
*/
otError SaveSrpKey(const Crypto::Ecdsa::P256::KeyPair &aKeyPair);
Error SaveSrpKey(const Crypto::Ecdsa::P256::KeyPair &aKeyPair);
/**
* This method reads SRP client ECDSA key pair.
*
* @param[out] aKeyPair A reference to a ECDA `KeyPair` to output the read content.
*
* @retval OT_ERROR_NONE Successfully read key-pair information.
* @retval OT_ERROR_NOT_FOUND No corresponding value in the setting store.
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
* @retval kErrorNone Successfully read key-pair information.
* @retval kErrorNotFound No corresponding value in the setting store.
* @retval kErrorNotImplemented The platform does not implement settings functionality.
*
*/
otError ReadSrpKey(Crypto::Ecdsa::P256::KeyPair &aKeyPair) const;
Error ReadSrpKey(Crypto::Ecdsa::P256::KeyPair &aKeyPair) const;
/**
* This method deletes SRP client ECDSA key pair from settings.
*
* @retval OT_ERROR_NONE Successfully deleted the value.
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
* @retval kErrorNone Successfully deleted the value.
* @retval kErrorNotImplemented The platform does not implement settings functionality.
*
*/
otError DeleteSrpKey(void);
Error DeleteSrpKey(void);
#endif // OPENTHREAD_CONFIG_SRP_CLIENT_ENABLE
private:
@@ -1118,10 +1118,10 @@ private:
ChildInfoIterator end(void) { return ChildInfoIterator(GetInstance(), ChildInfoIterator::kEndIterator); }
};
otError Read(Key aKey, void *aBuffer, uint16_t &aSize) const;
otError Save(Key aKey, const void *aValue, uint16_t aSize);
otError Add(Key aKey, const void *aValue, uint16_t aSize);
otError Delete(Key aKey);
Error Read(Key aKey, void *aBuffer, uint16_t &aSize) const;
Error Save(Key aKey, const void *aValue, uint16_t aSize);
Error Add(Key aKey, const void *aValue, uint16_t aSize);
Error Delete(Key aKey);
};
} // namespace ot
+5 -5
View File
@@ -65,10 +65,10 @@ const char *StringFind(const char *aString, char aChar)
return ret;
}
otError StringBase::Write(char *aBuffer, uint16_t aSize, uint16_t &aLength, const char *aFormat, va_list aArgs)
Error StringBase::Write(char *aBuffer, uint16_t aSize, uint16_t &aLength, const char *aFormat, va_list aArgs)
{
otError error = OT_ERROR_NONE;
int len;
Error error = kErrorNone;
int len;
len = vsnprintf(aBuffer + aLength, aSize - aLength, aFormat, aArgs);
@@ -76,12 +76,12 @@ otError StringBase::Write(char *aBuffer, uint16_t aSize, uint16_t &aLength, cons
{
aLength = 0;
aBuffer[0] = 0;
error = OT_ERROR_INVALID_ARGS;
error = kErrorInvalidArgs;
}
else if (len >= aSize - aLength)
{
aLength = aSize - 1;
error = OT_ERROR_NO_BUFS;
error = kErrorNoBufs;
}
else
{
+23 -24
View File
@@ -40,9 +40,8 @@
#include <stdint.h>
#include <stdio.h>
#include <openthread/error.h>
#include "common/code_utils.hpp"
#include "common/error.hpp"
namespace ot {
@@ -95,11 +94,11 @@ protected:
* @param[in] aFormat A pointer to the format string.
* @param[in] aArgs Arguments for the format specification.
*
* @retval OT_ERROR_NONE Updated the string successfully.
* @retval OT_ERROR_NO_BUFS String could not fit in the storage.
* @retval OT_ERROR_INVALID_ARGS Arguments do not match the format string.
* @retval kErrorNone Updated the string successfully.
* @retval kErrorNoBufs String could not fit in the storage.
* @retval kErrorInvalidArgs Arguments do not match the format string.
*/
static otError Write(char *aBuffer, uint16_t aSize, uint16_t &aLength, const char *aFormat, va_list aArgs);
static Error Write(char *aBuffer, uint16_t aSize, uint16_t &aLength, const char *aFormat, va_list aArgs);
};
/**
@@ -182,15 +181,15 @@ public:
* @param[in] aFormat A pointer to the format string.
* @param[in] ... Arguments for the format specification.
*
* @retval OT_ERROR_NONE Updated the string successfully.
* @retval OT_ERROR_NO_BUFS String could not fit in the storage.
* @retval OT_ERROR_INVALID_ARGS Arguments do not match the format string.
* @retval kErrorNone Updated the string successfully.
* @retval kErrorNoBufs String could not fit in the storage.
* @retval kErrorInvalidArgs Arguments do not match the format string.
*
*/
otError Set(const char *aFormat, ...)
Error Set(const char *aFormat, ...)
{
va_list args;
otError error;
Error error;
va_start(args, aFormat);
mLength = 0;
@@ -206,15 +205,15 @@ public:
* @param[in] aFormat A pointer to the format string.
* @param[in] ... Arguments for the format specification.
*
* @retval OT_ERROR_NONE Updated the string successfully.
* @retval OT_ERROR_NO_BUFS String could not fit in the storage.
* @retval OT_ERROR_INVALID_ARGS Arguments do not match the format string.
* @retval kErrorNone Updated the string successfully.
* @retval kErrorNoBufs String could not fit in the storage.
* @retval kErrorInvalidArgs Arguments do not match the format string.
*
*/
otError Append(const char *aFormat, ...)
Error Append(const char *aFormat, ...)
{
va_list args;
otError error;
Error error;
va_start(args, aFormat);
error = Write(mBuffer, kSize, mLength, aFormat, args);
@@ -229,12 +228,12 @@ public:
* @param[in] aFormat A pointer to the format string.
* @param[in] aArgs Arguments for the format specification (as `va_list`).
*
* @retval OT_ERROR_NONE Updated the string successfully.
* @retval OT_ERROR_NO_BUFS String could not fit in the storage.
* @retval OT_ERROR_INVALID_ARGS Arguments do not match the format string.
* @retval kErrorNone Updated the string successfully.
* @retval kErrorNoBufs String could not fit in the storage.
* @retval kErrorInvalidArgs Arguments do not match the format string.
*
*/
otError AppendVarArgs(const char *aFormat, va_list aArgs) { return Write(mBuffer, kSize, mLength, aFormat, aArgs); }
Error AppendVarArgs(const char *aFormat, va_list aArgs) { return Write(mBuffer, kSize, mLength, aFormat, aArgs); }
/**
* This method appends an array of bytes in hex representation (using "%02x" style) to the `String` object.
@@ -242,13 +241,13 @@ public:
* @param[in] aBytes A pointer to buffer containing the bytes to append.
* @param[in] aLength The length of @p aBytes buffer (in bytes).
*
* @retval OT_ERROR_NONE Updated the string successfully.
* @retval OT_ERROR_NO_BUFS String could not fit in the storage.
* @retval kErrorNone Updated the string successfully.
* @retval kErrorNoBufs String could not fit in the storage.
*
*/
otError AppendHexBytes(const uint8_t *aBytes, uint16_t aLength)
Error AppendHexBytes(const uint8_t *aBytes, uint16_t aLength)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
while (aLength--)
{
+34 -34
View File
@@ -55,14 +55,14 @@ const uint8_t *Tlv::GetValue(void) const
return reinterpret_cast<const uint8_t *>(this) + (IsExtended() ? sizeof(ExtendedTlv) : sizeof(Tlv));
}
otError Tlv::AppendTo(Message &aMessage) const
Error Tlv::AppendTo(Message &aMessage) const
{
return aMessage.AppendBytes(this, static_cast<uint16_t>(GetSize()));
}
otError Tlv::FindTlv(const Message &aMessage, uint8_t aType, uint16_t aMaxSize, Tlv &aTlv)
Error Tlv::FindTlv(const Message &aMessage, uint8_t aType, uint16_t aMaxSize, Tlv &aTlv)
{
otError error;
Error error;
uint16_t offset;
uint16_t size;
@@ -79,14 +79,14 @@ exit:
return error;
}
otError Tlv::FindTlvOffset(const Message &aMessage, uint8_t aType, uint16_t &aOffset)
Error Tlv::FindTlvOffset(const Message &aMessage, uint8_t aType, uint16_t &aOffset)
{
return Find(aMessage, aType, &aOffset, nullptr, nullptr);
}
otError Tlv::FindTlvValueOffset(const Message &aMessage, uint8_t aType, uint16_t &aValueOffset, uint16_t &aLength)
Error Tlv::FindTlvValueOffset(const Message &aMessage, uint8_t aType, uint16_t &aValueOffset, uint16_t &aLength)
{
otError error;
Error error;
uint16_t offset;
uint16_t size;
bool isExtendedTlv;
@@ -108,9 +108,9 @@ exit:
return error;
}
otError Tlv::Find(const Message &aMessage, uint8_t aType, uint16_t *aOffset, uint16_t *aSize, bool *aIsExtendedTlv)
Error Tlv::Find(const Message &aMessage, uint8_t aType, uint16_t *aOffset, uint16_t *aSize, bool *aIsExtendedTlv)
{
otError error = OT_ERROR_NOT_FOUND;
Error error = kErrorNotFound;
uint16_t offset = aMessage.GetOffset();
uint16_t remainingLen = aMessage.GetLength();
Tlv tlv;
@@ -156,7 +156,7 @@ otError Tlv::Find(const Message &aMessage, uint8_t aType, uint16_t *aOffset, uin
*aIsExtendedTlv = (tlv.mLength == kExtendedLength);
}
error = OT_ERROR_NONE;
error = kErrorNone;
ExitNow();
}
@@ -168,9 +168,9 @@ exit:
return error;
}
template <typename UintType> otError Tlv::ReadUintTlv(const Message &aMessage, uint16_t aOffset, UintType &aValue)
template <typename UintType> Error Tlv::ReadUintTlv(const Message &aMessage, uint16_t aOffset, UintType &aValue)
{
otError error;
Error error;
SuccessOrExit(error = ReadTlv(aMessage, aOffset, &aValue, sizeof(aValue)));
aValue = Encoding::BigEndian::HostSwap<UintType>(aValue);
@@ -180,18 +180,18 @@ exit:
}
// Explicit instantiations of `ReadUintTlv<>()`
template otError Tlv::ReadUintTlv<uint8_t>(const Message &aMessage, uint16_t aOffset, uint8_t &aValue);
template otError Tlv::ReadUintTlv<uint16_t>(const Message &aMessage, uint16_t aOffset, uint16_t &aValue);
template otError Tlv::ReadUintTlv<uint32_t>(const Message &aMessage, uint16_t aOffset, uint32_t &aValue);
template Error Tlv::ReadUintTlv<uint8_t>(const Message &aMessage, uint16_t aOffset, uint8_t &aValue);
template Error Tlv::ReadUintTlv<uint16_t>(const Message &aMessage, uint16_t aOffset, uint16_t &aValue);
template Error Tlv::ReadUintTlv<uint32_t>(const Message &aMessage, uint16_t aOffset, uint32_t &aValue);
otError Tlv::ReadTlv(const Message &aMessage, uint16_t aOffset, void *aValue, uint8_t aMinLength)
Error Tlv::ReadTlv(const Message &aMessage, uint16_t aOffset, void *aValue, uint8_t aMinLength)
{
otError error = OT_ERROR_NONE;
Tlv tlv;
Error error = kErrorNone;
Tlv tlv;
SuccessOrExit(error = aMessage.Read(aOffset, tlv));
VerifyOrExit(!tlv.IsExtended() && (tlv.GetLength() >= aMinLength), error = OT_ERROR_PARSE);
VerifyOrExit(tlv.GetSize() + aOffset <= aMessage.GetLength(), error = OT_ERROR_PARSE);
VerifyOrExit(!tlv.IsExtended() && (tlv.GetLength() >= aMinLength), error = kErrorParse);
VerifyOrExit(tlv.GetSize() + aOffset <= aMessage.GetLength(), error = kErrorParse);
aMessage.ReadBytes(aOffset + sizeof(Tlv), aValue, aMinLength);
@@ -199,9 +199,9 @@ exit:
return error;
}
template <typename UintType> otError Tlv::FindUintTlv(const Message &aMessage, uint8_t aType, UintType &aValue)
template <typename UintType> Error Tlv::FindUintTlv(const Message &aMessage, uint8_t aType, UintType &aValue)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
uint16_t offset;
SuccessOrExit(error = FindTlvOffset(aMessage, aType, offset));
@@ -212,25 +212,25 @@ exit:
}
// Explicit instantiations of `FindUintTlv<>()`
template otError Tlv::FindUintTlv<uint8_t>(const Message &aMessage, uint8_t aType, uint8_t &aValue);
template otError Tlv::FindUintTlv<uint16_t>(const Message &aMessage, uint8_t aType, uint16_t &aValue);
template otError Tlv::FindUintTlv<uint32_t>(const Message &aMessage, uint8_t aType, uint32_t &aValue);
template Error Tlv::FindUintTlv<uint8_t>(const Message &aMessage, uint8_t aType, uint8_t &aValue);
template Error Tlv::FindUintTlv<uint16_t>(const Message &aMessage, uint8_t aType, uint16_t &aValue);
template Error Tlv::FindUintTlv<uint32_t>(const Message &aMessage, uint8_t aType, uint32_t &aValue);
otError Tlv::FindTlv(const Message &aMessage, uint8_t aType, void *aValue, uint8_t aLength)
Error Tlv::FindTlv(const Message &aMessage, uint8_t aType, void *aValue, uint8_t aLength)
{
otError error;
Error error;
uint16_t offset;
uint16_t length;
SuccessOrExit(error = FindTlvValueOffset(aMessage, aType, offset, length));
VerifyOrExit(length >= aLength, error = OT_ERROR_PARSE);
VerifyOrExit(length >= aLength, error = kErrorParse);
aMessage.ReadBytes(offset, aValue, aLength);
exit:
return error;
}
template <typename UintType> otError Tlv::AppendUintTlv(Message &aMessage, uint8_t aType, UintType aValue)
template <typename UintType> Error Tlv::AppendUintTlv(Message &aMessage, uint8_t aType, UintType aValue)
{
UintType value = Encoding::BigEndian::HostSwap<UintType>(aValue);
@@ -238,14 +238,14 @@ template <typename UintType> otError Tlv::AppendUintTlv(Message &aMessage, uint8
}
// Explicit instantiations of `AppendUintTlv<>()`
template otError Tlv::AppendUintTlv<uint8_t>(Message &aMessage, uint8_t aType, uint8_t aValue);
template otError Tlv::AppendUintTlv<uint16_t>(Message &aMessage, uint8_t aType, uint16_t aValue);
template otError Tlv::AppendUintTlv<uint32_t>(Message &aMessage, uint8_t aType, uint32_t aValue);
template Error Tlv::AppendUintTlv<uint8_t>(Message &aMessage, uint8_t aType, uint8_t aValue);
template Error Tlv::AppendUintTlv<uint16_t>(Message &aMessage, uint8_t aType, uint16_t aValue);
template Error Tlv::AppendUintTlv<uint32_t>(Message &aMessage, uint8_t aType, uint32_t aValue);
otError Tlv::AppendTlv(Message &aMessage, uint8_t aType, const void *aValue, uint8_t aLength)
Error Tlv::AppendTlv(Message &aMessage, uint8_t aType, const void *aValue, uint8_t aLength)
{
otError error = OT_ERROR_NONE;
Tlv tlv;
Error error = kErrorNone;
Tlv tlv;
OT_ASSERT(aLength <= Tlv::kBaseTlvMaxLength);
+57 -65
View File
@@ -36,11 +36,11 @@
#include "openthread-core-config.h"
#include <openthread/error.h>
#include <openthread/thread.h>
#include <openthread/platform/toolchain.h>
#include "common/encoding.hpp"
#include "common/error.hpp"
#include "common/type_traits.hpp"
namespace ot {
@@ -171,11 +171,11 @@ public:
*
* @param[in] aMessage A reference to the message to append to.
*
* @retval OT_ERROR_NONE Successfully appended the TLV to the message.
* @retval OT_ERROR_NO_BUFS Insufficient available buffers to grow the message.
* @retval kErrorNone Successfully appended the TLV to the message.
* @retval kErrorNoBufs Insufficient available buffers to grow the message.
*
*/
otError AppendTo(Message &aMessage) const;
Error AppendTo(Message &aMessage) const;
/**
* This static method reads a TLV in a message at a given offset expecting a minimum length for the value.
@@ -185,11 +185,11 @@ public:
* @param[out] aValue A buffer to output the TLV's value, must contain (at least) @p aMinLength bytes.
* @param[in] aMinLength The minimum expected length of TLV and number of bytes to copy into @p aValue buffer.
*
* @retval OT_ERROR_NONE Successfully read the TLV and copied @p aMinLength into @p aValue.
* @retval OT_ERROR_PARSE The TLV was not well-formed and could not be parsed.
* @retval kErrorNone Successfully read the TLV and copied @p aMinLength into @p aValue.
* @retval kErrorParse The TLV was not well-formed and could not be parsed.
*
*/
static otError ReadTlv(const Message &aMessage, uint16_t aOffset, void *aValue, uint8_t aMinLength);
static Error ReadTlv(const Message &aMessage, uint16_t aOffset, void *aValue, uint8_t aMinLength);
/**
* This static method reads a simple TLV with a single non-integral value in a message at a given offset.
@@ -200,12 +200,12 @@ public:
* @param[in] aOffset The offset into the message pointing to the start of the TLV.
* @param[out] aValue A reference to the value object to output the read value.
*
* @retval OT_ERROR_NONE Successfully read the TLV and updated the @p aValue.
* @retval OT_ERROR_PARSE The TLV was not well-formed and could not be parsed.
* @retval kErrorNone Successfully read the TLV and updated the @p aValue.
* @retval kErrorParse The TLV was not well-formed and could not be parsed.
*
*/
template <typename SimpleTlvType>
static otError Read(const Message &aMessage, uint16_t aOffset, typename SimpleTlvType::ValueType &aValue)
static Error Read(const Message &aMessage, uint16_t aOffset, typename SimpleTlvType::ValueType &aValue)
{
return ReadTlv(aMessage, aOffset, &aValue, sizeof(aValue));
}
@@ -219,12 +219,12 @@ public:
* @param[in] aOffset The offset into the message pointing to the start of the TLV.
* @param[out] aValue A reference to an unsigned int to output the read value.
*
* @retval OT_ERROR_NONE Successfully read the TLV and updated the @p aValue.
* @retval OT_ERROR_PARSE The TLV was not well-formed and could not be parsed.
* @retval kErrorNone Successfully read the TLV and updated the @p aValue.
* @retval kErrorParse The TLV was not well-formed and could not be parsed.
*
*/
template <typename UintTlvType>
static otError Read(const Message &aMessage, uint16_t aOffset, typename UintTlvType::UintValueType &aValue)
static Error Read(const Message &aMessage, uint16_t aOffset, typename UintTlvType::UintValueType &aValue)
{
return ReadUintTlv(aMessage, aOffset, aValue);
}
@@ -239,11 +239,11 @@ public:
* @param[in] aMaxSize Maximum number of bytes to read.
* @param[out] aTlv A reference to the TLV that will be copied to.
*
* @retval OT_ERROR_NONE Successfully copied the TLV.
* @retval OT_ERROR_NOT_FOUND Could not find the TLV with Type @p aType.
* @retval kErrorNone Successfully copied the TLV.
* @retval kErrorNotFound Could not find the TLV with Type @p aType.
*
*/
static otError FindTlv(const Message &aMessage, uint8_t aType, uint16_t aMaxSize, Tlv &aTlv);
static Error FindTlv(const Message &aMessage, uint8_t aType, uint16_t aMaxSize, Tlv &aTlv);
/**
* This static method searches for and reads a requested TLV out of a given message.
@@ -255,11 +255,11 @@ public:
* @param[in] aMessage A reference to the message.
* @param[out] aTlv A reference to the TLV that will be copied to.
*
* @retval OT_ERROR_NONE Successfully copied the TLV.
* @retval OT_ERROR_NOT_FOUND Could not find the TLV with Type @p aType.
* @retval kErrorNone Successfully copied the TLV.
* @retval kErrorNotFound Could not find the TLV with Type @p aType.
*
*/
template <typename TlvType> static otError FindTlv(const Message &aMessage, TlvType &aTlv)
template <typename TlvType> static Error FindTlv(const Message &aMessage, TlvType &aTlv)
{
return FindTlv(aMessage, TlvType::kType, sizeof(TlvType), aTlv);
}
@@ -273,11 +273,11 @@ public:
* @param[in] aType The Type value to search for.
* @param[out] aOffset A reference to the offset of the TLV.
*
* @retval OT_ERROR_NONE Successfully copied the TLV.
* @retval OT_ERROR_NOT_FOUND Could not find the TLV with Type @p aType.
* @retval kErrorNone Successfully copied the TLV.
* @retval kErrorNotFound Could not find the TLV with Type @p aType.
*
*/
static otError FindTlvOffset(const Message &aMessage, uint8_t aType, uint16_t &aOffset);
static Error FindTlvOffset(const Message &aMessage, uint8_t aType, uint16_t &aOffset);
/**
* This static method finds the offset and length of a given TLV type.
@@ -289,21 +289,18 @@ public:
* @param[out] aValueOffset The offset where the value starts.
* @param[out] aLength The length of the value.
*
* @retval OT_ERROR_NONE Successfully found the TLV.
* @retval OT_ERROR_NOT_FOUND Could not find the TLV with Type @p aType.
* @retval kErrorNone Successfully found the TLV.
* @retval kErrorNotFound Could not find the TLV with Type @p aType.
*
*/
static otError FindTlvValueOffset(const Message &aMessage,
uint8_t aType,
uint16_t & aValueOffset,
uint16_t & aLength);
static Error FindTlvValueOffset(const Message &aMessage, uint8_t aType, uint16_t &aValueOffset, uint16_t &aLength);
/**
* This static method searches for a TLV with a given type in a message, ensures its length is same or larger than
* an expected minimum value, and then reads its value into a given buffer.
*
* If the TLV length is smaller than the minimum length @p aLength, the TLV is considered invalid. In this case,
* this method returns `OT_ERROR_PARSE` and the @p aValue buffer is not updated.
* this method returns `kErrorParse` and the @p aValue buffer is not updated.
*
* If the TLV length is larger than @p aLength, the TLV is considered valid, but only the first @p aLength bytes
* of the value are read and copied into the @p aValue buffer.
@@ -315,12 +312,12 @@ public:
* @param[out] aValue A buffer to output the value (must contain at least @p aLength bytes).
* @param[in] aLength The expected (minimum) length of the TLV value.
*
* @retval OT_ERROR_NONE The TLV was found and read successfully. @p aValue is updated.
* @retval OT_ERROR_NOT_FOUND Could not find the TLV with Type @p aType.
* @retval OT_ERROR_PARSE TLV was found but it was not well-formed and could not be parsed.
* @retval kErrorNone The TLV was found and read successfully. @p aValue is updated.
* @retval kErrorNotFound Could not find the TLV with Type @p aType.
* @retval kErrorParse TLV was found but it was not well-formed and could not be parsed.
*
*/
template <typename TlvType> static otError Find(const Message &aMessage, void *aValue, uint8_t aLength)
template <typename TlvType> static Error Find(const Message &aMessage, void *aValue, uint8_t aLength)
{
return FindTlv(aMessage, TlvType::kType, aValue, aLength);
}
@@ -330,7 +327,7 @@ public:
* same or larger than the expected `ValueType` object size, and then reads its value into a value object reference.
*
* If the TLV length is smaller than the size of @p aValue, the TLV is considered invalid. In this case, this
* method returns `OT_ERROR_PARSE` and the @p aValue is not updated.
* method returns `kErrorParse` and the @p aValue is not updated.
*
* If the TLV length is larger than the size of @p aValue, the TLV is considered valid, but the size of
* `ValueType` bytes are read and copied into the @p aValue.
@@ -341,13 +338,13 @@ public:
* @param[in] aType The TLV type to search for.
* @param[out] aValue A reference to the value object to output the read value.
*
* @retval OT_ERROR_NONE The TLV was found and read successfully. @p aValue is updated.
* @retval OT_ERROR_NOT_FOUND Could not find the TLV with Type @p aType.
* @retval OT_ERROR_PARSE TLV was found but it was not well-formed and could not be parsed.
* @retval kErrorNone The TLV was found and read successfully. @p aValue is updated.
* @retval kErrorNotFound Could not find the TLV with Type @p aType.
* @retval kErrorParse TLV was found but it was not well-formed and could not be parsed.
*
*/
template <typename SimpleTlvType>
static otError Find(const Message &aMessage, typename SimpleTlvType::ValueType &aValue)
static Error Find(const Message &aMessage, typename SimpleTlvType::ValueType &aValue)
{
return FindTlv(aMessage, SimpleTlvType::kType, &aValue, sizeof(aValue));
}
@@ -357,20 +354,20 @@ public:
* into a given `uint` reference variable.
*
* If the TLV length is smaller than size of integral value, the TLV is considered invalid. In this case, this
* method returns `OT_ERROR_PARSE` and the @p aValue is not updated.
* method returns `kErrorParse` and the @p aValue is not updated.
*
* @tparam UintTlvType The simple TLV type to find (must be a sub-class of `UintTlvInfo`)
*
* @param[in] aMessage A reference to the message.
* @param[out] aValue A reference to an unsigned int value to output the TLV's value.
*
* @retval OT_ERROR_NONE The TLV was found and read successfully. @p aValue is updated.
* @retval OT_ERROR_NOT_FOUND Could not find the TLV with Type @p aType.
* @retval OT_ERROR_PARSE TLV was found but it was not well-formed and could not be parsed.
* @retval kErrorNone The TLV was found and read successfully. @p aValue is updated.
* @retval kErrorNotFound Could not find the TLV with Type @p aType.
* @retval kErrorParse TLV was found but it was not well-formed and could not be parsed.
*
*/
template <typename UintTlvType>
static otError Find(const Message &aMessage, typename UintTlvType::UintValueType &aValue)
static Error Find(const Message &aMessage, typename UintTlvType::UintValueType &aValue)
{
return FindUintTlv(aMessage, UintTlvType::kType, aValue);
}
@@ -386,11 +383,11 @@ public:
* @param[in] aValue A buffer containing the TLV value.
* @param[in] aLength The value length (in bytes).
*
* @retval OT_ERROR_NONE Successfully appended the TLV to the message.
* @retval OT_ERROR_NO_BUFS Insufficient available buffers to grow the message.
* @retval kErrorNone Successfully appended the TLV to the message.
* @retval kErrorNoBufs Insufficient available buffers to grow the message.
*
*/
template <typename TlvType> static otError Append(Message &aMessage, const void *aValue, uint8_t aLength)
template <typename TlvType> static Error Append(Message &aMessage, const void *aValue, uint8_t aLength)
{
return AppendTlv(aMessage, TlvType::kType, aValue, aLength);
}
@@ -405,12 +402,12 @@ public:
* @param[in] aMessage A reference to the message to append to.
* @param[in] aValue A reference to the object containing TLV's value.
*
* @retval OT_ERROR_NONE Successfully appended the TLV to the message.
* @retval OT_ERROR_NO_BUFS Insufficient available buffers to grow the message.
* @retval kErrorNone Successfully appended the TLV to the message.
* @retval kErrorNoBufs Insufficient available buffers to grow the message.
*
*/
template <typename SimpleTlvType>
static otError Append(Message &aMessage, const typename SimpleTlvType::ValueType &aValue)
static Error Append(Message &aMessage, const typename SimpleTlvType::ValueType &aValue)
{
return AppendTlv(aMessage, SimpleTlvType::kType, &aValue, sizeof(aValue));
}
@@ -425,11 +422,11 @@ public:
* @param[in] aMessage A reference to the message to append to.
* @param[in] aValue An unsigned int value to use as TLV's value.
*
* @retval OT_ERROR_NONE Successfully appended the TLV to the message.
* @retval OT_ERROR_NO_BUFS Insufficient available buffers to grow the message.
* @retval kErrorNone Successfully appended the TLV to the message.
* @retval kErrorNoBufs Insufficient available buffers to grow the message.
*
*/
template <typename UintTlvType> static otError Append(Message &aMessage, typename UintTlvType::UintValueType aValue)
template <typename UintTlvType> static Error Append(Message &aMessage, typename UintTlvType::UintValueType aValue)
{
return AppendUintTlv(aMessage, UintTlvType::kType, aValue);
}
@@ -454,22 +451,17 @@ private:
* @param[out] aSize A pointer to a variable to output the size (total number of bytes) of the TLV.
* @param[out] aIsExtendedTlv A pointer to a boolean variable to output whether the found TLV is extended or not.
*
* @retval OT_ERROR_NONE Successfully found the TLV.
* @retval OT_ERROR_NOT_FOUND Could not find the TLV with Type @p aType.
* @retval kErrorNone Successfully found the TLV.
* @retval kErrorNotFound Could not find the TLV with Type @p aType.
*
*/
static otError Find(const Message &aMessage,
uint8_t aType,
uint16_t * aOffset,
uint16_t * aSize,
bool * aIsExtendedTlv);
static Error Find(const Message &aMessage, uint8_t aType, uint16_t *aOffset, uint16_t *aSize, bool *aIsExtendedTlv);
static otError FindTlv(const Message &aMessage, uint8_t aType, void *aValue, uint8_t aLength);
static otError AppendTlv(Message &aMessage, uint8_t aType, const void *aValue, uint8_t aLength);
template <typename UintType>
static otError ReadUintTlv(const Message &aMessage, uint16_t aOffset, UintType &aValue);
template <typename UintType> static otError FindUintTlv(const Message &aMessage, uint8_t aType, UintType &aValue);
template <typename UintType> static otError AppendUintTlv(Message &aMessage, uint8_t aType, UintType aValue);
static Error FindTlv(const Message &aMessage, uint8_t aType, void *aValue, uint8_t aLength);
static Error AppendTlv(Message &aMessage, uint8_t aType, const void *aValue, uint8_t aLength);
template <typename UintType> static Error ReadUintTlv(const Message &aMessage, uint16_t aOffset, UintType &aValue);
template <typename UintType> static Error FindUintTlv(const Message &aMessage, uint8_t aType, UintType &aValue);
template <typename UintType> static Error AppendUintTlv(Message &aMessage, uint8_t aType, UintType aValue);
uint8_t mType;
uint8_t mLength;
+1 -2
View File
@@ -38,8 +38,7 @@
#include <stdint.h>
#include <openthread/error.h>
#include "common/error.hpp"
#include "crypto/aes_ecb.hpp"
#include "mac/mac_types.hpp"
+27 -27
View File
@@ -50,7 +50,7 @@ namespace Ecdsa {
#if OPENTHREAD_CONFIG_ECDSA_ENABLE
otError P256::KeyPair::Generate(void)
Error P256::KeyPair::Generate(void)
{
mbedtls_pk_context pk;
int ret;
@@ -74,26 +74,26 @@ otError P256::KeyPair::Generate(void)
exit:
mbedtls_pk_free(&pk);
return (ret >= 0) ? OT_ERROR_NONE : MbedTls::MapError(ret);
return (ret >= 0) ? kErrorNone : MbedTls::MapError(ret);
}
otError P256::KeyPair::Parse(void *aContext) const
Error P256::KeyPair::Parse(void *aContext) const
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
mbedtls_pk_context *pk = reinterpret_cast<mbedtls_pk_context *>(aContext);
mbedtls_pk_init(pk);
VerifyOrExit(mbedtls_pk_setup(pk, mbedtls_pk_info_from_type(MBEDTLS_PK_ECKEY)) == 0, error = OT_ERROR_FAILED);
VerifyOrExit(mbedtls_pk_parse_key(pk, mDerBytes, mDerLength, nullptr, 0) == 0, error = OT_ERROR_PARSE);
VerifyOrExit(mbedtls_pk_setup(pk, mbedtls_pk_info_from_type(MBEDTLS_PK_ECKEY)) == 0, error = kErrorFailed);
VerifyOrExit(mbedtls_pk_parse_key(pk, mDerBytes, mDerLength, nullptr, 0) == 0, error = kErrorParse);
exit:
return error;
}
otError P256::KeyPair::GetPublicKey(PublicKey &aPublicKey) const
Error P256::KeyPair::GetPublicKey(PublicKey &aPublicKey) const
{
otError error;
Error error;
mbedtls_pk_context pk;
mbedtls_ecp_keypair *keyPair;
int ret;
@@ -113,9 +113,9 @@ exit:
return error;
}
otError P256::KeyPair::Sign(const Sha256::Hash &aHash, Signature &aSignature) const
Error P256::KeyPair::Sign(const Sha256::Hash &aHash, Signature &aSignature) const
{
otError error;
Error error;
mbedtls_pk_context pk;
mbedtls_ecp_keypair * keypair;
mbedtls_ecdsa_context ecdsa;
@@ -155,9 +155,9 @@ exit:
return error;
}
otError P256::PublicKey::Verify(const Sha256::Hash &aHash, const Signature &aSignature) const
Error P256::PublicKey::Verify(const Sha256::Hash &aHash, const Signature &aSignature) const
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
mbedtls_ecdsa_context ecdsa;
mbedtls_mpi r;
mbedtls_mpi s;
@@ -184,7 +184,7 @@ otError P256::PublicKey::Verify(const Sha256::Hash &aHash, const Signature &aSig
VerifyOrExit(ret == 0, error = MbedTls::MapError(ret));
ret = mbedtls_ecdsa_verify(&ecdsa.grp, aHash.GetBytes(), Sha256::Hash::kSize, &ecdsa.Q, &r, &s);
VerifyOrExit(ret == 0, error = OT_ERROR_SECURITY);
VerifyOrExit(ret == 0, error = kErrorSecurity);
exit:
mbedtls_mpi_free(&s);
@@ -194,14 +194,14 @@ exit:
return error;
}
otError Sign(uint8_t * aOutput,
uint16_t & aOutputLength,
const uint8_t *aInputHash,
uint16_t aInputHashLength,
const uint8_t *aPrivateKey,
uint16_t aPrivateKeyLength)
Error Sign(uint8_t * aOutput,
uint16_t & aOutputLength,
const uint8_t *aInputHash,
uint16_t aInputHashLength,
const uint8_t *aPrivateKey,
uint16_t aPrivateKeyLength)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
mbedtls_ecdsa_context ctx;
mbedtls_pk_context pkCtx;
mbedtls_ecp_keypair * keypair;
@@ -215,26 +215,26 @@ otError Sign(uint8_t * aOutput,
// Parse a private key in PEM format.
VerifyOrExit(mbedtls_pk_parse_key(&pkCtx, aPrivateKey, aPrivateKeyLength, nullptr, 0) == 0,
error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(mbedtls_pk_get_type(&pkCtx) == MBEDTLS_PK_ECKEY, error = OT_ERROR_INVALID_ARGS);
error = kErrorInvalidArgs);
VerifyOrExit(mbedtls_pk_get_type(&pkCtx) == MBEDTLS_PK_ECKEY, error = kErrorInvalidArgs);
keypair = mbedtls_pk_ec(pkCtx);
OT_ASSERT(keypair != nullptr);
VerifyOrExit(mbedtls_ecdsa_from_keypair(&ctx, keypair) == 0, error = OT_ERROR_FAILED);
VerifyOrExit(mbedtls_ecdsa_from_keypair(&ctx, keypair) == 0, error = kErrorFailed);
// Sign using ECDSA.
VerifyOrExit(mbedtls_ecdsa_sign(&ctx.grp, &rMpi, &sMpi, &ctx.d, aInputHash, aInputHashLength,
mbedtls_ctr_drbg_random, Random::Crypto::MbedTlsContextGet()) == 0,
error = OT_ERROR_FAILED);
VerifyOrExit(mbedtls_mpi_size(&rMpi) + mbedtls_mpi_size(&sMpi) <= aOutputLength, error = OT_ERROR_NO_BUFS);
error = kErrorFailed);
VerifyOrExit(mbedtls_mpi_size(&rMpi) + mbedtls_mpi_size(&sMpi) <= aOutputLength, error = kErrorNoBufs);
// Concatenate the two octet sequences in the order R and then S.
VerifyOrExit(mbedtls_mpi_write_binary(&rMpi, aOutput, mbedtls_mpi_size(&rMpi)) == 0, error = OT_ERROR_FAILED);
VerifyOrExit(mbedtls_mpi_write_binary(&rMpi, aOutput, mbedtls_mpi_size(&rMpi)) == 0, error = kErrorFailed);
aOutputLength = static_cast<uint16_t>(mbedtls_mpi_size(&rMpi));
VerifyOrExit(mbedtls_mpi_write_binary(&sMpi, aOutput + aOutputLength, mbedtls_mpi_size(&sMpi)) == 0,
error = OT_ERROR_FAILED);
error = kErrorFailed);
aOutputLength += mbedtls_mpi_size(&sMpi);
exit:
+30 -31
View File
@@ -39,8 +39,7 @@
#include <stdint.h>
#include <stdlib.h>
#include <openthread/error.h>
#include "common/error.hpp"
#include "crypto/sha256.hpp"
namespace ot {
@@ -146,24 +145,24 @@ public:
/**
* This method generates and populates the `KeyPair` with a new public/private keys.
*
* @retval OT_ERROR_NONE A new key pair was generated successfully.
* @retval OT_ERROR_NO_BUFS Failed to allocate buffer for key generation.
* @retval OT_ERROR_NOT_CAPABLE Feature not supported.
* @retval OT_ERROR_FAILED Failed to generate key.
* @retval kErrorNone A new key pair was generated successfully.
* @retval kErrorNoBufs Failed to allocate buffer for key generation.
* @retval kErrorNotCapable Feature not supported.
* @retval kErrorFailed Failed to generate key.
*
*/
otError Generate(void);
Error Generate(void);
/**
* This method gets the associated public key from the `KeyPair`.
*
* @param[out] aPublicKey A reference to a `PublicKey` to output the value.
*
* @retval OT_ERROR_NONE Public key was retrieved successfully, and @p aPublicKey is updated.
* @retval OT_ERROR_PARSE The key-pair DER format could not be parsed (invalid format).
* @retval kErrorNone Public key was retrieved successfully, and @p aPublicKey is updated.
* @retval kErrorParse The key-pair DER format could not be parsed (invalid format).
*
*/
otError GetPublicKey(PublicKey &aPublicKey) const;
Error GetPublicKey(PublicKey &aPublicKey) const;
/**
* This method gets the pointer to start of the buffer containing the key-pair info in DER format.
@@ -211,16 +210,16 @@ public:
* @param[in] aHash The SHA-256 hash value of the message to use for signature calculation.
* @param[out] aSignature A reference to a `Signature` to output the calculated signature value.
*
* @retval OT_ERROR_NONE The signature was calculated successfully and @p aSignature was updated.
* @retval OT_ERROR_PARSE The key-pair DER format could not be parsed (invalid format).
* @retval OT_ERROR_INVALID_ARGS The @p aHash is invalid.
* @retval OT_ERROR_NO_BUFS Failed to allocate buffer for signature calculation.
* @retval kErrorNone The signature was calculated successfully and @p aSignature was updated.
* @retval kErrorParse The key-pair DER format could not be parsed (invalid format).
* @retval kErrorInvalidArgs The @p aHash is invalid.
* @retval kErrorNoBufs Failed to allocate buffer for signature calculation.
*
*/
otError Sign(const Sha256::Hash &aHash, Signature &aSignature) const;
Error Sign(const Sha256::Hash &aHash, Signature &aSignature) const;
private:
otError Parse(void *aContext) const;
Error Parse(void *aContext) const;
uint8_t mDerBytes[kMaxDerSize];
uint8_t mDerLength;
@@ -257,13 +256,13 @@ public:
* @param[in] aHash The SHA-256 hash value of a message to use for signature verification.
* @param[in] aSignature The signature value to verify.
*
* @retval OT_ERROR_NONE The signature was verified successfully.
* @retval OT_ERROR_SECURITY The signature is invalid.
* @retval OT_ERROR_INVALID_ARGS The key or has is invalid.
* @retval OT_ERROR_NO_BUFS Failed to allocate buffer for signature verification
* @retval kErrorNone The signature was verified successfully.
* @retval kErrorSecurity The signature is invalid.
* @retval kErrorInvalidArgs The key or has is invalid.
* @retval kErrorNoBufs Failed to allocate buffer for signature verification
*
*/
otError Verify(const Sha256::Hash &aHash, const Signature &aSignature) const;
Error Verify(const Sha256::Hash &aHash, const Signature &aSignature) const;
private:
uint8_t mData[kSize];
@@ -280,18 +279,18 @@ public:
* @param[in] aPrivateKey A private key in PEM format.
* @param[in] aPrivateKeyLength The length of the @p aPrivateKey buffer.
*
* @retval OT_ERROR_NONE ECDSA sign has been created successfully.
* @retval OT_ERROR_NO_BUFS Output buffer is too small.
* @retval OT_ERROR_INVALID_ARGS Private key is not valid EC Private Key.
* @retval OT_ERROR_FAILED Error during signing.
* @retval kErrorNone ECDSA sign has been created successfully.
* @retval kErrorNoBufs Output buffer is too small.
* @retval kErrorInvalidArgs Private key is not valid EC Private Key.
* @retval kErrorFailed Error during signing.
*
*/
otError Sign(uint8_t * aOutput,
uint16_t & aOutputLength,
const uint8_t *aInputHash,
uint16_t aInputHashLength,
const uint8_t *aPrivateKey,
uint16_t aPrivateKeyLength);
Error Sign(uint8_t * aOutput,
uint16_t & aOutputLength,
const uint8_t *aInputHash,
uint16_t aInputHashLength,
const uint8_t *aPrivateKey,
uint16_t aPrivateKeyLength);
/**
* @}
+10 -10
View File
@@ -36,7 +36,6 @@
#include <mbedtls/ctr_drbg.h>
#include <mbedtls/debug.h>
#include <mbedtls/entropy.h>
#include <mbedtls/error.h>
#include <mbedtls/platform.h>
#include <mbedtls/threading.h>
@@ -44,6 +43,7 @@
#include <mbedtls/pem.h>
#endif
#include "common/error.hpp"
#include "common/instance.hpp"
namespace ot {
@@ -60,9 +60,9 @@ MbedTls::MbedTls(void)
#endif // OPENTHREAD_CONFIG_ENABLE_BUILTIN_MBEDTLS_MANAGEMENT
}
otError MbedTls::MapError(int aMbedTlsError)
Error MbedTls::MapError(int aMbedTlsError)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
switch (aMbedTlsError)
{
@@ -102,7 +102,7 @@ otError MbedTls::MapError(int aMbedTlsError)
case MBEDTLS_ERR_SSL_BAD_INPUT_DATA:
case MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG:
case MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG:
error = OT_ERROR_INVALID_ARGS;
error = kErrorInvalidArgs;
break;
#if OPENTHREAD_CONFIG_ECDSA_ENABLE
@@ -119,7 +119,7 @@ otError MbedTls::MapError(int aMbedTlsError)
case MBEDTLS_ERR_SSL_ALLOC_FAILED:
case MBEDTLS_ERR_SSL_WANT_WRITE:
case MBEDTLS_ERR_ENTROPY_MAX_SOURCES:
error = OT_ERROR_NO_BUFS;
error = kErrorNoBufs;
break;
#ifdef MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
@@ -135,29 +135,29 @@ otError MbedTls::MapError(int aMbedTlsError)
case MBEDTLS_ERR_SSL_PEER_VERIFY_FAILED:
case MBEDTLS_ERR_THREADING_BAD_INPUT_DATA:
case MBEDTLS_ERR_THREADING_MUTEX_ERROR:
error = OT_ERROR_SECURITY;
error = kErrorSecurity;
break;
#ifdef MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
case MBEDTLS_ERR_X509_FATAL_ERROR:
error = OT_ERROR_FAILED;
error = kErrorFailed;
break;
#endif
case MBEDTLS_ERR_SSL_TIMEOUT:
case MBEDTLS_ERR_SSL_WANT_READ:
error = OT_ERROR_BUSY;
error = kErrorBusy;
break;
#if OPENTHREAD_CONFIG_ECDSA_ENABLE
case MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE:
error = OT_ERROR_NOT_CAPABLE;
error = kErrorNotCapable;
break;
#endif
default:
if (aMbedTlsError < 0)
{
error = OT_ERROR_FAILED;
error = kErrorFailed;
}
break;
+3 -2
View File
@@ -38,6 +38,7 @@
#include <openthread/instance.h>
#include "common/error.hpp"
#include "common/non_copyable.hpp"
namespace ot {
@@ -68,10 +69,10 @@ public:
*
* @param[in] aMbedTlsError The mbed TLS error.
*
* @returns The mapped otError.
* @returns The mapped Error.
*
*/
static otError MapError(int aMbedTlsError);
static Error MapError(int aMbedTlsError);
};
/**
+64 -64
View File
@@ -58,7 +58,7 @@ otError otPlatDiagProcess(otInstance *aInstance,
OT_UNUSED_VARIABLE(aOutput);
OT_UNUSED_VARIABLE(aOutputMaxLen);
return OT_ERROR_INVALID_COMMAND;
return ot::kErrorInvalidCommand;
}
namespace ot {
@@ -79,15 +79,15 @@ Diags::Diags(Instance &aInstance)
{
}
otError Diags::ProcessChannel(uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen)
Error Diags::ProcessChannel(uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen)
{
otError error = OT_ERROR_NONE;
long value;
Error error = kErrorNone;
long value;
VerifyOrExit(aArgsLength == 1, error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(aArgsLength == 1, error = kErrorInvalidArgs);
SuccessOrExit(error = ParseLong(aArgs[0], value));
VerifyOrExit(value >= Radio::kChannelMin && value <= Radio::kChannelMax, error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(value >= Radio::kChannelMin && value <= Radio::kChannelMax, error = kErrorInvalidArgs);
otPlatDiagChannelSet(static_cast<uint8_t>(value));
@@ -96,12 +96,12 @@ exit:
return error;
}
otError Diags::ProcessPower(uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen)
Error Diags::ProcessPower(uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen)
{
otError error = OT_ERROR_NONE;
long value;
Error error = kErrorNone;
long value;
VerifyOrExit(aArgsLength == 1, error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(aArgsLength == 1, error = kErrorInvalidArgs);
SuccessOrExit(error = ParseLong(aArgs[0], value));
@@ -112,7 +112,7 @@ exit:
return error;
}
otError Diags::ProcessStart(uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen)
Error Diags::ProcessStart(uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen)
{
OT_UNUSED_VARIABLE(aArgsLength);
OT_UNUSED_VARIABLE(aArgs);
@@ -121,10 +121,10 @@ otError Diags::ProcessStart(uint8_t aArgsLength, char *aArgs[], char *aOutput, s
otPlatDiagModeSet(true);
return OT_ERROR_NONE;
return kErrorNone;
}
otError Diags::ProcessStop(uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen)
Error Diags::ProcessStop(uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen)
{
OT_UNUSED_VARIABLE(aArgsLength);
OT_UNUSED_VARIABLE(aArgs);
@@ -133,7 +133,7 @@ otError Diags::ProcessStop(uint8_t aArgsLength, char *aArgs[], char *aOutput, si
otPlatDiagModeSet(false);
return OT_ERROR_NONE;
return kErrorNone;
}
extern "C" void otPlatDiagAlarmFired(otInstance *aInstance)
@@ -162,11 +162,11 @@ Diags::Diags(Instance &aInstance)
mStats.Clear();
}
otError Diags::ProcessChannel(uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen)
Error Diags::ProcessChannel(uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
VerifyOrExit(otPlatDiagModeGet(), error = OT_ERROR_INVALID_STATE);
VerifyOrExit(otPlatDiagModeGet(), error = kErrorInvalidState);
if (aArgsLength == 0)
{
@@ -177,7 +177,7 @@ otError Diags::ProcessChannel(uint8_t aArgsLength, char *aArgs[], char *aOutput,
long value;
SuccessOrExit(error = ParseLong(aArgs[0], value));
VerifyOrExit(value >= Radio::kChannelMin && value <= Radio::kChannelMax, error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(value >= Radio::kChannelMin && value <= Radio::kChannelMax, error = kErrorInvalidArgs);
mChannel = static_cast<uint8_t>(value);
IgnoreError(Get<Radio>().Receive(mChannel));
@@ -191,11 +191,11 @@ exit:
return error;
}
otError Diags::ProcessPower(uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen)
Error Diags::ProcessPower(uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
VerifyOrExit(otPlatDiagModeGet(), error = OT_ERROR_INVALID_STATE);
VerifyOrExit(otPlatDiagModeGet(), error = kErrorInvalidState);
if (aArgsLength == 0)
{
@@ -219,12 +219,12 @@ exit:
return error;
}
otError Diags::ProcessRepeat(uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen)
Error Diags::ProcessRepeat(uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
VerifyOrExit(otPlatDiagModeGet(), error = OT_ERROR_INVALID_STATE);
VerifyOrExit(aArgsLength > 0, error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(otPlatDiagModeGet(), error = kErrorInvalidState);
VerifyOrExit(aArgsLength > 0, error = kErrorInvalidArgs);
if (strcmp(aArgs[0], "stop") == 0)
{
@@ -236,13 +236,13 @@ otError Diags::ProcessRepeat(uint8_t aArgsLength, char *aArgs[], char *aOutput,
{
long value;
VerifyOrExit(aArgsLength == 2, error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(aArgsLength == 2, error = kErrorInvalidArgs);
SuccessOrExit(error = ParseLong(aArgs[0], value));
mTxPeriod = static_cast<uint32_t>(value);
SuccessOrExit(error = ParseLong(aArgs[1], value));
VerifyOrExit(value <= OT_RADIO_FRAME_MAX_SIZE, error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(value <= OT_RADIO_FRAME_MAX_SIZE, error = kErrorInvalidArgs);
mTxLen = static_cast<uint8_t>(value);
mRepeatActive = true;
@@ -257,19 +257,19 @@ exit:
return error;
}
otError Diags::ProcessSend(uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen)
Error Diags::ProcessSend(uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen)
{
otError error = OT_ERROR_NONE;
long value;
Error error = kErrorNone;
long value;
VerifyOrExit(otPlatDiagModeGet(), error = OT_ERROR_INVALID_STATE);
VerifyOrExit(aArgsLength == 2, error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(otPlatDiagModeGet(), error = kErrorInvalidState);
VerifyOrExit(aArgsLength == 2, error = kErrorInvalidArgs);
SuccessOrExit(error = ParseLong(aArgs[0], value));
mTxPackets = static_cast<uint32_t>(value);
SuccessOrExit(error = ParseLong(aArgs[1], value));
VerifyOrExit(value <= OT_RADIO_FRAME_MAX_SIZE, error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(value <= OT_RADIO_FRAME_MAX_SIZE, error = kErrorInvalidArgs);
mTxLen = static_cast<uint8_t>(value);
snprintf(aOutput, aOutputMaxLen, "sending %#x packet(s), length %#x\r\nstatus 0x%02x\r\n",
@@ -281,14 +281,14 @@ exit:
return error;
}
otError Diags::ProcessStart(uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen)
Error Diags::ProcessStart(uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen)
{
OT_UNUSED_VARIABLE(aArgsLength);
OT_UNUSED_VARIABLE(aArgs);
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
VerifyOrExit(!Get<ThreadNetif>().IsUp(), error = OT_ERROR_INVALID_STATE);
VerifyOrExit(!Get<ThreadNetif>().IsUp(), error = kErrorInvalidState);
otPlatDiagChannelSet(mChannel);
otPlatDiagTxPowerSet(mTxPower);
@@ -307,11 +307,11 @@ exit:
return error;
}
otError Diags::ProcessStats(uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen)
Error Diags::ProcessStats(uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
VerifyOrExit(otPlatDiagModeGet(), error = OT_ERROR_INVALID_STATE);
VerifyOrExit(otPlatDiagModeGet(), error = kErrorInvalidState);
if ((aArgsLength == 1) && (strcmp(aArgs[0], "clear") == 0))
{
@@ -320,7 +320,7 @@ otError Diags::ProcessStats(uint8_t aArgsLength, char *aArgs[], char *aOutput, s
}
else
{
VerifyOrExit(aArgsLength == 0, error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(aArgsLength == 0, error = kErrorInvalidArgs);
snprintf(aOutput, aOutputMaxLen,
"received packets: %d\r\nsent packets: %d\r\n"
"first received packet: rssi=%d, lqi=%d\r\n"
@@ -335,14 +335,14 @@ exit:
return error;
}
otError Diags::ProcessStop(uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen)
Error Diags::ProcessStop(uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen)
{
OT_UNUSED_VARIABLE(aArgsLength);
OT_UNUSED_VARIABLE(aArgs);
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
VerifyOrExit(otPlatDiagModeGet(), error = OT_ERROR_INVALID_STATE);
VerifyOrExit(otPlatDiagModeGet(), error = kErrorInvalidState);
otPlatAlarmMilliStop(&GetInstance());
otPlatDiagModeSet(false);
@@ -375,12 +375,12 @@ void Diags::TransmitPacket(void)
IgnoreError(Get<Radio>().Transmit(*static_cast<Mac::TxFrame *>(mTxPacket)));
}
otError Diags::ProcessRadio(uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen)
Error Diags::ProcessRadio(uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen)
{
otError error = OT_ERROR_INVALID_ARGS;
Error error = kErrorInvalidArgs;
VerifyOrExit(otPlatDiagModeGet(), error = OT_ERROR_INVALID_STATE);
VerifyOrExit(aArgsLength > 0, error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(otPlatDiagModeGet(), error = kErrorInvalidState);
VerifyOrExit(aArgsLength > 0, error = kErrorInvalidArgs);
if (strcmp(aArgs[0], "sleep") == 0)
{
@@ -401,7 +401,7 @@ otError Diags::ProcessRadio(uint8_t aArgsLength, char *aArgs[], char *aOutput, s
{
otRadioState state = Get<Radio>().GetState();
error = OT_ERROR_NONE;
error = kErrorNone;
switch (state)
{
@@ -454,9 +454,9 @@ void Diags::AlarmFired(void)
}
}
void Diags::ReceiveDone(otRadioFrame *aFrame, otError aError)
void Diags::ReceiveDone(otRadioFrame *aFrame, Error aError)
{
if (aError == OT_ERROR_NONE)
if (aError == kErrorNone)
{
// for sensitivity test, only record the rssi and lqi for the first and last packet
if (mStats.mReceivedPackets == 0)
@@ -474,9 +474,9 @@ void Diags::ReceiveDone(otRadioFrame *aFrame, otError aError)
otPlatDiagRadioReceived(&GetInstance(), aFrame, aError);
}
void Diags::TransmitDone(otError aError)
void Diags::TransmitDone(Error aError)
{
if (aError == OT_ERROR_NONE)
if (aError == kErrorNone)
{
mStats.mSentPackets++;
@@ -499,19 +499,19 @@ exit:
#endif // OPENTHREAD_RADIO
void Diags::AppendErrorResult(otError aError, char *aOutput, size_t aOutputMaxLen)
void Diags::AppendErrorResult(Error aError, char *aOutput, size_t aOutputMaxLen)
{
if (aError != OT_ERROR_NONE)
if (aError != kErrorNone)
{
snprintf(aOutput, aOutputMaxLen, "failed\r\nstatus %#x\r\n", aError);
}
}
otError Diags::ParseLong(char *aString, long &aLong)
Error Diags::ParseLong(char *aString, long &aLong)
{
char *endptr;
aLong = strtol(aString, &endptr, 0);
return (*endptr == '\0') ? OT_ERROR_NONE : OT_ERROR_PARSE;
return (*endptr == '\0') ? kErrorNone : kErrorParse;
}
void Diags::ProcessLine(const char *aString, char *aOutput, size_t aOutputMaxLen)
@@ -522,12 +522,12 @@ void Diags::ProcessLine(const char *aString, char *aOutput, size_t aOutputMaxLen
kMaxCommandBuffer = OPENTHREAD_CONFIG_DIAG_CMD_LINE_BUFFER_SIZE,
};
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
char buffer[kMaxCommandBuffer];
char * aArgsector[kMaxArgs];
uint8_t argCount = 0;
VerifyOrExit(StringLength(aString, kMaxCommandBuffer) < kMaxCommandBuffer, error = OT_ERROR_NO_BUFS);
VerifyOrExit(StringLength(aString, kMaxCommandBuffer) < kMaxCommandBuffer, error = kErrorNoBufs);
strcpy(buffer, aString);
error = ot::Utils::CmdLineParser::ParseCmd(buffer, argCount, aArgsector, kMaxArgs);
@@ -536,16 +536,16 @@ exit:
switch (error)
{
case OT_ERROR_NONE:
case kErrorNone:
aOutput[0] = '\0'; // In case there is no output.
IgnoreError(ProcessCmd(argCount, &aArgsector[0], aOutput, aOutputMaxLen));
break;
case OT_ERROR_NO_BUFS:
case kErrorNoBufs:
snprintf(aOutput, aOutputMaxLen, "failed: command string too long\r\n");
break;
case OT_ERROR_INVALID_ARGS:
case kErrorInvalidArgs:
snprintf(aOutput, aOutputMaxLen, "failed: command string contains too many arguments\r\n");
break;
@@ -555,9 +555,9 @@ exit:
}
}
otError Diags::ProcessCmd(uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen)
Error Diags::ProcessCmd(uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
// This `rcp` command is for debugging and testing only, building only when NDEBUG is not defined
// so that it will be excluded from release build.
@@ -594,7 +594,7 @@ otError Diags::ProcessCmd(uint8_t aArgsLength, char *aArgs[], char *aOutput, siz
exit:
// Add more platform specific diagnostics features here.
if (error == OT_ERROR_INVALID_COMMAND && aArgsLength > 1)
if (error == kErrorInvalidCommand && aArgsLength > 1)
{
snprintf(aOutput, aOutputMaxLen, "diag feature '%s' is not supported\r\n", aArgs[0]);
}
+24 -23
View File
@@ -40,6 +40,7 @@
#include <openthread/platform/radio.h>
#include "common/error.hpp"
#include "common/locator.hpp"
#include "common/non_copyable.hpp"
@@ -77,12 +78,12 @@ public:
* @param[out] aOutput The diagnostics execution result.
* @param[in] aOutputMaxLen The output buffer size.
*
* @retval OT_ERROR_INVALID_ARGS The command is supported but invalid arguments provided.
* @retval OT_ERROR_NONE The command is successfully process.
* @retval OT_ERROR_NOT_IMPLEMENTED The command is not supported.
* @retval kErrorInvalidArgs The command is supported but invalid arguments provided.
* @retval kErrorNone The command is successfully process.
* @retval kErrorNotImplemented The command is not supported.
*
*/
otError ProcessCmd(uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen);
Error ProcessCmd(uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen);
/**
* This method indicates whether or not the factory diagnostics mode is enabled.
@@ -103,28 +104,28 @@ public:
* The radio driver calls this method to notify OpenThread diagnostics module of a received frame.
*
* @param[in] aFrame A pointer to the received frame or nullptr if the receive operation failed.
* @param[in] aError OT_ERROR_NONE when successfully received a frame,
* OT_ERROR_ABORT when reception was aborted and a frame was not received,
* OT_ERROR_NO_BUFS when a frame could not be received due to lack of rx buffer space.
* @param[in] aError kErrorNone when successfully received a frame,
* kErrorAbort when reception was aborted and a frame was not received,
* kErrorNoBufs when a frame could not be received due to lack of rx buffer space.
*
*/
void ReceiveDone(otRadioFrame *aFrame, otError aError);
void ReceiveDone(otRadioFrame *aFrame, Error aError);
/**
* The radio driver calls this method to notify OpenThread diagnostics module that the transmission has completed.
*
* @param[in] aError OT_ERROR_NONE when the frame was transmitted,
* OT_ERROR_CHANNEL_ACCESS_FAILURE tx could not take place due to activity on channel,
* OT_ERROR_ABORT when transmission was aborted for other reasons.
* @param[in] aError kErrorNone when the frame was transmitted,
* kErrorChannelAccessFailure tx could not take place due to activity on channel,
* kErrorAbort when transmission was aborted for other reasons.
*
*/
void TransmitDone(otError aError);
void TransmitDone(Error aError);
private:
struct Command
{
const char *mName;
otError (Diags::*mCommand)(uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen);
Error (Diags::*mCommand)(uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen);
};
struct Stats
@@ -139,19 +140,19 @@ private:
uint8_t mLastLqi;
};
otError ProcessChannel(uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen);
otError ProcessPower(uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen);
otError ProcessRadio(uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen);
otError ProcessRepeat(uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen);
otError ProcessSend(uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen);
otError ProcessStart(uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen);
otError ProcessStats(uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen);
otError ProcessStop(uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen);
Error ProcessChannel(uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen);
Error ProcessPower(uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen);
Error ProcessRadio(uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen);
Error ProcessRepeat(uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen);
Error ProcessSend(uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen);
Error ProcessStart(uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen);
Error ProcessStats(uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen);
Error ProcessStop(uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen);
void TransmitPacket(void);
static void AppendErrorResult(otError aError, char *aOutput, size_t aOutputMaxLen);
static otError ParseLong(char *aString, long &aLong);
static void AppendErrorResult(Error aError, char *aOutput, size_t aOutputMaxLen);
static Error ParseLong(char *aString, long &aLong);
static const struct Command sCommands[];
+7 -7
View File
@@ -44,7 +44,7 @@ uint8_t ChannelMask::GetNumberOfChannels(void) const
uint8_t num = 0;
uint8_t channel = kChannelIteratorFirst;
while (GetNextChannel(channel) == OT_ERROR_NONE)
while (GetNextChannel(channel) == kErrorNone)
{
num++;
}
@@ -52,9 +52,9 @@ uint8_t ChannelMask::GetNumberOfChannels(void) const
return num;
}
otError ChannelMask::GetNextChannel(uint8_t &aChannel) const
Error ChannelMask::GetNextChannel(uint8_t &aChannel) const
{
otError error = OT_ERROR_NOT_FOUND;
Error error = kErrorNotFound;
if (aChannel == kChannelIteratorFirst)
{
@@ -65,7 +65,7 @@ otError ChannelMask::GetNextChannel(uint8_t &aChannel) const
{
if (ContainsChannel(aChannel))
{
ExitNow(error = OT_ERROR_NONE);
ExitNow(error = kErrorNone);
}
}
@@ -98,18 +98,18 @@ ChannelMask::InfoString ChannelMask::ToString(void) const
InfoString string;
uint8_t channel = kChannelIteratorFirst;
bool addComma = false;
otError error;
Error error;
IgnoreError(string.Append("{"));
error = GetNextChannel(channel);
while (error == OT_ERROR_NONE)
while (error == kErrorNone)
{
uint8_t rangeStart = channel;
uint8_t rangeEnd = channel;
while ((error = GetNextChannel(channel)) == OT_ERROR_NONE)
while ((error = GetNextChannel(channel)) == kErrorNone)
{
if (channel != rangeEnd + 1)
{
+3 -3
View File
@@ -201,11 +201,11 @@ public:
* On entry it should contain the previous channel or `kChannelIteratorFirst`.
* On exit it contains the next channel.
*
* @retval OT_ERROR_NONE Got the next channel, @p aChannel updated successfully.
* @retval OT_ERROR_NOT_FOUND No next channel in the channel mask (note: @p aChannel may be changed).
* @retval kErrorNone Got the next channel, @p aChannel updated successfully.
* @retval kErrorNotFound No next channel in the channel mask (note: @p aChannel may be changed).
*
*/
otError GetNextChannel(uint8_t &aChannel) const;
Error GetNextChannel(uint8_t &aChannel) const;
/**
* This method randomly chooses a channel from the channel mask.
+11 -11
View File
@@ -47,16 +47,16 @@ DataPollHandler::Callbacks::Callbacks(Instance &aInstance)
{
}
inline otError DataPollHandler::Callbacks::PrepareFrameForChild(Mac::TxFrame &aFrame,
FrameContext &aContext,
Child & aChild)
inline Error DataPollHandler::Callbacks::PrepareFrameForChild(Mac::TxFrame &aFrame,
FrameContext &aContext,
Child & aChild)
{
return Get<IndirectSender>().PrepareFrameForChild(aFrame, aContext, aChild);
}
inline void DataPollHandler::Callbacks::HandleSentFrameToChild(const Mac::TxFrame &aFrame,
const FrameContext &aContext,
otError aError,
Error aError,
Child & aChild)
{
Get<IndirectSender>().HandleSentFrameToChild(aFrame, aContext, aError, aChild);
@@ -183,7 +183,7 @@ Mac::TxFrame *DataPollHandler::HandleFrameRequest(Mac::TxFrames &aTxFrames)
frame = &aTxFrames.GetTxFrame();
#endif
VerifyOrExit(mCallbacks.PrepareFrameForChild(*frame, mFrameContext, *mIndirectTxChild) == OT_ERROR_NONE,
VerifyOrExit(mCallbacks.PrepareFrameForChild(*frame, mFrameContext, *mIndirectTxChild) == kErrorNone,
frame = nullptr);
if (mIndirectTxChild->GetIndirectTxAttempts() > 0)
@@ -210,7 +210,7 @@ exit:
return frame;
}
void DataPollHandler::HandleSentFrame(const Mac::TxFrame &aFrame, otError aError)
void DataPollHandler::HandleSentFrame(const Mac::TxFrame &aFrame, Error aError)
{
Child *child = mIndirectTxChild;
@@ -223,7 +223,7 @@ exit:
ProcessPendingPolls();
}
void DataPollHandler::HandleSentFrame(const Mac::TxFrame &aFrame, otError aError, Child &aChild)
void DataPollHandler::HandleSentFrame(const Mac::TxFrame &aFrame, Error aError, Child &aChild)
{
if (aChild.IsFramePurgePending())
{
@@ -236,12 +236,12 @@ void DataPollHandler::HandleSentFrame(const Mac::TxFrame &aFrame, otError aError
switch (aError)
{
case OT_ERROR_NONE:
case kErrorNone:
aChild.ResetIndirectTxAttempts();
aChild.SetFrameReplacePending(false);
break;
case OT_ERROR_NO_ACK:
case kErrorNoAck:
aChild.IncrementIndirectTxAttempts();
otLogInfoMac("Indirect tx to child %04x failed, attempt %d/%d", aChild.GetRloc16(),
@@ -249,8 +249,8 @@ void DataPollHandler::HandleSentFrame(const Mac::TxFrame &aFrame, otError aError
OT_FALL_THROUGH;
case OT_ERROR_CHANNEL_ACCESS_FAILURE:
case OT_ERROR_ABORT:
case kErrorChannelAccessFailure:
case kErrorAbort:
if (aChild.IsFrameReplacePending())
{
+10 -10
View File
@@ -171,27 +171,27 @@ public:
* @param[out] aContext A reference to a `FrameContext` where the context for the new frame would be placed.
* @param[in] aChild The child for which to prepare the frame.
*
* @retval OT_ERROR_NONE Frame was prepared successfully.
* @retval OT_ERROR_ABORT Indirect transmission to child should be aborted (no frame for the child).
* @retval kErrorNone Frame was prepared successfully.
* @retval kErrorAbort Indirect transmission to child should be aborted (no frame for the child).
*
*/
otError PrepareFrameForChild(Mac::TxFrame &aFrame, FrameContext &aContext, Child &aChild);
Error PrepareFrameForChild(Mac::TxFrame &aFrame, FrameContext &aContext, Child &aChild);
/**
* This callback method notifies the end of indirect frame transmission to a child.
*
* @param[in] aFrame The transmitted frame.
* @param[in] aContext The context associated with the frame when it was prepared.
* @param[in] aError OT_ERROR_NONE when the frame was transmitted successfully,
* OT_ERROR_NO_ACK when the frame was transmitted but no ACK was received,
* OT_ERROR_CHANNEL_ACCESS_FAILURE tx failed due to activity on the channel,
* OT_ERROR_ABORT when transmission was aborted for other reasons.
* @param[in] aError kErrorNone when the frame was transmitted successfully,
* kErrorNoAck when the frame was transmitted but no ACK was received,
* kErrorChannelAccessFailure tx failed due to activity on the channel,
* kErrorAbort when transmission was aborted for other reasons.
* @param[in] aChild The child to which the frame was transmitted.
*
*/
void HandleSentFrameToChild(const Mac::TxFrame &aFrame,
const FrameContext &aContext,
otError aError,
Error aError,
Child & aChild);
/**
@@ -272,9 +272,9 @@ private:
// Callbacks from MAC
void HandleDataPoll(Mac::RxFrame &aFrame);
Mac::TxFrame *HandleFrameRequest(Mac::TxFrames &aTxFrames);
void HandleSentFrame(const Mac::TxFrame &aFrame, otError aError);
void HandleSentFrame(const Mac::TxFrame &aFrame, Error aError);
void HandleSentFrame(const Mac::TxFrame &aFrame, otError aError, Child &aChild);
void HandleSentFrame(const Mac::TxFrame &aFrame, Error aError, Child &aChild);
void ProcessPendingPolls(void);
// In the current implementation of `DataPollHandler`, we can have a
+22 -22
View File
@@ -94,14 +94,14 @@ void DataPollSender::StopPolling(void)
mEnabled = false;
}
otError DataPollSender::SendDataPoll(void)
Error DataPollSender::SendDataPoll(void)
{
otError error;
Error error;
VerifyOrExit(mEnabled, error = OT_ERROR_INVALID_STATE);
VerifyOrExit(!Get<Mac::Mac>().GetRxOnWhenIdle(), error = OT_ERROR_INVALID_STATE);
VerifyOrExit(mEnabled, error = kErrorInvalidState);
VerifyOrExit(!Get<Mac::Mac>().GetRxOnWhenIdle(), error = kErrorInvalidState);
VerifyOrExit(GetParent().IsStateValidOrRestoring(), error = OT_ERROR_INVALID_STATE);
VerifyOrExit(GetParent().IsStateValidOrRestoring(), error = kErrorInvalidState);
mTimer.Stop();
@@ -111,23 +111,23 @@ exit:
switch (error)
{
case OT_ERROR_NONE:
case kErrorNone:
otLogDebgMac("Sending data poll");
ScheduleNextPoll(kUsePreviousPollPeriod);
break;
case OT_ERROR_INVALID_STATE:
case kErrorInvalidState:
otLogWarnMac("Data poll tx requested while data polling was not enabled!");
StopPolling();
break;
case OT_ERROR_ALREADY:
case kErrorAlready:
otLogDebgMac("Data poll tx requested when a previous data request still in send queue.");
ScheduleNextPoll(kUsePreviousPollPeriod);
break;
default:
otLogWarnMac("Unexpected error %s requesting data poll", otThreadErrorToString(error));
otLogWarnMac("Unexpected error %s requesting data poll", ErrorToString(error));
ScheduleNextPoll(kRecalculatePollPeriod);
break;
}
@@ -136,15 +136,15 @@ exit:
}
#if OPENTHREAD_CONFIG_MULTI_RADIO
otError DataPollSender::GetPollDestinationAddress(Mac::Address &aDest, Mac::RadioType &aRadioType) const
Error DataPollSender::GetPollDestinationAddress(Mac::Address &aDest, Mac::RadioType &aRadioType) const
#else
otError DataPollSender::GetPollDestinationAddress(Mac::Address &aDest) const
Error DataPollSender::GetPollDestinationAddress(Mac::Address &aDest) const
#endif
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
const Neighbor &parent = GetParent();
VerifyOrExit(parent.IsStateValidOrRestoring(), error = OT_ERROR_ABORT);
VerifyOrExit(parent.IsStateValidOrRestoring(), error = kErrorAbort);
// Use extended address attaching to a new parent (i.e. parent is the parent candidate).
if ((Get<Mac::Mac>().GetShortAddress() == Mac::kShortAddrInvalid) ||
@@ -165,13 +165,13 @@ exit:
return error;
}
otError DataPollSender::SetExternalPollPeriod(uint32_t aPeriod)
Error DataPollSender::SetExternalPollPeriod(uint32_t aPeriod)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
if (aPeriod != 0)
{
VerifyOrExit(aPeriod >= OPENTHREAD_CONFIG_MAC_MINIMUM_POLL_PERIOD, error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(aPeriod >= OPENTHREAD_CONFIG_MAC_MINIMUM_POLL_PERIOD, error = kErrorInvalidArgs);
// Clipped by the maximal value.
if (aPeriod > kMaxExternalPeriod)
@@ -206,7 +206,7 @@ uint32_t DataPollSender::GetKeepAlivePollPeriod(void) const
return period;
}
void DataPollSender::HandlePollSent(Mac::TxFrame &aFrame, otError aError)
void DataPollSender::HandlePollSent(Mac::TxFrame &aFrame, Error aError)
{
Mac::Address macDest;
bool shouldRecalculatePollPeriod = false;
@@ -228,7 +228,7 @@ void DataPollSender::HandlePollSent(Mac::TxFrame &aFrame, otError aError)
switch (aError)
{
case OT_ERROR_NONE:
case kErrorNone:
if (mRemainingFastPolls != 0)
{
@@ -250,8 +250,8 @@ void DataPollSender::HandlePollSent(Mac::TxFrame &aFrame, otError aError)
break;
case OT_ERROR_CHANNEL_ACCESS_FAILURE:
case OT_ERROR_ABORT:
case kErrorChannelAccessFailure:
case kErrorAbort:
mRetxMode = true;
shouldRecalculatePollPeriod = true;
break;
@@ -259,8 +259,8 @@ void DataPollSender::HandlePollSent(Mac::TxFrame &aFrame, otError aError)
default:
mPollTxFailureCounter++;
otLogInfoMac("Failed to send data poll, error:%s, retx:%d/%d", otThreadErrorToString(aError),
mPollTxFailureCounter, kMaxPollRetxAttempts);
otLogInfoMac("Failed to send data poll, error:%s, retx:%d/%d", ErrorToString(aError), mPollTxFailureCounter,
kMaxPollRetxAttempts);
if (mPollTxFailureCounter < kMaxPollRetxAttempts)
{
+16 -16
View File
@@ -92,13 +92,13 @@ public:
/**
* This method enqueues a data poll (an IEEE 802.15.4 Data Request) message.
*
* @retval OT_ERROR_NONE Successfully enqueued a data poll message
* @retval OT_ERROR_ALREADY A data poll message is already enqueued.
* @retval OT_ERROR_INVALID_STATE Device is not in rx-off-when-idle mode.
* @retval OT_ERROR_NO_BUFS Insufficient message buffers available.
* @retval kErrorNone Successfully enqueued a data poll message
* @retval kErrorAlready A data poll message is already enqueued.
* @retval kErrorInvalidState Device is not in rx-off-when-idle mode.
* @retval kErrorNoBufs Insufficient message buffers available.
*
*/
otError SendDataPoll(void);
Error SendDataPoll(void);
/**
* This method sets/clears a user-specified/external data poll period.
@@ -111,16 +111,16 @@ public:
* value is larger than the child timeout.
*
* A non-zero `aPeriod` should be larger than or equal to `OPENTHREAD_CONFIG_MAC_MINIMUM_POLL_PERIOD` (10ms) or
* this method returns `OT_ERROR_INVALID_ARGS`. If a non-zero `aPeriod` is larger than maximum value of
* this method returns `kErrorInvalidArgs`. If a non-zero `aPeriod` is larger than maximum value of
* `0x3FFFFFF ((1 << 26) - 1)`, it would be clipped to this value.
*
* @param[in] aPeriod The data poll period in milliseconds.
*
* @retval OT_ERROR_NONE Successfully set/cleared user-specified poll period.
* @retval OT_ERROR_INVALID_ARGS If aPeriod is invalid.
* @retval kErrorNone Successfully set/cleared user-specified poll period.
* @retval kErrorInvalidArgs If aPeriod is invalid.
*
*/
otError SetExternalPollPeriod(uint32_t aPeriod);
Error SetExternalPollPeriod(uint32_t aPeriod);
/**
* This method gets the current user-specified/external data poll period.
@@ -137,22 +137,22 @@ public:
* @param[out] aDest Reference to a `MAC::Address` to output the poll destination address (on success).
* @param[out] aRadioType Reference to a `Mac::RadioType` to output the link type (on success).
*
* @retval OT_ERROR_NONE @p aDest and @p aRadioType were updated successfully.
* @retval OT_ERROR_ABORT Abort the data poll transmission (not currently attached to any parent).
* @retval kErrorNone @p aDest and @p aRadioType were updated successfully.
* @retval kErrorAbort Abort the data poll transmission (not currently attached to any parent).
*
*/
otError GetPollDestinationAddress(Mac::Address &aDest, Mac::RadioType &aRadioType) const;
Error GetPollDestinationAddress(Mac::Address &aDest, Mac::RadioType &aRadioType) const;
#else
/**
* This method gets the destination MAC address for a data poll frame.
*
* @param[out] aDest Reference to a `MAC::Address` to output the poll destination address (on success).
*
* @retval OT_ERROR_NONE @p aDest was updated successfully.
* @retval OT_ERROR_ABORT Abort the data poll transmission (not currently attached to any parent).
* @retval kErrorNone @p aDest was updated successfully.
* @retval kErrorAbort Abort the data poll transmission (not currently attached to any parent).
*
*/
otError GetPollDestinationAddress(Mac::Address &aDest) const;
Error GetPollDestinationAddress(Mac::Address &aDest) const;
#endif // #if OPENTHREAD_CONFIG_MULTI_RADIO
/**
@@ -166,7 +166,7 @@ public:
* @param[in] aError Error status of a data poll message transmission.
*
*/
void HandlePollSent(Mac::TxFrame &aFrame, otError aError);
void HandlePollSent(Mac::TxFrame &aFrame, Error aError);
/**
* This method informs the data poll sender that a data poll timeout happened, i.e., when the ack in response to
+44 -44
View File
@@ -64,15 +64,15 @@ LinkRaw::LinkRaw(Instance &aInstance)
{
}
otError LinkRaw::SetReceiveDone(otLinkRawReceiveDone aCallback)
Error LinkRaw::SetReceiveDone(otLinkRawReceiveDone aCallback)
{
otError error = OT_ERROR_NONE;
bool enable = aCallback != nullptr;
Error error = kErrorNone;
bool enable = aCallback != nullptr;
otLogDebgMac("LinkRaw::Enabled(%s)", (enable ? "true" : "false"));
#if OPENTHREAD_MTD || OPENTHREAD_FTD
VerifyOrExit(!Get<ThreadNetif>().IsUp(), error = OT_ERROR_INVALID_STATE);
VerifyOrExit(!Get<ThreadNetif>().IsUp(), error = kErrorInvalidState);
// In MTD/FTD build, `Mac` has already enabled sub-mac. We ensure to
// disable/enable MAC layer when link-raw is being enabled/disabled to
@@ -84,7 +84,7 @@ otError LinkRaw::SetReceiveDone(otLinkRawReceiveDone aCallback)
// When disabling link-raw, make sure there is no ongoing
// transmit or scan operation. Otherwise Mac will attempt to
// handle an unexpected "done" callback.
VerifyOrExit(!mSubMac.IsTransmittingOrScanning(), error = OT_ERROR_BUSY);
VerifyOrExit(!mSubMac.IsTransmittingOrScanning(), error = kErrorBusy);
}
Get<Mac>().SetEnabled(!enable);
@@ -105,11 +105,11 @@ exit:
return error;
}
otError LinkRaw::SetPanId(uint16_t aPanId)
Error LinkRaw::SetPanId(uint16_t aPanId)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
VerifyOrExit(IsEnabled(), error = OT_ERROR_INVALID_STATE);
VerifyOrExit(IsEnabled(), error = kErrorInvalidState);
mSubMac.SetPanId(aPanId);
mPanId = aPanId;
@@ -117,44 +117,44 @@ exit:
return error;
}
otError LinkRaw::SetChannel(uint8_t aChannel)
Error LinkRaw::SetChannel(uint8_t aChannel)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
VerifyOrExit(IsEnabled(), error = OT_ERROR_INVALID_STATE);
VerifyOrExit(IsEnabled(), error = kErrorInvalidState);
mReceiveChannel = aChannel;
exit:
return error;
}
otError LinkRaw::SetExtAddress(const ExtAddress &aExtAddress)
Error LinkRaw::SetExtAddress(const ExtAddress &aExtAddress)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
VerifyOrExit(IsEnabled(), error = OT_ERROR_INVALID_STATE);
VerifyOrExit(IsEnabled(), error = kErrorInvalidState);
mSubMac.SetExtAddress(aExtAddress);
exit:
return error;
}
otError LinkRaw::SetShortAddress(ShortAddress aShortAddress)
Error LinkRaw::SetShortAddress(ShortAddress aShortAddress)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
VerifyOrExit(IsEnabled(), error = OT_ERROR_INVALID_STATE);
VerifyOrExit(IsEnabled(), error = kErrorInvalidState);
mSubMac.SetShortAddress(aShortAddress);
exit:
return error;
}
otError LinkRaw::Receive(void)
Error LinkRaw::Receive(void)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
VerifyOrExit(IsEnabled(), error = OT_ERROR_INVALID_STATE);
VerifyOrExit(IsEnabled(), error = kErrorInvalidState);
SuccessOrExit(error = mSubMac.Receive(mReceiveChannel));
@@ -162,22 +162,22 @@ exit:
return error;
}
void LinkRaw::InvokeReceiveDone(RxFrame *aFrame, otError aError)
void LinkRaw::InvokeReceiveDone(RxFrame *aFrame, Error aError)
{
otLogDebgMac("LinkRaw::ReceiveDone(%d bytes), error:%s", (aFrame != nullptr) ? aFrame->mLength : 0,
otThreadErrorToString(aError));
ErrorToString(aError));
if (mReceiveDoneCallback && (aError == OT_ERROR_NONE))
if (mReceiveDoneCallback && (aError == kErrorNone))
{
mReceiveDoneCallback(&GetInstance(), aFrame, aError);
}
}
otError LinkRaw::Transmit(otLinkRawTransmitDone aCallback)
Error LinkRaw::Transmit(otLinkRawTransmitDone aCallback)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
VerifyOrExit(IsEnabled(), error = OT_ERROR_INVALID_STATE);
VerifyOrExit(IsEnabled(), error = kErrorInvalidState);
SuccessOrExit(error = mSubMac.Send());
mTransmitDoneCallback = aCallback;
@@ -186,9 +186,9 @@ exit:
return error;
}
void LinkRaw::InvokeTransmitDone(TxFrame &aFrame, RxFrame *aAckFrame, otError aError)
void LinkRaw::InvokeTransmitDone(TxFrame &aFrame, RxFrame *aAckFrame, Error aError)
{
otLogDebgMac("LinkRaw::TransmitDone(%d bytes), error:%s", aFrame.mLength, otThreadErrorToString(aError));
otLogDebgMac("LinkRaw::TransmitDone(%d bytes), error:%s", aFrame.mLength, ErrorToString(aError));
if (mTransmitDoneCallback)
{
@@ -197,11 +197,11 @@ void LinkRaw::InvokeTransmitDone(TxFrame &aFrame, RxFrame *aAckFrame, otError aE
}
}
otError LinkRaw::EnergyScan(uint8_t aScanChannel, uint16_t aScanDuration, otLinkRawEnergyScanDone aCallback)
Error LinkRaw::EnergyScan(uint8_t aScanChannel, uint16_t aScanDuration, otLinkRawEnergyScanDone aCallback)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
VerifyOrExit(IsEnabled(), error = OT_ERROR_INVALID_STATE);
VerifyOrExit(IsEnabled(), error = kErrorInvalidState);
SuccessOrExit(error = mSubMac.EnergyScan(aScanChannel, aScanDuration));
mEnergyScanDoneCallback = aCallback;
@@ -219,26 +219,26 @@ void LinkRaw::InvokeEnergyScanDone(int8_t aEnergyScanMaxRssi)
}
}
otError LinkRaw::SetMacKey(uint8_t aKeyIdMode,
uint8_t aKeyId,
const Key &aPrevKey,
const Key &aCurrKey,
const Key &aNextKey)
Error LinkRaw::SetMacKey(uint8_t aKeyIdMode,
uint8_t aKeyId,
const Key &aPrevKey,
const Key &aCurrKey,
const Key &aNextKey)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
VerifyOrExit(IsEnabled(), error = OT_ERROR_INVALID_STATE);
VerifyOrExit(IsEnabled(), error = kErrorInvalidState);
mSubMac.SetMacKey(aKeyIdMode, aKeyId, aPrevKey, aCurrKey, aNextKey);
exit:
return error;
}
otError LinkRaw::SetMacFrameCounter(uint32_t aMacFrameCounter)
Error LinkRaw::SetMacFrameCounter(uint32_t aMacFrameCounter)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
VerifyOrExit(IsEnabled(), error = OT_ERROR_INVALID_STATE);
VerifyOrExit(IsEnabled(), error = kErrorInvalidState);
mSubMac.SetFrameCounter(aMacFrameCounter);
exit:
@@ -251,16 +251,16 @@ exit:
void LinkRaw::RecordFrameTransmitStatus(const TxFrame &aFrame,
const RxFrame *aAckFrame,
otError aError,
Error aError,
uint8_t aRetryCount,
bool aWillRetx)
{
OT_UNUSED_VARIABLE(aAckFrame);
OT_UNUSED_VARIABLE(aWillRetx);
if (aError != OT_ERROR_NONE)
if (aError != kErrorNone)
{
otLogInfoMac("Frame tx failed, error:%s, retries:%d/%d, %s", otThreadErrorToString(aError), aRetryCount,
otLogInfoMac("Frame tx failed, error:%s, retries:%d/%d, %s", ErrorToString(aError), aRetryCount,
aFrame.GetMaxFrameRetries(), aFrame.ToInfoString().AsCString());
}
}
+46 -50
View File
@@ -80,12 +80,12 @@ public:
* raw link-layer.
*
*
* @retval OT_ERROR_INVALID_STATE Thread stack is enabled.
* @retval OT_ERROR_FAILED The radio could not be enabled/disabled.
* @retval OT_ERROR_NONE Successfully enabled/disabled raw link.
* @retval kErrorInvalidState Thread stack is enabled.
* @retval kErrorFailed The radio could not be enabled/disabled.
* @retval kErrorNone Successfully enabled/disabled raw link.
*
*/
otError SetReceiveDone(otLinkRawReceiveDone aCallback);
Error SetReceiveDone(otLinkRawReceiveDone aCallback);
/**
* This method returns the capabilities of the raw link-layer.
@@ -98,22 +98,22 @@ public:
/**
* This method starts a (recurring) Receive on the link-layer.
*
* @retval OT_ERROR_NONE Successfully transitioned to Receive.
* @retval OT_ERROR_INVALID_STATE The radio was disabled or transmitting.
* @retval kErrorNone Successfully transitioned to Receive.
* @retval kErrorInvalidState The radio was disabled or transmitting.
*
*/
otError Receive(void);
Error Receive(void);
/**
* This method invokes the mReceiveDoneCallback, if set.
*
* @param[in] aFrame A pointer to the received frame or nullptr if the receive operation failed.
* @param[in] aError OT_ERROR_NONE when successfully received a frame,
* OT_ERROR_ABORT when reception was aborted and a frame was not received,
* OT_ERROR_NO_BUFS when a frame could not be received due to lack of rx buffer space.
* @param[in] aError kErrorNone when successfully received a frame,
* kErrorAbort when reception was aborted and a frame was not received,
* kErrorNoBufs when a frame could not be received due to lack of rx buffer space.
*
*/
void InvokeReceiveDone(RxFrame *aFrame, otError aError);
void InvokeReceiveDone(RxFrame *aFrame, Error aError);
/**
* This method gets the radio transmit frame.
@@ -126,28 +126,28 @@ public:
/**
* This method starts a (single) Transmit on the link-layer.
*
* @note The callback @p aCallback will not be called if this call does not return OT_ERROR_NONE.
* @note The callback @p aCallback will not be called if this call does not return kErrorNone.
*
* @param[in] aCallback A pointer to a function called on completion of the transmission.
*
* @retval OT_ERROR_NONE Successfully transitioned to Transmit.
* @retval OT_ERROR_INVALID_STATE The radio was not in the Receive state.
* @retval kErrorNone Successfully transitioned to Transmit.
* @retval kErrorInvalidState The radio was not in the Receive state.
*
*/
otError Transmit(otLinkRawTransmitDone aCallback);
Error Transmit(otLinkRawTransmitDone aCallback);
/**
* This method invokes the mTransmitDoneCallback, if set.
*
* @param[in] aFrame The transmitted frame.
* @param[in] aAckFrame A pointer to the ACK frame, nullptr if no ACK was received.
* @param[in] aError OT_ERROR_NONE when the frame was transmitted,
* OT_ERROR_NO_ACK when the frame was transmitted but no ACK was received,
* OT_ERROR_CHANNEL_ACCESS_FAILURE tx failed due to activity on the channel,
* OT_ERROR_ABORT when transmission was aborted for other reasons.
* @param[in] aError kErrorNone when the frame was transmitted,
* kErrorNoAck when the frame was transmitted but no ACK was received,
* kErrorChannelAccessFailure tx failed due to activity on the channel,
* kErrorAbort when transmission was aborted for other reasons.
*
*/
void InvokeTransmitDone(TxFrame &aFrame, RxFrame *aAckFrame, otError aError);
void InvokeTransmitDone(TxFrame &aFrame, RxFrame *aAckFrame, Error aError);
/**
* This method starts a (single) Energy Scan on the link-layer.
@@ -156,12 +156,12 @@ public:
* @param[in] aScanDuration The duration, in milliseconds, for the channel to be scanned.
* @param[in] aCallback A pointer to a function called on completion of a scanned channel.
*
* @retval OT_ERROR_NONE Successfully started scanning the channel.
* @retval OT_ERROR_NOT_IMPLEMENTED The radio doesn't support energy scanning.
* @retval OT_ERROR_INVALID_STATE If the raw link-layer isn't enabled.
* @retval kErrorNone Successfully started scanning the channel.
* @retval kErrorNotImplemented The radio doesn't support energy scanning.
* @retval kErrorInvalidState If the raw link-layer isn't enabled.
*
*/
otError EnergyScan(uint8_t aScanChannel, uint16_t aScanDuration, otLinkRawEnergyScanDone aCallback);
Error EnergyScan(uint8_t aScanChannel, uint16_t aScanDuration, otLinkRawEnergyScanDone aCallback);
/**
* This method invokes the mEnergyScanDoneCallback, if set.
@@ -184,11 +184,11 @@ public:
*
* @param[in] aShortAddress The short address.
*
* @retval OT_ERROR_NONE If successful.
* @retval OT_ERROR_INVALID_STATE If the raw link-layer isn't enabled.
* @retval kErrorNone If successful.
* @retval kErrorInvalidState If the raw link-layer isn't enabled.
*
*/
otError SetShortAddress(ShortAddress aShortAddress);
Error SetShortAddress(ShortAddress aShortAddress);
/**
* This function returns PANID.
@@ -203,11 +203,11 @@ public:
*
* @param[in] aPanId The PANID.
*
* @retval OT_ERROR_NONE If successful.
* @retval OT_ERROR_INVALID_STATE If the raw link-layer isn't enabled.
* @retval kErrorNone If successful.
* @retval kErrorInvalidState If the raw link-layer isn't enabled.
*
*/
otError SetPanId(PanId aPanId);
Error SetPanId(PanId aPanId);
/**
* This method gets the current receiving channel.
@@ -223,7 +223,7 @@ public:
* @param[in] aChannel The channel to use for receiving.
*
*/
otError SetChannel(uint8_t aChannel);
Error SetChannel(uint8_t aChannel);
/**
* This function returns the extended address.
@@ -238,11 +238,11 @@ public:
*
* @param[in] aExtAddress The extended address.
*
* @retval OT_ERROR_NONE If successful.
* @retval OT_ERROR_INVALID_STATE If the raw link-layer isn't enabled.
* @retval kErrorNone If successful.
* @retval kErrorInvalidState If the raw link-layer isn't enabled.
*
*/
otError SetExtAddress(const ExtAddress &aExtAddress);
Error SetExtAddress(const ExtAddress &aExtAddress);
/**
* This method updates MAC keys and key index.
@@ -253,26 +253,22 @@ public:
* @param[in] aCurrKey The current MAC key.
* @param[in] aNextKey The next MAC key.
*
* @retval OT_ERROR_NONE If successful.
* @retval OT_ERROR_INVALID_STATE If the raw link-layer isn't enabled.
* @retval kErrorNone If successful.
* @retval kErrorInvalidState If the raw link-layer isn't enabled.
*
*/
otError SetMacKey(uint8_t aKeyIdMode,
uint8_t aKeyId,
const Key &aPrevKey,
const Key &aCurrKey,
const Key &aNextKey);
Error SetMacKey(uint8_t aKeyIdMode, uint8_t aKeyId, const Key &aPrevKey, const Key &aCurrKey, const Key &aNextKey);
/**
* This method sets the current MAC frame counter value.
*
* @param[in] aMacFrameCounter The MAC frame counter value.
*
* @retval OT_ERROR_NONE If successful.
* @retval OT_ERROR_INVALID_STATE If the raw link-layer isn't enabled.
* @retval kErrorNone If successful.
* @retval kErrorInvalidState If the raw link-layer isn't enabled.
*
*/
otError SetMacFrameCounter(uint32_t aMacFrameCounter);
Error SetMacFrameCounter(uint32_t aMacFrameCounter);
/**
* This method records the status of a frame transmission attempt and is mainly used for logging failures.
@@ -282,10 +278,10 @@ public:
*
* @param[in] aFrame The transmitted frame.
* @param[in] aAckFrame A pointer to the ACK frame, or nullptr if no ACK was received.
* @param[in] aError OT_ERROR_NONE when the frame was transmitted successfully,
* OT_ERROR_NO_ACK when the frame was transmitted but no ACK was received,
* OT_ERROR_CHANNEL_ACCESS_FAILURE tx failed due to activity on the channel,
* OT_ERROR_ABORT when transmission was aborted for other reasons.
* @param[in] aError kErrorNone when the frame was transmitted successfully,
* kErrorNoAck when the frame was transmitted but no ACK was received,
* kErrorChannelAccessFailure tx failed due to activity on the channel,
* kErrorAbort when transmission was aborted for other reasons.
* @param[in] aRetryCount Indicates number of transmission retries for this frame.
* @param[in] aWillRetx Indicates whether frame will be retransmitted or not. This is applicable only
* when there was an error in transmission (i.e., `aError` is not NONE).
@@ -294,11 +290,11 @@ public:
#if (OPENTHREAD_CONFIG_LOG_LEVEL >= OT_LOG_LEVEL_INFO) && (OPENTHREAD_CONFIG_LOG_MAC == 1)
void RecordFrameTransmitStatus(const TxFrame &aFrame,
const RxFrame *aAckFrame,
otError aError,
Error aError,
uint8_t aRetryCount,
bool aWillRetx);
#else
void RecordFrameTransmitStatus(const TxFrame &, const RxFrame *, otError, uint8_t, bool) {}
void RecordFrameTransmitStatus(const TxFrame &, const RxFrame *, Error, uint8_t, bool) {}
#endif
private:
+126 -128
View File
@@ -124,7 +124,7 @@ Mac::Mac(Instance &aInstance)
, mKeyIdMode2FrameCounter(0)
, mCcaSampleCount(0)
#if OPENTHREAD_CONFIG_MULTI_RADIO
, mTxError(OT_ERROR_NONE)
, mTxError(kErrorNone)
#endif
{
ExtAddress randomExtAddress;
@@ -149,12 +149,12 @@ Mac::Mac(Instance &aInstance)
SetShortAddress(GetShortAddress());
}
otError Mac::ActiveScan(uint32_t aScanChannels, uint16_t aScanDuration, ActiveScanHandler aHandler, void *aContext)
Error Mac::ActiveScan(uint32_t aScanChannels, uint16_t aScanDuration, ActiveScanHandler aHandler, void *aContext)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
VerifyOrExit(IsEnabled(), error = OT_ERROR_INVALID_STATE);
VerifyOrExit(!IsActiveScanInProgress() && !IsEnergyScanInProgress(), error = OT_ERROR_BUSY);
VerifyOrExit(IsEnabled(), error = kErrorInvalidState);
VerifyOrExit(!IsActiveScanInProgress() && !IsEnergyScanInProgress(), error = kErrorBusy);
mActiveScanHandler = aHandler;
mScanHandlerContext = aContext;
@@ -170,12 +170,12 @@ exit:
return error;
}
otError Mac::EnergyScan(uint32_t aScanChannels, uint16_t aScanDuration, EnergyScanHandler aHandler, void *aContext)
Error Mac::EnergyScan(uint32_t aScanChannels, uint16_t aScanDuration, EnergyScanHandler aHandler, void *aContext)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
VerifyOrExit(IsEnabled(), error = OT_ERROR_INVALID_STATE);
VerifyOrExit(!IsActiveScanInProgress() && !IsEnergyScanInProgress(), error = OT_ERROR_BUSY);
VerifyOrExit(IsEnabled(), error = kErrorInvalidState);
VerifyOrExit(!IsActiveScanInProgress() && !IsEnergyScanInProgress(), error = kErrorBusy);
mEnergyScanHandler = aHandler;
mScanHandlerContext = aContext;
@@ -231,9 +231,9 @@ bool Mac::IsInTransmitState(void) const
return retval;
}
otError Mac::ConvertBeaconToActiveScanResult(const RxFrame *aBeaconFrame, ActiveScanResult &aResult)
Error Mac::ConvertBeaconToActiveScanResult(const RxFrame *aBeaconFrame, ActiveScanResult &aResult)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Address address;
const Beacon * beacon = nullptr;
const BeaconPayload *beaconPayload = nullptr;
@@ -241,14 +241,14 @@ otError Mac::ConvertBeaconToActiveScanResult(const RxFrame *aBeaconFrame, Active
memset(&aResult, 0, sizeof(ActiveScanResult));
VerifyOrExit(aBeaconFrame != nullptr, error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(aBeaconFrame != nullptr, error = kErrorInvalidArgs);
VerifyOrExit(aBeaconFrame->GetType() == Frame::kFcfFrameBeacon, error = OT_ERROR_PARSE);
VerifyOrExit(aBeaconFrame->GetType() == Frame::kFcfFrameBeacon, error = kErrorParse);
SuccessOrExit(error = aBeaconFrame->GetSrcAddr(address));
VerifyOrExit(address.IsExtended(), error = OT_ERROR_PARSE);
VerifyOrExit(address.IsExtended(), error = kErrorParse);
aResult.mExtAddress = address.GetExtended();
if (OT_ERROR_NONE != aBeaconFrame->GetSrcPanId(aResult.mPanId))
if (kErrorNone != aBeaconFrame->GetSrcPanId(aResult.mPanId))
{
IgnoreError(aBeaconFrame->GetDstPanId(aResult.mPanId));
}
@@ -268,7 +268,7 @@ otError Mac::ConvertBeaconToActiveScanResult(const RxFrame *aBeaconFrame, Active
aResult.mIsJoinable = beaconPayload->IsJoiningPermitted();
aResult.mIsNative = beaconPayload->IsNative();
IgnoreError(static_cast<NetworkName &>(aResult.mNetworkName).Set(beaconPayload->GetNetworkName()));
VerifyOrExit(IsValidUtf8String(aResult.mNetworkName.m8), error = OT_ERROR_PARSE);
VerifyOrExit(IsValidUtf8String(aResult.mNetworkName.m8), error = kErrorParse);
aResult.mExtendedPanId = beaconPayload->GetExtendedPanId();
}
@@ -278,11 +278,11 @@ exit:
return error;
}
otError Mac::UpdateScanChannel(void)
Error Mac::UpdateScanChannel(void)
{
otError error;
Error error;
VerifyOrExit(IsEnabled(), error = OT_ERROR_ABORT);
VerifyOrExit(IsEnabled(), error = kErrorAbort);
error = mScanChannelMask.GetNextChannel(mScanChannel);
@@ -292,7 +292,7 @@ exit:
void Mac::PerformActiveScan(void)
{
if (UpdateScanChannel() == OT_ERROR_NONE)
if (UpdateScanChannel() == kErrorNone)
{
// If there are more channels to scan, send the beacon request.
BeginTransmit();
@@ -328,7 +328,7 @@ exit:
void Mac::PerformEnergyScan(void)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
SuccessOrExit(error = UpdateScanChannel());
@@ -348,7 +348,7 @@ void Mac::PerformEnergyScan(void)
exit:
if (error != OT_ERROR_NONE)
if (error != kErrorNone)
{
FinishOperation();
@@ -420,11 +420,11 @@ exit:
return;
}
otError Mac::SetPanChannel(uint8_t aChannel)
Error Mac::SetPanChannel(uint8_t aChannel)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
VerifyOrExit(mSupportedChannelMask.ContainsChannel(aChannel), error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(mSupportedChannelMask.ContainsChannel(aChannel), error = kErrorInvalidArgs);
SuccessOrExit(Get<Notifier>().Update(mPanChannel, aChannel, kEventThreadChannelChanged));
@@ -440,11 +440,11 @@ exit:
return error;
}
otError Mac::SetTemporaryChannel(uint8_t aChannel)
Error Mac::SetTemporaryChannel(uint8_t aChannel)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
VerifyOrExit(mSupportedChannelMask.ContainsChannel(aChannel), error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(mSupportedChannelMask.ContainsChannel(aChannel), error = kErrorInvalidArgs);
mUsingTemporaryChannel = true;
mRadioChannel = aChannel;
@@ -473,7 +473,7 @@ void Mac::SetSupportedChannelMask(const ChannelMask &aMask)
IgnoreError(Get<Notifier>().Update(mSupportedChannelMask, newMask, kEventSupportedChannelMaskChanged));
}
otError Mac::SetNetworkName(const char *aNameString)
Error Mac::SetNetworkName(const char *aNameString)
{
// When setting Network Name from a string, we treat it as `NameData`
// with `kMaxSize + 1` chars. `NetworkName::Set(data)` will look
@@ -481,12 +481,12 @@ otError Mac::SetNetworkName(const char *aNameString)
// the name's length and ensure that the name fits in `kMaxSize`
// chars. The `+ 1` ensures that a `aNameString` with length
// longer than `kMaxSize` is correctly rejected (returning error
// `OT_ERROR_INVALID_ARGS`).
// `kErrorInvalidArgs`).
otError error;
Error error;
NameData data(aNameString, NetworkName::kMaxSize + 1);
VerifyOrExit(IsValidUtf8String(aNameString), error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(IsValidUtf8String(aNameString), error = kErrorInvalidArgs);
error = SetNetworkName(data);
@@ -494,14 +494,14 @@ exit:
return error;
}
otError Mac::SetNetworkName(const NameData &aNameData)
Error Mac::SetNetworkName(const NameData &aNameData)
{
otError error = mNetworkName.Set(aNameData);
Error error = mNetworkName.Set(aNameData);
if (error == OT_ERROR_ALREADY)
if (error == kErrorAlready)
{
Get<Notifier>().SignalIfFirst(kEventThreadNetworkNameChanged);
error = OT_ERROR_NONE;
error = kErrorNone;
ExitNow();
}
@@ -513,7 +513,7 @@ exit:
}
#if (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)
otError Mac::SetDomainName(const char *aNameString)
Error Mac::SetDomainName(const char *aNameString)
{
// When setting Domain Name from a string, we treat it as `NameData`
// with `kMaxSize + 1` chars. `DomainName::Set(data)` will look
@@ -521,12 +521,12 @@ otError Mac::SetDomainName(const char *aNameString)
// the name's length and ensure that the name fits in `kMaxSize`
// chars. The `+ 1` ensures that a `aNameString` with length
// longer than `kMaxSize` is correctly rejected (returning error
// `OT_ERROR_INVALID_ARGS`).
// `kErrorInvalidArgs`).
otError error;
Error error;
NameData data(aNameString, DomainName::kMaxSize + 1);
VerifyOrExit(IsValidUtf8String(aNameString), error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(IsValidUtf8String(aNameString), error = kErrorInvalidArgs);
error = SetDomainName(data);
@@ -534,13 +534,13 @@ exit:
return error;
}
otError Mac::SetDomainName(const NameData &aNameData)
Error Mac::SetDomainName(const NameData &aNameData)
{
otError error = mDomainName.Set(aNameData);
Error error = mDomainName.Set(aNameData);
if (error == OT_ERROR_ALREADY)
if (error == kErrorAlready)
{
error = OT_ERROR_NONE;
error = kErrorNone;
}
return error;
@@ -599,14 +599,13 @@ exit:
#endif
#endif // OPENTHREAD_FTD
otError Mac::RequestOutOfBandFrameTransmission(otRadioFrame *aOobFrame)
Error Mac::RequestOutOfBandFrameTransmission(otRadioFrame *aOobFrame)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
VerifyOrExit(aOobFrame != nullptr, error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(IsEnabled(), error = OT_ERROR_INVALID_STATE);
VerifyOrExit(!mPendingTransmitOobFrame && (mOperation != kOperationTransmitOutOfBandFrame),
error = OT_ERROR_ALREADY);
VerifyOrExit(aOobFrame != nullptr, error = kErrorInvalidArgs);
VerifyOrExit(IsEnabled(), error = kErrorInvalidState);
VerifyOrExit(!mPendingTransmitOobFrame && (mOperation != kOperationTransmitOutOfBandFrame), error = kErrorAlready);
mOobFrame = static_cast<TxFrame *>(aOobFrame);
@@ -616,12 +615,12 @@ exit:
return error;
}
otError Mac::RequestDataPollTransmission(void)
Error Mac::RequestDataPollTransmission(void)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
VerifyOrExit(IsEnabled(), error = OT_ERROR_INVALID_STATE);
VerifyOrExit(!mPendingTransmitPoll && (mOperation != kOperationTransmitPoll), error = OT_ERROR_ALREADY);
VerifyOrExit(IsEnabled(), error = kErrorInvalidState);
VerifyOrExit(!mPendingTransmitPoll && (mOperation != kOperationTransmitPoll), error = kErrorAlready);
// We ensure data frame and data poll tx requests are handled in the
// order they are requested. So if we have a pending direct data frame
@@ -1149,7 +1148,7 @@ void Mac::BeginTransmit(void)
#if OPENTHREAD_CONFIG_MULTI_RADIO
mTxPendingRadioLinks.Clear();
mTxError = OT_ERROR_ABORT;
mTxError = kErrorAbort;
#endif
VerifyOrExit(IsEnabled());
@@ -1300,15 +1299,15 @@ void Mac::BeginTransmit(void)
mTxPendingRadioLinks = txFrames.GetSelectedRadioTypes();
// If the "required radio type set" is empty,`mTxError` starts as
// `OT_ERROR_ABORT`. In this case, successful tx over any radio
// `kErrorAbort`. In this case, successful tx over any radio
// link is sufficient for overall tx to be considered successful.
// When the "required radio type set" is not empty, `mTxError`
// starts as `OT_ERROR_NONE` and we update it if tx over any link
// starts as `kErrorNone` and we update it if tx over any link
// in the required set fails.
if (!txFrames.GetRequiredRadioTypes().IsEmpty())
{
mTxError = OT_ERROR_NONE;
mTxError = kErrorNone;
}
#endif
@@ -1338,7 +1337,7 @@ exit:
frame = &txFrames.GetBroadcastTxFrame();
frame->SetLength(0);
HandleTransmitDone(*frame, nullptr, OT_ERROR_ABORT);
HandleTransmitDone(*frame, nullptr, kErrorAbort);
}
}
@@ -1365,7 +1364,7 @@ void Mac::RecordCcaStatus(bool aCcaSuccess, uint8_t aChannel)
void Mac::RecordFrameTransmitStatus(const TxFrame &aFrame,
const RxFrame *aAckFrame,
otError aError,
Error aError,
uint8_t aRetryCount,
bool aWillRetx)
{
@@ -1390,12 +1389,12 @@ void Mac::RecordFrameTransmitStatus(const TxFrame &aFrame,
switch (aError)
{
case OT_ERROR_NO_ACK:
case kErrorNoAck:
frameTxSuccess = false;
OT_FALL_THROUGH;
case OT_ERROR_NONE:
case kErrorNone:
neighbor->GetLinkInfo().AddFrameTxStatus(frameTxSuccess);
break;
@@ -1406,7 +1405,7 @@ void Mac::RecordFrameTransmitStatus(const TxFrame &aFrame,
// Log frame transmission failure.
if (aError != OT_ERROR_NONE)
if (aError != kErrorNone)
{
LogFrameTxFailure(aFrame, aError, aRetryCount, aWillRetx);
otDumpDebgMac("TX ERR", aFrame.GetHeader(), 16);
@@ -1425,7 +1424,7 @@ void Mac::RecordFrameTransmitStatus(const TxFrame &aFrame,
// Update neighbor's RSSI link info from the received Ack.
if ((aError == OT_ERROR_NONE) && ackRequested && (aAckFrame != nullptr) && (neighbor != nullptr))
if ((aError == kErrorNone) && ackRequested && (aAckFrame != nullptr) && (neighbor != nullptr))
{
neighbor->GetLinkInfo().AddRss(aAckFrame->GetRssi());
#if OPENTHREAD_CONFIG_MLE_LINK_METRICS_ENABLE
@@ -1447,12 +1446,12 @@ void Mac::RecordFrameTransmitStatus(const TxFrame &aFrame,
mCounters.mTxTotal++;
if (aError == OT_ERROR_ABORT)
if (aError == kErrorAbort)
{
mCounters.mTxErrAbort++;
}
if (aError == OT_ERROR_CHANNEL_ACCESS_FAILURE)
if (aError == kErrorChannelAccessFailure)
{
mCounters.mTxErrBusyChannel++;
}
@@ -1461,7 +1460,7 @@ void Mac::RecordFrameTransmitStatus(const TxFrame &aFrame,
{
mCounters.mTxAckRequested++;
if (aError == OT_ERROR_NONE)
if (aError == kErrorNone)
{
mCounters.mTxAcked++;
}
@@ -1484,7 +1483,7 @@ exit:
return;
}
void Mac::HandleTransmitDone(TxFrame &aFrame, RxFrame *aAckFrame, otError aError)
void Mac::HandleTransmitDone(TxFrame &aFrame, RxFrame *aAckFrame, Error aError)
{
#if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE
if (!aFrame.IsEmpty()
@@ -1522,10 +1521,10 @@ void Mac::HandleTransmitDone(TxFrame &aFrame, RxFrame *aAckFrame, otError aError
#if OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2
// Verify Enh-ACK integrity by checking its MIC
if ((aError == OT_ERROR_NONE) && (aAckFrame != nullptr) &&
(ProcessEnhAckSecurity(aFrame, *aAckFrame) != OT_ERROR_NONE))
if ((aError == kErrorNone) && (aAckFrame != nullptr) &&
(ProcessEnhAckSecurity(aFrame, *aAckFrame) != kErrorNone))
{
aError = OT_ERROR_NO_ACK;
aError = kErrorNoAck;
}
#endif
}
@@ -1544,10 +1543,10 @@ void Mac::HandleTransmitDone(TxFrame &aFrame, RxFrame *aAckFrame, otError aError
// If the "required radio type set" is empty, successful
// tx over any radio link is sufficient for overall tx to
// be considered successful. In this case `mTxError`
// starts as `OT_ERROR_ABORT` and we update it only when
// it is not already `OT_ERROR_NONE`.
// starts as `kErrorAbort` and we update it only when
// it is not already `kErrorNone`.
if (mTxError != OT_ERROR_NONE)
if (mTxError != kErrorNone)
{
mTxError = aError;
}
@@ -1557,13 +1556,13 @@ void Mac::HandleTransmitDone(TxFrame &aFrame, RxFrame *aAckFrame, otError aError
// When the "required radio type set" is not empty we
// expect the successful frame tx on all links in this set
// to consider the overall tx successful. In this case,
// `mTxError` starts as `OT_ERROR_NONE` and we update it
// `mTxError` starts as `kErrorNone` and we update it
// if tx over any link in the set fails.
if (requriedRadios.Contains(radio) && (aError != OT_ERROR_NONE))
if (requriedRadios.Contains(radio) && (aError != kErrorNone))
{
otLogDebgMac("Frame tx failed on required radio link %s with error %s", RadioTypeToString(radio),
otThreadErrorToString(aError));
ErrorToString(aError));
mTxError = aError;
}
@@ -1597,7 +1596,7 @@ void Mac::HandleTransmitDone(TxFrame &aFrame, RxFrame *aAckFrame, otError aError
case kOperationTransmitPoll:
OT_ASSERT(aFrame.IsEmpty() || aFrame.GetAckRequest());
if ((aError == OT_ERROR_NONE) && (aAckFrame != nullptr))
if ((aError == kErrorNone) && (aAckFrame != nullptr))
{
bool framePending = aAckFrame->GetFramePending();
@@ -1618,7 +1617,7 @@ void Mac::HandleTransmitDone(TxFrame &aFrame, RxFrame *aAckFrame, otError aError
case kOperationTransmitDataDirect:
mCounters.mTxData++;
if (aError != OT_ERROR_NONE)
if (aError != kErrorNone)
{
mCounters.mTxDirectMaxRetryExpiry++;
}
@@ -1633,7 +1632,7 @@ void Mac::HandleTransmitDone(TxFrame &aFrame, RxFrame *aAckFrame, otError aError
FinishOperation();
Get<MeshForwarder>().HandleSentFrame(aFrame, aError);
#if OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2
if (aError == OT_ERROR_NONE && Get<Mle::Mle>().GetParent().IsEnhancedKeepAliveSupported() &&
if (aError == kErrorNone && Get<Mle::Mle>().GetParent().IsEnhancedKeepAliveSupported() &&
aFrame.GetSecurityEnabled() && aAckFrame != nullptr)
{
Get<DataPollSender>().ProcessFrame(*aAckFrame);
@@ -1657,7 +1656,7 @@ void Mac::HandleTransmitDone(TxFrame &aFrame, RxFrame *aAckFrame, otError aError
case kOperationTransmitDataIndirect:
mCounters.mTxData++;
if (aError != OT_ERROR_NONE)
if (aError != kErrorNone)
{
mCounters.mTxIndirectMaxRetryExpiry++;
}
@@ -1738,10 +1737,10 @@ void Mac::HandleTimer(void)
}
}
otError Mac::ProcessReceiveSecurity(RxFrame &aFrame, const Address &aSrcAddr, Neighbor *aNeighbor)
Error Mac::ProcessReceiveSecurity(RxFrame &aFrame, const Address &aSrcAddr, Neighbor *aNeighbor)
{
KeyManager & keyManager = Get<KeyManager>();
otError error = OT_ERROR_SECURITY;
Error error = kErrorSecurity;
uint8_t securityLevel;
uint8_t keyIdMode;
uint32_t frameCounter;
@@ -1750,7 +1749,7 @@ otError Mac::ProcessReceiveSecurity(RxFrame &aFrame, const Address &aSrcAddr, Ne
const Key * macKey;
const ExtAddress *extAddress;
VerifyOrExit(aFrame.GetSecurityEnabled(), error = OT_ERROR_NONE);
VerifyOrExit(aFrame.GetSecurityEnabled(), error = kErrorNone);
IgnoreError(aFrame.GetSecurityLevel(securityLevel));
VerifyOrExit(securityLevel == Frame::kSecEncMic32);
@@ -1813,7 +1812,7 @@ otError Mac::ProcessReceiveSecurity(RxFrame &aFrame, const Address &aSrcAddr, Ne
#endif
// If frame counter is one off, then frame is a duplicate.
VerifyOrExit((frameCounter + 1) != neighborFrameCounter, error = OT_ERROR_DUPLICATED);
VerifyOrExit((frameCounter + 1) != neighborFrameCounter, error = kErrorDuplicated);
VerifyOrExit(frameCounter >= neighborFrameCounter);
}
@@ -1867,16 +1866,16 @@ otError Mac::ProcessReceiveSecurity(RxFrame &aFrame, const Address &aSrcAddr, Ne
}
}
error = OT_ERROR_NONE;
error = kErrorNone;
exit:
return error;
}
#if OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2
otError Mac::ProcessEnhAckSecurity(TxFrame &aTxFrame, RxFrame &aAckFrame)
Error Mac::ProcessEnhAckSecurity(TxFrame &aTxFrame, RxFrame &aAckFrame)
{
otError error = OT_ERROR_SECURITY;
Error error = kErrorSecurity;
uint8_t securityLevel;
uint8_t txKeyId;
uint8_t ackKeyId;
@@ -1888,14 +1887,14 @@ otError Mac::ProcessEnhAckSecurity(TxFrame &aTxFrame, RxFrame &aAckFrame)
KeyManager &keyManager = Get<KeyManager>();
const Key * macKey;
VerifyOrExit(aAckFrame.GetSecurityEnabled(), error = OT_ERROR_NONE);
VerifyOrExit(aAckFrame.GetSecurityEnabled(), error = kErrorNone);
VerifyOrExit(aAckFrame.IsVersion2015());
IgnoreError(aAckFrame.GetSecurityLevel(securityLevel));
VerifyOrExit(securityLevel == Frame::kSecEncMic32);
IgnoreError(aAckFrame.GetKeyIdMode(keyIdMode));
VerifyOrExit(keyIdMode == Frame::kKeyIdMode1, error = OT_ERROR_NONE);
VerifyOrExit(keyIdMode == Frame::kKeyIdMode1, error = kErrorNone);
IgnoreError(aTxFrame.GetKeyId(txKeyId));
IgnoreError(aAckFrame.GetKeyId(ackKeyId));
@@ -1962,7 +1961,7 @@ otError Mac::ProcessEnhAckSecurity(TxFrame &aTxFrame, RxFrame &aAckFrame)
}
exit:
if (error != OT_ERROR_NONE)
if (error != kErrorNone)
{
otLogInfoMac("Frame tx attempt failed, error: Enh-ACK security check fail");
}
@@ -1971,19 +1970,19 @@ exit:
}
#endif // OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2
void Mac::HandleReceivedFrame(RxFrame *aFrame, otError aError)
void Mac::HandleReceivedFrame(RxFrame *aFrame, Error aError)
{
Address srcaddr;
Address dstaddr;
PanId panid;
Neighbor *neighbor;
otError error = aError;
Error error = aError;
mCounters.mRxTotal++;
SuccessOrExit(error);
VerifyOrExit(aFrame != nullptr, error = OT_ERROR_NO_FRAME_RECEIVED);
VerifyOrExit(IsEnabled(), error = OT_ERROR_INVALID_STATE);
VerifyOrExit(aFrame != nullptr, error = kErrorNoFrameReceived);
VerifyOrExit(IsEnabled(), error = kErrorInvalidState);
// Ensure we have a valid frame before attempting to read any contents of
// the buffer received from the radio.
@@ -2001,7 +2000,7 @@ void Mac::HandleReceivedFrame(RxFrame *aFrame, otError aError)
case Address::kTypeShort:
VerifyOrExit((mRxOnWhenIdle && dstaddr.IsBroadcast()) || dstaddr.GetShort() == GetShortAddress(),
error = OT_ERROR_DESTINATION_ADDRESS_FILTERED);
error = kErrorDestinationAddressFiltered);
#if OPENTHREAD_FTD
// Allow multicasts from neighbor routers if FTD
@@ -2014,14 +2013,14 @@ void Mac::HandleReceivedFrame(RxFrame *aFrame, otError aError)
break;
case Address::kTypeExtended:
VerifyOrExit(dstaddr.GetExtended() == GetExtAddress(), error = OT_ERROR_DESTINATION_ADDRESS_FILTERED);
VerifyOrExit(dstaddr.GetExtended() == GetExtAddress(), error = kErrorDestinationAddressFiltered);
break;
}
// Verify destination PAN ID if present
if (OT_ERROR_NONE == aFrame->GetDstPanId(panid))
if (kErrorNone == aFrame->GetDstPanId(panid))
{
VerifyOrExit(panid == kShortAddrBroadcast || panid == mPanId, error = OT_ERROR_DESTINATION_ADDRESS_FILTERED);
VerifyOrExit(panid == kShortAddrBroadcast || panid == mPanId, error = kErrorDestinationAddressFiltered);
}
// Source Address Filtering
@@ -2033,7 +2032,7 @@ void Mac::HandleReceivedFrame(RxFrame *aFrame, otError aError)
case Address::kTypeShort:
otLogDebgMac("Received frame from short address 0x%04x", srcaddr.GetShort());
VerifyOrExit(neighbor != nullptr, error = OT_ERROR_UNKNOWN_NEIGHBOR);
VerifyOrExit(neighbor != nullptr, error = kErrorUnknownNeighbor);
srcaddr.SetExtended(neighbor->GetExtAddress());
@@ -2042,7 +2041,7 @@ void Mac::HandleReceivedFrame(RxFrame *aFrame, otError aError)
case Address::kTypeExtended:
// Duplicate Address Protection
VerifyOrExit(srcaddr.GetExtended() != GetExtAddress(), error = OT_ERROR_INVALID_SOURCE_ADDRESS);
VerifyOrExit(srcaddr.GetExtended() != GetExtAddress(), error = kErrorInvalidSourceAddress);
#if OPENTHREAD_CONFIG_MAC_FILTER_ENABLE
{
@@ -2080,7 +2079,7 @@ void Mac::HandleReceivedFrame(RxFrame *aFrame, otError aError)
switch (error)
{
case OT_ERROR_DUPLICATED:
case kErrorDuplicated:
// Allow a duplicate received frame pass, only if the
// current operation is `kOperationWaitingForData` (i.e.,
@@ -2099,7 +2098,7 @@ void Mac::HandleReceivedFrame(RxFrame *aFrame, otError aError)
OT_FALL_THROUGH;
case OT_ERROR_NONE:
case kErrorNone:
break;
default:
@@ -2139,11 +2138,11 @@ void Mac::HandleReceivedFrame(RxFrame *aFrame, otError aError)
case Neighbor::kStateChildUpdateRequest:
// Only accept a "MAC Data Request" frame from a child being restored.
VerifyOrExit(aFrame->IsDataRequestCommand(), error = OT_ERROR_DROP);
VerifyOrExit(aFrame->IsDataRequestCommand(), error = kErrorDrop);
break;
default:
ExitNow(error = OT_ERROR_UNKNOWN_NEIGHBOR);
ExitNow(error = kErrorUnknownNeighbor);
}
#if OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2 && OPENTHREAD_FTD
@@ -2214,7 +2213,7 @@ void Mac::HandleReceivedFrame(RxFrame *aFrame, otError aError)
case Frame::kFcfFrameMacCmd:
if (HandleMacCommand(*aFrame)) // returns `true` when handled
{
ExitNow(error = OT_ERROR_NONE);
ExitNow(error = kErrorNone);
}
break;
@@ -2239,41 +2238,41 @@ void Mac::HandleReceivedFrame(RxFrame *aFrame, otError aError)
exit:
if (error != OT_ERROR_NONE)
if (error != kErrorNone)
{
LogFrameRxFailure(aFrame, error);
switch (error)
{
case OT_ERROR_SECURITY:
case kErrorSecurity:
mCounters.mRxErrSec++;
break;
case OT_ERROR_FCS:
case kErrorFcs:
mCounters.mRxErrFcs++;
break;
case OT_ERROR_NO_FRAME_RECEIVED:
case kErrorNoFrameReceived:
mCounters.mRxErrNoFrame++;
break;
case OT_ERROR_UNKNOWN_NEIGHBOR:
case kErrorUnknownNeighbor:
mCounters.mRxErrUnknownNeighbor++;
break;
case OT_ERROR_INVALID_SOURCE_ADDRESS:
case kErrorInvalidSourceAddress:
mCounters.mRxErrInvalidSrcAddr++;
break;
case OT_ERROR_ADDRESS_FILTERED:
case kErrorAddressFiltered:
mCounters.mRxAddressFiltered++;
break;
case OT_ERROR_DESTINATION_ADDRESS_FILTERED:
case kErrorDestinationAddressFiltered:
mCounters.mRxDestAddrFiltered++;
break;
case OT_ERROR_DUPLICATED:
case kErrorDuplicated:
mCounters.mRxDuplicated++;
break;
@@ -2412,15 +2411,15 @@ const char *Mac::OperationToString(Operation aOperation)
return kOperationStrings[aOperation];
}
void Mac::LogFrameRxFailure(const RxFrame *aFrame, otError aError) const
void Mac::LogFrameRxFailure(const RxFrame *aFrame, Error aError) const
{
otLogLevel logLevel;
switch (aError)
{
case OT_ERROR_ABORT:
case OT_ERROR_NO_FRAME_RECEIVED:
case OT_ERROR_DESTINATION_ADDRESS_FILTERED:
case kErrorAbort:
case kErrorNoFrameReceived:
case kErrorDestinationAddressFiltered:
logLevel = OT_LOG_LEVEL_DEBG;
break;
@@ -2431,16 +2430,15 @@ void Mac::LogFrameRxFailure(const RxFrame *aFrame, otError aError) const
if (aFrame == nullptr)
{
otLogMac(logLevel, "Frame rx failed, error:%s", otThreadErrorToString(aError));
otLogMac(logLevel, "Frame rx failed, error:%s", ErrorToString(aError));
}
else
{
otLogMac(logLevel, "Frame rx failed, error:%s, %s", otThreadErrorToString(aError),
aFrame->ToInfoString().AsCString());
otLogMac(logLevel, "Frame rx failed, error:%s, %s", ErrorToString(aError), aFrame->ToInfoString().AsCString());
}
}
void Mac::LogFrameTxFailure(const TxFrame &aFrame, otError aError, uint8_t aRetryCount, bool aWillRetx) const
void Mac::LogFrameTxFailure(const TxFrame &aFrame, Error aError, uint8_t aRetryCount, bool aWillRetx) const
{
#if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE && OPENTHREAD_CONFIG_MULTI_RADIO
if (aFrame.GetRadioType() == kRadioTypeIeee802154)
@@ -2453,12 +2451,12 @@ void Mac::LogFrameTxFailure(const TxFrame &aFrame, otError aError, uint8_t aRetr
uint8_t maxAttempts = aFrame.GetMaxFrameRetries() + 1;
uint8_t curAttempt = aWillRetx ? (aRetryCount + 1) : maxAttempts;
otLogInfoMac("Frame tx attempt %d/%d failed, error:%s, %s", curAttempt, maxAttempts,
otThreadErrorToString(aError), aFrame.ToInfoString().AsCString());
otLogInfoMac("Frame tx attempt %d/%d failed, error:%s, %s", curAttempt, maxAttempts, ErrorToString(aError),
aFrame.ToInfoString().AsCString());
}
else
{
otLogInfoMac("Frame tx failed, error:%s, %s", otThreadErrorToString(aError), aFrame.ToInfoString().AsCString());
otLogInfoMac("Frame tx failed, error:%s, %s", ErrorToString(aError), aFrame.ToInfoString().AsCString());
}
}
@@ -2469,7 +2467,7 @@ void Mac::LogBeacon(const char *aActionText, const BeaconPayload &aBeaconPayload
#else // #if (OPENTHREAD_CONFIG_LOG_LEVEL >= OT_LOG_LEVEL_INFO) && (OPENTHREAD_CONFIG_LOG_MAC == 1)
void Mac::LogFrameRxFailure(const RxFrame *, otError) const
void Mac::LogFrameRxFailure(const RxFrame *, Error) const
{
}
@@ -2477,7 +2475,7 @@ void Mac::LogBeacon(const char *, const BeaconPayload &) const
{
}
void Mac::LogFrameTxFailure(const TxFrame &, otError, uint8_t, bool) const
void Mac::LogFrameTxFailure(const TxFrame &, Error, uint8_t, bool) const
{
}
+59 -59
View File
@@ -147,11 +147,11 @@ public:
* @param[in] aHandler A pointer to a function that is called on receiving an IEEE 802.15.4 Beacon.
* @param[in] aContext A pointer to an arbitrary context (used when invoking `aHandler` callback).
*
* @retval OT_ERROR_NONE Successfully scheduled the Active Scan request.
* @retval OT_ERROR_BUSY Could not schedule the scan (a scan is ongoing or scheduled).
* @retval kErrorNone Successfully scheduled the Active Scan request.
* @retval kErrorBusy Could not schedule the scan (a scan is ongoing or scheduled).
*
*/
otError ActiveScan(uint32_t aScanChannels, uint16_t aScanDuration, ActiveScanHandler aHandler, void *aContext);
Error ActiveScan(uint32_t aScanChannels, uint16_t aScanDuration, ActiveScanHandler aHandler, void *aContext);
/**
* This method starts an IEEE 802.15.4 Energy Scan.
@@ -162,11 +162,11 @@ public:
* @param[in] aHandler A pointer to a function called to pass on scan result or indicate scan completion.
* @param[in] aContext A pointer to an arbitrary context (used when invoking @p aHandler callback).
*
* @retval OT_ERROR_NONE Accepted the Energy Scan request.
* @retval OT_ERROR_BUSY Could not start the energy scan.
* @retval kErrorNone Accepted the Energy Scan request.
* @retval kErrorBusy Could not start the energy scan.
*
*/
otError EnergyScan(uint32_t aScanChannels, uint16_t aScanDuration, EnergyScanHandler aHandler, void *aContext);
Error EnergyScan(uint32_t aScanChannels, uint16_t aScanDuration, EnergyScanHandler aHandler, void *aContext);
/**
* This method indicates the energy scan for the current channel is complete.
@@ -240,23 +240,23 @@ public:
*
* @param[in] aOobFrame A pointer to the frame.
*
* @retval OT_ERROR_NONE Successfully scheduled the frame transmission.
* @retval OT_ERROR_ALREADY MAC layer is busy sending a previously requested frame.
* @retval OT_ERROR_INVALID_STATE The MAC layer is not enabled.
* @retval OT_ERROR_INVALID_ARGS The argument @p aOobFrame is nullptr.
* @retval kErrorNone Successfully scheduled the frame transmission.
* @retval kErrorAlready MAC layer is busy sending a previously requested frame.
* @retval kErrorInvalidState The MAC layer is not enabled.
* @retval kErrorInvalidArgs The argument @p aOobFrame is nullptr.
*
*/
otError RequestOutOfBandFrameTransmission(otRadioFrame *aOobFrame);
Error RequestOutOfBandFrameTransmission(otRadioFrame *aOobFrame);
/**
* This method requests transmission of a data poll (MAC Data Request) frame.
*
* @retval OT_ERROR_NONE Data poll transmission request is scheduled successfully.
* @retval OT_ERROR_ALREADY MAC is busy sending earlier poll transmission request.
* @retval OT_ERROR_INVALID_STATE The MAC layer is not enabled.
* @retval kErrorNone Data poll transmission request is scheduled successfully.
* @retval kErrorAlready MAC is busy sending earlier poll transmission request.
* @retval kErrorInvalidState The MAC layer is not enabled.
*
*/
otError RequestDataPollTransmission(void);
Error RequestDataPollTransmission(void);
/**
* This method returns a reference to the IEEE 802.15.4 Extended Address.
@@ -303,11 +303,11 @@ public:
*
* @param[in] aChannel The IEEE 802.15.4 PAN Channel.
*
* @retval OT_ERROR_NONE Successfully set the IEEE 802.15.4 PAN Channel.
* @retval OT_ERROR_INVALID_ARGS The @p aChannel is not in the supported channel mask.
* @retval kErrorNone Successfully set the IEEE 802.15.4 PAN Channel.
* @retval kErrorInvalidArgs The @p aChannel is not in the supported channel mask.
*
*/
otError SetPanChannel(uint8_t aChannel);
Error SetPanChannel(uint8_t aChannel);
/**
* This method sets the temporary IEEE 802.15.4 radio channel.
@@ -319,11 +319,11 @@ public:
*
* @param[in] aChannel A IEEE 802.15.4 channel.
*
* @retval OT_ERROR_NONE Successfully set the temporary channel
* @retval OT_ERROR_INVALID_ARGS The @p aChannel is not in the supported channel mask.
* @retval kErrorNone Successfully set the temporary channel
* @retval kErrorInvalidArgs The @p aChannel is not in the supported channel mask.
*
*/
otError SetTemporaryChannel(uint8_t aChannel);
Error SetTemporaryChannel(uint8_t aChannel);
/**
* This method clears the use of a previously set temporary channel and adopts the PAN channel.
@@ -360,22 +360,22 @@ public:
*
* @param[in] aNameString A pointer to a string character array. Must be null terminated.
*
* @retval OT_ERROR_NONE Successfully set the IEEE 802.15.4 Network Name.
* @retval OT_ERROR_INVALID_ARGS Given name is too long.
* @retval kErrorNone Successfully set the IEEE 802.15.4 Network Name.
* @retval kErrorInvalidArgs Given name is too long.
*
*/
otError SetNetworkName(const char *aNameString);
Error SetNetworkName(const char *aNameString);
/**
* This method sets the IEEE 802.15.4 Network Name.
*
* @param[in] aNameData A name data (pointer to char buffer and length).
*
* @retval OT_ERROR_NONE Successfully set the IEEE 802.15.4 Network Name.
* @retval OT_ERROR_INVALID_ARGS Given name is too long.
* @retval kErrorNone Successfully set the IEEE 802.15.4 Network Name.
* @retval kErrorInvalidArgs Given name is too long.
*
*/
otError SetNetworkName(const NameData &aNameData);
Error SetNetworkName(const NameData &aNameData);
#if (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)
/**
@@ -391,22 +391,22 @@ public:
*
* @param[in] aNameString A pointer to a string character array. Must be null terminated.
*
* @retval OT_ERROR_NONE Successfully set the Thread Domain Name.
* @retval OT_ERROR_INVALID_ARGS Given name is too long.
* @retval kErrorNone Successfully set the Thread Domain Name.
* @retval kErrorInvalidArgs Given name is too long.
*
*/
otError SetDomainName(const char *aNameString);
Error SetDomainName(const char *aNameString);
/**
* This method sets the Thread Domain Name.
*
* @param[in] aNameData A name data (pointer to char buffer and length).
*
* @retval OT_ERROR_NONE Successfully set the Thread Domain Name.
* @retval OT_ERROR_INVALID_ARGS Given name is too long.
* @retval kErrorNone Successfully set the Thread Domain Name.
* @retval kErrorInvalidArgs Given name is too long.
*
*/
otError SetDomainName(const NameData &aNameData);
Error SetDomainName(const NameData &aNameData);
#endif // (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)
/**
@@ -482,11 +482,11 @@ public:
* This method is called to handle a received frame.
*
* @param[in] aFrame A pointer to the received frame, or nullptr if the receive operation was aborted.
* @param[in] aError OT_ERROR_NONE when successfully received a frame,
* OT_ERROR_ABORT when reception was aborted and a frame was not received.
* @param[in] aError kErrorNone when successfully received a frame,
* kErrorAbort when reception was aborted and a frame was not received.
*
*/
void HandleReceivedFrame(RxFrame *aFrame, otError aError);
void HandleReceivedFrame(RxFrame *aFrame, Error aError);
/**
* This method records CCA status (success/failure) for a frame transmission attempt.
@@ -505,10 +505,10 @@ public:
*
* @param[in] aFrame The transmitted frame.
* @param[in] aAckFrame A pointer to the ACK frame, or nullptr if no ACK was received.
* @param[in] aError OT_ERROR_NONE when the frame was transmitted successfully,
* OT_ERROR_NO_ACK when the frame was transmitted but no ACK was received,
* OT_ERROR_CHANNEL_ACCESS_FAILURE tx failed due to activity on the channel,
* OT_ERROR_ABORT when transmission was aborted for other reasons.
* @param[in] aError kErrorNone when the frame was transmitted successfully,
* kErrorNoAck when the frame was transmitted but no ACK was received,
* kErrorChannelAccessFailure tx failed due to activity on the channel,
* kErrorAbort when transmission was aborted for other reasons.
* @param[in] aRetryCount Indicates number of transmission retries for this frame.
* @param[in] aWillRetx Indicates whether frame will be retransmitted or not. This is applicable only
* when there was an error in transmission (i.e., `aError` is not NONE).
@@ -516,7 +516,7 @@ public:
*/
void RecordFrameTransmitStatus(const TxFrame &aFrame,
const RxFrame *aAckFrame,
otError aError,
Error aError,
uint8_t aRetryCount,
bool aWillRetx);
@@ -525,13 +525,13 @@ public:
*
* @param[in] aFrame The frame that was transmitted.
* @param[in] aAckFrame A pointer to the ACK frame, nullptr if no ACK was received.
* @param[in] aError OT_ERROR_NONE when the frame was transmitted successfully,
* OT_ERROR_NO_ACK when the frame was transmitted but no ACK was received,
* OT_ERROR_CHANNEL_ACCESS_FAILURE when the tx failed due to activity on the channel,
* OT_ERROR_ABORT when transmission was aborted for other reasons.
* @param[in] aError kErrorNone when the frame was transmitted successfully,
* kErrorNoAck when the frame was transmitted but no ACK was received,
* kErrorChannelAccessFailure when the tx failed due to activity on the channel,
* kErrorAbort when transmission was aborted for other reasons.
*
*/
void HandleTransmitDone(TxFrame &aFrame, RxFrame *aAckFrame, otError aError);
void HandleTransmitDone(TxFrame &aFrame, RxFrame *aAckFrame, Error aError);
/**
* This method returns if an active scan is in progress.
@@ -795,10 +795,10 @@ private:
};
#endif // OPENTHREAD_CONFIG_MAC_RETRY_SUCCESS_HISTOGRAM_ENABLE
otError ProcessReceiveSecurity(RxFrame &aFrame, const Address &aSrcAddr, Neighbor *aNeighbor);
void ProcessTransmitSecurity(TxFrame &aFrame);
Error ProcessReceiveSecurity(RxFrame &aFrame, const Address &aSrcAddr, Neighbor *aNeighbor);
void ProcessTransmitSecurity(TxFrame &aFrame);
#if OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2
otError ProcessEnhAckSecurity(TxFrame &aTxFrame, RxFrame &aAckFrame);
Error ProcessEnhAckSecurity(TxFrame &aTxFrame, RxFrame &aAckFrame);
#endif
void UpdateIdleMode(void);
@@ -817,16 +817,16 @@ private:
void HandleTimer(void);
static void HandleOperationTask(Tasklet &aTasklet);
void Scan(Operation aScanOperation, uint32_t aScanChannels, uint16_t aScanDuration);
otError UpdateScanChannel(void);
void PerformActiveScan(void);
void ReportActiveScanResult(const RxFrame *aBeaconFrame);
otError ConvertBeaconToActiveScanResult(const RxFrame *aBeaconFrame, ActiveScanResult &aResult);
void PerformEnergyScan(void);
void ReportEnergyScanResult(int8_t aRssi);
void Scan(Operation aScanOperation, uint32_t aScanChannels, uint16_t aScanDuration);
Error UpdateScanChannel(void);
void PerformActiveScan(void);
void ReportActiveScanResult(const RxFrame *aBeaconFrame);
Error ConvertBeaconToActiveScanResult(const RxFrame *aBeaconFrame, ActiveScanResult &aResult);
void PerformEnergyScan(void);
void ReportEnergyScanResult(int8_t aRssi);
void LogFrameRxFailure(const RxFrame *aFrame, otError aError) const;
void LogFrameTxFailure(const TxFrame &aFrame, otError aError, uint8_t aRetryCount, bool aWillRetx) const;
void LogFrameRxFailure(const RxFrame *aFrame, Error aError) const;
void LogFrameTxFailure(const TxFrame &aFrame, Error aError, uint8_t aRetryCount, bool aWillRetx) const;
void LogBeacon(const char *aActionText, const BeaconPayload &aBeaconPayload) const;
#if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE
@@ -917,7 +917,7 @@ private:
#if OPENTHREAD_CONFIG_MULTI_RADIO
RadioTypes mTxPendingRadioLinks;
otError mTxError;
Error mTxError;
#endif
#if OPENTHREAD_CONFIG_MAC_FILTER_ENABLE
+17 -17
View File
@@ -83,14 +83,14 @@ exit:
return rval;
}
otError Filter::AddAddress(const ExtAddress &aExtAddress)
Error Filter::AddAddress(const ExtAddress &aExtAddress)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
FilterEntry *entry = FindEntry(aExtAddress);
if (entry == nullptr)
{
VerifyOrExit((entry = FindAvailableEntry()) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((entry = FindAvailableEntry()) != nullptr, error = kErrorNoBufs);
entry->mExtAddress = aExtAddress;
}
@@ -118,9 +118,9 @@ void Filter::ClearAddresses(void)
}
}
otError Filter::GetNextAddress(Iterator &aIterator, Entry &aEntry) const
Error Filter::GetNextAddress(Iterator &aIterator, Entry &aEntry) const
{
otError error = OT_ERROR_NOT_FOUND;
Error error = kErrorNotFound;
for (; aIterator < OT_ARRAY_LENGTH(mFilterEntries); aIterator++)
{
@@ -130,7 +130,7 @@ otError Filter::GetNextAddress(Iterator &aIterator, Entry &aEntry) const
{
aEntry.mExtAddress = entry.mExtAddress;
aEntry.mRssIn = entry.mRssIn;
error = OT_ERROR_NONE;
error = kErrorNone;
aIterator++;
break;
}
@@ -139,15 +139,15 @@ otError Filter::GetNextAddress(Iterator &aIterator, Entry &aEntry) const
return error;
}
otError Filter::AddRssIn(const ExtAddress &aExtAddress, int8_t aRss)
Error Filter::AddRssIn(const ExtAddress &aExtAddress, int8_t aRss)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
FilterEntry *entry = FindEntry(aExtAddress);
if (entry == nullptr)
{
entry = FindAvailableEntry();
VerifyOrExit(entry != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit(entry != nullptr, error = kErrorNoBufs);
entry->mExtAddress = aExtAddress;
}
@@ -180,9 +180,9 @@ void Filter::ClearAllRssIn(void)
mDefaultRssIn = kFixedRssDisabled;
}
otError Filter::GetNextRssIn(Iterator &aIterator, Entry &aEntry)
Error Filter::GetNextRssIn(Iterator &aIterator, Entry &aEntry)
{
otError error = OT_ERROR_NOT_FOUND;
Error error = kErrorNotFound;
for (; aIterator < OT_ARRAY_LENGTH(mFilterEntries); aIterator++)
{
@@ -192,7 +192,7 @@ otError Filter::GetNextRssIn(Iterator &aIterator, Entry &aEntry)
{
aEntry.mExtAddress = entry.mExtAddress;
aEntry.mRssIn = entry.mRssIn;
error = OT_ERROR_NONE;
error = kErrorNone;
aIterator++;
ExitNow();
}
@@ -203,7 +203,7 @@ otError Filter::GetNextRssIn(Iterator &aIterator, Entry &aEntry)
{
static_cast<ExtAddress &>(aEntry.mExtAddress).Fill(0xff);
aEntry.mRssIn = mDefaultRssIn;
error = OT_ERROR_NONE;
error = kErrorNone;
aIterator++;
}
@@ -211,9 +211,9 @@ exit:
return error;
}
otError Filter::Apply(const ExtAddress &aExtAddress, int8_t &aRss)
Error Filter::Apply(const ExtAddress &aExtAddress, int8_t &aRss)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
FilterEntry *entry = FindEntry(aExtAddress);
bool isInFilterList;
@@ -231,11 +231,11 @@ otError Filter::Apply(const ExtAddress &aExtAddress, int8_t &aRss)
break;
case kModeAllowlist:
VerifyOrExit(isInFilterList, error = OT_ERROR_ADDRESS_FILTERED);
VerifyOrExit(isInFilterList, error = kErrorAddressFiltered);
break;
case kModeDenylist:
VerifyOrExit(!isInFilterList, error = OT_ERROR_ADDRESS_FILTERED);
VerifyOrExit(!isInFilterList, error = kErrorAddressFiltered);
break;
}
+15 -16
View File
@@ -117,11 +117,11 @@ public:
*
* @param[in] aExtAddress A reference to the Extended Address.
*
* @retval OT_ERROR_NONE Successfully added @p aExtAddress to the filter.
* @retval OT_ERROR_NO_BUFS No available entry exists.
* @retval kErrorNone Successfully added @p aExtAddress to the filter.
* @retval kErrorNoBufs No available entry exists.
*
*/
otError AddAddress(const ExtAddress &aExtAddress);
Error AddAddress(const ExtAddress &aExtAddress);
/**
* This method removes an Extended Address from the filter.
@@ -146,11 +146,11 @@ public:
* To get the first in-use address filter, set it to OT_MAC_FILTER_ITERATOR_INIT.
* @param[out] aEntry A reference to where the information is placed.
*
* @retval OT_ERROR_NONE Successfully retrieved the next address filter entry.
* @retval OT_ERROR_NOT_FOUND No subsequent entry exists.
* @retval kErrorNone Successfully retrieved the next address filter entry.
* @retval kErrorNotFound No subsequent entry exists.
*
*/
otError GetNextAddress(Iterator &aIterator, Entry &aEntry) const;
Error GetNextAddress(Iterator &aIterator, Entry &aEntry) const;
/**
* This method adds a fixed received signal strength entry for the messages from a given Extended Address.
@@ -158,11 +158,11 @@ public:
* @param[in] aExtAddress An Extended Address
* @param[in] aRss The received signal strength to set.
*
* @retval OT_ERROR_NONE Successfully set @p aRss for @p aExtAddress.
* @retval OT_ERROR_NO_BUFS No available entry exists.
* @retval kErrorNone Successfully set @p aRss for @p aExtAddress.
* @retval kErrorNoBufs No available entry exists.
*
*/
otError AddRssIn(const ExtAddress &aExtAddress, int8_t aRss);
Error AddRssIn(const ExtAddress &aExtAddress, int8_t aRss);
/**
* This method removes a fixed received signal strength entry for a given Extended Address.
@@ -206,11 +206,11 @@ public:
* Extended Address as all 0xff to indicate the default received signal strength
* if it was set.
*
* @retval OT_ERROR_NONE Successfully retrieved the next RssIn filter entry.
* @retval OT_ERROR_NOT_FOUND No subsequent entry exists.
* @retval kErrorNone Successfully retrieved the next RssIn filter entry.
* @retval kErrorNotFound No subsequent entry exists.
*
*/
otError GetNextRssIn(Iterator &aIterator, Entry &aEntry);
Error GetNextRssIn(Iterator &aIterator, Entry &aEntry);
/**
* This method applies the filter rules on a given Extended Address.
@@ -218,12 +218,11 @@ public:
* @param[in] aExtAddress A reference to the Extended Address.
* @param[out] aRss A reference to where the received signal strength to be placed.
*
* @retval OT_ERROR_NONE Successfully applied the filter rules on @p aExtAddress.
* @retval OT_ERROR_ADDRESS_FILTERED Address filter (allowlist or denylist) is enabled and @p aExtAddress is
* filtered.
* @retval kErrorNone Successfully applied the filter rules on @p aExtAddress.
* @retval kErrorAddressFiltered Address filter (allowlist or denylist) is enabled and @p aExtAddress is filtered.
*
*/
otError Apply(const ExtAddress &aExtAddress, int8_t &aRss);
Error Apply(const ExtAddress &aExtAddress, int8_t &aRss);
private:
enum
+56 -56
View File
@@ -86,13 +86,13 @@ uint16_t Frame::GetFrameControlField(void) const
return ReadUint16(mPsdu);
}
otError Frame::ValidatePsdu(void) const
Error Frame::ValidatePsdu(void) const
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
uint8_t index = FindPayloadIndex();
VerifyOrExit(index != kInvalidIndex, error = OT_ERROR_PARSE);
VerifyOrExit((index + GetFooterLength()) <= mLength, error = OT_ERROR_PARSE);
VerifyOrExit(index != kInvalidIndex, error = kErrorParse);
VerifyOrExit((index + GetFooterLength()) <= mLength, error = kErrorParse);
exit:
return error;
@@ -166,12 +166,12 @@ bool Frame::IsDstPanIdPresent(uint16_t aFcf)
return present;
}
otError Frame::GetDstPanId(PanId &aPanId) const
Error Frame::GetDstPanId(PanId &aPanId) const
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
uint8_t index = FindDstPanIdIndex();
VerifyOrExit(index != kInvalidIndex, error = OT_ERROR_PARSE);
VerifyOrExit(index != kInvalidIndex, error = kErrorParse);
aPanId = ReadUint16(&mPsdu[index]);
exit:
@@ -191,12 +191,12 @@ uint8_t Frame::FindDstAddrIndex(void) const
return kFcfSize + kDsnSize + (IsDstPanIdPresent() ? sizeof(PanId) : 0);
}
otError Frame::GetDstAddr(Address &aAddress) const
Error Frame::GetDstAddr(Address &aAddress) const
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
uint8_t index = FindDstAddrIndex();
VerifyOrExit(index != kInvalidIndex, error = OT_ERROR_PARSE);
VerifyOrExit(index != kInvalidIndex, error = kErrorParse);
switch (GetFrameControlField() & kFcfDstAddrMask)
{
@@ -304,24 +304,24 @@ bool Frame::IsSrcPanIdPresent(uint16_t aFcf)
return srcPanIdPresent;
}
otError Frame::GetSrcPanId(PanId &aPanId) const
Error Frame::GetSrcPanId(PanId &aPanId) const
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
uint8_t index = FindSrcPanIdIndex();
VerifyOrExit(index != kInvalidIndex, error = OT_ERROR_PARSE);
VerifyOrExit(index != kInvalidIndex, error = kErrorParse);
aPanId = ReadUint16(&mPsdu[index]);
exit:
return error;
}
otError Frame::SetSrcPanId(PanId aPanId)
Error Frame::SetSrcPanId(PanId aPanId)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
uint8_t index = FindSrcPanIdIndex();
VerifyOrExit(index != kInvalidIndex, error = OT_ERROR_PARSE);
VerifyOrExit(index != kInvalidIndex, error = kErrorParse);
WriteUint16(aPanId, &mPsdu[index]);
exit:
@@ -359,13 +359,13 @@ uint8_t Frame::FindSrcAddrIndex(void) const
return index;
}
otError Frame::GetSrcAddr(Address &aAddress) const
Error Frame::GetSrcAddr(Address &aAddress) const
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
uint8_t index = FindSrcAddrIndex();
uint16_t fcf = GetFrameControlField();
VerifyOrExit(index != kInvalidIndex, error = OT_ERROR_PARSE);
VerifyOrExit(index != kInvalidIndex, error = kErrorParse);
switch (fcf & kFcfSrcAddrMask)
{
@@ -423,12 +423,12 @@ void Frame::SetSrcAddr(const Address &aAddress)
}
}
otError Frame::GetSecurityControlField(uint8_t &aSecurityControlField) const
Error Frame::GetSecurityControlField(uint8_t &aSecurityControlField) const
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
uint8_t index = FindSecurityHeaderIndex();
VerifyOrExit(index != kInvalidIndex, error = OT_ERROR_PARSE);
VerifyOrExit(index != kInvalidIndex, error = kErrorParse);
aSecurityControlField = mPsdu[index];
@@ -457,12 +457,12 @@ exit:
return index;
}
otError Frame::GetSecurityLevel(uint8_t &aSecurityLevel) const
Error Frame::GetSecurityLevel(uint8_t &aSecurityLevel) const
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
uint8_t index = FindSecurityHeaderIndex();
VerifyOrExit(index != kInvalidIndex, error = OT_ERROR_PARSE);
VerifyOrExit(index != kInvalidIndex, error = kErrorParse);
aSecurityLevel = mPsdu[index] & kSecLevelMask;
@@ -470,12 +470,12 @@ exit:
return error;
}
otError Frame::GetKeyIdMode(uint8_t &aKeyIdMode) const
Error Frame::GetKeyIdMode(uint8_t &aKeyIdMode) const
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
uint8_t index = FindSecurityHeaderIndex();
VerifyOrExit(index != kInvalidIndex, error = OT_ERROR_PARSE);
VerifyOrExit(index != kInvalidIndex, error = kErrorParse);
aKeyIdMode = mPsdu[index] & kKeyIdModeMask;
@@ -483,12 +483,12 @@ exit:
return error;
}
otError Frame::GetFrameCounter(uint32_t &aFrameCounter) const
Error Frame::GetFrameCounter(uint32_t &aFrameCounter) const
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
uint8_t index = FindSecurityHeaderIndex();
VerifyOrExit(index != kInvalidIndex, error = OT_ERROR_PARSE);
VerifyOrExit(index != kInvalidIndex, error = kErrorParse);
// Security Control
index += kSecurityControlSize;
@@ -558,9 +558,9 @@ void Frame::SetKeySource(const uint8_t *aKeySource)
memcpy(&mPsdu[index + kSecurityControlSize + kFrameCounterSize], aKeySource, keySourceLength);
}
otError Frame::GetKeyId(uint8_t &aKeyId) const
Error Frame::GetKeyId(uint8_t &aKeyId) const
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
uint8_t keySourceLength;
uint8_t index = FindSecurityHeaderIndex();
@@ -586,11 +586,11 @@ void Frame::SetKeyId(uint8_t aKeyId)
mPsdu[index + kSecurityControlSize + kFrameCounterSize + keySourceLength] = aKeyId;
}
otError Frame::GetCommandId(uint8_t &aCommandId) const
Error Frame::GetCommandId(uint8_t &aCommandId) const
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
uint8_t index = FindPayloadIndex();
VerifyOrExit(index != kInvalidIndex, error = OT_ERROR_PARSE);
VerifyOrExit(index != kInvalidIndex, error = kErrorParse);
aCommandId = mPsdu[IsVersion2015() ? index : (index - 1)];
@@ -598,12 +598,12 @@ exit:
return error;
}
otError Frame::SetCommandId(uint8_t aCommandId)
Error Frame::SetCommandId(uint8_t aCommandId)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
uint8_t index = FindPayloadIndex();
VerifyOrExit(index != kInvalidIndex, error = OT_ERROR_PARSE);
VerifyOrExit(index != kInvalidIndex, error = kErrorParse);
mPsdu[IsVersion2015() ? index : (index - 1)] = aCommandId;
@@ -894,9 +894,9 @@ exit:
}
#if OPENTHREAD_CONFIG_MAC_HEADER_IE_SUPPORT
template <typename IeType> otError Frame::AppendHeaderIeAt(uint8_t &aIndex)
template <typename IeType> Error Frame::AppendHeaderIeAt(uint8_t &aIndex)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
SuccessOrExit(error = InitIeHeaderAt(aIndex, IeType::kHeaderIeId, IeType::kIeContentSize));
@@ -906,16 +906,16 @@ exit:
return error;
}
otError Frame::InitIeHeaderAt(uint8_t &aIndex, uint8_t ieId, uint8_t ieContentSize)
Error Frame::InitIeHeaderAt(uint8_t &aIndex, uint8_t ieId, uint8_t ieContentSize)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
if (aIndex == 0)
{
aIndex = FindHeaderIeIndex();
}
VerifyOrExit(aIndex != kInvalidIndex, error = OT_ERROR_NOT_FOUND);
VerifyOrExit(aIndex != kInvalidIndex, error = kErrorNotFound);
reinterpret_cast<HeaderIe *>(mPsdu + aIndex)->Init(ieId, ieContentSize);
aIndex += sizeof(HeaderIe);
@@ -1123,12 +1123,12 @@ uint8_t Frame::GetFcsSize(void) const
// Explicit instantiation
#if OPENTHREAD_CONFIG_MAC_HEADER_IE_SUPPORT
#if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE
template otError Frame::AppendHeaderIeAt<TimeIe>(uint8_t &aIndex);
template Error Frame::AppendHeaderIeAt<TimeIe>(uint8_t &aIndex);
#endif
#if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE
template otError Frame::AppendHeaderIeAt<CslIe>(uint8_t &aIndex);
template Error Frame::AppendHeaderIeAt<CslIe>(uint8_t &aIndex);
#endif
template otError Frame::AppendHeaderIeAt<Termination2Ie>(uint8_t &aIndex);
template Error Frame::AppendHeaderIeAt<Termination2Ie>(uint8_t &aIndex);
#endif
void TxFrame::CopyFrom(const TxFrame &aFromFrame)
@@ -1222,9 +1222,9 @@ void TxFrame::GenerateImmAck(const RxFrame &aFrame, bool aIsFramePending)
}
#if OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2
otError TxFrame::GenerateEnhAck(const RxFrame &aFrame, bool aIsFramePending, const uint8_t *aIeData, uint8_t aIeLength)
Error TxFrame::GenerateEnhAck(const RxFrame &aFrame, bool aIsFramePending, const uint8_t *aIeData, uint8_t aIeLength)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
uint16_t fcf = kFcfFrameAck | kFcfFrameVersion2015 | kFcfSrcAddrNone;
Address address;
@@ -1289,7 +1289,7 @@ otError TxFrame::GenerateEnhAck(const RxFrame &aFrame, bool aIsFramePending, con
}
else
{
ExitNow(error = OT_ERROR_PARSE);
ExitNow(error = kErrorParse);
}
SetDstPanId(panId);
@@ -1332,15 +1332,15 @@ exit:
}
#endif // OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2
otError RxFrame::ProcessReceiveAesCcm(const ExtAddress &aExtAddress, const Key &aMacKey)
Error RxFrame::ProcessReceiveAesCcm(const ExtAddress &aExtAddress, const Key &aMacKey)
{
#if OPENTHREAD_RADIO
OT_UNUSED_VARIABLE(aExtAddress);
OT_UNUSED_VARIABLE(aMacKey);
return OT_ERROR_NONE;
return kErrorNone;
#else
otError error = OT_ERROR_SECURITY;
Error error = kErrorSecurity;
uint32_t frameCounter = 0;
uint8_t securityLevel;
uint8_t nonce[Crypto::AesCcm::kNonceSize];
@@ -1348,7 +1348,7 @@ otError RxFrame::ProcessReceiveAesCcm(const ExtAddress &aExtAddress, const Key &
uint8_t tagLength;
Crypto::AesCcm aesCcm;
VerifyOrExit(GetSecurityEnabled(), error = OT_ERROR_NONE);
VerifyOrExit(GetSecurityEnabled(), error = kErrorNone);
SuccessOrExit(GetSecurityLevel(securityLevel));
SuccessOrExit(GetFrameCounter(frameCounter));
@@ -1373,7 +1373,7 @@ otError RxFrame::ProcessReceiveAesCcm(const ExtAddress &aExtAddress, const Key &
VerifyOrExit(memcmp(tag, GetFooter(), tagLength) == 0);
#endif
error = OT_ERROR_NONE;
error = kErrorNone;
exit:
return error;
@@ -1409,7 +1409,7 @@ Frame::InfoString Frame::ToInfoString(void) const
break;
case kFcfFrameMacCmd:
if (GetCommandId(commandId) != OT_ERROR_NONE)
if (GetCommandId(commandId) != kErrorNone)
{
commandId = 0xff;
}
+39 -39
View File
@@ -407,11 +407,11 @@ public:
/**
* This method validates the frame.
*
* @retval OT_ERROR_NONE Successfully parsed the MAC header.
* @retval OT_ERROR_PARSE Failed to parse through the MAC header.
* @retval kErrorNone Successfully parsed the MAC header.
* @retval kErrorParse Failed to parse through the MAC header.
*
*/
otError ValidatePsdu(void) const;
Error ValidatePsdu(void) const;
/**
* This method returns the IEEE 802.15.4 Frame Type.
@@ -536,11 +536,11 @@ public:
*
* @param[out] aPanId The Destination PAN Identifier.
*
* @retval OT_ERROR_NONE Successfully retrieved the Destination PAN Identifier.
* @retval OT_ERROR_PARSE Failed to parse the PAN Identifier.
* @retval kErrorNone Successfully retrieved the Destination PAN Identifier.
* @retval kErrorParse Failed to parse the PAN Identifier.
*
*/
otError GetDstPanId(PanId &aPanId) const;
Error GetDstPanId(PanId &aPanId) const;
/**
* This method sets the Destination PAN Identifier.
@@ -563,10 +563,10 @@ public:
*
* @param[out] aAddress The Destination Address.
*
* @retval OT_ERROR_NONE Successfully retrieved the Destination Address.
* @retval kErrorNone Successfully retrieved the Destination Address.
*
*/
otError GetDstAddr(Address &aAddress) const;
Error GetDstAddr(Address &aAddress) const;
/**
* This method sets the Destination Address.
@@ -605,20 +605,20 @@ public:
*
* @param[out] aPanId The Source PAN Identifier.
*
* @retval OT_ERROR_NONE Successfully retrieved the Source PAN Identifier.
* @retval kErrorNone Successfully retrieved the Source PAN Identifier.
*
*/
otError GetSrcPanId(PanId &aPanId) const;
Error GetSrcPanId(PanId &aPanId) const;
/**
* This method sets the Source PAN Identifier.
*
* @param[in] aPanId The Source PAN Identifier.
*
* @retval OT_ERROR_NONE Successfully set the Source PAN Identifier.
* @retval kErrorNone Successfully set the Source PAN Identifier.
*
*/
otError SetSrcPanId(PanId aPanId);
Error SetSrcPanId(PanId aPanId);
/**
* This method indicates whether or not the Source Address is present for this object.
@@ -633,10 +633,10 @@ public:
*
* @param[out] aAddress The Source Address.
*
* @retval OT_ERROR_NONE Successfully retrieved the Source Address.
* @retval kErrorNone Successfully retrieved the Source Address.
*
*/
otError GetSrcAddr(Address &aAddress) const;
Error GetSrcAddr(Address &aAddress) const;
/**
* This method sets the Source Address.
@@ -667,11 +667,11 @@ public:
*
* @param[out] aSecurityControlField The Security Control Field.
*
* @retval OT_ERROR_NONE Successfully retrieved the Security Level Identifier.
* @retval OT_ERROR_PARSE Failed to find the security control field in the frame.
* @retval kErrorNone Successfully retrieved the Security Level Identifier.
* @retval kErrorParse Failed to find the security control field in the frame.
*
*/
otError GetSecurityControlField(uint8_t &aSecurityControlField) const;
Error GetSecurityControlField(uint8_t &aSecurityControlField) const;
/**
* This method sets the Security Control Field.
@@ -686,30 +686,30 @@ public:
*
* @param[out] aSecurityLevel The Security Level Identifier.
*
* @retval OT_ERROR_NONE Successfully retrieved the Security Level Identifier.
* @retval kErrorNone Successfully retrieved the Security Level Identifier.
*
*/
otError GetSecurityLevel(uint8_t &aSecurityLevel) const;
Error GetSecurityLevel(uint8_t &aSecurityLevel) const;
/**
* This method gets the Key Identifier Mode.
*
* @param[out] aSecurityLevel The Key Identifier Mode.
*
* @retval OT_ERROR_NONE Successfully retrieved the Key Identifier Mode.
* @retval kErrorNone Successfully retrieved the Key Identifier Mode.
*
*/
otError GetKeyIdMode(uint8_t &aKeyIdMode) const;
Error GetKeyIdMode(uint8_t &aKeyIdMode) const;
/**
* This method gets the Frame Counter.
*
* @param[out] aFrameCounter The Frame Counter.
*
* @retval OT_ERROR_NONE Successfully retrieved the Frame Counter.
* @retval kErrorNone Successfully retrieved the Frame Counter.
*
*/
otError GetFrameCounter(uint32_t &aFrameCounter) const;
Error GetFrameCounter(uint32_t &aFrameCounter) const;
/**
* This method sets the Frame Counter.
@@ -740,10 +740,10 @@ public:
*
* @param[out] aKeyId The Key Identifier.
*
* @retval OT_ERROR_NONE Successfully retrieved the Key Identifier.
* @retval kErrorNone Successfully retrieved the Key Identifier.
*
*/
otError GetKeyId(uint8_t &aKeyId) const;
Error GetKeyId(uint8_t &aKeyId) const;
/**
* This method sets the Key Identifier.
@@ -758,20 +758,20 @@ public:
*
* @param[out] aCommandId The Command ID.
*
* @retval OT_ERROR_NONE Successfully retrieved the Command ID.
* @retval kErrorNone Successfully retrieved the Command ID.
*
*/
otError GetCommandId(uint8_t &aCommandId) const;
Error GetCommandId(uint8_t &aCommandId) const;
/**
* This method sets the Command ID.
*
* @param[in] aCommandId The Command ID.
*
* @retval OT_ERROR_NONE Successfully set the Command ID.
* @retval kErrorNone Successfully set the Command ID.
*
*/
otError SetCommandId(uint8_t aCommandId);
Error SetCommandId(uint8_t aCommandId);
/**
* This method indicates whether the frame is a MAC Data Request command (data poll).
@@ -957,11 +957,11 @@ public:
* @tparam IeType The Header IE type, it MUST contain an enum `kHeaderIeId` equal to the IE's Id
* and an enum `kIeContentSize` indicating the IE body's size.
*
* @retval OT_ERROR_NONE Successfully appended the Header IE.
* @retval OT_ERROR_NOT_FOUND The position for first IE is not found.
* @retval kErrorNone Successfully appended the Header IE.
* @retval kErrorNotFound The position for first IE is not found.
*
*/
template <typename IeType> otError AppendHeaderIeAt(uint8_t &aIndex);
template <typename IeType> Error AppendHeaderIeAt(uint8_t &aIndex);
/**
* This method returns a pointer to the Header IE.
@@ -1121,7 +1121,7 @@ protected:
#if OPENTHREAD_CONFIG_MAC_HEADER_IE_SUPPORT
uint8_t FindHeaderIeIndex(void) const;
otError InitIeHeaderAt(uint8_t &aIndex, uint8_t ieId, uint8_t ieContentSize);
Error InitIeHeaderAt(uint8_t &aIndex, uint8_t ieId, uint8_t ieContentSize);
template <typename IeType> void InitIeContentAt(uint8_t &aIndex);
#endif
@@ -1203,11 +1203,11 @@ public:
* for AES CCM computation.
* @param[in] aMacKey A reference to the MAC key to decrypt the received frame.
*
* @retval OT_ERROR_NONE Process of received frame AES CCM succeeded.
* @retval OT_ERROR_SECURITY Received frame MIC check failed.
* @retval kErrorNone Process of received frame AES CCM succeeded.
* @retval kErrorSecurity Received frame MIC check failed.
*
*/
otError ProcessReceiveAesCcm(const ExtAddress &aExtAddress, const Key &aMacKey);
Error ProcessReceiveAesCcm(const ExtAddress &aExtAddress, const Key &aMacKey);
#if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE
/**
@@ -1426,11 +1426,11 @@ public:
* @param[in] aIeData A pointer to the IE data portion of the ACK to be sent.
* @param[in] aIeLength The length of IE data portion of the ACK to be sent.
*
* @retval OT_ERROR_NONE Successfully generated Enh Ack.
* @retval OT_ERROR_PARSE @p aFrame has incorrect format.
* @retval kErrorNone Successfully generated Enh Ack.
* @retval kErrorParse @p aFrame has incorrect format.
*
*/
otError GenerateEnhAck(const RxFrame &aFrame, bool aIsFramePending, const uint8_t *aIeData, uint8_t aIeLength);
Error GenerateEnhAck(const RxFrame &aFrame, bool aIsFramePending, const uint8_t *aIeData, uint8_t aIeLength);
#if OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2
/**
+2 -2
View File
@@ -159,9 +159,9 @@ void Links::Send(TxFrame &aFrame, RadioTypes aRadioTypes)
#if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE
if (aRadioTypes.Contains(kRadioTypeIeee802154))
{
otError error = mSubMac.Send();
Error error = mSubMac.Send();
OT_ASSERT(error == OT_ERROR_NONE);
OT_ASSERT(error == kErrorNone);
OT_UNUSED_VARIABLE(error);
}
#endif
+9 -9
View File
@@ -513,8 +513,8 @@ public:
{
#if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE
{
otError error = mSubMac.Send();
OT_ASSERT(error == OT_ERROR_NONE);
Error error = mSubMac.Send();
OT_ASSERT(error == kErrorNone);
OT_UNUSED_VARIABLE(error);
}
#endif
@@ -576,12 +576,12 @@ public:
* @param[in] aScanChannel The channel to perform the energy scan on.
* @param[in] aScanDuration The duration, in milliseconds, for the channel to be scanned.
*
* @retval OT_ERROR_NONE Successfully started scanning the channel.
* @retval OT_ERROR_INVALID_STATE The radio was disabled or transmitting.
* @retval OT_ERROR_NOT_IMPLEMENTED Energy scan is not supported by radio link.
* @retval kErrorNone Successfully started scanning the channel.
* @retval kErrorInvalidState The radio was disabled or transmitting.
* @retval kErrorNotImplemented Energy scan is not supported by radio link.
*
*/
otError EnergyScan(uint8_t aScanChannel, uint16_t aScanDuration)
Error EnergyScan(uint8_t aScanChannel, uint16_t aScanDuration)
{
OT_UNUSED_VARIABLE(aScanChannel);
OT_UNUSED_VARIABLE(aScanDuration);
@@ -590,7 +590,7 @@ public:
#if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE
mSubMac.EnergyScan(aScanChannel, aScanDuration);
#else
OT_ERROR_NOT_IMPLEMENTED;
kErrorNotImplemented;
#endif
}
@@ -654,8 +654,8 @@ public:
*
* @param[in] TxFrame The `TxFrame` from which to get the counter value.
*
* @retval OT_ERROR_NONE If successful.
* @retval OT_ERROR_INVALID_STATE If the raw link-layer isn't enabled.
* @retval kErrorNone If successful.
* @retval kErrorInvalidState If the raw link-layer isn't enabled.
*
*/
void SetMacFrameCounter(TxFrame &aFrame);
+8 -8
View File
@@ -128,15 +128,15 @@ NameData NetworkName::GetAsData(void) const
return NameData(m8, len);
}
otError NetworkName::Set(const NameData &aNameData)
Error NetworkName::Set(const NameData &aNameData)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
uint8_t newLen = static_cast<uint8_t>(StringLength(aNameData.GetBuffer(), aNameData.GetLength()));
VerifyOrExit(newLen <= kMaxSize, error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(newLen <= kMaxSize, error = kErrorInvalidArgs);
// Ensure the new name does not match the current one.
VerifyOrExit(memcmp(m8, aNameData.GetBuffer(), newLen) || (m8[newLen] != '\0'), error = OT_ERROR_ALREADY);
VerifyOrExit(memcmp(m8, aNameData.GetBuffer(), newLen) || (m8[newLen] != '\0'), error = kErrorAlready);
memcpy(m8, aNameData.GetBuffer(), newLen);
m8[newLen] = '\0';
@@ -162,15 +162,15 @@ NameData DomainName::GetAsData(void) const
return NameData(m8, len);
}
otError DomainName::Set(const NameData &aNameData)
Error DomainName::Set(const NameData &aNameData)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
uint8_t newLen = static_cast<uint8_t>(StringLength(aNameData.GetBuffer(), aNameData.GetLength()));
VerifyOrExit(newLen <= kMaxSize, error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(newLen <= kMaxSize, error = kErrorInvalidArgs);
// Ensure the new name does not match the current one.
VerifyOrExit(memcmp(m8, aNameData.GetBuffer(), newLen) || (m8[newLen] != '\0'), error = OT_ERROR_ALREADY);
VerifyOrExit(memcmp(m8, aNameData.GetBuffer(), newLen) || (m8[newLen] != '\0'), error = kErrorAlready);
memcpy(m8, aNameData.GetBuffer(), newLen);
m8[newLen] = '\0';
+8 -8
View File
@@ -564,12 +564,12 @@ public:
*
* @param[in] aNameData A reference to name data.
*
* @retval OT_ERROR_NONE Successfully set the IEEE 802.15.4 Network Name.
* @retval OT_ERROR_ALREADY The name is already set to the same string.
* @retval OT_ERROR_INVALID_ARGS Given name is too long.
* @retval kErrorNone Successfully set the IEEE 802.15.4 Network Name.
* @retval kErrorAlready The name is already set to the same string.
* @retval kErrorInvalidArgs Given name is too long.
*
*/
otError Set(const NameData &aNameData);
Error Set(const NameData &aNameData);
/**
* This method overloads operator `==` to evaluate whether or not two given `NetworkName` objects are equal.
@@ -623,12 +623,12 @@ public:
*
* @param[in] aNameData A reference to name data.
*
* @retval OT_ERROR_NONE Successfully set the Thread Domain Name.
* @retval OT_ERROR_ALREADY The name is already set to the same string.
* @retval OT_ERROR_INVALID_ARGS Given name is too long.
* @retval kErrorNone Successfully set the Thread Domain Name.
* @retval kErrorAlready The name is already set to the same string.
* @retval kErrorInvalidArgs Given name is too long.
*
*/
otError Set(const NameData &aNameData);
Error Set(const NameData &aNameData);
private:
char m8[kMaxSize + 1]; ///< Byte values.
+42 -43
View File
@@ -151,9 +151,9 @@ void SubMac::SetPcapCallback(otLinkPcapCallback aPcapCallback, void *aCallbackCo
mPcapCallbackContext = aCallbackContext;
}
otError SubMac::Enable(void)
Error SubMac::Enable(void)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
VerifyOrExit(mState == kStateDisabled);
@@ -163,13 +163,13 @@ otError SubMac::Enable(void)
SetState(kStateSleep);
exit:
OT_ASSERT(error == OT_ERROR_NONE);
OT_ASSERT(error == kErrorNone);
return error;
}
otError SubMac::Disable(void)
Error SubMac::Disable(void)
{
otError error;
Error error;
mTimer.Stop();
SuccessOrExit(error = Get<Radio>().Sleep());
@@ -180,13 +180,13 @@ exit:
return error;
}
otError SubMac::Sleep(void)
Error SubMac::Sleep(void)
{
otError error = Get<Radio>().Sleep();
Error error = Get<Radio>().Sleep();
if (error != OT_ERROR_NONE)
if (error != kErrorNone)
{
otLogWarnMac("RadioSleep() failed, error: %s", otThreadErrorToString(error));
otLogWarnMac("RadioSleep() failed, error: %s", ErrorToString(error));
ExitNow();
}
@@ -196,13 +196,13 @@ exit:
return error;
}
otError SubMac::Receive(uint8_t aChannel)
Error SubMac::Receive(uint8_t aChannel)
{
otError error = Get<Radio>().Receive(aChannel);
Error error = Get<Radio>().Receive(aChannel);
if (error != OT_ERROR_NONE)
if (error != kErrorNone)
{
otLogWarnMac("RadioReceive() failed, error: %s", otThreadErrorToString(error));
otLogWarnMac("RadioReceive() failed, error: %s", ErrorToString(error));
ExitNow();
}
@@ -213,9 +213,9 @@ exit:
}
#if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE
otError SubMac::CslSample(uint8_t aPanChannel)
Error SubMac::CslSample(uint8_t aPanChannel)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
if (!IsCslChannelSpecified())
{
@@ -233,7 +233,7 @@ otError SubMac::CslSample(uint8_t aPanChannel)
#endif
break;
case kCslIdle:
ExitNow(error = OT_ERROR_INVALID_STATE);
ExitNow(error = kErrorInvalidState);
default:
OT_ASSERT(false);
}
@@ -241,17 +241,17 @@ otError SubMac::CslSample(uint8_t aPanChannel)
SetState(kStateCslSample);
exit:
if (error != OT_ERROR_NONE)
if (error != kErrorNone)
{
otLogWarnMac("CslSample() failed, error: %s", otThreadErrorToString(error));
otLogWarnMac("CslSample() failed, error: %s", ErrorToString(error));
}
return error;
}
#endif
void SubMac::HandleReceiveDone(RxFrame *aFrame, otError aError)
void SubMac::HandleReceiveDone(RxFrame *aFrame, Error aError)
{
if (mPcapCallback && (aFrame != nullptr) && (aError == OT_ERROR_NONE))
if (mPcapCallback && (aFrame != nullptr) && (aError == kErrorNone))
{
mPcapCallback(aFrame, false, mPcapCallbackContext);
}
@@ -262,7 +262,7 @@ void SubMac::HandleReceiveDone(RxFrame *aFrame, otError aError)
}
#if OPENTHREAD_CONFIG_MAC_CSL_DEBUG_ENABLE
if (aFrame != nullptr && aError == OT_ERROR_NONE)
if (aFrame != nullptr && aError == kErrorNone)
{
// Split the log into two lines for RTT to output
otLogDebgMac("Received frame in state (SubMac %s, CSL %s), timestamp %u", StateToString(mState),
@@ -275,9 +275,9 @@ void SubMac::HandleReceiveDone(RxFrame *aFrame, otError aError)
mCallbacks.ReceiveDone(aFrame, aError);
}
otError SubMac::Send(void)
Error SubMac::Send(void)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
switch (mState)
{
@@ -288,7 +288,7 @@ otError SubMac::Send(void)
#endif
case kStateTransmit:
case kStateEnergyScan:
ExitNow(error = OT_ERROR_INVALID_STATE);
ExitNow(error = kErrorInvalidState);
OT_UNREACHABLE_CODE(break);
case kStateSleep:
@@ -409,7 +409,7 @@ exit:
void SubMac::BeginTransmit(void)
{
otError error;
Error error;
OT_UNUSED_VARIABLE(error);
@@ -422,7 +422,7 @@ void SubMac::BeginTransmit(void)
if ((mRadioCaps & OT_RADIO_CAPS_SLEEP_TO_TX) == 0)
{
error = Get<Radio>().Receive(mTransmitFrame.GetChannel());
OT_ASSERT(error == OT_ERROR_NONE);
OT_ASSERT(error == kErrorNone);
}
SetState(kStateTransmit);
@@ -433,14 +433,14 @@ void SubMac::BeginTransmit(void)
}
error = Get<Radio>().Transmit(mTransmitFrame);
if (error == OT_ERROR_INVALID_STATE && mTransmitFrame.mInfo.mTxInfo.mTxDelay > 0)
if (error == kErrorInvalidState && mTransmitFrame.mInfo.mTxInfo.mTxDelay > 0)
{
// Platform `transmit_at` fails and we send the frame directly.
mTransmitFrame.mInfo.mTxInfo.mTxDelay = 0;
mTransmitFrame.mInfo.mTxInfo.mTxDelayBaseTime = 0;
error = Get<Radio>().Transmit(mTransmitFrame);
}
OT_ASSERT(error == OT_ERROR_NONE);
OT_ASSERT(error == kErrorNone);
exit:
return;
@@ -458,7 +458,7 @@ void SubMac::HandleTransmitStarted(TxFrame &aFrame)
}
}
void SubMac::HandleTransmitDone(TxFrame &aFrame, RxFrame *aAckFrame, otError aError)
void SubMac::HandleTransmitDone(TxFrame &aFrame, RxFrame *aAckFrame, Error aError)
{
bool ccaSuccess = true;
bool shouldRetx;
@@ -471,18 +471,18 @@ void SubMac::HandleTransmitDone(TxFrame &aFrame, RxFrame *aAckFrame, otError aEr
switch (aError)
{
case OT_ERROR_ABORT:
case kErrorAbort:
// Do not record CCA status in case of `ABORT` error
// since there may be no CCA check performed by radio.
break;
case OT_ERROR_CHANNEL_ACCESS_FAILURE:
case kErrorChannelAccessFailure:
ccaSuccess = false;
OT_FALL_THROUGH;
case OT_ERROR_NONE:
case OT_ERROR_NO_ACK:
case kErrorNone:
case kErrorNoAck:
if (aFrame.IsCsmaCaEnabled())
{
mCallbacks.RecordCcaStatus(ccaSuccess, aFrame.GetChannel());
@@ -510,8 +510,7 @@ void SubMac::HandleTransmitDone(TxFrame &aFrame, RxFrame *aAckFrame, otError aEr
// Determine whether to re-transmit the frame.
shouldRetx =
((aError != OT_ERROR_NONE) && ShouldHandleRetries() && (mTransmitRetries < aFrame.GetMaxFrameRetries()));
shouldRetx = ((aError != kErrorNone) && ShouldHandleRetries() && (mTransmitRetries < aFrame.GetMaxFrameRetries()));
mCallbacks.RecordFrameTransmitStatus(aFrame, aAckFrame, aError, mTransmitRetries, shouldRetx);
@@ -554,10 +553,10 @@ void SubMac::UpdateFrameCounterOnTxDone(const TxFrame &aFrame)
allowError = Get<LinkRaw>().IsEnabled();
#endif
VerifyOrExit(aFrame.GetKeyIdMode(keyIdMode) == OT_ERROR_NONE, OT_ASSERT(allowError));
VerifyOrExit(aFrame.GetKeyIdMode(keyIdMode) == kErrorNone, OT_ASSERT(allowError));
VerifyOrExit(keyIdMode == Frame::kKeyIdMode1);
VerifyOrExit(aFrame.GetFrameCounter(frameCounter) == OT_ERROR_NONE, OT_ASSERT(allowError));
VerifyOrExit(aFrame.GetFrameCounter(frameCounter) == kErrorNone, OT_ASSERT(allowError));
UpdateFrameCounter(frameCounter);
exit:
@@ -574,9 +573,9 @@ int8_t SubMac::GetNoiseFloor(void)
return Get<Radio>().GetReceiveSensitivity();
}
otError SubMac::EnergyScan(uint8_t aScanChannel, uint16_t aScanDuration)
Error SubMac::EnergyScan(uint8_t aScanChannel, uint16_t aScanDuration)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
switch (mState)
{
@@ -587,7 +586,7 @@ otError SubMac::EnergyScan(uint8_t aScanChannel, uint16_t aScanDuration)
case kStateCslTransmit:
#endif
case kStateEnergyScan:
ExitNow(error = OT_ERROR_INVALID_STATE);
ExitNow(error = kErrorInvalidState);
case kStateReceive:
case kStateSleep:
@@ -605,7 +604,7 @@ otError SubMac::EnergyScan(uint8_t aScanChannel, uint16_t aScanDuration)
else if (ShouldHandleEnergyScan())
{
error = Get<Radio>().Receive(aScanChannel);
OT_ASSERT(error == OT_ERROR_NONE);
OT_ASSERT(error == kErrorNone);
SetState(kStateEnergyScan);
mEnergyScanMaxRssi = kInvalidRssiValue;
@@ -614,7 +613,7 @@ otError SubMac::EnergyScan(uint8_t aScanChannel, uint16_t aScanDuration)
}
else
{
error = OT_ERROR_NOT_IMPLEMENTED;
error = kErrorNotImplemented;
}
exit:
@@ -676,7 +675,7 @@ void SubMac::HandleTimer(void)
case kStateTransmit:
otLogDebgMac("Ack timer timed out");
IgnoreError(Get<Radio>().Receive(mTransmitFrame.GetChannel()));
HandleTransmitDone(mTransmitFrame, nullptr, OT_ERROR_NO_ACK);
HandleTransmitDone(mTransmitFrame, nullptr, kErrorNoAck);
break;
case kStateEnergyScan:
+39 -39
View File
@@ -116,12 +116,12 @@ public:
* This method notifies user of `SubMac` of a received frame.
*
* @param[in] aFrame A pointer to the received frame or nullptr if the receive operation failed.
* @param[in] aError OT_ERROR_NONE when successfully received a frame,
* OT_ERROR_ABORT when reception was aborted and a frame was not received,
* OT_ERROR_NO_BUFS when a frame could not be received due to lack of rx buffer space.
* @param[in] aError kErrorNone when successfully received a frame,
* kErrorAbort when reception was aborted and a frame was not received,
* kErrorNoBufs when a frame could not be received due to lack of rx buffer space.
*
*/
void ReceiveDone(RxFrame *aFrame, otError aError);
void ReceiveDone(RxFrame *aFrame, Error aError);
/**
* This method notifies user of `SubMac` of CCA status (success/failure) for a frame transmission attempt.
@@ -144,10 +144,10 @@ public:
*
* @param[in] aFrame The transmitted frame.
* @param[in] aAckFrame A pointer to the ACK frame, or nullptr if no ACK was received.
* @param[in] aError OT_ERROR_NONE when the frame was transmitted successfully,
* OT_ERROR_NO_ACK when the frame was transmitted but no ACK was received,
* OT_ERROR_CHANNEL_ACCESS_FAILURE tx failed due to activity on the channel,
* OT_ERROR_ABORT when transmission was aborted for other reasons.
* @param[in] aError kErrorNone when the frame was transmitted successfully,
* kErrorNoAck when the frame was transmitted but no ACK was received,
* kErrorChannelAccessFailure tx failed due to activity on the channel,
* kErrorAbort when transmission was aborted for other reasons.
* @param[in] aRetryCount Current retry count. This is valid only when sub-mac handles frame re-transmissions.
* @param[in] aWillRetx Indicates whether frame will be retransmitted or not. This is applicable only
* when there was an error in current transmission attempt.
@@ -155,7 +155,7 @@ public:
*/
void RecordFrameTransmitStatus(const TxFrame &aFrame,
const RxFrame *aAckFrame,
otError aError,
Error aError,
uint8_t aRetryCount,
bool aWillRetx);
@@ -165,13 +165,13 @@ public:
*
* @param[in] aFrame The transmitted frame.
* @param[in] aAckFrame A pointer to the ACK frame, nullptr if no ACK was received.
* @param[in] aError OT_ERROR_NONE when the frame was transmitted,
* OT_ERROR_NO_ACK when the frame was transmitted but no ACK was received,
* OT_ERROR_CHANNEL_ACCESS_FAILURE tx failed due to activity on the channel,
* OT_ERROR_ABORT when transmission was aborted for other reasons.
* @param[in] aError kErrorNone when the frame was transmitted,
* kErrorNoAck when the frame was transmitted but no ACK was received,
* kErrorChannelAccessFailure tx failed due to activity on the channel,
* kErrorAbort when transmission was aborted for other reasons.
*
*/
void TransmitDone(TxFrame &aFrame, RxFrame *aAckFrame, otError aError);
void TransmitDone(TxFrame &aFrame, RxFrame *aAckFrame, Error aError);
/**
* This method notifies user of `SubMac` that energy scan is complete.
@@ -275,29 +275,29 @@ public:
/**
* This method enables the radio.
*
* @retval OT_ERROR_NONE Successfully enabled.
* @retval OT_ERROR_FAILED The radio could not be enabled.
* @retval kErrorNone Successfully enabled.
* @retval kErrorFailed The radio could not be enabled.
*
*/
otError Enable(void);
Error Enable(void);
/**
* This method disables the radio.
*
* @retval OT_ERROR_NONE Successfully disabled the radio.
* @retval kErrorNone Successfully disabled the radio.
*
*/
otError Disable(void);
Error Disable(void);
/**
* This method transitions the radio to Sleep.
*
* @retval OT_ERROR_NONE Successfully transitioned to Sleep.
* @retval OT_ERROR_BUSY The radio was transmitting.
* @retval OT_ERROR_INVALID_STATE The radio was disabled.
* @retval kErrorNone Successfully transitioned to Sleep.
* @retval kErrorBusy The radio was transmitting.
* @retval kErrorInvalidState The radio was disabled.
*
*/
otError Sleep(void);
Error Sleep(void);
/**
* This method indicates whether the sub-mac is busy transmitting or scanning.
@@ -313,11 +313,11 @@ public:
*
* @param[in] aChannel The channel to use for receiving.
*
* @retval OT_ERROR_NONE Successfully transitioned to Receive.
* @retval OT_ERROR_INVALID_STATE The radio was disabled or transmitting.
* @retval kErrorNone Successfully transitioned to Receive.
* @retval kErrorInvalidState The radio was disabled or transmitting.
*
*/
otError Receive(uint8_t aChannel);
Error Receive(uint8_t aChannel);
#if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE
/**
@@ -330,12 +330,12 @@ public:
* @param[in] aPanChannel The current phy channel used by the device. This param will only take effect when CSL
* channel hasn't been explicitly specified.
*
* @retval OT_ERROR_NONE Successfully entered CSL operation (sleep or receive according to CSL timer).
* @retval OT_ERROR_BUSY The radio was transmitting.
* @retval OT_ERROR_INVALID_STATE The radio was disabled.
* @retval kErrorNone Successfully entered CSL operation (sleep or receive according to CSL timer).
* @retval kErrorBusy The radio was transmitting.
* @retval kErrorInvalidState The radio was disabled.
*
*/
otError CslSample(uint8_t aPanChannel);
Error CslSample(uint8_t aPanChannel);
#endif
/**
@@ -353,11 +353,11 @@ public:
*
* The `SubMac` layer handles Ack timeout, CSMA backoff, and frame retransmission.
*
* @retval OT_ERROR_NONE Successfully started the frame transmission
* @retval OT_ERROR_INVALID_STATE The radio was disabled or transmitting.
* @retval kErrorNone Successfully started the frame transmission
* @retval kErrorInvalidState The radio was disabled or transmitting.
*
*/
otError Send(void);
Error Send(void);
/**
* This method gets the number of transmit retries of last transmitted frame.
@@ -381,12 +381,12 @@ public:
* @param[in] aScanChannel The channel to perform the energy scan on.
* @param[in] aScanDuration The duration, in milliseconds, for the channel to be scanned.
*
* @retval OT_ERROR_NONE Successfully started scanning the channel.
* @retval OT_ERROR_INVALID_STATE The radio was disabled or transmitting.
* @retval OT_ERROR_NOT_IMPLEMENTED Energy scan is not supported (applicable in link-raw/radio mode only).
* @retval kErrorNone Successfully started scanning the channel.
* @retval kErrorInvalidState The radio was disabled or transmitting.
* @retval kErrorNotImplemented Energy scan is not supported (applicable in link-raw/radio mode only).
*
*/
otError EnergyScan(uint8_t aScanChannel, uint16_t aScanDuration);
Error EnergyScan(uint8_t aScanChannel, uint16_t aScanDuration);
/**
* This method returns the noise floor value (currently use the radio receive sensitivity value).
@@ -596,9 +596,9 @@ private:
void BeginTransmit(void);
void SampleRssi(void);
void HandleReceiveDone(RxFrame *aFrame, otError aError);
void HandleReceiveDone(RxFrame *aFrame, Error aError);
void HandleTransmitStarted(TxFrame &aFrame);
void HandleTransmitDone(TxFrame &aFrame, RxFrame *aAckFrame, otError aError);
void HandleTransmitDone(TxFrame &aFrame, RxFrame *aAckFrame, Error aError);
void UpdateFrameCounterOnTxDone(const TxFrame &aFrame);
void HandleEnergyScanDone(int8_t aMaxRssi);
+6 -6
View File
@@ -51,7 +51,7 @@ SubMac::Callbacks::Callbacks(Instance &aInstance)
#if OPENTHREAD_FTD || OPENTHREAD_MTD
void SubMac::Callbacks::ReceiveDone(RxFrame *aFrame, otError aError)
void SubMac::Callbacks::ReceiveDone(RxFrame *aFrame, Error aError)
{
#if OPENTHREAD_CONFIG_LINK_RAW_ENABLE
if (Get<LinkRaw>().IsEnabled())
@@ -72,14 +72,14 @@ void SubMac::Callbacks::RecordCcaStatus(bool aCcaSuccess, uint8_t aChannel)
void SubMac::Callbacks::RecordFrameTransmitStatus(const TxFrame &aFrame,
const RxFrame *aAckFrame,
otError aError,
Error aError,
uint8_t aRetryCount,
bool aWillRetx)
{
Get<Mac>().RecordFrameTransmitStatus(aFrame, aAckFrame, aError, aRetryCount, aWillRetx);
}
void SubMac::Callbacks::TransmitDone(TxFrame &aFrame, RxFrame *aAckFrame, otError aError)
void SubMac::Callbacks::TransmitDone(TxFrame &aFrame, RxFrame *aAckFrame, Error aError)
{
#if OPENTHREAD_CONFIG_LINK_RAW_ENABLE
if (Get<LinkRaw>().IsEnabled())
@@ -114,7 +114,7 @@ void SubMac::Callbacks::FrameCounterUpdated(uint32_t aFrameCounter)
#elif OPENTHREAD_RADIO
void SubMac::Callbacks::ReceiveDone(RxFrame *aFrame, otError aError)
void SubMac::Callbacks::ReceiveDone(RxFrame *aFrame, Error aError)
{
Get<LinkRaw>().InvokeReceiveDone(aFrame, aError);
}
@@ -125,14 +125,14 @@ void SubMac::Callbacks::RecordCcaStatus(bool, uint8_t)
void SubMac::Callbacks::RecordFrameTransmitStatus(const TxFrame &aFrame,
const RxFrame *aAckFrame,
otError aError,
Error aError,
uint8_t aRetryCount,
bool aWillRetx)
{
Get<LinkRaw>().RecordFrameTransmitStatus(aFrame, aAckFrame, aError, aRetryCount, aWillRetx);
}
void SubMac::Callbacks::TransmitDone(TxFrame &aFrame, RxFrame *aAckFrame, otError aError)
void SubMac::Callbacks::TransmitDone(TxFrame &aFrame, RxFrame *aAckFrame, Error aError)
{
Get<LinkRaw>().InvokeTransmitDone(aFrame, aAckFrame, aError);
}
+7 -7
View File
@@ -53,18 +53,18 @@ AnnounceBeginClient::AnnounceBeginClient(Instance &aInstance)
{
}
otError AnnounceBeginClient::SendRequest(uint32_t aChannelMask,
uint8_t aCount,
uint16_t aPeriod,
const Ip6::Address &aAddress)
Error AnnounceBeginClient::SendRequest(uint32_t aChannelMask,
uint8_t aCount,
uint16_t aPeriod,
const Ip6::Address &aAddress)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
MeshCoP::ChannelMaskTlv channelMask;
Ip6::MessageInfo messageInfo;
Coap::Message * message = nullptr;
VerifyOrExit(Get<MeshCoP::Commissioner>().IsActive(), error = OT_ERROR_INVALID_STATE);
VerifyOrExit((message = MeshCoP::NewMeshCoPMessage(Get<Tmf::TmfAgent>())) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit(Get<MeshCoP::Commissioner>().IsActive(), error = kErrorInvalidState);
VerifyOrExit((message = MeshCoP::NewMeshCoPMessage(Get<Tmf::TmfAgent>())) != nullptr, error = kErrorNoBufs);
SuccessOrExit(error = message->InitAsPost(aAddress, UriPath::kAnnounceBegin));
SuccessOrExit(error = message->SetPayloadMarker());
+3 -3
View File
@@ -64,11 +64,11 @@ public:
* @param[in] aPeriod The time between two successive MLE Announce transmissions (in milliseconds).
* @param[in] aAddress The destination address.
*
* @retval OT_ERROR_NONE Successfully enqueued the Announce Begin message.
* @retval OT_ERROR_NO_BUFS Insufficient buffers to generate a Announce Begin message.
* @retval kErrorNone Successfully enqueued the Announce Begin message.
* @retval kErrorNoBufs Insufficient buffers to generate a Announce Begin message.
*
*/
otError SendRequest(uint32_t aChannelMask, uint8_t aCount, uint16_t aPeriod, const Ip6::Address &aAddress);
Error SendRequest(uint32_t aChannelMask, uint8_t aCount, uint16_t aPeriod, const Ip6::Address &aAddress);
};
/**
+47 -48
View File
@@ -62,7 +62,7 @@ void BorderAgent::ForwardContext::Init(Instance & aInstance,
memcpy(mToken, aMessage.GetToken(), mTokenLength);
}
otError BorderAgent::ForwardContext::ToHeader(Coap::Message &aMessage, uint8_t aCode)
Error BorderAgent::ForwardContext::ToHeader(Coap::Message &aMessage, uint8_t aCode)
{
if ((mType == Coap::kTypeNonConfirmable) || mSeparate)
{
@@ -81,17 +81,17 @@ otError BorderAgent::ForwardContext::ToHeader(Coap::Message &aMessage, uint8_t a
return aMessage.SetToken(mToken, mTokenLength);
}
Coap::Message::Code BorderAgent::CoapCodeFromError(otError aError)
Coap::Message::Code BorderAgent::CoapCodeFromError(Error aError)
{
Coap::Message::Code code;
switch (aError)
{
case OT_ERROR_NONE:
case kErrorNone:
code = Coap::kCodeChanged;
break;
case OT_ERROR_PARSE:
case kErrorParse:
code = Coap::kCodeBadRequest;
break;
@@ -103,13 +103,13 @@ Coap::Message::Code BorderAgent::CoapCodeFromError(otError aError)
return code;
}
void BorderAgent::SendErrorMessage(ForwardContext &aForwardContext, otError aError)
void BorderAgent::SendErrorMessage(ForwardContext &aForwardContext, Error aError)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Coap::CoapSecure &coaps = Get<Coap::CoapSecure>();
Coap::Message * message = nullptr;
VerifyOrExit((message = NewMeshCoPMessage(coaps)) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((message = NewMeshCoPMessage(coaps)) != nullptr, error = kErrorNoBufs);
SuccessOrExit(error = aForwardContext.ToHeader(*message, CoapCodeFromError(aError)));
SuccessOrExit(error = coaps.SendMessage(*message, coaps.GetMessageInfo()));
@@ -118,13 +118,13 @@ exit:
LogError("send error CoAP message", error);
}
void BorderAgent::SendErrorMessage(const Coap::Message &aRequest, bool aSeparate, otError aError)
void BorderAgent::SendErrorMessage(const Coap::Message &aRequest, bool aSeparate, Error aError)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Coap::CoapSecure &coaps = Get<Coap::CoapSecure>();
Coap::Message * message = nullptr;
VerifyOrExit((message = NewMeshCoPMessage(coaps)) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((message = NewMeshCoPMessage(coaps)) != nullptr, error = kErrorNoBufs);
if (aRequest.IsNonConfirmable() || aSeparate)
{
@@ -152,7 +152,7 @@ exit:
void BorderAgent::HandleCoapResponse(void * aContext,
otMessage * aMessage,
const otMessageInfo *aMessageInfo,
otError aResult)
Error aResult)
{
OT_UNUSED_VARIABLE(aMessageInfo);
@@ -162,13 +162,13 @@ void BorderAgent::HandleCoapResponse(void * aContext,
aResult);
}
void BorderAgent::HandleCoapResponse(ForwardContext &aForwardContext, const Coap::Message *aResponse, otError aResult)
void BorderAgent::HandleCoapResponse(ForwardContext &aForwardContext, const Coap::Message *aResponse, Error aResult)
{
Coap::Message *message = nullptr;
otError error;
Error error;
SuccessOrExit(error = aResult);
VerifyOrExit((message = NewMeshCoPMessage(Get<Coap::CoapSecure>())) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((message = NewMeshCoPMessage(Get<Coap::CoapSecure>())) != nullptr, error = kErrorNoBufs);
if (aForwardContext.IsPetition() && aResponse->GetCode() == Coap::kCodeChanged)
{
@@ -199,12 +199,11 @@ void BorderAgent::HandleCoapResponse(ForwardContext &aForwardContext, const Coap
exit:
if (error != OT_ERROR_NONE)
if (error != kErrorNone)
{
FreeMessage(message);
otLogWarnMeshCoP("Commissioner request[%hu] failed: %s", aForwardContext.GetMessageId(),
otThreadErrorToString(error));
otLogWarnMeshCoP("Commissioner request[%hu] failed: %s", aForwardContext.GetMessageId(), ErrorToString(error));
SendErrorMessage(aForwardContext, error);
}
@@ -316,13 +315,13 @@ void BorderAgent::HandleProxyTransmit(const Coap::Message &aMessage)
Message * message = nullptr;
Ip6::MessageInfo messageInfo;
uint16_t offset;
otError error;
Error error;
UdpEncapsulationTlv tlv;
SuccessOrExit(error = Tlv::FindTlvOffset(aMessage, Tlv::kUdpEncapsulation, offset));
SuccessOrExit(error = aMessage.Read(offset, tlv));
VerifyOrExit((message = Get<Ip6::Udp>().NewMessage(0)) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((message = Get<Ip6::Udp>().NewMessage(0)) != nullptr, error = kErrorNoBufs);
SuccessOrExit(error = message->SetLength(tlv.GetUdpLength()));
aMessage.CopyTo(offset + sizeof(tlv), 0, tlv.GetUdpLength(), *message);
@@ -342,15 +341,15 @@ exit:
bool BorderAgent::HandleUdpReceive(const Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
{
otError error;
Error error;
Coap::Message *message = nullptr;
VerifyOrExit(aMessageInfo.GetSockAddr() == mCommissionerAloc.GetAddress(),
error = OT_ERROR_DESTINATION_ADDRESS_FILTERED);
error = kErrorDestinationAddressFiltered);
VerifyOrExit(aMessage.GetLength() > 0, error = OT_ERROR_NONE);
VerifyOrExit(aMessage.GetLength() > 0, error = kErrorNone);
VerifyOrExit((message = NewMeshCoPMessage(Get<Coap::CoapSecure>())) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((message = NewMeshCoPMessage(Get<Coap::CoapSecure>())) != nullptr, error = kErrorNoBufs);
message->InitAsNonConfirmablePost();
SuccessOrExit(error = message->AppendUriPathOptions(UriPath::kProxyRx));
@@ -382,16 +381,16 @@ exit:
FreeMessageOnError(message, error);
LogError("notify commissioner on ProxyRx (c/ur)", error);
return error != OT_ERROR_DESTINATION_ADDRESS_FILTERED;
return error != kErrorDestinationAddressFiltered;
}
void BorderAgent::HandleRelayReceive(const Coap::Message &aMessage)
{
Coap::Message *message = nullptr;
otError error;
Error error;
VerifyOrExit(aMessage.IsNonConfirmablePostRequest(), error = OT_ERROR_DROP);
VerifyOrExit((message = NewMeshCoPMessage(Get<Coap::CoapSecure>())) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit(aMessage.IsNonConfirmablePostRequest(), error = kErrorDrop);
VerifyOrExit((message = NewMeshCoPMessage(Get<Coap::CoapSecure>())) != nullptr, error = kErrorNoBufs);
message->InitAsNonConfirmablePost();
SuccessOrExit(error = message->AppendUriPathOptions(UriPath::kRelayRx));
@@ -408,9 +407,9 @@ exit:
FreeMessageOnError(message, error);
}
otError BorderAgent::ForwardToCommissioner(Coap::Message &aForwardMessage, const Message &aMessage)
Error BorderAgent::ForwardToCommissioner(Coap::Message &aForwardMessage, const Message &aMessage)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
uint16_t offset = 0;
offset = aForwardMessage.GetLength();
@@ -429,11 +428,11 @@ exit:
void BorderAgent::HandleKeepAlive(const Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
{
otError error;
Error error;
error = ForwardToLeader(aMessage, aMessageInfo, UriPath::kLeaderKeepAlive, false, true);
if (error == OT_ERROR_NONE)
if (error == kErrorNone)
{
mTimer.Start(kKeepAliveTimeout);
}
@@ -441,7 +440,7 @@ void BorderAgent::HandleKeepAlive(const Coap::Message &aMessage, const Ip6::Mess
void BorderAgent::HandleRelayTransmit(const Coap::Message &aMessage)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
uint16_t joinerRouterRloc;
Coap::Message * message = nullptr;
Ip6::MessageInfo messageInfo;
@@ -451,7 +450,7 @@ void BorderAgent::HandleRelayTransmit(const Coap::Message &aMessage)
SuccessOrExit(error = Tlv::Find<JoinerRouterLocatorTlv>(aMessage, joinerRouterRloc));
VerifyOrExit((message = NewMeshCoPMessage(Get<Tmf::TmfAgent>())) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((message = NewMeshCoPMessage(Get<Tmf::TmfAgent>())) != nullptr, error = kErrorNoBufs);
SuccessOrExit(error = message->InitAsNonConfirmablePost(UriPath::kRelayTx));
SuccessOrExit(error = message->SetPayloadMarker());
@@ -475,19 +474,19 @@ exit:
LogError("send to joiner router request RelayTx (c/tx)", error);
}
otError BorderAgent::ForwardToLeader(const Coap::Message & aMessage,
const Ip6::MessageInfo &aMessageInfo,
const char * aPath,
bool aPetition,
bool aSeparate)
Error BorderAgent::ForwardToLeader(const Coap::Message & aMessage,
const Ip6::MessageInfo &aMessageInfo,
const char * aPath,
bool aPetition,
bool aSeparate)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
ForwardContext * forwardContext = nullptr;
Ip6::MessageInfo messageInfo;
Coap::Message * message = nullptr;
uint16_t offset = 0;
VerifyOrExit((message = NewMeshCoPMessage(Get<Tmf::TmfAgent>())) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((message = NewMeshCoPMessage(Get<Tmf::TmfAgent>())) != nullptr, error = kErrorNoBufs);
if (aSeparate)
{
@@ -495,7 +494,7 @@ otError BorderAgent::ForwardToLeader(const Coap::Message & aMessage,
}
forwardContext = static_cast<ForwardContext *>(Instance::HeapCAlloc(1, sizeof(ForwardContext)));
VerifyOrExit(forwardContext != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit(forwardContext != nullptr, error = kErrorNoBufs);
forwardContext->Init(GetInstance(), aMessage, aPetition, aSeparate);
@@ -526,7 +525,7 @@ otError BorderAgent::ForwardToLeader(const Coap::Message & aMessage,
exit:
LogError("forward to leader", error);
if (error != OT_ERROR_NONE)
if (error != kErrorNone)
{
if (forwardContext != nullptr)
{
@@ -562,12 +561,12 @@ void BorderAgent::HandleConnected(bool aConnected)
}
}
otError BorderAgent::Start(void)
Error BorderAgent::Start(void)
{
otError error;
Error error;
Coap::CoapSecure &coaps = Get<Coap::CoapSecure>();
VerifyOrExit(mState == kStateStopped, error = OT_ERROR_ALREADY);
VerifyOrExit(mState == kStateStopped, error = kErrorAlready);
SuccessOrExit(error = coaps.Start(kBorderAgentUdpPort));
SuccessOrExit(error = coaps.SetPsk(Get<KeyManager>().GetPskc().m8, OT_PSKC_MAX_SIZE));
@@ -606,12 +605,12 @@ void BorderAgent::HandleTimeout(void)
}
}
otError BorderAgent::Stop(void)
Error BorderAgent::Stop(void)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Coap::CoapSecure &coaps = Get<Coap::CoapSecure>();
VerifyOrExit(mState != kStateStopped, error = OT_ERROR_ALREADY);
VerifyOrExit(mState != kStateStopped, error = kErrorAlready);
mTimer.Stop();
+14 -14
View File
@@ -75,20 +75,20 @@ public:
/**
* This method starts the Border Agent service.
*
* @retval OT_ERROR_NONE Successfully started the Border Agent service.
* @retval OT_ERROR_ALREADY Border Agent is already started.
* @retval kErrorNone Successfully started the Border Agent service.
* @retval kErrorAlready Border Agent is already started.
*
*/
otError Start(void);
Error Start(void);
/**
* This method stops the Border Agent service.
*
* @retval OT_ERROR_NONE Successfully stopped the Border Agent service.
* @retval OT_ERROR_ALREADY Border Agent is already stopped.
* @retval kErrorNone Successfully stopped the Border Agent service.
* @retval kErrorAlready Border Agent is already stopped.
*
*/
otError Stop(void);
Error Stop(void);
/**
* This method gets the state of the Border Agent service.
@@ -111,7 +111,7 @@ private:
void Init(Instance &aInstance, const Coap::Message &aMessage, bool aPetition, bool aSeparate);
bool IsPetition(void) const { return mPetition; }
uint16_t GetMessageId(void) const { return mMessageId; }
otError ToHeader(Coap::Message &aMessage, uint8_t aCode);
Error ToHeader(Coap::Message &aMessage, uint8_t aCode);
private:
uint16_t mMessageId; // The CoAP Message ID of the original request.
@@ -124,9 +124,9 @@ private:
void HandleNotifierEvents(Events aEvents);
Coap::Message::Code CoapCodeFromError(otError aError);
void SendErrorMessage(ForwardContext &aForwardContext, otError aError);
void SendErrorMessage(const Coap::Message &aRequest, bool aSeparate, otError aError);
Coap::Message::Code CoapCodeFromError(Error aError);
void SendErrorMessage(ForwardContext &aForwardContext, Error aError);
void SendErrorMessage(const Coap::Message &aRequest, bool aSeparate, Error aError);
static void HandleConnected(bool aConnected, void *aContext);
void HandleConnected(bool aConnected);
@@ -140,15 +140,15 @@ private:
static void HandleCoapResponse(void * aContext,
otMessage * aMessage,
const otMessageInfo *aMessageInfo,
otError aResult);
void HandleCoapResponse(ForwardContext &aForwardContext, const Coap::Message *aResponse, otError aResult);
Error aResult);
void HandleCoapResponse(ForwardContext &aForwardContext, const Coap::Message *aResponse, Error aResult);
otError ForwardToLeader(const Coap::Message & aMessage,
Error ForwardToLeader(const Coap::Message & aMessage,
const Ip6::MessageInfo &aMessageInfo,
const char * aPath,
bool aPetition,
bool aSeparate);
otError ForwardToCommissioner(Coap::Message &aForwardMessage, const Message &aMessage);
Error ForwardToCommissioner(Coap::Message &aForwardMessage, const Message &aMessage);
void HandleKeepAlive(const Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
void HandleRelayTransmit(const Coap::Message &aMessage);
void HandleRelayReceive(const Coap::Message &aMessage);
+69 -69
View File
@@ -294,18 +294,18 @@ void Commissioner::RemoveJoinerEntry(Commissioner::Joiner &aJoiner)
SignalJoinerEvent(kJoinerEventRemoved, &joinerCopy);
}
otError Commissioner::Start(otCommissionerStateCallback aStateCallback,
otCommissionerJoinerCallback aJoinerCallback,
void * aCallbackContext)
Error Commissioner::Start(otCommissionerStateCallback aStateCallback,
otCommissionerJoinerCallback aJoinerCallback,
void * aCallbackContext)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
VerifyOrExit(Get<Mle::MleRouter>().IsAttached(), error = OT_ERROR_INVALID_STATE);
VerifyOrExit(mState == kStateDisabled, error = OT_ERROR_ALREADY);
VerifyOrExit(Get<Mle::MleRouter>().IsAttached(), error = kErrorInvalidState);
VerifyOrExit(mState == kStateDisabled, error = kErrorAlready);
#if OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE
error = Get<MeshCoP::BorderAgent>().Stop();
VerifyOrExit(error == OT_ERROR_NONE || error == OT_ERROR_ALREADY);
VerifyOrExit(error == kErrorNone || error == kErrorAlready);
#endif
SuccessOrExit(error = Get<Coap::CoapSecure>().Start(SendRelayTransmit, this));
@@ -320,7 +320,7 @@ otError Commissioner::Start(otCommissionerStateCallback aStateCallback,
SetState(kStatePetition);
exit:
if ((error != OT_ERROR_NONE) && (error != OT_ERROR_ALREADY))
if ((error != kErrorNone) && (error != kErrorAlready))
{
Get<Coap::CoapSecure>().Stop();
}
@@ -329,12 +329,12 @@ exit:
return error;
}
otError Commissioner::Stop(bool aResign)
Error Commissioner::Stop(bool aResign)
{
otError error = OT_ERROR_NONE;
bool needResign = false;
Error error = kErrorNone;
bool needResign = false;
VerifyOrExit(mState != kStateDisabled, error = OT_ERROR_ALREADY);
VerifyOrExit(mState != kStateDisabled, error = kErrorAlready);
Get<Coap::CoapSecure>().Stop();
@@ -398,10 +398,10 @@ exit:
void Commissioner::SendCommissionerSet(void)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
otCommissioningDataset dataset;
VerifyOrExit(mState == kStateActive, error = OT_ERROR_INVALID_STATE);
VerifyOrExit(mState == kStateActive, error = kErrorInvalidState);
memset(&dataset, 0, sizeof(dataset));
@@ -427,19 +427,19 @@ void Commissioner::ClearJoiners(void)
SendCommissionerSet();
}
otError Commissioner::AddJoiner(const Mac::ExtAddress *aEui64,
const JoinerDiscerner *aDiscerner,
const char * aPskd,
uint32_t aTimeout)
Error Commissioner::AddJoiner(const Mac::ExtAddress *aEui64,
const JoinerDiscerner *aDiscerner,
const char * aPskd,
uint32_t aTimeout)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Joiner *joiner;
VerifyOrExit(mState == kStateActive, error = OT_ERROR_INVALID_STATE);
VerifyOrExit(mState == kStateActive, error = kErrorInvalidState);
if (aDiscerner != nullptr)
{
VerifyOrExit(aDiscerner->IsValid(), error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(aDiscerner->IsValid(), error = kErrorInvalidArgs);
joiner = FindJoinerEntry(*aDiscerner);
}
else
@@ -452,7 +452,7 @@ otError Commissioner::AddJoiner(const Mac::ExtAddress *aEui64,
joiner = GetUnusedJoinerEntry();
}
VerifyOrExit(joiner != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit(joiner != nullptr, error = kErrorNoBufs);
SuccessOrExit(error = joiner->mPskd.SetFrom(aPskd));
@@ -514,9 +514,9 @@ exit:
return;
}
otError Commissioner::GetNextJoinerInfo(uint16_t &aIterator, otJoinerInfo &aJoinerInfo) const
Error Commissioner::GetNextJoinerInfo(uint16_t &aIterator, otJoinerInfo &aJoinerInfo) const
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
while (aIterator < OT_ARRAY_LENGTH(mJoiners))
{
@@ -529,22 +529,22 @@ otError Commissioner::GetNextJoinerInfo(uint16_t &aIterator, otJoinerInfo &aJoin
}
}
error = OT_ERROR_NOT_FOUND;
error = kErrorNotFound;
exit:
return error;
}
otError Commissioner::RemoveJoiner(const Mac::ExtAddress *aEui64, const JoinerDiscerner *aDiscerner, uint32_t aDelay)
Error Commissioner::RemoveJoiner(const Mac::ExtAddress *aEui64, const JoinerDiscerner *aDiscerner, uint32_t aDelay)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Joiner *joiner;
VerifyOrExit(mState == kStateActive, error = OT_ERROR_INVALID_STATE);
VerifyOrExit(mState == kStateActive, error = kErrorInvalidState);
if (aDiscerner != nullptr)
{
VerifyOrExit(aDiscerner->IsValid(), error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(aDiscerner->IsValid(), error = kErrorInvalidArgs);
joiner = FindJoinerEntry(*aDiscerner);
}
else
@@ -552,7 +552,7 @@ otError Commissioner::RemoveJoiner(const Mac::ExtAddress *aEui64, const JoinerDi
joiner = FindJoinerEntry(aEui64);
}
VerifyOrExit(joiner != nullptr, error = OT_ERROR_NOT_FOUND);
VerifyOrExit(joiner != nullptr, error = kErrorNotFound);
RemoveJoiner(*joiner, aDelay);
@@ -578,9 +578,9 @@ void Commissioner::RemoveJoiner(Joiner &aJoiner, uint32_t aDelay)
}
}
otError Commissioner::SetProvisioningUrl(const char *aProvisioningUrl)
Error Commissioner::SetProvisioningUrl(const char *aProvisioningUrl)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
uint8_t len;
if (aProvisioningUrl == nullptr)
@@ -589,11 +589,11 @@ otError Commissioner::SetProvisioningUrl(const char *aProvisioningUrl)
ExitNow();
}
VerifyOrExit(IsValidUtf8String(aProvisioningUrl), error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(IsValidUtf8String(aProvisioningUrl), error = kErrorInvalidArgs);
len = static_cast<uint8_t>(StringLength(aProvisioningUrl, sizeof(mProvisioningUrl)));
VerifyOrExit(len < sizeof(mProvisioningUrl), error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(len < sizeof(mProvisioningUrl), error = kErrorInvalidArgs);
memcpy(mProvisioningUrl, aProvisioningUrl, len);
mProvisioningUrl[len] = '\0';
@@ -682,14 +682,14 @@ void Commissioner::UpdateJoinerExpirationTimer(void)
}
}
otError Commissioner::SendMgmtCommissionerGetRequest(const uint8_t *aTlvs, uint8_t aLength)
Error Commissioner::SendMgmtCommissionerGetRequest(const uint8_t *aTlvs, uint8_t aLength)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Coap::Message * message;
Ip6::MessageInfo messageInfo;
MeshCoP::Tlv tlv;
VerifyOrExit((message = NewMeshCoPMessage(Get<Tmf::TmfAgent>())) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((message = NewMeshCoPMessage(Get<Tmf::TmfAgent>())) != nullptr, error = kErrorNoBufs);
SuccessOrExit(error = message->InitAsConfirmablePost(UriPath::kCommissionerGet));
@@ -722,7 +722,7 @@ exit:
void Commissioner::HandleMgmtCommissionerGetResponse(void * aContext,
otMessage * aMessage,
const otMessageInfo *aMessageInfo,
otError aResult)
Error aResult)
{
static_cast<Commissioner *>(aContext)->HandleMgmtCommissionerGetResponse(
static_cast<Coap::Message *>(aMessage), static_cast<const Ip6::MessageInfo *>(aMessageInfo), aResult);
@@ -730,26 +730,26 @@ void Commissioner::HandleMgmtCommissionerGetResponse(void * aConte
void Commissioner::HandleMgmtCommissionerGetResponse(Coap::Message * aMessage,
const Ip6::MessageInfo *aMessageInfo,
otError aResult)
Error aResult)
{
OT_UNUSED_VARIABLE(aMessageInfo);
VerifyOrExit(aResult == OT_ERROR_NONE && aMessage->GetCode() == Coap::kCodeChanged);
VerifyOrExit(aResult == kErrorNone && aMessage->GetCode() == Coap::kCodeChanged);
otLogInfoMeshCoP("received MGMT_COMMISSIONER_GET response");
exit:
return;
}
otError Commissioner::SendMgmtCommissionerSetRequest(const otCommissioningDataset &aDataset,
const uint8_t * aTlvs,
uint8_t aLength)
Error Commissioner::SendMgmtCommissionerSetRequest(const otCommissioningDataset &aDataset,
const uint8_t * aTlvs,
uint8_t aLength)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Coap::Message * message;
Ip6::MessageInfo messageInfo;
VerifyOrExit((message = NewMeshCoPMessage(Get<Tmf::TmfAgent>())) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((message = NewMeshCoPMessage(Get<Tmf::TmfAgent>())) != nullptr, error = kErrorNoBufs);
SuccessOrExit(error = message->InitAsConfirmablePost(UriPath::kCommissionerSet));
SuccessOrExit(error = message->SetPayloadMarker());
@@ -802,7 +802,7 @@ exit:
void Commissioner::HandleMgmtCommissionerSetResponse(void * aContext,
otMessage * aMessage,
const otMessageInfo *aMessageInfo,
otError aResult)
Error aResult)
{
static_cast<Commissioner *>(aContext)->HandleMgmtCommissionerSetResponse(
static_cast<Coap::Message *>(aMessage), static_cast<const Ip6::MessageInfo *>(aMessageInfo), aResult);
@@ -810,27 +810,27 @@ void Commissioner::HandleMgmtCommissionerSetResponse(void * aConte
void Commissioner::HandleMgmtCommissionerSetResponse(Coap::Message * aMessage,
const Ip6::MessageInfo *aMessageInfo,
otError aResult)
Error aResult)
{
OT_UNUSED_VARIABLE(aMessageInfo);
VerifyOrExit(aResult == OT_ERROR_NONE && aMessage->GetCode() == Coap::kCodeChanged);
VerifyOrExit(aResult == kErrorNone && aMessage->GetCode() == Coap::kCodeChanged);
otLogInfoMeshCoP("received MGMT_COMMISSIONER_SET response");
exit:
return;
}
otError Commissioner::SendPetition(void)
Error Commissioner::SendPetition(void)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Coap::Message * message = nullptr;
Ip6::MessageInfo messageInfo;
CommissionerIdTlv commissionerId;
mTransmitAttempts++;
VerifyOrExit((message = NewMeshCoPMessage(Get<Tmf::TmfAgent>())) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((message = NewMeshCoPMessage(Get<Tmf::TmfAgent>())) != nullptr, error = kErrorNoBufs);
SuccessOrExit(error = message->InitAsConfirmablePost(UriPath::kLeaderPetition));
SuccessOrExit(error = message->SetPayloadMarker());
@@ -856,7 +856,7 @@ exit:
void Commissioner::HandleLeaderPetitionResponse(void * aContext,
otMessage * aMessage,
const otMessageInfo *aMessageInfo,
otError aResult)
Error aResult)
{
static_cast<Commissioner *>(aContext)->HandleLeaderPetitionResponse(
static_cast<Coap::Message *>(aMessage), static_cast<const Ip6::MessageInfo *>(aMessageInfo), aResult);
@@ -864,7 +864,7 @@ void Commissioner::HandleLeaderPetitionResponse(void * aContext,
void Commissioner::HandleLeaderPetitionResponse(Coap::Message * aMessage,
const Ip6::MessageInfo *aMessageInfo,
otError aResult)
Error aResult)
{
OT_UNUSED_VARIABLE(aMessageInfo);
@@ -872,7 +872,7 @@ void Commissioner::HandleLeaderPetitionResponse(Coap::Message * aMessage
bool retransmit = false;
VerifyOrExit(mState != kStateActive);
VerifyOrExit(aResult == OT_ERROR_NONE && aMessage->GetCode() == Coap::kCodeChanged,
VerifyOrExit(aResult == kErrorNone && aMessage->GetCode() == Coap::kCodeChanged,
retransmit = (mState == kStatePetition));
otLogInfoMeshCoP("received Leader Petition response");
@@ -921,11 +921,11 @@ void Commissioner::SendKeepAlive(void)
void Commissioner::SendKeepAlive(uint16_t aSessionId)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Coap::Message * message = nullptr;
Ip6::MessageInfo messageInfo;
VerifyOrExit((message = NewMeshCoPMessage(Get<Tmf::TmfAgent>())) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((message = NewMeshCoPMessage(Get<Tmf::TmfAgent>())) != nullptr, error = kErrorNoBufs);
SuccessOrExit(error = message->InitAsConfirmablePost(UriPath::kLeaderKeepAlive));
SuccessOrExit(error = message->SetPayloadMarker());
@@ -951,7 +951,7 @@ exit:
void Commissioner::HandleLeaderKeepAliveResponse(void * aContext,
otMessage * aMessage,
const otMessageInfo *aMessageInfo,
otError aResult)
Error aResult)
{
static_cast<Commissioner *>(aContext)->HandleLeaderKeepAliveResponse(
static_cast<Coap::Message *>(aMessage), static_cast<const Ip6::MessageInfo *>(aMessageInfo), aResult);
@@ -959,14 +959,14 @@ void Commissioner::HandleLeaderKeepAliveResponse(void * aContext,
void Commissioner::HandleLeaderKeepAliveResponse(Coap::Message * aMessage,
const Ip6::MessageInfo *aMessageInfo,
otError aResult)
Error aResult)
{
OT_UNUSED_VARIABLE(aMessageInfo);
uint8_t state;
VerifyOrExit(mState == kStateActive);
VerifyOrExit(aResult == OT_ERROR_NONE && aMessage->GetCode() == Coap::kCodeChanged,
VerifyOrExit(aResult == kErrorNone && aMessage->GetCode() == Coap::kCodeChanged,
IgnoreError(Stop(/* aResign */ false)));
otLogInfoMeshCoP("received Leader keep-alive response");
@@ -990,7 +990,7 @@ void Commissioner::HandleRelayReceive(Coap::Message &aMessage, const Ip6::Messag
{
OT_UNUSED_VARIABLE(aMessageInfo);
otError error;
Error error;
uint16_t joinerPort;
Ip6::InterfaceIdentifier joinerIid;
uint16_t joinerRloc;
@@ -998,7 +998,7 @@ void Commissioner::HandleRelayReceive(Coap::Message &aMessage, const Ip6::Messag
uint16_t offset;
uint16_t length;
VerifyOrExit(mState == kStateActive, error = OT_ERROR_INVALID_STATE);
VerifyOrExit(mState == kStateActive, error = kErrorInvalidState);
VerifyOrExit(aMessage.IsNonConfirmablePostRequest());
@@ -1007,7 +1007,7 @@ void Commissioner::HandleRelayReceive(Coap::Message &aMessage, const Ip6::Messag
SuccessOrExit(error = Tlv::Find<JoinerRouterLocatorTlv>(aMessage, joinerRloc));
SuccessOrExit(error = Tlv::FindTlvValueOffset(aMessage, Tlv::kJoinerDtlsEncapsulation, offset, length));
VerifyOrExit(length <= aMessage.GetLength() - offset, error = OT_ERROR_PARSE);
VerifyOrExit(length <= aMessage.GetLength() - offset, error = kErrorParse);
if (!Get<Coap::CoapSecure>().IsConnectionActive())
{
@@ -1084,7 +1084,7 @@ void Commissioner::HandleJoinerFinalize(Coap::Message &aMessage, const Ip6::Mess
otLogInfoMeshCoP("received joiner finalize");
if (Tlv::FindTlv(aMessage, provisioningUrl) == OT_ERROR_NONE)
if (Tlv::FindTlv(aMessage, provisioningUrl) == kErrorNone)
{
uint8_t len = static_cast<uint8_t>(StringLength(mProvisioningUrl, sizeof(mProvisioningUrl)));
@@ -1111,11 +1111,11 @@ void Commissioner::HandleJoinerFinalize(Coap::Message &aMessage, const Ip6::Mess
void Commissioner::SendJoinFinalizeResponse(const Coap::Message &aRequest, StateTlv::State aState)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Ip6::MessageInfo joinerMessageInfo;
Coap::Message * message;
VerifyOrExit((message = NewMeshCoPMessage(Get<Coap::CoapSecure>())) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((message = NewMeshCoPMessage(Get<Coap::CoapSecure>())) != nullptr, error = kErrorNoBufs);
SuccessOrExit(error = message->SetDefaultResponseHeader(aRequest));
SuccessOrExit(error = message->SetPayloadMarker());
@@ -1152,22 +1152,22 @@ exit:
FreeMessageOnError(message, error);
}
otError Commissioner::SendRelayTransmit(void *aContext, Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
Error Commissioner::SendRelayTransmit(void *aContext, Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
{
return static_cast<Commissioner *>(aContext)->SendRelayTransmit(aMessage, aMessageInfo);
}
otError Commissioner::SendRelayTransmit(Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
Error Commissioner::SendRelayTransmit(Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
{
OT_UNUSED_VARIABLE(aMessageInfo);
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
ExtendedTlv tlv;
Coap::Message * message;
uint16_t offset;
Ip6::MessageInfo messageInfo;
VerifyOrExit((message = NewMeshCoPMessage(Get<Tmf::TmfAgent>())) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((message = NewMeshCoPMessage(Get<Tmf::TmfAgent>())) != nullptr, error = kErrorNoBufs);
message->InitAsNonConfirmablePost();
SuccessOrExit(error = message->AppendUriPathOptions(UriPath::kRelayTx));
+68 -70
View File
@@ -86,25 +86,25 @@ public:
* @param[in] aJoinerCallback A pointer to a function that is called when a joiner event occurs.
* @param[in] aCallbackContext A pointer to application-specific context.
*
* @retval OT_ERROR_NONE Successfully started the Commissioner service.
* @retval OT_ERROR_ALREADY Commissioner is already started.
* @retval OT_ERROR_INVALID_STATE Device is not currently attached to a network.
* @retval kErrorNone Successfully started the Commissioner service.
* @retval kErrorAlready Commissioner is already started.
* @retval kErrorInvalidState Device is not currently attached to a network.
*
*/
otError Start(otCommissionerStateCallback aStateCallback,
otCommissionerJoinerCallback aJoinerCallback,
void * aCallbackContext);
Error Start(otCommissionerStateCallback aStateCallback,
otCommissionerJoinerCallback aJoinerCallback,
void * aCallbackContext);
/**
* This method stops the Commissioner service.
*
* @param[in] aResign Whether send LEAD_KA.req to resign as Commissioner
*
* @retval OT_ERROR_NONE Successfully stopped the Commissioner service.
* @retval OT_ERROR_ALREADY Commissioner is already stopped.
* @retval kErrorNone Successfully stopped the Commissioner service.
* @retval kErrorAlready Commissioner is already stopped.
*
*/
otError Stop(bool aResign);
Error Stop(bool aResign);
/**
* This method clears all Joiner entries.
@@ -118,12 +118,12 @@ public:
* @param[in] aPskd A pointer to the PSKd.
* @param[in] aTimeout A time after which a Joiner is automatically removed, in seconds.
*
* @retval OT_ERROR_NONE Successfully added the Joiner.
* @retval OT_ERROR_NO_BUFS No buffers available to add the Joiner.
* @retval OT_ERROR_INVALID_STATE Commissioner service is not started.
* @retval kErrorNone Successfully added the Joiner.
* @retval kErrorNoBufs No buffers available to add the Joiner.
* @retval kErrorInvalidState Commissioner service is not started.
*
*/
otError AddJoinerAny(const char *aPskd, uint32_t aTimeout) { return AddJoiner(nullptr, nullptr, aPskd, aTimeout); }
Error AddJoinerAny(const char *aPskd, uint32_t aTimeout) { return AddJoiner(nullptr, nullptr, aPskd, aTimeout); }
/**
* This method adds a Joiner entry.
@@ -132,12 +132,12 @@ public:
* @param[in] aPskd A pointer to the PSKd.
* @param[in] aTimeout A time after which a Joiner is automatically removed, in seconds.
*
* @retval OT_ERROR_NONE Successfully added the Joiner.
* @retval OT_ERROR_NO_BUFS No buffers available to add the Joiner.
* @retval OT_ERROR_INVALID_STATE Commissioner service is not started.
* @retval kErrorNone Successfully added the Joiner.
* @retval kErrorNoBufs No buffers available to add the Joiner.
* @retval kErrorInvalidState Commissioner service is not started.
*
*/
otError AddJoiner(const Mac::ExtAddress &aEui64, const char *aPskd, uint32_t aTimeout)
Error AddJoiner(const Mac::ExtAddress &aEui64, const char *aPskd, uint32_t aTimeout)
{
return AddJoiner(&aEui64, nullptr, aPskd, aTimeout);
}
@@ -149,12 +149,12 @@ public:
* @param[in] aPskd A pointer to the PSKd.
* @param[in] aTimeout A time after which a Joiner is automatically removed, in seconds.
*
* @retval OT_ERROR_NONE Successfully added the Joiner.
* @retval OT_ERROR_NO_BUFS No buffers available to add the Joiner.
* @retval OT_ERROR_INVALID_STATE Commissioner service is not started.
* @retval kErrorNone Successfully added the Joiner.
* @retval kErrorNoBufs No buffers available to add the Joiner.
* @retval kErrorInvalidState Commissioner service is not started.
*
*/
otError AddJoiner(const JoinerDiscerner &aDiscerner, const char *aPskd, uint32_t aTimeout)
Error AddJoiner(const JoinerDiscerner &aDiscerner, const char *aPskd, uint32_t aTimeout)
{
return AddJoiner(nullptr, &aDiscerner, aPskd, aTimeout);
}
@@ -165,23 +165,23 @@ public:
* @param[inout] aIterator A iterator to the index of the joiner.
* @param[out] aJoiner A reference to Joiner info.
*
* @retval OT_ERROR_NONE Successfully get the Joiner info.
* @retval OT_ERROR_NOT_FOUND Not found next Joiner.
* @retval kErrorNone Successfully get the Joiner info.
* @retval kErrorNotFound Not found next Joiner.
*
*/
otError GetNextJoinerInfo(uint16_t &aIterator, otJoinerInfo &aJoiner) const;
Error GetNextJoinerInfo(uint16_t &aIterator, otJoinerInfo &aJoiner) const;
/**
* This method removes a Joiner entry accepting any Joiner.
*
* @param[in] aDelay The delay to remove Joiner (in seconds).
*
* @retval OT_ERROR_NONE Successfully added the Joiner.
* @retval OT_ERROR_NOT_FOUND The Joiner entry accepting any Joiner was not found.
* @retval OT_ERROR_INVALID_STATE Commissioner service is not started.
* @retval kErrorNone Successfully added the Joiner.
* @retval kErrorNotFound The Joiner entry accepting any Joiner was not found.
* @retval kErrorInvalidState Commissioner service is not started.
*
*/
otError RemoveJoinerAny(uint32_t aDelay) { return RemoveJoiner(nullptr, nullptr, aDelay); }
Error RemoveJoinerAny(uint32_t aDelay) { return RemoveJoiner(nullptr, nullptr, aDelay); }
/**
* This method removes a Joiner entry.
@@ -189,12 +189,12 @@ public:
* @param[in] aEui64 The Joiner's IEEE EUI-64.
* @param[in] aDelay The delay to remove Joiner (in seconds).
*
* @retval OT_ERROR_NONE Successfully added the Joiner.
* @retval OT_ERROR_NOT_FOUND The Joiner specified by @p aEui64 was not found.
* @retval OT_ERROR_INVALID_STATE Commissioner service is not started.
* @retval kErrorNone Successfully added the Joiner.
* @retval kErrorNotFound The Joiner specified by @p aEui64 was not found.
* @retval kErrorInvalidState Commissioner service is not started.
*
*/
otError RemoveJoiner(const Mac::ExtAddress &aEui64, uint32_t aDelay)
Error RemoveJoiner(const Mac::ExtAddress &aEui64, uint32_t aDelay)
{
return RemoveJoiner(&aEui64, nullptr, aDelay);
}
@@ -205,12 +205,12 @@ public:
* @param[in] aDiscerner A Joiner Discerner.
* @param[in] aDelay The delay to remove Joiner (in seconds).
*
* @retval OT_ERROR_NONE Successfully added the Joiner.
* @retval OT_ERROR_NOT_FOUND The Joiner specified by @p aEui64 was not found.
* @retval OT_ERROR_INVALID_STATE Commissioner service is not started.
* @retval kErrorNone Successfully added the Joiner.
* @retval kErrorNotFound The Joiner specified by @p aEui64 was not found.
* @retval kErrorInvalidState Commissioner service is not started.
*
*/
otError RemoveJoiner(const JoinerDiscerner &aDiscerner, uint32_t aDelay)
Error RemoveJoiner(const JoinerDiscerner &aDiscerner, uint32_t aDelay)
{
return RemoveJoiner(nullptr, &aDiscerner, aDelay);
}
@@ -228,11 +228,11 @@ public:
*
* @param[in] aProvisioningUrl A pointer to the Provisioning URL (may be nullptr to set URL to empty string).
*
* @retval OT_ERROR_NONE Successfully set the Provisioning URL.
* @retval OT_ERROR_INVALID_ARGS @p aProvisioningUrl is invalid (too long).
* @retval kErrorNone Successfully set the Provisioning URL.
* @retval kErrorInvalidArgs @p aProvisioningUrl is invalid (too long).
*
*/
otError SetProvisioningUrl(const char *aProvisioningUrl);
Error SetProvisioningUrl(const char *aProvisioningUrl);
/**
* This method returns the Commissioner Session ID.
@@ -272,12 +272,12 @@ public:
* @param[in] aTlvs A pointer to Commissioning Data TLVs.
* @param[in] aLength The length of requested TLVs in bytes.
*
* @retval OT_ERROR_NONE Send MGMT_COMMISSIONER_GET successfully.
* @retval OT_ERROR_NO_BUFS Insufficient buffer space to send.
* @retval OT_ERROR_INVALID_STATE Commissioner service is not started.
* @retval kErrorNone Send MGMT_COMMISSIONER_GET successfully.
* @retval kErrorNoBufs Insufficient buffer space to send.
* @retval kErrorInvalidState Commissioner service is not started.
*
*/
otError SendMgmtCommissionerGetRequest(const uint8_t *aTlvs, uint8_t aLength);
Error SendMgmtCommissionerGetRequest(const uint8_t *aTlvs, uint8_t aLength);
/**
* This method sends MGMT_COMMISSIONER_SET.
@@ -286,14 +286,12 @@ public:
* @param[in] aTlvs A pointer to user specific Commissioning Data TLVs.
* @param[in] aLength The length of user specific TLVs in bytes.
*
* @retval OT_ERROR_NONE Send MGMT_COMMISSIONER_SET successfully.
* @retval OT_ERROR_NO_BUFS Insufficient buffer space to send.
* @retval OT_ERROR_INVALID_STATE Commissioner service is not started.
* @retval kErrorNone Send MGMT_COMMISSIONER_SET successfully.
* @retval kErrorNoBufs Insufficient buffer space to send.
* @retval kErrorInvalidState Commissioner service is not started.
*
*/
otError SendMgmtCommissionerSetRequest(const otCommissioningDataset &aDataset,
const uint8_t * aTlvs,
uint8_t aLength);
Error SendMgmtCommissionerSetRequest(const otCommissioningDataset &aDataset, const uint8_t *aTlvs, uint8_t aLength);
/**
* This method returns a reference to the AnnounceBeginClient instance.
@@ -374,12 +372,12 @@ private:
Joiner *FindBestMatchingJoinerEntry(const Mac::ExtAddress &aReceivedJoinerId);
void RemoveJoinerEntry(Joiner &aJoiner);
otError AddJoiner(const Mac::ExtAddress *aEui64,
const JoinerDiscerner *aDiscerner,
const char * aPskd,
uint32_t aTimeout);
otError RemoveJoiner(const Mac::ExtAddress *aEui64, const JoinerDiscerner *aDiscerner, uint32_t aDelay);
void RemoveJoiner(Joiner &aJoiner, uint32_t aDelay);
Error AddJoiner(const Mac::ExtAddress *aEui64,
const JoinerDiscerner *aDiscerner,
const char * aPskd,
uint32_t aTimeout);
Error RemoveJoiner(const Mac::ExtAddress *aEui64, const JoinerDiscerner *aDiscerner, uint32_t aDelay);
void RemoveJoiner(Joiner &aJoiner, uint32_t aDelay);
void AddCoapResources(void);
void RemoveCoapResources(void);
@@ -395,27 +393,27 @@ private:
static void HandleMgmtCommissionerSetResponse(void * aContext,
otMessage * aMessage,
const otMessageInfo *aMessageInfo,
otError aResult);
Error aResult);
void HandleMgmtCommissionerSetResponse(Coap::Message * aMessage,
const Ip6::MessageInfo *aMessageInfo,
otError aResult);
Error aResult);
static void HandleMgmtCommissionerGetResponse(void * aContext,
otMessage * aMessage,
const otMessageInfo *aMessageInfo,
otError aResult);
Error aResult);
void HandleMgmtCommissionerGetResponse(Coap::Message * aMessage,
const Ip6::MessageInfo *aMessageInfo,
otError aResult);
Error aResult);
static void HandleLeaderPetitionResponse(void * aContext,
otMessage * aMessage,
const otMessageInfo *aMessageInfo,
otError aResult);
void HandleLeaderPetitionResponse(Coap::Message *aMessage, const Ip6::MessageInfo *aMessageInfo, otError aResult);
Error aResult);
void HandleLeaderPetitionResponse(Coap::Message *aMessage, const Ip6::MessageInfo *aMessageInfo, Error aResult);
static void HandleLeaderKeepAliveResponse(void * aContext,
otMessage * aMessage,
const otMessageInfo *aMessageInfo,
otError aResult);
void HandleLeaderKeepAliveResponse(Coap::Message *aMessage, const Ip6::MessageInfo *aMessageInfo, otError aResult);
Error aResult);
void HandleLeaderKeepAliveResponse(Coap::Message *aMessage, const Ip6::MessageInfo *aMessageInfo, Error aResult);
static void HandleCoapsConnected(bool aConnected, void *aContext);
void HandleCoapsConnected(bool aConnected);
@@ -431,14 +429,14 @@ private:
void SendJoinFinalizeResponse(const Coap::Message &aRequest, StateTlv::State aState);
static otError SendRelayTransmit(void *aContext, Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
otError SendRelayTransmit(Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
static Error SendRelayTransmit(void *aContext, Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
Error SendRelayTransmit(Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
void ComputeBloomFilter(SteeringData &aSteeringData) const;
void SendCommissionerSet(void);
otError SendPetition(void);
void SendKeepAlive(void);
void SendKeepAlive(uint16_t aSessionId);
void ComputeBloomFilter(SteeringData &aSteeringData) const;
void SendCommissionerSet(void);
Error SendPetition(void);
void SendKeepAlive(void);
void SendKeepAlive(uint16_t aSessionId);
void SetState(State aState);
void SignalJoinerEvent(JoinerEvent aEvent, const Joiner *aJoiner) const;
+18 -18
View File
@@ -48,9 +48,9 @@
namespace ot {
namespace MeshCoP {
otError Dataset::Info::GenerateRandom(Instance &aInstance)
Error Dataset::Info::GenerateRandom(Instance &aInstance)
{
otError error;
Error error;
Mac::ChannelMask supportedChannels = aInstance.Get<Mac::Mac>().GetSupportedChannelMask();
Mac::ChannelMask preferredChannels(aInstance.Get<Radio>().GetPreferredChannelMask());
@@ -285,9 +285,9 @@ void Dataset::SetFrom(const otOperationalDatasetTlvs &aDataset)
memcpy(mTlvs, aDataset.mTlvs, mLength);
}
otError Dataset::SetFrom(const Info &aDatasetInfo)
Error Dataset::SetFrom(const Info &aDatasetInfo)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
if (aDatasetInfo.IsActiveTimestampPresent())
{
@@ -400,9 +400,9 @@ void Dataset::SetTimestamp(const Timestamp &aTimestamp)
IgnoreError(SetTlv((mType == kActive) ? Tlv::kActiveTimestamp : Tlv::kPendingTimestamp, aTimestamp));
}
otError Dataset::SetTlv(Tlv::Type aType, const void *aValue, uint8_t aLength)
Error Dataset::SetTlv(Tlv::Type aType, const void *aValue, uint8_t aLength)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
uint16_t bytesAvailable = sizeof(mTlvs) - mLength;
Tlv * old = GetTlv(aType);
Tlv tlv;
@@ -412,7 +412,7 @@ otError Dataset::SetTlv(Tlv::Type aType, const void *aValue, uint8_t aLength)
bytesAvailable += sizeof(Tlv) + old->GetLength();
}
VerifyOrExit(sizeof(Tlv) + aLength <= bytesAvailable, error = OT_ERROR_NO_BUFS);
VerifyOrExit(sizeof(Tlv) + aLength <= bytesAvailable, error = kErrorNoBufs);
if (old != nullptr)
{
@@ -433,20 +433,20 @@ exit:
return error;
}
otError Dataset::SetTlv(const Tlv &aTlv)
Error Dataset::SetTlv(const Tlv &aTlv)
{
return SetTlv(aTlv.GetType(), aTlv.GetValue(), aTlv.GetLength());
}
otError Dataset::Set(const Message &aMessage, uint16_t aOffset, uint8_t aLength)
Error Dataset::Set(const Message &aMessage, uint16_t aOffset, uint8_t aLength)
{
otError error = OT_ERROR_INVALID_ARGS;
Error error = kErrorInvalidArgs;
SuccessOrExit(aMessage.Read(aOffset, mTlvs, aLength));
mLength = aLength;
mUpdateTime = TimerMilli::GetNow();
error = OT_ERROR_NONE;
error = kErrorNone;
exit:
return error;
@@ -463,9 +463,9 @@ exit:
return;
}
otError Dataset::AppendMleDatasetTlv(Message &aMessage) const
Error Dataset::AppendMleDatasetTlv(Message &aMessage) const
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Mle::Tlv tlv;
Mle::Tlv::Type type;
@@ -519,13 +519,13 @@ void Dataset::RemoveTlv(Tlv *aTlv)
mLength -= length;
}
otError Dataset::ApplyConfiguration(Instance &aInstance, bool *aIsMasterKeyUpdated) const
Error Dataset::ApplyConfiguration(Instance &aInstance, bool *aIsMasterKeyUpdated) const
{
Mac::Mac & mac = aInstance.Get<Mac::Mac>();
KeyManager &keyManager = aInstance.Get<KeyManager>();
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
VerifyOrExit(IsValid(), error = OT_ERROR_PARSE);
VerifyOrExit(IsValid(), error = kErrorParse);
if (aIsMasterKeyUpdated)
{
@@ -542,10 +542,10 @@ otError Dataset::ApplyConfiguration(Instance &aInstance, bool *aIsMasterKeyUpdat
error = mac.SetPanChannel(channel);
if (error != OT_ERROR_NONE)
if (error != kErrorNone)
{
otLogWarnMeshCoP("DatasetManager::ApplyConfiguration() Failed to set channel to %d (%s)", channel,
otThreadErrorToString(error));
ErrorToString(error));
ExitNow();
}
+29 -29
View File
@@ -603,10 +603,10 @@ public:
*
* @param[in] aInstance The OpenThread instance.
*
* @retval OT_ERROR_NONE If the Dataset was generated successfully.
* @retval kErrorNone If the Dataset was generated successfully.
*
*/
otError GenerateRandom(Instance &aInstance);
Error GenerateRandom(Instance &aInstance);
/**
* This method checks whether the Dataset is a subset of another one, i.e., all the components in the current
@@ -764,11 +764,11 @@ public:
*
* @param[in] aTlv A reference to the TLV.
*
* @retval OT_ERROR_NONE Successfully set the TLV.
* @retval OT_ERROR_NO_BUFS Could not set the TLV due to insufficient buffer space.
* @retval kErrorNone Successfully set the TLV.
* @retval kErrorNoBufs Could not set the TLV due to insufficient buffer space.
*
*/
otError SetTlv(const Tlv &aTlv);
Error SetTlv(const Tlv &aTlv);
/**
* This method sets a TLV with a given TLV Type and Value.
@@ -777,11 +777,11 @@ public:
* @param[in] aValue A pointer to TLV Value.
* @param[in] aLength The TLV Length in bytes (length of @p aValue).
*
* @retval OT_ERROR_NONE Successfully set the TLV.
* @retval OT_ERROR_NO_BUFS Could not set the TLV due to insufficient buffer space.
* @retval kErrorNone Successfully set the TLV.
* @retval kErrorNoBufs Could not set the TLV due to insufficient buffer space.
*
*/
otError SetTlv(Tlv::Type aType, const void *aValue, uint8_t aLength);
Error SetTlv(Tlv::Type aType, const void *aValue, uint8_t aLength);
/**
* This template method sets a TLV with a given TLV Type and Value.
@@ -791,11 +791,11 @@ public:
* @param[in] aType The TLV Type.
* @param[in] aValue The TLV Value (of type `ValueType`).
*
* @retval OT_ERROR_NONE Successfully set the TLV.
* @retval OT_ERROR_NO_BUFS Could not set the TLV due to insufficient buffer space.
* @retval kErrorNone Successfully set the TLV.
* @retval kErrorNoBufs Could not set the TLV due to insufficient buffer space.
*
*/
template <typename ValueType> otError SetTlv(Tlv::Type aType, const ValueType &aValue)
template <typename ValueType> Error SetTlv(Tlv::Type aType, const ValueType &aValue)
{
static_assert(!TypeTraits::IsPointer<ValueType>::kValue, "ValueType must not be a pointer");
@@ -809,11 +809,11 @@ public:
* @param[in] aOffset The message buffer offset where the dataset starts.
* @param[in] aLength The TLVs length in the message buffer in bytes.
*
* @retval OT_ERROR_NONE Successfully set the Dataset.
* @retval OT_ERROR_INVALID_ARGS The values of @p aOffset and @p aLength are not valid for @p aMessage.
* @retval kErrorNone Successfully set the Dataset.
* @retval kErrorInvalidArgs The values of @p aOffset and @p aLength are not valid for @p aMessage.
*
*/
otError Set(const Message &aMessage, uint16_t aOffset, uint8_t aLength);
Error Set(const Message &aMessage, uint16_t aOffset, uint8_t aLength);
/**
* This method sets the Dataset using an existing Dataset.
@@ -831,11 +831,11 @@ public:
*
* @param[in] aDatasetInfo The input Dataset as `Dataset::Info`.
*
* @retval OT_ERROR_NONE Successfully set the Dataset.
* @retval OT_ERROR_INVALID_ARGS Dataset is missing Active and/or Pending Timestamp.
* @retval kErrorNone Successfully set the Dataset.
* @retval kErrorInvalidArgs Dataset is missing Active and/or Pending Timestamp.
*
*/
otError SetFrom(const Info &aDatasetInfo);
Error SetFrom(const Info &aDatasetInfo);
/**
* This method sets the Dataset using @p aDataset.
@@ -858,11 +858,11 @@ public:
*
* @param[in] aMessage A message to append to.
*
* @retval OT_ERROR_NONE Successfully append MLE Dataset TLV without MeshCoP Sub Timestamp TLV.
* @retval OT_ERROR_NO_BUFS Insufficient available buffers to append the message with MLE Dataset TLV.
* @retval kErrorNone Successfully append MLE Dataset TLV without MeshCoP Sub Timestamp TLV.
* @retval kErrorNoBufs Insufficient available buffers to append the message with MLE Dataset TLV.
*
*/
otError AppendMleDatasetTlv(Message &aMessage) const;
Error AppendMleDatasetTlv(Message &aMessage) const;
/**
* This method applies the Active or Pending Dataset to the Thread interface.
@@ -870,11 +870,11 @@ public:
* @param[in] aInstance A reference to the OpenThread instance.
* @param[out] aIsMasterKeyUpdated A pointer to where to place whether master key was updated.
*
* @retval OT_ERROR_NONE Successfully applied configuration.
* @retval OT_ERROR_PARSE The dataset has at least one TLV with invalid format.
* @retval kErrorNone Successfully applied configuration.
* @retval kErrorParse The dataset has at least one TLV with invalid format.
*
*/
otError ApplyConfiguration(Instance &aInstance, bool *aIsMasterKeyUpdated = nullptr) const;
Error ApplyConfiguration(Instance &aInstance, bool *aIsMasterKeyUpdated = nullptr) const;
/**
* This method converts a Pending Dataset to an Active Dataset.
@@ -943,11 +943,11 @@ private:
* @param[in] aType The TLV Type.
* @param[in] aValue The TLV value (as `uint16_t`).
*
* @retval OT_ERROR_NONE Successfully set the TLV.
* @retval OT_ERROR_NO_BUFS Could not set the TLV due to insufficient buffer space.
* @retval kErrorNone Successfully set the TLV.
* @retval kErrorNoBufs Could not set the TLV due to insufficient buffer space.
*
*/
template <> inline otError Dataset::SetTlv(Tlv::Type aType, const uint16_t &aValue)
template <> inline Error Dataset::SetTlv(Tlv::Type aType, const uint16_t &aValue)
{
uint16_t value = Encoding::BigEndian::HostSwap16(aValue);
@@ -960,11 +960,11 @@ template <> inline otError Dataset::SetTlv(Tlv::Type aType, const uint16_t &aVal
* @param[in] aType The TLV Type.
* @param[in] aValue The TLV value (as `uint32_t`).
*
* @retval OT_ERROR_NONE Successfully set the TLV.
* @retval OT_ERROR_NO_BUFS Could not set the TLV due to insufficient buffer space.
* @retval kErrorNone Successfully set the TLV.
* @retval kErrorNoBufs Could not set the TLV due to insufficient buffer space.
*
*/
template <> inline otError Dataset::SetTlv(Tlv::Type aType, const uint32_t &aValue)
template <> inline Error Dataset::SetTlv(Tlv::Type aType, const uint32_t &aValue)
{
uint32_t value = Encoding::BigEndian::HostSwap32(aValue);
+14 -14
View File
@@ -66,10 +66,10 @@ void DatasetLocal::Clear(void)
mSaved = false;
}
otError DatasetLocal::Restore(Dataset &aDataset)
Error DatasetLocal::Restore(Dataset &aDataset)
{
const Timestamp *timestamp;
otError error;
Error error;
mTimestampPresent = false;
@@ -89,14 +89,14 @@ exit:
return error;
}
otError DatasetLocal::Read(Dataset &aDataset) const
Error DatasetLocal::Read(Dataset &aDataset) const
{
DelayTimerTlv *delayTimer;
uint32_t elapsed;
otError error;
Error error;
error = Get<Settings>().ReadOperationalDataset(IsActive(), aDataset);
VerifyOrExit(error == OT_ERROR_NONE, aDataset.mLength = 0);
VerifyOrExit(error == kErrorNone, aDataset.mLength = 0);
if (mType == Dataset::kActive)
{
@@ -126,10 +126,10 @@ exit:
return error;
}
otError DatasetLocal::Read(Dataset::Info &aDatasetInfo) const
Error DatasetLocal::Read(Dataset::Info &aDatasetInfo) const
{
Dataset dataset(mType);
otError error;
Error error;
aDatasetInfo.Clear();
@@ -140,10 +140,10 @@ exit:
return error;
}
otError DatasetLocal::Read(otOperationalDatasetTlvs &aDataset) const
Error DatasetLocal::Read(otOperationalDatasetTlvs &aDataset) const
{
Dataset dataset(mType);
otError error;
Error error;
memset(&aDataset, 0, sizeof(aDataset));
@@ -154,9 +154,9 @@ exit:
return error;
}
otError DatasetLocal::Save(const Dataset::Info &aDatasetInfo)
Error DatasetLocal::Save(const Dataset::Info &aDatasetInfo)
{
otError error;
Error error;
Dataset dataset(mType);
SuccessOrExit(error = dataset.SetFrom(aDatasetInfo));
@@ -166,7 +166,7 @@ exit:
return error;
}
otError DatasetLocal::Save(const otOperationalDatasetTlvs &aDataset)
Error DatasetLocal::Save(const otOperationalDatasetTlvs &aDataset)
{
Dataset dataset(mType);
@@ -175,10 +175,10 @@ otError DatasetLocal::Save(const otOperationalDatasetTlvs &aDataset)
return Save(dataset);
}
otError DatasetLocal::Save(const Dataset &aDataset)
Error DatasetLocal::Save(const Dataset &aDataset)
{
const Timestamp *timestamp;
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
if (aDataset.GetSize() == 0)
{
+21 -21
View File
@@ -95,44 +95,44 @@ public:
*
* @param[out] aDataset Where to place the dataset.
*
* @retval OT_ERROR_NONE Successfully retrieved the dataset.
* @retval OT_ERROR_NOT_FOUND There is no corresponding dataset stored in non-volatile memory.
* @retval kErrorNone Successfully retrieved the dataset.
* @retval kErrorNotFound There is no corresponding dataset stored in non-volatile memory.
*
*/
otError Restore(Dataset &aDataset);
Error Restore(Dataset &aDataset);
/**
* This method retrieves the dataset from non-volatile memory.
*
* @param[out] aDataset Where to place the dataset.
*
* @retval OT_ERROR_NONE Successfully retrieved the dataset.
* @retval OT_ERROR_NOT_FOUND There is no corresponding dataset stored in non-volatile memory.
* @retval kErrorNone Successfully retrieved the dataset.
* @retval kErrorNotFound There is no corresponding dataset stored in non-volatile memory.
*
*/
otError Read(Dataset &aDataset) const;
Error Read(Dataset &aDataset) const;
/**
* This method retrieves the dataset from non-volatile memory.
*
* @param[out] aDatasetInfo Where to place the dataset as `Dataset::Info`.
*
* @retval OT_ERROR_NONE Successfully retrieved the dataset.
* @retval OT_ERROR_NOT_FOUND There is no corresponding dataset stored in non-volatile memory.
* @retval kErrorNone Successfully retrieved the dataset.
* @retval kErrorNotFound There is no corresponding dataset stored in non-volatile memory.
*
*/
otError Read(Dataset::Info &aDatasetInfo) const;
Error Read(Dataset::Info &aDatasetInfo) const;
/**
* This method retrieves the dataset from non-volatile memory.
*
* @param[out] aDataset Where to place the dataset.
*
* @retval OT_ERROR_NONE Successfully retrieved the dataset.
* @retval OT_ERROR_NOT_FOUND There is no corresponding dataset stored in non-volatile memory.
* @retval kErrorNone Successfully retrieved the dataset.
* @retval kErrorNotFound There is no corresponding dataset stored in non-volatile memory.
*
*/
otError Read(otOperationalDatasetTlvs &aDataset) const;
Error Read(otOperationalDatasetTlvs &aDataset) const;
/**
* This method returns the local time this dataset was last updated or restored.
@@ -147,33 +147,33 @@ public:
*
* @param[in] aDatasetInfo The Dataset to save as `Dataset::Info`.
*
* @retval OT_ERROR_NONE Successfully saved the dataset.
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
* @retval kErrorNone Successfully saved the dataset.
* @retval kErrorNotImplemented The platform does not implement settings functionality.
*
*/
otError Save(const Dataset::Info &aDatasetInfo);
Error Save(const Dataset::Info &aDatasetInfo);
/**
* This method stores the dataset into non-volatile memory.
*
* @param[in] aDataset The Dataset to save as `otOperationalDatasetTlvs`.
*
* @retval OT_ERROR_NONE Successfully saved the dataset.
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
* @retval kErrorNone Successfully saved the dataset.
* @retval kErrorNotImplemented The platform does not implement settings functionality.
*
*/
otError Save(const otOperationalDatasetTlvs &aDataset);
Error Save(const otOperationalDatasetTlvs &aDataset);
/**
* This method stores the dataset into non-volatile memory.
*
* @param[in] aDataset The Dataset to save.
*
* @retval OT_ERROR_NONE Successfully saved the dataset.
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
* @retval kErrorNone Successfully saved the dataset.
* @retval kErrorNotImplemented The platform does not implement settings functionality.
*
*/
otError Save(const Dataset &aDataset);
Error Save(const Dataset &aDataset);
/**
* This method compares this dataset to another based on the timestamp.
+50 -50
View File
@@ -78,9 +78,9 @@ int DatasetManager::Compare(const Timestamp &aTimestamp) const
return rval;
}
otError DatasetManager::Restore(void)
Error DatasetManager::Restore(void)
{
otError error;
Error error;
Dataset dataset(GetType());
const Timestamp *timestamp;
@@ -109,9 +109,9 @@ exit:
return error;
}
otError DatasetManager::ApplyConfiguration(void) const
Error DatasetManager::ApplyConfiguration(void) const
{
otError error;
Error error;
Dataset dataset(GetType());
SuccessOrExit(error = Read(dataset));
@@ -135,9 +135,9 @@ void DatasetManager::HandleDetach(void)
IgnoreError(Restore());
}
otError DatasetManager::Save(const Dataset &aDataset)
Error DatasetManager::Save(const Dataset &aDataset)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
const Timestamp *timestamp;
int compare;
bool isMasterkeyUpdated = false;
@@ -167,7 +167,7 @@ otError DatasetManager::Save(const Dataset &aDataset)
}
else if (compare < 0)
{
VerifyOrExit(!Get<Mle::MleRouter>().IsLeader(), error = OT_ERROR_INVALID_STATE);
VerifyOrExit(!Get<Mle::MleRouter>().IsLeader(), error = kErrorInvalidState);
SendSet();
}
@@ -177,9 +177,9 @@ exit:
return error;
}
otError DatasetManager::Save(const Dataset::Info &aDatasetInfo)
Error DatasetManager::Save(const Dataset::Info &aDatasetInfo)
{
otError error;
Error error;
SuccessOrExit(error = mLocal.Save(aDatasetInfo));
HandleDatasetUpdated();
@@ -188,9 +188,9 @@ exit:
return error;
}
otError DatasetManager::Save(const otOperationalDatasetTlvs &aDataset)
Error DatasetManager::Save(const otOperationalDatasetTlvs &aDataset)
{
otError error;
Error error;
SuccessOrExit(error = mLocal.Save(aDataset));
HandleDatasetUpdated();
@@ -199,9 +199,9 @@ exit:
return error;
}
otError DatasetManager::SaveLocal(const Dataset &aDataset)
Error DatasetManager::SaveLocal(const Dataset &aDataset)
{
otError error;
Error error;
SuccessOrExit(error = mLocal.Save(aDataset));
HandleDatasetUpdated();
@@ -245,9 +245,9 @@ void DatasetManager::SignalDatasetChange(void) const
: kEventPendingDatasetChanged);
}
otError DatasetManager::GetChannelMask(Mac::ChannelMask &aChannelMask) const
Error DatasetManager::GetChannelMask(Mac::ChannelMask &aChannelMask) const
{
otError error;
Error error;
const MeshCoP::ChannelMaskTlv *channelMaskTlv;
uint32_t mask;
Dataset dataset(GetType());
@@ -255,12 +255,12 @@ otError DatasetManager::GetChannelMask(Mac::ChannelMask &aChannelMask) const
SuccessOrExit(error = Read(dataset));
channelMaskTlv = dataset.GetTlv<ChannelMaskTlv>();
VerifyOrExit(channelMaskTlv != nullptr, error = OT_ERROR_NOT_FOUND);
VerifyOrExit(channelMaskTlv != nullptr, error = kErrorNotFound);
VerifyOrExit((mask = channelMaskTlv->GetChannelMask()) != 0);
aChannelMask.SetMask(mask & Get<Mac::Mac>().GetSupportedChannelMask().GetMask());
VerifyOrExit(!aChannelMask.IsEmpty(), error = OT_ERROR_NOT_FOUND);
VerifyOrExit(!aChannelMask.IsEmpty(), error = kErrorNotFound);
exit:
return error;
@@ -273,14 +273,14 @@ void DatasetManager::HandleTimer(void)
void DatasetManager::SendSet(void)
{
otError error;
Error error;
Coap::Message * message = nullptr;
Ip6::MessageInfo messageInfo;
Dataset dataset(GetType());
VerifyOrExit(!mCoapPending, error = OT_ERROR_BUSY);
VerifyOrExit(Get<Mle::MleRouter>().IsAttached(), error = OT_ERROR_INVALID_STATE);
VerifyOrExit(mLocal.Compare(GetTimestamp()) < 0, error = OT_ERROR_INVALID_STATE);
VerifyOrExit(!mCoapPending, error = kErrorBusy);
VerifyOrExit(Get<Mle::MleRouter>().IsAttached(), error = kErrorInvalidState);
VerifyOrExit(mLocal.Compare(GetTimestamp()) < 0, error = kErrorInvalidState);
if (IsActiveDataset())
{
@@ -293,11 +293,11 @@ void DatasetManager::SendSet(void)
if (pendingActiveTimestamp != nullptr && mLocal.Compare(pendingActiveTimestamp) == 0)
{
// stop registration attempts during dataset transition
ExitNow(error = OT_ERROR_INVALID_STATE);
ExitNow(error = kErrorInvalidState);
}
}
VerifyOrExit((message = NewMeshCoPMessage(Get<Tmf::TmfAgent>())) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((message = NewMeshCoPMessage(Get<Tmf::TmfAgent>())) != nullptr, error = kErrorNoBufs);
SuccessOrExit(error =
message->InitAsConfirmablePost(IsActiveDataset() ? UriPath::kActiveSet : UriPath::kPendingSet));
@@ -318,11 +318,11 @@ exit:
switch (error)
{
case OT_ERROR_NONE:
case kErrorNone:
mCoapPending = true;
break;
case OT_ERROR_NO_BUFS:
case kErrorNoBufs:
mTimer.Start(kDelayNoBufs);
OT_FALL_THROUGH;
@@ -336,7 +336,7 @@ exit:
void DatasetManager::HandleCoapResponse(void * aContext,
otMessage * aMessage,
const otMessageInfo *aMessageInfo,
otError aError)
Error aError)
{
OT_UNUSED_VARIABLE(aMessage);
OT_UNUSED_VARIABLE(aMessageInfo);
@@ -401,13 +401,13 @@ void DatasetManager::SendGetResponse(const Coap::Message & aRequest,
uint8_t * aTlvs,
uint8_t aLength) const
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Coap::Message *message;
Dataset dataset(GetType());
IgnoreError(Read(dataset));
VerifyOrExit((message = NewMeshCoPMessage(Get<Tmf::TmfAgent>())) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((message = NewMeshCoPMessage(Get<Tmf::TmfAgent>())) != nullptr, error = kErrorNoBufs);
SuccessOrExit(error = message->SetDefaultResponseHeader(aRequest));
SuccessOrExit(error = message->SetPayloadMarker());
@@ -454,9 +454,9 @@ exit:
FreeMessageOnError(message, error);
}
otError DatasetManager::AppendDatasetToMessage(const Dataset::Info &aDatasetInfo, Message &aMessage) const
Error DatasetManager::AppendDatasetToMessage(const Dataset::Info &aDatasetInfo, Message &aMessage) const
{
otError error;
Error error;
Dataset dataset(GetType());
SuccessOrExit(error = dataset.SetFrom(aDatasetInfo));
@@ -466,13 +466,13 @@ exit:
return error;
}
otError DatasetManager::SendSetRequest(const Dataset::Info &aDatasetInfo, const uint8_t *aTlvs, uint8_t aLength)
Error DatasetManager::SendSetRequest(const Dataset::Info &aDatasetInfo, const uint8_t *aTlvs, uint8_t aLength)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Coap::Message * message;
Ip6::MessageInfo messageInfo;
VerifyOrExit((message = NewMeshCoPMessage(Get<Tmf::TmfAgent>())) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((message = NewMeshCoPMessage(Get<Tmf::TmfAgent>())) != nullptr, error = kErrorNoBufs);
SuccessOrExit(error =
message->InitAsConfirmablePost(IsActiveDataset() ? UriPath::kActiveSet : UriPath::kPendingSet));
@@ -487,7 +487,7 @@ otError DatasetManager::SendSetRequest(const Dataset::Info &aDatasetInfo, const
for (const Tlv *cur = reinterpret_cast<const Tlv *>(aTlvs); cur < end; cur = cur->GetNext())
{
VerifyOrExit((cur + 1) <= end, error = OT_ERROR_INVALID_ARGS);
VerifyOrExit((cur + 1) <= end, error = kErrorInvalidArgs);
if (cur->GetType() == Tlv::kCommissionerSessionId)
{
@@ -529,12 +529,12 @@ exit:
return error;
}
otError DatasetManager::SendGetRequest(const Dataset::Components &aDatasetComponents,
const uint8_t * aTlvTypes,
uint8_t aLength,
const otIp6Address * aAddress) const
Error DatasetManager::SendGetRequest(const Dataset::Components &aDatasetComponents,
const uint8_t * aTlvTypes,
uint8_t aLength,
const otIp6Address * aAddress) const
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Coap::Message * message;
Ip6::MessageInfo messageInfo;
Tlv tlv;
@@ -603,7 +603,7 @@ otError DatasetManager::SendGetRequest(const Dataset::Components &aDatasetCompon
datasetTlvs[length++] = Tlv::kChannelMask;
}
VerifyOrExit((message = NewMeshCoPMessage(Get<Tmf::TmfAgent>())) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((message = NewMeshCoPMessage(Get<Tmf::TmfAgent>())) != nullptr, error = kErrorNoBufs);
SuccessOrExit(error =
message->InitAsConfirmablePost(IsActiveDataset() ? UriPath::kActiveGet : UriPath::kPendingGet));
@@ -679,9 +679,9 @@ exit:
return isValid;
}
otError ActiveDataset::Save(const Timestamp &aTimestamp, const Message &aMessage, uint16_t aOffset, uint8_t aLength)
Error ActiveDataset::Save(const Timestamp &aTimestamp, const Message &aMessage, uint16_t aOffset, uint8_t aLength)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Dataset dataset(GetType());
SuccessOrExit(error = dataset.Set(aMessage, aOffset, aLength));
@@ -734,9 +734,9 @@ void PendingDataset::ClearNetwork(void)
IgnoreError(DatasetManager::Save(dataset));
}
otError PendingDataset::Save(const Dataset::Info &aDatasetInfo)
Error PendingDataset::Save(const Dataset::Info &aDatasetInfo)
{
otError error;
Error error;
SuccessOrExit(error = DatasetManager::Save(aDatasetInfo));
StartDelayTimer();
@@ -745,9 +745,9 @@ exit:
return error;
}
otError PendingDataset::Save(const otOperationalDatasetTlvs &aDataset)
Error PendingDataset::Save(const otOperationalDatasetTlvs &aDataset)
{
otError error;
Error error;
SuccessOrExit(error = DatasetManager::Save(aDataset));
StartDelayTimer();
@@ -756,9 +756,9 @@ exit:
return error;
}
otError PendingDataset::Save(const Dataset &aDataset)
Error PendingDataset::Save(const Dataset &aDataset)
{
otError error;
Error error;
SuccessOrExit(error = DatasetManager::SaveLocal(aDataset));
StartDelayTimer();
@@ -767,9 +767,9 @@ exit:
return error;
}
otError PendingDataset::Save(const Timestamp &aTimestamp, const Message &aMessage, uint16_t aOffset, uint8_t aLength)
Error PendingDataset::Save(const Timestamp &aTimestamp, const Message &aMessage, uint16_t aOffset, uint8_t aLength)
{
otError error = OT_ERROR_NONE;
Error error = kErrorNone;
Dataset dataset(GetType());
SuccessOrExit(error = dataset.Set(aMessage, aOffset, aLength));
+84 -84
View File
@@ -64,11 +64,11 @@ public:
/**
* This method restores the Operational Dataset from non-volatile memory.
*
* @retval OT_ERROR_NONE Successfully restore the dataset.
* @retval OT_ERROR_NOT_FOUND There is no corresponding dataset stored in non-volatile memory.
* @retval kErrorNone Successfully restore the dataset.
* @retval kErrorNotFound There is no corresponding dataset stored in non-volatile memory.
*
*/
otError Restore(void);
Error Restore(void);
/**
* This method compares @p aTimestamp to the dataset's timestamp value.
@@ -87,53 +87,53 @@ public:
*
* @param[out] aDataset Where to place the dataset.
*
* @retval OT_ERROR_NONE Successfully retrieved the dataset.
* @retval OT_ERROR_NOT_FOUND There is no corresponding dataset stored in non-volatile memory.
* @retval kErrorNone Successfully retrieved the dataset.
* @retval kErrorNotFound There is no corresponding dataset stored in non-volatile memory.
*
*/
otError Read(Dataset &aDataset) const { return mLocal.Read(aDataset); }
Error Read(Dataset &aDataset) const { return mLocal.Read(aDataset); }
/**
* This method retrieves the dataset from non-volatile memory.
*
* @param[out] aDatasetInfo Where to place the dataset (as `Dataset::Info`).
*
* @retval OT_ERROR_NONE Successfully retrieved the dataset.
* @retval OT_ERROR_NOT_FOUND There is no corresponding dataset stored in non-volatile memory.
* @retval kErrorNone Successfully retrieved the dataset.
* @retval kErrorNotFound There is no corresponding dataset stored in non-volatile memory.
*
*/
otError Read(Dataset::Info &aDatasetInfo) const { return mLocal.Read(aDatasetInfo); }
Error Read(Dataset::Info &aDatasetInfo) const { return mLocal.Read(aDatasetInfo); }
/**
* This method retrieves the dataset from non-volatile memory.
*
* @param[out] aDataset Where to place the dataset.
*
* @retval OT_ERROR_NONE Successfully retrieved the dataset.
* @retval OT_ERROR_NOT_FOUND There is no corresponding dataset stored in non-volatile memory.
* @retval kErrorNone Successfully retrieved the dataset.
* @retval kErrorNotFound There is no corresponding dataset stored in non-volatile memory.
*
*/
otError Read(otOperationalDatasetTlvs &aDataset) const { return mLocal.Read(aDataset); }
Error Read(otOperationalDatasetTlvs &aDataset) const { return mLocal.Read(aDataset); }
/**
* This method retrieves the channel mask from local dataset.
*
* @param[out] aChannelMask A reference to the channel mask.
*
* @retval OT_ERROR_NONE Successfully retrieved the channel mask.
* @retval OT_ERROR_NOT_FOUND There is no valid channel mask stored in local dataset.
* @retval kErrorNone Successfully retrieved the channel mask.
* @retval kErrorNotFound There is no valid channel mask stored in local dataset.
*
*/
otError GetChannelMask(Mac::ChannelMask &aChannelMask) const;
Error GetChannelMask(Mac::ChannelMask &aChannelMask) const;
/**
* This method applies the Active or Pending Dataset to the Thread interface.
*
* @retval OT_ERROR_NONE Successfully applied configuration.
* @retval OT_ERROR_PARSE The dataset has at least one TLV with invalid format.
* @retval kErrorNone Successfully applied configuration.
* @retval kErrorParse The dataset has at least one TLV with invalid format.
*
*/
otError ApplyConfiguration(void) const;
Error ApplyConfiguration(void) const;
/**
* This method updates the Operational Dataset when detaching from the network.
@@ -150,11 +150,11 @@ public:
* @param[in] aTlvs Any additional raw TLVs to include.
* @param[in] aLength Number of bytes in @p aTlvs.
*
* @retval OT_ERROR_NONE Successfully send the meshcop dataset command.
* @retval OT_ERROR_NO_BUFS Insufficient buffer space to send.
* @retval kErrorNone Successfully send the meshcop dataset command.
* @retval kErrorNoBufs Insufficient buffer space to send.
*
*/
otError SendSetRequest(const Dataset::Info &aDatasetInfo, const uint8_t *aTlvs, uint8_t aLength);
Error SendSetRequest(const Dataset::Info &aDatasetInfo, const uint8_t *aTlvs, uint8_t aLength);
/**
* This method sends a MGMT_GET request.
@@ -164,25 +164,25 @@ public:
* @param[in] aLength Number of bytes in @p aTlvTypes.
* @param[in] aAddress The IPv6 destination address for the MGMT_GET request.
*
* @retval OT_ERROR_NONE Successfully send the meshcop dataset command.
* @retval OT_ERROR_NO_BUFS Insufficient buffer space to send.
* @retval kErrorNone Successfully send the meshcop dataset command.
* @retval kErrorNoBufs Insufficient buffer space to send.
*
*/
otError SendGetRequest(const Dataset::Components &aDatasetComponents,
const uint8_t * aTlvTypes,
uint8_t aLength,
const otIp6Address * aAddress) const;
Error SendGetRequest(const Dataset::Components &aDatasetComponents,
const uint8_t * aTlvTypes,
uint8_t aLength,
const otIp6Address * aAddress) const;
#if OPENTHREAD_FTD
/**
* This method appends the MLE Dataset TLV but excluding MeshCoP Sub Timestamp TLV.
*
* @param[in] aMessage The message to append the TLV to.
*
* @retval OT_ERROR_NONE Successfully append MLE Dataset TLV without MeshCoP Sub Timestamp TLV.
* @retval OT_ERROR_NO_BUFS Insufficient available buffers to append the message with MLE Dataset TLV.
* @retval kErrorNone Successfully append MLE Dataset TLV without MeshCoP Sub Timestamp TLV.
* @retval kErrorNoBufs Insufficient available buffers to append the message with MLE Dataset TLV.
*
*/
otError AppendMleDatasetTlv(Message &aMessage) const;
Error AppendMleDatasetTlv(Message &aMessage) const;
#endif
protected:
@@ -200,11 +200,11 @@ protected:
* @param[in] aMessage A message to read the TLV from.
* @param[in] aOffset An offset into the message to read from.
*
* @retval OT_ERROR_NONE The TLV was read successfully.
* @retval OT_ERROR_PARSE The TLV was not well-formed and could not be parsed.
* @retval kErrorNone The TLV was read successfully.
* @retval kErrorParse The TLV was not well-formed and could not be parsed.
*
*/
otError ReadFromMessage(const Message &aMessage, uint16_t aOffset);
Error ReadFromMessage(const Message &aMessage, uint16_t aOffset);
private:
enum
@@ -244,33 +244,33 @@ protected:
*
* @param[in] aDataset The Operational Dataset.
*
* @retval OT_ERROR_NONE Successfully applied configuration.
* @retval OT_ERROR_PARSE The dataset has at least one TLV with invalid format.
* @retval kErrorNone Successfully applied configuration.
* @retval kErrorParse The dataset has at least one TLV with invalid format.
*
*/
otError Save(const Dataset &aDataset);
Error Save(const Dataset &aDataset);
/**
* This method saves the Operational Dataset in non-volatile memory.
*
* @param[in] aDatasetInfo The Operational Dataset as `Dataset::Info`.
*
* @retval OT_ERROR_NONE Successfully saved the dataset.
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
* @retval kErrorNone Successfully saved the dataset.
* @retval kErrorNotImplemented The platform does not implement settings functionality.
*
*/
otError Save(const Dataset::Info &aDatasetInfo);
Error Save(const Dataset::Info &aDatasetInfo);
/**
* This method saves the Operational Dataset in non-volatile memory.
*
* @param[in] aDataset The Operational Dataset.
*
* @retval OT_ERROR_NONE Successfully saved the dataset.
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
* @retval kErrorNone Successfully saved the dataset.
* @retval kErrorNotImplemented The platform does not implement settings functionality.
*
*/
otError Save(const otOperationalDatasetTlvs &aDataset);
Error Save(const otOperationalDatasetTlvs &aDataset);
/**
* This method sets the Operational Dataset for the partition.
@@ -283,18 +283,18 @@ protected:
* @param[in] aLength The length of the Operational Dataset.
*
*/
otError Save(const Timestamp &aTimestamp, const Message &aMessage, uint16_t aOffset, uint8_t aLength);
Error Save(const Timestamp &aTimestamp, const Message &aMessage, uint16_t aOffset, uint8_t aLength);
/**
* This method saves the Operational Dataset in non-volatile memory.
*
* @param[in] aDataset The Operational Dataset.
*
* @retval OT_ERROR_NONE Successfully applied configuration.
* @retval OT_ERROR_PARSE The dataset has at least one TLV with invalid format.
* @retval kErrorNone Successfully applied configuration.
* @retval kErrorParse The dataset has at least one TLV with invalid format.
*
*/
otError SaveLocal(const Dataset &aDataset);
Error SaveLocal(const Dataset &aDataset);
/**
* This method handles a MGMT_GET request message.
@@ -327,11 +327,11 @@ protected:
* @param[in] aMessage The CoAP message buffer.
* @param[in] aMessageInfo The message info.
*
* @retval OT_ERROR_NONE The MGMT_SET request message was handled successfully.
* @retval OT_ERROR_DROP The MGMT_SET request message was dropped.
* @retval kErrorNone The MGMT_SET request message was handled successfully.
* @retval kErrorDrop The MGMT_SET request message was dropped.
*
*/
otError HandleSet(Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
Error HandleSet(Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
#endif
DatasetLocal mLocal;
@@ -342,19 +342,19 @@ private:
static void HandleCoapResponse(void * aContext,
otMessage * aMessage,
const otMessageInfo *aMessageInfo,
otError aError);
Error aError);
void HandleCoapResponse(void);
bool IsActiveDataset(void) const { return GetType() == Dataset::kActive; }
bool IsPendingDataset(void) const { return GetType() == Dataset::kPending; }
void SignalDatasetChange(void) const;
void HandleDatasetUpdated(void);
otError AppendDatasetToMessage(const Dataset::Info &aDatasetInfo, Message &aMessage) const;
void SendSet(void);
void SendGetResponse(const Coap::Message & aRequest,
const Ip6::MessageInfo &aMessageInfo,
uint8_t * aTlvs,
uint8_t aLength) const;
bool IsActiveDataset(void) const { return GetType() == Dataset::kActive; }
bool IsPendingDataset(void) const { return GetType() == Dataset::kPending; }
void SignalDatasetChange(void) const;
void HandleDatasetUpdated(void);
Error AppendDatasetToMessage(const Dataset::Info &aDatasetInfo, Message &aMessage) const;
void SendSet(void);
void SendGetResponse(const Coap::Message & aRequest,
const Ip6::MessageInfo &aMessageInfo,
uint8_t * aTlvs,
uint8_t aLength) const;
#if OPENTHREAD_FTD
void SendSetResponse(const Coap::Message &aRequest, const Ip6::MessageInfo &aMessageInfo, StateTlv::State aState);
@@ -430,29 +430,29 @@ public:
* @param[in] aLength The length of the Operational Dataset.
*
*/
otError Save(const Timestamp &aTimestamp, const Message &aMessage, uint16_t aOffset, uint8_t aLength);
Error Save(const Timestamp &aTimestamp, const Message &aMessage, uint16_t aOffset, uint8_t aLength);
/**
* This method sets the Operational Dataset in non-volatile memory.
*
* @param[in] aDatasetInfo The Operational Dataset as `Dataset::Info`.
*
* @retval OT_ERROR_NONE Successfully saved the dataset.
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
* @retval kErrorNone Successfully saved the dataset.
* @retval kErrorNotImplemented The platform does not implement settings functionality.
*
*/
otError Save(const Dataset::Info &aDatasetInfo) { return DatasetManager::Save(aDatasetInfo); }
Error Save(const Dataset::Info &aDatasetInfo) { return DatasetManager::Save(aDatasetInfo); }
/**
* This method sets the Operational Dataset in non-volatile memory.
*
* @param[in] aDataset The Operational Dataset.
*
* @retval OT_ERROR_NONE Successfully saved the dataset.
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
* @retval kErrorNone Successfully saved the dataset.
* @retval kErrorNotImplemented The platform does not implement settings functionality.
*
*/
otError Save(const otOperationalDatasetTlvs &aDataset) { return DatasetManager::Save(aDataset); }
Error Save(const otOperationalDatasetTlvs &aDataset) { return DatasetManager::Save(aDataset); }
#if OPENTHREAD_FTD
@@ -461,11 +461,11 @@ public:
*
* @param[out] aDatasetInfo The Operational Dataset as `Dataset::Info`.
*
* @retval OT_ERROR_NONE Successfully created a new Operational Dataset.
* @retval OT_ERROR_FAILED Failed to generate random values for new parameters.
* @retval kErrorNone Successfully created a new Operational Dataset.
* @retval kErrorFailed Failed to generate random values for new parameters.
*
*/
otError CreateNewNetwork(Dataset::Info &aDatasetInfo) { return aDatasetInfo.GenerateRandom(GetInstance()); }
Error CreateNewNetwork(Dataset::Info &aDatasetInfo) { return aDatasetInfo.GenerateRandom(GetInstance()); }
/**
* This method starts the Leader functions for maintaining the Active Operational Dataset.
@@ -482,12 +482,12 @@ public:
/**
* This method generate a default Active Operational Dataset.
*
* @retval OT_ERROR_NONE Successfully generated an Active Operational Dataset.
* @retval OT_ERROR_ALREADY A valid Active Operational Dataset already exists.
* @retval OT_ERROR_INVALID_STATE Device is not currently attached to a network.
* @retval kErrorNone Successfully generated an Active Operational Dataset.
* @retval kErrorAlready A valid Active Operational Dataset already exists.
* @retval kErrorInvalidState Device is not currently attached to a network.
*
*/
otError GenerateLocal(void);
Error GenerateLocal(void);
#endif
private:
@@ -543,11 +543,11 @@ public:
*
* @param[in] aDatasetInfo The Operational Dataset as `Dataset::Info`.
*
* @retval OT_ERROR_NONE Successfully saved the dataset.
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
* @retval kErrorNone Successfully saved the dataset.
* @retval kErrorNotImplemented The platform does not implement settings functionality.
*
*/
otError Save(const Dataset::Info &aDatasetInfo);
Error Save(const Dataset::Info &aDatasetInfo);
/**
* This method saves the Operational Dataset in non-volatile memory.
@@ -556,11 +556,11 @@ public:
*
* @param[in] aDataset The Operational Dataset.
*
* @retval OT_ERROR_NONE Successfully saved the dataset.
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
* @retval kErrorNone Successfully saved the dataset.
* @retval kErrorNotImplemented The platform does not implement settings functionality.
*
*/
otError Save(const otOperationalDatasetTlvs &aDataset);
Error Save(const otOperationalDatasetTlvs &aDataset);
/**
* This method sets the Operational Dataset for the partition.
@@ -575,18 +575,18 @@ public:
* @param[in] aLength The length of the Operational Dataset.
*
*/
otError Save(const Timestamp &aTimestamp, const Message &aMessage, uint16_t aOffset, uint8_t aLength);
Error Save(const Timestamp &aTimestamp, const Message &aMessage, uint16_t aOffset, uint8_t aLength);
/**
* This method saves the Operational Dataset in non-volatile memory.
*
* @param[in] aDataset The Operational Dataset.
*
* @retval OT_ERROR_NONE Successfully applied configuration.
* @retval OT_ERROR_PARSE The dataset has at least one TLV with invalid format.
* @retval kErrorNone Successfully applied configuration.
* @retval kErrorParse The dataset has at least one TLV with invalid format.
*
*/
otError Save(const Dataset &aDataset);
Error Save(const Dataset &aDataset);
#if OPENTHREAD_FTD
/**

Some files were not shown because too many files have changed in this diff Show More